From 958fcf8ec6e5356a5bcae8c968070109db8c4abd Mon Sep 17 00:00:00 2001 From: 1zc Date: Wed, 7 Feb 2024 19:49:58 +1100 Subject: [PATCH] Change hook methods for OnTriggerStart/EndTouch --- src/ST-Events/TriggerEndTouch.cs | 10 ++++++---- src/ST-Events/TriggerStartTouch.cs | 10 ++++++---- src/SurfTimer.cs | 11 +++++++---- src/SurfTimer.csproj | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/ST-Events/TriggerEndTouch.cs b/src/ST-Events/TriggerEndTouch.cs index b98ed13..a8cd4ca 100644 --- a/src/ST-Events/TriggerEndTouch.cs +++ b/src/ST-Events/TriggerEndTouch.cs @@ -1,17 +1,19 @@ using System.Text.RegularExpressions; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Utils; -using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; namespace SurfTimer; public partial class SurfTimer { // Trigger end touch handler - CBaseTrigger_EndTouchFunc - internal HookResult OnTriggerEndTouch(DynamicHook handler) + // internal HookResult OnTriggerEndTouch(DynamicHook handler) + internal HookResult OnTriggerEndTouch(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay) { - CBaseTrigger trigger = handler.GetParam(0); - CBaseEntity entity = handler.GetParam(1); + // CBaseTrigger trigger = handler.GetParam(0); + CBaseTrigger trigger = new CBaseTrigger(caller.Handle); + // CBaseEntity entity = handler.GetParam(1); + CBaseEntity entity = new CBaseEntity(activator.Handle); CCSPlayerController client = new CCSPlayerController(new CCSPlayerPawn(entity.Handle).Controller.Value!.Handle); if (!client.IsValid || client.UserId == -1 || !client.PawnIsAlive || !playerList.ContainsKey((int)client.UserId!)) // `client.IsBot` throws error in server console when going to spectator? + !playerList.ContainsKey((int)client.UserId!) make sure to not check for user_id that doesnt exists { diff --git a/src/ST-Events/TriggerStartTouch.cs b/src/ST-Events/TriggerStartTouch.cs index 4f29736..c0af249 100644 --- a/src/ST-Events/TriggerStartTouch.cs +++ b/src/ST-Events/TriggerStartTouch.cs @@ -1,7 +1,6 @@ using System.Text.RegularExpressions; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Utils; -using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; using CounterStrikeSharp.API; namespace SurfTimer; @@ -9,10 +8,13 @@ namespace SurfTimer; public partial class SurfTimer { // Trigger start touch handler - CBaseTrigger_StartTouchFunc - internal HookResult OnTriggerStartTouch(DynamicHook handler) + // internal HookResult OnTriggerStartTouch(DynamicHook handler) + internal HookResult OnTriggerStartTouch(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay) { - CBaseTrigger trigger = handler.GetParam(0); - CBaseEntity entity = handler.GetParam(1); + // CBaseTrigger trigger = handler.GetParam(0); + CBaseTrigger trigger = new CBaseTrigger(caller.Handle); + // CBaseEntity entity = handler.GetParam(1); + CBaseEntity entity = new CBaseEntity(activator.Handle); CCSPlayerController client = new CCSPlayerController(new CCSPlayerPawn(entity.Handle).Controller.Value!.Handle); if (!client.IsValid || !client.PawnIsAlive || !playerList.ContainsKey((int)client.UserId!)) // !playerList.ContainsKey((int)client.UserId!) make sure to not check for user_id that doesnt exists { diff --git a/src/SurfTimer.cs b/src/SurfTimer.cs index 846a225..b1344df 100644 --- a/src/SurfTimer.cs +++ b/src/SurfTimer.cs @@ -122,9 +122,12 @@ public override void Load(bool hotReload) // Tick listener RegisterListener(OnTick); - // StartTouch Hook - VirtualFunctions.CBaseTrigger_StartTouchFunc.Hook(OnTriggerStartTouch, HookMode.Post); - // EndTouch Hook - VirtualFunctions.CBaseTrigger_EndTouchFunc.Hook(OnTriggerEndTouch, HookMode.Post); + // StartTouch Hook -- DEPRECATE BROKEN CS2 7TH FEB 2024 + // VirtualFunctions.CBaseTrigger_StartTouchFunc.Hook(OnTriggerStartTouch, HookMode.Post); + // EndTouch Hook -- DEPRECATE BROKEN CS2 7TH FEB 2024 + // VirtualFunctions.CBaseTrigger_EndTouchFunc.Hook(OnTriggerEndTouch, HookMode.Post); + + HookEntityOutput("trigger_multiple", "OnStartTouch", OnTriggerStartTouch); + HookEntityOutput("trigger_multiple", "OnEndTouch", OnTriggerEndTouch); } } diff --git a/src/SurfTimer.csproj b/src/SurfTimer.csproj index a35d1af..87e253f 100644 --- a/src/SurfTimer.csproj +++ b/src/SurfTimer.csproj @@ -13,7 +13,7 @@ - +