2
0
mirror of https://github.com/rehlds/reapi.git synced 2025-01-14 15:48:03 +03:00

Implement RG_CBasePlayerWeapon_CanDeploy & CBasePlayerWeapon_DefaultDeploy hooks (#150)

* Implement RG_CBasePlayerWeapon_CanDeploy & CBasePlayerWeapon_DefaultDeploy hooks
* Implement RG_CBasePlayerWeapon_CanDeploy & CBasePlayerWeapon_DefaultDeploy hooks
* Implement RG_CBasePlayerWeapon_DefaultReload hook
* ImplementRG_ CBasePlayerWeapon_DefaultShotgunReload hook
This commit is contained in:
fant1kua 2019-10-27 16:20:23 +02:00 committed by Dmitry Novikov
parent 45584b6716
commit 9874820989
8 changed files with 127 additions and 5 deletions

View File

@ -1,3 +1,3 @@
majorVersion=5
minorVersion=10
minorVersion=11
maintenanceVersion=0

View File

@ -22,7 +22,8 @@ enum hooks_tables_e
ht_gamerules,
ht_rechecker,
ht_grenade,
ht_weaponbox
ht_weaponbox,
ht_weapon
};
enum members_tables_e
@ -136,7 +137,7 @@ enum HookChain
*
* @return Returns a hook handle. Use EnableHookChain/DisableHookChain to toggle the forward on or off
*/
native HookChain:RegisterHookChain({EngineFunc, GamedllFunc, GamedllFunc_CBaseAnimating, GamedllFunc_CBasePlayer, GamedllFunc_CSGameRules, GamedllFunc_CGrenade, GamedllFunc_CWeaponBox, ReCheckerFunc}:function_id, const callback[], post = 0);
native HookChain:RegisterHookChain({EngineFunc, GamedllFunc, GamedllFunc_CBaseAnimating, GamedllFunc_CBasePlayer, GamedllFunc_CSGameRules, GamedllFunc_CGrenade, GamedllFunc_CWeaponBox, ReCheckerFunc, GamedllFunc_CBasePlayerWeapon}:function_id, const callback[], post = 0);
/*
* Stops a hook from triggering.

View File

@ -763,6 +763,40 @@ enum GamedllFunc_CBasePlayer
RG_CBasePlayer_UseEmpty,
};
/**
* GamedllFunc CBasePlayer
*/
enum GamedllFunc_CBasePlayerWeapon
{
/*
* Description: -
* Return type: BOOL
* Params: (const this)
*/
RG_CBasePlayerWeapon_CanDeploy = BEGIN_FUNC_REGION(weapon),
/*
* Description: -
* Return type: BOOL
* Params: (const this, szViewModel[], szWeaponModel[], iAnim, szAnimExt[], skiplocal)
*/
RG_CBasePlayerWeapon_DefaultDeploy,
/*
* Description: -
* Return type: int
* Params: (const this, iClipSize, iAnim, Float:fDelay)
*/
RG_CBasePlayerWeapon_DefaultReload,
/*
* Description: -
* Return type: bool
* Params: (const this, iAnim, iStartAnim, Float:fDelay, Float:fStartDelay, const pszReloadSound1[], const pszReloadSound2[])
*/
RG_CBasePlayerWeapon_DefaultShotgunReload,
};
/**
* GamedllFunc CSGameRules
*/

View File

@ -38,7 +38,7 @@
#include <API/CSInterfaces.h>
#define REGAMEDLL_API_VERSION_MAJOR 5
#define REGAMEDLL_API_VERSION_MINOR 11
#define REGAMEDLL_API_VERSION_MINOR 12
// CBasePlayer::Spawn hook
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_Spawn;
@ -444,6 +444,22 @@ typedef IHookChainRegistryClass<bool, class CBasePlayer, const char *, float, bo
typedef IHookChainClass<void, class CBasePlayer> IReGameHook_CBasePlayer_UseEmpty;
typedef IHookChainRegistryClass<void, class CBasePlayer> IReGameHookRegistry_CBasePlayer_UseEmpty;
// CBasePlayerWeapon::CanDeploy hook
typedef IHookChainClass<BOOL, class CBasePlayerWeapon> IReGameHook_CBasePlayerWeapon_CanDeploy;
typedef IHookChainRegistryClass<BOOL, class CBasePlayerWeapon> IReGameHookRegistry_CBasePlayerWeapon_CanDeploy;
// CBasePlayerWeapon::DefaultDeploy hook
typedef IHookChainClass<BOOL, class CBasePlayerWeapon, char *, char *, int, char *, int> IReGameHook_CBasePlayerWeapon_DefaultDeploy;
typedef IHookChainRegistryClass<BOOL, class CBasePlayerWeapon, char *, char *, int, char *, int> IReGameHookRegistry_CBasePlayerWeapon_DefaultDeploy;
// CBasePlayerWeapon::DefaultReload hook
typedef IHookChainClass<int, class CBasePlayerWeapon, int, int, float> IReGameHook_CBasePlayerWeapon_DefaultReload;
typedef IHookChainRegistryClass<int, class CBasePlayerWeapon, int, int, float> IReGameHookRegistry_CBasePlayerWeapon_DefaultReload;
// CBasePlayerWeapon::DefaultShotgunReload hook
typedef IHookChainClass<bool, class CBasePlayerWeapon, int, int, float, float, const char *, const char *> IReGameHook_CBasePlayerWeapon_DefaultShotgunReload;
typedef IHookChainRegistryClass<bool, class CBasePlayerWeapon, int, int, float, float, const char *, const char *> IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload;
class IReGameHookchains {
public:
virtual ~IReGameHookchains() {}
@ -554,6 +570,10 @@ public:
virtual IReGameHookRegistry_IsPenetrableEntity *IsPenetrableEntity() = 0;
virtual IReGameHookRegistry_CBasePlayer_HintMessageEx *CBasePlayer_HintMessageEx() = 0;
virtual IReGameHookRegistry_CBasePlayer_UseEmpty *CBasePlayer_UseEmpty() = 0;
virtual IReGameHookRegistry_CBasePlayerWeapon_CanDeploy *CBasePlayerWeapon_CanDeploy() = 0;
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultDeploy *CBasePlayerWeapon_DefaultDeploy() = 0;
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultReload *CBasePlayerWeapon_DefaultReload() = 0;
virtual IReGameHookRegistry_CBasePlayerWeapon_DefaultShotgunReload *CBasePlayerWeapon_DefaultShotgunReload() = 0;
};
struct ReGameFuncs_t {

View File

@ -562,6 +562,46 @@ void CBaseAnimating_ResetSequenceInfo(IReGameHook_CBaseAnimating_ResetSequenceIn
callVoidForward(RG_CBaseAnimating_ResetSequenceInfo, original, indexOfEdict(pthis->pev));
}
BOOL CBasePlayerWeapon_CanDeploy(IReGameHook_CBasePlayerWeapon_CanDeploy *chain, CBasePlayerWeapon *pthis)
{
auto original = [chain](int _pthis)
{
return chain->callNext(getPrivate<CBasePlayerWeapon>(_pthis));
};
return callForward<BOOL>(RG_CBasePlayerWeapon_CanDeploy, original, indexOfEdict(pthis->pev));
}
BOOL CBasePlayerWeapon_DefaultDeploy(IReGameHook_CBasePlayerWeapon_DefaultDeploy *chain, CBasePlayerWeapon *pthis, char *szViewModel, char *szWeaponModel, int iAnim, char *szAnimExt, int skiplocal)
{
auto original = [chain](int _pthis, char *_szViewModel, char *_szWeaponModel, int _iAnim, char *_szAnimExt, int _skiplocal)
{
return chain->callNext(getPrivate<CBasePlayerWeapon>(_pthis), _szViewModel, _szWeaponModel, _iAnim, _szAnimExt, _skiplocal);
};
return callForward<BOOL>(RG_CBasePlayerWeapon_DefaultDeploy, original, indexOfEdict(pthis->pev), szViewModel, szWeaponModel, iAnim, szAnimExt, skiplocal);
}
int CBasePlayerWeapon_DefaultReload(IReGameHook_CBasePlayerWeapon_DefaultReload *chain, CBasePlayerWeapon *pthis, int iClipSize, int iAnim, float fDelay)
{
auto original = [chain](int _pthis, int _iClipSize, int _iAnim, float _fDelay)
{
return chain->callNext(getPrivate<CBasePlayerWeapon>(_pthis), _iClipSize, _iAnim, _fDelay);
};
return callForward<int>(RG_CBasePlayerWeapon_DefaultReload, original, indexOfEdict(pthis->pev), iClipSize, iAnim, fDelay);
}
bool CBasePlayerWeapon_DefaultShotgunReload(IReGameHook_CBasePlayerWeapon_DefaultShotgunReload *chain, CBasePlayerWeapon *pthis, int iAnim, int iStartAnim, float fDelay, float fStartDelay, const char *pszReloadSound1, const char *pszReloadSound2)
{
auto original = [chain](int _pthis, int _iAnim, int _iStartAnim, float _fDelay, float _fStartDelay, const char *_pszReloadSound1, const char *_pszReloadSound2)
{
return chain->callNext(getPrivate<CBasePlayerWeapon>(_pthis), _iAnim, _iStartAnim, _fDelay, _fStartDelay, _pszReloadSound1, _pszReloadSound2);
};
return callForward<int>(RG_CBasePlayerWeapon_DefaultShotgunReload, original, indexOfEdict(pthis->pev), iAnim, iStartAnim, fDelay, fStartDelay, pszReloadSound1, pszReloadSound2);
}
int GetForceCamera(IReGameHook_GetForceCamera *chain, CBasePlayer *pObserver)
{
auto original = [chain](int _pObserver)

View File

@ -392,6 +392,11 @@ void CBasePlayer_UseEmpty(IReGameHook_CBasePlayer_UseEmpty *chain, CBasePlayer *
void CBaseAnimating_ResetSequenceInfo(IReGameHook_CBaseAnimating_ResetSequenceInfo *chain, CBaseAnimating *pthis);
BOOL CBasePlayerWeapon_CanDeploy(IReGameHook_CBasePlayerWeapon_CanDeploy *chain, CBasePlayerWeapon *pthis);
BOOL CBasePlayerWeapon_DefaultDeploy(IReGameHook_CBasePlayerWeapon_DefaultDeploy *chain, CBasePlayerWeapon *pthis, char *szViewModel, char *szWeaponModel, int iAnim, char *szAnimExt, int skiplocal);
int CBasePlayerWeapon_DefaultReload(IReGameHook_CBasePlayerWeapon_DefaultReload *chain, CBasePlayerWeapon *pthis, int iClipSize, int iAnim, float fDelay);
bool CBasePlayerWeapon_DefaultShotgunReload(IReGameHook_CBasePlayerWeapon_DefaultShotgunReload *chain, CBasePlayerWeapon *pthis, int iAnim, int iStartAnim, float fDelay, float fStartDelay, const char *pszReloadSound1, const char *pszReloadSound2);
BOOL CSGameRules_FShouldSwitchWeapon(IReGameHook_CSGameRules_FShouldSwitchWeapon *chain, CBasePlayer *pPlayer, CBasePlayerItem *pWeapon);
BOOL CSGameRules_GetNextBestWeapon(IReGameHook_CSGameRules_GetNextBestWeapon *chain, CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon);
float CSGameRules_FlPlayerFallDamage(IReGameHook_CSGameRules_FlPlayerFallDamage *chain, CBasePlayer *pPlayer);

View File

@ -197,6 +197,13 @@ hook_t hooklist_weaponbox[] = {
DLL(CWeaponBox_SetModel),
};
hook_t hooklist_weapon[] = {
DLL(CBasePlayerWeapon_CanDeploy),
DLL(CBasePlayerWeapon_DefaultDeploy),
DLL(CBasePlayerWeapon_DefaultReload),
DLL(CBasePlayerWeapon_DefaultShotgunReload),
};
#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); }}
hook_t hooklist_rechecker[] = {
RCHECK(FileConsistencyProcess, _AMXX),
@ -220,6 +227,7 @@ hook_t* hooklist_t::getHookSafe(size_t hook)
CASE(rechecker)
CASE(grenade)
CASE(weaponbox)
CASE(weapon)
}
return nullptr;
@ -237,6 +245,7 @@ void hooklist_t::clear()
FOREACH_CLEAR(rechecker);
FOREACH_CLEAR(grenade);
FOREACH_CLEAR(weaponbox);
FOREACH_CLEAR(weapon);
}
void hook_t::clear()

View File

@ -33,6 +33,7 @@ extern hook_t hooklist_gamerules[];
extern hook_t hooklist_rechecker[];
extern hook_t hooklist_grenade[];
extern hook_t hooklist_weaponbox[];
extern hook_t hooklist_weapon[];
enum
{
@ -57,6 +58,7 @@ struct hooklist_t
CASE(rechecker)
CASE(grenade)
CASE(weaponbox)
CASE(weapon)
}
#undef CASE
@ -76,7 +78,8 @@ struct hooklist_t
ht_gamerules,
ht_rechecker,
ht_grenade,
ht_weaponbox
ht_weaponbox,
ht_weapon
};
};
@ -200,6 +203,16 @@ enum GamedllFunc_CWeaponBox
// [...]
};
enum GamedllFunc_CBasePlayerWeapon
{
RG_CBasePlayerWeapon_CanDeploy = BEGIN_FUNC_REGION(weapon),
RG_CBasePlayerWeapon_DefaultDeploy,
RG_CBasePlayerWeapon_DefaultReload,
RG_CBasePlayerWeapon_DefaultShotgunReload,
// [...]
};
enum GamedllFunc_CSGameRules
{
// CSGameRules virtual