The 'meta refresh' command now handles plugins loaded via VDF files.
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++) { \
141 /* Initialize everything here */
143 mm_InitializeForLoad()
145 char full_path[PATH_SIZE] = {0};
146 GetFileOfAddress((void *)gamedll_info.factory, full_path, sizeof(full_path));
147 full_bin_path.assign(full_path);
149 /* Like Metamod, reload plugins at the end of the map.
150 * This is so plugins can hook everything on load, BUT, new plugins will be reloaded
151 * if the server is shut down (silly, but rare case).
153 in_first_level = true;
155 SourceHook::MemFuncInfo info;
157 if (!provider->GetHookInfo(ProvidedHook_GameInit, &info))
159 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::GameInit");
161 SH_MANUALHOOK_RECONFIGURE(SGD_GameInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
162 SH_ADD_MANUALHOOK_STATICFUNC(SGD_GameInit, server, Handler_GameInit, false);
164 if (!provider->GetHookInfo(ProvidedHook_LevelInit, &info))
166 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelInit");
168 SH_MANUALHOOK_RECONFIGURE(SGD_LevelInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
169 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelInit, server, Handler_LevelInit, true);
171 if (!provider->GetHookInfo(ProvidedHook_LevelShutdown, &info))
173 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelShutdown");
175 SH_MANUALHOOK_RECONFIGURE(SGD_LevelShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
176 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelShutdown, server, Handler_LevelShutdown, true);
180 mm_DetectGameInformation()
182 char mm_path[PATH_SIZE];
183 char game_path[PATH_SIZE];
185 /* Get path to SourceMM DLL */
186 if (!GetFileOfAddress((void *)mm_InitializeForLoad, mm_path, sizeof(mm_path)))
191 metamod_path.assign(mm_path);
193 /* Get value of -game from command line, defaulting to hl2 as engine seems to do */
194 const char *game_dir = provider->GetCommandLineValue("-game", "hl2");
196 /* Get absolute path */
197 abspath(game_path, game_dir);
198 mod_path.assign(game_path);
200 engine_build = provider->DetermineSourceEngine(game_dir);;
206 ServerFactory(const char *iface, int *ret)
208 IFACE_MACRO(gamedll_info.factory, GameDLL);
212 CreateInterface(const char *iface, int *ret)
216 if (!mm_IsVspBridged() && strncmp(iface, "ISERVERPLUGINCALLBACKS", 22) == 0)
218 if (vsp_callbacks != NULL)
225 vsp_version = atoi(&iface[22]);
226 ptr = provider->GetVSPCallbacks(vsp_version);
233 *ret = (ptr != NULL) ? IFACE_OK : IFACE_FAILED;
239 LoadPluginsFromFile(const char *filepath, int &skipped)
248 fp = fopen(filepath, "rt");
254 char buffer[255], error[255], full_path[PATH_SIZE];
255 const char *ptr, *ext, *file;
257 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
259 UTIL_TrimLeft(buffer);
260 UTIL_TrimRight(buffer);
262 length = strlen(buffer);
268 if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
274 if (buffer[0] == '"')
297 while (*cptr && isspace(*cptr))
302 UTIL_TrimRight(cptr);
303 if (*cptr && isalpha(*cptr))
305 g_PluginMngr.SetAlias(buffer, cptr);
317 /* First find if it's an absolute path or not... */
318 if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
320 /* If we're in an absolute path, ignore our normal heuristics */
321 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
322 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
324 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
336 /* Attempt to find a file extension */
337 ptr = UTIL_GetExtension(file);
338 /* Add an extension if there's none there */
341 #if defined WIN32 || defined _WIN32
351 /* Format the new path */
352 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s%s", mod_path.c_str(), file, ext);
353 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
354 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
356 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
378 char engine_file[PATH_SIZE];
379 char engine_path[PATH_SIZE];
380 char rel_path[PATH_SIZE * 2];
382 GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
384 /* Chop off the "engine" file part */
385 len = strlen(engine_file);
386 for (size_t i = len - 1; i >= 0 && i < len; i--)
388 if (engine_file[i] == '/' || engine_file[i] == '\\')
390 engine_file[i] = '\0';
394 abspath(engine_path, engine_file);
396 const char *usepath = metamod_path.c_str();
397 if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
402 char command[PATH_SIZE * 2];
403 UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
404 provider->ServerCommand(command);
407 /* Wrapper function. This is called when the GameDLL thinks it's using
408 * the engine's real engineFactory.
411 EngineFactory(const char *iface, int *ret)
413 IFACE_MACRO(engine_factory, Engine);
416 /* Wrapper function. This is called when the GameDLL thinks it's using
417 * the engine's real physicsFactory.
420 PhysicsFactory(const char *iface, int *ret)
422 IFACE_MACRO(physics_factory, Physics);
425 /* Wrapper function. This is called when the GameDLL thinks it's using
426 * the engine's real fileSystemFactory.
429 FileSystemFactory(const char *iface, int *ret)
431 IFACE_MACRO(filesystem_factory, FileSystem);
435 mm_LogMessage(const char *msg, ...)
438 static char buffer[2048];
441 size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
444 buffer[len++] = '\n';
447 if (!provider->LogMessage(buffer))
449 fprintf(stdout, "%s", buffer);
454 DoInitialPluginLoads()
456 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
457 const char *mmBaseDir = provider->GetCommandLineValue("mm_basedir", NULL);
460 pluginFile = provider->GetConVarString(mm_pluginsfile);
461 if (pluginFile == NULL)
463 pluginFile = "addons/metamod/metaplugins.ini";
468 mmBaseDir = provider->GetConVarString(mm_basedir);
469 if (mmBaseDir == NULL)
471 mmBaseDir = "addons/metamod";
475 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
477 g_Metamod.PathFormat(filepath, sizeof(filepath), "%s/%s", mod_path.c_str(), pluginFile);
478 g_Metamod.PathFormat(vdfpath, sizeof(vdfpath), "%s/%s", mod_path.c_str(), mmBaseDir);
479 mm_LoadPlugins(filepath, vdfpath);
483 mm_StartupMetamod(bool is_vsp_load)
491 is_vsp_load ? "V" : "");
493 metamod_version = provider->CreateConVar("metamod_version",
495 "Metamod:Source Version",
496 ConVarFlag_Notify|ConVarFlag_SpOnly);
498 provider->SetConVarString(metamod_version, buffer);
500 mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
501 #if defined WIN32 || defined _WIN32
502 "addons\\metamod\\metaplugins.ini",
504 "addons/metamod/metaplugins.ini",
506 "Metamod:Source Plugins File",
509 mm_basedir = provider->CreateConVar("mm_basedir",
510 #if defined __linux__
515 "Metamod:Source Base Folder",
518 g_bIsVspBridged = is_vsp_load;
522 DoInitialPluginLoads();
523 in_first_level = true;
528 mm_InitializeGlobals(CreateInterfaceFn engineFactory,
529 CreateInterfaceFn physicsFactory,
530 CreateInterfaceFn filesystemFactory,
531 CGlobalVars *pGlobals)
533 engine_factory = engineFactory;
534 physics_factory = physicsFactory;
535 filesystem_factory = filesystemFactory;
536 gpGlobals = pGlobals;
537 provider->Notify_DLLInit_Pre(engineFactory, gamedll_info.factory);
546 if (vsp_load_requested)
549 if (g_bIsVspBridged && !were_plugins_loaded)
551 DoInitialPluginLoads();
552 g_PluginMngr.SetAllLoaded();
553 were_plugins_loaded = true;
558 RETURN_META_VALUE(MRES_IGNORED, true);
565 g_PluginMngr.UnloadAll();
567 provider->Notify_DLLShutdown_Pre();
569 g_SourceHook.CompleteShutdown();
573 Handler_LevelShutdown(void)
575 if (g_bIsVspBridged && !were_plugins_loaded)
577 g_PluginMngr.SetAllLoaded();
578 DoInitialPluginLoads();
579 were_plugins_loaded = true;
580 in_first_level = true;
585 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
587 g_Metamod.PathFormat(filepath,
591 provider->GetConVarString(mm_pluginsfile));
592 g_Metamod.PathFormat(vdfpath,
596 provider->GetConVarString(mm_basedir));
597 mm_LoadPlugins(filepath, vdfpath);
601 in_first_level = false;
604 ITER_EVENT(OnLevelShutdown, ());
606 RETURN_META(MRES_IGNORED);
610 Handler_LevelInit(char const *pMapName,
611 char const *pMapEntities,
612 char const *pOldLevel,
613 char const *pLandmarkName,
617 ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
619 RETURN_META_VALUE(MRES_IGNORED, false);
622 void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
628 UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
631 mm_LogMessage("[%s] %s", pl->GetLogTag(), buffer);
634 CreateInterfaceFn MetamodSource::GetEngineFactory(bool syn/* =true */)
637 return EngineFactory;
638 return engine_factory;
641 CreateInterfaceFn MetamodSource::GetPhysicsFactory(bool syn/* =true */)
644 return PhysicsFactory;
645 return physics_factory;
648 CreateInterfaceFn MetamodSource::GetFileSystemFactory(bool syn/* =true */)
651 return FileSystemFactory;
652 return filesystem_factory;
655 CreateInterfaceFn MetamodSource::GetServerFactory(bool syn/* =true */)
658 return ServerFactory;
659 return gamedll_info.factory;
662 CGlobalVars *MetamodSource::GetCGlobals()
667 void MetamodSource::SetLastMetaReturn(META_RES res)
672 META_RES MetamodSource::GetLastMetaReturn()
674 return last_meta_res;
677 void MetamodSource::ConPrint(const char *str)
679 provider->ConsolePrint(str);
682 void MetamodSource::ConPrintf(const char *fmt, ...)
688 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
691 provider->ConsolePrint(buffer);
694 void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
696 major = METAMOD_API_MAJOR;
697 minor = METAMOD_API_MINOR;
698 plvers = METAMOD_PLAPI_VERSION;
699 plmin = PLAPI_MIN_VERSION;
702 void MetamodSource::GetShVersions(int &shvers, int &shimpl)
704 shvers = SH_IFACE_VERSION;
705 shimpl = SH_IMPL_VERSION;
708 int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
710 int length = (int)strlen(iface);
714 for (i = length - 1; i >= 0; i--)
716 if (!isdigit(iface[i]))
726 if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
733 num = atoi(&(iface[++i]));
738 snprintf(&(iface[i]), 4, "%03d", num);
743 void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
745 char _if[256]; /* assume no interface goes beyond this */
746 size_t len = strlen(iface);
755 if (len + 4 > sizeof(_if))
768 if ((pf = (fn)(_if, ret)) != NULL)
776 } while ((num = FormatIface(_if, len+1)));
781 void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
783 char buffer[256]; /* assume no interface will go beyond this */
784 size_t len = strlen(iface);
785 int ret; /* just in case something doesn't handle NULL properly */
787 if (len > sizeof(buffer) - 4)
792 strcpy(buffer, iface);
796 char *ptr = &buffer[len - 1];
798 while (isdigit(*ptr) && digits <=3)
806 /* for now, assume this is an error */
807 strcpy(buffer, iface);
812 min = (min == 0) ? 1 : min;
813 snprintf(num, sizeof(num), "%03d", min);
818 return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
821 const char *MetamodSource::GetBaseDir()
823 return mod_path.c_str();
826 size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
830 size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
833 for (size_t i = 0; i < mylen; i++)
835 if (buffer[i] == ALT_SEP_CHAR)
837 buffer[i] = PATH_SEP_CHAR;
844 void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
850 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
853 provider->ClientConsolePrint(client, buffer);
856 void MetamodSource::EnableVSPListener()
858 if (is_game_init && !vsp_load_requested && !vsp_loaded)
861 vsp_load_requested = true;
864 int MetamodSource::GetVSPVersion()
869 int MetamodSource::GetGameDLLVersion()
871 return gamedll_version;
874 bool MetamodSource::RemotePrintingAvailable()
876 return provider->IsRemotePrintingAvailable();
879 void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
891 /* First check ours... we get first chance! */
892 if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
898 return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
900 else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
906 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
908 else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
914 return static_cast<void *>(static_cast<SourceHook::IHookManagerAutoGen *>(&g_SH_HookManagerAutoGen));
917 CPluginManager::CPlugin *pl;
918 List<IMetamodListener *>::iterator event;
919 IMetamodListener *api;
923 for (PluginIter iter = g_PluginMngr._begin();
924 iter != g_PluginMngr._end();
928 for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
931 subret = IFACE_FAILED;
932 if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
955 void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
957 CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
959 pl->m_Events.push_back(pListener);
962 const char *MetamodSource::GetGameBinaryPath()
964 return full_bin_path.c_str();
967 const char *MetamodSource::GetPluginsFile()
969 return provider->GetConVarString(mm_pluginsfile);
972 const char *MetamodSource::GetVDFDir()
974 return provider->GetConVarString(mm_basedir);
977 IConCommandBaseAccessor *MetamodSource::GetCvarBaseAccessor()
979 return provider->GetConCommandBaseAccessor();
982 bool MetamodSource::RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
984 if (provider->IsConCommandBaseACommand(pCommand))
986 g_PluginMngr.AddPluginCmd(plugin, pCommand);
990 g_PluginMngr.AddPluginCvar(plugin, pCommand);
993 return provider->RegisterConCommandBase(pCommand);
996 void MetamodSource::UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
998 if (provider->IsConCommandBaseACommand(pCommand))
1000 g_PluginMngr.RemovePluginCmd(plugin, pCommand);
1004 g_PluginMngr.RemovePluginCvar(plugin, pCommand);
1007 CPluginManager::CPlugin *pOrig = g_PluginMngr.FindByAPI(plugin);
1008 UnregisterConCommandBase(pOrig ? pOrig->m_Id : 0, pCommand);
1011 void MetamodSource::UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand)
1014 CPluginManager::CPlugin *pPlugin;
1015 List<IMetamodListener *>::iterator event;
1016 IMetamodListener *pML;
1017 for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
1020 if (pPlugin->m_Status < Pl_Paused)
1024 /* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
1025 if (pPlugin->m_API->GetApiVersion() < 12)
1029 for (event=pPlugin->m_Events.begin();
1030 event!=pPlugin->m_Events.end();
1034 pML->OnUnlinkConCommandBase(id, pCommand);
1038 return provider->UnregisterConCommandBase(pCommand);
1041 int MetamodSource::GetUserMessageCount()
1043 return provider->GetUserMessageCount();
1046 int MetamodSource::FindUserMessage(const char *name, int *size/* =NULL */)
1048 return provider->FindUserMessage(name, size);
1051 const char *MetamodSource::GetUserMessage(int index, int *size/* =NULL */)
1053 return provider->GetUserMessage(index, size);
1056 int MetamodSource::GetSourceEngineBuild()
1058 return engine_build;
1061 void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks, int version)
1064 vsp_version = version;
1066 vsp_callbacks = callbacks;
1067 ITER_EVENT(OnVSPListening, (callbacks));
1070 IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion)
1074 *pVersion = vsp_version;
1077 return vsp_callbacks;
1080 size_t MetamodSource::Format(char *buffer, size_t maxlength, const char *format, ...)
1085 va_start(ap, format);
1086 result = FormatArgs(buffer, maxlength, format, ap);
1092 size_t MetamodSource::FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap)
1094 return UTIL_FormatArgs(buffer, maxlength, format, ap);
1097 bool MetamodSource::IsLoadedAsGameDLL()
1099 return is_gamedll_loaded;
1102 void MetamodSource::SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded)
1104 gamedll_info.factory = serverFactory;
1105 gamedll_version = version;
1106 is_gamedll_loaded = loaded;
1110 ProcessVDF(const char *path, bool &skipped)
1114 char alias[24], file[255], error[255];
1116 if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias)))
1122 if (alias[0] != '\0')
1123 g_PluginMngr.SetAlias(alias, file);
1125 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
1127 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1129 mm_LogMessage("[META] Failed to load plugin %s: %s", file, error);
1137 LoadVDFPluginsFromDir(const char *dir, int &skipped)
1141 char path[MAX_PATH];
1142 char relpath[MAX_PATH * 2];
1146 #if defined _MSC_VER
1151 g_Metamod.PathFormat(path, sizeof(path), "%s\\*.vdf", dir);
1152 if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
1154 DWORD dw = GetLastError();
1155 if (dw == ERROR_FILE_NOT_FOUND)
1158 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
1161 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1165 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
1171 g_Metamod.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
1172 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1173 success = ProcessVDF(relpath, skip);
1178 } while (FindNextFile(hFind, &fd));
1183 struct dirent *pEnt;
1186 if ((pDir = opendir(dir)) == NULL)
1188 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
1192 while ((pEnt = readdir(pDir)) != NULL)
1194 if (strcmp(pEnt->d_name, ".") == 0
1195 || strcmp(pEnt->d_name, "..") == 0)
1199 extidx = strlen(pEnt->d_name) - 4;
1200 if (extidx < 0 || stricmp(&pEnt->d_name[extidx], ".vdf"))
1204 g_Metamod.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
1205 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1206 success = ProcessVDF(relpath, skip);
1220 mm_LoadPlugins(const char *filepath, const char *vdfpath)
1222 int total, skipped, fskipped, vskipped;
1225 total = LoadPluginsFromFile(filepath, fskipped);
1226 total += LoadVDFPluginsFromDir(vdfpath, vskipped);
1227 skipped = fskipped + vskipped;
1229 if (total == 0 || total > 1)
1233 mm_LogMessage("[META] Loaded %d plugin%s (%d already loaded)", total, s, skipped);
1235 mm_LogMessage("[META] Loaded %d plugin%s.", total, s);
1243 return g_bIsVspBridged;
1247 mm_IsVspLoadComplete()
1249 return were_plugins_loaded;