Added OnUnlinkConCommandBase to IMetamodListener to notify when Metamod:Source is about remove a concommand or convar.
Added OnUnlinkConCommandBase to IMetamodListener to notify when Metamod:Source is about remove a concommand or convar.
1.1 --- a/sourcemm/CPlugin.cpp Fri Jul 20 22:21:14 2007 +0000
1.2 +++ b/sourcemm/CPlugin.cpp Mon Jul 23 18:19:02 2007 +0000
1.3 @@ -605,12 +605,12 @@
1.4 SourceHook::List<ConCommandBase *>::iterator i;
1.5
1.6 for (i=pl->m_Cvars.begin(); i!=pl->m_Cvars.end(); i++)
1.7 - g_SMConVarAccessor.Unregister( (*i) );
1.8 + g_SMConVarAccessor.Unregister(pl->m_Id, (*i) );
1.9
1.10 pl->m_Cvars.clear();
1.11
1.12 for (i=pl->m_Cmds.begin(); i!=pl->m_Cmds.end(); i++)
1.13 - g_SMConVarAccessor.Unregister( (*i) );
1.14 + g_SMConVarAccessor.Unregister(pl->m_Id, (*i) );
1.15
1.16 pl->m_Cmds.clear();
1.17 }
2.1 --- a/sourcemm/CSmmAPI.cpp Fri Jul 20 22:21:14 2007 +0000
2.2 +++ b/sourcemm/CSmmAPI.cpp Mon Jul 23 18:19:02 2007 +0000
2.3 @@ -118,7 +118,7 @@
2.4 g_PluginMngr.RemovePluginCvar(plugin, pCommand);
2.5 }
2.6
2.7 - g_SMConVarAccessor.Unregister(pCommand);
2.8 + g_SMConVarAccessor.Unregister(g_PluginMngr.FindByAPI(plugin)->m_Id, pCommand);
2.9 }
2.10
2.11 void CSmmAPI::ConPrint(const char *fmt)
3.1 --- a/sourcemm/ISmmPlugin.h Fri Jul 20 22:21:14 2007 +0000
3.2 +++ b/sourcemm/ISmmPlugin.h Mon Jul 23 18:19:02 2007 +0000
3.3 @@ -20,7 +20,7 @@
3.4 #include <sourcehook/sourcehook.h>
3.5 #include "ISmmAPI.h"
3.6
3.7 -#define PLAPI_VERSION 11
3.8 +#define PLAPI_VERSION 12
3.9 #define PLAPI_NAME "ISmmPlugin"
3.10
3.11 class ISmmAPI;
3.12 @@ -313,9 +313,15 @@
3.13 * @param iface Interface pointer. If NULL, then the VSP listening construct
3.14 * failed to initialize and is not available.
3.15 */
3.16 - virtual void OnVSPListening(IServerPluginCallbacks *iface)
3.17 - {
3.18 - }
3.19 + virtual void OnVSPListening(IServerPluginCallbacks *iface) { }
3.20 +
3.21 + /* @brief Called when Metamod:Source is about to remove a concommand or convar.
3.22 + * This can also be called if ISmmAPI::UnregisterConCmdBase is used by a plugin.
3.23 + *
3.24 + * @param id Id of the plugin that created the concommand or convar.
3.25 + * @param pCommand Pointer to concommand or convar that is being removed.
3.26 + */
3.27 + virtual void OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand) { }
3.28 };
3.29
3.30 #define PL_EXPOSURE CreateInterface
4.1 --- a/sourcemm/changelog.txt Fri Jul 20 22:21:14 2007 +0000
4.2 +++ b/sourcemm/changelog.txt Mon Jul 23 18:19:02 2007 +0000
4.3 @@ -8,7 +8,9 @@
4.4 instance pointer rather than a callclass pointer.
4.5 - Added API for getting highest supported IServerPluginCallbacks interface
4.6 version.
4.7 -
4.8 + - Added OnUnlinkConCommandBase to IMetamodListner to notify when Metamod:Source
4.9 + is about to remove a concommand or convar.
4.10 +
4.11 2007/06/26 1.4.2:
4.12 - Fixed a bug where unloading all plugins could crash if one plugin had child
4.13 plugins.
5.1 --- a/sourcemm/concommands.cpp Fri Jul 20 22:21:14 2007 +0000
5.2 +++ b/sourcemm/concommands.cpp Mon Jul 23 18:19:02 2007 +0000
5.3 @@ -57,18 +57,44 @@
5.4 }
5.5 }
5.6
5.7 -void SMConVarAccessor::Unregister(ConCommandBase *pCommand)
5.8 +void SMConVarAccessor::Unregister(PluginId id, ConCommandBase *pCommand)
5.9 {
5.10 + /* Notify via IMetamodListener */
5.11 + PluginIter iter;
5.12 + SourceMM::CPluginManager::CPlugin *pPlugin;
5.13 + SourceHook::List<IMetamodListener *>::iterator event;
5.14 + IMetamodListener *pML;
5.15 + for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
5.16 + {
5.17 + pPlugin = (*iter);
5.18 + if (pPlugin->m_Status < Pl_Paused)
5.19 + {
5.20 + continue;
5.21 + }
5.22 + /* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
5.23 + if (pPlugin->m_API->GetApiVersion() < 12)
5.24 + {
5.25 + continue;
5.26 + }
5.27 + for (event=pPlugin->m_Events.begin();
5.28 + event!=pPlugin->m_Events.end();
5.29 + event++)
5.30 + {
5.31 + pML = (*event);
5.32 + pML->OnUnlinkConCommandBase(id, pCommand);
5.33 + }
5.34 + }
5.35 +
5.36 ICvar *cv = g_Engine.icvar;
5.37 ConCommandBase *ptr = cv->GetCommands();
5.38
5.39 if (ptr == pCommand)
5.40 {
5.41 - //first in list
5.42 + /* First in list */
5.43 g_EternalCommand.BringToFront();
5.44 g_EternalCommand.SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));
5.45 } else {
5.46 - //find us and unregister us
5.47 + /* Find us and unregister us */
5.48 ConCommandBase *pPrev = NULL;
5.49 while (ptr)
5.50 {
5.51 @@ -91,10 +117,10 @@
5.52 ConCommandBase *prev = NULL;
5.53 while (iter)
5.54 {
5.55 - // watch out for the ETERNAL COMMAND!
5.56 + /* Watch out for the ETERNAL COMMAND! */
5.57 if (iter != &g_EternalCommand && iter->IsBitSet(FCVAR_GAMEDLL))
5.58 {
5.59 - // Remove it!
5.60 + /* Remove it! */
5.61 if (iter == begin)
5.62 {
5.63 g_EternalCommand.BringToFront();
6.1 --- a/sourcemm/concommands.h Fri Jul 20 22:21:14 2007 +0000
6.2 +++ b/sourcemm/concommands.h Mon Jul 23 18:19:02 2007 +0000
6.3 @@ -29,7 +29,7 @@
6.4 virtual bool RegisterConCommandBase(ConCommandBase *pCommand);
6.5 bool Register(ConCommandBase *pCommand);
6.6 void MarkCommandsAsGameDLL();
6.7 - void Unregister(ConCommandBase *pCommand);
6.8 + void Unregister(PluginId id, ConCommandBase *pCommand);
6.9 void UnregisterGameDLLCommands();
6.10 };
6.11