Fixed a crash on chat parsing. + Returned the commended try catch block

Fixed a crash on chat parsing. + Returned the commended try catch block
This commit is contained in:
Anon 2024-02-21 17:41:37 +01:00 committed by GitHub
commit 798a24e8be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 53 additions and 48 deletions

View file

@ -686,7 +686,6 @@ namespace MinecraftClient.Protocol.Handlers
? key >> 5 // 1.8
: ReadNextVarInt(cache); // 1.9+
EntityMetaDataType type;
try
{

View file

@ -365,8 +365,8 @@ namespace MinecraftClient.Protocol.Handlers
/// <returns>TRUE if the packet was processed, FALSE if ignored or unknown</returns>
internal bool HandlePacket(int packetId, Queue<byte> packetData)
{
//try
//{
try
{
switch (currentState)
{
// https://wiki.vg/Protocol#Login
@ -449,23 +449,22 @@ namespace MinecraftClient.Protocol.Handlers
default:
return true;
}
//}
//catch (Exception innerException)
//{
// //throw;
// if (innerException is ThreadAbortException || innerException is SocketException ||
// innerException.InnerException is SocketException)
// throw; //Thread abort or Connection lost rather than invalid data
}
catch (Exception innerException)
{
if (innerException is ThreadAbortException || innerException is SocketException ||
innerException.InnerException is SocketException)
throw; //Thread abort or Connection lost rather than invalid data
// throw new System.IO.InvalidDataException(
// string.Format(Translations.exception_packet_process,
// packetPalette.GetIncomingTypeById(packetId),
// packetId,
// protocolVersion,
// currentState == CurrentState.Login,
// innerException.GetType()),
// innerException);
//}
throw new System.IO.InvalidDataException(
string.Format(Translations.exception_packet_process,
packetPalette.GetIncomingTypeById(packetId),
packetId,
protocolVersion,
currentState == CurrentState.Login,
innerException.GetType()),
innerException);
}
return true;
}
@ -493,7 +492,8 @@ namespace MinecraftClient.Protocol.Handlers
return;
//Send back "accepted" and "successfully loaded" responses for plugins or server config making use of resource pack mandatory
var responseHeader = protocolVersion < MC_1_10_Version // After 1.10, the MC does not include resource pack hash in responses
var responseHeader =
protocolVersion < MC_1_10_Version // After 1.10, the MC does not include resource pack hash in responses
? dataTypes.ConcatBytes(DataTypes.GetVarInt(hash.Length), Encoding.UTF8.GetBytes(hash))
: Array.Empty<byte>();
@ -507,7 +507,8 @@ namespace MinecraftClient.Protocol.Handlers
if (currentState == CurrentState.Configuration)
{
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse, acceptedResourcePackData); // Accepted
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse, loadedResourcePackData); // Successfully loaded
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse,
loadedResourcePackData); // Successfully loaded
}
else
{
@ -1677,7 +1678,7 @@ namespace MinecraftClient.Protocol.Handlers
var hasIcon = dataTypes.ReadNextBool(packetData);
if (hasIcon)
{
if(protocolVersion < MC_1_20_2_Version)
if (protocolVersion < MC_1_20_2_Version)
iconBase64 = dataTypes.ReadNextString(packetData);
else
{
@ -2164,7 +2165,7 @@ namespace MinecraftClient.Protocol.Handlers
break;
case PacketTypesIn.ResetScore:
dataTypes.ReadNextString(packetData); // Entity Name
if(dataTypes.ReadNextBool(packetData)) // Has Objective Name
if (dataTypes.ReadNextBool(packetData)) // Has Objective Name
dataTypes.ReadNextString(packetData); // Objective Name
break;
@ -2567,7 +2568,8 @@ namespace MinecraftClient.Protocol.Handlers
objectiveValue2 = dataTypes.ReadNextVarInt(packetData); // Value
if (dataTypes.ReadNextBool(packetData)) // Has Display Name
objectiveDisplayName3 = ChatParser.ParseText(dataTypes.ReadNextString(packetData)); // Has Display Name
objectiveDisplayName3 =
ChatParser.ParseText(dataTypes.ReadNextString(packetData)); // Has Display Name
if (dataTypes.ReadNextBool(packetData)) // Has Number Format
numberFormat2 = dataTypes.ReadNextVarInt(packetData); // Number Format
@ -2585,7 +2587,8 @@ namespace MinecraftClient.Protocol.Handlers
objectiveValue2 = dataTypes.ReadNextVarInt(packetData);
}
handler.OnUpdateScore(entityName, action3, objectiveName3, objectiveDisplayName3, objectiveValue2, numberFormat2);
handler.OnUpdateScore(entityName, action3, objectiveName3, objectiveDisplayName3, objectiveValue2,
numberFormat2);
break;
case PacketTypesIn.BlockChangedAck:
handler.OnBlockChangeAck(dataTypes.ReadNextVarInt(packetData));

View file

@ -471,7 +471,10 @@ namespace MinecraftClient.Protocol.Message
var withs = (object[])withComponent;
for (int i = 0; i < withs.Length; i++)
{
var withDict = (Dictionary<string, object>)withs[i];
var withDict = withs[i] is string
? new Dictionary<string, object>() { { "text", (string)withs[i] } }
: (Dictionary<string, object>)withs[i];
translateString.Add(NbtToString(withDict));
}
}