1 /* ======== SourceMM ========
2 * Copyright (C) 2004-2007 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): David "BAILOPAN" Anderson
8 * Contributor(s): Scott "Damaged Soul" Ehlert
9 * : Pavol "PM OnoTo" Marko
10 * ============================
17 #include <interface.h>
20 #include "metamod_provider.h"
21 #include "metamod_plugins.h"
22 #include "metamod_util.h"
23 #include "metamod_console.h"
29 using namespace SourceMM;
30 using namespace SourceHook;
33 * @brief Implementation of main SourceMM GameDLL functionality
37 SH_DECL_MANUALHOOK4(SGD_DLLInit, 0, 0, 0, bool, CreateInterfaceFn, CreateInterfaceFn, CreateInterfaceFn, CGlobalVars *);
38 SH_DECL_MANUALHOOK0(SGD_GameInit, 0, 0, 0, bool);
39 SH_DECL_MANUALHOOK6(SGD_LevelInit, 0, 0, 0, bool, const char *, const char *, const char *, const char *, bool, bool);
40 SH_DECL_MANUALHOOK0_void(SGD_LevelShutdown, 0, 0, 0);
41 SH_DECL_MANUALHOOK0_void(SGD_DLLShutdown, 0, 0, 0);
43 bool Handler_DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals);
44 bool Handler_DLLInit_Post(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals);
45 void Handler_DLLShutdown();
46 void Handler_LevelShutdown();
47 bool Handler_LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
48 bool Handler_GameInit();
54 CreateInterfaceFn factory;
57 SourceHook::CallClass<IServerGameDLL> *g_GameDllPatch;
61 bool parsed_game_info = false;
63 int gamedll_version = 0;
64 int engine_build = SOURCE_ENGINE_UNKNOWN;
65 List<game_dll_t *> gamedll_list;
66 bool is_gamedll_loaded = false;
67 bool in_first_level = true;
68 bool is_game_init = false;
69 bool vsp_load_attempted = false;
70 bool vsp_load_requested = false;
71 bool vsp_loaded = false;
72 game_dll_t gamedll_info;
73 ConVar *metamod_version = NULL;
74 ConVar *mm_pluginsfile = NULL;
75 IServerGameDLL *server = NULL;
76 CreateInterfaceFn engine_factory = NULL;
77 CreateInterfaceFn physics_factory = NULL;
78 CreateInterfaceFn filesystem_factory = NULL;
79 CGlobalVars *gpGlobals = NULL;
80 SourceHook::CSourceHookImpl g_SourceHook;
81 SourceHook::ISourceHook *g_SHPtr = &g_SourceHook;
82 PluginId g_PLID = Pl_Console;
83 META_RES last_meta_res;
85 MetamodSource g_Metamod;
87 void ClearGamedllList();
90 #define IFACE_MACRO(orig,nam) \
91 CPluginManager::CPlugin *pl; \
92 SourceHook::List<IMetamodListener *>::iterator event; \
93 IMetamodListener *api; \
96 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
98 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
100 mret = IFACE_FAILED; \
101 if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
102 if (ret) *ret = mret; \
107 return (orig)(iface, ret);
109 #define ITER_EVENT(evn, args) \
110 CPluginManager::CPlugin *pl; \
111 SourceHook::List<IMetamodListener *>::iterator event; \
112 IMetamodListener *api; \
113 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
115 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
121 /* Initialize everything here */
122 void InitMainStates()
124 char full_path[PATH_SIZE] = {0};
125 GetFileOfAddress((void *)gamedll_info.factory, full_path, sizeof(full_path));
126 full_bin_path.assign(full_path);
128 /* Like Metamod, reload plugins at the end of the map.
129 * This is so plugins can hook everything on load, BUT, new plugins will be reloaded
130 * if the server is shut down (silly, but rare case).
132 in_first_level = true;
134 SourceHook::MemFuncInfo info;
136 if (!provider->GetHookInfo(ProvidedHook_DLLInit, &info))
138 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::DLLInit");
140 SH_MANUALHOOK_RECONFIGURE(SGD_DLLInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
141 SH_ADD_MANUALHOOK_STATICFUNC(SGD_DLLInit, server, Handler_DLLInit, false);
142 SH_ADD_MANUALHOOK_STATICFUNC(SGD_DLLInit, server, Handler_DLLInit_Post, true);
144 if (!provider->GetHookInfo(ProvidedHook_GameInit, &info))
146 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::GameInit");
148 SH_MANUALHOOK_RECONFIGURE(SGD_GameInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
149 SH_ADD_MANUALHOOK_STATICFUNC(SGD_GameInit, server, Handler_GameInit, false);
151 if (!provider->GetHookInfo(ProvidedHook_LevelInit, &info))
153 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelInit");
155 SH_MANUALHOOK_RECONFIGURE(SGD_LevelInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
156 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelInit, server, Handler_LevelInit, true);
158 if (!provider->GetHookInfo(ProvidedHook_LevelShutdown, &info))
160 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelShutdown");
162 SH_MANUALHOOK_RECONFIGURE(SGD_LevelShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
163 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelShutdown, server, Handler_LevelShutdown, true);
165 if (!provider->GetHookInfo(ProvidedHook_DLLShutdown, &info))
167 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::DLLShutdown");
169 SH_MANUALHOOK_RECONFIGURE(SGD_DLLShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
170 SH_ADD_MANUALHOOK_STATICFUNC(SGD_DLLShutdown, server, Handler_DLLShutdown, false);
173 /* This is where the magic happens */
174 SMM_API void *CreateInterface(const char *iface, int *ret)
176 /* Prevent loading of self as a SourceMM plugin or Valve server plugin :x */
177 if (strcmp(iface, PLAPI_NAME) == 0)
179 provider->DisplayWarning("Do not try loading Metamod:Source as a plugin.\n");
189 if (strncmp(iface, "ISERVERPLUGINCALLBACKS", 22) == 0)
191 IServerPluginCallbacks *pCallbacks = provider->GetVSPCallbacks(iface);
193 if (pCallbacks && vsp_version == 0)
195 vsp_version = atoi(&iface[22]);
198 if (pCallbacks && ret)
200 *ret = pCallbacks ? IFACE_OK : IFACE_FAILED;
206 if (!parsed_game_info)
208 parsed_game_info = true;
209 const char *game_dir = NULL;
210 char game_path[PATH_SIZE];
211 char mm_path[PATH_SIZE];
213 /* Get path to SourceMM DLL */
214 if (!GetFileOfAddress((void *)CreateInterface, mm_path, sizeof(mm_path)))
216 provider->DisplayError("GetFileOfAddress() failed! Metamod cannot load.\n");
220 metamod_path.assign(mm_path);
222 /* Get value of -game from command line, defaulting to hl2 as engine seems to do */
223 game_dir = provider->GetCommandLineValue("-game", "hl2");
225 /* Get absolute path */
226 abspath(game_path, game_dir);
227 mod_path.assign(game_path);
229 char temp_path[PATH_SIZE];
231 /* Path to gameinfo.txt */
232 g_Metamod.PathFormat(temp_path, PATH_SIZE, "%s/%s", mod_path.c_str(), "gameinfo.txt");
234 FILE *fp = fopen(temp_path, "rt");
238 provider->DisplayError("Unable to open gameinfo.txt! Metamod cannot load.\n");
243 char key[128], val[128];
245 bool gamebin = false;
248 char cur_path[PATH_SIZE];
250 getcwd(cur_path, PATH_SIZE);
252 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
254 UTIL_TrimComments(buffer);
255 UTIL_TrimLeft(buffer);
256 UTIL_TrimRight(buffer);
258 if (stricmp(buffer, "SearchPaths") == 0)
268 UTIL_KeySplit(buffer, key, sizeof(key) - 1, val, sizeof(val) - 1);
269 if (stricmp(key, "Game") == 0 || stricmp(key, "GameBin") == 0)
271 if (stricmp(key, "Game") == 0)
280 if (strncmp(val, "|gameinfo_path|", sizeof("|gameinfo_path|") - 1) == 0)
282 ptr = &(val[sizeof("|gameinfo_path|") - 1]);
287 lptr = mod_path.c_str();
293 size_t ptr_len = strlen(ptr);
294 if (ptr[ptr_len] == '/' || ptr[ptr_len] == '\\')
296 ptr[--ptr_len] = '\0';
299 /* No need to append "bin" if key is GameBin */
302 g_Metamod.PathFormat(temp_path, PATH_SIZE, "%s/%s/%s", lptr, ptr, SERVER_DLL);
306 g_Metamod.PathFormat(temp_path, PATH_SIZE, "%s/%s/%s", lptr, "bin", SERVER_DLL);
310 g_Metamod.PathFormat(temp_path, PATH_SIZE, "%s/%s/%s/%s", lptr, ptr, "bin", SERVER_DLL);
313 /* If not path to SourceMM... */
314 if (!UTIL_PathCmp(mm_path, temp_path))
316 FILE *temp_fp = fopen(temp_path, "rb");
323 /* Search for a matching game dll */
324 List<game_dll_t *>::iterator iter;
327 for (iter = gamedll_list.begin(); iter != gamedll_list.end(); iter++)
330 if (GetFileOfAddress((void *)pCheck->factory, buffer, sizeof(buffer)))
332 if (UTIL_PathCmp(temp_path, buffer))
345 HINSTANCE gamedll = dlmount(temp_path);
351 CreateInterfaceFn fn = (CreateInterfaceFn)dlsym(gamedll, "CreateInterface");
358 game_dll_t *pInfo = new game_dll_t;
360 pInfo->lib = gamedll;
361 gamedll_list.push_back(pInfo);
369 if (!is_gamedll_loaded)
371 if (strncmp(iface, "ServerGameDLL", 13) == 0)
373 List<game_dll_t *>::iterator iter;
375 for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
378 if ((server = (IServerGameDLL *)((pInfo->factory)(iface, ret))) != NULL)
380 if ((gamedll_version = provider->TryServerGameDLL(iface)) != 0)
382 /* We have a match. Erase us from the list and save our info. */
383 gamedll_list.erase(iter);
384 gamedll_info = *pInfo;
386 is_gamedll_loaded = true;
389 /* :TODO: error otherwise? */
393 if (is_gamedll_loaded)
409 /* wtf do we do... */
410 /* :TODO: .. something a bit more intelligent? */
411 provider->DisplayError("Engine requested unknown interface before GameDLL was known!\n");
416 /* If we got here, there's definitely a GameDLL */
417 IFACE_MACRO(gamedll_info.factory, GameDLL);
420 void ClearGamedllList()
422 List<game_dll_t *>::iterator iter;
425 for (iter = gamedll_list.begin(); iter != gamedll_list.end(); iter++)
432 gamedll_list.clear();
435 int LoadPluginsFromFile(const char *_file)
438 int total = 0, skipped=0;
442 fp = fopen(_file, "rt");
445 LogMessage("[META] Could not open plugins file %s\n", _file);
449 char buffer[255], error[255], full_path[255];
450 const char *ptr, *ext, *file;
452 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
454 UTIL_TrimLeft(buffer);
455 UTIL_TrimRight(buffer);
457 length = strlen(buffer);
463 if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
469 if (buffer[0] == '"')
492 while (*cptr && isspace(*cptr))
497 UTIL_TrimRight(cptr);
498 if (*cptr && isalpha(*cptr))
500 g_PluginMngr.SetAlias(buffer, cptr);
512 /* First find if it's an absolute path or not... */
513 if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
515 /* If we're in an absolute path, ignore our normal heuristics */
516 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
517 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
519 LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
535 /* Attempt to find a file extension */
536 ptr = UTIL_GetExtension(file);
537 /* Add an extension if there's none there */
540 #if defined WIN32 || defined _WIN32
550 /* Format the new path */
551 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s%s", mod_path.c_str(), file, ext);
552 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
553 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
555 LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
574 LogMessage("[META] Loaded %d plugins from file (%d already loaded)", total, skipped);
578 LogMessage("[META] Loaded %d plugins from file.", total);
587 char engine_file[PATH_SIZE];
588 char engine_path[PATH_SIZE];
589 char rel_path[PATH_SIZE * 2];
591 GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
593 /* Chop off the "engine" file part */
594 len = strlen(engine_file);
595 for (size_t i = len - 1; i >= 0 && i < len; i--)
597 if (engine_file[i] == '/' || engine_file[i] == '\\')
599 engine_file[i] = '\0';
603 abspath(engine_path, engine_file);
605 const char *usepath = metamod_path.c_str();
606 if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
611 char command[PATH_SIZE * 2];
612 UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
613 provider->ServerCommand(command);
616 /* Wrapper function. This is called when the GameDLL thinks it's using
617 * the engine's real engineFactory.
619 void *EngineFactory(const char *iface, int *ret)
621 IFACE_MACRO(engine_factory, Engine);
624 /* Wrapper function. This is called when the GameDLL thinks it's using
625 * the engine's real physicsFactory.
627 void *PhysicsFactory(const char *iface, int *ret)
629 IFACE_MACRO(physics_factory, Physics);
632 /* Wrapper function. This is called when the GameDLL thinks it's using
633 * the engine's real fileSystemFactory.
635 void *FileSystemFactory(const char *iface, int *ret)
637 IFACE_MACRO(filesystem_factory, FileSystem);
640 void LogMessage(const char *msg, ...)
643 static char buffer[2048];
646 size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
649 buffer[len++] = '\n';
652 if (!provider->LogMessage(buffer))
654 fprintf(stdout, "%s", buffer);
658 bool Handler_DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals)
660 engine_factory = engineFactory;
661 filesystem_factory = filesystemFactory;
662 physics_factory = physicsFactory;
663 gpGlobals = pGlobals;
665 g_GameDllPatch = SH_GET_CALLCLASS(server);
667 provider->Notify_DLLInit_Pre(server, engineFactory, gamedll_info.factory);
669 metamod_version = provider->CreateConVar("metamod_version",
671 "Metamod:Source Version",
672 ConVarFlag_Notify|ConVarFlag_Replicated|ConVarFlag_SpOnly);
674 mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
675 #if defined WIN32 || defined _WIN32
676 "addons\\metamod\\metaplugins.ini",
678 "addons/metamod/metaplugins.ini",
680 "Metamod:Source Plugins File",
683 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
686 pluginFile = provider->GetConVarString(mm_pluginsfile);
690 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), pluginFile);
692 LoadPluginsFromFile(full_path);
694 in_first_level = true;
696 RETURN_META_VALUE(MRES_IGNORED, true);
699 bool Handler_GameInit()
706 if (vsp_load_requested)
713 RETURN_META_VALUE(MRES_IGNORED, true);
716 bool Handler_DLLInit_Post(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals)
718 g_PluginMngr.SetAllLoaded();
719 RETURN_META_VALUE(MRES_IGNORED, true);
722 void Handler_DLLShutdown()
725 g_PluginMngr.UnloadAll();
727 SH_CALL(g_GameDllPatch, &IServerGameDLL::DLLShutdown)();
729 SH_RELEASE_CALLCLASS(g_GameDllPatch);
730 g_GameDllPatch = NULL;
732 g_SourceHook.CompleteShutdown();
734 if (is_gamedll_loaded && gamedll_info.lib)
736 dlclose(gamedll_info.lib);
737 is_gamedll_loaded = false;
740 RETURN_META(MRES_SUPERCEDE);
743 void Handler_LevelShutdown(void)
748 g_Metamod.PathFormat(full_path,
752 provider->GetConVarString(mm_pluginsfile));
754 LoadPluginsFromFile(full_path);
758 in_first_level = false;
761 ITER_EVENT(OnLevelShutdown, ());
763 RETURN_META(MRES_IGNORED);
766 bool Handler_LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background)
768 ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
770 RETURN_META_VALUE(MRES_IGNORED, false);
773 void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
779 UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
782 LogMessage("[%s] %s", pl->GetLogTag(), buffer);
785 CreateInterfaceFn MetamodSource::engineFactory(bool syn/* =true */)
789 return EngineFactory;
792 return engine_factory;
795 CreateInterfaceFn MetamodSource::physicsFactory(bool syn/* =true */)
799 return PhysicsFactory;
802 return physics_factory;
805 CreateInterfaceFn MetamodSource::fileSystemFactory(bool syn/* =true */)
809 return FileSystemFactory;
812 return filesystem_factory;
815 CreateInterfaceFn MetamodSource::serverFactory(bool syn/* =true */)
819 return CreateInterface;
822 return gamedll_info.factory;
825 CGlobalVars *MetamodSource::pGlobals()
830 void MetamodSource::SetLastMetaReturn(META_RES res)
835 META_RES MetamodSource::GetLastMetaReturn()
837 return last_meta_res;
840 void MetamodSource::ConPrint(const char *str)
842 provider->ConsolePrint(str);
845 void MetamodSource::ConPrintf(const char *fmt, ...)
851 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
854 provider->ConsolePrint(buffer);
857 void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
859 major = SM_VERS_API_MAJOR;
860 minor = SM_VERS_API_MINOR;
861 plvers = PLAPI_VERSION;
862 plmin = PLAPI_MIN_VERSION;
865 void MetamodSource::GetShVersions(int &shvers, int &shimpl)
867 shvers = SH_IFACE_VERSION;
868 shimpl = SH_IMPL_VERSION;
871 int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
873 int length = (int)strlen(iface);
877 for (i = length - 1; i >= 0; i--)
879 if (!isdigit(iface[i]))
889 if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
896 num = atoi(&(iface[++i]));
901 snprintf(&(iface[i]), 4, "%03d", num);
906 void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
908 char _if[256]; /* assume no interface goes beyond this */
909 size_t len = strlen(iface);
918 if (len + 4 > sizeof(_if))
931 if ((pf = (fn)(_if, ret)) != NULL)
939 } while ((num = FormatIface(_if, len+1)));
944 void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
946 char buffer[256]; /* assume no interface will go beyond this */
947 size_t len = strlen(iface);
948 int ret; /* just in case something doesn't handle NULL properly */
950 if (len > sizeof(buffer) - 4)
955 strcpy(buffer, iface);
959 char *ptr = &buffer[len - 1];
961 while (isdigit(*ptr) && digits <=3)
969 /* for now, assume this is an error */
970 strcpy(buffer, iface);
975 min = (min == 0) ? 1 : min;
976 snprintf(num, sizeof(num), "%03d", min);
981 return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
984 const char *MetamodSource::GetBaseDir()
986 return mod_path.c_str();
989 void MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
993 size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
996 for (size_t i = 0; i < mylen; i++)
998 if (buffer[i] == ALT_SEP_CHAR)
1000 buffer[i] = PATH_SEP_CHAR;
1005 void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
1011 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
1014 provider->ClientConsolePrint(client, buffer);
1017 void MetamodSource::EnableVSPListener()
1019 if (is_game_init && !vsp_load_requested && !vsp_loaded)
1024 vsp_load_requested = true;
1027 int MetamodSource::GetVSPVersion()
1032 int MetamodSource::GetGameDLLVersion()
1034 return gamedll_version;
1037 bool MetamodSource::RemotePrintingAvailable()
1039 return provider->IsRemotePrintingAvailable();
1042 void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
1054 /* First check ours... we get first chance! */
1055 if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
1061 return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
1063 else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
1069 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
1072 CPluginManager::CPlugin *pl;
1073 List<IMetamodListener *>::iterator event;
1074 IMetamodListener *api;
1078 for (PluginIter iter = g_PluginMngr._begin();
1079 iter != g_PluginMngr._end();
1083 for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
1086 subret = IFACE_FAILED;
1087 if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
1104 *ret = IFACE_FAILED;
1110 void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
1112 CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
1114 pl->m_Events.push_back(pListener);
1117 const char *MetamodSource::GetGameBinaryPath()
1119 return full_bin_path.c_str();
1122 const char *MetamodSource::GetPluginsFile()
1124 return provider->GetConVarString(mm_pluginsfile);
1127 IConCommandBaseAccessor *MetamodSource::GetCvarBaseAccessor()
1129 return provider->GetConCommandBaseAccessor();
1132 bool MetamodSource::RegisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
1134 if (provider->IsConCommandBaseACommand(pCommand))
1136 g_PluginMngr.AddPluginCmd(plugin, pCommand);
1140 g_PluginMngr.AddPluginCvar(plugin, pCommand);
1143 return provider->RegisterConCommandBase(pCommand);
1146 void MetamodSource::UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
1148 if (provider->IsConCommandBaseACommand(pCommand))
1150 g_PluginMngr.RemovePluginCmd(plugin, pCommand);
1154 g_PluginMngr.RemovePluginCvar(plugin, pCommand);
1157 CPluginManager::CPlugin *pOrig = g_PluginMngr.FindByAPI(plugin);
1158 UnregisterConCommandBase(pOrig ? pOrig->m_Id : 0, pCommand);
1161 void MetamodSource::UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand)
1164 CPluginManager::CPlugin *pPlugin;
1165 List<IMetamodListener *>::iterator event;
1166 IMetamodListener *pML;
1167 for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
1170 if (pPlugin->m_Status < Pl_Paused)
1174 /* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
1175 if (pPlugin->m_API->GetApiVersion() < 12)
1179 for (event=pPlugin->m_Events.begin();
1180 event!=pPlugin->m_Events.end();
1184 pML->OnUnlinkConCommandBase(id, pCommand);
1188 return provider->UnregisterConCommandBase(pCommand);
1191 int MetamodSource::GetUserMessageCount()
1193 return provider->GetUserMessageCount();
1196 int MetamodSource::FindUserMessage(const char *name, int *size/* =NULL */)
1198 return provider->FindUserMessage(name, size);
1201 const char *MetamodSource::GetUserMessage(int index, int *size/* =NULL */)
1203 return provider->GetUserMessage(index, size);
1206 int MetamodSource::GetSourceEngineBuild()
1208 return engine_build;