diff --git a/MinecraftClient/Logger/FileLogLogger.cs b/MinecraftClient/Logger/FileLogLogger.cs index 53fb9a57..ab660bdf 100644 --- a/MinecraftClient/Logger/FileLogLogger.cs +++ b/MinecraftClient/Logger/FileLogLogger.cs @@ -90,6 +90,17 @@ namespace MinecraftClient.Logger } } + public override void PacketDebug(string msg) + { + if (Settings.Config.Logging.PacketDebugMessages) + { + if (ShouldDisplay(FilterChannel.Debug, msg)) + { + LogAndSave("§8[DEBUG] " + msg); + } + } + } + public override void Error(string msg) { base.Error(msg); diff --git a/MinecraftClient/Logger/FilteredLogger.cs b/MinecraftClient/Logger/FilteredLogger.cs index 6260c373..a520434c 100644 --- a/MinecraftClient/Logger/FilteredLogger.cs +++ b/MinecraftClient/Logger/FilteredLogger.cs @@ -57,6 +57,17 @@ namespace MinecraftClient.Logger } } + public override void PacketDebug(string msg) + { + if (Settings.Config.Logging.PacketDebugMessages) + { + if (ShouldDisplay(FilterChannel.Debug, msg)) + { + Log("§8[DEBUG] " + msg); + } + } + } + public override void Info(string msg) { if (InfoEnabled) diff --git a/MinecraftClient/Logger/ILogger.cs b/MinecraftClient/Logger/ILogger.cs index ba3f143f..89a1b686 100644 --- a/MinecraftClient/Logger/ILogger.cs +++ b/MinecraftClient/Logger/ILogger.cs @@ -16,6 +16,10 @@ void Debug(string msg, params object[] args); void Debug(object msg); + void PacketDebug(string msg); + void PacketDebug(string msg, params object[] args); + void PacketDebug(object msg); + void Warn(string msg); void Warn(string msg, params object[] args); void Warn(object msg); diff --git a/MinecraftClient/Logger/LoggerBase.cs b/MinecraftClient/Logger/LoggerBase.cs index 8569bfc9..500c43b6 100644 --- a/MinecraftClient/Logger/LoggerBase.cs +++ b/MinecraftClient/Logger/LoggerBase.cs @@ -40,6 +40,18 @@ Debug(msg.ToString() ?? string.Empty); } + public abstract void PacketDebug(string msg); + + public void PacketDebug(string msg, params object[] args) + { + PacketDebug(string.Format(msg, args)); + } + + public void PacketDebug(object msg) + { + PacketDebug(msg.ToString() ?? string.Empty); + } + public abstract void Error(string msg); public void Error(string msg, params object[] args) diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index bc77463d..180b174a 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -795,7 +795,7 @@ namespace MinecraftClient.Protocol.Handlers case PacketTypesIn.JoinGame: // Temporary fix - log.Debug("Receive JoinGame"); + log.PacketDebug("Receive JoinGame"); receiveDeclareCommands = receivePlayerInfo = false; @@ -988,7 +988,7 @@ namespace MinecraftClient.Protocol.Handlers case PacketTypesIn.DeclareCommands: if (protocolVersion >= MC_1_19_Version) { - log.Debug("Receive DeclareCommands"); + log.PacketDebug("Receive DeclareCommands"); DeclareCommands.Read(dataTypes, packetData, protocolVersion); receiveDeclareCommands = true; if (receivePlayerInfo) @@ -2155,7 +2155,7 @@ namespace MinecraftClient.Protocol.Handlers if (playerUuid == handler.GetUserUuid()) { - log.Debug($"Receive ChatUuid = {chatUuid}"); + log.PacketDebug($"Receive ChatUuid = {chatUuid}"); this.chatUuid = chatUuid; } } @@ -2164,7 +2164,7 @@ namespace MinecraftClient.Protocol.Handlers player.ClearPublicKey(); if (playerUuid == handler.GetUserUuid()) - log.Debug("Receive ChatUuid = Empty"); + log.PacketDebug("Receive ChatUuid = Empty"); } if (playerUuid == handler.GetUserUuid()) @@ -4144,7 +4144,7 @@ namespace MinecraftClient.Protocol.Handlers if (!log.DebugEnabled) return; - log.Debug(string.Format(Translations.debug_packet_state_change, previousState, newState)); + log.PacketDebug(string.Format(Translations.debug_packet_state_change, previousState, newState)); } private void LogIncomingPacket(int packetId, int payloadLength, int frameLength, bool compressed, int uncompressedLength) @@ -4159,7 +4159,7 @@ namespace MinecraftClient.Protocol.Handlers ? string.Format(Translations.debug_packet_compression_compressed, uncompressedLength) : Translations.debug_packet_compression_uncompressed; - log.Debug(string.Format(Translations.debug_packet_incoming, + log.PacketDebug(string.Format(Translations.debug_packet_incoming, currentState, packetId, packetType, @@ -4173,7 +4173,7 @@ namespace MinecraftClient.Protocol.Handlers if (!log.DebugEnabled) return; - log.Debug(string.Format(Translations.debug_packet_outgoing, + log.PacketDebug(string.Format(Translations.debug_packet_outgoing, currentState, packetId, packetType ?? ResolveOutgoingPacketType(packetId), @@ -4186,7 +4186,7 @@ namespace MinecraftClient.Protocol.Handlers if (!log.DebugEnabled) return; - log.Debug(string.Format(Translations.debug_packet_loop_exit, + log.PacketDebug(string.Format(Translations.debug_packet_loop_exit, loopName, reason, currentState, @@ -4245,7 +4245,7 @@ namespace MinecraftClient.Protocol.Handlers int nextState = isTransfer && protocolVersion >= MC_1_20_6_Version ? 3 : 2; if (nextState == 3) - log.Debug("Using transfer handshake intent for transferred login."); + log.PacketDebug("Using transfer handshake intent for transferred login."); // 1. Send the handshake packet SendPacket(0x00, dataTypes.ConcatBytes( @@ -4389,7 +4389,7 @@ namespace MinecraftClient.Protocol.Handlers var RSAService = CryptoHandler.DecodeRSAPublicKey(serverPublicKey)!; var secretKey = CryptoHandler.ClientAESPrivateKey ?? CryptoHandler.GenerateAESPrivateKey(); - log.Debug($"§8{Translations.debug_crypto}"); + log.PacketDebug($"§8{Translations.debug_crypto}"); if (serverIDhash != "-" && !string.IsNullOrWhiteSpace(sessionID)) { @@ -4883,7 +4883,7 @@ namespace MinecraftClient.Protocol.Handlers command = Regex.Replace(command, @"\s+", " "); command = Regex.Replace(command, @"\s$", string.Empty); - log.Debug($"chat command = {command}"); + log.PacketDebug($"chat command = {command}"); if (protocolVersion >= MC_1_20_6_Version && !isOnlineMode) { @@ -4911,7 +4911,7 @@ namespace MinecraftClient.Protocol.Handlers else { needSigned = []; - log.Debug("DeclareCommands tree unavailable, sending command without signed arguments."); + log.PacketDebug("DeclareCommands tree unavailable, sending command without signed arguments."); } } @@ -6417,7 +6417,7 @@ namespace MinecraftClient.Protocol.Handlers packet.AddRange(DataTypes.GetVarInt(playerKeyPair.PublicKey.SignatureV2!.Length)); packet.AddRange(playerKeyPair.PublicKey.SignatureV2); - log.Debug( + log.PacketDebug( $"SendPlayerSession MessageUUID = {chatUuid.ToString()}, len(PublicKey) = {playerKeyPair.PublicKey.Key.Length}, len(SignatureV2) = {playerKeyPair.PublicKey.SignatureV2!.Length}"); SendPacket(PacketTypesOut.PlayerSession, packet); diff --git a/MinecraftClient/Resources/ConfigComments/ConfigComments.Designer.cs b/MinecraftClient/Resources/ConfigComments/ConfigComments.Designer.cs index 64f83f4a..4a0cc7fd 100644 --- a/MinecraftClient/Resources/ConfigComments/ConfigComments.Designer.cs +++ b/MinecraftClient/Resources/ConfigComments/ConfigComments.Designer.cs @@ -1532,6 +1532,15 @@ namespace MinecraftClient { } } + /// + /// Looks up a localized string similar to Show low-level packet debug logs.. + /// + internal static string Logging_PacketDebugMessages { + get { + return ResourceManager.GetString("Logging.PacketDebugMessages", resourceCulture); + } + } + /// /// Looks up a localized string similar to Show error messages.. /// diff --git a/MinecraftClient/Resources/ConfigComments/ConfigComments.resx b/MinecraftClient/Resources/ConfigComments/ConfigComments.resx index e92415a9..5515ae24 100644 --- a/MinecraftClient/Resources/ConfigComments/ConfigComments.resx +++ b/MinecraftClient/Resources/ConfigComments/ConfigComments.resx @@ -626,6 +626,9 @@ Want to upgrade to a newer version? See https://github.com/MCCTeam/Minecraft-Con Please enable this before submitting bug reports. Thanks! + + Show low-level packet debug logs. + Show error messages. diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index ce7beada..06a3837c 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -1077,6 +1077,9 @@ namespace MinecraftClient [TomlInlineComment("$Logging.DebugMessages$")] public bool DebugMessages = false; + [TomlInlineComment("$Logging.PacketDebugMessages$")] + public bool PacketDebugMessages = false; + [TomlInlineComment("$Logging.ChatMessages$")] public bool ChatMessages = true;