diff --git a/nbt.class.php b/nbt.class.php index 4b1d680..9a904d4 100644 --- a/nbt.class.php +++ b/nbt.class.php @@ -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)) { @@ -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; } } @@ -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; } } }