I write plugin for Meta Mod:Source for CS:S game. My plugin based on sample_mm plugin from source codes of Meta Mod from this download page
http://www.sourcemm.net/downloads.
I want make simple plugin, that able enable flash effect for all players by entering command in the console, for example "flashbang".
I modified "Hook_ClientCommand" function in sample_mm.cpp:
Code:
#if SOURCE_ENGINE >= SE_ORANGEBOX
void SamplePlugin::Hook_ClientCommand(edict_t *pEntity, const CCommand &args)
#else
void SamplePlugin::Hook_ClientCommand(edict_t *pEntity)
#endif
{
#if SOURCE_ENGINE <= SE_DARKMESSIAH
CCommand args;
#endif
if (!pEntity || pEntity->IsFree())
{
return;
}
const char *cmd = args.Arg(0);
if (strcmp(cmd, "flashbang") == 0)
{
int i;
edict_t *pEnt;
for (i=1; i<=64; i++)
{
pEnt = engine->PEntityOfEntIndex(i);
if (pEnt && !pEnt->IsFree() && FStrEq(pEnt->GetClassName(), "player"))
{
gVFuncs.SomeFunc(pEnt->GetUnknown()->GetBaseEntity());
}
}
RETURN_META(MRES_SUPERCEDE);
}
}
and I make "VFuncs" class as in this example
http://wiki.alliedmods.net/Virtual_O..._(Source_Mods)
but my "VFuncs" class have single function, that enable flash effect for certain player entity
Code:
void VFuncs::SomeFunc(CBaseEntity *pThisPtr)
{
void **this_ptr = *(void ***)&pThisPtr;
void **vtable = *(void ***)pThisPtr;
void *func = vtable[348];
union {void (VfuncEmptyClass::*mfpnew)();
#ifndef __linux__
void *addr; } u; u.addr = func;
#else // GCC's member function pointers all contain a this pointer adjustor. You'd probably set it to 0
struct {void *addr; intptr_t adjustor;} s; } u; u.s.addr = func; u.s.adjustor = 0;
#endif
(void) (reinterpret_cast<VfuncEmptyClass*>(this_ptr)->*u.mfpnew)();
}
In this code 348 is offset CCSPlayer::FlashlightTurnOn() function in Virtual Table from
Virtual Table Offset List page.
I have successfully compiled plugin, and started server with Metamod plugin and my plugin. But when I enter into client console "flashbang" command nothing happens.
In what may be a problem?