Skip to content

Commit

Permalink
Hook before TSAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
sgkoishi committed Apr 4, 2024
1 parent 53ac4fe commit 28a3507
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Core/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,17 @@ public record class MitigationSettings
/// </summary>
public Optional<bool> RestrictiveSocketSend = Optional.Default(false, true);

/// <summary>
/// <para>
/// Echo unchanged inventory back to the owner. This is meaningless and might be
/// used to duplicate items.
/// </para>
/// <para>
/// If you believe that this causes performance issues, turn this off.
/// </para>
/// </summary>
public Optional<bool> EchoUnchangedItem = Optional.Default(true, true);

public enum DisabledDamageAction
{
AsIs,
Expand Down
7 changes: 5 additions & 2 deletions Core/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ public Plugin(Main game) : base(game)

if (this.config.PrioritizedPacketHandle)
{
OTAPI.Hooks.MessageBuffer.GetData += this.OTHook_Modded_GetData;
OTAPI.Hooks.MessageBuffer.GetData += this.OTHook_Mitigation_GetData;
Utils.RegisterFirst(typeof(OTAPI.Hooks.MessageBuffer),
nameof(OTAPI.Hooks.MessageBuffer.GetData),
null,
this.OTHook_Mitigation_GetData,
this.OTHook_Mitigation_GetData);
}
}

Expand Down
6 changes: 6 additions & 0 deletions Core/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,12 @@ public static void AssemblyMutex(TerrariaApi.Server.TerrariaPlugin plugin)
}
}

public static void RegisterFirst(Type def, string name, object? instnace, params Delegate?[] eventHandlers)
{
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]));
}

public class ConsolePlayer : TSPlayer
{
public static ConsolePlayer Instance = new ConsolePlayer("Console");
Expand Down

0 comments on commit 28a3507

Please sign in to comment.