From 11c8084ccd530290df459e12b50e5852f777ddee Mon Sep 17 00:00:00 2001 From: Benoist <14257866+Kenzzer@users.noreply.github.com> Date: Sat, 11 Nov 2023 17:59:22 +0100 Subject: [PATCH] Deprecate CreateInterface (#2001) * Deprecate CreateInterface Co-authored-by: KitRifty <4492504+KitRifty@users.noreply.github.com> * Expose the 'newer' data * Update smsdk_ext.cpp --------- Co-authored-by: Kenzzer Co-authored-by: KitRifty <4492504+KitRifty@users.noreply.github.com> --- public/smsdk_ext.cpp | 33 +++++++++++++-------------------- public/smsdk_ext.h | 9 +++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/public/smsdk_ext.cpp b/public/smsdk_ext.cpp index bad4dbb4..e9b8d768 100644 --- a/public/smsdk_ext.cpp +++ b/public/smsdk_ext.cpp @@ -297,6 +297,12 @@ void SDKExtension::SDK_OnDependenciesDropped() #if defined SMEXT_CONF_METAMOD +#if defined _MSC_VER +#define SMEXT_DLL_EXPORT extern "C" __declspec(dllexport) +#else +#define SMEXT_DLL_EXPORT extern "C" __attribute__((visibility("default"))) +#endif + PluginId g_PLID = 0; /**< Metamod plugin ID */ ISmmPlugin *g_PLAPI = NULL; /**< Metamod plugin API */ SourceHook::ISourceHook *g_SHPtr = NULL; /**< SourceHook pointer */ @@ -308,27 +314,9 @@ IServerGameDLL *gamedll = NULL; /**< IServerGameDLL pointer */ #endif /** Exposes the extension to Metamod */ -SMM_API void *PL_EXPOSURE(const char *name, int *code) +SMEXT_DLL_EXPORT METAMOD_PLUGIN *CreateInterface_MMS(const MetamodVersionInfo *mvi, const MetamodLoaderInfo *mli) { -#if defined METAMOD_PLAPI_VERSION - if (name && !strcmp(name, METAMOD_PLAPI_NAME)) -#else - if (name && !strcmp(name, PLAPI_NAME)) -#endif - { - if (code) - { - *code = META_IFACE_OK; - } - return static_cast(g_pExtensionIface); - } - - if (code) - { - *code = META_IFACE_FAILED; - } - - return NULL; + return g_pExtensionIface->SDK_OnMetamodCreateInterface(mvi, mli); } bool SDKExtension::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late) @@ -457,6 +445,11 @@ const char *SDKExtension::GetVersion() return GetExtensionVerString(); } +METAMOD_PLUGIN *SDKExtension::SDK_OnMetamodCreateInterface(const MetamodVersionInfo *mvi, const MetamodLoaderInfo *mli) +{ + return this; +} + bool SDKExtension::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late) { return true; diff --git a/public/smsdk_ext.h b/public/smsdk_ext.h index b5d6a2d4..156d0116 100644 --- a/public/smsdk_ext.h +++ b/public/smsdk_ext.h @@ -152,6 +152,15 @@ public: virtual void SDK_OnDependenciesDropped(); #if defined SMEXT_CONF_METAMOD + /** + * @brief Called when Metamod is requesting the extension (ISmmPlugin) interface. + * + * @param mvi Struct that contains Metamod version, SourceHook version, Plugin version and Source Engine version. + * @param mli Struct that contains the library file name and path being loaded. + * @return The ISmmPlugin interface. + */ + virtual METAMOD_PLUGIN *SDK_OnMetamodCreateInterface(const MetamodVersionInfo *mvi, const MetamodLoaderInfo *mli); + /** * @brief Called when Metamod is attached, before the extension version is called. *