2014-08-04 14:10:06 +04:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fakemeta Module
|
|
|
|
//
|
|
|
|
|
2004-08-11 09:06:27 +04:00
|
|
|
#include "fakemeta_amxx.h"
|
|
|
|
|
2013-02-13 11:14:37 +04:00
|
|
|
#if defined PAWN_CELL_SIZE
|
|
|
|
# if PAWN_CELL_SIZE == 16
|
|
|
|
# define CELL_MIN SHRT_MIN
|
|
|
|
# elif PAWN_CELL_SIZE == 32
|
|
|
|
# define CELL_MIN INT_MIN
|
|
|
|
# elif PAWN_CELL_SIZE == 64
|
|
|
|
# define CELL_MIN _I64_MIN
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# define CELL_MIN _I32_MIN
|
|
|
|
#endif
|
|
|
|
|
2006-02-12 01:56:55 +03:00
|
|
|
#if defined WIN32
|
|
|
|
#define WINDOWS_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#else
|
|
|
|
//implement these with setjmp later.
|
|
|
|
bool IsBadReadPtr(void *l, size_t size)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool IsBadWritePtr(void *l, size_t size)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-08-11 09:06:27 +04:00
|
|
|
static cell AMX_NATIVE_CALL set_pdata_int(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
int index=params[1];
|
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2004-08-11 09:06:27 +04:00
|
|
|
int iOffset=params[2];
|
2015-10-07 00:53:01 +03:00
|
|
|
CHECK_OFFSET(iOffset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
#if defined( __linux__ )
|
2004-08-11 09:06:27 +04:00
|
|
|
iOffset += params[4];
|
2013-07-02 18:05:39 +04:00
|
|
|
#elif defined( __APPLE__ )
|
2013-02-13 11:14:37 +04:00
|
|
|
// Use Linux offset in older plugins
|
|
|
|
if (params[0] / sizeof(cell) == 4)
|
|
|
|
iOffset += params[4];
|
|
|
|
else
|
|
|
|
iOffset += params[5];
|
2004-08-11 09:06:27 +04:00
|
|
|
#endif
|
|
|
|
int iValue=params[3];
|
2015-10-07 00:53:01 +03:00
|
|
|
set_pdata<int>(TypeConversion.id_to_edict(index), iOffset, iValue);
|
2004-08-11 09:06:27 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2015-10-07 00:53:01 +03:00
|
|
|
|
2004-08-11 09:06:27 +04:00
|
|
|
static cell AMX_NATIVE_CALL get_pdata_int(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
int index=params[1];
|
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2004-08-11 09:06:27 +04:00
|
|
|
int iOffset=params[2];
|
2015-10-07 00:53:01 +03:00
|
|
|
CHECK_OFFSET(iOffset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
#if defined( __linux__ )
|
2004-08-11 09:06:27 +04:00
|
|
|
iOffset += params[3];
|
2013-07-02 18:05:39 +04:00
|
|
|
#elif defined( __APPLE__ )
|
2013-02-13 11:14:37 +04:00
|
|
|
// Use Linux offset in older plugins
|
|
|
|
if (params[0] / sizeof(cell) == 3)
|
|
|
|
iOffset += params[3];
|
|
|
|
else
|
|
|
|
iOffset += params[4];
|
2004-08-11 09:06:27 +04:00
|
|
|
#endif
|
2013-02-13 11:14:37 +04:00
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
return get_pdata<int>(TypeConversion.id_to_edict(index), iOffset);
|
2004-08-11 09:06:27 +04:00
|
|
|
}
|
2015-10-07 00:53:01 +03:00
|
|
|
|
2004-08-11 09:06:27 +04:00
|
|
|
// Float
|
|
|
|
static cell AMX_NATIVE_CALL set_pdata_float(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
int index=params[1];
|
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2004-08-11 09:06:27 +04:00
|
|
|
int iOffset=params[2];
|
2013-07-02 18:05:39 +04:00
|
|
|
CHECK_OFFSET(iOffset);
|
|
|
|
|
|
|
|
#if defined( __linux__ )
|
2004-08-11 09:06:27 +04:00
|
|
|
iOffset += params[4];
|
2013-07-02 18:05:39 +04:00
|
|
|
#elif defined( __APPLE__ )
|
2013-02-13 11:14:37 +04:00
|
|
|
// Use Linux offset in older plugins
|
|
|
|
if (params[0] / sizeof(cell) == 4)
|
|
|
|
iOffset += params[4];
|
|
|
|
else
|
|
|
|
iOffset += params[5];
|
2004-08-11 09:06:27 +04:00
|
|
|
#endif
|
2013-02-13 11:14:37 +04:00
|
|
|
|
2004-08-11 09:06:27 +04:00
|
|
|
float fValue=amx_ctof(params[3]);
|
2015-10-07 00:53:01 +03:00
|
|
|
set_pdata<float>(TypeConversion.id_to_edict(index), iOffset, fValue);
|
2004-08-11 09:06:27 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
static cell AMX_NATIVE_CALL get_pdata_float(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
int index=params[1];
|
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2004-08-11 09:06:27 +04:00
|
|
|
int iOffset=params[2];
|
2015-10-07 00:53:01 +03:00
|
|
|
CHECK_OFFSET(iOffset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
#if defined( __linux__ )
|
2004-08-11 09:06:27 +04:00
|
|
|
iOffset += params[3];
|
2013-07-02 18:05:39 +04:00
|
|
|
#elif defined( __APPLE__ )
|
2013-02-13 11:14:37 +04:00
|
|
|
// Use Linux offset in older plugins
|
|
|
|
if (params[0] / sizeof(cell) == 3)
|
|
|
|
iOffset += params[3];
|
|
|
|
else
|
|
|
|
iOffset += params[4];
|
2004-08-11 09:06:27 +04:00
|
|
|
#endif
|
2013-02-13 11:14:37 +04:00
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
return amx_ftoc(get_pdata<float>(TypeConversion.id_to_edict(index), iOffset));
|
2004-08-11 09:06:27 +04:00
|
|
|
}
|
2005-08-21 20:33:38 +04:00
|
|
|
|
|
|
|
static cell AMX_NATIVE_CALL get_pdata_string(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
int index=params[1];
|
|
|
|
CHECK_ENTITY(index);
|
|
|
|
|
|
|
|
int iOffset=params[2];
|
2013-07-02 18:05:39 +04:00
|
|
|
CHECK_OFFSET(iOffset);
|
|
|
|
|
|
|
|
#if defined( __linux__ )
|
2005-08-21 20:33:38 +04:00
|
|
|
iOffset += params[6];
|
2013-07-02 18:05:39 +04:00
|
|
|
#elif defined( __APPLE__ )
|
2013-02-13 11:14:37 +04:00
|
|
|
// Use Linux offset in older plugins
|
|
|
|
if (params[0] / sizeof(cell) == 6 || params[7] == CELL_MIN)
|
|
|
|
iOffset += params[6];
|
|
|
|
else
|
|
|
|
iOffset += params[7];
|
2005-08-21 20:33:38 +04:00
|
|
|
#endif
|
2015-10-07 00:53:01 +03:00
|
|
|
edict_t *pEdict = TypeConversion.id_to_edict(index);
|
2005-08-21 20:33:38 +04:00
|
|
|
|
|
|
|
char *szData;
|
|
|
|
if (params[5])
|
|
|
|
{
|
2015-10-07 00:53:01 +03:00
|
|
|
szData = get_pdata<char*>(pEdict, iOffset);
|
2005-08-21 20:33:38 +04:00
|
|
|
} else {
|
2015-10-07 00:53:01 +03:00
|
|
|
szData = get_pdata_direct<char*>(pEdict, iOffset);
|
2005-08-21 20:33:38 +04:00
|
|
|
}
|
|
|
|
|
2006-02-12 01:56:55 +03:00
|
|
|
if (IsBadReadPtr(szData, 1))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2005-08-21 20:33:38 +04:00
|
|
|
|
2006-02-12 01:56:55 +03:00
|
|
|
MF_SetAmxString(amx, params[3], szData, params[4]);
|
|
|
|
|
|
|
|
return 1;
|
2005-08-21 20:33:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static cell AMX_NATIVE_CALL set_pdata_string(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
int index=params[1];
|
|
|
|
CHECK_ENTITY(index);
|
|
|
|
|
|
|
|
int iOffset=params[2];
|
2013-07-02 18:05:39 +04:00
|
|
|
CHECK_OFFSET(iOffset);
|
|
|
|
|
|
|
|
#if defined( __linux__ )
|
2005-08-21 20:33:38 +04:00
|
|
|
iOffset += params[5];
|
2013-07-02 18:05:39 +04:00
|
|
|
#elif defined( __APPLE__ )
|
2013-02-13 11:14:37 +04:00
|
|
|
// Use Linux offset in older plugins
|
|
|
|
if (params[0] / sizeof(cell) == 5 || params[6] == CELL_MIN)
|
|
|
|
iOffset += params[5];
|
|
|
|
else
|
|
|
|
iOffset += params[6];
|
2005-08-21 20:33:38 +04:00
|
|
|
#endif
|
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
edict_t *pEdict = TypeConversion.id_to_edict(index);
|
2005-08-21 20:33:38 +04:00
|
|
|
|
|
|
|
char *szData;
|
|
|
|
int len;
|
|
|
|
char *data = MF_GetAmxString(amx, params[3], 0, &len);
|
|
|
|
if (params[4] == -1)
|
|
|
|
{
|
2015-10-07 00:53:01 +03:00
|
|
|
szData = get_pdata_direct<char*>(pEdict, iOffset);
|
2006-02-12 01:56:55 +03:00
|
|
|
if (IsBadWritePtr(szData, 1))
|
|
|
|
return 0;
|
2005-08-21 20:33:38 +04:00
|
|
|
strcpy(szData, data);
|
|
|
|
} else {
|
2015-10-07 00:53:01 +03:00
|
|
|
szData = get_pdata<char*>(pEdict, iOffset);
|
2006-02-12 01:56:55 +03:00
|
|
|
if (IsBadWritePtr(szData, 1))
|
|
|
|
return 0;
|
2005-08-21 20:33:38 +04:00
|
|
|
if (params[4] == 1)
|
|
|
|
{
|
|
|
|
free(szData);
|
|
|
|
szData = (char *)malloc(len + 1);
|
|
|
|
} else if (params[4] == 2) {
|
|
|
|
delete [] szData;
|
|
|
|
szData = new char[len + 1];
|
|
|
|
}
|
|
|
|
strcpy(szData, data);
|
2015-10-07 00:53:01 +03:00
|
|
|
set_pdata<char*>(pEdict, iOffset, szData);
|
2005-08-21 20:33:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-10-22 23:52:06 +04:00
|
|
|
static cell AMX_NATIVE_CALL get_pdata_ent(AMX *amx, cell *params)
|
|
|
|
{
|
|
|
|
int index=params[1];
|
|
|
|
CHECK_ENTITY(index);
|
|
|
|
|
2013-07-02 18:05:39 +04:00
|
|
|
int iOffset=params[2];
|
|
|
|
CHECK_OFFSET(iOffset);
|
|
|
|
|
|
|
|
#if defined( __linux__ )
|
2007-10-22 23:52:06 +04:00
|
|
|
iOffset += params[3];
|
2013-07-02 18:05:39 +04:00
|
|
|
#elif defined( __APPLE__ )
|
2013-02-13 11:14:37 +04:00
|
|
|
// Use Linux offset in older plugins
|
|
|
|
if (params[0] / sizeof(cell) == 3)
|
|
|
|
iOffset += params[3];
|
|
|
|
else
|
|
|
|
iOffset += params[4];
|
2007-10-22 23:52:06 +04:00
|
|
|
#endif
|
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
edict_t *pEdict = get_pdata<edict_t*>(TypeConversion.id_to_edict(index), iOffset);
|
2007-10-22 23:52:06 +04:00
|
|
|
|
|
|
|
if (pEdict == NULL)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
edict_t *pWorld = INDEXENT(0);
|
|
|
|
int ent = pEdict - pWorld;
|
|
|
|
|
|
|
|
if (ent < 0 || ent > gpGlobals->maxEntities)
|
|
|
|
{
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pEdict->free || pEdict->pvPrivateData == NULL)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ent;
|
|
|
|
}
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
static cell AMX_NATIVE_CALL set_pdata_ent(AMX *amx, cell *params)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
int index = params[1];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
int offset = params[2];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_OFFSET(offset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
int entity = params[3];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_ENTITY(entity);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
#if defined(__linux__)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
2013-07-03 01:31:27 +04:00
|
|
|
#elif defined(__APPLE__)
|
2013-07-02 18:05:39 +04:00
|
|
|
// Use Linux offset in older plugins
|
2013-07-03 01:31:27 +04:00
|
|
|
if (params[0] / sizeof(cell) == 4)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
|
|
|
else
|
|
|
|
offset += params[5];
|
|
|
|
#endif
|
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
set_pdata<edict_t*>(TypeConversion.id_to_edict(index), offset, TypeConversion.id_to_edict(entity));
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
static cell AMX_NATIVE_CALL get_pdata_bool(AMX *amx, cell *params)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
int index = params[1];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
int offset = params[2];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_OFFSET(offset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
#if defined(__linux__)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[3];
|
2013-07-03 01:31:27 +04:00
|
|
|
#elif defined(__APPLE__)
|
2013-07-02 18:05:39 +04:00
|
|
|
// Use Linux offset in older plugins
|
2013-07-03 01:31:27 +04:00
|
|
|
if (params[0] / sizeof(cell) == 3)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[3];
|
|
|
|
else
|
|
|
|
offset += params[4];
|
|
|
|
#endif
|
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
return get_pdata<bool>(TypeConversion.id_to_edict(index), offset) ? TRUE : FALSE;
|
2013-07-02 18:05:39 +04:00
|
|
|
}
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
static cell AMX_NATIVE_CALL set_pdata_bool(AMX *amx, cell *params)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
int index = params[1];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
int offset = params[2];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_OFFSET(offset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
bool value = params[3] ? true : false;
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
#if defined(__linux__)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
2013-07-03 01:31:27 +04:00
|
|
|
#elif defined(__APPLE__)
|
2013-07-02 18:05:39 +04:00
|
|
|
// Use Linux offset in older plugins
|
2013-07-03 01:31:27 +04:00
|
|
|
if (params[0] / sizeof(cell) == 4)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
|
|
|
else
|
|
|
|
offset += params[5];
|
|
|
|
#endif
|
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
set_pdata<bool>(TypeConversion.id_to_edict(index), offset, value);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
static cell AMX_NATIVE_CALL get_pdata_byte(AMX *amx, cell *params)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
int index = params[1];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
int offset = params[2];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_OFFSET(offset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
#if defined(__linux__)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[3];
|
2013-07-03 01:31:27 +04:00
|
|
|
#elif defined(__APPLE__)
|
2013-07-02 18:05:39 +04:00
|
|
|
// Use Linux offset in older plugins
|
2013-07-03 01:31:27 +04:00
|
|
|
if (params[0] / sizeof(cell) == 3)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[3];
|
|
|
|
else
|
|
|
|
offset += params[4];
|
|
|
|
#endif
|
2015-10-07 00:53:01 +03:00
|
|
|
|
|
|
|
return static_cast<cell>(get_pdata<byte>(TypeConversion.id_to_edict(index), offset));
|
2013-07-02 18:05:39 +04:00
|
|
|
}
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
static cell AMX_NATIVE_CALL set_pdata_byte(AMX *amx, cell *params)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
int index = params[1];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
int offset = params[2];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_OFFSET(offset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
byte value = static_cast<byte>(params[3]);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
#if defined(__linux__)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
2013-07-03 01:31:27 +04:00
|
|
|
#elif defined(__APPLE__)
|
2013-07-02 18:05:39 +04:00
|
|
|
// Use Linux offset in older plugins
|
2013-07-03 01:31:27 +04:00
|
|
|
if (params[0] / sizeof(cell) == 4)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
|
|
|
else
|
|
|
|
offset += params[5];
|
|
|
|
#endif
|
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
set_pdata<byte>(TypeConversion.id_to_edict(index), offset, value);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
static cell AMX_NATIVE_CALL get_pdata_short(AMX *amx, cell *params)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
int index = params[1];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
int offset = params[2];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_OFFSET(offset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
#if defined(__linux__)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[3];
|
2013-07-03 01:31:27 +04:00
|
|
|
#elif defined(__APPLE__)
|
2013-07-02 18:05:39 +04:00
|
|
|
// Use Linux offset in older plugins
|
2013-07-03 01:31:27 +04:00
|
|
|
if (params[0] / sizeof(cell) == 3)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[3];
|
|
|
|
else
|
|
|
|
offset += params[4];
|
|
|
|
#endif
|
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
return static_cast<cell>(get_pdata<short>(TypeConversion.id_to_edict(index), offset));
|
2013-07-02 18:05:39 +04:00
|
|
|
}
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
static cell AMX_NATIVE_CALL set_pdata_short(AMX *amx, cell *params)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
int index = params[1];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
int offset = params[2];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_OFFSET(offset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
short value = static_cast<short>(params[3]);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
#if defined(__linux__)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
2013-07-03 01:31:27 +04:00
|
|
|
#elif defined(__APPLE__)
|
2013-07-02 18:05:39 +04:00
|
|
|
// Use Linux offset in older plugins
|
2013-07-03 01:31:27 +04:00
|
|
|
if (params[0] / sizeof(cell) == 4)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
|
|
|
else
|
|
|
|
offset += params[5];
|
|
|
|
#endif
|
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
set_pdata<short>(TypeConversion.id_to_edict(index), offset, value);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
static cell AMX_NATIVE_CALL get_pdata_vector(AMX *amx, cell *params)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
int index = params[1];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
int offset = params[2];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_OFFSET(offset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
#if defined(__linux__)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
2013-07-03 01:31:27 +04:00
|
|
|
#elif defined(__APPLE__)
|
2013-07-02 18:05:39 +04:00
|
|
|
// Use Linux offset in older plugins
|
2013-07-03 01:31:27 +04:00
|
|
|
if (params[0] / sizeof(cell) == 4)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
|
|
|
else
|
|
|
|
offset += params[5];
|
|
|
|
#endif
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
cell *cpvec = MF_GetAmxAddr(amx, params[3]);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
Vector vec = get_pdata<Vector>(TypeConversion.id_to_edict(index), offset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
cpvec[0] = amx_ftoc(vec.x);
|
|
|
|
cpvec[1] = amx_ftoc(vec.y);
|
|
|
|
cpvec[2] = amx_ftoc(vec.z);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
static cell AMX_NATIVE_CALL set_pdata_vector(AMX *amx, cell *params)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
int index = params[1];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
int offset = params[2];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_OFFSET(offset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
#if defined(__linux__)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
2013-07-03 01:31:27 +04:00
|
|
|
#elif defined(__APPLE__)
|
2013-07-02 18:05:39 +04:00
|
|
|
// Use Linux offset in older plugins
|
2013-07-03 01:31:27 +04:00
|
|
|
if (params[0] / sizeof(cell) == 4)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
|
|
|
else
|
|
|
|
offset += params[5];
|
|
|
|
#endif
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
cell *pcvec = MF_GetAmxAddr(amx, params[3]);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
Vector vec(amx_ctof(pcvec[0]), amx_ctof(pcvec[1]), amx_ctof(pcvec[2]));
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
set_pdata<Vector>(TypeConversion.id_to_edict(index), offset, vec);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
static cell AMX_NATIVE_CALL get_pdata_ehandle(AMX *amx, cell *params)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
int index = params[1];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
int offset = params[2];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_OFFSET(offset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
#if defined(__linux__)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[3];
|
2013-07-03 01:31:27 +04:00
|
|
|
#elif defined(__APPLE__)
|
2013-07-02 18:05:39 +04:00
|
|
|
// Use Linux offset in older plugins
|
2013-07-03 01:31:27 +04:00
|
|
|
if (params[0] / sizeof(cell) == 3)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[3];
|
|
|
|
else
|
|
|
|
offset += params[4];
|
|
|
|
#endif
|
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
edict_t *pEdict = get_pdata<edict_t*>(TypeConversion.id_to_edict(index), offset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
if (pEdict == NULL)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
edict_t *pWorld = INDEXENT(0);
|
2013-07-02 18:05:39 +04:00
|
|
|
int ent = pEdict - pWorld;
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
if (ent < 0 || ent > gpGlobals->maxEntities)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
if (pEdict->free || pEdict->pvPrivateData == NULL)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
int serialnumber = get_pdata<int>(TypeConversion.id_to_edict(index), offset + 4);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
if (pEdict->serialnumber != serialnumber)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ent;
|
|
|
|
}
|
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
static cell AMX_NATIVE_CALL set_pdata_ehandle(AMX *amx, cell *params)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
|
|
|
int index = params[1];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_ENTITY(index);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
int offset = params[2];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_OFFSET(offset);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
|
|
|
int entity = params[3];
|
2013-07-03 01:31:27 +04:00
|
|
|
CHECK_ENTITY(entity);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
#if defined(__linux__)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
2013-07-03 01:31:27 +04:00
|
|
|
#elif defined(__APPLE__)
|
2013-07-02 18:05:39 +04:00
|
|
|
// Use Linux offset in older plugins
|
2013-07-03 01:31:27 +04:00
|
|
|
if (params[0] / sizeof(cell) == 4)
|
2013-07-02 18:05:39 +04:00
|
|
|
offset += params[4];
|
|
|
|
else
|
|
|
|
offset += params[5];
|
|
|
|
#endif
|
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
edict_t *pEntity = TypeConversion.id_to_edict(entity);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2015-10-07 00:53:01 +03:00
|
|
|
set_pdata<edict_t*>(TypeConversion.id_to_edict(index), offset, pEntity);
|
2013-07-02 18:05:39 +04:00
|
|
|
|
2013-07-03 01:31:27 +04:00
|
|
|
if (pEntity)
|
2013-07-02 18:05:39 +04:00
|
|
|
{
|
2015-10-07 00:53:01 +03:00
|
|
|
set_pdata<int>(TypeConversion.id_to_edict(index), offset + 4, pEntity->serialnumber);
|
2013-07-02 18:05:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-10-22 23:52:06 +04:00
|
|
|
AMX_NATIVE_INFO pdata_natives[] =
|
|
|
|
{
|
2004-08-11 09:06:27 +04:00
|
|
|
{ "get_pdata_int", get_pdata_int },
|
|
|
|
{ "set_pdata_int", set_pdata_int },
|
|
|
|
{ "get_pdata_float", get_pdata_float },
|
|
|
|
{ "set_pdata_float", set_pdata_float },
|
2005-08-21 20:33:38 +04:00
|
|
|
{ "set_pdata_string", set_pdata_string },
|
|
|
|
{ "get_pdata_string", get_pdata_string },
|
2007-10-22 23:52:06 +04:00
|
|
|
{ "get_pdata_ent", get_pdata_ent },
|
2013-07-02 18:05:39 +04:00
|
|
|
{ "set_pdata_ent", set_pdata_ent },
|
|
|
|
{ "get_pdata_bool", get_pdata_bool },
|
|
|
|
{ "set_pdata_bool", set_pdata_bool },
|
|
|
|
{ "get_pdata_byte", get_pdata_byte },
|
|
|
|
{ "set_pdata_byte", set_pdata_byte },
|
|
|
|
{ "get_pdata_short", get_pdata_short },
|
|
|
|
{ "set_pdata_short", set_pdata_short },
|
|
|
|
{ "get_pdata_vector", get_pdata_vector },
|
|
|
|
{ "set_pdata_vector", set_pdata_vector },
|
|
|
|
{ "get_pdata_ehandle", get_pdata_ehandle },
|
|
|
|
{ "set_pdata_ehandle", set_pdata_ehandle },
|
2004-08-11 09:06:27 +04:00
|
|
|
{ NULL, NULL }
|
2004-09-12 04:13:46 +04:00
|
|
|
};
|