added entity functions and stocks for send props

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40567
This commit is contained in:
David Anderson 2007-03-02 19:11:04 +00:00
parent 66b244011e
commit 791cbc985f
2 changed files with 229 additions and 4 deletions

View File

@ -16,6 +16,7 @@
#include "sourcemm_api.h"
#include "server_class.h"
#include "CPlayerManager.h"
#include "CHalfLife2.h"
inline edict_t *GetEdict(cell_t num)
{
@ -253,6 +254,11 @@ static cell_t SetEntData(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Offset %d is invalid", offset);
}
if (params[5])
{
pEdict->StateChanged(offset);
}
switch (params[4])
{
case 4:
@ -316,6 +322,11 @@ static cell_t SetEntDataFloat(IPluginContext *pContext, const cell_t *params)
*(float *)((uint8_t *)pEntity + offset) = sp_ctof(params[3]);
if (params[4])
{
pEdict->StateChanged(offset);
}
return 1;
}
@ -372,6 +383,11 @@ static cell_t SetEntDataVector(IPluginContext *pContext, const cell_t *params)
v->y = vec[1];
v->z = vec[2];
if (params[4])
{
pEdict->StateChanged(offset);
}
return 1;
}
@ -434,6 +450,11 @@ static cell_t SetEntDataEnt(IPluginContext *pContext, const cell_t *params)
hndl.Set(pEntOther);
}
if (params[4])
{
pEdict->StateChanged(offset);
}
return 1;
}
@ -468,10 +489,27 @@ static cell_t ChangeEdictState(IPluginContext *pContext, const cell_t *params)
return 1;
}
static cell_t FindSendPropOffs(IPluginContext *pContext, const cell_t *params)
{
char *cls, *prop;
pContext->LocalToString(params[1], &cls);
pContext->LocalToString(params[2], &prop);
SendProp *pSend = g_HL2.FindInSendTable(cls, prop);
if (!pSend)
{
return -1;
}
return pSend->GetOffset();
}
REGISTER_NATIVES(entityNatives)
{
{"ChangeEdictState", ChangeEdictState},
{"CreateEdict", CreateEdict},
{"FindSendPropOffs", FindSendPropOffs},
{"GetEdictClassname", GetEdictClassname},
{"GetEdictFlags", GetEdictFlags},
{"GetEntData", GetEntData},

View File

@ -183,11 +183,12 @@ native GetEntData(entity, offset, size=4);
* @param entity Edict index.
* @param offset Offset to use.
* @param size Number of bytes to write (valid values are 1, 2, or 4).
* @param changeState If true, change will be sent over the network.
* @return Value at the given memory location.
* @error Invalid entity or offset out of reasonable bounds.
* @noreturn
*/
native SetEntData(entity, offset, value, size=4);
native SetEntData(entity, offset, value, size=4, bool:changeState=false);
/**
* Peeks into an entity's object data and retrieves the float value at
@ -206,11 +207,12 @@ native Float:GetEntDataFloat(entity, offset);
*
* @param entity Edict index.
* @param offset Offset to use.
* @param changeState If true, change will be sent over the network.
* @return Value at the given memory location.
* @error Invalid entity or offset out of reasonable bounds.
* @noreturn
*/
native SetEntDataFloat(entity, offset, Float:value);
native SetEntDataFloat(entity, offset, Float:value, bool:changeState=false);
/**
* Peeks into an entity's object data and retrieves the entity handle
@ -230,10 +232,11 @@ native GetEntDataEnt(entity, offset);
* @param entity Edict index.
* @param offset Offset to use.
* @param other Entity index to set, or 0 to clear.
* @param changeState If true, change will be sent over the network.
* @noreturn
* @error Invalid entity or offset out of reasonable bounds.
*/
native SetEntDataEnt(entity, offset, other);
native SetEntDataEnt(entity, offset, other, bool:changeState=false);
/**
* Peeks into an entity's object data and retrieves the vector at the
@ -258,7 +261,191 @@ native GetEntDataVector(entity, offset, Float:vec[3]);
* @param entity Edict index.
* @param offset Offset to use.
* @param vec Vector to set.
* @param changeState If true, change will be sent over the network.
* @noreturn
* @error Invalid entity or offset out of reasonable bounds.
*/
native SetEntDataVector(entity, offset, const Float:vec[3]);
native SetEntDataVector(entity, offset, const Float:vec[3], bool:changeState=false);
/**
* Given a ServerClass name, finds a networkable send property offset.
* This information is cached for future calls.
*
* @param cls Classname.
* @param prop Property name.
* @return An offset, or -1 on failure.
*/
native FindSendPropOffs(const String:cls[], const String:prop[]);
/**
* Wrapper function for finding a send property for a particular entity.
*
* @param ent Entity index.
* @param prop Property name.
* @return An offset, or -1 on failure.
*/
stock GetEntSendPropOffs(ent, const String:prop[])
{
decl String:cls[64];
if (!GetEntityNetClass(ent, cls, sizeof(cls)))
{
return -1;
}
return FindSendPropOffs(cls, prop);
}
/**
* Gets a network property as an integer; wrapper around GetEntData().
*
* @param entity Edict index.
* @param prop Property to use.
* @param size Number of bytes to read (valid values are 1, 2, or 4).
* @return Value at the given property offset.
* @error Invalid entity or property not found.
*/
stock GetEntProp(entity, const String:prop[], size=4)
{
new offs = GetEntSendPropOffs(entity, prop);
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().
*
* @param entity Edict index.
* @param prop Property to use.
* @param size Number of bytes to write (valid values are 1, 2, or 4).
* @error Invalid entity or offset out of reasonable bounds.
* @noreturn
*/
stock SetEntProp(entity, const String:prop[], value, size=4)
{
new offs = GetEntSendPropOffs(entity, prop);
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().
*
* @param entity Edict index.
* @param prop Property to use.
* @return Value at the given property offset..
* @error Invalid entity or offset out of reasonable bounds.
*/
stock Float:GetEntPropFloat(entity, const String:prop[])
{
new offs = GetEntSendPropOffs(entity, prop);
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().
*
* @param entity Edict index.
* @param prop Property to use.
* @param value Value to set.
* @noreturn
* @error Invalid entity or offset out of reasonable bounds.
*/
stock SetEntPropFloat(entity, const String:prop[], Float:value)
{
new offs = GetEntSendPropOffs(entity, prop);
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().
*
* @param entity Edict index.
* @param prop Property to use.
* @return Entity index at the given property, or 0 if none.
* @error Invalid entity or offset out of reasonable bounds.
*/
stock GetEntPropEnt(entity, const String:prop[])
{
new offs = GetEntSendPropOffs(entity, prop);
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().
*
* @param entity Edict index.
* @param prop Property to use.
* @param other Entity index to set, or 0 to unset.
* @noreturn
* @error Invalid entity or offset out of reasonable bounds.
*/
stock SetEntPropEnt(entity, const String:prop[], other)
{
new offs = GetEntSendPropOffs(entity, prop);
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().
* @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.
* @param prop Property to use.
* @param vec Vector buffer to store data in.
* @noreturn
* @error Invalid entity or offset out of reasonable bounds.
*/
stock GetEntPropVector(entity, const String:prop[], Float:vec[3])
{
new offs = GetEntSendPropOffs(entity, prop);
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().
* @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.
* @param prop Property to use.
* @param vec Vector to set.
* @noreturn
* @error Invalid entity or offset out of reasonable bounds.
*/
stock SetEntPropVector(entity, const String:prop[], const Float:vec[3])
{
new offs = GetEntSendPropOffs(entity, prop);
if (offs == -1)
{
ThrowError("Property \"%s\" not found for entity %d", prop, entity);
}
return SetEntDataVector(entity, offs, vec, true);
}