From 8fa52b02951e8267d0bf1baf51c1a2c4ef75492a Mon Sep 17 00:00:00 2001 From: s1lentq Date: Thu, 11 Jan 2024 23:31:58 +0700 Subject: [PATCH 1/8] rg_find_ent_by_owner: Change behavior (always start search from next entity) --- .../scripting/include/reapi_gamedll.inc | 12 +++--- reapi/src/natives/natives_misc.cpp | 38 ++++++++++--------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index a91bd509..060f36f0 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -443,12 +443,12 @@ native rg_find_ent_by_class(start_index, const classname[], const bool:useHashTa /* * Finds an entity in the world using Counter-Strike's custom FindEntityByString wrapper, matching by owner. * -* @param start_index Entity index to start searching from. -1 to start from the first entity +* @param start_index Entity index to start searching from. AMX_NULLENT (-1) to start from the first entity * @param classname Classname to search for * -* @return 1 if found, 0 otherwise +* @return true if found, false otherwise */ -native rg_find_ent_by_owner(&start_index, const classname[], owner); +native bool:rg_find_ent_by_owner(&start_index, const classname[], owner); /* * Finds the weapon by name in the player's inventory. @@ -1077,7 +1077,7 @@ native rg_emit_texture_sound(const ptr, Float:vecSrc[3], Float:vecEnd[3], Bullet * @note To see a visual effect, WeaponList message should be sent using the custom ammo name, * where ammo icon HUD will be the one listed in "sprites/weapon_.txt" file. * -* @param szAmmoname Ammo name to create. +* @param szAmmoname Ammo name to create. * * @note Maximum ammo index is 31, after that every ammo instantiation will start from 1 overriding existing ones. * @return New ammo index. If name already exists, will return the matched index from memory. @@ -1091,7 +1091,7 @@ native rg_add_ammo_registry(const szAmmoname[]); * @param szViewModel Weapon view model name ("models/v_*.mdl") * @param szWeaponModel Weapon world model bame ("models/p_*.mdl") * @param iAnim Weapon view model animation to play (often "deploy", use HLMV to see anim index) -* @param szAnimExt Player anim extension name to assign. Examples: "carbine", "shotgun", "knife", etc. +* @param szAnimExt Player anim extension name to assign. Examples: "carbine", "shotgun", "knife", etc. * Use HLMV on a player model to see animext names. * @param skiplocal If 0, weapon animation will be forced to play on client ignoring active client prediction. * @@ -1175,7 +1175,7 @@ native rg_switch_best_weapon(const player, const currentWeapon = 0); native rg_disappear(const player); /* -* Sets player current Observer mode. +* Sets player current Observer mode. * @note Player must be a valid observer (m_afPhysicsFlags & PFLAG_OBSERVER). * * @param player Player index. diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 4aa53b4d..ccd9d0bc 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -613,12 +613,12 @@ cell AMX_NATIVE_CALL rg_find_ent_by_class(AMX *amx, cell *params) /* * Finds an entity in the world using Counter-Strike's custom FindEntityByString wrapper, matching by owner. * -* @param start_index Entity index to start searching from. -1 to start from the first entity +* @param start_index Entity index to start searching from. AMX_NULLENT (-1) to start from the first entity * @param classname Classname to search for * -* @return 1 if found, 0 otherwise +* @return true if found, false otherwise * -* native rg_find_ent_by_owner(&start_index, const classname[], owner); +* native bool:rg_find_ent_by_owner(&start_index, const classname[], owner); */ cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params) { @@ -629,12 +629,14 @@ cell AMX_NATIVE_CALL rg_find_ent_by_owner(AMX *amx, cell *params) char classname[256]; cell& startIndex = *getAmxAddr(amx, params[arg_start_index]); + startIndex = clamp(startIndex, AMX_NULLENT, gpGlobals->maxEntities - 1); + const char* value = getAmxString(amx, params[arg_classname], classname); edict_t* pOwner = edictByIndexAmx(params[arg_onwer]); - edict_t* pEntity = g_pEdicts + startIndex; - for (int i = startIndex; i < gpGlobals->maxEntities; i++, pEntity++) + for (int i = startIndex + 1; i < gpGlobals->maxEntities; i++) { + edict_t *pEntity = edictByIndex(i); if (pEntity->v.owner != pOwner) continue; @@ -2637,11 +2639,11 @@ cell AMX_NATIVE_CALL rg_spawn_grenade(AMX* amx, cell* params) CAmxArgs args(amx, params); CGrenade *pBomb = g_ReGameFuncs->SpawnGrenade(args[arg_weapon_id], - pPlayer->pev, - args[arg_origin], - args[arg_velocity], - args[arg_time], - args[arg_team], + pPlayer->pev, + args[arg_origin], + args[arg_velocity], + args[arg_time], + args[arg_team], args[arg_event]); // Sanity check anyway @@ -2677,7 +2679,7 @@ cell AMX_NATIVE_CALL rg_create_weaponbox(AMX* amx, cell* params) AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid or uninitialized entity", __FUNCTION__); return FALSE; } - + CBasePlayer *pPlayer = nullptr; if (params[arg_player] != 0) @@ -2771,7 +2773,7 @@ cell AMX_NATIVE_CALL rg_emit_texture_sound(AMX* amx, cell* params) * @note To see a visual effect, WeaponList message should be sent using the custom ammo name, * where ammo icon HUD will be the one listed in "sprites/weapon_.txt" file. * -* @param szAmmoname Ammo name to create. +* @param szAmmoname Ammo name to create. * * @note Maximum ammo index is 31, after that every ammo instantiation will start from 1 overriding existing ones. * @return New ammo index. If name already exists, will return the matched index from memory. @@ -2799,7 +2801,7 @@ cell AMX_NATIVE_CALL rg_add_ammo_registry(AMX* amx, cell* params) * @param szViewModel Weapon view model name ("models/v_*.mdl") * @param szWeaponModel Weapon world model bame ("models/p_*.mdl") * @param iAnim Weapon view model animation to play (often "deploy", use HLMV to see anim index) -* @param szAnimExt Player anim extension name to assign. Examples: "carbine", "shotgun", "knife", etc. +* @param szAnimExt Player anim extension name to assign. Examples: "carbine", "shotgun", "knife", etc. * Use HLMV on a player model to see animext names. * @param skiplocal If 0, weapon animation will be forced to play on client ignoring active client prediction. * @@ -2871,7 +2873,7 @@ cell AMX_NATIVE_CALL rg_weapon_reload(AMX* amx, cell* params) } else { - CHECK_ISENTITY(arg_weapon); + CHECK_ISENTITY(arg_weapon); pWeapon = getPrivate(params[arg_weapon]); } @@ -2941,7 +2943,7 @@ cell AMX_NATIVE_CALL rg_weapon_shotgun_reload(AMX* amx, cell* params) } else { - CHECK_ISENTITY(arg_weapon); + CHECK_ISENTITY(arg_weapon); pWeapon = getPrivate(params[arg_weapon]); } @@ -3005,7 +3007,7 @@ cell AMX_NATIVE_CALL rg_weapon_send_animation(AMX* amx, cell* params) } else { - CHECK_ISENTITY(arg_weapon); + CHECK_ISENTITY(arg_weapon); pWeapon = getPrivate(params[arg_weapon]); } @@ -3071,7 +3073,7 @@ cell AMX_NATIVE_CALL rg_weapon_kickback(AMX* amx, cell* params) } else { - CHECK_ISENTITY(arg_weapon); + CHECK_ISENTITY(arg_weapon); pWeapon = getPrivate(params[arg_weapon]); } @@ -3175,7 +3177,7 @@ cell AMX_NATIVE_CALL rg_disappear(AMX* amx, cell* params) } /* -* Sets player current Observer mode. +* Sets player current Observer mode. * @note Player must be a valid observer (m_afPhysicsFlags & PFLAG_OBSERVER). * * @param player Player index. From 9bbebe1741af18aaeef94d83736d592b00e2f1b7 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Tue, 23 Jan 2024 11:42:25 +0700 Subject: [PATCH 2/8] PM_LadderMove: Fixed wrong pass player index --- reapi/src/hook_callback.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index 518a74e0..b1d68030 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -1460,7 +1460,7 @@ void PM_LadderMove_AMXX(IReGameHook_PM_LadderMove *chain, physent_t *pLadder, in void PM_LadderMove(IReGameHook_PM_LadderMove *chain, physent_t *pLadder) { - PM_LadderMove_AMXX(chain, pLadder, pLadder->player + 1); + PM_LadderMove_AMXX(chain, pLadder, g_pMove->player_index + 1); } void PM_WaterJump_AMXX(IReGameHook_PM_WaterJump *chain, int playerIndex) From 16afeded608beab2034cd5b53f03850798c6ce3d Mon Sep 17 00:00:00 2001 From: s1lentq Date: Sat, 27 Jan 2024 20:56:17 +0700 Subject: [PATCH 3/8] Add new native CheckVisibilityInOrigin --- .../scripting/include/reapi_engine.inc | 28 ++++++-- .../scripting/include/reapi_engine_const.inc | 9 +++ reapi/src/natives/natives_common.cpp | 66 +++++++++++++++++-- 3 files changed, 91 insertions(+), 12 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc index ce3aabb8..ba71180a 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc @@ -133,8 +133,8 @@ native GetAttachment(const entity, const attachment, Float:vecOrigin[3], Float:v * @return 1 on success, 0 otherwise * @error If the index is not within the range of 1 to maxEntities or * the entity is not valid, an error will be thrown. -* -*/ +* +*/ native SetBodygroup(const entity, const group, const value); /* @@ -146,8 +146,8 @@ native SetBodygroup(const entity, const group, const value); * @return Body group value * @error If the index is not within the range of 1 to maxEntities or * the entity is not valid, an error will be thrown. -* -*/ +* +*/ native GetBodygroup(const entity, const group); /* @@ -161,10 +161,26 @@ native GetBodygroup(const entity, const group); * @return True on success, false otherwise * @error If the index is not within the range of 1 to maxEntities or * the entity is not valid, an error will be thrown. -* -*/ +* +*/ native bool:GetSequenceInfo(const entity, &piFlags, &Float:pflFrameRate, &Float:pflGroundSpeed); +/* +* Test visibility of an entity from a given origin using either PVS or PAS +* +* @param entity Entity index +* @param origin Vector representing the origin from which visibility is checked +* @param type Type of visibility check: VisibilityInPVS (Potentially Visible Set) or VisibilityInPAS (Potentially Audible Set) +* +* @return 0 - Not visible +* 1 - Visible, passed by a leafnum +* 2 - Visible, passed by a headnode +* +* @remarks This function checks the visibility of the specified entity from the given origin, using either +* the Potentially Visible Set (PVS) or the Potentially Audible Set (PAS) depending on the provided type +*/ +native CheckVisibilityInOrigin(const ent, Float:origin[3], CheckVisibilityType:type = VisibilityInPVS); + /* * Sets the name of the map. * diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc index d1b114e9..a88342c3 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc @@ -13,6 +13,15 @@ enum MapNameType MNT_SET // return the name of the current map }; +/** +* For native CheckVisibilityInOrigin +*/ +enum CheckVisibilityType +{ + VisibilityInPVS = 0, // Check in Potentially Visible Set (PVS) + VisibilityInPAS // Check in Potentially Audible Set (PAS) +}; + /* * For RH_SV_AddResource hook */ diff --git a/reapi/src/natives/natives_common.cpp b/reapi/src/natives/natives_common.cpp index 416521a7..b538c14a 100644 --- a/reapi/src/natives/natives_common.cpp +++ b/reapi/src/natives/natives_common.cpp @@ -322,8 +322,8 @@ cell AMX_NATIVE_CALL amx_GetAttachment(AMX *amx, cell *params) * @return 1 on success, 0 otherwise * @error If the index is not within the range of 1 to maxEntities or * the entity is not valid, an error will be thrown. -* -*/ +* +*/ cell AMX_NATIVE_CALL amx_GetBodygroup(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_group }; @@ -353,8 +353,8 @@ cell AMX_NATIVE_CALL amx_GetBodygroup(AMX *amx, cell *params) * @return Body group value * @error If the index is not within the range of 1 to maxEntities or * the entity is not valid, an error will be thrown. -* -*/ +* +*/ cell AMX_NATIVE_CALL amx_SetBodygroup(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_group, arg_value }; @@ -387,8 +387,8 @@ cell AMX_NATIVE_CALL amx_SetBodygroup(AMX *amx, cell *params) * @return True on success, false otherwise * @error If the index is not within the range of 1 to maxEntities or * the entity is not valid, an error will be thrown. -* -*/ +* +*/ cell AMX_NATIVE_CALL amx_GetSequenceInfo(AMX *amx, cell *params) { enum args_e { arg_count, arg_index, arg_flags, arg_framerate, arg_groundspeed }; @@ -634,6 +634,58 @@ cell AMX_NATIVE_CALL amx_SetMoveDone(AMX *amx, cell *params) return (cell)EntityCallbackDispatcher().SetMoveDone(amx, pEntity, funcname, pParams, params[arg_len]); } +enum class CheckVisibilityType { + PVS = 0, // Check in Potentially Visible Set (PVS) + PAS // Check in Potentially Audible Set (PAS) +}; + +/* +* Test visibility of an entity from a given origin using either PVS or PAS +* +* @param entity Entity index +* @param origin Vector representing the origin from which visibility is checked +* @param type Type of visibility check: VisibilityInPVS (Potentially Visible Set) or VisibilityInPAS (Potentially Audible Set) +* +* @return 0 - Not visible +* 1 - Visible, passed by a leafnum +* 2 - Visible, passed by a headnode +* +* @remarks This function checks the visibility of the specified entity from the given origin, using either +* the Potentially Visible Set (PVS) or the Potentially Audible Set (PAS) depending on the provided type +* +* native CheckVisibilityInOrigin(const ent, Float:origin[3], CheckVisibilityType:type = VisibilityInPVS); +*/ +cell AMX_NATIVE_CALL amx_CheckVisibilityInOrigin(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_index, arg_origin, arg_type }; + + CHECK_ISENTITY(arg_index); + + CBaseEntity *pEntity = getPrivate(params[arg_index]); + if (unlikely(pEntity == nullptr)) { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid or uninitialized entity", __FUNCTION__); + return FALSE; + } + + CheckVisibilityType type = static_cast(params[arg_type]); + if (type < CheckVisibilityType::PVS || type > CheckVisibilityType::PAS) { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid visibility check type %d. Use either VisibilityInPVS or VisibilityInPAS.", __FUNCTION__, params[arg_type]); + return FALSE; + } + + Vector &origin = *(Vector *)getAmxAddr(amx, params[arg_origin]); + + unsigned char *pSet = NULL; + switch (type) + { + case CheckVisibilityType::PVS: pSet = ENGINE_SET_PVS(origin); break; + case CheckVisibilityType::PAS: pSet = ENGINE_SET_PAS(origin); break; + default: break; + } + + return ENGINE_CHECK_VISIBILITY(pEntity->edict(), pSet); +} + AMX_NATIVE_INFO Natives_Common[] = { { "FClassnameIs", amx_FClassnameIs }, @@ -655,6 +707,8 @@ AMX_NATIVE_INFO Natives_Common[] = { "SetBlocked", amx_SetBlocked }, { "SetMoveDone", amx_SetMoveDone }, + { "CheckVisibilityInOrigin", amx_CheckVisibilityInOrigin }, + { nullptr, nullptr } }; From 016a08a58a0855e334c8ec739ed42a540a4c5ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=82=AF=E5=AE=9A=E9=BE=99?= <52111952+overl4y@users.noreply.github.com> Date: Wed, 31 Jan 2024 08:46:19 -0400 Subject: [PATCH 4/8] API: PlayerDeathThink and Observer_Think (#301) --- .../scripting/include/reapi_gamedll_const.inc | 12 ++++++++++++ reapi/include/cssdk/dlls/regamedll_api.h | 6 ++++++ reapi/src/hook_callback.cpp | 19 +++++++++++++++++++ reapi/src/hook_callback.h | 2 ++ reapi/src/hook_list.cpp | 3 +++ reapi/src/hook_list.h | 3 +++ 6 files changed, 45 insertions(+) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 5f2d6ae2..0b303097 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -914,6 +914,18 @@ enum GamedllFunc_CBasePlayer * Params: (const this) */ RG_CBasePlayer_EntSelectSpawnPoint, + + /* + * Description: - + * Params: (const this) + */ + RG_CBasePlayer_PlayerDeathThink, + + /* + * Description: - + * Params: (const this) + */ + RG_CBasePlayer_Observer_Think, }; /** diff --git a/reapi/include/cssdk/dlls/regamedll_api.h b/reapi/include/cssdk/dlls/regamedll_api.h index 762d06d6..dbf50875 100644 --- a/reapi/include/cssdk/dlls/regamedll_api.h +++ b/reapi/include/cssdk/dlls/regamedll_api.h @@ -622,6 +622,10 @@ typedef IHookChainRegistry IReGameHook_CBasePlayer_PlayerDeathThink; typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_PlayerDeathThink; +// CBasePlayer::Observer_Think hook +typedef IHookChainClass IReGameHook_CBasePlayer_Observer_Think; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_Observer_Think; + class IReGameHookchains { public: virtual ~IReGameHookchains() {} @@ -782,6 +786,8 @@ class IReGameHookchains { virtual IReGameHookRegistry_CSGameRules_SendDeathMessage *CSGameRules_SendDeathMessage() = 0; virtual IReGameHookRegistry_CBasePlayer_PlayerDeathThink *CBasePlayer_PlayerDeathThink() = 0; + virtual IReGameHookRegistry_CBasePlayer_Observer_Think *CBasePlayer_Observer_Think() = 0; + }; struct ReGameFuncs_t { diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index b1d68030..3c286045 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -1710,6 +1710,25 @@ void CBasePlayerWeapon_SendWeaponAnim(IReGameHook_CBasePlayerWeapon_SendWeaponAn callVoidForward(RG_CBasePlayerWeapon_SendWeaponAnim, original, indexOfEdict(pthis->pev), iAnim, skiplocal); } +void CBasePlayer_PlayerDeathThink(IReGameHook_CBasePlayer_PlayerDeathThink *chain, CBasePlayer *pthis) +{ + auto original = [chain](int _pthis) + { + chain->callNext(getPrivate(_pthis)); + }; + + callVoidForward(RG_CBasePlayer_PlayerDeathThink, original, indexOfEdict(pthis->pev)); +} + +void CBasePlayer_Observer_Think(IReGameHook_CBasePlayer_Observer_Think *chain, CBasePlayer *pthis) +{ + auto original = [chain](int _pthis) + { + chain->callNext(getPrivate(_pthis)); + }; + + callVoidForward(RG_CBasePlayer_Observer_Think, original, indexOfEdict(pthis->pev)); +} /* * VTC functions diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index af39e6ad..ede4ad76 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -558,6 +558,8 @@ edict_t *CBasePlayer_EntSelectSpawnPoint(IReGameHook_CBasePlayer_EntSelectSpawnP void CBasePlayerWeapon_ItemPostFrame(IReGameHook_CBasePlayerWeapon_ItemPostFrame *chain, CBasePlayerWeapon *pthis); void CBasePlayerWeapon_KickBack(IReGameHook_CBasePlayerWeapon_KickBack *chain, CBasePlayerWeapon *pthis, float up_base, float lateral_base, float up_modifier, float lateral_modifier, float up_max, float lateral_max, int direction_change); void CBasePlayerWeapon_SendWeaponAnim(IReGameHook_CBasePlayerWeapon_SendWeaponAnim *chain, CBasePlayerWeapon *pthis, int iAnim, int skiplocal); +void CBasePlayer_PlayerDeathThink(IReGameHook_CBasePlayer_PlayerDeathThink *chain, CBasePlayer *pthis); +void CBasePlayer_Observer_Think(IReGameHook_CBasePlayer_Observer_Think *chain, CBasePlayer *pthis); /* * VTC functions diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index 870c95c1..8f5bf54a 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -212,6 +212,9 @@ hook_t hooklist_player[] = { DLL(CBasePlayer_CheckTimeBasedDamage), DLL(CBasePlayer_EntSelectSpawnPoint), + + DLL(CBasePlayer_PlayerDeathThink), + DLL(CBasePlayer_Observer_Think), }; hook_t hooklist_gamerules[] = { diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 18483eb2..6e6d9da7 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -236,6 +236,9 @@ enum GamedllFunc_CBasePlayer RG_CBasePlayer_CheckTimeBasedDamage, RG_CBasePlayer_EntSelectSpawnPoint, + RG_CBasePlayer_PlayerDeathThink, + RG_CBasePlayer_Observer_Think, + // [...] }; From 55151847af3d61d9a53dc8278bf4bfb3de059ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=82=AF=E5=AE=9A=E9=BE=99?= <52111952+overl4y@users.noreply.github.com> Date: Wed, 31 Jan 2024 08:56:38 -0400 Subject: [PATCH 5/8] API: Added rg_player_relationship native (#304) --- .../amxmodx/scripting/include/cssdk_const.inc | 12 +++++++++ .../scripting/include/reapi_gamedll.inc | 10 ++++++++ reapi/src/natives/natives_misc.cpp | 25 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/reapi/extra/amxmodx/scripting/include/cssdk_const.inc b/reapi/extra/amxmodx/scripting/include/cssdk_const.inc index a3bfc5e9..0f91158b 100644 --- a/reapi/extra/amxmodx/scripting/include/cssdk_const.inc +++ b/reapi/extra/amxmodx/scripting/include/cssdk_const.inc @@ -1539,3 +1539,15 @@ enum Decal DECAL_MOMMABIRTH, // Big momma birth splatter DECAL_MOMMASPLAT, }; + +/** +* Player relationship return codes +*/ +enum +{ + GR_NOTTEAMMATE = 0, + GR_TEAMMATE, + GR_ENEMY, + GR_ALLY, + GR_NEUTRAL, +}; \ No newline at end of file diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 060f36f0..454ff8ce 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -1195,3 +1195,13 @@ native rg_set_observer_mode(const player, const mode); * @noreturn */ native rg_death_notice(const pVictim, const pKiller, const pevInflictor); + +/* +* Checks a player relationship with another reference +* +* @param player Player index +* @param target Target index +* +* @return Match player relationship, see GR_* constants in cssdk_const.inc +*/ +native rg_player_relationship(const player, const target); \ No newline at end of file diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index ccd9d0bc..6d4c5a5c 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -3225,6 +3225,30 @@ cell AMX_NATIVE_CALL rg_death_notice(AMX* amx, cell* params) return TRUE; } +/* +* Checks a player relationship with another reference +* +* @param player Player index +* @param target Target index +* +* @return Match player relationship, see GR_* constants in cssdk_const.inc +*/ +cell AMX_NATIVE_CALL rg_player_relationship(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_player, arg_target }; + + CHECK_GAMERULES(); + CHECK_ISPLAYER(arg_player); + CHECK_ISENTITY(arg_target); + + CBasePlayer *pPlayer = UTIL_PlayerByIndex(params[arg_player]); + CHECK_CONNECTED(pPlayer, arg_player); + + CBaseEntity *pTarget = getPrivate(params[arg_target]); + + return CSGameRules()->PlayerRelationship(pPlayer, pTarget); +} + AMX_NATIVE_INFO Misc_Natives_RG[] = { { "rg_set_animation", rg_set_animation }, @@ -3336,6 +3360,7 @@ AMX_NATIVE_INFO Misc_Natives_RG[] = { "rg_disappear", rg_disappear }, { "rg_set_observer_mode", rg_set_observer_mode }, { "rg_death_notice", rg_death_notice }, + { "rg_player_relationship", rg_player_relationship }, { nullptr, nullptr } }; From f2ef526271e7bf26817841b49866566b4848a347 Mon Sep 17 00:00:00 2001 From: Javekson <132286351+Javekson@users.noreply.github.com> Date: Thu, 1 Feb 2024 09:24:05 +0400 Subject: [PATCH 6/8] feat: add WI_SLOT for rg_get_weapon_info (#292) --- .../scripting/include/reapi_gamedll_const.inc | 10 +++++++++- reapi/src/natives/natives_misc.cpp | 14 ++++++++++++++ reapi/src/natives/natives_misc.h | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 0b303097..2970c5d5 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -134,7 +134,15 @@ enum WpnInfo * Get params: rg_get_weapon_info(const weapon_id, WI_NAME, const output[], maxlenght); * Set params: - */ - WI_NAME + WI_NAME, + + /* + * Description: - + * Return type: enum InventorySlotType + * Get params: rg_get_weapon_info(const weapon_id, WI_SLOT); + * Set params: rg_set_weapon_info(const weapon_id, WI_SLOT, const value); + */ + WI_SLOT, }; /** diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 6d4c5a5c..5a01e14e 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -840,7 +840,15 @@ cell AMX_NATIVE_CALL rg_get_weapon_info(AMX *amx, cell *params) setAmxString(dest, info->entityName, length); return 1; } + case WI_SLOT: + { + auto pInfo = g_ReGameApi->GetWeaponSlot(weaponId); + if (pInfo) { + return pInfo->slot; + } + return NONE_SLOT; + } default: AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: unknown type statement %i, params count %i", __FUNCTION__, info_type, PARAMS_COUNT); return -1; @@ -896,6 +904,12 @@ cell AMX_NATIVE_CALL rg_set_weapon_info(AMX *amx, cell *params) case WI_NAME: AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: this change will have no effect, type statement %i", __FUNCTION__, info_type); return 0; + case WI_SLOT: + { + auto pInfo = g_ReGameApi->GetWeaponSlot(weaponId); + pInfo->slot = static_cast(*value); + break; + } default: AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: unknown type statement %i, params count %i", __FUNCTION__, info_type, PARAMS_COUNT); return 0; diff --git a/reapi/src/natives/natives_misc.h b/reapi/src/natives/natives_misc.h index 70ca2131..1ad58361 100644 --- a/reapi/src/natives/natives_misc.h +++ b/reapi/src/natives/natives_misc.h @@ -18,6 +18,7 @@ enum WpnInfo WI_AMMO_TYPE, WI_AMMO_NAME, WI_NAME, + WI_SLOT, }; void RegisterNatives_Misc(); From fbe2788623ba7a1b21cbc2ab4b00b46ae98e46d2 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Fri, 2 Feb 2024 04:43:08 +0700 Subject: [PATCH 7/8] Add safe check for weapon natives (make sure it's a CBasePlayerWeapon instance) --- reapi/src/natives/natives_helper.h | 1 + reapi/src/natives/natives_misc.cpp | 50 ++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/reapi/src/natives/natives_helper.h b/reapi/src/natives/natives_helper.h index 6ec6b5ea..f6c664e4 100644 --- a/reapi/src/natives/natives_helper.h +++ b/reapi/src/natives/natives_helper.h @@ -6,6 +6,7 @@ #define CHECK_ISENTITY(x) if (unlikely(params[x] < 0 || params[x] > gpGlobals->maxEntities)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid entity index %i [%s]", __FUNCTION__, params[x], #x); return FALSE; } #define CHECK_GAMERULES() if (unlikely(!g_pGameRules)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: gamerules not initialized", __FUNCTION__); return FALSE; } #define CHECK_CONNECTED(x, y) if (unlikely(x == nullptr || x->has_disconnected)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: player %i is not connected", __FUNCTION__, params[y]); return FALSE; } +#define CHECK_INSTANCE_OF(x, y) if (unlikely(dynamic_cast((x::BaseClass *)y) == nullptr)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid entity %d ('%s'), is not an instance of the base class '%s'", __FUNCTION__, indexOfEdict(y->pev), STRING(y->pev->classname), #x); return FALSE; } class CAmxArg { diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 5a01e14e..609695c3 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -1675,8 +1675,15 @@ cell AMX_NATIVE_CALL rg_instant_reload_weapons(AMX *amx, cell *params) if (params[arg_weapon] != 0) { pWeapon = getPrivate(params[arg_weapon]); - if (!pWeapon || !pWeapon->IsWeapon()) { - AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: Invalid entity weapon", __FUNCTION__); + if (unlikely(pWeapon == nullptr)) { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid or uninitialized entity", __FUNCTION__); + return FALSE; + } + + CHECK_INSTANCE_OF(CBasePlayerWeapon, pWeapon); + + if (!pWeapon->IsWeapon()) { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: #%d entity is not a weapon.", __FUNCTION__, indexOfEdict(pWeapon->pev)); return FALSE; } } @@ -1867,9 +1874,16 @@ cell AMX_NATIVE_CALL rg_switch_weapon(AMX *amx, cell *params) CBasePlayer *pPlayer = UTIL_PlayerByIndex(params[arg_index]); CHECK_CONNECTED(pPlayer, arg_index); - auto pWeapon = getPrivate(params[arg_weapon]); - if (pWeapon == nullptr || !pWeapon->IsWeapon()) { - AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: Invalid entity weapon", __FUNCTION__); + CBasePlayerWeapon *pWeapon = getPrivate(params[arg_weapon]); + if (unlikely(pWeapon == nullptr)) { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid or uninitialized entity", __FUNCTION__); + return FALSE; + } + + CHECK_INSTANCE_OF(CBasePlayerWeapon, pWeapon); + + if (!pWeapon->IsWeapon()) { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: #%d entity is not a weapon.", __FUNCTION__, indexOfEdict(pWeapon->pev)); return FALSE; } @@ -2142,6 +2156,8 @@ cell AMX_NATIVE_CALL rg_set_iteminfo(AMX *amx, cell *params) return FALSE; } + CHECK_INSTANCE_OF(CBasePlayerWeapon, pWeapon); + if (!pWeapon->IsWeapon()) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: #%d entity is not a weapon.", __FUNCTION__, indexOfEdict(pWeapon->pev)); return FALSE; @@ -2205,6 +2221,8 @@ cell AMX_NATIVE_CALL rg_get_iteminfo(AMX *amx, cell *params) return FALSE; } + CHECK_INSTANCE_OF(CBasePlayerWeapon, pWeapon); + if (!pWeapon->IsWeapon()) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: #%d entity is not a weapon.", __FUNCTION__, indexOfEdict(pWeapon->pev)); return FALSE; @@ -2834,6 +2852,8 @@ cell AMX_NATIVE_CALL rg_weapon_deploy(AMX* amx, cell* params) return FALSE; } + CHECK_INSTANCE_OF(CBasePlayerWeapon, pWeapon); + if (!pWeapon->IsWeapon()) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: #%d entity is not a weapon.", __FUNCTION__, indexOfEdict(pWeapon->pev)); @@ -2898,6 +2918,8 @@ cell AMX_NATIVE_CALL rg_weapon_reload(AMX* amx, cell* params) return FALSE; } + CHECK_INSTANCE_OF(CBasePlayerWeapon, pWeapon); + if (!pWeapon->IsWeapon()) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: #%d entity is not a weapon.", __FUNCTION__, indexOfEdict(pWeapon->pev)); @@ -2968,6 +2990,8 @@ cell AMX_NATIVE_CALL rg_weapon_shotgun_reload(AMX* amx, cell* params) return FALSE; } + CHECK_INSTANCE_OF(CBasePlayerWeapon, pWeapon); + if (!pWeapon->IsWeapon()) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: #%d entity is not a weapon.", __FUNCTION__, indexOfEdict(pWeapon->pev)); @@ -3032,6 +3056,8 @@ cell AMX_NATIVE_CALL rg_weapon_send_animation(AMX* amx, cell* params) return FALSE; } + CHECK_INSTANCE_OF(CBasePlayerWeapon, pWeapon); + if (!pWeapon->IsWeapon()) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: #%d entity is not a weapon.", __FUNCTION__, indexOfEdict(pWeapon->pev)); @@ -3097,6 +3123,8 @@ cell AMX_NATIVE_CALL rg_weapon_kickback(AMX* amx, cell* params) return FALSE; } + CHECK_INSTANCE_OF(CBasePlayerWeapon, pWeapon); + if (!pWeapon->IsWeapon()) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: #%d entity is not a weapon.", __FUNCTION__, indexOfEdict(pWeapon->pev)); @@ -3151,11 +3179,6 @@ cell AMX_NATIVE_CALL rg_switch_best_weapon(AMX* amx, cell* params) AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid or uninitialized entity", __FUNCTION__); return FALSE; } - - if (!pWeapon->IsWeapon()) { - AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: #%d entity is not a weapon.", __FUNCTION__, indexOfEdict(pWeapon->pev)); - return FALSE; - } } else { @@ -3167,6 +3190,13 @@ cell AMX_NATIVE_CALL rg_switch_best_weapon(AMX* amx, cell* params) } } + CHECK_INSTANCE_OF(CBasePlayerWeapon, pWeapon); + + if (!pWeapon->IsWeapon()) { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: #%d entity is not a weapon.", __FUNCTION__, indexOfEdict(pWeapon->pev)); + return FALSE; + } + return CSGameRules()->GetNextBestWeapon(pPlayer, pWeapon); } From d40a0fed1f1583b188fe2b5978e2a0250c8d72bd Mon Sep 17 00:00:00 2001 From: s1lentq Date: Fri, 2 Feb 2024 04:50:56 +0700 Subject: [PATCH 8/8] Fix broken order in amxx includes (Related #263) (Resolves #300) --- .../amxmodx/scripting/include/reapi_engine_const.inc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc index a88342c3..2302d05b 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc @@ -171,12 +171,6 @@ enum EngineFunc */ RH_SV_ClientPrintf, - /* - * Description: Called when a command is being sent to server. - * Params: (const cmd[], source, id) - */ - RH_ExecuteServerStringCmd, - /* * Description: Called before adding an entity to the physents of a player. * Return type: bool @@ -184,6 +178,12 @@ enum EngineFunc */ RH_SV_AllowPhysent, + /* + * Description: Called when a command is being sent to server. + * Params: (const cmd[], source, id) + */ + RH_ExecuteServerStringCmd, + }; /**