From db63fdc00c0050b7f83bcd09d0a872442ce66f94 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Wed, 27 Dec 2023 14:32:37 +1000 Subject: [PATCH] feat: add `AcceptInput` method to `CEntityInstance` (#228) --- .../counterstrikesharp/gamedata/gamedata.json | 7 +++++++ .../Core/Model/CEntityInstance.cs | 18 ++++++++++++++++++ .../Modules/Memory/VirtualFunctions.cs | 3 +++ managed/TestPlugin/TestPlugin.cs | 11 +++++++++++ 4 files changed, 39 insertions(+) diff --git a/configs/addons/counterstrikesharp/gamedata/gamedata.json b/configs/addons/counterstrikesharp/gamedata/gamedata.json index bef31da1e..8fdf7f78d 100644 --- a/configs/addons/counterstrikesharp/gamedata/gamedata.json +++ b/configs/addons/counterstrikesharp/gamedata/gamedata.json @@ -113,6 +113,13 @@ "linux": "\\x48\\x85\\xFF\\x74\\x4B\\x55\\x48\\x89\\xE5\\x41\\x56" } }, + "CEntityInstance_AcceptInput": { + "signatures": { + "library": "server", + "windows": "\\x48\\x89\\x5C\\x24\\x10\\x48\\x89\\x74\\x24\\x18\\x57\\x48\\x83\\xEC\\x40\\x49\\x8B\\xF0", + "linux": "\\x55\\x48\\x89\\xE5\\x41\\x57\\x49\\x89\\xFF\\x41\\x56\\x48\\x8D\\x7D\\xC0" + } + }, "LegacyGameEventListener": { "signatures": { "library": "server", diff --git a/managed/CounterStrikeSharp.API/Core/Model/CEntityInstance.cs b/managed/CounterStrikeSharp.API/Core/Model/CEntityInstance.cs index ffd8c3392..4d5d74017 100644 --- a/managed/CounterStrikeSharp.API/Core/Model/CEntityInstance.cs +++ b/managed/CounterStrikeSharp.API/Core/Model/CEntityInstance.cs @@ -58,6 +58,24 @@ public override int GetHashCode() { return !Equals(left, right); } + + /// + /// Calls a named input method on an entity. + /// + /// + /// entity.AcceptInput("Break"); + /// + /// + /// + /// Input action name + /// Entity which initiated the action, for no entity + /// Entity that is sending the event, for no entity + /// String variant value to send with the event + /// Unknown, defaults to 0 + public void AcceptInput(string inputName, CEntityInstance? activator = null, CEntityInstance? caller = null, string value = "", int outputId = 0) + { + VirtualFunctions.AcceptInput(Handle, inputName, activator?.Handle ?? IntPtr.Zero, caller?.Handle ?? IntPtr.Zero, value, 0); + } } public partial class CEntityIdentity diff --git a/managed/CounterStrikeSharp.API/Modules/Memory/VirtualFunctions.cs b/managed/CounterStrikeSharp.API/Modules/Memory/VirtualFunctions.cs index 3b9777e6b..82a072b4e 100644 --- a/managed/CounterStrikeSharp.API/Modules/Memory/VirtualFunctions.cs +++ b/managed/CounterStrikeSharp.API/Modules/Memory/VirtualFunctions.cs @@ -80,4 +80,7 @@ public static class VirtualFunctions public static MemoryFunctionVoid RemovePlayerItemFunc = new(GameData.GetSignature("CBasePlayerPawn_RemovePlayerItem")); public static Action RemovePlayerItemVirtual = RemovePlayerItemFunc.Invoke; + + public static MemoryFunctionVoid AcceptInputFunc = new(GameData.GetSignature("CEntityInstance_AcceptInput")); + public static Action AcceptInput = AcceptInputFunc.Invoke; } \ No newline at end of file diff --git a/managed/TestPlugin/TestPlugin.cs b/managed/TestPlugin/TestPlugin.cs index f737d4c1b..5486748ae 100644 --- a/managed/TestPlugin/TestPlugin.cs +++ b/managed/TestPlugin/TestPlugin.cs @@ -501,6 +501,17 @@ public void OnRespawn(CCSPlayerController? player, CommandInfo command) player.Respawn(); } + [ConsoleCommand("css_break", "Breaks the breakable entities")] + public void OnBreakCommand(CCSPlayerController? player, CommandInfo command) + { + var entities = Utilities.FindAllEntitiesByDesignerName("prop_dynamic") + .Concat(Utilities.FindAllEntitiesByDesignerName("func_breakable")); + foreach (var entity in entities) + { + entity.AcceptInput("Break"); + } + } + [ConsoleCommand("cssharp_attribute", "This is a custom attribute event")] public void OnCommand(CCSPlayerController? player, CommandInfo command) {