PocketMine-MP 5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
Loading...
Searching...
No Matches
ClientDataToSkinDataHelper.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol\types\login;
16
22use function array_map;
23use function base64_decode;
24
26
30 private static function safeB64Decode(string $base64, string $context) : string{
31 $result = base64_decode($base64, true);
32 if($result === false){
33 throw new \InvalidArgumentException("$context: Malformed base64, cannot be decoded");
34 }
35 return $result;
36 }
37
41 public static function fromClientData(ClientData $clientData) : SkinData{
43 $animations = [];
44 foreach($clientData->AnimatedImageData as $k => $animation){
45 $animations[] = new SkinAnimation(
46 new SkinImage(
47 $animation->ImageHeight,
48 $animation->ImageWidth,
49 self::safeB64Decode($animation->Image, "AnimatedImageData.$k.Image")
50 ),
51 $animation->Type,
52 $animation->Frames,
53 $animation->AnimationExpression
54 );
55 }
56 return new SkinData(
57 $clientData->SkinId,
58 $clientData->PlayFabId,
59 self::safeB64Decode($clientData->SkinResourcePatch, "SkinResourcePatch"),
60 new SkinImage($clientData->SkinImageHeight, $clientData->SkinImageWidth, self::safeB64Decode($clientData->SkinData, "SkinData")),
61 $animations,
62 new SkinImage($clientData->CapeImageHeight, $clientData->CapeImageWidth, self::safeB64Decode($clientData->CapeData, "CapeData")),
63 self::safeB64Decode($clientData->SkinGeometryData, "SkinGeometryData"),
64 self::safeB64Decode($clientData->SkinGeometryDataEngineVersion, "SkinGeometryDataEngineVersion"), //yes, they actually base64'd the version!
65 self::safeB64Decode($clientData->SkinAnimationData, "SkinAnimationData"),
66 $clientData->CapeId,
67 null,
68 $clientData->ArmSize,
69 $clientData->SkinColor,
70 array_map(function(ClientDataPersonaSkinPiece $piece) : PersonaSkinPiece{
71 return new PersonaSkinPiece($piece->PieceId, $piece->PieceType, $piece->PackId, $piece->IsDefault, $piece->ProductId);
72 }, $clientData->PersonaPieces),
73 array_map(function(ClientDataPersonaPieceTintColor $tint) : PersonaPieceTintColor{
74 return new PersonaPieceTintColor($tint->PieceType, $tint->Colors);
75 }, $clientData->PieceTintColors),
76 true,
77 $clientData->PremiumSkin,
78 $clientData->PersonaSkin,
79 $clientData->CapeOnClassicSkin,
80 true, //assume this is true? there's no field for it ...
81 $clientData->OverrideSkin ?? true,
82 );
83 }
84}