1.1 --- a/sourcemm/CPlugin.cpp Sat Apr 16 20:26:33 2005 +0000
1.2 +++ b/sourcemm/CPlugin.cpp Sat Apr 16 23:33:39 2005 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /* ======== SourceMM ========
1.5 -* Copyright (C) 2004-2005 SourceMM Development Team
1.6 +* Copyright (C) 2004-2005 Metamod:Source Development Team
1.7 * No warranties of any kind
1.8 *
1.9 * License: zlib/libpng
1.10 @@ -9,7 +9,8 @@
1.11 */
1.12
1.13 #include "CPlugin.h"
1.14 -#include "CISmmAPI.h"
1.15 +#include "CSmmAPI.h"
1.16 +#include "sourcemm.h"
1.17
1.18 /**
1.19 * @brief Implements functions from CPlugin.h
1.20 @@ -36,6 +37,7 @@
1.21
1.22 CPluginManager::CPlugin::CPlugin() : m_Lib(NULL), m_API(NULL), m_Id(0), m_Source(0)
1.23 {
1.24 + memset(&fac_list, 0, sizeof(factories));
1.25 }
1.26
1.27 PluginId CPluginManager::Load(const char *file, PluginId source, bool &already, char *error, size_t maxlen)
1.28 @@ -108,17 +110,17 @@
1.29 return _Unpause(pl, error, maxlen);
1.30 }
1.31
1.32 -bool CPluginManager::Unload(PluginId id, char *error, size_t maxlen)
1.33 +bool CPluginManager::Unload(PluginId id, bool force, char *error, size_t maxlen)
1.34 {
1.35 CPlugin *pl = FindById(id);
1.36
1.37 if (!pl)
1.38 {
1.39 - snprintf(error, maxlen, "Plugin id not found");
1.40 + snprintf(error, maxlen, "Plugin %d not found", id);
1.41 return false;
1.42 }
1.43
1.44 - return _Unload(pl, error, maxlen);
1.45 + return _Unload(pl, force, error, maxlen);
1.46 }
1.47
1.48 CPluginManager::CPlugin *CPluginManager::_Load(const char *file, PluginId source, char *error, size_t maxlen)
1.49 @@ -196,14 +198,19 @@
1.50 return pl;
1.51 }
1.52
1.53 -bool CPluginManager::_Unload(CPluginManager::CPlugin *pl, char *error, size_t maxlen)
1.54 +bool CPluginManager::_Unload(CPluginManager::CPlugin *pl, bool force, char *error, size_t maxlen)
1.55 {
1.56 if (error)
1.57 *error = '\0';
1.58 if (pl->m_API && pl->m_Lib)
1.59 {
1.60 - if (pl->m_API->Unload(error, maxlen))
1.61 + //Note, we'll always tell the plugin it will be unloading...
1.62 + if (pl->m_API->Unload(error, maxlen) || force)
1.63 {
1.64 + //Make sure to detach it from sourcehook!
1.65 + g_SourceHook.UnloadPlugin(pl->m_Id);
1.66 +
1.67 + //Clean up the DLL
1.68 dlclose(pl->m_Lib);
1.69 pl->m_Lib = NULL;
1.70 pl->m_API = NULL;
1.71 @@ -218,6 +225,7 @@
1.72 break;
1.73 }
1.74 }
1.75 + //Free its memory
1.76 delete pl;
1.77
1.78 return true;
1.79 @@ -250,7 +258,10 @@
1.80 if (error)
1.81 snprintf(error, maxlen, "Plugin cannot be paused");
1.82 } else {
1.83 - return pl->m_API->Pause(error, maxlen);
1.84 + if (pl->m_API->Pause(error, maxlen))
1.85 + {
1.86 + g_SourceHook.PausePlugin(pl->m_Id);
1.87 + }
1.88 }
1.89
1.90 return false;
1.91 @@ -266,13 +277,15 @@
1.92 if (error)
1.93 snprintf(error, maxlen, "Plugin cannot be unpaused");
1.94 } else {
1.95 - return pl->m_API->Unpause(error, maxlen);
1.96 + if (pl->m_API->Unpause(error, maxlen))
1.97 + {
1.98 + g_SourceHook.UnpausePlugin(pl->m_Id);
1.99 + }
1.100 }
1.101
1.102 return false;
1.103 }
1.104
1.105 -
1.106 bool CPluginManager::UnloadAll()
1.107 {
1.108 PluginIter i;
1.109 @@ -287,6 +300,10 @@
1.110 if ( (*i)->m_API->Unload(NULL, 0) )
1.111 status = false;
1.112
1.113 + //Unlink from SourceHook
1.114 + g_SourceHook.UnloadPlugin( (*i)->m_Id );
1.115 +
1.116 + //Free the DLL
1.117 dlclose( (*i)->m_Lib );
1.118 }
1.119 delete (*i);