IEntityFactoryDictionary *EntityFactoryDictionary() { if(g_entityFactoryDictionary) return g_entityFactoryDictionary; if ( g_nServerToolsVersion >= 2 ) { g_entityFactoryDictionary = servertools->GetEntityFactoryDictionary(); return g_entityFactoryDictionary; } #ifdef WIN32 ConCommandBase *pPtr = pAdminOP.GetCommands(); while (pPtr) { if (pPtr->IsCommand() && strcmp(pPtr->GetName(), "dumpentityfactories") == 0) { ConCommand *ptr = (ConCommand*)pPtr; //CEntityFactoryDictionary *dict = ( CEntityFactoryDictionary * )*(int *)( ((char*)VFuncs::GetCommandCallback(ptr))+0x14 ); CEntityFactoryDictionary *dict = VFuncs::GetEntityDictionary(ptr); if ( dict ) { g_entityFactoryDictionary = dict; return dict; } } pPtr = const_cast<ConCommandBase*>(pPtr->GetNext()); } #else g_entityFactoryDictionary = VFuncs::GetEntityDictionary(NULL); return g_entityFactoryDictionary; #endif return NULL; }
//Thanks to fysh for the idea of extracting info from "echo" and for // having the original offsets at hand! bool CSmmAPI::CacheCmds() { ICvar *pCvar = g_Engine.icvar; ConCommandBase *pBase = pCvar->GetCommands(); unsigned char *ptr = NULL; FnCommandCallback callback = NULL; int offs = 0; while (pBase) { if ( strcmp(pBase->GetName(), "echo") == 0 ) { //callback = //*((FnCommandCallback *)((char *)pBase + offsetof(ConCommand, m_fnCommandCallback))); callback = ((ConCommand *)pBase)->GetCallback(); ptr = (unsigned char *)callback; #ifdef OS_LINUX if (UTIL_VerifySignature(ptr, ENGINE486_SIG, SIGLEN)) { offs = ENGINE486_OFFS; } else if (UTIL_VerifySignature(ptr, ENGINE686_SIG, SIGLEN)) { offs = ENGINE686_OFFS; } else if (UTIL_VerifySignature(ptr, ENGINEAMD_SIG, SIGLEN)) { offs = ENGINEAMD_OFFS; } #elif defined OS_WIN32 // Only one Windows engine binary so far... if (UTIL_VerifySignature(ptr, ENGINEW32_SIG, SIGLEN)) { offs = ENGINEW32_OFFS; } #endif if (!offs || ptr[offs - 1] != IA32_CALL) { m_ConPrintf = (CONPRINTF_FUNC)Msg; return false; } //get the relative offset m_ConPrintf = *((CONPRINTF_FUNC *)(ptr + offs)); //add the base offset, to the ip (which is the address+offset + 4 bytes for next instruction) m_ConPrintf = (CONPRINTF_FUNC)((unsigned long)m_ConPrintf + (unsigned long)(ptr + offs) + 4); m_CmdCache = true; return true; } pBase = const_cast<ConCommandBase *>(pBase->GetNext()); } m_ConPrintf = (CONPRINTF_FUNC)Msg; return false; }
void CSourceMMMAP::HookConCommands() { //find the commands in the server's CVAR list #if defined (GAME_CSGO) pSayCmd = static_cast<ConCommand *>(g_pCVar->FindCommand("say")); pTeamSayCmd = static_cast<ConCommand *>(g_pCVar->FindCommand("say_team")); pChangeLevelCmd = static_cast<ConCommand *>(g_pCVar->FindCommand("changelevel")); pAutoBuyCmd = static_cast<ConCommand *>(g_pCVar->FindCommand("autobuy")); pReBuyCmd = static_cast<ConCommand *>(g_pCVar->FindCommand("rebuy")); pRespawnEntities = static_cast<ConCommand *>(g_pCVar->FindCommand("respawn_entities")); #else ConCommandBase *pCmd = g_pCVar->GetCommands(); while (pCmd) { if (pCmd->IsCommand()) { if (strcmp(pCmd->GetName(), "say") == 0) pSayCmd = static_cast<ConCommand *>(pCmd); else if (strcmp(pCmd->GetName(), "say_team") == 0) pTeamSayCmd = static_cast<ConCommand *>(pCmd); else if (strcmp(pCmd->GetName(), "changelevel") == 0) pChangeLevelCmd = static_cast<ConCommand *>(pCmd); else if (strcmp(pCmd->GetName(), "autobuy") == 0) pAutoBuyCmd = static_cast<ConCommand *>(pCmd); else if (strcmp(pCmd->GetName(), "rebuy") == 0) pReBuyCmd = static_cast<ConCommand *>(pCmd); else if (strcmp(pCmd->GetName(), "respawn_entities") == 0) pRespawnEntities = static_cast<ConCommand *>(pCmd); } pCmd = const_cast<ConCommandBase *>(pCmd->GetNext()); } #endif #if !defined GAME_ORANGE && defined SOURCEMM if (pSayCmd) SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pSayCmd, Say_handler, false); if (pRespawnEntities) SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pRespawnEntities, RespawnEntities_handler, false); if (pTeamSayCmd) SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pTeamSayCmd, TeamSay_handler, false); if (pChangeLevelCmd) SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pChangeLevelCmd, ChangeLevel_handler, false); if (pAutoBuyCmd) { SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pAutoBuyCmd, AutoBuy_handler, false); autobuy_cc = SH_GET_CALLCLASS(pAutoBuyCmd); } if (pReBuyCmd) { SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pReBuyCmd, ReBuy_handler, false); rebuy_cc = SH_GET_CALLCLASS(pReBuyCmd); } #else if (pSayCmd) SH_ADD_HOOK(ConCommand, Dispatch, pSayCmd, SH_STATIC(Say_handler), false); if (pRespawnEntities) SH_ADD_HOOK(ConCommand, Dispatch, pRespawnEntities, SH_STATIC(RespawnEntities_handler), false); if (pTeamSayCmd) SH_ADD_HOOK(ConCommand, Dispatch, pTeamSayCmd, SH_STATIC(TeamSay_handler), false); if (pChangeLevelCmd) SH_ADD_HOOK(ConCommand, Dispatch, pChangeLevelCmd, SH_STATIC(ChangeLevel_handler), false); if (pAutoBuyCmd) SH_ADD_HOOK(ConCommand, Dispatch, pAutoBuyCmd, SH_STATIC(AutoBuy_handler), false); if (pReBuyCmd) SH_ADD_HOOK(ConCommand, Dispatch, pReBuyCmd, SH_STATIC(ReBuy_handler), false); #endif }
void ChatTriggers::OnSourceModGameInitialized() { unsigned int total = 2; ConCommandBase *pCmd = icvar->GetCommands(); const char *name; while (pCmd) { if (pCmd->IsCommand()) { name = pCmd->GetName(); if (!m_pSayCmd && strcmp(name, "say") == 0) { m_pSayCmd = (ConCommand *)pCmd; if (--total == 0) { break; } } else if (!m_pSayTeamCmd && strcmp(name, "say_team") == 0) { m_pSayTeamCmd = (ConCommand *)pCmd; if (--total == 0) { break; } } } pCmd = const_cast<ConCommandBase *>(pCmd->GetNext()); } if (m_pSayCmd) { SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayCmd, this, &ChatTriggers::OnSayCommand_Pre, false); SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayCmd, this, &ChatTriggers::OnSayCommand_Post, true); } if (m_pSayTeamCmd) { SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayTeamCmd, this, &ChatTriggers::OnSayCommand_Pre, false); SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayTeamCmd, this, &ChatTriggers::OnSayCommand_Post, true); } }
void ManiSMMHooks::HookConCommands() { //find the commands in the server's CVAR list #if defined (GAME_CSGO) pSayCmd = static_cast<ConCommand *>(g_pCVar->FindCommand("say")); pTeamSayCmd = static_cast<ConCommand *>(g_pCVar->FindCommand("say_team")); pChangeLevelCmd = static_cast<ConCommand *>(g_pCVar->FindCommand("changelevel")); pAutoBuyCmd = static_cast<ConCommand *>(g_pCVar->FindCommand("autobuy")); pReBuyCmd = static_cast<ConCommand *>(g_pCVar->FindCommand("rebuy")); pRespawnEntities = static_cast<ConCommand *>(g_pCVar->FindCommand("respawn_entities")); #else ConCommandBase *pCmd = NULL; pCmd = g_pCVar->GetCommands(); while (pCmd) { if (pCmd->IsCommand()) { if (strcmp(pCmd->GetName(), "say") == 0) pSayCmd = static_cast<ConCommand *>(pCmd); else if (strcmp(pCmd->GetName(), "say_team") == 0) pTeamSayCmd = static_cast<ConCommand *>(pCmd); else if (strcmp(pCmd->GetName(), "changelevel") == 0) pChangeLevelCmd = static_cast<ConCommand *>(pCmd); else if (strcmp(pCmd->GetName(), "autobuy") == 0) pAutoBuyCmd = static_cast<ConCommand *>(pCmd); else if (strcmp(pCmd->GetName(), "rebuy") == 0) pReBuyCmd = static_cast<ConCommand *>(pCmd); else if (strcmp(pCmd->GetName(), "respawn_entities") == 0) pRespawnEntities = static_cast<ConCommand *>(pCmd); } pCmd = const_cast<ConCommandBase *>(pCmd->GetNext()); } #endif if (pSayCmd) SH_ADD_HOOK(ConCommand, Dispatch, pSayCmd, SH_STATIC(Say_handler), false); if (pRespawnEntities) SH_ADD_HOOK(ConCommand, Dispatch, pRespawnEntities, SH_STATIC(RespawnEntities_handler), false); if (pTeamSayCmd) SH_ADD_HOOK(ConCommand, Dispatch, pTeamSayCmd, SH_STATIC(TeamSay_handler), false); if (pChangeLevelCmd) SH_ADD_HOOK(ConCommand, Dispatch, pChangeLevelCmd, SH_STATIC(ChangeLevel_handler), false); if (pAutoBuyCmd) SH_ADD_HOOK(ConCommand, Dispatch, pAutoBuyCmd, SH_STATIC(AutoBuy_handler), false); if (pReBuyCmd) SH_ADD_HOOK(ConCommand, Dispatch, pReBuyCmd, SH_STATIC(ReBuy_handler), false); }
bool MyPlugin::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory) { serverGameDLL = (IServerGameDLL *)gameServerFactory(INTERFACEVERSION_SERVERGAMEDLL, NULL); if (serverGameDLL) { ServerClass *svrclass = serverGameDLL->GetAllServerClasses(); while (svrclass) { const char *classname = svrclass->GetName(); Msg("[%s]\n", classname); if (strcmp(classname, "CBasePlayer") == 0) { SendTable *st = svrclass->m_pTable; for (int i = 0; i < st->m_nProps; i++) { SendProp *sp = st->GetProp(i); const char *propname = sp->GetName(); Msg("Prop name: %s | Prop Offset: %d | Type: %d | IsSigned: %d\n", propname, sp->GetOffset(), sp->GetType(), sp->IsSigned()); if (strcmp(propname, "m_fFlags") == 0) { m_fFlags_off = sp->GetOffset(); continue; } if (strcmp(propname, "m_iHealth") == 0) { m_iHealth_off = sp->GetOffset(); continue; } } } if (strcmp(classname, "CBaseEntity") == 0) { SendTable *st = svrclass->m_pTable; for (int i = 0; i < st->m_nProps; i++) { SendProp *sp = st->GetProp(i); const char *propname = sp->GetName(); Msg("Prop name: %s | Prop Offset: %d | Type: %d | IsSigned: %d\n", propname, sp->GetOffset(), sp->GetType(), sp->IsSigned()); if (strcmp(propname, "m_iTeamNum") == 0) { m_iTeamNum_off = sp->GetOffset(); continue; } if (strcmp(propname, "m_iPendingTeamNum") == 0) { m_iPendingTeamNum_off = sp->GetOffset(); continue; } if (strcmp(propname, "m_fEffects") == 0) { m_fEffects_off = sp->GetOffset(); continue; } if (strcmp(propname, "m_nRenderMode") == 0) { m_nRenderMode_off = sp->GetOffset(); continue; } } } /*if (strcmp(classname, "CBaseCombatWeapon") == 0) { SendTable *st = svrclass->m_pTable; for (int i = 0; i < st->m_nProps; i++) { SendProp *sp = st->GetProp(i); const char *propname = sp->GetName(); Msg("Prop name: %s | Prop Offset: %d | Type: %d | IsSigned: %d\n", propname, sp->GetOffset(), sp->GetType(), sp->IsSigned()); } }*/ svrclass = svrclass->m_pNext; } } else { Warning("Unable to load IServerGameDLL.\n"); return false; } serverGameEnts = (IServerGameEnts *)gameServerFactory(INTERFACEVERSION_SERVERGAMEENTS, NULL); if (!serverGameEnts) { Warning("Unable to load IServerGameEnts.\n"); return false; } playerInfoManager = (IPlayerInfoManager *)gameServerFactory(INTERFACEVERSION_PLAYERINFOMANAGER, NULL); if (playerInfoManager) { globalVars = playerInfoManager->GetGlobalVars(); } else { Warning("Unable to load IPlayerInfoManager.\n"); return false; } g_pCVar = (ICvar *)interfaceFactory(CVAR_INTERFACE_VERSION, NULL); if (g_pCVar) { ICvar::Iterator iter(g_pCVar); for (iter.SetFirst(); iter.IsValid(); iter.Next()) { ConCommandBase *cmd = iter.Get(); if (cmd->IsCommand()) continue; const char *cmdname = cmd->GetName(); ConVar *cvar = (ConVar *)cmd; if (strcmp(cmdname, "net_maxcleartime") == 0) cvar->SetValue(0.001f); /*if (strcmp(cmdname, "net_minroutable") == 0) cvar->SetValue(1000);*/ } } else { Warning("Unable to load ICVar.\n"); return false; } gameEventManager2 = (IGameEventManager2 *)interfaceFactory(INTERFACEVERSION_GAMEEVENTSMANAGER2, NULL); if (!gameEventManager2) { Warning("Unable to load IGameEventManager2.\n"); return false; } vEngineServer = (IVEngineServer *)interfaceFactory(INTERFACEVERSION_VENGINESERVER, NULL); if (!vEngineServer) { Warning("Unable to load IVEngineServer.\n"); return false; } serverTools = (IServerTools *)gameServerFactory(VSERVERTOOLS_INTERFACE_VERSION, NULL); if (!serverTools) { Warning("Unable to load IServerTools.\n"); return false; } serverPluginHelpers = (IServerPluginHelpers *)interfaceFactory(INTERFACEVERSION_ISERVERPLUGINHELPERS, NULL); if (!serverPluginHelpers) { Warning("Unable to load IServerPluginHelpers.\n"); return false; } //playerDeathEvent = new PlayerDeathEvent(); //playerSayEvent = new PlayerSayEvent(); //playerConnectEvent = new PlayerConnectEvent(); //playerDisconnectEvent = new PlayerDisconnectEvent(); roundStartEvent = new RoundStartEvent(); //itemPickupEvent = new ItemPickupEvent(); //playerSpawnEvent = new PlayerSpawnEvent(); //playerSpawnedEvent = new PlayerSpawnedEvent(); //announphaseendevent = new AnnouncePhaseEndEvent(); return true; }
void FindConPrintf(void) { ConCommandBase *pBase = NULL; unsigned char *ptr = NULL; #ifdef GAME_ORANGE FnCommandCallback_t callback = NULL; #else FnCommandCallback callback = NULL; #endif int offs = 0; #if !defined ( GAME_CSGO ) pBase = g_pCVar->GetCommands(); while (pBase) { if ( strcmp(pBase->GetName(), "echo") == 0 ) { //callback = //*((FnCommandCallback *)((char *)pBase + offsetof(ConCommand, m_fnCommandCallback))); callback = ((ConCommand *)pBase)->m_fnCommandCallback; ptr = (unsigned char *)callback; if (vcmp(ptr, ENGINE486_SIG, SIGLEN)) { offs = ENGINE486_OFFS; } else if (vcmp(ptr, ENGINE686_SIG, SIGLEN)) { offs = ENGINE686_OFFS; } else if (vcmp(ptr, ENGINEAMD_SIG, SIGLEN)) { offs = ENGINEAMD_OFFS; } else if (vcmp(ptr, ENGINEW32_SIG, SIGLEN)) { offs = ENGINEW32_OFFS; } if (!offs || ptr[offs-1] != IA32_CALL) { return; } //get the relative offset MMsg = *((CONPRINTF_FUNC *)(ptr + offs)); //add the base offset, to the ip (which is the address+offset + 4 bytes for next instruction) MMsg = (CONPRINTF_FUNC)((unsigned long)MMsg + (unsigned long)(ptr + offs) + 4); Msg("Using conprintf\n"); return; } pBase = const_cast<ConCommandBase *>(pBase->GetNext()); } #else pBase = g_pCVar->FindCommand("echo"); callback = ((ConCommand *)pBase)->m_fnCommandCallback; ptr = (unsigned char *)callback; if (vcmp(ptr, ENGINE486_SIG, SIGLEN)) { offs = ENGINE486_OFFS; } else if (vcmp(ptr, ENGINE686_SIG, SIGLEN)) { offs = ENGINE686_OFFS; } else if (vcmp(ptr, ENGINEAMD_SIG, SIGLEN)) { offs = ENGINEAMD_OFFS; } else if (vcmp(ptr, ENGINEW32_SIG, SIGLEN)) { offs = ENGINEW32_OFFS; } if (!offs || ptr[offs-1] != IA32_CALL) { return; } //get the relative offset MMsg = *((CONPRINTF_FUNC *)(ptr + offs)); //add the base offset, to the ip (which is the address+offset + 4 bytes for next instruction) MMsg = (CONPRINTF_FUNC)((unsigned long)MMsg + (unsigned long)(ptr + offs) + 4); Msg("Using conprintf\n"); return; #endif Msg("Using Msg()\n"); MMsg = (CONPRINTF_FUNC)Msg; return; }