Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "extension.h"
- #include "variant_t.h"
- Sample g_Sample; /**< Global singleton for extension's main interface */
- SMEXT_LINK(&g_Sample);
- int g_hookEntCreated = 0;
- int g_hookEntRemoved = 0;
- int g_hookInput[MAX_EDICTS] = {0};
- SH_DECL_HOOK2_void(CEntListHack, OnAddEntity, SH_NOATTRIB, 0, CBaseEntity *, CBaseHandle);
- SH_DECL_HOOK2_void(CEntListHack, OnRemoveEntity, SH_NOATTRIB, 0, CBaseEntity *, CBaseHandle);
- SH_DECL_MANUALHOOK5(AcceptInput, 0, 0, 0, bool, const char *, CBaseEntity *, CBaseEntity *, variant_t, int);
- bool Sample::SDK_OnLoad(char *error, size_t maxlength, bool late)
- {
- // Get AcceptInput offset from gamedata. (from SDK Tools)
- IGameConfig *pGameConf;
- char sError[255];
- int offset;
- if (!gameconfs->LoadGameConfigFile("sdktools.games", &pGameConf, sError, sizeof(sError)))
- {
- snprintf(error, maxlength, "Failed to read sdktools.games gamedata: %s", sError);
- return false;
- }
- if (!pGameConf->GetOffset("AcceptInput", &offset))
- {
- snprintf(error, maxlength, "Failed to find AcceptInput offset.");
- return false;
- }
- SH_MANUALHOOK_RECONFIGURE(AcceptInput, offset, 0, 0);
- gameconfs->CloseGameConfigFile(pGameConf);
- // Prepare entity hooks. (from SDK Hooks)
- void *gEntList = gamehelpers->GetGlobalEntityList();
- if (!gEntList)
- {
- g_pSM->Format(error, maxlength, "Failed to find gEntList pointer.");
- return false;
- }
- g_hookEntCreated = SH_ADD_HOOK(CEntListHack, OnAddEntity, (CEntListHack *)gEntList, SH_MEMBER(this, &Sample::OnEntityCreated), true);
- g_hookEntRemoved = SH_ADD_HOOK(CEntListHack, OnRemoveEntity, (CEntListHack *)gEntList, SH_MEMBER(this, &Sample::OnEntityDeleted), false);
- return true;
- }
- void Sample::SDK_OnUnload()
- {
- // Unhook everything.
- SH_REMOVE_HOOK_ID(g_hookEntCreated);
- SH_REMOVE_HOOK_ID(g_hookEntRemoved);
- for (int i = 0; i < MAX_EDICTS; i++)
- {
- if (g_hookInput[i] != 0)
- {
- SH_REMOVE_HOOK_ID(g_hookInput[i]);
- }
- }
- }
- void Sample::OnEntityCreated(CBaseEntity *pEntity, CBaseHandle hndl)
- {
- int entity = hndl.GetEntryIndex();
- if (entity > playerhelpers->GetMaxClients() && entity < MAX_EDICTS)
- {
- const char *pName = gamehelpers->GetEntityClassname(pEntity);
- if (strcmp(pName, "point_servercommand") == 0 ||
- strcmp(pName, "point_clientcommand") == 0 ||
- strcmp(pName, "point_broadcastclientcommand") == 0)
- {
- g_hookInput[entity] = SH_ADD_MANUALHOOK(AcceptInput, pEntity, SH_MEMBER(this, &Sample::Hook_AcceptInput), false);
- }
- }
- }
- void Sample::OnEntityDeleted(CBaseEntity *pEntity, CBaseHandle hndl)
- {
- int entity = hndl.GetEntryIndex();
- if (entity > playerhelpers->GetMaxClients() && entity < MAX_EDICTS && g_hookInput[entity] != 0)
- {
- SH_REMOVE_HOOK_ID(g_hookInput[entity]);
- g_hookInput[entity] = 0;
- }
- }
- bool Sample::Hook_AcceptInput(const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, int outputID)
- {
- // We only care if a command is being sent.
- if (strcmp(szInputName, "Command") != 0)
- RETURN_META_VALUE(MRES_IGNORED, true);
- // Print command string to console and block.
- META_CONPRINTF("Value: %s\n", Value.String());
- RETURN_META_VALUE(MRES_SUPERCEDE, false);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement