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
325 /* Format the new path */
326 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s%s", mod_path.c_str(), file, ext);
327 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
328 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
330 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
352 char engine_file[PATH_SIZE];
353 char engine_path[PATH_SIZE];
354 char rel_path[PATH_SIZE * 2];
356 GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
358 /* Chop off the "engine" file part */
359 len = strlen(engine_file);
360 for (size_t i = len - 1; i >= 0 && i < len; i--)
362 if (engine_file[i] == '/' || engine_file[i] == '\\')
364 engine_file[i] = '\0';
368 abspath(engine_path, engine_file);
370 const char *usepath = metamod_path.c_str();
371 if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
376 char command[PATH_SIZE * 2];
377 UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
378 provider->ServerCommand(command);
381 /* Wrapper function. This is called when the GameDLL thinks it's using
382 * the engine's real engineFactory.
385 EngineFactory(const char *iface, int *ret)
387 IFACE_MACRO(engine_factory, Engine);
390 /* Wrapper function. This is called when the GameDLL thinks it's using
391 * the engine's real physicsFactory.
394 PhysicsFactory(const char *iface, int *ret)
396 IFACE_MACRO(physics_factory, Physics);
399 /* Wrapper function. This is called when the GameDLL thinks it's using
400 * the engine's real fileSystemFactory.
403 FileSystemFactory(const char *iface, int *ret)
405 IFACE_MACRO(filesystem_factory, FileSystem);
409 mm_LogMessage(const char *msg, ...)
412 static char buffer[2048];
415 size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
418 buffer[len++] = '\n';
421 if (!provider->LogMessage(buffer))
423 fprintf(stdout, "%s", buffer);
428 DoInitialPluginLoads()
430 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
431 const char *mmBaseDir = provider->GetCommandLineValue("mm_basedir", NULL);
434 pluginFile = provider->GetConVarString(mm_pluginsfile);
435 if (pluginFile == NULL)
437 pluginFile = "addons/metamod/metaplugins.ini";
442 mmBaseDir = provider->GetConVarString(mm_basedir);
443 if (mmBaseDir == NULL)
445 mmBaseDir = "addons/metamod";
449 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
451 g_Metamod.PathFormat(filepath, sizeof(filepath), "%s/%s", mod_path.c_str(), pluginFile);
452 g_Metamod.PathFormat(vdfpath, sizeof(vdfpath), "%s/%s", mod_path.c_str(), mmBaseDir);
453 mm_LoadPlugins(filepath, vdfpath);
457 mm_StartupMetamod(bool is_vsp_load)
465 is_vsp_load ? "V" : "");
467 metamod_version = provider->CreateConVar("metamod_version",
469 "Metamod:Source Version",
470 ConVarFlag_Notify|ConVarFlag_SpOnly);
472 provider->SetConVarString(metamod_version, buffer);
474 mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
475 #if defined WIN32 || defined _WIN32
476 "addons\\metamod\\metaplugins.ini",
478 "addons/metamod/metaplugins.ini",
480 "Metamod:Source Plugins File",
483 mm_basedir = provider->CreateConVar("mm_basedir",
484 #if defined __linux__
489 "Metamod:Source Base Folder",
492 g_bIsVspBridged = is_vsp_load;
496 DoInitialPluginLoads();
497 in_first_level = true;
502 mm_InitializeGlobals(CreateInterfaceFn engineFactory,
503 CreateInterfaceFn physicsFactory,
504 CreateInterfaceFn filesystemFactory,
505 CGlobalVars *pGlobals)
507 engine_factory = engineFactory;
508 physics_factory = physicsFactory;
509 filesystem_factory = filesystemFactory;
510 gpGlobals = pGlobals;
511 provider->Notify_DLLInit_Pre(engineFactory, gamedll_info.factory);
520 if (vsp_load_requested)
523 if (g_bIsVspBridged && !were_plugins_loaded)
525 DoInitialPluginLoads();
526 g_PluginMngr.SetAllLoaded();
527 were_plugins_loaded = true;
532 RETURN_META_VALUE(MRES_IGNORED, true);
539 g_PluginMngr.UnloadAll();
541 provider->Notify_DLLShutdown_Pre();
543 g_SourceHook.CompleteShutdown();
547 Handler_LevelShutdown(void)
549 if (g_bIsVspBridged && !were_plugins_loaded)
551 DoInitialPluginLoads();
552 g_PluginMngr.SetAllLoaded();
553 were_plugins_loaded = true;
554 in_first_level = true;
559 char filepath[PATH_SIZE], vdfpath[PATH_SIZE];
561 g_Metamod.PathFormat(filepath,
565 provider->GetConVarString(mm_pluginsfile));
566 g_Metamod.PathFormat(vdfpath,
570 provider->GetConVarString(mm_basedir));
571 mm_LoadPlugins(filepath, vdfpath);
575 in_first_level = false;
578 ITER_EVENT(OnLevelShutdown, ());
580 RETURN_META(MRES_IGNORED);
584 Handler_LevelInit(char const *pMapName,
585 char const *pMapEntities,
586 char const *pOldLevel,
587 char const *pLandmarkName,
591 ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
593 RETURN_META_VALUE(MRES_IGNORED, false);
596 void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
602 UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
605 mm_LogMessage("[%s] %s", pl->GetLogTag(), buffer);
608 CreateInterfaceFn MetamodSource::GetEngineFactory(bool syn/* =true */)
611 return EngineFactory;
612 return engine_factory;
615 CreateInterfaceFn MetamodSource::GetPhysicsFactory(bool syn/* =true */)
618 return PhysicsFactory;
619 return physics_factory;
622 CreateInterfaceFn MetamodSource::GetFileSystemFactory(bool syn/* =true */)
625 return FileSystemFactory;
626 return filesystem_factory;
629 CreateInterfaceFn MetamodSource::GetServerFactory(bool syn/* =true */)
632 return ServerFactory;
633 return gamedll_info.factory;
636 CGlobalVars *MetamodSource::GetCGlobals()
641 void MetamodSource::SetLastMetaReturn(META_RES res)
646 META_RES MetamodSource::GetLastMetaReturn()
648 return last_meta_res;
651 void MetamodSource::ConPrint(const char *str)
653 provider->ConsolePrint(str);
656 void MetamodSource::ConPrintf(const char *fmt, ...)
662 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
665 provider->ConsolePrint(buffer);
668 void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
670 major = METAMOD_API_MAJOR;
671 minor = METAMOD_API_MINOR;
672 plvers = METAMOD_PLAPI_VERSION;
673 plmin = PLAPI_MIN_VERSION;
676 void MetamodSource::GetShVersions(int &shvers, int &shimpl)
678 shvers = SH_IFACE_VERSION;
679 shimpl = SH_IMPL_VERSION;
682 int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
684 int length = (int)strlen(iface);
688 for (i = length - 1; i >= 0; i--)
690 if (!isdigit(iface[i]))
700 if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
707 num = atoi(&(iface[++i]));
712 snprintf(&(iface[i]), 4, "%03d", num);
717 void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
719 char _if[256]; /* assume no interface goes beyond this */
720 size_t len = strlen(iface);
729 if (len + 4 > sizeof(_if))
742 if ((pf = (fn)(_if, ret)) != NULL)
750 } while ((num = FormatIface(_if, len+1)));
755 void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
757 char buffer[256]; /* assume no interface will go beyond this */
758 size_t len = strlen(iface);
759 int ret; /* just in case something doesn't handle NULL properly */
761 if (len > sizeof(buffer) - 4)
766 strcpy(buffer, iface);
770 char *ptr = &buffer[len - 1];
772 while (isdigit(*ptr) && digits <=3)
780 /* for now, assume this is an error */
781 strcpy(buffer, iface);
786 min = (min == 0) ? 1 : min;
787 snprintf(num, sizeof(num), "%03d", min);
792 return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
795 const char *MetamodSource::GetBaseDir()
797 return mod_path.c_str();
800 size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
804 size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
807 for (size_t i = 0; i < mylen; i++)
809 if (buffer[i] == ALT_SEP_CHAR)
811 buffer[i] = PATH_SEP_CHAR;
818 void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
824 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
827 provider->ClientConsolePrint(client, buffer);
830 void MetamodSource::EnableVSPListener()
832 if (is_game_init && !vsp_load_requested && !vsp_loaded)
837 vsp_load_requested = true;
840 int MetamodSource::GetVSPVersion()
845 int MetamodSource::GetGameDLLVersion()
847 return gamedll_version;
850 bool MetamodSource::RemotePrintingAvailable()
852 return provider->IsRemotePrintingAvailable();
855 void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
867 /* First check ours... we get first chance! */
868 if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
874 return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
876 else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
882 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
884 else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
890 return static_cast<void *>(static_cast<SourceHook::IHookManagerAutoGen *>(&g_SH_HookManagerAutoGen));
893 CPluginManager::CPlugin *pl;
894 List<IMetamodListener *>::iterator event;
895 IMetamodListener *api;
899 for (PluginIter iter = g_PluginMngr._begin();
900 iter != g_PluginMngr._end();
904 for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
907 subret = IFACE_FAILED;
908 if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
931 void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
933 CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
935 pl->m_Events.push_back(pListener);
938 const char *MetamodSource::GetGameBinaryPath()
940 return full_bin_path.c_str();
943 const char *MetamodSource::GetPluginsFile()
945 return provider->GetConVarString(mm_pluginsfile);
948 const char *MetamodSource::GetVDFDir()
950 return provider->GetConVarString(mm_basedir);
953 IConCommandBaseAccessor *MetamodSource::GetCvarBaseAccessor()
955 return provider->GetConCommandBaseAccessor();
958 bool MetamodSource::RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
960 if (provider->IsConCommandBaseACommand(pCommand))
962 g_PluginMngr.AddPluginCmd(plugin, pCommand);
966 g_PluginMngr.AddPluginCvar(plugin, pCommand);
969 return provider->RegisterConCommandBase(pCommand);
972 void MetamodSource::UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
974 if (provider->IsConCommandBaseACommand(pCommand))
976 g_PluginMngr.RemovePluginCmd(plugin, pCommand);
980 g_PluginMngr.RemovePluginCvar(plugin, pCommand);
983 CPluginManager::CPlugin *pOrig = g_PluginMngr.FindByAPI(plugin);
984 UnregisterConCommandBase(pOrig ? pOrig->m_Id : 0, pCommand);
987 void MetamodSource::UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand)
990 CPluginManager::CPlugin *pPlugin;
991 List<IMetamodListener *>::iterator event;
992 IMetamodListener *pML;
993 for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
996 if (pPlugin->m_Status < Pl_Paused)
1000 /* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
1001 if (pPlugin->m_API->GetApiVersion() < 12)
1005 for (event=pPlugin->m_Events.begin();
1006 event!=pPlugin->m_Events.end();
1010 pML->OnUnlinkConCommandBase(id, pCommand);
1014 return provider->UnregisterConCommandBase(pCommand);
1017 int MetamodSource::GetUserMessageCount()
1019 return provider->GetUserMessageCount();
1022 int MetamodSource::FindUserMessage(const char *name, int *size/* =NULL */)
1024 return provider->FindUserMessage(name, size);
1027 const char *MetamodSource::GetUserMessage(int index, int *size/* =NULL */)
1029 return provider->GetUserMessage(index, size);
1032 int MetamodSource::GetSourceEngineBuild()
1034 return engine_build;
1037 void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks, int version)
1040 vsp_version = version;
1042 vsp_callbacks = callbacks;
1043 ITER_EVENT(OnVSPListening, (callbacks));
1045 if (is_gamedll_loaded)
1048 * MM:S is loaded as a game DLL so we need to set these for mm_IsVspBridged() and
1049 * mm_IsVspLoadComplete()
1051 g_bIsVspBridged = true;
1052 were_plugins_loaded = true;
1056 IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion)
1060 *pVersion = vsp_version;
1063 return vsp_callbacks;
1066 size_t MetamodSource::Format(char *buffer, size_t maxlength, const char *format, ...)
1071 va_start(ap, format);
1072 result = FormatArgs(buffer, maxlength, format, ap);
1078 size_t MetamodSource::FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap)
1080 return UTIL_FormatArgs(buffer, maxlength, format, ap);
1083 bool MetamodSource::IsLoadedAsGameDLL()
1085 return is_gamedll_loaded;
1088 void MetamodSource::SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded)
1090 gamedll_info.factory = serverFactory;
1091 gamedll_version = version;
1092 is_gamedll_loaded = loaded;
1095 void MetamodSource::SetVSPListener(const char *path)
1097 metamod_path.assign(path);
1101 ProcessVDF(const char *path, bool &skipped)
1105 char alias[24], file[255], full_path[255], error[255];
1107 if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias)))
1113 if (alias[0] != '\0')
1114 g_PluginMngr.SetAlias(alias, file);
1116 /* Attempt to find a file extension */
1117 if (UTIL_GetExtension(file) == NULL)
1119 g_pMetamod->PathFormat(full_path,
1122 g_pMetamod->GetBaseDir(),
1124 #if defined WIN32 || defined _WIN32
1133 g_pMetamod->PathFormat(full_path,
1136 g_pMetamod->GetBaseDir(),
1140 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
1142 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1144 mm_LogMessage("[META] Failed to load plugin %s: %s", file, error);
1152 LoadVDFPluginsFromDir(const char *dir, int &skipped)
1156 char path[MAX_PATH];
1157 char relpath[MAX_PATH * 2];
1161 #if defined _MSC_VER
1166 g_Metamod.PathFormat(path, sizeof(path), "%s\\*.vdf", dir);
1167 if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
1169 DWORD dw = GetLastError();
1170 if (dw == ERROR_FILE_NOT_FOUND)
1173 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
1176 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1180 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
1186 g_Metamod.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
1187 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1188 success = ProcessVDF(relpath, skip);
1193 } while (FindNextFile(hFind, &fd));
1198 struct dirent *pEnt;
1201 if ((pDir = opendir(dir)) == NULL)
1203 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
1207 while ((pEnt = readdir(pDir)) != NULL)
1209 if (strcmp(pEnt->d_name, ".") == 0
1210 || strcmp(pEnt->d_name, "..") == 0)
1214 extidx = strlen(pEnt->d_name) - 4;
1215 if (extidx < 0 || stricmp(&pEnt->d_name[extidx], ".vdf"))
1219 g_Metamod.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
1220 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1221 success = ProcessVDF(relpath, skip);
1235 mm_LoadPlugins(const char *filepath, const char *vdfpath)
1237 int total, skipped, fskipped, vskipped;
1240 total = LoadPluginsFromFile(filepath, fskipped);
1241 total += LoadVDFPluginsFromDir(vdfpath, vskipped);
1242 skipped = fskipped + vskipped;
1244 if (total == 0 || total > 1)
1248 mm_LogMessage("[META] Loaded %d plugin%s (%d already loaded)", total, s, skipped);
1250 mm_LogMessage("[META] Loaded %d plugin%s.", total, s);
1258 return g_bIsVspBridged;
1262 mm_IsVspLoadComplete()
1264 return were_plugins_loaded;