Skip to content

Commit

Permalink
Use typed delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
sgkoishi committed Apr 4, 2024
1 parent 28a3507 commit 3311843
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Core/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public Plugin(Main game) : base(game)

if (this.config.PrioritizedPacketHandle)
{
Utils.RegisterFirst(typeof(OTAPI.Hooks.MessageBuffer),
Utils.RegisterFirst<EventHandler<OTAPI.Hooks.MessageBuffer.GetDataEventArgs>>(typeof(OTAPI.Hooks.MessageBuffer),
nameof(OTAPI.Hooks.MessageBuffer.GetData),
null,
this.OTHook_Mitigation_GetData,
Expand Down
4 changes: 2 additions & 2 deletions Core/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,10 @@ public static void AssemblyMutex(TerrariaApi.Server.TerrariaPlugin plugin)
}
}

public static void RegisterFirst(Type def, string name, object? instnace, params Delegate?[] eventHandlers)
public static void RegisterFirst<T>(Type def, string name, object? instnace, params T?[] eventHandlers) where T : Delegate
{
var t = def.GetField(name, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance);
t?.SetValue(instnace, Delegate.Combine([.. eventHandlers, t.GetValue(instnace) as Delegate]));
t?.SetValue(instnace, Delegate.Combine([.. eventHandlers, (T?) t.GetValue(instnace)]));
}

public class ConsolePlayer : TSPlayer
Expand Down

0 comments on commit 3311843

Please sign in to comment.