From a9d3cf45741b9b8888f8226ca89d257b6bdb980a Mon Sep 17 00:00:00 2001 From: Adam Short Date: Thu, 24 Jun 2021 18:04:10 -0400 Subject: [PATCH] sdktools: Add SetCollisionGroup native (#1461) (#1507) * Add SetCollisionGroup native * Add newline to end of file * Fix gamedata locations * Remove extra spaces * Fix gamedata formatting * Add Windows signature for CS:GO * Fix native doc comment * Revert formatting change * Change references of client -> entity * Moved CallWrapper into method * typofix Co-authored-by: Kyle Sanderson --- extensions/sdktools/vnatives.cpp | 48 +++++++++++++++++++++++++ gamedata/sdktools.games/engine.csgo.txt | 6 ++++ gamedata/sdktools.games/engine.css.txt | 6 ++++ gamedata/sdktools.games/game.tf.txt | 6 ++++ plugins/include/sdktools_functions.inc | 9 +++++ 5 files changed, 75 insertions(+) diff --git a/extensions/sdktools/vnatives.cpp b/extensions/sdktools/vnatives.cpp index bc340184..caa0eda0 100644 --- a/extensions/sdktools/vnatives.cpp +++ b/extensions/sdktools/vnatives.cpp @@ -41,10 +41,18 @@ #include #include "iserver.h" #include "am-string.h" +#include SourceHook::List g_RegCalls; SourceHook::List g_CallWraps; +#define ENTINDEX_TO_CBASEENTITY(ref, buffer) \ + buffer = gamehelpers->ReferenceToEntity(ref); \ + if (!buffer) \ + { \ + return pContext->ThrowNativeError("Entity %d (%d) is not a CBaseEntity", gamehelpers->ReferenceToIndex(ref), ref); \ + } + inline void InitPass(ValvePassInfo &info, ValveType vtype, PassType type, unsigned int flags, unsigned int decflags=0) { info.decflags = decflags; @@ -1491,6 +1499,45 @@ static cell_t GivePlayerAmmo(IPluginContext *pContext, const cell_t *params) return ammoGiven; } +// SetCollisionGroup(int entity, int collisionGroup) +static cell_t SetCollisionGroup(IPluginContext *pContext, const cell_t *params) +{ + static ICallWrapper *pSetCollisionGroup = NULL; + if (!pSetCollisionGroup) + { + void *addr; + if (!g_pGameConf->GetMemSig("SetCollisionGroup", &addr) || !addr) + { + return pContext->ThrowNativeError("\"SetCollisionGroup\" not supported by this mod"); + } + PassInfo pass[2]; + // Entity + pass[0].type = PassType_Basic; + pass[0].flags = PASSFLAG_BYVAL; + pass[0].size = sizeof(CBaseEntity *); + + // Collision Group + pass[1].type = PassType_Basic; + pass[1].flags = PASSFLAG_BYVAL; + pass[1].size = sizeof(int); + + if (!(pSetCollisionGroup = g_pBinTools->CreateCall(addr, CallConv_ThisCall, NULL, pass, 2))) + { + return pContext->ThrowNativeError("\"SetCollisionGroup\" wrapper failed to initialize"); + } + } + + CBaseEntity *pEntity; + ENTINDEX_TO_CBASEENTITY(params[1], pEntity); + + ArgBuffer vstk(pEntity, params[2]); + + pSetCollisionGroup->Execute(vstk, nullptr); + + return 1; + +} + sp_nativeinfo_t g_Natives[] = { {"ExtinguishEntity", ExtinguishEntity}, @@ -1522,5 +1569,6 @@ sp_nativeinfo_t g_Natives[] = {"SetClientName", SetClientName}, {"GetPlayerResourceEntity", GetPlayerResourceEntity}, {"GivePlayerAmmo", GivePlayerAmmo}, + {"SetCollisionGroup", SetCollisionGroup}, {NULL, NULL}, }; diff --git a/gamedata/sdktools.games/engine.csgo.txt b/gamedata/sdktools.games/engine.csgo.txt index 0c004759..9ea157dd 100644 --- a/gamedata/sdktools.games/engine.csgo.txt +++ b/gamedata/sdktools.games/engine.csgo.txt @@ -181,6 +181,12 @@ "linux64" "\x55\x48\x89\xE5\x41\x57\x41\x56\x49\x89\xF6\x41\x55\x41\x54\x49\x89\xCC\x53" "mac64" "\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x41\x54\x53\x48\x81\xEC\x88\x01\x00\x00\xF3\x0F\x11\x85\x8C\xFE\xFF\xFF" } + "SetCollisionGroup" + { + "library" "server" + "windows" "\x55\x8B\xEC\x53\x8B\xD9\x56\x57\x8B\x7D\x08\x39\xBB\x54\x01\x00\x00\x74\x40\x80\x79\x58\x00\x74" + "linux" "\x55\x89\xE5\x83\xEC\x18\x89\x5D\xF8\x8B\x5D\x08\x89\x75\xFC\x8B\x75\x0C\x39\xB3\x5C\x01\x00\x00" + } } } diff --git a/gamedata/sdktools.games/engine.css.txt b/gamedata/sdktools.games/engine.css.txt index 332753ba..1e906ce2 100644 --- a/gamedata/sdktools.games/engine.css.txt +++ b/gamedata/sdktools.games/engine.css.txt @@ -86,6 +86,12 @@ "linux" "@_ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f" "mac" "@_ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f" } + "SetCollisionGroup" + { + "library" "server" + "windows" "\x55\x8b\xec\x53\x8b\x5d\x08\x56\x57\x8b\xf9\x39\x9f\xe0\x01\x00\x00\x74\x4f\x8b" + "linux" "@_ZN11CBaseEntity17SetCollisionGroupEi" + } } } diff --git a/gamedata/sdktools.games/game.tf.txt b/gamedata/sdktools.games/game.tf.txt index e3466505..9d4b4b25 100644 --- a/gamedata/sdktools.games/game.tf.txt +++ b/gamedata/sdktools.games/game.tf.txt @@ -127,6 +127,12 @@ "linux" "@_ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f" "mac" "@_ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f" } + "SetCollisionGroup" + { + "library" "server" + "windows" "\x55\x8B\xEC\x53\x8B\x5D\x08\x56\x57\x8B\xF9\x39\x9F\xF0\x01\x00\x00" + "linux" "@_ZN11CBaseEntity17SetCollisionGroupEi" + } } } } diff --git a/plugins/include/sdktools_functions.inc b/plugins/include/sdktools_functions.inc index b5d5cf47..c843268c 100644 --- a/plugins/include/sdktools_functions.inc +++ b/plugins/include/sdktools_functions.inc @@ -351,3 +351,12 @@ native void SetClientName(int client, const char[] name); * @error Lack of mod support. */ native int GivePlayerAmmo(int client, int amount, int ammotype, bool suppressSound=false); + +/** + * Changes an entity's collision group (CBaseEntity::SetCollisionGroup). + * + * @param entity The entity index. + * @param collisionGroup Collision group to use. + * @error Invalid entity or lack of mod support. + */ +native void SetCollisionGroup(int entity, int collisionGroup);