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
36 IMetamodSourceProvider *provider = NULL;
38 SH_DECL_MANUALHOOK4(SGD_DLLInit, 0, 0, 0, bool, CreateInterfaceFn, CreateInterfaceFn, CreateInterfaceFn, CGlobalVars *);
39 SH_DECL_MANUALHOOK0(SGD_GameInit, 0, 0, 0, bool);
40 SH_DECL_MANUALHOOK6(SGD_LevelInit, 0, 0, 0, bool, const char *, const char *, const char *, const char *, bool, bool);
41 SH_DECL_MANUALHOOK0_void(SGD_LevelShutdown, 0, 0, 0);
42 SH_DECL_MANUALHOOK0_void(SGD_DLLShutdown, 0, 0, 0);
44 bool Handler_DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals);
45 bool Handler_DLLInit_Post(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals);
46 void Handler_DLLShutdown();
47 void Handler_LevelShutdown();
48 bool Handler_LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
49 bool Handler_GameInit();
55 CreateInterfaceFn factory;
58 SourceHook::CallClass<IServerGameDLL> *g_GameDllPatch;
62 bool parsed_game_info = false;
64 int gamedll_version = 0;
65 int engine_build = SOURCE_ENGINE_UNKNOWN;
66 List<game_dll_t *> gamedll_list;
67 bool is_gamedll_loaded = false;
68 bool in_first_level = true;
69 bool is_game_init = false;
70 bool vsp_load_attempted = false;
71 bool vsp_load_requested = false;
72 bool vsp_loaded = false;
73 game_dll_t gamedll_info;
74 ConVar *metamod_version = NULL;
75 ConVar *mm_pluginsfile = NULL;
76 IServerGameDLL *server = NULL;
77 CreateInterfaceFn engine_factory = NULL;
78 CreateInterfaceFn physics_factory = NULL;
79 CreateInterfaceFn filesystem_factory = NULL;
80 CGlobalVars *gpGlobals = NULL;
81 SourceHook::CSourceHookImpl g_SourceHook;
82 SourceHook::ISourceHook *g_SHPtr = &g_SourceHook;
83 PluginId g_PLID = Pl_Console;
84 META_RES last_meta_res;
86 MetamodSource g_Metamod;
88 void ClearGamedllList();
91 #define IFACE_MACRO(orig,nam) \
92 CPluginManager::CPlugin *pl; \
93 SourceHook::List<IMetamodListener *>::iterator event; \
94 IMetamodListener *api; \
97 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
99 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
101 mret = IFACE_FAILED; \
102 if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
103 if (ret) *ret = mret; \
108 return (orig)(iface, ret);
110 #define ITER_EVENT(evn, args) \
111 CPluginManager::CPlugin *pl; \
112 SourceHook::List<IMetamodListener *>::iterator event; \
113 IMetamodListener *api; \
114 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
116 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
122 /* Initialize everything here */
123 void InitMainStates()
125 char full_path[PATH_SIZE] = {0};
126 GetFileOfAddress((void *)gamedll_info.factory, full_path, sizeof(full_path));
127 full_bin_path.assign(full_path);
129 /* Like Metamod, reload plugins at the end of the map.
130 * This is so plugins can hook everything on load, BUT, new plugins will be reloaded
131 * if the server is shut down (silly, but rare case).
133 in_first_level = true;
135 SourceHook::MemFuncInfo info;
137 if (!provider->GetHookInfo(ProvidedHook_DLLInit, &info))
139 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::DLLInit");
141 SH_MANUALHOOK_RECONFIGURE(SGD_DLLInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
142 SH_ADD_MANUALHOOK_STATICFUNC(SGD_DLLInit, server, Handler_DLLInit, false);
143 SH_ADD_MANUALHOOK_STATICFUNC(SGD_DLLInit, server, Handler_DLLInit_Post, true);
145 if (!provider->GetHookInfo(ProvidedHook_GameInit, &info))
147 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::GameInit");
149 SH_MANUALHOOK_RECONFIGURE(SGD_GameInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
150 SH_ADD_MANUALHOOK_STATICFUNC(SGD_GameInit, server, Handler_GameInit, false);
152 if (!provider->GetHookInfo(ProvidedHook_LevelInit, &info))
154 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelInit");
156 SH_MANUALHOOK_RECONFIGURE(SGD_LevelInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
157 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelInit, server, Handler_LevelInit, true);
159 if (!provider->GetHookInfo(ProvidedHook_LevelShutdown, &info))
161 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelShutdown");
163 SH_MANUALHOOK_RECONFIGURE(SGD_LevelShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
164 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelShutdown, server, Handler_LevelShutdown, true);
166 if (!provider->GetHookInfo(ProvidedHook_DLLShutdown, &info))
168 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::DLLShutdown");
170 SH_MANUALHOOK_RECONFIGURE(SGD_DLLShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
171 SH_ADD_MANUALHOOK_STATICFUNC(SGD_DLLShutdown, server, Handler_DLLShutdown, false);
174 /* This is where the magic happens */
175 SMM_API void *CreateInterface(const char *iface, int *ret)
177 /* Prevent loading of self as a SourceMM plugin or Valve server plugin :x */
178 if (strcmp(iface, PLAPI_NAME) == 0)
180 provider->DisplayWarning("Do not try loading Metamod:Source as a plugin.\n");
190 if (strncmp(iface, "ISERVERPLUGINCALLBACKS", 22) == 0)
192 IServerPluginCallbacks *pCallbacks = provider->GetVSPCallbacks(iface);
194 if (pCallbacks && vsp_version == 0)
196 vsp_version = atoi(&iface[22]);
199 if (pCallbacks && ret)
201 *ret = pCallbacks ? IFACE_OK : IFACE_FAILED;
207 if (!parsed_game_info)
209 parsed_game_info = true;
210 const char *game_dir = NULL;
211 char game_path[PATH_SIZE];
212 char mm_path[PATH_SIZE];
214 /* Get path to SourceMM DLL */
215 if (!GetFileOfAddress((void *)CreateInterface, mm_path, sizeof(mm_path)))
217 provider->DisplayError("GetFileOfAddress() failed! Metamod cannot load.\n");
221 metamod_path.assign(mm_path);
223 /* Get value of -game from command line, defaulting to hl2 as engine seems to do */
224 game_dir = provider->GetCommandLineValue("-game", "hl2");
226 /* Get absolute path */
227 abspath(game_path, game_dir);
228 mod_path.assign(game_path);
230 char temp_path[PATH_SIZE];
232 /* Path to gameinfo.txt */
233 g_Metamod.PathFormat(temp_path, PATH_SIZE, "%s/%s", mod_path.c_str(), "gameinfo.txt");
235 FILE *fp = fopen(temp_path, "rt");
239 provider->DisplayError("Unable to open gameinfo.txt! Metamod cannot load.\n");
244 char key[128], val[128];
246 bool gamebin = false;
249 char cur_path[PATH_SIZE];
251 getcwd(cur_path, PATH_SIZE);
253 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
255 UTIL_TrimComments(buffer);
256 UTIL_TrimLeft(buffer);
257 UTIL_TrimRight(buffer);
259 if (stricmp(buffer, "SearchPaths") == 0)
269 UTIL_KeySplit(buffer, key, sizeof(key) - 1, val, sizeof(val) - 1);
270 if (stricmp(key, "Game") == 0 || stricmp(key, "GameBin") == 0)
272 if (stricmp(key, "Game") == 0)
281 if (strncmp(val, "|gameinfo_path|", sizeof("|gameinfo_path|") - 1) == 0)
283 ptr = &(val[sizeof("|gameinfo_path|") - 1]);
288 lptr = mod_path.c_str();
294 size_t ptr_len = strlen(ptr);
295 if (ptr[ptr_len] == '/' || ptr[ptr_len] == '\\')
297 ptr[--ptr_len] = '\0';
300 /* No need to append "bin" if key is GameBin */
303 g_Metamod.PathFormat(temp_path, PATH_SIZE, "%s/%s/%s", lptr, ptr, SERVER_DLL);
307 g_Metamod.PathFormat(temp_path, PATH_SIZE, "%s/%s/%s", lptr, "bin", SERVER_DLL);
311 g_Metamod.PathFormat(temp_path, PATH_SIZE, "%s/%s/%s/%s", lptr, ptr, "bin", SERVER_DLL);
314 /* If not path to SourceMM... */
315 if (!UTIL_PathCmp(mm_path, temp_path))
317 FILE *temp_fp = fopen(temp_path, "rb");
324 /* Search for a matching game dll */
325 List<game_dll_t *>::iterator iter;
328 for (iter = gamedll_list.begin(); iter != gamedll_list.end(); iter++)
331 if (GetFileOfAddress((void *)pCheck->factory, buffer, sizeof(buffer)))
333 if (UTIL_PathCmp(temp_path, buffer))
346 HINSTANCE gamedll = dlmount(temp_path);
352 CreateInterfaceFn fn = (CreateInterfaceFn)dlsym(gamedll, "CreateInterface");
359 game_dll_t *pInfo = new game_dll_t;
361 pInfo->lib = gamedll;
362 gamedll_list.push_back(pInfo);
370 if (!is_gamedll_loaded)
372 if (strncmp(iface, "ServerGameDLL", 13) == 0)
374 List<game_dll_t *>::iterator iter;
376 for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
379 if ((server = (IServerGameDLL *)((pInfo->factory)(iface, ret))) != NULL)
381 if ((gamedll_version = provider->TryServerGameDLL(iface)) != 0)
383 /* We have a match. Erase us from the list and save our info. */
384 gamedll_list.erase(iter);
385 gamedll_info = *pInfo;
387 is_gamedll_loaded = true;
390 /* :TODO: error otherwise? */
394 if (is_gamedll_loaded)
410 /* wtf do we do... */
411 /* :TODO: .. something a bit more intelligent? */
412 provider->DisplayError("Engine requested unknown interface before GameDLL was known!\n");
417 /* If we got here, there's definitely a GameDLL */
418 IFACE_MACRO(gamedll_info.factory, GameDLL);
421 void ClearGamedllList()
423 List<game_dll_t *>::iterator iter;
426 for (iter = gamedll_list.begin(); iter != gamedll_list.end(); iter++)
433 gamedll_list.clear();
436 int LoadPluginsFromFile(const char *_file)
439 int total = 0, skipped=0;
443 fp = fopen(_file, "rt");
446 LogMessage("[META] Could not open plugins file %s\n", _file);
450 char buffer[255], error[255], full_path[255];
451 const char *ptr, *ext, *file;
453 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
455 UTIL_TrimLeft(buffer);
456 UTIL_TrimRight(buffer);
458 length = strlen(buffer);
464 if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
470 if (buffer[0] == '"')
493 while (*cptr && isspace(*cptr))
498 UTIL_TrimRight(cptr);
499 if (*cptr && isalpha(*cptr))
501 g_PluginMngr.SetAlias(buffer, cptr);
513 /* First find if it's an absolute path or not... */
514 if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
516 /* If we're in an absolute path, ignore our normal heuristics */
517 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
518 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
520 LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
536 /* Attempt to find a file extension */
537 ptr = UTIL_GetExtension(file);
538 /* Add an extension if there's none there */
541 #if defined WIN32 || defined _WIN32
551 /* Format the new path */
552 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s%s", mod_path.c_str(), file, ext);
553 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
554 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
556 LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
575 LogMessage("[META] Loaded %d plugins from file (%d already loaded)", total, skipped);
579 LogMessage("[META] Loaded %d plugins from file.", total);
588 char engine_file[PATH_SIZE];
589 char engine_path[PATH_SIZE];
590 char rel_path[PATH_SIZE * 2];
592 GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
594 /* Chop off the "engine" file part */
595 len = strlen(engine_file);
596 for (size_t i = len - 1; i >= 0 && i < len; i--)
598 if (engine_file[i] == '/' || engine_file[i] == '\\')
600 engine_file[i] = '\0';
604 abspath(engine_path, engine_file);
606 const char *usepath = metamod_path.c_str();
607 if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
612 char command[PATH_SIZE * 2];
613 UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
614 provider->ServerCommand(command);
617 /* Wrapper function. This is called when the GameDLL thinks it's using
618 * the engine's real engineFactory.
620 void *EngineFactory(const char *iface, int *ret)
622 IFACE_MACRO(engine_factory, Engine);
625 /* Wrapper function. This is called when the GameDLL thinks it's using
626 * the engine's real physicsFactory.
628 void *PhysicsFactory(const char *iface, int *ret)
630 IFACE_MACRO(physics_factory, Physics);
633 /* Wrapper function. This is called when the GameDLL thinks it's using
634 * the engine's real fileSystemFactory.
636 void *FileSystemFactory(const char *iface, int *ret)
638 IFACE_MACRO(filesystem_factory, FileSystem);
641 void LogMessage(const char *msg, ...)
644 static char buffer[2048];
647 size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
650 buffer[len++] = '\n';
653 if (!provider->LogMessage(buffer))
655 fprintf(stdout, "%s", buffer);
659 bool Handler_DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals)
661 engine_factory = engineFactory;
662 filesystem_factory = filesystemFactory;
663 physics_factory = physicsFactory;
664 gpGlobals = pGlobals;
666 g_GameDllPatch = SH_GET_CALLCLASS(server);
668 provider->Notify_DLLInit_Pre();
670 metamod_version = provider->CreateConVar("metamod_version",
672 "Metamod:Source Version",
673 ConVarFlag_Notify|ConVarFlag_Replicated|ConVarFlag_SpOnly);
675 mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
676 #if defined WIN32 || defined _WIN32
677 "addons\\metamod\\metaplugins.ini",
679 "addons/metamod/metaplugins.ini",
681 "Metamod:Source Plugins File",
684 provider->CreateCommand("meta", Command_Meta, "Metamod:Source Menu");
685 provider->SetClientCommandHandler(Command_ClientMeta);
687 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
690 pluginFile = provider->GetConVarString(mm_pluginsfile);
694 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), pluginFile);
696 LoadPluginsFromFile(full_path);
698 in_first_level = true;
700 RETURN_META_VALUE(MRES_IGNORED, true);
703 bool Handler_GameInit()
710 if (vsp_load_requested)
717 RETURN_META_VALUE(MRES_IGNORED, true);
720 bool Handler_DLLInit_Post(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals)
722 g_PluginMngr.SetAllLoaded();
723 RETURN_META_VALUE(MRES_IGNORED, true);
726 void Handler_DLLShutdown()
729 g_PluginMngr.UnloadAll();
731 SH_CALL(g_GameDllPatch, &IServerGameDLL::DLLShutdown)();
733 SH_RELEASE_CALLCLASS(g_GameDllPatch);
734 g_GameDllPatch = NULL;
736 g_SourceHook.CompleteShutdown();
738 if (is_gamedll_loaded && gamedll_info.lib)
740 dlclose(gamedll_info.lib);
741 is_gamedll_loaded = false;
744 RETURN_META(MRES_SUPERCEDE);
747 void Handler_LevelShutdown(void)
752 g_Metamod.PathFormat(full_path,
756 provider->GetConVarString(mm_pluginsfile));
758 LoadPluginsFromFile(full_path);
762 in_first_level = false;
765 ITER_EVENT(OnLevelShutdown, ());
767 RETURN_META(MRES_IGNORED);
770 bool Handler_LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background)
772 ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
774 RETURN_META_VALUE(MRES_IGNORED, false);
777 void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
783 UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
786 LogMessage("[%s] %s", pl->GetLogTag(), buffer);
789 CreateInterfaceFn MetamodSource::engineFactory(bool syn/* =true */)
793 return EngineFactory;
796 return engine_factory;
799 CreateInterfaceFn MetamodSource::physicsFactory(bool syn/* =true */)
803 return PhysicsFactory;
806 return physics_factory;
809 CreateInterfaceFn MetamodSource::fileSystemFactory(bool syn/* =true */)
813 return FileSystemFactory;
816 return filesystem_factory;
819 CreateInterfaceFn MetamodSource::serverFactory(bool syn/* =true */)
823 return CreateInterface;
826 return gamedll_info.factory;
829 CGlobalVars *MetamodSource::pGlobals()
834 void MetamodSource::SetLastMetaReturn(META_RES res)
839 META_RES MetamodSource::GetLastMetaReturn()
841 return last_meta_res;
844 void MetamodSource::ConPrint(const char *str)
846 provider->ConsolePrint(str);
849 void MetamodSource::ConPrintf(const char *fmt, ...)
855 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
858 provider->ConsolePrint(buffer);
861 void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
863 major = SM_VERS_API_MAJOR;
864 minor = SM_VERS_API_MINOR;
865 plvers = PLAPI_VERSION;
866 plmin = PLAPI_MIN_VERSION;
869 void MetamodSource::GetShVersions(int &shvers, int &shimpl)
871 shvers = SH_IFACE_VERSION;
872 shimpl = SH_IMPL_VERSION;
875 int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
877 int length = (int)strlen(iface);
881 for (i = length - 1; i >= 0; i--)
883 if (!isdigit(iface[i]))
893 if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
900 num = atoi(&(iface[++i]));
905 snprintf(&(iface[i]), 4, "%03d", num);
910 void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
912 char _if[256]; /* assume no interface goes beyond this */
913 size_t len = strlen(iface);
922 if (len + 4 > sizeof(_if))
935 if ((pf = (fn)(_if, ret)) != NULL)
943 } while ((num = FormatIface(_if, len+1)));
948 void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
950 char buffer[256]; /* assume no interface will go beyond this */
951 size_t len = strlen(iface);
952 int ret; /* just in case something doesn't handle NULL properly */
954 if (len > sizeof(buffer) - 4)
959 strcpy(buffer, iface);
963 char *ptr = &buffer[len - 1];
965 while (isdigit(*ptr) && digits <=3)
973 /* for now, assume this is an error */
974 strcpy(buffer, iface);
979 min = (min == 0) ? 1 : min;
980 snprintf(num, sizeof(num), "%03d", min);
985 return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
988 const char *MetamodSource::GetBaseDir()
990 return mod_path.c_str();
993 void MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
997 size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
1000 for (size_t i = 0; i < mylen; i++)
1002 if (buffer[i] == ALT_SEP_CHAR)
1004 buffer[i] = PATH_SEP_CHAR;
1009 void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
1015 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
1018 provider->ClientConsolePrint(client, buffer);
1021 void MetamodSource::EnableVSPListener()
1023 if (is_game_init && !vsp_load_requested && !vsp_loaded)
1028 vsp_load_requested = true;
1031 int MetamodSource::GetVSPVersion()
1036 int MetamodSource::GetGameDLLVersion()
1038 return gamedll_version;
1041 bool MetamodSource::RemotePrintingAvailable()
1043 return provider->IsRemotePrintingAvailable();
1046 void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
1058 /* First check ours... we get first chance! */
1059 if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
1065 return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
1067 else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
1073 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
1076 CPluginManager::CPlugin *pl;
1077 List<IMetamodListener *>::iterator event;
1078 IMetamodListener *api;
1082 for (PluginIter iter = g_PluginMngr._begin();
1083 iter != g_PluginMngr._end();
1087 for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
1090 subret = IFACE_FAILED;
1091 if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
1108 *ret = IFACE_FAILED;
1114 void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
1116 CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
1118 pl->m_Events.push_back(pListener);
1121 const char *MetamodSource::GetGameBinaryPath()
1123 return full_bin_path.c_str();
1126 const char *MetamodSource::GetPluginsFile()
1128 return provider->GetConVarString(mm_pluginsfile);
1131 IConCommandBaseAccessor *MetamodSource::GetCvarBaseAccessor()
1133 return provider->GetConCommandBaseAccessor();
1136 bool MetamodSource::RegisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
1138 if (provider->IsConCommandBaseACommand(pCommand))
1140 g_PluginMngr.AddPluginCmd(plugin, pCommand);
1144 g_PluginMngr.AddPluginCvar(plugin, pCommand);
1147 return provider->RegisterConCommandBase(pCommand);
1150 void MetamodSource::UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
1152 if (provider->IsConCommandBaseACommand(pCommand))
1154 g_PluginMngr.AddPluginCmd(plugin, pCommand);
1158 g_PluginMngr.AddPluginCvar(plugin, pCommand);
1161 return provider->UnregisterConCommandBase(pCommand);
1164 int MetamodSource::GetUserMessageCount()
1166 return provider->GetUserMessageCount();
1169 int MetamodSource::FindUserMessage(const char *name, int *size/* =NULL */)
1171 return provider->FindUserMessage(name, size);
1174 const char *MetamodSource::GetUserMessage(int index, int *size/* =NULL */)
1176 return provider->GetUserMessage(index, size);
1179 int MetamodSource::GetSourceEngineBuild()
1181 return engine_build;