mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
Fix crash on unknown packet IDs on some Forge servers (#1422)
* Fix unknown packet ID cause crash (#1419) * Ignore unknown packet ID only if forge enabled
This commit is contained in:
parent
0cbe543c30
commit
939c8fb383
3 changed files with 67 additions and 12 deletions
|
|
@ -38,6 +38,8 @@ namespace MinecraftClient.Protocol.Handlers.PacketPalettes
|
|||
|
||||
private Dictionary<PacketTypesOut, int> reverseMappingOut = new Dictionary<PacketTypesOut, int>();
|
||||
|
||||
private bool forgeEnabled = false;
|
||||
|
||||
public PacketTypePalette()
|
||||
{
|
||||
foreach (var p in GetListIn())
|
||||
|
|
@ -57,7 +59,19 @@ namespace MinecraftClient.Protocol.Handlers.PacketPalettes
|
|||
/// <returns>Packet type</returns>
|
||||
public PacketTypesIn GetIncommingTypeById(int packetId)
|
||||
{
|
||||
return GetListIn()[packetId];
|
||||
PacketTypesIn p;
|
||||
if (GetListIn().TryGetValue(packetId, out p))
|
||||
{
|
||||
return p;
|
||||
}
|
||||
else if (forgeEnabled)
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
ConsoleIO.WriteLogLine("Ignoring unknown packet ID of 0x" + packetId.ToString("X2"));
|
||||
return PacketTypesIn.Unknown;
|
||||
}
|
||||
else
|
||||
throw new KeyNotFoundException("Packet ID of 0x" + packetId.ToString("X2") + " doesn't exist!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -77,7 +91,19 @@ namespace MinecraftClient.Protocol.Handlers.PacketPalettes
|
|||
/// <returns>Packet type</returns>
|
||||
public PacketTypesOut GetOutgoingTypeById(int packetId)
|
||||
{
|
||||
return GetListOut()[packetId];
|
||||
PacketTypesOut p;
|
||||
if (GetListOut().TryGetValue(packetId, out p))
|
||||
{
|
||||
return p;
|
||||
}
|
||||
else if (forgeEnabled)
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
ConsoleIO.WriteLogLine("Ignoring unknown packet ID of 0x" + packetId.ToString("X2"));
|
||||
return PacketTypesOut.Unknown;
|
||||
}
|
||||
else
|
||||
throw new KeyNotFoundException("Packet ID of 0x" + packetId.ToString("X2") + " doesn't exist!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -108,5 +134,19 @@ namespace MinecraftClient.Protocol.Handlers.PacketPalettes
|
|||
{
|
||||
return GetListOut();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable forge or disable forge
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Have a rare chance that forge mod may modify packet ID.
|
||||
/// Ignore packet type not found when forge enabled to
|
||||
/// prevent program crash.
|
||||
/// </remarks>
|
||||
/// <param name="enabled"></param>
|
||||
public void SetForgeEnabled(bool enabled)
|
||||
{
|
||||
this.forgeEnabled = enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue