void BaseProvider::Notify_DLLInit_Pre(CreateInterfaceFn engineFactory, CreateInterfaceFn serverFactory) { engine = (IVEngineServer *)((engineFactory)(INTERFACEVERSION_VENGINESERVER, NULL)); if (!engine) { DisplayError("Could not find IVEngineServer! Metamod cannot load."); return; } #if SOURCE_ENGINE >= SE_ORANGEBOX icvar = (ICvar *)((engineFactory)(CVAR_INTERFACE_VERSION, NULL)); #else icvar = (ICvar *)((engineFactory)(VENGINE_CVAR_INTERFACE_VERSION, NULL)); #endif if (!icvar) { DisplayError("Could not find ICvar! Metamod cannot load."); return; } if ((gameclients = (IServerGameClients *)(serverFactory("ServerGameClients003", NULL))) == NULL) { gameclients = (IServerGameClients *)(serverFactory("ServerGameClients004", NULL)); } baseFs = (IFileSystem *)((engineFactory)(FILESYSTEM_INTERFACE_VERSION, NULL)); if (baseFs == NULL) { mm_LogMessage("Unable to find \"%s\": .vdf files will not be parsed", FILESYSTEM_INTERFACE_VERSION); } #if SOURCE_ENGINE >= SE_ORANGEBOX g_pCVar = icvar; #endif g_SMConVarAccessor.RegisterConCommandBase(&meta_local_cmd); CacheUserMessages(); #if SOURCE_ENGINE == SE_DARKMESSIAH if (!g_SMConVarAccessor.InitConCommandBaseList()) { /* This is very unlikely considering it's old engine */ mm_LogMessage("[META] Warning: Failed to find ConCommandBase list!"); mm_LogMessage("[META] Warning: ConVars and ConCommands cannot be unregistered properly! Please file a bug report."); } #endif if (gameclients) { SH_ADD_HOOK_STATICFUNC(IServerGameClients, ClientCommand, gameclients, ClientCommand, 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 CoreConfig::OnSourceModLevelChange(const char *mapName) { static bool already_checked = false; if (!already_checked) { if (engine->IsDedicatedServer()) { g_ServerCfgFile = icvar->FindVar("servercfgfile"); } else { g_ServerCfgFile = icvar->FindVar("lservercfgfile"); } if (g_ServerCfgFile != NULL) { g_pExecPtr = FindCommand("exec"); if (g_pExecPtr != NULL) { SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPre, false); SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPost, true); } else { g_ServerCfgFile = NULL; } } already_checked = true; } g_bConfigsExecd = false; g_bServerExecd = false; g_bGotServerStart = false; g_bGotTrigger = false; }
void NextMapManager::OnSourceModAllInitialized_Post() { #if SOURCE_ENGINE >= SE_ORANGEBOX SH_ADD_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false); #else SH_ADD_HOOK_MEMFUNC(IVEngineServer, ChangeLevel, engine, this, &NextMapManager::HookChangeLevel, false); #endif ConCommand *pCmd = FindCommand("changelevel"); if (pCmd != NULL) { SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pCmd, CmdChangeLevelCallback, false); changeLevelCmd = pCmd; } }
void ConVarManager::OnSourceModAllInitialized() { /** * Episode 2 has this function by default, but the older versions do not. */ #if SOURCE_ENGINE == SE_EPISODEONE if (g_SMAPI->GetGameDLLVersion() >= 6) { SH_ADD_HOOK_MEMFUNC(IServerGameDLL, OnQueryCvarValueFinished, gamedll, this, &ConVarManager::OnQueryCvarValueFinished, false); m_bIsDLLQueryHooked = true; } #endif SH_ADD_HOOK_STATICFUNC(ICvar, CallGlobalChangeCallbacks, icvar, OnConVarChanged, false); g_PluginSys.AddPluginsListener(this); /* Add the 'convars' option to the 'sm' console command */ g_RootMenu.AddRootConsoleCommand("cvars", "View convars created by a plugin", this); }
virtual bool Load(const vsp_bridge_info *info, char *error, size_t maxlength) { if (!g_Metamod.IsLoadedAsGameDLL()) { vsp_desc.append(" "); vsp_desc.append(METAMOD_VERSION); CGlobalVars *pGlobals; IPlayerInfoManager *playerInfoManager; playerInfoManager = (IPlayerInfoManager *)info->gsFactory("PlayerInfoManager002", NULL); if (playerInfoManager == NULL) { UTIL_Format(error, maxlength, "Metamod:Source requires gameinfo.txt modification to load on this game"); return false; } pGlobals = playerInfoManager->GetGlobalVars(); char gamedll_iface[24]; for (unsigned int i = 3; i <= 50; i++) { UTIL_Format(gamedll_iface, sizeof(gamedll_iface), "ServerGameDLL%03d", i); if ((server = (IServerGameDLL *)info->gsFactory(gamedll_iface, NULL)) != NULL) { g_Metamod.SetGameDLLInfo((CreateInterfaceFn)info->gsFactory, i, false); break; } } if (server == NULL) { UTIL_Format(error, maxlength, "Metamod:Source could not load (GameDLL version not compatible)."); return false; } char gameclients_iface[] = "ServerGameClients000"; for (unsigned int i = 3; i <= 4; i++) { gameclients_iface[19] = '0' + i; if ((gameclients = (IServerGameClients *)info->gsFactory(gameclients_iface, NULL)) == NULL) break; } mm_InitializeGlobals((CreateInterfaceFn) info->engineFactory, (CreateInterfaceFn) info->engineFactory, (CreateInterfaceFn) info->engineFactory, pGlobals); if (!mm_DetectGameInformation()) { UTIL_Format(error, maxlength, "Metamod:Source failed to detect game paths; cannot load."); return false; } mm_InitializeForLoad(); g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version); mm_StartupMetamod(true); } else { vsp_desc.append(" Interface "); vsp_desc.append(METAMOD_VERSION); g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version); } #if SOURCE_ENGINE >= SE_ORANGEBOX g_plugin_unload = icvar->FindCommand("plugin_unload"); #else const ConCommandBase *pBase = icvar->GetCommands(); while (pBase != NULL) { if (pBase->IsCommand() && strcmp(pBase->GetName(), "plugin_unload") == 0) { g_plugin_unload = (ConCommand *)pBase; break; } pBase = pBase->GetNext(); } #endif if (g_plugin_unload != NULL) { SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads, false); SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_plugin_unload, InterceptPluginUnloads_Post, true); } return true; }