Add GetPlayerResourceEntity to SDKTools; deprecate old, broken TF2-specific impl (bug 5491, r=asherkin).
1.1 --- a/extensions/sdktools/extension.cpp Sat Mar 16 13:42:11 2013 -0400
1.2 +++ b/extensions/sdktools/extension.cpp Sat Mar 16 13:50:36 2013 -0400
1.3 @@ -43,6 +43,7 @@
1.4 #include "gamerulesnatives.h"
1.5 #include <ISDKTools.h>
1.6 #include "clientnatives.h"
1.7 +#include "teamnatives.h"
1.8 /**
1.9 * @file extension.cpp
1.10 * @brief Implements SDK Tools extension code.
1.11 @@ -279,6 +280,12 @@
1.12 InitializeValveGlobals();
1.13 }
1.14
1.15 +void SDKTools::OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
1.16 +{
1.17 + InitTeamNatives();
1.18 + GetResourceEntity();
1.19 +}
1.20 +
1.21 bool SDKTools::QueryRunning(char *error, size_t maxlength)
1.22 {
1.23 SM_CHECK_IFACE(BINTOOLS, g_pBinTools);
2.1 --- a/extensions/sdktools/extension.h Sat Mar 16 13:42:11 2013 -0400
2.2 +++ b/extensions/sdktools/extension.h Sat Mar 16 13:50:36 2013 -0400
2.3 @@ -135,8 +135,6 @@
2.4 extern SourceHook::CallClass<IVEngineServer> *enginePatch;
2.5 extern SourceHook::CallClass<IEngineSound> *enginesoundPatch;
2.6
2.7 -extern const char *tools_GetTeamName(int team);
2.8 -
2.9 #include <compat_wrappers.h>
2.10
2.11 #define ENGINE_CALL(func) SH_CALL(enginePatch, &IVEngineServer::func)
3.1 --- a/extensions/sdktools/msvc10/sdktools.vcxproj Sat Mar 16 13:42:11 2013 -0400
3.2 +++ b/extensions/sdktools/msvc10/sdktools.vcxproj Sat Mar 16 13:50:36 2013 -0400
3.3 @@ -1325,6 +1325,7 @@
3.4 <ClInclude Include="..\hooks.h" />
3.5 <ClInclude Include="..\..\..\public\extensions\ISDKTools.h" />
3.6 <ClInclude Include="..\output.h" />
3.7 + <ClInclude Include="..\teamnatives.h" />
3.8 <ClInclude Include="..\tempents.h" />
3.9 <ClInclude Include="..\vcallbuilder.h" />
3.10 <ClInclude Include="..\vdecoder.h" />
4.1 --- a/extensions/sdktools/msvc10/sdktools.vcxproj.filters Sat Mar 16 13:42:11 2013 -0400
4.2 +++ b/extensions/sdktools/msvc10/sdktools.vcxproj.filters Sat Mar 16 13:50:36 2013 -0400
4.3 @@ -137,6 +137,9 @@
4.4 <ClInclude Include="..\clientnatives.h">
4.5 <Filter>Header Files</Filter>
4.6 </ClInclude>
4.7 + <ClInclude Include="..\teamnatives.h">
4.8 + <Filter>Header Files</Filter>
4.9 + </ClInclude>
4.10 </ItemGroup>
4.11 <ItemGroup>
4.12 <ResourceCompile Include="..\version.rc">
5.1 --- a/extensions/sdktools/teamnatives.cpp Sat Mar 16 13:42:11 2013 -0400
5.2 +++ b/extensions/sdktools/teamnatives.cpp Sat Mar 16 13:50:36 2013 -0400
5.3 @@ -30,6 +30,7 @@
5.4 */
5.5
5.6 #include "extension.h"
5.7 +#include "vhelpers.h"
5.8 #include <sh_vector.h>
5.9
5.10 struct TeamInfo
5.11 @@ -42,36 +43,13 @@
5.12
5.13 SourceHook::CVector<TeamInfo> g_Teams;
5.14
5.15 -bool FindTeamEntities(SendTable *pTable, const char *name)
5.16 -{
5.17 - if (strcmp(pTable->GetName(), name) == 0)
5.18 - {
5.19 - return true;
5.20 - }
5.21 -
5.22 - int props = pTable->GetNumProps();
5.23 - SendProp *prop;
5.24 -
5.25 - for (int i=0; i<props; i++)
5.26 - {
5.27 - prop = pTable->GetProp(i);
5.28 - if (prop->GetDataTable())
5.29 - {
5.30 - if (FindTeamEntities(prop->GetDataTable(), name))
5.31 - {
5.32 - return true;
5.33 - }
5.34 - }
5.35 - }
5.36 -
5.37 - return false;
5.38 -}
5.39 -
5.40 -void SDKTools::OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
5.41 +void InitTeamNatives()
5.42 {
5.43 g_Teams.clear();
5.44 g_Teams.resize(1);
5.45
5.46 + int edictCount = gpGlobals->maxEntities;
5.47 +
5.48 for (int i=0; i<edictCount; i++)
5.49 {
5.50 edict_t *pEdict = PEntityOfEntIndex(i);
5.51 @@ -85,7 +63,7 @@
5.52 }
5.53
5.54 ServerClass *pClass = pEdict->GetNetworkable()->GetServerClass();
5.55 - if (FindTeamEntities(pClass->m_pTable, "DT_Team"))
5.56 + if (FindNestedDataTable(pClass->m_pTable, "DT_Team"))
5.57 {
5.58 SendProp *pTeamNumProp = g_pGameHelpers->FindInSendTable(pClass->GetName(), "m_iTeamNum");
5.59
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/extensions/sdktools/teamnatives.h Sat Mar 16 13:50:36 2013 -0400
6.3 @@ -0,0 +1,39 @@
6.4 +/**
6.5 + * vim: set ts=4 :
6.6 + * =============================================================================
6.7 + * SourceMod SDKTools Extension
6.8 + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6.9 + * =============================================================================
6.10 + *
6.11 + * This program is free software; you can redistribute it and/or modify it under
6.12 + * the terms of the GNU General Public License, version 3.0, as published by the
6.13 + * Free Software Foundation.
6.14 + *
6.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
6.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
6.17 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
6.18 + * details.
6.19 + *
6.20 + * You should have received a copy of the GNU General Public License along with
6.21 + * this program. If not, see <http://www.gnu.org/licenses/>.
6.22 + *
6.23 + * As a special exception, AlliedModders LLC gives you permission to link the
6.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
6.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
6.26 + * by the Valve Corporation. You must obey the GNU General Public License in
6.27 + * all respects for all other code used. Additionally, AlliedModders LLC grants
6.28 + * this exception to all derivative works. AlliedModders LLC defines further
6.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
6.30 + * or <http://www.sourcemod.net/license.php>.
6.31 + *
6.32 + * Version: $Id$
6.33 + */
6.34 +
6.35 +#ifndef _INCLUDE_SOURCEMOD_TEAMNATIVES_H_
6.36 +#define _INCLUDE_SOURCEMOD_TEAMNATIVES_H_
6.37 +
6.38 +void InitTeamNatives();
6.39 +
6.40 +extern const char *tools_GetTeamName(int team);
6.41 +
6.42 +#endif //_INCLUDE_SOURCEMOD_TEAMNATIVES_H_
7.1 --- a/extensions/sdktools/vglobals.cpp Sat Mar 16 13:42:11 2013 -0400
7.2 +++ b/extensions/sdktools/vglobals.cpp Sat Mar 16 13:50:36 2013 -0400
7.3 @@ -30,9 +30,11 @@
7.4 */
7.5
7.6 #include "extension.h"
7.7 +#include "vhelpers.h"
7.8
7.9 void **g_pGameRules = NULL;
7.10 void *g_EntList = NULL;
7.11 +CBaseHandle g_ResourceEntity;
7.12
7.13
7.14 void InitializeValveGlobals()
7.15 @@ -183,6 +185,54 @@
7.16 }
7.17 #endif
7.18
7.19 +void GetResourceEntity()
7.20 +{
7.21 + g_ResourceEntity.Term();
7.22 +
7.23 + const char *classname = g_pGameConf->GetKeyValue("ResourceEntityClassname");
7.24 + if (classname != NULL)
7.25 + {
7.26 + for (void *pEntity = servertools->FirstEntity(); pEntity; pEntity = servertools->NextEntity(pEntity))
7.27 + {
7.28 + if (!strcmp(gamehelpers->GetEntityClassname((CBaseEntity *)pEntity), classname))
7.29 + {
7.30 + g_ResourceEntity = ((IHandleEntity *)pEntity)->GetRefEHandle();
7.31 + break;
7.32 + }
7.33 + }
7.34 + }
7.35 + else
7.36 + {
7.37 + int edictCount = gpGlobals->maxEntities;
7.38 +
7.39 + for (int i=0; i<edictCount; i++)
7.40 + {
7.41 + edict_t *pEdict = PEntityOfEntIndex(i);
7.42 + if (!pEdict || pEdict->IsFree())
7.43 + {
7.44 + continue;
7.45 + }
7.46 + if (!pEdict->GetNetworkable())
7.47 + {
7.48 + continue;
7.49 + }
7.50 +
7.51 + IHandleEntity *pHandleEnt = pEdict->GetNetworkable()->GetEntityHandle();
7.52 + if (!pHandleEnt)
7.53 + {
7.54 + continue;
7.55 + }
7.56 +
7.57 + ServerClass *pClass = pEdict->GetNetworkable()->GetServerClass();
7.58 + if (FindNestedDataTable(pClass->m_pTable, "DT_PlayerResource"))
7.59 + {
7.60 + g_ResourceEntity = pHandleEnt->GetRefEHandle();
7.61 + break;
7.62 + }
7.63 + }
7.64 + }
7.65 +}
7.66 +
7.67 const char *GetDTTypeName(int type)
7.68 {
7.69 switch (type)
8.1 --- a/extensions/sdktools/vglobals.h Sat Mar 16 13:42:11 2013 -0400
8.2 +++ b/extensions/sdktools/vglobals.h Sat Mar 16 13:50:36 2013 -0400
8.3 @@ -35,9 +35,13 @@
8.4 extern void **g_pGameRules;
8.5 extern void *g_EntList;
8.6
8.7 +extern CBaseHandle g_ResourceEntity;
8.8 +
8.9 void InitializeValveGlobals();
8.10 void GetIServer();
8.11
8.12 +void GetResourceEntity();
8.13 +
8.14 const char *GetDTTypeName(int type);
8.15
8.16 #endif // _INCLUDE_SDKTOOLS_VGLOBALS_H_
9.1 --- a/extensions/sdktools/vhelpers.cpp Sat Mar 16 13:42:11 2013 -0400
9.2 +++ b/extensions/sdktools/vhelpers.cpp Sat Mar 16 13:50:36 2013 -0400
9.3 @@ -279,6 +279,31 @@
9.4 s_EyeAngles.Shutdown();
9.5 }
9.6
9.7 +bool FindNestedDataTable(SendTable *pTable, const char *name)
9.8 +{
9.9 + if (strcmp(pTable->GetName(), name) == 0)
9.10 + {
9.11 + return true;
9.12 + }
9.13 +
9.14 + int props = pTable->GetNumProps();
9.15 + SendProp *prop;
9.16 +
9.17 + for (int i=0; i<props; i++)
9.18 + {
9.19 + prop = pTable->GetProp(i);
9.20 + if (prop->GetDataTable())
9.21 + {
9.22 + if (FindNestedDataTable(prop->GetDataTable(), name))
9.23 + {
9.24 + return true;
9.25 + }
9.26 + }
9.27 + }
9.28 +
9.29 + return false;
9.30 +}
9.31 +
9.32 void UTIL_DrawSendTable_XML(FILE *fp, SendTable *pTable, int space_count)
9.33 {
9.34 char spaces[255];
10.1 --- a/extensions/sdktools/vhelpers.h Sat Mar 16 13:42:11 2013 -0400
10.2 +++ b/extensions/sdktools/vhelpers.h Sat Mar 16 13:50:36 2013 -0400
10.3 @@ -72,4 +72,6 @@
10.4
10.5 void ShutdownHelpers();
10.6
10.7 +bool FindNestedDataTable(SendTable *pTable, const char *name);
10.8 +
10.9 #endif //_INCLUDE_SDKTOOLS_VHELPERS_H_
11.1 --- a/extensions/sdktools/vnatives.cpp Sat Mar 16 13:42:11 2013 -0400
11.2 +++ b/extensions/sdktools/vnatives.cpp Sat Mar 16 13:50:36 2013 -0400
11.3 @@ -1208,6 +1208,16 @@
11.4 return 1;
11.5 }
11.6
11.7 +static cell_t GetPlayerResourceEntity(IPluginContext *pContext, const cell_t *params)
11.8 +{
11.9 + if (gamehelpers->GetHandleEntity(g_ResourceEntity) != NULL)
11.10 + {
11.11 + return g_ResourceEntity.GetEntryIndex();
11.12 + }
11.13 +
11.14 + return -1;
11.15 +}
11.16 +
11.17 sp_nativeinfo_t g_Natives[] =
11.18 {
11.19 {"ExtinguishEntity", ExtinguishEntity},
11.20 @@ -1235,5 +1245,6 @@
11.21 {"EquipPlayerWeapon", WeaponEquip},
11.22 {"ActivateEntity", ActivateEntity},
11.23 {"SetClientInfo", SetClientInfo},
11.24 + {"GetPlayerResourceEntity", GetPlayerResourceEntity},
11.25 {NULL, NULL},
11.26 };
12.1 --- a/plugins/include/sdktools.inc Sat Mar 16 13:42:11 2013 -0400
12.2 +++ b/plugins/include/sdktools.inc Sat Mar 16 13:50:36 2013 -0400
12.3 @@ -194,6 +194,13 @@
12.4 */
12.5 native any:SDKCall(Handle:call, any:...);
12.6
12.7 +/*
12.8 + * Returns the entity index of the player resource/manager entity.
12.9 + *
12.10 + * @return Index of resource entity or -1 if not found.
12.11 + */
12.12 +native GetPlayerResourceEntity();
12.13 +
12.14 #include <sdktools_stocks>
12.15
12.16 /**
13.1 --- a/plugins/include/tf2.inc Sat Mar 16 13:42:11 2013 -0400
13.2 +++ b/plugins/include/tf2.inc Sat Mar 16 13:50:36 2013 -0400
13.3 @@ -278,6 +278,7 @@
13.4 *
13.5 * @return The current resource entity index.
13.6 */
13.7 +#pragma deprecated Use GetPlayerResourceEntity instead
13.8 native TF2_GetResourceEntity();
13.9
13.10 /**
14.1 --- a/plugins/include/tf2_stocks.inc Sat Mar 16 13:42:11 2013 -0400
14.2 +++ b/plugins/include/tf2_stocks.inc Sat Mar 16 13:50:36 2013 -0400
14.3 @@ -350,6 +350,7 @@
14.4 * @return Value or -1 on failure.
14.5 * @error Invalid client index, client not in game or failed to find resource entity.
14.6 */
14.7 +#pragma deprecated Use GetPlayerResourceEntity and GetEntProp instead
14.8 stock TF2_GetPlayerResourceData(client, TFResourceType:type)
14.9 {
14.10 if (!IsClientConnected(client))
14.11 @@ -385,6 +386,7 @@
14.12 * @return Value or -1 on failure.
14.13 * @error Invalid client index, client not in game or failed to find resource entity.
14.14 */
14.15 +#pragma deprecated Use GetPlayerResourceEntity and SetEntProp instead
14.16 stock bool:TF2_SetPlayerResourceData(client, TFResourceType:type, any:value)
14.17 {
14.18 if (!IsClientConnected(client))