From b660df8df65350c12f76b6d53e5235d83f34b277 Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Sun, 13 May 2007 14:01:13 +0000 Subject: [PATCH] Added {get,set}_pdata_cbase{_safe} - compliments Fakemeta's get_pdata functions, but this will set/get an offset that is a CBaseEntity. Split constants from hamsandwich.inc into ham_const.inc. Finished commenting native calls, need to finish the constant comments. --- dlls/hamsandwich/pdata.cpp | 116 +++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 dlls/hamsandwich/pdata.cpp diff --git a/dlls/hamsandwich/pdata.cpp b/dlls/hamsandwich/pdata.cpp new file mode 100644 index 00000000..b0911d6a --- /dev/null +++ b/dlls/hamsandwich/pdata.cpp @@ -0,0 +1,116 @@ +#include "sdk/amxxmodule.h" +#include "offsets.h" +#include "NEW_Util.h" +#include "ham_utils.h" + +#define FM_CHECK_ENTITY(x) \ + if (x < 0 || x > gpGlobals->maxEntities) { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", x); \ + return 0; \ + } else { \ + if (x <= gpGlobals->maxClients) { \ + if (!MF_IsPlayerIngame(x)) { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not in-game)", x); \ + return 0; \ + } \ + } else { \ + if (x != 0 && FNullEnt(INDEXENT(x))) { \ + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d", x); \ + return 0; \ + } \ + } \ + } + +// Return -1 on null, -2 on invalid, and the the index of any other. +static cell AMX_NATIVE_CALL get_pdata_cbase_safe(AMX *amx, cell *params) +{ + int index=params[1]; + FM_CHECK_ENTITY(index); + int iOffset=params[2]; +#ifdef __linux__ + iOffset += params[3]; +#endif + if (iOffset <0) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid offset provided. (got: %d)", iOffset); + return 0; + } + void *ptr=*((void **)((int *)INDEXENT_NEW(index)->pvPrivateData + iOffset)); + + if (ptr == 0) + { + return -1; + } + + for (int i=0; imaxEntities; ++i) + { + if (ptr == INDEXENT_NEW(i)->pvPrivateData) + { + return i; + } + } + + return -2; +} +static cell AMX_NATIVE_CALL get_pdata_cbase(AMX *amx, cell *params) +{ + int index=params[1]; + FM_CHECK_ENTITY(index); + int iOffset=params[2]; +#ifdef __linux__ + iOffset += params[3]; +#endif + if (iOffset <0) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid offset provided. (got: %d)", iOffset); + return 0; + } + void *ptr=*((void **)((int *)INDEXENT_NEW(index)->pvPrivateData + iOffset)); + + return PrivateToIndex(ptr); +} +static cell AMX_NATIVE_CALL set_pdata_cbase(AMX *amx, cell *params) +{ + int index=params[1]; + FM_CHECK_ENTITY(index); + int target=params[3]; + + if (target != -1) + { + FM_CHECK_ENTITY(target); + } + int iOffset=params[2]; +#ifdef __linux__ + iOffset += params[4]; +#endif + if (iOffset <0) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid offset provided. (got: %d)", iOffset); + return 0; + } + + if (target == -1) + { + *((void **)((int *)INDEXENT_NEW(index)->pvPrivateData + iOffset)) = NULL; + } + else + { + *((void **)((int *)INDEXENT_NEW(index)->pvPrivateData + iOffset)) = INDEXENT_NEW(target)->pvPrivateData; + } + + return 1; +} + +AMX_NATIVE_INFO pdata_natives_safe[] = +{ + { "get_pdata_cbase_safe", get_pdata_cbase_safe }, + + { NULL, NULL } +}; +AMX_NATIVE_INFO pdata_natives[] = +{ + { "get_pdata_cbase", get_pdata_cbase }, + { "set_pdata_cbase", set_pdata_cbase }, + + { NULL, NULL } +};