1.1 --- a/sourcemm/sourcemm.cpp Sat Oct 15 17:55:31 2005 +0000
1.2 +++ b/sourcemm/sourcemm.cpp Thu Oct 20 14:37:47 2005 +0000
1.3 @@ -15,8 +15,11 @@
1.4 #include "sourcemm.h"
1.5 #include "concommands.h"
1.6 #include "CSmmAPI.h"
1.7 +#include "CPlugin.h"
1.8 #include "util.h"
1.9
1.10 +using namespace SourceMM;
1.11 +
1.12 /**
1.13 * @brief Implementation of main SourceMM GameDLL functionality
1.14 * @file sourcemm.cpp
1.15 @@ -45,6 +48,26 @@
1.16
1.17 void ClearGamedllList();
1.18
1.19 +//helper macro
1.20 +#define IFACE_MACRO(orig,nam) \
1.21 + CPluginManager::CPlugin *pl; \
1.22 + SourceHook::List<IMetamodListener *>::iterator event; \
1.23 + IMetamodListener *api; \
1.24 + int mret = 0; \
1.25 + void *val = NULL; \
1.26 + for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \
1.27 + pl = (*iter); \
1.28 + for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \
1.29 + api = (*event); \
1.30 + mret = IFACE_FAILED; \
1.31 + if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \
1.32 + if (ret) *ret = mret; \
1.33 + return val; \
1.34 + } \
1.35 + } \
1.36 + } \
1.37 + return (orig)(iface, ret);
1.38 +
1.39 ///////////////////////////////////
1.40 // Main code for HL2 Interaction //
1.41 ///////////////////////////////////
1.42 @@ -115,7 +138,7 @@
1.43 }
1.44
1.45 //This is where the magic happens
1.46 -SMM_API void *CreateInterface(const char *name, int *ret)
1.47 +SMM_API void *CreateInterface(const char *iface, int *ret)
1.48 {
1.49 if (!gParsedGameInfo)
1.50 {
1.51 @@ -317,10 +340,10 @@
1.52 const char *str = "ServerGameDLL";
1.53 size_t len = strlen(str);
1.54
1.55 - if (strncmp(name, str, len) == 0)
1.56 + if (strncmp(iface, str, len) == 0)
1.57 {
1.58 //This is the interface we want! Right now we support versions 3 and 4.
1.59 - int version = atoi(&(name[len]));
1.60 + int version = atoi(&(iface[len]));
1.61 if (version < MIN_GAMEDLL_VERSION || version > MAX_GAMEDLL_VERSION)
1.62 {
1.63 Error("GameDLL version %d is not supported by Metamod!", version);
1.64 @@ -332,7 +355,7 @@
1.65 for (iter=gamedll_list.begin(); iter!=gamedll_list.end(); iter++)
1.66 {
1.67 pInfo = (*iter);
1.68 - ptr = (pInfo->factory)(name, ret);
1.69 + ptr = (pInfo->factory)(iface, ret);
1.70 if (ptr)
1.71 {
1.72 //this is our gamedll. unload the others.
1.73 @@ -361,8 +384,7 @@
1.74 }
1.75
1.76 //if we got here, there's definitely a gamedll.
1.77 - //META_INTERFACE_MACRO(server, g_GameDll.factory);
1.78 - return (g_GameDll.factory)(name, ret);
1.79 + IFACE_MACRO(g_GameDll.factory, GameDLL);
1.80 }
1.81
1.82 void ClearGamedllList()
1.83 @@ -491,23 +513,23 @@
1.84
1.85 //Wrapper function. This is called when the GameDLL thinks it's using
1.86 // the engine's real engineFactory.
1.87 -void *EngineFactory(const char *name, int *ret)
1.88 +void *EngineFactory(const char *iface, int *ret)
1.89 {
1.90 - META_INTERFACE_MACRO(engine, g_Engine.engineFactory);
1.91 + IFACE_MACRO(g_Engine.engineFactory, Engine);
1.92 }
1.93
1.94 //Wrapper function. This is called when the GameDLL thinks it's using
1.95 // the engine's real physicsFactory.
1.96 -void *PhysicsFactory(const char *name, int *ret)
1.97 +void *PhysicsFactory(const char *iface, int *ret)
1.98 {
1.99 - META_INTERFACE_MACRO(physics, g_Engine.physicsFactory);
1.100 + IFACE_MACRO(g_Engine.physicsFactory, Physics);
1.101 }
1.102
1.103 //Wrapper function. This is called when the GameDLL thinks it's using
1.104 // the engine's real fileSystemFactory.
1.105 -void *FileSystemFactory(const char *name, int *ret)
1.106 +void *FileSystemFactory(const char *iface, int *ret)
1.107 {
1.108 - META_INTERFACE_MACRO(fileSystem, g_Engine.fileSystemFactory);
1.109 + IFACE_MACRO(g_Engine.fileSystemFactory, FileSystem);
1.110 }
1.111
1.112 void LogMessage(const char *msg, ...)