/** * Read a specific lump. Currently only supports entities. * * @param $index * @throws \Exception */ private function readLump($index) { $info = $this->lumpHeader[$index]; $this->buffer->seek($info['fileofs']); if ($index === 0) { $hdr = $this->buffer->peek(4); if ($hdr == 'LZMA') { // Team Fortress 2 // Decompress $buffer = $this->decompressLZMALump($this->buffer); } else { $buffer = $this->buffer->slice($info['filelen']); } $parts = explode("}", $buffer->getData()); $lump = []; foreach ($parts as $data) { $data = trim($data); if (strlen($data) < 1 || $data[0] != '{') { continue; } $lump[] = KeyValues::decode("\"Entity\"\n" . trim($data) . "\n}")['Entity']; } } else { if ($index === 40) { $file = tempnam(sys_get_temp_dir(), 'zip'); $tmp = fopen($file, 'w'); $remaining = $info['filelen']; while ($remaining > 0) { $chunk = $this->buffer->read($remaining > CHUNK_SIZE ? CHUNK_SIZE : $remaining); fwrite($tmp, $chunk); $remaining -= strlen($chunk); } $lump = new PakFile($file); } } return $lump; }