Triggering build.
2 * vim: set ts=4 sw=4 tw=99 noet :
3 * ======================================================
5 * Copyright (C) 2004-2009 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.
27 #include "metamod_oslink.h"
29 #include <interface.h>
31 #include "metamod_provider.h"
32 #include "metamod_plugins.h"
33 #include "metamod_util.h"
34 #include "metamod_console.h"
35 #include "provider/provider_ep2.h"
37 using namespace SourceMM;
38 using namespace SourceHook;
39 using namespace SourceHook::Impl;
42 * @brief Implementation of main SourceMM GameDLL functionality
46 SH_DECL_MANUALHOOK0(SGD_GameInit, 0, 0, 0, bool);
47 SH_DECL_MANUALHOOK6(SGD_LevelInit, 0, 0, 0, bool, const char *, const char *, const char *, const char *, bool, bool);
48 SH_DECL_MANUALHOOK0_void(SGD_LevelShutdown, 0, 0, 0);
51 Handler_LevelShutdown();
54 Handler_LevelInit(char const *pMapName,
55 char const *pMapEntities,
56 char const *pOldLevel,
57 char const *pLandmarkName,
68 LoadPluginsFromFile(const char *filepath, int &skipped);
71 LoadVDFPluginsFromDir(const char *dir, int &skipped);
75 CreateInterfaceFn factory;
78 static String mod_path;
79 static String metamod_path;
80 static String full_bin_path;
81 static int vsp_version = 0;
82 static int gamedll_version = 0;
83 static int engine_build = SOURCE_ENGINE_UNKNOWN;
84 static List<game_dll_t *> gamedll_list;
85 static bool is_gamedll_loaded = false;
86 static bool in_first_level = true;
87 static bool is_game_init = false;
88 static bool vsp_load_requested = false;
89 static bool vsp_loaded = false;
90 static game_dll_t gamedll_info;
91 static ConVar *metamod_version = NULL;
92 static ConVar *mm_pluginsfile = NULL;
93 static ConVar *mm_basedir = NULL;
94 static CreateInterfaceFn engine_factory = NULL;
95 static CreateInterfaceFn physics_factory = NULL;
96 static CreateInterfaceFn filesystem_factory = NULL;
97 static CGlobalVars *gpGlobals = NULL;
98 static CHookManagerAutoGen g_SH_HookManagerAutoGen(&g_SourceHook);
99 static META_RES last_meta_res;
100 static IServerPluginCallbacks *vsp_callbacks = NULL;
101 static bool were_plugins_loaded = false;
102 static bool g_bIsVspBridged = false;
104 MetamodSource g_Metamod;
105 PluginId g_PLID = Pl_Console;
106 CSourceHookImpl g_SourceHook;
107 ISourceHook *g_SHPtr = &g_SourceHook;
108 SourceMM::ISmmAPI *g_pMetamod = &g_Metamod;
111 #define IFACE_MACRO(orig,nam) \
112 CPluginManager::CPlugin *pl; \
113 SourceHook::List<IMetamodListener *>::iterator event; \
114 IMetamodListener *api; \
117 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
119 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
121 mret = IFACE_FAILED; \
122 if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
123 if (ret) *ret = mret; \
128 return (orig)(iface, ret);
130 #define ITER_EVENT(evn, args) \
131 CPluginManager::CPlugin *pl; \
132 SourceHook::List<IMetamodListener *>::iterator event; \
133 IMetamodListener *api; \
134 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
136 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
142 /* Initialize everything here */
144 mm_InitializeForLoad()
146 char full_path[PATH_SIZE] = {0};
147 GetFileOfAddress((void *)gamedll_info.factory, full_path, sizeof(full_path));
148 full_bin_path.assign(full_path);
150 /* Like Metamod, reload plugins at the end of the map.
151 * This is so plugins can hook everything on load, BUT, new plugins will be reloaded
152 * if the server is shut down (silly, but rare case).
154 in_first_level = true;
156 SourceHook::MemFuncInfo info;
158 if (!provider->GetHookInfo(ProvidedHook_GameInit, &info))
160 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::GameInit");
162 SH_MANUALHOOK_RECONFIGURE(SGD_GameInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
163 SH_ADD_MANUALHOOK_STATICFUNC(SGD_GameInit, server, Handler_GameInit, false);
165 if (!provider->GetHookInfo(ProvidedHook_LevelInit, &info))
167 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelInit");
169 SH_MANUALHOOK_RECONFIGURE(SGD_LevelInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
170 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelInit, server, Handler_LevelInit, true);
172 if (!provider->GetHookInfo(ProvidedHook_LevelShutdown, &info))
174 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelShutdown");
176 SH_MANUALHOOK_RECONFIGURE(SGD_LevelShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
177 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelShutdown, server, Handler_LevelShutdown, true);
181 mm_DetectGameInformation()
183 char game_path[PATH_SIZE];
185 /* Get value of -game from command line, defaulting to hl2 as engine seems to do */
186 const char *game_dir = provider->GetCommandLineValue("-game");
190 /* Get absolute path */
191 abspath(game_path, game_dir);
195 /* Get absolute path for current directory */
196 abspath(game_path, ".");
199 mod_path.assign(game_path);
201 engine_build = provider->DetermineSourceEngine(game_dir);
207 ServerFactory(const char *iface, int *ret)
209 IFACE_MACRO(gamedll_info.factory, GameDLL);
213 LoadPluginsFromFile(const char *filepath, int &skipped)
222 fp = fopen(filepath, "rt");
228 char buffer[255], error[255], full_path[PATH_SIZE];
229 const char *ptr, *ext, *file;
231 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
233 UTIL_TrimLeft(buffer);
234 UTIL_TrimRight(buffer);
236 length = strlen(buffer);
242 if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
248 if (buffer[0] == '"')
271 while (*cptr && isspace(*cptr))
276 UTIL_TrimRight(cptr);
277 if (*cptr && isalpha(*cptr))
279 g_PluginMngr.SetAlias(buffer, cptr);
291 /* First find if it's an absolute path or not... */
292 if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
294 /* If we're in an absolute path, ignore our normal heuristics */
295 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
296 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
298 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
310 /* Attempt to find a file extension */
311 ptr = UTIL_GetExtension(file);
312 /* Add an extension if there's none there */
315 #if defined WIN32 || defined _WIN32
317 #elif defined __APPLE__
327 /* Format the new path */
328 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s%s", mod_path.c_str(), file, ext);
329 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
330 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
332 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
354 char engine_file[PATH_SIZE];
355 char engine_path[PATH_SIZE];
356 char rel_path[PATH_SIZE * 2];
358 GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
360 /* Chop off the "engine" file part */
361 len = strlen(engine_file);
362 for (size_t i = len - 1; i >= 0 && i < len; i--)
364 if (engine_file[i] == '/' || engine_file[i] == '\\')
366 engine_file[i] = '\0';
370 abspath(engine_path, engine_file);
372 const char *usepath = metamod_path.c_str();
373 if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
378 char command[PATH_SIZE * 2];
379 UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
380 provider->ServerCommand(command);
383 /* Wrapper function. This is called when the GameDLL thinks it's using
384 * the engine's real engineFactory.
387 EngineFactory(const char *iface, int *ret)
389 IFACE_MACRO(engine_factory, Engine);
392 /* Wrapper function. This is called when the GameDLL thinks it's using
393 * the engine's real physicsFactory.
396 PhysicsFactory(const char *iface, int *ret)
398 IFACE_MACRO(physics_factory, Physics);
401 /* Wrapper function. This is called when the GameDLL thinks it's using
402 * the engine's real fileSystemFactory.
405 FileSystemFactory(const char *iface, int *ret)
407 IFACE_MACRO(filesystem_factory, FileSystem);
411 mm_LogMessage(const char *msg, ...)
414 static char buffer[2048];
417 size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
420 buffer[len++] = '\n';
423 if (!provider->LogMessage(buffer))
425 fprintf(stdout, "%s", buffer);
430 DoInitialPluginLoads()
432 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
433 const char *mmBaseDir = provider->GetCommandLineValue("mm_basedir", NULL);
436 pluginFile = provider->GetConVarString(mm_pluginsfile);
437 if (pluginFile == NULL)
439 pluginFile = "addons/metamod/metaplugins.ini";
444 mmBaseDir = provider->GetConVarString(mm_basedir);
445 if (mmBaseDir == NULL)
447 mmBaseDir = "addons/metamod";
451 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
453 g_Metamod.PathFormat(filepath, sizeof(filepath), "%s/%s", mod_path.c_str(), pluginFile);
454 g_Metamod.PathFormat(vdfpath, sizeof(vdfpath), "%s/%s", mod_path.c_str(), mmBaseDir);
455 mm_LoadPlugins(filepath, vdfpath);
459 mm_StartupMetamod(bool is_vsp_load)
467 is_vsp_load ? "V" : "");
469 metamod_version = provider->CreateConVar("metamod_version",
471 "Metamod:Source Version",
472 ConVarFlag_Notify|ConVarFlag_SpOnly);
474 provider->SetConVarString(metamod_version, buffer);
476 mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
477 #if defined WIN32 || defined _WIN32
478 "addons\\metamod\\metaplugins.ini",
480 "addons/metamod/metaplugins.ini",
482 "Metamod:Source Plugins File",
485 mm_basedir = provider->CreateConVar("mm_basedir",
486 #if defined __linux__ || defined __APPLE__
491 "Metamod:Source Base Folder",
494 g_bIsVspBridged = is_vsp_load;
498 DoInitialPluginLoads();
499 in_first_level = true;
504 mm_InitializeGlobals(CreateInterfaceFn engineFactory,
505 CreateInterfaceFn physicsFactory,
506 CreateInterfaceFn filesystemFactory,
507 CGlobalVars *pGlobals)
509 engine_factory = engineFactory;
510 physics_factory = physicsFactory;
511 filesystem_factory = filesystemFactory;
512 gpGlobals = pGlobals;
513 provider->Notify_DLLInit_Pre(engineFactory, gamedll_info.factory);
522 if (vsp_load_requested)
525 if (g_bIsVspBridged && !were_plugins_loaded)
527 DoInitialPluginLoads();
528 g_PluginMngr.SetAllLoaded();
529 were_plugins_loaded = true;
534 RETURN_META_VALUE(MRES_IGNORED, true);
541 g_PluginMngr.UnloadAll();
543 provider->Notify_DLLShutdown_Pre();
545 g_SourceHook.CompleteShutdown();
549 Handler_LevelShutdown(void)
551 if (g_bIsVspBridged && !were_plugins_loaded)
553 DoInitialPluginLoads();
554 g_PluginMngr.SetAllLoaded();
555 were_plugins_loaded = true;
556 in_first_level = true;
561 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
563 g_Metamod.PathFormat(filepath,
567 provider->GetConVarString(mm_pluginsfile));
568 g_Metamod.PathFormat(vdfpath,
572 provider->GetConVarString(mm_basedir));
573 mm_LoadPlugins(filepath, vdfpath);
577 in_first_level = false;
580 ITER_EVENT(OnLevelShutdown, ());
582 RETURN_META(MRES_IGNORED);
586 Handler_LevelInit(char const *pMapName,
587 char const *pMapEntities,
588 char const *pOldLevel,
589 char const *pLandmarkName,
593 ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
595 RETURN_META_VALUE(MRES_IGNORED, false);
598 void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
604 UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
607 mm_LogMessage("[%s] %s", pl->GetLogTag(), buffer);
610 CreateInterfaceFn MetamodSource::GetEngineFactory(bool syn/* =true */)
613 return EngineFactory;
614 return engine_factory;
617 CreateInterfaceFn MetamodSource::GetPhysicsFactory(bool syn/* =true */)
620 return PhysicsFactory;
621 return physics_factory;
624 CreateInterfaceFn MetamodSource::GetFileSystemFactory(bool syn/* =true */)
627 return FileSystemFactory;
628 return filesystem_factory;
631 CreateInterfaceFn MetamodSource::GetServerFactory(bool syn/* =true */)
634 return ServerFactory;
635 return gamedll_info.factory;
638 CGlobalVars *MetamodSource::GetCGlobals()
643 void MetamodSource::SetLastMetaReturn(META_RES res)
648 META_RES MetamodSource::GetLastMetaReturn()
650 return last_meta_res;
653 void MetamodSource::ConPrint(const char *str)
655 provider->ConsolePrint(str);
658 void MetamodSource::ConPrintf(const char *fmt, ...)
664 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
667 provider->ConsolePrint(buffer);
670 void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
672 major = METAMOD_API_MAJOR;
673 minor = METAMOD_API_MINOR;
674 plvers = METAMOD_PLAPI_VERSION;
675 plmin = PLAPI_MIN_VERSION;
678 void MetamodSource::GetShVersions(int &shvers, int &shimpl)
680 shvers = SH_IFACE_VERSION;
681 shimpl = SH_IMPL_VERSION;
684 int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
686 int length = (int)strlen(iface);
690 for (i = length - 1; i >= 0; i--)
692 if (!isdigit(iface[i]))
702 if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
709 num = atoi(&(iface[++i]));
714 snprintf(&(iface[i]), 4, "%03d", num);
719 void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
721 char _if[256]; /* assume no interface goes beyond this */
722 size_t len = strlen(iface);
731 if (len + 4 > sizeof(_if))
744 if ((pf = (fn)(_if, ret)) != NULL)
752 } while ((num = FormatIface(_if, len+1)));
757 void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
759 char buffer[256]; /* assume no interface will go beyond this */
760 size_t len = strlen(iface);
761 int ret; /* just in case something doesn't handle NULL properly */
763 if (len > sizeof(buffer) - 4)
768 strcpy(buffer, iface);
772 char *ptr = &buffer[len - 1];
774 while (isdigit(*ptr) && digits <=3)
782 /* for now, assume this is an error */
783 strcpy(buffer, iface);
788 min = (min == 0) ? 1 : min;
789 snprintf(num, sizeof(num), "%03d", min);
794 return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
797 const char *MetamodSource::GetBaseDir()
799 return mod_path.c_str();
802 size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
806 size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
809 for (size_t i = 0; i < mylen; i++)
811 if (buffer[i] == ALT_SEP_CHAR)
813 buffer[i] = PATH_SEP_CHAR;
820 void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
826 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
829 provider->ClientConsolePrint(client, buffer);
832 void MetamodSource::EnableVSPListener()
834 if (is_game_init && !vsp_load_requested && !vsp_loaded)
839 vsp_load_requested = true;
842 int MetamodSource::GetVSPVersion()
847 int MetamodSource::GetGameDLLVersion()
849 return gamedll_version;
852 bool MetamodSource::RemotePrintingAvailable()
854 return provider->IsRemotePrintingAvailable();
857 void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
869 /* First check ours... we get first chance! */
870 if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
876 return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
878 else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
884 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
886 else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
892 return static_cast<void *>(static_cast<SourceHook::IHookManagerAutoGen *>(&g_SH_HookManagerAutoGen));
895 CPluginManager::CPlugin *pl;
896 List<IMetamodListener *>::iterator event;
897 IMetamodListener *api;
901 for (PluginIter iter = g_PluginMngr._begin();
902 iter != g_PluginMngr._end();
906 for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
909 subret = IFACE_FAILED;
910 if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
933 void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
935 CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
937 pl->m_Events.push_back(pListener);
940 const char *MetamodSource::GetGameBinaryPath()
942 return full_bin_path.c_str();
945 const char *MetamodSource::GetPluginsFile()
947 return provider->GetConVarString(mm_pluginsfile);
950 const char *MetamodSource::GetVDFDir()
952 return provider->GetConVarString(mm_basedir);
955 IConCommandBaseAccessor *MetamodSource::GetCvarBaseAccessor()
957 return provider->GetConCommandBaseAccessor();
960 bool MetamodSource::RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
962 if (provider->IsConCommandBaseACommand(pCommand))
964 g_PluginMngr.AddPluginCmd(plugin, pCommand);
968 g_PluginMngr.AddPluginCvar(plugin, pCommand);
971 return provider->RegisterConCommandBase(pCommand);
974 void MetamodSource::UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
976 if (provider->IsConCommandBaseACommand(pCommand))
978 g_PluginMngr.RemovePluginCmd(plugin, pCommand);
982 g_PluginMngr.RemovePluginCvar(plugin, pCommand);
985 CPluginManager::CPlugin *pOrig = g_PluginMngr.FindByAPI(plugin);
986 UnregisterConCommandBase(pOrig ? pOrig->m_Id : 0, pCommand);
989 void MetamodSource::UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand)
992 CPluginManager::CPlugin *pPlugin;
993 List<IMetamodListener *>::iterator event;
994 IMetamodListener *pML;
995 for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
998 if (pPlugin->m_Status < Pl_Paused)
1002 /* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
1003 if (pPlugin->m_API->GetApiVersion() < 12)
1007 for (event=pPlugin->m_Events.begin();
1008 event!=pPlugin->m_Events.end();
1012 pML->OnUnlinkConCommandBase(id, pCommand);
1016 return provider->UnregisterConCommandBase(pCommand);
1019 int MetamodSource::GetUserMessageCount()
1021 return provider->GetUserMessageCount();
1024 int MetamodSource::FindUserMessage(const char *name, int *size/* =NULL */)
1026 return provider->FindUserMessage(name, size);
1029 const char *MetamodSource::GetUserMessage(int index, int *size/* =NULL */)
1031 return provider->GetUserMessage(index, size);
1034 int MetamodSource::GetSourceEngineBuild()
1036 return engine_build;
1039 void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks, int version)
1042 vsp_version = version;
1044 vsp_callbacks = callbacks;
1045 ITER_EVENT(OnVSPListening, (callbacks));
1047 if (is_gamedll_loaded)
1050 * MM:S is loaded as a game DLL so we need to set these for mm_IsVspBridged() and
1051 * mm_IsVspLoadComplete()
1053 g_bIsVspBridged = true;
1054 were_plugins_loaded = true;
1058 IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion)
1062 *pVersion = vsp_version;
1065 return vsp_callbacks;
1068 size_t MetamodSource::Format(char *buffer, size_t maxlength, const char *format, ...)
1073 va_start(ap, format);
1074 result = FormatArgs(buffer, maxlength, format, ap);
1080 size_t MetamodSource::FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap)
1082 return UTIL_FormatArgs(buffer, maxlength, format, ap);
1085 bool MetamodSource::IsLoadedAsGameDLL()
1087 return is_gamedll_loaded;
1090 void MetamodSource::SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded)
1092 gamedll_info.factory = serverFactory;
1093 gamedll_version = version;
1094 is_gamedll_loaded = loaded;
1097 void MetamodSource::SetVSPListener(const char *path)
1099 metamod_path.assign(path);
1103 ProcessVDF(const char *path, bool &skipped)
1107 char alias[24], file[255], full_path[255], error[255];
1109 if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias)))
1115 if (alias[0] != '\0')
1116 g_PluginMngr.SetAlias(alias, file);
1118 /* Attempt to find a file extension */
1119 if (UTIL_GetExtension(file) == NULL)
1121 g_pMetamod->PathFormat(full_path,
1124 g_pMetamod->GetBaseDir(),
1126 #if defined WIN32 || defined _WIN32
1128 #elif defined __APPLE__
1137 g_pMetamod->PathFormat(full_path,
1140 g_pMetamod->GetBaseDir(),
1144 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
1146 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1148 mm_LogMessage("[META] Failed to load plugin %s: %s", file, error);
1156 LoadVDFPluginsFromDir(const char *dir, int &skipped)
1160 char path[MAX_PATH];
1161 char relpath[MAX_PATH * 2];
1165 #if defined _MSC_VER
1170 g_Metamod.PathFormat(path, sizeof(path), "%s\\*.vdf", dir);
1171 if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
1173 DWORD dw = GetLastError();
1174 if (dw == ERROR_FILE_NOT_FOUND)
1177 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
1180 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1184 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
1190 g_Metamod.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
1191 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1192 success = ProcessVDF(relpath, skip);
1197 } while (FindNextFile(hFind, &fd));
1202 struct dirent *pEnt;
1205 if ((pDir = opendir(dir)) == NULL)
1207 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
1211 while ((pEnt = readdir(pDir)) != NULL)
1213 if (strcmp(pEnt->d_name, ".") == 0
1214 || strcmp(pEnt->d_name, "..") == 0)
1218 extidx = strlen(pEnt->d_name) - 4;
1219 if (extidx < 0 || stricmp(&pEnt->d_name[extidx], ".vdf"))
1223 g_Metamod.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
1224 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1225 success = ProcessVDF(relpath, skip);
1239 mm_LoadPlugins(const char *filepath, const char *vdfpath)
1241 int total, skipped, fskipped, vskipped;
1244 total = LoadPluginsFromFile(filepath, fskipped);
1245 total += LoadVDFPluginsFromDir(vdfpath, vskipped);
1246 skipped = fskipped + vskipped;
1248 if (total == 0 || total > 1)
1252 mm_LogMessage("[META] Loaded %d plugin%s (%d already loaded)", total, s, skipped);
1254 mm_LogMessage("[META] Loaded %d plugin%s.", total, s);
1262 return g_bIsVspBridged;
1266 mm_IsVspLoadComplete()
1268 return were_plugins_loaded;