Clean up duplicated skin entries

This commit is contained in:
Stephen 2019-11-05 20:30:41 -05:00
parent 3b7ded0ba3
commit 5b11ddee35
3 changed files with 53 additions and 84 deletions

View File

@ -27,6 +27,7 @@ namespace pocketmine\network\mcpe;
use pocketmine\entity\Attribute;
use pocketmine\entity\Entity;
use pocketmine\entity\Skin;
use pocketmine\item\Durable;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
@ -40,6 +41,7 @@ use pocketmine\network\mcpe\protocol\types\EntityLink;
use pocketmine\network\mcpe\protocol\types\StructureSettings;
use pocketmine\utils\BinaryStream;
use pocketmine\utils\SerializedImage;
use pocketmine\utils\SkinAnimation;
use pocketmine\utils\UUID;
use function count;
use function strlen;
@ -75,10 +77,47 @@ class NetworkBinaryStream extends BinaryStream{
$this->putLInt($uuid->getPart(2));
}
public function putImage(SerializedImage $image) : void{
$this->putLInt($image->getWidth());
$this->putLInt($image->getHeight());
$this->putString($image->getData());
public function getSkin() : Skin{
$skinId = $this->getString();
$skinResourcePatch = $this->getString();
$skinData = $this->getImage();
$animationCount = $this->getLInt();
$animations = [];
for($i = 0; $i < $animationCount; ++$i){
$animations[] = new SkinAnimation($this->getImage(), $this->getLInt(), $this->getLFloat());
}
$capeData = $this->getImage();
$geometryData = $this->getString();
$animationData = $this->getString();
$premium = $this->getBool();
$persona = $this->getBool();
$capeOnClassic = $this->getBool();
$capeId = $this->getString();
$fullSkinId = $this->getString();
return new Skin(
$skinId, $skinResourcePatch, $skinData, $animations, $capeData, $geometryData, $animationData, $premium, $persona, $capeOnClassic, $capeId
);
}
public function putSkin(Skin $skin){
$this->putString($skin->getSkinId());
$this->putString($skin->getSkinResourcePatch());
$this->putImage($skin->getSkinData());
$this->putLInt(count($skin->getAnimations()));
foreach($skin->getAnimations() as $animation){
$this->putImage($animation->getImage());
$this->putLInt($animation->getType());
$this->putLFloat($animation->getFrames());
}
$this->putImage($skin->getCapeData());
$this->putString($skin->getGeometryData());
$this->putString($skin->getAnimationData());
$this->putBool($skin->getPremium());
$this->putBool($skin->getPersona());
$this->putBool($skin->getCapeOnClassic());
$this->putString($skin->getCapeId());
$this->putString($skin->getFullSkinId());
}
public function getImage() : SerializedImage{
@ -88,6 +127,12 @@ class NetworkBinaryStream extends BinaryStream{
return new SerializedImage($height, $width, $data);
}
public function putImage(SerializedImage $image) : void{
$this->putLInt($image->getWidth());
$this->putLInt($image->getHeight());
$this->putString($image->getData());
}
public function getSlot() : Item{
$id = $this->getVarInt();
if($id === 0){

View File

@ -62,28 +62,7 @@ class PlayerListPacket extends DataPacket{
$entry->xboxUserId = $this->getString();
$entry->platformChatId = $this->getString();
$entry->buildPlatform = $this->getLInt();
$skinId = $this->getString();
$skinResourcePatch = $this->getString();
$skinData = $this->getImage();
$animationCount = $this->getLInt();
$animations = [];
for($i = 0; $i < $animationCount; ++$i){
$animations[] = new SkinAnimation($this->getImage(), $this->getLInt(), $this->getLFloat());
}
$capeData = $this->getImage();
$geometryData = $this->getString();
$animationData = $this->getString();
$premium = $this->getBool();
$persona = $this->getBool();
$capeOnClassic = $this->getBool();
$capeId = $this->getString();
$fullSkinId = $this->getString();
$entry->skin = new Skin(
$skinId, $skinResourcePatch, $skinData, $animations, $capeData, $geometryData, $animationData, $premium, $persona, $capeOnClassic, $capeId
);
$entry->skin = $this->getSkin();
$entry->isTeacher = $this->getBool();
$entry->isHost = $this->getBool();
}else{
@ -105,25 +84,7 @@ class PlayerListPacket extends DataPacket{
$this->putString($entry->xboxUserId);
$this->putString($entry->platformChatId);
$this->putLInt($entry->buildPlatform);
$this->putString($entry->skin->getSkinId());
$this->putString($entry->skin->getSkinResourcePatch());
$this->putImage($entry->skin->getSkinData());
$this->putLInt(count($entry->skin->getAnimations()));
foreach($entry->skin->getAnimations() as $animation){
$this->putImage($animation->getImage());
$this->putLInt($animation->getType());
$this->putLFloat($animation->getFrames());
}
$this->putImage($entry->skin->getCapeData());
$this->putString($entry->skin->getGeometryData());
$this->putString($entry->skin->getAnimationData());
$this->putBool($entry->skin->getPremium());
$this->putBool($entry->skin->getPersona());
$this->putBool($entry->skin->getCapeOnClassic());
$this->putString($entry->skin->getCapeId());
$this->putString($entry->skin->getFullSkinId());
$this->putSkin($entry->skin);
$this->putBool($entry->isTeacher);
$this->putBool($entry->isHost);
}else{

View File

@ -41,49 +41,12 @@ class PlayerSkinPacket extends DataPacket{
protected function decodePayload(){
$this->uuid = $this->getUUID();
$skinId = $this->getString();
$skinResourcePatch = $this->getString();
$skinData = $this->getImage();
$animationCount = $this->getLInt();
$animations = [];
for($i = 0; $i < $animationCount; ++$i){
$animations[] = new SkinAnimation($this->getImage(), $this->getLInt(), $this->getLFloat());
}
$capeData = $this->getImage();
$geometryData = $this->getString();
$animationData = $this->getString();
$premium = $this->getBool();
$persona = $this->getBool();
$capeOnClassic = $this->getBool();
$capeId = $this->getString();
$fullSkinId = $this->getString();
$this->skin = new Skin(
$skinId, $skinResourcePatch, $skinData, $animations, $capeData, $geometryData, $animationData, $premium, $persona, $capeOnClassic, $capeId
);
$this->skin = $this->getSkin();
}
protected function encodePayload(){
$this->putUUID($this->uuid);
$this->putString($this->skin->getSkinId());
$this->putString($this->skin->getSkinResourcePatch());
$this->putImage($this->skin->getSkinData());
$this->putLInt(count($this->skin->getAnimations()));
foreach($this->skin->getAnimations() as $animation){
$this->putImage($animation->getImage());
$this->putLInt($animation->getType());
$this->putLFloat($animation->getFrames());
}
$this->putImage($this->skin->getCapeData());
$this->putString($this->skin->getGeometryData());
$this->putString($this->skin->getAnimationData());
$this->putBool($this->skin->getPremium());
$this->putBool($this->skin->getPersona());
$this->putBool($this->skin->getCapeOnClassic());
$this->putString($this->skin->getCapeId());
$this->putString($this->skin->getFullSkinId());
$this->putSkin($this->skin);
}
public function handle(NetworkSession $session) : bool{