From 98c10cba785ce923481a047f0b97f075220dd0e4 Mon Sep 17 00:00:00 2001 From: hax0r31337 Date: Mon, 24 Apr 2023 10:59:25 +0000 Subject: [PATCH] fix: some servers sent -1 for default player permission (recoded) --- .../codec/v291/serializer/StartGameSerializer_v291.java | 5 +++-- .../codec/v332/serializer/StartGameSerializer_v332.java | 5 +++-- .../codec/v407/serializer/StartGameSerializer_v407.java | 5 +++-- .../codec/v419/serializer/StartGameSerializer_v419.java | 5 +++-- .../codec/v465/serializer/StartGameSerializer_v465.java | 5 +++-- .../codec/v534/serializer/StartGameSerializer_v534.java | 5 +++-- .../codec/v544/serializer/StartGameSerializer_v544.java | 5 +++-- .../codec/v567/serializer/StartGameSerializer_v567.java | 5 +++-- .../codec/v582/serializer/StartGameSerializer_v582.java | 5 +++-- 9 files changed, 27 insertions(+), 18 deletions(-) diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v291/serializer/StartGameSerializer_v291.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v291/serializer/StartGameSerializer_v291.java index 7f9982d3d..6a1eaa1fe 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v291/serializer/StartGameSerializer_v291.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v291/serializer/StartGameSerializer_v291.java @@ -105,7 +105,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta buffer.writeBoolean(packet.isBonusChestEnabled()); buffer.writeBoolean(packet.isStartingWithMap()); buffer.writeBoolean(packet.isTrustingPlayers()); - VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); + VarInts.writeInt(buffer, packet.getDefaultPlayerPermission() == null ? -1 : packet.getDefaultPlayerPermission().ordinal()); VarInts.writeInt(buffer, packet.getXblBroadcastMode().ordinal()); buffer.writeIntLE(packet.getServerChunkTickRange()); buffer.writeBoolean(packet.getPlatformBroadcastMode() != GamePublishSetting.NO_MULTI_PLAY); @@ -139,7 +139,8 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); packet.setTrustingPlayers(buffer.readBoolean()); - packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); + final int ordinal = VarInts.readInt(buffer); + packet.setDefaultPlayerPermission(ordinal == -1 ? null : PLAYER_PERMISSIONS[ordinal]); packet.setXblBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer))); packet.setServerChunkTickRange(buffer.readIntLE()); buffer.readBoolean(); // Broadcasting to Platform diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v332/serializer/StartGameSerializer_v332.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v332/serializer/StartGameSerializer_v332.java index 2c636b130..ad259c2cf 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v332/serializer/StartGameSerializer_v332.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v332/serializer/StartGameSerializer_v332.java @@ -38,7 +38,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta helper.writeArray(buffer, packet.getGamerules(), helper::writeGameRule); buffer.writeBoolean(packet.isBonusChestEnabled()); buffer.writeBoolean(packet.isStartingWithMap()); - VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); + VarInts.writeInt(buffer, packet.getDefaultPlayerPermission() == null ? -1 : packet.getDefaultPlayerPermission().ordinal()); buffer.writeIntLE(packet.getServerChunkTickRange()); buffer.writeBoolean(packet.isBehaviorPackLocked()); buffer.writeBoolean(packet.isResourcePackLocked()); @@ -72,7 +72,8 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star helper.readArray(buffer, packet.getGamerules(), helper::readGameRule); packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); - packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); + final int ordinal = VarInts.readInt(buffer); + packet.setDefaultPlayerPermission(ordinal == -1 ? null : PLAYER_PERMISSIONS[ordinal]); packet.setServerChunkTickRange(buffer.readIntLE()); packet.setBehaviorPackLocked(buffer.readBoolean()); packet.setResourcePackLocked(buffer.readBoolean()); diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v407/serializer/StartGameSerializer_v407.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v407/serializer/StartGameSerializer_v407.java index ca87b0cf8..13c8c1cb3 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v407/serializer/StartGameSerializer_v407.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v407/serializer/StartGameSerializer_v407.java @@ -61,7 +61,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta helper.writeArray(buffer, packet.getGamerules(), helper::writeGameRule); buffer.writeBoolean(packet.isBonusChestEnabled()); buffer.writeBoolean(packet.isStartingWithMap()); - VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); + VarInts.writeInt(buffer, packet.getDefaultPlayerPermission() == null ? -1 : packet.getDefaultPlayerPermission().ordinal()); buffer.writeIntLE(packet.getServerChunkTickRange()); buffer.writeBoolean(packet.isBehaviorPackLocked()); buffer.writeBoolean(packet.isResourcePackLocked()); @@ -105,7 +105,8 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star helper.readArray(buffer, packet.getGamerules(), helper::readGameRule); packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); - packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); + final int ordinal = VarInts.readInt(buffer); + packet.setDefaultPlayerPermission(ordinal == -1 ? null : PLAYER_PERMISSIONS[ordinal]); packet.setServerChunkTickRange(buffer.readIntLE()); packet.setBehaviorPackLocked(buffer.readBoolean()); packet.setResourcePackLocked(buffer.readBoolean()); diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v419/serializer/StartGameSerializer_v419.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v419/serializer/StartGameSerializer_v419.java index 764dc313e..5f0b692ba 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v419/serializer/StartGameSerializer_v419.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v419/serializer/StartGameSerializer_v419.java @@ -117,7 +117,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta buffer.writeBoolean(packet.isExperimentsPreviouslyToggled()); buffer.writeBoolean(packet.isBonusChestEnabled()); buffer.writeBoolean(packet.isStartingWithMap()); - VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); + VarInts.writeInt(buffer, packet.getDefaultPlayerPermission() == null ? -1 : packet.getDefaultPlayerPermission().ordinal()); buffer.writeIntLE(packet.getServerChunkTickRange()); buffer.writeBoolean(packet.isBehaviorPackLocked()); buffer.writeBoolean(packet.isResourcePackLocked()); @@ -162,7 +162,8 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star packet.setExperimentsPreviouslyToggled(buffer.readBoolean()); packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); - packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); + final int ordinal = VarInts.readInt(buffer); + packet.setDefaultPlayerPermission(ordinal == -1 ? null : PLAYER_PERMISSIONS[ordinal]); packet.setServerChunkTickRange(buffer.readIntLE()); packet.setBehaviorPackLocked(buffer.readBoolean()); packet.setResourcePackLocked(buffer.readBoolean()); diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v465/serializer/StartGameSerializer_v465.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v465/serializer/StartGameSerializer_v465.java index d17eb4bb3..812c4a4c2 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v465/serializer/StartGameSerializer_v465.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v465/serializer/StartGameSerializer_v465.java @@ -46,7 +46,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta buffer.writeBoolean(packet.isExperimentsPreviouslyToggled()); buffer.writeBoolean(packet.isBonusChestEnabled()); buffer.writeBoolean(packet.isStartingWithMap()); - VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); + VarInts.writeInt(buffer, packet.getDefaultPlayerPermission() == null ? -1 : packet.getDefaultPlayerPermission().ordinal()); buffer.writeIntLE(packet.getServerChunkTickRange()); buffer.writeBoolean(packet.isBehaviorPackLocked()); buffer.writeBoolean(packet.isResourcePackLocked()); @@ -94,7 +94,8 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star packet.setExperimentsPreviouslyToggled(buffer.readBoolean()); packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); - packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); + final int ordinal = VarInts.readInt(buffer); + packet.setDefaultPlayerPermission(ordinal == -1 ? null : PLAYER_PERMISSIONS[ordinal]); packet.setServerChunkTickRange(buffer.readIntLE()); packet.setBehaviorPackLocked(buffer.readBoolean()); packet.setResourcePackLocked(buffer.readBoolean()); diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v534/serializer/StartGameSerializer_v534.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v534/serializer/StartGameSerializer_v534.java index 050843695..879209dcb 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v534/serializer/StartGameSerializer_v534.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v534/serializer/StartGameSerializer_v534.java @@ -47,7 +47,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta buffer.writeBoolean(packet.isExperimentsPreviouslyToggled()); buffer.writeBoolean(packet.isBonusChestEnabled()); buffer.writeBoolean(packet.isStartingWithMap()); - VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); + VarInts.writeInt(buffer, packet.getDefaultPlayerPermission() == null ? -1 : packet.getDefaultPlayerPermission().ordinal()); buffer.writeIntLE(packet.getServerChunkTickRange()); buffer.writeBoolean(packet.isBehaviorPackLocked()); buffer.writeBoolean(packet.isResourcePackLocked()); @@ -96,7 +96,8 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star packet.setExperimentsPreviouslyToggled(buffer.readBoolean()); packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); - packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); + final int ordinal = VarInts.readInt(buffer); + packet.setDefaultPlayerPermission(ordinal == -1 ? null : PLAYER_PERMISSIONS[ordinal]); packet.setServerChunkTickRange(buffer.readIntLE()); packet.setBehaviorPackLocked(buffer.readBoolean()); packet.setResourcePackLocked(buffer.readBoolean()); diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v544/serializer/StartGameSerializer_v544.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v544/serializer/StartGameSerializer_v544.java index 13484053f..dd4315a21 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v544/serializer/StartGameSerializer_v544.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v544/serializer/StartGameSerializer_v544.java @@ -53,7 +53,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta buffer.writeBoolean(packet.isExperimentsPreviouslyToggled()); buffer.writeBoolean(packet.isBonusChestEnabled()); buffer.writeBoolean(packet.isStartingWithMap()); - VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); + VarInts.writeInt(buffer, packet.getDefaultPlayerPermission() == null ? -1 : packet.getDefaultPlayerPermission().ordinal()); buffer.writeIntLE(packet.getServerChunkTickRange()); buffer.writeBoolean(packet.isBehaviorPackLocked()); buffer.writeBoolean(packet.isResourcePackLocked()); @@ -106,7 +106,8 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star packet.setExperimentsPreviouslyToggled(buffer.readBoolean()); packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); - packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); + final int ordinal = VarInts.readInt(buffer); + packet.setDefaultPlayerPermission(ordinal == -1 ? null : PLAYER_PERMISSIONS[ordinal]); packet.setServerChunkTickRange(buffer.readIntLE()); packet.setBehaviorPackLocked(buffer.readBoolean()); packet.setResourcePackLocked(buffer.readBoolean()); diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v567/serializer/StartGameSerializer_v567.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v567/serializer/StartGameSerializer_v567.java index 155c38969..a19a84d29 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v567/serializer/StartGameSerializer_v567.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v567/serializer/StartGameSerializer_v567.java @@ -40,7 +40,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta buffer.writeBoolean(packet.isExperimentsPreviouslyToggled()); buffer.writeBoolean(packet.isBonusChestEnabled()); buffer.writeBoolean(packet.isStartingWithMap()); - VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); + VarInts.writeInt(buffer, packet.getDefaultPlayerPermission() == null ? -1 : packet.getDefaultPlayerPermission().ordinal()); buffer.writeIntLE(packet.getServerChunkTickRange()); buffer.writeBoolean(packet.isBehaviorPackLocked()); buffer.writeBoolean(packet.isResourcePackLocked()); @@ -94,7 +94,8 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star packet.setExperimentsPreviouslyToggled(buffer.readBoolean()); packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); - packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); + final int ordinal = VarInts.readInt(buffer); + packet.setDefaultPlayerPermission(ordinal == -1 ? null : PLAYER_PERMISSIONS[ordinal]); packet.setServerChunkTickRange(buffer.readIntLE()); packet.setBehaviorPackLocked(buffer.readBoolean()); packet.setResourcePackLocked(buffer.readBoolean()); diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v582/serializer/StartGameSerializer_v582.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v582/serializer/StartGameSerializer_v582.java index 7ac715e7c..2beb8200c 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v582/serializer/StartGameSerializer_v582.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v582/serializer/StartGameSerializer_v582.java @@ -54,7 +54,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta buffer.writeBoolean(packet.isExperimentsPreviouslyToggled()); buffer.writeBoolean(packet.isBonusChestEnabled()); buffer.writeBoolean(packet.isStartingWithMap()); - VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal()); + VarInts.writeInt(buffer, packet.getDefaultPlayerPermission() == null ? -1 : packet.getDefaultPlayerPermission().ordinal()); buffer.writeIntLE(packet.getServerChunkTickRange()); buffer.writeBoolean(packet.isBehaviorPackLocked()); buffer.writeBoolean(packet.isResourcePackLocked()); @@ -110,7 +110,8 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star packet.setExperimentsPreviouslyToggled(buffer.readBoolean()); packet.setBonusChestEnabled(buffer.readBoolean()); packet.setStartingWithMap(buffer.readBoolean()); - packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]); + final int ordinal = VarInts.readInt(buffer); + packet.setDefaultPlayerPermission(ordinal == -1 ? null : PLAYER_PERMISSIONS[ordinal]); packet.setServerChunkTickRange(buffer.readIntLE()); packet.setBehaviorPackLocked(buffer.readBoolean()); packet.setResourcePackLocked(buffer.readBoolean());