Fixed core VSP listening when bridged as a VSP.
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);
235 *ret = (ptr != NULL) ? IFACE_OK : IFACE_FAILED;
241 mm_LoadPluginsFromFile(const char *_file)
244 int total = 0, skipped=0;
248 fp = fopen(_file, "rt");
251 mm_LogMessage("[META] Could not open plugins file %s\n", _file);
255 char buffer[255], error[255], full_path[255];
256 const char *ptr, *ext, *file;
258 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
260 UTIL_TrimLeft(buffer);
261 UTIL_TrimRight(buffer);
263 length = strlen(buffer);
269 if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
275 if (buffer[0] == '"')
298 while (*cptr && isspace(*cptr))
303 UTIL_TrimRight(cptr);
304 if (*cptr && isalpha(*cptr))
306 g_PluginMngr.SetAlias(buffer, cptr);
318 /* First find if it's an absolute path or not... */
319 if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
321 /* If we're in an absolute path, ignore our normal heuristics */
322 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
323 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
325 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
337 /* Attempt to find a file extension */
338 ptr = UTIL_GetExtension(file);
339 /* Add an extension if there's none there */
342 #if defined WIN32 || defined _WIN32
352 /* Format the new path */
353 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s%s", mod_path.c_str(), file, ext);
354 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
355 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
357 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
371 mm_LogMessage("[META] Loaded %d plugins from file (%d already loaded)", total, skipped);
373 mm_LogMessage("[META] Loaded %d plugins from file.", total);
384 char engine_file[PATH_SIZE];
385 char engine_path[PATH_SIZE];
386 char rel_path[PATH_SIZE * 2];
388 GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
390 /* Chop off the "engine" file part */
391 len = strlen(engine_file);
392 for (size_t i = len - 1; i >= 0 && i < len; i--)
394 if (engine_file[i] == '/' || engine_file[i] == '\\')
396 engine_file[i] = '\0';
400 abspath(engine_path, engine_file);
402 const char *usepath = metamod_path.c_str();
403 if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
408 char command[PATH_SIZE * 2];
409 UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
410 provider->ServerCommand(command);
413 /* Wrapper function. This is called when the GameDLL thinks it's using
414 * the engine's real engineFactory.
417 EngineFactory(const char *iface, int *ret)
419 IFACE_MACRO(engine_factory, Engine);
422 /* Wrapper function. This is called when the GameDLL thinks it's using
423 * the engine's real physicsFactory.
426 PhysicsFactory(const char *iface, int *ret)
428 IFACE_MACRO(physics_factory, Physics);
431 /* Wrapper function. This is called when the GameDLL thinks it's using
432 * the engine's real fileSystemFactory.
435 FileSystemFactory(const char *iface, int *ret)
437 IFACE_MACRO(filesystem_factory, FileSystem);
441 mm_LogMessage(const char *msg, ...)
444 static char buffer[2048];
447 size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
450 buffer[len++] = '\n';
453 if (!provider->LogMessage(buffer))
455 fprintf(stdout, "%s", buffer);
460 DoInitialPluginLoads()
462 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
463 const char *mmBaseDir = provider->GetCommandLineValue("mm_basedir", NULL);
466 pluginFile = provider->GetConVarString(mm_pluginsfile);
467 if (pluginFile == NULL)
469 pluginFile = "addons/metamod/metaplugins.ini";
474 mmBaseDir = provider->GetConVarString(mm_basedir);
475 if (mmBaseDir == NULL)
477 mmBaseDir = "addons/metamod";
483 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), pluginFile);
484 mm_LoadPluginsFromFile(full_path);
486 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), mmBaseDir);
487 LookForVDFs(full_path);
491 mm_StartupMetamod(bool is_vsp_load)
499 is_vsp_load ? "V" : "");
501 metamod_version = provider->CreateConVar("metamod_version",
503 "Metamod:Source Version",
504 ConVarFlag_Notify|ConVarFlag_SpOnly);
506 provider->SetConVarString(metamod_version, buffer);
508 mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
509 #if defined WIN32 || defined _WIN32
510 "addons\\metamod\\metaplugins.ini",
512 "addons/metamod/metaplugins.ini",
514 "Metamod:Source Plugins File",
517 mm_basedir = provider->CreateConVar("mm_basedir",
518 #if defined __linux__
523 "Metamod:Source Base Folder",
526 g_bIsVspBridged = is_vsp_load;
530 DoInitialPluginLoads();
531 in_first_level = true;
536 mm_InitializeGlobals(CreateInterfaceFn engineFactory,
537 CreateInterfaceFn physicsFactory,
538 CreateInterfaceFn filesystemFactory,
539 CGlobalVars *pGlobals)
541 engine_factory = engineFactory;
542 physics_factory = physicsFactory;
543 filesystem_factory = filesystemFactory;
544 gpGlobals = pGlobals;
545 provider->Notify_DLLInit_Pre(engineFactory, gamedll_info.factory);
554 if (vsp_load_requested)
557 if (g_bIsVspBridged && !were_plugins_loaded)
559 DoInitialPluginLoads();
560 g_PluginMngr.SetAllLoaded();
561 were_plugins_loaded = true;
566 RETURN_META_VALUE(MRES_IGNORED, true);
573 g_PluginMngr.UnloadAll();
575 provider->Notify_DLLShutdown_Pre();
577 g_SourceHook.CompleteShutdown();
581 Handler_LevelShutdown(void)
583 if (g_bIsVspBridged && !were_plugins_loaded)
585 g_PluginMngr.SetAllLoaded();
586 DoInitialPluginLoads();
587 were_plugins_loaded = true;
588 in_first_level = true;
595 g_Metamod.PathFormat(full_path,
599 provider->GetConVarString(mm_pluginsfile));
600 mm_LoadPluginsFromFile(full_path);
602 g_Metamod.PathFormat(full_path,
606 provider->GetConVarString(mm_basedir));
607 LookForVDFs(full_path);
611 in_first_level = false;
614 ITER_EVENT(OnLevelShutdown, ());
616 RETURN_META(MRES_IGNORED);
620 Handler_LevelInit(char const *pMapName,
621 char const *pMapEntities,
622 char const *pOldLevel,
623 char const *pLandmarkName,
627 ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
629 RETURN_META_VALUE(MRES_IGNORED, false);
632 void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
638 UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
641 mm_LogMessage("[%s] %s", pl->GetLogTag(), buffer);
644 CreateInterfaceFn MetamodSource::GetEngineFactory(bool syn/* =true */)
647 return EngineFactory;
648 return engine_factory;
651 CreateInterfaceFn MetamodSource::GetPhysicsFactory(bool syn/* =true */)
654 return PhysicsFactory;
655 return physics_factory;
658 CreateInterfaceFn MetamodSource::GetFileSystemFactory(bool syn/* =true */)
661 return FileSystemFactory;
662 return filesystem_factory;
665 CreateInterfaceFn MetamodSource::GetServerFactory(bool syn/* =true */)
668 return ServerFactory;
669 return gamedll_info.factory;
672 CGlobalVars *MetamodSource::GetCGlobals()
677 void MetamodSource::SetLastMetaReturn(META_RES res)
682 META_RES MetamodSource::GetLastMetaReturn()
684 return last_meta_res;
687 void MetamodSource::ConPrint(const char *str)
689 provider->ConsolePrint(str);
692 void MetamodSource::ConPrintf(const char *fmt, ...)
698 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
701 provider->ConsolePrint(buffer);
704 void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
706 major = METAMOD_API_MAJOR;
707 minor = METAMOD_API_MINOR;
708 plvers = METAMOD_PLAPI_VERSION;
709 plmin = PLAPI_MIN_VERSION;
712 void MetamodSource::GetShVersions(int &shvers, int &shimpl)
714 shvers = SH_IFACE_VERSION;
715 shimpl = SH_IMPL_VERSION;
718 int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
720 int length = (int)strlen(iface);
724 for (i = length - 1; i >= 0; i--)
726 if (!isdigit(iface[i]))
736 if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
743 num = atoi(&(iface[++i]));
748 snprintf(&(iface[i]), 4, "%03d", num);
753 void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
755 char _if[256]; /* assume no interface goes beyond this */
756 size_t len = strlen(iface);
765 if (len + 4 > sizeof(_if))
778 if ((pf = (fn)(_if, ret)) != NULL)
786 } while ((num = FormatIface(_if, len+1)));
791 void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
793 char buffer[256]; /* assume no interface will go beyond this */
794 size_t len = strlen(iface);
795 int ret; /* just in case something doesn't handle NULL properly */
797 if (len > sizeof(buffer) - 4)
802 strcpy(buffer, iface);
806 char *ptr = &buffer[len - 1];
808 while (isdigit(*ptr) && digits <=3)
816 /* for now, assume this is an error */
817 strcpy(buffer, iface);
822 min = (min == 0) ? 1 : min;
823 snprintf(num, sizeof(num), "%03d", min);
828 return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
831 const char *MetamodSource::GetBaseDir()
833 return mod_path.c_str();
836 size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
840 size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
843 for (size_t i = 0; i < mylen; i++)
845 if (buffer[i] == ALT_SEP_CHAR)
847 buffer[i] = PATH_SEP_CHAR;
854 void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
860 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
863 provider->ClientConsolePrint(client, buffer);
866 void MetamodSource::EnableVSPListener()
868 if (is_game_init && !vsp_load_requested && !vsp_loaded)
871 vsp_load_requested = true;
874 int MetamodSource::GetVSPVersion()
879 int MetamodSource::GetGameDLLVersion()
881 return gamedll_version;
884 bool MetamodSource::RemotePrintingAvailable()
886 return provider->IsRemotePrintingAvailable();
889 void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
901 /* First check ours... we get first chance! */
902 if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
908 return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
910 else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
916 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
918 else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
924 return static_cast<void *>(static_cast<SourceHook::IHookManagerAutoGen *>(&g_SH_HookManagerAutoGen));
927 CPluginManager::CPlugin *pl;
928 List<IMetamodListener *>::iterator event;
929 IMetamodListener *api;
933 for (PluginIter iter = g_PluginMngr._begin();
934 iter != g_PluginMngr._end();
938 for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
941 subret = IFACE_FAILED;
942 if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
965 void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
967 CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
969 pl->m_Events.push_back(pListener);
972 const char *MetamodSource::GetGameBinaryPath()
974 return full_bin_path.c_str();
977 const char *MetamodSource::GetPluginsFile()
979 return provider->GetConVarString(mm_pluginsfile);
982 IConCommandBaseAccessor *MetamodSource::GetCvarBaseAccessor()
984 return provider->GetConCommandBaseAccessor();
987 bool MetamodSource::RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
989 if (provider->IsConCommandBaseACommand(pCommand))
991 g_PluginMngr.AddPluginCmd(plugin, pCommand);
995 g_PluginMngr.AddPluginCvar(plugin, pCommand);
998 return provider->RegisterConCommandBase(pCommand);
1001 void MetamodSource::UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
1003 if (provider->IsConCommandBaseACommand(pCommand))
1005 g_PluginMngr.RemovePluginCmd(plugin, pCommand);
1009 g_PluginMngr.RemovePluginCvar(plugin, pCommand);
1012 CPluginManager::CPlugin *pOrig = g_PluginMngr.FindByAPI(plugin);
1013 UnregisterConCommandBase(pOrig ? pOrig->m_Id : 0, pCommand);
1016 void MetamodSource::UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand)
1019 CPluginManager::CPlugin *pPlugin;
1020 List<IMetamodListener *>::iterator event;
1021 IMetamodListener *pML;
1022 for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
1025 if (pPlugin->m_Status < Pl_Paused)
1029 /* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
1030 if (pPlugin->m_API->GetApiVersion() < 12)
1034 for (event=pPlugin->m_Events.begin();
1035 event!=pPlugin->m_Events.end();
1039 pML->OnUnlinkConCommandBase(id, pCommand);
1043 return provider->UnregisterConCommandBase(pCommand);
1046 int MetamodSource::GetUserMessageCount()
1048 return provider->GetUserMessageCount();
1051 int MetamodSource::FindUserMessage(const char *name, int *size/* =NULL */)
1053 return provider->FindUserMessage(name, size);
1056 const char *MetamodSource::GetUserMessage(int index, int *size/* =NULL */)
1058 return provider->GetUserMessage(index, size);
1061 int MetamodSource::GetSourceEngineBuild()
1063 return engine_build;
1066 void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks, int version)
1069 vsp_version = version;
1071 vsp_callbacks = callbacks;
1072 ITER_EVENT(OnVSPListening, (callbacks));
1075 IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion)
1079 *pVersion = vsp_version;
1082 return vsp_callbacks;
1085 size_t MetamodSource::Format(char *buffer, size_t maxlength, const char *format, ...)
1090 va_start(ap, format);
1091 result = FormatArgs(buffer, maxlength, format, ap);
1097 size_t MetamodSource::FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap)
1099 return UTIL_FormatArgs(buffer, maxlength, format, ap);
1102 bool MetamodSource::IsLoadedAsGameDLL()
1104 return is_gamedll_loaded;
1107 void MetamodSource::SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded)
1109 gamedll_info.factory = serverFactory;
1110 gamedll_version = version;
1111 is_gamedll_loaded = loaded;
1115 ProcessVDF(const char *path)
1119 char alias[24], file[255], error[255];
1121 if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias)))
1124 if (alias[0] != '\0')
1125 g_PluginMngr.SetAlias(alias, file);
1127 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
1128 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1129 mm_LogMessage("[META] Failed to load plugin %s: %s", file, error);
1133 LookForVDFs(const char *dir)
1135 char path[MAX_PATH];
1136 char relpath[MAX_PATH * 2];
1138 #if defined _MSC_VER
1143 g_Metamod.PathFormat(path, sizeof(path), "%s\\*.vdf", dir);
1144 if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
1146 DWORD dw = GetLastError();
1147 if (dw == ERROR_FILE_NOT_FOUND)
1150 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
1153 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1157 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
1163 g_Metamod.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
1164 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1165 ProcessVDF(relpath);
1166 } while (FindNextFile(hFind, &fd));
1171 struct dirent *pEnt;
1174 if ((pDir = opendir(dir)) == NULL)
1176 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
1180 while ((pEnt = readdir(pDir)) != NULL)
1182 if (strcmp(pEnt->d_name, ".") == 0
1183 || strcmp(pEnt->d_name, "..") == 0)
1187 extidx = strlen(pEnt->d_name) - 4;
1188 if (extidx < 0 || stricmp(&pEnt->d_name[extidx], ".vdf"))
1192 g_Metamod.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
1193 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1194 ProcessVDF(relpath);
1204 return g_bIsVspBridged;
1208 mm_IsVspLoadComplete()
1210 return were_plugins_loaded;