Skip to content

Commit

Permalink
fix: IndexOutOfRange on packet reading (Forge)
Browse files Browse the repository at this point in the history
fix: IndexOutOfRange on packet reading (Forge)
  • Loading branch information
milutinke authored Mar 10, 2024
2 parents 5f4227a + 4bb25c3 commit ac9a70c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions MinecraftClient/Protocol/Handlers/Packet/s2c/DeclareCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static void Read(DataTypes dataTypes, Queue<byte> packetData, int protoco
29 => new ParserScoreHolder(dataTypes, packetData),
43 => new ParserResourceOrTag(dataTypes, packetData),
44 => new ParserResource(dataTypes, packetData),
50 => new ParserForgeEnum(dataTypes, packetData),
_ => new ParserEmpty(dataTypes, packetData),
};
else if (protocolVersion <= Protocol18Handler.MC_1_19_3_Version) // 1.19.3
Expand All @@ -69,6 +70,7 @@ public static void Read(DataTypes dataTypes, Queue<byte> packetData, int protoco
42 => new ParserResourceOrTag(dataTypes, packetData),
43 => new ParserResource(dataTypes, packetData),
44 => new ParserResource(dataTypes, packetData),
50 => new ParserForgeEnum(dataTypes, packetData),
_ => new ParserEmpty(dataTypes, packetData),
};
else if (protocolVersion <= Protocol18Handler.MC_1_20_2_Version)// 1.19.4 - 1.20.2
Expand All @@ -92,6 +94,13 @@ public static void Read(DataTypes dataTypes, Queue<byte> packetData, int protoco
42 => new ParserResourceOrTag(dataTypes, packetData),
43 => new ParserResource(dataTypes, packetData),
44 => new ParserResource(dataTypes, packetData),
50 => protocolVersion == Protocol18Handler.MC_1_19_4_Version ?
new ParserForgeEnum(dataTypes, packetData) :
new ParserEmpty(dataTypes, packetData),
51 => (protocolVersion >= Protocol18Handler.MC_1_20_Version &&
protocolVersion <= Protocol18Handler.MC_1_20_2_Version) ? // 1.20 - 1.20.2
new ParserForgeEnum(dataTypes, packetData) :
new ParserEmpty(dataTypes, packetData),
_ => new ParserEmpty(dataTypes, packetData),
};
else // 1.20.3+
Expand All @@ -115,6 +124,7 @@ public static void Read(DataTypes dataTypes, Queue<byte> packetData, int protoco
43 => new ParserResourceOrTag(dataTypes, packetData),
44 => new ParserResource(dataTypes, packetData),
45 => new ParserResource(dataTypes, packetData),
52 => new ParserForgeEnum(dataTypes, packetData),
_ => new ParserEmpty(dataTypes, packetData),
};
}
Expand Down Expand Up @@ -670,5 +680,28 @@ public override string GetName()
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";
}
}
}
}

0 comments on commit ac9a70c

Please sign in to comment.