Skip to content

Instantly share code, notes, and snippets.

@shoghicp
Last active July 4, 2020 12:27
Show Gist options
  • Save shoghicp/5d6b6bd6f11e6de1b70a to your computer and use it in GitHub Desktop.
Save shoghicp/5d6b6bd6f11e6de1b70a to your computer and use it in GitHub Desktop.
Minecraft: PE network enum generator
<?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";
@iksaku
Copy link

iksaku commented Jun 23, 2015

Simple xD Instead of writing everything again...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment