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 LookForVDFs(const char *dir);
74 CreateInterfaceFn factory;
77 static String mod_path;
78 static String metamod_path;
79 static String full_bin_path;
80 static int vsp_version = 0;
81 static int gamedll_version = 0;
82 static int engine_build = SOURCE_ENGINE_UNKNOWN;
83 static List<game_dll_t *> gamedll_list;
84 static bool is_gamedll_loaded = false;
85 static bool in_first_level = true;
86 static bool is_game_init = false;
87 static bool vsp_load_requested = false;
88 static bool vsp_loaded = false;
89 static game_dll_t gamedll_info;
90 static ConVar *metamod_version = NULL;
91 static ConVar *mm_pluginsfile = NULL;
92 static ConVar *mm_basedir = NULL;
93 static CreateInterfaceFn engine_factory = NULL;
94 static CreateInterfaceFn physics_factory = NULL;
95 static CreateInterfaceFn filesystem_factory = NULL;
96 static CGlobalVars *gpGlobals = NULL;
97 static CHookManagerAutoGen g_SH_HookManagerAutoGen(&g_SourceHook);
98 static META_RES last_meta_res;
99 static IServerPluginCallbacks *vsp_callbacks = NULL;
100 static bool were_plugins_loaded = false;
101 static bool g_bIsVspBridged = false;
103 MetamodSource g_Metamod;
104 PluginId g_PLID = Pl_Console;
105 CSourceHookImpl g_SourceHook;
106 ISourceHook *g_SHPtr = &g_SourceHook;
107 SourceMM::ISmmAPI *g_pMetamod = &g_Metamod;
110 #define IFACE_MACRO(orig,nam) \
111 CPluginManager::CPlugin *pl; \
112 SourceHook::List<IMetamodListener *>::iterator event; \
113 IMetamodListener *api; \
116 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
118 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
120 mret = IFACE_FAILED; \
121 if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
122 if (ret) *ret = mret; \
127 return (orig)(iface, ret);
129 #define ITER_EVENT(evn, args) \
130 CPluginManager::CPlugin *pl; \
131 SourceHook::List<IMetamodListener *>::iterator event; \
132 IMetamodListener *api; \
133 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
135 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
142 mm_SetVspInfo(IServerPluginCallbacks *ispc, unsigned int version)
144 vsp_version = version;
147 /* Initialize everything here */
149 mm_InitializeForLoad()
151 char full_path[PATH_SIZE] = {0};
152 GetFileOfAddress((void *)gamedll_info.factory, full_path, sizeof(full_path));
153 full_bin_path.assign(full_path);
155 /* Like Metamod, reload plugins at the end of the map.
156 * This is so plugins can hook everything on load, BUT, new plugins will be reloaded
157 * if the server is shut down (silly, but rare case).
159 in_first_level = true;
161 SourceHook::MemFuncInfo info;
163 if (!provider->GetHookInfo(ProvidedHook_GameInit, &info))
165 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::GameInit");
167 SH_MANUALHOOK_RECONFIGURE(SGD_GameInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
168 SH_ADD_MANUALHOOK_STATICFUNC(SGD_GameInit, server, Handler_GameInit, false);
170 if (!provider->GetHookInfo(ProvidedHook_LevelInit, &info))
172 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelInit");
174 SH_MANUALHOOK_RECONFIGURE(SGD_LevelInit, info.vtblindex, info.vtbloffs, info.thisptroffs);
175 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelInit, server, Handler_LevelInit, true);
177 if (!provider->GetHookInfo(ProvidedHook_LevelShutdown, &info))
179 provider->DisplayError("Metamod:Source could not find a valid hook for IServerGameDLL::LevelShutdown");
181 SH_MANUALHOOK_RECONFIGURE(SGD_LevelShutdown, info.vtblindex, info.vtbloffs, info.thisptroffs);
182 SH_ADD_MANUALHOOK_STATICFUNC(SGD_LevelShutdown, server, Handler_LevelShutdown, true);
186 mm_DetectGameInformation()
188 char mm_path[PATH_SIZE];
189 char game_path[PATH_SIZE];
191 /* Get path to SourceMM DLL */
192 if (!GetFileOfAddress((void *)mm_InitializeForLoad, mm_path, sizeof(mm_path)))
197 metamod_path.assign(mm_path);
199 /* Get value of -game from command line, defaulting to hl2 as engine seems to do */
200 const char *game_dir = provider->GetCommandLineValue("-game", "hl2");
202 /* Get absolute path */
203 abspath(game_path, game_dir);
204 mod_path.assign(game_path);
206 engine_build = provider->DetermineSourceEngine(game_dir);;
212 ServerFactory(const char *iface, int *ret)
214 IFACE_MACRO(gamedll_info.factory, GameDLL);
218 mm_LoadPluginsFromFile(const char *_file)
221 int total = 0, skipped=0;
225 fp = fopen(_file, "rt");
228 mm_LogMessage("[META] Could not open plugins file %s\n", _file);
232 char buffer[255], error[255], full_path[255];
233 const char *ptr, *ext, *file;
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);
295 /* First find if it's an absolute path or not... */
296 if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
298 /* If we're in an absolute path, ignore our normal heuristics */
299 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
300 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
302 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
314 /* Attempt to find a file extension */
315 ptr = UTIL_GetExtension(file);
316 /* Add an extension if there's none there */
319 #if defined WIN32 || defined _WIN32
329 /* Format the new path */
330 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s%s", mod_path.c_str(), file, ext);
331 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
332 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
334 mm_LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
348 mm_LogMessage("[META] Loaded %d plugins from file (%d already loaded)", total, skipped);
350 mm_LogMessage("[META] Loaded %d plugins from file.", total);
361 char engine_file[PATH_SIZE];
362 char engine_path[PATH_SIZE];
363 char rel_path[PATH_SIZE * 2];
365 GetFileOfAddress((void *)engine_factory, engine_file, sizeof(engine_file));
367 /* Chop off the "engine" file part */
368 len = strlen(engine_file);
369 for (size_t i = len - 1; i >= 0 && i < len; i--)
371 if (engine_file[i] == '/' || engine_file[i] == '\\')
373 engine_file[i] = '\0';
377 abspath(engine_path, engine_file);
379 const char *usepath = metamod_path.c_str();
380 if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_path, metamod_path.c_str()))
385 char command[PATH_SIZE * 2];
386 UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
387 provider->ServerCommand(command);
390 /* Wrapper function. This is called when the GameDLL thinks it's using
391 * the engine's real engineFactory.
394 EngineFactory(const char *iface, int *ret)
396 IFACE_MACRO(engine_factory, Engine);
399 /* Wrapper function. This is called when the GameDLL thinks it's using
400 * the engine's real physicsFactory.
403 PhysicsFactory(const char *iface, int *ret)
405 IFACE_MACRO(physics_factory, Physics);
408 /* Wrapper function. This is called when the GameDLL thinks it's using
409 * the engine's real fileSystemFactory.
412 FileSystemFactory(const char *iface, int *ret)
414 IFACE_MACRO(filesystem_factory, FileSystem);
418 mm_LogMessage(const char *msg, ...)
421 static char buffer[2048];
424 size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
427 buffer[len++] = '\n';
430 if (!provider->LogMessage(buffer))
432 fprintf(stdout, "%s", buffer);
437 DoInitialPluginLoads()
439 const char *pluginFile = provider->GetCommandLineValue("mm_pluginsfile", NULL);
440 const char *mmBaseDir = provider->GetCommandLineValue("mm_basedir", NULL);
443 pluginFile = provider->GetConVarString(mm_pluginsfile);
444 if (pluginFile == NULL)
446 pluginFile = "addons/metamod/metaplugins.ini";
451 mmBaseDir = provider->GetConVarString(mm_basedir);
452 if (mmBaseDir == NULL)
454 mmBaseDir = "addons/metamod";
460 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), pluginFile);
461 mm_LoadPluginsFromFile(full_path);
463 g_Metamod.PathFormat(full_path, sizeof(full_path), "%s/%s", mod_path.c_str(), mmBaseDir);
464 LookForVDFs(full_path);
468 mm_StartupMetamod(bool is_vsp_load)
476 is_vsp_load ? "V" : "");
478 metamod_version = provider->CreateConVar("metamod_version",
480 "Metamod:Source Version",
481 ConVarFlag_Notify|ConVarFlag_SpOnly);
483 provider->SetConVarString(metamod_version, buffer);
485 mm_pluginsfile = provider->CreateConVar("mm_pluginsfile",
486 #if defined WIN32 || defined _WIN32
487 "addons\\metamod\\metaplugins.ini",
489 "addons/metamod/metaplugins.ini",
491 "Metamod:Source Plugins File",
494 mm_basedir = provider->CreateConVar("mm_basedir",
495 #if defined __linux__
500 "Metamod:Source Base Folder",
503 g_bIsVspBridged = true;
507 DoInitialPluginLoads();
508 in_first_level = true;
513 mm_InitializeGlobals(CreateInterfaceFn engineFactory,
514 CreateInterfaceFn physicsFactory,
515 CreateInterfaceFn filesystemFactory,
516 CGlobalVars *pGlobals)
518 engine_factory = engineFactory;
519 physics_factory = physicsFactory;
520 filesystem_factory = filesystemFactory;
521 gpGlobals = pGlobals;
522 provider->Notify_DLLInit_Pre(engineFactory, gamedll_info.factory);
531 if (vsp_load_requested)
534 if (g_bIsVspBridged && !were_plugins_loaded)
536 DoInitialPluginLoads();
537 g_PluginMngr.SetAllLoaded();
538 were_plugins_loaded = true;
543 RETURN_META_VALUE(MRES_IGNORED, true);
550 g_PluginMngr.UnloadAll();
552 provider->Notify_DLLShutdown_Pre();
554 g_SourceHook.CompleteShutdown();
558 Handler_LevelShutdown(void)
560 if (g_bIsVspBridged && !were_plugins_loaded)
562 g_PluginMngr.SetAllLoaded();
563 DoInitialPluginLoads();
564 were_plugins_loaded = true;
565 in_first_level = true;
572 g_Metamod.PathFormat(full_path,
576 provider->GetConVarString(mm_pluginsfile));
577 mm_LoadPluginsFromFile(full_path);
579 g_Metamod.PathFormat(full_path,
583 provider->GetConVarString(mm_basedir));
584 LookForVDFs(full_path);
588 in_first_level = false;
591 ITER_EVENT(OnLevelShutdown, ());
593 RETURN_META(MRES_IGNORED);
597 Handler_LevelInit(char const *pMapName,
598 char const *pMapEntities,
599 char const *pOldLevel,
600 char const *pLandmarkName,
604 ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
606 RETURN_META_VALUE(MRES_IGNORED, false);
609 void MetamodSource::LogMsg(ISmmPlugin *pl, const char *msg, ...)
615 UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
618 mm_LogMessage("[%s] %s", pl->GetLogTag(), buffer);
621 CreateInterfaceFn MetamodSource::GetEngineFactory(bool syn/* =true */)
624 return EngineFactory;
625 return engine_factory;
628 CreateInterfaceFn MetamodSource::GetPhysicsFactory(bool syn/* =true */)
631 return PhysicsFactory;
632 return physics_factory;
635 CreateInterfaceFn MetamodSource::GetFileSystemFactory(bool syn/* =true */)
638 return FileSystemFactory;
639 return filesystem_factory;
642 CreateInterfaceFn MetamodSource::GetServerFactory(bool syn/* =true */)
645 return ServerFactory;
646 return gamedll_info.factory;
649 CGlobalVars *MetamodSource::GetCGlobals()
654 void MetamodSource::SetLastMetaReturn(META_RES res)
659 META_RES MetamodSource::GetLastMetaReturn()
661 return last_meta_res;
664 void MetamodSource::ConPrint(const char *str)
666 provider->ConsolePrint(str);
669 void MetamodSource::ConPrintf(const char *fmt, ...)
675 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
678 provider->ConsolePrint(buffer);
681 void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
683 major = METAMOD_API_MAJOR;
684 minor = METAMOD_API_MINOR;
685 plvers = METAMOD_PLAPI_VERSION;
686 plmin = PLAPI_MIN_VERSION;
689 void MetamodSource::GetShVersions(int &shvers, int &shimpl)
691 shvers = SH_IFACE_VERSION;
692 shimpl = SH_IMPL_VERSION;
695 int MetamodSource::FormatIface(char iface[], unsigned int maxlength)
697 int length = (int)strlen(iface);
701 for (i = length - 1; i >= 0; i--)
703 if (!isdigit(iface[i]))
713 if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
720 num = atoi(&(iface[++i]));
725 snprintf(&(iface[i]), 4, "%03d", num);
730 void *MetamodSource::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
732 char _if[256]; /* assume no interface goes beyond this */
733 size_t len = strlen(iface);
742 if (len + 4 > sizeof(_if))
755 if ((pf = (fn)(_if, ret)) != NULL)
763 } while ((num = FormatIface(_if, len+1)));
768 void *MetamodSource::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
770 char buffer[256]; /* assume no interface will go beyond this */
771 size_t len = strlen(iface);
772 int ret; /* just in case something doesn't handle NULL properly */
774 if (len > sizeof(buffer) - 4)
779 strcpy(buffer, iface);
783 char *ptr = &buffer[len - 1];
785 while (isdigit(*ptr) && digits <=3)
793 /* for now, assume this is an error */
794 strcpy(buffer, iface);
799 min = (min == 0) ? 1 : min;
800 snprintf(num, sizeof(num), "%03d", min);
805 return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
808 const char *MetamodSource::GetBaseDir()
810 return mod_path.c_str();
813 size_t MetamodSource::PathFormat(char *buffer, size_t len, const char *fmt, ...)
817 size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
820 for (size_t i = 0; i < mylen; i++)
822 if (buffer[i] == ALT_SEP_CHAR)
824 buffer[i] = PATH_SEP_CHAR;
831 void MetamodSource::ClientConPrintf(edict_t *client, const char *fmt, ...)
837 UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
840 provider->ClientConsolePrint(client, buffer);
843 void MetamodSource::EnableVSPListener()
845 if (is_game_init && !vsp_load_requested && !vsp_loaded)
848 vsp_load_requested = true;
851 int MetamodSource::GetVSPVersion()
856 int MetamodSource::GetGameDLLVersion()
858 return gamedll_version;
861 bool MetamodSource::RemotePrintingAvailable()
863 return provider->IsRemotePrintingAvailable();
866 void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
878 /* First check ours... we get first chance! */
879 if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
885 return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
887 else if (strcmp(iface, MMIFACE_PLMANAGER) == 0)
893 return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
895 else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
901 return static_cast<void *>(static_cast<SourceHook::IHookManagerAutoGen *>(&g_SH_HookManagerAutoGen));
904 CPluginManager::CPlugin *pl;
905 List<IMetamodListener *>::iterator event;
906 IMetamodListener *api;
910 for (PluginIter iter = g_PluginMngr._begin();
911 iter != g_PluginMngr._end();
915 for (event = pl->m_Events.begin(); event != pl->m_Events.end(); event++)
918 subret = IFACE_FAILED;
919 if ((value = api->OnMetamodQuery(iface, &subret)) != NULL)
942 void MetamodSource::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
944 CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
946 pl->m_Events.push_back(pListener);
949 const char *MetamodSource::GetGameBinaryPath()
951 return full_bin_path.c_str();
954 const char *MetamodSource::GetPluginsFile()
956 return provider->GetConVarString(mm_pluginsfile);
959 IConCommandBaseAccessor *MetamodSource::GetCvarBaseAccessor()
961 return provider->GetConCommandBaseAccessor();
964 bool MetamodSource::RegisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
966 if (provider->IsConCommandBaseACommand(pCommand))
968 g_PluginMngr.AddPluginCmd(plugin, pCommand);
972 g_PluginMngr.AddPluginCvar(plugin, pCommand);
975 return provider->RegisterConCommandBase(pCommand);
978 void MetamodSource::UnregisterConCommandBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
980 if (provider->IsConCommandBaseACommand(pCommand))
982 g_PluginMngr.RemovePluginCmd(plugin, pCommand);
986 g_PluginMngr.RemovePluginCvar(plugin, pCommand);
989 CPluginManager::CPlugin *pOrig = g_PluginMngr.FindByAPI(plugin);
990 UnregisterConCommandBase(pOrig ? pOrig->m_Id : 0, pCommand);
993 void MetamodSource::UnregisterConCommandBase(PluginId id, ConCommandBase *pCommand)
996 CPluginManager::CPlugin *pPlugin;
997 List<IMetamodListener *>::iterator event;
998 IMetamodListener *pML;
999 for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
1002 if (pPlugin->m_Status < Pl_Paused)
1006 /* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
1007 if (pPlugin->m_API->GetApiVersion() < 12)
1011 for (event=pPlugin->m_Events.begin();
1012 event!=pPlugin->m_Events.end();
1016 pML->OnUnlinkConCommandBase(id, pCommand);
1020 return provider->UnregisterConCommandBase(pCommand);
1023 int MetamodSource::GetUserMessageCount()
1025 return provider->GetUserMessageCount();
1028 int MetamodSource::FindUserMessage(const char *name, int *size/* =NULL */)
1030 return provider->FindUserMessage(name, size);
1033 const char *MetamodSource::GetUserMessage(int index, int *size/* =NULL */)
1035 return provider->GetUserMessage(index, size);
1038 int MetamodSource::GetSourceEngineBuild()
1040 return engine_build;
1043 void MetamodSource::NotifyVSPListening(IServerPluginCallbacks *callbacks)
1045 ITER_EVENT(OnVSPListening, (callbacks));
1048 IServerPluginCallbacks *MetamodSource::GetVSPInfo(int *pVersion)
1052 *pVersion = vsp_version;
1055 return vsp_callbacks;
1058 size_t MetamodSource::Format(char *buffer, size_t maxlength, const char *format, ...)
1063 va_start(ap, format);
1064 result = FormatArgs(buffer, maxlength, format, ap);
1070 size_t MetamodSource::FormatArgs(char *buffer, size_t maxlength, const char *format, va_list ap)
1072 return UTIL_FormatArgs(buffer, maxlength, format, ap);
1075 bool MetamodSource::IsLoadedAsGameDLL()
1077 return is_gamedll_loaded;
1080 void MetamodSource::SetGameDLLInfo(CreateInterfaceFn serverFactory, int version, bool loaded)
1082 gamedll_info.factory = serverFactory;
1083 gamedll_version = version;
1084 is_gamedll_loaded = loaded;
1088 ProcessVDF(const char *path)
1092 char alias[24], file[255], error[255];
1094 if (!provider->ProcessVDF(path, file, sizeof(file), alias, sizeof(alias)))
1097 if (alias[0] != '\0')
1098 g_PluginMngr.SetAlias(alias, file);
1100 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
1101 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
1102 mm_LogMessage("[META] Failed to load plugin %s: %s", file, error);
1106 LookForVDFs(const char *dir)
1108 char path[MAX_PATH];
1109 char relpath[MAX_PATH * 2];
1111 #if defined _MSC_VER
1116 g_Metamod.PathFormat(path, sizeof(path), "%s\\*.vdf", dir);
1117 if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
1119 DWORD dw = GetLastError();
1120 if (dw == ERROR_FILE_NOT_FOUND)
1123 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
1126 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1130 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
1136 g_Metamod.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
1137 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1138 ProcessVDF(relpath);
1139 } while (FindNextFile(hFind, &fd));
1144 struct dirent *pEnt;
1147 if ((pDir = opendir(dir)) == NULL)
1149 mm_LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
1153 while ((pEnt = readdir(pDir)) != NULL)
1155 if (strcmp(pEnt->d_name, ".") == 0
1156 || strcmp(pEnt->d_name, "..") == 0)
1160 extidx = strlen(pEnt->d_name) - 4;
1161 if (extidx < 0 || stricmp(&pEnt->d_name[extidx], ".vdf"))
1165 g_Metamod.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
1166 UTIL_Relatize(relpath, sizeof(relpath), mod_path.c_str(), path);
1167 ProcessVDF(relpath);
1177 return g_bIsVspBridged;
1181 mm_IsVspLoadComplete()
1183 return were_plugins_loaded;