From c50b360eae7c6231773f31e2d18c371ee33ea281 Mon Sep 17 00:00:00 2001 From: breadbyte <14045257+breadbyte@users.noreply.github.com> Date: Sun, 14 Jul 2024 01:30:16 +0800 Subject: [PATCH] Fix minor bugs (#2759) * add miscellaneous fixes * Fixed connecting to server when compression threshold is set to 0 The client assumes that 0 means disabled, when on a notchian (vanilla) server, it is possible to set the compression threshold to 0 (compress all packets). * Try to capture all exceptions through Sentry No exceptions are being logged through Sentry, so be more aggressive when sending exceptions (cherry picked from commit eb1c2f5e771760fb3be32ffea79f8292adca92f1) * Call OnSpawnPlayer packet when a player is spawned using the SpawnEntity packet references #2721 (cherry picked from commit ef28ae09ac89e8988dd612de61f2849a9f0e528c) --- MinecraftClient/Program.cs | 5 +++++ MinecraftClient/Protocol/Handlers/Protocol18.cs | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index e36f6bc7..07e44a8e 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -74,6 +74,11 @@ namespace MinecraftClient options.EnableTracing = true; options.SendDefaultPii = false; }); + + AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => + { + SentrySdk.CaptureException((Exception)eventArgs.ExceptionObject); + }; } Task.Run(() => diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 4053a94a..6b0fa3db 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; @@ -72,7 +72,7 @@ namespace MinecraftClient.Protocol.Handlers internal const int MC_1_20_2_Version = 764; internal const int MC_1_20_4_Version = 765; - private int compression_treshold = 0; + private int compression_treshold = -1; private int autocomplete_transaction_id = 0; private readonly Dictionary window_actions = new(); private CurrentState currentState = CurrentState.Login; @@ -345,7 +345,7 @@ namespace MinecraftClient.Protocol.Handlers //Handle packet decompression if (protocolVersion >= MC_1_8_Version - && compression_treshold > 0) + && compression_treshold >= 0) { var sizeUncompressed = dataTypes.ReadNextVarInt(packetData); if (sizeUncompressed != 0) // != 0 means compressed, let's decompress @@ -2196,6 +2196,14 @@ namespace MinecraftClient.Protocol.Handlers if (handler.GetEntityHandlingEnabled()) { var entity = dataTypes.ReadNextEntity(packetData, entityPalette, false); + + if (protocolVersion >= MC_1_20_2_Version) + { + if (entity.Type == EntityType.Player) + handler.OnSpawnPlayer(entity.ID, entity.UUID, entity.Location, (byte)entity.Yaw, (byte)entity.Pitch); + break; + } + handler.OnSpawnEntity(entity); } @@ -2759,7 +2767,7 @@ namespace MinecraftClient.Protocol.Handlers //The inner packet var thePacket = dataTypes.ConcatBytes(DataTypes.GetVarInt(packetId), packetData.ToArray()); - if (compression_treshold > 0) //Compression enabled? + if (compression_treshold >= 0) //Compression enabled? { thePacket = thePacket.Length >= compression_treshold ? dataTypes.ConcatBytes(DataTypes.GetVarInt(thePacket.Length), ZlibUtils.Compress(thePacket))