1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core-legacy/gamedll_bridge.cpp Sun Nov 23 21:22:04 2008 -0600
1.3 @@ -0,0 +1,91 @@
1.4 +#include <assert.h>
1.5 +#include "sourcemm.h"
1.6 +#include "CPlugin.h"
1.7 +#include <loader_bridge.h>
1.8 +
1.9 +using namespace SourceMM;
1.10 +
1.11 +#define IFACE_MACRO(orig,nam) \
1.12 + CPluginManager::CPlugin *pl; \
1.13 + SourceHook::List<CPluginEventHandler>::iterator event; \
1.14 + IMetamodListener *api; \
1.15 + int mret = 0; \
1.16 + void *val = NULL; \
1.17 + for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
1.18 + pl = (*iter); \
1.19 + for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
1.20 + api = (*event).event; \
1.21 + mret = IFACE_FAILED; \
1.22 + if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
1.23 + if (ret) *ret = mret; \
1.24 + return val; \
1.25 + } \
1.26 + } \
1.27 + } \
1.28 + return (orig)(iface, ret);
1.29 +
1.30 +
1.31 +class GameDllBridge : public IGameDllBridge
1.32 +{
1.33 +public:
1.34 + virtual bool DLLInit_Pre(const gamedll_bridge_info *info, char *buffer, size_t maxlength)
1.35 + {
1.36 + assert(!g_GameDll.loaded && !g_bIsBridgedAsVsp);
1.37 + LoadAsGameDLL(info);
1.38 + return true;
1.39 + }
1.40 + virtual void DLLInit_Post()
1.41 + {
1.42 + g_PluginMngr.SetAllLoaded();
1.43 + }
1.44 + virtual void *QueryInterface(const char *iface, int *ret)
1.45 + {
1.46 + /* We use this interface for responding to the meta client command */
1.47 + if (strncmp(iface, "ServerGameClients", 17) == 0)
1.48 + {
1.49 + void *ptr = (g_GameDll.factory)(iface, ret);
1.50 + g_GameDll.pGameClients = static_cast<IServerGameClients *>(ptr);
1.51 + return ptr;
1.52 + }
1.53 +
1.54 + /* If we got here, there's definitely a GameDLL */
1.55 + IFACE_MACRO(g_GameDll.factory, GameDLL);
1.56 + }
1.57 + virtual void Unload()
1.58 + {
1.59 + }
1.60 +};
1.61 +
1.62 +GameDllBridge mm14_gamedll_bridge;
1.63 +
1.64 +SMM_API IGameDllBridge *
1.65 +GetGameDllBridge()
1.66 +{
1.67 + return &mm14_gamedll_bridge;
1.68 +}
1.69 +
1.70 +/* Wrapper function. This is called when the GameDLL thinks it's using
1.71 + * the engine's real engineFactory.
1.72 + */
1.73 +void *EngineFactory(const char *iface, int *ret)
1.74 +{
1.75 + IFACE_MACRO(g_Engine.engineFactory, Engine);
1.76 +}
1.77 +
1.78 +/* Wrapper function. This is called when the GameDLL thinks it's using
1.79 + * the engine's real physicsFactory.
1.80 + */
1.81 +void *PhysicsFactory(const char *iface, int *ret)
1.82 +{
1.83 + IFACE_MACRO(g_Engine.physicsFactory, Physics);
1.84 +}
1.85 +
1.86 +/* Wrapper function. This is called when the GameDLL thinks it's using
1.87 + * the engine's real fileSystemFactory.
1.88 + */
1.89 +void *FileSystemFactory(const char *iface, int *ret)
1.90 +{
1.91 + IFACE_MACRO(g_Engine.fileSystemFactory, FileSystem);
1.92 +}
1.93 +
1.94 +