Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@iksaku 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