1.1 --- a/sourcemm/CSmmAPI.cpp Sat Oct 15 17:55:31 2005 +0000
1.2 +++ b/sourcemm/CSmmAPI.cpp Thu Oct 20 14:37:47 2005 +0000
1.3 @@ -28,16 +28,6 @@
1.4 m_Cache = false;
1.5 }
1.6
1.7 -ISmmPluginManager *CSmmAPI::PluginManager()
1.8 -{
1.9 - return static_cast<ISmmPluginManager *>(&g_PluginMngr);
1.10 -}
1.11 -
1.12 -SourceHook::ISourceHook *CSmmAPI::SourceHook()
1.13 -{
1.14 - return static_cast<SourceHook::ISourceHook *>(&g_SourceHook);
1.15 -}
1.16 -
1.17 void CSmmAPI::LogMsg(ISmmPlugin *pl, const char *msg, ...)
1.18 {
1.19 va_list ap;
1.20 @@ -139,6 +129,58 @@
1.21 va_end(ap);
1.22 }
1.23
1.24 +void CSmmAPI::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
1.25 +{
1.26 + CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
1.27 +
1.28 + pl->m_Events.push_back(pListener);
1.29 +}
1.30 +
1.31 +void *CSmmAPI::MetaFactory(const char *iface, int *_ret)
1.32 +{
1.33 + if (!iface)
1.34 + return NULL;
1.35 +
1.36 + //first check ours... we get first chance!
1.37 + if (strcmp(iface, MMIFACE_SOURCEHOOK)==0)
1.38 + {
1.39 + if (_ret)
1.40 + *_ret = IFACE_OK;
1.41 + return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
1.42 + } else if (strcmp(iface, MMIFACE_PLMANAGER)==0) {
1.43 + if (_ret)
1.44 + *_ret = IFACE_OK;
1.45 + return static_cast<void *>(static_cast<IConCommandBaseAccessor *>(&g_SMConVarAccessor));
1.46 + }
1.47 +
1.48 + CPluginManager::CPlugin *pl;
1.49 + SourceHook::List<IMetamodListener *>::iterator event;
1.50 + IMetamodListener *api;
1.51 + int ret = 0;
1.52 + void *val = NULL;
1.53 +
1.54 + for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++)
1.55 + {
1.56 + pl = (*iter);
1.57 + for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++)
1.58 + {
1.59 + api = (*event);
1.60 + ret = IFACE_FAILED;
1.61 + if ( (val=api->OnMetamodQuery(iface, &ret)) != NULL )
1.62 + {
1.63 + if (_ret)
1.64 + *_ret = ret;
1.65 + return val;
1.66 + }
1.67 + }
1.68 + }
1.69 +
1.70 + if (_ret)
1.71 + *_ret = IFACE_FAILED;
1.72 +
1.73 + return NULL;
1.74 +}
1.75 +
1.76 //////////////////////////////////////////////////////////////////////////
1.77 //THERE BE HAX HERE!!!! DON'T TELL ALFRED, BUT GABE WANTED IT THAT WAY. //
1.78 // (note: you can find the offset by looking for the text //