Hammered vsp bridge into core-legacy.
1 /* ======== SourceMM ========
2 * Copyright (C) 2004-2008 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): David "BAILOPAN" Anderson
8 * Contributor(s): Scott "Damaged Soul" Ehlert
9 * : Pavol "PM OnoTo" Marko
10 * ============================
13 #include <interface.h>
15 #include <tier0/icommandline.h>
17 #include "concommands.h"
21 #include "vsp_listener.h"
22 #include "iplayerinfo.h"
23 #include <filesystem.h>
25 using namespace SourceMM;
28 * @brief Implementation of main SourceMM GameDLL functionality
33 DLL_IMPORT ICommandLine *CommandLine();
35 SH_DECL_HOOK4(IServerGameDLL, DLLInit, SH_NOATTRIB, false, bool, CreateInterfaceFn, CreateInterfaceFn, CreateInterfaceFn, CGlobalVars *);
36 SH_DECL_HOOK0_void(IServerGameDLL, DLLShutdown, SH_NOATTRIB, false);
37 SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false);
38 SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
39 SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
40 SH_DECL_HOOK0(IServerGameDLL, GameInit, SH_NOATTRIB, false, bool);
42 bool DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals);
43 bool DLLInit_Post(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals);
44 void DLLShutdown_handler();
45 void LevelShutdown_handler();
46 bool LevelInit_handler(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
47 bool GameInit_handler();
48 void LookForVDFs(const char *dir);
49 bool KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID = NULL);
51 GameDllInfo g_GameDll = {false, NULL, NULL, NULL, NULL};
53 SourceHook::CSourceHookImpl g_SourceHook;
54 SourceHook::ISourceHook *g_SHPtr = &g_SourceHook;
55 SourceHook::String g_ModPath;
56 SourceHook::String g_BinPath;
57 SourceHook::String g_SmmPath;
58 PluginId g_PLID = Pl_Console; /* Technically, SourceMM is the "Console" plugin... :p */
59 bool bInFirstLevel = true;
60 bool gParsedGameInfo = false;
61 bool bGameInit = false;
62 SourceHook::List<GameDllInfo *> gamedll_list;
63 SourceHook::CallClass<IServerGameDLL> *g_GameDllPatch;
64 SourceHook::CallClass<ICvar> *g_CvarPatch;
65 int g_GameDllVersion = 0;
66 const char VSPIFACE_001[] = "ISERVERPLUGINCALLBACKS001";
67 const char VSPIFACE_002[] = "ISERVERPLUGINCALLBACKS002";
68 const char GAMEINFO_PATH[] = "|gameinfo_path|";
69 IFileSystem *baseFs = NULL;
70 bool g_bLevelChanged = false;
71 IServerPluginCallbacks *g_pRealVspCallbacks = &g_VspListener;
73 void ClearGamedllList();
76 #define IFACE_MACRO(orig,nam) \
77 CPluginManager::CPlugin *pl; \
78 SourceHook::List<CPluginEventHandler>::iterator event; \
79 IMetamodListener *api; \
82 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
84 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
85 api = (*event).event; \
86 mret = IFACE_FAILED; \
87 if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
88 if (ret) *ret = mret; \
93 return (orig)(iface, ret);
95 #define ITER_EVENT(evn, args) \
96 CPluginManager::CPlugin *pl; \
97 SourceHook::List<CPluginEventHandler>::iterator event; \
98 IMetamodListener *api; \
99 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
101 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
102 api = (*event).event; \
107 ///////////////////////////////////
108 // Main code for HL2 Interaction //
109 ///////////////////////////////////
111 /* Initialize everything here */
112 void InitMainStates()
114 char full_path[PATH_SIZE] = {0};
115 GetFileOfAddress((void *)g_GameDll.factory, full_path, sizeof(full_path));
116 g_BinPath.assign(full_path);
118 /* Like Metamod, reload plugins at the end of the map.
119 * This is so plugins can hook everything on load, BUT, new plugins will be reloaded
120 * if the server is shut down (silly, but rare case).
122 bInFirstLevel = true;
124 SH_ADD_HOOK_STATICFUNC(IServerGameDLL, DLLInit, g_GameDll.pGameDLL, DLLInit, false);
125 SH_ADD_HOOK_STATICFUNC(IServerGameDLL, DLLInit, g_GameDll.pGameDLL, DLLInit_Post, true);
126 SH_ADD_HOOK_STATICFUNC(IServerGameDLL, DLLShutdown, g_GameDll.pGameDLL, DLLShutdown_handler, false);
127 SH_ADD_HOOK_STATICFUNC(IServerGameDLL, LevelShutdown, g_GameDll.pGameDLL, LevelShutdown_handler, true);
128 SH_ADD_HOOK_STATICFUNC(IServerGameDLL, LevelInit, g_GameDll.pGameDLL, LevelInit_handler, true);
129 SH_ADD_HOOK_STATICFUNC(IServerGameDLL, GameInit, g_GameDll.pGameDLL, GameInit_handler, false);
132 void DoInitialPluginLoads()
134 const char *pluginFile = g_Engine.icvar->GetCommandLineValue("mm_pluginsfile");
135 const char *mmBaseDir = g_Engine.icvar->GetCommandLineValue("mm_basedir");
139 pluginFile = GetPluginsFile();
143 mmBaseDir = GetMetamodBaseDir();
148 g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s", g_ModPath.c_str(), pluginFile);
149 LoadPluginsFromFile(full_path);
150 g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s", g_ModPath.c_str(), mmBaseDir);
151 LookForVDFs(full_path);
154 bool StartupMetamod(CreateInterfaceFn engineFactory, bool bWaitForGameInit)
156 g_Engine.engine = (IVEngineServer *)((engineFactory)(INTERFACEVERSION_VENGINESERVER, NULL));
158 if (!g_Engine.engine)
160 Error("Could not find IVEngineServer! Metamod cannot load.");
163 g_Engine.icvar = (ICvar *)((engineFactory)(VENGINE_CVAR_INTERFACE_VERSION , NULL));
166 Error("Could not find ICvar! Metamod cannot load.");
170 g_Engine.loaded = true;
172 /* The Ship is the only game known at this time that uses the pre-Episode One engine */
173 g_Engine.original = strcmp(CommandLine()->ParmValue("-game", "hl2"), "ship") == 0;
175 ConCommandBaseMgr::OneTimeInit(static_cast<IConCommandBaseAccessor *>(&g_SMConVarAccessor));
177 g_GameDllPatch = SH_GET_CALLCLASS(g_GameDll.pGameDLL);
178 g_CvarPatch = SH_GET_CALLCLASS(g_Engine.icvar);
180 if (g_GameDll.pGameClients)
182 SH_ADD_HOOK_STATICFUNC(IServerGameClients, ClientCommand, g_GameDll.pGameClients, ClientCommand_handler, false);
186 /* If IServerGameClients isn't found, this really isn't a fatal error so... */
187 LogMessage("[META] Warning: Could not find IServerGameClients!");
188 LogMessage("[META] Warning: The 'meta' command will not be available to clients.");
191 if (!g_SmmAPI.CacheCmds())
193 LogMessage("[META] Warning: Failed to initialize Con_Printf. Defaulting to Msg().");
194 LogMessage("[META] Warning: Console messages will not be redirected to rcon console.");
197 if (!g_SmmAPI.CacheUserMessages())
199 /* Don't know of a mod that has stripped out user messages completely,
200 * but perhaps should do something different here?
202 LogMessage("[META] Warning: Failed to get list of user messages.");
203 LogMessage("[META] Warning: The 'meta game' command will not display user messages.");
206 baseFs = (IFileSystem *)((engineFactory)(FILESYSTEM_INTERFACE_VERSION, NULL));
209 LogMessage("[META] Failed to find filesystem interface, .vdf files will not be parsed.");
212 if (!g_SMConVarAccessor.InitConCommandBaseList())
214 /* This is very unlikely considering it's old engine */
215 LogMessage("[META] Warning: Failed to find ConCommandBase list!");
216 LogMessage("[META] Warning: ConVars and ConCommands cannot be unregistered properly! Please file a bug report.");
219 if (!bWaitForGameInit)
221 DoInitialPluginLoads();
222 bInFirstLevel = true;
228 bool DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals)
230 g_Engine.engineFactory = engineFactory;
231 g_Engine.fileSystemFactory = filesystemFactory;
232 g_Engine.physicsFactory = physicsFactory;
233 g_Engine.pGlobals = pGlobals;
235 StartupMetamod(engineFactory, false);
237 RETURN_META_VALUE(MRES_IGNORED, true);
240 bool AlternatelyLoadMetamod(CreateInterfaceFn ifaceFactory, CreateInterfaceFn serverFactory)
242 g_Engine.engineFactory = ifaceFactory;
243 g_Engine.fileSystemFactory = ifaceFactory;
244 g_Engine.physicsFactory = ifaceFactory;
246 IPlayerInfoManager *playerInfoManager = (IPlayerInfoManager *)serverFactory("PlayerInfoManager002", NULL);
247 if (playerInfoManager == NULL)
249 Error("Metamod:Source requires gameinfo.txt modification to load on this game.");
253 g_Engine.pGlobals = playerInfoManager->GetGlobalVars();
255 /* Now find the server */
256 g_GameDll.factory = serverFactory;
257 g_GameDll.lib = NULL;
259 char gamedll_iface[] = "ServerGameDLL000";
260 for (unsigned int i = 3; i <= 50; i++)
262 gamedll_iface[15] = '0' + i;
263 g_GameDll.pGameDLL = (IServerGameDLL *)serverFactory(gamedll_iface, NULL);
264 if (g_GameDll.pGameDLL != NULL)
266 g_GameDllVersion = i;
271 if (g_GameDll.pGameDLL == NULL)
273 Error("Metamod:Source requires gameinfo.txt modification to load on this game.");
277 char gameclients_iface[] = "ServerGameClients000";
278 for (unsigned int i = 3; i <= 4; i++)
280 gameclients_iface[19] = '0' + i;
281 g_GameDll.pGameClients = (IServerGameClients *)serverFactory(gameclients_iface, NULL);
282 if (g_GameDll.pGameClients != NULL)
288 char smm_path[PATH_SIZE];
289 const char *game_dir;
290 GetFileOfAddress((void *)AlternatelyLoadMetamod, smm_path, sizeof(smm_path));
291 g_SmmPath.assign(smm_path);
293 game_dir = CommandLine()->ParmValue("-game", "hl2");
294 abspath(smm_path, game_dir);
295 g_ModPath.assign(smm_path);
299 if (!StartupMetamod(ifaceFactory, true))
304 g_PluginMngr.SetAllLoaded();
309 bool GameInit_handler()
312 RETURN_META_VALUE(MRES_IGNORED, true);
314 if (g_SmmAPI.VSPEnabled() && !g_bIsBridgedAsVsp)
315 g_SmmAPI.LoadAsVSP();
317 if (g_bIsBridgedAsVsp)
318 DoInitialPluginLoads();
322 RETURN_META_VALUE(MRES_IGNORED, true);
325 bool DLLInit_Post(CreateInterfaceFn engineFactory, CreateInterfaceFn physicsFactory, CreateInterfaceFn filesystemFactory, CGlobalVars *pGlobals)
327 g_PluginMngr.SetAllLoaded();
328 RETURN_META_VALUE(MRES_IGNORED, true);
331 /* This is where the magic happens */
332 SMM_API void *CreateInterface(const char *iface, int *ret)
334 /* Prevent loading of self as a SourceMM plugin or Valve server plugin :x */
335 if (strcmp(iface, PLAPI_NAME) == 0)
337 Warning("Do not try loading Metamod:Source as a Metamod:Source plugin");
347 /* We check these separately because we can't reply
348 * unless our interface version really matches.
350 if (!g_bIsBridgedAsVsp &&
351 (strcmp(iface, VSPIFACE_002) == 0 ||
352 strcmp(iface, VSPIFACE_001) == 0))
358 return &g_VspListener;
361 /* If we're a VSP, bypass this by default */
362 if (g_bIsBridgedAsVsp)
364 IFACE_MACRO(g_GameDll.factory, GameDLL);
367 if (!gParsedGameInfo)
369 gParsedGameInfo = true;
370 const char *gameDir = NULL;
371 char gamePath[PATH_SIZE];
372 char smmPath[PATH_SIZE];
374 /* Get path to SourceMM DLL */
375 if (!GetFileOfAddress((void *)CreateInterface, smmPath, sizeof(smmPath)))
377 Error("GetFileOfAddress() failed! Metamod cannot load.\n");
381 g_SmmPath.assign(smmPath);
383 /* Get value of -game from command line, defaulting to hl2 as engine seems to do */
384 gameDir = CommandLine()->ParmValue("-game", "hl2");
386 /* Get absolute path */
387 abspath(gamePath, gameDir);
388 g_ModPath.assign(gamePath);
390 char tempPath[PATH_SIZE];
392 /* Path to gameinfo.txt */
393 g_SmmAPI.PathFormat(tempPath, PATH_SIZE, "%s/%s", g_ModPath.c_str(), "gameinfo.txt");
395 FILE *fp = fopen(tempPath, "rt");
399 Error("Unable to open gameinfo.txt! Metamod cannot load.\n");
404 char key[128], val[128];
407 bool gamebin = false;
410 char curPath[PATH_SIZE];
412 getcwd(curPath, PATH_SIZE);
417 fgets(buffer, sizeof(buffer), fp);
418 len = strlen(buffer);
419 if (buffer[len-1] == '\n')
420 buffer[--len] = '\0';
421 UTIL_TrimComments(buffer);
422 UTIL_TrimLeft(buffer);
423 UTIL_TrimRight(buffer);
424 if (stricmp(buffer, "SearchPaths") == 0)
428 UTIL_KeySplit(buffer, key, sizeof(key) - 1, val, sizeof(val) - 1);
429 if (stricmp(key, "Game") == 0 || stricmp(key, "GameBin") == 0)
431 if (stricmp(key, "Game") == 0)
436 if (strncmp(val, GAMEINFO_PATH, sizeof(GAMEINFO_PATH) - 1) == 0)
438 ptr = &(val[sizeof(GAMEINFO_PATH) - 1]);
441 lptr = g_ModPath.c_str();
447 size_t ptr_len = strlen(ptr);
448 if (ptr[ptr_len] == '/' || ptr[ptr_len] == '\\')
449 ptr[--ptr_len] = '\0';
451 /* No need to append "bin" if key is GameBin */
454 g_SmmAPI.PathFormat(tempPath, PATH_SIZE, "%s/%s/%s", lptr, ptr, SERVER_DLL);
455 } else if (!ptr[0]) {
456 g_SmmAPI.PathFormat(tempPath, PATH_SIZE, "%s/%s/%s", lptr, "bin", SERVER_DLL);
458 g_SmmAPI.PathFormat(tempPath, PATH_SIZE, "%s/%s/%s/%s", lptr, ptr, "bin", SERVER_DLL);
461 /* If not path to SourceMM... */
462 if (!UTIL_PathCmp(smmPath, tempPath))
464 FILE *fp = fopen(tempPath, "rb");
467 //:TODO: Optimize this a bit!
468 SourceHook::List<GameDllInfo *>::iterator iter;
471 for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
474 if (GetFileOfAddress((void *)pCheck->factory, buffer, sizeof(buffer)))
476 if (UTIL_PathCmp(tempPath, buffer))
486 HINSTANCE gamedll = dlmount(tempPath);
489 CreateInterfaceFn fn = (CreateInterfaceFn)dlsym(gamedll, "CreateInterface");
495 GameDllInfo *pInfo = new GameDllInfo;
497 pInfo->lib = gamedll;
498 pInfo->loaded = true;
499 pInfo->pGameDLL = NULL;
500 gamedll_list.push_back(pInfo);
508 if (!g_GameDll.loaded)
510 const char *str = "ServerGameDLL";
511 size_t len = strlen(str);
513 if (strncmp(iface, str, len) == 0)
515 /* This is the interface we want! Right now we support versions 3 through 8 */
516 g_GameDllVersion = atoi(&(iface[len]));
517 int sizeTooBig = 0; //rename this to sizeWrong in the future!
518 if (g_GameDllVersion < MIN_GAMEDLL_VERSION || g_GameDllVersion > MAX_GAMEDLL_VERSION)
520 /* Maybe this will get used in the future */
521 sizeTooBig = g_GameDllVersion;
527 SourceHook::List<GameDllInfo *>::iterator iter;
528 GameDllInfo *pInfo = NULL;
530 for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
533 ptr = (pInfo->factory)(iface, ret);
536 /* This is our GameDLL. Unload the others. */
537 gamedll_list.erase(iter);
539 pInfo->pGameDLL = static_cast<IServerGameDLL *>(ptr);
545 if (g_GameDll.loaded)
549 Error("This mod version requires a SourceMM update (ServerGameDLL%03d)!\n", sizeTooBig);
565 /* wtf do we do... */
566 /* :TODO: .. something a bit more intelligent? */
567 Error("Engine requested unknown interface before GameDLL was known!\n");
572 /* We use this interface for responding to the meta client command */
573 if (strncmp(iface, "ServerGameClients", 17) == 0)
575 void *ptr = (g_GameDll.factory)(iface, ret);
576 g_GameDll.pGameClients = static_cast<IServerGameClients *>(ptr);
581 /* If we got here, there's definitely a GameDLL */
582 IFACE_MACRO(g_GameDll.factory, GameDLL);
585 void ClearGamedllList()
587 SourceHook::List<GameDllInfo *>::iterator iter;
590 for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
597 gamedll_list.clear();
600 void UnloadMetamod(bool shutting_down)
603 g_PluginMngr.UnloadAll();
607 /* Add the FCVAR_GAMEDLL flag to our cvars so the engine removes them properly */
608 g_SMConVarAccessor.MarkCommandsAsGameDLL();
609 g_Engine.icvar->UnlinkVariables(FCVAR_GAMEDLL);
611 SH_CALL(g_GameDllPatch, &IServerGameDLL::DLLShutdown)();
614 SH_RELEASE_CALLCLASS(g_GameDllPatch);
615 SH_RELEASE_CALLCLASS(g_CvarPatch);
616 g_GameDllPatch = NULL;
619 g_SourceHook.CompleteShutdown();
621 if (g_GameDll.lib && g_GameDll.loaded)
623 dlclose(g_GameDll.lib);
625 memset(&g_GameDll, 0, sizeof(GameDllInfo));
628 void DLLShutdown_handler()
631 RETURN_META(MRES_SUPERCEDE);
634 void LoadFromVDF(const char *file)
637 bool already, kvfileLoaded;
639 const char *plugin_file, *alias;
640 char full_path[256], error[256];
642 pValues = new KeyValues("Metamod Plugin");
644 if (g_Engine.original)
646 /* The Ship must use a special version of this function */
647 kvfileLoaded = KVLoadFromFile(pValues, baseFs, file);
651 kvfileLoaded = pValues->LoadFromFile(baseFs, file);
656 pValues->deleteThis();
660 if ((plugin_file = pValues->GetString("file", NULL)) == NULL)
662 pValues->deleteThis();
666 if ((alias = pValues->GetString("alias", NULL)) != NULL)
668 g_PluginMngr.SetAlias(alias, plugin_file);
671 /* Attempt to find a file extension */
672 if (UTIL_GetExtension(plugin_file) == NULL)
674 g_SmmAPI.PathFormat(full_path,
679 #if defined WIN32 || defined _WIN32
688 g_SmmAPI.PathFormat(full_path,
695 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
696 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
698 LogMessage("[META] Failed to load plugin %s: %s", plugin_file, error);
701 pValues->deleteThis();
704 void LookForVDFs(const char *dir)
714 g_SmmAPI.PathFormat(path, sizeof(path), "%s\\*.*", dir);
715 if ((hFind = FindFirstFile(path, &fd)) == INVALID_HANDLE_VALUE)
717 DWORD dw = GetLastError();
718 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
721 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
725 LogMessage("[META] Could not open folder \"%s\" (%s)", dir, error);
731 if (strcmp(fd.cFileName, ".") == 0
732 || strcmp(fd.cFileName, "..") == 0)
736 extidx = strlen(fd.cFileName) - 4;
737 if (extidx < 0 || stricmp(&fd.cFileName[extidx], ".vdf"))
741 g_SmmAPI.PathFormat(path, sizeof(path), "%s\\%s", dir, fd.cFileName);
743 } while (FindNextFile(hFind, &fd));
750 if ((pDir = opendir(dir)) == NULL)
752 LogMessage("[META] Could not open folder \"%s\" (%s)", dir, strerror(errno));
756 while ((pEnt = readdir(pDir)) != NULL)
758 if (strcmp(pEnt->d_name, ".") == 0
759 || strcmp(pEnt->d_name, "..") == 0)
763 extidx = strlen(pEnt->d_name) - 4;
764 if (extidx < 0 || stricmp(&pEnt->d_name[extidx], ".vdf"))
768 g_SmmAPI.PathFormat(path, sizeof(path), "%s/%s", dir, pEnt->d_name);
776 bool KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID)
780 Assert(_heapchk() == _HEAPOK);
783 FileHandle_t f = filesystem->Open(resourceName, "rb", pathID);
787 // load file into a null-terminated buffer
788 int fileSize = filesystem->Size(f);
789 char *buffer = (char *)MemAllocScratch(fileSize + 1);
793 filesystem->Read(buffer, fileSize, f); // read into local buffer
795 buffer[fileSize] = 0; // null terminate file as EOF
797 filesystem->Close( f ); // close file after reading
799 bool retOK = kv->LoadFromBuffer( resourceName, buffer, filesystem );
806 int LoadPluginsFromFile(const char *_file)
809 int total = 0, skipped=0;
813 fp = fopen(_file, "rt");
816 LogMessage("[META] Could not open plugins file %s\n", _file);
820 char buffer[255], error[255], full_path[255];
821 const char *ptr, *ext, *file;
823 while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL)
825 UTIL_TrimLeft(buffer);
826 UTIL_TrimRight(buffer);
828 length = strlen(buffer);
834 if (buffer[0] == '\0' || buffer[0] == ';' || strncmp(buffer, "//", 2) == 0)
840 if (buffer[0] == '"')
863 while (*cptr && isspace(*cptr))
868 UTIL_TrimRight(cptr);
869 if (*cptr && isalpha(*cptr))
871 g_PluginMngr.SetAlias(buffer, cptr);
883 /* First find if it's an absolute path or not... */
884 if (file[0] == '/' || strncmp(&(file[1]), ":\\", 2) == 0)
886 /* If we're in an absolute path, ignore our normal heuristics */
887 id = g_PluginMngr.Load(file, Pl_File, already, error, sizeof(error));
888 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
890 LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
906 /* Attempt to find a file extension */
907 ptr = UTIL_GetExtension(file);
908 /* Add an extension if there's none there */
911 #if defined WIN32 || defined _WIN32
921 /* Format the new path */
922 g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s%s", g_ModPath.c_str(), file, ext);
923 id = g_PluginMngr.Load(full_path, Pl_File, already, error, sizeof(error));
924 if (id < Pl_MinId || g_PluginMngr.FindById(id)->m_Status < Pl_Paused)
926 LogMessage("[META] Failed to load plugin %s. %s", buffer, error);
945 LogMessage("[META] Loaded %d plugins from file (%d already loaded)", total, skipped);
949 LogMessage("[META] Loaded %d plugins from file.", total);
956 /* Wrapper function. This is called when the GameDLL thinks it's using
957 * the engine's real engineFactory.
959 void *EngineFactory(const char *iface, int *ret)
961 IFACE_MACRO(g_Engine.engineFactory, Engine);
964 /* Wrapper function. This is called when the GameDLL thinks it's using
965 * the engine's real physicsFactory.
967 void *PhysicsFactory(const char *iface, int *ret)
969 IFACE_MACRO(g_Engine.physicsFactory, Physics);
972 /* Wrapper function. This is called when the GameDLL thinks it's using
973 * the engine's real fileSystemFactory.
975 void *FileSystemFactory(const char *iface, int *ret)
977 IFACE_MACRO(g_Engine.fileSystemFactory, FileSystem);
980 void LogMessage(const char *msg, ...)
983 static char buffer[2048];
986 size_t len = vsnprintf(buffer, sizeof(buffer) - 2, msg, ap);
989 buffer[len++] = '\n';
992 if (!g_Engine.engine)
994 fprintf(stdout, "%s", buffer);
996 g_Engine.engine->LogPrint(buffer);
1000 void LevelShutdown_handler(void)
1004 char full_path[255];
1006 g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s", g_ModPath.c_str(), GetPluginsFile());
1007 LoadPluginsFromFile(full_path);
1009 g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s", g_ModPath.c_str(), GetMetamodBaseDir());
1010 LookForVDFs(full_path);
1014 bInFirstLevel = false;
1017 g_bLevelChanged = true;
1019 ITER_EVENT(OnLevelShutdown, ());
1021 RETURN_META(MRES_IGNORED);
1024 bool LevelInit_handler(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background)
1026 if (!g_SmmAPI.CmdCacheSuccessful())
1028 LogMessage("[META] Warning: Failed to initialize Con_Printf. Defaulting to Msg().");
1029 LogMessage("[META] Warning: Console messages will not be redirected to rcon console.");
1032 ITER_EVENT(OnLevelInit, (pMapName, pMapEntities, pOldLevel, pLandmarkName, loadGame, background));
1034 RETURN_META_VALUE(MRES_IGNORED, false);
1037 #if defined __GNUC__ && (__GNUC__ == 3 || __GNUC__ == 4)
1038 void * operator new(size_t size) {
1039 return(calloc(1, size));
1042 void * operator new[](size_t size) {
1043 return(calloc(1, size));
1046 void operator delete(void * ptr) {
1051 void operator delete[](void * ptr) {