From 91cfd6e614f5bddfb6eec4facc5fb905af1fd977 Mon Sep 17 00:00:00 2001 From: Shauren Date: Mon, 13 Jan 2025 15:32:24 +0100 Subject: [PATCH] Improve error log for duplicate opcode handlers to make locating them easier --- WowPacketParser/Parsing/Handler.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/WowPacketParser/Parsing/Handler.cs b/WowPacketParser/Parsing/Handler.cs index ff0a6ee529..b5921dcfed 100644 --- a/WowPacketParser/Parsing/Handler.cs +++ b/WowPacketParser/Parsing/Handler.cs @@ -70,19 +70,13 @@ private static void LoadHandlersInto(Dictionary)Delegate.CreateDelegate(typeof(Action), method); - if (handlers.ContainsKey(key)) + if (handlers.TryGetValue(key, out var existingHandler)) { - // @TODO This is a hack to keep things easy regarding declaration of opcodes. - // Ideally, we would split the opcodes into three different enums: - // ClientOpcodes, ServerOpcodes, BidirectionalOpcodes - // The first two are obvious as to what they would contain. - // The last one would be MSG_, UMSG_, TEST_, etc... opcodes - // However that's just too much pain to do considering the mess Blizzard does - // by naming their opcodes sometimes without following their own rules. Direction direction = attr.Opcode.ToString()[0] == 'S' ? Direction.ServerToClient : Direction.ClientToServer; - // ReSharper disable once UseStringInterpolation - Trace.WriteLine(string.Format("Error: (Build: {0}) tried to overwrite delegate for opcode {1} ({2}); new handler: {3}; old handler: {4}", - ClientVersion.Build, Opcodes.GetOpcode(attr.Opcode, direction), attr.Opcode, del.Method, handlers[key].Method)); + Trace.WriteLine( + $"Error: (Build: {ClientVersion.Build}) tried to overwrite delegate for opcode {Opcodes.GetOpcode(attr.Opcode, direction)} ({attr.Opcode});" + + $" new handler: {del.Method.DeclaringType}.{del.Method.Name};" + + $" old handler: {existingHandler.Method.DeclaringType}.{existingHandler.Method.Name}"); continue; }