1.1 --- a/core/ConVarManager.cpp Mon Jul 23 17:38:06 2007 +0000
1.2 +++ b/core/ConVarManager.cpp Mon Jul 23 18:30:02 2007 +0000
1.3 @@ -31,6 +31,10 @@
1.4
1.5 ConVarManager::ConVarManager() : m_ConVarType(0), m_VSPIface(NULL), m_CanQueryConVars(false)
1.6 {
1.7 +#if PLAPI_VERSION < 12
1.8 + m_IgnoreHandle = false;
1.9 +#endif
1.10 +
1.11 /* Create a convar lookup trie */
1.12 m_ConVarCache = sm_trie_create();
1.13 }
1.14 @@ -127,6 +131,52 @@
1.15 }
1.16 }
1.17
1.18 +#if PLAPI_VERSION >= 12
1.19 +void ConVarManager::OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
1.20 +{
1.21 + /* Only check convars that have not been created by SourceMod's core */
1.22 + if (id != g_PLID && !pCommand->IsCommand())
1.23 + {
1.24 + ConVarInfo *pInfo;
1.25 + HandleSecurity sec(NULL, g_pCoreIdent);
1.26 + bool handleExists = sm_trie_retrieve(m_ConVarCache, pCommand->GetName(), reinterpret_cast<void **>(&pInfo));
1.27 +
1.28 + if (handleExists)
1.29 + {
1.30 + g_HandleSys.FreeHandle(pInfo->handle, &sec);
1.31 + }
1.32 + }
1.33 +}
1.34 +
1.35 +#else
1.36 +
1.37 +/* I truly detest this code */
1.38 +void ConVarManager::OnMetamodPluginUnloaded(PluginId id)
1.39 +{
1.40 + ConVarInfo *pInfo;
1.41 + const char *cvarName;
1.42 + HandleSecurity sec(NULL, g_pCoreIdent);
1.43 +
1.44 + List<ConVarInfo *>::iterator i;
1.45 + for (i = m_ConVars.begin(); i != m_ConVars.end(); i++)
1.46 + {
1.47 + pInfo = (*i);
1.48 + cvarName = pInfo->name;
1.49 +
1.50 + if (!icvar->FindVar(cvarName))
1.51 + {
1.52 + m_IgnoreHandle = true;
1.53 + g_HandleSys.FreeHandle(pInfo->handle, &sec);
1.54 +
1.55 + sm_trie_delete(m_ConVarCache, cvarName);
1.56 + m_ConVars.erase(i);
1.57 +
1.58 + delete [] cvarName;
1.59 + }
1.60 + }
1.61 +}
1.62 +#endif
1.63 +
1.64 void ConVarManager::OnPluginUnloaded(IPlugin *plugin)
1.65 {
1.66 ConVarList *pConVarList;
1.67 @@ -140,6 +190,15 @@
1.68
1.69 void ConVarManager::OnHandleDestroy(HandleType_t type, void *object)
1.70 {
1.71 +#if PLAPI_VERSION < 12
1.72 + /* Lovely workaround for our workaround! */
1.73 + if (m_IgnoreHandle)
1.74 + {
1.75 + m_IgnoreHandle = false;
1.76 + return;
1.77 + }
1.78 +#endif
1.79 +
1.80 ConVarInfo *info;
1.81 ConVar *pConVar = static_cast<ConVar *>(object);
1.82
1.83 @@ -235,6 +294,9 @@
1.84 pInfo->sourceMod = false;
1.85 pInfo->pChangeForward = NULL;
1.86 pInfo->origCallback = pConVar->GetCallback();
1.87 + #if PLAPI_VERSION < 12
1.88 + pInfo->name = sm_strdup(pConVar->GetName());
1.89 + #endif
1.90
1.91 /* Insert struct into caches */
1.92 m_ConVars.push_back(pInfo);
1.93 @@ -310,6 +372,9 @@
1.94 pInfo->sourceMod = false;
1.95 pInfo->pChangeForward = NULL;
1.96 pInfo->origCallback = pConVar->GetCallback();
1.97 +#if PLAPI_VERSION < 12
1.98 + pInfo->name = sm_strdup(pConVar->GetName());
1.99 +#endif
1.100
1.101 /* Insert struct into our caches */
1.102 m_ConVars.push_back(pInfo);