Fixed core GameDLL loading not having a VSP listener.
3 * ======================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC and authors.
7 * ======================================================
9 * This software is provided 'as-is', without any express or implied warranty.
10 * In no event will the authors be held liable for any damages arising from
11 * the use of this software.
13 * Permission is granted to anyone to use this software for any purpose,
14 * including commercial applications, and to alter it and redistribute it
15 * freely, subject to the following restrictions:
17 * 1. The origin of this software must not be misrepresented; you must not
18 * claim that you wrote the original software. If you use this software in a
19 * product, an acknowledgment in the product documentation would be
20 * appreciated but is not required.
21 * 2. Altered source versions must be plainly marked as such, and must not be
22 * misrepresented as being the original software.
23 * 3. This notice may not be removed or altered from any source distribution.
29 #include "metamod_oslink.h"
31 #include <interface.h>
33 #include "metamod_provider.h"
34 #include "metamod_plugins.h"
35 #include "metamod_util.h"
36 #include "metamod_console.h"
37 #include "provider/provider_ep2.h"
39 using namespace SourceMM;
40 using namespace SourceHook;
41 using namespace SourceHook::Impl;
44 * @brief Implementation of main SourceMM GameDLL functionality
48 SH_DECL_MANUALHOOK0(SGD_GameInit, 0, 0, 0, bool);
49 SH_DECL_MANUALHOOK6(SGD_LevelInit, 0, 0, 0, bool, const char *, const char *, const char *, const char *, bool, bool);
50 SH_DECL_MANUALHOOK0_void(SGD_LevelShutdown, 0, 0, 0);
53 Handler_LevelShutdown();
56 Handler_LevelInit(char const *pMapName,
57 char const *pMapEntities,
58 char const *pOldLevel,
59 char const *pLandmarkName,
70 LookForVDFs(const char *dir);
74 CreateInterfaceFn factory;
77 static String mod_path;
78 static String metamod_path;
79 static String full_bin_path;
80 static int vsp_version = 0;
81 static int gamedll_version = 0;
82 static int engine_build = SOURCE_ENGINE_UNKNOWN;
83 static List<game_dll_t *> gamedll_list;
84 static bool is_gamedll_loaded = false;
85 static bool in_first_level = true;
86 static bool is_game_init = false;
87 static bool vsp_load_requested = false;
88 static bool vsp_loaded = false;
89 static game_dll_t gamedll_info;
90 static ConVar *metamod_version = NULL;
91 static ConVar *mm_pluginsfile = NULL;
92 static ConVar *mm_basedir = NULL;
93 static CreateInterfaceFn engine_factory = NULL;
94 static CreateInterfaceFn physics_factory = NULL;
95 static CreateInterfaceFn filesystem_factory = NULL;
96 static CGlobalVars *gpGlobals = NULL;
97 static CHookManagerAutoGen g_SH_HookManagerAutoGen(&g_SourceHook);
98 static META_RES last_meta_res;
99 static IServerPluginCallbacks *vsp_callbacks = NULL;
100 static bool were_plugins_loaded = false;
101 static bool g_bIsVspBridged = false;
103 MetamodSource g_Metamod;
104 PluginId g_PLID = Pl_Console;
105 CSourceHookImpl g_SourceHook;
106 ISourceHook *g_SHPtr = &g_SourceHook;
107 SourceMM::ISmmAPI *g_pMetamod = &g_Metamod;
110 #define IFACE_MACRO(orig,nam) \
111 CPluginManager::CPlugin *pl; \
112 SourceHook::List<IMetamodListener *>::iterator event; \
113 IMetamodListener *api; \
116 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
118 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
120 mret = IFACE_FAILED; \
121 if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
122 if (ret) *ret = mret; \
127 return (orig)(iface, ret);
129 #define ITER_EVENT(evn, args) \
130 CPluginManager::CPlugin *pl; \
131 SourceHook::List<IMetamodListener *>::iterator event; \
132 IMetamodListener *api; \
133 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
135 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
142 mm_SetVspInfo(IServerPluginCallbacks *ispc, unsigned int version)
144 vsp_version = version;
147 /* Initialize everything here */
149 mm_InitializeForLoad()
151 char full_path[PATH_SIZE] = {0};
152 GetFileOfAddress((void *)gamedll_info.factory, full_path, sizeof(full_path));
153 full_bin_path.assign(full_path);
155 /* Like Metamod, reload plugins at the end of the map.
156 * This is so plugins can hook everything on load, BUT, new plugins will be reloaded
157 * if the server is shut down (silly, but rare case).
159 in_first_level = true;
161 SourceHook::MemFuncInfo info;
163 if (!provider->GetHookInfo(ProvidedHook_GameInit, &info))
165 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::GameInit");
167 SH_MANUALHOOK_RECONFIGURE(SGD_GameInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
168 SH_ADD_MANUALHOOK_STATICFUNC(SGD_GameInit, server, Handler_GameInit, false);
170 if (!provider->GetHookInfo(ProvidedHook_LevelInit, &info))
172 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelInit");
174 SH_MANUALHOOK_RECONFIGURE(SGD_LevelInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
175 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelInit, server, Handler_LevelInit, true);
177 if (!provider->GetHookInfo(ProvidedHook_LevelShutdown, &info))
179 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelShutdown");
181 SH_MANUALHOOK_RECONFIGURE(SGD_LevelShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
182 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelShutdown, server, Handler_LevelShutdown, true);
186 mm_DetectGameInformation()
188 char mm_path[PATH_SIZE];
189 char game_path[PATH_SIZE];
191 /* Get path to SourceMM DLL */
192 if (!GetFileOfAddress((void *)mm_InitializeForLoad, mm_path, sizeof(mm_path)))
197 metamod_path.assign(mm_path);
199 /* Get value of -game from command line, defaulting to hl2 as engine seems to do */
200 const char *game_dir = provider->GetCommandLineValue("-game", "hl2");
202 /* Get absolute path */
203 abspath(game_path, game_dir);
204 mod_path.assign(game_path);
206 engine_build = provider->DetermineSourceEngine(game_dir);;
212 ServerFactory(const char *iface, int *ret)
214 IFACE_MACRO(gamedll_info.factory, GameDLL);
218 CreateInterface(const char *iface, int *ret)
222 if (!mm_IsVspBridged() && strncmp(iface, "ISERVERPLUGINCALLBACKS", 22) == 0)
224 if (vsp_callbacks != NULL)
231 vsp_version = atoi(&iface[22]);
232 ptr = provider->GetVSPCallbacks(vsp_version);
241 *ret = (ptr != NULL) ? IFACE_OK : IFACE_FAILED;
247 mm_LoadPluginsFromFile(const char *_file)
250 int total = 0, skipped=0;
254 fp = fopen(_file, "rt");
257 mm_LogMessage("[META] Could not open plugins file %s\n", _file);
261 char buffer[255], error[255], full_path[255];
262 const char *ptr, *ext, *file;
264 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
266 UTIL_TrimLeft(buffer);
267 UTIL_TrimRight(buffer);
269 length = strlen(buffer);
275 if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
281 if (buffer[0] == '"')
304 while (*cptr && isspace(*cptr))
309 UTIL_TrimRight(cptr);
310 if (*cptr && isalpha(*cptr))
312 g_PluginMngr.SetAlias(buffer, cptr);
324 /* First find if it's an absolute path or not... */
325 if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
327 /* If we're in an absolute path, ignore our normal heuristics */
328 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
329 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
331 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
343 /* Attempt to find a file extension */
344 ptr = UTIL_GetExtension(file);
345 /* Add an extension if there's none there */
348 #if defined WIN32 || defined _WIN32
358 /* Format the new path */
359 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s%s", mod_path.c_str(), file, ext);
360 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
361 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
363 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
377 mm_LogMessage("[META] Loaded %d plugins from file (%d already loaded)", total, skipped);
379 mm_LogMessage("[META] Loaded %d plugins from file.", total);
390 char engine_file[PATH_SIZE];
391 char engine_path[PATH_SIZE];
392 char rel_path[PATH_SIZE * 2];
394 GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
396 /* Chop off the "engine" file part */
397 len = strlen(engine_file);
398 for (size_t i = len - 1; i >= 0 && i < len; i--)
400 if (engine_file[i] == '/' || engine_file[i] == '\\')
402 engine_file[i] = '\0';
406 abspath(engine_path, engine_file);
408 const char *usepath = metamod_path.c_str();
409 if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
414 char command[PATH_SIZE * 2];
415 UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
416 provider->ServerCommand(command);
419 /* Wrapper function. This is called when the GameDLL thinks it's using
420 * the engine's real engineFactory.
423 EngineFactory(const char *iface, int *ret)
425 IFACE_MACRO(engine_factory, Engine);
428 /* Wrapper function. This is called when the GameDLL thinks it's using
429 * the engine's real physicsFactory.
432 PhysicsFactory(const char *iface, int *ret)
434 IFACE_MACRO(physics_factory, Physics);
437 /* Wrapper function. This is called when the GameDLL thinks it's using
438 * the engine's real fileSystemFactory.
441 FileSystemFactory(const char *iface, int *ret)
443 IFACE_MACRO(filesystem_factory, FileSystem);
447 mm_LogMessage(const char *msg, ...)
450 static char buffer[2048];
453 size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
456 buffer[len++] = '\n';
459 if (!provider->LogMessage(buffer))
461 fprintf(stdout, "%s", buffer);
466 DoInitialPluginLoads()
468 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
469 const char *mmBaseDir = provider->GetCommandLineValue("mm_basedir", NULL);
472 pluginFile = provider->GetConVarString(mm_pluginsfile);
473 if (pluginFile == NULL)
475 pluginFile = "addons/metamod/metaplugins.ini";
480 mmBaseDir = provider->GetConVarString(mm_basedir);
481 if (mmBaseDir == NULL)
483 mmBaseDir = "addons/metamod";
489 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), pluginFile);
490 mm_LoadPluginsFromFile(full_path);
492 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), mmBaseDir);
493 LookForVDFs(full_path);
497 mm_StartupMetamod(bool is_vsp_load)
505 is_vsp_load ? "V" : "");
507 metamod_version = provider->CreateConVar("metamod_version",
509 "Metamod:Source Version",
510 ConVarFlag_Notify|ConVarFlag_SpOnly);
512 provider->SetConVarString(metamod_version, buffer);
514 mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
515 #if defined WIN32 || defined _WIN32
516 "addons\\metamod\\metaplugins.ini",
518 "addons/metamod/metaplugins.ini",
520 "Metamod:Source Plugins File",
523 mm_basedir = provider->CreateConVar("mm_basedir",
524 #if defined __linux__
529 "Metamod:Source Base Folder",
532 g_bIsVspBridged = is_vsp_load;
536 DoInitialPluginLoads();
537 in_first_level = true;
542 mm_InitializeGlobals(CreateInterfaceFn engineFactory,
543 CreateInterfaceFn physicsFactory,
544 CreateInterfaceFn filesystemFactory,
545 CGlobalVars *pGlobals)
547 engine_factory = engineFactory;
548 physics_factory = physicsFactory;
549 filesystem_factory = filesystemFactory;
550 gpGlobals = pGlobals;
551 provider->Notify_DLLInit_Pre(engineFactory, gamedll_info.factory);
560 if (vsp_load_requested)
563 if (g_bIsVspBridged && !were_plugins_loaded)
565 DoInitialPluginLoads();
566 g_PluginMngr.SetAllLoaded();
567 were_plugins_loaded = true;
572 RETURN_META_VALUE(MRES_IGNORED, true);
579 g_PluginMngr.UnloadAll();
581 provider->Notify_DLLShutdown_Pre();
583 g_SourceHook.CompleteShutdown();
587 Handler_LevelShutdown(void)
589 if (g_bIsVspBridged && !were_plugins_loaded)
591 g_PluginMngr.SetAllLoaded();
592 DoInitialPluginLoads();
593 were_plugins_loaded = true;
594 in_first_level = true;
601 g_Metamod.PathFormat(full_path,
605 provider->GetConVarString(mm_pluginsfile));
606 mm_LoadPluginsFromFile(full_path);
608 g_Metamod.PathFormat(full_path,
612 provider->GetConVarString(mm_basedir));
613 LookForVDFs(full_path);
617 in_first_level = false;
620 ITER_EVENT(OnLevelShutdown, ());
622 RETURN_META(MRES_IGNORED);
626 Handler_LevelInit(char const *pMapName,
627 char const *pMapEntities,
628 char const *pOldLevel,
629 char const *pLandmarkName,
633 ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
635 RETURN_META_VALUE(MRES_IGNORED, false);
638 void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
644 UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
647 mm_LogMessage("[%s] %s", pl->GetLogTag(), buffer);
650 CreateInterfaceFn MetamodSource::GetEngineFactory(bool syn/* =true */)
653 return EngineFactory;
654 return engine_factory;
657 CreateInterfaceFn MetamodSource::GetPhysicsFactory(bool syn/* =true */)
660 return PhysicsFactory;
661 return physics_factory;
664 CreateInterfaceFn MetamodSource::GetFileSystemFactory(bool syn/* =true */)
667 return FileSystemFactory;
668 return filesystem_factory;
671 CreateInterfaceFn MetamodSource::GetServerFactory(bool syn/* =true */)
674 return ServerFactory;
675 return gamedll_info.factory;
678 CGlobalVars *MetamodSource::GetCGlobals()
683 void MetamodSource::SetLastMetaReturn(META_RES res)
688 META_RES MetamodSource::GetLastMetaReturn()
690 return last_meta_res;
693 void MetamodSource::ConPrint(const char *str)
695 provider->ConsolePrint(str);
698 void MetamodSource::ConPrintf(const char *fmt, ...)
704 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
707 provider->ConsolePrint(buffer);
710 void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
712 major = METAMOD_API_MAJOR;
713 minor = METAMOD_API_MINOR;
714 plvers = METAMOD_PLAPI_VERSION;
715 plmin = PLAPI_MIN_VERSION;
718 void MetamodSource::GetShVersions(int &shvers, int &shimpl)
720 shvers = SH_IFACE_VERSION;
721 shimpl = SH_IMPL_VERSION;
724 int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
726 int length = (int)strlen(iface);
730 for (i = length - 1; i >= 0; i--)
732 if (!isdigit(iface[i]))
742 if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
749 num = atoi(&(iface[++i]));
754 snprintf(&(iface[i]), 4, "%03d", num);
759 void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
761 char _if[256]; /* assume no interface goes beyond this */
762 size_t len = strlen(iface);
771 if (len + 4 > sizeof(_if))
784 if ((pf = (fn)(_if, ret)) != NULL)
792 } while ((num = FormatIface(_if, len+1)));
797 void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
799 char buffer[256]; /* assume no interface will go beyond this */
800 size_t len = strlen(iface);
801 int ret; /* just in case something doesn't handle NULL properly */
803 if (len > sizeof(buffer) - 4)
808 strcpy(buffer, iface);
812 char *ptr = &buffer[len - 1];
814 while (isdigit(*ptr) && digits <=3)
822 /* for now, assume this is an error */
823 strcpy(buffer, iface);
828 min = (min == 0) ? 1 : min;
829 snprintf(num, sizeof(num), "%03d", min);
834 return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
837 const char *MetamodSource::GetBaseDir()
839 return mod_path.c_str();
842 size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
846 size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
849 for (size_t i = 0; i < mylen; i++)
851 if (buffer[i] == ALT_SEP_CHAR)
853 buffer[i] = PATH_SEP_CHAR;
860 void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
866 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
869 provider->ClientConsolePrint(client, buffer);
872 void MetamodSource::EnableVSPListener()
874 if (is_game_init && !vsp_load_requested && !vsp_loaded)
877 vsp_load_requested = true;
880 int MetamodSource::GetVSPVersion()
885 int MetamodSource::GetGameDLLVersion()
887 return gamedll_version;
890 bool MetamodSource::RemotePrintingAvailable()
892 return provider->IsRemotePrintingAvailable();
895 void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
907 /* First check ours... we get first chance! */
908 if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
914 return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
916 else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
922 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
924 else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
930 return static_cast<void *>(static_cast<SourceHook::IHookManagerAutoGen *>(&g_SH_HookManagerAutoGen));
933 CPluginManager::CPlugin *pl;
934 List<IMetamodListener *>::iterator event;
935 IMetamodListener *api;
939 for (PluginIter iter = g_PluginMngr._begin();
940 iter != g_PluginMngr._end();
944 for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
947 subret = IFACE_FAILED;
948 if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
971 void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
973 CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
975 pl->m_Events.push_back(pListener);
978 const char *MetamodSource::GetGameBinaryPath()
980 return full_bin_path.c_str();
983 const char *MetamodSource::GetPluginsFile()
985 return provider->GetConVarString(mm_pluginsfile);
988 IConCommandBaseAccessor *MetamodSource::GetCvarBaseAccessor()
990 return provider->GetConCommandBaseAccessor();
993 bool MetamodSource::RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
995 if (provider->IsConCommandBaseACommand(pCommand))
997 g_PluginMngr.AddPluginCmd(plugin, pCommand);
1001 g_PluginMngr.AddPluginCvar(plugin, pCommand);
1004 return provider->RegisterConCommandBase(pCommand);
1007 void MetamodSource::UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
1009 if (provider->IsConCommandBaseACommand(pCommand))
1011 g_PluginMngr.RemovePluginCmd(plugin, pCommand);
1015 g_PluginMngr.RemovePluginCvar(plugin, pCommand);
1018 CPluginManager::CPlugin *pOrig = g_PluginMngr.FindByAPI(plugin);
1019 UnregisterConCommandBase(pOrig ? pOrig->m_Id : 0, pCommand);
1022 void MetamodSource::UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand)
1025 CPluginManager::CPlugin *pPlugin;
1026 List<IMetamodListener *>::iterator event;
1027 IMetamodListener *pML;
1028 for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
1031 if (pPlugin->m_Status < Pl_Paused)
1035 /* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
1036 if (pPlugin->m_API->GetApiVersion() < 12)
1040 for (event=pPlugin->m_Events.begin();
1041 event!=pPlugin->m_Events.end();
1045 pML->OnUnlinkConCommandBase(id, pCommand);
1049 return provider->UnregisterConCommandBase(pCommand);
1052 int MetamodSource::GetUserMessageCount()
1054 return provider->GetUserMessageCount();
1057 int MetamodSource::FindUserMessage(const char *name, int *size/* =NULL */)
1059 return provider->FindUserMessage(name, size);
1062 const char *MetamodSource::GetUserMessage(int index, int *size/* =NULL */)
1064 return provider->GetUserMessage(index, size);
1067 int MetamodSource::GetSourceEngineBuild()
1069 return engine_build;
1072 void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks)
1074 vsp_callbacks = callbacks;
1075 ITER_EVENT(OnVSPListening, (callbacks));
1078 IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion)
1082 *pVersion = vsp_version;
1085 return vsp_callbacks;
1088 size_t MetamodSource::Format(char *buffer, size_t maxlength, const char *format, ...)
1093 va_start(ap, format);
1094 result = FormatArgs(buffer, maxlength, format, ap);
1100 size_t MetamodSource::FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap)
1102 return UTIL_FormatArgs(buffer, maxlength, format, ap);
1105 bool MetamodSource::IsLoadedAsGameDLL()
1107 return is_gamedll_loaded;
1110 void MetamodSource::SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded)
1112 gamedll_info.factory = serverFactory;
1113 gamedll_version = version;
1114 is_gamedll_loaded = loaded;
1118 ProcessVDF(const char *path)
1122 char alias[24], file[255], error[255];
1124 if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias)))
1127 if (alias[0] != '\0')
1128 g_PluginMngr.SetAlias(alias, file);
1130 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
1131 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1132 mm_LogMessage("[META] Failed to load plugin %s: %s", file, error);
1136 LookForVDFs(const char *dir)
1138 char path[MAX_PATH];
1139 char relpath[MAX_PATH * 2];
1141 #if defined _MSC_VER
1146 g_Metamod.PathFormat(path, sizeof(path), "%s\\*.vdf", dir);
1147 if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
1149 DWORD dw = GetLastError();
1150 if (dw == ERROR_FILE_NOT_FOUND)
1153 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
1156 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1160 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
1166 g_Metamod.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
1167 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1168 ProcessVDF(relpath);
1169 } while (FindNextFile(hFind, &fd));
1174 struct dirent *pEnt;
1177 if ((pDir = opendir(dir)) == NULL)
1179 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
1183 while ((pEnt = readdir(pDir)) != NULL)
1185 if (strcmp(pEnt->d_name, ".") == 0
1186 || strcmp(pEnt->d_name, "..") == 0)
1190 extidx = strlen(pEnt->d_name) - 4;
1191 if (extidx < 0 || stricmp(&pEnt->d_name[extidx], ".vdf"))
1195 g_Metamod.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
1196 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1197 ProcessVDF(relpath);
1207 return g_bIsVspBridged;
1211 mm_IsVspLoadComplete()
1213 return were_plugins_loaded;