From 9f2e4d64e1dc3e7971a504e40e8a9beb8a28ad34 Mon Sep 17 00:00:00 2001 From: dystopm Date: Thu, 4 May 2023 23:48:56 -0400 Subject: [PATCH 1/7] Implement RG_CreateWeaponBox hook Interface was coded but never implemented. It needs tests --- .../scripting/include/reapi_gamedll_const.inc | 7 +++++++ reapi/src/hook_callback.cpp | 12 ++++++++++++ reapi/src/hook_callback.h | 1 + reapi/src/hook_list.cpp | 1 + reapi/src/hook_list.h | 2 ++ 5 files changed, 23 insertions(+) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 5265f7ed..e2f896d9 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -400,6 +400,13 @@ enum GamedllFunc * Params: (pevVictim, cGibs, human) */ RG_SpawnRandomGibs, + + /* + * Description: Called when a player drops a weapon (usually manual drop or death) + * Return type: CWeaponBox * (Entity index of weaponbox) + * Params: (const weaponent, const owner, modelName[], Float:origin[3], Float:angles[3], Float:velocity[3], Float:lifeTime, bool:packAmmo) + */ + RG_CreateWeaponBox, }; /** diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index 46f662c5..4cca12d0 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -1329,6 +1329,18 @@ bool IsPenetrableEntity(IReGameHook_IsPenetrableEntity *chain, Vector &vecSrc, V return callForward(RG_IsPenetrableEntity, original, getAmxVector(vecSrcCopy), getAmxVector(vecEndCopy), indexOfEdict(pevAttacker), indexOfEdict(pHit)); } +CWeaponBox *CreateWeaponBox(IReGameHook_CreateWeaponBox *chain, CBasePlayerItem *pItem, CBasePlayer *pPlayerOwner, const char *modelName, Vector &origin, Vector &angles, Vector &velocity, float lifeTime, bool packAmmo) +{ + Vector vecOriginCopy(origin), vecAnglesCopy(angles), vecVelocityCopy(velocity); + + auto original = [chain, &vecOriginCopy, &vecAnglesCopy, &vecVelocityCopy](int _pItem, int _pPlayerOwner, const char *_modelName, cell _origin, cell _angles, cell _velocity, float _lifeTime, bool _packAmmo) + { + return indexOfPDataAmx(chain->callNext(getPrivate(_pItem), getPrivate(_pPlayerOwner), _modelName, vecOriginCopy, vecAnglesCopy, vecVelocityCopy, _lifeTime, _packAmmo)); + }; + + return getPrivate(callForward(RG_CreateWeaponBox, original, indexOfEdictAmx(pItem->pev), indexOfEdictAmx(pPlayerOwner->pev), modelName, getAmxVector(vecOriginCopy), getAmxVector(vecAnglesCopy), getAmxVector(vecVelocityCopy), lifeTime, packAmmo)); +} + CGib *SpawnHeadGib(IReGameHook_SpawnHeadGib *chain, entvars_t *pevVictim) { auto original = [chain](int _pevVictim) diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index 6340010d..7d0bd3d2 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -411,6 +411,7 @@ CGrenade *ThrowFlashbang(IReGameHook_ThrowFlashbang *chain, entvars_t *pevOwner, CGrenade *ThrowSmokeGrenade(IReGameHook_ThrowSmokeGrenade *chain, entvars_t *pevOwner, Vector &vecStart, Vector &vecVelocity, float time, unsigned short usEvent); CGrenade *PlantBomb(IReGameHook_PlantBomb *chain, entvars_t *pevOwner, Vector &vecStart, Vector &vecVelocity); bool IsPenetrableEntity(IReGameHook_IsPenetrableEntity *chain, Vector &vecSrc, Vector &vecEnd, entvars_t *pevAttacker, edict_t *pHit); +CWeaponBox *CreateWeaponBox(IReGameHook_CreateWeaponBox *chain, CBasePlayerItem *pItem, CBasePlayer *pPlayerOwner, const char *modelName, Vector &origin, Vector &angles, Vector &velocity, float lifeTime, bool packAmmo); CGib *SpawnHeadGib(IReGameHook_SpawnHeadGib *chain, entvars_t *pevVictim); void SpawnRandomGibs(IReGameHook_SpawnRandomGibs *chain, entvars_t *pevVictim, int cGibs, int human); diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index 5699ecf6..312ef37f 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -130,6 +130,7 @@ hook_t hooklist_gamedll[] = { DLL(IsPenetrableEntity), DLL(SpawnHeadGib), DLL(SpawnRandomGibs), + DLL(CreateWeaponBox), }; hook_t hooklist_animating[] = { diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 91125824..14b45b26 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -144,6 +144,8 @@ enum GamedllFunc RG_SpawnHeadGib, RG_SpawnRandomGibs, + RG_CreateWeaponBox, + // [...] }; From b816b9bf7fbf64b5481e06800f2e915bc3357f27 Mon Sep 17 00:00:00 2001 From: dystopm Date: Fri, 30 Jun 2023 03:02:44 -0400 Subject: [PATCH 2/7] Add global_iteminfo natives --- reapi/src/natives/natives_misc.cpp | 130 +++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 24b19f04..1b0f005f 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -2243,6 +2243,136 @@ cell AMX_NATIVE_CALL rg_get_iteminfo(AMX *amx, cell *params) return TRUE; } +/** +* Sets a parameter of the global CBasePlayerItem::m_ItemInfoArray array +* @note To have effect on client side (i.g. clip size on HUD) you should +* alter this value BEFORE WeaponList message is sent to client, or +* force it's alteration by sending again to the specific client. +* Hooking WeaponList message with AMXX's register_message is a choice. +* +* @param weapon Weapon id, see WEAPON_* constants +* @param type Item info type. See ItemInfo constants. +* +* native rg_set_global_iteminfo(const {WeaponIdType,_}:weapon_id, ItemInfo:type, any:...); +*/ +cell AMX_NATIVE_CALL rg_set_global_iteminfo(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_weapon_id, arg_type, arg_value }; + + WeaponIdType weaponId = static_cast(params[arg_weapon_id]); + if (!GetWeaponInfoRange(weaponId, true)) + { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weaponId); + return FALSE; + } + + ItemInfo* II = g_ReGameFuncs->GetItemInfo(weaponId); + + char itembuf[256]; + cell *ptr = getAmxAddr(amx, params[arg_value]); + + ItemInfo_e type = static_cast(params[arg_type]); + switch (type) + { + case ItemInfo_iSlot: II->iSlot = *ptr; break; + case ItemInfo_iPosition: II->iPosition = *ptr; break; + case ItemInfo_iMaxAmmo1: II->iMaxAmmo1 = *ptr; break; + case ItemInfo_iMaxAmmo2: II->iMaxAmmo2 = *ptr; break; + case ItemInfo_iMaxClip: II->iMaxClip = *ptr; break; + case ItemInfo_iId: II->iId = *ptr; break; + case ItemInfo_iFlags: II->iFlags = *ptr; break; + case ItemInfo_iWeight: II->iWeight = *ptr; break; + case ItemInfo_pszAmmo1: II->pszAmmo1 = STRING(getAmxStringAlloc(amx, params[arg_value], itembuf)); break; + case ItemInfo_pszAmmo2: II->pszAmmo2 = STRING(getAmxStringAlloc(amx, params[arg_value], itembuf)); break; + case ItemInfo_pszName: II->pszName = STRING(getAmxStringAlloc(amx, params[arg_value], itembuf)); break; + + default: + AMXX_LogError(amx, AMX_ERR_NATIVE, "Unknown ItemInfo type %d", type); + return FALSE; + } + + return TRUE; +} + +/** +* Gets a parameter of the global CBasePlayerItem::m_ItemInfoArray array +* +* @param weapon Weapon id, see WEAPON_* constants +* @param type Item info type. See ItemInfo constants. +* +* native rg_get_global_iteminfo(const {WeaponIdType,_}:weapon_id, ItemInfo:type, any:...); +*/ +cell AMX_NATIVE_CALL rg_get_global_iteminfo(AMX *amx, cell *params) +{ + enum args_e { arg_count, arg_weapon_id, arg_type, arg_output, arg_length }; + + WeaponIdType weaponId = static_cast(params[arg_weapon_id]); + if (!GetWeaponInfoRange(weaponId, true)) + { + AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weaponId); + return FALSE; + } + + ItemInfo_e type = static_cast(params[arg_type]); + if ((type == ItemInfo_pszAmmo1 || type == ItemInfo_pszAmmo2 || type == ItemInfo_pszName) && PARAMS_COUNT != 4) + { + AMXX_LogError(amx, AMX_ERR_NATIVE, "Bad arg count. Expected %d, got %d.", 4, PARAMS_COUNT); + return FALSE; + } + + ItemInfo* II = g_ReGameFuncs->GetItemInfo(weaponId); + + cell *dest = getAmxAddr(amx, params[arg_output]); + size_t length = (PARAMS_COUNT == 4) ? *getAmxAddr(amx, params[arg_length]) : 0; + + switch (type) + { + case ItemInfo_iSlot: return II->iSlot; + case ItemInfo_iPosition: return II->iPosition; + case ItemInfo_iMaxAmmo1: return II->iMaxAmmo1; + case ItemInfo_iMaxAmmo2: return II->iMaxAmmo2; + case ItemInfo_iMaxClip: return II->iMaxClip; + case ItemInfo_iId: return II->iId; + case ItemInfo_iFlags: return II->iFlags; + case ItemInfo_iWeight: return II->iWeight; + case ItemInfo_pszAmmo1: + { + if (II->pszAmmo1 == nullptr) { + setAmxString(dest, "", 1); + break; + } + + setAmxString(dest, II->pszAmmo1, length); + break; + } + case ItemInfo_pszAmmo2: + { + if (II->pszAmmo2 == nullptr) { + setAmxString(dest, "", 1); + break; + } + + setAmxString(dest, II->pszAmmo2, length); + break; + } + case ItemInfo_pszName: + { + if (II->pszName == nullptr) { + setAmxString(dest, "", 1); + break; + } + + setAmxString(dest, II->pszName, length); + break; + } + default: + AMXX_LogError(amx, AMX_ERR_NATIVE, "Unknown ItemInfo type %d", type); + return FALSE; + } + + return TRUE; +} + /* * Adds hint message to the queue. * From e5e5c0176b6e4ca3610659b4f2a5d85cf9e61ea6 Mon Sep 17 00:00:00 2001 From: dystopm Date: Fri, 30 Jun 2023 03:05:18 -0400 Subject: [PATCH 3/7] API typo --- reapi/src/natives/natives_misc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 1b0f005f..563fcf2c 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -2266,7 +2266,7 @@ cell AMX_NATIVE_CALL rg_set_global_iteminfo(AMX *amx, cell *params) return FALSE; } - ItemInfo* II = g_ReGameFuncs->GetItemInfo(weaponId); + ItemInfo* II = g_ReGameApi->GetItemInfo(weaponId); char itembuf[256]; cell *ptr = getAmxAddr(amx, params[arg_value]); @@ -2320,7 +2320,7 @@ cell AMX_NATIVE_CALL rg_get_global_iteminfo(AMX *amx, cell *params) return FALSE; } - ItemInfo* II = g_ReGameFuncs->GetItemInfo(weaponId); + ItemInfo* II = g_ReGameApi->GetItemInfo(weaponId); cell *dest = getAmxAddr(amx, params[arg_output]); size_t length = (PARAMS_COUNT == 4) ? *getAmxAddr(amx, params[arg_length]) : 0; From ce48534791edb2dd73f77475a4a93ad78e6c6c6f Mon Sep 17 00:00:00 2001 From: dystopm Date: Fri, 30 Jun 2023 03:18:42 -0400 Subject: [PATCH 4/7] Add include with docs --- .../scripting/include/reapi_gamedll.inc | 22 +++++++++++++++++++ reapi/src/natives/natives_misc.cpp | 8 +++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 984fb563..a57ee1c0 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -895,6 +895,28 @@ native rg_set_iteminfo(const entity, ItemInfo:type, any:...); */ native rg_get_iteminfo(const ent, ItemInfo:type, any:...); +/** +* Sets a parameter of the global CBasePlayerItem::m_ItemInfoArray array +* @note To have effect on client side (i.g. clip size on HUD) you should +* alter this value BEFORE WeaponList message is sent to client, or +* force it's alteration by sending again to the specific client. +* Hooking WeaponList message with AMXX's register_message is a choice. +* +* @param weapon_id Weapon id, see WEAPON_* constants +* @param type Item info type. See ItemInfo constants. +* +*/ +native rg_set_global_iteminfo(const {WeaponIdType,_}:weapon_id, ItemInfo:type, any:...); + +/** +* Gets a parameter of the global CBasePlayerItem::m_ItemInfoArray array +* +* @param weapon_id Weapon id, see WEAPON_* constants +* @param type Item info type. See ItemInfo constants. +* +*/ +native rg_get_global_iteminfo(const {WeaponIdType,_}:weapon_id, ItemInfo:type, any:...); + /* * Adds hint message to the queue. * diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 563fcf2c..a8368489 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -2250,8 +2250,8 @@ cell AMX_NATIVE_CALL rg_get_iteminfo(AMX *amx, cell *params) * force it's alteration by sending again to the specific client. * Hooking WeaponList message with AMXX's register_message is a choice. * -* @param weapon Weapon id, see WEAPON_* constants -* @param type Item info type. See ItemInfo constants. +* @param weapon_id Weapon id, see WEAPON_* constants +* @param type Item info type. See ItemInfo constants. * * native rg_set_global_iteminfo(const {WeaponIdType,_}:weapon_id, ItemInfo:type, any:...); */ @@ -2297,8 +2297,8 @@ cell AMX_NATIVE_CALL rg_set_global_iteminfo(AMX *amx, cell *params) /** * Gets a parameter of the global CBasePlayerItem::m_ItemInfoArray array * -* @param weapon Weapon id, see WEAPON_* constants -* @param type Item info type. See ItemInfo constants. +* @param weapon_id Weapon id, see WEAPON_* constants +* @param type Item info type. See ItemInfo constants. * * native rg_get_global_iteminfo(const {WeaponIdType,_}:weapon_id, ItemInfo:type, any:...); */ From d6725c98822ca14f22146535937702008277897d Mon Sep 17 00:00:00 2001 From: dystopm Date: Fri, 30 Jun 2023 03:29:04 -0400 Subject: [PATCH 5/7] Linking --- reapi/src/natives/natives_misc.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index a8368489..7b891bc2 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -2684,6 +2684,8 @@ AMX_NATIVE_INFO Misc_Natives_RG[] = { "rg_set_iteminfo", rg_set_iteminfo }, { "rg_get_iteminfo", rg_get_iteminfo }, + { "rg_set_global_iteminfo", rg_set_global_iteminfo }, + { "rg_get_global_iteminfo", rg_get_global_iteminfo }, { "rg_hint_message", rg_hint_message }, From 2fc4bbdc7230285fc2b483a6e456af3b3b5d6ced Mon Sep 17 00:00:00 2001 From: dystopm Date: Fri, 30 Jun 2023 03:32:09 -0400 Subject: [PATCH 6/7] Param mistake --- reapi/src/natives/natives_misc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 7b891bc2..687396fb 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -2260,7 +2260,7 @@ cell AMX_NATIVE_CALL rg_set_global_iteminfo(AMX *amx, cell *params) enum args_e { arg_count, arg_weapon_id, arg_type, arg_value }; WeaponIdType weaponId = static_cast(params[arg_weapon_id]); - if (!GetWeaponInfoRange(weaponId, true)) + if (!GetWeaponInfoRange(weaponId, false)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weaponId); return FALSE; @@ -2307,7 +2307,7 @@ cell AMX_NATIVE_CALL rg_get_global_iteminfo(AMX *amx, cell *params) enum args_e { arg_count, arg_weapon_id, arg_type, arg_output, arg_length }; WeaponIdType weaponId = static_cast(params[arg_weapon_id]); - if (!GetWeaponInfoRange(weaponId, true)) + if (!GetWeaponInfoRange(weaponId, false)) { AMXX_LogError(amx, AMX_ERR_NATIVE, "%s: invalid weapon id %i", __FUNCTION__, weaponId); return FALSE; From eabfab307ad5e612aa3178556a1d3ca374120d51 Mon Sep 17 00:00:00 2001 From: dystopm Date: Sun, 16 Jul 2023 00:37:11 -0400 Subject: [PATCH 7/7] Tiny documentation fixes --- reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc | 2 +- reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc | 2 +- reapi/src/natives/natives_misc.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index a57ee1c0..29a2252f 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -897,7 +897,7 @@ native rg_get_iteminfo(const ent, ItemInfo:type, any:...); /** * Sets a parameter of the global CBasePlayerItem::m_ItemInfoArray array -* @note To have effect on client side (i.g. clip size on HUD) you should +* @note To have effect on client side (i.g. ammo size on HUD) you should * alter this value BEFORE WeaponList message is sent to client, or * force it's alteration by sending again to the specific client. * Hooking WeaponList message with AMXX's register_message is a choice. diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index df3ebb7e..ce31aa34 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -138,7 +138,7 @@ enum WpnInfo }; /** -* Item's info types for use with rg_set_iteminfo/rg_get_iteminfo() +* Item's info types for use with rg_set_[global_]iteminfo/rg_get_[global_]iteminfo() */ enum ItemInfo { diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 687396fb..5a0db3ac 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -2245,7 +2245,7 @@ cell AMX_NATIVE_CALL rg_get_iteminfo(AMX *amx, cell *params) /** * Sets a parameter of the global CBasePlayerItem::m_ItemInfoArray array -* @note To have effect on client side (i.g. clip size on HUD) you should +* @note To have effect on client side (i.g. ammo size on HUD) you should * alter this value BEFORE WeaponList message is sent to client, or * force it's alteration by sending again to the specific client. * Hooking WeaponList message with AMXX's register_message is a choice.