2 * vim: set ts=4 sw=4 tw=99 noet :
3 * ======================================================
5 * Copyright (C) 2004-2010 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 <versionlib.h>
32 #include "metamod_provider.h"
33 #include "metamod_plugins.h"
34 #include "metamod_util.h"
35 #include "metamod_console.h"
36 #include "provider/provider_ep2.h"
41 using namespace SourceMM;
42 using namespace SourceHook;
43 using namespace SourceHook::Impl;
46 * @brief Implementation of main SourceMM GameDLL functionality
50 SH_DECL_MANUALHOOK0(SGD_GameInit, 0, 0, 0, bool);
51 SH_DECL_MANUALHOOK6(SGD_LevelInit, 0, 0, 0, bool, const char *, const char *, const char *, const char *, bool, bool);
52 SH_DECL_MANUALHOOK0_void(SGD_LevelShutdown, 0, 0, 0);
55 Handler_LevelShutdown();
58 Handler_LevelInit(char const *pMapName,
59 char const *pMapEntities,
60 char const *pOldLevel,
61 char const *pLandmarkName,
72 LoadPluginsFromFile(const char *filepath, int &skipped);
75 LoadVDFPluginsFromDir(const char *dir, int &skipped);
79 CreateInterfaceFn factory;
82 static String mod_path;
83 static String metamod_path;
84 static String full_bin_path;
85 static int vsp_version = 0;
86 static int gamedll_version = 0;
87 static int engine_build = SOURCE_ENGINE_UNKNOWN;
88 static List<game_dll_t *> gamedll_list;
89 static bool is_gamedll_loaded = false;
90 static bool in_first_level = true;
91 static bool is_game_init = false;
92 static bool vsp_load_requested = false;
93 static bool vsp_loaded = false;
94 static game_dll_t gamedll_info;
95 static ConVar *metamod_version = NULL;
96 static ConVar *mm_pluginsfile = NULL;
97 static ConVar *mm_basedir = NULL;
98 static CreateInterfaceFn engine_factory = NULL;
99 static CreateInterfaceFn physics_factory = NULL;
100 static CreateInterfaceFn filesystem_factory = NULL;
101 static CGlobalVars *gpGlobals = NULL;
102 static CHookManagerAutoGen g_SH_HookManagerAutoGen(&g_SourceHook);
103 static META_RES last_meta_res;
104 static IServerPluginCallbacks *vsp_callbacks = NULL;
105 static bool were_plugins_loaded = false;
106 static bool g_bIsVspBridged = false;
108 MetamodSource g_Metamod;
109 PluginId g_PLID = Pl_Console;
110 CSourceHookImpl g_SourceHook;
111 ISourceHook *g_SHPtr = &g_SourceHook;
112 SourceMM::ISmmAPI *g_pMetamod = &g_Metamod;
115 #define IFACE_MACRO(orig,nam) \
116 CPluginManager::CPlugin *pl; \
117 SourceHook::List<IMetamodListener *>::iterator event; \
118 IMetamodListener *api; \
121 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
123 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
125 mret = IFACE_FAILED; \
126 if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
127 if (ret) *ret = mret; \
132 return (orig)(iface, ret);
134 #define ITER_EVENT(evn, args) \
135 CPluginManager::CPlugin *pl; \
136 SourceHook::List<IMetamodListener *>::iterator event; \
137 IMetamodListener *api; \
138 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
140 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
146 /* Initialize everything here */
148 mm_InitializeForLoad()
150 char full_path[PATH_SIZE] = {0};
151 GetFileOfAddress((void *)gamedll_info.factory, full_path, sizeof(full_path));
152 full_bin_path.assign(full_path);
154 /* Like Metamod, reload plugins at the end of the map.
155 * This is so plugins can hook everything on load, BUT, new plugins will be reloaded
156 * if the server is shut down (silly, but rare case).
158 in_first_level = true;
160 SourceHook::MemFuncInfo info;
162 if (!provider->GetHookInfo(ProvidedHook_GameInit, &info))
164 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::GameInit");
166 SH_MANUALHOOK_RECONFIGURE(SGD_GameInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
167 SH_ADD_MANUALHOOK_STATICFUNC(SGD_GameInit, server, Handler_GameInit, false);
169 if (!provider->GetHookInfo(ProvidedHook_LevelInit, &info))
171 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelInit");
173 SH_MANUALHOOK_RECONFIGURE(SGD_LevelInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
174 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelInit, server, Handler_LevelInit, true);
176 if (!provider->GetHookInfo(ProvidedHook_LevelShutdown, &info))
178 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelShutdown");
180 SH_MANUALHOOK_RECONFIGURE(SGD_LevelShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
181 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelShutdown, server, Handler_LevelShutdown, true);
185 mm_DetectGameInformation()
187 char game_path[PATH_SIZE];
189 /* Get value of -game from command line, defaulting to hl2 as engine seems to do */
190 const char *game_dir = provider->GetCommandLineValue("-game");
194 /* Get absolute path */
195 abspath(game_path, game_dir);
199 /* Get absolute path for current directory */
200 abspath(game_path, ".");
203 mod_path.assign(game_path);
205 engine_build = provider->DetermineSourceEngine(game_dir);
211 ServerFactory(const char *iface, int *ret)
213 IFACE_MACRO(gamedll_info.factory, GameDLL);
217 LoadPluginsFromFile(const char *filepath, int &skipped)
226 fp = fopen(filepath, "rt");
232 char buffer[255], error[255], full_path[PATH_SIZE];
235 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
237 UTIL_TrimLeft(buffer);
238 UTIL_TrimRight(buffer);
240 length = strlen(buffer);
246 if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
252 if (buffer[0] == '"')
275 while (*cptr && isspace(*cptr))
280 UTIL_TrimRight(cptr);
281 if (*cptr && isalpha(*cptr))
283 g_PluginMngr.SetAlias(buffer, cptr);
296 g_Metamod.GetFullPluginPath(file, full_path, sizeof(full_path));
298 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
299 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
301 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
322 char engine_file[PATH_SIZE];
323 char engine_path[PATH_SIZE];
324 char rel_path[PATH_SIZE * 2];
326 GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
328 /* Chop off the "engine" file part */
329 len = strlen(engine_file);
330 for (size_t i = len - 1; i < len; i--)
332 if (engine_file[i] == '/' || engine_file[i] == '\\')
334 engine_file[i] = '\0';
338 abspath(engine_path, engine_file);
340 const char *usepath = metamod_path.c_str();
341 if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
346 char command[PATH_SIZE * 2];
347 UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
348 provider->ServerCommand(command);
351 /* Wrapper function. This is called when the GameDLL thinks it's using
352 * the engine's real engineFactory.
355 EngineFactory(const char *iface, int *ret)
357 IFACE_MACRO(engine_factory, Engine);
360 /* Wrapper function. This is called when the GameDLL thinks it's using
361 * the engine's real physicsFactory.
364 PhysicsFactory(const char *iface, int *ret)
366 IFACE_MACRO(physics_factory, Physics);
369 /* Wrapper function. This is called when the GameDLL thinks it's using
370 * the engine's real fileSystemFactory.
373 FileSystemFactory(const char *iface, int *ret)
375 IFACE_MACRO(filesystem_factory, FileSystem);
379 mm_LogMessage(const char *msg, ...)
382 static char buffer[2048];
385 size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
388 buffer[len++] = '\n';
391 if (!provider->LogMessage(buffer))
393 fprintf(stdout, "%s", buffer);
398 DoInitialPluginLoads()
400 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
401 const char *mmBaseDir = provider->GetCommandLineValue("mm_basedir", NULL);
404 pluginFile = provider->GetConVarString(mm_pluginsfile);
405 if (pluginFile == NULL)
407 pluginFile = "addons/metamod/metaplugins.ini";
412 mmBaseDir = provider->GetConVarString(mm_basedir);
413 if (mmBaseDir == NULL)
415 mmBaseDir = "addons/metamod";
419 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
421 g_Metamod.PathFormat(filepath, sizeof(filepath), "%s/%s", mod_path.c_str(), pluginFile);
422 g_Metamod.PathFormat(vdfpath, sizeof(vdfpath), "%s/%s", mod_path.c_str(), mmBaseDir);
423 mm_LoadPlugins(filepath, vdfpath);
427 mm_StartupMetamod(bool is_vsp_load)
435 is_vsp_load ? "V" : "");
437 metamod_version = provider->CreateConVar("metamod_version",
439 "Metamod:Source Version",
440 ConVarFlag_Notify|ConVarFlag_SpOnly);
442 provider->SetConVarString(metamod_version, buffer);
444 mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
445 #if defined WIN32 || defined _WIN32
446 "addons\\metamod\\metaplugins.ini",
448 "addons/metamod/metaplugins.ini",
450 "Metamod:Source Plugins File",
453 mm_basedir = provider->CreateConVar("mm_basedir",
454 #if defined __linux__ || defined __APPLE__
459 "Metamod:Source Base Folder",
462 g_bIsVspBridged = is_vsp_load;
466 DoInitialPluginLoads();
467 in_first_level = true;
472 mm_InitializeGlobals(CreateInterfaceFn engineFactory,
473 CreateInterfaceFn physicsFactory,
474 CreateInterfaceFn filesystemFactory,
475 CGlobalVars *pGlobals)
477 engine_factory = engineFactory;
478 physics_factory = physicsFactory;
479 filesystem_factory = filesystemFactory;
480 gpGlobals = pGlobals;
481 provider->Notify_DLLInit_Pre(engineFactory, gamedll_info.factory);
490 if (vsp_load_requested)
493 if (g_bIsVspBridged && !were_plugins_loaded)
495 DoInitialPluginLoads();
496 g_PluginMngr.SetAllLoaded();
497 were_plugins_loaded = true;
502 RETURN_META_VALUE(MRES_IGNORED, true);
509 g_PluginMngr.UnloadAll();
511 provider->Notify_DLLShutdown_Pre();
513 g_SourceHook.CompleteShutdown();
517 Handler_LevelShutdown(void)
519 if (g_bIsVspBridged && !were_plugins_loaded)
521 DoInitialPluginLoads();
522 g_PluginMngr.SetAllLoaded();
523 were_plugins_loaded = true;
524 in_first_level = true;
529 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
531 g_Metamod.PathFormat(filepath,
535 provider->GetConVarString(mm_pluginsfile));
536 g_Metamod.PathFormat(vdfpath,
540 provider->GetConVarString(mm_basedir));
541 mm_LoadPlugins(filepath, vdfpath);
545 in_first_level = false;
548 ITER_EVENT(OnLevelShutdown, ());
550 RETURN_META(MRES_IGNORED);
554 Handler_LevelInit(char const *pMapName,
555 char const *pMapEntities,
556 char const *pOldLevel,
557 char const *pLandmarkName,
561 ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
563 RETURN_META_VALUE(MRES_IGNORED, false);
566 void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
572 UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
575 mm_LogMessage("[%s] %s", pl->GetLogTag(), buffer);
578 CreateInterfaceFn MetamodSource::GetEngineFactory(bool syn/* =true */)
581 return EngineFactory;
582 return engine_factory;
585 CreateInterfaceFn MetamodSource::GetPhysicsFactory(bool syn/* =true */)
588 return PhysicsFactory;
589 return physics_factory;
592 CreateInterfaceFn MetamodSource::GetFileSystemFactory(bool syn/* =true */)
595 return FileSystemFactory;
596 return filesystem_factory;
599 CreateInterfaceFn MetamodSource::GetServerFactory(bool syn/* =true */)
602 return ServerFactory;
603 return gamedll_info.factory;
606 CGlobalVars *MetamodSource::GetCGlobals()
611 void MetamodSource::SetLastMetaReturn(META_RES res)
616 META_RES MetamodSource::GetLastMetaReturn()
618 return last_meta_res;
621 void MetamodSource::ConPrint(const char *str)
623 provider->ConsolePrint(str);
626 void MetamodSource::ConPrintf(const char *fmt, ...)
632 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
635 provider->ConsolePrint(buffer);
638 void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
640 major = METAMOD_API_MAJOR;
641 minor = METAMOD_API_MINOR;
642 plvers = METAMOD_PLAPI_VERSION;
643 plmin = PLAPI_MIN_VERSION;
646 void MetamodSource::GetShVersions(int &shvers, int &shimpl)
648 shvers = SH_IFACE_VERSION;
649 shimpl = SH_IMPL_VERSION;
652 int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
654 int length = (int)strlen(iface);
658 for (i = length - 1; i >= 0; i--)
660 if (!isdigit(iface[i]))
670 if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
677 num = atoi(&(iface[++i]));
682 snprintf(&(iface[i]), 4, "%03d", num);
687 void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
689 char _if[256]; /* assume no interface goes beyond this */
690 size_t len = strlen(iface);
699 if (len + 4 > sizeof(_if))
712 if ((pf = (fn)(_if, ret)) != NULL)
720 } while ((num = FormatIface(_if, len+1)));
725 void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
727 char buffer[256]; /* assume no interface will go beyond this */
728 size_t len = strlen(iface);
729 int ret; /* just in case something doesn't handle NULL properly */
731 if (len > sizeof(buffer) - 4)
736 strcpy(buffer, iface);
740 char *ptr = &buffer[len - 1];
742 while (isdigit(*ptr) && digits <=3)
750 /* for now, assume this is an error */
751 strcpy(buffer, iface);
756 min = (min == 0) ? 1 : min;
757 snprintf(num, sizeof(num), "%03d", min);
762 return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
765 const char *MetamodSource::GetBaseDir()
767 return mod_path.c_str();
770 size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
774 size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
777 for (size_t i = 0; i < mylen; i++)
779 if (buffer[i] == ALT_SEP_CHAR)
781 buffer[i] = PATH_SEP_CHAR;
788 #if SOURCE_ENGINE == SE_DOTA
789 void MetamodSource::ClientConPrintf(int clientIndex, const char *fmt, ...)
795 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
798 ClientConPrintf((edict_t *)(gpGlobals->pEdicts + clientIndex), "%s", buffer);
802 void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
808 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
811 provider->ClientConsolePrint(client, buffer);
814 void MetamodSource::EnableVSPListener()
816 if (is_game_init && !vsp_load_requested && !vsp_loaded)
821 vsp_load_requested = true;
824 int MetamodSource::GetVSPVersion()
829 int MetamodSource::GetGameDLLVersion()
831 return gamedll_version;
834 bool MetamodSource::RemotePrintingAvailable()
836 return provider->IsRemotePrintingAvailable();
839 void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
851 /* First check ours... we get first chance! */
852 if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
858 return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
860 else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
866 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
868 else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
874 return static_cast<void *>(static_cast<SourceHook::IHookManagerAutoGen *>(&g_SH_HookManagerAutoGen));
877 CPluginManager::CPlugin *pl;
878 List<IMetamodListener *>::iterator event;
879 IMetamodListener *api;
883 for (PluginIter iter = g_PluginMngr._begin();
884 iter != g_PluginMngr._end();
888 for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
891 subret = IFACE_FAILED;
892 if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
915 void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
917 CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
919 pl->m_Events.push_back(pListener);
922 const char *MetamodSource::GetGameBinaryPath()
924 return full_bin_path.c_str();
927 const char *MetamodSource::GetPluginsFile()
929 return provider->GetConVarString(mm_pluginsfile);
932 const char *MetamodSource::GetVDFDir()
934 return provider->GetConVarString(mm_basedir);
937 IConCommandBaseAccessor *MetamodSource::GetCvarBaseAccessor()
939 return provider->GetConCommandBaseAccessor();
942 bool MetamodSource::RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
944 if (provider->IsConCommandBaseACommand(pCommand))
946 g_PluginMngr.AddPluginCmd(plugin, pCommand);
950 g_PluginMngr.AddPluginCvar(plugin, pCommand);
953 return provider->RegisterConCommandBase(pCommand);
956 void MetamodSource::UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
958 if (provider->IsConCommandBaseACommand(pCommand))
960 g_PluginMngr.RemovePluginCmd(plugin, pCommand);
964 g_PluginMngr.RemovePluginCvar(plugin, pCommand);
967 CPluginManager::CPlugin *pOrig = g_PluginMngr.FindByAPI(plugin);
968 UnregisterConCommandBase(pOrig ? pOrig->m_Id : 0, pCommand);
971 void MetamodSource::UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand)
974 CPluginManager::CPlugin *pPlugin;
975 List<IMetamodListener *>::iterator event;
976 IMetamodListener *pML;
977 for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
980 if (pPlugin->m_Status < Pl_Paused)
984 /* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
985 if (pPlugin->m_API->GetApiVersion() < 12)
989 for (event=pPlugin->m_Events.begin();
990 event!=pPlugin->m_Events.end();
994 pML->OnUnlinkConCommandBase(id, pCommand);
998 return provider->UnregisterConCommandBase(pCommand);
1001 int MetamodSource::GetUserMessageCount()
1003 return provider->GetUserMessageCount();
1006 int MetamodSource::FindUserMessage(const char *name, int *size/* =NULL */)
1008 return provider->FindUserMessage(name, size);
1011 const char *MetamodSource::GetUserMessage(int index, int *size/* =NULL */)
1013 return provider->GetUserMessage(index, size);
1016 int MetamodSource::GetSourceEngineBuild()
1018 return engine_build;
1021 void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks, int version)
1024 vsp_version = version;
1026 vsp_callbacks = callbacks;
1027 ITER_EVENT(OnVSPListening, (callbacks));
1029 if (is_gamedll_loaded)
1032 * MM:S is loaded as a game DLL so we need to set these for mm_IsVspBridged() and
1033 * mm_IsVspLoadComplete()
1035 g_bIsVspBridged = true;
1036 were_plugins_loaded = true;
1040 IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion)
1044 *pVersion = vsp_version;
1047 return vsp_callbacks;
1050 size_t MetamodSource::Format(char *buffer, size_t maxlength, const char *format, ...)
1055 va_start(ap, format);
1056 result = FormatArgs(buffer, maxlength, format, ap);
1062 size_t MetamodSource::FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap)
1064 return UTIL_FormatArgs(buffer, maxlength, format, ap);
1067 bool MetamodSource::IsLoadedAsGameDLL()
1069 return is_gamedll_loaded;
1072 void MetamodSource::SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded)
1074 gamedll_info.factory = serverFactory;
1075 gamedll_version = version;
1076 is_gamedll_loaded = loaded;
1079 void MetamodSource::SetVSPListener(const char *path)
1081 metamod_path.assign(path);
1084 size_t MetamodSource::GetFullPluginPath(const char *plugin, char *buffer, size_t len)
1086 const char *pext, *ext;
1089 /* First find if it's an absolute path or not... */
1090 if (plugin[0] == '/' || strncmp(&(plugin[1]), ":\\", 2) == 0)
1092 return UTIL_Format(buffer, len, plugin);
1095 /* Attempt to find a file extension */
1096 pext = UTIL_GetExtension(plugin);
1097 /* Add an extension if there's none there */
1100 #if defined WIN32 || defined _WIN32
1102 #elif defined __APPLE__
1113 /* Format the new path */
1114 num = PathFormat(buffer, len, "%s/%s%s", mod_path.c_str(), plugin, ext);
1116 #if defined __linux__
1117 /* If path was passed without extension and it doesn't exist with "_i486.so" try ".so" */
1119 if (!pext && stat(buffer, &s) != 0)
1121 num = PathFormat(buffer, len, "%s/%s.so", mod_path.c_str(), plugin);
1129 ProcessVDF(const char *path, bool &skipped)
1133 char alias[24], file[255], full_path[255], error[255];
1135 if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias)))
1141 if (alias[0] != '\0')
1142 g_PluginMngr.SetAlias(alias, file);
1144 g_Metamod.GetFullPluginPath(file, full_path, sizeof(full_path));
1146 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
1148 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1150 mm_LogMessage("[META] Failed to load plugin %s: %s", file, error);
1158 LoadVDFPluginsFromDir(const char *dir, int &skipped)
1162 char path[MAX_PATH];
1163 char relpath[MAX_PATH * 2];
1167 #if defined _MSC_VER
1172 g_Metamod.PathFormat(path, sizeof(path), "%s\\*.vdf", dir);
1173 if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
1175 DWORD dw = GetLastError();
1176 if (dw == ERROR_FILE_NOT_FOUND)
1179 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
1182 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1186 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
1192 g_Metamod.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
1193 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1194 success = ProcessVDF(relpath, skip);
1199 } while (FindNextFile(hFind, &fd));
1204 struct dirent *pEnt;
1207 if ((pDir = opendir(dir)) == NULL)
1209 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
1213 while ((pEnt = readdir(pDir)) != NULL)
1215 if (strcmp(pEnt->d_name, ".") == 0
1216 || strcmp(pEnt->d_name, "..") == 0)
1220 extidx = strlen(pEnt->d_name) - 4;
1221 if (extidx < 0 || stricmp(&pEnt->d_name[extidx], ".vdf"))
1225 g_Metamod.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
1226 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1227 success = ProcessVDF(relpath, skip);
1241 mm_LoadPlugins(const char *filepath, const char *vdfpath)
1243 int total, skipped, fskipped, vskipped;
1246 total = LoadPluginsFromFile(filepath, fskipped);
1247 total += LoadVDFPluginsFromDir(vdfpath, vskipped);
1248 skipped = fskipped + vskipped;
1250 if (total == 0 || total > 1)
1254 mm_LogMessage("[META] Loaded %d plugin%s (%d already loaded)", total, s, skipped);
1256 mm_LogMessage("[META] Loaded %d plugin%s.", total, s);
1264 return g_bIsVspBridged;
1268 mm_IsVspLoadComplete()
1270 return were_plugins_loaded;