From ab1fb8309ebf181d3b410b9cc2bf4c3c6863d89f Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Thu, 30 Oct 2014 19:25:26 -0400 Subject: [PATCH] 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