From c19ab976107446b629e586add9983db83496f0e6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 27 Feb 2020 17:37:45 +0000 Subject: [PATCH 1/2] AddActorPacket: move BC hack to higher level we shouldn't hack the protocol impl for BC. --- src/pocketmine/entity/Entity.php | 2 +- .../network/mcpe/protocol/AddActorPacket.php | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index cfb8be6b7..8838433ba 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1914,7 +1914,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ protected function sendSpawnPacket(Player $player) : void{ $pk = new AddActorPacket(); $pk->entityRuntimeId = $this->getId(); - $pk->type = static::NETWORK_ID; + $pk->type = AddActorPacket::LEGACY_ID_MAP_BC[static::NETWORK_ID]; $pk->position = $this->asVector3(); $pk->motion = $this->getMotion(); $pk->yaw = $this->yaw; diff --git a/src/pocketmine/network/mcpe/protocol/AddActorPacket.php b/src/pocketmine/network/mcpe/protocol/AddActorPacket.php index e3122dc05..cb0e72374 100644 --- a/src/pocketmine/network/mcpe/protocol/AddActorPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddActorPacket.php @@ -148,7 +148,7 @@ class AddActorPacket extends DataPacket{ public $entityUniqueId = null; //TODO /** @var int */ public $entityRuntimeId; - /** @var int */ + /** @var string */ public $type; /** @var Vector3 */ public $position; @@ -174,10 +174,7 @@ class AddActorPacket extends DataPacket{ protected function decodePayload(){ $this->entityUniqueId = $this->getEntityUniqueId(); $this->entityRuntimeId = $this->getEntityRuntimeId(); - $this->type = array_search($t = $this->getString(), self::LEGACY_ID_MAP_BC, true); - if($this->type === false){ - throw new \UnexpectedValueException("Can't map ID $t to legacy ID"); - } + $this->type = $this->getString(); $this->position = $this->getVector3(); $this->motion = $this->getVector3(); $this->pitch = $this->getLFloat(); @@ -212,10 +209,7 @@ class AddActorPacket extends DataPacket{ protected function encodePayload(){ $this->putEntityUniqueId($this->entityUniqueId ?? $this->entityRuntimeId); $this->putEntityRuntimeId($this->entityRuntimeId); - if(!isset(self::LEGACY_ID_MAP_BC[$this->type])){ - throw new \InvalidArgumentException("Unknown entity numeric ID $this->type"); - } - $this->putString(self::LEGACY_ID_MAP_BC[$this->type]); + $this->putString($this->type); $this->putVector3($this->position); $this->putVector3Nullable($this->motion); $this->putLFloat($this->pitch); From 15d81154e6b203a2163fdd509a7c858a20312b20 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 5 Mar 2020 19:53:01 +0000 Subject: [PATCH 2/2] PluginDescription: drop unenforceable type constraint on array keys the data that comes through here isn't validated, and there's also no guarantee that all the keys will be strings in spite of our best efforts even if it was validated, because PHP is fucking stupid and casts int-like string keys to int keys. --- src/pocketmine/plugin/PluginDescription.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pocketmine/plugin/PluginDescription.php b/src/pocketmine/plugin/PluginDescription.php index cd55c9ed4..cc321cbf6 100644 --- a/src/pocketmine/plugin/PluginDescription.php +++ b/src/pocketmine/plugin/PluginDescription.php @@ -89,7 +89,6 @@ class PluginDescription{ /** * @param string|mixed[] $yamlString - * @phpstan-param string|array $yamlString */ public function __construct($yamlString){ $this->loadMap(!is_array($yamlString) ? yaml_parse($yamlString) : $yamlString); @@ -97,7 +96,6 @@ class PluginDescription{ /** * @param mixed[] $plugin - * @phpstan-param array $plugin * @throws PluginException */ private function loadMap(array $plugin) : void{