Triggering build to test buildbot.
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 "metamod_provider.h"
32 #include "metamod_plugins.h"
33 #include "metamod_util.h"
34 #include "metamod_console.h"
35 #include "provider/provider_ep2.h"
40 using namespace SourceMM;
41 using namespace SourceHook;
42 using namespace SourceHook::Impl;
45 * @brief Implementation of main SourceMM GameDLL functionality
49 SH_DECL_MANUALHOOK0(SGD_GameInit, 0, 0, 0, bool);
50 SH_DECL_MANUALHOOK6(SGD_LevelInit, 0, 0, 0, bool, const char *, const char *, const char *, const char *, bool, bool);
51 SH_DECL_MANUALHOOK0_void(SGD_LevelShutdown, 0, 0, 0);
54 Handler_LevelShutdown();
57 Handler_LevelInit(char const *pMapName,
58 char const *pMapEntities,
59 char const *pOldLevel,
60 char const *pLandmarkName,
71 LoadPluginsFromFile(const char *filepath, int &skipped);
74 LoadVDFPluginsFromDir(const char *dir, int &skipped);
78 CreateInterfaceFn factory;
81 static String mod_path;
82 static String metamod_path;
83 static String full_bin_path;
84 static int vsp_version = 0;
85 static int gamedll_version = 0;
86 static int engine_build = SOURCE_ENGINE_UNKNOWN;
87 static List<game_dll_t *> gamedll_list;
88 static bool is_gamedll_loaded = false;
89 static bool in_first_level = true;
90 static bool is_game_init = false;
91 static bool vsp_load_requested = false;
92 static bool vsp_loaded = false;
93 static game_dll_t gamedll_info;
94 static ConVar *metamod_version = NULL;
95 static ConVar *mm_pluginsfile = NULL;
96 static ConVar *mm_basedir = NULL;
97 static CreateInterfaceFn engine_factory = NULL;
98 static CreateInterfaceFn physics_factory = NULL;
99 static CreateInterfaceFn filesystem_factory = NULL;
100 static CGlobalVars *gpGlobals = NULL;
101 static CHookManagerAutoGen g_SH_HookManagerAutoGen(&g_SourceHook);
102 static META_RES last_meta_res;
103 static IServerPluginCallbacks *vsp_callbacks = NULL;
104 static bool were_plugins_loaded = false;
105 static bool g_bIsVspBridged = false;
107 MetamodSource g_Metamod;
108 PluginId g_PLID = Pl_Console;
109 CSourceHookImpl g_SourceHook;
110 ISourceHook *g_SHPtr = &g_SourceHook;
111 SourceMM::ISmmAPI *g_pMetamod = &g_Metamod;
114 #define IFACE_MACRO(orig,nam) \
115 CPluginManager::CPlugin *pl; \
116 SourceHook::List<IMetamodListener *>::iterator event; \
117 IMetamodListener *api; \
120 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
122 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
124 mret = IFACE_FAILED; \
125 if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
126 if (ret) *ret = mret; \
131 return (orig)(iface, ret);
133 #define ITER_EVENT(evn, args) \
134 CPluginManager::CPlugin *pl; \
135 SourceHook::List<IMetamodListener *>::iterator event; \
136 IMetamodListener *api; \
137 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
139 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
145 /* Initialize everything here */
147 mm_InitializeForLoad()
149 char full_path[PATH_SIZE] = {0};
150 GetFileOfAddress((void *)gamedll_info.factory, full_path, sizeof(full_path));
151 full_bin_path.assign(full_path);
153 /* Like Metamod, reload plugins at the end of the map.
154 * This is so plugins can hook everything on load, BUT, new plugins will be reloaded
155 * if the server is shut down (silly, but rare case).
157 in_first_level = true;
159 SourceHook::MemFuncInfo info;
161 if (!provider->GetHookInfo(ProvidedHook_GameInit, &info))
163 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::GameInit");
165 SH_MANUALHOOK_RECONFIGURE(SGD_GameInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
166 SH_ADD_MANUALHOOK_STATICFUNC(SGD_GameInit, server, Handler_GameInit, false);
168 if (!provider->GetHookInfo(ProvidedHook_LevelInit, &info))
170 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelInit");
172 SH_MANUALHOOK_RECONFIGURE(SGD_LevelInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
173 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelInit, server, Handler_LevelInit, true);
175 if (!provider->GetHookInfo(ProvidedHook_LevelShutdown, &info))
177 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelShutdown");
179 SH_MANUALHOOK_RECONFIGURE(SGD_LevelShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
180 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelShutdown, server, Handler_LevelShutdown, true);
184 mm_DetectGameInformation()
186 char game_path[PATH_SIZE];
188 /* Get value of -game from command line, defaulting to hl2 as engine seems to do */
189 const char *game_dir = provider->GetCommandLineValue("-game");
193 /* Get absolute path */
194 abspath(game_path, game_dir);
198 /* Get absolute path for current directory */
199 abspath(game_path, ".");
202 mod_path.assign(game_path);
204 engine_build = provider->DetermineSourceEngine(game_dir);
210 ServerFactory(const char *iface, int *ret)
212 IFACE_MACRO(gamedll_info.factory, GameDLL);
216 LoadPluginsFromFile(const char *filepath, int &skipped)
225 fp = fopen(filepath, "rt");
231 char buffer[255], error[255], full_path[PATH_SIZE];
234 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
236 UTIL_TrimLeft(buffer);
237 UTIL_TrimRight(buffer);
239 length = strlen(buffer);
245 if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
251 if (buffer[0] == '"')
274 while (*cptr && isspace(*cptr))
279 UTIL_TrimRight(cptr);
280 if (*cptr && isalpha(*cptr))
282 g_PluginMngr.SetAlias(buffer, cptr);
295 g_Metamod.GetFullPluginPath(file, full_path, sizeof(full_path));
297 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
298 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
300 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
321 char engine_file[PATH_SIZE];
322 char engine_path[PATH_SIZE];
323 char rel_path[PATH_SIZE * 2];
325 GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
327 /* Chop off the "engine" file part */
328 len = strlen(engine_file);
329 for (size_t i = len - 1; i < len; i--)
331 if (engine_file[i] == '/' || engine_file[i] == '\\')
333 engine_file[i] = '\0';
337 abspath(engine_path, engine_file);
339 const char *usepath = metamod_path.c_str();
340 if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
345 char command[PATH_SIZE * 2];
346 UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
347 provider->ServerCommand(command);
350 /* Wrapper function. This is called when the GameDLL thinks it's using
351 * the engine's real engineFactory.
354 EngineFactory(const char *iface, int *ret)
356 IFACE_MACRO(engine_factory, Engine);
359 /* Wrapper function. This is called when the GameDLL thinks it's using
360 * the engine's real physicsFactory.
363 PhysicsFactory(const char *iface, int *ret)
365 IFACE_MACRO(physics_factory, Physics);
368 /* Wrapper function. This is called when the GameDLL thinks it's using
369 * the engine's real fileSystemFactory.
372 FileSystemFactory(const char *iface, int *ret)
374 IFACE_MACRO(filesystem_factory, FileSystem);
378 mm_LogMessage(const char *msg, ...)
381 static char buffer[2048];
384 size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
387 buffer[len++] = '\n';
390 if (!provider->LogMessage(buffer))
392 fprintf(stdout, "%s", buffer);
397 DoInitialPluginLoads()
399 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
400 const char *mmBaseDir = provider->GetCommandLineValue("mm_basedir", NULL);
403 pluginFile = provider->GetConVarString(mm_pluginsfile);
404 if (pluginFile == NULL)
406 pluginFile = "addons/metamod/metaplugins.ini";
411 mmBaseDir = provider->GetConVarString(mm_basedir);
412 if (mmBaseDir == NULL)
414 mmBaseDir = "addons/metamod";
418 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
420 g_Metamod.PathFormat(filepath, sizeof(filepath), "%s/%s", mod_path.c_str(), pluginFile);
421 g_Metamod.PathFormat(vdfpath, sizeof(vdfpath), "%s/%s", mod_path.c_str(), mmBaseDir);
422 mm_LoadPlugins(filepath, vdfpath);
426 mm_StartupMetamod(bool is_vsp_load)
434 is_vsp_load ? "V" : "");
436 metamod_version = provider->CreateConVar("metamod_version",
438 "Metamod:Source Version",
439 ConVarFlag_Notify|ConVarFlag_SpOnly);
441 provider->SetConVarString(metamod_version, buffer);
443 mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
444 #if defined WIN32 || defined _WIN32
445 "addons\\metamod\\metaplugins.ini",
447 "addons/metamod/metaplugins.ini",
449 "Metamod:Source Plugins File",
452 mm_basedir = provider->CreateConVar("mm_basedir",
453 #if defined __linux__ || defined __APPLE__
458 "Metamod:Source Base Folder",
461 g_bIsVspBridged = is_vsp_load;
465 DoInitialPluginLoads();
466 in_first_level = true;
471 mm_InitializeGlobals(CreateInterfaceFn engineFactory,
472 CreateInterfaceFn physicsFactory,
473 CreateInterfaceFn filesystemFactory,
474 CGlobalVars *pGlobals)
476 engine_factory = engineFactory;
477 physics_factory = physicsFactory;
478 filesystem_factory = filesystemFactory;
479 gpGlobals = pGlobals;
480 provider->Notify_DLLInit_Pre(engineFactory, gamedll_info.factory);
489 if (vsp_load_requested)
492 if (g_bIsVspBridged && !were_plugins_loaded)
494 DoInitialPluginLoads();
495 g_PluginMngr.SetAllLoaded();
496 were_plugins_loaded = true;
501 RETURN_META_VALUE(MRES_IGNORED, true);
508 g_PluginMngr.UnloadAll();
510 provider->Notify_DLLShutdown_Pre();
512 g_SourceHook.CompleteShutdown();
516 Handler_LevelShutdown(void)
518 if (g_bIsVspBridged && !were_plugins_loaded)
520 DoInitialPluginLoads();
521 g_PluginMngr.SetAllLoaded();
522 were_plugins_loaded = true;
523 in_first_level = true;
528 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
530 g_Metamod.PathFormat(filepath,
534 provider->GetConVarString(mm_pluginsfile));
535 g_Metamod.PathFormat(vdfpath,
539 provider->GetConVarString(mm_basedir));
540 mm_LoadPlugins(filepath, vdfpath);
544 in_first_level = false;
547 ITER_EVENT(OnLevelShutdown, ());
549 RETURN_META(MRES_IGNORED);
553 Handler_LevelInit(char const *pMapName,
554 char const *pMapEntities,
555 char const *pOldLevel,
556 char const *pLandmarkName,
560 ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
562 RETURN_META_VALUE(MRES_IGNORED, false);
565 void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
571 UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
574 mm_LogMessage("[%s] %s", pl->GetLogTag(), buffer);
577 CreateInterfaceFn MetamodSource::GetEngineFactory(bool syn/* =true */)
580 return EngineFactory;
581 return engine_factory;
584 CreateInterfaceFn MetamodSource::GetPhysicsFactory(bool syn/* =true */)
587 return PhysicsFactory;
588 return physics_factory;
591 CreateInterfaceFn MetamodSource::GetFileSystemFactory(bool syn/* =true */)
594 return FileSystemFactory;
595 return filesystem_factory;
598 CreateInterfaceFn MetamodSource::GetServerFactory(bool syn/* =true */)
601 return ServerFactory;
602 return gamedll_info.factory;
605 CGlobalVars *MetamodSource::GetCGlobals()
610 void MetamodSource::SetLastMetaReturn(META_RES res)
615 META_RES MetamodSource::GetLastMetaReturn()
617 return last_meta_res;
620 void MetamodSource::ConPrint(const char *str)
622 provider->ConsolePrint(str);
625 void MetamodSource::ConPrintf(const char *fmt, ...)
631 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
634 provider->ConsolePrint(buffer);
637 void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
639 major = METAMOD_API_MAJOR;
640 minor = METAMOD_API_MINOR;
641 plvers = METAMOD_PLAPI_VERSION;
642 plmin = PLAPI_MIN_VERSION;
645 void MetamodSource::GetShVersions(int &shvers, int &shimpl)
647 shvers = SH_IFACE_VERSION;
648 shimpl = SH_IMPL_VERSION;
651 int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
653 int length = (int)strlen(iface);
657 for (i = length - 1; i >= 0; i--)
659 if (!isdigit(iface[i]))
669 if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
676 num = atoi(&(iface[++i]));
681 snprintf(&(iface[i]), 4, "%03d", num);
686 void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
688 char _if[256]; /* assume no interface goes beyond this */
689 size_t len = strlen(iface);
698 if (len + 4 > sizeof(_if))
711 if ((pf = (fn)(_if, ret)) != NULL)
719 } while ((num = FormatIface(_if, len+1)));
724 void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
726 char buffer[256]; /* assume no interface will go beyond this */
727 size_t len = strlen(iface);
728 int ret; /* just in case something doesn't handle NULL properly */
730 if (len > sizeof(buffer) - 4)
735 strcpy(buffer, iface);
739 char *ptr = &buffer[len - 1];
741 while (isdigit(*ptr) && digits <=3)
749 /* for now, assume this is an error */
750 strcpy(buffer, iface);
755 min = (min == 0) ? 1 : min;
756 snprintf(num, sizeof(num), "%03d", min);
761 return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
764 const char *MetamodSource::GetBaseDir()
766 return mod_path.c_str();
769 size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
773 size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
776 for (size_t i = 0; i < mylen; i++)
778 if (buffer[i] == ALT_SEP_CHAR)
780 buffer[i] = PATH_SEP_CHAR;
787 #if SOURCE_ENGINE == SE_DOTA
788 void MetamodSource::ClientConPrintf(int clientIndex, const char *fmt, ...)
794 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
797 ClientConPrintf((edict_t *)(gpGlobals->pEdicts + clientIndex), "%s", buffer);
801 void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
807 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
810 provider->ClientConsolePrint(client, buffer);
813 void MetamodSource::EnableVSPListener()
815 if (is_game_init && !vsp_load_requested && !vsp_loaded)
820 vsp_load_requested = true;
823 int MetamodSource::GetVSPVersion()
828 int MetamodSource::GetGameDLLVersion()
830 return gamedll_version;
833 bool MetamodSource::RemotePrintingAvailable()
835 return provider->IsRemotePrintingAvailable();
838 void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
850 /* First check ours... we get first chance! */
851 if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
857 return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
859 else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
865 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
867 else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
873 return static_cast<void *>(static_cast<SourceHook::IHookManagerAutoGen *>(&g_SH_HookManagerAutoGen));
876 CPluginManager::CPlugin *pl;
877 List<IMetamodListener *>::iterator event;
878 IMetamodListener *api;
882 for (PluginIter iter = g_PluginMngr._begin();
883 iter != g_PluginMngr._end();
887 for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
890 subret = IFACE_FAILED;
891 if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
914 void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
916 CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
918 pl->m_Events.push_back(pListener);
921 const char *MetamodSource::GetGameBinaryPath()
923 return full_bin_path.c_str();
926 const char *MetamodSource::GetPluginsFile()
928 return provider->GetConVarString(mm_pluginsfile);
931 const char *MetamodSource::GetVDFDir()
933 return provider->GetConVarString(mm_basedir);
936 IConCommandBaseAccessor *MetamodSource::GetCvarBaseAccessor()
938 return provider->GetConCommandBaseAccessor();
941 bool MetamodSource::RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
943 if (provider->IsConCommandBaseACommand(pCommand))
945 g_PluginMngr.AddPluginCmd(plugin, pCommand);
949 g_PluginMngr.AddPluginCvar(plugin, pCommand);
952 return provider->RegisterConCommandBase(pCommand);
955 void MetamodSource::UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
957 if (provider->IsConCommandBaseACommand(pCommand))
959 g_PluginMngr.RemovePluginCmd(plugin, pCommand);
963 g_PluginMngr.RemovePluginCvar(plugin, pCommand);
966 CPluginManager::CPlugin *pOrig = g_PluginMngr.FindByAPI(plugin);
967 UnregisterConCommandBase(pOrig ? pOrig->m_Id : 0, pCommand);
970 void MetamodSource::UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand)
973 CPluginManager::CPlugin *pPlugin;
974 List<IMetamodListener *>::iterator event;
975 IMetamodListener *pML;
976 for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
979 if (pPlugin->m_Status < Pl_Paused)
983 /* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
984 if (pPlugin->m_API->GetApiVersion() < 12)
988 for (event=pPlugin->m_Events.begin();
989 event!=pPlugin->m_Events.end();
993 pML->OnUnlinkConCommandBase(id, pCommand);
997 return provider->UnregisterConCommandBase(pCommand);
1000 int MetamodSource::GetUserMessageCount()
1002 return provider->GetUserMessageCount();
1005 int MetamodSource::FindUserMessage(const char *name, int *size/* =NULL */)
1007 return provider->FindUserMessage(name, size);
1010 const char *MetamodSource::GetUserMessage(int index, int *size/* =NULL */)
1012 return provider->GetUserMessage(index, size);
1015 int MetamodSource::GetSourceEngineBuild()
1017 return engine_build;
1020 void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks, int version)
1023 vsp_version = version;
1025 vsp_callbacks = callbacks;
1026 ITER_EVENT(OnVSPListening, (callbacks));
1028 if (is_gamedll_loaded)
1031 * MM:S is loaded as a game DLL so we need to set these for mm_IsVspBridged() and
1032 * mm_IsVspLoadComplete()
1034 g_bIsVspBridged = true;
1035 were_plugins_loaded = true;
1039 IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion)
1043 *pVersion = vsp_version;
1046 return vsp_callbacks;
1049 size_t MetamodSource::Format(char *buffer, size_t maxlength, const char *format, ...)
1054 va_start(ap, format);
1055 result = FormatArgs(buffer, maxlength, format, ap);
1061 size_t MetamodSource::FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap)
1063 return UTIL_FormatArgs(buffer, maxlength, format, ap);
1066 bool MetamodSource::IsLoadedAsGameDLL()
1068 return is_gamedll_loaded;
1071 void MetamodSource::SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded)
1073 gamedll_info.factory = serverFactory;
1074 gamedll_version = version;
1075 is_gamedll_loaded = loaded;
1078 void MetamodSource::SetVSPListener(const char *path)
1080 metamod_path.assign(path);
1083 size_t MetamodSource::GetFullPluginPath(const char *plugin, char *buffer, size_t len)
1085 const char *pext, *ext;
1088 /* First find if it's an absolute path or not... */
1089 if (plugin[0] == '/' || strncmp(&(plugin[1]), ":\\", 2) == 0)
1091 return UTIL_Format(buffer, len, plugin);
1094 /* Attempt to find a file extension */
1095 pext = UTIL_GetExtension(plugin);
1096 /* Add an extension if there's none there */
1099 #if defined WIN32 || defined _WIN32
1101 #elif defined __APPLE__
1112 /* Format the new path */
1113 num = PathFormat(buffer, len, "%s/%s%s", mod_path.c_str(), plugin, ext);
1115 #if defined __linux__
1116 /* If path was passed without extension and it doesn't exist with "_i486.so" try ".so" */
1118 if (!pext && stat(buffer, &s) != 0)
1120 num = PathFormat(buffer, len, "%s/%s.so", mod_path.c_str(), plugin);
1128 ProcessVDF(const char *path, bool &skipped)
1132 char alias[24], file[255], full_path[255], error[255];
1134 if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias)))
1140 if (alias[0] != '\0')
1141 g_PluginMngr.SetAlias(alias, file);
1143 g_Metamod.GetFullPluginPath(file, full_path, sizeof(full_path));
1145 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
1147 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1149 mm_LogMessage("[META] Failed to load plugin %s: %s", file, error);
1157 LoadVDFPluginsFromDir(const char *dir, int &skipped)
1161 char path[MAX_PATH];
1162 char relpath[MAX_PATH * 2];
1166 #if defined _MSC_VER
1171 g_Metamod.PathFormat(path, sizeof(path), "%s\\*.vdf", dir);
1172 if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
1174 DWORD dw = GetLastError();
1175 if (dw == ERROR_FILE_NOT_FOUND)
1178 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
1181 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1185 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
1191 g_Metamod.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
1192 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1193 success = ProcessVDF(relpath, skip);
1198 } while (FindNextFile(hFind, &fd));
1203 struct dirent *pEnt;
1206 if ((pDir = opendir(dir)) == NULL)
1208 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
1212 while ((pEnt = readdir(pDir)) != NULL)
1214 if (strcmp(pEnt->d_name, ".") == 0
1215 || strcmp(pEnt->d_name, "..") == 0)
1219 extidx = strlen(pEnt->d_name) - 4;
1220 if (extidx < 0 || stricmp(&pEnt->d_name[extidx], ".vdf"))
1224 g_Metamod.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
1225 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1226 success = ProcessVDF(relpath, skip);
1240 mm_LoadPlugins(const char *filepath, const char *vdfpath)
1242 int total, skipped, fskipped, vskipped;
1245 total = LoadPluginsFromFile(filepath, fskipped);
1246 total += LoadVDFPluginsFromDir(vdfpath, vskipped);
1247 skipped = fskipped + vskipped;
1249 if (total == 0 || total > 1)
1253 mm_LogMessage("[META] Loaded %d plugin%s (%d already loaded)", total, s, skipped);
1255 mm_LogMessage("[META] Loaded %d plugin%s.", total, s);
1263 return g_bIsVspBridged;
1267 mm_IsVspLoadComplete()
1269 return were_plugins_loaded;