1
0
mirror of https://github.com/alliedmodders/metamod-source.git synced 2025-01-30 19:52:17 +01:00

Added OnUnlinkConCommandBase to IMetamodListener to notify when Metamod:Source is about remove a concommand or convar.

--HG--
extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40419
This commit is contained in:
Scott Ehlert 2007-07-23 18:19:02 +00:00
parent 98caa6168f
commit e00aa3cbd4
6 changed files with 48 additions and 14 deletions

View File

@ -605,12 +605,12 @@ void CPluginManager::UnregAllConCmds(CPlugin *pl)
SourceHook::List<ConCommandBase *>::iterator i; SourceHook::List<ConCommandBase *>::iterator i;
for (i=pl->m_Cvars.begin(); i!=pl->m_Cvars.end(); i++) for (i=pl->m_Cvars.begin(); i!=pl->m_Cvars.end(); i++)
g_SMConVarAccessor.Unregister( (*i) ); g_SMConVarAccessor.Unregister(pl->m_Id, (*i) );
pl->m_Cvars.clear(); pl->m_Cvars.clear();
for (i=pl->m_Cmds.begin(); i!=pl->m_Cmds.end(); i++) for (i=pl->m_Cmds.begin(); i!=pl->m_Cmds.end(); i++)
g_SMConVarAccessor.Unregister( (*i) ); g_SMConVarAccessor.Unregister(pl->m_Id, (*i) );
pl->m_Cmds.clear(); pl->m_Cmds.clear();
} }

View File

@ -118,7 +118,7 @@ void CSmmAPI::UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
g_PluginMngr.RemovePluginCvar(plugin, pCommand); g_PluginMngr.RemovePluginCvar(plugin, pCommand);
} }
g_SMConVarAccessor.Unregister(pCommand); g_SMConVarAccessor.Unregister(g_PluginMngr.FindByAPI(plugin)->m_Id, pCommand);
} }
void CSmmAPI::ConPrint(const char *fmt) void CSmmAPI::ConPrint(const char *fmt)

View File

@ -20,7 +20,7 @@
#include <sourcehook/sourcehook.h> #include <sourcehook/sourcehook.h>
#include "ISmmAPI.h" #include "ISmmAPI.h"
#define PLAPI_VERSION 11 #define PLAPI_VERSION 12
#define PLAPI_NAME "ISmmPlugin" #define PLAPI_NAME "ISmmPlugin"
class ISmmAPI; class ISmmAPI;
@ -313,9 +313,15 @@ public:
* @param iface Interface pointer. If NULL, then the VSP listening construct * @param iface Interface pointer. If NULL, then the VSP listening construct
* failed to initialize and is not available. * failed to initialize and is not available.
*/ */
virtual void OnVSPListening(IServerPluginCallbacks *iface) virtual void OnVSPListening(IServerPluginCallbacks *iface) { }
{
} /* @brief Called when Metamod:Source is about to remove a concommand or convar.
* This can also be called if ISmmAPI::UnregisterConCmdBase is used by a plugin.
*
* @param id Id of the plugin that created the concommand or convar.
* @param pCommand Pointer to concommand or convar that is being removed.
*/
virtual void OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand) { }
}; };
#define PL_EXPOSURE CreateInterface #define PL_EXPOSURE CreateInterface

View File

@ -8,7 +8,9 @@
instance pointer rather than a callclass pointer. instance pointer rather than a callclass pointer.
- Added API for getting highest supported IServerPluginCallbacks interface - Added API for getting highest supported IServerPluginCallbacks interface
version. version.
- Added OnUnlinkConCommandBase to IMetamodListner to notify when Metamod:Source
is about to remove a concommand or convar.
2007/06/26 1.4.2: 2007/06/26 1.4.2:
- Fixed a bug where unloading all plugins could crash if one plugin had child - Fixed a bug where unloading all plugins could crash if one plugin had child
plugins. plugins.

View File

@ -57,18 +57,44 @@ void SMConVarAccessor::MarkCommandsAsGameDLL()
} }
} }
void SMConVarAccessor::Unregister(ConCommandBase *pCommand) void SMConVarAccessor::Unregister(PluginId id, ConCommandBase *pCommand)
{ {
/* Notify via IMetamodListener */
PluginIter iter;
SourceMM::CPluginManager::CPlugin *pPlugin;
SourceHook::List<IMetamodListener *>::iterator event;
IMetamodListener *pML;
for (iter=g_PluginMngr._begin(); iter!=g_PluginMngr._end(); iter++)
{
pPlugin = (*iter);
if (pPlugin->m_Status < Pl_Paused)
{
continue;
}
/* Only valid for plugins >= 12 (v1:6, SourceMM 1.5) */
if (pPlugin->m_API->GetApiVersion() < 12)
{
continue;
}
for (event=pPlugin->m_Events.begin();
event!=pPlugin->m_Events.end();
event++)
{
pML = (*event);
pML->OnUnlinkConCommandBase(id, pCommand);
}
}
ICvar *cv = g_Engine.icvar; ICvar *cv = g_Engine.icvar;
ConCommandBase *ptr = cv->GetCommands(); ConCommandBase *ptr = cv->GetCommands();
if (ptr == pCommand) if (ptr == pCommand)
{ {
//first in list /* First in list */
g_EternalCommand.BringToFront(); g_EternalCommand.BringToFront();
g_EternalCommand.SetNext(const_cast<ConCommandBase *>(pCommand->GetNext())); g_EternalCommand.SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));
} else { } else {
//find us and unregister us /* Find us and unregister us */
ConCommandBase *pPrev = NULL; ConCommandBase *pPrev = NULL;
while (ptr) while (ptr)
{ {
@ -91,10 +117,10 @@ void SMConVarAccessor::UnregisterGameDLLCommands()
ConCommandBase *prev = NULL; ConCommandBase *prev = NULL;
while (iter) while (iter)
{ {
// watch out for the ETERNAL COMMAND! /* Watch out for the ETERNAL COMMAND! */
if (iter != &g_EternalCommand && iter->IsBitSet(FCVAR_GAMEDLL)) if (iter != &g_EternalCommand && iter->IsBitSet(FCVAR_GAMEDLL))
{ {
// Remove it! /* Remove it! */
if (iter == begin) if (iter == begin)
{ {
g_EternalCommand.BringToFront(); g_EternalCommand.BringToFront();

View File

@ -29,7 +29,7 @@ public:
virtual bool RegisterConCommandBase(ConCommandBase *pCommand); virtual bool RegisterConCommandBase(ConCommandBase *pCommand);
bool Register(ConCommandBase *pCommand); bool Register(ConCommandBase *pCommand);
void MarkCommandsAsGameDLL(); void MarkCommandsAsGameDLL();
void Unregister(ConCommandBase *pCommand); void Unregister(PluginId id, ConCommandBase *pCommand);
void UnregisterGameDLLCommands(); void UnregisterGameDLLCommands();
}; };