From ad3588d0aab900ed256ffb3d6bdd2a393f23634d Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Wed, 11 Jan 2017 21:25:00 -0500 Subject: [PATCH] Use newer MM:S api for Ep1/Original engine. (#548) * Use newer MM:S api for Ep1/Original engine. * Remove doubled FILENAME_1_6_EP1 define. --- AMBuildScript | 11 ++--- core/ConsoleDetours.cpp | 10 +---- core/CoreConfig.cpp | 6 +-- core/NextMap.cpp | 5 +-- core/PlayerManager.cpp | 5 +-- core/logic_bridge.cpp | 19 +-------- core/smn_halflife.cpp | 6 --- core/sourcemm_api.cpp | 7 ---- core/sourcemm_api.h | 4 -- extensions/sdkhooks/extension.h | 6 --- extensions/sdktools/extension.cpp | 4 -- loader/loader.cpp | 69 ------------------------------- 12 files changed, 10 insertions(+), 142 deletions(-) diff --git a/AMBuildScript b/AMBuildScript index 1bbfd8af..ceb5011c 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -17,7 +17,7 @@ WinLinux = ['windows', 'linux'] WinLinuxMac = ['windows', 'linux', 'mac'] PossibleSDKs = { - 'episode1': SDK('HL2SDK', '1.ep1', '1', 'EPISODEONE', WinLinux, 'episode1'), + 'episode1': SDK('HL2SDK', '2.ep1', '1', 'EPISODEONE', WinLinux, 'episode1'), 'ep2': SDK('HL2SDKOB', '2.ep2', '3', 'ORANGEBOX', WinLinux, 'orangebox'), 'css': SDK('HL2SDKCSS', '2.css', '6', 'CSS', WinLinuxMac, 'css'), 'hl2dm': SDK('HL2SDKHL2DM', '2.hl2dm', '7', 'HL2DM', WinLinuxMac, 'hl2dm'), @@ -362,14 +362,9 @@ class SMConfig(object): def ConfigureForHL2(self, binary, sdk): compiler = binary.compiler - if sdk.name == 'episode1': - mms_path = os.path.join(self.mms_root, 'core-legacy') - else: - mms_path = os.path.join(self.mms_root, 'core') - compiler.cxxincludes += [ - os.path.join(mms_path), - os.path.join(mms_path, 'sourcehook'), + os.path.join(self.mms_root, 'core'), + os.path.join(self.mms_root, 'core', 'sourcehook'), ] defines = ['SE_' + PossibleSDKs[i].define + '=' + PossibleSDKs[i].code for i in PossibleSDKs] diff --git a/core/ConsoleDetours.cpp b/core/ConsoleDetours.cpp index 0d49d550..1e445458 100644 --- a/core/ConsoleDetours.cpp +++ b/core/ConsoleDetours.cpp @@ -62,16 +62,10 @@ # include #endif -#if SH_IMPL_VERSION >= 5 -# if SOURCE_ENGINE >= SE_ORANGEBOX +#if SOURCE_ENGINE >= SE_ORANGEBOX SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); -# else - SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false); -# endif #else -extern int __SourceHook_FHVPAddConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0,bool); -extern int __SourceHook_FHAddConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0); -extern bool __SourceHook_FHRemoveConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0); + SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false); #endif class GenericCommandHooker : public IConCommandLinkListener diff --git a/core/CoreConfig.cpp b/core/CoreConfig.cpp index bcc3b979..2c5326ce 100644 --- a/core/CoreConfig.cpp +++ b/core/CoreConfig.cpp @@ -70,12 +70,8 @@ void CheckAndFinalizeConfigs(); #if SOURCE_ENGINE >= SE_ORANGEBOX SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); void Hook_ExecDispatchPre(const CCommand &cmd) -#elif SOURCE_ENGINE == SE_DARKMESSIAH -SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false); -void Hook_ExecDispatchPre() #else -extern int __SourceHook_FHAddConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0); -extern bool __SourceHook_FHRemoveConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0); +SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false); void Hook_ExecDispatchPre() #endif { diff --git a/core/NextMap.cpp b/core/NextMap.cpp index b9d1f749..bcd5a6c6 100644 --- a/core/NextMap.cpp +++ b/core/NextMap.cpp @@ -50,11 +50,8 @@ SH_DECL_HOOK4_void(IVEngineServer, ChangeLevel, SH_NOATTRIB, 0, const char *, co #if SOURCE_ENGINE >= SE_ORANGEBOX SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); -#elif SOURCE_ENGINE == SE_DARKMESSIAH -SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false); #else -extern int __SourceHook_FHAddConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0); -extern bool __SourceHook_FHRemoveConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0); +SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false); #endif ConCommand *changeLevelCmd = NULL; diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 87f8b647..7d68ee06 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -90,11 +90,8 @@ SH_DECL_HOOK1_void(IServerGameDLL, SetServerHibernation, SH_NOATTRIB, 0, bool); #if SOURCE_ENGINE >= SE_ORANGEBOX SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); -#elif SOURCE_ENGINE == SE_DARKMESSIAH -SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false); #else -extern int __SourceHook_FHAddConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0); -extern bool __SourceHook_FHRemoveConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0); +SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false); #endif ConCommand *maxplayersCmd = NULL; diff --git a/core/logic_bridge.cpp b/core/logic_bridge.cpp index 1666c91b..cbaab001 100644 --- a/core/logic_bridge.cpp +++ b/core/logic_bridge.cpp @@ -354,7 +354,6 @@ void UTIL_ConsolePrint(const char *fmt, ...) va_end(ap); } -#if defined METAMOD_PLAPI_VERSION #if SOURCE_ENGINE == SE_LEFT4DEAD #define GAMEFIX "2.l4d" #elif SOURCE_ENGINE == SE_LEFT4DEAD2 @@ -395,10 +394,7 @@ void UTIL_ConsolePrint(const char *fmt, ...) #define GAMEFIX "2.contagion" #else #define GAMEFIX "2.ep1" -#endif //(SOURCE_ENGINE == SE_LEFT4DEAD) || (SOURCE_ENGINE == SE_LEFT4DEAD2) -#else //METAMOD_PLAPI_VERSION -#define GAMEFIX "1.ep1" -#endif //METAMOD_PLAPI_VERSION +#endif static ServerGlobals serverGlobals; @@ -601,18 +597,7 @@ int CoreProviderImpl::LoadMMSPlugin(const char *file, bool *ok, char *error, siz Pl_Status status; -#ifndef METAMOD_PLAPI_VERSION - const char *filep; - PluginId source; -#endif - - if (!id || ( -#ifndef METAMOD_PLAPI_VERSION - g_pMMPlugins->Query(id, filep, status, source) -#else - g_pMMPlugins->Query(id, NULL, &status, NULL) -#endif - && status < Pl_Paused)) + if (!id || (g_pMMPlugins->Query(id, NULL, &status, NULL) && status < Pl_Paused)) { *ok = false; } diff --git a/core/smn_halflife.cpp b/core/smn_halflife.cpp index b8c1898f..20782566 100644 --- a/core/smn_halflife.cpp +++ b/core/smn_halflife.cpp @@ -484,9 +484,6 @@ static cell_t GuessSDKVersion(IPluginContext *pContext, const cell_t *params) return 10; case SOURCE_ENGINE_EPISODEONE: return 20; - -#if defined METAMOD_PLAPI_VERSION - /* Newer games. */ case SOURCE_ENGINE_DARKMESSIAH: return 15; case SOURCE_ENGINE_ORANGEBOX: @@ -516,7 +513,6 @@ static cell_t GuessSDKVersion(IPluginContext *pContext, const cell_t *params) return 70; case SOURCE_ENGINE_CSGO: return 80; -#endif } return 0; @@ -525,7 +521,6 @@ static cell_t GuessSDKVersion(IPluginContext *pContext, const cell_t *params) static cell_t GetEngineVersion(IPluginContext *pContext, const cell_t *params) { int engineVer = g_SMAPI->GetSourceEngineBuild(); -#if defined METAMOD_PLAPI_VERSION if (engineVer == SOURCE_ENGINE_ORANGEBOXVALVE_DEPRECATED) { const char *gamedir = g_SourceMod.GetGameFolderName(); @@ -538,7 +533,6 @@ static cell_t GetEngineVersion(IPluginContext *pContext, const cell_t *params) else if (strcmp(gamedir, "hl2mp") == 0) return SOURCE_ENGINE_HL2DM; } -#endif return engineVer; } diff --git a/core/sourcemm_api.cpp b/core/sourcemm_api.cpp index 2582fa2d..926360e7 100644 --- a/core/sourcemm_api.cpp +++ b/core/sourcemm_api.cpp @@ -63,13 +63,6 @@ int vsp_version = 0; PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core); -#if !defined(METAMOD_PLAPI_VERSION) && PLAPI_VERSION < 11 -# error "SourceMod requires Metamod:Source 1.8 or higher." -#endif -#if SH_IMPL_VERSION < 4 -# error "SourceMod requires a newer version of SourceHook." -#endif - ConVar sourcemod_version("sourcemod_version", SOURCEMOD_VERSION, FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY, "SourceMod Version"); bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late) diff --git a/core/sourcemm_api.h b/core/sourcemm_api.h index c1f194b8..316738a3 100644 --- a/core/sourcemm_api.h +++ b/core/sourcemm_api.h @@ -49,10 +49,6 @@ #include #include -#ifndef METAMOD_PLAPI_VERSION - #include -#endif - /** * @file Contains wrappers around required Metamod:Source API exports */ diff --git a/extensions/sdkhooks/extension.h b/extensions/sdkhooks/extension.h index 12507df7..cc8c3903 100644 --- a/extensions/sdkhooks/extension.h +++ b/extensions/sdkhooks/extension.h @@ -18,12 +18,6 @@ #include "takedamageinfohack.h" -#ifndef METAMOD_PLAPI_VERSION -#define GetCGlobals pGlobals -#define GetEngineFactory engineFactory -#define GetServerFactory serverFactory -#endif - #if SOURCE_ENGINE >= SE_CSS && SOURCE_ENGINE != SE_LEFT4DEAD #define GETMAXHEALTH_IS_VIRTUAL #endif diff --git a/extensions/sdktools/extension.cpp b/extensions/sdktools/extension.cpp index 428ab93f..620b0253 100644 --- a/extensions/sdktools/extension.cpp +++ b/extensions/sdktools/extension.cpp @@ -357,11 +357,7 @@ void SDKTools::NotifyInterfaceDrop(SMInterface *pInterface) bool SDKTools::RegisterConCommandBase(ConCommandBase *pVar) { -#if defined METAMOD_PLAPI_VERSION return g_SMAPI->RegisterConCommandBase(g_PLAPI, pVar); -#else - return g_SMAPI->RegisterConCmdBase(g_PLAPI, pVar); -#endif } bool SDKTools::LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background) diff --git a/loader/loader.cpp b/loader/loader.cpp index 45bd034d..cf0ac50d 100644 --- a/loader/loader.cpp +++ b/loader/loader.cpp @@ -41,10 +41,6 @@ #define PLATFORM_EXT ".dll" #define vsnprintf _vsnprintf #define PATH_SEP_CHAR "\\" - inline bool IsPathSepChar(char c) - { - return (c == '/' || c == '\\'); - } #include #else #define DLL_EXPORT extern "C" __attribute__((visibility("default"))) @@ -58,15 +54,10 @@ #endif typedef void * HINSTANCE; #define PATH_SEP_CHAR "/" - inline bool IsPathSepChar(char c) - { - return (c == '/'); - } #include #endif #define METAMOD_API_MAJOR 2 -#define FILENAME_1_4_EP1 "sourcemod.1.ep1" PLATFORM_EXT #define FILENAME_1_6_EP2 "sourcemod.2.ep2" PLATFORM_EXT #define FILENAME_1_6_EP1 "sourcemod.2.ep1" PLATFORM_EXT #define FILENAME_1_6_L4D "sourcemod.2.l4d" PLATFORM_EXT @@ -187,28 +178,6 @@ error: return NULL; } -bool GetFileOfAddress(void *pAddr, char *buffer, size_t maxlength) -{ -#if defined _MSC_VER - MEMORY_BASIC_INFORMATION mem; - if (!VirtualQuery(pAddr, &mem, sizeof(mem))) - return false; - if (mem.AllocationBase == NULL) - return false; - HMODULE dll = (HMODULE)mem.AllocationBase; - GetModuleFileName(dll, (LPTSTR)buffer, maxlength); -#else - Dl_info info; - if (!dladdr(pAddr, &info)) - return false; - if (!info.dli_fbase || !info.dli_fname) - return false; - const char *dllpath = info.dli_fname; - snprintf(buffer, maxlength, "%s", dllpath); -#endif - return true; -} - DLL_EXPORT METAMOD_PLUGIN *CreateInterface_MMS(const MetamodVersionInfo *mvi, const MetamodLoaderInfo *mli) { const char *filename; @@ -373,44 +342,6 @@ DLL_EXPORT void UnloadInterface_MMS() } } -DLL_EXPORT void *CreateInterface(const char *iface, int *ret) -{ - /** - * If a load has already been attempted, bail out immediately. - */ - if (load_attempted) - { - return NULL; - } - - if (strcmp(iface, METAMOD_PLAPI_NAME) == 0) - { - char thisfile[256]; - char targetfile[256]; - - if (!GetFileOfAddress((void *)CreateInterface_MMS, thisfile, sizeof(thisfile))) - { - return NULL; - } - - size_t len = strlen(thisfile); - for (size_t iter=len-1; iter