Last active
July 4, 2020 12:27
-
-
Save shoghicp/5d6b6bd6f11e6de1b70a to your computer and use it in GitHub Desktop.
Minecraft: PE network enum generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = $argv[1]; | |
if(!file_exists($file)){ | |
die("File $file does not exist\n"); | |
} | |
$contents = file_get_contents($file); | |
$newContent = ""; | |
$firstId = null; | |
$count = 0; | |
foreach(explode("\n", $contents) as $line){ | |
if(preg_match("#^[ \t/]*const[ \t]+([A-Z0-9_]+_PACKET)[ \t]*=[ \t]*([0-9xA-Fa-f]+)[ \t]*;[ \t]*$#", $line, $matches) > 0){ | |
if($firstId === null){ | |
if(strpos($matches[2], "0x") !== false){ | |
$number = hexdec($matches[2]); | |
}else{ | |
$number = intval($matches[2]); | |
} | |
$firstId = $number; | |
$n = "0x" . dechex($number); | |
}else{ | |
$n = "0x" . dechex($firstId + ++$count); | |
$line = str_replace($matches[2], $n, $line); | |
} | |
echo $matches[1] . " => " . $n . "\n"; | |
} | |
$newContent .= $line . "\n"; | |
} | |
file_put_contents($file, $newContent); | |
echo "Done!\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple xD Instead of writing everything again...