From 9eed7e0fc713d7f01ae2a8f8c107f14965ffc785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szab=C3=B3=20Erhard=20P=C3=A1l?= Date: Sat, 25 May 2024 17:11:37 +0200 Subject: [PATCH] Implement Check* Hooks - CheckGameOver - CheckTimeLimit - CheckFragLimit - CheckMaxRounds - CheckWinLimit --- .../scripting/include/reapi_gamedll_const.inc | 35 +++++++++++++ reapi/include/cssdk/dlls/gamerules.h | 7 +++ reapi/include/cssdk/dlls/regamedll_api.h | 26 ++++++++++ reapi/src/hook_callback.cpp | 50 +++++++++++++++++++ reapi/src/hook_callback.h | 6 +++ reapi/src/hook_list.cpp | 5 ++ reapi/src/hook_list.h | 5 ++ 7 files changed, 134 insertions(+) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 30c0f55..8ffa92f 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -1260,6 +1260,41 @@ enum GamedllFunc_CSGameRules * Params: (const pKiller, const pVictim, const pAssister, const pevInflictor, const killerWeaponName[], const DeathMessageFlags:iDeathMessageFlags, const KillRarity:iRarityOfKill) */ RG_CSGameRules_SendDeathMessage, + + /* + * Description: Called when the game over condition is being checked. + * Return type: bool + * Params: () + */ + RG_CSGameRules_CheckGameOver, + + /* + * Description: Called when the time limit condition is being checked. + * Return type: bool + * Params: () + */ + RG_CSGameRules_CheckTimeLimit, + + /* + * Description: Called when the frag limit condition is being checked. + * Return type: bool + * Params: () + */ + RG_CSGameRules_CheckFragLimit, + + /* + * Description: Called when the max rounds condition is being checked. + * Return type: bool + * Params: () + */ + RG_CSGameRules_CheckMaxRounds, + + /* + * Description: Called when the win limit condition is being checked. + * Return type: bool + * Params: () + */ + RG_CSGameRules_CheckWinLimit, }; /** diff --git a/reapi/include/cssdk/dlls/gamerules.h b/reapi/include/cssdk/dlls/gamerules.h index 5bb125d..2526e40 100644 --- a/reapi/include/cssdk/dlls/gamerules.h +++ b/reapi/include/cssdk/dlls/gamerules.h @@ -555,6 +555,13 @@ public: virtual void SendDeathMessage(CBaseEntity *pKiller, CBasePlayer *pVictim, CBasePlayer *pAssister, entvars_t *pevInflictor, const char *killerWeaponName, int iDeathMessageFlags, int iRarityOfKill) = 0; + // Check various conditions to end the map. + virtual BOOL CheckGameOver() = 0; + virtual BOOL CheckTimeLimit() = 0; + virtual BOOL CheckFragLimit() = 0; + virtual BOOL CheckMaxRounds() = 0; + virtual BOOL CheckWinLimit() = 0; + public: bool ShouldSkipShowMenu() const { return m_bSkipShowMenu; } void MarkShowMenuSkipped() { m_bSkipShowMenu = false; } diff --git a/reapi/include/cssdk/dlls/regamedll_api.h b/reapi/include/cssdk/dlls/regamedll_api.h index c0aa993..d8abb97 100644 --- a/reapi/include/cssdk/dlls/regamedll_api.h +++ b/reapi/include/cssdk/dlls/regamedll_api.h @@ -630,6 +630,26 @@ typedef IHookChainRegistryClass IReGameHookRegistry_CBa typedef IHookChainClass IReGameHook_CBasePlayer_RemoveAllItems; typedef IHookChainRegistryClass IReGameHookRegistry_CBasePlayer_RemoveAllItems; +// CHalfLifeMultiplay::CheckGameOver hook +typedef IHookChain IReGameHook_CSGameRules_CheckGameOver; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_CheckGameOver; + +// CHalfLifeMultiplay::CheckTimeLimit hook +typedef IHookChain IReGameHook_CSGameRules_CheckTimeLimit; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_CheckTimeLimit; + +// CHalfLifeMultiplay::CheckFragLimit hook +typedef IHookChain IReGameHook_CSGameRules_CheckFragLimit; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_CheckFragLimit; + +// CHalfLifeMultiplay::CheckMaxRounds hook +typedef IHookChain IReGameHook_CSGameRules_CheckMaxRounds; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_CheckMaxRounds; + +// CHalfLifeMultiplay::CheckWinLimit hook +typedef IHookChain IReGameHook_CSGameRules_CheckWinLimit; +typedef IHookChainRegistry IReGameHookRegistry_CSGameRules_CheckWinLimit; + class IReGameHookchains { public: virtual ~IReGameHookchains() {} @@ -792,6 +812,12 @@ public: 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_CSGameRules_CheckGameOver *CSGameRules_CheckGameOver() = 0; + virtual IReGameHookRegistry_CSGameRules_CheckTimeLimit *CSGameRules_CheckTimeLimit() = 0; + virtual IReGameHookRegistry_CSGameRules_CheckFragLimit *CSGameRules_CheckFragLimit() = 0; + virtual IReGameHookRegistry_CSGameRules_CheckMaxRounds *CSGameRules_CheckMaxRounds() = 0; + virtual IReGameHookRegistry_CSGameRules_CheckWinLimit *CSGameRules_CheckWinLimit() = 0; }; struct ReGameFuncs_t { diff --git a/reapi/src/hook_callback.cpp b/reapi/src/hook_callback.cpp index fb228ad..35bb5b1 100644 --- a/reapi/src/hook_callback.cpp +++ b/reapi/src/hook_callback.cpp @@ -1766,6 +1766,56 @@ void CSGameRules_SendDeathMessage(IReGameHook_CSGameRules_SendDeathMessage *chai callVoidForward(RG_CSGameRules_SendDeathMessage, original, indexOfPDataAmx(pKiller), indexOfEdict(pVictim->pev), indexOfPDataAmx(pAssister), indexOfEdictAmx(pevInflictor), killerWeaponName, iDeathMessageFlags, iRarityOfKill); } +BOOL CSGameRules_CheckGameOver(IReGameHook_CSGameRules_CheckGameOver *chain) +{ + auto original = [chain]() + { + return chain->callNext(); + }; + + return callForward(RG_CSGameRules_CheckGameOver, original); +} + +BOOL CSGameRules_CheckTimeLimit(IReGameHook_CSGameRules_CheckTimeLimit *chain) +{ + auto original = [chain]() + { + return chain->callNext(); + }; + + return callForward(RG_CSGameRules_CheckTimeLimit, original); +} + +BOOL CSGameRules_CheckFragLimit(IReGameHook_CSGameRules_CheckFragLimit *chain) +{ + auto original = [chain]() + { + return chain->callNext(); + }; + + return callForward(RG_CSGameRules_CheckFragLimit, original); +} + +BOOL CSGameRules_CheckMaxRounds(IReGameHook_CSGameRules_CheckMaxRounds *chain) +{ + auto original = [chain]() + { + return chain->callNext(); + }; + + return callForward(RG_CSGameRules_CheckMaxRounds, original); +} + +BOOL CSGameRules_CheckWinLimit(IReGameHook_CSGameRules_CheckWinLimit *chain) +{ + auto original = [chain]() + { + return chain->callNext(); + }; + + return callForward(RG_CSGameRules_CheckWinLimit, original); +} + /* * VTC functions */ diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index 84356d3..9bb491a 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -567,6 +567,12 @@ void CBasePlayer_Observer_Think(IReGameHook_CBasePlayer_Observer_Think *chain, C 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); +BOOL CSGameRules_CheckGameOver(IReGameHook_CSGameRules_CheckGameOver *chain); +BOOL CSGameRules_CheckTimeLimit(IReGameHook_CSGameRules_CheckTimeLimit *chain); +BOOL CSGameRules_CheckFragLimit(IReGameHook_CSGameRules_CheckFragLimit *chain); +BOOL CSGameRules_CheckMaxRounds(IReGameHook_CSGameRules_CheckMaxRounds *chain); +BOOL CSGameRules_CheckWinLimit(IReGameHook_CSGameRules_CheckWinLimit *chain); + /* * VTC functions */ diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index df09450..da5b1e7 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -248,6 +248,11 @@ hook_t hooklist_gamerules[] = { DLL(CSGameRules_TeamStacked), DLL(CSGameRules_PlayerGotWeapon), DLL(CSGameRules_SendDeathMessage), + DLL(CSGameRules_CheckGameOver), + DLL(CSGameRules_CheckTimeLimit), + DLL(CSGameRules_CheckFragLimit), + DLL(CSGameRules_CheckMaxRounds), + DLL(CSGameRules_CheckWinLimit), }; hook_t hooklist_grenade[] = { diff --git a/reapi/src/hook_list.h b/reapi/src/hook_list.h index 1618afd..795002b 100644 --- a/reapi/src/hook_list.h +++ b/reapi/src/hook_list.h @@ -308,6 +308,11 @@ enum GamedllFunc_CSGameRules RG_CSGameRules_TeamStacked, RG_CSGameRules_PlayerGotWeapon, RG_CSGameRules_SendDeathMessage, + RG_CSGameRules_CheckGameOver, + RG_CSGameRules_CheckTimeLimit, + RG_CSGameRules_CheckFragLimit, + RG_CSGameRules_CheckMaxRounds, + RG_CSGameRules_CheckWinLimit, // [...] };