From 12c8a60ad7d70dddda5f6044b4c6dea03d170c04 Mon Sep 17 00:00:00 2001 From: Milutinke Date: Thu, 22 Sep 2022 19:36:24 +0200 Subject: [PATCH] Tested on all versions 1.8 + Fixed 1.14 not working at all. --- .../Protocol/Handlers/DataTypes.cs | 2 + .../Protocol/Handlers/PacketType18Handler.cs | 2 +- .../Protocol/Handlers/Protocol18.cs | 82 +++++++++++++++---- 3 files changed, 68 insertions(+), 18 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs index 9a0d50f1..2e2e90b7 100644 --- a/MinecraftClient/Protocol/Handlers/DataTypes.cs +++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs @@ -584,6 +584,7 @@ namespace MinecraftClient.Protocol.Handlers { Dictionary data = new(); byte key = ReadNextByte(cache); + while (key != 0xff) { int type = ReadNextVarInt(cache); @@ -599,6 +600,7 @@ namespace MinecraftClient.Protocol.Handlers type += 1; } } + // Value's data type is depended on Type object? value = null; diff --git a/MinecraftClient/Protocol/Handlers/PacketType18Handler.cs b/MinecraftClient/Protocol/Handlers/PacketType18Handler.cs index 4dff45a9..72a44990 100644 --- a/MinecraftClient/Protocol/Handlers/PacketType18Handler.cs +++ b/MinecraftClient/Protocol/Handlers/PacketType18Handler.cs @@ -62,7 +62,7 @@ namespace MinecraftClient.Protocol.Handlers p = new PacketPalette112(); else if (protocol <= Protocol18Handler.MC_1_12_2_Version) p = new PacketPalette1122(); - else if (protocol <= Protocol18Handler.MC_1_14_Version) + else if (protocol < Protocol18Handler.MC_1_14_Version) p = new PacketPalette113(); else if (protocol <= Protocol18Handler.MC_1_15_Version) p = new PacketPalette114(); diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 065a261c..1e0f5dc5 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -4,23 +4,22 @@ using System.Linq; using System.Text; using System.Net.Sockets; using System.Threading; +using System.Security.Cryptography; +using System.Diagnostics; +using System.Text.RegularExpressions; +using System.Collections.Concurrent; using MinecraftClient.Crypto; using MinecraftClient.Proxy; -using System.Security.Cryptography; using MinecraftClient.Mapping; using MinecraftClient.Mapping.BlockPalettes; using MinecraftClient.Mapping.EntityPalettes; using MinecraftClient.Protocol.Handlers.Forge; using MinecraftClient.Inventory; -using System.Diagnostics; using MinecraftClient.Inventory.ItemPalettes; using MinecraftClient.Protocol.Handlers.PacketPalettes; using MinecraftClient.Logger; -using System.Threading.Tasks; using MinecraftClient.Protocol.Keys; -using System.Text.RegularExpressions; using MinecraftClient.Protocol.Session; -using System.Collections.Concurrent; using MinecraftClient.Protocol.Message; namespace MinecraftClient.Protocol.Handlers @@ -45,6 +44,7 @@ namespace MinecraftClient.Protocol.Handlers internal const int MC_1_12_Version = 335; internal const int MC_1_12_2_Version = 340; internal const int MC_1_13_Version = 393; + internal const int MC_1_13_2_Version = 404; internal const int MC_1_14_Version = 477; internal const int MC_1_15_Version = 573; internal const int MC_1_15_2_Version = 578; @@ -781,23 +781,42 @@ namespace MinecraftClient.Protocol.Handlers } break; case PacketTypesIn.MapData: + if (protocolVersion < MC_1_8_Version) + break; + int mapid = dataTypes.ReadNextVarInt(packetData); byte scale = dataTypes.ReadNextByte(packetData); - bool trackingPosition = protocolVersion >= MC_1_17_Version ? false : dataTypes.ReadNextBool(packetData); + + + // 1.9 + + bool trackingPosition = true; + + // 1.14+ bool locked = false; - if (protocolVersion >= MC_1_14_Version) - { - locked = dataTypes.ReadNextBool(packetData); - } + + // 1.17+ (locked and trackingPosition switched places) if (protocolVersion >= MC_1_17_Version) { - trackingPosition = dataTypes.ReadNextBool(packetData); + if (protocolVersion >= MC_1_14_Version) + locked = dataTypes.ReadNextBool(packetData); + + if (protocolVersion >= MC_1_9_Version) + trackingPosition = dataTypes.ReadNextBool(packetData); + } + else + { + if (protocolVersion >= MC_1_9_Version) + trackingPosition = dataTypes.ReadNextBool(packetData); + + if (protocolVersion >= MC_1_14_Version) + locked = dataTypes.ReadNextBool(packetData); } int iconcount = 0; List icons = new(); - if (trackingPosition) + // 1,9 + = needs tracking position to be true to get the icons + if (protocolVersion > MC_1_9_Version ? trackingPosition : true) { iconcount = dataTypes.ReadNextVarInt(packetData); @@ -805,14 +824,43 @@ namespace MinecraftClient.Protocol.Handlers { MapIcon mapIcon = new(); - mapIcon.Type = (MapIconType)dataTypes.ReadNextVarInt(packetData); + // 1.8 - 1.13 + if (protocolVersion < MC_1_13_2_Version) + { + byte directionAndtype = dataTypes.ReadNextByte(packetData); + byte direction, type; + + // 1.12.2+ + if (protocolVersion >= MC_1_12_2_Version) + { + direction = (byte)(directionAndtype & 0xF); + type = (byte)((directionAndtype >> 4) & 0xF); + } + else // 1.8 - 1.12 + { + direction = (byte)((directionAndtype >> 4) & 0xF); + type = (byte)(directionAndtype & 0xF); + } + + mapIcon.Type = (MapIconType)type; + mapIcon.Direction = direction; + } + + // 1.13.2+ + if (protocolVersion >= MC_1_13_2_Version) + mapIcon.Type = (MapIconType)dataTypes.ReadNextVarInt(packetData); + mapIcon.X = dataTypes.ReadNextByte(packetData); mapIcon.Z = dataTypes.ReadNextByte(packetData); - mapIcon.Direction = dataTypes.ReadNextByte(packetData); - bool mapIconHasDisplayName = dataTypes.ReadNextBool(packetData); - if (mapIconHasDisplayName) - mapIcon.DisplayName = ChatParser.ParseText(dataTypes.ReadNextString(packetData)); + // 1.13.2+ + if (protocolVersion >= MC_1_13_2_Version) + { + mapIcon.Direction = dataTypes.ReadNextByte(packetData); + + if (dataTypes.ReadNextBool(packetData)) // Has Display Name? + mapIcon.DisplayName = ChatParser.ParseText(dataTypes.ReadNextString(packetData)); + } icons.Add(mapIcon); }