Advertisement
plirof2

zx_edit_sna_skooldaze.php

Nov 26th, 2022 (edited)
806
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 - SkoolDaze names - 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="SKOOLDAZ.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. function hex2str($hex) {
  25.     $str = '';
  26.     for($i=0;$i<strlen($hex);$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
  27.     return $str;
  28. }
  29.  
  30. //Second time
  31. $interval_size=13;// intervals 37 ok for first 17 ($group_iterations)
  32. $string_size=10; //Size of stored string
  33. $group_iterations=9;
  34.  
  35.  
  36.  
  37. $addr_array = array(
  38.     "999B"=>"Names",
  39.     //"0000A701"=>"Monsters first 18manticore",
  40.     //"0000A797"=>"Monsters first 18manticore",
  41.     //"0000A829"=>"Monsters first 18manticore",
  42.     //"0000A7BA"=>"BEAR Monsters first 18manticore",
  43.     //"0000AA31"=>"Monsters wraith",
  44.     //"0000929B"=>"SPELLNAMES",
  45.  
  46.  
  47.        
  48. );
  49.  
  50. // spells inital address is "929b"=>"MAGIC FIRE"
  51. //$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');
  52. //$chaos_spell_names=array('MAGIC FIRE','GOOEY BLOB');
  53.  
  54.  
  55. if($debug)print_r($chaos_spell_names);
  56.  
  57. $tmp_array_creation_string="";//used to get $addr_array entries individually
  58.  
  59. //$position=hexdec($addr);
  60. //if ($debug) echo $position;
  61. //$data="ARISOLE".$addr; // Replacement
  62.  
  63. $data="TEAM";
  64. $data=str_pad($data, 9);
  65. $index_add=0;
  66. /*
  67. if ($f=fopen($filename, "r+")) {
  68.  
  69.     foreach($addr_array as $pos => $pos_team ){
  70.         echo "<h3>$pos / ".hexdec($pos)." , $pos_team </h3>";
  71.         $position=hexdec($pos);
  72.         $index_add=0;
  73.         for($i=1;$i<23;$i++){
  74.             fseek($f, $position+$index_add);
  75.             $teamname=fread($f,9);
  76.             fseek($f, $position+$index_add);
  77.             echo "<li>$i ) $teamname (position+index_add($index_add))".dechex($position+$index_add)."/".($position+$index_add);
  78.             if ($write_enabled)fwrite($f, $data);
  79.             $index_add=10*$i;
  80.         } //End of for($i=1;$i,30l$i++){
  81.         echo "<HR>";
  82.     } //foreach($addr_array as $pos => $pos_team ){
  83.     fclose($f);
  84. } else {
  85.     echo "Can't open file";
  86. }
  87. */
  88.  
  89.  
  90. if ($f=fopen($filename, "rb")) {
  91.  
  92. //READ contents of file
  93. $contents = '';
  94. while (!feof($f)) {
  95.     $contents .= fread($f, 8192);
  96. }
  97. //echo "<hr>".$contents;
  98. fclose($f);
  99. }
  100. $content_orig=$contents;
  101. if ($debug) echo '<hr> COMPARE1 '.strcmp($content_orig, $contents);
  102.  
  103.  
  104.  
  105.  
  106.  
  107. if(@$_REQUEST["getfile"]!="true") {
  108. //if we don't have a request
  109.  
  110.  
  111. //echo "<h3>".substr($contents, 18987,220)."</h3>";
  112. echo "<form target='_blank' action='' method=POST >";
  113.  
  114.     foreach($addr_array as $pos => $pos_team ){
  115.         echo "<h3>$pos / ".hexdec($pos)." , $pos_team </h3>";
  116.         $position=hexdec($pos);
  117.         $index_add=0;
  118.         for($i=1;$i<$group_iterations;$i++){
  119.             //fseek($f, $position+$index_add);
  120.            // $teamname=fread($f,9);
  121.             $teamname=substr($contents, $position+$index_add,$string_size);
  122.             $teamname=str_replace(hex2str("00")," ",$teamname);
  123.             //$teamname="PATATAKIA";
  124.             //$teamname=str_pad($teamname, $string_size);
  125.             $tmp_array_creation_string=$tmp_array_creation_string.'"'.dechex($position+$index_add).'"=>"'.$teamname.'",';//    "0000A47E"=>"Monsters first 17",
  126.             //fseek($f, $position+$index_add);
  127.             echo "<li>$i ) $teamname (position+index_add($index_add))".dechex($position+$index_add)."/".($position+$index_add);
  128.             echo '<input type="text" id="fname'.($position+$index_add).'" name="'.($position+$index_add).'" value="'.$teamname.'" maxlength="'.$string_size.'" size="'.($string_size+4).'"   ><br>';
  129.             if ($write_enabled)fwrite($f, $data);
  130.             $index_add=($interval_size+1)*$i;
  131.         } //End of for($i=1;$i,30l$i++){
  132.         echo "<HR>";
  133.     } //foreach($addr_array as $pos => $pos_team ){
  134.  
  135. /*
  136. //SPELLS CHAOS specific
  137. echo "<h3>SPELL NAMES</H3>";
  138. $pos="929b";
  139. $position=hexdec($pos);
  140. $index_add=0;
  141. foreach($chaos_spell_names as $spell_name){
  142.     // spells inital address is "929b"=>"MAGIC FIRE"
  143.     $spell_string_length=strlen($spell_name);
  144.    // $spell_name=str_replace(" ","-",$spell_name);
  145.     echo "<li>"." ) $spell_name (position".dechex($position+$index_add)."/".($position+$index_add);
  146.  
  147.     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>';
  148.      $index_add=$index_add+$spell_string_length;
  149. }   // END of foreach($chaos_spell_names as $spell_name){  
  150. */
  151.  
  152.  
  153. /*
  154. //Skool Daze specific NOT good
  155. echo "<h3>Skool Daze</H3>";
  156. $pos="999B";
  157. $skooldaze_all_names_str_size=95;
  158. $position=hexdec($pos);
  159. $index_add=0;
  160.  
  161. $teamname=substr($contents, $position+$index_add,$skooldaze_all_names_str_size);
  162. echo "<hr>".$teamname."<hr>";
  163.  
  164. $skool_names_array = explode(hex2str("EDED"), $teamname);
  165. print_r($skool_names_array);
  166. echo "<hr>";
  167.  
  168. foreach($skool_names_array as $name){
  169.     // spells inital address is "929b"=>"MAGIC FIRE"
  170.     $spell_string_length=strlen($name);
  171.    // $spell_name=str_replace(" ","-",$spell_name);
  172.     echo "<li>"." ) $name (position".dechex($position+$index_add)."/".($position+$index_add);
  173.  
  174.     echo '<input type="text" id="fname'.($name).'" name="'.($position+$index_add).'" value="'.$name.'" maxlength="'.($spell_string_length).'" >(max size:'.($spell_string_length).')<br>';
  175.      $index_add=$index_add+$spell_string_length;
  176. }   // END of foreach($chaos_spell_names as $spell_name){  
  177. */
  178.  
  179. echo "<input type=hidden name='getfile' value=true >";
  180. echo "<input type=submit>";
  181. echo "</form>";
  182.  
  183.  
  184. echo"<hr>".$tmp_array_creation_string;
  185.  
  186.  
  187. }else {
  188. // If file download
  189.  
  190.  
  191. //if($debug)echo "<h3>contents line 126</h3>".$contents."<hr>";
  192. foreach($_REQUEST as $pos => $text ){
  193.     if ($debug) echo "<hr> $pos => $text";
  194.     if($pos=="getfile") continue;
  195.     //https://www.php.net/manual/en/function.file-put-contents.php
  196.  
  197. //}
  198.  
  199. //echo "<h3>".substr($contents, 18987,220)."</h3>";
  200. //echo "<form target='_blank' action=zx_recreate_sna_file.php >";
  201.     //oreach($addr_array as $pos => $pos_team ){
  202.         if ($debug) echo "<h3>$pos / ".hexdec($pos)." , $text </h3>";
  203.         $position=hexdec($pos);
  204.         $index_add=0;
  205.  
  206.         //for($i=1;$i<23;$i++){
  207.             //fseek($f, $position+$index_add);
  208.            // $teamname=fread($f,9);
  209.             //if($debug)echo "<h3>contents line 143</h3>".substr($contents, 0,9)."<hr>";           
  210.             //$contents=substr_replace($contents,$text,$pos,$string_size);
  211.             $text_length=strlen($text);
  212.             $contents=substr_replace($contents,$text,$pos,$text_length);               
  213.             //fseek($f, $position+$index_add);
  214.             $teamname=substr($contents, $position+$index_add,$text_length);
  215.             if ($debug) echo "<li> ) $teamname (position+index_add($index_add))".dechex($position+$index_add)."/".($position+$index_add);
  216.             //echo '<input type="text" id="fname'.($position+$index_add).'" name="'.($position+$index_add).'" value="'.$teamname.'" maxlength="9" ><br>';
  217.             //if ($write_enabled)fwrite($f, $data);
  218.             //$index_add=10*$i;
  219.         //} //End of for($i=1;$i,30l$i++){
  220.         if ($debug) echo "<HR>";
  221.     } //foreach($addr_array as $pos => $pos_team ){
  222. //echo "<input type=submit>";
  223. //echo "</form>";
  224.  
  225. if ($debug) echo '<hr> COMPARE '.strcmp($content_orig, $contents)."<BR>";
  226. //if($debug)echo "<hr><hr><hr>".$content_orig."<hr><hr>";
  227. if($debug) print_r($_REQUEST);
  228. header('Content-Disposition: attachment; filename="skoolmod.sna"');
  229. 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
  230. header('Content-Length: ' . strlen($contents));
  231. header('Connection: close');
  232. echo $contents;
  233.  
  234. //echo $str;
  235. }
  236. //end of if($_REQUEST["getfile"]!="true") {
  237. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement