Add GetPlayerResourceEntity to SDKTools; deprecate old, broken TF2-specific impl (bug 5491, r=asherkin).

This commit is contained in:
Nicholas Hastings 2013-03-16 13:50:36 -04:00
parent 9e540eb1c4
commit 0c7696da65
14 changed files with 157 additions and 29 deletions

View File

@ -43,6 +43,7 @@
#include "gamerulesnatives.h"
#include <ISDKTools.h>
#include "clientnatives.h"
#include "teamnatives.h"
/**
* @file extension.cpp
* @brief Implements SDK Tools extension code.
@ -279,6 +280,12 @@ void SDKTools::SDK_OnAllLoaded()
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);

View File

@ -135,8 +135,6 @@ extern ICallWrapper *g_pAcceptInput;
extern SourceHook::CallClass<IVEngineServer> *enginePatch;
extern SourceHook::CallClass<IEngineSound> *enginesoundPatch;
extern const char *tools_GetTeamName(int team);
#include <compat_wrappers.h>
#define ENGINE_CALL(func) SH_CALL(enginePatch, &IVEngineServer::func)

View File

@ -1325,6 +1325,7 @@
<ClInclude Include="..\hooks.h" />
<ClInclude Include="..\..\..\public\extensions\ISDKTools.h" />
<ClInclude Include="..\output.h" />
<ClInclude Include="..\teamnatives.h" />
<ClInclude Include="..\tempents.h" />
<ClInclude Include="..\vcallbuilder.h" />
<ClInclude Include="..\vdecoder.h" />

View File

@ -137,6 +137,9 @@
<ClInclude Include="..\clientnatives.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\teamnatives.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\version.rc">

View File

@ -30,6 +30,7 @@
*/
#include "extension.h"
#include "vhelpers.h"
#include <sh_vector.h>
struct TeamInfo
@ -42,36 +43,13 @@ const char *m_iScore;
SourceHook::CVector<TeamInfo> 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; i<props; i++)
{
prop = pTable->GetProp(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; i<edictCount; i++)
{
edict_t *pEdict = PEntityOfEntIndex(i);
@ -85,7 +63,7 @@ void SDKTools::OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax
}
ServerClass *pClass = pEdict->GetNetworkable()->GetServerClass();
if (FindTeamEntities(pClass->m_pTable, "DT_Team"))
if (FindNestedDataTable(pClass->m_pTable, "DT_Team"))
{
SendProp *pTeamNumProp = g_pGameHelpers->FindInSendTable(pClass->GetName(), "m_iTeamNum");

View File

@ -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 <http://www.gnu.org/licenses/>.
*
* 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 <http://www.sourcemod.net/license.php>.
*
* 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_

View File

@ -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 @@ void GetIServer()
}
#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; i<edictCount; i++)
{
edict_t *pEdict = PEntityOfEntIndex(i);
if (!pEdict || pEdict->IsFree())
{
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)

View File

@ -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_

View File

@ -279,6 +279,31 @@ void ShutdownHelpers()
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; i<props; i++)
{
prop = pTable->GetProp(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];

View File

@ -72,4 +72,6 @@ bool GetPlayerInfo(int client, player_info_t *info);
void ShutdownHelpers();
bool FindNestedDataTable(SendTable *pTable, const char *name);
#endif //_INCLUDE_SDKTOOLS_VHELPERS_H_

View File

@ -1208,6 +1208,16 @@ static cell_t SetClientInfo(IPluginContext *pContext, const cell_t *params)
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 @@ sp_nativeinfo_t g_Natives[] =
{"EquipPlayerWeapon", WeaponEquip},
{"ActivateEntity", ActivateEntity},
{"SetClientInfo", SetClientInfo},
{"GetPlayerResourceEntity", GetPlayerResourceEntity},
{NULL, NULL},
};

View File

@ -194,6 +194,13 @@ native Handle:EndPrepSDKCall();
*/
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 <sdktools_stocks>
/**

View File

@ -278,6 +278,7 @@ native TF2_MakeBleed(client, attacker, Float:duration);
*
* @return The current resource entity index.
*/
#pragma deprecated Use GetPlayerResourceEntity instead
native TF2_GetResourceEntity();
/**

View File

@ -350,6 +350,7 @@ stock TF2_SetPlayerClass(client, TFClassType:class, bool:weapons=true, bool:pers
* @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 @@ stock TF2_GetPlayerResourceData(client, TFResourceType:type)
* @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))