extensions/sdktools/tenatives.cpp
changeset 1430 be0ed85786bb
parent 1330 ab94316bb52b
child 1457 591c38df0b47
     1.1 --- a/extensions/sdktools/tenatives.cpp	Sun Sep 16 02:36:49 2007 +0000
     1.2 +++ b/extensions/sdktools/tenatives.cpp	Sun Sep 16 03:28:30 2007 +0000
     1.3 @@ -48,10 +48,12 @@
     1.4  void TempEntHooks::Initialize()
     1.5  {
     1.6  	m_TEHooks = adtfactory->CreateBasicTrie();
     1.7 +	plsys->AddPluginsListener(this);
     1.8  }
     1.9  
    1.10  void TempEntHooks::Shutdown()
    1.11  {
    1.12 +	plsys->RemovePluginsListener(this);
    1.13  	List<TEHookInfo *>::iterator iter;
    1.14  	for (iter=m_HookInfo.begin(); iter!=m_HookInfo.end(); iter++)
    1.15  	{
    1.16 @@ -65,6 +67,47 @@
    1.17  	m_TEHooks->Destroy();
    1.18  }
    1.19  
    1.20 +void TempEntHooks::OnPluginUnloaded(IPlugin *plugin)
    1.21 +{
    1.22 +	List<TEHookInfo *>::iterator iter = m_HookInfo.begin();
    1.23 +	IPluginContext *pContext = plugin->GetBaseContext();
    1.24 +
    1.25 +	/* For each hook list... */
    1.26 +	while (iter != m_HookInfo.end())
    1.27 +	{
    1.28 +		List<IPluginFunction *>::iterator f_iter = (*iter)->lst.begin();
    1.29 +
    1.30 +		/* Find the hooks on the given temp entity */
    1.31 +		while (f_iter != (*iter)->lst.end())
    1.32 +		{
    1.33 +			/* If it matches, remove it and dec the ref count */
    1.34 +			if ((*f_iter)->GetParentContext() == pContext)
    1.35 +			{
    1.36 +				f_iter = (*iter)->lst.erase(f_iter);
    1.37 +				_DecRefCounter();
    1.38 +			}
    1.39 +			else
    1.40 +			{
    1.41 +				f_iter++;
    1.42 +			}
    1.43 +		}
    1.44 +
    1.45 +		/* If there are no more hooks left, we can safely 
    1.46 +		 * remove it from the cache and remove its list.
    1.47 +		 */
    1.48 +		if ((*iter)->lst.size() == 0)
    1.49 +		{
    1.50 +			m_TEHooks->Delete((*iter)->te->GetName());
    1.51 +			delete (*iter);
    1.52 +			iter = m_HookInfo.erase(iter);
    1.53 +		}
    1.54 +		else
    1.55 +		{
    1.56 +			iter++;
    1.57 +		}
    1.58 +	}
    1.59 +}
    1.60 +
    1.61  void TempEntHooks::_IncRefCounter()
    1.62  {
    1.63  	if (m_HookCount++ == 0)