From d90635f40b38fea4a33521aa759a730fd15259bb Mon Sep 17 00:00:00 2001 From: Anon Date: Fri, 7 Apr 2023 15:21:42 +0200 Subject: [PATCH 1/2] Fixed crash on 1.8 when receiving entity data --- MinecraftClient/Protocol/Handlers/DataTypes.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs index 5162d4f9..6f7a53a8 100644 --- a/MinecraftClient/Protocol/Handlers/DataTypes.cs +++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs @@ -504,6 +504,7 @@ namespace MinecraftClient.Protocol.Handlers int metadata = -1; + bool hasData = false; byte entityPitch, entityYaw; if (living) @@ -522,13 +523,16 @@ namespace MinecraftClient.Protocol.Handlers // Data if (protocolversion >= Protocol18Handler.MC_1_19_Version) - ReadNextVarInt(cache); - else ReadNextInt(cache); + hasData = ReadNextVarInt(cache) == 1; + else hasData = ReadNextInt(cache) == 1; } - short velocityX = ReadNextShort(cache); - short velocityY = ReadNextShort(cache); - short velocityZ = ReadNextShort(cache); + if (hasData) + { + short velocityX = ReadNextShort(cache); + short velocityY = ReadNextShort(cache); + short velocityZ = ReadNextShort(cache); + } return new Entity(entityID, entityType, new Location(entityX, entityY, entityZ), entityYaw, entityPitch, metadata); } From 03b06ea3aca6c50173270262225c02a378138ec0 Mon Sep 17 00:00:00 2001 From: Anon Date: Fri, 7 Apr 2023 15:26:26 +0200 Subject: [PATCH 2/2] Fixed crash on 1.8 when receiving entity data --- .../Protocol/Handlers/DataTypes.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs index 6f7a53a8..2906e4d9 100644 --- a/MinecraftClient/Protocol/Handlers/DataTypes.cs +++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs @@ -523,15 +523,25 @@ namespace MinecraftClient.Protocol.Handlers // Data if (protocolversion >= Protocol18Handler.MC_1_19_Version) - hasData = ReadNextVarInt(cache) == 1; + ReadNextVarInt(cache); else hasData = ReadNextInt(cache) == 1; } - if (hasData) + // In 1.8 those 3 fields for Velocity are optional + if (protocolversion < Protocol18Handler.MC_1_9_Version) { - short velocityX = ReadNextShort(cache); - short velocityY = ReadNextShort(cache); - short velocityZ = ReadNextShort(cache); + if (hasData) + { + ReadNextShort(cache); + ReadNextShort(cache); + ReadNextShort(cache); + } + } + else + { + ReadNextShort(cache); + ReadNextShort(cache); + ReadNextShort(cache); } return new Entity(entityID, entityType, new Location(entityX, entityY, entityZ), entityYaw, entityPitch, metadata);