From eee79dc902a848653aa06884985e040a5ade90b0 Mon Sep 17 00:00:00 2001 From: Krzyhau Date: Mon, 27 Nov 2023 15:34:04 +0100 Subject: [PATCH] fix: dirty hack to fix both angle decays --- src/Modules/Client.cpp | 24 ++++++++++++++++++++++++ src/Modules/Client.hpp | 3 +++ src/OffsetsData.hpp | 1 + 3 files changed, 28 insertions(+) diff --git a/src/Modules/Client.cpp b/src/Modules/Client.cpp index 476faa7c2..1b831c5bc 100644 --- a/src/Modules/Client.cpp +++ b/src/Modules/Client.cpp @@ -47,6 +47,7 @@ Variable r_drawviewmodel; Variable sar_disable_coop_score_hud("sar_disable_coop_score_hud", "0", "Disables the coop score HUD which appears in demo playback.\n"); Variable sar_disable_save_status_hud("sar_disable_save_status_hud", "0", "Disables the saving/saved HUD which appears when you make a save.\n"); +Variable sar_remove_angle_decay("sar_disable_angle_decay", "0", 0, 2, "Removes angle decay.\n1 - remove small decay only.\n2 - remove angle decay entirely.\n"); REDECL(Client::LevelInitPreEntity); REDECL(Client::CreateMove); @@ -59,6 +60,7 @@ REDECL(Client::GetTextColorForClient); REDECL(Client::DecodeUserCmdFromBuffer); REDECL(Client::CInput_CreateMove); REDECL(Client::GetButtonBits); +REDECL(Client::ApplyMouse); REDECL(Client::SteamControllerMove); REDECL(Client::playvideo_end_level_transition_callback); REDECL(Client::OverrideView); @@ -402,6 +404,27 @@ DETOUR(Client::GetButtonBits, bool bResetState) { return bits; } +// CInput::ApplyMouse +DETOUR(Client::ApplyMouse, int nSlot, QAngle &viewangles, CUserCmd *cmd, float mouse_x, float mouse_y) { + + auto lastViewAngles = viewangles; + + auto playerLocal = client->GetPlayer(nSlot + 1)->portal_local(); + + auto result = Client::ApplyMouse(thisptr, nSlot, viewangles, cmd, mouse_x, mouse_y); + + if (sar_remove_angle_decay.GetBool()) { + if ( + !mouse_x && !mouse_y && !viewangles.z && + (sar_remove_angle_decay.GetInt() > 1 || fabsf(viewangles.x) < 45.0f) + ) { + viewangles = lastViewAngles; + } + } + + return result; +} + // CInput::SteamControllerMove DETOUR(Client::SteamControllerMove, int nSlot, float flFrametime, CUserCmd *cmd) { auto result = Client::SteamControllerMove(thisptr, nSlot, flFrametime, cmd); @@ -580,6 +603,7 @@ bool Client::Init() { g_Input->Hook(Client::DecodeUserCmdFromBuffer_Hook, Client::DecodeUserCmdFromBuffer, Offsets::DecodeUserCmdFromBuffer); g_Input->Hook(Client::GetButtonBits_Hook, Client::GetButtonBits, Offsets::GetButtonBits); g_Input->Hook(Client::SteamControllerMove_Hook, Client::SteamControllerMove, Offsets::SteamControllerMove); + g_Input->Hook(Client::ApplyMouse_Hook, Client::ApplyMouse, Offsets::ApplyMouse); in_forceuser = Variable("in_forceuser"); if (!!in_forceuser && this->g_Input) { diff --git a/src/Modules/Client.hpp b/src/Modules/Client.hpp index 941d9cbc9..e23850a51 100644 --- a/src/Modules/Client.hpp +++ b/src/Modules/Client.hpp @@ -119,6 +119,9 @@ class Client : public Module { // CInput::GetButtonBits DECL_DETOUR(GetButtonBits, bool bResetState); + // CInput::ApplyMouse + DECL_DETOUR(ApplyMouse, int nSlot, QAngle &viewangles, CUserCmd *cmd, float mouse_x, float mouse_y); + // CInput::SteamControllerMove DECL_DETOUR(SteamControllerMove, int nSlot, float flFrametime, CUserCmd *cmd); // is it slot though? :thinking: diff --git a/src/OffsetsData.hpp b/src/OffsetsData.hpp index 1abbc71a8..dcc66a3fa 100644 --- a/src/OffsetsData.hpp +++ b/src/OffsetsData.hpp @@ -36,6 +36,7 @@ OFFSET_DEFAULT(GetAllClasses, 8, 8) OFFSET_DEFAULT(HudProcessInput, 10, 10) OFFSET_DEFAULT(IN_ActivateMouse, 15, 15) OFFSET_DEFAULT(IN_DeactivateMouse, 16, 16) +OFFSET_DEFAULT(ApplyMouse, 56, 56) OFFSET_DEFAULT(SteamControllerMove, 58, 58) OFFSET_DEFAULT(LevelInitPreEntity, 5, 5)