Fix SDKHooks hook ent validation missing first datatable name (bug 5881, r=asherkin).

This commit is contained in:
Nicholas Hastings 2013-08-24 21:59:52 -04:00
parent 9bf78a96cc
commit 96e971084a
4 changed files with 10 additions and 17 deletions

View File

@ -525,11 +525,10 @@ HookReturn SDKHooks::Hook(int entity, SDKHookType type, IPluginFunction *callbac
if (!!strcmp(g_HookTypes[type].dtReq, ""))
{
sm_sendprop_info_t spi;
IServerUnknown *pUnk = (IServerUnknown *)pEnt;
IServerNetworkable *pNet = pUnk->GetNetworkable();
if (pNet && !UTIL_FindDataTable(pNet->GetServerClass()->m_pTable, g_HookTypes[type].dtReq, &spi, 0))
if (pNet && !UTIL_ContainsDataTable(pNet->GetServerClass()->m_pTable, g_HookTypes[type].dtReq))
return HookRet_BadEntForHookType;
}

View File

@ -190,13 +190,13 @@ cell_t Native_DropWeapon(IPluginContext *pContext, const cell_t *params)
if (!pWeapon)
return pContext->ThrowNativeError("Invalid entity index %d for weapon", params[2]);
sm_sendprop_info_t spi;
IServerUnknown *pUnk = (IServerUnknown *)pWeapon;
IServerNetworkable *pNet = pUnk->GetNetworkable();
if (!UTIL_FindDataTable(pNet->GetServerClass()->m_pTable, "DT_BaseCombatWeapon", &spi, 0))
if (!UTIL_ContainsDataTable(pNet->GetServerClass()->m_pTable, "DT_BaseCombatWeapon"))
return pContext->ThrowNativeError("Entity index %d is not a weapon", params[2]);
sm_sendprop_info_t spi;
if (!gamehelpers->FindSendPropInfo("CBaseCombatWeapon", "m_hOwnerEntity", &spi))
return pContext->ThrowNativeError("Invalid entity index %d for weapon", params[2]);

View File

@ -64,16 +64,16 @@ CBaseEntity *UTIL_GetCBaseEntity(int num, bool onlyPlayers)
return pUnk->GetBaseEntity();
}
bool UTIL_FindDataTable(SendTable *pTable,
const char *name,
sm_sendprop_info_t *info,
unsigned int offset)
bool UTIL_ContainsDataTable(SendTable *pTable, const char *name)
{
const char *pname;
const char *pname = pTable->GetName();
int props = pTable->GetNumProps();
SendProp *prop;
SendTable *table;
if (pname && strcmp(name, pname) == 0)
return true;
for (int i=0; i<props; i++)
{
prop = pTable->GetProp(i);
@ -83,16 +83,10 @@ bool UTIL_FindDataTable(SendTable *pTable,
pname = table->GetName();
if (pname && strcmp(name, pname) == 0)
{
info->prop = prop;
info->actual_offset = offset + info->prop->GetOffset();
return true;
}
if (UTIL_FindDataTable(table,
name,
info,
offset + prop->GetOffset())
)
if (UTIL_ContainsDataTable(table, name))
{
return true;
}

View File

@ -35,6 +35,6 @@
#include <compat_wrappers.h>
CBaseEntity *UTIL_GetCBaseEntity(int num, bool onlyPlayers=false);
bool UTIL_FindDataTable(SendTable *pTable, const char *name, sm_sendprop_info_t *info, unsigned int offset);
bool UTIL_ContainsDataTable(SendTable *pTable, const char *name);
#endif //_INCLUDE_TF2TOOLS_UTIL_H_