# HG changeset patch # User Nicholas Hastings # Date 1363456236 14400 # Node ID 31650bb3c7e85f964ee60c2f45c1c48a8ba43e1e # Parent 05a9a13701c4bcd54b6529cbe3daf7abd77aed5a Add GetPlayerResourceEntity to SDKTools; deprecate old, broken TF2-specific impl (bug 5491, r=asherkin). diff -r 05a9a13701c4 -r 31650bb3c7e8 extensions/sdktools/extension.cpp --- a/extensions/sdktools/extension.cpp Sat Mar 16 13:42:11 2013 -0400 +++ b/extensions/sdktools/extension.cpp Sat Mar 16 13:50:36 2013 -0400 @@ -43,6 +43,7 @@ #include "gamerulesnatives.h" #include #include "clientnatives.h" +#include "teamnatives.h" /** * @file extension.cpp * @brief Implements SDK Tools extension code. @@ -279,6 +280,12 @@ InitializeValveGlobals(); } +void SDKTools::OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax) +{ + InitTeamNatives(); + GetResourceEntity(); +} + bool SDKTools::QueryRunning(char *error, size_t maxlength) { SM_CHECK_IFACE(BINTOOLS, g_pBinTools); diff -r 05a9a13701c4 -r 31650bb3c7e8 extensions/sdktools/extension.h --- a/extensions/sdktools/extension.h Sat Mar 16 13:42:11 2013 -0400 +++ b/extensions/sdktools/extension.h Sat Mar 16 13:50:36 2013 -0400 @@ -135,8 +135,6 @@ extern SourceHook::CallClass *enginePatch; extern SourceHook::CallClass *enginesoundPatch; -extern const char *tools_GetTeamName(int team); - #include #define ENGINE_CALL(func) SH_CALL(enginePatch, &IVEngineServer::func) diff -r 05a9a13701c4 -r 31650bb3c7e8 extensions/sdktools/msvc10/sdktools.vcxproj --- a/extensions/sdktools/msvc10/sdktools.vcxproj Sat Mar 16 13:42:11 2013 -0400 +++ b/extensions/sdktools/msvc10/sdktools.vcxproj Sat Mar 16 13:50:36 2013 -0400 @@ -1325,6 +1325,7 @@ + diff -r 05a9a13701c4 -r 31650bb3c7e8 extensions/sdktools/msvc10/sdktools.vcxproj.filters --- a/extensions/sdktools/msvc10/sdktools.vcxproj.filters Sat Mar 16 13:42:11 2013 -0400 +++ b/extensions/sdktools/msvc10/sdktools.vcxproj.filters Sat Mar 16 13:50:36 2013 -0400 @@ -137,6 +137,9 @@ Header Files + + Header Files + diff -r 05a9a13701c4 -r 31650bb3c7e8 extensions/sdktools/teamnatives.cpp --- a/extensions/sdktools/teamnatives.cpp Sat Mar 16 13:42:11 2013 -0400 +++ b/extensions/sdktools/teamnatives.cpp Sat Mar 16 13:50:36 2013 -0400 @@ -30,6 +30,7 @@ */ #include "extension.h" +#include "vhelpers.h" #include struct TeamInfo @@ -42,36 +43,13 @@ SourceHook::CVector g_Teams; -bool FindTeamEntities(SendTable *pTable, const char *name) -{ - if (strcmp(pTable->GetName(), name) == 0) - { - return true; - } - - int props = pTable->GetNumProps(); - SendProp *prop; - - for (int i=0; iGetProp(i); - if (prop->GetDataTable()) - { - if (FindTeamEntities(prop->GetDataTable(), name)) - { - return true; - } - } - } - - return false; -} - -void SDKTools::OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax) +void InitTeamNatives() { g_Teams.clear(); g_Teams.resize(1); + int edictCount = gpGlobals->maxEntities; + for (int i=0; iGetNetworkable()->GetServerClass(); - if (FindTeamEntities(pClass->m_pTable, "DT_Team")) + if (FindNestedDataTable(pClass->m_pTable, "DT_Team")) { SendProp *pTeamNumProp = g_pGameHelpers->FindInSendTable(pClass->GetName(), "m_iTeamNum"); diff -r 05a9a13701c4 -r 31650bb3c7e8 extensions/sdktools/teamnatives.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/sdktools/teamnatives.h Sat Mar 16 13:50:36 2013 -0400 @@ -0,0 +1,39 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod SDKTools Extension + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. + * ============================================================================= + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + * As a special exception, AlliedModders LLC gives you permission to link the + * code of this program (as well as its derivative works) to "Half-Life 2," the + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software + * by the Valve Corporation. You must obey the GNU General Public License in + * all respects for all other code used. Additionally, AlliedModders LLC grants + * this exception to all derivative works. AlliedModders LLC defines further + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), + * or . + * + * Version: $Id$ + */ + +#ifndef _INCLUDE_SOURCEMOD_TEAMNATIVES_H_ +#define _INCLUDE_SOURCEMOD_TEAMNATIVES_H_ + +void InitTeamNatives(); + +extern const char *tools_GetTeamName(int team); + +#endif //_INCLUDE_SOURCEMOD_TEAMNATIVES_H_ diff -r 05a9a13701c4 -r 31650bb3c7e8 extensions/sdktools/vglobals.cpp --- a/extensions/sdktools/vglobals.cpp Sat Mar 16 13:42:11 2013 -0400 +++ b/extensions/sdktools/vglobals.cpp Sat Mar 16 13:50:36 2013 -0400 @@ -30,9 +30,11 @@ */ #include "extension.h" +#include "vhelpers.h" void **g_pGameRules = NULL; void *g_EntList = NULL; +CBaseHandle g_ResourceEntity; void InitializeValveGlobals() @@ -183,6 +185,54 @@ } #endif +void GetResourceEntity() +{ + g_ResourceEntity.Term(); + + const char *classname = g_pGameConf->GetKeyValue("ResourceEntityClassname"); + if (classname != NULL) + { + for (void *pEntity = servertools->FirstEntity(); pEntity; pEntity = servertools->NextEntity(pEntity)) + { + if (!strcmp(gamehelpers->GetEntityClassname((CBaseEntity *)pEntity), classname)) + { + g_ResourceEntity = ((IHandleEntity *)pEntity)->GetRefEHandle(); + break; + } + } + } + else + { + int edictCount = gpGlobals->maxEntities; + + for (int i=0; iIsFree()) + { + continue; + } + if (!pEdict->GetNetworkable()) + { + continue; + } + + IHandleEntity *pHandleEnt = pEdict->GetNetworkable()->GetEntityHandle(); + if (!pHandleEnt) + { + continue; + } + + ServerClass *pClass = pEdict->GetNetworkable()->GetServerClass(); + if (FindNestedDataTable(pClass->m_pTable, "DT_PlayerResource")) + { + g_ResourceEntity = pHandleEnt->GetRefEHandle(); + break; + } + } + } +} + const char *GetDTTypeName(int type) { switch (type) diff -r 05a9a13701c4 -r 31650bb3c7e8 extensions/sdktools/vglobals.h --- a/extensions/sdktools/vglobals.h Sat Mar 16 13:42:11 2013 -0400 +++ b/extensions/sdktools/vglobals.h Sat Mar 16 13:50:36 2013 -0400 @@ -35,9 +35,13 @@ extern void **g_pGameRules; extern void *g_EntList; +extern CBaseHandle g_ResourceEntity; + void InitializeValveGlobals(); void GetIServer(); +void GetResourceEntity(); + const char *GetDTTypeName(int type); #endif // _INCLUDE_SDKTOOLS_VGLOBALS_H_ diff -r 05a9a13701c4 -r 31650bb3c7e8 extensions/sdktools/vhelpers.cpp --- a/extensions/sdktools/vhelpers.cpp Sat Mar 16 13:42:11 2013 -0400 +++ b/extensions/sdktools/vhelpers.cpp Sat Mar 16 13:50:36 2013 -0400 @@ -279,6 +279,31 @@ s_EyeAngles.Shutdown(); } +bool FindNestedDataTable(SendTable *pTable, const char *name) +{ + if (strcmp(pTable->GetName(), name) == 0) + { + return true; + } + + int props = pTable->GetNumProps(); + SendProp *prop; + + for (int i=0; iGetProp(i); + if (prop->GetDataTable()) + { + if (FindNestedDataTable(prop->GetDataTable(), name)) + { + return true; + } + } + } + + return false; +} + void UTIL_DrawSendTable_XML(FILE *fp, SendTable *pTable, int space_count) { char spaces[255]; diff -r 05a9a13701c4 -r 31650bb3c7e8 extensions/sdktools/vhelpers.h --- a/extensions/sdktools/vhelpers.h Sat Mar 16 13:42:11 2013 -0400 +++ b/extensions/sdktools/vhelpers.h Sat Mar 16 13:50:36 2013 -0400 @@ -72,4 +72,6 @@ void ShutdownHelpers(); +bool FindNestedDataTable(SendTable *pTable, const char *name); + #endif //_INCLUDE_SDKTOOLS_VHELPERS_H_ diff -r 05a9a13701c4 -r 31650bb3c7e8 extensions/sdktools/vnatives.cpp --- a/extensions/sdktools/vnatives.cpp Sat Mar 16 13:42:11 2013 -0400 +++ b/extensions/sdktools/vnatives.cpp Sat Mar 16 13:50:36 2013 -0400 @@ -1208,6 +1208,16 @@ return 1; } +static cell_t GetPlayerResourceEntity(IPluginContext *pContext, const cell_t *params) +{ + if (gamehelpers->GetHandleEntity(g_ResourceEntity) != NULL) + { + return g_ResourceEntity.GetEntryIndex(); + } + + return -1; +} + sp_nativeinfo_t g_Natives[] = { {"ExtinguishEntity", ExtinguishEntity}, @@ -1235,5 +1245,6 @@ {"EquipPlayerWeapon", WeaponEquip}, {"ActivateEntity", ActivateEntity}, {"SetClientInfo", SetClientInfo}, + {"GetPlayerResourceEntity", GetPlayerResourceEntity}, {NULL, NULL}, }; diff -r 05a9a13701c4 -r 31650bb3c7e8 plugins/include/sdktools.inc --- a/plugins/include/sdktools.inc Sat Mar 16 13:42:11 2013 -0400 +++ b/plugins/include/sdktools.inc Sat Mar 16 13:50:36 2013 -0400 @@ -194,6 +194,13 @@ */ native any:SDKCall(Handle:call, any:...); +/* + * Returns the entity index of the player resource/manager entity. + * + * @return Index of resource entity or -1 if not found. + */ +native GetPlayerResourceEntity(); + #include /** diff -r 05a9a13701c4 -r 31650bb3c7e8 plugins/include/tf2.inc --- a/plugins/include/tf2.inc Sat Mar 16 13:42:11 2013 -0400 +++ b/plugins/include/tf2.inc Sat Mar 16 13:50:36 2013 -0400 @@ -278,6 +278,7 @@ * * @return The current resource entity index. */ +#pragma deprecated Use GetPlayerResourceEntity instead native TF2_GetResourceEntity(); /** diff -r 05a9a13701c4 -r 31650bb3c7e8 plugins/include/tf2_stocks.inc --- a/plugins/include/tf2_stocks.inc Sat Mar 16 13:42:11 2013 -0400 +++ b/plugins/include/tf2_stocks.inc Sat Mar 16 13:50:36 2013 -0400 @@ -350,6 +350,7 @@ * @return Value or -1 on failure. * @error Invalid client index, client not in game or failed to find resource entity. */ +#pragma deprecated Use GetPlayerResourceEntity and GetEntProp instead stock TF2_GetPlayerResourceData(client, TFResourceType:type) { if (!IsClientConnected(client)) @@ -385,6 +386,7 @@ * @return Value or -1 on failure. * @error Invalid client index, client not in game or failed to find resource entity. */ +#pragma deprecated Use GetPlayerResourceEntity and SetEntProp instead stock bool:TF2_SetPlayerResourceData(client, TFResourceType:type, any:value) { if (!IsClientConnected(client))