From 8c321078701867553c3b421b20c37472d480b9bb Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 29 Mar 2024 10:32:12 +0100 Subject: [PATCH 1/4] Add weapon drops to logs --- .../Listeners/LogEntityListeners.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs b/mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs index 22f51286..876b0fa0 100644 --- a/mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs +++ b/mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs @@ -1,7 +1,8 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; - +using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; +using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Views; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Extensions; @@ -15,6 +16,24 @@ public class LogEntityListeners : IPluginBehavior public LogEntityListeners(IRichLogService logs) { _logs = logs; + OnDropGun(); + } + + private static MemoryFunctionVoid WeaponDrop = new( "\\x55\\x48\\x89\\xE5\\x41\\x56\\x41\\x55\\x49\\x89\\xD5\\x41\\x54\\x49\\x89\\xFC\\x53\\x48\\x89\\xF3\\xE8\\x2A\\x2A\\x2A\\x2A" ); + + private void OnDropGun() + { + WeaponDrop.Hook(hook => + { + var player = hook.GetParam(0); + var weapon = hook.GetParam(1); + + if (!player.IsValid) return HookResult.Continue; + if (player.TeamNum != (byte)CsTeam.CounterTerrorist) return HookResult.Changed; + + _logs.Append(_logs.Player((CCSPlayerController)player.Controller.Value), $"dropped weapon: {weapon.DesignerName}"); + return HookResult.Continue; + }, HookMode.Pre); } [EntityOutputHook("func_button", "OnPressed")] From 844abdc92b0e7988ba152da5c656f9c36c1d5d9e Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 14 Apr 2024 12:15:36 +0200 Subject: [PATCH 2/4] Add weapon logs to item pickup, needs testing --- .../Listeners/LogEntityListeners.cs | 47 +++++++++++++++++-- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs b/mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs index 876b0fa0..236587b3 100644 --- a/mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs +++ b/mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs @@ -19,23 +19,60 @@ public LogEntityListeners(IRichLogService logs) OnDropGun(); } - private static MemoryFunctionVoid WeaponDrop = new( "\\x55\\x48\\x89\\xE5\\x41\\x56\\x41\\x55\\x49\\x89\\xD5\\x41\\x54\\x49\\x89\\xFC\\x53\\x48\\x89\\xF3\\xE8\\x2A\\x2A\\x2A\\x2A" ); + private static MemoryFunctionVoid WeaponDrop = new( @"\x55\x48\x89\xE5\x41\x56\x41\x55\x49\x89\xD5\x41\x54\x49\x89\xFC\x53\x48\x89\xF3\xE8\x2A\x2A\x2A\x2A" ); private void OnDropGun() { WeaponDrop.Hook(hook => { - var player = hook.GetParam(0); + var pawn = hook.GetParam(0); var weapon = hook.GetParam(1); - if (!player.IsValid) return HookResult.Continue; - if (player.TeamNum != (byte)CsTeam.CounterTerrorist) return HookResult.Changed; + if (!pawn.IsValid) return HookResult.Continue; + if (pawn.Controller.Value == null || !pawn.Controller.IsValid) return HookResult.Continue; + + var player = (CCSPlayerController)pawn.Controller.Value; + + if (player.Team != CsTeam.CounterTerrorist) return HookResult.Changed; - _logs.Append(_logs.Player((CCSPlayerController)player.Controller.Value), $"dropped weapon: {weapon.DesignerName}"); + _logs.Append(_logs.Player(player), $"dropped weapon: {weapon.DesignerName}"); return HookResult.Continue; }, HookMode.Pre); } + [GameEventHandler] + public void OnItemPickup(EventItemPickup @event, GameEventInfo info) + { + var player = @event.Userid; + if (!player.IsReal()) + return; + + if (!player.IsValid) + return; + + if (player.Team != CsTeam.Terrorist) return; + + + Server.NextFrame(() => + { + var pawn = player.PlayerPawn.Value; + if (pawn == null || !pawn.IsValid) return; + var weaponServices = pawn.WeaponServices; + if (weaponServices == null) return; + + foreach (var weaponHandle in weaponServices.MyWeapons.Where(handle => handle.IsValid && handle.Value != null).ToList()) + { + if (!weaponHandle.Value.DesignerName.Equals(@event.Item)) continue; + + var owner = weaponHandle.Value.OwnerEntity.Value.As(); + if (owner.Team != CsTeam.CounterTerrorist) return; + _logs.Append(_logs.Player(player), $"picked up an {_logs.Player(owner)}s item: {weaponHandle.Value.DesignerName}"); + + } + }); + + } + [EntityOutputHook("func_button", "OnPressed")] public HookResult OnButtonPressed(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay) From bfd3002c007163f33bda1b0fa49936ad5bf63a07 Mon Sep 17 00:00:00 2001 From: jii Date: Fri, 26 Apr 2024 16:24:46 -0500 Subject: [PATCH 3/4] Update CS# Version --- public/Jailbreak.Public/Jailbreak.Public.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/Jailbreak.Public/Jailbreak.Public.csproj b/public/Jailbreak.Public/Jailbreak.Public.csproj index 92d4cd0f..5a410e5e 100644 --- a/public/Jailbreak.Public/Jailbreak.Public.csproj +++ b/public/Jailbreak.Public/Jailbreak.Public.csproj @@ -7,7 +7,7 @@ - + From 279600f9a17cdbaa01650a12c4b350d45bce8d3e Mon Sep 17 00:00:00 2001 From: jithatsonei Date: Fri, 26 Apr 2024 21:13:50 -0500 Subject: [PATCH 4/4] Revert "Add weapon drops to logs" --- .../Listeners/LogEntityListeners.cs | 58 +------------------ 1 file changed, 1 insertion(+), 57 deletions(-) diff --git a/mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs b/mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs index 236587b3..22f51286 100644 --- a/mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs +++ b/mod/Jailbreak.Logs/Listeners/LogEntityListeners.cs @@ -1,8 +1,7 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; -using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; -using CounterStrikeSharp.API.Modules.Utils; + using Jailbreak.Formatting.Views; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Extensions; @@ -16,61 +15,6 @@ public class LogEntityListeners : IPluginBehavior public LogEntityListeners(IRichLogService logs) { _logs = logs; - OnDropGun(); - } - - private static MemoryFunctionVoid WeaponDrop = new( @"\x55\x48\x89\xE5\x41\x56\x41\x55\x49\x89\xD5\x41\x54\x49\x89\xFC\x53\x48\x89\xF3\xE8\x2A\x2A\x2A\x2A" ); - - private void OnDropGun() - { - WeaponDrop.Hook(hook => - { - var pawn = hook.GetParam(0); - var weapon = hook.GetParam(1); - - if (!pawn.IsValid) return HookResult.Continue; - if (pawn.Controller.Value == null || !pawn.Controller.IsValid) return HookResult.Continue; - - var player = (CCSPlayerController)pawn.Controller.Value; - - if (player.Team != CsTeam.CounterTerrorist) return HookResult.Changed; - - _logs.Append(_logs.Player(player), $"dropped weapon: {weapon.DesignerName}"); - return HookResult.Continue; - }, HookMode.Pre); - } - - [GameEventHandler] - public void OnItemPickup(EventItemPickup @event, GameEventInfo info) - { - var player = @event.Userid; - if (!player.IsReal()) - return; - - if (!player.IsValid) - return; - - if (player.Team != CsTeam.Terrorist) return; - - - Server.NextFrame(() => - { - var pawn = player.PlayerPawn.Value; - if (pawn == null || !pawn.IsValid) return; - var weaponServices = pawn.WeaponServices; - if (weaponServices == null) return; - - foreach (var weaponHandle in weaponServices.MyWeapons.Where(handle => handle.IsValid && handle.Value != null).ToList()) - { - if (!weaponHandle.Value.DesignerName.Equals(@event.Item)) continue; - - var owner = weaponHandle.Value.OwnerEntity.Value.As(); - if (owner.Team != CsTeam.CounterTerrorist) return; - _logs.Append(_logs.Player(player), $"picked up an {_logs.Player(owner)}s item: {weaponHandle.Value.DesignerName}"); - - } - }); - } [EntityOutputHook("func_button", "OnPressed")]