From 35cfd4a7dbd341550effd2e66de680674fd5afef Mon Sep 17 00:00:00 2001 From: Anon Date: Sun, 18 Feb 2024 17:56:02 +0100 Subject: [PATCH] Fixed a NBT crash < 1.20.2 and Fixed a crash with parsing 'extra' section in Chat --- MinecraftClient/Protocol/Handlers/DataTypes.cs | 8 +------- MinecraftClient/Protocol/Message/ChatParser.cs | 5 ++++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs index 6f8961ff..cbeeabbe 100644 --- a/MinecraftClient/Protocol/Handlers/DataTypes.cs +++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs @@ -565,12 +565,9 @@ namespace MinecraftClient.Protocol.Handlers var nextId = cache.Dequeue(); if (protocolversion < Protocol18Handler.MC_1_20_2_Version) { - if (nextId is 10) // TAG_Compound + if (nextId is not 10) // TAG_Compound throw new System.IO.InvalidDataException("Failed to decode NBT: Does not start with TAG_Compound"); - // Read TAG_Compound - ReadNextByte(cache); - // NBT root name var rootName = Encoding.ASCII.GetString(ReadData(ReadNextUShort(cache), cache)); @@ -595,9 +592,6 @@ namespace MinecraftClient.Protocol.Handlers { "", result } }; } - - // Read TAG_Compound - //ReadNextByte(cache); } } diff --git a/MinecraftClient/Protocol/Message/ChatParser.cs b/MinecraftClient/Protocol/Message/ChatParser.cs index 3551e4ba..7be5dbee 100644 --- a/MinecraftClient/Protocol/Message/ChatParser.cs +++ b/MinecraftClient/Protocol/Message/ChatParser.cs @@ -452,7 +452,10 @@ namespace MinecraftClient.Protocol.Message object[] extras = (object[])value; for (int i = 0; i < extras.Length; i++) { - var extraDict = (Dictionary)extras[i]; + var extraDict = extras[i] is string + ? new Dictionary() { { "text", (string)extras[i] } } + : (Dictionary)extras[i]; + extraBuilder.Append(NbtToString(extraDict) + "§r"); } }