Advertisement
Guest User

Fire Emblem 3 Insert Script

a guest
Oct 26th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 43.84 KB | None | 0 0
  1. #inserts all text into FE3
  2. #expects intro text at intro.dump
  3.  
  4. use Insert;
  5. use rmheader;
  6. use insertfont;
  7.  
  8. die "Usage: insertall.pl original.smc finished.smc" unless @ARGV == 2;
  9.  
  10. my $original = shift @ARGV;
  11. my $output = shift @ARGV;
  12.  
  13. #clobber whatever is in $output
  14. open OUTPUT, ">$output" or die;
  15. close OUTPUT;
  16.  
  17. #set up output
  18. rmheader::rmheader( $original, $output );
  19. insertfont::insertfont( $output, "font.insert" );
  20.  
  21. #dump intro conversations
  22. my $ready = 0;
  23. my $temp = "temp.dump";
  24. my $ptr_index;
  25. my $txt_pos = "3000A0";
  26. my $position;
  27. open INTRO, "intro.dump" or die;
  28. while ( <INTRO> ) {
  29.     if ( /^\[META*/ ) {
  30.         #metadata line - either telling us the ptr_index, or useless
  31.         if ( / = / ) {
  32.             $line = $_;
  33.             #if we're ready, insert!
  34.             if ( $ready ) {
  35.                 print "Inserting $ptr_index at $txt_pos\n";
  36.                 close TEMP;
  37.                 if ( $ptr_index != 42 ) {
  38.                     $position =
  39.                         Insert::intro( $temp, $output, "300000",
  40.                                 $ptr_index, $txt_pos );
  41.                     $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  42.                 } else {
  43.                     #this part should always be written at 0x2e7243
  44.                     $temp_pos = "2e7243";
  45.                     close TEMP;
  46.                     $position = Insert::intro(
  47.                         $temp, $output, "300000", $ptr_index, $temp_pos );
  48.                 }
  49.             }
  50.             #start the next insertion
  51.             open TEMP, ">$temp" or die;
  52.             $line =~ / = ([0-9]*)/;
  53.             $ptr_index = $1;
  54.             $ready = 1;
  55.             print "Next pointer to insert: $ptr_index\n";
  56.         }
  57.     } else {
  58.         #write the line to TEMP
  59.         print TEMP;
  60.     }
  61. }
  62. print "Inserting $ptr_index at $txt_pos\n";
  63. close TEMP;
  64. #always write this at 0x2e305a
  65. $position = Insert::intro( $temp, $output, "300000", $ptr_index, "2e3157" );
  66. close INTRO;
  67.  
  68. #dump conversations
  69. $ready = 0;
  70. $temp = "temp.dump";
  71. $ptr_index = 1;
  72. open CONV, "conv.dump" or die;
  73. while ( <CONV> ) {
  74.     if ( /^\[META*/ ) {
  75.         #metadata line - either telling us the ptr_index, or useless
  76.         if ( / = / ) {
  77.             $line = $_;
  78.             #if we're ready, insert!
  79.             if ( $ready ) {
  80.                 print "Inserting $ptr_index at $txt_pos\n";
  81.                 close TEMP;
  82.                 $position =
  83.                     Insert::conv( $temp, $output, $ptr_index, "71213",
  84.                                  $txt_pos, 3 );
  85.                 $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  86.             }
  87.             #start the next insertion
  88.             open TEMP, ">$temp" or die;
  89.             $line =~ / = ([0-9]*)/;
  90.             $ptr_index = $1;
  91.             $ready = 1;
  92.         }
  93.     } else {
  94.         #write the line to TEMP
  95.         print TEMP;
  96.     }
  97. }
  98. #the last conversation
  99. close TEMP;
  100. $position = Insert::conv( $temp, $output, $ptr_index, "71213", $txt_pos, 3 );
  101. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  102.  
  103. #write the chapter headings - menu edition
  104. $first_byte = hex substr $txt_pos, 0, 2;
  105. $second_byte = hex substr $txt_pos, 2, 2;
  106. $first_byte = 2 * $first_byte;
  107. if ( $second_byte >= 0x80 ) {
  108.     $first_byte++;
  109. }
  110. $first_byte = sprintf "%.2x", $first_byte;
  111. Insert::write_misc( $output, $first_byte, "24218" );
  112. $ready = 0;
  113. open CHAP, "24223.dump" or die;
  114. while ( <CHAP> ) {
  115.     if ( /^\[META*/ ) {
  116.         #metadata line - either telling us the ptr_index, or useless
  117.         if ( / = / ) {
  118.             $line = $_;
  119.             #if we're ready, insert!
  120.             if ( $ready ) {
  121.                 print "Inserting $ptr_index at $txt_pos\n";
  122.                 close TEMP;
  123.                 $position =
  124.                     Insert::conv( $temp, $output, $ptr_index, "24223",
  125.                                 $txt_pos, 2 );
  126.                 $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  127.             }
  128.             #start the next insertion
  129.             open TEMP, ">$temp" or die;
  130.             $line =~ / = ([0-9]*)/;
  131.             $ptr_index = $1;
  132.             $ready = 1;
  133.             print "Next pointer to insert: $ptr_index\n";
  134.         }
  135.     } else {
  136.         #write the line to TEMP
  137.         print TEMP;
  138.     }
  139. }
  140. print "Inserting $ptr_index at $txt_pos\n";
  141. close CHAP;
  142. close TEMP;
  143. $position = Insert::conv( $temp, $output, $ptr_index, "24223", $txt_pos, 2 );
  144. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  145.  
  146. #write the chapter headings - chapter intro edition
  147. $first_byte = hex substr $txt_pos, 0, 2;
  148. $second_byte = hex substr $txt_pos, 2, 2;
  149. $first_byte = 2 * $first_byte;
  150. if ( $second_byte >= 0x80 ) {
  151.     $first_byte++;
  152. }
  153. $first_byte = sprintf "%.2x", $first_byte;
  154. #write the new subroutine that uses a different table for lookups
  155. Insert::write_misc( $output, "08c2300aaaa900" . $first_byte .
  156.     "8504bf0082ee8503286b", "370100" );
  157. #have the chapter intros call this subroutine
  158. Insert::write_misc( $output, "0081ee", "026721" );
  159. $ready = 0;
  160. open CHAP, "24223.dump2" or die;
  161. while ( <CHAP> ) {
  162.     if ( /^\[META*/ ) {
  163.         #metadata line - either telling us the ptr_index, or useless
  164.         if ( / = / ) {
  165.             $line = $_;
  166.             #if we're ready, insert!
  167.             if ( $ready ) {
  168.                 print "Inserting $ptr_index at $txt_pos\n";
  169.                 close TEMP;
  170.                 $position =
  171.                     Insert::conv( $temp, $output, $ptr_index, "370200",
  172.                                 $txt_pos, 2, 1 );
  173.                 $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  174.             }
  175.             #start the next insertion
  176.             open TEMP, ">$temp" or die;
  177.             $line =~ / = ([0-9]*)/;
  178.             $ptr_index = $1;
  179.             $ready = 1;
  180.             print "Next pointer to insert: $ptr_index\n";
  181.         }
  182.     } else {
  183.         #write the line to TEMP
  184.         print TEMP;
  185.     }
  186. }
  187. print "Inserting $ptr_index at $txt_pos\n";
  188. close CHAP;
  189. close TEMP;
  190. $position = Insert::conv( $temp, $output, $ptr_index, "24223", $txt_pos, 2 );
  191. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  192.  
  193. #write the delete/overwrite text
  194. $ready = 0;
  195. open DEL, "245bf.dump" or die;
  196. while ( <DEL> ) {
  197.     if ( /^\[META*/ ) {
  198.         #metadata line - either telling us the ptr_index, or useless
  199.         if ( / = / ) {
  200.             $line = $_;
  201.             #if we're ready, insert!
  202.             if ( $ready ) {
  203.                 print "Inserting $ptr_index at $txt_pos\n";
  204.                 close TEMP;
  205.                 $position =
  206.                     Insert::conv( $temp, $output, $ptr_index, "245bf",
  207.                                 $txt_pos, 3 );
  208.                 $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  209.             }
  210.             #start the next insertion
  211.             open TEMP, ">$temp" or die;
  212.             $line =~ / = ([0-9]*)/;
  213.             $ptr_index = $1;
  214.             $ready = 1;
  215.             print "Next pointer to insert: $ptr_index\n";
  216.         }
  217.     } else {
  218.         #write the line to TEMP
  219.         print TEMP;
  220.     }
  221. }
  222. print "Inserting $ptr_index at $txt_pos\n";
  223. close DEL;
  224. close TEMP;
  225. $position = Insert::conv( $temp, $output, $ptr_index, "245bf", $txt_pos, 3 );
  226. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  227.  
  228. $ready = 0;
  229. open DEL, "24604.dump" or die;
  230. while ( <DEL> ) {
  231.     if ( /^\[META*/ ) {
  232.         #metadata line - either telling us the ptr_index, or useless
  233.         if ( / = / ) {
  234.             $line = $_;
  235.             #if we're ready, insert!
  236.             if ( $ready ) {
  237.                 print "Inserting $ptr_index at $txt_pos\n";
  238.                 close TEMP;
  239.                 $position =
  240.                     Insert::conv( $temp, $output, $ptr_index, "24604",
  241.                                 $txt_pos, 3 );
  242.                 $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  243.             }
  244.             #start the next insertion
  245.             open TEMP, ">$temp" or die;
  246.             $line =~ / = ([0-9]*)/;
  247.             $ptr_index = $1;
  248.             $ready = 1;
  249.             print "Next pointer to insert: $ptr_index\n";
  250.         }
  251.     } else {
  252.         #write the line to TEMP
  253.         print TEMP;
  254.     }
  255. }
  256. print "Inserting $ptr_index at $txt_pos\n";
  257. close DEL;
  258. close TEMP;
  259. $position = Insert::conv( $temp, $output, $ptr_index, "24604", $txt_pos, 3 );
  260. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  261.  
  262. #insert the class roll
  263. Insert::write_misc( $output, "67", "3481e" );
  264. $ready = 0;
  265. open CLASS, "a9658.dump" or die;
  266. while ( <CLASS> ) {
  267.     if ( /^\[META*/ ) {
  268.         #metadata line - either telling us the ptr_index, or useless
  269.         if ( / = / ) {
  270.             $line = $_;
  271.             #if we're ready, insert!
  272.             if ( $ready ) {
  273.                 print "Inserting $ptr_index at $txt_pos\n";
  274.                 close TEMP;
  275.                 $position =
  276.                     Insert::conv( $temp, $output, $ptr_index, "a9658",
  277.                                 $txt_pos, 3 );
  278.                 $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  279.             }
  280.             #start the next insertion
  281.             open TEMP, ">$temp" or die;
  282.             $line =~ / = ([0-9]*)/;
  283.             $ptr_index = $1;
  284.             $ready = 1;
  285.             print "Next pointer to insert: $ptr_index\n";
  286.         }
  287.     } else {
  288.         #write the line to TEMP
  289.         print TEMP;
  290.     }
  291. }
  292. print "Inserting $ptr_index at $txt_pos\n";
  293. close CLASS;
  294. close TEMP;
  295. $position = Insert::conv( $temp, $output, $ptr_index, "a9658", $txt_pos, 3 );
  296. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  297.  
  298. #insert the scrolling intro
  299. $first_byte = hex substr $txt_pos, 0, 2;
  300. $second_byte = hex substr $txt_pos, 2, 2;
  301. $first_byte = 2 * $first_byte;
  302. if ( $second_byte >= 0x80 ) {
  303.     $first_byte++;
  304. }
  305. $first_byte = sprintf "%.2x", $first_byte;
  306. Insert::write_misc( $output, $first_byte, "6facf" );
  307. $ready = 0;
  308. open SCROLL, "6fb45.dump" or die;
  309. while ( <SCROLL> ) {
  310.     if ( /^\[META*/ ) {
  311.         #metadata line - either telling us the ptr_index, or useless
  312.         if ( / = / ) {
  313.             $line = $_;
  314.             #if we're ready, insert!
  315.             if ( $ready ) {
  316.                 print "Inserting $ptr_index at $txt_pos\n";
  317.                 close TEMP;
  318.                 $position =
  319.                     Insert::conv( $temp, $output, $ptr_index, "6fb45",
  320.                                 $txt_pos, 2, 2 );
  321.                 $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  322.             }
  323.             #start the next insertion
  324.             open TEMP, ">$temp" or die;
  325.             $line =~ / = ([0-9]*)/;
  326.             $ptr_index = $1;
  327.             $ready = 1;
  328.             print "Next pointer to insert: $ptr_index\n";
  329.         }
  330.     } else {
  331.         #write the line to TEMP
  332.         print TEMP;
  333.     }
  334. }
  335. print "Inserting $ptr_index at $txt_pos\n";
  336. close SCROLL;
  337. close TEMP;
  338. $position = Insert::conv( $temp, $output, $ptr_index, "6fb45", $txt_pos, 2, 2 );
  339. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  340.  
  341. #insert shop dialogue
  342. $ready = 0;
  343. open SHOP, "701c4.dump" or die;
  344. while ( <SHOP> ) {
  345.     if ( /^\[META*/ ) {
  346.         #metadata line - either telling us the ptr_index, or useless
  347.         if ( / = / ) {
  348.             $line = $_;
  349.             #if we're ready, insert!
  350.             if ( $ready ) {
  351.                 print "Inserting $ptr_index at $txt_pos\n";
  352.                 close TEMP;
  353.                 $position =
  354.                     Insert::conv( $temp, $output, $ptr_index, "701c4",
  355.                                 $txt_pos, 3 );
  356.                 $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  357.             }
  358.             #start the next insertion
  359.             open TEMP, ">$temp" or die;
  360.             $line =~ / = ([0-9]*)/;
  361.             $ptr_index = $1;
  362.             $ready = 1;
  363.             print "Next pointer to insert: $ptr_index\n";
  364.         }
  365.     } else {
  366.         #write the line to TEMP
  367.         print TEMP;
  368.     }
  369. }
  370. print "Inserting $ptr_index at $txt_pos\n";
  371. close SHOP;
  372. close TEMP;
  373. $position = Insert::conv( $temp, $output, $ptr_index, "701c4", $txt_pos, 3 );
  374. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  375.  
  376. #insert weapon names for the shop dialogue
  377. $first_byte = hex substr $txt_pos, 0, 2;
  378. $second_byte = hex substr $txt_pos, 2, 2;
  379. $first_byte = 2 * $first_byte;
  380. if ( $second_byte >= 0x80 ) {
  381.     $first_byte++;
  382. }
  383. $first_byte = sprintf "%.2x", $first_byte;
  384. Insert::write_misc( $output, "220089ee60", "3d521" );
  385. Insert::write_misc( $output,
  386.     "a50048a900${first_byte}85018d030f688d020f6b", "370900" );
  387. $ready = 0;
  388. open WEAP, "70c4a.dump" or die;
  389. while ( <WEAP> ) {
  390.     if ( /^\[META*/ ) {
  391.         #metadata line - either telling us the ptr_index, or useless
  392.         if ( / = / ) {
  393.             $line = $_;
  394.             #if we're ready, insert!
  395.             if ( $ready ) {
  396.                 print "Inserting $ptr_index at $txt_pos\n";
  397.                 close TEMP;
  398.                 $position =
  399.                     Insert::conv( $temp, $output, $ptr_index, "70c4a",
  400.                                 $txt_pos, 2, 3 );
  401.                 $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  402.             }
  403.             #start the next insertion
  404.             open TEMP, ">$temp" or die;
  405.             $line =~ / = ([0-9]*)/;
  406.             $ptr_index = $1;
  407.             $ready = 1;
  408.             print "Next pointer to insert: $ptr_index\n";
  409.         }
  410.     } else {
  411.         #write the line to TEMP
  412.         print TEMP;
  413.     }
  414. }
  415. print "Inserting $ptr_index at $txt_pos\n";
  416. close WEAP;
  417. close TEMP;
  418. $position = Insert::conv( $temp, $output, $ptr_index, "70c4a", $txt_pos, 2, 3 );
  419. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  420.  
  421. #insert coliseum dialogue
  422. Insert::write_misc( $output, "bf00808e8500e8bf00808e8501ca6b", "370500" );
  423. Insert::write_misc( $output, "2200856eeaea", "3a48a" );
  424. $ready = 0;
  425. open COL, "70000.dump" or die;
  426. while ( <COL> ) {
  427.     if ( /^\[META*/ ) {
  428.         #metadata line - either telling us the ptr_index, or useless
  429.         if ( / = / ) {
  430.             $line = $_;
  431.             #if we're ready, insert!
  432.             if ( $ready ) {
  433.                 print "Inserting $ptr_index at $txt_pos\n";
  434.                 close TEMP;
  435.                 $position =
  436.                     Insert::conv( $temp, $output, $ptr_index, "70000",
  437.                                 $txt_pos, 3 );
  438.                 $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  439.             }
  440.             #start the next insertion
  441.             open TEMP, ">$temp" or die;
  442.             $line =~ / = ([0-9]*)/;
  443.             $ptr_index = $1;
  444.             $ready = 1;
  445.             print "Next pointer to insert: $ptr_index\n";
  446.         }
  447.     } else {
  448.         #write the line to TEMP
  449.         print TEMP;
  450.     }
  451. }
  452. print "Inserting $ptr_index at $txt_pos\n";
  453. close COL;
  454. close TEMP;
  455. $position = Insert::conv( $temp, $output, $ptr_index,
  456.             "70000", $txt_pos, 3 );
  457. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  458.  
  459. #insert the ending text
  460. Insert::write_misc( $output, "220080ff", "b5f8b" );
  461. Insert::write_misc( $output, "220080ff", "b61a4" );
  462. Insert::write_misc( $output, "8ba9ff48abb2008703ab6b", "3f8000" );
  463. $ready = 0;
  464. $backup = $txt_pos;
  465. $txt_pos = "3f8100";
  466. $ptr_index = -1;
  467. open ENDING, "endings3.dump" or die;
  468. while ( <ENDING> ) {
  469.     if ( /^\[META*/ ) {
  470.         #metadata line
  471.         $line = $_;
  472.         #if we're ready, insert!
  473.         if ( $ready ) {
  474.             print "Inserting $ptr_index at $txt_pos\n";
  475.             close TEMP;
  476.             $position =
  477.                 Insert::ending( $temp, $output, "b356a", $ptr_index,
  478.                     $txt_pos, 8 );
  479.             $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  480.         }
  481.         #start the next insertion
  482.         open TEMP, ">$temp" or die;
  483.         #print three padding spaces to temp
  484.         $ptr_index++;
  485.         $ready = 1;
  486.         print "Next pointer to insert: $ptr_index\n";
  487.     } else {
  488.         #write the line to TEMP
  489.         print TEMP;
  490.     }
  491. }
  492. print "Inserting $ptr_index at $txt_pos\n";
  493. close ENDING;
  494. close TEMP;
  495. $position = Insert::ending( $temp, $output, "b356a", $ptr_index, $txt_pos, 8 );
  496. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  497. #insert the death text for endings
  498. Insert::write_misc( $output, "220080ff", "b618d" );
  499. $ready = 0;
  500. $ptr_index = -1;
  501. open ENDING2, "endings4.dump" or die;
  502. while ( <ENDING2> ) {
  503.     if ( /^\[META*/ ) {
  504.         #metadata line
  505.         $line = $_;
  506.         #if we're ready, insert!
  507.         if ( $ready ) {
  508.             print "Inserting $ptr_index at $txt_pos\n";
  509.             close TEMP;
  510.             $position =
  511.                 Insert::ending( $temp, $output, "b3842", $ptr_index,
  512.                     $txt_pos, 4 );
  513.             $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  514.         }
  515.         #start the next insertion
  516.         open TEMP, ">$temp" or die;
  517.         #print three padding spaces to temp
  518.         $ptr_index++;
  519.         $ready = 1;
  520.         print "Next pointer to insert: $ptr_index\n";
  521.     } else {
  522.         #write the line to TEMP
  523.         print TEMP;
  524.     }
  525. }
  526. print "Inserting $ptr_index at $txt_pos\n";
  527. close ENDING2;
  528. close TEMP;
  529. $position = Insert::ending( $temp, $output, "b3842", $ptr_index, $txt_pos, 4 );
  530. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  531. #miscellaneous ending stuff
  532. Insert::write_misc( $output,
  533.      "000100010001000f06101f2c2d29281b2631121f1d292c1e2d0000", "b39b0" );
  534. Insert::write_misc( $output, "b0b9", "b5d59" );
  535. Insert::write_misc( $output, "1700110c0011001131a0a0a0a0a005181000110000",
  536.     "b3907" );
  537. Insert::write_misc( $output, "0001000100010f03142292e1b2631061f2626010000", "b3950");
  538. Insert::write_misc( $output, "50b9", "b5dcf" );
  539. Insert::write_misc( $output, "50b9", "b60f0" );
  540. Insert::write_misc( $output, "02292925313f31171b2c31292031081f2c291f2d", "b3970" );
  541. Insert::write_misc( $output, "70b9", "b5ac3" );
  542. Insert::write_misc( $output, "01281e312d2938312e23271f312a1b2d2d1f2d3939390000",
  543.     "b3990" );
  544. Insert::write_misc( $output, "90b9", "b5a4a" );
  545. $position = Insert::ending( "b56a1.dump", $output, "b56a1", 0, $txt_pos, 4 );
  546. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  547. $position = Insert::ending( "b56c5.dump", $output, "b56c5", 0, $txt_pos, 4 );
  548. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  549. $position = Insert::ending( "b56f5.dump", $output, "b56f5", 0, $txt_pos, 4 );
  550. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  551. $position = Insert::ending( "b56fd.dump", $output, "b56fd", 0, $txt_pos, 4 );
  552. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  553. $position = Insert::ending( "b573d.dump", $output, "b573d", 0, $txt_pos, 4 );
  554. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  555. $position = Insert::ending( "b5741.dump", $output, "b5741", 0, $txt_pos, 4 );
  556. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  557. $txt_pos = $backup;
  558.  
  559. #insert the ending chapter names
  560. $position = Insert::intro( "b205e.dump", $output, "b3158", 0, $txt_pos, 1 );
  561. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  562. $position = Insert::intro( "b23d5.dump", $output, "b306f", 0, $txt_pos, 1 );
  563. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  564. $position = Insert::intro( "b276c.dump", $output, "b2f4b", 0, $txt_pos, 1 );
  565. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  566. #insert the ending turn number positions
  567. $position = "b1fdc";
  568. $value = "0033";
  569. for (0..19) {
  570.     $byte1 = substr $value, 0, 2;
  571.     $byte2 = substr $value, 2, 2;
  572.     Insert::write_misc( $output, $byte2 . $byte1, $position );
  573.     $value = sprintf "%.4x", hex( $value ) + hex( "21" );
  574.     $position = sprintf "%x", hex( $position ) + hex( "2" );
  575. }
  576. Insert::write_misc( $output, "c302", $position );
  577. $position = "b2006";
  578. $value = "0035";
  579. for (0..19) {
  580.     $byte1 = substr $value, 0, 2;
  581.     $byte2 = substr $value, 2, 2;
  582.     Insert::write_misc( $output, $byte2 . $byte1, $position );
  583.     $value = sprintf "%.4x", hex( $value ) + hex( "21" );
  584.     $position = sprintf "%x", hex( $position ) + hex( "2" );
  585. }
  586. Insert::write_misc( $output, "c302", $position );
  587. $position = "b2030";
  588. $value = "0035";
  589. for (0..21) {
  590.     $byte1 = substr $value, 0, 2;
  591.     $byte2 = substr $value, 2, 2;
  592.     Insert::write_misc( $output, $byte2 . $byte1, $position );
  593.     $value = sprintf "%.4x", hex( $value ) + hex( "21" );
  594.     $position = sprintf "%x", hex( $position ) + hex( "2" );
  595. }
  596. Insert::write_misc( $output, "0703", $position );
  597.  
  598. #insert the ending intro (book 1)
  599. $first_byte = hex substr $txt_pos, 0, 2;
  600. $second_byte = hex substr $txt_pos, 2, 2;
  601. $third_byte = hex substr $txt_pos, 4, 2;
  602. $first_byte = 2 * $first_byte;
  603. if ( $second_byte < 0x80 ) {
  604.     $second_byte += 0x80;
  605. } else {
  606.     $first_byte++;
  607. }
  608. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  609. $first_byte = sprintf "%.2x", $first_byte;
  610. $position = Insert::intro( "b114f.dump", $output, "b1150", 0, $txt_pos );
  611. Insert::write_misc( $output, "205391eaea", "b1b79" );
  612. Insert::write_misc( $output, "a900" . $first_byte . "8501" . "a9" . $bytes .
  613.     "850060", "b1153" );
  614. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  615. #insert the ending intro (book 2 - missed finale)
  616. $first_byte = hex substr $txt_pos, 0, 2;
  617. $second_byte = hex substr $txt_pos, 2, 2;
  618. $third_byte = hex substr $txt_pos, 4, 2;
  619. $first_byte = 2 * $first_byte;
  620. if ( $second_byte < 0x80 ) {
  621.     $second_byte += 0x80;
  622. } else {
  623.     $first_byte++;
  624. }
  625. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  626. $first_byte = sprintf "%.2x", $first_byte;
  627. $position = Insert::intro( "b11b6.dump", $output, "b1150", 0, $txt_pos );
  628. Insert::write_misc( $output, "205e91eaea", "b1b69" );
  629. Insert::write_misc( $output, "a900" . $first_byte . "8501" . "a9" . $bytes .
  630.     "850060", "b115e" );
  631. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  632. #insert the ending intro (book 2 - with finale)
  633. $first_byte = hex substr $txt_pos, 0, 2;
  634. $second_byte = hex substr $txt_pos, 2, 2;
  635. $third_byte = hex substr $txt_pos, 4, 2;
  636. $first_byte = 2 * $first_byte;
  637. if ( $second_byte < 0x80 ) {
  638.     $second_byte += 0x80;
  639. } else {
  640.     $first_byte++;
  641. }
  642. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  643. $first_byte = sprintf "%.2x", $first_byte;
  644. $position = Insert::intro( "b121b.dump", $output, "b1150", 0, $txt_pos, 2 );
  645. Insert::write_misc( $output, "206991eaea", "b1b59" );
  646. Insert::write_misc( $output, "a900" . $first_byte . "8501" . "a9" . $bytes .
  647.     "850060", "b1169" );
  648. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  649. #insert the perfect ending
  650. $first_byte = hex substr $txt_pos, 0, 2;
  651. $second_byte = hex substr $txt_pos, 2, 2;
  652. $third_byte = hex substr $txt_pos, 4, 2;
  653. $first_byte = 2 * $first_byte;
  654. if ( $second_byte < 0x80 ) {
  655.     $second_byte += 0x80;
  656. } else {
  657.     $first_byte++;
  658. }
  659. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  660. $first_byte = sprintf "%.2x", $first_byte;
  661. Insert::write_misc( $output, $bytes, "b6f74" );
  662. Insert::write_misc( $output, $first_byte, "b7778" );
  663. open PERFECT, "6c9d7.dump" or die;
  664. $ready = 0;
  665. $ptr_index = -1;
  666. while ( <PERFECT> ) {
  667.     if ( /^\[META*/ ) {
  668.         #metadata line
  669.         $line = $_;
  670.         #if we're ready, insert!
  671.         if ( $ready ) {
  672.             print "Inserting $ptr_index at $txt_pos\n";
  673.             close TEMP;
  674.             $position =
  675.                 Insert::intro( $temp, $output, $txt_pos, $ptr_index,
  676.                     $txt_pos, 3 );
  677.             $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  678.         }
  679.         #start the next insertion
  680.         open TEMP, ">$temp" or die;
  681.         #print three padding spaces to temp
  682.         $ptr_index++;
  683.         $ready = 1;
  684.         print "Next pointer to insert: $ptr_index\n";
  685.     } else {
  686.         #write the line to TEMP
  687.         print TEMP;
  688.     }
  689. }
  690. print "Inserting $ptr_index at $txt_pos\n";
  691. close PERFECT;
  692. close TEMP;
  693. $position = Insert::intro( $temp, $output, $txt_pos, $ptr_index, $txt_pos, 3 );
  694. $txt_pos = sprintf "%.6x", hex( $txt_pos ) + $position;
  695.  
  696. #insert the menu at the beginning of the game
  697. Insert::write_misc( $output, "121f2d2f271f310322310000", "360000" );
  698. Insert::write_misc( $output, "ec", "27ae2" );
  699. Insert::write_misc( $output, "0080", "27ae6" );
  700. Insert::write_misc( $output, "121f2d2e1b2c2e3103223100", "36000c" );
  701. Insert::write_misc( $output, "ec", "27b08" );
  702. Insert::write_misc( $output, "0c80", "27b0c" );
  703. Insert::write_misc( $output, "ec", "27ba0" );
  704. Insert::write_misc( $output, "0c80", "27ba4" );
  705. Insert::write_misc( $output, "0e1f3231071b271f31310000", "360018" );
  706. Insert::write_misc( $output, "ec", "27b2e" );
  707. Insert::write_misc( $output, "1880", "27b32" );
  708. Insert::write_misc( $output, "ec", "27bc6" );
  709. Insert::write_misc( $output, "1880", "27bca" );
  710. Insert::write_misc( $output, "ec", "27c38" );
  711. Insert::write_misc( $output, "1880", "27c3c" );
  712. Insert::write_misc( $output, "ec", "27c5e" );
  713. Insert::write_misc( $output, "1880", "27c62" );
  714. Insert::write_misc( $output, "03292a34310623261f310000", "360024" );
  715. Insert::write_misc( $output, "ec", "27b54" );
  716. Insert::write_misc( $output, "2480", "27b58" );
  717. Insert::write_misc( $output, "ec", "27bec" );
  718. Insert::write_misc( $output, "2480", "27bf0" );
  719. Insert::write_misc( $output, "052c1b2d1f310623261f0000", "360030" );
  720. Insert::write_misc( $output, "ec", "27b7a" );
  721. Insert::write_misc( $output, "3080", "27b7e" );
  722. Insert::write_misc( $output, "ec", "27c12" );
  723. Insert::write_misc( $output, "3080", "27c16" );
  724. #insert Empty for empty files
  725. Insert::write_misc( $output, "05272a2e34313131313131313131313131313131313131310000",
  726.                          "360042" );
  727. Insert::write_misc( $output, "ec", "24083" );
  728. Insert::write_misc( $output, "4280", "24087" );
  729.  
  730. #insert "BXCHXX" for the chapter prologues/file select menu
  731. Insert::write_misc( $output, "0200110011c40300110011c4c4c40000", "26821" );
  732. Insert::write_misc( $output, "0200110011c40300110011c4c4c40000", "246b0" );
  733. Insert::write_misc( $output, "0200110011c40300110011c4c4c40000", "246c5" );
  734. Insert::write_misc( $output, "0200110011c40300110011c4c4c40000", "246d0" );
  735. Insert::write_misc( $output, "3e", "240e4" );
  736.  
  737. #insert the book names
  738. Insert::write_misc( $output,
  739.     "02292925313e31171b2c31292031041b2c25281f2d2d313131310000", "36005c" );
  740. Insert::write_misc( $output, "eaeaeaea", "27d93" );
  741. Insert::write_misc( $output, "ec", "27da3" );
  742. Insert::write_misc( $output, "5c80", "27da7" );
  743. Insert::write_misc( $output, "b8", "27dac" );
  744. Insert::write_misc( $output,
  745.     "02292925313f31171b2c31292031081f2c291f2d3131313131310000", "360078" );
  746. Insert::write_misc( $output, "eaeaeaea", "27dd1" );
  747. Insert::write_misc( $output, "ec", "27de1" );
  748. Insert::write_misc( $output, "7880", "27de5" );
  749. Insert::write_misc( $output, "b8", "27dea" );
  750.  
  751. #insert yes/no for overwriting files
  752. Insert::write_misc( $output, "191f2d0000", "24664" );
  753. Insert::write_misc( $output, "0e29310000", "2466a" );
  754.  
  755. #insert the truncation for classes in the battle screen
  756. Insert::write_misc( $output,
  757. "088ba00000b700c9fffff010c00a00f00b200084e603e603c8c880e998186d18108d1810ab286b",
  758.                 "370300" );
  759. Insert::write_misc( $output,
  760.     "da5a0a0aaaa00000bff89a8b29ffc305069703a04000bffa9a8b29ffc3050697037afa60",
  761.                 "370400" );
  762. Insert::write_misc( $output,
  763.             "088b840029ff000aa8b7008500e220a97e8505c2208a1869fe408503a00000" .
  764.             "b70329003c85062200836eab2860",
  765.             "37f67" );
  766. Insert::write_misc( $output, "67ff", "3175f" );
  767. Insert::write_misc( $output, "67ff", "317c2" );
  768.  
  769. #insert the menus
  770. Insert::write_misc( $output, "00806e", "3b15e" );
  771. Insert::write_misc( $output, "00806e", "3b17a" );
  772. #insert the character names
  773. Insert::write_misc( $output, "0080", "8617" );
  774. Insert::write_misc( $output, "008b6e", "861b" );
  775. Insert::write_misc( $output, "0080", "923a" );
  776. Insert::write_misc( $output, "00806e", "923e" );
  777. Insert::write_misc( $output, "0080", "a86c" );
  778. Insert::write_misc( $output, "00806e", "a871" );
  779. Insert::write_misc( $output, "0080", "c5da" );
  780. Insert::write_misc( $output, "00806e", "c5e1" );
  781. Insert::write_misc( $output, "0080", "cb3f" );
  782. Insert::write_misc( $output, "00806e", "cb46" );
  783. Insert::write_misc( $output, "f0", "31746" );
  784. Insert::write_misc( $output, "0080", "31750" );
  785. Insert::write_misc( $output, "f0", "317a9" );
  786. Insert::write_misc( $output, "0080", "317b3" );
  787. Insert::write_misc( $output, "f0", "330bc" );
  788. Insert::write_misc( $output, "0080", "330c0" );
  789. Insert::write_misc( $output, "0080", "39f4b" );
  790. Insert::write_misc( $output, "f0", "39f6f" );
  791. Insert::write_misc( $output, "0080f0", "39f7b" );
  792. Insert::write_misc( $output, "0080", "3a675" );
  793. Insert::write_misc( $output, "0080f0", "3a6af" );
  794. $position = Insert::menu( "char.dump", $output, "380000", 142 );
  795. #insert the class names
  796. $second_byte = hex substr $position, 2, 2;
  797. $third_byte = hex substr $position, 4, 2;
  798. if ( $second_byte < 0x80 ) {
  799.     $second_byte += 0x80;
  800. }
  801. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  802. Insert::write_misc( $output, $bytes, "a3de" );
  803. Insert::write_misc( $output, "00806e", "a3e1" );
  804. Insert::write_misc( $output, $bytes, "c5e7" );
  805. Insert::write_misc( $output, "00806e", "c5ee" );
  806. Insert::write_misc( $output, $bytes, "cb4c" );
  807. Insert::write_misc( $output, "00806e", "cb53" );
  808. Insert::write_misc( $output, "f0", "3182c" );
  809. Insert::write_misc( $output, $bytes, "31832" );
  810. Insert::write_misc( $output, "f0", "3185e" );
  811. Insert::write_misc( $output, $bytes, "31864" );
  812. Insert::write_misc( $output, "f0", "33101" );
  813. Insert::write_misc( $output, $bytes, "33105" );
  814. $position = Insert::menu( "class.dump", $output, $position, 45 );
  815. #insert the special battle class names
  816. $second_byte = hex substr $position, 2, 2;
  817. $third_byte = hex substr $position, 4, 2;
  818. if ( $second_byte < 0x80 ) {
  819.     $second_byte += 0x80;
  820. }
  821. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  822. Insert::write_misc( $output, "f0", "31821" );
  823. Insert::write_misc( $output, $bytes, "31825" );
  824. $position = Insert::menu( "43297.dump", $output, $position, 9 );
  825. #insert the long version of knight names
  826. $second_byte = hex substr $position, 2, 2;
  827. $third_byte = hex substr $position, 4, 2;
  828. if ( $second_byte < 0x80 ) {
  829.     $second_byte += 0x80;
  830. }
  831. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  832. Insert::write_misc( $output, "f0", "31851" );
  833. Insert::write_misc( $output, $bytes, "31855" );
  834. $position = Insert::menu( "4330b.dump", $output, $position, 4 );
  835. #insert the weapon/item names
  836. $second_byte = hex substr $position, 2, 2;
  837. $third_byte = hex substr $position, 4, 2;
  838. if ( $second_byte < 0x80 ) {
  839.     $second_byte += 0x80;
  840. }
  841.  
  842. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  843. Insert::write_misc( $output, $bytes, "971f" );
  844. Insert::write_misc( $output, "00806e", "9725" );
  845. Insert::write_misc( $output, $bytes, "9b96" );
  846. Insert::write_misc( $output, "00806e", "9b99" );
  847. Insert::write_misc( $output, $bytes, "a3ff" );
  848. Insert::write_misc( $output, "00806e", "a402" );
  849. Insert::write_misc( $output, $bytes, "b2c0" );
  850. Insert::write_misc( $output, "00806e", "b2c4" );
  851. Insert::write_misc( $output, $bytes, "c600" );
  852. Insert::write_misc( $output, "00806e", "c607" );
  853. Insert::write_misc( $output, $bytes, "c699" );
  854. Insert::write_misc( $output, "00806e", "c69c" );
  855. Insert::write_misc( $output, $bytes, "c73e" );
  856. Insert::write_misc( $output, "00806e", "c741" );
  857. Insert::write_misc( $output, $bytes, "c866" );
  858. Insert::write_misc( $output, "00806e", "c86b" );
  859. Insert::write_misc( $output, $bytes, "ca26" );
  860. Insert::write_misc( $output, "00806e", "ca29" );
  861. Insert::write_misc( $output, $bytes, "da36" );
  862. Insert::write_misc( $output, "00806e", "da39" );
  863. Insert::write_misc( $output, $bytes, "db49" );
  864. Insert::write_misc( $output, "00806e", "db4f" );
  865. Insert::write_misc( $output, $bytes, "ed68" );
  866. Insert::write_misc( $output, "00806e", "ed6e" );
  867. Insert::write_misc( $output, $bytes, "edac" );
  868. Insert::write_misc( $output, "00806e", "edb2" );
  869. Insert::write_misc( $output, "f0", "31763" );
  870. Insert::write_misc( $output, $bytes, "31775" );
  871. Insert::write_misc( $output, "f0", "317c6" );
  872. Insert::write_misc( $output, $bytes, "317d8" );
  873. Insert::write_misc( $output, "f0", "330e7" );
  874. Insert::write_misc( $output, $bytes, "330eb" );
  875. Insert::write_misc( $output, $bytes, "3ae45" );
  876. Insert::write_misc( $output, "00806e", "3ae4b" );
  877. $position = Insert::menu ( "weapon.dump", $output, $position, 127 );
  878. #$position = Insert::menu ( "weapon.dump", $output, "5df58", 127 );
  879. #insert the weapon/item descriptions
  880. $second_byte = hex substr $position, 2, 2;
  881. $third_byte = hex substr $position, 4, 2;
  882. if ( $second_byte < 0x80 ) {
  883.     $second_byte += 0x80;
  884. }
  885. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  886. Insert::write_misc( $output, $bytes, "c1e8" );
  887. Insert::write_misc( $output, "00806e", "c1eb" );
  888. Insert::write_misc( $output, $bytes, "e74d" );
  889. Insert::write_misc( $output, "00806e", "e753" );
  890. Insert::write_misc( $output, $bytes, "e792" );
  891. Insert::write_misc( $output, "00806e", "e798" );
  892. $position = Insert::menu( "desc.dump", $output, $position, 129 );
  893. #insert the chapter names
  894. $second_byte = hex substr $position, 2, 2;
  895. $third_byte = hex substr $position, 4, 2;
  896. if ( $second_byte < 0x80 ) {
  897.     $second_byte += 0x80;
  898. }
  899. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  900. Insert::write_misc( $output, $bytes, "9a0a" );
  901. Insert::write_misc( $output, "00806e", "9a10" );
  902. $position = Insert::menu( "5c94e.dump", $output, $position, 45 );
  903. #insert the objectives
  904. $second_byte = hex substr $position, 2, 2;
  905. $third_byte = hex substr $position, 4, 2;
  906. if ( $second_byte < 0x80 ) {
  907.     $second_byte += 0x80;
  908. }
  909. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  910. Insert::write_misc( $output, $bytes, "9ad0" );
  911. Insert::write_misc( $output, "00806e", "9ad6" );
  912. $position = Insert::menu( "5d036.dump", $output, $position, 45 );
  913. #insert the terrain
  914. $second_byte = hex substr $position, 2, 2;
  915. $third_byte = hex substr $position, 4, 2;
  916. if ( $second_byte < 0x80 ) {
  917.     $second_byte += 0x80;
  918. }
  919. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  920. Insert::write_misc( $output, $bytes, "dc5d" );
  921. Insert::write_misc( $output, "00806e", "dc61" );
  922. $position = Insert::menu( "5f48e.dump", $output, $position, 162 );
  923. #insert the (character) menus
  924. $second_byte = hex substr $position, 2, 2;
  925. $third_byte = hex substr $position, 4, 2;
  926. if ( $second_byte < 0x80 ) {
  927.     $second_byte += 0x80;
  928. }
  929. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  930. Insert::write_misc( $output, $bytes, "ba08" );
  931. Insert::write_misc( $output, "00806e", "ba0d" );
  932. Insert::write_misc( $output, $bytes, "ba4a" );
  933. Insert::write_misc( $output, "00806e", "ba4f" );
  934. Insert::write_misc( $output, $bytes, "baa1" );
  935. Insert::write_misc( $output, "00806e", "baa4" );
  936. $position = Insert::menu( "5aae6.dump", $output, $position, 24 );
  937. #insert the character status screen
  938. $second_byte = hex substr $position, 2, 2;
  939. $third_byte = hex substr $position, 4, 2;
  940. if ( $second_byte < 0x80 ) {
  941.     $second_byte += 0x80;
  942. }
  943. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  944. Insert::write_misc( $output, $bytes, "cb59" );
  945. Insert::write_misc( $output, "00806e", "cb5f" );
  946. Insert::write_misc( $output, $bytes, "ce66" );
  947. Insert::write_misc( $output, "00806e", "ce6b" );
  948. Insert::write_misc( $output, $bytes, "cf3a" );
  949. Insert::write_misc( $output, "00806e", "cf3d" );
  950. Insert::write_misc( $output, $bytes, "cf7b" );
  951. Insert::write_misc( $output, "00806e", "cf80" );
  952. Insert::write_misc( $output, $bytes, "d09c" );
  953. Insert::write_misc( $output, "00806e", "d0a2" );
  954. $position = Insert::menu( "5ad32.dump", $output, $position, 16 );
  955. #insert the menu
  956. $second_byte = hex substr $position, 2, 2;
  957. $third_byte = hex substr $position, 4, 2;
  958. if ( $second_byte < 0x80 ) {
  959.     $second_byte += 0x80;
  960. }
  961. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  962. Insert::write_misc( $output, $bytes, "9853" );
  963. Insert::write_misc( $output, "00806e", "e2de" );
  964. Insert::write_misc( $output, $bytes, "99fa" );
  965. Insert::write_misc( $output, "00806e", "9a00" );
  966. Insert::write_misc( $output, $bytes, "a8ff" );
  967. Insert::write_misc( $output, "00806e", "a90c" );
  968. Insert::write_misc( $output, $bytes, "a9d7" );
  969. Insert::write_misc( $output, "00806e", "a9dc" );
  970. Insert::write_misc( $output, $bytes, "aa22" );
  971. Insert::write_misc( $output, "00806e", "aa28" );
  972. Insert::write_misc( $output, $bytes, "e97f" );
  973. Insert::write_misc( $output, "00806e", "e985" );
  974. Insert::write_misc( $output, $bytes, "eabc" );
  975. Insert::write_misc( $output, "00806e", "eac2" );
  976. Insert::write_misc( $output, $bytes, "eb4f" );
  977. Insert::write_misc( $output, "00806e", "eb55" );
  978. $position = Insert::menu( "59fea.dump", $output, $position, 14 );
  979. #insert the unit menu
  980. $second_byte = hex substr $position, 2, 2;
  981. $third_byte = hex substr $position, 4, 2;
  982. if ( $second_byte < 0x80 ) {
  983.     $second_byte += 0x80;
  984. }
  985. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  986. Insert::write_misc( $output, $bytes, "a2a8" );
  987. Insert::write_misc( $output, "00806e", "a2ae" );
  988. Insert::write_misc( $output, $bytes, "a2b5" );
  989. Insert::write_misc( $output, "00806e", "a2bf" );
  990. $position = Insert::menu( "5b46a.dump", $output, $position, 5 );
  991. #insert the trade/select menus
  992. $second_byte = hex substr $position, 2, 2;
  993. $third_byte = hex substr $position, 4, 2;
  994. if ( $second_byte < 0x80 ) {
  995.     $second_byte += 0x80;
  996. }
  997. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  998. Insert::write_misc( $output, $bytes, "845f" );
  999. Insert::write_misc( $output, "00806e", "8466" );
  1000. Insert::write_misc( $output, $bytes, "8486" );
  1001. Insert::write_misc( $output, "00806e", "848b" );
  1002. Insert::write_misc( $output, $bytes, "8efe" );
  1003. Insert::write_misc( $output, "00806e", "8f04" );
  1004. Insert::write_misc( $output, $bytes, "9626" );
  1005. Insert::write_misc( $output, "00806e", "962b" );
  1006. $position = Insert::menu( "5c638.dump", $output, $position, 6 );
  1007. #insert the options menu
  1008. $second_byte = hex substr $position, 2, 2;
  1009. $third_byte = hex substr $position, 4, 2;
  1010. if ( $second_byte < 0x80 ) {
  1011.     $second_byte += 0x80;
  1012. }
  1013. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  1014. Insert::write_misc( $output, $bytes, "9c3a" );
  1015. Insert::write_misc( $output, $bytes, "9c8c" );
  1016. $position = Insert::menu( "5bdd6.dump", $output, $position, 6 );
  1017. #insert the shop menus
  1018. $second_byte = hex substr $position, 2, 2;
  1019. $third_byte = hex substr $position, 4, 2;
  1020. if ( $second_byte < 0x80 ) {
  1021.     $second_byte += 0x80;
  1022. }
  1023. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  1024. Insert::write_misc( $output, $bytes, "3937a" );
  1025. Insert::write_misc( $output, "00806e", "39380" );
  1026. Insert::write_misc( $output, $bytes, "3965a" );
  1027. Insert::write_misc( $output, "00806e", "3965f" );
  1028. $position = Insert::menu( "5bcca.dump", $output, $position, 5 );
  1029. #insert the pre-chapter menu
  1030. $second_byte = hex substr $position, 2, 2;
  1031. $third_byte = hex substr $position, 4, 2;
  1032. if ( $second_byte < 0x80 ) {
  1033.     $second_byte += 0x80;
  1034. }
  1035. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  1036. Insert::write_misc( $output, $bytes, "8072" );
  1037. Insert::write_misc( $output, "00806e", "8078" );
  1038. $position = Insert::menu( "59f64.dump", $output, $position, 1 );
  1039. #insert "door opened!"
  1040. $second_byte = hex substr $position, 2, 2;
  1041. $third_byte = hex substr $position, 4, 2;
  1042. if ( $second_byte < 0x80 ) {
  1043.     $second_byte += 0x80;
  1044. }
  1045. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  1046. Insert::write_misc( $output, $bytes, "3a1b6" );
  1047. Insert::write_misc( $output, "00806e", "3a1b9" );
  1048. $position = Insert::menu( "59f64.dump", $output, $position, 1 );
  1049. #insert the turn switch menu
  1050. $second_byte = hex substr $position, 2, 2;
  1051. $third_byte = hex substr $position, 4, 2;
  1052. if ( $second_byte < 0x80 ) {
  1053.     $second_byte += 0x80;
  1054. }
  1055. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  1056. Insert::write_misc( $output, $bytes, "c2f6" );
  1057. Insert::write_misc( $output, "00806e", "c2f9" );
  1058. $position = Insert::menu( "5d0fa.dump", $output, $position, 3 );
  1059. #insert take/store/discard
  1060. $second_byte = hex substr $position, 2, 2;
  1061. $third_byte = hex substr $position, 4, 2;
  1062. if ( $second_byte < 0x80 ) {
  1063.     $second_byte += 0x80;
  1064. }
  1065. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  1066. Insert::write_misc( $output, $bytes, "af66" );
  1067. Insert::write_misc( $output, "00806e", "af6b" );
  1068. $position = Insert::menu( "5c4bc.dump", $output, $position, 1 );
  1069. #insert the battle animation menu
  1070. $second_byte = hex substr $position, 2, 2;
  1071. $third_byte = hex substr $position, 4, 2;
  1072. if ( $second_byte < 0x80 ) {
  1073.     $second_byte += 0x80;
  1074. }
  1075. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  1076. Insert::write_misc( $output, $bytes, "c434" );
  1077. Insert::write_misc( $output, "00806e", "c439" );
  1078. Insert::write_misc( $output, $bytes, "c463" );
  1079. $position = Insert::menu( "5c010.dump", $output, $position, 2 );
  1080. #insert the item menu
  1081. $second_byte = hex substr $position, 2, 2;
  1082. $third_byte = hex substr $position, 4, 2;
  1083. if ( $second_byte < 0x80 ) {
  1084.     $second_byte += 0x80;
  1085. }
  1086. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  1087. Insert::write_misc( $output, $bytes, "bb06" );
  1088. Insert::write_misc( $output, "00806e", "bb0c" );
  1089. Insert::write_misc( $output, $bytes, "bb38" );
  1090. Insert::write_misc( $output, "00806e", "bb3b" );
  1091. Insert::write_misc( $output, $bytes, "bb64" );
  1092. Insert::write_misc( $output, "00806e", "bb6a" );
  1093. $position = Insert::menu( "5acc6.dump", $output, $position, 6 );
  1094. #insert the discard menu
  1095. $second_byte = hex substr $position, 2, 2;
  1096. $third_byte = hex substr $position, 4, 2;
  1097. if ( $second_byte < 0x80 ) {
  1098.     $second_byte += 0x80;
  1099. }
  1100. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  1101. Insert::write_misc( $output, $bytes, "9253" );
  1102. Insert::write_misc( $output, "00806e", "9259" );
  1103. Insert::write_misc( $output, $bytes, "926e" );
  1104. Insert::write_misc( $output, "00806e", "9274" );
  1105. Insert::write_misc( $output, $bytes, "9705" );
  1106. Insert::write_misc( $output, "00806e", "970b" );
  1107. Insert::write_misc( $output, $bytes, "9729" );
  1108. Insert::write_misc( $output, "00806e", "972f" );
  1109. Insert::write_misc( $output, $bytes, "9b75" );
  1110. Insert::write_misc( $output, "00806e", "9b7b" );
  1111. Insert::write_misc( $output, $bytes, "a898" );
  1112. Insert::write_misc( $output, "00806e", "a89b" );
  1113. Insert::write_misc( $output, $bytes, "b2a6" );
  1114. Insert::write_misc( $output, "00806e", "b2ac" );
  1115. Insert::write_misc( $output, $bytes, "b2c8" );
  1116. Insert::write_misc( $output, "00806e", "b2ce" );
  1117. Insert::write_misc( $output, $bytes, "c716" );
  1118. Insert::write_misc( $output, "00806e", "c71b" );
  1119. Insert::write_misc( $output, $bytes, "c7b6" );
  1120. Insert::write_misc( $output, "00806e", "c7bb" );
  1121. Insert::write_misc( $output, $bytes, "ca8f" );
  1122. Insert::write_misc( $output, "00806e", "ca95" );
  1123. Insert::write_misc( $output, $bytes, "db34" );
  1124. Insert::write_misc( $output, "00806e", "db39" );
  1125. $position = Insert::menu( "5a9bc.dump", $output, $position, 6 );
  1126. #insert a miscellaneous menu
  1127. $second_byte = hex substr $position, 2, 2;
  1128. $third_byte = hex substr $position, 4, 2;
  1129. if ( $second_byte < 0x80 ) {
  1130.     $second_byte += 0x80;
  1131. }
  1132. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  1133. Insert::write_misc( $output, $bytes, "9b0a" );
  1134. Insert::write_misc( $output, "00806e", "9b10" );
  1135. Insert::write_misc( $output, $bytes, "c151" );
  1136. Insert::write_misc( $output, "00806e", "c157" );
  1137. Insert::write_misc( $output, $bytes, "c5c0" );
  1138. Insert::write_misc( $output, "00806e", "c5c6" );
  1139. Insert::write_misc( $output, $bytes, "c90a" );
  1140. Insert::write_misc( $output, "00806e", "c910" );
  1141. Insert::write_misc( $output, $bytes, "da43" );
  1142. Insert::write_misc( $output, "00806e", "da46" );
  1143. Insert::write_misc( $output, $bytes, "dc79" );
  1144. Insert::write_misc( $output, "00806e", "dc7f" );
  1145. Insert::write_misc( $output, $bytes, "ee34" );
  1146. Insert::write_misc( $output, "00806e", "ee3a" );
  1147. Insert::write_misc( $output, $bytes, "3ae32" );
  1148. Insert::write_misc( $output, "00806e", "3ae35" );
  1149. Insert::write_misc( $output, $bytes, "3998f" );
  1150. Insert::write_misc( $output, "00806e", "39995" );
  1151. Insert::write_misc( $output, $bytes, "39a9d" );
  1152. Insert::write_misc( $output, "00806e", "39aa3" );
  1153. Insert::write_misc( $output, $bytes, "39ac0" );
  1154. Insert::write_misc( $output, "00806e", "39ac6" );
  1155. Insert::write_misc( $output, $bytes, "39f56" );
  1156. $position = Insert::menu( "5b522.dump", $output, $position, 25 );
  1157.  
  1158. #insert the supply notices
  1159. $second_byte = hex substr $position, 2, 2;
  1160. $third_byte = hex substr $position, 4, 2;
  1161. if ( $second_byte < 0x80 ) {
  1162.     $second_byte += 0x80;
  1163. }
  1164. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  1165. Insert::write_misc( $output, $bytes, "bea0" );
  1166. Insert::write_misc( $output, "00806e", "bea6" );
  1167. Insert::write_misc( $output, $bytes, "bed4" );
  1168. Insert::write_misc( $output, "00806e", "beda" );
  1169. Insert::write_misc( $output, $bytes, "bf0c" );
  1170. Insert::write_misc( $output, "00806e", "bf12" );
  1171. Insert::write_misc( $output, $bytes, "bf53" );
  1172. Insert::write_misc( $output, "00806e", "bf59" );
  1173. Insert::write_misc( $output, $bytes, "e434" );
  1174. Insert::write_misc( $output, "00806e", "e43c" );
  1175. $position = Insert::menu( "5ae94.dump", $output, $position, 13 );
  1176. #insert the item effect notices
  1177. $second_byte = hex substr $position, 2, 2;
  1178. $third_byte = hex substr $position, 4, 2;
  1179. if ( $second_byte < 0x80 ) {
  1180.     $second_byte += 0x80;
  1181. }
  1182. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  1183. Insert::write_misc( $output, $bytes, "ec9d" );
  1184. Insert::write_misc( $output, "00806e", "eca2" );
  1185. Insert::write_misc( $output, $bytes, "ecdc" );
  1186. Insert::write_misc( $output, "00806e", "ece7" );
  1187. Insert::write_misc( $output, $bytes, "ed20" );
  1188. Insert::write_misc( $output, "00806e", "ed25" );
  1189. Insert::write_misc( $output, $bytes, "ed4e" );
  1190. Insert::write_misc( $output, "00806e", "ed54" );
  1191. Insert::write_misc( $output, $bytes, "ed97" );
  1192. Insert::write_misc( $output, "00806e", "ed9c" );
  1193. Insert::write_misc( $output, $bytes, "3b3d4" );
  1194. Insert::write_misc( $output, "00806e", "3b3d9" );
  1195. $position = Insert::menu( "5d13a.dump", $output, $position, 15 );
  1196. #insert the in-battle text
  1197. $first_byte = hex substr $position, 0, 2;
  1198. $second_byte = hex substr $position, 2, 2;
  1199. $third_byte = hex substr $position, 4, 2;
  1200. $first_byte = 2 * $first_byte;
  1201. if ( $second_byte < 0x80 ) {
  1202.     $second_byte += 0x80;
  1203. } else {
  1204.     $first_byte++;
  1205. }
  1206. $bytes = sprintf "%.2x%.2x", $third_byte, $second_byte;
  1207. $first_byte = sprintf "%.2x", $first_byte;
  1208. Insert::write_misc( $output, $bytes, "330a1" );
  1209. Insert::write_misc( $output, $first_byte, "3309d" );
  1210. Insert::write_misc( $output, $bytes, "33147" );
  1211. Insert::write_misc( $output, $first_byte, "33143" );
  1212. $position = Insert::menu( "42ddb.dump", $output, $position, 69 );
  1213. #in-battle participle hax
  1214. Insert::write_misc( $output, "20a0ff", "330b0" );
  1215. Insert::write_misc( $output, "220086eeae181060", "37fa0" );
  1216. Insert::write_misc( $output,
  1217. "e220c905f003c2206be8e8bdb41d48c907f03ac909f022c920f01ec90af01ec90bf026c913f022c914f01ec935f016c936f012c92df00a801fa9408012a941800ea943800aa9428006a91f8002a9449db41dcaca68c2206b68a943cacac2206b",
  1218.     "370600" );
  1219. #in-battle weapon/command switch hax
  1220. Insert::write_misc( $output, "20b0ff", "330d9" );
  1221. Insert::write_misc( $output, "22008aee60", "37fb0" );
  1222. Insert::write_misc( $output, "209bb06b", "37fc0" );
  1223. Insert::write_misc( $output,
  1224. "daee3910ae3910bdb41de220c913f016c914f012c907f00ec909f010c220ce3910faa900246bc22022c0ff86e220a91fce3910ae39109db41d80e1",
  1225. "370a00" );
  1226. #in-battle newlines hax
  1227. Insert::write_misc( $output, "220087ee60", "33199" );
  1228. Insert::write_misc( $output, "2075b1e603e603c8c86b", "331a5" );
  1229. Insert::write_misc( $output,
  1230.     "48a503186980002980ff18690c00850368c8c86b", "370800" );
  1231. Insert::write_misc( $output,
  1232. "088ba00000b700c9fdffd006220088ee80f3c9fffff00622a5b18680e898186d18108d1810ab286b",
  1233.     "370700" );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement