Fix dependency graph.
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.
31 #include <loader_bridge.h>
33 using namespace SourceMM;
35 #define IFACE_MACRO(orig,nam) \
36 CPluginManager::CPlugin *pl; \
37 SourceHook::List<CPluginEventHandler>::iterator event; \
38 IMetamodListener *api; \
41 for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
43 for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
44 api = (*event).event; \
45 mret = IFACE_FAILED; \
46 if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
47 if (ret) *ret = mret; \
52 return (orig)(iface, ret);
55 class GameDllBridge : public IGameDllBridge
58 virtual bool DLLInit_Pre(const gamedll_bridge_info *info, char *buffer, size_t maxlength)
60 assert(!g_GameDll.loaded && !g_bIsBridgedAsVsp);
64 virtual void DLLInit_Post(int *isgdUnload)
66 SourceHook::MemFuncInfo mfi;
68 mfi.isVirtual = false;
69 SourceHook::GetFuncInfo(&IServerGameDLL::DLLShutdown, mfi);
70 assert(mfi.isVirtual);
71 assert(mfi.vtbloffs == 0);
72 assert(mfi.thisptroffs == 0);
73 *isgdUnload = mfi.vtblindex;
75 g_PluginMngr.SetAllLoaded();
77 virtual void *QueryInterface(const char *iface, int *ret)
79 /* We use this interface for responding to the meta client command */
80 if (strncmp(iface, "ServerGameClients", 17) == 0)
82 void *ptr = (g_GameDll.factory)(iface, ret);
83 g_GameDll.pGameClients = static_cast<IServerGameClients *>(ptr);
87 /* If we got here, there's definitely a GameDLL */
88 IFACE_MACRO(g_GameDll.factory, GameDLL);
96 GameDllBridge mm14_gamedll_bridge;
98 SMM_API IGameDllBridge *
101 return &mm14_gamedll_bridge;
104 void *ServerFactory(const char *name, int *code)
106 return mm14_gamedll_bridge.QueryInterface(name, code);
109 /* Wrapper function. This is called when the GameDLL thinks it's using
110 * the engine's real engineFactory.
112 void *EngineFactory(const char *iface, int *ret)
114 IFACE_MACRO(g_Engine.engineFactory, Engine);
117 /* Wrapper function. This is called when the GameDLL thinks it's using
118 * the engine's real physicsFactory.
120 void *PhysicsFactory(const char *iface, int *ret)
122 IFACE_MACRO(g_Engine.physicsFactory, Physics);
125 /* Wrapper function. This is called when the GameDLL thinks it's using
126 * the engine's real fileSystemFactory.
128 void *FileSystemFactory(const char *iface, int *ret)
130 IFACE_MACRO(g_Engine.fileSystemFactory, FileSystem);