Skip to content
48 changes: 48 additions & 0 deletions extensions/sdktools/vnatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@
#include <iclient.h>
#include "iserver.h"
#include "am-string.h"
#include <sm_argbuffer.h>

SourceHook::List<ValveCall *> g_RegCalls;
SourceHook::List<ICallWrapper *> 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;
Expand Down Expand Up @@ -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<CBaseEntity *, int> vstk(pEntity, params[2]);

pSetCollisionGroup->Execute(vstk, nullptr);

return 1;

}

sp_nativeinfo_t g_Natives[] =
{
{"ExtinguishEntity", ExtinguishEntity},
Expand Down Expand Up @@ -1522,5 +1569,6 @@ sp_nativeinfo_t g_Natives[] =
{"SetClientName", SetClientName},
{"GetPlayerResourceEntity", GetPlayerResourceEntity},
{"GivePlayerAmmo", GivePlayerAmmo},
{"SetCollisionGroup", SetCollisionGroup},
{NULL, NULL},
};
6 changes: 6 additions & 0 deletions gamedata/sdktools.games/engine.csgo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions gamedata/sdktools.games/engine.css.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions gamedata/sdktools.games/game.tf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
9 changes: 9 additions & 0 deletions plugins/include/sdktools_functions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,12 @@ native void SetClientName(int client, const char[] name);
* @return Amount of ammo actually given.
*/
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);