Skip to content

Commit

Permalink
Change hook methods for OnTriggerStart/EndTouch
Browse files Browse the repository at this point in the history
  • Loading branch information
1zc committed Feb 7, 2024
1 parent 07b9eff commit 958fcf8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
10 changes: 6 additions & 4 deletions src/ST-Events/TriggerEndTouch.cs
Original file line number Diff line number Diff line change
@@ -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<CBaseTrigger>(0);
CBaseEntity entity = handler.GetParam<CBaseEntity>(1);
// CBaseTrigger trigger = handler.GetParam<CBaseTrigger>(0);
CBaseTrigger trigger = new CBaseTrigger(caller.Handle);
// CBaseEntity entity = handler.GetParam<CBaseEntity>(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
{
Expand Down
10 changes: 6 additions & 4 deletions src/ST-Events/TriggerStartTouch.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using System.Text.RegularExpressions;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using CounterStrikeSharp.API;

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<CBaseTrigger>(0);
CBaseEntity entity = handler.GetParam<CBaseEntity>(1);
// CBaseTrigger trigger = handler.GetParam<CBaseTrigger>(0);
CBaseTrigger trigger = new CBaseTrigger(caller.Handle);
// CBaseEntity entity = handler.GetParam<CBaseEntity>(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
{
Expand Down
11 changes: 7 additions & 4 deletions src/SurfTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ public override void Load(bool hotReload)
// Tick listener
RegisterListener<Listeners.OnTick>(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);
}
}
2 changes: 1 addition & 1 deletion src/SurfTimer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.159" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.160" />
<PackageReference Include="MaxMind.GeoIP2" Version="5.2.0" />
<PackageReference Include="MySqlConnector" Version="2.3.1" />
</ItemGroup>
Expand Down

0 comments on commit 958fcf8

Please sign in to comment.