-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnbt.php
59 lines (59 loc) · 1.28 KB
/
nbt.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
require __DIR__."/_autoload.php";
use Phpcraft\
{Connection, Phpcraft};
$con = new Connection();
if(empty($argv[1]))
{
$con->read_buffer = "";
if(!Phpcraft::isWindows())
{
$fh = fopen("php://stdin", "r");
stream_set_blocking($fh, false);
$con->read_buffer = stream_get_contents($fh);
}
if($con->read_buffer === "")
{
echo "Syntax: php nbt.php <file>\n";
if(!Phpcraft::isWindows())
{
echo "or: echo \"...\" | php nbt.php\n";
}
exit;
}
}
else
{
$con->read_buffer = file_get_contents($argv[1]);
}
try
{
$tag = $con->readNBT();
}
catch(Exception $e)
{
$con->read_buffer = @zlib_decode($con->read_buffer);
if(!$con->read_buffer)
{
die("Invalid NBT: ".$e->getMessage()."\nUncompressing failed.\n");
}
try
{
$tag = $con->readNBT();
}
catch(Exception $e_)
{
die("Invalid NBT.\nNormal reading threw: ".$e->getMessage()."\nUncompressed reading threw: ".$e_->getMessage()."\n");
}
}
if($con->hasRemainingData())
{
$bytes = strlen($con->read_buffer);
echo "Warning: NBT has been read, but {$bytes} byte".($bytes == 1 ? "" : "s")." remain".($bytes == 1 ? "s" : "").": ".bin2hex($con->getRemainingData())."\n";
}
echo "::: String Dump\n";
echo $tag->__toString()."\n";
echo "::: SNBT\n";
echo $tag->toSNBT(false)."\n";
echo "::: Pretty SNBT\n";
echo $tag->toSNBT(true)."\n";