diff --git a/d3d9ex/AutoFix.cpp b/d3d9ex/AutoFix.cpp index b6756b5..9f95bda 100644 --- a/d3d9ex/AutoFix.cpp +++ b/d3d9ex/AutoFix.cpp @@ -196,7 +196,7 @@ void MainContext::FF13_EnableControllerVibration() MemPatch::Nop(ff13_vibration_low_set_zero_address, 5); MemPatch::Nop(ff13_vibration_high_set_zero_address, 5); - xinputManager = new XInputManager(ff13_base_controller_input_address_ptr); + xinputManager = new XInputManager(ff13_base_controller_input_address_ptr, config.GetFFXIIIVibrationStrengthFactor()); } void MainContext::FF13_RemoveContinuousControllerScan() @@ -302,7 +302,7 @@ void MainContext::FF13_2_EnableControllerVibration() MemPatch::Nop(ff13_2_vibration_low_set_zero_address, 5); MemPatch::Nop(ff13_2_vibration_high_set_zero_address, 5); - xinputManager = new XInputManager(ff13_2_base_controller_input_address_ptr); + xinputManager = new XInputManager(ff13_2_base_controller_input_address_ptr, config.GetFFXIIIVibrationStrengthFactor()); } void MainContext::FF13_2_InitializeGameAddresses() diff --git a/d3d9ex/Settings.h b/d3d9ex/Settings.h index 0bc1451..e0231aa 100644 --- a/d3d9ex/Settings.h +++ b/d3d9ex/Settings.h @@ -13,6 +13,7 @@ SETTING(u32, LongValue, BehaviorFlags, Options, 0); SETTING(s32, LongValue, IngameFrameRateLimit, FFXIII, 0); SETTING(bool, BoolValue, DisableIngameControllerHotSwapping, FFXIII, true); SETTING(bool, BoolValue, EnableControllerVibration, FFXIII, true); +SETTING(bool, DoubleValue, VibrationStrengthFactor, FFXIII, 2.0); SETTING(bool, BoolValue, Adapter, Adapter, false); SETTING(u32, LongValue, VendorId, Adapter, 0); diff --git a/d3d9ex/XInputManager.cpp b/d3d9ex/XInputManager.cpp index da52b87..f34a59e 100644 --- a/d3d9ex/XInputManager.cpp +++ b/d3d9ex/XInputManager.cpp @@ -2,8 +2,9 @@ #include "XInputManager.h" #include -XInputManager::XInputManager(uint8_t** base_controller_input_address_ptr) +XInputManager::XInputManager(uint8_t** base_controller_input_address_ptr, const float vibrationStrengthFactor) { + this->vibrationStrengthFactor = vibrationStrengthFactor; xinputThread = std::thread(&XInputManager::Run, this, base_controller_input_address_ptr); } @@ -46,11 +47,13 @@ void XInputManager::VibrationLoop() while (true) { const float vibrationStrengthLowFrequency = *vibration_address_low_frequency; const float vibrationStrengthHighFrequency = *vibration_address_high_frequency; - if (vibrationStrengthLowFrequency > 0.0f || vibrationStrengthHighFrequency > 0.0f) { - SetControllerVibration((WORD)(vibrationStrengthLowFrequency * maxVibrationStrength), (WORD)(vibrationStrengthHighFrequency * maxVibrationStrength)); + if (vibrationStrengthLowFrequency > 0.01f || vibrationStrengthHighFrequency > 0.01f) { + const WORD leftMotorVibration = std::min((WORD)(vibrationStrengthFactor * vibrationStrengthLowFrequency * maxVibrationStrength), maxVibrationStrength); + const WORD rightMotorVibration = std::min((WORD)(vibrationStrengthFactor * vibrationStrengthHighFrequency * maxVibrationStrength), maxVibrationStrength); + SetControllerVibration(leftMotorVibration, rightMotorVibration); wasVibrating = true; } - else if(wasVibrating) { + else if (wasVibrating) { SetControllerVibration(0, 0); wasVibrating = false; } diff --git a/d3d9ex/XInputManager.h b/d3d9ex/XInputManager.h index fef8e13..a7e1dca 100644 --- a/d3d9ex/XInputManager.h +++ b/d3d9ex/XInputManager.h @@ -2,11 +2,12 @@ class XInputManager { float* vibration_address_high_frequency = NULL; + float vibrationStrengthFactor; float* vibration_address_low_frequency = NULL; DWORD controllerId = -1; std::thread xinputThread; public: - XInputManager(uint8_t** base_controller_input_address_ptr); + XInputManager(uint8_t** base_controller_input_address_ptr, const float vibrationStrengthFactor); void Run(uint8_t** base_controller_input_address_ptr); void WaitAndSetVibrationAddress(uint8_t** base_controller_input_address_ptr); void VibrationLoop();