From e569ffe0cc67c692214cc053e0b390b488e1902b Mon Sep 17 00:00:00 2001 From: oldkingOK Date: Tue, 20 Feb 2024 15:37:57 +0800 Subject: [PATCH] fix: IndexOutOfRange on packet reading (Forge) Add two missing forge Command Packet Parsers, which won't affect the vanilla parsers. The ids of the two Command Packet Parsers `forge:enum` and `forge:modid` [Forge once added in order](https://github.com/MinecraftForge/MinecraftForge/blob/19f8d2a7937dc7968ecbef2f9785687193fcd210/src/main/java/net/minecraftforge/common/ForgeMod.java#L175) are the maximum value of the Vanilla Parser id plus 1 or plus 2. `forge:enum` has a [String Type argument](https://wiki.vg/Command_Data#forge:enum). The specific id is from [wiki.vg](https://wiki.vg/Command_Data) or Forge-generated minecraft source code. --- .../Handlers/Packet/s2c/DeclareCommands.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/MinecraftClient/Protocol/Handlers/Packet/s2c/DeclareCommands.cs b/MinecraftClient/Protocol/Handlers/Packet/s2c/DeclareCommands.cs index 0311c9f7..be0315df 100644 --- a/MinecraftClient/Protocol/Handlers/Packet/s2c/DeclareCommands.cs +++ b/MinecraftClient/Protocol/Handlers/Packet/s2c/DeclareCommands.cs @@ -29,7 +29,19 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c Parser? parser = null; if ((flags & 0x03) == 2) { - if (protocolVersion <= Protocol18Handler.MC_1_19_2_Version) + if (protocolVersion switch + { + Protocol18Handler.MC_1_19_Version => parserId == 50, + Protocol18Handler.MC_1_19_2_Version => parserId == 50, + Protocol18Handler.MC_1_19_3_Version => parserId == 50, + Protocol18Handler.MC_1_19_4_Version => parserId == 50, + Protocol18Handler.MC_1_20_Version => parserId == 51, + Protocol18Handler.MC_1_20_2_Version => parserId == 51, + _ => false + }) + parser = new ParserForgeEnum(dataTypes, packetData); + + else if (protocolVersion <= Protocol18Handler.MC_1_19_2_Version) parser = parserId switch { 1 => new ParserFloat(dataTypes, packetData), @@ -644,5 +656,28 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c return "minecraft:time"; } } + + internal class ParserForgeEnum : Parser + { + public ParserForgeEnum(DataTypes dataTypes, Queue packetData) + { + dataTypes.ReadNextString(packetData); + } + + public override bool Check(string text) + { + return true; + } + + public override int GetArgCnt() + { + return 1; + } + + public override string GetName() + { + return "forge:enum"; + } + } } }