/** * @param $data * @throws \Exception */ protected function readBinary(&$data) { if (strlen($data) < 204) { throw new \Exception("Too few data!"); } $this->data = $data; // ok then, parse the header $header = substr($this->data, 0, 204); $header = array_values(unpack("C*", $header)); $this->memScramble($header); // [0..25]: RedWolf Design GrpFolder assert("RedWolf Design GrpFolder" === Data::parseStr($header, 0, 25)); // [28::31]: int(1) assert(1 === Data::parseInt($header, 28)); // [32::35]: int(2) assert(2 === Data::parseInt($header, 32)); // [36::39]: int(childs) $this->setNumEntries(Data::parseInt($header, 36)); // [40..71]: author $this->setAuthor(Data::parseStr($header, 40, 32)); // [72::103]: reserved // [104::107]: int(created) $this->setCreated(Data::parseInt($header, 104)); // [108::111]: int(original) $this->setOriginal(1234567 === Data::parseInt($header, 108)); // [112::203]: reserved // ok then, parse the file entries for ($i = 0; $i < $this->getNumEntries(); $i++) { $offset = 204 + $i * 316; $data = array_values(unpack("C*", substr($this->data, $offset, 316))); $entry = new C4GroupEntry($data); $dataOffset = 204 + $this->getNumEntries() * 316 + $entry->getDataOffset(); $entry->setData(substr($this->data, $dataOffset, $entry->getFileSize())); $this->addEntry($entry); } $this->data = null; }
/** * @param C4GroupEntry $entry * @return C4Group|C4Scenario|mixed */ public static function getInstance(C4GroupEntry &$entry) { // TODO: implement proper subclasses switch (strtolower(pathinfo($entry->getFilename(), PATHINFO_EXTENSION))) { case "c4s": return C4Scenario::fromBinary($entry->getData()); case "c4f": return C4Group::fromBinary($entry->getData()); case "c4d": return C4Group::fromBinary($entry->getData()); case "c4g": return C4Group::fromBinary($entry->getData()); default: return $entry->getData(); } }