From 1c13ba565660e0985c08f2c6b59e26f8216f87e4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 17 Jun 2020 21:01:01 +0100 Subject: [PATCH] Avoid parameter ordering bugs during packet decoding A PhpStorm refactor could have side effects on code that directly reads stuff from the packet input stream in the arguments block, because those calls will get moved into a different order if the constructor gets refactored. This would, obviously, break packet decoding, so that's something we should avoid and really should not encourage. --- .../network/mcpe/NetworkBinaryStream.php | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/pocketmine/network/mcpe/NetworkBinaryStream.php b/src/pocketmine/network/mcpe/NetworkBinaryStream.php index 0586f0e17..04615d369 100644 --- a/src/pocketmine/network/mcpe/NetworkBinaryStream.php +++ b/src/pocketmine/network/mcpe/NetworkBinaryStream.php @@ -88,11 +88,10 @@ class NetworkBinaryStream extends BinaryStream{ $animationCount = $this->getLInt(); $animations = []; for($i = 0; $i < $animationCount; ++$i){ - $animations[] = new SkinAnimation( - $skinImage = $this->getSkinImage(), - $animationType = $this->getLInt(), - $animationFrames = $this->getLFloat() - ); + $skinImage = $this->getSkinImage(); + $animationType = $this->getLInt(); + $animationFrames = $this->getLFloat(); + $animations[] = new SkinAnimation($skinImage, $animationType, $animationFrames); } $capeData = $this->getSkinImage(); $geometryData = $this->getString(); @@ -107,13 +106,12 @@ class NetworkBinaryStream extends BinaryStream{ $personaPieceCount = $this->getLInt(); $personaPieces = []; for($i = 0; $i < $personaPieceCount; ++$i){ - $personaPieces[] = new PersonaSkinPiece( - $pieceId = $this->getString(), - $pieceType = $this->getString(), - $packId = $this->getString(), - $isDefaultPiece = $this->getBool(), - $productId = $this->getString() - ); + $pieceId = $this->getString(); + $pieceType = $this->getString(); + $packId = $this->getString(); + $isDefaultPiece = $this->getBool(); + $productId = $this->getString(); + $personaPieces[] = new PersonaSkinPiece($pieceId, $pieceType, $packId, $isDefaultPiece, $productId); } $pieceTintColorCount = $this->getLInt(); $pieceTintColors = []; @@ -546,11 +544,10 @@ class NetworkBinaryStream extends BinaryStream{ * Reads a floating-point Vector3 object with coordinates rounded to 4 decimal places. */ public function getVector3() : Vector3{ - return new Vector3( - $this->getLFloat(), - $this->getLFloat(), - $this->getLFloat() - ); + $x = $this->getLFloat(); + $y = $this->getLFloat(); + $z = $this->getLFloat(); + return new Vector3($x, $y, $z); } /** @@ -647,12 +644,11 @@ class NetworkBinaryStream extends BinaryStream{ } protected function getEntityLink() : EntityLink{ - return new EntityLink( - $fromEntityUniqueId = $this->getEntityUniqueId(), - $toEntityUniqueId = $this->getEntityUniqueId(), - $type = $this->getByte(), - $immediate = $this->getBool() - ); + $fromEntityUniqueId = $this->getEntityUniqueId(); + $toEntityUniqueId = $this->getEntityUniqueId(); + $type = $this->getByte(); + $immediate = $this->getBool(); + return new EntityLink($fromEntityUniqueId, $toEntityUniqueId, $type, $immediate); } protected function putEntityLink(EntityLink $link) : void{