fixed amb951 - te hooking did not auto-remove hooks from plugins

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401436
This commit is contained in:
David Anderson 2007-09-16 03:28:30 +00:00
parent 82108a7fcd
commit 95c46b781e
5 changed files with 59 additions and 1 deletions

View File

@ -70,5 +70,6 @@
#define SMEXT_ENABLE_GAMEHELPERS #define SMEXT_ENABLE_GAMEHELPERS
//#define SMEXT_ENABLE_TIMERSYS //#define SMEXT_ENABLE_TIMERSYS
#define SMEXT_ENABLE_ADTFACTORY #define SMEXT_ENABLE_ADTFACTORY
#define SMEXT_ENABLE_PLUGINSYS
#endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_ #endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_

View File

@ -79,6 +79,9 @@ IThreader *threader = NULL;
#if defined SMEXT_ENABLE_LIBSYS #if defined SMEXT_ENABLE_LIBSYS
ILibrarySys *libsys = NULL; ILibrarySys *libsys = NULL;
#endif #endif
#if defined SMEXT_ENABLE_PLUGINSYS
SourceMod::IPluginManager *plsys;
#endif
/** Exports the main interface */ /** Exports the main interface */
PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI() PLATFORM_EXTERN_C IExtensionInterface *GetSMExtAPI()
@ -149,6 +152,9 @@ bool SDKExtension::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error,
#if defined SMEXT_ENABLE_LIBSYS #if defined SMEXT_ENABLE_LIBSYS
SM_GET_IFACE(LIBRARYSYS, libsys); SM_GET_IFACE(LIBRARYSYS, libsys);
#endif #endif
#if defined SMEXT_ENABLE_PLUGINSYS
SM_GET_IFACE(PLUGINSYSTEM, plsys);
#endif
if (SDK_OnLoad(error, maxlength, late)) if (SDK_OnLoad(error, maxlength, late))
{ {

View File

@ -73,6 +73,9 @@
#if defined SMEXT_ENABLE_LIBSYS #if defined SMEXT_ENABLE_LIBSYS
#include <ILibrarySys.h> #include <ILibrarySys.h>
#endif #endif
#if defined SMEXT_ENABLE_PLUGINSYS
#include <IPluginSys.h>
#endif
#if defined SMEXT_CONF_METAMOD #if defined SMEXT_CONF_METAMOD
#include <ISmmPlugin.h> #include <ISmmPlugin.h>
@ -256,6 +259,9 @@ extern IThreader *threader;
#if defined SMEXT_ENABLE_LIBSYS #if defined SMEXT_ENABLE_LIBSYS
extern ILibrarySys *libsys; extern ILibrarySys *libsys;
#endif #endif
#if defined SMEXT_ENABLE_PLUGINSYS
extern SourceMod::IPluginManager *plsys;
#endif
#if defined SMEXT_CONF_METAMOD #if defined SMEXT_CONF_METAMOD
PLUGIN_GLOBALVARS(); PLUGIN_GLOBALVARS();

View File

@ -94,8 +94,10 @@ struct TEHookInfo
List<IPluginFunction *> lst; List<IPluginFunction *> lst;
}; };
class TempEntHooks class TempEntHooks : public IPluginsListener
{ {
public: //IPluginsListener
void OnPluginUnloaded(IPlugin *plugin);
public: public:
void Initialize(); void Initialize();
void Shutdown(); void Shutdown();

View File

@ -48,10 +48,12 @@ int g_TEPlayers[256];
void TempEntHooks::Initialize() void TempEntHooks::Initialize()
{ {
m_TEHooks = adtfactory->CreateBasicTrie(); m_TEHooks = adtfactory->CreateBasicTrie();
plsys->AddPluginsListener(this);
} }
void TempEntHooks::Shutdown() void TempEntHooks::Shutdown()
{ {
plsys->RemovePluginsListener(this);
List<TEHookInfo *>::iterator iter; List<TEHookInfo *>::iterator iter;
for (iter=m_HookInfo.begin(); iter!=m_HookInfo.end(); iter++) for (iter=m_HookInfo.begin(); iter!=m_HookInfo.end(); iter++)
{ {
@ -65,6 +67,47 @@ void TempEntHooks::Shutdown()
m_TEHooks->Destroy(); m_TEHooks->Destroy();
} }
void TempEntHooks::OnPluginUnloaded(IPlugin *plugin)
{
List<TEHookInfo *>::iterator iter = m_HookInfo.begin();
IPluginContext *pContext = plugin->GetBaseContext();
/* For each hook list... */
while (iter != m_HookInfo.end())
{
List<IPluginFunction *>::iterator f_iter = (*iter)->lst.begin();
/* Find the hooks on the given temp entity */
while (f_iter != (*iter)->lst.end())
{
/* If it matches, remove it and dec the ref count */
if ((*f_iter)->GetParentContext() == pContext)
{
f_iter = (*iter)->lst.erase(f_iter);
_DecRefCounter();
}
else
{
f_iter++;
}
}
/* If there are no more hooks left, we can safely
* remove it from the cache and remove its list.
*/
if ((*iter)->lst.size() == 0)
{
m_TEHooks->Delete((*iter)->te->GetName());
delete (*iter);
iter = m_HookInfo.erase(iter);
}
else
{
iter++;
}
}
}
void TempEntHooks::_IncRefCounter() void TempEntHooks::_IncRefCounter()
{ {
if (m_HookCount++ == 0) if (m_HookCount++ == 0)