Normalized line endings to unix (no bug).
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 LoadPluginsFromFile(const char *filepath, int &skipped);
73 LoadVDFPluginsFromDir(const char *dir, int &skipped);
77 CreateInterfaceFn factory;
80 static String mod_path;
81 static String metamod_path;
82 static String full_bin_path;
83 static int vsp_version = 0;
84 static int gamedll_version = 0;
85 static int engine_build = SOURCE_ENGINE_UNKNOWN;
86 static List<game_dll_t *> gamedll_list;
87 static bool is_gamedll_loaded = false;
88 static bool in_first_level = true;
89 static bool is_game_init = false;
90 static bool vsp_load_requested = false;
91 static bool vsp_loaded = false;
92 static game_dll_t gamedll_info;
93 static ConVar *metamod_version = NULL;
94 static ConVar *mm_pluginsfile = NULL;
95 static ConVar *mm_basedir = NULL;
96 static CreateInterfaceFn engine_factory = NULL;
97 static CreateInterfaceFn physics_factory = NULL;
98 static CreateInterfaceFn filesystem_factory = NULL;
99 static CGlobalVars *gpGlobals = NULL;
100 static CHookManagerAutoGen g_SH_HookManagerAutoGen(&g_SourceHook);
101 static META_RES last_meta_res;
102 static IServerPluginCallbacks *vsp_callbacks = NULL;
103 static bool were_plugins_loaded = false;
104 static bool g_bIsVspBridged = false;
106 MetamodSource g_Metamod;
107 PluginId g_PLID = Pl_Console;
108 CSourceHookImpl g_SourceHook;
109 ISourceHook *g_SHPtr = &g_SourceHook;
110 SourceMM::ISmmAPI *g_pMetamod = &g_Metamod;
113 #define IFACE_MACRO(orig,nam) \
114 CPluginManager::CPlugin *pl; \
115 SourceHook::List<IMetamodListener *>::iterator event; \
116 IMetamodListener *api; \
119 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
121 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
123 mret = IFACE_FAILED; \
124 if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
125 if (ret) *ret = mret; \
130 return (orig)(iface, ret);
132 #define ITER_EVENT(evn, args) \
133 CPluginManager::CPlugin *pl; \
134 SourceHook::List<IMetamodListener *>::iterator event; \
135 IMetamodListener *api; \
136 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
138 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
144 /* Initialize everything here */
146 mm_InitializeForLoad()
148 char full_path[PATH_SIZE] = {0};
149 GetFileOfAddress((void *)gamedll_info.factory, full_path, sizeof(full_path));
150 full_bin_path.assign(full_path);
152 /* Like Metamod, reload plugins at the end of the map.
153 * This is so plugins can hook everything on load, BUT, new plugins will be reloaded
154 * if the server is shut down (silly, but rare case).
156 in_first_level = true;
158 SourceHook::MemFuncInfo info;
160 if (!provider->GetHookInfo(ProvidedHook_GameInit, &info))
162 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::GameInit");
164 SH_MANUALHOOK_RECONFIGURE(SGD_GameInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
165 SH_ADD_MANUALHOOK_STATICFUNC(SGD_GameInit, server, Handler_GameInit, false);
167 if (!provider->GetHookInfo(ProvidedHook_LevelInit, &info))
169 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelInit");
171 SH_MANUALHOOK_RECONFIGURE(SGD_LevelInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
172 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelInit, server, Handler_LevelInit, true);
174 if (!provider->GetHookInfo(ProvidedHook_LevelShutdown, &info))
176 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelShutdown");
178 SH_MANUALHOOK_RECONFIGURE(SGD_LevelShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
179 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelShutdown, server, Handler_LevelShutdown, true);
183 mm_DetectGameInformation()
185 char mm_path[PATH_SIZE];
186 char game_path[PATH_SIZE];
188 /* Get path to SourceMM DLL */
189 if (!GetFileOfAddress((void *)mm_InitializeForLoad, mm_path, sizeof(mm_path)))
194 metamod_path.assign(mm_path);
196 /* Get value of -game from command line, defaulting to hl2 as engine seems to do */
197 const char *game_dir = provider->GetCommandLineValue("-game", "hl2");
199 /* Get absolute path */
200 abspath(game_path, game_dir);
201 mod_path.assign(game_path);
203 engine_build = provider->DetermineSourceEngine(game_dir);;
209 ServerFactory(const char *iface, int *ret)
211 IFACE_MACRO(gamedll_info.factory, GameDLL);
215 CreateInterface(const char *iface, int *ret)
219 if (!mm_IsVspBridged() && strncmp(iface, "ISERVERPLUGINCALLBACKS", 22) == 0)
221 if (vsp_callbacks != NULL)
228 vsp_version = atoi(&iface[22]);
229 ptr = provider->GetVSPCallbacks(vsp_version);
236 *ret = (ptr != NULL) ? IFACE_OK : IFACE_FAILED;
242 LoadPluginsFromFile(const char *filepath, int &skipped)
251 fp = fopen(filepath, "rt");
257 char buffer[255], error[255], full_path[PATH_SIZE];
258 const char *ptr, *ext, *file;
260 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
262 UTIL_TrimLeft(buffer);
263 UTIL_TrimRight(buffer);
265 length = strlen(buffer);
271 if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
277 if (buffer[0] == '"')
300 while (*cptr && isspace(*cptr))
305 UTIL_TrimRight(cptr);
306 if (*cptr && isalpha(*cptr))
308 g_PluginMngr.SetAlias(buffer, cptr);
320 /* First find if it's an absolute path or not... */
321 if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
323 /* If we're in an absolute path, ignore our normal heuristics */
324 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
325 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
327 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
339 /* Attempt to find a file extension */
340 ptr = UTIL_GetExtension(file);
341 /* Add an extension if there's none there */
344 #if defined WIN32 || defined _WIN32
354 /* Format the new path */
355 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s%s", mod_path.c_str(), file, ext);
356 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
357 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
359 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
381 char engine_file[PATH_SIZE];
382 char engine_path[PATH_SIZE];
383 char rel_path[PATH_SIZE * 2];
385 GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
387 /* Chop off the "engine" file part */
388 len = strlen(engine_file);
389 for (size_t i = len - 1; i >= 0 && i < len; i--)
391 if (engine_file[i] == '/' || engine_file[i] == '\\')
393 engine_file[i] = '\0';
397 abspath(engine_path, engine_file);
399 const char *usepath = metamod_path.c_str();
400 if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
405 char command[PATH_SIZE * 2];
406 UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
407 provider->ServerCommand(command);
410 /* Wrapper function. This is called when the GameDLL thinks it's using
411 * the engine's real engineFactory.
414 EngineFactory(const char *iface, int *ret)
416 IFACE_MACRO(engine_factory, Engine);
419 /* Wrapper function. This is called when the GameDLL thinks it's using
420 * the engine's real physicsFactory.
423 PhysicsFactory(const char *iface, int *ret)
425 IFACE_MACRO(physics_factory, Physics);
428 /* Wrapper function. This is called when the GameDLL thinks it's using
429 * the engine's real fileSystemFactory.
432 FileSystemFactory(const char *iface, int *ret)
434 IFACE_MACRO(filesystem_factory, FileSystem);
438 mm_LogMessage(const char *msg, ...)
441 static char buffer[2048];
444 size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
447 buffer[len++] = '\n';
450 if (!provider->LogMessage(buffer))
452 fprintf(stdout, "%s", buffer);
457 DoInitialPluginLoads()
459 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
460 const char *mmBaseDir = provider->GetCommandLineValue("mm_basedir", NULL);
463 pluginFile = provider->GetConVarString(mm_pluginsfile);
464 if (pluginFile == NULL)
466 pluginFile = "addons/metamod/metaplugins.ini";
471 mmBaseDir = provider->GetConVarString(mm_basedir);
472 if (mmBaseDir == NULL)
474 mmBaseDir = "addons/metamod";
478 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
480 g_Metamod.PathFormat(filepath, sizeof(filepath), "%s/%s", mod_path.c_str(), pluginFile);
481 g_Metamod.PathFormat(vdfpath, sizeof(vdfpath), "%s/%s", mod_path.c_str(), mmBaseDir);
482 mm_LoadPlugins(filepath, vdfpath);
486 mm_StartupMetamod(bool is_vsp_load)
494 is_vsp_load ? "V" : "");
496 metamod_version = provider->CreateConVar("metamod_version",
498 "Metamod:Source Version",
499 ConVarFlag_Notify|ConVarFlag_SpOnly);
501 provider->SetConVarString(metamod_version, buffer);
503 mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
504 #if defined WIN32 || defined _WIN32
505 "addons\\metamod\\metaplugins.ini",
507 "addons/metamod/metaplugins.ini",
509 "Metamod:Source Plugins File",
512 mm_basedir = provider->CreateConVar("mm_basedir",
513 #if defined __linux__
518 "Metamod:Source Base Folder",
521 g_bIsVspBridged = is_vsp_load;
525 DoInitialPluginLoads();
526 in_first_level = true;
531 mm_InitializeGlobals(CreateInterfaceFn engineFactory,
532 CreateInterfaceFn physicsFactory,
533 CreateInterfaceFn filesystemFactory,
534 CGlobalVars *pGlobals)
536 engine_factory = engineFactory;
537 physics_factory = physicsFactory;
538 filesystem_factory = filesystemFactory;
539 gpGlobals = pGlobals;
540 provider->Notify_DLLInit_Pre(engineFactory, gamedll_info.factory);
549 if (vsp_load_requested)
552 if (g_bIsVspBridged && !were_plugins_loaded)
554 DoInitialPluginLoads();
555 g_PluginMngr.SetAllLoaded();
556 were_plugins_loaded = true;
561 RETURN_META_VALUE(MRES_IGNORED, true);
568 g_PluginMngr.UnloadAll();
570 provider->Notify_DLLShutdown_Pre();
572 g_SourceHook.CompleteShutdown();
576 Handler_LevelShutdown(void)
578 if (g_bIsVspBridged && !were_plugins_loaded)
580 g_PluginMngr.SetAllLoaded();
581 DoInitialPluginLoads();
582 were_plugins_loaded = true;
583 in_first_level = true;
588 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
590 g_Metamod.PathFormat(filepath,
594 provider->GetConVarString(mm_pluginsfile));
595 g_Metamod.PathFormat(vdfpath,
599 provider->GetConVarString(mm_basedir));
600 mm_LoadPlugins(filepath, vdfpath);
604 in_first_level = false;
607 ITER_EVENT(OnLevelShutdown, ());
609 RETURN_META(MRES_IGNORED);
613 Handler_LevelInit(char const *pMapName,
614 char const *pMapEntities,
615 char const *pOldLevel,
616 char const *pLandmarkName,
620 ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
622 RETURN_META_VALUE(MRES_IGNORED, false);
625 void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
631 UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
634 mm_LogMessage("[%s] %s", pl->GetLogTag(), buffer);
637 CreateInterfaceFn MetamodSource::GetEngineFactory(bool syn/* =true */)
640 return EngineFactory;
641 return engine_factory;
644 CreateInterfaceFn MetamodSource::GetPhysicsFactory(bool syn/* =true */)
647 return PhysicsFactory;
648 return physics_factory;
651 CreateInterfaceFn MetamodSource::GetFileSystemFactory(bool syn/* =true */)
654 return FileSystemFactory;
655 return filesystem_factory;
658 CreateInterfaceFn MetamodSource::GetServerFactory(bool syn/* =true */)
661 return ServerFactory;
662 return gamedll_info.factory;
665 CGlobalVars *MetamodSource::GetCGlobals()
670 void MetamodSource::SetLastMetaReturn(META_RES res)
675 META_RES MetamodSource::GetLastMetaReturn()
677 return last_meta_res;
680 void MetamodSource::ConPrint(const char *str)
682 provider->ConsolePrint(str);
685 void MetamodSource::ConPrintf(const char *fmt, ...)
691 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
694 provider->ConsolePrint(buffer);
697 void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
699 major = METAMOD_API_MAJOR;
700 minor = METAMOD_API_MINOR;
701 plvers = METAMOD_PLAPI_VERSION;
702 plmin = PLAPI_MIN_VERSION;
705 void MetamodSource::GetShVersions(int &shvers, int &shimpl)
707 shvers = SH_IFACE_VERSION;
708 shimpl = SH_IMPL_VERSION;
711 int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
713 int length = (int)strlen(iface);
717 for (i = length - 1; i >= 0; i--)
719 if (!isdigit(iface[i]))
729 if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
736 num = atoi(&(iface[++i]));
741 snprintf(&(iface[i]), 4, "%03d", num);
746 void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
748 char _if[256]; /* assume no interface goes beyond this */
749 size_t len = strlen(iface);
758 if (len + 4 > sizeof(_if))
771 if ((pf = (fn)(_if, ret)) != NULL)
779 } while ((num = FormatIface(_if, len+1)));
784 void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
786 char buffer[256]; /* assume no interface will go beyond this */
787 size_t len = strlen(iface);
788 int ret; /* just in case something doesn't handle NULL properly */
790 if (len > sizeof(buffer) - 4)
795 strcpy(buffer, iface);
799 char *ptr = &buffer[len - 1];
801 while (isdigit(*ptr) && digits <=3)
809 /* for now, assume this is an error */
810 strcpy(buffer, iface);
815 min = (min == 0) ? 1 : min;
816 snprintf(num, sizeof(num), "%03d", min);
821 return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
824 const char *MetamodSource::GetBaseDir()
826 return mod_path.c_str();
829 size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
833 size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
836 for (size_t i = 0; i < mylen; i++)
838 if (buffer[i] == ALT_SEP_CHAR)
840 buffer[i] = PATH_SEP_CHAR;
847 void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
853 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
856 provider->ClientConsolePrint(client, buffer);
859 void MetamodSource::EnableVSPListener()
861 if (is_game_init && !vsp_load_requested && !vsp_loaded)
864 vsp_load_requested = true;
867 int MetamodSource::GetVSPVersion()
872 int MetamodSource::GetGameDLLVersion()
874 return gamedll_version;
877 bool MetamodSource::RemotePrintingAvailable()
879 return provider->IsRemotePrintingAvailable();
882 void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
894 /* First check ours... we get first chance! */
895 if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
901 return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
903 else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
909 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
911 else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
917 return static_cast<void *>(static_cast<SourceHook::IHookManagerAutoGen *>(&g_SH_HookManagerAutoGen));
920 CPluginManager::CPlugin *pl;
921 List<IMetamodListener *>::iterator event;
922 IMetamodListener *api;
926 for (PluginIter iter = g_PluginMngr._begin();
927 iter != g_PluginMngr._end();
931 for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
934 subret = IFACE_FAILED;
935 if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
958 void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
960 CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
962 pl->m_Events.push_back(pListener);
965 const char *MetamodSource::GetGameBinaryPath()
967 return full_bin_path.c_str();
970 const char *MetamodSource::GetPluginsFile()
972 return provider->GetConVarString(mm_pluginsfile);
975 const char *MetamodSource::GetVDFDir()
977 return provider->GetConVarString(mm_basedir);
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, bool &skipped)
1117 char alias[24], file[255], full_path[255], error[255];
1119 if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias)))
1125 if (alias[0] != '\0')
1126 g_PluginMngr.SetAlias(alias, file);
1128 /* Attempt to find a file extension */
1129 if (UTIL_GetExtension(file) == NULL)
1131 g_pMetamod->PathFormat(full_path,
1134 g_pMetamod->GetBaseDir(),
1136 #if defined WIN32 || defined _WIN32
1145 g_pMetamod->PathFormat(full_path,
1148 g_pMetamod->GetBaseDir(),
1152 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
1154 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1156 mm_LogMessage("[META] Failed to load plugin %s: %s", file, error);
1164 LoadVDFPluginsFromDir(const char *dir, int &skipped)
1168 char path[MAX_PATH];
1169 char relpath[MAX_PATH * 2];
1173 #if defined _MSC_VER
1178 g_Metamod.PathFormat(path, sizeof(path), "%s\\*.vdf", dir);
1179 if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
1181 DWORD dw = GetLastError();
1182 if (dw == ERROR_FILE_NOT_FOUND)
1185 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
1188 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1192 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
1198 g_Metamod.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
1199 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1200 success = ProcessVDF(relpath, skip);
1205 } while (FindNextFile(hFind, &fd));
1210 struct dirent *pEnt;
1213 if ((pDir = opendir(dir)) == NULL)
1215 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
1219 while ((pEnt = readdir(pDir)) != NULL)
1221 if (strcmp(pEnt->d_name, ".") == 0
1222 || strcmp(pEnt->d_name, "..") == 0)
1226 extidx = strlen(pEnt->d_name) - 4;
1227 if (extidx < 0 || stricmp(&pEnt->d_name[extidx], ".vdf"))
1231 g_Metamod.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
1232 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1233 success = ProcessVDF(relpath, skip);
1247 mm_LoadPlugins(const char *filepath, const char *vdfpath)
1249 int total, skipped, fskipped, vskipped;
1252 total = LoadPluginsFromFile(filepath, fskipped);
1253 total += LoadVDFPluginsFromDir(vdfpath, vskipped);
1254 skipped = fskipped + vskipped;
1256 if (total == 0 || total > 1)
1260 mm_LogMessage("[META] Loaded %d plugin%s (%d already loaded)", total, s, skipped);
1262 mm_LogMessage("[META] Loaded %d plugin%s.", total, s);
1270 return g_bIsVspBridged;
1274 mm_IsVspLoadComplete()
1276 return were_plugins_loaded;