Server: add cvar that allows enabling/disabling view punch when taking damage

This commit is contained in:
Kawe Mazidjatari 2024-08-07 13:01:50 +02:00
parent 907e0fd8bc
commit ffb8c5992d
2 changed files with 17 additions and 0 deletions

View File

@ -195,6 +195,19 @@ void CPlayer::SetLastUserCommand(CUserCmd* pUserCmd)
m_LastCmd.Copy(pUserCmd);
}
static ConVar player_applyViewPunch("player_applyViewPunch", "0", FCVAR_RELEASE, "Whether to apply view punch from damage.");
//------------------------------------------------------------------------------
// Purpose: applies view punch to player view angles when taking damage
// Input : *player (this) -
// inputInfo -
//------------------------------------------------------------------------------
void Player_ApplyViewPunch(CPlayer* thisptr, const CTakeDamageInfo* inputInfo)
{
if (player_applyViewPunch.GetBool())
CPlayer__ApplyViewPunch(thisptr, inputInfo);
}
//------------------------------------------------------------------------------
// Purpose: run physics simulation for player
// Input : *player (this) -
@ -263,4 +276,5 @@ static ConCommand sv_addbot("sv_addbot", CC_CreateFakePlayer_f, "Creates a bot o
void VPlayer::Detour(const bool bAttach) const
{
DetourSetup(&CPlayer__PhysicsSimulate, &Player_PhysicsSimulate, bAttach);
DetourSetup(&CPlayer__ApplyViewPunch, &Player_ApplyViewPunch, bAttach);
}

View File

@ -751,6 +751,7 @@ static_assert(sizeof(CPlayer) == 0x7EF0);
inline QAngle*(*CPlayer__EyeAngles)(CPlayer* pPlayer, QAngle* pAngles);
inline void(*CPlayer__PlayerRunCommand)(CPlayer* pPlayer, CUserCmd* pUserCmd, IMoveHelper* pMover);
inline bool(*CPlayer__PhysicsSimulate)(CPlayer* pPlayer, int numPerIteration, bool adjustTimeBase);
inline void(*CPlayer__ApplyViewPunch)(CPlayer* pPlayer, const CTakeDamageInfo* inputInfo);
///////////////////////////////////////////////////////////////////////////////
class VPlayer : public IDetour
@ -760,12 +761,14 @@ class VPlayer : public IDetour
LogFunAdr("CPlayer::EyeAngles", CPlayer__EyeAngles);
LogFunAdr("CPlayer::PlayerRunCommand", CPlayer__PlayerRunCommand);
LogFunAdr("CPlayer::PhysicsSimulate", CPlayer__PhysicsSimulate);
LogFunAdr("CPlayer::ApplyViewPunch", CPlayer__ApplyViewPunch);
}
virtual void GetFun(void) const
{
g_GameDll.FindPatternSIMD("40 53 48 83 EC 30 F2 0F 10 05 ?? ?? ?? ??").GetPtr(CPlayer__EyeAngles);
g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? 8B 03 49 81 C6 ?? ?? ?? ??").FollowNearCallSelf().GetPtr(CPlayer__PlayerRunCommand);
g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? 48 8B 15 ?? ?? ?? ?? 84 C0 74 06").FollowNearCallSelf().GetPtr(CPlayer__PhysicsSimulate);
g_GameDll.FindPatternSIMD("4C 8B DC 49 89 5B ?? 49 89 6B ?? 49 89 7B ?? 41 54 41 56 41 57 48 81 EC").GetPtr(CPlayer__ApplyViewPunch);
}
virtual void GetVar(void) const { }
virtual void GetCon(void) const { }