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; }
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 }
//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 SMConVarAccessor::Unregister(ConCommandBase *pCommand) { #if SOURCE_ENGINE >= SE_ORANGEBOX icvar->UnregisterConCommand(pCommand); #else ConCommandBase *pCur = NULL; ConCommandBase *pPrev = NULL; if (!pCommand) { return; } pCur = icvar->GetCommands(); if (!m_TopConCommandBase || !pCur) { return; } if (pCur == pCommand) { *m_TopConCommandBase = const_cast<ConCommandBase *>(pCommand->GetNext()); pCommand->SetNext(NULL); return; } pPrev = pCur; pCur = const_cast<ConCommandBase *>(pCur->GetNext()); while (pCur) { if (pCur == pCommand) { pPrev->SetNext(const_cast<ConCommandBase *>(pCommand->GetNext())); pCommand->SetNext(NULL); } pPrev = pCur; pCur = const_cast<ConCommandBase *>(pCur->GetNext()); } #endif }
void SMConVarAccessor::Unregister(ConCommandBase *pCommand) { ConCommandBase *pCur = NULL; ConCommandBase *pPrev = NULL; if (!pCommand || !pCommand->IsRegistered()) { return; } pCur = g_Engine.icvar->GetCommands(); pCommand->SetRegistered(false); if (!m_TopConCommandBase || !pCur) { return; } if (pCur == pCommand) { *m_TopConCommandBase = const_cast<ConCommandBase *>(pCommand->GetNext()); pCommand->SetNext(NULL); return; } pPrev = pCur; pCur = const_cast<ConCommandBase *>(pCur->GetNext()); while (pCur) { if (pCur == pCommand) { pPrev->SetNext(const_cast<ConCommandBase *>(pCommand->GetNext())); pCommand->SetNext(NULL); } pPrev = pCur; pCur = const_cast<ConCommandBase *>(pCur->GetNext()); } }
// // Name: CC_BalanceMacroReport( const CCommand& args ) // Author: Hekar Khani // Description: ConCommand to display a simple report of the current balance macros // Notes: // void CC_BalanceMacroReport( const CCommand& args ) { ConCommandBase *Command = cvar->GetCommands(); for ( ; Command != NULL; Command = Command->GetNext()) { ConVar *convar = dynamic_cast< ConVar * > ( Command ); if ( !convar ) { continue; } const char *convarname = convar->GetName(); if ( Q_strstr( convarname, "lfm" ) ) { Msg( "Name: %s\t\tValue: %s\t\tDesc: %s\n", convar->GetName(), convar->GetString(), convar->GetHelpText() ); } } }
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); }
// // Name: CC_BalanceMacroReport( const CCommand& args ) // Author: Hekar Khani // Description: ConCommand to display a report of the current balance macros in CSV format // Notes: // void CC_BalanceMacroReportCSV( const CCommand& args ) { // HODO: add ability to write to file ConCommandBase *Command = cvar->GetCommands(); for ( ; Command != NULL; Command = Command->GetNext()) { ConVar *convar = dynamic_cast< ConVar * > ( Command ); if ( !convar ) { continue; } Msg( "Convar, Value, Description\n" ); const char *convarname = convar->GetName(); if ( Q_strstr( convarname, "lfm" ) ) { Msg( "%s, %s, %s\n", convar->GetName(), convar->GetString(), convar->GetHelpText() ); } } }
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 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; }