diff --git a/core/sourcemm_api.cpp b/core/sourcemm_api.cpp index 3ac89de7..0ee04a95 100644 --- a/core/sourcemm_api.cpp +++ b/core/sourcemm_api.cpp @@ -33,6 +33,7 @@ #include "sourcemm_api.h" #include "sm_version.h" #include "Logger.h" +#include "ExtensionSys.h" #include "concmd_cleaner.h" #include "compat_wrappers.h" @@ -219,3 +220,21 @@ void SourceMod_Core::OnPluginUnload(PluginId id) } #endif + +void *SourceMod_Core::OnMetamodQuery(const char *iface, int *ret) +{ + void *ptr = NULL; + + if (strcmp(iface, SOURCEMOD_INTERFACE_EXTENSIONS) == 0) + { + ptr = (IExtensionManager *)&g_Extensions; + } + + if (ret != NULL) + { + *ret = (ptr == NULL) ? IFACE_FAILED : IFACE_OK; + } + + return NULL; +} + diff --git a/core/sourcemm_api.h b/core/sourcemm_api.h index 7fba5258..85b85817 100644 --- a/core/sourcemm_api.h +++ b/core/sourcemm_api.h @@ -79,6 +79,7 @@ public: #else void OnPluginUnload(PluginId id); #endif + void *OnMetamodQuery(const char *iface, int *ret); }; extern SourceMod_Core g_SourceMod_Core; @@ -105,3 +106,4 @@ extern int vsp_version; PLUGIN_GLOBALVARS(); #endif //_INCLUDE_SOURCEMOD_MM_API_H_ + diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index 777e98fe..e59afd31 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -406,6 +406,9 @@ void SourceModBase::DoGlobalPluginLoads() /* Load any auto extensions */ g_Extensions.TryAutoload(); + /* Fire the extensions ready message */ + g_SMAPI->MetaFactory(SOURCEMOD_NOTICE_EXTENSIONS, NULL, NULL); + /* Load any game extension */ const char *game_ext; if ((game_ext = g_pGameConf->GetKeyValue("GameExtension")) != NULL) diff --git a/public/IExtensionSys.h b/public/IExtensionSys.h index 31b8d647..1c64bd84 100644 --- a/public/IExtensionSys.h +++ b/public/IExtensionSys.h @@ -288,6 +288,24 @@ namespace SourceMod virtual const char *GetExtensionDateString() =0; }; + /** + * @brief Returned via OnMetamodQuery() to get an IExtensionManager pointer. + */ + #define SOURCEMOD_INTERFACE_EXTENSIONS "SM_ExtensionManager" + + /** + * @brief Fired through OnMetamodQuery() to notify plugins that SourceMod is + * loaded. + * + * Plugins should not return an interface pointer or IFACE_OK, instead, + * they should attach as needed by searching for SOURCEMOD_INTERFACE_EXTENSIONS. + * + * This may be fired more than once; if already attached, an extension should + * not attempt to re-attach. The purpose of this is to notify Metamod:Source + * plugins which load after SourceMod loads. + */ + #define SOURCEMOD_NOTICE_EXTENSIONS "SM_ExtensionsAttachable" + #define SMINTERFACE_EXTENSIONMANAGER_NAME "IExtensionManager" #define SMINTERFACE_EXTENSIONMANAGER_VERSION 2 @@ -389,7 +407,8 @@ namespace SourceMod } #define SM_FIND_IFACE(prefix, variable) \ - sharesys->RequestInterface(SM_IFACEPAIR(prefix), myself, (SMInterface **)&variable)); + sharesys->RequestInterface(SM_IFACEPAIR(prefix), myself, (SMInterface **)&variable); } #endif //_INCLUDE_SOURCEMOD_MODULE_INTERFACE_H_ +`