Add TE_WriteEnt and TE_ReadEnt natives to SDKTools. (#1905)
This commit is contained in:
parent
27b1817b10
commit
8922ed0c5d
@ -30,6 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tempents.h"
|
#include "tempents.h"
|
||||||
|
#include <basehandle.h>
|
||||||
|
|
||||||
TempEntityManager g_TEManager;
|
TempEntityManager g_TEManager;
|
||||||
ICallWrapper *g_GetServerClass = NULL;
|
ICallWrapper *g_GetServerClass = NULL;
|
||||||
@ -183,6 +184,43 @@ bool TempEntityInfo::TE_GetEntData(const char *name, int *value)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TempEntityInfo::TE_SetEntDataEnt(const char *name, IHandleEntity *value)
|
||||||
|
{
|
||||||
|
/* Search for our offset */
|
||||||
|
int offset = _FindOffset(name);
|
||||||
|
|
||||||
|
if (offset < 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *pHndl = (CBaseHandle *)((uint8_t *)m_Me + offset);
|
||||||
|
pHndl->Set(value);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TempEntityInfo::TE_GetEntDataEnt(const char *name, IHandleEntity **value)
|
||||||
|
{
|
||||||
|
/* Search for our offset */
|
||||||
|
int offset = _FindOffset(name);
|
||||||
|
|
||||||
|
if (offset < 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *pHndl = (CBaseHandle *)((uint8_t *)m_Me + offset);
|
||||||
|
auto *pEnt = reinterpret_cast<IHandleEntity *>(gamehelpers->ReferenceToEntity(pHndl->GetEntryIndex()));
|
||||||
|
if (!pEnt || *pHndl != pEnt->GetRefEHandle())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*value = pEnt;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool TempEntityInfo::TE_SetEntDataFloat(const char *name, float value)
|
bool TempEntityInfo::TE_SetEntDataFloat(const char *name, float value)
|
||||||
{
|
{
|
||||||
/* Search for our offset */
|
/* Search for our offset */
|
||||||
|
@ -47,10 +47,12 @@ public:
|
|||||||
ServerClass *GetServerClass();
|
ServerClass *GetServerClass();
|
||||||
bool IsValidProp(const char *name);
|
bool IsValidProp(const char *name);
|
||||||
bool TE_SetEntData(const char *name, int value);
|
bool TE_SetEntData(const char *name, int value);
|
||||||
|
bool TE_SetEntDataEnt(const char *name, IHandleEntity *value);
|
||||||
bool TE_SetEntDataFloat(const char *name, float value);
|
bool TE_SetEntDataFloat(const char *name, float value);
|
||||||
bool TE_SetEntDataVector(const char *name, float vector[3]);
|
bool TE_SetEntDataVector(const char *name, float vector[3]);
|
||||||
bool TE_SetEntDataFloatArray(const char *name, cell_t *array, int size);
|
bool TE_SetEntDataFloatArray(const char *name, cell_t *array, int size);
|
||||||
bool TE_GetEntData(const char *name, int *value);
|
bool TE_GetEntData(const char *name, int *value);
|
||||||
|
bool TE_GetEntDataEnt(const char *name, IHandleEntity **value);
|
||||||
bool TE_GetEntDataFloat(const char *name, float *value);
|
bool TE_GetEntDataFloat(const char *name, float *value);
|
||||||
bool TE_GetEntDataVector(const char *name, float vector[3]);
|
bool TE_GetEntDataVector(const char *name, float vector[3]);
|
||||||
void Send(IRecipientFilter &filter, float delay);
|
void Send(IRecipientFilter &filter, float delay);
|
||||||
|
@ -307,6 +307,57 @@ static cell_t smn_TEReadNum(IPluginContext *pContext, const cell_t *params)
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cell_t smn_TEWriteEnt(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
if (!g_TEManager.IsAvailable())
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
|
||||||
|
}
|
||||||
|
if (!g_CurrentTE)
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("No TempEntity call is in progress");
|
||||||
|
}
|
||||||
|
|
||||||
|
char *prop;
|
||||||
|
pContext->LocalToString(params[1], &prop);
|
||||||
|
|
||||||
|
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(params[2]);
|
||||||
|
if (!pEntity && params[2] != -1)
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Entity %d (%d) is invalid", gamehelpers->ReferenceToIndex(params[2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_CurrentTE->TE_SetEntDataEnt(prop, reinterpret_cast<IHandleEntity *>(pEntity)))
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static cell_t smn_TEReadEnt(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
if (!g_TEManager.IsAvailable())
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("TempEntity System unsupported or not available, file a bug report");
|
||||||
|
}
|
||||||
|
if (!g_CurrentTE)
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("No TempEntity call is in progress");
|
||||||
|
}
|
||||||
|
|
||||||
|
char *prop;
|
||||||
|
IHandleEntity *val;
|
||||||
|
pContext->LocalToString(params[1], &prop);
|
||||||
|
|
||||||
|
if (!g_CurrentTE->TE_GetEntDataEnt(prop, &val))
|
||||||
|
{
|
||||||
|
return pContext->ThrowNativeError("Temp entity property \"%s\" not found", prop);
|
||||||
|
}
|
||||||
|
|
||||||
|
return gamehelpers->EntityToBCompatRef(reinterpret_cast<CBaseEntity *>(val));
|
||||||
|
}
|
||||||
|
|
||||||
static cell_t smn_TE_WriteFloat(IPluginContext *pContext, const cell_t *params)
|
static cell_t smn_TE_WriteFloat(IPluginContext *pContext, const cell_t *params)
|
||||||
{
|
{
|
||||||
if (!g_TEManager.IsAvailable())
|
if (!g_TEManager.IsAvailable())
|
||||||
@ -547,6 +598,8 @@ sp_nativeinfo_t g_TENatives[] =
|
|||||||
{"TE_Start", smn_TEStart},
|
{"TE_Start", smn_TEStart},
|
||||||
{"TE_WriteNum", smn_TEWriteNum},
|
{"TE_WriteNum", smn_TEWriteNum},
|
||||||
{"TE_ReadNum", smn_TEReadNum},
|
{"TE_ReadNum", smn_TEReadNum},
|
||||||
|
{"TE_WriteEnt", smn_TEWriteEnt},
|
||||||
|
{"TE_ReadEnt", smn_TEReadEnt},
|
||||||
{"TE_WriteFloat", smn_TE_WriteFloat},
|
{"TE_WriteFloat", smn_TE_WriteFloat},
|
||||||
{"TE_ReadFloat", smn_TE_ReadFloat},
|
{"TE_ReadFloat", smn_TE_ReadFloat},
|
||||||
{"TE_WriteVector", smn_TEWriteVector},
|
{"TE_WriteVector", smn_TEWriteVector},
|
||||||
|
@ -98,6 +98,24 @@ native void TE_WriteNum(const char[] prop, int value);
|
|||||||
*/
|
*/
|
||||||
native int TE_ReadNum(const char[] prop);
|
native int TE_ReadNum(const char[] prop);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets an entity value in the current temp entity.
|
||||||
|
*
|
||||||
|
* @param prop Property to use.
|
||||||
|
* @param value Entity reference or index value to set.
|
||||||
|
* @error Property not found.
|
||||||
|
*/
|
||||||
|
native void TE_WriteEnt(const char[] prop, int value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads an entity value in the current temp entity.
|
||||||
|
*
|
||||||
|
* @param prop Property to use.
|
||||||
|
* @return Property value as backwards compatible entity reference.
|
||||||
|
* @error Property not found.
|
||||||
|
*/
|
||||||
|
native int TE_ReadEnt(const char[] prop);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a floating point number in the current temp entity.
|
* Sets a floating point number in the current temp entity.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user