From a365acc7277c5253fe1d0d99c760aac012ecfa6f Mon Sep 17 00:00:00 2001 From: yefengeeeeeeeeeee <403749250@qq.com> Date: Sat, 3 May 2025 15:32:20 +0800 Subject: [PATCH] Thanks to @Gameherobrine --- src/network/PacketPool.php | 4 ++-- .../protocol/packet/ContainerAckPacket.php | 12 ++++++++++++ .../protocol/packet/ContainerOpenPacket.php | 3 ++- .../packet/ContainerSetContentPacket.php | 8 +++++++- src/network/protocol/packet/DropItemPacket.php | 6 +++++- src/network/protocol/packet/LoginPacket.php | 3 ++- .../protocol/packet/MoveEntityPacket.php | 2 +- .../protocol/packet/PlayerActionPacket.php | 9 ++++++++- src/network/protocol/packet/ReadyPacket.php | 4 +++- .../protocol/packet/RemoveBlockPacket.php | 7 ++++++- .../protocol/packet/RequestChunkPacket.php | 5 ++++- .../protocol/packet/SetEntityDataPacket.php | 1 - src/network/protocol/packet/SetTimePacket.php | 4 +++- src/network/protocol/packet/UseItemPacket.php | 17 ++++++++++++++++- 14 files changed, 71 insertions(+), 14 deletions(-) diff --git a/src/network/PacketPool.php b/src/network/PacketPool.php index 8774e022..4f691b52 100644 --- a/src/network/PacketPool.php +++ b/src/network/PacketPool.php @@ -55,7 +55,7 @@ class PacketPool{ self::registerPacket(AdventureSettingsPacket::class, [8, 9, 10, 11, 12, 13, 14]); self::registerPacket(AnimatePacket::class); - self::registerPacket(ChatPacket::class, [7, 8, 9, 10, 11, 12, 13, 14]); + self::registerPacket(ChatPacket::class, [6, 7, 8, 9, 10, 11, 12, 13, 14]); self::registerPacket(ChunkDataPacket::class); self::registerPacket(ClientConnectPacket::class); self::registerPacket(ClientHandshakePacket::class); @@ -88,7 +88,7 @@ class PacketPool{ self::registerPacket(PingPacket::class); self::registerPacket(PlaceBlockPacket::class); - self::registerPacket(PlayerActionPacket::class, [7, 8, 9, 10, 11, 12, 13, 14]); + self::registerPacket(PlayerActionPacket::class, [6, 7, 8, 9, 10, 11, 12, 13, 14]); self::registerPacket(PlayerArmorEquipmentPacket::class, [9, 10, 11, 12, 13, 14]); self::registerPacket(PlayerEquipmentPacket::class); self::registerPacket(PlayerInputPacket::class, [8, 9, 10, 11, 12, 13, 14]); diff --git a/src/network/protocol/packet/ContainerAckPacket.php b/src/network/protocol/packet/ContainerAckPacket.php index 93309e64..9b411215 100644 --- a/src/network/protocol/packet/ContainerAckPacket.php +++ b/src/network/protocol/packet/ContainerAckPacket.php @@ -2,6 +2,7 @@ class ContainerAckPacket extends RakNetDataPacket{ public $unknwonubyte1; + public $unknwonubyte2; // Only exist in Version 0.3.3 && 0.4.0 public $unknownshort; public $write1; public $write0; @@ -24,6 +25,10 @@ class ContainerAckPacket extends RakNetDataPacket{ public function decode(){ $this->unknwonubyte1 = $this->getByte(); $this->unknownshort = $this->getShort(); + if($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + $this->unknwonubyte2 = $this->getByte(); + return; + } $this->write1 = $this->get(); $this->write0 = $this->get(); ConsoleAPI::debug($this->unknwonubyte1); @@ -33,8 +38,15 @@ class ContainerAckPacket extends RakNetDataPacket{ } public function encode(){ + if($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + $this->reset(); + } $this->putByte($this->unknwonubyte1); $this->putShort($this->unknownshort); + if($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){ + $this->putByte($this->unknwonubyte2); + return; + } $this->put($this->write1); $this->put($this->write0); ConsoleAPI::debug($this->unknwonubyte1); diff --git a/src/network/protocol/packet/ContainerOpenPacket.php b/src/network/protocol/packet/ContainerOpenPacket.php index afdb66ed..e2fca894 100644 --- a/src/network/protocol/packet/ContainerOpenPacket.php +++ b/src/network/protocol/packet/ContainerOpenPacket.php @@ -7,6 +7,7 @@ class ContainerOpenPacket extends RakNetDataPacket{ public $x; public $y; public $z; + public $unknownstring; public function pid(){ if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ @@ -35,7 +36,7 @@ class ContainerOpenPacket extends RakNetDataPacket{ $this->putByte($this->type); $this->putByte($this->slots); if ($this->PROTOCOL <= ProtocolInfo9::CURRENT_PROTOCOL_9){ - $this->putString(); + $this->putString($this->unknownstring); }else{ $this->putInt($this->x); $this->putInt($this->y); diff --git a/src/network/protocol/packet/ContainerSetContentPacket.php b/src/network/protocol/packet/ContainerSetContentPacket.php index 97a5ce78..115058e6 100644 --- a/src/network/protocol/packet/ContainerSetContentPacket.php +++ b/src/network/protocol/packet/ContainerSetContentPacket.php @@ -28,6 +28,9 @@ class ContainerSetContentPacket extends RakNetDataPacket{ for($s = 0; $s < $count and !$this->feof(); ++$s){ $this->slots[$s] = $this->getSlot(); } + if($this->PROTOCOL <= ProtocolInfo9::CURRENT_PROTOCOL_9){ + return; + } if($this->windowid === 0){ $count = $this->getShort(); for($s = 0; $s < $count and !$this->feof(); ++$s){ @@ -43,8 +46,11 @@ class ContainerSetContentPacket extends RakNetDataPacket{ foreach($this->slots as $slot){ $this->putSlot($this->PROTOCOL, $slot); } + if($this->PROTOCOL <= ProtocolInfo9::CURRENT_PROTOCOL_9){ + return; + } if($this->windowid === 0 and count($this->hotbar) > 0){ - $this->putShort(count($this->hotbar));//null + $this->putShort(count($this->hotbar)); foreach($this->hotbar as $slot){ $this->putInt($slot); } diff --git a/src/network/protocol/packet/DropItemPacket.php b/src/network/protocol/packet/DropItemPacket.php index 364afd11..b3fccc5c 100644 --- a/src/network/protocol/packet/DropItemPacket.php +++ b/src/network/protocol/packet/DropItemPacket.php @@ -23,13 +23,17 @@ class DropItemPacket extends RakNetDataPacket{ } public function decode(){ + //if($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8)$this->reset(); $this->eid = $this->getInt(); $this->unknown = $this->getByte(); $this->item = $this->getSlot(); } public function encode(){ - + /*$this->reset(); + $this->putInt($this->eid); + $this->putByte($this->unknown); + $this->putSlot($this->item);*/ } } \ No newline at end of file diff --git a/src/network/protocol/packet/LoginPacket.php b/src/network/protocol/packet/LoginPacket.php index 9bd59938..0d4225a6 100644 --- a/src/network/protocol/packet/LoginPacket.php +++ b/src/network/protocol/packet/LoginPacket.php @@ -12,12 +12,13 @@ class LoginPacket extends RakNetDataPacket{ } public function decode(){ + //if($this->PROTOCOL <= ProtocolInfo9::CURRENT_PROTOCOL_9)$this->reset(); $this->username = $this->getString(); $this->protocol1 = $this->getInt(); $this->protocol2 = $this->getInt(); $this->clientId = $this->getInt();//null $this->loginData = $this->getString(); - $this->PROTOCOL = $this->protocol1; + $this->PROTOCOL = $this->protocol1; } public function encode(){ diff --git a/src/network/protocol/packet/MoveEntityPacket.php b/src/network/protocol/packet/MoveEntityPacket.php index 18032c02..d4cbbf93 100644 --- a/src/network/protocol/packet/MoveEntityPacket.php +++ b/src/network/protocol/packet/MoveEntityPacket.php @@ -14,7 +14,7 @@ class MoveEntityPacket extends RakNetDataPacket{ } public function encode(){ - $this->reset(); + $this->reset(); //null } } \ No newline at end of file diff --git a/src/network/protocol/packet/PlayerActionPacket.php b/src/network/protocol/packet/PlayerActionPacket.php index 9e423e71..945347cc 100644 --- a/src/network/protocol/packet/PlayerActionPacket.php +++ b/src/network/protocol/packet/PlayerActionPacket.php @@ -20,6 +20,7 @@ class PlayerActionPacket extends RakNetDataPacket{ } public function decode(){ + //if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9)$this->reset(); $this->action = $this->getInt(); $this->x = $this->getInt(); $this->y = $this->getInt(); @@ -29,7 +30,13 @@ class PlayerActionPacket extends RakNetDataPacket{ } public function encode(){ - + /*$this->reset(); + $this->putInt($this->action); + $this->putInt($this->x); + $this->putInt($this->y); + $this->putInt($this->z); + $this->putInt($this->face); + $this->putInt($this->eid);*/ } } \ No newline at end of file diff --git a/src/network/protocol/packet/ReadyPacket.php b/src/network/protocol/packet/ReadyPacket.php index 08cd53a1..e6eae824 100644 --- a/src/network/protocol/packet/ReadyPacket.php +++ b/src/network/protocol/packet/ReadyPacket.php @@ -8,11 +8,13 @@ class ReadyPacket extends RakNetDataPacket{ } public function decode(){ + //if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9)$this->reset(); $this->status = $this->getByte(); } public function encode(){ - + /*$this->reset(); + $this->putByte($this->status);*/ } } \ No newline at end of file diff --git a/src/network/protocol/packet/RemoveBlockPacket.php b/src/network/protocol/packet/RemoveBlockPacket.php index f7ba3de5..4c01228c 100644 --- a/src/network/protocol/packet/RemoveBlockPacket.php +++ b/src/network/protocol/packet/RemoveBlockPacket.php @@ -16,6 +16,7 @@ class RemoveBlockPacket extends RakNetDataPacket{ } public function decode(){ + //if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9)$this->reset(); $this->eid = $this->getInt(); $this->x = $this->getInt(); $this->z = $this->getInt(); @@ -23,7 +24,11 @@ class RemoveBlockPacket extends RakNetDataPacket{ } public function encode(){ - + /*$this->reset(); + $this->putInt($this->eid); + $this->putInt($this->x); + $this->putInt($this->z); + $this->putInt($this->y);*/ } } \ No newline at end of file diff --git a/src/network/protocol/packet/RequestChunkPacket.php b/src/network/protocol/packet/RequestChunkPacket.php index 33c1ecc2..8bdeea7c 100644 --- a/src/network/protocol/packet/RequestChunkPacket.php +++ b/src/network/protocol/packet/RequestChunkPacket.php @@ -18,12 +18,15 @@ class RequestChunkPacket extends RakNetDataPacket{ } public function decode(){ + //if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9)$this->reset(); $this->chunkX = $this->getInt(); $this->chunkZ = $this->getInt(); } public function encode(){ - + /*$this->reset(); + $this->putInt($this->chunkX); + $this->putInt($this->chunkZ);*/ } } \ No newline at end of file diff --git a/src/network/protocol/packet/SetEntityDataPacket.php b/src/network/protocol/packet/SetEntityDataPacket.php index eac162d3..160d35c4 100644 --- a/src/network/protocol/packet/SetEntityDataPacket.php +++ b/src/network/protocol/packet/SetEntityDataPacket.php @@ -25,7 +25,6 @@ class SetEntityDataPacket extends RakNetDataPacket{ public function encode(){ $this->reset(); - if($this->PROTOCOL >= ProtocolInfo8::CURRENT_PROTOCOL_8) $this->putInt($this->eid); $this->put(Utils::writeMetadata($this->metadata)); } diff --git a/src/network/protocol/packet/SetTimePacket.php b/src/network/protocol/packet/SetTimePacket.php index c586e97c..afbc9fd2 100644 --- a/src/network/protocol/packet/SetTimePacket.php +++ b/src/network/protocol/packet/SetTimePacket.php @@ -15,7 +15,9 @@ class SetTimePacket extends RakNetDataPacket{ public function encode(){ $this->reset(); $this->putInt($this->time);//long - $this->putByte($this->started ? 0x80:0x00); + if($this->PROTOCOL >= ProtocolInfo8::CURRENT_PROTOCOL_8){ + $this->putByte($this->started ? 0x80:0x00); + } } } \ No newline at end of file diff --git a/src/network/protocol/packet/UseItemPacket.php b/src/network/protocol/packet/UseItemPacket.php index 593df77d..b0d8777c 100644 --- a/src/network/protocol/packet/UseItemPacket.php +++ b/src/network/protocol/packet/UseItemPacket.php @@ -15,6 +15,8 @@ class UseItemPacket extends RakNetDataPacket{ public $posY; public $posZ; + public $unknownInt1; + public function pid(){ if($this->PROTOCOL < ProtocolInfo4::CURRENT_PROTOCOL_4){ return ProtocolInfo3::USE_ITEM_PACKET; @@ -31,6 +33,7 @@ class UseItemPacket extends RakNetDataPacket{ } public function decode(){ + //if($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9)$this->reset(); $this->x = $this->getInt(); $this->y = $this->getInt(); $this->z = $this->getInt(); @@ -38,6 +41,10 @@ class UseItemPacket extends RakNetDataPacket{ $this->item = $this->getShort(); $this->meta = $this->getByte(); //Mojang: fix this $this->eid = $this->getInt(); + if ($this->PROTOCOL > ProtocolInfo9::CURRENT_PROTOCOL_9) { + $this->unknownInt1 = $this->getInt(); + return; + } $this->fx = $this->getFloat(); $this->fy = $this->getFloat(); $this->fz = $this->getFloat(); @@ -49,7 +56,15 @@ class UseItemPacket extends RakNetDataPacket{ } public function encode(){ - + /*$this->reset(); + $this->putInt($this->x); + $this->putInt($this->y); + $this->putInt($this->z); + $this->putInt($this->face); + $this->putShort($this->item); + $this->putByte($this->meta); + $this->putInt($this->eid); + $this->putInt($this->unknownInt1);*/ } } \ No newline at end of file