Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions nbt.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class NBT {
const TAG_STRING = 8;
const TAG_LIST = 9;
const TAG_COMPOUND = 10;
const TAG_INT_ARRAY = 11;
const TAG_LONG_ARRAY = 12;

public function loadFile($filename, $wrapper = "compress.zlib://") {
if(is_string($wrapper) && is_file($filename)) {
Expand Down Expand Up @@ -148,6 +150,16 @@ public function readType($fp, $tagType) {
$tree = array();
while($this->traverseTag($fp, $tree));
return $tree;
case self::TAG_INT_ARRAY: // Int array
$arrayLength = $this->readType($fp, self::TAG_INT);
$array = array();
for($i = 0; $i < $arrayLength; $i++) $array[] = $this->readType($fp, self::TAG_INT);
return $array;
case self::TAG_LONG_ARRAY: // Long array
$arrayLength = $this->readType($fp, self::TAG_INT);
$array = array();
for($i = 0; $i < $arrayLength; $i++) $array[] = $this->readType($fp, self::TAG_LONG);
return $array;
}
}

Expand Down Expand Up @@ -187,6 +199,15 @@ public function writeType($fp, $tagType, $value) {
foreach($value as $listItem) if(!$this->writeTag($fp, $listItem)) return false;
if(!is_int(fwrite($fp, "\0"))) return false;
return true;
case self::TAG_INT_ARRAY: // Int array
return $this->writeType($fp, self::TAG_INT, count($value)) && is_int(fwrite($fp, call_user_func_array("pack", array_merge(array("N".count($value)), $value))));
case self::TAG_LONG_ARRAY: // Long array
$this->writeType($fp, self::TAG_INT, count($value));
foreach($value as $v) {
if(!$this->writeType($fp, self::TAG_LONG, $v))
return false;
}
return true;
}
}
}
Expand Down