From bf38135d88620146e4b3068f5c65dd71e9ccf614 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Tue, 24 Apr 2007 22:07:00 +0000 Subject: [PATCH] Added ISmmAPI::GetVSPVersion() to get highest supported IServerPluginCallbacks interface version --HG-- extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40379 --- sourcemm/CSmmAPI.cpp | 5 +++++ sourcemm/CSmmAPI.h | 1 + sourcemm/ISmmAPI.h | 14 ++++++++++++-- sourcemm/changelog.txt | 3 +++ sourcemm/sourcemm.cpp | 21 +++++++++++---------- sourcemm/sourcemm.h | 10 ++++++++-- 6 files changed, 40 insertions(+), 14 deletions(-) diff --git a/sourcemm/CSmmAPI.cpp b/sourcemm/CSmmAPI.cpp index 0f336d2..f9a9670 100644 --- a/sourcemm/CSmmAPI.cpp +++ b/sourcemm/CSmmAPI.cpp @@ -629,3 +629,8 @@ const char *CSmmAPI::GetUserMessage(int index, int *size) return msg->name; } + +int CSmmAPI::GetVSPVersion() +{ + return g_VspVersion; +} diff --git a/sourcemm/CSmmAPI.h b/sourcemm/CSmmAPI.h index 914fb7f..546b77b 100644 --- a/sourcemm/CSmmAPI.h +++ b/sourcemm/CSmmAPI.h @@ -70,6 +70,7 @@ namespace SourceMM int GetUserMessageCount(); int FindUserMessage(const char *name, int *size=NULL); const char *GetUserMessage(int index, int *size=NULL); + int GetVSPVersion(); public: bool CacheCmds(); bool CmdCacheSuccessful(); diff --git a/sourcemm/ISmmAPI.h b/sourcemm/ISmmAPI.h index e6e90a7..3b2d6b6 100644 --- a/sourcemm/ISmmAPI.h +++ b/sourcemm/ISmmAPI.h @@ -266,7 +266,7 @@ public: // Added in 1.4 (1:5) /** * @brief Tells SourceMM to add VSP hooking capability to plugins. * - * Since this potentially uses more resources than it would otherwise, plugins have to + * Since this potentially uses more resources than it would otherwise, plugins have to * explicitly enable the feature. Whether requested or not, if it is enabled, all plugins * will get a pointer to the VSP listener through IMetamodListener. */ @@ -303,6 +303,15 @@ public: // Added in 1.4 (1:5) * @return Message name, or NULL on failure. */ virtual const char *GetUserMessage(int index, int *size=NULL) =0; +public: // Added in 1.4.1 (1:6) + /** + * @brief Returns the highest interface version of IServerPluginCallbacks that the engine supports. + * This is useful for games that run on older versions of the Source engine, such as The Ship. + * + * @return Highest interface version of IServerPluginCallbacks. + * Returns 0 if SourceMM's VSP listener isn't currently enabled. + */ + virtual int GetVSPVersion() =0; }; @@ -314,7 +323,8 @@ public: // Added in 1.4 (1:5) * 1.2 Added API more helper functions and new SourceHook version. * 1.2.2 Added API for printing to client console (with string formatting). * 1.3 Added new interface search API. - * 1.4 Added VSP listener and user message API. + * 1.4 Added VSP listener and user message API. + * 1.4.1 Added API for getting highest supported version of IServerPluginCallbacks. */ #endif //_INCLUDE_ISMM_API_H diff --git a/sourcemm/changelog.txt b/sourcemm/changelog.txt index fffa8f6..2a14af5 100644 --- a/sourcemm/changelog.txt +++ b/sourcemm/changelog.txt @@ -1,3 +1,6 @@ +2007/??/?? 1.4.1: + - Added API for getting highest supported IServerPluginCallbacks interface version. + 2007/04/05 1.4.0: - Added API functions for retrieving User Message info without potentially crashing. - Added API functions for letting SourceMM plugins use Valve Server Plugin callbacks. diff --git a/sourcemm/sourcemm.cpp b/sourcemm/sourcemm.cpp index d11a01b..e4fa389 100644 --- a/sourcemm/sourcemm.cpp +++ b/sourcemm/sourcemm.cpp @@ -58,8 +58,8 @@ bool bGameInit = false; SourceHook::List gamedll_list; SourceHook::CallClass *g_GameDllPatch; int g_GameDllVersion = 0; -const char VSPIFACE_001[] = "ISERVERPLUGINCALLBACKS001"; -const char VSPIFACE_002[] = "ISERVERPLUGINCALLBACKS002"; +int g_VspVersion = 0; +const char VSPIFACE[] = "ISERVERPLUGINCALLBACKS"; const char GAMEINFO_PATH[] = "|gameinfo_path|"; void ClearGamedllList(); @@ -227,17 +227,18 @@ SMM_API void *CreateInterface(const char *iface, int *ret) return NULL; } - /* We check these separately because we can't reply - * unless our interface version really matches. - */ - if ((strcmp(iface, VSPIFACE_002) == 0) - || strcmp(iface, VSPIFACE_001) == 0) + if (strncmp(iface, VSPIFACE, 22) == 0) { - if (ret) + g_VspVersion = atoi(&(iface[22])); + + if (g_VspVersion <= MAX_VSP_VERSION) { - *ret = IFACE_OK; + if (ret) + { + *ret = IFACE_OK; + } + return &g_VspListener; } - return &g_VspListener; } if (!gParsedGameInfo) diff --git a/sourcemm/sourcemm.h b/sourcemm/sourcemm.h index b61f9eb..03da32d 100644 --- a/sourcemm/sourcemm.h +++ b/sourcemm/sourcemm.h @@ -35,12 +35,15 @@ #define SOURCEMM_VERSION SVN_FILE_VERSION_STRING #define SOURCEMM_DATE __DATE__ #define SM_VERS_API_MAJOR 1 //increase this on a breaking change -#define SM_VERS_API_MINOR 5 //increase this on a non-breaking API change +#define SM_VERS_API_MINOR 6 //increase this on a non-breaking API change -//We need a good CServerGameDLL version to work properly. We support these inclusively. +/* We need a good CServerGameDLL version to work properly. We support these inclusively. */ #define MIN_GAMEDLL_VERSION 3 #define MAX_GAMEDLL_VERSION 8 +/* Maximum version of IServerPluginCallbacks that SourceMM supports */ +#define MAX_VSP_VERSION 2 + /** * @brief Entry point for HL2 Engine */ @@ -114,6 +117,9 @@ extern PluginId g_PLID; /** @brief ServerGameDLL version that is currently loaded */ extern int g_GameDllVersion; +/** @brief Highest IServerPluginCallbacks version that is supported by engine */ +extern int g_VspVersion; + extern bool bGameInit; /** @brief Global CallClass for IServerGameDLL */