From 0f8acb940e35f5489693e52ac75464a800cb74d9 Mon Sep 17 00:00:00 2001 From: Louvenarde Date: Sat, 14 Aug 2021 13:51:22 +0200 Subject: [PATCH] Better dvar handling --- src/Components/Loader.cpp | 2 +- src/Components/Modules/XInput.cpp | 35 ++++++++++++++++++------------- src/Components/Modules/XInput.hpp | 7 +++++++ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index a6c525f2..85dfabb6 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -101,9 +101,9 @@ namespace Components Loader::Register(new StructuredData()); Loader::Register(new ConnectProtocol()); Loader::Register(new StartupMessages()); + Loader::Register(new XInput()); Loader::Register(new Client()); - Loader::Register(new XInput()); Loader::Pregame = false; } diff --git a/src/Components/Modules/XInput.cpp b/src/Components/Modules/XInput.cpp index bd5e0e2e..26d1b079 100644 --- a/src/Components/Modules/XInput.cpp +++ b/src/Components/Modules/XInput.cpp @@ -11,6 +11,13 @@ namespace Components std::chrono::milliseconds XInput::timeAtFirstHeldMaxLookX = 0ms; // "For how much time in milliseconds has the player been holding a horizontal direction on their stick, fully" (-1.0 or 1.0) bool XInput::isHoldingMaxLookX = false; bool XInput::isADS; + + Dvar::Var XInput::xpadSensitivity; + Dvar::Var XInput::xpadEarlyTime; + Dvar::Var XInput::xpadEarlyMultiplier; + Dvar::Var XInput::xpadHorizontalMultiplier; + Dvar::Var XInput::xpadVerticalMultiplier; + Dvar::Var XInput::xpadAdsMultiplier; float XInput::lastMenuNavigationDirection = .0f; std::chrono::milliseconds XInput::lastNavigationTime = 0ms; @@ -380,12 +387,12 @@ namespace Components { XINPUT_STATE* xiState = &xiStates[xiPlayerNum]; - float viewSensitivityMultiplier = Dvar::Var("xpad_sensitivity").get() * XINPUT_SENSITIVITY_MULTIPLIER; + float viewSensitivityMultiplier = xpadSensitivity.get() * XINPUT_SENSITIVITY_MULTIPLIER; - float lockedSensitivityMultiplier = Dvar::Var("xpad_early_multiplier").get(); - float generalXSensitivityMultiplier = Dvar::Var("xpad_horizontal_multiplier").get(); - float generalYSensitivityMultiplier = Dvar::Var("xpad_vertical_multiplier").get(); - std::chrono::milliseconds msBeforeUnlockingSensitivity = std::chrono::milliseconds(Dvar::Var("xpad_early_time").get()); + float lockedSensitivityMultiplier = xpadEarlyMultiplier.get(); + float generalXSensitivityMultiplier = xpadHorizontalMultiplier.get(); + float generalYSensitivityMultiplier = xpadVerticalMultiplier.get(); + std::chrono::milliseconds msBeforeUnlockingSensitivity = std::chrono::milliseconds(xpadEarlyTime.get()); float viewStickX, viewStickY; GetRightStick01Value(xiState, viewStickX, viewStickY); @@ -416,8 +423,6 @@ namespace Components XInput::isHoldingMaxLookX = false; XInput::timeAtFirstHeldMaxLookX = 0ms; viewStickX *= lockedSensitivityMultiplier; - - Components::Logger::Print("multiplier will be %f\n", lockedSensitivityMultiplier); } float adsMultiplier = 1.0f; @@ -426,7 +431,7 @@ namespace Components // DO NOT use clientActive->usingAds ! It only works for toggle ADS if (Game::PM_IsAdsAllowed(ps) && XInput::isADS) { - adsMultiplier = Dvar::Var("xpad_ads_multiplier").get(); + adsMultiplier = xpadAdsMultiplier.get(); } if (viewStickX != 0 || viewStickY != 0) { @@ -512,13 +517,13 @@ namespace Components Utils::Hook(0x5A6816, CL_GetMouseMovementStub, HOOK_CALL).install()->quick(); Utils::Hook(0x5A6829, unk_CheckKeyHook, HOOK_CALL).install()->quick(); - Game::Dvar_RegisterFloat("xpad_sensitivity", 1.9f, 0.1f, 10.0f, Game::DVAR_FLAG_SAVED, "View sensitivity for XInput-compatible gamepads"); - Game::Dvar_RegisterInt("xpad_early_time", 130, 0, 1000, Game::DVAR_FLAG_SAVED, "Time (in milliseconds) of reduced view sensitivity"); - Game::Dvar_RegisterFloat("xpad_early_multiplier", 0.25f, 0.01f, 1.0f, Game::DVAR_FLAG_SAVED, "By how much the view sensitivity is multiplied during xpad_early_time when moving the view stick"); - Game::Dvar_RegisterFloat("xpad_horizontal_multiplier", 1.5f, 1.0f, 20.0f, Game::DVAR_FLAG_SAVED, "Horizontal view sensitivity multiplier"); - Game::Dvar_RegisterFloat("xpad_vertical_multiplier", 0.8f, 1.0f, 20.0f, Game::DVAR_FLAG_SAVED, "Vertical view sensitivity multiplier"); - Game::Dvar_RegisterFloat("xpad_ads_multiplier", 0.7f, 0.1f, 1.0f, Game::DVAR_FLAG_SAVED, "By how much the view sensitivity is multiplied when aiming down the sights."); - + XInput::xpadSensitivity = Dvar::Register("xpad_sensitivity", 1.9f, 0.1f, 10.0f, Game::DVAR_FLAG_SAVED, "View sensitivity for XInput-compatible gamepads"); + XInput::xpadEarlyTime = Dvar::Register("xpad_early_time", 130, 0, 1000, Game::DVAR_FLAG_SAVED, "Time (in milliseconds) of reduced view sensitivity"); + XInput::xpadEarlyMultiplier = Dvar::Register("xpad_early_multiplier", 0.25f, 0.01f, 1.0f, Game::DVAR_FLAG_SAVED, "By how much the view sensitivity is multiplied during xpad_early_time when moving the view stick"); + XInput::xpadHorizontalMultiplier = Dvar::Register("xpad_horizontal_multiplier", 1.5f, 1.0f, 20.0f, Game::DVAR_FLAG_SAVED, "Horizontal view sensitivity multiplier"); + XInput::xpadVerticalMultiplier = Dvar::Register("xpad_vertical_multiplier", 0.8f, 1.0f, 20.0f, Game::DVAR_FLAG_SAVED, "Vertical view sensitivity multiplier"); + XInput::xpadAdsMultiplier = Dvar::Register("xpad_ads_multiplier", 0.7f, 0.1f, 1.0f, Game::DVAR_FLAG_SAVED, "By how much the view sensitivity is multiplied when aiming down the sights."); + PollXInputDevices(); if (xiPlayerNum >= 0) { diff --git a/src/Components/Modules/XInput.hpp b/src/Components/Modules/XInput.hpp index 7339e09b..60f2821e 100644 --- a/src/Components/Modules/XInput.hpp +++ b/src/Components/Modules/XInput.hpp @@ -48,6 +48,13 @@ namespace Components static std::chrono::milliseconds msBetweenNavigations; static float lastMenuNavigationDirection; + static Dvar::Var XInput::xpadSensitivity; + static Dvar::Var XInput::xpadEarlyTime; + static Dvar::Var XInput::xpadEarlyMultiplier; + static Dvar::Var XInput::xpadHorizontalMultiplier; + static Dvar::Var XInput::xpadVerticalMultiplier; + static Dvar::Var XInput::xpadAdsMultiplier; + static void CL_GetMouseMovementCl(Game::clientActive_t* result, float* mx, float* my); static int unk_CheckKeyHook(int localClientNum, Game::keyNum_t keyCode);