1.1 --- a/sourcemm/ISmmPlugin.h Mon Oct 08 20:12:06 2007 +0000
1.2 +++ b/sourcemm/ISmmPlugin.h Mon Oct 08 20:21:14 2007 +0000
1.3 @@ -38,7 +38,7 @@
1.4 #include <IPluginManager.h>
1.5 #include <ISmmAPI.h>
1.6
1.7 -#define METAMOD_PLAPI_VERSION 13 /**< Version of this header file */
1.8 +#define METAMOD_PLAPI_VERSION 14 /**< Version of this header file */
1.9 #define METAMOD_PLAPI_NAME "ISmmPlugin" /**< Name of the plugin interface */
1.10
1.11 namespace SourceMM
2.1 --- a/sourcemm/ISmmPluginExt.h Mon Oct 08 20:12:06 2007 +0000
2.2 +++ b/sourcemm/ISmmPluginExt.h Mon Oct 08 20:21:14 2007 +0000
2.3 @@ -30,9 +30,11 @@
2.4
2.5 namespace SourceMM
2.6 {
2.7 - class ISmmAPI;
2.8 + class ISmmPlugin;
2.9 }
2.10
2.11 +typedef SourceMM::ISmmPlugin METAMOD_PLUGIN;
2.12 +
2.13 /**
2.14 * @file ISmmPluginExt.h Definitions for extended plugin exposure syntax.
2.15 * @brief Provides an alternate method for loading plugins, without needing to
2.16 @@ -74,14 +76,17 @@
2.17 * @param mli MetamodLoaderInfo structure.
2.18 * @return ISmmAPI pointer, or NULL if none.
2.19 */
2.20 -typedef SourceMM::ISmmAPI *(*METAMOD_FN_LOAD)(const MetamodVersionInfo *mvi,
2.21 - const MetamodLoaderInfo *mli);
2.22 +typedef METAMOD_PLUGIN *(*METAMOD_FN_LOAD)(const MetamodVersionInfo *mvi,
2.23 + const MetamodLoaderInfo *mli);
2.24
2.25 /**
2.26 * @brief If a function of this type is exposed as "UnloadInterface_MMS", then
2.27 * Metamod:Source will attempt to call this function after calling
2.28 * ISmmAPI::Unload(), and before closing the library. This lets loader plugins
2.29 * clean up before exiting.
2.30 + *
2.31 + * Note: This function will be ignored unless CreateInterfce_MMS was exposed.
2.32 + * It may be called even if ISmmAPI::Unload() could not be called.
2.33 */
2.34 typedef void (*METAMOD_FN_UNLOAD)();
2.35
3.1 --- a/sourcemm/metamod.cpp Mon Oct 08 20:12:06 2007 +0000
3.2 +++ b/sourcemm/metamod.cpp Mon Oct 08 20:21:14 2007 +0000
3.3 @@ -876,8 +876,8 @@
3.4
3.5 void MetamodSource::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
3.6 {
3.7 - major = SM_VERS_API_MAJOR;
3.8 - minor = SM_VERS_API_MINOR;
3.9 + major = METAMOD_API_MAJOR;
3.10 + minor = METAMOD_API_MINOR;
3.11 plvers = METAMOD_PLAPI_VERSION;
3.12 plmin = PLAPI_MIN_VERSION;
3.13 }
4.1 --- a/sourcemm/metamod.h Mon Oct 08 20:12:06 2007 +0000
4.2 +++ b/sourcemm/metamod.h Mon Oct 08 20:21:14 2007 +0000
4.3 @@ -51,8 +51,8 @@
4.4 */
4.5 #define SOURCEMM_VERSION SVN_FILE_VERSION_STRING
4.6 #define SOURCEMM_DATE __DATE__
4.7 -#define SM_VERS_API_MAJOR 2 //increase this on a breaking change
4.8 -#define SM_VERS_API_MINOR 0 //increase this on a non-breaking API change
4.9 +#define METAMOD_API_MAJOR 2 /* increase this on a breaking change */
4.10 +#define METAMOD_API_MINOR 0 /* increase this on a non-breaking API change */
4.11
4.12 class MetamodSource : public ISmmAPI
4.13 {
5.1 --- a/sourcemm/metamod_plugins.cpp Mon Oct 08 20:12:06 2007 +0000
5.2 +++ b/sourcemm/metamod_plugins.cpp Mon Oct 08 20:21:14 2007 +0000
5.3 @@ -60,6 +60,17 @@
5.4
5.5 CPluginManager g_PluginMngr;
5.6
5.7 +MetamodVersionInfo GlobVersionInfo =
5.8 +{
5.9 + METAMOD_API_MAJOR,
5.10 + METAMOD_API_MINOR,
5.11 + SH_IFACE_VERSION,
5.12 + SH_IMPL_VERSION,
5.13 + PLAPI_MIN_VERSION,
5.14 + METAMOD_PLAPI_VERSION,
5.15 + SOURCE_ENGINE_UNKNOWN
5.16 +};
5.17 +
5.18 CPluginManager::CPluginManager()
5.19 {
5.20 m_LastId = Pl_MinId;
5.21 @@ -139,7 +150,7 @@
5.22 }
5.23 }
5.24
5.25 -CPluginManager::CPlugin::CPlugin() : m_Id(0), m_Source(0), m_API(NULL), m_Lib(NULL)
5.26 +CPluginManager::CPlugin::CPlugin() : m_Id(0), m_Source(0), m_API(NULL), m_Lib(NULL), m_UnloadFn(NULL)
5.27 {
5.28
5.29 }
5.30 @@ -415,63 +426,96 @@
5.31 }
5.32 else
5.33 {
5.34 - CreateInterfaceFn pfn = (CreateInterfaceFn)(dlsym(pl->m_Lib, PL_EXPOSURE_C));
5.35 - if (!pfn)
5.36 + pl->m_API = NULL;
5.37 +
5.38 + /**
5.39 + * First, try the new "advanced" interface
5.40 + */
5.41 + METAMOD_FN_LOAD fnLoad = (METAMOD_FN_LOAD)dlsym(pl->m_Lib, "CreateInterface_MMS");
5.42 + if (fnLoad != NULL)
5.43 {
5.44 - if (error)
5.45 + if (GlobVersionInfo.source_engine == SOURCE_ENGINE_UNKNOWN)
5.46 {
5.47 - UTIL_Format(error, maxlen, "Function %s not found", PL_EXPOSURE_C);
5.48 + GlobVersionInfo.source_engine = g_Metamod.GetSourceEngineBuild();
5.49 }
5.50 - pl->m_Status = Pl_Error;
5.51 +
5.52 + pl->m_API = fnLoad(&GlobVersionInfo, NULL);
5.53 + pl->m_UnloadFn = (METAMOD_FN_UNLOAD)dlsym(pl->m_Lib, "UnloadInterface_MMS");
5.54 }
5.55 - else
5.56 +
5.57 + /**
5.58 + * If we didn't get anything, try the normal/simple interface.
5.59 + */
5.60 + if (pl->m_API == NULL)
5.61 {
5.62 - pl->m_API = static_cast<ISmmPlugin *>((pfn)(METAMOD_PLAPI_NAME, NULL));
5.63 - if (!pl->m_API)
5.64 + CreateInterfaceFn pfn = (CreateInterfaceFn)(dlsym(pl->m_Lib, PL_EXPOSURE_C));
5.65 + if (!pfn)
5.66 {
5.67 if (error)
5.68 {
5.69 - UTIL_Format(error, maxlen, "Failed to get API");
5.70 + UTIL_Format(error, maxlen, "Function %s not found", PL_EXPOSURE_C);
5.71 }
5.72 pl->m_Status = Pl_Error;
5.73 }
5.74 else
5.75 {
5.76 - int api = pl->m_API->GetApiVersion();
5.77 - if (api < PLAPI_MIN_VERSION)
5.78 + pl->m_API = static_cast<ISmmPlugin *>((pfn)(METAMOD_PLAPI_NAME, NULL));
5.79 +
5.80 + if (!pl->m_API)
5.81 {
5.82 if (error)
5.83 {
5.84 - UTIL_Format(error, maxlen, "Plugin API %d is out of date with required minimum (%d)", api, PLAPI_MIN_VERSION);
5.85 - }
5.86 - pl->m_Status = Pl_Error;
5.87 - }
5.88 - else if (api > METAMOD_PLAPI_VERSION)
5.89 - {
5.90 - if (error)
5.91 - {
5.92 - UTIL_Format(error, maxlen, "Plugin API %d is newer than internal version (%d)", api, METAMOD_PLAPI_VERSION);
5.93 + UTIL_Format(error, maxlen, "Failed to get API");
5.94 }
5.95 pl->m_Status = Pl_Error;
5.96 }
5.97 - else
5.98 + }
5.99 + }
5.100 +
5.101 + if (pl->m_API != NULL)
5.102 + {
5.103 + int api = pl->m_API->GetApiVersion();
5.104 + if (api < PLAPI_MIN_VERSION)
5.105 + {
5.106 + if (error)
5.107 {
5.108 - if (pl->m_API->Load(pl->m_Id, &g_Metamod, error, maxlen, m_AllLoaded))
5.109 + if (api == 13)
5.110 {
5.111 - pl->m_Status = Pl_Running;
5.112 - if (m_AllLoaded)
5.113 - {
5.114 - //API 4 is when we added this callback
5.115 - //Removing this code as the min version is now 5
5.116 - //if (pl->m_API->GetApiVersion() >= 4)
5.117 - pl->m_API->AllPluginsLoaded();
5.118 - }
5.119 + UTIL_Format(error, maxlen, "Plugin uses experimental Metamod build, probably 1.6.x (%d < %d)", api, PLAPI_MIN_VERSION);
5.120 + }
5.121 + else if (api <= 12 && api >= 7)
5.122 + {
5.123 + UTIL_Format(error, maxlen, "Older Metamod version required, probably 1.4.x (%d < %d)", api, PLAPI_MIN_VERSION);
5.124 }
5.125 else
5.126 {
5.127 - pl->m_Status = Pl_Refused;
5.128 + UTIL_Format(error, maxlen, "Older Metamod version required, probably 1.0 (%d < %d)", api, PLAPI_MIN_VERSION);
5.129 }
5.130 }
5.131 + pl->m_Status = Pl_Error;
5.132 + }
5.133 + else if (api > METAMOD_PLAPI_VERSION)
5.134 + {
5.135 + if (error)
5.136 + {
5.137 + UTIL_Format(error, maxlen, "Plugin requires newer Metamod version (%d > %d)", api, METAMOD_PLAPI_VERSION);
5.138 + }
5.139 + pl->m_Status = Pl_Error;
5.140 + }
5.141 + else
5.142 + {
5.143 + if (pl->m_API->Load(pl->m_Id, &g_Metamod, error, maxlen, m_AllLoaded))
5.144 + {
5.145 + pl->m_Status = Pl_Running;
5.146 + if (m_AllLoaded)
5.147 + {
5.148 + pl->m_API->AllPluginsLoaded();
5.149 + }
5.150 + }
5.151 + else
5.152 + {
5.153 + pl->m_Status = Pl_Refused;
5.154 + }
5.155 }
5.156 }
5.157 }
5.158 @@ -483,6 +527,11 @@
5.159 g_SourceHook.UnloadPlugin(pl->m_Id);
5.160 UnregAllConCmds(pl);
5.161
5.162 + if (pl->m_UnloadFn != NULL)
5.163 + {
5.164 + pl->m_UnloadFn();
5.165 + }
5.166 +
5.167 dlclose(pl->m_Lib);
5.168 pl->m_Lib = NULL;
5.169 pl->m_API = NULL;
5.170 @@ -510,6 +559,11 @@
5.171
5.172 UnregAllConCmds(pl);
5.173
5.174 + if (pl->m_UnloadFn != NULL)
5.175 + {
5.176 + pl->m_UnloadFn();
5.177 + }
5.178 +
5.179 //Clean up the DLL
5.180 dlclose(pl->m_Lib);
5.181 pl->m_Lib = NULL;
6.1 --- a/sourcemm/metamod_plugins.h Mon Oct 08 20:12:06 2007 +0000
6.2 +++ b/sourcemm/metamod_plugins.h Mon Oct 08 20:21:14 2007 +0000
6.3 @@ -38,7 +38,8 @@
6.4 #include <convar.h>
6.5 #include <sh_list.h>
6.6 #include <sh_string.h>
6.7 -#include "IPluginManager.h"
6.8 +#include <IPluginManager.h>
6.9 +#include <ISmmPluginExt.h>
6.10 #include "metamod_oslink.h"
6.11
6.12 /**
6.13 @@ -58,10 +59,11 @@
6.14 * 10: Added VSP listen functions to ISmmAPI and IMetamodListener (2007-02-09)
6.15 * 11: New SourceHook version v4.5 (May, 2007)
6.16 * 12: Orange Box API
6.17 - * MC 13: Breaking of API for next SH version and other API changes
6.18 + * 13: Breaking of API for next SH version and other API changes
6.19 + * MC 14: ABI stability reached for 1.6.0 changes
6.20 */
6.21
6.22 -#define PLAPI_MIN_VERSION 13
6.23 +#define PLAPI_MIN_VERSION 14
6.24
6.25 struct CNameAlias
6.26 {
6.27 @@ -91,6 +93,7 @@
6.28 SourceHook::List<ConCommandBase *> m_Cvars;
6.29 SourceHook::List<ConCommandBase *> m_Cmds;
6.30 SourceHook::List<IMetamodListener *> m_Events;
6.31 + METAMOD_FN_UNLOAD m_UnloadFn;
6.32 };
6.33 public:
6.34 CPluginManager();