2014-08-04 10:21:40 +00: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
|
|
|
|
|
|
|
|
//
|
|
|
|
// Ham Sandwich Module
|
|
|
|
//
|
2014-04-09 14:35:46 +00:00
|
|
|
|
|
|
|
#ifndef HAM_UTILS_H
|
|
|
|
#define HAM_UTILS_H
|
|
|
|
|
|
|
|
#include "amxxmodule.h"
|
|
|
|
#include "offsets.h"
|
2015-10-07 15:31:28 +00:00
|
|
|
#include <HLTypeConversion.h>
|
|
|
|
|
|
|
|
extern HLTypeConversion TypeConversion;
|
2014-04-09 14:35:46 +00:00
|
|
|
|
|
|
|
#define CHECK_FUNCTION(x) \
|
|
|
|
if (x < 0 || x >= HAM_LAST_ENTRY_DONT_USE_ME_LOL) { \
|
|
|
|
char msg[1024]; \
|
2015-10-05 17:06:38 +00:00
|
|
|
ke::SafeSprintf(msg, sizeof(msg), "Function out of bounds. Got: %d Max: %d", x, HAM_LAST_ENTRY_DONT_USE_ME_LOL - 1); \
|
2018-09-06 15:09:10 +00:00
|
|
|
FailPlugin(amx, x, HAM_INVALID_FUNC, msg); \
|
|
|
|
return 0; \
|
|
|
|
} else if (hooklist[x].isremoved) { \
|
|
|
|
char msg[1024]; \
|
|
|
|
ke::SafeSprintf(msg, sizeof(msg), "Function %s is no more available in the mod.", hooklist[x].name); \
|
|
|
|
FailPlugin(amx, x, HAM_FUNC_NOT_AVAILABLE, msg); \
|
2014-04-09 14:35:46 +00:00
|
|
|
return 0; \
|
|
|
|
} else if (hooklist[x].isset == 0) { \
|
|
|
|
char msg[1024]; \
|
2015-10-05 17:06:38 +00:00
|
|
|
ke::SafeSprintf(msg, sizeof(msg), "Function %s is not configured in hamdata.ini.", hooklist[x].name); \
|
2014-04-09 14:35:46 +00:00
|
|
|
FailPlugin(amx, x, HAM_FUNC_NOT_CONFIGURED, msg); \
|
|
|
|
return 0; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-06 15:09:10 +00:00
|
|
|
|
|
|
|
|
2014-04-09 14:35:46 +00:00
|
|
|
#define CHECK_ENTITY(x) \
|
|
|
|
if (x < 0 || x > gpGlobals->maxEntities) { \
|
|
|
|
MF_LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", x); \
|
|
|
|
return 0; \
|
|
|
|
} else { \
|
2015-10-07 15:31:28 +00:00
|
|
|
if (TypeConversion.id_to_edict(x)->free) { \
|
2014-04-09 14:35:46 +00:00
|
|
|
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity (%d)", x); \
|
|
|
|
return 0; \
|
2015-10-07 15:31:28 +00:00
|
|
|
} else if (TypeConversion.id_to_edict(x)->pvPrivateData == NULL) { \
|
2014-04-09 14:35:46 +00:00
|
|
|
MF_LogError(amx, AMX_ERR_NATIVE, "Entity has null private data (%d)", x); \
|
|
|
|
return 0; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void **EdictToVTable(edict_t *ent)
|
|
|
|
{
|
2015-10-07 15:31:28 +00:00
|
|
|
char *btbl = (char *)ent->pvPrivateData;
|
|
|
|
btbl += Offsets.GetBase();
|
2014-04-09 14:35:46 +00:00
|
|
|
return *((void ***)btbl);
|
|
|
|
};
|
|
|
|
|
|
|
|
inline void **GetVTable(void *pthis, int size)
|
|
|
|
{
|
2015-10-07 15:31:28 +00:00
|
|
|
return *((void***)(((char*)pthis) + size));
|
2014-04-09 14:35:46 +00:00
|
|
|
}
|
|
|
|
inline void *GetVTableEntry(void *pthis, int ventry, int size)
|
|
|
|
{
|
2015-10-07 15:31:28 +00:00
|
|
|
void **vtbl = GetVTable(pthis, size);
|
2014-04-09 14:35:46 +00:00
|
|
|
|
|
|
|
return vtbl[ventry];
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|