amxmodx/modules/hamsandwich/ham_utils.h

77 lines
2.4 KiB
C
Raw Normal View History

// 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
//
#ifndef HAM_UTILS_H
#define HAM_UTILS_H
#include "amxxmodule.h"
#include "offsets.h"
#include <HLTypeConversion.h>
extern HLTypeConversion TypeConversion;
#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); \
Update Hamsandwich for Sven Coop 5.17 (#452) * Remove dropped functions * Update existing offsets * Add some logic to prevent the use of removed functions. * Add Ham_SC_AddPoints and Ham_SC_AddPointsToTeam * Add Ham_SC_GiveAmmo * Add Ham_SC_FVisibleFromPos * Fix an old typos with CanPlaySentence for all mods * Add Ham_SC_CanPlaySequence * Add Ham_SC_PlayScriptSentence * Add Ham_SC_StartPlayerFollowing * Fix CanPlaySequence hamdata.ini (SC) * Add Ham_SC_StopPlayerFollowing * Fix handlers from previous commits * Add Ham_SC_PreSpawn * Add Ham_SC_PostSpawn * Add Ham_SC_OnKeyValueUpdate * Add Ham_SC_SetClassification * Add Ham_SC_MyCustomPointer and Ham_SC_MyItemPointer * Add Ham_SC_IsSneaking * Add Ham_SC_IsAlive * Add Ham_SC_IsBSPModel * Add Ham_SC_ReflectGauss * Add Ham_SC_HasTarget * Add Ham_SC_IsInWorld * Add Ham_SC_IsPlayer * Add Ham_SC_IsNetClient * Add Ham_SC_IsBreakable * Fix Ham_SC_IsMonster, Ham_SC_IsPointEntity, Ham_SC_IsMachine and Ham_SC_CriticakRemove handlers * Add Ham_SC_OnControls * Fix Ham_SC_TakeHealth and Ham_SC_TakeArmor handlers * Add Ham_SC_IsTriggered * Add Ham_SC_RemovePlayerItem * Fix typo * Fix Ham_SC_IsMoving handler * Add Ham_SC_SUB_UseTargets * Ham_SC_IsLockedByMaster * Add Ham_SC_FBecomeProne * Fix Ham_SC_FVisible handler * Add Ham_SC_FVecVisible * Fix Ham_SC_FVisibleFromPos handler * Fix Ham_SC_IsFacing handler * Add Ham_SC_SetPlayerAlly * Add Ham_SC_OnSetOriginByMap * Add Ham_SC_IsRevivable * Add Ham_SC_BeginRevive and Ham_SC_EndRevive * Update offsets based on SvenCoop v5.17 * Add Ham_SC_Item_CanCollect and Ham_SC_Item_Collect * Add Ham_SC_Item_AddToPlayer * Add Ham_SC_Item_AddDuplicate * Add Ham_SC_Item_AddAmmoFromItem * Add Ham_SC_Item_GetItemInfo * Add Ham_SC_Item_CanDeploy, Ham_SC_Item_Deploy and Ham_SC_Item_CanHolster * Add Ham_SC_Item_UpdateClientData * Add Ham_SC_Item_GetRespawnTime * Add Ham_SC_Item_CanHaveDuplicates * Add Ham_SC_Weapon_ExtractAmmoFromItem * Add Ham_SC_Weapon_GetAmmo1Drop and Ham_SC_Weapon_GetAmmo2Drop * Add Ham_SC_Weapon_FinishReload and Ham_SC_Weapon_ShouldReload * Fix Ham_SC_IsMultiplayer, Ham_SC_FRunfuncs and Ham_SC_FCanRun handlers * Add Ham_SC_Weapon_AddWeapon, _PlayEmptySound, _IsUsable, _ShouldWeaponIdle and _UseDecrement * Add Ham_SC_Item_GetPickupSound * Add Ham_SC_Item_InactiveItemPreFrame and Ham_SC_Item_InactiveItemPostFrame * Add Ham_SC_Item_DetachFromPlayer * Fix Ham_SC_Player_IsConnected handler * Add Ham_SC_Player_EnteredObserver, Ham_SC_Player_LeftObserver and Ham_SC_Player_IsObserver * Fix sc_postpawn typo (should be sc_postspawn) * Add few more assert
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); \
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); \
FailPlugin(amx, x, HAM_FUNC_NOT_CONFIGURED, msg); \
return 0; \
}
Update Hamsandwich for Sven Coop 5.17 (#452) * Remove dropped functions * Update existing offsets * Add some logic to prevent the use of removed functions. * Add Ham_SC_AddPoints and Ham_SC_AddPointsToTeam * Add Ham_SC_GiveAmmo * Add Ham_SC_FVisibleFromPos * Fix an old typos with CanPlaySentence for all mods * Add Ham_SC_CanPlaySequence * Add Ham_SC_PlayScriptSentence * Add Ham_SC_StartPlayerFollowing * Fix CanPlaySequence hamdata.ini (SC) * Add Ham_SC_StopPlayerFollowing * Fix handlers from previous commits * Add Ham_SC_PreSpawn * Add Ham_SC_PostSpawn * Add Ham_SC_OnKeyValueUpdate * Add Ham_SC_SetClassification * Add Ham_SC_MyCustomPointer and Ham_SC_MyItemPointer * Add Ham_SC_IsSneaking * Add Ham_SC_IsAlive * Add Ham_SC_IsBSPModel * Add Ham_SC_ReflectGauss * Add Ham_SC_HasTarget * Add Ham_SC_IsInWorld * Add Ham_SC_IsPlayer * Add Ham_SC_IsNetClient * Add Ham_SC_IsBreakable * Fix Ham_SC_IsMonster, Ham_SC_IsPointEntity, Ham_SC_IsMachine and Ham_SC_CriticakRemove handlers * Add Ham_SC_OnControls * Fix Ham_SC_TakeHealth and Ham_SC_TakeArmor handlers * Add Ham_SC_IsTriggered * Add Ham_SC_RemovePlayerItem * Fix typo * Fix Ham_SC_IsMoving handler * Add Ham_SC_SUB_UseTargets * Ham_SC_IsLockedByMaster * Add Ham_SC_FBecomeProne * Fix Ham_SC_FVisible handler * Add Ham_SC_FVecVisible * Fix Ham_SC_FVisibleFromPos handler * Fix Ham_SC_IsFacing handler * Add Ham_SC_SetPlayerAlly * Add Ham_SC_OnSetOriginByMap * Add Ham_SC_IsRevivable * Add Ham_SC_BeginRevive and Ham_SC_EndRevive * Update offsets based on SvenCoop v5.17 * Add Ham_SC_Item_CanCollect and Ham_SC_Item_Collect * Add Ham_SC_Item_AddToPlayer * Add Ham_SC_Item_AddDuplicate * Add Ham_SC_Item_AddAmmoFromItem * Add Ham_SC_Item_GetItemInfo * Add Ham_SC_Item_CanDeploy, Ham_SC_Item_Deploy and Ham_SC_Item_CanHolster * Add Ham_SC_Item_UpdateClientData * Add Ham_SC_Item_GetRespawnTime * Add Ham_SC_Item_CanHaveDuplicates * Add Ham_SC_Weapon_ExtractAmmoFromItem * Add Ham_SC_Weapon_GetAmmo1Drop and Ham_SC_Weapon_GetAmmo2Drop * Add Ham_SC_Weapon_FinishReload and Ham_SC_Weapon_ShouldReload * Fix Ham_SC_IsMultiplayer, Ham_SC_FRunfuncs and Ham_SC_FCanRun handlers * Add Ham_SC_Weapon_AddWeapon, _PlayEmptySound, _IsUsable, _ShouldWeaponIdle and _UseDecrement * Add Ham_SC_Item_GetPickupSound * Add Ham_SC_Item_InactiveItemPreFrame and Ham_SC_Item_InactiveItemPostFrame * Add Ham_SC_Item_DetachFromPlayer * Fix Ham_SC_Player_IsConnected handler * Add Ham_SC_Player_EnteredObserver, Ham_SC_Player_LeftObserver and Ham_SC_Player_IsObserver * Fix sc_postpawn typo (should be sc_postspawn) * Add few more assert
2018-09-06 15:09:10 +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 { \
if (TypeConversion.id_to_edict(x)->free) { \
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid entity (%d)", x); \
return 0; \
} else if (TypeConversion.id_to_edict(x)->pvPrivateData == NULL) { \
MF_LogError(amx, AMX_ERR_NATIVE, "Entity has null private data (%d)", x); \
return 0; \
} \
}
inline void **EdictToVTable(edict_t *ent)
{
char *btbl = (char *)ent->pvPrivateData;
btbl += Offsets.GetBase();
return *((void ***)btbl);
};
inline void **GetVTable(void *pthis, int size)
{
return *((void***)(((char*)pthis) + size));
}
inline void *GetVTableEntry(void *pthis, int ventry, int size)
{
void **vtbl = GetVTable(pthis, size);
return vtbl[ventry];
}
#endif