Syntax: Select all
#include "extension.h"
#include "CDetour/detours.h"
/**
* Globals
*/
ggfix g_Interface;
SMEXT_LINK(&g_Interface);
CGlobalVars *g_pGlobals;
void *g_pEntityFactoryDictAddr = NULL;
IGameConfig *g_pGameConf = NULL;
IServerGameEnts *gameents = NULL;
CDetour *UTIL_GetLocalPlayer_Detour = NULL;
DETOUR_DECL_MEMBER0(UTIL_GetLocalPlayer, CBaseEntity *)
{
for(int i=1;i<=g_pGlobals->maxClients;i++)
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex(i);
if(pPlayer) {
return pPlayer;
}
}
return NULL;
}
class BaseAccessor : public IConCommandBaseAccessor
{
public:
bool RegisterConCommandBase(ConCommandBase *pCommandBase)
{
return META_REGCVAR(pCommandBase);
}
} s_BaseAccessor;
bool ggfix::SDK_OnLoad(char *error, size_t maxlength, bool late)
{
#if SOURCE_ENGINE >= SE_ORANGEBOX
g_pCVar = icvar;
ConVar_Register(0, &s_BaseAccessor);
#else
ConCommandBaseMgr::OneTimeInit(&s_BaseAccessor);
#endif
char conf_error[255] = "";
if(!gameconfs->LoadGameConfigFile("ggfix", &g_pGameConf, conf_error, sizeof(conf_error)))
{
if(conf_error[0])
snprintf(error, maxlength, "Could not read ggfix.txt: %s", conf_error);
return false;
}
CDetourManager::Init(g_pSM->GetScriptingEngine(), g_pGameConf);
UTIL_GetLocalPlayer_Detour = DETOUR_CREATE_MEMBER(UTIL_GetLocalPlayer, "UTIL_GetLocalPlayer");
if (UTIL_GetLocalPlayer_Detour != NULL)
{
UTIL_GetLocalPlayer_Detour->EnableDetour();
}
else
{
return false;
}
return true;
}
void ggfix::SDK_OnAllLoaded()
{
}
void ggfix::SDK_OnUnload()
{
if (UTIL_GetLocalPlayer_Detour != NULL)
{
UTIL_GetLocalPlayer_Detour->Destroy();
UTIL_GetLocalPlayer_Detour = NULL;
}
gameconfs->CloseGameConfigFile(g_pGameConf);
}
bool ggfix::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
GET_V_IFACE_CURRENT(GetServerFactory, gameents, IServerGameEnts, INTERFACEVERSION_SERVERGAMEENTS);
g_pGlobals = ismm->GetCGlobals();
return true;
}
It seems like the engine thinks that the player is in single player (UTIL_GetLocalPlayer), and the only way to fix this is to force the engine to use UTIL_PlayerByIndex instead. How would I even begin to do this in SP?