fixed amb1379 with sweeping changes to the entity stuff. all prop stocks are now natives so they can properly compute everything quickly, as well as do type checks. Get/SetEntDataEnt are deprecated for being sucky, the new 2 versions do more checking and uses better values. lastly, there are functions/parameters for finding types and sizes of property.

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401853
This commit is contained in:
David Anderson 2008-01-13 08:10:25 +00:00
parent a9017a8291
commit 5f61876ab6
6 changed files with 1267 additions and 331 deletions

View File

@ -70,7 +70,6 @@ CHalfLife2::~CHalfLife2()
for (iter=m_Tables.begin(); iter!=m_Tables.end(); iter++) for (iter=m_Tables.begin(); iter!=m_Tables.end(); iter++)
{ {
pInfo = (*iter); pInfo = (*iter);
sm_trie_destroy(pInfo->lookup);
delete pInfo; delete pInfo;
} }
@ -115,6 +114,8 @@ void CHalfLife2::OnSourceModAllInitialized()
m_HinTextMsg = g_UserMsgs.GetMessageIndex("HintText"); m_HinTextMsg = g_UserMsgs.GetMessageIndex("HintText");
m_VGUIMenu = g_UserMsgs.GetMessageIndex("VGUIMenu"); m_VGUIMenu = g_UserMsgs.GetMessageIndex("VGUIMenu");
g_ShareSys.AddInterface(NULL, this); g_ShareSys.AddInterface(NULL, this);
FindInSendTable("CTFPlayer", "m_nDisguiseClass");
} }
#if !defined METAMOD_PLAPI_VERSION #if !defined METAMOD_PLAPI_VERSION
@ -129,7 +130,10 @@ IChangeInfoAccessor *CBaseEdict::GetChangeAccessor()
return engine->GetChangeAccessor( (const edict_t *)this ); return engine->GetChangeAccessor( (const edict_t *)this );
} }
SendProp *UTIL_FindInSendTable(SendTable *pTable, const char *name) bool UTIL_FindInSendTable(SendTable *pTable,
const char *name,
sm_sendprop_info_t *info,
unsigned int offset)
{ {
const char *pname; const char *pname;
int props = pTable->GetNumProps(); int props = pTable->GetNumProps();
@ -141,13 +145,19 @@ SendProp *UTIL_FindInSendTable(SendTable *pTable, const char *name)
pname = prop->GetName(); pname = prop->GetName();
if (pname && strcmp(name, pname) == 0) if (pname && strcmp(name, pname) == 0)
{ {
return prop; info->prop = prop;
info->actual_offset = offset + info->prop->GetOffset();
return true;
} }
if (prop->GetDataTable()) if (prop->GetDataTable())
{ {
if ((prop=UTIL_FindInSendTable(prop->GetDataTable(), name)) != NULL) if (UTIL_FindInSendTable(prop->GetDataTable(),
name,
info,
offset + prop->GetOffset())
)
{ {
return prop; return true;
} }
} }
} }
@ -187,6 +197,7 @@ typedescription_t *UTIL_FindInDataMap(datamap_t *pMap, const char *name)
ServerClass *CHalfLife2::FindServerClass(const char *classname) ServerClass *CHalfLife2::FindServerClass(const char *classname)
{ {
DataTableInfo *pInfo = _FindServerClass(classname); DataTableInfo *pInfo = _FindServerClass(classname);
if (!pInfo) if (!pInfo)
{ {
return NULL; return NULL;
@ -207,7 +218,6 @@ DataTableInfo *CHalfLife2::_FindServerClass(const char *classname)
if (strcmp(classname, sc->GetName()) == 0) if (strcmp(classname, sc->GetName()) == 0)
{ {
pInfo = new DataTableInfo; pInfo = new DataTableInfo;
pInfo->lookup = sm_trie_create();
pInfo->sc = sc; pInfo->sc = sc;
sm_trie_insert(m_pClasses, classname, pInfo); sm_trie_insert(m_pClasses, classname, pInfo);
m_Tables.push_back(pInfo); m_Tables.push_back(pInfo);
@ -224,25 +234,46 @@ DataTableInfo *CHalfLife2::_FindServerClass(const char *classname)
return pInfo; return pInfo;
} }
bool CHalfLife2::FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info)
{
DataTableInfo *pInfo;
sm_sendprop_info_t *prop;
if ((pInfo = _FindServerClass(classname)) == NULL)
{
return false;
}
if ((prop = pInfo->lookup.retrieve(offset)) == NULL)
{
sm_sendprop_info_t temp_info;
if (!UTIL_FindInSendTable(pInfo->sc->m_pTable, offset, &temp_info, 0))
{
return false;
}
pInfo->lookup.insert(offset, temp_info);
*info = temp_info;
}
else
{
*info = *prop;
}
return true;
}
SendProp *CHalfLife2::FindInSendTable(const char *classname, const char *offset) SendProp *CHalfLife2::FindInSendTable(const char *classname, const char *offset)
{ {
DataTableInfo *pInfo = _FindServerClass(classname); sm_sendprop_info_t info;
if (!pInfo) if (!FindSendPropInfo(classname, offset, &info))
{ {
return NULL; return NULL;
} }
SendProp *pProp = NULL; return info.prop;
if (!sm_trie_retrieve(pInfo->lookup, offset, (void **)&pProp))
{
if ((pProp = UTIL_FindInSendTable(pInfo->sc->m_pTable, offset)) != NULL)
{
sm_trie_insert(pInfo->lookup, offset, pProp);
}
}
return pProp;
} }
typedescription_t *CHalfLife2::FindInDataMap(datamap_t *pMap, const char *offset) typedescription_t *CHalfLife2::FindInDataMap(datamap_t *pMap, const char *offset)
@ -272,7 +303,9 @@ void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset)
if (offset) if (offset)
{ {
pEdict->StateChanged(offset); pEdict->StateChanged(offset);
} else { }
else
{
pEdict->StateChanged(); pEdict->StateChanged();
} }
} }

View File

@ -35,6 +35,7 @@
#include <sh_list.h> #include <sh_list.h>
#include <sh_string.h> #include <sh_string.h>
#include <sh_tinyhash.h> #include <sh_tinyhash.h>
#include <sm_trie_tpl.h>
#include "sm_trie.h" #include "sm_trie.h"
#include "sm_globals.h" #include "sm_globals.h"
#include "sm_queue.h" #include "sm_queue.h"
@ -52,7 +53,7 @@ using namespace SourceMod;
struct DataTableInfo struct DataTableInfo
{ {
ServerClass *sc; ServerClass *sc;
Trie *lookup; KTrie<sm_sendprop_info_t> lookup;
}; };
struct DataMapTrie struct DataMapTrie
@ -89,6 +90,7 @@ public:
/*void OnSourceModAllShutdown();*/ /*void OnSourceModAllShutdown();*/
public: //IGameHelpers public: //IGameHelpers
SendProp *FindInSendTable(const char *classname, const char *offset); SendProp *FindInSendTable(const char *classname, const char *offset);
bool FindSendPropInfo(const char *classname, const char *offset, sm_sendprop_info_t *info);
datamap_t *GetDataMap(CBaseEntity *pEntity); datamap_t *GetDataMap(CBaseEntity *pEntity);
ServerClass *FindServerClass(const char *classname); ServerClass *FindServerClass(const char *classname);
typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset); typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);

View File

@ -45,7 +45,7 @@
AdditionalIncludeDirectories="..\;..\systems;..\..\public;..\..\public\sourcepawn;$(HL2SDK)\public;$(HL2SDK)\public\dlls;$(HL2SDK)\public\engine;$(HL2SDK)\public\tier0;$(HL2SDK)\public\tier1;$(HL2SDK)\public\vstdlib;$(HL2SDK)\tier1;$(SOURCEMM);$(SOURCEMM)\sourcemm;$(SOURCEMM)\sourcehook" AdditionalIncludeDirectories="..\;..\systems;..\..\public;..\..\public\sourcepawn;$(HL2SDK)\public;$(HL2SDK)\public\dlls;$(HL2SDK)\public\engine;$(HL2SDK)\public\tier0;$(HL2SDK)\public\tier1;$(HL2SDK)\public\vstdlib;$(HL2SDK)\tier1;$(SOURCEMM);$(SOURCEMM)\sourcemm;$(SOURCEMM)\sourcehook"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SOURCEMOD_MM_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;SM_DEFAULT_THREADER" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SOURCEMOD_MM_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;SM_DEFAULT_THREADER"
RuntimeLibrary="0" RuntimeLibrary="0"
EnableEnhancedInstructionSet="1" EnableEnhancedInstructionSet="0"
RuntimeTypeInfo="false" RuntimeTypeInfo="false"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
@ -128,7 +128,7 @@
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="1" RuntimeLibrary="1"
EnableEnhancedInstructionSet="1" EnableEnhancedInstructionSet="0"
RuntimeTypeInfo="false" RuntimeTypeInfo="false"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
@ -288,7 +288,7 @@
AdditionalIncludeDirectories="..\;..\systems;..\..\public;..\..\public\sourcepawn;$(HL2SDKOB)\public;$(HL2SDKOB)\public\dlls;$(HL2SDKOB)\public\engine;$(HL2SDKOB)\public\tier0;$(HL2SDKOB)\public\tier1;$(HL2SDKOB)\public\vstdlib;$(HL2SDKOB)\tier1;$(SOURCEMM);$(SOURCEMM)\sourcemm;$(SOURCEMM)\sourcehook" AdditionalIncludeDirectories="..\;..\systems;..\..\public;..\..\public\sourcepawn;$(HL2SDKOB)\public;$(HL2SDKOB)\public\dlls;$(HL2SDKOB)\public\engine;$(HL2SDKOB)\public\tier0;$(HL2SDKOB)\public\tier1;$(HL2SDKOB)\public\vstdlib;$(HL2SDKOB)\tier1;$(SOURCEMM);$(SOURCEMM)\sourcemm;$(SOURCEMM)\sourcehook"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SOURCEMOD_MM_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;SM_DEFAULT_THREADER;ORANGEBOX_BUILD" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SOURCEMOD_MM_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;SM_DEFAULT_THREADER;ORANGEBOX_BUILD"
RuntimeLibrary="0" RuntimeLibrary="0"
EnableEnhancedInstructionSet="1" EnableEnhancedInstructionSet="0"
RuntimeTypeInfo="false" RuntimeTypeInfo="false"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
@ -371,7 +371,7 @@
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="1" RuntimeLibrary="1"
EnableEnhancedInstructionSet="1" EnableEnhancedInstructionSet="0"
RuntimeTypeInfo="false" RuntimeTypeInfo="false"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
@ -453,7 +453,7 @@
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="1" RuntimeLibrary="1"
EnableEnhancedInstructionSet="1" EnableEnhancedInstructionSet="0"
RuntimeTypeInfo="false" RuntimeTypeInfo="false"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
@ -534,7 +534,7 @@
AdditionalIncludeDirectories="..\;..\systems;..\..\public;..\..\public\sourcepawn;$(HL2SDK)\public;$(HL2SDK)\public\dlls;$(HL2SDK)\public\engine;$(HL2SDK)\public\tier0;$(HL2SDK)\public\tier1;$(HL2SDK)\public\vstdlib;$(HL2SDK)\tier1;$(SOURCEMM142);$(SOURCEMM142)\sourcemm;$(SOURCEMM142)\sourcehook" AdditionalIncludeDirectories="..\;..\systems;..\..\public;..\..\public\sourcepawn;$(HL2SDK)\public;$(HL2SDK)\public\dlls;$(HL2SDK)\public\engine;$(HL2SDK)\public\tier0;$(HL2SDK)\public\tier1;$(HL2SDK)\public\vstdlib;$(HL2SDK)\tier1;$(SOURCEMM142);$(SOURCEMM142)\sourcemm;$(SOURCEMM142)\sourcehook"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SOURCEMOD_MM_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;SM_DEFAULT_THREADER" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;SOURCEMOD_MM_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;SOURCEMOD_BUILD;SM_DEFAULT_THREADER"
RuntimeLibrary="0" RuntimeLibrary="0"
EnableEnhancedInstructionSet="1" EnableEnhancedInstructionSet="0"
RuntimeTypeInfo="false" RuntimeTypeInfo="false"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"

File diff suppressed because it is too large Load Diff

View File

@ -41,7 +41,7 @@
enum PropType enum PropType
{ {
Prop_Send = 0, /**< This property is networked. */ Prop_Send = 0, /**< This property is networked. */
Prop_Data = 1, /**< This property is for saved game files. */ Prop_Data = 1, /**< This property is for save game data fields. */
}; };
/** /**
@ -59,6 +59,16 @@ enum PropType
#define FL_EDICT_DIRTY_PVS_INFORMATION (1<<7) #define FL_EDICT_DIRTY_PVS_INFORMATION (1<<7)
#define FL_FULL_EDICT_CHANGED (1<<8) #define FL_FULL_EDICT_CHANGED (1<<8)
enum PropFieldType
{
PropField_Unsupported, /**< The type is unsupported. */
PropField_Integer, /**< Valid for SendProp and Data fields */
PropField_Float, /**< Valid for SendProp and Data fields */
PropField_Entity, /**< Valid for Data fields only (SendProp shows as int) */
PropField_Vector, /**< Valid for SendProp and Data fields */
PropField_String, /**< Valid for SendProp and Data fields */
};
/** /**
* @endsection * @endsection
*/ */
@ -244,8 +254,14 @@ native Float:GetEntDataFloat(entity, offset);
native SetEntDataFloat(entity, offset, Float:value, bool:changeState=false); native SetEntDataFloat(entity, offset, Float:value, bool:changeState=false);
/** /**
* Peeks into an entity's object data and retrieves the entity handle * This function is deprecated. Use GetEntDataEnt2 instead, for
* info at the given offset. * reasons explained in the notes.
*
* Note: This function returns 0 on failure, which may be misleading,
* as the number 0 is also used for the world entity index.
*
* Note: This function makes no attempt to validate the returned
* entity, and in fact, it could be garbage or completely unexpected.
* *
* @param entity Edict index. * @param entity Edict index.
* @param offset Offset to use. * @param offset Offset to use.
@ -255,8 +271,12 @@ native SetEntDataFloat(entity, offset, Float:value, bool:changeState=false);
native GetEntDataEnt(entity, offset); native GetEntDataEnt(entity, offset);
/** /**
* Peeks into an entity's object data and sets the entity handle info * This function is deprecated. Use GetEntDataEnt2 instead, for
* at the given offset. * reasons explained in the notes.
*
* Note: This function uses 0 as an indicator to unset data, but
* 0 is also the world entity index. Thus, the a property cannot
* be set to the world entity using this native.
* *
* @param entity Edict index. * @param entity Edict index.
* @param offset Offset to use. * @param offset Offset to use.
@ -267,6 +287,39 @@ native GetEntDataEnt(entity, offset);
*/ */
native SetEntDataEnt(entity, offset, other, bool:changeState=false); native SetEntDataEnt(entity, offset, other, bool:changeState=false);
/**
* Peeks into an entity's object data and retrieves the entity index
* at the given offset.
*
* Note: This will only work on offsets that are stored as "entity
* handles" (which usually looks like m_h* in properties). These
* are not SourceMod Handles, but internal Source structures.
*
* @param entity Edict index.
* @param offset Offset to use.
* @return Entity index at the given location. If there is no entity,
* or the stored entity is invalid, then -1 is returned.
* @error Invalid input entity, or offset out of reasonable bounds.
*/
native GetEntDataEnt2(entity, offset);
/**
* Peeks into an entity's object data and sets the entity index at the
* given offset.
*
* Note: This will only work on offsets that are stored as "entity
* handles" (which usually looks like m_h* in properties). These
* are not SourceMod Handles, but internal Source structures.
*
* @param entity Edict index.
* @param offset Offset to use.
* @param other Entity index to set, or -1 to clear.
* @param changeState If true, change will be sent over the network.
* @noreturn
* @error Invalid input entity, or offset out of reasonable bounds.
*/
native SetEntDataEnt2(entity, offset, other, bool:changeState=false);
/** /**
* Peeks into an entity's object data and retrieves the vector at the * Peeks into an entity's object data and retrieves the vector at the
* given offset. * given offset.
@ -331,30 +384,74 @@ native SetEntDataString(entity, offset, const String:buffer[], maxlen, bool:chan
* Given a ServerClass name, finds a networkable send property offset. * Given a ServerClass name, finds a networkable send property offset.
* This information is cached for future calls. * This information is cached for future calls.
* *
* Note, this function may return offsets that do not work!
* If a property is nested beneath a parent object, the resulting offset
* will be invalid for direct use with data functions. Therefore, you
* should use FindSendPropInfo() instead. An example of such a property is
* CTFPlayer::DT_LocalPlayer.m_nDisguiseClass on Team Fortress.
*
* @param cls Classname. * @param cls Classname.
* @param prop Property name. * @param prop Property name.
* @return An offset, or -1 on failure. * @return An offset, or -1 on failure.
*/ */
native FindSendPropOffs(const String:cls[], const String:prop[]); native FindSendPropOffs(const String:cls[], const String:prop[]);
/**
* Given a ServerClass name, finds a networkable send property offset.
* This information is cached for future calls.
*
* Note: This function will correctly compute nested offsets, unlike
* FindSendPropOffs(). YOU SHOULD NOT use this function to self-compute
* nested offsets. For example, it is okay to add indexes for arrays,
* but not to add DT_LocalPlayer to m_nDisguiseClass.
*
* @param cls Classname.
* @param prop Property name.
* @param type Optional parameter to store the type.
* @param num_bits Optional parameter to store the number of bits the field
* uses, if applicable (otherwise 0 is stored). The number
* of bits varies for integers and floats, and is always 0
* for strings.
* @param local_offset Optional parameter to store the local offset, as
* FindSendPropOffs() would return.
* @return On success, returns an absolutely computed offset.
* If no offset is available, 0 is returned.
* If the property is not found, -1 is returned.
*/
native FindSendPropInfo(const String:cls[],
const String:prop[],
&PropFieldType:type=PropFieldType:0,
&num_bits=0,
&local_offset=0);
/** /**
* Given an entity, finds a datamap property offset. * Given an entity, finds a datamap property offset.
* This information is cached for future calls. * This information is cached for future calls.
* *
* @param entity Entity index. * @param entity Entity index.
* @param prop Property name. * @param prop Property name.
* @param type Optional parameter to store the type.
* @param num_bits Optional parameter to store the number of bits the field
* uses. The bit count will either be 1 (for boolean) or
* divisible by 8 (including 0 if unknown).
* @return An offset, or -1 on failure. * @return An offset, or -1 on failure.
*/ */
native FindDataMapOffs(entity, const String:prop[]); native FindDataMapOffs(entity,
const String:prop[],
&PropFieldType:type=PropFieldType:0,
&num_bits=0);
/** /**
* Wrapper function for finding a send property for a particular entity. * Wrapper function for finding a send property for a particular entity.
* *
* @param ent Entity index. * @param ent Entity index.
* @param prop Property name. * @param prop Property name.
* @param actual Defaults to false for backwards compatibility.
* If true, the newer FindSendPropInfo() function
* is used instead.
* @return An offset, or -1 on failure. * @return An offset, or -1 on failure.
*/ */
stock GetEntSendPropOffs(ent, const String:prop[]) stock GetEntSendPropOffs(ent, const String:prop[], bool:actual=false)
{ {
decl String:cls[64]; decl String:cls[64];
@ -363,314 +460,149 @@ stock GetEntSendPropOffs(ent, const String:prop[])
return -1; return -1;
} }
if (actual)
{
return FindSendPropInfo(cls, prop);
}
else
{
return FindSendPropOffs(cls, prop); return FindSendPropOffs(cls, prop);
}
} }
/** /**
* Gets a network property as an integer; wrapper around GetEntData(). * Retrieves an integer value from an entity's property.
* *
* @param entity Edict index. * This function is considered safer and more robust over GetEntData,
* because it performs strict offset checking and typing rules. There is a
* very minor performance hit from this.
*
* @param entity Entity/edict index.
* @param type Property type. * @param type Property type.
* @param prop Property to use. * @param prop Property name.
* @param size Number of bytes to read (valid values are 1, 2, or 4). * @param size Number of bytes to write (valid values are 1, 2, or 4).
* This value is auto-detected, and the size parameter is
* only used as a fallback in case detection fails.
* @return Value at the given property offset. * @return Value at the given property offset.
* @error Invalid entity or property not found. * @error Invalid entity or property not found.
*/ */
stock GetEntProp(entity, PropType:type, const String:prop[], size=4) native GetEntProp(entity, PropType:type, const String:prop[], size=4);
{
new offs;
switch (type)
{
case Prop_Send:
{
offs = GetEntSendPropOffs(entity, prop);
}
case Prop_Data:
{
offs = FindDataMapOffs(entity, prop);
}
default:
{
ThrowError("Invalid Property type %d", type);
}
}
if (offs == -1)
{
ThrowError("Property \"%s\" not found for entity %d", prop, entity);
}
return GetEntData(entity, offs, size);
}
/** /**
* Sets a network property as an integer; wrapper around GetEntData(). * Sets an integer value in an entity's property.
* *
* @param entity Edict index. * This function is considered safer and more robust over SetEntData,
* because it performs strict offset checking and typing rules. There is a
* very minor performance hit from this.
*
* @param entity Entity/edict index.
* @param type Property type. * @param type Property type.
* @param prop Property to use. * @param prop Property name.
* @param size Number of bytes to write (valid values are 1, 2, or 4). * @param size Number of bytes to write (valid values are 1, 2, or 4).
* This value is auto-detected, and the size parameter is
* only used as a fallback in case detection fails.
* @error Invalid entity or offset out of reasonable bounds. * @error Invalid entity or offset out of reasonable bounds.
* @noreturn * @noreturn
*/ */
stock SetEntProp(entity, PropType:type, const String:prop[], any:value, size=4) native SetEntProp(entity, PropType:type, const String:prop[], any:value, size=4);
{
new offs;
switch (type)
{
case Prop_Send:
{
offs = GetEntSendPropOffs(entity, prop);
}
case Prop_Data:
{
offs = FindDataMapOffs(entity, prop);
}
default:
{
ThrowError("Invalid Property type %d", type);
}
}
if (offs == -1)
{
ThrowError("Property \"%s\" not found for entity %d", prop, entity);
}
return SetEntData(entity, offs, value, size, true);
}
/** /**
* Gets a network property as a float; wrapper around GetEntDataFloat(). * Retrieves a float value from an entity's property.
* *
* @param entity Edict index. * This function is considered safer and more robust over GetEntDataFloat,
* because it performs strict offset checking and typing rules. There is a
* very minor performance hit from this.
*
* @param entity Entity/edict index.
* @param type Property type. * @param type Property type.
* @param prop Property to use. * @param prop Property name.
* @return Value at the given property offset. * @return Value at the given property offset.
* @error Invalid entity or offset out of reasonable bounds. * @error Invalid entity or offset out of reasonable bounds.
*/ */
stock Float:GetEntPropFloat(entity, PropType:type, const String:prop[]) native Float:GetEntPropFloat(entity, PropType:type, const String:prop[]);
{
new offs;
switch (type)
{
case Prop_Send:
{
offs = GetEntSendPropOffs(entity, prop);
}
case Prop_Data:
{
offs = FindDataMapOffs(entity, prop);
}
default:
{
ThrowError("Invalid Property type %d", type);
}
}
if (offs == -1)
{
ThrowError("Property \"%s\" not found for entity %d", prop, entity);
}
return GetEntDataFloat(entity, offs);
}
/** /**
* Sets a network property as a float; wrapper around SetEntDataFloat(). * Sets a float value in an entity's property.
* *
* @param entity Edict index. * This function is considered safer and more robust over SetEntDataFloat,
* because it performs strict offset checking and typing rules. There is a
* very minor performance hit from this.
*
* @param entity Entity/edict index.
* @param type Property type. * @param type Property type.
* @param prop Property to use. * @param prop Property name.
* @param value Value to set. * @param value Value to set.
* @noreturn * @noreturn
* @error Invalid entity or offset out of reasonable bounds. * @error Invalid entity or offset out of reasonable bounds.
*/ */
stock SetEntPropFloat(entity, PropType:type, const String:prop[], Float:value) native SetEntPropFloat(entity, PropType:type, const String:prop[], Float:value);
{
new offs;
switch (type)
{
case Prop_Send:
{
offs = GetEntSendPropOffs(entity, prop);
}
case Prop_Data:
{
offs = FindDataMapOffs(entity, prop);
}
default:
{
ThrowError("Invalid Property type %d", type);
}
}
if (offs == -1)
{
ThrowError("Property \"%s\" not found for entity %d", prop, entity);
}
return SetEntDataFloat(entity, offs, value, true);
}
/** /**
* Gets a network property as a handle entity; wrapper around GetEntDataEnt(). * Retrieves an entity index from an entity's property.
* *
* @param entity Edict index. * This function is considered safer and more robust over GetEntDataEnt*,
* because it performs strict offset checking and typing rules. There is a
* very minor performance hit from this.
*
* @param entity Entity/edict index.
* @param type Property type. * @param type Property type.
* @param prop Property to use. * @param prop Property name.
* @return Entity index at the given property, or 0 if none. * @return Entity index at the given property.
* If there is no entity, or the entity is not valid,
* then -1 is returned.
* @error Invalid entity or offset out of reasonable bounds. * @error Invalid entity or offset out of reasonable bounds.
*/ */
stock GetEntPropEnt(entity, PropType:type, const String:prop[]) native GetEntPropEnt(entity, PropType:type, const String:prop[]);
{
new offs;
switch (type)
{
case Prop_Send:
{
offs = GetEntSendPropOffs(entity, prop);
}
case Prop_Data:
{
offs = FindDataMapOffs(entity, prop);
}
default:
{
ThrowError("Invalid Property type %d", type);
}
}
if (offs == -1)
{
ThrowError("Property \"%s\" not found for entity %d", prop, entity);
}
return GetEntDataEnt(entity, offs);
}
/** /**
* Sets a network property as a handle entity; wrapper around SetEntDataEnt(). * Sets an entity index in an entity's property.
* *
* @param entity Edict index. * This function is considered safer and more robust over SetEntDataEnt*,
* because it performs strict offset checking and typing rules. There is a
* very minor performance hit from this.
*
* @param entity Entity/edict index.
* @param type Property type. * @param type Property type.
* @param prop Property to use. * @param prop Property name.
* @param other Entity index to set, or 0 to unset. * @param other Entity index to set, or -1 to unset.
* @noreturn * @noreturn
* @error Invalid entity or offset out of reasonable bounds. * @error Invalid entity or offset out of reasonable bounds.
*/ */
stock SetEntPropEnt(entity, PropType:type, const String:prop[], other) native SetEntPropEnt(entity, PropType:type, const String:prop[], other);
{
new offs;
switch (type)
{
case Prop_Send:
{
offs = GetEntSendPropOffs(entity, prop);
}
case Prop_Data:
{
offs = FindDataMapOffs(entity, prop);
}
default:
{
ThrowError("Invalid Property type %d", type);
}
}
if (offs == -1)
{
ThrowError("Property \"%s\" not found for entity %d", prop, entity);
}
return SetEntDataEnt(entity, offs, other, true);
}
/** /**
* Gets a network property as a vector; wrapper around GetEntDataVector(). * Retrieves a vector of floats from an entity, given a named network property.
* @note Both a Vector and a QAngle are three floats. This is a
* convenience function and will work with both types.
* *
* @param entity Edict index. * This function is considered safer and more robust over GetEntDataVector,
* because it performs strict offset checking and typing rules. There is a
* very minor performance hit from this.
*
* @param entity Entity/edict index.
* @param type Property type. * @param type Property type.
* @param prop Property to use. * @param prop Property name.
* @param vec Vector buffer to store data in. * @param vec Vector buffer to store data in.
* @noreturn * @noreturn
* @error Invalid entity or offset out of reasonable bounds. * @error Invalid entity, property not found, or property not
* actually a vector data type.
*/ */
stock GetEntPropVector(entity, PropType:type, const String:prop[], Float:vec[3]) native GetEntPropVector(entity, PropType:type, const String:prop[], Float:vec[3]);
{
new offs;
switch (type)
{
case Prop_Send:
{
offs = GetEntSendPropOffs(entity, prop);
}
case Prop_Data:
{
offs = FindDataMapOffs(entity, prop);
}
default:
{
ThrowError("Invalid Property type %d", type);
}
}
if (offs == -1)
{
ThrowError("Property \"%s\" not found for entity %d", prop, entity);
}
return GetEntDataVector(entity, offs, vec);
}
/** /**
* Sets a network property as a vector; wrapper around SetEntDataVector(). * Sets a vector of floats in an entity, given a named network property.
* @note Both a Vector and a QAngle are three floats. This is a
* convenience function and will work with both types.
* *
* @param entity Edict index. * This function is considered safer and more robust over SetEntDataVector,
* because it performs strict offset checking and typing rules. There is a
* very minor performance hit from this.
*
* @param entity Entity/edict index.
* @param type Property type. * @param type Property type.
* @param prop Property to use. * @param prop Property name.
* @param vec Vector to set. * @param vec Vector to set.
* @noreturn * @noreturn
* @error Invalid entity or offset out of reasonable bounds. * @error Invalid entity, property not found, or property not
* actually a vector data type.
*/ */
stock SetEntPropVector(entity, PropType:type, const String:prop[], const Float:vec[3]) native SetEntPropVector(entity, PropType:type, const String:prop[], const Float:vec[3]);
{
new offs;
switch (type)
{
case Prop_Send:
{
offs = GetEntSendPropOffs(entity, prop);
}
case Prop_Data:
{
offs = FindDataMapOffs(entity, prop);
}
default:
{
ThrowError("Invalid Property type %d", type);
}
}
if (offs == -1)
{
ThrowError("Property \"%s\" not found for entity %d", prop, entity);
}
return SetEntDataVector(entity, offs, vec, true);
}
/** /**
* Gets a network property as a string. * Gets a network property as a string.
@ -716,7 +648,6 @@ stock GetEntDataArray(entity, offset, array[], arraySize, dataSize=4)
} }
} }
/** /**
* Copies an array of cells to an entity at a given offset. * Copies an array of cells to an entity at a given offset.
* *

View File

@ -48,6 +48,15 @@
namespace SourceMod namespace SourceMod
{ {
/**
* @brief Maps the heirarchy of a SendProp.
*/
struct sm_sendprop_info_t
{
SendProp *prop; /**< Property instance. */
unsigned int actual_offset; /**< Actual computed offset. */
};
class IGameHelpers : public SMInterface class IGameHelpers : public SMInterface
{ {
public: public:
@ -61,11 +70,11 @@ namespace SourceMod
} }
public: public:
/** /**
* @brief Finds a send property in a named send table. * @brief Deprecated; use FindSendPropInfo() instead.
* *
* @param classname Top-level sendtable name. * @param classname Do not use.
* @param offset Property name. * @param offset Do not use.
* @return SendProp pointer on success, NULL on failure. * @return Do not use.
*/ */
virtual SendProp *FindInSendTable(const char *classname, const char *offset) =0; virtual SendProp *FindInSendTable(const char *classname, const char *offset) =0;
@ -118,6 +127,21 @@ namespace SourceMod
* @return True if LAN server, false otherwise. * @return True if LAN server, false otherwise.
*/ */
virtual bool IsLANServer() =0; virtual bool IsLANServer() =0;
/**
* @brief Finds a send property in a named ServerClass.
*
* This version, unlike FindInSendTable(), correctly deduces the
* offsets of nested tables.
*
* @param classname ServerClass name (such as CBasePlayer).
* @param offset Offset name (such as m_iAmmo).
* @param info Buffer to store sm_sendprop_info_t data.
* @return True on success, false on failure.
*/
virtual bool FindSendPropInfo(const char *classname,
const char *offset,
sm_sendprop_info_t *info) =0;
}; };
} }