From 5c2ae0257c33076ad9dde94f6c2c1d4d1ffb0af9 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 25 Feb 2020 16:19:11 +0000 Subject: [PATCH] DataPacket: inject buffer via parameter instead of class field (packet & stream separation, step 2) this is not complete yet, but the final change (having the binarystream actually come from outside) is a little more disruptive, and some extra changes need to be made. This will grant some sanity in the meantime without breaking too much stuff. --- .../mcpe/protocol/ActorEventPacket.php | 17 +- src/network/mcpe/protocol/ActorFallPacket.php | 17 +- .../mcpe/protocol/ActorPickRequestPacket.php | 13 +- src/network/mcpe/protocol/AddActorPacket.php | 69 +++--- .../mcpe/protocol/AddBehaviorTreePacket.php | 9 +- src/network/mcpe/protocol/AddEntityPacket.php | 9 +- .../mcpe/protocol/AddItemActorPacket.php | 33 +-- .../mcpe/protocol/AddPaintingPacket.php | 25 ++- src/network/mcpe/protocol/AddPlayerPacket.php | 93 ++++---- .../mcpe/protocol/AdventureSettingsPacket.php | 29 +-- src/network/mcpe/protocol/AnimatePacket.php | 17 +- .../mcpe/protocol/AnvilDamagePacket.php | 13 +- .../AutomationClientConnectPacket.php | 9 +- .../AvailableActorIdentifiersPacket.php | 9 +- .../mcpe/protocol/AvailableCommandsPacket.php | 171 +++++++------- .../protocol/BiomeDefinitionListPacket.php | 9 +- .../mcpe/protocol/BlockActorDataPacket.php | 13 +- .../mcpe/protocol/BlockEventPacket.php | 17 +- .../mcpe/protocol/BlockPickRequestPacket.php | 17 +- src/network/mcpe/protocol/BookEditPacket.php | 49 +++-- src/network/mcpe/protocol/BossEventPacket.php | 45 ++-- src/network/mcpe/protocol/CameraPacket.php | 13 +- .../mcpe/protocol/ChangeDimensionPacket.php | 17 +- .../protocol/ChunkRadiusUpdatedPacket.php | 9 +- .../protocol/ClientCacheBlobStatusPacket.php | 21 +- .../ClientCacheMissResponsePacket.php | 17 +- .../mcpe/protocol/ClientCacheStatusPacket.php | 9 +- .../ClientToServerHandshakePacket.php | 5 +- .../protocol/ClientboundMapItemDataPacket.php | 101 ++++----- .../protocol/CommandBlockUpdatePacket.php | 53 ++--- .../mcpe/protocol/CommandOutputPacket.php | 49 +++-- .../mcpe/protocol/CommandRequestPacket.php | 17 +- .../protocol/CompletedUsingItemPacket.php | 13 +- .../mcpe/protocol/ContainerClosePacket.php | 9 +- .../mcpe/protocol/ContainerOpenPacket.php | 21 +- .../mcpe/protocol/ContainerSetDataPacket.php | 17 +- .../mcpe/protocol/CraftingDataPacket.php | 96 ++++---- .../mcpe/protocol/CraftingEventPacket.php | 33 +-- src/network/mcpe/protocol/DataPacket.php | 22 +- .../mcpe/protocol/DisconnectPacket.php | 13 +- .../mcpe/protocol/EducationSettingsPacket.php | 13 +- src/network/mcpe/protocol/EmotePacket.php | 17 +- src/network/mcpe/protocol/EventPacket.php | 17 +- .../mcpe/protocol/GameRulesChangedPacket.php | 9 +- .../mcpe/protocol/GuiDataPickItemPacket.php | 17 +- src/network/mcpe/protocol/HurtArmorPacket.php | 9 +- src/network/mcpe/protocol/InteractPacket.php | 25 ++- .../mcpe/protocol/InventoryContentPacket.php | 17 +- .../mcpe/protocol/InventorySlotPacket.php | 17 +- .../protocol/InventoryTransactionPacket.php | 13 +- .../mcpe/protocol/ItemFrameDropItemPacket.php | 9 +- src/network/mcpe/protocol/LabTablePacket.php | 17 +- .../mcpe/protocol/LecternUpdatePacket.php | 21 +- .../mcpe/protocol/LevelChunkPacket.php | 33 +-- .../mcpe/protocol/LevelEventGenericPacket.php | 13 +- .../mcpe/protocol/LevelEventPacket.php | 17 +- .../mcpe/protocol/LevelSoundEventPacket.php | 29 +-- .../mcpe/protocol/LevelSoundEventPacketV1.php | 29 +-- .../mcpe/protocol/LevelSoundEventPacketV2.php | 29 +-- src/network/mcpe/protocol/LoginPacket.php | 13 +- .../protocol/MapCreateLockedCopyPacket.php | 13 +- .../mcpe/protocol/MapInfoRequestPacket.php | 9 +- .../mcpe/protocol/MobArmorEquipmentPacket.php | 25 ++- src/network/mcpe/protocol/MobEffectPacket.php | 29 +-- .../mcpe/protocol/MobEquipmentPacket.php | 25 ++- .../mcpe/protocol/ModalFormRequestPacket.php | 13 +- .../mcpe/protocol/ModalFormResponsePacket.php | 13 +- .../mcpe/protocol/MoveActorAbsolutePacket.php | 29 +-- .../mcpe/protocol/MoveActorDeltaPacket.php | 53 ++--- .../mcpe/protocol/MovePlayerPacket.php | 45 ++-- .../protocol/MultiplayerSettingsPacket.php | 9 +- .../NetworkChunkPublisherUpdatePacket.php | 13 +- .../mcpe/protocol/NetworkSettingsPacket.php | 9 +- .../protocol/NetworkStackLatencyPacket.php | 13 +- .../mcpe/protocol/NpcRequestPacket.php | 21 +- .../OnScreenTextureAnimationPacket.php | 9 +- .../mcpe/protocol/PhotoTransferPacket.php | 17 +- src/network/mcpe/protocol/PlaySoundPacket.php | 21 +- .../mcpe/protocol/PlayStatusPacket.php | 9 +- .../mcpe/protocol/PlayerActionPacket.php | 21 +- .../mcpe/protocol/PlayerAuthInputPacket.php | 45 ++-- .../mcpe/protocol/PlayerHotbarPacket.php | 17 +- .../mcpe/protocol/PlayerInputPacket.php | 21 +- .../mcpe/protocol/PlayerListPacket.php | 53 ++--- .../mcpe/protocol/PlayerSkinPacket.php | 21 +- .../mcpe/protocol/PurchaseReceiptPacket.php | 13 +- .../mcpe/protocol/RemoveActorPacket.php | 9 +- .../mcpe/protocol/RemoveEntityPacket.php | 9 +- .../mcpe/protocol/RemoveObjectivePacket.php | 9 +- .../protocol/RequestChunkRadiusPacket.php | 9 +- .../protocol/ResourcePackChunkDataPacket.php | 21 +- .../ResourcePackChunkRequestPacket.php | 13 +- .../ResourcePackClientResponsePacket.php | 17 +- .../protocol/ResourcePackDataInfoPacket.php | 33 +-- .../mcpe/protocol/ResourcePackStackPacket.php | 33 +-- .../mcpe/protocol/ResourcePacksInfoPacket.php | 29 +-- src/network/mcpe/protocol/RespawnPacket.php | 17 +- src/network/mcpe/protocol/RiderJumpPacket.php | 9 +- .../mcpe/protocol/ScriptCustomEventPacket.php | 13 +- .../protocol/ServerSettingsRequestPacket.php | 5 +- .../protocol/ServerSettingsResponsePacket.php | 13 +- .../ServerToClientHandshakePacket.php | 9 +- .../mcpe/protocol/SetActorDataPacket.php | 13 +- .../mcpe/protocol/SetActorLinkPacket.php | 9 +- .../mcpe/protocol/SetActorMotionPacket.php | 13 +- .../protocol/SetCommandsEnabledPacket.php | 9 +- .../protocol/SetDefaultGameTypePacket.php | 9 +- .../mcpe/protocol/SetDifficultyPacket.php | 9 +- .../protocol/SetDisplayObjectivePacket.php | 25 ++- src/network/mcpe/protocol/SetHealthPacket.php | 9 +- .../mcpe/protocol/SetLastHurtByPacket.php | 9 +- .../SetLocalPlayerAsInitializedPacket.php | 9 +- .../mcpe/protocol/SetPlayerGameTypePacket.php | 9 +- src/network/mcpe/protocol/SetScorePacket.php | 37 ++-- .../protocol/SetScoreboardIdentityPacket.php | 21 +- .../mcpe/protocol/SetSpawnPositionPacket.php | 17 +- src/network/mcpe/protocol/SetTimePacket.php | 9 +- src/network/mcpe/protocol/SetTitlePacket.php | 25 ++- .../mcpe/protocol/SettingsCommandPacket.php | 13 +- .../mcpe/protocol/ShowCreditsPacket.php | 13 +- .../mcpe/protocol/ShowProfilePacket.php | 9 +- .../mcpe/protocol/ShowStoreOfferPacket.php | 13 +- .../mcpe/protocol/SimpleEventPacket.php | 9 +- .../protocol/SpawnExperienceOrbPacket.php | 13 +- .../protocol/SpawnParticleEffectPacket.php | 21 +- src/network/mcpe/protocol/StartGamePacket.php | 208 +++++++++--------- src/network/mcpe/protocol/StopSoundPacket.php | 13 +- .../protocol/StructureBlockUpdatePacket.php | 5 +- .../StructureTemplateDataRequestPacket.php | 21 +- .../StructureTemplateDataResponsePacket.php | 17 +- .../mcpe/protocol/SubClientLoginPacket.php | 9 +- .../mcpe/protocol/TakeItemActorPacket.php | 13 +- src/network/mcpe/protocol/TextPacket.php | 41 ++-- src/network/mcpe/protocol/TickSyncPacket.php | 13 +- src/network/mcpe/protocol/TransferPacket.php | 13 +- src/network/mcpe/protocol/UnknownPacket.php | 13 +- .../mcpe/protocol/UpdateAttributesPacket.php | 13 +- .../mcpe/protocol/UpdateBlockPacket.php | 21 +- .../protocol/UpdateBlockPropertiesPacket.php | 9 +- .../mcpe/protocol/UpdateBlockSyncedPacket.php | 17 +- .../mcpe/protocol/UpdateEquipPacket.php | 25 ++- .../mcpe/protocol/UpdateSoftEnumPacket.php | 21 +- .../mcpe/protocol/UpdateTradePacket.php | 45 ++-- .../protocol/VideoStreamConnectPacket.php | 25 ++- .../network/mcpe/protocol/TestPacket.php | 5 +- 145 files changed, 1704 insertions(+), 1562 deletions(-) diff --git a/src/network/mcpe/protocol/ActorEventPacket.php b/src/network/mcpe/protocol/ActorEventPacket.php index 438f7ce83..292a0fcbf 100644 --- a/src/network/mcpe/protocol/ActorEventPacket.php +++ b/src/network/mcpe/protocol/ActorEventPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ActorEventPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::ACTOR_EVENT_PACKET; @@ -97,16 +98,16 @@ class ActorEventPacket extends DataPacket implements ClientboundPacket, Serverbo return $result; } - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->event = $this->buf->getByte(); - $this->data = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->event = $in->getByte(); + $this->data = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putByte($this->event); - $this->buf->putVarInt($this->data); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putByte($this->event); + $out->putVarInt($this->data); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ActorFallPacket.php b/src/network/mcpe/protocol/ActorFallPacket.php index 10fd48cc9..deb072006 100644 --- a/src/network/mcpe/protocol/ActorFallPacket.php +++ b/src/network/mcpe/protocol/ActorFallPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ActorFallPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::ACTOR_FALL_PACKET; @@ -37,16 +38,16 @@ class ActorFallPacket extends DataPacket implements ServerboundPacket{ /** @var bool */ public $isInVoid; - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->fallDistance = $this->buf->getLFloat(); - $this->isInVoid = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->fallDistance = $in->getLFloat(); + $this->isInVoid = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putLFloat($this->fallDistance); - $this->buf->putBool($this->isInVoid); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putLFloat($this->fallDistance); + $out->putBool($this->isInVoid); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ActorPickRequestPacket.php b/src/network/mcpe/protocol/ActorPickRequestPacket.php index b307e7d51..e87bf1061 100644 --- a/src/network/mcpe/protocol/ActorPickRequestPacket.php +++ b/src/network/mcpe/protocol/ActorPickRequestPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ActorPickRequestPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::ACTOR_PICK_REQUEST_PACKET; @@ -35,14 +36,14 @@ class ActorPickRequestPacket extends DataPacket implements ServerboundPacket{ /** @var int */ public $hotbarSlot; - protected function decodePayload() : void{ - $this->entityUniqueId = $this->buf->getLLong(); - $this->hotbarSlot = $this->buf->getByte(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityUniqueId = $in->getLLong(); + $this->hotbarSlot = $in->getByte(); } - protected function encodePayload() : void{ - $this->buf->putLLong($this->entityUniqueId); - $this->buf->putByte($this->hotbarSlot); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putLLong($this->entityUniqueId); + $out->putByte($this->hotbarSlot); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/AddActorPacket.php b/src/network/mcpe/protocol/AddActorPacket.php index 60e802af7..fb4e8b189 100644 --- a/src/network/mcpe/protocol/AddActorPacket.php +++ b/src/network/mcpe/protocol/AddActorPacket.php @@ -32,6 +32,7 @@ use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; use pocketmine\network\mcpe\protocol\types\entity\EntityLink; use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function array_search; use function count; @@ -173,25 +174,25 @@ class AddActorPacket extends DataPacket implements ClientboundPacket{ /** @var EntityLink[] */ public $links = []; - protected function decodePayload() : void{ - $this->entityUniqueId = $this->buf->getEntityUniqueId(); - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->type = array_search($t = $this->buf->getString(), self::LEGACY_ID_MAP_BC, true); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityUniqueId = $in->getEntityUniqueId(); + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->type = array_search($t = $in->getString(), self::LEGACY_ID_MAP_BC, true); if($this->type === false){ throw new BadPacketException("Can't map ID $t to legacy ID"); } - $this->position = $this->buf->getVector3(); - $this->motion = $this->buf->getVector3(); - $this->pitch = $this->buf->getLFloat(); - $this->yaw = $this->buf->getLFloat(); - $this->headYaw = $this->buf->getLFloat(); + $this->position = $in->getVector3(); + $this->motion = $in->getVector3(); + $this->pitch = $in->getLFloat(); + $this->yaw = $in->getLFloat(); + $this->headYaw = $in->getLFloat(); - $attrCount = $this->buf->getUnsignedVarInt(); + $attrCount = $in->getUnsignedVarInt(); for($i = 0; $i < $attrCount; ++$i){ - $id = $this->buf->getString(); - $min = $this->buf->getLFloat(); - $current = $this->buf->getLFloat(); - $max = $this->buf->getLFloat(); + $id = $in->getString(); + $min = $in->getLFloat(); + $current = $in->getLFloat(); + $max = $in->getLFloat(); $attr = Attribute::get($id); if($attr !== null){ @@ -208,38 +209,38 @@ class AddActorPacket extends DataPacket implements ClientboundPacket{ } } - $this->metadata = $this->buf->getEntityMetadata(); - $linkCount = $this->buf->getUnsignedVarInt(); + $this->metadata = $in->getEntityMetadata(); + $linkCount = $in->getUnsignedVarInt(); for($i = 0; $i < $linkCount; ++$i){ - $this->links[] = $this->buf->getEntityLink(); + $this->links[] = $in->getEntityLink(); } } - protected function encodePayload() : void{ - $this->buf->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); - $this->buf->putEntityRuntimeId($this->entityRuntimeId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); + $out->putEntityRuntimeId($this->entityRuntimeId); if(!isset(self::LEGACY_ID_MAP_BC[$this->type])){ throw new \InvalidArgumentException("Unknown entity numeric ID $this->type"); } - $this->buf->putString(self::LEGACY_ID_MAP_BC[$this->type]); - $this->buf->putVector3($this->position); - $this->buf->putVector3Nullable($this->motion); - $this->buf->putLFloat($this->pitch); - $this->buf->putLFloat($this->yaw); - $this->buf->putLFloat($this->headYaw); + $out->putString(self::LEGACY_ID_MAP_BC[$this->type]); + $out->putVector3($this->position); + $out->putVector3Nullable($this->motion); + $out->putLFloat($this->pitch); + $out->putLFloat($this->yaw); + $out->putLFloat($this->headYaw); - $this->buf->putUnsignedVarInt(count($this->attributes)); + $out->putUnsignedVarInt(count($this->attributes)); foreach($this->attributes as $attribute){ - $this->buf->putString($attribute->getId()); - $this->buf->putLFloat($attribute->getMinValue()); - $this->buf->putLFloat($attribute->getValue()); - $this->buf->putLFloat($attribute->getMaxValue()); + $out->putString($attribute->getId()); + $out->putLFloat($attribute->getMinValue()); + $out->putLFloat($attribute->getValue()); + $out->putLFloat($attribute->getMaxValue()); } - $this->buf->putEntityMetadata($this->metadata); - $this->buf->putUnsignedVarInt(count($this->links)); + $out->putEntityMetadata($this->metadata); + $out->putUnsignedVarInt(count($this->links)); foreach($this->links as $link){ - $this->buf->putEntityLink($link); + $out->putEntityLink($link); } } diff --git a/src/network/mcpe/protocol/AddBehaviorTreePacket.php b/src/network/mcpe/protocol/AddBehaviorTreePacket.php index 57bb64c4f..5fb1eefcc 100644 --- a/src/network/mcpe/protocol/AddBehaviorTreePacket.php +++ b/src/network/mcpe/protocol/AddBehaviorTreePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class AddBehaviorTreePacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::ADD_BEHAVIOR_TREE_PACKET; @@ -33,12 +34,12 @@ class AddBehaviorTreePacket extends DataPacket implements ClientboundPacket{ /** @var string */ public $behaviorTreeJson; - protected function decodePayload() : void{ - $this->behaviorTreeJson = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->behaviorTreeJson = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putString($this->behaviorTreeJson); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->behaviorTreeJson); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/AddEntityPacket.php b/src/network/mcpe/protocol/AddEntityPacket.php index 7e03e96a2..380747fe4 100644 --- a/src/network/mcpe/protocol/AddEntityPacket.php +++ b/src/network/mcpe/protocol/AddEntityPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class AddEntityPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::ADD_ENTITY_PACKET; @@ -43,12 +44,12 @@ class AddEntityPacket extends DataPacket implements ClientboundPacket{ return $this->uvarint1; } - protected function decodePayload() : void{ - $this->uvarint1 = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->uvarint1 = $in->getUnsignedVarInt(); } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt($this->uvarint1); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt($this->uvarint1); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/AddItemActorPacket.php b/src/network/mcpe/protocol/AddItemActorPacket.php index 9f841ea2c..71ceab391 100644 --- a/src/network/mcpe/protocol/AddItemActorPacket.php +++ b/src/network/mcpe/protocol/AddItemActorPacket.php @@ -29,6 +29,7 @@ use pocketmine\item\Item; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class AddItemActorPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::ADD_ITEM_ACTOR_PACKET; @@ -51,24 +52,24 @@ class AddItemActorPacket extends DataPacket implements ClientboundPacket{ /** @var bool */ public $isFromFishing = false; - protected function decodePayload() : void{ - $this->entityUniqueId = $this->buf->getEntityUniqueId(); - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->item = $this->buf->getSlot(); - $this->position = $this->buf->getVector3(); - $this->motion = $this->buf->getVector3(); - $this->metadata = $this->buf->getEntityMetadata(); - $this->isFromFishing = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityUniqueId = $in->getEntityUniqueId(); + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->item = $in->getSlot(); + $this->position = $in->getVector3(); + $this->motion = $in->getVector3(); + $this->metadata = $in->getEntityMetadata(); + $this->isFromFishing = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putSlot($this->item); - $this->buf->putVector3($this->position); - $this->buf->putVector3Nullable($this->motion); - $this->buf->putEntityMetadata($this->metadata); - $this->buf->putBool($this->isFromFishing); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putSlot($this->item); + $out->putVector3($this->position); + $out->putVector3Nullable($this->motion); + $out->putEntityMetadata($this->metadata); + $out->putBool($this->isFromFishing); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/AddPaintingPacket.php b/src/network/mcpe/protocol/AddPaintingPacket.php index a4db84d68..80f827111 100644 --- a/src/network/mcpe/protocol/AddPaintingPacket.php +++ b/src/network/mcpe/protocol/AddPaintingPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class AddPaintingPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::ADD_PAINTING_PACKET; @@ -42,20 +43,20 @@ class AddPaintingPacket extends DataPacket implements ClientboundPacket{ /** @var string */ public $title; - protected function decodePayload() : void{ - $this->entityUniqueId = $this->buf->getEntityUniqueId(); - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->position = $this->buf->getVector3(); - $this->direction = $this->buf->getVarInt(); - $this->title = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityUniqueId = $in->getEntityUniqueId(); + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->position = $in->getVector3(); + $this->direction = $in->getVarInt(); + $this->title = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putVector3($this->position); - $this->buf->putVarInt($this->direction); - $this->buf->putString($this->title); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putVector3($this->position); + $out->putVarInt($this->direction); + $out->putString($this->title); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/AddPlayerPacket.php b/src/network/mcpe/protocol/AddPlayerPacket.php index beb6fa595..453b10dbe 100644 --- a/src/network/mcpe/protocol/AddPlayerPacket.php +++ b/src/network/mcpe/protocol/AddPlayerPacket.php @@ -30,6 +30,7 @@ use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\entity\EntityLink; use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use pocketmine\utils\UUID; use function count; @@ -87,66 +88,66 @@ class AddPlayerPacket extends DataPacket implements ClientboundPacket{ /** @var int */ public $buildPlatform = -1; - protected function decodePayload() : void{ - $this->uuid = $this->buf->getUUID(); - $this->username = $this->buf->getString(); - $this->entityUniqueId = $this->buf->getEntityUniqueId(); - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->platformChatId = $this->buf->getString(); - $this->position = $this->buf->getVector3(); - $this->motion = $this->buf->getVector3(); - $this->pitch = $this->buf->getLFloat(); - $this->yaw = $this->buf->getLFloat(); - $this->headYaw = $this->buf->getLFloat(); - $this->item = $this->buf->getSlot(); - $this->metadata = $this->buf->getEntityMetadata(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->uuid = $in->getUUID(); + $this->username = $in->getString(); + $this->entityUniqueId = $in->getEntityUniqueId(); + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->platformChatId = $in->getString(); + $this->position = $in->getVector3(); + $this->motion = $in->getVector3(); + $this->pitch = $in->getLFloat(); + $this->yaw = $in->getLFloat(); + $this->headYaw = $in->getLFloat(); + $this->item = $in->getSlot(); + $this->metadata = $in->getEntityMetadata(); - $this->uvarint1 = $this->buf->getUnsignedVarInt(); - $this->uvarint2 = $this->buf->getUnsignedVarInt(); - $this->uvarint3 = $this->buf->getUnsignedVarInt(); - $this->uvarint4 = $this->buf->getUnsignedVarInt(); - $this->uvarint5 = $this->buf->getUnsignedVarInt(); + $this->uvarint1 = $in->getUnsignedVarInt(); + $this->uvarint2 = $in->getUnsignedVarInt(); + $this->uvarint3 = $in->getUnsignedVarInt(); + $this->uvarint4 = $in->getUnsignedVarInt(); + $this->uvarint5 = $in->getUnsignedVarInt(); - $this->long1 = $this->buf->getLLong(); + $this->long1 = $in->getLLong(); - $linkCount = $this->buf->getUnsignedVarInt(); + $linkCount = $in->getUnsignedVarInt(); for($i = 0; $i < $linkCount; ++$i){ - $this->links[$i] = $this->buf->getEntityLink(); + $this->links[$i] = $in->getEntityLink(); } - $this->deviceId = $this->buf->getString(); - $this->buildPlatform = $this->buf->getLInt(); + $this->deviceId = $in->getString(); + $this->buildPlatform = $in->getLInt(); } - protected function encodePayload() : void{ - $this->buf->putUUID($this->uuid); - $this->buf->putString($this->username); - $this->buf->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putString($this->platformChatId); - $this->buf->putVector3($this->position); - $this->buf->putVector3Nullable($this->motion); - $this->buf->putLFloat($this->pitch); - $this->buf->putLFloat($this->yaw); - $this->buf->putLFloat($this->headYaw ?? $this->yaw); - $this->buf->putSlot($this->item); - $this->buf->putEntityMetadata($this->metadata); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUUID($this->uuid); + $out->putString($this->username); + $out->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putString($this->platformChatId); + $out->putVector3($this->position); + $out->putVector3Nullable($this->motion); + $out->putLFloat($this->pitch); + $out->putLFloat($this->yaw); + $out->putLFloat($this->headYaw ?? $this->yaw); + $out->putSlot($this->item); + $out->putEntityMetadata($this->metadata); - $this->buf->putUnsignedVarInt($this->uvarint1); - $this->buf->putUnsignedVarInt($this->uvarint2); - $this->buf->putUnsignedVarInt($this->uvarint3); - $this->buf->putUnsignedVarInt($this->uvarint4); - $this->buf->putUnsignedVarInt($this->uvarint5); + $out->putUnsignedVarInt($this->uvarint1); + $out->putUnsignedVarInt($this->uvarint2); + $out->putUnsignedVarInt($this->uvarint3); + $out->putUnsignedVarInt($this->uvarint4); + $out->putUnsignedVarInt($this->uvarint5); - $this->buf->putLLong($this->long1); + $out->putLLong($this->long1); - $this->buf->putUnsignedVarInt(count($this->links)); + $out->putUnsignedVarInt(count($this->links)); foreach($this->links as $link){ - $this->buf->putEntityLink($link); + $out->putEntityLink($link); } - $this->buf->putString($this->deviceId); - $this->buf->putLInt($this->buildPlatform); + $out->putString($this->deviceId); + $out->putLInt($this->buildPlatform); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/AdventureSettingsPacket.php b/src/network/mcpe/protocol/AdventureSettingsPacket.php index a81782af2..4075d65a0 100644 --- a/src/network/mcpe/protocol/AdventureSettingsPacket.php +++ b/src/network/mcpe/protocol/AdventureSettingsPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\PlayerPermissions; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class AdventureSettingsPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::ADVENTURE_SETTINGS_PACKET; @@ -75,22 +76,22 @@ class AdventureSettingsPacket extends DataPacket implements ClientboundPacket, S /** @var int */ public $entityUniqueId; //This is a little-endian long, NOT a var-long. (WTF Mojang) - protected function decodePayload() : void{ - $this->flags = $this->buf->getUnsignedVarInt(); - $this->commandPermission = $this->buf->getUnsignedVarInt(); - $this->flags2 = $this->buf->getUnsignedVarInt(); - $this->playerPermission = $this->buf->getUnsignedVarInt(); - $this->customFlags = $this->buf->getUnsignedVarInt(); - $this->entityUniqueId = $this->buf->getLLong(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->flags = $in->getUnsignedVarInt(); + $this->commandPermission = $in->getUnsignedVarInt(); + $this->flags2 = $in->getUnsignedVarInt(); + $this->playerPermission = $in->getUnsignedVarInt(); + $this->customFlags = $in->getUnsignedVarInt(); + $this->entityUniqueId = $in->getLLong(); } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt($this->flags); - $this->buf->putUnsignedVarInt($this->commandPermission); - $this->buf->putUnsignedVarInt($this->flags2); - $this->buf->putUnsignedVarInt($this->playerPermission); - $this->buf->putUnsignedVarInt($this->customFlags); - $this->buf->putLLong($this->entityUniqueId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt($this->flags); + $out->putUnsignedVarInt($this->commandPermission); + $out->putUnsignedVarInt($this->flags2); + $out->putUnsignedVarInt($this->playerPermission); + $out->putUnsignedVarInt($this->customFlags); + $out->putLLong($this->entityUniqueId); } public function getFlag(int $flag) : bool{ diff --git a/src/network/mcpe/protocol/AnimatePacket.php b/src/network/mcpe/protocol/AnimatePacket.php index 003d7d5e4..58a910a80 100644 --- a/src/network/mcpe/protocol/AnimatePacket.php +++ b/src/network/mcpe/protocol/AnimatePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class AnimatePacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::ANIMATE_PACKET; @@ -57,19 +58,19 @@ class AnimatePacket extends DataPacket implements ClientboundPacket, Serverbound return $result; } - protected function decodePayload() : void{ - $this->action = $this->buf->getVarInt(); - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->action = $in->getVarInt(); + $this->entityRuntimeId = $in->getEntityRuntimeId(); if(($this->action & 0x80) !== 0){ - $this->float = $this->buf->getLFloat(); + $this->float = $in->getLFloat(); } } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->action); - $this->buf->putEntityRuntimeId($this->entityRuntimeId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->action); + $out->putEntityRuntimeId($this->entityRuntimeId); if(($this->action & 0x80) !== 0){ - $this->buf->putLFloat($this->float); + $out->putLFloat($this->float); } } diff --git a/src/network/mcpe/protocol/AnvilDamagePacket.php b/src/network/mcpe/protocol/AnvilDamagePacket.php index a0f1d1e20..495779b45 100644 --- a/src/network/mcpe/protocol/AnvilDamagePacket.php +++ b/src/network/mcpe/protocol/AnvilDamagePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class AnvilDamagePacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::ANVIL_DAMAGE_PACKET; @@ -62,14 +63,14 @@ class AnvilDamagePacket extends DataPacket implements ServerboundPacket{ return $this->z; } - protected function decodePayload() : void{ - $this->damageAmount = $this->buf->getByte(); - $this->buf->getBlockPosition($this->x, $this->y, $this->z); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->damageAmount = $in->getByte(); + $in->getBlockPosition($this->x, $this->y, $this->z); } - protected function encodePayload() : void{ - $this->buf->putByte($this->damageAmount); - $this->buf->putBlockPosition($this->x, $this->y, $this->z); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->damageAmount); + $out->putBlockPosition($this->x, $this->y, $this->z); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/AutomationClientConnectPacket.php b/src/network/mcpe/protocol/AutomationClientConnectPacket.php index 98e9740b6..b01f237ab 100644 --- a/src/network/mcpe/protocol/AutomationClientConnectPacket.php +++ b/src/network/mcpe/protocol/AutomationClientConnectPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class AutomationClientConnectPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::AUTOMATION_CLIENT_CONNECT_PACKET; @@ -33,12 +34,12 @@ class AutomationClientConnectPacket extends DataPacket implements ClientboundPac /** @var string */ public $serverUri; - protected function decodePayload() : void{ - $this->serverUri = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->serverUri = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putString($this->serverUri); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->serverUri); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/AvailableActorIdentifiersPacket.php b/src/network/mcpe/protocol/AvailableActorIdentifiersPacket.php index 53bb70539..b583a85f7 100644 --- a/src/network/mcpe/protocol/AvailableActorIdentifiersPacket.php +++ b/src/network/mcpe/protocol/AvailableActorIdentifiersPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function base64_decode; use function file_get_contents; @@ -38,12 +39,12 @@ class AvailableActorIdentifiersPacket extends DataPacket implements ClientboundP /** @var string */ public $namedtag; - protected function decodePayload() : void{ - $this->namedtag = $this->buf->getRemaining(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->namedtag = $in->getRemaining(); } - protected function encodePayload() : void{ - $this->buf->put( + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->put( $this->namedtag ?? self::$DEFAULT_NBT_CACHE ?? (self::$DEFAULT_NBT_CACHE = file_get_contents(\pocketmine\RESOURCE_PATH . '/vanilla/entity_identifiers.nbt')) diff --git a/src/network/mcpe/protocol/AvailableCommandsPacket.php b/src/network/mcpe/protocol/AvailableCommandsPacket.php index 4ed1ae8f3..d98ee2e01 100644 --- a/src/network/mcpe/protocol/AvailableCommandsPacket.php +++ b/src/network/mcpe/protocol/AvailableCommandsPacket.php @@ -31,6 +31,7 @@ use pocketmine\network\mcpe\protocol\types\command\CommandData; use pocketmine\network\mcpe\protocol\types\command\CommandEnum; use pocketmine\network\mcpe\protocol\types\command\CommandEnumConstraint; use pocketmine\network\mcpe\protocol\types\command\CommandParameter; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use pocketmine\utils\BinaryDataException; use function array_search; use function count; @@ -111,38 +112,38 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ */ public $enumConstraints = []; - protected function decodePayload() : void{ + protected function decodePayload(NetworkBinaryStream $in) : void{ /** @var string[] $enumValues */ $enumValues = []; - for($i = 0, $enumValuesCount = $this->buf->getUnsignedVarInt(); $i < $enumValuesCount; ++$i){ - $enumValues[] = $this->buf->getString(); + for($i = 0, $enumValuesCount = $in->getUnsignedVarInt(); $i < $enumValuesCount; ++$i){ + $enumValues[] = $in->getString(); } /** @var string[] $postfixes */ $postfixes = []; - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $postfixes[] = $this->buf->getString(); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $postfixes[] = $in->getString(); } /** @var CommandEnum[] $enums */ $enums = []; - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $enums[] = $enum = $this->getEnum($enumValues); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $enums[] = $enum = $this->getEnum($enumValues, $in); if(isset(self::HARDCODED_ENUM_NAMES[$enum->getName()])){ $this->hardcodedEnums[] = $enum; } } - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $this->commandData[] = $this->getCommandData($enums, $postfixes); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $this->commandData[] = $this->getCommandData($enums, $postfixes, $in); } - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $this->softEnums[] = $this->getSoftEnum(); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $this->softEnums[] = $this->getSoftEnum($in); } - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $this->enumConstraints[] = $this->getEnumConstraint($enums, $enumValues); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $this->enumConstraints[] = $this->getEnumConstraint($enums, $enumValues, $in); } } @@ -152,14 +153,14 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ * @throws BadPacketException * @throws BinaryDataException */ - protected function getEnum(array $enumValueList) : CommandEnum{ - $enumName = $this->buf->getString(); + protected function getEnum(array $enumValueList, NetworkBinaryStream $in) : CommandEnum{ + $enumName = $in->getString(); $enumValues = []; $listSize = count($enumValueList); - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $index = $this->getEnumValueIndex($listSize); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $index = $this->getEnumValueIndex($listSize, $in); if(!isset($enumValueList[$index])){ throw new BadPacketException("Invalid enum value index $index"); } @@ -173,13 +174,13 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ /** * @throws BinaryDataException */ - protected function getSoftEnum() : CommandEnum{ - $enumName = $this->buf->getString(); + protected function getSoftEnum(NetworkBinaryStream $in) : CommandEnum{ + $enumName = $in->getString(); $enumValues = []; - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ //Get the enum value from the initial pile of mess - $enumValues[] = $this->buf->getString(); + $enumValues[] = $in->getString(); } return new CommandEnum($enumName, $enumValues); @@ -188,51 +189,51 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ /** * @param int[] $enumValueMap */ - protected function putEnum(CommandEnum $enum, array $enumValueMap) : void{ - $this->buf->putString($enum->getName()); + protected function putEnum(CommandEnum $enum, array $enumValueMap, NetworkBinaryStream $out) : void{ + $out->putString($enum->getName()); $values = $enum->getValues(); - $this->buf->putUnsignedVarInt(count($values)); + $out->putUnsignedVarInt(count($values)); $listSize = count($enumValueMap); foreach($values as $value){ $index = $enumValueMap[$value] ?? -1; if($index === -1){ throw new \InvalidStateException("Enum value '$value' not found"); } - $this->putEnumValueIndex($index, $listSize); + $this->putEnumValueIndex($index, $listSize, $out); } } - protected function putSoftEnum(CommandEnum $enum) : void{ - $this->buf->putString($enum->getName()); + protected function putSoftEnum(CommandEnum $enum, NetworkBinaryStream $out) : void{ + $out->putString($enum->getName()); $values = $enum->getValues(); - $this->buf->putUnsignedVarInt(count($values)); + $out->putUnsignedVarInt(count($values)); foreach($values as $value){ - $this->buf->putString($value); + $out->putString($value); } } /** * @throws BinaryDataException */ - protected function getEnumValueIndex(int $valueCount) : int{ + protected function getEnumValueIndex(int $valueCount, NetworkBinaryStream $in) : int{ if($valueCount < 256){ - return $this->buf->getByte(); + return $in->getByte(); }elseif($valueCount < 65536){ - return $this->buf->getLShort(); + return $in->getLShort(); }else{ - return $this->buf->getLInt(); + return $in->getLInt(); } } - protected function putEnumValueIndex(int $index, int $valueCount) : void{ + protected function putEnumValueIndex(int $index, int $valueCount, NetworkBinaryStream $out) : void{ if($valueCount < 256){ - $this->buf->putByte($index); + $out->putByte($index); }elseif($valueCount < 65536){ - $this->buf->putLShort($index); + $out->putLShort($index); }else{ - $this->buf->putLInt($index); + $out->putLInt($index); } } @@ -243,13 +244,13 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ * @throws BadPacketException * @throws BinaryDataException */ - protected function getEnumConstraint(array $enums, array $enumValues) : CommandEnumConstraint{ + protected function getEnumConstraint(array $enums, array $enumValues, NetworkBinaryStream $in) : CommandEnumConstraint{ //wtf, what was wrong with an offset inside the enum? :( - $valueIndex = $this->buf->getLInt(); + $valueIndex = $in->getLInt(); if(!isset($enumValues[$valueIndex])){ throw new BadPacketException("Enum constraint refers to unknown enum value index $valueIndex"); } - $enumIndex = $this->buf->getLInt(); + $enumIndex = $in->getLInt(); if(!isset($enums[$enumIndex])){ throw new BadPacketException("Enum constraint refers to unknown enum index $enumIndex"); } @@ -260,8 +261,8 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ } $constraintIds = []; - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $constraintIds[] = $this->buf->getByte(); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $constraintIds[] = $in->getByte(); } return new CommandEnumConstraint($enum, $valueOffset, $constraintIds); @@ -271,12 +272,12 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ * @param int[] $enumIndexes string enum name -> int index * @param int[] $enumValueIndexes string value -> int index */ - protected function putEnumConstraint(CommandEnumConstraint $constraint, array $enumIndexes, array $enumValueIndexes) : void{ - $this->buf->putLInt($enumValueIndexes[$constraint->getAffectedValue()]); - $this->buf->putLInt($enumIndexes[$constraint->getEnum()->getName()]); - $this->buf->putUnsignedVarInt(count($constraint->getConstraints())); + protected function putEnumConstraint(CommandEnumConstraint $constraint, array $enumIndexes, array $enumValueIndexes, NetworkBinaryStream $out) : void{ + $out->putLInt($enumValueIndexes[$constraint->getAffectedValue()]); + $out->putLInt($enumIndexes[$constraint->getEnum()->getName()]); + $out->putUnsignedVarInt(count($constraint->getConstraints())); foreach($constraint->getConstraints() as $v){ - $this->buf->putByte($v); + $out->putByte($v); } } @@ -287,22 +288,22 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ * @throws BadPacketException * @throws BinaryDataException */ - protected function getCommandData(array $enums, array $postfixes) : CommandData{ - $name = $this->buf->getString(); - $description = $this->buf->getString(); - $flags = $this->buf->getByte(); - $permission = $this->buf->getByte(); - $aliases = $enums[$this->buf->getLInt()] ?? null; + protected function getCommandData(array $enums, array $postfixes, NetworkBinaryStream $in) : CommandData{ + $name = $in->getString(); + $description = $in->getString(); + $flags = $in->getByte(); + $permission = $in->getByte(); + $aliases = $enums[$in->getLInt()] ?? null; $overloads = []; - for($overloadIndex = 0, $overloadCount = $this->buf->getUnsignedVarInt(); $overloadIndex < $overloadCount; ++$overloadIndex){ + for($overloadIndex = 0, $overloadCount = $in->getUnsignedVarInt(); $overloadIndex < $overloadCount; ++$overloadIndex){ $overloads[$overloadIndex] = []; - for($paramIndex = 0, $paramCount = $this->buf->getUnsignedVarInt(); $paramIndex < $paramCount; ++$paramIndex){ + for($paramIndex = 0, $paramCount = $in->getUnsignedVarInt(); $paramIndex < $paramCount; ++$paramIndex){ $parameter = new CommandParameter(); - $parameter->paramName = $this->buf->getString(); - $parameter->paramType = $this->buf->getLInt(); - $parameter->isOptional = $this->buf->getBool(); - $parameter->flags = $this->buf->getByte(); + $parameter->paramName = $in->getString(); + $parameter->paramType = $in->getLInt(); + $parameter->isOptional = $in->getBool(); + $parameter->flags = $in->getByte(); if(($parameter->paramType & self::ARG_FLAG_ENUM) !== 0){ $index = ($parameter->paramType & 0xffff); @@ -331,24 +332,24 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ * @param int[] $enumIndexes string enum name -> int index * @param int[] $postfixIndexes */ - protected function putCommandData(CommandData $data, array $enumIndexes, array $postfixIndexes) : void{ - $this->buf->putString($data->name); - $this->buf->putString($data->description); - $this->buf->putByte($data->flags); - $this->buf->putByte($data->permission); + protected function putCommandData(CommandData $data, array $enumIndexes, array $postfixIndexes, NetworkBinaryStream $out) : void{ + $out->putString($data->name); + $out->putString($data->description); + $out->putByte($data->flags); + $out->putByte($data->permission); if($data->aliases !== null){ - $this->buf->putLInt($enumIndexes[$data->aliases->getName()] ?? -1); + $out->putLInt($enumIndexes[$data->aliases->getName()] ?? -1); }else{ - $this->buf->putLInt(-1); + $out->putLInt(-1); } - $this->buf->putUnsignedVarInt(count($data->overloads)); + $out->putUnsignedVarInt(count($data->overloads)); foreach($data->overloads as $overload){ /** @var CommandParameter[] $overload */ - $this->buf->putUnsignedVarInt(count($overload)); + $out->putUnsignedVarInt(count($overload)); foreach($overload as $parameter){ - $this->buf->putString($parameter->paramName); + $out->putString($parameter->paramName); if($parameter->enum !== null){ $type = self::ARG_FLAG_ENUM | self::ARG_FLAG_VALID | ($enumIndexes[$parameter->enum->getName()] ?? -1); @@ -362,9 +363,9 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ $type = $parameter->paramType; } - $this->buf->putLInt($type); - $this->buf->putBool($parameter->isOptional); - $this->buf->putByte($parameter->flags); + $out->putLInt($type); + $out->putBool($parameter->isOptional); + $out->putByte($parameter->flags); } } } @@ -412,7 +413,7 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ return "unknown ($argtype)"; } - protected function encodePayload() : void{ + protected function encodePayload(NetworkBinaryStream $out) : void{ /** @var int[] $enumValueIndexes */ $enumValueIndexes = []; /** @var int[] $postfixIndexes */ @@ -452,34 +453,34 @@ class AvailableCommandsPacket extends DataPacket implements ClientboundPacket{ } } - $this->buf->putUnsignedVarInt(count($enumValueIndexes)); + $out->putUnsignedVarInt(count($enumValueIndexes)); foreach($enumValueIndexes as $enumValue => $index){ - $this->buf->putString((string) $enumValue); //stupid PHP key casting D: + $out->putString((string) $enumValue); //stupid PHP key casting D: } - $this->buf->putUnsignedVarInt(count($postfixIndexes)); + $out->putUnsignedVarInt(count($postfixIndexes)); foreach($postfixIndexes as $postfix => $index){ - $this->buf->putString((string) $postfix); //stupid PHP key casting D: + $out->putString((string) $postfix); //stupid PHP key casting D: } - $this->buf->putUnsignedVarInt(count($enums)); + $out->putUnsignedVarInt(count($enums)); foreach($enums as $enum){ - $this->putEnum($enum, $enumValueIndexes); + $this->putEnum($enum, $enumValueIndexes, $out); } - $this->buf->putUnsignedVarInt(count($this->commandData)); + $out->putUnsignedVarInt(count($this->commandData)); foreach($this->commandData as $data){ - $this->putCommandData($data, $enumIndexes, $postfixIndexes); + $this->putCommandData($data, $enumIndexes, $postfixIndexes, $out); } - $this->buf->putUnsignedVarInt(count($this->softEnums)); + $out->putUnsignedVarInt(count($this->softEnums)); foreach($this->softEnums as $enum){ - $this->putSoftEnum($enum); + $this->putSoftEnum($enum, $out); } - $this->buf->putUnsignedVarInt(count($this->enumConstraints)); + $out->putUnsignedVarInt(count($this->enumConstraints)); foreach($this->enumConstraints as $constraint){ - $this->putEnumConstraint($constraint, $enumIndexes, $enumValueIndexes); + $this->putEnumConstraint($constraint, $enumIndexes, $enumValueIndexes, $out); } } diff --git a/src/network/mcpe/protocol/BiomeDefinitionListPacket.php b/src/network/mcpe/protocol/BiomeDefinitionListPacket.php index a16f17708..8ce5583bd 100644 --- a/src/network/mcpe/protocol/BiomeDefinitionListPacket.php +++ b/src/network/mcpe/protocol/BiomeDefinitionListPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function file_get_contents; class BiomeDefinitionListPacket extends DataPacket implements ClientboundPacket{ @@ -37,12 +38,12 @@ class BiomeDefinitionListPacket extends DataPacket implements ClientboundPacket{ /** @var string */ public $namedtag; - protected function decodePayload() : void{ - $this->namedtag = $this->buf->getRemaining(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->namedtag = $in->getRemaining(); } - protected function encodePayload() : void{ - $this->buf->put( + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->put( $this->namedtag ?? self::$DEFAULT_NBT_CACHE ?? (self::$DEFAULT_NBT_CACHE = file_get_contents(\pocketmine\RESOURCE_PATH . '/vanilla/biome_definitions.nbt')) diff --git a/src/network/mcpe/protocol/BlockActorDataPacket.php b/src/network/mcpe/protocol/BlockActorDataPacket.php index 2bcc51067..21a981a59 100644 --- a/src/network/mcpe/protocol/BlockActorDataPacket.php +++ b/src/network/mcpe/protocol/BlockActorDataPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class BlockActorDataPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::BLOCK_ACTOR_DATA_PACKET; @@ -46,14 +47,14 @@ class BlockActorDataPacket extends DataPacket implements ClientboundPacket, Serv return $result; } - protected function decodePayload() : void{ - $this->buf->getBlockPosition($this->x, $this->y, $this->z); - $this->namedtag = $this->buf->getRemaining(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $in->getBlockPosition($this->x, $this->y, $this->z); + $this->namedtag = $in->getRemaining(); } - protected function encodePayload() : void{ - $this->buf->putBlockPosition($this->x, $this->y, $this->z); - $this->buf->put($this->namedtag); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putBlockPosition($this->x, $this->y, $this->z); + $out->put($this->namedtag); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/BlockEventPacket.php b/src/network/mcpe/protocol/BlockEventPacket.php index b928db6c8..a4b74ddb5 100644 --- a/src/network/mcpe/protocol/BlockEventPacket.php +++ b/src/network/mcpe/protocol/BlockEventPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class BlockEventPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::BLOCK_EVENT_PACKET; @@ -52,16 +53,16 @@ class BlockEventPacket extends DataPacket implements ClientboundPacket{ return $pk; } - protected function decodePayload() : void{ - $this->buf->getBlockPosition($this->x, $this->y, $this->z); - $this->eventType = $this->buf->getVarInt(); - $this->eventData = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $in->getBlockPosition($this->x, $this->y, $this->z); + $this->eventType = $in->getVarInt(); + $this->eventData = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putBlockPosition($this->x, $this->y, $this->z); - $this->buf->putVarInt($this->eventType); - $this->buf->putVarInt($this->eventData); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putBlockPosition($this->x, $this->y, $this->z); + $out->putVarInt($this->eventType); + $out->putVarInt($this->eventData); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/BlockPickRequestPacket.php b/src/network/mcpe/protocol/BlockPickRequestPacket.php index 4adf0251d..ff2a6ed95 100644 --- a/src/network/mcpe/protocol/BlockPickRequestPacket.php +++ b/src/network/mcpe/protocol/BlockPickRequestPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class BlockPickRequestPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::BLOCK_PICK_REQUEST_PACKET; @@ -41,16 +42,16 @@ class BlockPickRequestPacket extends DataPacket implements ServerboundPacket{ /** @var int */ public $hotbarSlot; - protected function decodePayload() : void{ - $this->buf->getSignedBlockPosition($this->blockX, $this->blockY, $this->blockZ); - $this->addUserData = $this->buf->getBool(); - $this->hotbarSlot = $this->buf->getByte(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $in->getSignedBlockPosition($this->blockX, $this->blockY, $this->blockZ); + $this->addUserData = $in->getBool(); + $this->hotbarSlot = $in->getByte(); } - protected function encodePayload() : void{ - $this->buf->putSignedBlockPosition($this->blockX, $this->blockY, $this->blockZ); - $this->buf->putBool($this->addUserData); - $this->buf->putByte($this->hotbarSlot); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putSignedBlockPosition($this->blockX, $this->blockY, $this->blockZ); + $out->putBool($this->addUserData); + $out->putByte($this->hotbarSlot); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/BookEditPacket.php b/src/network/mcpe/protocol/BookEditPacket.php index 6df127780..3527009df 100644 --- a/src/network/mcpe/protocol/BookEditPacket.php +++ b/src/network/mcpe/protocol/BookEditPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\BadPacketException; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class BookEditPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::BOOK_EDIT_PACKET; @@ -58,56 +59,56 @@ class BookEditPacket extends DataPacket implements ServerboundPacket{ /** @var string */ public $xuid; - protected function decodePayload() : void{ - $this->type = $this->buf->getByte(); - $this->inventorySlot = $this->buf->getByte(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->type = $in->getByte(); + $this->inventorySlot = $in->getByte(); switch($this->type){ case self::TYPE_REPLACE_PAGE: case self::TYPE_ADD_PAGE: - $this->pageNumber = $this->buf->getByte(); - $this->text = $this->buf->getString(); - $this->photoName = $this->buf->getString(); + $this->pageNumber = $in->getByte(); + $this->text = $in->getString(); + $this->photoName = $in->getString(); break; case self::TYPE_DELETE_PAGE: - $this->pageNumber = $this->buf->getByte(); + $this->pageNumber = $in->getByte(); break; case self::TYPE_SWAP_PAGES: - $this->pageNumber = $this->buf->getByte(); - $this->secondaryPageNumber = $this->buf->getByte(); + $this->pageNumber = $in->getByte(); + $this->secondaryPageNumber = $in->getByte(); break; case self::TYPE_SIGN_BOOK: - $this->title = $this->buf->getString(); - $this->author = $this->buf->getString(); - $this->xuid = $this->buf->getString(); + $this->title = $in->getString(); + $this->author = $in->getString(); + $this->xuid = $in->getString(); break; default: throw new BadPacketException("Unknown book edit type $this->type!"); } } - protected function encodePayload() : void{ - $this->buf->putByte($this->type); - $this->buf->putByte($this->inventorySlot); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->type); + $out->putByte($this->inventorySlot); switch($this->type){ case self::TYPE_REPLACE_PAGE: case self::TYPE_ADD_PAGE: - $this->buf->putByte($this->pageNumber); - $this->buf->putString($this->text); - $this->buf->putString($this->photoName); + $out->putByte($this->pageNumber); + $out->putString($this->text); + $out->putString($this->photoName); break; case self::TYPE_DELETE_PAGE: - $this->buf->putByte($this->pageNumber); + $out->putByte($this->pageNumber); break; case self::TYPE_SWAP_PAGES: - $this->buf->putByte($this->pageNumber); - $this->buf->putByte($this->secondaryPageNumber); + $out->putByte($this->pageNumber); + $out->putByte($this->secondaryPageNumber); break; case self::TYPE_SIGN_BOOK: - $this->buf->putString($this->title); - $this->buf->putString($this->author); - $this->buf->putString($this->xuid); + $out->putString($this->title); + $out->putString($this->author); + $out->putString($this->xuid); break; default: throw new \InvalidArgumentException("Unknown book edit type $this->type!"); diff --git a/src/network/mcpe/protocol/BossEventPacket.php b/src/network/mcpe/protocol/BossEventPacket.php index 460e9492d..867cf19f9 100644 --- a/src/network/mcpe/protocol/BossEventPacket.php +++ b/src/network/mcpe/protocol/BossEventPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class BossEventPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::BOSS_EVENT_PACKET; @@ -118,60 +119,60 @@ class BossEventPacket extends DataPacket implements ClientboundPacket, Serverbou return $result; } - protected function decodePayload() : void{ - $this->bossEid = $this->buf->getEntityUniqueId(); - $this->eventType = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->bossEid = $in->getEntityUniqueId(); + $this->eventType = $in->getUnsignedVarInt(); switch($this->eventType){ case self::TYPE_REGISTER_PLAYER: case self::TYPE_UNREGISTER_PLAYER: - $this->playerEid = $this->buf->getEntityUniqueId(); + $this->playerEid = $in->getEntityUniqueId(); break; /** @noinspection PhpMissingBreakStatementInspection */ case self::TYPE_SHOW: - $this->title = $this->buf->getString(); - $this->healthPercent = $this->buf->getLFloat(); + $this->title = $in->getString(); + $this->healthPercent = $in->getLFloat(); /** @noinspection PhpMissingBreakStatementInspection */ case self::TYPE_UNKNOWN_6: - $this->unknownShort = $this->buf->getLShort(); + $this->unknownShort = $in->getLShort(); case self::TYPE_TEXTURE: - $this->color = $this->buf->getUnsignedVarInt(); - $this->overlay = $this->buf->getUnsignedVarInt(); + $this->color = $in->getUnsignedVarInt(); + $this->overlay = $in->getUnsignedVarInt(); break; case self::TYPE_HEALTH_PERCENT: - $this->healthPercent = $this->buf->getLFloat(); + $this->healthPercent = $in->getLFloat(); break; case self::TYPE_TITLE: - $this->title = $this->buf->getString(); + $this->title = $in->getString(); break; default: break; } } - protected function encodePayload() : void{ - $this->buf->putEntityUniqueId($this->bossEid); - $this->buf->putUnsignedVarInt($this->eventType); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityUniqueId($this->bossEid); + $out->putUnsignedVarInt($this->eventType); switch($this->eventType){ case self::TYPE_REGISTER_PLAYER: case self::TYPE_UNREGISTER_PLAYER: - $this->buf->putEntityUniqueId($this->playerEid); + $out->putEntityUniqueId($this->playerEid); break; /** @noinspection PhpMissingBreakStatementInspection */ case self::TYPE_SHOW: - $this->buf->putString($this->title); - $this->buf->putLFloat($this->healthPercent); + $out->putString($this->title); + $out->putLFloat($this->healthPercent); /** @noinspection PhpMissingBreakStatementInspection */ case self::TYPE_UNKNOWN_6: - $this->buf->putLShort($this->unknownShort); + $out->putLShort($this->unknownShort); case self::TYPE_TEXTURE: - $this->buf->putUnsignedVarInt($this->color); - $this->buf->putUnsignedVarInt($this->overlay); + $out->putUnsignedVarInt($this->color); + $out->putUnsignedVarInt($this->overlay); break; case self::TYPE_HEALTH_PERCENT: - $this->buf->putLFloat($this->healthPercent); + $out->putLFloat($this->healthPercent); break; case self::TYPE_TITLE: - $this->buf->putString($this->title); + $out->putString($this->title); break; default: break; diff --git a/src/network/mcpe/protocol/CameraPacket.php b/src/network/mcpe/protocol/CameraPacket.php index 81a3bfe07..bcdd42f6e 100644 --- a/src/network/mcpe/protocol/CameraPacket.php +++ b/src/network/mcpe/protocol/CameraPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class CameraPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::CAMERA_PACKET; @@ -35,14 +36,14 @@ class CameraPacket extends DataPacket implements ClientboundPacket{ /** @var int */ public $playerUniqueId; - protected function decodePayload() : void{ - $this->cameraUniqueId = $this->buf->getEntityUniqueId(); - $this->playerUniqueId = $this->buf->getEntityUniqueId(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->cameraUniqueId = $in->getEntityUniqueId(); + $this->playerUniqueId = $in->getEntityUniqueId(); } - protected function encodePayload() : void{ - $this->buf->putEntityUniqueId($this->cameraUniqueId); - $this->buf->putEntityUniqueId($this->playerUniqueId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityUniqueId($this->cameraUniqueId); + $out->putEntityUniqueId($this->playerUniqueId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ChangeDimensionPacket.php b/src/network/mcpe/protocol/ChangeDimensionPacket.php index ac68ac1d1..03d38f11e 100644 --- a/src/network/mcpe/protocol/ChangeDimensionPacket.php +++ b/src/network/mcpe/protocol/ChangeDimensionPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ChangeDimensionPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::CHANGE_DIMENSION_PACKET; @@ -38,16 +39,16 @@ class ChangeDimensionPacket extends DataPacket implements ClientboundPacket{ /** @var bool */ public $respawn = false; - protected function decodePayload() : void{ - $this->dimension = $this->buf->getVarInt(); - $this->position = $this->buf->getVector3(); - $this->respawn = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->dimension = $in->getVarInt(); + $this->position = $in->getVector3(); + $this->respawn = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->dimension); - $this->buf->putVector3($this->position); - $this->buf->putBool($this->respawn); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->dimension); + $out->putVector3($this->position); + $out->putBool($this->respawn); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php b/src/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php index 996dfc3c7..b42a1474a 100644 --- a/src/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php +++ b/src/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ChunkRadiusUpdatedPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::CHUNK_RADIUS_UPDATED_PACKET; @@ -39,12 +40,12 @@ class ChunkRadiusUpdatedPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->radius = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->radius = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->radius); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->radius); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ClientCacheBlobStatusPacket.php b/src/network/mcpe/protocol/ClientCacheBlobStatusPacket.php index 7954fa6bb..2d3e6f19e 100644 --- a/src/network/mcpe/protocol/ClientCacheBlobStatusPacket.php +++ b/src/network/mcpe/protocol/ClientCacheBlobStatusPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function count; class ClientCacheBlobStatusPacket extends DataPacket implements ServerboundPacket{ @@ -65,25 +66,25 @@ class ClientCacheBlobStatusPacket extends DataPacket implements ServerboundPacke return $this->missHashes; } - protected function decodePayload() : void{ - $hitCount = $this->buf->getUnsignedVarInt(); - $missCount = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $hitCount = $in->getUnsignedVarInt(); + $missCount = $in->getUnsignedVarInt(); for($i = 0; $i < $hitCount; ++$i){ - $this->hitHashes[] = $this->buf->getLLong(); + $this->hitHashes[] = $in->getLLong(); } for($i = 0; $i < $missCount; ++$i){ - $this->missHashes[] = $this->buf->getLLong(); + $this->missHashes[] = $in->getLLong(); } } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt(count($this->hitHashes)); - $this->buf->putUnsignedVarInt(count($this->missHashes)); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt(count($this->hitHashes)); + $out->putUnsignedVarInt(count($this->missHashes)); foreach($this->hitHashes as $hash){ - $this->buf->putLLong($hash); + $out->putLLong($hash); } foreach($this->missHashes as $hash){ - $this->buf->putLLong($hash); + $out->putLLong($hash); } } diff --git a/src/network/mcpe/protocol/ClientCacheMissResponsePacket.php b/src/network/mcpe/protocol/ClientCacheMissResponsePacket.php index 883859acc..8029582d6 100644 --- a/src/network/mcpe/protocol/ClientCacheMissResponsePacket.php +++ b/src/network/mcpe/protocol/ClientCacheMissResponsePacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\ChunkCacheBlob; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function count; class ClientCacheMissResponsePacket extends DataPacket implements ClientboundPacket{ @@ -54,19 +55,19 @@ class ClientCacheMissResponsePacket extends DataPacket implements ClientboundPac return $this->blobs; } - protected function decodePayload() : void{ - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $hash = $this->buf->getLLong(); - $payload = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $hash = $in->getLLong(); + $payload = $in->getString(); $this->blobs[] = new ChunkCacheBlob($hash, $payload); } } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt(count($this->blobs)); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt(count($this->blobs)); foreach($this->blobs as $blob){ - $this->buf->putLLong($blob->getHash()); - $this->buf->putString($blob->getPayload()); + $out->putLLong($blob->getHash()); + $out->putString($blob->getPayload()); } } diff --git a/src/network/mcpe/protocol/ClientCacheStatusPacket.php b/src/network/mcpe/protocol/ClientCacheStatusPacket.php index 4b44f6dc1..f15bc3a6b 100644 --- a/src/network/mcpe/protocol/ClientCacheStatusPacket.php +++ b/src/network/mcpe/protocol/ClientCacheStatusPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ClientCacheStatusPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::CLIENT_CACHE_STATUS_PACKET; @@ -43,12 +44,12 @@ class ClientCacheStatusPacket extends DataPacket implements ServerboundPacket{ return $this->enabled; } - protected function decodePayload() : void{ - $this->enabled = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->enabled = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putBool($this->enabled); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putBool($this->enabled); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ClientToServerHandshakePacket.php b/src/network/mcpe/protocol/ClientToServerHandshakePacket.php index 697d46246..c141822ea 100644 --- a/src/network/mcpe/protocol/ClientToServerHandshakePacket.php +++ b/src/network/mcpe/protocol/ClientToServerHandshakePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ClientToServerHandshakePacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::CLIENT_TO_SERVER_HANDSHAKE_PACKET; @@ -34,11 +35,11 @@ class ClientToServerHandshakePacket extends DataPacket implements ServerboundPac return true; } - protected function decodePayload() : void{ + protected function decodePayload(NetworkBinaryStream $in) : void{ //No payload } - protected function encodePayload() : void{ + protected function encodePayload(NetworkBinaryStream $out) : void{ //No payload } diff --git a/src/network/mcpe/protocol/ClientboundMapItemDataPacket.php b/src/network/mcpe/protocol/ClientboundMapItemDataPacket.php index d9be5178e..f427b959c 100644 --- a/src/network/mcpe/protocol/ClientboundMapItemDataPacket.php +++ b/src/network/mcpe/protocol/ClientboundMapItemDataPacket.php @@ -30,6 +30,7 @@ use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\DimensionIds; use pocketmine\network\mcpe\protocol\types\MapDecoration; use pocketmine\network\mcpe\protocol\types\MapTrackedObject; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use pocketmine\utils\Color; use function count; #ifndef COMPILE @@ -72,69 +73,69 @@ class ClientboundMapItemDataPacket extends DataPacket implements ClientboundPack /** @var Color[][] */ public $colors = []; - protected function decodePayload() : void{ - $this->mapId = $this->buf->getEntityUniqueId(); - $this->type = $this->buf->getUnsignedVarInt(); - $this->dimensionId = $this->buf->getByte(); - $this->isLocked = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->mapId = $in->getEntityUniqueId(); + $this->type = $in->getUnsignedVarInt(); + $this->dimensionId = $in->getByte(); + $this->isLocked = $in->getBool(); if(($this->type & 0x08) !== 0){ - $count = $this->buf->getUnsignedVarInt(); + $count = $in->getUnsignedVarInt(); for($i = 0; $i < $count; ++$i){ - $this->eids[] = $this->buf->getEntityUniqueId(); + $this->eids[] = $in->getEntityUniqueId(); } } if(($this->type & (0x08 | self::BITFLAG_DECORATION_UPDATE | self::BITFLAG_TEXTURE_UPDATE)) !== 0){ //Decoration bitflag or colour bitflag - $this->scale = $this->buf->getByte(); + $this->scale = $in->getByte(); } if(($this->type & self::BITFLAG_DECORATION_UPDATE) !== 0){ - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ $object = new MapTrackedObject(); - $object->type = $this->buf->getLInt(); + $object->type = $in->getLInt(); if($object->type === MapTrackedObject::TYPE_BLOCK){ - $this->buf->getBlockPosition($object->x, $object->y, $object->z); + $in->getBlockPosition($object->x, $object->y, $object->z); }elseif($object->type === MapTrackedObject::TYPE_ENTITY){ - $object->entityUniqueId = $this->buf->getEntityUniqueId(); + $object->entityUniqueId = $in->getEntityUniqueId(); }else{ throw new BadPacketException("Unknown map object type $object->type"); } $this->trackedEntities[] = $object; } - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $icon = $this->buf->getByte(); - $rotation = $this->buf->getByte(); - $xOffset = $this->buf->getByte(); - $yOffset = $this->buf->getByte(); - $label = $this->buf->getString(); - $color = Color::fromRGBA(Binary::flipIntEndianness($this->buf->getUnsignedVarInt())); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $icon = $in->getByte(); + $rotation = $in->getByte(); + $xOffset = $in->getByte(); + $yOffset = $in->getByte(); + $label = $in->getString(); + $color = Color::fromRGBA(Binary::flipIntEndianness($in->getUnsignedVarInt())); $this->decorations[] = new MapDecoration($icon, $rotation, $xOffset, $yOffset, $label, $color); } } if(($this->type & self::BITFLAG_TEXTURE_UPDATE) !== 0){ - $this->width = $this->buf->getVarInt(); - $this->height = $this->buf->getVarInt(); - $this->xOffset = $this->buf->getVarInt(); - $this->yOffset = $this->buf->getVarInt(); + $this->width = $in->getVarInt(); + $this->height = $in->getVarInt(); + $this->xOffset = $in->getVarInt(); + $this->yOffset = $in->getVarInt(); - $count = $this->buf->getUnsignedVarInt(); + $count = $in->getUnsignedVarInt(); if($count !== $this->width * $this->height){ throw new BadPacketException("Expected colour count of " . ($this->height * $this->width) . " (height $this->height * width $this->width), got $count"); } for($y = 0; $y < $this->height; ++$y){ for($x = 0; $x < $this->width; ++$x){ - $this->colors[$y][$x] = Color::fromRGBA(Binary::flipIntEndianness($this->buf->getUnsignedVarInt())); + $this->colors[$y][$x] = Color::fromRGBA(Binary::flipIntEndianness($in->getUnsignedVarInt())); } } } } - protected function encodePayload() : void{ - $this->buf->putEntityUniqueId($this->mapId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityUniqueId($this->mapId); $type = 0; if(($eidsCount = count($this->eids)) > 0){ @@ -147,57 +148,57 @@ class ClientboundMapItemDataPacket extends DataPacket implements ClientboundPack $type |= self::BITFLAG_TEXTURE_UPDATE; } - $this->buf->putUnsignedVarInt($type); - $this->buf->putByte($this->dimensionId); - $this->buf->putBool($this->isLocked); + $out->putUnsignedVarInt($type); + $out->putByte($this->dimensionId); + $out->putBool($this->isLocked); if(($type & 0x08) !== 0){ //TODO: find out what these are for - $this->buf->putUnsignedVarInt($eidsCount); + $out->putUnsignedVarInt($eidsCount); foreach($this->eids as $eid){ - $this->buf->putEntityUniqueId($eid); + $out->putEntityUniqueId($eid); } } if(($type & (0x08 | self::BITFLAG_TEXTURE_UPDATE | self::BITFLAG_DECORATION_UPDATE)) !== 0){ - $this->buf->putByte($this->scale); + $out->putByte($this->scale); } if(($type & self::BITFLAG_DECORATION_UPDATE) !== 0){ - $this->buf->putUnsignedVarInt(count($this->trackedEntities)); + $out->putUnsignedVarInt(count($this->trackedEntities)); foreach($this->trackedEntities as $object){ - $this->buf->putLInt($object->type); + $out->putLInt($object->type); if($object->type === MapTrackedObject::TYPE_BLOCK){ - $this->buf->putBlockPosition($object->x, $object->y, $object->z); + $out->putBlockPosition($object->x, $object->y, $object->z); }elseif($object->type === MapTrackedObject::TYPE_ENTITY){ - $this->buf->putEntityUniqueId($object->entityUniqueId); + $out->putEntityUniqueId($object->entityUniqueId); }else{ throw new \InvalidArgumentException("Unknown map object type $object->type"); } } - $this->buf->putUnsignedVarInt($decorationCount); + $out->putUnsignedVarInt($decorationCount); foreach($this->decorations as $decoration){ - $this->buf->putByte($decoration->getIcon()); - $this->buf->putByte($decoration->getRotation()); - $this->buf->putByte($decoration->getXOffset()); - $this->buf->putByte($decoration->getYOffset()); - $this->buf->putString($decoration->getLabel()); - $this->buf->putUnsignedVarInt(Binary::flipIntEndianness($decoration->getColor()->toRGBA())); + $out->putByte($decoration->getIcon()); + $out->putByte($decoration->getRotation()); + $out->putByte($decoration->getXOffset()); + $out->putByte($decoration->getYOffset()); + $out->putString($decoration->getLabel()); + $out->putUnsignedVarInt(Binary::flipIntEndianness($decoration->getColor()->toRGBA())); } } if(($type & self::BITFLAG_TEXTURE_UPDATE) !== 0){ - $this->buf->putVarInt($this->width); - $this->buf->putVarInt($this->height); - $this->buf->putVarInt($this->xOffset); - $this->buf->putVarInt($this->yOffset); + $out->putVarInt($this->width); + $out->putVarInt($this->height); + $out->putVarInt($this->xOffset); + $out->putVarInt($this->yOffset); - $this->buf->putUnsignedVarInt($this->width * $this->height); //list count, but we handle it as a 2D array... thanks for the confusion mojang + $out->putUnsignedVarInt($this->width * $this->height); //list count, but we handle it as a 2D array... thanks for the confusion mojang for($y = 0; $y < $this->height; ++$y){ for($x = 0; $x < $this->width; ++$x){ //if mojang had any sense this would just be a regular LE int - $this->buf->putUnsignedVarInt(Binary::flipIntEndianness($this->colors[$y][$x]->toRGBA())); + $out->putUnsignedVarInt(Binary::flipIntEndianness($this->colors[$y][$x]->toRGBA())); } } } diff --git a/src/network/mcpe/protocol/CommandBlockUpdatePacket.php b/src/network/mcpe/protocol/CommandBlockUpdatePacket.php index 038e1bacb..daa0df039 100644 --- a/src/network/mcpe/protocol/CommandBlockUpdatePacket.php +++ b/src/network/mcpe/protocol/CommandBlockUpdatePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class CommandBlockUpdatePacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::COMMAND_BLOCK_UPDATE_PACKET; @@ -62,47 +63,47 @@ class CommandBlockUpdatePacket extends DataPacket implements ServerboundPacket{ /** @var bool */ public $executeOnFirstTick; - protected function decodePayload() : void{ - $this->isBlock = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->isBlock = $in->getBool(); if($this->isBlock){ - $this->buf->getBlockPosition($this->x, $this->y, $this->z); - $this->commandBlockMode = $this->buf->getUnsignedVarInt(); - $this->isRedstoneMode = $this->buf->getBool(); - $this->isConditional = $this->buf->getBool(); + $in->getBlockPosition($this->x, $this->y, $this->z); + $this->commandBlockMode = $in->getUnsignedVarInt(); + $this->isRedstoneMode = $in->getBool(); + $this->isConditional = $in->getBool(); }else{ //Minecart with command block - $this->minecartEid = $this->buf->getEntityRuntimeId(); + $this->minecartEid = $in->getEntityRuntimeId(); } - $this->command = $this->buf->getString(); - $this->lastOutput = $this->buf->getString(); - $this->name = $this->buf->getString(); + $this->command = $in->getString(); + $this->lastOutput = $in->getString(); + $this->name = $in->getString(); - $this->shouldTrackOutput = $this->buf->getBool(); - $this->tickDelay = $this->buf->getLInt(); - $this->executeOnFirstTick = $this->buf->getBool(); + $this->shouldTrackOutput = $in->getBool(); + $this->tickDelay = $in->getLInt(); + $this->executeOnFirstTick = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putBool($this->isBlock); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putBool($this->isBlock); if($this->isBlock){ - $this->buf->putBlockPosition($this->x, $this->y, $this->z); - $this->buf->putUnsignedVarInt($this->commandBlockMode); - $this->buf->putBool($this->isRedstoneMode); - $this->buf->putBool($this->isConditional); + $out->putBlockPosition($this->x, $this->y, $this->z); + $out->putUnsignedVarInt($this->commandBlockMode); + $out->putBool($this->isRedstoneMode); + $out->putBool($this->isConditional); }else{ - $this->buf->putEntityRuntimeId($this->minecartEid); + $out->putEntityRuntimeId($this->minecartEid); } - $this->buf->putString($this->command); - $this->buf->putString($this->lastOutput); - $this->buf->putString($this->name); + $out->putString($this->command); + $out->putString($this->lastOutput); + $out->putString($this->name); - $this->buf->putBool($this->shouldTrackOutput); - $this->buf->putLInt($this->tickDelay); - $this->buf->putBool($this->executeOnFirstTick); + $out->putBool($this->shouldTrackOutput); + $out->putLInt($this->tickDelay); + $out->putBool($this->executeOnFirstTick); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/CommandOutputPacket.php b/src/network/mcpe/protocol/CommandOutputPacket.php index ec15f581e..f01f5467c 100644 --- a/src/network/mcpe/protocol/CommandOutputPacket.php +++ b/src/network/mcpe/protocol/CommandOutputPacket.php @@ -28,6 +28,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\command\CommandOriginData; use pocketmine\network\mcpe\protocol\types\command\CommandOutputMessage; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use pocketmine\utils\BinaryDataException; use function count; @@ -45,58 +46,58 @@ class CommandOutputPacket extends DataPacket implements ClientboundPacket{ /** @var string */ public $unknownString; - protected function decodePayload() : void{ - $this->originData = $this->buf->getCommandOriginData(); - $this->outputType = $this->buf->getByte(); - $this->successCount = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->originData = $in->getCommandOriginData(); + $this->outputType = $in->getByte(); + $this->successCount = $in->getUnsignedVarInt(); - for($i = 0, $size = $this->buf->getUnsignedVarInt(); $i < $size; ++$i){ - $this->messages[] = $this->getCommandMessage(); + for($i = 0, $size = $in->getUnsignedVarInt(); $i < $size; ++$i){ + $this->messages[] = $this->getCommandMessage($in); } if($this->outputType === 4){ - $this->unknownString = $this->buf->getString(); + $this->unknownString = $in->getString(); } } /** * @throws BinaryDataException */ - protected function getCommandMessage() : CommandOutputMessage{ + protected function getCommandMessage(NetworkBinaryStream $in) : CommandOutputMessage{ $message = new CommandOutputMessage(); - $message->isInternal = $this->buf->getBool(); - $message->messageId = $this->buf->getString(); + $message->isInternal = $in->getBool(); + $message->messageId = $in->getString(); - for($i = 0, $size = $this->buf->getUnsignedVarInt(); $i < $size; ++$i){ - $message->parameters[] = $this->buf->getString(); + for($i = 0, $size = $in->getUnsignedVarInt(); $i < $size; ++$i){ + $message->parameters[] = $in->getString(); } return $message; } - protected function encodePayload() : void{ - $this->buf->putCommandOriginData($this->originData); - $this->buf->putByte($this->outputType); - $this->buf->putUnsignedVarInt($this->successCount); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putCommandOriginData($this->originData); + $out->putByte($this->outputType); + $out->putUnsignedVarInt($this->successCount); - $this->buf->putUnsignedVarInt(count($this->messages)); + $out->putUnsignedVarInt(count($this->messages)); foreach($this->messages as $message){ - $this->putCommandMessage($message); + $this->putCommandMessage($message, $out); } if($this->outputType === 4){ - $this->buf->putString($this->unknownString); + $out->putString($this->unknownString); } } - protected function putCommandMessage(CommandOutputMessage $message) : void{ - $this->buf->putBool($message->isInternal); - $this->buf->putString($message->messageId); + protected function putCommandMessage(CommandOutputMessage $message, NetworkBinaryStream $out) : void{ + $out->putBool($message->isInternal); + $out->putString($message->messageId); - $this->buf->putUnsignedVarInt(count($message->parameters)); + $out->putUnsignedVarInt(count($message->parameters)); foreach($message->parameters as $parameter){ - $this->buf->putString($parameter); + $out->putString($parameter); } } diff --git a/src/network/mcpe/protocol/CommandRequestPacket.php b/src/network/mcpe/protocol/CommandRequestPacket.php index ab49ada1f..682a074a4 100644 --- a/src/network/mcpe/protocol/CommandRequestPacket.php +++ b/src/network/mcpe/protocol/CommandRequestPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\command\CommandOriginData; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class CommandRequestPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::COMMAND_REQUEST_PACKET; @@ -38,16 +39,16 @@ class CommandRequestPacket extends DataPacket implements ServerboundPacket{ /** @var bool */ public $isInternal; - protected function decodePayload() : void{ - $this->command = $this->buf->getString(); - $this->originData = $this->buf->getCommandOriginData(); - $this->isInternal = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->command = $in->getString(); + $this->originData = $in->getCommandOriginData(); + $this->isInternal = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putString($this->command); - $this->buf->putCommandOriginData($this->originData); - $this->buf->putBool($this->isInternal); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->command); + $out->putCommandOriginData($this->originData); + $out->putBool($this->isInternal); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/CompletedUsingItemPacket.php b/src/network/mcpe/protocol/CompletedUsingItemPacket.php index 4e7e4724a..72d84a3d2 100644 --- a/src/network/mcpe/protocol/CompletedUsingItemPacket.php +++ b/src/network/mcpe/protocol/CompletedUsingItemPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class CompletedUsingItemPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::COMPLETED_USING_ITEM_PACKET; @@ -52,14 +53,14 @@ class CompletedUsingItemPacket extends DataPacket implements ClientboundPacket{ /** @var int */ public $action; - public function decodePayload() : void{ - $this->itemId = $this->buf->getShort(); - $this->action = $this->buf->getLInt(); + public function decodePayload(NetworkBinaryStream $in) : void{ + $this->itemId = $in->getShort(); + $this->action = $in->getLInt(); } - public function encodePayload() : void{ - $this->buf->putShort($this->itemId); - $this->buf->putLInt($this->action); + public function encodePayload(NetworkBinaryStream $out) : void{ + $out->putShort($this->itemId); + $out->putLInt($this->action); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ContainerClosePacket.php b/src/network/mcpe/protocol/ContainerClosePacket.php index 13a694862..a0bc2f688 100644 --- a/src/network/mcpe/protocol/ContainerClosePacket.php +++ b/src/network/mcpe/protocol/ContainerClosePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ContainerClosePacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::CONTAINER_CLOSE_PACKET; @@ -39,12 +40,12 @@ class ContainerClosePacket extends DataPacket implements ClientboundPacket, Serv return $result; } - protected function decodePayload() : void{ - $this->windowId = $this->buf->getByte(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->windowId = $in->getByte(); } - protected function encodePayload() : void{ - $this->buf->putByte($this->windowId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->windowId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ContainerOpenPacket.php b/src/network/mcpe/protocol/ContainerOpenPacket.php index f45eccc06..0ac590772 100644 --- a/src/network/mcpe/protocol/ContainerOpenPacket.php +++ b/src/network/mcpe/protocol/ContainerOpenPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ContainerOpenPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::CONTAINER_OPEN_PACKET; @@ -65,18 +66,18 @@ class ContainerOpenPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->windowId = $this->buf->getByte(); - $this->type = $this->buf->getByte(); - $this->buf->getBlockPosition($this->x, $this->y, $this->z); - $this->entityUniqueId = $this->buf->getEntityUniqueId(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->windowId = $in->getByte(); + $this->type = $in->getByte(); + $in->getBlockPosition($this->x, $this->y, $this->z); + $this->entityUniqueId = $in->getEntityUniqueId(); } - protected function encodePayload() : void{ - $this->buf->putByte($this->windowId); - $this->buf->putByte($this->type); - $this->buf->putBlockPosition($this->x, $this->y, $this->z); - $this->buf->putEntityUniqueId($this->entityUniqueId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->windowId); + $out->putByte($this->type); + $out->putBlockPosition($this->x, $this->y, $this->z); + $out->putEntityUniqueId($this->entityUniqueId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ContainerSetDataPacket.php b/src/network/mcpe/protocol/ContainerSetDataPacket.php index a67b3f2d3..a7c2507ab 100644 --- a/src/network/mcpe/protocol/ContainerSetDataPacket.php +++ b/src/network/mcpe/protocol/ContainerSetDataPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ContainerSetDataPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::CONTAINER_SET_DATA_PACKET; @@ -55,16 +56,16 @@ class ContainerSetDataPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->windowId = $this->buf->getByte(); - $this->property = $this->buf->getVarInt(); - $this->value = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->windowId = $in->getByte(); + $this->property = $in->getVarInt(); + $this->value = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putByte($this->windowId); - $this->buf->putVarInt($this->property); - $this->buf->putVarInt($this->value); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->windowId); + $out->putVarInt($this->property); + $out->putVarInt($this->value); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/CraftingDataPacket.php b/src/network/mcpe/protocol/CraftingDataPacket.php index 362f10d28..e6a7cce03 100644 --- a/src/network/mcpe/protocol/CraftingDataPacket.php +++ b/src/network/mcpe/protocol/CraftingDataPacket.php @@ -65,62 +65,62 @@ class CraftingDataPacket extends DataPacket implements ClientboundPacket{ /** @var mixed[][] */ public $decodedEntries = []; - protected function decodePayload() : void{ + protected function decodePayload(NetworkBinaryStream $in) : void{ $this->decodedEntries = []; - $recipeCount = $this->buf->getUnsignedVarInt(); + $recipeCount = $in->getUnsignedVarInt(); for($i = 0; $i < $recipeCount; ++$i){ $entry = []; - $entry["type"] = $recipeType = $this->buf->getVarInt(); + $entry["type"] = $recipeType = $in->getVarInt(); switch($recipeType){ case self::ENTRY_SHAPELESS: case self::ENTRY_SHULKER_BOX: case self::ENTRY_SHAPELESS_CHEMISTRY: - $entry["recipe_id"] = $this->buf->getString(); - $ingredientCount = $this->buf->getUnsignedVarInt(); + $entry["recipe_id"] = $in->getString(); + $ingredientCount = $in->getUnsignedVarInt(); /** @var Item */ $entry["input"] = []; for($j = 0; $j < $ingredientCount; ++$j){ - $entry["input"][] = $in = $this->buf->getRecipeIngredient(); + $entry["input"][] = $in = $in->getRecipeIngredient(); $in->setCount(1); //TODO HACK: they send a useless count field which breaks the PM crafting system because it isn't always 1 } - $resultCount = $this->buf->getUnsignedVarInt(); + $resultCount = $in->getUnsignedVarInt(); $entry["output"] = []; for($k = 0; $k < $resultCount; ++$k){ - $entry["output"][] = $this->buf->getSlot(); + $entry["output"][] = $in->getSlot(); } - $entry["uuid"] = $this->buf->getUUID()->toString(); - $entry["block"] = $this->buf->getString(); - $entry["priority"] = $this->buf->getVarInt(); + $entry["uuid"] = $in->getUUID()->toString(); + $entry["block"] = $in->getString(); + $entry["priority"] = $in->getVarInt(); break; case self::ENTRY_SHAPED: case self::ENTRY_SHAPED_CHEMISTRY: - $entry["recipe_id"] = $this->buf->getString(); - $entry["width"] = $this->buf->getVarInt(); - $entry["height"] = $this->buf->getVarInt(); + $entry["recipe_id"] = $in->getString(); + $entry["width"] = $in->getVarInt(); + $entry["height"] = $in->getVarInt(); $count = $entry["width"] * $entry["height"]; $entry["input"] = []; for($j = 0; $j < $count; ++$j){ - $entry["input"][] = $in = $this->buf->getRecipeIngredient(); + $entry["input"][] = $in = $in->getRecipeIngredient(); $in->setCount(1); //TODO HACK: they send a useless count field which breaks the PM crafting system } - $resultCount = $this->buf->getUnsignedVarInt(); + $resultCount = $in->getUnsignedVarInt(); $entry["output"] = []; for($k = 0; $k < $resultCount; ++$k){ - $entry["output"][] = $this->buf->getSlot(); + $entry["output"][] = $in->getSlot(); } - $entry["uuid"] = $this->buf->getUUID()->toString(); - $entry["block"] = $this->buf->getString(); - $entry["priority"] = $this->buf->getVarInt(); + $entry["uuid"] = $in->getUUID()->toString(); + $entry["block"] = $in->getString(); + $entry["priority"] = $in->getVarInt(); break; case self::ENTRY_FURNACE: case self::ENTRY_FURNACE_DATA: - $inputId = $this->buf->getVarInt(); + $inputId = $in->getVarInt(); $inputData = -1; if($recipeType === self::ENTRY_FURNACE_DATA){ - $inputData = $this->buf->getVarInt(); + $inputData = $in->getVarInt(); if($inputData === 0x7fff){ $inputData = -1; } @@ -130,34 +130,34 @@ class CraftingDataPacket extends DataPacket implements ClientboundPacket{ }catch(\InvalidArgumentException $e){ throw new BadPacketException($e->getMessage(), 0, $e); } - $entry["output"] = $out = $this->buf->getSlot(); + $entry["output"] = $out = $in->getSlot(); if($out->getMeta() === 0x7fff){ $entry["output"] = ItemFactory::get($out->getId(), 0); //TODO HACK: some 1.12 furnace recipe outputs have wildcard damage values } - $entry["block"] = $this->buf->getString(); + $entry["block"] = $in->getString(); break; case self::ENTRY_MULTI: - $entry["uuid"] = $this->buf->getUUID()->toString(); + $entry["uuid"] = $in->getUUID()->toString(); break; default: throw new BadPacketException("Unhandled recipe type $recipeType!"); //do not continue attempting to decode } $this->decodedEntries[] = $entry; } - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $input = $this->buf->getVarInt(); - $ingredient = $this->buf->getVarInt(); - $output = $this->buf->getVarInt(); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $input = $in->getVarInt(); + $ingredient = $in->getVarInt(); + $output = $in->getVarInt(); $this->potionTypeRecipes[] = new PotionTypeRecipe($input, $ingredient, $output); } - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $input = $this->buf->getVarInt(); - $ingredient = $this->buf->getVarInt(); - $output = $this->buf->getVarInt(); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $input = $in->getVarInt(); + $ingredient = $in->getVarInt(); + $output = $in->getVarInt(); $this->potionContainerRecipes[] = new PotionContainerChangeRecipe($input, $ingredient, $output); } - $this->cleanRecipes = $this->buf->getBool(); + $this->cleanRecipes = $in->getBool(); } /** @@ -244,36 +244,36 @@ class CraftingDataPacket extends DataPacket implements ClientboundPacket{ $this->entries[] = $recipe; } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt(count($this->entries)); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt(count($this->entries)); $writer = new NetworkBinaryStream(); $counter = 0; foreach($this->entries as $d){ $entryType = self::writeEntry($d, $writer, $counter++); if($entryType >= 0){ - $this->buf->putVarInt($entryType); - $this->buf->put($writer->getBuffer()); + $out->putVarInt($entryType); + $out->put($writer->getBuffer()); }else{ - $this->buf->putVarInt(-1); + $out->putVarInt(-1); } $writer->reset(); } - $this->buf->putUnsignedVarInt(count($this->potionTypeRecipes)); + $out->putUnsignedVarInt(count($this->potionTypeRecipes)); foreach($this->potionTypeRecipes as $recipe){ - $this->buf->putVarInt($recipe->getInputPotionType()); - $this->buf->putVarInt($recipe->getIngredientItemId()); - $this->buf->putVarInt($recipe->getOutputPotionType()); + $out->putVarInt($recipe->getInputPotionType()); + $out->putVarInt($recipe->getIngredientItemId()); + $out->putVarInt($recipe->getOutputPotionType()); } - $this->buf->putUnsignedVarInt(count($this->potionContainerRecipes)); + $out->putUnsignedVarInt(count($this->potionContainerRecipes)); foreach($this->potionContainerRecipes as $recipe){ - $this->buf->putVarInt($recipe->getInputItemId()); - $this->buf->putVarInt($recipe->getIngredientItemId()); - $this->buf->putVarInt($recipe->getOutputItemId()); + $out->putVarInt($recipe->getInputItemId()); + $out->putVarInt($recipe->getIngredientItemId()); + $out->putVarInt($recipe->getOutputItemId()); } - $this->buf->putBool($this->cleanRecipes); + $out->putBool($this->cleanRecipes); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/CraftingEventPacket.php b/src/network/mcpe/protocol/CraftingEventPacket.php index e932aa08a..b932f839b 100644 --- a/src/network/mcpe/protocol/CraftingEventPacket.php +++ b/src/network/mcpe/protocol/CraftingEventPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\item\Item; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use pocketmine\utils\UUID; use function count; @@ -44,35 +45,35 @@ class CraftingEventPacket extends DataPacket implements ServerboundPacket{ /** @var Item[] */ public $output = []; - protected function decodePayload() : void{ - $this->windowId = $this->buf->getByte(); - $this->type = $this->buf->getVarInt(); - $this->id = $this->buf->getUUID(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->windowId = $in->getByte(); + $this->type = $in->getVarInt(); + $this->id = $in->getUUID(); - $size = $this->buf->getUnsignedVarInt(); + $size = $in->getUnsignedVarInt(); for($i = 0; $i < $size and $i < 128; ++$i){ - $this->input[] = $this->buf->getSlot(); + $this->input[] = $in->getSlot(); } - $size = $this->buf->getUnsignedVarInt(); + $size = $in->getUnsignedVarInt(); for($i = 0; $i < $size and $i < 128; ++$i){ - $this->output[] = $this->buf->getSlot(); + $this->output[] = $in->getSlot(); } } - protected function encodePayload() : void{ - $this->buf->putByte($this->windowId); - $this->buf->putVarInt($this->type); - $this->buf->putUUID($this->id); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->windowId); + $out->putVarInt($this->type); + $out->putUUID($this->id); - $this->buf->putUnsignedVarInt(count($this->input)); + $out->putUnsignedVarInt(count($this->input)); foreach($this->input as $item){ - $this->buf->putSlot($item); + $out->putSlot($item); } - $this->buf->putUnsignedVarInt(count($this->output)); + $out->putUnsignedVarInt(count($this->output)); foreach($this->output as $item){ - $this->buf->putSlot($item); + $out->putSlot($item); } } diff --git a/src/network/mcpe/protocol/DataPacket.php b/src/network/mcpe/protocol/DataPacket.php index 051fa9af2..157c83b69 100644 --- a/src/network/mcpe/protocol/DataPacket.php +++ b/src/network/mcpe/protocol/DataPacket.php @@ -51,7 +51,7 @@ abstract class DataPacket implements Packet{ public $recipientSubId = 0; /** @var NetworkBinaryStream */ - protected $buf; + private $buf; public function __construct(){ $this->buf = new NetworkBinaryStream(); @@ -79,8 +79,8 @@ abstract class DataPacket implements Packet{ final public function decode() : void{ $this->buf->rewind(); try{ - $this->decodeHeader(); - $this->decodePayload(); + $this->decodeHeader($this->buf); + $this->decodePayload($this->buf); }catch(BinaryDataException | BadPacketException $e){ throw new BadPacketException($this->getName() . ": " . $e->getMessage(), 0, $e); } @@ -90,8 +90,8 @@ abstract class DataPacket implements Packet{ * @throws BinaryDataException * @throws \UnexpectedValueException */ - protected function decodeHeader() : void{ - $header = $this->buf->getUnsignedVarInt(); + protected function decodeHeader(NetworkBinaryStream $in) : void{ + $header = $in->getUnsignedVarInt(); $pid = $header & self::PID_MASK; if($pid !== static::NETWORK_ID){ //TODO: this means a logical error in the code, but how to prevent it from happening? @@ -108,16 +108,16 @@ abstract class DataPacket implements Packet{ * @throws BadPacketException * @throws BinaryDataException */ - abstract protected function decodePayload() : void; + abstract protected function decodePayload(NetworkBinaryStream $in) : void; final public function encode() : void{ $this->buf->reset(); - $this->encodeHeader(); - $this->encodePayload(); + $this->encodeHeader($this->buf); + $this->encodePayload($this->buf); } - protected function encodeHeader() : void{ - $this->buf->putUnsignedVarInt( + protected function encodeHeader(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt( static::NETWORK_ID | ($this->senderSubId << self::SENDER_SUBCLIENT_ID_SHIFT) | ($this->recipientSubId << self::RECIPIENT_SUBCLIENT_ID_SHIFT) @@ -127,7 +127,7 @@ abstract class DataPacket implements Packet{ /** * Encodes the packet body, without the packet ID or other generic header fields. */ - abstract protected function encodePayload() : void; + abstract protected function encodePayload(NetworkBinaryStream $out) : void; /** * @param string $name diff --git a/src/network/mcpe/protocol/DisconnectPacket.php b/src/network/mcpe/protocol/DisconnectPacket.php index 25f84743f..e9ec1cbbd 100644 --- a/src/network/mcpe/protocol/DisconnectPacket.php +++ b/src/network/mcpe/protocol/DisconnectPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class DisconnectPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::DISCONNECT_PACKET; @@ -52,17 +53,17 @@ class DisconnectPacket extends DataPacket implements ClientboundPacket, Serverbo return true; } - protected function decodePayload() : void{ - $this->hideDisconnectionScreen = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->hideDisconnectionScreen = $in->getBool(); if(!$this->hideDisconnectionScreen){ - $this->message = $this->buf->getString(); + $this->message = $in->getString(); } } - protected function encodePayload() : void{ - $this->buf->putBool($this->hideDisconnectionScreen); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putBool($this->hideDisconnectionScreen); if(!$this->hideDisconnectionScreen){ - $this->buf->putString($this->message); + $out->putString($this->message); } } diff --git a/src/network/mcpe/protocol/EducationSettingsPacket.php b/src/network/mcpe/protocol/EducationSettingsPacket.php index a561b5acb..264e34de0 100644 --- a/src/network/mcpe/protocol/EducationSettingsPacket.php +++ b/src/network/mcpe/protocol/EducationSettingsPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class EducationSettingsPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::EDUCATION_SETTINGS_PACKET; @@ -50,14 +51,14 @@ class EducationSettingsPacket extends DataPacket implements ClientboundPacket{ return $this->hasQuiz; } - protected function decodePayload() : void{ - $this->codeBuilderDefaultUri = $this->buf->getString(); - $this->hasQuiz = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->codeBuilderDefaultUri = $in->getString(); + $this->hasQuiz = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putString($this->codeBuilderDefaultUri); - $this->buf->putBool($this->hasQuiz); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->codeBuilderDefaultUri); + $out->putBool($this->hasQuiz); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/EmotePacket.php b/src/network/mcpe/protocol/EmotePacket.php index 23194e680..76ff71c18 100644 --- a/src/network/mcpe/protocol/EmotePacket.php +++ b/src/network/mcpe/protocol/EmotePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class EmotePacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::EMOTE_PACKET; @@ -62,16 +63,16 @@ class EmotePacket extends DataPacket implements ClientboundPacket, ServerboundPa return $this->flags; } - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->emoteId = $this->buf->getString(); - $this->flags = $this->buf->getByte(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->emoteId = $in->getString(); + $this->flags = $in->getByte(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putString($this->emoteId); - $this->buf->putByte($this->flags); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putString($this->emoteId); + $out->putByte($this->flags); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/EventPacket.php b/src/network/mcpe/protocol/EventPacket.php index 6dffeb7b4..882e2c241 100644 --- a/src/network/mcpe/protocol/EventPacket.php +++ b/src/network/mcpe/protocol/EventPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class EventPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::EVENT_PACKET; @@ -56,18 +57,18 @@ class EventPacket extends DataPacket implements ClientboundPacket{ /** @var int */ public $type; - protected function decodePayload() : void{ - $this->playerRuntimeId = $this->buf->getEntityRuntimeId(); - $this->eventData = $this->buf->getVarInt(); - $this->type = $this->buf->getByte(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->playerRuntimeId = $in->getEntityRuntimeId(); + $this->eventData = $in->getVarInt(); + $this->type = $in->getByte(); //TODO: nice confusing mess } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->playerRuntimeId); - $this->buf->putVarInt($this->eventData); - $this->buf->putByte($this->type); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->playerRuntimeId); + $out->putVarInt($this->eventData); + $out->putByte($this->type); //TODO: also nice confusing mess } diff --git a/src/network/mcpe/protocol/GameRulesChangedPacket.php b/src/network/mcpe/protocol/GameRulesChangedPacket.php index 7acbe1abc..f1249f87a 100644 --- a/src/network/mcpe/protocol/GameRulesChangedPacket.php +++ b/src/network/mcpe/protocol/GameRulesChangedPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class GameRulesChangedPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::GAME_RULES_CHANGED_PACKET; @@ -36,12 +37,12 @@ class GameRulesChangedPacket extends DataPacket implements ClientboundPacket{ */ public $gameRules = []; - protected function decodePayload() : void{ - $this->gameRules = $this->buf->getGameRules(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->gameRules = $in->getGameRules(); } - protected function encodePayload() : void{ - $this->buf->putGameRules($this->gameRules); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putGameRules($this->gameRules); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/GuiDataPickItemPacket.php b/src/network/mcpe/protocol/GuiDataPickItemPacket.php index f898dc6b1..820725651 100644 --- a/src/network/mcpe/protocol/GuiDataPickItemPacket.php +++ b/src/network/mcpe/protocol/GuiDataPickItemPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class GuiDataPickItemPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::GUI_DATA_PICK_ITEM_PACKET; @@ -37,16 +38,16 @@ class GuiDataPickItemPacket extends DataPacket implements ClientboundPacket{ /** @var int */ public $hotbarSlot; - protected function decodePayload() : void{ - $this->itemDescription = $this->buf->getString(); - $this->itemEffects = $this->buf->getString(); - $this->hotbarSlot = $this->buf->getLInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->itemDescription = $in->getString(); + $this->itemEffects = $in->getString(); + $this->hotbarSlot = $in->getLInt(); } - protected function encodePayload() : void{ - $this->buf->putString($this->itemDescription); - $this->buf->putString($this->itemEffects); - $this->buf->putLInt($this->hotbarSlot); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->itemDescription); + $out->putString($this->itemEffects); + $out->putLInt($this->hotbarSlot); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/HurtArmorPacket.php b/src/network/mcpe/protocol/HurtArmorPacket.php index 7ad5174a2..a53cf4d15 100644 --- a/src/network/mcpe/protocol/HurtArmorPacket.php +++ b/src/network/mcpe/protocol/HurtArmorPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class HurtArmorPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::HURT_ARMOR_PACKET; @@ -33,12 +34,12 @@ class HurtArmorPacket extends DataPacket implements ClientboundPacket{ /** @var int */ public $health; - protected function decodePayload() : void{ - $this->health = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->health = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->health); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->health); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/InteractPacket.php b/src/network/mcpe/protocol/InteractPacket.php index 715b24809..38c8e2a2b 100644 --- a/src/network/mcpe/protocol/InteractPacket.php +++ b/src/network/mcpe/protocol/InteractPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class InteractPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::INTERACT_PACKET; @@ -47,26 +48,26 @@ class InteractPacket extends DataPacket implements ServerboundPacket{ /** @var float */ public $z; - protected function decodePayload() : void{ - $this->action = $this->buf->getByte(); - $this->target = $this->buf->getEntityRuntimeId(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->action = $in->getByte(); + $this->target = $in->getEntityRuntimeId(); if($this->action === self::ACTION_MOUSEOVER){ //TODO: should this be a vector3? - $this->x = $this->buf->getLFloat(); - $this->y = $this->buf->getLFloat(); - $this->z = $this->buf->getLFloat(); + $this->x = $in->getLFloat(); + $this->y = $in->getLFloat(); + $this->z = $in->getLFloat(); } } - protected function encodePayload() : void{ - $this->buf->putByte($this->action); - $this->buf->putEntityRuntimeId($this->target); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->action); + $out->putEntityRuntimeId($this->target); if($this->action === self::ACTION_MOUSEOVER){ - $this->buf->putLFloat($this->x); - $this->buf->putLFloat($this->y); - $this->buf->putLFloat($this->z); + $out->putLFloat($this->x); + $out->putLFloat($this->y); + $out->putLFloat($this->z); } } diff --git a/src/network/mcpe/protocol/InventoryContentPacket.php b/src/network/mcpe/protocol/InventoryContentPacket.php index 0375a651b..2490b9b79 100644 --- a/src/network/mcpe/protocol/InventoryContentPacket.php +++ b/src/network/mcpe/protocol/InventoryContentPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\item\Item; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function count; class InventoryContentPacket extends DataPacket implements ClientboundPacket{ @@ -49,19 +50,19 @@ class InventoryContentPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->windowId = $this->buf->getUnsignedVarInt(); - $count = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->windowId = $in->getUnsignedVarInt(); + $count = $in->getUnsignedVarInt(); for($i = 0; $i < $count; ++$i){ - $this->items[] = $this->buf->getSlot(); + $this->items[] = $in->getSlot(); } } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt($this->windowId); - $this->buf->putUnsignedVarInt(count($this->items)); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt($this->windowId); + $out->putUnsignedVarInt(count($this->items)); foreach($this->items as $item){ - $this->buf->putSlot($item); + $out->putSlot($item); } } diff --git a/src/network/mcpe/protocol/InventorySlotPacket.php b/src/network/mcpe/protocol/InventorySlotPacket.php index 6c9c526dd..24632bc6e 100644 --- a/src/network/mcpe/protocol/InventorySlotPacket.php +++ b/src/network/mcpe/protocol/InventorySlotPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\item\Item; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class InventorySlotPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::INVENTORY_SLOT_PACKET; @@ -46,16 +47,16 @@ class InventorySlotPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->windowId = $this->buf->getUnsignedVarInt(); - $this->inventorySlot = $this->buf->getUnsignedVarInt(); - $this->item = $this->buf->getSlot(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->windowId = $in->getUnsignedVarInt(); + $this->inventorySlot = $in->getUnsignedVarInt(); + $this->item = $in->getSlot(); } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt($this->windowId); - $this->buf->putUnsignedVarInt($this->inventorySlot); - $this->buf->putSlot($this->item); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt($this->windowId); + $out->putUnsignedVarInt($this->inventorySlot); + $out->putSlot($this->item); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/InventoryTransactionPacket.php b/src/network/mcpe/protocol/InventoryTransactionPacket.php index 9d3404252..c3f99e55c 100644 --- a/src/network/mcpe/protocol/InventoryTransactionPacket.php +++ b/src/network/mcpe/protocol/InventoryTransactionPacket.php @@ -33,6 +33,7 @@ use pocketmine\network\mcpe\protocol\types\inventory\ReleaseItemTransactionData; use pocketmine\network\mcpe\protocol\types\inventory\TransactionData; use pocketmine\network\mcpe\protocol\types\inventory\UseItemOnEntityTransactionData; use pocketmine\network\mcpe\protocol\types\inventory\UseItemTransactionData; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; /** * This packet effectively crams multiple packets into one. @@ -49,8 +50,8 @@ class InventoryTransactionPacket extends DataPacket implements ClientboundPacket /** @var TransactionData */ public $trData; - protected function decodePayload() : void{ - $transactionType = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $transactionType = $in->getUnsignedVarInt(); switch($transactionType){ case self::TYPE_NORMAL: @@ -72,12 +73,12 @@ class InventoryTransactionPacket extends DataPacket implements ClientboundPacket throw new BadPacketException("Unknown transaction type $transactionType"); } - $this->trData->decode($this->buf); + $this->trData->decode($in); } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt($this->trData->getTypeId()); - $this->trData->encode($this->buf); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt($this->trData->getTypeId()); + $this->trData->encode($out); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ItemFrameDropItemPacket.php b/src/network/mcpe/protocol/ItemFrameDropItemPacket.php index f9bfb9753..bac21044a 100644 --- a/src/network/mcpe/protocol/ItemFrameDropItemPacket.php +++ b/src/network/mcpe/protocol/ItemFrameDropItemPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ItemFrameDropItemPacket extends DataPacket implements ServerboundPacket{ @@ -38,12 +39,12 @@ class ItemFrameDropItemPacket extends DataPacket implements ServerboundPacket{ /** @var int */ public $z; - protected function decodePayload() : void{ - $this->buf->getBlockPosition($this->x, $this->y, $this->z); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $in->getBlockPosition($this->x, $this->y, $this->z); } - protected function encodePayload() : void{ - $this->buf->putBlockPosition($this->x, $this->y, $this->z); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putBlockPosition($this->x, $this->y, $this->z); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/LabTablePacket.php b/src/network/mcpe/protocol/LabTablePacket.php index 09a5b1131..801c7d50e 100644 --- a/src/network/mcpe/protocol/LabTablePacket.php +++ b/src/network/mcpe/protocol/LabTablePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class LabTablePacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::LAB_TABLE_PACKET; @@ -43,16 +44,16 @@ class LabTablePacket extends DataPacket implements ClientboundPacket, Serverboun /** @var int */ public $reactionType; - protected function decodePayload() : void{ - $this->uselessByte = $this->buf->getByte(); - $this->buf->getSignedBlockPosition($this->x, $this->y, $this->z); - $this->reactionType = $this->buf->getByte(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->uselessByte = $in->getByte(); + $in->getSignedBlockPosition($this->x, $this->y, $this->z); + $this->reactionType = $in->getByte(); } - protected function encodePayload() : void{ - $this->buf->putByte($this->uselessByte); - $this->buf->putSignedBlockPosition($this->x, $this->y, $this->z); - $this->buf->putByte($this->reactionType); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->uselessByte); + $out->putSignedBlockPosition($this->x, $this->y, $this->z); + $out->putByte($this->reactionType); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/LecternUpdatePacket.php b/src/network/mcpe/protocol/LecternUpdatePacket.php index c46904d2e..3362ec0bf 100644 --- a/src/network/mcpe/protocol/LecternUpdatePacket.php +++ b/src/network/mcpe/protocol/LecternUpdatePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class LecternUpdatePacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::LECTERN_UPDATE_PACKET; @@ -43,18 +44,18 @@ class LecternUpdatePacket extends DataPacket implements ServerboundPacket{ /** @var bool */ public $dropBook; - protected function decodePayload() : void{ - $this->page = $this->buf->getByte(); - $this->totalPages = $this->buf->getByte(); - $this->buf->getBlockPosition($this->x, $this->y, $this->z); - $this->dropBook = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->page = $in->getByte(); + $this->totalPages = $in->getByte(); + $in->getBlockPosition($this->x, $this->y, $this->z); + $this->dropBook = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putByte($this->page); - $this->buf->putByte($this->totalPages); - $this->buf->putBlockPosition($this->x, $this->y, $this->z); - $this->buf->putBool($this->dropBook); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->page); + $out->putByte($this->totalPages); + $out->putBlockPosition($this->x, $this->y, $this->z); + $out->putBool($this->dropBook); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/LevelChunkPacket.php b/src/network/mcpe/protocol/LevelChunkPacket.php index f24491198..04a5e9c99 100644 --- a/src/network/mcpe/protocol/LevelChunkPacket.php +++ b/src/network/mcpe/protocol/LevelChunkPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function count; class LevelChunkPacket extends DataPacket implements ClientboundPacket{ @@ -100,31 +101,31 @@ class LevelChunkPacket extends DataPacket implements ClientboundPacket{ return $this->extraPayload; } - protected function decodePayload() : void{ - $this->chunkX = $this->buf->getVarInt(); - $this->chunkZ = $this->buf->getVarInt(); - $this->subChunkCount = $this->buf->getUnsignedVarInt(); - $this->cacheEnabled = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->chunkX = $in->getVarInt(); + $this->chunkZ = $in->getVarInt(); + $this->subChunkCount = $in->getUnsignedVarInt(); + $this->cacheEnabled = $in->getBool(); if($this->cacheEnabled){ - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $this->usedBlobHashes[] = $this->buf->getLLong(); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $this->usedBlobHashes[] = $in->getLLong(); } } - $this->extraPayload = $this->buf->getString(); + $this->extraPayload = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->chunkX); - $this->buf->putVarInt($this->chunkZ); - $this->buf->putUnsignedVarInt($this->subChunkCount); - $this->buf->putBool($this->cacheEnabled); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->chunkX); + $out->putVarInt($this->chunkZ); + $out->putUnsignedVarInt($this->subChunkCount); + $out->putBool($this->cacheEnabled); if($this->cacheEnabled){ - $this->buf->putUnsignedVarInt(count($this->usedBlobHashes)); + $out->putUnsignedVarInt(count($this->usedBlobHashes)); foreach($this->usedBlobHashes as $hash){ - $this->buf->putLLong($hash); + $out->putLLong($hash); } } - $this->buf->putString($this->extraPayload); + $out->putString($this->extraPayload); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/LevelEventGenericPacket.php b/src/network/mcpe/protocol/LevelEventGenericPacket.php index 6ae513b89..d0dc7d3df 100644 --- a/src/network/mcpe/protocol/LevelEventGenericPacket.php +++ b/src/network/mcpe/protocol/LevelEventGenericPacket.php @@ -28,6 +28,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\TreeRoot; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use pocketmine\network\mcpe\serializer\NetworkNbtSerializer; class LevelEventGenericPacket extends DataPacket implements ClientboundPacket{ @@ -53,14 +54,14 @@ class LevelEventGenericPacket extends DataPacket implements ClientboundPacket{ return $this->eventData; } - protected function decodePayload() : void{ - $this->eventId = $this->buf->getVarInt(); - $this->eventData = $this->buf->getRemaining(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->eventId = $in->getVarInt(); + $this->eventData = $in->getRemaining(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->eventId); - $this->buf->put($this->eventData); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->eventId); + $out->put($this->eventData); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/LevelEventPacket.php b/src/network/mcpe/protocol/LevelEventPacket.php index 3c1d8e8a5..27afb8008 100644 --- a/src/network/mcpe/protocol/LevelEventPacket.php +++ b/src/network/mcpe/protocol/LevelEventPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class LevelEventPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::LEVEL_EVENT_PACKET; @@ -133,16 +134,16 @@ class LevelEventPacket extends DataPacket implements ClientboundPacket{ return self::create(self::EVENT_ADD_PARTICLE_MASK | $particleId, $data, $pos); } - protected function decodePayload() : void{ - $this->evid = $this->buf->getVarInt(); - $this->position = $this->buf->getVector3(); - $this->data = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->evid = $in->getVarInt(); + $this->position = $in->getVector3(); + $this->data = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->evid); - $this->buf->putVector3Nullable($this->position); - $this->buf->putVarInt($this->data); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->evid); + $out->putVector3Nullable($this->position); + $out->putVarInt($this->data); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/LevelSoundEventPacket.php b/src/network/mcpe/protocol/LevelSoundEventPacket.php index 86d2631d8..447c55baf 100644 --- a/src/network/mcpe/protocol/LevelSoundEventPacket.php +++ b/src/network/mcpe/protocol/LevelSoundEventPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class LevelSoundEventPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::LEVEL_SOUND_EVENT_PACKET; @@ -335,22 +336,22 @@ class LevelSoundEventPacket extends DataPacket implements ClientboundPacket, Ser /** @var bool */ public $disableRelativeVolume = false; - protected function decodePayload() : void{ - $this->sound = $this->buf->getUnsignedVarInt(); - $this->position = $this->buf->getVector3(); - $this->extraData = $this->buf->getVarInt(); - $this->entityType = $this->buf->getString(); - $this->isBabyMob = $this->buf->getBool(); - $this->disableRelativeVolume = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->sound = $in->getUnsignedVarInt(); + $this->position = $in->getVector3(); + $this->extraData = $in->getVarInt(); + $this->entityType = $in->getString(); + $this->isBabyMob = $in->getBool(); + $this->disableRelativeVolume = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt($this->sound); - $this->buf->putVector3($this->position); - $this->buf->putVarInt($this->extraData); - $this->buf->putString($this->entityType); - $this->buf->putBool($this->isBabyMob); - $this->buf->putBool($this->disableRelativeVolume); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt($this->sound); + $out->putVector3($this->position); + $out->putVarInt($this->extraData); + $out->putString($this->entityType); + $out->putBool($this->isBabyMob); + $out->putBool($this->disableRelativeVolume); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/LevelSoundEventPacketV1.php b/src/network/mcpe/protocol/LevelSoundEventPacketV1.php index cb20f6042..f7b93b19a 100644 --- a/src/network/mcpe/protocol/LevelSoundEventPacketV1.php +++ b/src/network/mcpe/protocol/LevelSoundEventPacketV1.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; /** * Useless leftover from a 1.8 refactor, does nothing @@ -47,22 +48,22 @@ class LevelSoundEventPacketV1 extends DataPacket{ /** @var bool */ public $disableRelativeVolume = false; - protected function decodePayload() : void{ - $this->sound = $this->buf->getByte(); - $this->position = $this->buf->getVector3(); - $this->extraData = $this->buf->getVarInt(); - $this->entityType = $this->buf->getVarInt(); - $this->isBabyMob = $this->buf->getBool(); - $this->disableRelativeVolume = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->sound = $in->getByte(); + $this->position = $in->getVector3(); + $this->extraData = $in->getVarInt(); + $this->entityType = $in->getVarInt(); + $this->isBabyMob = $in->getBool(); + $this->disableRelativeVolume = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putByte($this->sound); - $this->buf->putVector3($this->position); - $this->buf->putVarInt($this->extraData); - $this->buf->putVarInt($this->entityType); - $this->buf->putBool($this->isBabyMob); - $this->buf->putBool($this->disableRelativeVolume); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->sound); + $out->putVector3($this->position); + $out->putVarInt($this->extraData); + $out->putVarInt($this->entityType); + $out->putBool($this->isBabyMob); + $out->putBool($this->disableRelativeVolume); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/LevelSoundEventPacketV2.php b/src/network/mcpe/protocol/LevelSoundEventPacketV2.php index 753f6c9ba..9447523ca 100644 --- a/src/network/mcpe/protocol/LevelSoundEventPacketV2.php +++ b/src/network/mcpe/protocol/LevelSoundEventPacketV2.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; /** * Useless leftover from a 1.9 refactor, does nothing @@ -47,22 +48,22 @@ class LevelSoundEventPacketV2 extends DataPacket{ /** @var bool */ public $disableRelativeVolume = false; - protected function decodePayload() : void{ - $this->sound = $this->buf->getByte(); - $this->position = $this->buf->getVector3(); - $this->extraData = $this->buf->getVarInt(); - $this->entityType = $this->buf->getString(); - $this->isBabyMob = $this->buf->getBool(); - $this->disableRelativeVolume = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->sound = $in->getByte(); + $this->position = $in->getVector3(); + $this->extraData = $in->getVarInt(); + $this->entityType = $in->getString(); + $this->isBabyMob = $in->getBool(); + $this->disableRelativeVolume = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putByte($this->sound); - $this->buf->putVector3($this->position); - $this->buf->putVarInt($this->extraData); - $this->buf->putString($this->entityType); - $this->buf->putBool($this->isBabyMob); - $this->buf->putBool($this->disableRelativeVolume); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->sound); + $out->putVector3($this->position); + $out->putVarInt($this->extraData); + $out->putString($this->entityType); + $out->putBool($this->isBabyMob); + $out->putBool($this->disableRelativeVolume); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/LoginPacket.php b/src/network/mcpe/protocol/LoginPacket.php index 4206694eb..af33b46f6 100644 --- a/src/network/mcpe/protocol/LoginPacket.php +++ b/src/network/mcpe/protocol/LoginPacket.php @@ -28,6 +28,7 @@ namespace pocketmine\network\mcpe\protocol; use Particle\Validator\Validator; use pocketmine\network\BadPacketException; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use pocketmine\utils\BinaryDataException; use pocketmine\utils\BinaryStream; use pocketmine\utils\Utils; @@ -108,9 +109,9 @@ class LoginPacket extends DataPacket implements ServerboundPacket{ return true; } - protected function decodePayload() : void{ - $this->protocol = $this->buf->getInt(); - $this->decodeConnectionRequest(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->protocol = $in->getInt(); + $this->decodeConnectionRequest($in); } /** @@ -133,8 +134,8 @@ class LoginPacket extends DataPacket implements ServerboundPacket{ * @throws BadPacketException * @throws BinaryDataException */ - protected function decodeConnectionRequest() : void{ - $buffer = new BinaryStream($this->buf->getString()); + protected function decodeConnectionRequest(NetworkBinaryStream $in) : void{ + $buffer = new BinaryStream($in->getString()); $chainData = json_decode($buffer->get($buffer->getLInt()), true); if(!is_array($chainData)){ @@ -219,7 +220,7 @@ class LoginPacket extends DataPacket implements ServerboundPacket{ $this->clientData = $clientData; } - protected function encodePayload() : void{ + protected function encodePayload(NetworkBinaryStream $out) : void{ //TODO } diff --git a/src/network/mcpe/protocol/MapCreateLockedCopyPacket.php b/src/network/mcpe/protocol/MapCreateLockedCopyPacket.php index 3405c7b3b..43b1a9718 100644 --- a/src/network/mcpe/protocol/MapCreateLockedCopyPacket.php +++ b/src/network/mcpe/protocol/MapCreateLockedCopyPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class MapCreateLockedCopyPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::MAP_CREATE_LOCKED_COPY_PACKET; @@ -35,14 +36,14 @@ class MapCreateLockedCopyPacket extends DataPacket implements ServerboundPacket{ /** @var int */ public $newMapId; - protected function decodePayload() : void{ - $this->originalMapId = $this->buf->getEntityUniqueId(); - $this->newMapId = $this->buf->getEntityUniqueId(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->originalMapId = $in->getEntityUniqueId(); + $this->newMapId = $in->getEntityUniqueId(); } - protected function encodePayload() : void{ - $this->buf->putEntityUniqueId($this->originalMapId); - $this->buf->putEntityUniqueId($this->newMapId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityUniqueId($this->originalMapId); + $out->putEntityUniqueId($this->newMapId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/MapInfoRequestPacket.php b/src/network/mcpe/protocol/MapInfoRequestPacket.php index 6aa6c2155..bbe8ba7b5 100644 --- a/src/network/mcpe/protocol/MapInfoRequestPacket.php +++ b/src/network/mcpe/protocol/MapInfoRequestPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class MapInfoRequestPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::MAP_INFO_REQUEST_PACKET; @@ -33,12 +34,12 @@ class MapInfoRequestPacket extends DataPacket implements ServerboundPacket{ /** @var int */ public $mapId; - protected function decodePayload() : void{ - $this->mapId = $this->buf->getEntityUniqueId(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->mapId = $in->getEntityUniqueId(); } - protected function encodePayload() : void{ - $this->buf->putEntityUniqueId($this->mapId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityUniqueId($this->mapId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/MobArmorEquipmentPacket.php b/src/network/mcpe/protocol/MobArmorEquipmentPacket.php index d6cffa39b..1d3aba6af 100644 --- a/src/network/mcpe/protocol/MobArmorEquipmentPacket.php +++ b/src/network/mcpe/protocol/MobArmorEquipmentPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\item\Item; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class MobArmorEquipmentPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET; @@ -55,20 +56,20 @@ class MobArmorEquipmentPacket extends DataPacket implements ClientboundPacket, S return $result; } - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->head = $this->buf->getSlot(); - $this->chest = $this->buf->getSlot(); - $this->legs = $this->buf->getSlot(); - $this->feet = $this->buf->getSlot(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->head = $in->getSlot(); + $this->chest = $in->getSlot(); + $this->legs = $in->getSlot(); + $this->feet = $in->getSlot(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putSlot($this->head); - $this->buf->putSlot($this->chest); - $this->buf->putSlot($this->legs); - $this->buf->putSlot($this->feet); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putSlot($this->head); + $out->putSlot($this->chest); + $out->putSlot($this->legs); + $out->putSlot($this->feet); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/MobEffectPacket.php b/src/network/mcpe/protocol/MobEffectPacket.php index 14d29fd77..683a5f2b2 100644 --- a/src/network/mcpe/protocol/MobEffectPacket.php +++ b/src/network/mcpe/protocol/MobEffectPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class MobEffectPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::MOB_EFFECT_PACKET; @@ -66,22 +67,22 @@ class MobEffectPacket extends DataPacket implements ClientboundPacket{ return $pk; } - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->eventId = $this->buf->getByte(); - $this->effectId = $this->buf->getVarInt(); - $this->amplifier = $this->buf->getVarInt(); - $this->particles = $this->buf->getBool(); - $this->duration = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->eventId = $in->getByte(); + $this->effectId = $in->getVarInt(); + $this->amplifier = $in->getVarInt(); + $this->particles = $in->getBool(); + $this->duration = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putByte($this->eventId); - $this->buf->putVarInt($this->effectId); - $this->buf->putVarInt($this->amplifier); - $this->buf->putBool($this->particles); - $this->buf->putVarInt($this->duration); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putByte($this->eventId); + $out->putVarInt($this->effectId); + $out->putVarInt($this->amplifier); + $out->putBool($this->particles); + $out->putVarInt($this->duration); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/MobEquipmentPacket.php b/src/network/mcpe/protocol/MobEquipmentPacket.php index 0393df687..53e87632c 100644 --- a/src/network/mcpe/protocol/MobEquipmentPacket.php +++ b/src/network/mcpe/protocol/MobEquipmentPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\item\Item; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class MobEquipmentPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::MOB_EQUIPMENT_PACKET; @@ -52,20 +53,20 @@ class MobEquipmentPacket extends DataPacket implements ClientboundPacket, Server return $result; } - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->item = $this->buf->getSlot(); - $this->inventorySlot = $this->buf->getByte(); - $this->hotbarSlot = $this->buf->getByte(); - $this->windowId = $this->buf->getByte(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->item = $in->getSlot(); + $this->inventorySlot = $in->getByte(); + $this->hotbarSlot = $in->getByte(); + $this->windowId = $in->getByte(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putSlot($this->item); - $this->buf->putByte($this->inventorySlot); - $this->buf->putByte($this->hotbarSlot); - $this->buf->putByte($this->windowId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putSlot($this->item); + $out->putByte($this->inventorySlot); + $out->putByte($this->hotbarSlot); + $out->putByte($this->windowId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ModalFormRequestPacket.php b/src/network/mcpe/protocol/ModalFormRequestPacket.php index 9f17b7450..6865c8af0 100644 --- a/src/network/mcpe/protocol/ModalFormRequestPacket.php +++ b/src/network/mcpe/protocol/ModalFormRequestPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ModalFormRequestPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::MODAL_FORM_REQUEST_PACKET; @@ -42,14 +43,14 @@ class ModalFormRequestPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->formId = $this->buf->getUnsignedVarInt(); - $this->formData = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->formId = $in->getUnsignedVarInt(); + $this->formData = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt($this->formId); - $this->buf->putString($this->formData); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt($this->formId); + $out->putString($this->formData); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ModalFormResponsePacket.php b/src/network/mcpe/protocol/ModalFormResponsePacket.php index 06af847fe..7f4379ae4 100644 --- a/src/network/mcpe/protocol/ModalFormResponsePacket.php +++ b/src/network/mcpe/protocol/ModalFormResponsePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ModalFormResponsePacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::MODAL_FORM_RESPONSE_PACKET; @@ -35,14 +36,14 @@ class ModalFormResponsePacket extends DataPacket implements ServerboundPacket{ /** @var string */ public $formData; //json - protected function decodePayload() : void{ - $this->formId = $this->buf->getUnsignedVarInt(); - $this->formData = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->formId = $in->getUnsignedVarInt(); + $this->formData = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt($this->formId); - $this->buf->putString($this->formData); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt($this->formId); + $out->putString($this->formData); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/MoveActorAbsolutePacket.php b/src/network/mcpe/protocol/MoveActorAbsolutePacket.php index 566ba2b9d..71d9df47f 100644 --- a/src/network/mcpe/protocol/MoveActorAbsolutePacket.php +++ b/src/network/mcpe/protocol/MoveActorAbsolutePacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class MoveActorAbsolutePacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::MOVE_ACTOR_ABSOLUTE_PACKET; @@ -47,22 +48,22 @@ class MoveActorAbsolutePacket extends DataPacket implements ClientboundPacket, S /** @var float */ public $zRot; - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->flags = $this->buf->getByte(); - $this->position = $this->buf->getVector3(); - $this->xRot = $this->buf->getByteRotation(); - $this->yRot = $this->buf->getByteRotation(); - $this->zRot = $this->buf->getByteRotation(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->flags = $in->getByte(); + $this->position = $in->getVector3(); + $this->xRot = $in->getByteRotation(); + $this->yRot = $in->getByteRotation(); + $this->zRot = $in->getByteRotation(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putByte($this->flags); - $this->buf->putVector3($this->position); - $this->buf->putByteRotation($this->xRot); - $this->buf->putByteRotation($this->yRot); - $this->buf->putByteRotation($this->zRot); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putByte($this->flags); + $out->putVector3($this->position); + $out->putByteRotation($this->xRot); + $out->putByteRotation($this->yRot); + $out->putByteRotation($this->zRot); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/MoveActorDeltaPacket.php b/src/network/mcpe/protocol/MoveActorDeltaPacket.php index d252baf8e..5ea13f2b6 100644 --- a/src/network/mcpe/protocol/MoveActorDeltaPacket.php +++ b/src/network/mcpe/protocol/MoveActorDeltaPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use pocketmine\utils\BinaryDataException; class MoveActorDeltaPacket extends DataPacket implements ClientboundPacket{ @@ -58,9 +59,9 @@ class MoveActorDeltaPacket extends DataPacket implements ClientboundPacket{ /** * @throws BinaryDataException */ - private function maybeReadCoord(int $flag) : int{ + private function maybeReadCoord(int $flag, NetworkBinaryStream $in) : int{ if(($this->flags & $flag) !== 0){ - return $this->buf->getVarInt(); + return $in->getVarInt(); } return 0; } @@ -68,45 +69,45 @@ class MoveActorDeltaPacket extends DataPacket implements ClientboundPacket{ /** * @throws BinaryDataException */ - private function maybeReadRotation(int $flag) : float{ + private function maybeReadRotation(int $flag, NetworkBinaryStream $in) : float{ if(($this->flags & $flag) !== 0){ - return $this->buf->getByteRotation(); + return $in->getByteRotation(); } return 0.0; } - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->flags = $this->buf->getLShort(); - $this->xDiff = $this->maybeReadCoord(self::FLAG_HAS_X); - $this->yDiff = $this->maybeReadCoord(self::FLAG_HAS_Y); - $this->zDiff = $this->maybeReadCoord(self::FLAG_HAS_Z); - $this->xRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_X); - $this->yRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_Y); - $this->zRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_Z); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->flags = $in->getLShort(); + $this->xDiff = $this->maybeReadCoord(self::FLAG_HAS_X, $in); + $this->yDiff = $this->maybeReadCoord(self::FLAG_HAS_Y, $in); + $this->zDiff = $this->maybeReadCoord(self::FLAG_HAS_Z, $in); + $this->xRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_X, $in); + $this->yRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_Y, $in); + $this->zRot = $this->maybeReadRotation(self::FLAG_HAS_ROT_Z, $in); } - private function maybeWriteCoord(int $flag, int $val) : void{ + private function maybeWriteCoord(int $flag, int $val, NetworkBinaryStream $out) : void{ if(($this->flags & $flag) !== 0){ - $this->buf->putVarInt($val); + $out->putVarInt($val); } } - private function maybeWriteRotation(int $flag, float $val) : void{ + private function maybeWriteRotation(int $flag, float $val, NetworkBinaryStream $out) : void{ if(($this->flags & $flag) !== 0){ - $this->buf->putByteRotation($val); + $out->putByteRotation($val); } } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putLShort($this->flags); - $this->maybeWriteCoord(self::FLAG_HAS_X, $this->xDiff); - $this->maybeWriteCoord(self::FLAG_HAS_Y, $this->yDiff); - $this->maybeWriteCoord(self::FLAG_HAS_Z, $this->zDiff); - $this->maybeWriteRotation(self::FLAG_HAS_ROT_X, $this->xRot); - $this->maybeWriteRotation(self::FLAG_HAS_ROT_Y, $this->yRot); - $this->maybeWriteRotation(self::FLAG_HAS_ROT_Z, $this->zRot); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putLShort($this->flags); + $this->maybeWriteCoord(self::FLAG_HAS_X, $this->xDiff, $out); + $this->maybeWriteCoord(self::FLAG_HAS_Y, $this->yDiff, $out); + $this->maybeWriteCoord(self::FLAG_HAS_Z, $this->zDiff, $out); + $this->maybeWriteRotation(self::FLAG_HAS_ROT_X, $this->xRot, $out); + $this->maybeWriteRotation(self::FLAG_HAS_ROT_Y, $this->yRot, $out); + $this->maybeWriteRotation(self::FLAG_HAS_ROT_Z, $this->zRot, $out); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/MovePlayerPacket.php b/src/network/mcpe/protocol/MovePlayerPacket.php index 3c42186a2..05a79649b 100644 --- a/src/network/mcpe/protocol/MovePlayerPacket.php +++ b/src/network/mcpe/protocol/MovePlayerPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class MovePlayerPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::MOVE_PLAYER_PACKET; @@ -57,33 +58,33 @@ class MovePlayerPacket extends DataPacket implements ClientboundPacket, Serverbo /** @var int */ public $teleportItem = 0; - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->position = $this->buf->getVector3(); - $this->pitch = $this->buf->getLFloat(); - $this->yaw = $this->buf->getLFloat(); - $this->headYaw = $this->buf->getLFloat(); - $this->mode = $this->buf->getByte(); - $this->onGround = $this->buf->getBool(); - $this->ridingEid = $this->buf->getEntityRuntimeId(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->position = $in->getVector3(); + $this->pitch = $in->getLFloat(); + $this->yaw = $in->getLFloat(); + $this->headYaw = $in->getLFloat(); + $this->mode = $in->getByte(); + $this->onGround = $in->getBool(); + $this->ridingEid = $in->getEntityRuntimeId(); if($this->mode === MovePlayerPacket::MODE_TELEPORT){ - $this->teleportCause = $this->buf->getLInt(); - $this->teleportItem = $this->buf->getLInt(); + $this->teleportCause = $in->getLInt(); + $this->teleportItem = $in->getLInt(); } } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putVector3($this->position); - $this->buf->putLFloat($this->pitch); - $this->buf->putLFloat($this->yaw); - $this->buf->putLFloat($this->headYaw); //TODO - $this->buf->putByte($this->mode); - $this->buf->putBool($this->onGround); - $this->buf->putEntityRuntimeId($this->ridingEid); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putVector3($this->position); + $out->putLFloat($this->pitch); + $out->putLFloat($this->yaw); + $out->putLFloat($this->headYaw); //TODO + $out->putByte($this->mode); + $out->putBool($this->onGround); + $out->putEntityRuntimeId($this->ridingEid); if($this->mode === MovePlayerPacket::MODE_TELEPORT){ - $this->buf->putLInt($this->teleportCause); - $this->buf->putLInt($this->teleportItem); + $out->putLInt($this->teleportCause); + $out->putLInt($this->teleportItem); } } diff --git a/src/network/mcpe/protocol/MultiplayerSettingsPacket.php b/src/network/mcpe/protocol/MultiplayerSettingsPacket.php index 7b59c8a8a..2fb6f692c 100644 --- a/src/network/mcpe/protocol/MultiplayerSettingsPacket.php +++ b/src/network/mcpe/protocol/MultiplayerSettingsPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class MultiplayerSettingsPacket extends DataPacket implements ServerboundPacket{ //TODO: this might be clientbound too, but unsure public const NETWORK_ID = ProtocolInfo::MULTIPLAYER_SETTINGS_PACKET; @@ -47,12 +48,12 @@ class MultiplayerSettingsPacket extends DataPacket implements ServerboundPacket{ return $this->action; } - protected function decodePayload() : void{ - $this->action = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->action = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->action); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->action); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/NetworkChunkPublisherUpdatePacket.php b/src/network/mcpe/protocol/NetworkChunkPublisherUpdatePacket.php index 0fccd283a..92b9b1df4 100644 --- a/src/network/mcpe/protocol/NetworkChunkPublisherUpdatePacket.php +++ b/src/network/mcpe/protocol/NetworkChunkPublisherUpdatePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class NetworkChunkPublisherUpdatePacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::NETWORK_CHUNK_PUBLISHER_UPDATE_PACKET; @@ -48,14 +49,14 @@ class NetworkChunkPublisherUpdatePacket extends DataPacket implements Clientboun return $result; } - protected function decodePayload() : void{ - $this->buf->getSignedBlockPosition($this->x, $this->y, $this->z); - $this->radius = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $in->getSignedBlockPosition($this->x, $this->y, $this->z); + $this->radius = $in->getUnsignedVarInt(); } - protected function encodePayload() : void{ - $this->buf->putSignedBlockPosition($this->x, $this->y, $this->z); - $this->buf->putUnsignedVarInt($this->radius); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putSignedBlockPosition($this->x, $this->y, $this->z); + $out->putUnsignedVarInt($this->radius); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/NetworkSettingsPacket.php b/src/network/mcpe/protocol/NetworkSettingsPacket.php index 7d1096eb4..40b387320 100644 --- a/src/network/mcpe/protocol/NetworkSettingsPacket.php +++ b/src/network/mcpe/protocol/NetworkSettingsPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class NetworkSettingsPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::NETWORK_SETTINGS_PACKET; @@ -46,12 +47,12 @@ class NetworkSettingsPacket extends DataPacket implements ClientboundPacket{ return $this->compressionThreshold; } - protected function decodePayload() : void{ - $this->compressionThreshold = $this->buf->getLShort(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->compressionThreshold = $in->getLShort(); } - protected function encodePayload() : void{ - $this->buf->putLShort($this->compressionThreshold); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putLShort($this->compressionThreshold); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/NetworkStackLatencyPacket.php b/src/network/mcpe/protocol/NetworkStackLatencyPacket.php index 327303c6e..ce1459d94 100644 --- a/src/network/mcpe/protocol/NetworkStackLatencyPacket.php +++ b/src/network/mcpe/protocol/NetworkStackLatencyPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class NetworkStackLatencyPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::NETWORK_STACK_LATENCY_PACKET; @@ -35,14 +36,14 @@ class NetworkStackLatencyPacket extends DataPacket implements ClientboundPacket, /** @var bool */ public $needResponse; - protected function decodePayload() : void{ - $this->timestamp = $this->buf->getLLong(); - $this->needResponse = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->timestamp = $in->getLLong(); + $this->needResponse = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putLLong($this->timestamp); - $this->buf->putBool($this->needResponse); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putLLong($this->timestamp); + $out->putBool($this->needResponse); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/NpcRequestPacket.php b/src/network/mcpe/protocol/NpcRequestPacket.php index d01c71d83..26b11eacb 100644 --- a/src/network/mcpe/protocol/NpcRequestPacket.php +++ b/src/network/mcpe/protocol/NpcRequestPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class NpcRequestPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::NPC_REQUEST_PACKET; @@ -39,18 +40,18 @@ class NpcRequestPacket extends DataPacket implements ServerboundPacket{ /** @var int */ public $actionType; - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->requestType = $this->buf->getByte(); - $this->commandString = $this->buf->getString(); - $this->actionType = $this->buf->getByte(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->requestType = $in->getByte(); + $this->commandString = $in->getString(); + $this->actionType = $in->getByte(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putByte($this->requestType); - $this->buf->putString($this->commandString); - $this->buf->putByte($this->actionType); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putByte($this->requestType); + $out->putString($this->commandString); + $out->putByte($this->actionType); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/OnScreenTextureAnimationPacket.php b/src/network/mcpe/protocol/OnScreenTextureAnimationPacket.php index 0aaf2b218..0a2565623 100644 --- a/src/network/mcpe/protocol/OnScreenTextureAnimationPacket.php +++ b/src/network/mcpe/protocol/OnScreenTextureAnimationPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class OnScreenTextureAnimationPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::ON_SCREEN_TEXTURE_ANIMATION_PACKET; @@ -33,12 +34,12 @@ class OnScreenTextureAnimationPacket extends DataPacket implements ClientboundPa /** @var int */ public $effectId; - protected function decodePayload() : void{ - $this->effectId = $this->buf->getLInt(); //unsigned + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->effectId = $in->getLInt(); //unsigned } - protected function encodePayload() : void{ - $this->buf->putLInt($this->effectId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putLInt($this->effectId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/PhotoTransferPacket.php b/src/network/mcpe/protocol/PhotoTransferPacket.php index a08c56ead..5e04ed441 100644 --- a/src/network/mcpe/protocol/PhotoTransferPacket.php +++ b/src/network/mcpe/protocol/PhotoTransferPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class PhotoTransferPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::PHOTO_TRANSFER_PACKET; @@ -37,16 +38,16 @@ class PhotoTransferPacket extends DataPacket implements ClientboundPacket{ /** @var string */ public $bookId; //photos are stored in a sibling directory to the games folder (screenshots/(some UUID)/bookID/example.png) - protected function decodePayload() : void{ - $this->photoName = $this->buf->getString(); - $this->photoData = $this->buf->getString(); - $this->bookId = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->photoName = $in->getString(); + $this->photoData = $in->getString(); + $this->bookId = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putString($this->photoName); - $this->buf->putString($this->photoData); - $this->buf->putString($this->bookId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->photoName); + $out->putString($this->photoData); + $out->putString($this->bookId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/PlaySoundPacket.php b/src/network/mcpe/protocol/PlaySoundPacket.php index e90f1f403..f59cd463c 100644 --- a/src/network/mcpe/protocol/PlaySoundPacket.php +++ b/src/network/mcpe/protocol/PlaySoundPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class PlaySoundPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::PLAY_SOUND_PACKET; @@ -43,21 +44,21 @@ class PlaySoundPacket extends DataPacket implements ClientboundPacket{ /** @var float */ public $pitch; - protected function decodePayload() : void{ - $this->soundName = $this->buf->getString(); - $this->buf->getBlockPosition($this->x, $this->y, $this->z); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->soundName = $in->getString(); + $in->getBlockPosition($this->x, $this->y, $this->z); $this->x /= 8; $this->y /= 8; $this->z /= 8; - $this->volume = $this->buf->getLFloat(); - $this->pitch = $this->buf->getLFloat(); + $this->volume = $in->getLFloat(); + $this->pitch = $in->getLFloat(); } - protected function encodePayload() : void{ - $this->buf->putString($this->soundName); - $this->buf->putBlockPosition((int) ($this->x * 8), (int) ($this->y * 8), (int) ($this->z * 8)); - $this->buf->putLFloat($this->volume); - $this->buf->putLFloat($this->pitch); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->soundName); + $out->putBlockPosition((int) ($this->x * 8), (int) ($this->y * 8), (int) ($this->z * 8)); + $out->putLFloat($this->volume); + $out->putLFloat($this->pitch); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/PlayStatusPacket.php b/src/network/mcpe/protocol/PlayStatusPacket.php index b0f88740d..76f3a5481 100644 --- a/src/network/mcpe/protocol/PlayStatusPacket.php +++ b/src/network/mcpe/protocol/PlayStatusPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class PlayStatusPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::PLAY_STATUS_PACKET; @@ -48,16 +49,16 @@ class PlayStatusPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->status = $this->buf->getInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->status = $in->getInt(); } public function canBeSentBeforeLogin() : bool{ return true; } - protected function encodePayload() : void{ - $this->buf->putInt($this->status); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putInt($this->status); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/PlayerActionPacket.php b/src/network/mcpe/protocol/PlayerActionPacket.php index 2985a206e..d3593289b 100644 --- a/src/network/mcpe/protocol/PlayerActionPacket.php +++ b/src/network/mcpe/protocol/PlayerActionPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class PlayerActionPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::PLAYER_ACTION_PACKET; @@ -70,18 +71,18 @@ class PlayerActionPacket extends DataPacket implements ServerboundPacket{ /** @var int */ public $face; - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->action = $this->buf->getVarInt(); - $this->buf->getBlockPosition($this->x, $this->y, $this->z); - $this->face = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->action = $in->getVarInt(); + $in->getBlockPosition($this->x, $this->y, $this->z); + $this->face = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putVarInt($this->action); - $this->buf->putBlockPosition($this->x, $this->y, $this->z); - $this->buf->putVarInt($this->face); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putVarInt($this->action); + $out->putBlockPosition($this->x, $this->y, $this->z); + $out->putVarInt($this->face); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/PlayerAuthInputPacket.php b/src/network/mcpe/protocol/PlayerAuthInputPacket.php index 12fdcc80b..5fd9d8fd2 100644 --- a/src/network/mcpe/protocol/PlayerAuthInputPacket.php +++ b/src/network/mcpe/protocol/PlayerAuthInputPacket.php @@ -29,6 +29,7 @@ use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\InputMode; use pocketmine\network\mcpe\protocol\types\PlayMode; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function assert; class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{ @@ -127,34 +128,34 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{ return $this->vrGazeDirection; } - protected function decodePayload() : void{ - $this->yaw = $this->buf->getLFloat(); - $this->pitch = $this->buf->getLFloat(); - $this->position = $this->buf->getVector3(); - $this->moveVecX = $this->buf->getLFloat(); - $this->moveVecZ = $this->buf->getLFloat(); - $this->headYaw = $this->buf->getLFloat(); - $this->inputFlags = $this->buf->getUnsignedVarLong(); - $this->inputMode = $this->buf->getUnsignedVarInt(); - $this->playMode = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->yaw = $in->getLFloat(); + $this->pitch = $in->getLFloat(); + $this->position = $in->getVector3(); + $this->moveVecX = $in->getLFloat(); + $this->moveVecZ = $in->getLFloat(); + $this->headYaw = $in->getLFloat(); + $this->inputFlags = $in->getUnsignedVarLong(); + $this->inputMode = $in->getUnsignedVarInt(); + $this->playMode = $in->getUnsignedVarInt(); if($this->playMode === PlayMode::VR){ - $this->vrGazeDirection = $this->buf->getVector3(); + $this->vrGazeDirection = $in->getVector3(); } } - protected function encodePayload() : void{ - $this->buf->putLFloat($this->yaw); - $this->buf->putLFloat($this->pitch); - $this->buf->putVector3($this->position); - $this->buf->putLFloat($this->moveVecX); - $this->buf->putLFloat($this->moveVecZ); - $this->buf->putLFloat($this->headYaw); - $this->buf->putUnsignedVarLong($this->inputFlags); - $this->buf->putUnsignedVarInt($this->inputMode); - $this->buf->putUnsignedVarInt($this->playMode); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putLFloat($this->yaw); + $out->putLFloat($this->pitch); + $out->putVector3($this->position); + $out->putLFloat($this->moveVecX); + $out->putLFloat($this->moveVecZ); + $out->putLFloat($this->headYaw); + $out->putUnsignedVarLong($this->inputFlags); + $out->putUnsignedVarInt($this->inputMode); + $out->putUnsignedVarInt($this->playMode); if($this->playMode === PlayMode::VR){ assert($this->vrGazeDirection !== null); - $this->buf->putVector3($this->vrGazeDirection); + $out->putVector3($this->vrGazeDirection); } } diff --git a/src/network/mcpe/protocol/PlayerHotbarPacket.php b/src/network/mcpe/protocol/PlayerHotbarPacket.php index e5bd9f2d1..36f10aa43 100644 --- a/src/network/mcpe/protocol/PlayerHotbarPacket.php +++ b/src/network/mcpe/protocol/PlayerHotbarPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\inventory\ContainerIds; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class PlayerHotbarPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::PLAYER_HOTBAR_PACKET; @@ -46,16 +47,16 @@ class PlayerHotbarPacket extends DataPacket implements ClientboundPacket, Server return $result; } - protected function decodePayload() : void{ - $this->selectedHotbarSlot = $this->buf->getUnsignedVarInt(); - $this->windowId = $this->buf->getByte(); - $this->selectHotbarSlot = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->selectedHotbarSlot = $in->getUnsignedVarInt(); + $this->windowId = $in->getByte(); + $this->selectHotbarSlot = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt($this->selectedHotbarSlot); - $this->buf->putByte($this->windowId); - $this->buf->putBool($this->selectHotbarSlot); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt($this->selectedHotbarSlot); + $out->putByte($this->windowId); + $out->putBool($this->selectHotbarSlot); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/PlayerInputPacket.php b/src/network/mcpe/protocol/PlayerInputPacket.php index f74da921e..c7446fcc5 100644 --- a/src/network/mcpe/protocol/PlayerInputPacket.php +++ b/src/network/mcpe/protocol/PlayerInputPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class PlayerInputPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::PLAYER_INPUT_PACKET; @@ -39,18 +40,18 @@ class PlayerInputPacket extends DataPacket implements ServerboundPacket{ /** @var bool */ public $sneaking; - protected function decodePayload() : void{ - $this->motionX = $this->buf->getLFloat(); - $this->motionY = $this->buf->getLFloat(); - $this->jumping = $this->buf->getBool(); - $this->sneaking = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->motionX = $in->getLFloat(); + $this->motionY = $in->getLFloat(); + $this->jumping = $in->getBool(); + $this->sneaking = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putLFloat($this->motionX); - $this->buf->putLFloat($this->motionY); - $this->buf->putBool($this->jumping); - $this->buf->putBool($this->sneaking); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putLFloat($this->motionX); + $out->putLFloat($this->motionY); + $out->putBool($this->jumping); + $out->putBool($this->sneaking); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/PlayerListPacket.php b/src/network/mcpe/protocol/PlayerListPacket.php index 068f68b0f..f23d40bac 100644 --- a/src/network/mcpe/protocol/PlayerListPacket.php +++ b/src/network/mcpe/protocol/PlayerListPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\PlayerListEntry; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function count; class PlayerListPacket extends DataPacket implements ClientboundPacket{ @@ -60,46 +61,46 @@ class PlayerListPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->type = $this->buf->getByte(); - $count = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->type = $in->getByte(); + $count = $in->getUnsignedVarInt(); for($i = 0; $i < $count; ++$i){ $entry = new PlayerListEntry(); if($this->type === self::TYPE_ADD){ - $entry->uuid = $this->buf->getUUID(); - $entry->entityUniqueId = $this->buf->getEntityUniqueId(); - $entry->username = $this->buf->getString(); - $entry->xboxUserId = $this->buf->getString(); - $entry->platformChatId = $this->buf->getString(); - $entry->buildPlatform = $this->buf->getLInt(); - $entry->skinData = $this->buf->getSkin(); - $entry->isTeacher = $this->buf->getBool(); - $entry->isHost = $this->buf->getBool(); + $entry->uuid = $in->getUUID(); + $entry->entityUniqueId = $in->getEntityUniqueId(); + $entry->username = $in->getString(); + $entry->xboxUserId = $in->getString(); + $entry->platformChatId = $in->getString(); + $entry->buildPlatform = $in->getLInt(); + $entry->skinData = $in->getSkin(); + $entry->isTeacher = $in->getBool(); + $entry->isHost = $in->getBool(); }else{ - $entry->uuid = $this->buf->getUUID(); + $entry->uuid = $in->getUUID(); } $this->entries[$i] = $entry; } } - protected function encodePayload() : void{ - $this->buf->putByte($this->type); - $this->buf->putUnsignedVarInt(count($this->entries)); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->type); + $out->putUnsignedVarInt(count($this->entries)); foreach($this->entries as $entry){ if($this->type === self::TYPE_ADD){ - $this->buf->putUUID($entry->uuid); - $this->buf->putEntityUniqueId($entry->entityUniqueId); - $this->buf->putString($entry->username); - $this->buf->putString($entry->xboxUserId); - $this->buf->putString($entry->platformChatId); - $this->buf->putLInt($entry->buildPlatform); - $this->buf->putSkin($entry->skinData); - $this->buf->putBool($entry->isTeacher); - $this->buf->putBool($entry->isHost); + $out->putUUID($entry->uuid); + $out->putEntityUniqueId($entry->entityUniqueId); + $out->putString($entry->username); + $out->putString($entry->xboxUserId); + $out->putString($entry->platformChatId); + $out->putLInt($entry->buildPlatform); + $out->putSkin($entry->skinData); + $out->putBool($entry->isTeacher); + $out->putBool($entry->isHost); }else{ - $this->buf->putUUID($entry->uuid); + $out->putUUID($entry->uuid); } } } diff --git a/src/network/mcpe/protocol/PlayerSkinPacket.php b/src/network/mcpe/protocol/PlayerSkinPacket.php index cefa9fbc8..2b66aa4dd 100644 --- a/src/network/mcpe/protocol/PlayerSkinPacket.php +++ b/src/network/mcpe/protocol/PlayerSkinPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\SkinData; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use pocketmine\utils\UUID; class PlayerSkinPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ @@ -41,18 +42,18 @@ class PlayerSkinPacket extends DataPacket implements ClientboundPacket, Serverbo /** @var SkinData */ public $skin; - protected function decodePayload() : void{ - $this->uuid = $this->buf->getUUID(); - $this->skin = $this->buf->getSkin(); - $this->newSkinName = $this->buf->getString(); - $this->oldSkinName = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->uuid = $in->getUUID(); + $this->skin = $in->getSkin(); + $this->newSkinName = $in->getString(); + $this->oldSkinName = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putUUID($this->uuid); - $this->buf->putSkin($this->skin); - $this->buf->putString($this->newSkinName); - $this->buf->putString($this->oldSkinName); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUUID($this->uuid); + $out->putSkin($this->skin); + $out->putString($this->newSkinName); + $out->putString($this->oldSkinName); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/PurchaseReceiptPacket.php b/src/network/mcpe/protocol/PurchaseReceiptPacket.php index 3d7fdc310..608335372 100644 --- a/src/network/mcpe/protocol/PurchaseReceiptPacket.php +++ b/src/network/mcpe/protocol/PurchaseReceiptPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function count; class PurchaseReceiptPacket extends DataPacket implements ServerboundPacket{ @@ -34,17 +35,17 @@ class PurchaseReceiptPacket extends DataPacket implements ServerboundPacket{ /** @var string[] */ public $entries = []; - protected function decodePayload() : void{ - $count = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $count = $in->getUnsignedVarInt(); for($i = 0; $i < $count; ++$i){ - $this->entries[] = $this->buf->getString(); + $this->entries[] = $in->getString(); } } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt(count($this->entries)); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt(count($this->entries)); foreach($this->entries as $entry){ - $this->buf->putString($entry); + $out->putString($entry); } } diff --git a/src/network/mcpe/protocol/RemoveActorPacket.php b/src/network/mcpe/protocol/RemoveActorPacket.php index 991fac064..276460f94 100644 --- a/src/network/mcpe/protocol/RemoveActorPacket.php +++ b/src/network/mcpe/protocol/RemoveActorPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class RemoveActorPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::REMOVE_ACTOR_PACKET; @@ -39,12 +40,12 @@ class RemoveActorPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->entityUniqueId = $this->buf->getEntityUniqueId(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityUniqueId = $in->getEntityUniqueId(); } - protected function encodePayload() : void{ - $this->buf->putEntityUniqueId($this->entityUniqueId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityUniqueId($this->entityUniqueId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/RemoveEntityPacket.php b/src/network/mcpe/protocol/RemoveEntityPacket.php index 2c26a1c35..e04182cd6 100644 --- a/src/network/mcpe/protocol/RemoveEntityPacket.php +++ b/src/network/mcpe/protocol/RemoveEntityPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class RemoveEntityPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::REMOVE_ENTITY_PACKET; @@ -43,12 +44,12 @@ class RemoveEntityPacket extends DataPacket implements ClientboundPacket{ return $this->uvarint1; } - protected function decodePayload() : void{ - $this->uvarint1 = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->uvarint1 = $in->getUnsignedVarInt(); } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt($this->uvarint1); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt($this->uvarint1); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/RemoveObjectivePacket.php b/src/network/mcpe/protocol/RemoveObjectivePacket.php index c44291daf..c05f118ad 100644 --- a/src/network/mcpe/protocol/RemoveObjectivePacket.php +++ b/src/network/mcpe/protocol/RemoveObjectivePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class RemoveObjectivePacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::REMOVE_OBJECTIVE_PACKET; @@ -33,12 +34,12 @@ class RemoveObjectivePacket extends DataPacket implements ClientboundPacket{ /** @var string */ public $objectiveName; - protected function decodePayload() : void{ - $this->objectiveName = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->objectiveName = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putString($this->objectiveName); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->objectiveName); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/RequestChunkRadiusPacket.php b/src/network/mcpe/protocol/RequestChunkRadiusPacket.php index 57b38afa6..2d669fa30 100644 --- a/src/network/mcpe/protocol/RequestChunkRadiusPacket.php +++ b/src/network/mcpe/protocol/RequestChunkRadiusPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class RequestChunkRadiusPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::REQUEST_CHUNK_RADIUS_PACKET; @@ -33,12 +34,12 @@ class RequestChunkRadiusPacket extends DataPacket implements ServerboundPacket{ /** @var int */ public $radius; - protected function decodePayload() : void{ - $this->radius = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->radius = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->radius); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->radius); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ResourcePackChunkDataPacket.php b/src/network/mcpe/protocol/ResourcePackChunkDataPacket.php index a2adbe838..26dee397a 100644 --- a/src/network/mcpe/protocol/ResourcePackChunkDataPacket.php +++ b/src/network/mcpe/protocol/ResourcePackChunkDataPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function strlen; class ResourcePackChunkDataPacket extends DataPacket implements ClientboundPacket{ @@ -49,18 +50,18 @@ class ResourcePackChunkDataPacket extends DataPacket implements ClientboundPacke return $result; } - protected function decodePayload() : void{ - $this->packId = $this->buf->getString(); - $this->chunkIndex = $this->buf->getLInt(); - $this->progress = $this->buf->getLLong(); - $this->data = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->packId = $in->getString(); + $this->chunkIndex = $in->getLInt(); + $this->progress = $in->getLLong(); + $this->data = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putString($this->packId); - $this->buf->putLInt($this->chunkIndex); - $this->buf->putLLong($this->progress); - $this->buf->putString($this->data); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->packId); + $out->putLInt($this->chunkIndex); + $out->putLLong($this->progress); + $out->putString($this->data); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ResourcePackChunkRequestPacket.php b/src/network/mcpe/protocol/ResourcePackChunkRequestPacket.php index e90154bcd..a8004ac10 100644 --- a/src/network/mcpe/protocol/ResourcePackChunkRequestPacket.php +++ b/src/network/mcpe/protocol/ResourcePackChunkRequestPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ResourcePackChunkRequestPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CHUNK_REQUEST_PACKET; @@ -35,14 +36,14 @@ class ResourcePackChunkRequestPacket extends DataPacket implements ServerboundPa /** @var int */ public $chunkIndex; - protected function decodePayload() : void{ - $this->packId = $this->buf->getString(); - $this->chunkIndex = $this->buf->getLInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->packId = $in->getString(); + $this->chunkIndex = $in->getLInt(); } - protected function encodePayload() : void{ - $this->buf->putString($this->packId); - $this->buf->putLInt($this->chunkIndex); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->packId); + $out->putLInt($this->chunkIndex); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ResourcePackClientResponsePacket.php b/src/network/mcpe/protocol/ResourcePackClientResponsePacket.php index ca4b19363..246a5924a 100644 --- a/src/network/mcpe/protocol/ResourcePackClientResponsePacket.php +++ b/src/network/mcpe/protocol/ResourcePackClientResponsePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function count; class ResourcePackClientResponsePacket extends DataPacket implements ServerboundPacket{ @@ -41,19 +42,19 @@ class ResourcePackClientResponsePacket extends DataPacket implements Serverbound /** @var string[] */ public $packIds = []; - protected function decodePayload() : void{ - $this->status = $this->buf->getByte(); - $entryCount = $this->buf->getLShort(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->status = $in->getByte(); + $entryCount = $in->getLShort(); while($entryCount-- > 0){ - $this->packIds[] = $this->buf->getString(); + $this->packIds[] = $in->getString(); } } - protected function encodePayload() : void{ - $this->buf->putByte($this->status); - $this->buf->putLShort(count($this->packIds)); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->status); + $out->putLShort(count($this->packIds)); foreach($this->packIds as $id){ - $this->buf->putString($id); + $out->putString($id); } } diff --git a/src/network/mcpe/protocol/ResourcePackDataInfoPacket.php b/src/network/mcpe/protocol/ResourcePackDataInfoPacket.php index f8066dcc1..fa3b8816e 100644 --- a/src/network/mcpe/protocol/ResourcePackDataInfoPacket.php +++ b/src/network/mcpe/protocol/ResourcePackDataInfoPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\resourcepacks\ResourcePackType; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ResourcePackDataInfoPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_DATA_INFO_PACKET; @@ -56,24 +57,24 @@ class ResourcePackDataInfoPacket extends DataPacket implements ClientboundPacket return $result; } - protected function decodePayload() : void{ - $this->packId = $this->buf->getString(); - $this->maxChunkSize = $this->buf->getLInt(); - $this->chunkCount = $this->buf->getLInt(); - $this->compressedPackSize = $this->buf->getLLong(); - $this->sha256 = $this->buf->getString(); - $this->isPremium = $this->buf->getBool(); - $this->packType = $this->buf->getByte(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->packId = $in->getString(); + $this->maxChunkSize = $in->getLInt(); + $this->chunkCount = $in->getLInt(); + $this->compressedPackSize = $in->getLLong(); + $this->sha256 = $in->getString(); + $this->isPremium = $in->getBool(); + $this->packType = $in->getByte(); } - protected function encodePayload() : void{ - $this->buf->putString($this->packId); - $this->buf->putLInt($this->maxChunkSize); - $this->buf->putLInt($this->chunkCount); - $this->buf->putLLong($this->compressedPackSize); - $this->buf->putString($this->sha256); - $this->buf->putBool($this->isPremium); - $this->buf->putByte($this->packType); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->packId); + $out->putLInt($this->maxChunkSize); + $out->putLInt($this->chunkCount); + $out->putLLong($this->compressedPackSize); + $out->putString($this->sha256); + $out->putBool($this->isPremium); + $out->putByte($this->packType); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ResourcePackStackPacket.php b/src/network/mcpe/protocol/ResourcePackStackPacket.php index f424fe8b5..89f85738e 100644 --- a/src/network/mcpe/protocol/ResourcePackStackPacket.php +++ b/src/network/mcpe/protocol/ResourcePackStackPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\resourcepacks\ResourcePackStackEntry; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function count; class ResourcePackStackPacket extends DataPacket implements ClientboundPacket{ @@ -60,37 +61,37 @@ class ResourcePackStackPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->mustAccept = $this->buf->getBool(); - $behaviorPackCount = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->mustAccept = $in->getBool(); + $behaviorPackCount = $in->getUnsignedVarInt(); while($behaviorPackCount-- > 0){ - $this->behaviorPackStack[] = ResourcePackStackEntry::read($this->buf); + $this->behaviorPackStack[] = ResourcePackStackEntry::read($in); } - $resourcePackCount = $this->buf->getUnsignedVarInt(); + $resourcePackCount = $in->getUnsignedVarInt(); while($resourcePackCount-- > 0){ - $this->resourcePackStack[] = ResourcePackStackEntry::read($this->buf); + $this->resourcePackStack[] = ResourcePackStackEntry::read($in); } - $this->isExperimental = $this->buf->getBool(); - $this->baseGameVersion = $this->buf->getString(); + $this->isExperimental = $in->getBool(); + $this->baseGameVersion = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putBool($this->mustAccept); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putBool($this->mustAccept); - $this->buf->putUnsignedVarInt(count($this->behaviorPackStack)); + $out->putUnsignedVarInt(count($this->behaviorPackStack)); foreach($this->behaviorPackStack as $entry){ - $entry->write($this->buf); + $entry->write($out); } - $this->buf->putUnsignedVarInt(count($this->resourcePackStack)); + $out->putUnsignedVarInt(count($this->resourcePackStack)); foreach($this->resourcePackStack as $entry){ - $entry->write($this->buf); + $entry->write($out); } - $this->buf->putBool($this->isExperimental); - $this->buf->putString($this->baseGameVersion); + $out->putBool($this->isExperimental); + $out->putString($this->baseGameVersion); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ResourcePacksInfoPacket.php b/src/network/mcpe/protocol/ResourcePacksInfoPacket.php index a0acc7586..a187a4db7 100644 --- a/src/network/mcpe/protocol/ResourcePacksInfoPacket.php +++ b/src/network/mcpe/protocol/ResourcePacksInfoPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\resourcepacks\ResourcePackInfoEntry; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function count; class ResourcePacksInfoPacket extends DataPacket implements ClientboundPacket{ @@ -56,30 +57,30 @@ class ResourcePacksInfoPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->mustAccept = $this->buf->getBool(); - $this->hasScripts = $this->buf->getBool(); - $behaviorPackCount = $this->buf->getLShort(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->mustAccept = $in->getBool(); + $this->hasScripts = $in->getBool(); + $behaviorPackCount = $in->getLShort(); while($behaviorPackCount-- > 0){ - $this->behaviorPackEntries[] = ResourcePackInfoEntry::read($this->buf); + $this->behaviorPackEntries[] = ResourcePackInfoEntry::read($in); } - $resourcePackCount = $this->buf->getLShort(); + $resourcePackCount = $in->getLShort(); while($resourcePackCount-- > 0){ - $this->resourcePackEntries[] = ResourcePackInfoEntry::read($this->buf); + $this->resourcePackEntries[] = ResourcePackInfoEntry::read($in); } } - protected function encodePayload() : void{ - $this->buf->putBool($this->mustAccept); - $this->buf->putBool($this->hasScripts); - $this->buf->putLShort(count($this->behaviorPackEntries)); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putBool($this->mustAccept); + $out->putBool($this->hasScripts); + $out->putLShort(count($this->behaviorPackEntries)); foreach($this->behaviorPackEntries as $entry){ - $entry->write($this->buf); + $entry->write($out); } - $this->buf->putLShort(count($this->resourcePackEntries)); + $out->putLShort(count($this->resourcePackEntries)); foreach($this->resourcePackEntries as $entry){ - $entry->write($this->buf); + $entry->write($out); } } diff --git a/src/network/mcpe/protocol/RespawnPacket.php b/src/network/mcpe/protocol/RespawnPacket.php index 3bb6c69b9..dfad800ac 100644 --- a/src/network/mcpe/protocol/RespawnPacket.php +++ b/src/network/mcpe/protocol/RespawnPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class RespawnPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::RESPAWN_PACKET; @@ -50,16 +51,16 @@ class RespawnPacket extends DataPacket implements ClientboundPacket, Serverbound return $result; } - protected function decodePayload() : void{ - $this->position = $this->buf->getVector3(); - $this->respawnState = $this->buf->getByte(); - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->position = $in->getVector3(); + $this->respawnState = $in->getByte(); + $this->entityRuntimeId = $in->getEntityRuntimeId(); } - protected function encodePayload() : void{ - $this->buf->putVector3($this->position); - $this->buf->putByte($this->respawnState); - $this->buf->putEntityRuntimeId($this->entityRuntimeId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVector3($this->position); + $out->putByte($this->respawnState); + $out->putEntityRuntimeId($this->entityRuntimeId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/RiderJumpPacket.php b/src/network/mcpe/protocol/RiderJumpPacket.php index 162424be8..ed67e227e 100644 --- a/src/network/mcpe/protocol/RiderJumpPacket.php +++ b/src/network/mcpe/protocol/RiderJumpPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class RiderJumpPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::RIDER_JUMP_PACKET; @@ -33,12 +34,12 @@ class RiderJumpPacket extends DataPacket implements ServerboundPacket{ /** @var int */ public $jumpStrength; //percentage - protected function decodePayload() : void{ - $this->jumpStrength = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->jumpStrength = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->jumpStrength); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->jumpStrength); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ScriptCustomEventPacket.php b/src/network/mcpe/protocol/ScriptCustomEventPacket.php index 3247bffed..59def6218 100644 --- a/src/network/mcpe/protocol/ScriptCustomEventPacket.php +++ b/src/network/mcpe/protocol/ScriptCustomEventPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ScriptCustomEventPacket extends DataPacket{ //TODO: this doesn't have handlers in either client or server in the game as of 1.8 public const NETWORK_ID = ProtocolInfo::SCRIPT_CUSTOM_EVENT_PACKET; @@ -35,14 +36,14 @@ class ScriptCustomEventPacket extends DataPacket{ //TODO: this doesn't have hand /** @var string json data */ public $eventData; - protected function decodePayload() : void{ - $this->eventName = $this->buf->getString(); - $this->eventData = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->eventName = $in->getString(); + $this->eventData = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putString($this->eventName); - $this->buf->putString($this->eventData); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->eventName); + $out->putString($this->eventData); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ServerSettingsRequestPacket.php b/src/network/mcpe/protocol/ServerSettingsRequestPacket.php index 53243e44d..c17b1b2a1 100644 --- a/src/network/mcpe/protocol/ServerSettingsRequestPacket.php +++ b/src/network/mcpe/protocol/ServerSettingsRequestPacket.php @@ -26,15 +26,16 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ServerSettingsRequestPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::SERVER_SETTINGS_REQUEST_PACKET; - protected function decodePayload() : void{ + protected function decodePayload(NetworkBinaryStream $in) : void{ //No payload } - protected function encodePayload() : void{ + protected function encodePayload(NetworkBinaryStream $out) : void{ //No payload } diff --git a/src/network/mcpe/protocol/ServerSettingsResponsePacket.php b/src/network/mcpe/protocol/ServerSettingsResponsePacket.php index 1134a44b9..aa6dd24b8 100644 --- a/src/network/mcpe/protocol/ServerSettingsResponsePacket.php +++ b/src/network/mcpe/protocol/ServerSettingsResponsePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ServerSettingsResponsePacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::SERVER_SETTINGS_RESPONSE_PACKET; @@ -35,14 +36,14 @@ class ServerSettingsResponsePacket extends DataPacket implements ClientboundPack /** @var string */ public $formData; //json - protected function decodePayload() : void{ - $this->formId = $this->buf->getUnsignedVarInt(); - $this->formData = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->formId = $in->getUnsignedVarInt(); + $this->formData = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt($this->formId); - $this->buf->putString($this->formData); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt($this->formId); + $out->putString($this->formData); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ServerToClientHandshakePacket.php b/src/network/mcpe/protocol/ServerToClientHandshakePacket.php index 51a2859b2..b0c62ee65 100644 --- a/src/network/mcpe/protocol/ServerToClientHandshakePacket.php +++ b/src/network/mcpe/protocol/ServerToClientHandshakePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ServerToClientHandshakePacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::SERVER_TO_CLIENT_HANDSHAKE_PACKET; @@ -46,12 +47,12 @@ class ServerToClientHandshakePacket extends DataPacket implements ClientboundPac return true; } - protected function decodePayload() : void{ - $this->jwt = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->jwt = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putString($this->jwt); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->jwt); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetActorDataPacket.php b/src/network/mcpe/protocol/SetActorDataPacket.php index 0d93ffe0b..776a1cfc5 100644 --- a/src/network/mcpe/protocol/SetActorDataPacket.php +++ b/src/network/mcpe/protocol/SetActorDataPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SetActorDataPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ //TODO: check why this is serverbound public const NETWORK_ID = ProtocolInfo::SET_ACTOR_DATA_PACKET; @@ -51,14 +52,14 @@ class SetActorDataPacket extends DataPacket implements ClientboundPacket, Server return $result; } - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->metadata = $this->buf->getEntityMetadata(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->metadata = $in->getEntityMetadata(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putEntityMetadata($this->metadata); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putEntityMetadata($this->metadata); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetActorLinkPacket.php b/src/network/mcpe/protocol/SetActorLinkPacket.php index 76efc2724..d981ce69f 100644 --- a/src/network/mcpe/protocol/SetActorLinkPacket.php +++ b/src/network/mcpe/protocol/SetActorLinkPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\entity\EntityLink; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SetActorLinkPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::SET_ACTOR_LINK_PACKET; @@ -34,12 +35,12 @@ class SetActorLinkPacket extends DataPacket implements ClientboundPacket{ /** @var EntityLink */ public $link; - protected function decodePayload() : void{ - $this->link = $this->buf->getEntityLink(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->link = $in->getEntityLink(); } - protected function encodePayload() : void{ - $this->buf->putEntityLink($this->link); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityLink($this->link); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetActorMotionPacket.php b/src/network/mcpe/protocol/SetActorMotionPacket.php index 553eeddd7..42f1c4bb5 100644 --- a/src/network/mcpe/protocol/SetActorMotionPacket.php +++ b/src/network/mcpe/protocol/SetActorMotionPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; /** * TODO: This packet is (erroneously) sent to the server when the client is riding a vehicle. @@ -46,14 +47,14 @@ class SetActorMotionPacket extends DataPacket implements ClientboundPacket, Garb return $result; } - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->motion = $this->buf->getVector3(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->motion = $in->getVector3(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putVector3($this->motion); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putVector3($this->motion); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetCommandsEnabledPacket.php b/src/network/mcpe/protocol/SetCommandsEnabledPacket.php index 38bcd8780..8a9331392 100644 --- a/src/network/mcpe/protocol/SetCommandsEnabledPacket.php +++ b/src/network/mcpe/protocol/SetCommandsEnabledPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SetCommandsEnabledPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::SET_COMMANDS_ENABLED_PACKET; @@ -33,12 +34,12 @@ class SetCommandsEnabledPacket extends DataPacket implements ClientboundPacket{ /** @var bool */ public $enabled; - protected function decodePayload() : void{ - $this->enabled = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->enabled = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putBool($this->enabled); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putBool($this->enabled); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetDefaultGameTypePacket.php b/src/network/mcpe/protocol/SetDefaultGameTypePacket.php index f39bbce4d..24882377b 100644 --- a/src/network/mcpe/protocol/SetDefaultGameTypePacket.php +++ b/src/network/mcpe/protocol/SetDefaultGameTypePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SetDefaultGameTypePacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::SET_DEFAULT_GAME_TYPE_PACKET; @@ -39,12 +40,12 @@ class SetDefaultGameTypePacket extends DataPacket implements ClientboundPacket, return $result; } - protected function decodePayload() : void{ - $this->gamemode = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->gamemode = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt($this->gamemode); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt($this->gamemode); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetDifficultyPacket.php b/src/network/mcpe/protocol/SetDifficultyPacket.php index 3489abe99..e8ae53f88 100644 --- a/src/network/mcpe/protocol/SetDifficultyPacket.php +++ b/src/network/mcpe/protocol/SetDifficultyPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SetDifficultyPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::SET_DIFFICULTY_PACKET; @@ -39,12 +40,12 @@ class SetDifficultyPacket extends DataPacket implements ClientboundPacket, Serve return $result; } - protected function decodePayload() : void{ - $this->difficulty = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->difficulty = $in->getUnsignedVarInt(); } - protected function encodePayload() : void{ - $this->buf->putUnsignedVarInt($this->difficulty); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putUnsignedVarInt($this->difficulty); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetDisplayObjectivePacket.php b/src/network/mcpe/protocol/SetDisplayObjectivePacket.php index 2f4075b2a..c2d146dd6 100644 --- a/src/network/mcpe/protocol/SetDisplayObjectivePacket.php +++ b/src/network/mcpe/protocol/SetDisplayObjectivePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SetDisplayObjectivePacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::SET_DISPLAY_OBJECTIVE_PACKET; @@ -41,20 +42,20 @@ class SetDisplayObjectivePacket extends DataPacket implements ClientboundPacket{ /** @var int */ public $sortOrder; - protected function decodePayload() : void{ - $this->displaySlot = $this->buf->getString(); - $this->objectiveName = $this->buf->getString(); - $this->displayName = $this->buf->getString(); - $this->criteriaName = $this->buf->getString(); - $this->sortOrder = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->displaySlot = $in->getString(); + $this->objectiveName = $in->getString(); + $this->displayName = $in->getString(); + $this->criteriaName = $in->getString(); + $this->sortOrder = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putString($this->displaySlot); - $this->buf->putString($this->objectiveName); - $this->buf->putString($this->displayName); - $this->buf->putString($this->criteriaName); - $this->buf->putVarInt($this->sortOrder); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->displaySlot); + $out->putString($this->objectiveName); + $out->putString($this->displayName); + $out->putString($this->criteriaName); + $out->putVarInt($this->sortOrder); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetHealthPacket.php b/src/network/mcpe/protocol/SetHealthPacket.php index 4fb3f1609..33d995ee1 100644 --- a/src/network/mcpe/protocol/SetHealthPacket.php +++ b/src/network/mcpe/protocol/SetHealthPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SetHealthPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::SET_HEALTH_PACKET; @@ -33,12 +34,12 @@ class SetHealthPacket extends DataPacket implements ClientboundPacket{ /** @var int */ public $health; - protected function decodePayload() : void{ - $this->health = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->health = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->health); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->health); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetLastHurtByPacket.php b/src/network/mcpe/protocol/SetLastHurtByPacket.php index 6cff93835..41cf6cc7b 100644 --- a/src/network/mcpe/protocol/SetLastHurtByPacket.php +++ b/src/network/mcpe/protocol/SetLastHurtByPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SetLastHurtByPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::SET_LAST_HURT_BY_PACKET; @@ -33,12 +34,12 @@ class SetLastHurtByPacket extends DataPacket implements ClientboundPacket{ /** @var int */ public $entityTypeId; - protected function decodePayload() : void{ - $this->entityTypeId = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityTypeId = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->entityTypeId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->entityTypeId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetLocalPlayerAsInitializedPacket.php b/src/network/mcpe/protocol/SetLocalPlayerAsInitializedPacket.php index 0897c6329..9bad32b37 100644 --- a/src/network/mcpe/protocol/SetLocalPlayerAsInitializedPacket.php +++ b/src/network/mcpe/protocol/SetLocalPlayerAsInitializedPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SetLocalPlayerAsInitializedPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::SET_LOCAL_PLAYER_AS_INITIALIZED_PACKET; @@ -33,12 +34,12 @@ class SetLocalPlayerAsInitializedPacket extends DataPacket implements Serverboun /** @var int */ public $entityRuntimeId; - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetPlayerGameTypePacket.php b/src/network/mcpe/protocol/SetPlayerGameTypePacket.php index bb8699aab..212810dab 100644 --- a/src/network/mcpe/protocol/SetPlayerGameTypePacket.php +++ b/src/network/mcpe/protocol/SetPlayerGameTypePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SetPlayerGameTypePacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::SET_PLAYER_GAME_TYPE_PACKET; @@ -39,12 +40,12 @@ class SetPlayerGameTypePacket extends DataPacket implements ClientboundPacket, S return $pk; } - protected function decodePayload() : void{ - $this->gamemode = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->gamemode = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->gamemode); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->gamemode); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetScorePacket.php b/src/network/mcpe/protocol/SetScorePacket.php index 59f61d321..73e1208dc 100644 --- a/src/network/mcpe/protocol/SetScorePacket.php +++ b/src/network/mcpe/protocol/SetScorePacket.php @@ -28,6 +28,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\BadPacketException; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\ScorePacketEntry; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function count; class SetScorePacket extends DataPacket implements ClientboundPacket{ @@ -41,22 +42,22 @@ class SetScorePacket extends DataPacket implements ClientboundPacket{ /** @var ScorePacketEntry[] */ public $entries = []; - protected function decodePayload() : void{ - $this->type = $this->buf->getByte(); - for($i = 0, $i2 = $this->buf->getUnsignedVarInt(); $i < $i2; ++$i){ + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->type = $in->getByte(); + for($i = 0, $i2 = $in->getUnsignedVarInt(); $i < $i2; ++$i){ $entry = new ScorePacketEntry(); - $entry->scoreboardId = $this->buf->getVarLong(); - $entry->objectiveName = $this->buf->getString(); - $entry->score = $this->buf->getLInt(); + $entry->scoreboardId = $in->getVarLong(); + $entry->objectiveName = $in->getString(); + $entry->score = $in->getLInt(); if($this->type !== self::TYPE_REMOVE){ - $entry->type = $this->buf->getByte(); + $entry->type = $in->getByte(); switch($entry->type){ case ScorePacketEntry::TYPE_PLAYER: case ScorePacketEntry::TYPE_ENTITY: - $entry->entityUniqueId = $this->buf->getEntityUniqueId(); + $entry->entityUniqueId = $in->getEntityUniqueId(); break; case ScorePacketEntry::TYPE_FAKE_PLAYER: - $entry->customName = $this->buf->getString(); + $entry->customName = $in->getString(); break; default: throw new BadPacketException("Unknown entry type $entry->type"); @@ -66,22 +67,22 @@ class SetScorePacket extends DataPacket implements ClientboundPacket{ } } - protected function encodePayload() : void{ - $this->buf->putByte($this->type); - $this->buf->putUnsignedVarInt(count($this->entries)); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->type); + $out->putUnsignedVarInt(count($this->entries)); foreach($this->entries as $entry){ - $this->buf->putVarLong($entry->scoreboardId); - $this->buf->putString($entry->objectiveName); - $this->buf->putLInt($entry->score); + $out->putVarLong($entry->scoreboardId); + $out->putString($entry->objectiveName); + $out->putLInt($entry->score); if($this->type !== self::TYPE_REMOVE){ - $this->buf->putByte($entry->type); + $out->putByte($entry->type); switch($entry->type){ case ScorePacketEntry::TYPE_PLAYER: case ScorePacketEntry::TYPE_ENTITY: - $this->buf->putEntityUniqueId($entry->entityUniqueId); + $out->putEntityUniqueId($entry->entityUniqueId); break; case ScorePacketEntry::TYPE_FAKE_PLAYER: - $this->buf->putString($entry->customName); + $out->putString($entry->customName); break; default: throw new \InvalidArgumentException("Unknown entry type $entry->type"); diff --git a/src/network/mcpe/protocol/SetScoreboardIdentityPacket.php b/src/network/mcpe/protocol/SetScoreboardIdentityPacket.php index 991771acc..bd42d29cb 100644 --- a/src/network/mcpe/protocol/SetScoreboardIdentityPacket.php +++ b/src/network/mcpe/protocol/SetScoreboardIdentityPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\ScoreboardIdentityPacketEntry; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function count; class SetScoreboardIdentityPacket extends DataPacket implements ClientboundPacket{ @@ -40,26 +41,26 @@ class SetScoreboardIdentityPacket extends DataPacket implements ClientboundPacke /** @var ScoreboardIdentityPacketEntry[] */ public $entries = []; - protected function decodePayload() : void{ - $this->type = $this->buf->getByte(); - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->type = $in->getByte(); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ $entry = new ScoreboardIdentityPacketEntry(); - $entry->scoreboardId = $this->buf->getVarLong(); + $entry->scoreboardId = $in->getVarLong(); if($this->type === self::TYPE_REGISTER_IDENTITY){ - $entry->entityUniqueId = $this->buf->getEntityUniqueId(); + $entry->entityUniqueId = $in->getEntityUniqueId(); } $this->entries[] = $entry; } } - protected function encodePayload() : void{ - $this->buf->putByte($this->type); - $this->buf->putUnsignedVarInt(count($this->entries)); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->type); + $out->putUnsignedVarInt(count($this->entries)); foreach($this->entries as $entry){ - $this->buf->putVarLong($entry->scoreboardId); + $out->putVarLong($entry->scoreboardId); if($this->type === self::TYPE_REGISTER_IDENTITY){ - $this->buf->putEntityUniqueId($entry->entityUniqueId); + $out->putEntityUniqueId($entry->entityUniqueId); } } } diff --git a/src/network/mcpe/protocol/SetSpawnPositionPacket.php b/src/network/mcpe/protocol/SetSpawnPositionPacket.php index 9e8320a14..fe65a4965 100644 --- a/src/network/mcpe/protocol/SetSpawnPositionPacket.php +++ b/src/network/mcpe/protocol/SetSpawnPositionPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SetSpawnPositionPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::SET_SPAWN_POSITION_PACKET; @@ -59,16 +60,16 @@ class SetSpawnPositionPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->spawnType = $this->buf->getVarInt(); - $this->buf->getBlockPosition($this->x, $this->y, $this->z); - $this->spawnForced = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->spawnType = $in->getVarInt(); + $in->getBlockPosition($this->x, $this->y, $this->z); + $this->spawnForced = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->spawnType); - $this->buf->putBlockPosition($this->x, $this->y, $this->z); - $this->buf->putBool($this->spawnForced); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->spawnType); + $out->putBlockPosition($this->x, $this->y, $this->z); + $out->putBool($this->spawnForced); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetTimePacket.php b/src/network/mcpe/protocol/SetTimePacket.php index b6fbac90b..188352492 100644 --- a/src/network/mcpe/protocol/SetTimePacket.php +++ b/src/network/mcpe/protocol/SetTimePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SetTimePacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::SET_TIME_PACKET; @@ -39,12 +40,12 @@ class SetTimePacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->time = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->time = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->time); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->time); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SetTitlePacket.php b/src/network/mcpe/protocol/SetTitlePacket.php index 0e1585fa7..ca765ad53 100644 --- a/src/network/mcpe/protocol/SetTitlePacket.php +++ b/src/network/mcpe/protocol/SetTitlePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SetTitlePacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::SET_TITLE_PACKET; @@ -48,20 +49,20 @@ class SetTitlePacket extends DataPacket implements ClientboundPacket{ /** @var int */ public $fadeOutTime = 0; - protected function decodePayload() : void{ - $this->type = $this->buf->getVarInt(); - $this->text = $this->buf->getString(); - $this->fadeInTime = $this->buf->getVarInt(); - $this->stayTime = $this->buf->getVarInt(); - $this->fadeOutTime = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->type = $in->getVarInt(); + $this->text = $in->getString(); + $this->fadeInTime = $in->getVarInt(); + $this->stayTime = $in->getVarInt(); + $this->fadeOutTime = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putVarInt($this->type); - $this->buf->putString($this->text); - $this->buf->putVarInt($this->fadeInTime); - $this->buf->putVarInt($this->stayTime); - $this->buf->putVarInt($this->fadeOutTime); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVarInt($this->type); + $out->putString($this->text); + $out->putVarInt($this->fadeInTime); + $out->putVarInt($this->stayTime); + $out->putVarInt($this->fadeOutTime); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SettingsCommandPacket.php b/src/network/mcpe/protocol/SettingsCommandPacket.php index 084449455..7b81a2098 100644 --- a/src/network/mcpe/protocol/SettingsCommandPacket.php +++ b/src/network/mcpe/protocol/SettingsCommandPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SettingsCommandPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::SETTINGS_COMMAND_PACKET; @@ -50,14 +51,14 @@ class SettingsCommandPacket extends DataPacket implements ServerboundPacket{ return $this->suppressOutput; } - protected function decodePayload() : void{ - $this->command = $this->buf->getString(); - $this->suppressOutput = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->command = $in->getString(); + $this->suppressOutput = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putString($this->command); - $this->buf->putBool($this->suppressOutput); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->command); + $out->putBool($this->suppressOutput); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ShowCreditsPacket.php b/src/network/mcpe/protocol/ShowCreditsPacket.php index 7d58c4cdd..3d3ea2ca1 100644 --- a/src/network/mcpe/protocol/ShowCreditsPacket.php +++ b/src/network/mcpe/protocol/ShowCreditsPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ShowCreditsPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::SHOW_CREDITS_PACKET; @@ -38,14 +39,14 @@ class ShowCreditsPacket extends DataPacket implements ClientboundPacket, Serverb /** @var int */ public $status; - protected function decodePayload() : void{ - $this->playerEid = $this->buf->getEntityRuntimeId(); - $this->status = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->playerEid = $in->getEntityRuntimeId(); + $this->status = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->playerEid); - $this->buf->putVarInt($this->status); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->playerEid); + $out->putVarInt($this->status); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ShowProfilePacket.php b/src/network/mcpe/protocol/ShowProfilePacket.php index 0b78bc2a2..b8865b9ec 100644 --- a/src/network/mcpe/protocol/ShowProfilePacket.php +++ b/src/network/mcpe/protocol/ShowProfilePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ShowProfilePacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::SHOW_PROFILE_PACKET; @@ -33,12 +34,12 @@ class ShowProfilePacket extends DataPacket implements ClientboundPacket{ /** @var string */ public $xuid; - protected function decodePayload() : void{ - $this->xuid = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->xuid = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putString($this->xuid); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->xuid); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/ShowStoreOfferPacket.php b/src/network/mcpe/protocol/ShowStoreOfferPacket.php index 992dd18f8..61f430a9d 100644 --- a/src/network/mcpe/protocol/ShowStoreOfferPacket.php +++ b/src/network/mcpe/protocol/ShowStoreOfferPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class ShowStoreOfferPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::SHOW_STORE_OFFER_PACKET; @@ -35,14 +36,14 @@ class ShowStoreOfferPacket extends DataPacket implements ClientboundPacket{ /** @var bool */ public $showAll; - protected function decodePayload() : void{ - $this->offerId = $this->buf->getString(); - $this->showAll = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->offerId = $in->getString(); + $this->showAll = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putString($this->offerId); - $this->buf->putBool($this->showAll); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->offerId); + $out->putBool($this->showAll); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SimpleEventPacket.php b/src/network/mcpe/protocol/SimpleEventPacket.php index 573fecbe8..732475b47 100644 --- a/src/network/mcpe/protocol/SimpleEventPacket.php +++ b/src/network/mcpe/protocol/SimpleEventPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SimpleEventPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::SIMPLE_EVENT_PACKET; @@ -36,12 +37,12 @@ class SimpleEventPacket extends DataPacket implements ClientboundPacket, Serverb /** @var int */ public $eventType; - protected function decodePayload() : void{ - $this->eventType = $this->buf->getLShort(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->eventType = $in->getLShort(); } - protected function encodePayload() : void{ - $this->buf->putLShort($this->eventType); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putLShort($this->eventType); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SpawnExperienceOrbPacket.php b/src/network/mcpe/protocol/SpawnExperienceOrbPacket.php index ea4aed766..74c6b2b25 100644 --- a/src/network/mcpe/protocol/SpawnExperienceOrbPacket.php +++ b/src/network/mcpe/protocol/SpawnExperienceOrbPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SpawnExperienceOrbPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::SPAWN_EXPERIENCE_ORB_PACKET; @@ -36,14 +37,14 @@ class SpawnExperienceOrbPacket extends DataPacket implements ServerboundPacket{ /** @var int */ public $amount; - protected function decodePayload() : void{ - $this->position = $this->buf->getVector3(); - $this->amount = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->position = $in->getVector3(); + $this->amount = $in->getVarInt(); } - protected function encodePayload() : void{ - $this->buf->putVector3($this->position); - $this->buf->putVarInt($this->amount); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putVector3($this->position); + $out->putVarInt($this->amount); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/SpawnParticleEffectPacket.php b/src/network/mcpe/protocol/SpawnParticleEffectPacket.php index 692dd8645..e5bf0e6a9 100644 --- a/src/network/mcpe/protocol/SpawnParticleEffectPacket.php +++ b/src/network/mcpe/protocol/SpawnParticleEffectPacket.php @@ -28,6 +28,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\DimensionIds; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SpawnParticleEffectPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::SPAWN_PARTICLE_EFFECT_PACKET; @@ -41,18 +42,18 @@ class SpawnParticleEffectPacket extends DataPacket implements ClientboundPacket{ /** @var string */ public $particleName; - protected function decodePayload() : void{ - $this->dimensionId = $this->buf->getByte(); - $this->entityUniqueId = $this->buf->getEntityUniqueId(); - $this->position = $this->buf->getVector3(); - $this->particleName = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->dimensionId = $in->getByte(); + $this->entityUniqueId = $in->getEntityUniqueId(); + $this->position = $in->getVector3(); + $this->particleName = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putByte($this->dimensionId); - $this->buf->putEntityUniqueId($this->entityUniqueId); - $this->buf->putVector3($this->position); - $this->buf->putString($this->particleName); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->dimensionId); + $out->putEntityUniqueId($this->entityUniqueId); + $out->putVector3($this->position); + $out->putString($this->particleName); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/StartGamePacket.php b/src/network/mcpe/protocol/StartGamePacket.php index 43099a907..f61cba135 100644 --- a/src/network/mcpe/protocol/StartGamePacket.php +++ b/src/network/mcpe/protocol/StartGamePacket.php @@ -162,150 +162,150 @@ class StartGamePacket extends DataPacket implements ClientboundPacket{ */ public $itemTable = null; - protected function decodePayload() : void{ - $this->entityUniqueId = $this->buf->getEntityUniqueId(); - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->playerGamemode = $this->buf->getVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityUniqueId = $in->getEntityUniqueId(); + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->playerGamemode = $in->getVarInt(); - $this->playerPosition = $this->buf->getVector3(); + $this->playerPosition = $in->getVector3(); - $this->pitch = $this->buf->getLFloat(); - $this->yaw = $this->buf->getLFloat(); + $this->pitch = $in->getLFloat(); + $this->yaw = $in->getLFloat(); //Level settings - $this->seed = $this->buf->getVarInt(); - $this->dimension = $this->buf->getVarInt(); - $this->generator = $this->buf->getVarInt(); - $this->worldGamemode = $this->buf->getVarInt(); - $this->difficulty = $this->buf->getVarInt(); - $this->buf->getBlockPosition($this->spawnX, $this->spawnY, $this->spawnZ); - $this->hasAchievementsDisabled = $this->buf->getBool(); - $this->time = $this->buf->getVarInt(); - $this->eduEditionOffer = $this->buf->getVarInt(); - $this->hasEduFeaturesEnabled = $this->buf->getBool(); - $this->rainLevel = $this->buf->getLFloat(); - $this->lightningLevel = $this->buf->getLFloat(); - $this->hasConfirmedPlatformLockedContent = $this->buf->getBool(); - $this->isMultiplayerGame = $this->buf->getBool(); - $this->hasLANBroadcast = $this->buf->getBool(); - $this->xboxLiveBroadcastMode = $this->buf->getVarInt(); - $this->platformBroadcastMode = $this->buf->getVarInt(); - $this->commandsEnabled = $this->buf->getBool(); - $this->isTexturePacksRequired = $this->buf->getBool(); - $this->gameRules = $this->buf->getGameRules(); - $this->hasBonusChestEnabled = $this->buf->getBool(); - $this->hasStartWithMapEnabled = $this->buf->getBool(); - $this->defaultPlayerPermission = $this->buf->getVarInt(); - $this->serverChunkTickRadius = $this->buf->getLInt(); - $this->hasLockedBehaviorPack = $this->buf->getBool(); - $this->hasLockedResourcePack = $this->buf->getBool(); - $this->isFromLockedWorldTemplate = $this->buf->getBool(); - $this->useMsaGamertagsOnly = $this->buf->getBool(); - $this->isFromWorldTemplate = $this->buf->getBool(); - $this->isWorldTemplateOptionLocked = $this->buf->getBool(); - $this->onlySpawnV1Villagers = $this->buf->getBool(); + $this->seed = $in->getVarInt(); + $this->dimension = $in->getVarInt(); + $this->generator = $in->getVarInt(); + $this->worldGamemode = $in->getVarInt(); + $this->difficulty = $in->getVarInt(); + $in->getBlockPosition($this->spawnX, $this->spawnY, $this->spawnZ); + $this->hasAchievementsDisabled = $in->getBool(); + $this->time = $in->getVarInt(); + $this->eduEditionOffer = $in->getVarInt(); + $this->hasEduFeaturesEnabled = $in->getBool(); + $this->rainLevel = $in->getLFloat(); + $this->lightningLevel = $in->getLFloat(); + $this->hasConfirmedPlatformLockedContent = $in->getBool(); + $this->isMultiplayerGame = $in->getBool(); + $this->hasLANBroadcast = $in->getBool(); + $this->xboxLiveBroadcastMode = $in->getVarInt(); + $this->platformBroadcastMode = $in->getVarInt(); + $this->commandsEnabled = $in->getBool(); + $this->isTexturePacksRequired = $in->getBool(); + $this->gameRules = $in->getGameRules(); + $this->hasBonusChestEnabled = $in->getBool(); + $this->hasStartWithMapEnabled = $in->getBool(); + $this->defaultPlayerPermission = $in->getVarInt(); + $this->serverChunkTickRadius = $in->getLInt(); + $this->hasLockedBehaviorPack = $in->getBool(); + $this->hasLockedResourcePack = $in->getBool(); + $this->isFromLockedWorldTemplate = $in->getBool(); + $this->useMsaGamertagsOnly = $in->getBool(); + $this->isFromWorldTemplate = $in->getBool(); + $this->isWorldTemplateOptionLocked = $in->getBool(); + $this->onlySpawnV1Villagers = $in->getBool(); - $this->vanillaVersion = $this->buf->getString(); - $this->levelId = $this->buf->getString(); - $this->worldName = $this->buf->getString(); - $this->premiumWorldTemplateId = $this->buf->getString(); - $this->isTrial = $this->buf->getBool(); - $this->isMovementServerAuthoritative = $this->buf->getBool(); - $this->currentTick = $this->buf->getLLong(); + $this->vanillaVersion = $in->getString(); + $this->levelId = $in->getString(); + $this->worldName = $in->getString(); + $this->premiumWorldTemplateId = $in->getString(); + $this->isTrial = $in->getBool(); + $this->isMovementServerAuthoritative = $in->getBool(); + $this->currentTick = $in->getLLong(); - $this->enchantmentSeed = $this->buf->getVarInt(); + $this->enchantmentSeed = $in->getVarInt(); - $offset = $this->buf->getOffset(); - $blockTable = (new NetworkNbtSerializer())->read($this->buf->getBuffer(), $offset, 512)->getTag(); - $this->buf->setOffset($offset); + $offset = $in->getOffset(); + $blockTable = (new NetworkNbtSerializer())->read($in->getBuffer(), $offset, 512)->getTag(); + $in->setOffset($offset); if(!($blockTable instanceof ListTag)){ throw new \UnexpectedValueException("Wrong block table root NBT tag type"); } $this->blockTable = $blockTable; $this->itemTable = []; - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $id = $this->buf->getString(); - $legacyId = $this->buf->getSignedLShort(); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $id = $in->getString(); + $legacyId = $in->getSignedLShort(); $this->itemTable[$id] = $legacyId; } - $this->multiplayerCorrelationId = $this->buf->getString(); + $this->multiplayerCorrelationId = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putEntityUniqueId($this->entityUniqueId); - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putVarInt($this->playerGamemode); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityUniqueId($this->entityUniqueId); + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putVarInt($this->playerGamemode); - $this->buf->putVector3($this->playerPosition); + $out->putVector3($this->playerPosition); - $this->buf->putLFloat($this->pitch); - $this->buf->putLFloat($this->yaw); + $out->putLFloat($this->pitch); + $out->putLFloat($this->yaw); //Level settings - $this->buf->putVarInt($this->seed); - $this->buf->putVarInt($this->dimension); - $this->buf->putVarInt($this->generator); - $this->buf->putVarInt($this->worldGamemode); - $this->buf->putVarInt($this->difficulty); - $this->buf->putBlockPosition($this->spawnX, $this->spawnY, $this->spawnZ); - $this->buf->putBool($this->hasAchievementsDisabled); - $this->buf->putVarInt($this->time); - $this->buf->putVarInt($this->eduEditionOffer); - $this->buf->putBool($this->hasEduFeaturesEnabled); - $this->buf->putLFloat($this->rainLevel); - $this->buf->putLFloat($this->lightningLevel); - $this->buf->putBool($this->hasConfirmedPlatformLockedContent); - $this->buf->putBool($this->isMultiplayerGame); - $this->buf->putBool($this->hasLANBroadcast); - $this->buf->putVarInt($this->xboxLiveBroadcastMode); - $this->buf->putVarInt($this->platformBroadcastMode); - $this->buf->putBool($this->commandsEnabled); - $this->buf->putBool($this->isTexturePacksRequired); - $this->buf->putGameRules($this->gameRules); - $this->buf->putBool($this->hasBonusChestEnabled); - $this->buf->putBool($this->hasStartWithMapEnabled); - $this->buf->putVarInt($this->defaultPlayerPermission); - $this->buf->putLInt($this->serverChunkTickRadius); - $this->buf->putBool($this->hasLockedBehaviorPack); - $this->buf->putBool($this->hasLockedResourcePack); - $this->buf->putBool($this->isFromLockedWorldTemplate); - $this->buf->putBool($this->useMsaGamertagsOnly); - $this->buf->putBool($this->isFromWorldTemplate); - $this->buf->putBool($this->isWorldTemplateOptionLocked); - $this->buf->putBool($this->onlySpawnV1Villagers); + $out->putVarInt($this->seed); + $out->putVarInt($this->dimension); + $out->putVarInt($this->generator); + $out->putVarInt($this->worldGamemode); + $out->putVarInt($this->difficulty); + $out->putBlockPosition($this->spawnX, $this->spawnY, $this->spawnZ); + $out->putBool($this->hasAchievementsDisabled); + $out->putVarInt($this->time); + $out->putVarInt($this->eduEditionOffer); + $out->putBool($this->hasEduFeaturesEnabled); + $out->putLFloat($this->rainLevel); + $out->putLFloat($this->lightningLevel); + $out->putBool($this->hasConfirmedPlatformLockedContent); + $out->putBool($this->isMultiplayerGame); + $out->putBool($this->hasLANBroadcast); + $out->putVarInt($this->xboxLiveBroadcastMode); + $out->putVarInt($this->platformBroadcastMode); + $out->putBool($this->commandsEnabled); + $out->putBool($this->isTexturePacksRequired); + $out->putGameRules($this->gameRules); + $out->putBool($this->hasBonusChestEnabled); + $out->putBool($this->hasStartWithMapEnabled); + $out->putVarInt($this->defaultPlayerPermission); + $out->putLInt($this->serverChunkTickRadius); + $out->putBool($this->hasLockedBehaviorPack); + $out->putBool($this->hasLockedResourcePack); + $out->putBool($this->isFromLockedWorldTemplate); + $out->putBool($this->useMsaGamertagsOnly); + $out->putBool($this->isFromWorldTemplate); + $out->putBool($this->isWorldTemplateOptionLocked); + $out->putBool($this->onlySpawnV1Villagers); - $this->buf->putString($this->vanillaVersion); - $this->buf->putString($this->levelId); - $this->buf->putString($this->worldName); - $this->buf->putString($this->premiumWorldTemplateId); - $this->buf->putBool($this->isTrial); - $this->buf->putBool($this->isMovementServerAuthoritative); - $this->buf->putLLong($this->currentTick); + $out->putString($this->vanillaVersion); + $out->putString($this->levelId); + $out->putString($this->worldName); + $out->putString($this->premiumWorldTemplateId); + $out->putBool($this->isTrial); + $out->putBool($this->isMovementServerAuthoritative); + $out->putLLong($this->currentTick); - $this->buf->putVarInt($this->enchantmentSeed); + $out->putVarInt($this->enchantmentSeed); if($this->blockTable === null){ if(self::$blockTableCache === null){ //this is a really nasty hack, but it'll do for now self::$blockTableCache = (new NetworkNbtSerializer())->write(new TreeRoot(new ListTag(RuntimeBlockMapping::getBedrockKnownStates()))); } - $this->buf->put(self::$blockTableCache); + $out->put(self::$blockTableCache); }else{ - $this->buf->put((new NetworkNbtSerializer())->write(new TreeRoot($this->blockTable))); + $out->put((new NetworkNbtSerializer())->write(new TreeRoot($this->blockTable))); } if($this->itemTable === null){ if(self::$itemTableCache === null){ self::$itemTableCache = self::serializeItemTable(json_decode(file_get_contents(RESOURCE_PATH . '/vanilla/item_id_map.json'), true)); } - $this->buf->put(self::$itemTableCache); + $out->put(self::$itemTableCache); }else{ - $this->buf->put(self::serializeItemTable($this->itemTable)); + $out->put(self::serializeItemTable($this->itemTable)); } - $this->buf->putString($this->multiplayerCorrelationId); + $out->putString($this->multiplayerCorrelationId); } /** diff --git a/src/network/mcpe/protocol/StopSoundPacket.php b/src/network/mcpe/protocol/StopSoundPacket.php index 4a61eea6b..50e92ede7 100644 --- a/src/network/mcpe/protocol/StopSoundPacket.php +++ b/src/network/mcpe/protocol/StopSoundPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class StopSoundPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::STOP_SOUND_PACKET; @@ -35,14 +36,14 @@ class StopSoundPacket extends DataPacket implements ClientboundPacket{ /** @var bool */ public $stopAll; - protected function decodePayload() : void{ - $this->soundName = $this->buf->getString(); - $this->stopAll = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->soundName = $in->getString(); + $this->stopAll = $in->getBool(); } - protected function encodePayload() : void{ - $this->buf->putString($this->soundName); - $this->buf->putBool($this->stopAll); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->soundName); + $out->putBool($this->stopAll); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/StructureBlockUpdatePacket.php b/src/network/mcpe/protocol/StructureBlockUpdatePacket.php index 422ad3a43..69e258de5 100644 --- a/src/network/mcpe/protocol/StructureBlockUpdatePacket.php +++ b/src/network/mcpe/protocol/StructureBlockUpdatePacket.php @@ -26,15 +26,16 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class StructureBlockUpdatePacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::STRUCTURE_BLOCK_UPDATE_PACKET; - protected function decodePayload() : void{ + protected function decodePayload(NetworkBinaryStream $in) : void{ //TODO } - protected function encodePayload() : void{ + protected function encodePayload(NetworkBinaryStream $out) : void{ //TODO } diff --git a/src/network/mcpe/protocol/StructureTemplateDataRequestPacket.php b/src/network/mcpe/protocol/StructureTemplateDataRequestPacket.php index b2c52ea31..11344f0dd 100644 --- a/src/network/mcpe/protocol/StructureTemplateDataRequestPacket.php +++ b/src/network/mcpe/protocol/StructureTemplateDataRequestPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\StructureSettings; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class StructureTemplateDataRequestPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::STRUCTURE_TEMPLATE_DATA_REQUEST_PACKET; @@ -47,18 +48,18 @@ class StructureTemplateDataRequestPacket extends DataPacket implements Serverbou /** @var int */ public $structureTemplateResponseType; - protected function decodePayload() : void{ - $this->structureTemplateName = $this->buf->getString(); - $this->buf->getBlockPosition($this->structureBlockX, $this->structureBlockY, $this->structureBlockZ); - $this->structureSettings = $this->buf->getStructureSettings(); - $this->structureTemplateResponseType = $this->buf->getByte(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->structureTemplateName = $in->getString(); + $in->getBlockPosition($this->structureBlockX, $this->structureBlockY, $this->structureBlockZ); + $this->structureSettings = $in->getStructureSettings(); + $this->structureTemplateResponseType = $in->getByte(); } - protected function encodePayload() : void{ - $this->buf->putString($this->structureTemplateName); - $this->buf->putBlockPosition($this->structureBlockX, $this->structureBlockY, $this->structureBlockZ); - $this->buf->putStructureSettings($this->structureSettings); - $this->buf->putByte($this->structureTemplateResponseType); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->structureTemplateName); + $out->putBlockPosition($this->structureBlockX, $this->structureBlockY, $this->structureBlockZ); + $out->putStructureSettings($this->structureSettings); + $out->putByte($this->structureTemplateResponseType); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/StructureTemplateDataResponsePacket.php b/src/network/mcpe/protocol/StructureTemplateDataResponsePacket.php index 7d81ac3ee..78f565296 100644 --- a/src/network/mcpe/protocol/StructureTemplateDataResponsePacket.php +++ b/src/network/mcpe/protocol/StructureTemplateDataResponsePacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class StructureTemplateDataResponsePacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::STRUCTURE_TEMPLATE_DATA_RESPONSE_PACKET; @@ -35,18 +36,18 @@ class StructureTemplateDataResponsePacket extends DataPacket implements Clientbo /** @var string|null */ public $namedtag; - protected function decodePayload() : void{ - $this->structureTemplateName = $this->buf->getString(); - if($this->buf->getBool()){ - $this->namedtag = $this->buf->getRemaining(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->structureTemplateName = $in->getString(); + if($in->getBool()){ + $this->namedtag = $in->getRemaining(); } } - protected function encodePayload() : void{ - $this->buf->putString($this->structureTemplateName); - $this->buf->putBool($this->namedtag !== null); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->structureTemplateName); + $out->putBool($this->namedtag !== null); if($this->namedtag !== null){ - $this->buf->put($this->namedtag); + $out->put($this->namedtag); } } diff --git a/src/network/mcpe/protocol/SubClientLoginPacket.php b/src/network/mcpe/protocol/SubClientLoginPacket.php index 90a4fa1b1..d2f8b4a09 100644 --- a/src/network/mcpe/protocol/SubClientLoginPacket.php +++ b/src/network/mcpe/protocol/SubClientLoginPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class SubClientLoginPacket extends DataPacket implements ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::SUB_CLIENT_LOGIN_PACKET; @@ -33,12 +34,12 @@ class SubClientLoginPacket extends DataPacket implements ServerboundPacket{ /** @var string */ public $connectionRequestData; - protected function decodePayload() : void{ - $this->connectionRequestData = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->connectionRequestData = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putString($this->connectionRequestData); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->connectionRequestData); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/TakeItemActorPacket.php b/src/network/mcpe/protocol/TakeItemActorPacket.php index e3b768afe..6a689b0ef 100644 --- a/src/network/mcpe/protocol/TakeItemActorPacket.php +++ b/src/network/mcpe/protocol/TakeItemActorPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class TakeItemActorPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::TAKE_ITEM_ACTOR_PACKET; @@ -42,14 +43,14 @@ class TakeItemActorPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->target = $this->buf->getEntityRuntimeId(); - $this->eid = $this->buf->getEntityRuntimeId(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->target = $in->getEntityRuntimeId(); + $this->eid = $in->getEntityRuntimeId(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->target); - $this->buf->putEntityRuntimeId($this->eid); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->target); + $out->putEntityRuntimeId($this->eid); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/TextPacket.php b/src/network/mcpe/protocol/TextPacket.php index 0e37555c6..0cc905363 100644 --- a/src/network/mcpe/protocol/TextPacket.php +++ b/src/network/mcpe/protocol/TextPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function count; class TextPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ @@ -115,66 +116,66 @@ class TextPacket extends DataPacket implements ClientboundPacket, ServerboundPac return self::messageOnly(self::TYPE_TIP, $message); } - protected function decodePayload() : void{ - $this->type = $this->buf->getByte(); - $this->needsTranslation = $this->buf->getBool(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->type = $in->getByte(); + $this->needsTranslation = $in->getBool(); switch($this->type){ case self::TYPE_CHAT: case self::TYPE_WHISPER: /** @noinspection PhpMissingBreakStatementInspection */ case self::TYPE_ANNOUNCEMENT: - $this->sourceName = $this->buf->getString(); + $this->sourceName = $in->getString(); case self::TYPE_RAW: case self::TYPE_TIP: case self::TYPE_SYSTEM: case self::TYPE_JSON: - $this->message = $this->buf->getString(); + $this->message = $in->getString(); break; case self::TYPE_TRANSLATION: case self::TYPE_POPUP: case self::TYPE_JUKEBOX_POPUP: - $this->message = $this->buf->getString(); - $count = $this->buf->getUnsignedVarInt(); + $this->message = $in->getString(); + $count = $in->getUnsignedVarInt(); for($i = 0; $i < $count; ++$i){ - $this->parameters[] = $this->buf->getString(); + $this->parameters[] = $in->getString(); } break; } - $this->xboxUserId = $this->buf->getString(); - $this->platformChatId = $this->buf->getString(); + $this->xboxUserId = $in->getString(); + $this->platformChatId = $in->getString(); } - protected function encodePayload() : void{ - $this->buf->putByte($this->type); - $this->buf->putBool($this->needsTranslation); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->type); + $out->putBool($this->needsTranslation); switch($this->type){ case self::TYPE_CHAT: case self::TYPE_WHISPER: /** @noinspection PhpMissingBreakStatementInspection */ case self::TYPE_ANNOUNCEMENT: - $this->buf->putString($this->sourceName); + $out->putString($this->sourceName); case self::TYPE_RAW: case self::TYPE_TIP: case self::TYPE_SYSTEM: case self::TYPE_JSON: - $this->buf->putString($this->message); + $out->putString($this->message); break; case self::TYPE_TRANSLATION: case self::TYPE_POPUP: case self::TYPE_JUKEBOX_POPUP: - $this->buf->putString($this->message); - $this->buf->putUnsignedVarInt(count($this->parameters)); + $out->putString($this->message); + $out->putUnsignedVarInt(count($this->parameters)); foreach($this->parameters as $p){ - $this->buf->putString($p); + $out->putString($p); } break; } - $this->buf->putString($this->xboxUserId); - $this->buf->putString($this->platformChatId); + $out->putString($this->xboxUserId); + $out->putString($this->platformChatId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/TickSyncPacket.php b/src/network/mcpe/protocol/TickSyncPacket.php index c192f6d62..47c0e3c0e 100644 --- a/src/network/mcpe/protocol/TickSyncPacket.php +++ b/src/network/mcpe/protocol/TickSyncPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class TickSyncPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ public const NETWORK_ID = ProtocolInfo::TICK_SYNC_PACKET; @@ -57,14 +58,14 @@ class TickSyncPacket extends DataPacket implements ClientboundPacket, Serverboun return $this->serverReceiveTime; } - protected function decodePayload() : void{ - $this->clientSendTime = $this->buf->getLLong(); - $this->serverReceiveTime = $this->buf->getLLong(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->clientSendTime = $in->getLLong(); + $this->serverReceiveTime = $in->getLLong(); } - protected function encodePayload() : void{ - $this->buf->putLLong($this->clientSendTime); - $this->buf->putLLong($this->serverReceiveTime); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putLLong($this->clientSendTime); + $out->putLLong($this->serverReceiveTime); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/TransferPacket.php b/src/network/mcpe/protocol/TransferPacket.php index d02d1e534..22bc5de94 100644 --- a/src/network/mcpe/protocol/TransferPacket.php +++ b/src/network/mcpe/protocol/TransferPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class TransferPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::TRANSFER_PACKET; @@ -42,14 +43,14 @@ class TransferPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->address = $this->buf->getString(); - $this->port = $this->buf->getLShort(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->address = $in->getString(); + $this->port = $in->getLShort(); } - protected function encodePayload() : void{ - $this->buf->putString($this->address); - $this->buf->putLShort($this->port); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->address); + $out->putLShort($this->port); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/UnknownPacket.php b/src/network/mcpe/protocol/UnknownPacket.php index dee77cce6..c5ba65a7a 100644 --- a/src/network/mcpe/protocol/UnknownPacket.php +++ b/src/network/mcpe/protocol/UnknownPacket.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function ord; use function strlen; @@ -44,20 +45,20 @@ class UnknownPacket extends DataPacket{ return "unknown packet"; } - protected function decodeHeader() : void{ + protected function decodeHeader(NetworkBinaryStream $in) : void{ } - protected function decodePayload() : void{ - $this->payload = $this->buf->getRemaining(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->payload = $in->getRemaining(); } - protected function encodeHeader() : void{ + protected function encodeHeader(NetworkBinaryStream $out) : void{ } - protected function encodePayload() : void{ - $this->buf->put($this->payload); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->put($this->payload); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/UpdateAttributesPacket.php b/src/network/mcpe/protocol/UpdateAttributesPacket.php index 4f14f13d8..65c25dd12 100644 --- a/src/network/mcpe/protocol/UpdateAttributesPacket.php +++ b/src/network/mcpe/protocol/UpdateAttributesPacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\entity\Attribute; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function array_values; class UpdateAttributesPacket extends DataPacket implements ClientboundPacket{ @@ -49,14 +50,14 @@ class UpdateAttributesPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->entityRuntimeId = $this->buf->getEntityRuntimeId(); - $this->entries = $this->buf->getAttributeList(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->entityRuntimeId = $in->getEntityRuntimeId(); + $this->entries = $in->getAttributeList(); } - protected function encodePayload() : void{ - $this->buf->putEntityRuntimeId($this->entityRuntimeId); - $this->buf->putAttributeList(...array_values($this->entries)); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putEntityRuntimeId($this->entityRuntimeId); + $out->putAttributeList(...array_values($this->entries)); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/UpdateBlockPacket.php b/src/network/mcpe/protocol/UpdateBlockPacket.php index 314999ef6..c7cb2669a 100644 --- a/src/network/mcpe/protocol/UpdateBlockPacket.php +++ b/src/network/mcpe/protocol/UpdateBlockPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class UpdateBlockPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::UPDATE_BLOCK_PACKET; @@ -58,18 +59,18 @@ class UpdateBlockPacket extends DataPacket implements ClientboundPacket{ return $result; } - protected function decodePayload() : void{ - $this->buf->getBlockPosition($this->x, $this->y, $this->z); - $this->blockRuntimeId = $this->buf->getUnsignedVarInt(); - $this->flags = $this->buf->getUnsignedVarInt(); - $this->dataLayerId = $this->buf->getUnsignedVarInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $in->getBlockPosition($this->x, $this->y, $this->z); + $this->blockRuntimeId = $in->getUnsignedVarInt(); + $this->flags = $in->getUnsignedVarInt(); + $this->dataLayerId = $in->getUnsignedVarInt(); } - protected function encodePayload() : void{ - $this->buf->putBlockPosition($this->x, $this->y, $this->z); - $this->buf->putUnsignedVarInt($this->blockRuntimeId); - $this->buf->putUnsignedVarInt($this->flags); - $this->buf->putUnsignedVarInt($this->dataLayerId); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putBlockPosition($this->x, $this->y, $this->z); + $out->putUnsignedVarInt($this->blockRuntimeId); + $out->putUnsignedVarInt($this->flags); + $out->putUnsignedVarInt($this->dataLayerId); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/UpdateBlockPropertiesPacket.php b/src/network/mcpe/protocol/UpdateBlockPropertiesPacket.php index 1ab72c79d..838a7a4ef 100644 --- a/src/network/mcpe/protocol/UpdateBlockPropertiesPacket.php +++ b/src/network/mcpe/protocol/UpdateBlockPropertiesPacket.php @@ -28,6 +28,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\TreeRoot; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use pocketmine\network\mcpe\serializer\NetworkNbtSerializer; class UpdateBlockPropertiesPacket extends DataPacket implements ClientboundPacket{ @@ -42,12 +43,12 @@ class UpdateBlockPropertiesPacket extends DataPacket implements ClientboundPacke return $result; } - protected function decodePayload() : void{ - $this->nbt = $this->buf->getRemaining(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->nbt = $in->getRemaining(); } - protected function encodePayload() : void{ - $this->buf->put($this->nbt); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->put($this->nbt); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/UpdateBlockSyncedPacket.php b/src/network/mcpe/protocol/UpdateBlockSyncedPacket.php index ace3894d8..605550dd3 100644 --- a/src/network/mcpe/protocol/UpdateBlockSyncedPacket.php +++ b/src/network/mcpe/protocol/UpdateBlockSyncedPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class UpdateBlockSyncedPacket extends UpdateBlockPacket{ public const NETWORK_ID = ProtocolInfo::UPDATE_BLOCK_SYNCED_PACKET; @@ -35,16 +36,16 @@ class UpdateBlockSyncedPacket extends UpdateBlockPacket{ /** @var int */ public $uvarint64_2 = 0; - protected function decodePayload() : void{ - parent::decodePayload(); - $this->entityUniqueId = $this->buf->getUnsignedVarLong(); - $this->uvarint64_2 = $this->buf->getUnsignedVarLong(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + parent::decodePayload($in); + $this->entityUniqueId = $in->getUnsignedVarLong(); + $this->uvarint64_2 = $in->getUnsignedVarLong(); } - protected function encodePayload() : void{ - parent::encodePayload(); - $this->buf->putUnsignedVarLong($this->entityUniqueId); - $this->buf->putUnsignedVarLong($this->uvarint64_2); + protected function encodePayload(NetworkBinaryStream $out) : void{ + parent::encodePayload($out); + $out->putUnsignedVarLong($this->entityUniqueId); + $out->putUnsignedVarLong($this->uvarint64_2); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/UpdateEquipPacket.php b/src/network/mcpe/protocol/UpdateEquipPacket.php index 9567e865f..3c155c611 100644 --- a/src/network/mcpe/protocol/UpdateEquipPacket.php +++ b/src/network/mcpe/protocol/UpdateEquipPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class UpdateEquipPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::UPDATE_EQUIP_PACKET; @@ -41,20 +42,20 @@ class UpdateEquipPacket extends DataPacket implements ClientboundPacket{ /** @var string */ public $namedtag; - protected function decodePayload() : void{ - $this->windowId = $this->buf->getByte(); - $this->windowType = $this->buf->getByte(); - $this->unknownVarint = $this->buf->getVarInt(); - $this->entityUniqueId = $this->buf->getEntityUniqueId(); - $this->namedtag = $this->buf->getRemaining(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->windowId = $in->getByte(); + $this->windowType = $in->getByte(); + $this->unknownVarint = $in->getVarInt(); + $this->entityUniqueId = $in->getEntityUniqueId(); + $this->namedtag = $in->getRemaining(); } - protected function encodePayload() : void{ - $this->buf->putByte($this->windowId); - $this->buf->putByte($this->windowType); - $this->buf->putVarInt($this->unknownVarint); - $this->buf->putEntityUniqueId($this->entityUniqueId); - $this->buf->put($this->namedtag); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->windowId); + $out->putByte($this->windowType); + $out->putVarInt($this->unknownVarint); + $out->putEntityUniqueId($this->entityUniqueId); + $out->put($this->namedtag); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/UpdateSoftEnumPacket.php b/src/network/mcpe/protocol/UpdateSoftEnumPacket.php index 5744a02c4..f838a195d 100644 --- a/src/network/mcpe/protocol/UpdateSoftEnumPacket.php +++ b/src/network/mcpe/protocol/UpdateSoftEnumPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; use function count; class UpdateSoftEnumPacket extends DataPacket implements ClientboundPacket{ @@ -42,21 +43,21 @@ class UpdateSoftEnumPacket extends DataPacket implements ClientboundPacket{ /** @var int */ public $type; - protected function decodePayload() : void{ - $this->enumName = $this->buf->getString(); - for($i = 0, $count = $this->buf->getUnsignedVarInt(); $i < $count; ++$i){ - $this->values[] = $this->buf->getString(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->enumName = $in->getString(); + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $this->values[] = $in->getString(); } - $this->type = $this->buf->getByte(); + $this->type = $in->getByte(); } - protected function encodePayload() : void{ - $this->buf->putString($this->enumName); - $this->buf->putUnsignedVarInt(count($this->values)); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->enumName); + $out->putUnsignedVarInt(count($this->values)); foreach($this->values as $v){ - $this->buf->putString($v); + $out->putString($v); } - $this->buf->putByte($this->type); + $out->putByte($this->type); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/UpdateTradePacket.php b/src/network/mcpe/protocol/UpdateTradePacket.php index 36e39ef8e..6fc84a9c1 100644 --- a/src/network/mcpe/protocol/UpdateTradePacket.php +++ b/src/network/mcpe/protocol/UpdateTradePacket.php @@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; use pocketmine\network\mcpe\protocol\types\inventory\WindowTypes; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class UpdateTradePacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::UPDATE_TRADE_PACKET; @@ -54,30 +55,30 @@ class UpdateTradePacket extends DataPacket implements ClientboundPacket{ /** @var string */ public $offers; - protected function decodePayload() : void{ - $this->windowId = $this->buf->getByte(); - $this->windowType = $this->buf->getByte(); - $this->thisIsAlwaysZero = $this->buf->getVarInt(); - $this->tradeTier = $this->buf->getVarInt(); - $this->traderEid = $this->buf->getEntityUniqueId(); - $this->playerEid = $this->buf->getEntityUniqueId(); - $this->displayName = $this->buf->getString(); - $this->isV2Trading = $this->buf->getBool(); - $this->isWilling = $this->buf->getBool(); - $this->offers = $this->buf->getRemaining(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->windowId = $in->getByte(); + $this->windowType = $in->getByte(); + $this->thisIsAlwaysZero = $in->getVarInt(); + $this->tradeTier = $in->getVarInt(); + $this->traderEid = $in->getEntityUniqueId(); + $this->playerEid = $in->getEntityUniqueId(); + $this->displayName = $in->getString(); + $this->isV2Trading = $in->getBool(); + $this->isWilling = $in->getBool(); + $this->offers = $in->getRemaining(); } - protected function encodePayload() : void{ - $this->buf->putByte($this->windowId); - $this->buf->putByte($this->windowType); - $this->buf->putVarInt($this->thisIsAlwaysZero); - $this->buf->putVarInt($this->tradeTier); - $this->buf->putEntityUniqueId($this->traderEid); - $this->buf->putEntityUniqueId($this->playerEid); - $this->buf->putString($this->displayName); - $this->buf->putBool($this->isV2Trading); - $this->buf->putBool($this->isWilling); - $this->buf->put($this->offers); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putByte($this->windowId); + $out->putByte($this->windowType); + $out->putVarInt($this->thisIsAlwaysZero); + $out->putVarInt($this->tradeTier); + $out->putEntityUniqueId($this->traderEid); + $out->putEntityUniqueId($this->playerEid); + $out->putString($this->displayName); + $out->putBool($this->isV2Trading); + $out->putBool($this->isWilling); + $out->put($this->offers); } public function handle(PacketHandler $handler) : bool{ diff --git a/src/network/mcpe/protocol/VideoStreamConnectPacket.php b/src/network/mcpe/protocol/VideoStreamConnectPacket.php index d599b2a61..94e8250c2 100644 --- a/src/network/mcpe/protocol/VideoStreamConnectPacket.php +++ b/src/network/mcpe/protocol/VideoStreamConnectPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class VideoStreamConnectPacket extends DataPacket implements ClientboundPacket{ public const NETWORK_ID = ProtocolInfo::VIDEO_STREAM_CONNECT_PACKET; @@ -44,20 +45,20 @@ class VideoStreamConnectPacket extends DataPacket implements ClientboundPacket{ /** @var int */ public $resolutionY; - protected function decodePayload() : void{ - $this->serverUri = $this->buf->getString(); - $this->frameSendFrequency = $this->buf->getLFloat(); - $this->action = $this->buf->getByte(); - $this->resolutionX = $this->buf->getLInt(); - $this->resolutionY = $this->buf->getLInt(); + protected function decodePayload(NetworkBinaryStream $in) : void{ + $this->serverUri = $in->getString(); + $this->frameSendFrequency = $in->getLFloat(); + $this->action = $in->getByte(); + $this->resolutionX = $in->getLInt(); + $this->resolutionY = $in->getLInt(); } - protected function encodePayload() : void{ - $this->buf->putString($this->serverUri); - $this->buf->putLFloat($this->frameSendFrequency); - $this->buf->putByte($this->action); - $this->buf->putLInt($this->resolutionX); - $this->buf->putLInt($this->resolutionY); + protected function encodePayload(NetworkBinaryStream $out) : void{ + $out->putString($this->serverUri); + $out->putLFloat($this->frameSendFrequency); + $out->putByte($this->action); + $out->putLInt($this->resolutionX); + $out->putLInt($this->resolutionY); } public function handle(PacketHandler $handler) : bool{ diff --git a/tests/phpunit/network/mcpe/protocol/TestPacket.php b/tests/phpunit/network/mcpe/protocol/TestPacket.php index 86e82f2d0..17a30bcb0 100644 --- a/tests/phpunit/network/mcpe/protocol/TestPacket.php +++ b/tests/phpunit/network/mcpe/protocol/TestPacket.php @@ -24,15 +24,16 @@ declare(strict_types=1); namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\handler\PacketHandler; +use pocketmine\network\mcpe\serializer\NetworkBinaryStream; class TestPacket extends DataPacket{ public const NETWORK_ID = 1023; - protected function decodePayload() : void{ + protected function decodePayload(NetworkBinaryStream $in) : void{ } - protected function encodePayload() : void{ + protected function encodePayload(NetworkBinaryStream $out) : void{ }