From dd2c80666da1351fe2c758de3babdfe55dca1028 Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Mon, 9 Jan 2023 10:55:15 -0800 Subject: [PATCH] Respect OTAPI hook result --- .../TerrariaApi.Server/Hooking/GameHooks.cs | 16 ++++++++++++++++ .../TerrariaApi.Server/Hooking/ItemHooks.cs | 4 ++++ .../TerrariaApi.Server/Hooking/NetHooks.cs | 16 ++++++++++++++++ .../TerrariaApi.Server/Hooking/NpcHooks.cs | 12 ++++++++++++ .../TerrariaApi.Server/Hooking/ServerHooks.cs | 4 ++++ .../TerrariaApi.Server/Hooking/WiringHooks.cs | 4 ++++ .../TerrariaApi.Server/Hooking/WorldHooks.cs | 8 ++++++++ 7 files changed, 64 insertions(+) diff --git a/TerrariaServerAPI/TerrariaApi.Server/Hooking/GameHooks.cs b/TerrariaServerAPI/TerrariaApi.Server/Hooking/GameHooks.cs index 9e556b61..9608cd8e 100644 --- a/TerrariaServerAPI/TerrariaApi.Server/Hooking/GameHooks.cs +++ b/TerrariaServerAPI/TerrariaApi.Server/Hooking/GameHooks.cs @@ -34,6 +34,10 @@ private static void OnUpdate(On.Terraria.Main.orig_Update orig, Terraria.Main in private static void OnHardmodeTileUpdate(object sender, Hooks.WorldGen.HardmodeTileUpdateEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } if (_hookManager.InvokeGameHardmodeTileUpdate(e.X, e.Y, e.Type)) { e.Result = HookResult.Cancel; @@ -42,6 +46,10 @@ private static void OnHardmodeTileUpdate(object sender, Hooks.WorldGen.HardmodeT private static void OnHardmodeTilePlace(object sender, Hooks.WorldGen.HardmodeTilePlaceEventArgs e) { + if (e.Result == HardmodeTileUpdateResult.Cancel) + { + return; + } if (_hookManager.InvokeGameHardmodeTileUpdate(e.X, e.Y, e.Type)) { e.Result = HardmodeTileUpdateResult.Cancel; @@ -63,6 +71,10 @@ private static void OnStartServer(On.Terraria.Netplay.orig_StartServer orig) private static void OnItemMechSpawn(object sender, Hooks.Item.MechSpawnEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } if (!_hookManager.InvokeGameStatueSpawn(e.Num2, e.Num3, e.Num, (int)(e.X / 16f), (int)(e.Y / 16f), e.Type, false)) { e.Result = HookResult.Cancel; @@ -71,6 +83,10 @@ private static void OnItemMechSpawn(object sender, Hooks.Item.MechSpawnEventArgs private static void OnNpcMechSpawn(object sender, Hooks.NPC.MechSpawnEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } if (!_hookManager.InvokeGameStatueSpawn(e.Num2, e.Num3, e.Num, (int)(e.X / 16f), (int)(e.Y / 16f), e.Type, true)) { e.Result = HookResult.Cancel; diff --git a/TerrariaServerAPI/TerrariaApi.Server/Hooking/ItemHooks.cs b/TerrariaServerAPI/TerrariaApi.Server/Hooking/ItemHooks.cs index 5919d323..f3f10ec1 100644 --- a/TerrariaServerAPI/TerrariaApi.Server/Hooking/ItemHooks.cs +++ b/TerrariaServerAPI/TerrariaApi.Server/Hooking/ItemHooks.cs @@ -40,6 +40,10 @@ private static void OnSetDefaults(On.Terraria.Item.orig_SetDefaults_int_bool_Ite private static void OnQuickStack(object sender, Hooks.Chest.QuickStackEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } if (_hookManager.InvokeItemForceIntoChest(Main.chest[e.ChestIndex], e.Item, Main.player[e.PlayerId])) { e.Result = HookResult.Cancel; diff --git a/TerrariaServerAPI/TerrariaApi.Server/Hooking/NetHooks.cs b/TerrariaServerAPI/TerrariaApi.Server/Hooking/NetHooks.cs index 07915205..a2c3c5fe 100644 --- a/TerrariaServerAPI/TerrariaApi.Server/Hooking/NetHooks.cs +++ b/TerrariaServerAPI/TerrariaApi.Server/Hooking/NetHooks.cs @@ -50,6 +50,10 @@ static void OnBroadcastChatMessage(On.Terraria.Chat.ChatHelper.orig_BroadcastCha static void OnSendData(object sender, Hooks.NetMessage.SendDataEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } if (e.Event == HookEvent.Before) { var msgType = e.MsgType; @@ -110,6 +114,10 @@ ref packet static void OnReceiveData(object sender, Hooks.MessageBuffer.GetDataEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } if (!Enum.IsDefined(typeof(PacketTypes), (int)e.PacketId)) { e.Result = HookResult.Cancel; @@ -141,6 +149,10 @@ static void OnGreetPlayer(On.Terraria.NetMessage.orig_greetPlayer orig, int plr) static void OnSendBytes(object sender, Hooks.NetMessage.SendBytesEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } if (_hookManager.InvokeNetSendBytes(Netplay.Clients[e.RemoteClient], e.Data, e.Offset, e.Size)) { e.Result = HookResult.Cancel; @@ -149,6 +161,10 @@ static void OnSendBytes(object sender, Hooks.NetMessage.SendBytesEventArgs e) static void OnNameCollision(object sender, Hooks.MessageBuffer.NameCollisionEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } if (_hookManager.InvokeNetNameCollision(e.Player.whoAmI, e.Player.name)) { e.Result = HookResult.Cancel; diff --git a/TerrariaServerAPI/TerrariaApi.Server/Hooking/NpcHooks.cs b/TerrariaServerAPI/TerrariaApi.Server/Hooking/NpcHooks.cs index a6b501fe..85ae4157 100644 --- a/TerrariaServerAPI/TerrariaApi.Server/Hooking/NpcHooks.cs +++ b/TerrariaServerAPI/TerrariaApi.Server/Hooking/NpcHooks.cs @@ -72,6 +72,10 @@ static void OnTransform(On.Terraria.NPC.orig_Transform orig, NPC npc, int newTyp static void OnSpawn(object sender, Hooks.NPC.SpawnEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } var index = e.Index; if (_hookManager.InvokeNpcSpawn(ref index)) { @@ -82,6 +86,10 @@ static void OnSpawn(object sender, Hooks.NPC.SpawnEventArgs e) static void OnDropLoot(object sender, Hooks.NPC.DropLootEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } if (e.Event == HookEvent.Before) { var Width = e.Width; @@ -129,6 +137,10 @@ ref reverseLookup static void OnBossBagItem(object sender, Hooks.NPC.BossBagEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } var Width = e.Width; var Height = e.Height; var Type = e.Type; diff --git a/TerrariaServerAPI/TerrariaApi.Server/Hooking/ServerHooks.cs b/TerrariaServerAPI/TerrariaApi.Server/Hooking/ServerHooks.cs index f4c0cd2d..3f5886ef 100644 --- a/TerrariaServerAPI/TerrariaApi.Server/Hooking/ServerHooks.cs +++ b/TerrariaServerAPI/TerrariaApi.Server/Hooking/ServerHooks.cs @@ -35,6 +35,10 @@ static void Main_startDedInput(On.Terraria.Main.orig_startDedInput orig) static void OnProcess(object sender, Hooks.Main.CommandProcessEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } if (_hookManager.InvokeServerCommand(e.Command)) { e.Result = HookResult.Cancel; diff --git a/TerrariaServerAPI/TerrariaApi.Server/Hooking/WiringHooks.cs b/TerrariaServerAPI/TerrariaApi.Server/Hooking/WiringHooks.cs index a5ef0ae2..84f116f0 100644 --- a/TerrariaServerAPI/TerrariaApi.Server/Hooking/WiringHooks.cs +++ b/TerrariaServerAPI/TerrariaApi.Server/Hooking/WiringHooks.cs @@ -20,6 +20,10 @@ public static void AttachTo(HookManager hookManager) static void OnAnnouncementBox(object sender, Hooks.Wiring.AnnouncementBoxEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } if (_hookManager.InvokeWireTriggerAnnouncementBox(Wiring.CurrentUser, e.X, e.Y, e.SignId, Main.sign[e.SignId].text)) { e.Result = HookResult.Cancel; diff --git a/TerrariaServerAPI/TerrariaApi.Server/Hooking/WorldHooks.cs b/TerrariaServerAPI/TerrariaApi.Server/Hooking/WorldHooks.cs index 7095fce4..8818131b 100644 --- a/TerrariaServerAPI/TerrariaApi.Server/Hooking/WorldHooks.cs +++ b/TerrariaServerAPI/TerrariaApi.Server/Hooking/WorldHooks.cs @@ -27,6 +27,10 @@ public static void AttachTo(HookManager hookManager) static void OnPressurePlate(object sender, Hooks.Collision.PressurePlateEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } if (e.Entity is NPC npc) { if (_hookManager.InvokeNpcTriggerPressurePlate(npc, e.X, e.Y)) @@ -62,6 +66,10 @@ private static void WorldGen_StartHardmode(On.Terraria.WorldGen.orig_StartHardmo static void OnDropMeteor(object sender, Hooks.WorldGen.MeteorEventArgs e) { + if (e.Result == HookResult.Cancel) + { + return; + } if (_hookManager.InvokeWorldMeteorDrop(e.X, e.Y)) { e.Result = HookResult.Cancel;