diff --git a/sourcemm/CPlugin.cpp b/sourcemm/CPlugin.cpp index 218a1ad..239f277 100644 --- a/sourcemm/CPlugin.cpp +++ b/sourcemm/CPlugin.cpp @@ -12,6 +12,7 @@ #include "CSmmAPI.h" #include "sourcemm.h" #include "concommands.h" +#include "vsp_listener.h" /** * @brief Implements functions from CPlugin.h @@ -22,14 +23,14 @@ using namespace SourceMM; #define ITER_PLEVENT(evn, plid) \ CPluginManager::CPlugin *_Xpl; \ - SourceHook::List::iterator event; \ + SourceHook::List::iterator event; \ IMetamodListener *api; \ for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \ _Xpl = (*iter); \ if (_Xpl->m_Id == plid) \ continue; \ for (event=_Xpl->m_Events.begin(); event!=_Xpl->m_Events.end(); event++) { \ - api = (*event); \ + api = (*event).event; \ api->evn(plid); \ } \ } @@ -182,6 +183,38 @@ void CPluginManager::SetAllLoaded() } } +void CPluginManager::SetVSPAsLoaded() +{ + PluginIter i; + CPlugin *pPlugin; + SourceHook::List::iterator event; + + for (i = m_Plugins.begin(); i != m_Plugins.end(); i++) + { + pPlugin = (*i); + if (pPlugin->m_Status < Pl_Paused) + { + continue; + } + /* Only valid for plugins >= 10 (v1:5, SourceMM 1.4) */ + if (pPlugin->m_API->GetApiVersion() < 10) + { + continue; + } + for (event = pPlugin->m_Events.begin(); + event != pPlugin->m_Events.end(); + event++) + { + if (!(*event).got_vsp) + { + continue; + } + (*event).got_vsp = true; + (*event).event->OnVSPListening(&g_VspListener); + } + } +} + bool CPluginManager::Pause(PluginId id, char *error, size_t maxlen) { CPlugin *pl = FindById(id); @@ -373,6 +406,21 @@ CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source //if (pl->m_API->GetApiVersion() >= 4) pl->m_API->AllPluginsLoaded(); } + if (g_VspListener.IsRootLoadMethod()) + { + SourceHook::List::iterator event; + for (event = pl->m_Events.begin(); + event != pl->m_Events.end(); + event++) + { + if ((*event).got_vsp) + { + continue; + } + (*event).got_vsp = true; + (*event).event->OnVSPListening(&g_VspListener); + } + } } else { pl->m_Status = Pl_Refused; } diff --git a/sourcemm/CPlugin.h b/sourcemm/CPlugin.h index 005041f..86058be 100644 --- a/sourcemm/CPlugin.h +++ b/sourcemm/CPlugin.h @@ -50,6 +50,13 @@ namespace SourceMM SourceHook::String alias; SourceHook::String value; }; + + struct CPluginEventHandler + { + bool got_vsp; + IMetamodListener *event; + }; + /** * @brief Implements Plugin Manager API */ @@ -72,7 +79,7 @@ namespace SourceMM HINSTANCE m_Lib; SourceHook::List m_Cvars; SourceHook::List m_Cmds; - SourceHook::List m_Events; + SourceHook::List m_Events; }; public: CPluginManager(); @@ -123,6 +130,8 @@ namespace SourceMM //Internal iterators SourceHook::List::iterator _begin(); SourceHook::List::iterator _end(); + + void SetVSPAsLoaded(); private: //These are identical internal functions for the wrappers above. CPlugin *_Load(const char *file, PluginId source, char *error, size_t maxlen); diff --git a/sourcemm/CSmmAPI.cpp b/sourcemm/CSmmAPI.cpp index 317d31a..7538f15 100644 --- a/sourcemm/CSmmAPI.cpp +++ b/sourcemm/CSmmAPI.cpp @@ -141,8 +141,12 @@ void CSmmAPI::ConPrintf(const char *fmt, ...) void CSmmAPI::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener) { CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin); + CPluginEventHandler cpeh; - pl->m_Events.push_back(pListener); + cpeh.event = pListener; + cpeh.got_vsp = false; + + pl->m_Events.push_back(cpeh); } void *CSmmAPI::MetaFactory(const char *iface, int *_ret, PluginId *id) @@ -174,7 +178,7 @@ void *CSmmAPI::MetaFactory(const char *iface, int *_ret, PluginId *id) } CPluginManager::CPlugin *pl; - SourceHook::List::iterator event; + SourceHook::List::iterator event; IMetamodListener *api; int ret = 0; void *val = NULL; @@ -184,7 +188,7 @@ void *CSmmAPI::MetaFactory(const char *iface, int *_ret, PluginId *id) pl = (*iter); for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { - api = (*event); + api = (*event).event; ret = IFACE_FAILED; if ( (val=api->OnMetamodQuery(iface, &ret)) != NULL ) { diff --git a/sourcemm/sourcemm.cpp b/sourcemm/sourcemm.cpp index fd6ceb4..d1f3210 100644 --- a/sourcemm/sourcemm.cpp +++ b/sourcemm/sourcemm.cpp @@ -73,14 +73,14 @@ void ClearGamedllList(); /* Helper Macro */ #define IFACE_MACRO(orig,nam) \ CPluginManager::CPlugin *pl; \ - SourceHook::List::iterator event; \ + SourceHook::List::iterator event; \ IMetamodListener *api; \ int mret = 0; \ void *val = NULL; \ for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \ pl = (*iter); \ for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \ - api = (*event); \ + api = (*event).event; \ mret = IFACE_FAILED; \ if ( (val=api->On##nam##Query(iface, &mret)) != NULL ) { \ if (ret) *ret = mret; \ @@ -92,12 +92,12 @@ void ClearGamedllList(); #define ITER_EVENT(evn, args) \ CPluginManager::CPlugin *pl; \ - SourceHook::List::iterator event; \ + SourceHook::List::iterator event; \ IMetamodListener *api; \ for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++) { \ pl = (*iter); \ for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++) { \ - api = (*event); \ + api = (*event).event; \ api->evn args; \ } \ } @@ -308,6 +308,7 @@ bool GameInit_handler() if (g_VspListener.IsRootLoadMethod()) { DoInitialPluginLoads(); + //gaben } bGameInit = true; diff --git a/sourcemm/svn_version.h b/sourcemm/svn_version.h index 0523c0c..15f8b97 100644 --- a/sourcemm/svn_version.h +++ b/sourcemm/svn_version.h @@ -5,9 +5,9 @@ #define SVN_PRODUCT_VERSION "1.4.3" -#define SVN_REVISION 590 -#define SVN_REVISION_STRING "590" -#define SVN_FILE_VERSION 1,4,3,590 -#define SVN_FILE_VERSION_STRING "1.4.3.590" +#define SVN_REVISION 599 +#define SVN_REVISION_STRING "599" +#define SVN_FILE_VERSION 1,4,3,599 +#define SVN_FILE_VERSION_STRING "1.4.3.599" #endif //_INCLUDE_SVN_VERSION_H_ diff --git a/sourcemm/vsp_listener.cpp b/sourcemm/vsp_listener.cpp index d3f13e6..0a4889c 100644 --- a/sourcemm/vsp_listener.cpp +++ b/sourcemm/vsp_listener.cpp @@ -178,29 +178,9 @@ bool VSPListener::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gam m_Loaded = true; SetLoadable(false); - PluginIter iter; - CPluginManager::CPlugin *pPlugin; - SourceHook::List::iterator event; - IMetamodListener *pML; - for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++) + if (!m_bIsRootLoadMethod) { - pPlugin = (*iter); - if (pPlugin->m_Status < Pl_Paused) - { - continue; - } - /* Only valid for plugins >= 10 (v1:5, SourceMM 1.4) */ - if (pPlugin->m_API->GetApiVersion() < 10) - { - continue; - } - for (event=pPlugin->m_Events.begin(); - event!=pPlugin->m_Events.end(); - event++) - { - pML = (*event); - pML->OnVSPListening(this); - } + g_PluginMngr.SetVSPAsLoaded(); } return true;