From 350dd2ebc7f568bf95a37dec06bc95626a095ece Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Thu, 30 Oct 2014 19:23:27 -0400 Subject: [PATCH 1/5] Eliminate need for gEntList gamedata on tf2/sdk2013 and soon dods/css/hl2dm. --- core/HalfLife2.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index 9cc3bc51..27b05305 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -153,6 +153,18 @@ void CHalfLife2::OnSourceModAllInitialized_Post() void CHalfLife2::InitLogicalEntData() { +#if SOURCE_ENGINE == SE_TF2 \ + || SOURCE_ENGINE == SE_DODS \ + || SOURCE_ENGINE == SE_HL2DM \ + || SOURCE_ENGINE == SE_CSS \ + || SOURCE_ENGINE == SE_SDK2013 + + if (g_SMAPI->GetServerFactory(false)("VSERVERTOOLS003", nullptr)) + { + g_EntList = servertools->GetEntityList(); + } +#endif + char *addr = NULL; /* @@ -162,21 +174,24 @@ void CHalfLife2::InitLogicalEntData() * If symbols aren't present (Windows or stripped Linux/Mac), * attempt find via LevelShutdown + offset */ - if (g_pGameConf->GetMemSig("gEntList", (void **)&addr)) + if (!g_EntList) { -#if !defined PLATFORM_WINDOWS - if (!addr) + if (g_pGameConf->GetMemSig("gEntList", (void **) &addr)) { - // Key exists so notify if lookup fails, but try other method. - logger->LogError("Failed lookup of gEntList directly - Reverting to lookup via LevelShutdown"); - } - else - { -#endif - g_EntList = reinterpret_cast(addr); #if !defined PLATFORM_WINDOWS - } + if (!addr) + { + // Key exists so notify if lookup fails, but try other method. + logger->LogError("Failed lookup of gEntList directly - Reverting to lookup via LevelShutdown"); + } + else + { #endif + g_EntList = reinterpret_cast(addr); +#if !defined PLATFORM_WINDOWS + } +#endif + } } if (!g_EntList) From 72c18cc3d925905f066750ae2c2e782fe03efa59 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Thu, 30 Oct 2014 19:24:00 -0400 Subject: [PATCH 2/5] Missing changes from last commit --- core/sourcemm_api.cpp | 2 ++ core/sourcemm_api.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/core/sourcemm_api.cpp b/core/sourcemm_api.cpp index 15a679a4..938f80c0 100644 --- a/core/sourcemm_api.cpp +++ b/core/sourcemm_api.cpp @@ -52,6 +52,7 @@ IPlayerInfoManager *playerinfo = NULL; IBaseFileSystem *basefilesystem = NULL; IFileSystem *filesystem = NULL; IEngineSound *enginesound = NULL; +IServerTools *servertools = NULL; IServerPluginHelpers *serverpluginhelpers = NULL; IServerPluginCallbacks *vsp_interface = NULL; int vsp_version = 0; @@ -71,6 +72,7 @@ bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen GET_V_IFACE_CURRENT(GetFileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION); GET_V_IFACE_CURRENT(GetFileSystemFactory, filesystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION); GET_V_IFACE_CURRENT(GetEngineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION); + GET_V_IFACE_CURRENT(GetServerFactory, servertools, IServerTools, VSERVERTOOLS_INTERFACE_VERSION); #if SOURCE_ENGINE != SE_DOTA GET_V_IFACE_CURRENT(GetEngineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS); #endif diff --git a/core/sourcemm_api.h b/core/sourcemm_api.h index cea9c8b9..43ad069b 100644 --- a/core/sourcemm_api.h +++ b/core/sourcemm_api.h @@ -50,6 +50,7 @@ #include #include #include +#include #ifndef METAMOD_PLAPI_VERSION #include @@ -103,6 +104,7 @@ extern IPlayerInfoManager *playerinfo; extern IBaseFileSystem *basefilesystem; extern IFileSystem *filesystem; extern IEngineSound *enginesound; +extern IServerTools *servertools; extern IServerPluginHelpers *serverpluginhelpers; extern IServerPluginCallbacks *vsp_interface; extern int vsp_version; From 10cee734dce7c8edd854037983f813dd7e0adfe7 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Thu, 30 Oct 2014 19:24:53 -0400 Subject: [PATCH 3/5] Eliminate need for s_pTempEnts gamedata on sdk2013 and soon css/dods/hl2dm (already on tf2). --- extensions/sdktools/tempents.cpp | 54 +++++++++++++++++++------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/extensions/sdktools/tempents.cpp b/extensions/sdktools/tempents.cpp index e492fff2..2a41b7b0 100644 --- a/extensions/sdktools/tempents.cpp +++ b/extensions/sdktools/tempents.cpp @@ -285,36 +285,46 @@ void TempEntityManager::Initialize() int offset; m_Loaded = false; -#if SOURCE_ENGINE == SE_TF2 - m_ListHead = servertools->GetTempEntList(); -#else - /* - * First try to lookup s_pTempEntities directly for platforms with symbols. - * If symbols aren't present (Windows or stripped Linux/Mac), - * attempt find via CBaseTempEntity ctor + offset - */ +#if SOURCE_ENGINE == SE_TF2 \ + || SOURCE_ENGINE == SE_DODS \ + || SOURCE_ENGINE == SE_HL2DM \ + || SOURCE_ENGINE == SE_CSS \ + || SOURCE_ENGINE == SE_SDK2013 - /* Read our sigs and offsets from the config file */ - if (g_pGameConf->GetMemSig("s_pTempEntities", &addr) && addr) + if (g_SMAPI->GetServerFactory(false)("VSERVERTOOLS003", nullptr)) { - - /* Store the head of the TE linked list */ - m_ListHead = *(void **)addr; + m_ListHead = servertools->GetTempEntList(); } - else if (g_pGameConf->GetMemSig("CBaseTempEntity", &addr) && addr) + else +#endif { - if (!g_pGameConf->GetOffset("s_pTempEntities", &offset)) + /* + * First try to lookup s_pTempEntities directly for platforms with symbols. + * If symbols aren't present (Windows or stripped Linux/Mac), + * attempt find via CBaseTempEntity ctor + offset + */ + + /* Read our sigs and offsets from the config file */ + if (g_pGameConf->GetMemSig("s_pTempEntities", &addr) && addr) + { + + /* Store the head of the TE linked list */ + m_ListHead = *(void **) addr; + } + else if (g_pGameConf->GetMemSig("CBaseTempEntity", &addr) && addr) + { + if (!g_pGameConf->GetOffset("s_pTempEntities", &offset)) + { + return; + } + /* Store the head of the TE linked list */ + m_ListHead = **(void ***) ((unsigned char *) addr + offset); + } + else { return; } - /* Store the head of the TE linked list */ - m_ListHead = **(void ***)((unsigned char *)addr + offset); } - else - { - return; - } -#endif // == TF2 if (!g_pGameConf->GetOffset("GetTEName", &m_NameOffs)) { From 749701014db45b1c4288054580e7be32ee7b7ff4 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Thu, 30 Oct 2014 19:25:13 -0400 Subject: [PATCH 4/5] Eliminate need for sv gamedata on sdk2013 and soon css/dods/hl2dm (already on tf2). --- extensions/sdktools/vglobals.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/extensions/sdktools/vglobals.cpp b/extensions/sdktools/vglobals.cpp index aeaf3bff..54b533bd 100644 --- a/extensions/sdktools/vglobals.cpp +++ b/extensions/sdktools/vglobals.cpp @@ -130,9 +130,19 @@ bool UTIL_VerifySignature(const void *addr, const char *sig, size_t len) void GetIServer() { -#if SOURCE_ENGINE == SE_TF2 - iserver = engine->GetIServer(); -#else +#if SOURCE_ENGINE == SE_TF2 \ + || SOURCE_ENGINE == SE_DODS \ + || SOURCE_ENGINE == SE_HL2DM \ + || SOURCE_ENGINE == SE_CSS \ + || SOURCE_ENGINE == SE_SDK2013 + + if (g_SMAPI->GetEngineFactory(false)("VEngineServer022", nullptr)) + { + iserver = engine->GetIServer(); + return; + } +#endif + void *addr; const char *sigstr; char sig[32]; @@ -191,7 +201,6 @@ void GetIServer() /* Finally we have the interface we were looking for */ iserver = *reinterpret_cast(reinterpret_cast(vfunc) + offset); -#endif // !TF2 } void GetResourceEntity() From f0dd129344be6afde0f0b79c4191f24dfe1b9c49 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Thu, 30 Oct 2014 19:25:26 -0400 Subject: [PATCH 5/5] Eliminate need for FindEntityByClassname gamedata on sdk2013 and soon css/dods/hl2dm (already on tf2). --- extensions/sdktools/vnatives.cpp | 41 +++++++++++++++++++------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/extensions/sdktools/vnatives.cpp b/extensions/sdktools/vnatives.cpp index 45be5c03..3539ccb6 100644 --- a/extensions/sdktools/vnatives.cpp +++ b/extensions/sdktools/vnatives.cpp @@ -714,7 +714,7 @@ static cell_t GetClientEyeAngles(IPluginContext *pContext, const cell_t *params) return got_angles ? 1 : 0; } -#if SOURCE_ENGINE >= SE_ORANGEBOX && SOURCE_ENGINE != SE_TF2 +#if SOURCE_ENGINE >= SE_ORANGEBOX static cell_t NativeFindEntityByClassname(IPluginContext *pContext, const cell_t *params) { char *searchname; @@ -793,25 +793,35 @@ static cell_t NativeFindEntityByClassname(IPluginContext *pContext, const cell_t static cell_t FindEntityByClassname(IPluginContext *pContext, const cell_t *params) { -#if SOURCE_ENGINE == SE_TF2 - CBaseEntity *pStartEnt = NULL; - if (params[1] != -1) +#if SOURCE_ENGINE == SE_TF2 \ + || SOURCE_ENGINE == SE_DODS \ + || SOURCE_ENGINE == SE_HL2DM \ + || SOURCE_ENGINE == SE_CSS \ + || SOURCE_ENGINE == SE_SDK2013 + + static bool bHasServerTools3 = !!g_SMAPI->GetServerFactory(false)("VSERVERTOOLS003", nullptr); + if (bHasServerTools3) { - pStartEnt = gamehelpers->ReferenceToEntity(params[1]); - if (!pStartEnt) + CBaseEntity *pStartEnt = NULL; + if (params[1] != -1) { - return pContext->ThrowNativeError("Entity %d (%d) is invalid", - gamehelpers->ReferenceToIndex(params[1]), - params[1]); + pStartEnt = gamehelpers->ReferenceToEntity(params[1]); + if (!pStartEnt) + { + return pContext->ThrowNativeError("Entity %d (%d) is invalid", + gamehelpers->ReferenceToIndex(params[1]), + params[1]); + } } + + char *searchname; + pContext->LocalToString(params[2], &searchname); + + CBaseEntity *pEntity = servertools->FindEntityByClassname(pStartEnt, searchname); + return gamehelpers->EntityToBCompatRef(pEntity); } +#endif - char *searchname; - pContext->LocalToString(params[2], &searchname); - - CBaseEntity *pEntity = servertools->FindEntityByClassname(pStartEnt, searchname); - return gamehelpers->EntityToBCompatRef(pEntity); -#else static ValveCall *pCall = NULL; static bool bProbablyNoFEBC = false; @@ -869,7 +879,6 @@ static cell_t FindEntityByClassname(IPluginContext *pContext, const cell_t *para FINISH_CALL_SIMPLE(&pEntity); return gamehelpers->EntityToBCompatRef(pEntity); -#endif // == TF2 } #if SOURCE_ENGINE >= SE_ORANGEBOX