Skip to content

Commit

Permalink
fix: some servers sent -1 for default player permission (recoded)
Browse files Browse the repository at this point in the history
  • Loading branch information
hax0r31337 committed Apr 24, 2023
1 parent 481e01c commit 98c10cb
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 98c10cb

Please sign in to comment.