Skip to content

Commit

Permalink
Improve error log for duplicate opcode handlers to make locating them…
Browse files Browse the repository at this point in the history
… easier
  • Loading branch information
Shauren committed Jan 13, 2025
1 parent 1e57262 commit 91cfd6e
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions WowPacketParser/Parsing/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,13 @@ private static void LoadHandlersInto(Dictionary<KeyValuePair<ClientVersionBuild,

var del = (Action<Packet>)Delegate.CreateDelegate(typeof(Action<Packet>), 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;
}

Expand Down

0 comments on commit 91cfd6e

Please sign in to comment.