Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect OTAPI hook result #247

Open
wants to merge 1 commit into
base: general-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions TerrariaServerAPI/TerrariaApi.Server/Hooking/GameHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions TerrariaServerAPI/TerrariaApi.Server/Hooking/ItemHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions TerrariaServerAPI/TerrariaApi.Server/Hooking/NetHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions TerrariaServerAPI/TerrariaApi.Server/Hooking/NpcHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions TerrariaServerAPI/TerrariaApi.Server/Hooking/ServerHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions TerrariaServerAPI/TerrariaApi.Server/Hooking/WiringHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions TerrariaServerAPI/TerrariaApi.Server/Hooking/WorldHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down