Add setting to control controller vibration strength

This commit is contained in:
rebtd7 2021-03-09 15:43:47 -03:00
parent d6a53cc49c
commit 2527648360
4 changed files with 12 additions and 7 deletions

View File

@ -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()

View File

@ -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);

View File

@ -2,8 +2,9 @@
#include "XInputManager.h"
#include <XInput.h>
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;
}

View File

@ -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();