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](19f8d2a793/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.
This commit is contained in:
oldkingOK 2024-02-20 15:37:57 +08:00
parent 9a147b57e5
commit e569ffe0cc

View file

@ -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<byte> 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";
}
}
}
}