Skip to content

Commit

Permalink
feat: support saving 256*256 skin (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd authored Jul 14, 2024
1 parent 2751018 commit 7695424
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.cloudburstmc.protocol.common.PacketSignal;
import org.cloudburstmc.proxypass.ProxyPass;
import org.cloudburstmc.proxypass.network.bedrock.util.ForgeryUtils;
import org.cloudburstmc.proxypass.network.bedrock.util.SkinUtils;
import org.jose4j.json.JsonUtil;
import org.jose4j.json.internal.json_simple.JSONObject;
import org.jose4j.jws.JsonWebSignature;
Expand Down Expand Up @@ -125,6 +126,7 @@ private void initializeProxySession() {
jws.setCompactSerialization(jwt);
player.getLogger().saveJson("chainData", new JSONObject(JsonUtil.parseJson(jws.getUnverifiedPayload())));
player.getLogger().saveJson("skinData", this.skinData);
SkinUtils.saveSkin(proxySession, this.skinData);
} catch (Exception e) {
log.error("JSON output error: " + e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class SkinUtils {
public static final int DOUBLE_SKIN_SIZE = 64 * 64 * PIXEL_SIZE;
public static final int SKIN_128_64_SIZE = 128 * 64 * PIXEL_SIZE;
public static final int SKIN_128_128_SIZE = 128 * 128 * PIXEL_SIZE;
public static final int SKIN_256_256_SIZE = 256 * 256 * PIXEL_SIZE;

public static void saveSkin(ProxyPlayerSession session, JSONObject skinData) {
byte[] skin = Base64.getDecoder().decode(JsonUtils.childAsType(skinData, "SkinData", String.class));
Expand All @@ -33,13 +34,18 @@ public static void saveSkin(ProxyPlayerSession session, JSONObject skinData) {
} else if (skin.length == SKIN_128_128_SIZE) {
width = 128;
height = 128;
} else if (skin.length == SKIN_256_256_SIZE) {
width = 256;
height = 256;
} else {
throw new IllegalStateException("Invalid skin");
}
saveImage(session, width, height, skin, "skin");

byte[] cape = Base64.getDecoder().decode(JsonUtils.childAsType(skinData, "CapeData", String.class));
saveImage(session, 64, 32, cape, "cape");
if (cape.length != 0) {
saveImage(session, 64, 32, cape, "cape");
}

byte[] geometry = Base64.getDecoder().decode(JsonUtils.childAsType(skinData, "SkinGeometry", String.class));
session.getLogger().saveJson("geometry", geometry);
Expand Down

0 comments on commit 7695424

Please sign in to comment.