Beispiel #1
0
 /**
  * @param Replay $replay
  * @param BinaryReader $br
  * @param Actor $actor
  * @return ActorProperty
  */
 public static function deserialize($replay, $br, $actor)
 {
     $id = bindec(strrev($br->readBits($actor->getPropertyBits())));
     $class = $actor->properties[$id];
     $property = new self($id, $class);
     return new self();
 }
Beispiel #2
0
 /**
  * @param Replay $replay
  * @param BinaryReader $br
  * @param int $number
  * @return Frame
  */
 public static function deserialize($replay, $br, $number)
 {
     $frame = new self($number);
     $frame->time = $br->readFloat();
     $frame->diff = $br->readFloat();
     while ($br->readBit() == 1) {
         $frame->replications[] = Replication::deserialize($replay, $br, $frame->number);
     }
     print "end\n";
     print $br->readBits(200);
     print "\n";
     return $frame;
 }
Beispiel #3
0
 /**
  * @param Replay $replay
  * @param BinaryReader $br
  * @param int $frameNumber
  * @return Replication
  */
 public static function deserialize($replay, $br, $frameNumber)
 {
     $r = new self();
     $r->actorId = bindec(strrev($br->readBits(10)));
     $r->channelState = $br->readBit();
     if (!$r->channelState) {
         $replay->closeActor($r->actorId, $frameNumber);
         return $r;
     }
     $r->actorState = $br->readBit();
     if ($r->actorState) {
         // New actor
         $r->propertyFlag = $br->readBit();
         // seems to always be 0 since we are creating a new actor
         $r->actorObjectId = bindec(strrev($br->readBits(8)));
         $actor = $replay->createActor($r->actorId, $r->actorObjectId, $frameNumber);
         $actor->deserializeInit($br);
         print "Actor #{$actor->id} {$actor->class} R:{$actor->rotator} P:{$actor->position} O:{$actor->orientation}\n";
     } else {
         // Existing actor
         print "existing actor\n";
         $actor = $replay->getActor($r->actorId);
         while ($br->readBit()) {
             $actor->updateProperty(ActorProperty::deserialize($replay, $br, $actor));
         }
     }
     return $r;
 }
Beispiel #4
0
 /**
  * @param BinaryReader $br
  * @return Vector
  */
 public static function deserializeOrientation($br)
 {
     $p = 0;
     $y = 0;
     $r = 0;
     if ($br->readBit()) {
         $p = bindec(strrev($br->readBits(8)));
     }
     if ($br->readBit()) {
         $y = bindec(strrev($br->readBits(8)));
     }
     if ($br->readBit()) {
         $r = bindec(strrev($br->readBits(8)));
     }
     return new self($p, $y, $r);
 }
 public function testReaders()
 {
     $dataBig = fopen(__DIR__ . '/asset/testfile-big.bin', 'rb');
     $brBig = new BinaryReader($dataBig, Endian::ENDIAN_BIG);
     $this->assertInstanceOf('\\PhpBinaryReader\\Type\\Bit', $brBig->getBitReader());
     $this->assertInstanceOf('\\PhpBinaryReader\\Type\\Byte', $brBig->getByteReader());
     $this->assertInstanceOf('\\PhpBinaryReader\\Type\\Int16', $brBig->getInt16Reader());
     $this->assertInstanceOf('\\PhpBinaryReader\\Type\\Int32', $brBig->getInt32Reader());
     $this->assertInstanceOf('\\PhpBinaryReader\\Type\\Int8', $brBig->getInt8Reader());
     $this->assertInstanceOf('\\PhpBinaryReader\\Type\\String', $brBig->getStringReader());
 }
Beispiel #6
0
 /**
  * @param resource $handle
  * @param int $length
  * @return int
  */
 public static function readInt($handle, $length = 4)
 {
     $formats = [1 => 'C', 2 => 'v', 4 => 'V', 8 => 'H*'];
     if (!array_key_exists($length, $formats)) {
         throw new \Exception('No int format found for length: ' . $length);
     }
     $format = $formats[$length];
     $value = unpack($format, fread($handle, $length))[1];
     if ($format == 'H*') {
         return bindec(strrev(BinaryReader::asBits($value)));
     }
     return $value;
 }