From 838fe357b9e5226a2a5d23a36c2c2017ec4f3188 Mon Sep 17 00:00:00 2001 From: Celio Lozatto Date: Thu, 15 Aug 2024 12:42:13 -0300 Subject: [PATCH 1/2] Add new natives RG_CBasePlayerItem_Materialize, RG_CBasePlayerItem_CheckRespawn --- .../scripting/include/reapi_gamedll_const.inc | 18 +++++++++++++++ reapi/include/cssdk/dlls/regamedll_api.h | 12 ++++++++++ reapi/src/hook_callback.cpp | 22 +++++++++++++++++++ reapi/src/hook_callback.h | 2 ++ reapi/src/hook_list.cpp | 11 ++++++++++ reapi/src/hook_list.h | 12 ++++++++++ 6 files changed, 77 insertions(+) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 30c0f559..e41bb4e8 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -942,6 +942,24 @@ enum GamedllFunc_CBasePlayer RG_CBasePlayer_RemoveAllItems, }; +/** +* GamedllFunc CBasePlayerItem +*/ +enum GamedllFunc_CBasePlayerItem +{ + /* + * Description: - + * Params: (const this) + */ + RG_CBasePlayerItem_Materialize = BEGIN_FUNC_REGION(cbaseplayeritem), + + /* + * Description: - + * Params: (const this) + */ + RG_CBasePlayerItem_CheckRespawn, +} + /** * GamedllFunc CBasePlayer */ diff --git a/reapi/include/cssdk/dlls/regamedll_api.h b/reapi/include/cssdk/dlls/regamedll_api.h index c0aa993a..2952336b 100644 --- a/reapi/include/cssdk/dlls/regamedll_api.h +++ b/reapi/include/cssdk/dlls/regamedll_api.h @@ -630,6 +630,15 @@ typedef IHookChainRegistryClass IReGameHookRegistry_CBa typedef IHookChainClass IReGameHook_CBasePlayer_RemoveAllItems; typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_RemoveAllItems; +// CBasePlayerItem::Materialize hook +typedef IHookChainClass IReGameHook_CBasePlayerItem_Materialize; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayerItem_Materialize; + +// CBasePlayerItem::CheckRespawn hook +typedef IHookChainClass IReGameHook_CBasePlayerItem_CheckRespawn; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayerItem_CheckRespawn; + + class IReGameHookchains { public: virtual ~IReGameHookchains() {} @@ -792,6 +801,9 @@ class IReGameHookchains { virtual IReGameHookRegistry_CBasePlayer_PlayerDeathThink *CBasePlayer_PlayerDeathThink() = 0; virtual IReGameHookRegistry_CBasePlayer_Observer_Think *CBasePlayer_Observer_Think() = 0; virtual IReGameHookRegistry_CBasePlayer_RemoveAllItems *CBasePlayer_RemoveAllItems() = 0; + + virtual IReGameHookRegistry_CBasePlayerItem_Materialize *CBasePlayerItem_Materialize() = 0; + virtual IReGameHookRegistry_CBasePlayerItem_CheckRespawn *CBasePlayerItem_CheckRespawn() = 0; }; struct ReGameFuncs_t { diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index fb228ad6..b8a1c5f2 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -1766,6 +1766,28 @@ void CSGameRules_SendDeathMessage(IReGameHook_CSGameRules_SendDeathMessage *chai callVoidForward(RG_CSGameRules_SendDeathMessage, original, indexOfPDataAmx(pKiller), indexOfEdict(pVictim->pev), indexOfPDataAmx(pAssister), indexOfEdictAmx(pevInflictor), killerWeaponName, iDeathMessageFlags, iRarityOfKill); } +void CBasePlayerItem_Materialize(IReGameHook_CBasePlayerItem_Materialize *chain, CBasePlayerItem *pthis) +{ + auto original = [chain](int _pthis) + { + chain->callNext(getPrivate(_pthis)); + }; + + callVoidForward(RG_CBasePlayerItem_Materialize, original, indexOfEdict(pthis->pev)); +} + + +void CBasePlayerItem_CheckRespawn(IReGameHook_CBasePlayerItem_CheckRespawn *chain, CBasePlayerItem *pthis) +{ + auto original = [chain](int _pthis) + { + chain->callNext(getPrivate(_pthis)); + }; + + callVoidForward(RG_CBasePlayerItem_CheckRespawn, original, indexOfEdict(pthis->pev)); +} + + /* * VTC functions */ diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index 84356d3a..764c4832 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -566,6 +566,8 @@ void CBasePlayer_PlayerDeathThink(IReGameHook_CBasePlayer_PlayerDeathThink *chai void CBasePlayer_Observer_Think(IReGameHook_CBasePlayer_Observer_Think *chain, CBasePlayer *pthis); void CBasePlayer_RemoveAllItems(IReGameHook_CBasePlayer_RemoveAllItems *chain, CBasePlayer *pthis, BOOL removeSuit); void CSGameRules_SendDeathMessage(IReGameHook_CSGameRules_SendDeathMessage *chain, CBaseEntity *pKiller, CBasePlayer *pVictim, CBasePlayer *pAssister, entvars_t *pevInflictor, const char *killerWeaponName, int iDeathMessageFlags, int iRarityOfKill); +void CBasePlayerItem_Materialize(IReGameHook_CBasePlayerItem_Materialize *chain, CBasePlayerItem *pthis); +void CBasePlayerItem_CheckRespawn(IReGameHook_CBasePlayerItem_CheckRespawn *chain, CBasePlayerItem *pthis); /* * VTC functions diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index df094509..7b1c8dc1 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -216,6 +216,7 @@ hook_t hooklist_player[] = { DLL(CBasePlayer_PlayerDeathThink), DLL(CBasePlayer_Observer_Think), DLL(CBasePlayer_RemoveAllItems), + }; hook_t hooklist_gamerules[] = { @@ -289,6 +290,14 @@ hook_t hooklist_botmanager[] = { DLL(CBotManager_OnEvent), }; +hook_t hooklist_cbaseplayeritem[] = { + DLL(CBasePlayerItem_Materialize), + DLL(CBasePlayerItem_CheckRespawn), +}; + + + + #define RCHECK(h,...) { {}, {}, #h, "ReChecker", [](){ return api_cfg.hasRechecker(); }, ((!(RC_##h & (MAX_REGION_RANGE - 1)) ? regfunc::current_cell = 1, true : false) || (RC_##h & (MAX_REGION_RANGE - 1)) == regfunc::current_cell++) ? regfunc(h##__VA_ARGS__) : regfunc(#h#__VA_ARGS__), [](){ g_RecheckerHookchains->h()->registerHook(&h); }, [](){ g_RecheckerHookchains->h()->unregisterHook(&h); }, false} hook_t hooklist_rechecker[] = { RCHECK(FileConsistencyProcess, _AMXX), @@ -316,6 +325,7 @@ hook_t* hooklist_t::getHookSafe(size_t hook) CASE(gib) CASE(cbaseentity) CASE(botmanager) + CASE(cbaseplayeritem) } return nullptr; @@ -337,6 +347,7 @@ void hooklist_t::clear() FOREACH_CLEAR(gib); FOREACH_CLEAR(cbaseentity); FOREACH_CLEAR(botmanager); + FOREACH_CLEAR(cbaseplayeritem); } void hook_t::clear() diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 1618afd4..6f20b595 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -39,6 +39,7 @@ extern hook_t hooklist_weapon[]; extern hook_t hooklist_gib[]; extern hook_t hooklist_cbaseentity[]; extern hook_t hooklist_botmanager[]; +extern hook_t hooklist_cbaseplayeritem[]; enum { @@ -67,6 +68,7 @@ struct hooklist_t CASE(gib) CASE(cbaseentity) CASE(botmanager) + CASE(cbaseplayeritem) } #undef CASE @@ -91,6 +93,7 @@ struct hooklist_t ht_gib, ht_cbaseentity, ht_botmanager, + ht_cbaseplayeritem, }; }; @@ -345,3 +348,12 @@ enum ReCheckerFunc // [...] }; + + +enum GamedllFunc_CBasePlayerItem +{ + RG_CBasePlayerItem_Materialize = BEGIN_FUNC_REGION(cbaseplayeritem), + RG_CBasePlayerItem_CheckRespawn, + + // [...] +}; \ No newline at end of file From 25bdd34b95dee954558e9e85f40de4f8ae6b38db Mon Sep 17 00:00:00 2001 From: Celio Lozatto Date: Thu, 15 Aug 2024 12:42:13 -0300 Subject: [PATCH 2/2] Add new natives RG_CBasePlayerItem_Materialize, RG_CBasePlayerItem_CheckRespawn --- .../extra/amxmodx/scripting/include/reapi.inc | 3 ++- .../scripting/include/reapi_gamedll_const.inc | 18 +++++++++++++++ reapi/include/cssdk/dlls/regamedll_api.h | 12 ++++++++++ reapi/src/hook_callback.cpp | 22 +++++++++++++++++++ reapi/src/hook_callback.h | 2 ++ reapi/src/hook_list.cpp | 11 ++++++++++ reapi/src/hook_list.h | 12 ++++++++++ 7 files changed, 79 insertions(+), 1 deletion(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi.inc b/reapi/extra/amxmodx/scripting/include/reapi.inc index 16160295..817ec5bd 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi.inc @@ -26,7 +26,8 @@ enum hooks_tables_e ht_weapon, ht_gib, ht_cbaseentity, - ht_botmanager + ht_botmanager, + ht_cbaseplayeritem }; enum members_tables_e diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 30c0f559..e41bb4e8 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -942,6 +942,24 @@ enum GamedllFunc_CBasePlayer RG_CBasePlayer_RemoveAllItems, }; +/** +* GamedllFunc CBasePlayerItem +*/ +enum GamedllFunc_CBasePlayerItem +{ + /* + * Description: - + * Params: (const this) + */ + RG_CBasePlayerItem_Materialize = BEGIN_FUNC_REGION(cbaseplayeritem), + + /* + * Description: - + * Params: (const this) + */ + RG_CBasePlayerItem_CheckRespawn, +} + /** * GamedllFunc CBasePlayer */ diff --git a/reapi/include/cssdk/dlls/regamedll_api.h b/reapi/include/cssdk/dlls/regamedll_api.h index c0aa993a..2952336b 100644 --- a/reapi/include/cssdk/dlls/regamedll_api.h +++ b/reapi/include/cssdk/dlls/regamedll_api.h @@ -630,6 +630,15 @@ typedef IHookChainRegistryClass IReGameHookRegistry_CBa typedef IHookChainClass IReGameHook_CBasePlayer_RemoveAllItems; typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_RemoveAllItems; +// CBasePlayerItem::Materialize hook +typedef IHookChainClass IReGameHook_CBasePlayerItem_Materialize; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayerItem_Materialize; + +// CBasePlayerItem::CheckRespawn hook +typedef IHookChainClass IReGameHook_CBasePlayerItem_CheckRespawn; +typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayerItem_CheckRespawn; + + class IReGameHookchains { public: virtual ~IReGameHookchains() {} @@ -792,6 +801,9 @@ class IReGameHookchains { virtual IReGameHookRegistry_CBasePlayer_PlayerDeathThink *CBasePlayer_PlayerDeathThink() = 0; virtual IReGameHookRegistry_CBasePlayer_Observer_Think *CBasePlayer_Observer_Think() = 0; virtual IReGameHookRegistry_CBasePlayer_RemoveAllItems *CBasePlayer_RemoveAllItems() = 0; + + virtual IReGameHookRegistry_CBasePlayerItem_Materialize *CBasePlayerItem_Materialize() = 0; + virtual IReGameHookRegistry_CBasePlayerItem_CheckRespawn *CBasePlayerItem_CheckRespawn() = 0; }; struct ReGameFuncs_t { diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index fb228ad6..b8a1c5f2 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -1766,6 +1766,28 @@ void CSGameRules_SendDeathMessage(IReGameHook_CSGameRules_SendDeathMessage *chai callVoidForward(RG_CSGameRules_SendDeathMessage, original, indexOfPDataAmx(pKiller), indexOfEdict(pVictim->pev), indexOfPDataAmx(pAssister), indexOfEdictAmx(pevInflictor), killerWeaponName, iDeathMessageFlags, iRarityOfKill); } +void CBasePlayerItem_Materialize(IReGameHook_CBasePlayerItem_Materialize *chain, CBasePlayerItem *pthis) +{ + auto original = [chain](int _pthis) + { + chain->callNext(getPrivate(_pthis)); + }; + + callVoidForward(RG_CBasePlayerItem_Materialize, original, indexOfEdict(pthis->pev)); +} + + +void CBasePlayerItem_CheckRespawn(IReGameHook_CBasePlayerItem_CheckRespawn *chain, CBasePlayerItem *pthis) +{ + auto original = [chain](int _pthis) + { + chain->callNext(getPrivate(_pthis)); + }; + + callVoidForward(RG_CBasePlayerItem_CheckRespawn, original, indexOfEdict(pthis->pev)); +} + + /* * VTC functions */ diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index 84356d3a..764c4832 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -566,6 +566,8 @@ void CBasePlayer_PlayerDeathThink(IReGameHook_CBasePlayer_PlayerDeathThink *chai void CBasePlayer_Observer_Think(IReGameHook_CBasePlayer_Observer_Think *chain, CBasePlayer *pthis); void CBasePlayer_RemoveAllItems(IReGameHook_CBasePlayer_RemoveAllItems *chain, CBasePlayer *pthis, BOOL removeSuit); void CSGameRules_SendDeathMessage(IReGameHook_CSGameRules_SendDeathMessage *chain, CBaseEntity *pKiller, CBasePlayer *pVictim, CBasePlayer *pAssister, entvars_t *pevInflictor, const char *killerWeaponName, int iDeathMessageFlags, int iRarityOfKill); +void CBasePlayerItem_Materialize(IReGameHook_CBasePlayerItem_Materialize *chain, CBasePlayerItem *pthis); +void CBasePlayerItem_CheckRespawn(IReGameHook_CBasePlayerItem_CheckRespawn *chain, CBasePlayerItem *pthis); /* * VTC functions diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index df094509..7b1c8dc1 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -216,6 +216,7 @@ hook_t hooklist_player[] = { DLL(CBasePlayer_PlayerDeathThink), DLL(CBasePlayer_Observer_Think), DLL(CBasePlayer_RemoveAllItems), + }; hook_t hooklist_gamerules[] = { @@ -289,6 +290,14 @@ hook_t hooklist_botmanager[] = { DLL(CBotManager_OnEvent), }; +hook_t hooklist_cbaseplayeritem[] = { + DLL(CBasePlayerItem_Materialize), + DLL(CBasePlayerItem_CheckRespawn), +}; + + + + #define RCHECK(h,...) { {}, {}, #h, "ReChecker", [](){ return api_cfg.hasRechecker(); }, ((!(RC_##h & (MAX_REGION_RANGE - 1)) ? regfunc::current_cell = 1, true : false) || (RC_##h & (MAX_REGION_RANGE - 1)) == regfunc::current_cell++) ? regfunc(h##__VA_ARGS__) : regfunc(#h#__VA_ARGS__), [](){ g_RecheckerHookchains->h()->registerHook(&h); }, [](){ g_RecheckerHookchains->h()->unregisterHook(&h); }, false} hook_t hooklist_rechecker[] = { RCHECK(FileConsistencyProcess, _AMXX), @@ -316,6 +325,7 @@ hook_t* hooklist_t::getHookSafe(size_t hook) CASE(gib) CASE(cbaseentity) CASE(botmanager) + CASE(cbaseplayeritem) } return nullptr; @@ -337,6 +347,7 @@ void hooklist_t::clear() FOREACH_CLEAR(gib); FOREACH_CLEAR(cbaseentity); FOREACH_CLEAR(botmanager); + FOREACH_CLEAR(cbaseplayeritem); } void hook_t::clear() diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 1618afd4..6f20b595 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -39,6 +39,7 @@ extern hook_t hooklist_weapon[]; extern hook_t hooklist_gib[]; extern hook_t hooklist_cbaseentity[]; extern hook_t hooklist_botmanager[]; +extern hook_t hooklist_cbaseplayeritem[]; enum { @@ -67,6 +68,7 @@ struct hooklist_t CASE(gib) CASE(cbaseentity) CASE(botmanager) + CASE(cbaseplayeritem) } #undef CASE @@ -91,6 +93,7 @@ struct hooklist_t ht_gib, ht_cbaseentity, ht_botmanager, + ht_cbaseplayeritem, }; }; @@ -345,3 +348,12 @@ enum ReCheckerFunc // [...] }; + + +enum GamedllFunc_CBasePlayerItem +{ + RG_CBasePlayerItem_Materialize = BEGIN_FUNC_REGION(cbaseplayeritem), + RG_CBasePlayerItem_CheckRespawn, + + // [...] +}; \ No newline at end of file