Fixed up some cruft.
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 mm_LoadPluginsFromFile(const char *_file)
242 int total = 0, skipped=0;
246 fp = fopen(_file, "rt");
249 mm_LogMessage("[META] Could not open plugins file %s\n", _file);
253 char buffer[255], error[255], full_path[255];
254 const char *ptr, *ext, *file;
256 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
258 UTIL_TrimLeft(buffer);
259 UTIL_TrimRight(buffer);
261 length = strlen(buffer);
267 if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
273 if (buffer[0] == '"')
296 while (*cptr && isspace(*cptr))
301 UTIL_TrimRight(cptr);
302 if (*cptr && isalpha(*cptr))
304 g_PluginMngr.SetAlias(buffer, cptr);
316 /* First find if it's an absolute path or not... */
317 if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
319 /* If we're in an absolute path, ignore our normal heuristics */
320 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
321 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
323 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
335 /* Attempt to find a file extension */
336 ptr = UTIL_GetExtension(file);
337 /* Add an extension if there's none there */
340 #if defined WIN32 || defined _WIN32
350 /* Format the new path */
351 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s%s", mod_path.c_str(), file, ext);
352 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
353 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
355 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
369 mm_LogMessage("[META] Loaded %d plugins from file (%d already loaded)", total, skipped);
371 mm_LogMessage("[META] Loaded %d plugins from file.", total);
382 char engine_file[PATH_SIZE];
383 char engine_path[PATH_SIZE];
384 char rel_path[PATH_SIZE * 2];
386 GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
388 /* Chop off the "engine" file part */
389 len = strlen(engine_file);
390 for (size_t i = len - 1; i >= 0 && i < len; i--)
392 if (engine_file[i] == '/' || engine_file[i] == '\\')
394 engine_file[i] = '\0';
398 abspath(engine_path, engine_file);
400 const char *usepath = metamod_path.c_str();
401 if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
406 char command[PATH_SIZE * 2];
407 UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
408 provider->ServerCommand(command);
411 /* Wrapper function. This is called when the GameDLL thinks it's using
412 * the engine's real engineFactory.
415 EngineFactory(const char *iface, int *ret)
417 IFACE_MACRO(engine_factory, Engine);
420 /* Wrapper function. This is called when the GameDLL thinks it's using
421 * the engine's real physicsFactory.
424 PhysicsFactory(const char *iface, int *ret)
426 IFACE_MACRO(physics_factory, Physics);
429 /* Wrapper function. This is called when the GameDLL thinks it's using
430 * the engine's real fileSystemFactory.
433 FileSystemFactory(const char *iface, int *ret)
435 IFACE_MACRO(filesystem_factory, FileSystem);
439 mm_LogMessage(const char *msg, ...)
442 static char buffer[2048];
445 size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
448 buffer[len++] = '\n';
451 if (!provider->LogMessage(buffer))
453 fprintf(stdout, "%s", buffer);
458 DoInitialPluginLoads()
460 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
461 const char *mmBaseDir = provider->GetCommandLineValue("mm_basedir", NULL);
464 pluginFile = provider->GetConVarString(mm_pluginsfile);
465 if (pluginFile == NULL)
467 pluginFile = "addons/metamod/metaplugins.ini";
472 mmBaseDir = provider->GetConVarString(mm_basedir);
473 if (mmBaseDir == NULL)
475 mmBaseDir = "addons/metamod";
481 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), pluginFile);
482 mm_LoadPluginsFromFile(full_path);
484 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), mmBaseDir);
485 LookForVDFs(full_path);
489 mm_StartupMetamod(bool is_vsp_load)
497 is_vsp_load ? "V" : "");
499 metamod_version = provider->CreateConVar("metamod_version",
501 "Metamod:Source Version",
502 ConVarFlag_Notify|ConVarFlag_SpOnly);
504 provider->SetConVarString(metamod_version, buffer);
506 mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
507 #if defined WIN32 || defined _WIN32
508 "addons\\metamod\\metaplugins.ini",
510 "addons/metamod/metaplugins.ini",
512 "Metamod:Source Plugins File",
515 mm_basedir = provider->CreateConVar("mm_basedir",
516 #if defined __linux__
521 "Metamod:Source Base Folder",
524 g_bIsVspBridged = is_vsp_load;
528 DoInitialPluginLoads();
529 in_first_level = true;
534 mm_InitializeGlobals(CreateInterfaceFn engineFactory,
535 CreateInterfaceFn physicsFactory,
536 CreateInterfaceFn filesystemFactory,
537 CGlobalVars *pGlobals)
539 engine_factory = engineFactory;
540 physics_factory = physicsFactory;
541 filesystem_factory = filesystemFactory;
542 gpGlobals = pGlobals;
543 provider->Notify_DLLInit_Pre(engineFactory, gamedll_info.factory);
552 if (vsp_load_requested)
555 if (g_bIsVspBridged && !were_plugins_loaded)
557 DoInitialPluginLoads();
558 g_PluginMngr.SetAllLoaded();
559 were_plugins_loaded = true;
564 RETURN_META_VALUE(MRES_IGNORED, true);
571 g_PluginMngr.UnloadAll();
573 provider->Notify_DLLShutdown_Pre();
575 g_SourceHook.CompleteShutdown();
579 Handler_LevelShutdown(void)
581 if (g_bIsVspBridged && !were_plugins_loaded)
583 g_PluginMngr.SetAllLoaded();
584 DoInitialPluginLoads();
585 were_plugins_loaded = true;
586 in_first_level = true;
593 g_Metamod.PathFormat(full_path,
597 provider->GetConVarString(mm_pluginsfile));
598 mm_LoadPluginsFromFile(full_path);
600 g_Metamod.PathFormat(full_path,
604 provider->GetConVarString(mm_basedir));
605 LookForVDFs(full_path);
609 in_first_level = false;
612 ITER_EVENT(OnLevelShutdown, ());
614 RETURN_META(MRES_IGNORED);
618 Handler_LevelInit(char const *pMapName,
619 char const *pMapEntities,
620 char const *pOldLevel,
621 char const *pLandmarkName,
625 ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
627 RETURN_META_VALUE(MRES_IGNORED, false);
630 void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
636 UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
639 mm_LogMessage("[%s] %s", pl->GetLogTag(), buffer);
642 CreateInterfaceFn MetamodSource::GetEngineFactory(bool syn/* =true */)
645 return EngineFactory;
646 return engine_factory;
649 CreateInterfaceFn MetamodSource::GetPhysicsFactory(bool syn/* =true */)
652 return PhysicsFactory;
653 return physics_factory;
656 CreateInterfaceFn MetamodSource::GetFileSystemFactory(bool syn/* =true */)
659 return FileSystemFactory;
660 return filesystem_factory;
663 CreateInterfaceFn MetamodSource::GetServerFactory(bool syn/* =true */)
666 return ServerFactory;
667 return gamedll_info.factory;
670 CGlobalVars *MetamodSource::GetCGlobals()
675 void MetamodSource::SetLastMetaReturn(META_RES res)
680 META_RES MetamodSource::GetLastMetaReturn()
682 return last_meta_res;
685 void MetamodSource::ConPrint(const char *str)
687 provider->ConsolePrint(str);
690 void MetamodSource::ConPrintf(const char *fmt, ...)
696 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
699 provider->ConsolePrint(buffer);
702 void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
704 major = METAMOD_API_MAJOR;
705 minor = METAMOD_API_MINOR;
706 plvers = METAMOD_PLAPI_VERSION;
707 plmin = PLAPI_MIN_VERSION;
710 void MetamodSource::GetShVersions(int &shvers, int &shimpl)
712 shvers = SH_IFACE_VERSION;
713 shimpl = SH_IMPL_VERSION;
716 int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
718 int length = (int)strlen(iface);
722 for (i = length - 1; i >= 0; i--)
724 if (!isdigit(iface[i]))
734 if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
741 num = atoi(&(iface[++i]));
746 snprintf(&(iface[i]), 4, "%03d", num);
751 void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
753 char _if[256]; /* assume no interface goes beyond this */
754 size_t len = strlen(iface);
763 if (len + 4 > sizeof(_if))
776 if ((pf = (fn)(_if, ret)) != NULL)
784 } while ((num = FormatIface(_if, len+1)));
789 void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
791 char buffer[256]; /* assume no interface will go beyond this */
792 size_t len = strlen(iface);
793 int ret; /* just in case something doesn't handle NULL properly */
795 if (len > sizeof(buffer) - 4)
800 strcpy(buffer, iface);
804 char *ptr = &buffer[len - 1];
806 while (isdigit(*ptr) && digits <=3)
814 /* for now, assume this is an error */
815 strcpy(buffer, iface);
820 min = (min == 0) ? 1 : min;
821 snprintf(num, sizeof(num), "%03d", min);
826 return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
829 const char *MetamodSource::GetBaseDir()
831 return mod_path.c_str();
834 size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
838 size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
841 for (size_t i = 0; i < mylen; i++)
843 if (buffer[i] == ALT_SEP_CHAR)
845 buffer[i] = PATH_SEP_CHAR;
852 void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
858 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
861 provider->ClientConsolePrint(client, buffer);
864 void MetamodSource::EnableVSPListener()
866 if (is_game_init && !vsp_load_requested && !vsp_loaded)
869 vsp_load_requested = true;
872 int MetamodSource::GetVSPVersion()
877 int MetamodSource::GetGameDLLVersion()
879 return gamedll_version;
882 bool MetamodSource::RemotePrintingAvailable()
884 return provider->IsRemotePrintingAvailable();
887 void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
899 /* First check ours... we get first chance! */
900 if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
906 return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
908 else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
914 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
916 else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
922 return static_cast<void *>(static_cast<SourceHook::IHookManagerAutoGen *>(&g_SH_HookManagerAutoGen));
925 CPluginManager::CPlugin *pl;
926 List<IMetamodListener *>::iterator event;
927 IMetamodListener *api;
931 for (PluginIter iter = g_PluginMngr._begin();
932 iter != g_PluginMngr._end();
936 for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
939 subret = IFACE_FAILED;
940 if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
963 void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
965 CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
967 pl->m_Events.push_back(pListener);
970 const char *MetamodSource::GetGameBinaryPath()
972 return full_bin_path.c_str();
975 const char *MetamodSource::GetPluginsFile()
977 return provider->GetConVarString(mm_pluginsfile);
980 IConCommandBaseAccessor *MetamodSource::GetCvarBaseAccessor()
982 return provider->GetConCommandBaseAccessor();
985 bool MetamodSource::RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
987 if (provider->IsConCommandBaseACommand(pCommand))
989 g_PluginMngr.AddPluginCmd(plugin, pCommand);
993 g_PluginMngr.AddPluginCvar(plugin, pCommand);
996 return provider->RegisterConCommandBase(pCommand);
999 void MetamodSource::UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
1001 if (provider->IsConCommandBaseACommand(pCommand))
1003 g_PluginMngr.RemovePluginCmd(plugin, pCommand);
1007 g_PluginMngr.RemovePluginCvar(plugin, pCommand);
1010 CPluginManager::CPlugin *pOrig = g_PluginMngr.FindByAPI(plugin);
1011 UnregisterConCommandBase(pOrig ? pOrig->m_Id : 0, pCommand);
1014 void MetamodSource::UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand)
1017 CPluginManager::CPlugin *pPlugin;
1018 List<IMetamodListener *>::iterator event;
1019 IMetamodListener *pML;
1020 for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
1023 if (pPlugin->m_Status < Pl_Paused)
1027 /* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
1028 if (pPlugin->m_API->GetApiVersion() < 12)
1032 for (event=pPlugin->m_Events.begin();
1033 event!=pPlugin->m_Events.end();
1037 pML->OnUnlinkConCommandBase(id, pCommand);
1041 return provider->UnregisterConCommandBase(pCommand);
1044 int MetamodSource::GetUserMessageCount()
1046 return provider->GetUserMessageCount();
1049 int MetamodSource::FindUserMessage(const char *name, int *size/* =NULL */)
1051 return provider->FindUserMessage(name, size);
1054 const char *MetamodSource::GetUserMessage(int index, int *size/* =NULL */)
1056 return provider->GetUserMessage(index, size);
1059 int MetamodSource::GetSourceEngineBuild()
1061 return engine_build;
1064 void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks, int version)
1067 vsp_version = version;
1069 vsp_callbacks = callbacks;
1070 ITER_EVENT(OnVSPListening, (callbacks));
1073 IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion)
1077 *pVersion = vsp_version;
1080 return vsp_callbacks;
1083 size_t MetamodSource::Format(char *buffer, size_t maxlength, const char *format, ...)
1088 va_start(ap, format);
1089 result = FormatArgs(buffer, maxlength, format, ap);
1095 size_t MetamodSource::FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap)
1097 return UTIL_FormatArgs(buffer, maxlength, format, ap);
1100 bool MetamodSource::IsLoadedAsGameDLL()
1102 return is_gamedll_loaded;
1105 void MetamodSource::SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded)
1107 gamedll_info.factory = serverFactory;
1108 gamedll_version = version;
1109 is_gamedll_loaded = loaded;
1113 ProcessVDF(const char *path)
1117 char alias[24], file[255], error[255];
1119 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));
1126 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1127 mm_LogMessage("[META] Failed to load plugin %s: %s", file, error);
1131 LookForVDFs(const char *dir)
1133 char path[MAX_PATH];
1134 char relpath[MAX_PATH * 2];
1136 #if defined _MSC_VER
1141 g_Metamod.PathFormat(path, sizeof(path), "%s\\*.vdf", dir);
1142 if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
1144 DWORD dw = GetLastError();
1145 if (dw == ERROR_FILE_NOT_FOUND)
1148 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
1151 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1155 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
1161 g_Metamod.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
1162 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1163 ProcessVDF(relpath);
1164 } while (FindNextFile(hFind, &fd));
1169 struct dirent *pEnt;
1172 if ((pDir = opendir(dir)) == NULL)
1174 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
1178 while ((pEnt = readdir(pDir)) != NULL)
1180 if (strcmp(pEnt->d_name, ".") == 0
1181 || strcmp(pEnt->d_name, "..") == 0)
1185 extidx = strlen(pEnt->d_name) - 4;
1186 if (extidx < 0 || stricmp(&pEnt->d_name[extidx], ".vdf"))
1190 g_Metamod.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
1191 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1192 ProcessVDF(relpath);
1202 return g_bIsVspBridged;
1206 mm_IsVspLoadComplete()
1208 return were_plugins_loaded;