Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/perl
- use strict;
- use warnings;
- my %ERROR_MESSAGES;
- $ERROR_MESSAGES{"invalid_stack_type"} = "invalid stack type. Only 7 and 17 are allowed, atm\n";
- # cli parameters
- my $gosub_offset;
- my $stack_type;
- my $target_offset; # offset you want to start the target mission at
- my $useful_code_size; # for name_thread, etc
- my $filler_code_size; # nops(0000) and alignment(FF05 FF)
- my $filler_code;
- my $thread_name_code;
- my $gosub_code;
- my $wait_code;
- print STDERR "THREAD NAME STUFF IS FOR SA, ATM (rest is compatible with vc).\n";
- ($stack_type, $gosub_offset) = stack_stuff();
- $target_offset = shift @ARGV;
- $useful_code_size = 0;
- $wait_code = "wait 0";
- $useful_code_size += 4;
- $gosub_code = "gosub \@loop\n:loop";
- $useful_code_size += 7;
- $thread_name_code = "03A4: 'perfect'";
- $useful_code_size += 11;
- $filler_code_size = $target_offset - $useful_code_size;
- if( $filler_code_size % 2 == 1 ) {
- # needs alignment
- $filler_code = "9905 FF " . "00" x ($filler_code_size - 3);
- }else{
- $filler_code = "00" x $filler_code_size;
- }
- #################
- #Finally ;), print the code
- #################
- if( $stack_type eq "name_thread" ) {
- print "$thread_name_code\n";
- print "$gosub_code\n";
- }elsif( $stack_type eq "immediate" ) {
- print "$gosub_code\n";
- print "$thread_name_code\n";
- }else{
- die $ERROR_MESSAGES{"invalid_stack_type"};
- }
- print "
- hex
- $filler_code
- end
- $wait_code
- jump \@loop
- ";
- sub stack_stuff {
- if(@ARGV == 2) {
- $gosub_offset = shift @ARGV;
- if($gosub_offset == 7) {
- $stack_type = "immediate";
- }elsif($gosub_offset == 17) {
- $stack_type = "name_thread";
- }else{
- die $ERROR_MESSAGES{"invalid_stack_type"};
- }
- }else{
- $stack_type = "name_thread";
- $gosub_offset = 17;
- }
- return ($stack_type, $gosub_offset);
- }
Add Comment
Please, Sign In to add comment