From b455a742779fee94d25f931cc2cbf6b2c5d61c1f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 25 Oct 2022 22:51:46 +0100 Subject: [PATCH] Protocol changes for 1.19.40 --- src/AddActorPacket.php | 8 +++ src/AddPlayerPacket.php | 6 ++ src/ProtocolInfo.php | 6 +- src/SetActorDataPacket.php | 7 ++- src/types/UpdateAbilitiesPacketLayer.php | 1 + src/types/entity/PropertySyncData.php | 74 ++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 src/types/entity/PropertySyncData.php diff --git a/src/AddActorPacket.php b/src/AddActorPacket.php index 396ace1c..d1110fa1 100644 --- a/src/AddActorPacket.php +++ b/src/AddActorPacket.php @@ -19,6 +19,7 @@ use pocketmine\network\mcpe\protocol\types\entity\Attribute; use pocketmine\network\mcpe\protocol\types\entity\EntityLink; use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty; +use pocketmine\network\mcpe\protocol\types\entity\PropertySyncData; use function count; class AddActorPacket extends DataPacket implements ClientboundPacket{ @@ -41,6 +42,7 @@ class AddActorPacket extends DataPacket implements ClientboundPacket{ * @phpstan-var array */ public array $metadata = []; + public PropertySyncData $syncedProperties; /** @var EntityLink[] */ public array $links = []; @@ -63,6 +65,7 @@ public static function create( float $bodyYaw, array $attributes, array $metadata, + PropertySyncData $syncedProperties, array $links, ) : self{ $result = new self; @@ -77,6 +80,7 @@ public static function create( $result->bodyYaw = $bodyYaw; $result->attributes = $attributes; $result->metadata = $metadata; + $result->syncedProperties = $syncedProperties; $result->links = $links; return $result; } @@ -102,6 +106,8 @@ protected function decodePayload(PacketSerializer $in) : void{ } $this->metadata = $in->getEntityMetadata(); + $this->syncedProperties = PropertySyncData::read($in); + $linkCount = $in->getUnsignedVarInt(); for($i = 0; $i < $linkCount; ++$i){ $this->links[] = $in->getEntityLink(); @@ -128,6 +134,8 @@ protected function encodePayload(PacketSerializer $out) : void{ } $out->putEntityMetadata($this->metadata); + $this->syncedProperties->write($out); + $out->putUnsignedVarInt(count($this->links)); foreach($this->links as $link){ $out->putEntityLink($link); diff --git a/src/AddPlayerPacket.php b/src/AddPlayerPacket.php index 9371953f..c12334c8 100644 --- a/src/AddPlayerPacket.php +++ b/src/AddPlayerPacket.php @@ -19,6 +19,7 @@ use pocketmine\network\mcpe\protocol\types\DeviceOS; use pocketmine\network\mcpe\protocol\types\entity\EntityLink; use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty; +use pocketmine\network\mcpe\protocol\types\entity\PropertySyncData; use pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper; use Ramsey\Uuid\UuidInterface; use function count; @@ -42,6 +43,7 @@ class AddPlayerPacket extends DataPacket implements ClientboundPacket{ * @phpstan-var array */ public array $metadata = []; + public PropertySyncData $syncedProperties; public UpdateAbilitiesPacket $abilitiesPacket; @@ -69,6 +71,7 @@ public static function create( ItemStackWrapper $item, int $gameMode, array $metadata, + PropertySyncData $syncedProperties, UpdateAbilitiesPacket $abilitiesPacket, array $links, string $deviceId, @@ -87,6 +90,7 @@ public static function create( $result->item = $item; $result->gameMode = $gameMode; $result->metadata = $metadata; + $result->syncedProperties = $syncedProperties; $result->abilitiesPacket = $abilitiesPacket; $result->links = $links; $result->deviceId = $deviceId; @@ -107,6 +111,7 @@ protected function decodePayload(PacketSerializer $in) : void{ $this->item = ItemStackWrapper::read($in); $this->gameMode = $in->getVarInt(); $this->metadata = $in->getEntityMetadata(); + $this->syncedProperties = PropertySyncData::read($in); $this->abilitiesPacket = new UpdateAbilitiesPacket(); $this->abilitiesPacket->decodePayload($in); @@ -133,6 +138,7 @@ protected function encodePayload(PacketSerializer $out) : void{ $this->item->write($out); $out->putVarInt($this->gameMode); $out->putEntityMetadata($this->metadata); + $this->syncedProperties->write($out); $this->abilitiesPacket->encodePayload($out); diff --git a/src/ProtocolInfo.php b/src/ProtocolInfo.php index c71dfbd6..130331cd 100644 --- a/src/ProtocolInfo.php +++ b/src/ProtocolInfo.php @@ -32,11 +32,11 @@ private function __construct(){ */ /** Actual Minecraft: PE protocol version */ - public const CURRENT_PROTOCOL = 554; + public const CURRENT_PROTOCOL = 557; /** Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. */ - public const MINECRAFT_VERSION = 'v1.19.30'; + public const MINECRAFT_VERSION = 'v1.19.40'; /** Version number sent to clients in ping responses. */ - public const MINECRAFT_VERSION_NETWORK = '1.19.30'; + public const MINECRAFT_VERSION_NETWORK = '1.19.40'; public const LOGIN_PACKET = 0x01; public const PLAY_STATUS_PACKET = 0x02; diff --git a/src/SetActorDataPacket.php b/src/SetActorDataPacket.php index 0aaf7783..db698af2 100644 --- a/src/SetActorDataPacket.php +++ b/src/SetActorDataPacket.php @@ -16,6 +16,7 @@ use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; use pocketmine\network\mcpe\protocol\types\entity\MetadataProperty; +use pocketmine\network\mcpe\protocol\types\entity\PropertySyncData; class SetActorDataPacket extends DataPacket implements ClientboundPacket, ServerboundPacket{ //TODO: check why this is serverbound public const NETWORK_ID = ProtocolInfo::SET_ACTOR_DATA_PACKET; @@ -26,6 +27,7 @@ class SetActorDataPacket extends DataPacket implements ClientboundPacket, Server * @phpstan-var array */ public array $metadata; + public PropertySyncData $syncedProperties; public int $tick = 0; /** @@ -33,10 +35,11 @@ class SetActorDataPacket extends DataPacket implements ClientboundPacket, Server * @param MetadataProperty[] $metadata * @phpstan-param array $metadata */ - public static function create(int $actorRuntimeId, array $metadata, int $tick) : self{ + public static function create(int $actorRuntimeId, array $metadata, PropertySyncData $syncedProperties, int $tick) : self{ $result = new self; $result->actorRuntimeId = $actorRuntimeId; $result->metadata = $metadata; + $result->syncedProperties = $syncedProperties; $result->tick = $tick; return $result; } @@ -44,12 +47,14 @@ public static function create(int $actorRuntimeId, array $metadata, int $tick) : protected function decodePayload(PacketSerializer $in) : void{ $this->actorRuntimeId = $in->getActorRuntimeId(); $this->metadata = $in->getEntityMetadata(); + $this->syncedProperties = PropertySyncData::read($in); $this->tick = $in->getUnsignedVarLong(); } protected function encodePayload(PacketSerializer $out) : void{ $out->putActorRuntimeId($this->actorRuntimeId); $out->putEntityMetadata($this->metadata); + $this->syncedProperties->write($out); $out->putUnsignedVarLong($this->tick); } diff --git a/src/types/UpdateAbilitiesPacketLayer.php b/src/types/UpdateAbilitiesPacketLayer.php index bc3e2f70..c34ab725 100644 --- a/src/types/UpdateAbilitiesPacketLayer.php +++ b/src/types/UpdateAbilitiesPacketLayer.php @@ -23,6 +23,7 @@ final class UpdateAbilitiesPacketLayer{ public const LAYER_BASE = 1; public const LAYER_SPECTATOR = 2; public const LAYER_COMMANDS = 3; + public const LAYER_EDITOR = 4; public const ABILITY_BUILD = 0; public const ABILITY_MINE = 1; diff --git a/src/types/entity/PropertySyncData.php b/src/types/entity/PropertySyncData.php new file mode 100644 index 00000000..fea5ef47 --- /dev/null +++ b/src/types/entity/PropertySyncData.php @@ -0,0 +1,74 @@ + + * + * BedrockProtocol is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + */ + +declare(strict_types=1); + +namespace pocketmine\network\mcpe\protocol\types\entity; + +use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; +use function count; + +final class PropertySyncData{ + /** + * @param int[] $intProperties + * @param float[] $floatProperties + * @phpstan-param array $intProperties + * @phpstan-param array $floatProperties + */ + public function __construct( + private array $intProperties, + private array $floatProperties, + ){} + + /** + * @return int[] + * @phpstan-return array + */ + public function getIntProperties() : array{ + return $this->intProperties; + } + + /** + * @return float[] + * @phpstan-return array + */ + public function getFloatProperties() : array{ + return $this->floatProperties; + } + + public static function read(PacketSerializer $in) : self{ + $intProperties = []; + $floatProperties = []; + + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $intProperties[$in->getUnsignedVarInt()] = $in->getVarInt(); + } + for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){ + $floatProperties[$in->getUnsignedVarInt()] = $in->getLFloat(); + } + + return new self($intProperties, $floatProperties); + } + + public function write(PacketSerializer $out) : void{ + $out->putUnsignedVarInt(count($this->intProperties)); + foreach($this->intProperties as $key => $value){ + $out->putUnsignedVarInt($key); + $out->putVarInt($value); + } + $out->putUnsignedVarInt(count($this->floatProperties)); + foreach($this->floatProperties as $key => $value){ + $out->putUnsignedVarInt($key); + $out->putLFloat($value); + } + } +}