Advertisement
plirof2

zx_edit_sna_Chaos_v008.php

Nov 25th, 2022 (edited)
864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $debug=false; //NEED to be false to enable download
  3. /*
  4. v221125a - Seems to work
  5. v221124b-
  6. v221123 - Initial PHP version
  7.  
  8. use https://hexed.it/
  9.  
  10. ToDo:
  11. - Create second PHP file where it merges changes and SNA file
  12. - Footballer of the year -add HEX for players names
  13. */
  14. $write_enabled=false;
  15. $filename="fb_year.sna";
  16. $filename="CHAOS.SNA";
  17.  
  18.  
  19. //echo str_pad($input, 9);                      // produces "Alien     "
  20.  
  21. //$position=hexdec("00004Α2Β"); // You have to pre-calculate it once
  22. //$position=hexdec("00010edb"); // You have to pre-calculate it
  23.  
  24. //Second time
  25. $interval_size=37;// intervals 37 ok for first 17 ($group_iterations)
  26. $string_size=13; //Size of stored string
  27. $group_iterations=2;
  28.  
  29. $addr_array = array(
  30.     //"000092B8"=>"Monsters first 17",
  31.     //"0000A701"=>"Monsters first 18manticore",
  32.     //"0000A797"=>"Monsters first 18manticore",
  33.     //"0000A829"=>"Monsters first 18manticore",
  34.     //"0000A7BA"=>"BEAR Monsters first 18manticore",
  35.     //"0000AA31"=>"Monsters wraith",
  36.     //"0000929B"=>"SPELLNAMES",
  37.  
  38.  
  39.     "a47e"=>"KING COBRA ","a4a4"=>"BAT ","a4ca"=>"BLOB ","a4f0"=>"DIRE WOLF ","a516"=>"SPECTRE ","a53c"=>"GOBLIN ","a562"=>"CROCODILE ","a588"=>"GREEN DRAGON ","a5ae"=>"VAMPIRE ","a5d4"=>"FAUN ","a5fa"=>"LION ","a620"=>"GRYPHON ","a646"=>"ELF ","a66c"=>"HORSE ","a692"=>"ORC ","a6b8"=>"RED DRAGON ","a701"=>"MANTICORE ","a728"=>"TROLL ","a74e"=>"UNICORN ","a773"=>"EGHOST ",
  40.  
  41.     "a797"=>"WRAITH ",
  42.     "a7ba"=>"BEAR ","a7e0"=>"GORILLA ","a806"=>"SKELETON ",
  43.  
  44.     "a829"=>"OGRE ","a84f"=>"ZOMBIE ",
  45.  
  46.     "a872"=>"HARPY ","a898"=>"PEGASUS ","a8be"=>"EAGLE ","a8e4"=>"HYDRA ","a90a"=>"GIANT RAT ","a930"=>"CENTAUR ","a956"=>"GIANT ","a97c"=>"GOLDEN DRAGON","a9a2"=>"DARK CITADEL ","a9c8"=>"MAGIC CASTLE ",
  47.  
  48.     "0000A9EB"=>"SHADOW WOOD ","0000AA0E"=>"MAGIC WOOD ","0000AA31"=>"WALL ",
  49.  
  50.        
  51. );
  52. /*
  53. $addr_spell_names_chaos=array(
  54.         //spells (different size each one)
  55.     "929b"=>"MAGIC FIRE","92a5"=>"GOOEY BLOB",
  56.     "92b8"=>"VENGEANCE",
  57.  
  58. "929B"=>'MAGIC FIREGOOEY BLOBLIGHTNINGVENGEANCEDARK POWERDECREEJUSTICELAW-1LAW-2CHAOS-1CHAOS-2MAGIC SHIELDMAGIC ARMOURMAGIC SWORDMAGIC KNIFEMAGIC BOWBLINDMAGIC BOLTTEMPESTRAISE DEADTELEPORTSUBVERSIONTURMOILDEAD REVENGECONSECRATIONDISPELCOUNTER SPELLMAGIC WINGSMAGIC SLEEPSHADOW FORM'
  59. );
  60. */
  61. // spells inital address is "929b"=>"MAGIC FIRE"
  62. $chaos_spell_names=array('MAGIC FIRE','GOOEY BLOB','LIGHTNING','VENGEANCE','DARK POWER','DECREE','JUSTICE','LAW-1','LAW-2','CHAOS-1','CHAOS-2','MAGIC SHIELD','MAGIC ARMOUR','MAGIC SWORD','MAGIC KNIFE','MAGIC BOW','BLIND','MAGIC BOLT','TEMPEST','RAISE DEAD','TELEPORT','SUBVERSION','TURMOIL','DEAD REVENGE','CONSECRATION','DISPEL','COUNTER SPELL','MAGIC WINGS','MAGIC SLEEP','SHADOW FORM');
  63. //$chaos_spell_names=array('MAGIC FIRE','GOOEY BLOB');
  64.  
  65.  
  66. if($debug)print_r($chaos_spell_names);
  67.  
  68. $tmp_array_creation_string="";//used to get $addr_array entries individually
  69.  
  70. //$position=hexdec($addr);
  71. //if ($debug) echo $position;
  72. //$data="ARISOLE".$addr; // Replacement
  73.  
  74. $data="TEAM";
  75. $data=str_pad($data, 9);
  76. $index_add=0;
  77. /*
  78. if ($f=fopen($filename, "r+")) {
  79.  
  80.     foreach($addr_array as $pos => $pos_team ){
  81.         echo "<h3>$pos / ".hexdec($pos)." , $pos_team </h3>";
  82.         $position=hexdec($pos);
  83.         $index_add=0;
  84.         for($i=1;$i<23;$i++){
  85.             fseek($f, $position+$index_add);
  86.             $teamname=fread($f,9);
  87.             fseek($f, $position+$index_add);
  88.             echo "<li>$i ) $teamname (position+index_add($index_add))".dechex($position+$index_add)."/".($position+$index_add);
  89.             if ($write_enabled)fwrite($f, $data);
  90.             $index_add=10*$i;
  91.         } //End of for($i=1;$i,30l$i++){
  92.         echo "<HR>";
  93.     } //foreach($addr_array as $pos => $pos_team ){
  94.     fclose($f);
  95. } else {
  96.     echo "Can't open file";
  97. }
  98. */
  99.  
  100.  
  101. if ($f=fopen($filename, "rb")) {
  102.  
  103. //READ contents of file
  104. $contents = '';
  105. while (!feof($f)) {
  106.     $contents .= fread($f, 8192);
  107. }
  108. //echo "<hr>".$contents;
  109. fclose($f);
  110. }
  111. $content_orig=$contents;
  112. if ($debug) echo '<hr> COMPARE1 '.strcmp($content_orig, $contents);
  113.  
  114.  
  115.  
  116.  
  117.  
  118. if(@$_REQUEST["getfile"]!="true") {
  119. //if we don't have a request
  120.  
  121.  
  122. //echo "<h3>".substr($contents, 18987,220)."</h3>";
  123. echo "<form target='_blank' action='' method=POST >";
  124.  
  125.     foreach($addr_array as $pos => $pos_team ){
  126.         echo "<h3>$pos / ".hexdec($pos)." , $pos_team </h3>";
  127.         $position=hexdec($pos);
  128.         $index_add=0;
  129.         for($i=1;$i<$group_iterations;$i++){
  130.             //fseek($f, $position+$index_add);
  131.            // $teamname=fread($f,9);
  132.             $teamname=substr($contents, $position+$index_add,$string_size);
  133.             //$teamname="PATATAKIA";
  134.             //$teamname=str_pad($teamname, $string_size);
  135.             $tmp_array_creation_string=$tmp_array_creation_string.'"'.dechex($position+$index_add).'"=>"'.$teamname.'",';//    "0000A47E"=>"Monsters first 17",
  136.             //fseek($f, $position+$index_add);
  137.             echo "<li>$i ) $teamname (position+index_add($index_add))".dechex($position+$index_add)."/".($position+$index_add);
  138.             echo '<input type="text" id="fname'.($position+$index_add).'" name="'.($position+$index_add).'" value="'.$teamname.'" maxlength="'.$string_size.'" ><br>';
  139.             if ($write_enabled)fwrite($f, $data);
  140.             $index_add=($interval_size+1)*$i;
  141.         } //End of for($i=1;$i,30l$i++){
  142.         echo "<HR>";
  143.     } //foreach($addr_array as $pos => $pos_team ){
  144.  
  145.  
  146. //SPELLS CHAOS specific
  147. echo "<h3>SPELL NAMES</H3>";
  148. $pos="929b";
  149. $position=hexdec($pos);
  150. $index_add=0;
  151. foreach($chaos_spell_names as $spell_name){
  152.     // spells inital address is "929b"=>"MAGIC FIRE"
  153.     $spell_string_length=strlen($spell_name);
  154.    // $spell_name=str_replace(" ","-",$spell_name);
  155.     echo "<li>"." ) $spell_name (position".dechex($position+$index_add)."/".($position+$index_add);
  156.  
  157.     echo '<input type="text" id="fname'.($spell_name).'" name="'.($position+$index_add).'" value="'.$spell_name.'" maxlength="'.($spell_string_length).'" >(max size:'.($spell_string_length).')<br>';
  158.      $index_add=$index_add+$spell_string_length;
  159. }   // END of foreach($chaos_spell_names as $spell_name){  
  160.  
  161. echo "<input type=hidden name='getfile' value=true >";
  162. echo "<input type=submit>";
  163. echo "</form>";
  164.  
  165.  
  166. echo"<hr>".$tmp_array_creation_string;
  167.  
  168.  
  169. }else {
  170. // If file download
  171.  
  172.  
  173. //if($debug)echo "<h3>contents line 126</h3>".$contents."<hr>";
  174. foreach($_REQUEST as $pos => $text ){
  175.     if ($debug) echo "<hr> $pos => $text";
  176.     if($pos=="getfile") continue;
  177.     //https://www.php.net/manual/en/function.file-put-contents.php
  178.  
  179. //}
  180.  
  181. //echo "<h3>".substr($contents, 18987,220)."</h3>";
  182. //echo "<form target='_blank' action=zx_recreate_sna_file.php >";
  183.     //oreach($addr_array as $pos => $pos_team ){
  184.         if ($debug) echo "<h3>$pos / ".hexdec($pos)." , $text </h3>";
  185.         $position=hexdec($pos);
  186.         $index_add=0;
  187.  
  188.         //for($i=1;$i<23;$i++){
  189.             //fseek($f, $position+$index_add);
  190.            // $teamname=fread($f,9);
  191.             //if($debug)echo "<h3>contents line 143</h3>".substr($contents, 0,9)."<hr>";           
  192.             //$contents=substr_replace($contents,$text,$pos,$string_size);
  193.             $text_length=strlen($text);
  194.             $contents=substr_replace($contents,$text,$pos,$text_length);               
  195.             //fseek($f, $position+$index_add);
  196.             $teamname=substr($contents, $position+$index_add,$text_length);
  197.             if ($debug) echo "<li> ) $teamname (position+index_add($index_add))".dechex($position+$index_add)."/".($position+$index_add);
  198.             //echo '<input type="text" id="fname'.($position+$index_add).'" name="'.($position+$index_add).'" value="'.$teamname.'" maxlength="9" ><br>';
  199.             //if ($write_enabled)fwrite($f, $data);
  200.             //$index_add=10*$i;
  201.         //} //End of for($i=1;$i,30l$i++){
  202.         if ($debug) echo "<HR>";
  203.     } //foreach($addr_array as $pos => $pos_team ){
  204. //echo "<input type=submit>";
  205. //echo "</form>";
  206.  
  207. if ($debug) echo '<hr> COMPARE '.strcmp($content_orig, $contents)."<BR>";
  208. //if($debug)echo "<hr><hr><hr>".$content_orig."<hr><hr>";
  209. if($debug) print_r($_REQUEST);
  210. header('Content-Disposition: attachment; filename="chaosmod.sna"');
  211. header('Content-Type: text/plain'); # Don't use application/force-download - it's not a real MIME type, and the Content-Disposition header is sufficient
  212. header('Content-Length: ' . strlen($contents));
  213. header('Connection: close');
  214. echo $contents;
  215.  
  216. //echo $str;
  217. }
  218. //end of if($_REQUEST["getfile"]!="true") {
  219. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement