From 2720ff96071402cad048067e933b54477128a6b9 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 27 May 2019 16:45:55 +0100 Subject: [PATCH] Skin: debloat geometry in constructor directly --- src/pocketmine/entity/Human.php | 1 - src/pocketmine/entity/Skin.php | 31 +++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index bc744956ff..edca17db84 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -160,7 +160,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ */ public function setSkin(Skin $skin) : void{ $this->skin = $skin; - $this->skin->debloatGeometryData(); } /** diff --git a/src/pocketmine/entity/Skin.php b/src/pocketmine/entity/Skin.php index 7192748622..83d8eff395 100644 --- a/src/pocketmine/entity/Skin.php +++ b/src/pocketmine/entity/Skin.php @@ -27,6 +27,7 @@ use function implode; use function in_array; use function json_decode; use function json_encode; +use function json_last_error_msg; use function strlen; class Skin{ @@ -58,7 +59,22 @@ class Skin{ if($capeData !== "" and strlen($capeData) !== 8192){ throw new \InvalidArgumentException("Invalid cape data size " . strlen($capeData) . " bytes (must be exactly 8192 bytes)"); } - //TODO: validate geometry + + if($geometryData !== ""){ + $decodedGeometry = json_decode($geometryData); + if($decodedGeometry === false){ + throw new \InvalidArgumentException("Invalid geometry data (" . json_last_error_msg() . ")"); + } + + /* + * Hack to cut down on network overhead due to skins, by un-pretty-printing geometry JSON. + * + * Mojang, some stupid reason, send every single model for every single skin in the selected skin-pack. + * Not only that, they are pretty-printed. + * TODO: find out what model crap can be safely dropped from the packet (unless it gets fixed first) + */ + $geometryData = json_encode($decodedGeometry); + } $this->skinId = $skinId; $this->skinData = $skinData; @@ -101,17 +117,4 @@ class Skin{ public function getGeometryData() : string{ return $this->geometryData; } - - /** - * Hack to cut down on network overhead due to skins, by un-pretty-printing geometry JSON. - * - * Mojang, some stupid reason, send every single model for every single skin in the selected skin-pack. - * Not only that, they are pretty-printed. - * TODO: find out what model crap can be safely dropped from the packet (unless it gets fixed first) - */ - public function debloatGeometryData() : void{ - if($this->geometryData !== ""){ - $this->geometryData = (string) json_encode(json_decode($this->geometryData)); - } - } }