diff --git a/Core/Config.cs b/Core/Config.cs index b60fc6c..30635fa 100644 --- a/Core/Config.cs +++ b/Core/Config.cs @@ -20,6 +20,11 @@ public class Config /// public Optional DateTimeFormat = Optional.Default("yyyy-MM-dd HH:mm:ss.fff"); + /// + /// Let Chireiden.TShock.Omni to handle packets earlier. + /// + public Optional PrioritizedPacketHandle = Optional.Default(true); + /// /// The wildcard of matching all players. Directly using "*" itself is not /// suggested as some commands might have special meaning for it. @@ -673,7 +678,7 @@ public record class MitigationSettings /// /// - /// The `WorldGen.countTiles` is recursive and might cause stack overflow. + /// The `WorldGen.countTiles` is recursive and might cause stack overflow. /// Reported by a Mac (rosetta) user @ Discord during spider cave gen every time. /// /// @@ -687,7 +692,7 @@ public record class MitigationSettings /// Allow journey and non-journey players to join the server. /// /// - /// There is nothing wrong with this option. It is inside the Mitigations because it + /// There is nothing wrong with this option. It is inside the Mitigations because it /// requires GetData detour like many other mitigations and I put them together. /// /// @@ -710,7 +715,7 @@ public record class MitigationSettings /// /// Sample: /// { - /// + /// /// } /// /// @@ -718,7 +723,7 @@ public record class MitigationSettings /// /// - /// Restrict all socket send operations to have exactly one message/packet per + /// Restrict all socket send operations to have exactly one message/packet per /// Send call. Requires AnotherAsyncSocket. /// /// diff --git a/Core/Plugin.cs b/Core/Plugin.cs index db95a74..37cfc02 100644 --- a/Core/Plugin.cs +++ b/Core/Plugin.cs @@ -133,6 +133,12 @@ public Plugin(Main game) : base(game) .GetMethod(nameof(TShockAPI.Utils.GetRealIP), _bfany), this.Detour_RealIP_IPv6Support ); + + if (this.config.PrioritizedPacketHandle) + { + OTAPI.Hooks.MessageBuffer.GetData += this.OTHook_Modded_GetData; + OTAPI.Hooks.MessageBuffer.GetData += this.OTHook_Mitigation_GetData; + } } private Assembly? AssemblyResolveHandler(object? sender, ResolveEventArgs args) @@ -286,8 +292,13 @@ public override void Initialize() On.Terraria.Initializers.ChatInitializer.Load += this.MMHook_Mitigation_I18nCommand; On.Terraria.WorldGen.nextCount += this.MMHook_Mitigation_WorldGenNextCount; OTAPI.Hooks.NetMessage.SendBytes += this.OTHook_Ghost_SendBytes; + OTAPI.Hooks.NetMessage.SendBytes += this.OTHook_DebugPacket_SendBytes; OTAPI.Hooks.MessageBuffer.GetData += this.OTHook_Ping_GetData; - OTAPI.Hooks.MessageBuffer.GetData += this.OTHook_Modded_GetData; + if (!this.config.PrioritizedPacketHandle) + { + OTAPI.Hooks.MessageBuffer.GetData += this.OTHook_Modded_GetData; + OTAPI.Hooks.MessageBuffer.GetData += this.OTHook_Mitigation_GetData; + } TerrariaApi.Server.ServerApi.Hooks.NetNameCollision.Register(this, this.TAHook_NameCollision); TerrariaApi.Server.ServerApi.Hooks.GamePostInitialize.Register(this, this.OnGamePostInitialize); TerrariaApi.Server.ServerApi.Hooks.GameUpdate.Register(this, this.TAHook_Update); @@ -360,8 +371,6 @@ protected override void Dispose(bool disposing) private void OnGamePostInitialize(EventArgs args) { - OTAPI.Hooks.MessageBuffer.GetData += this.OTHook_Mitigation_GetData; - OTAPI.Hooks.NetMessage.SendBytes += this.OTHook_DebugPacket_SendBytes; On.Terraria.NetMessage.SendData += this.MMHook_DebugPacket_SendData; On.Terraria.MessageBuffer.GetData += this.MMHook_DebugPacket_GetData; On.Terraria.NetMessage.SendData += this.MMHook_DebugPacket_CatchSend;