Browse Source

Add setting to control controller vibration strength

pull/47/head
rebtd7 6 months ago
parent
commit
2527648360
  1. 4
      d3d9ex/AutoFix.cpp
  2. 1
      d3d9ex/Settings.h
  3. 11
      d3d9ex/XInputManager.cpp
  4. 3
      d3d9ex/XInputManager.h

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

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

11
d3d9ex/XInputManager.cpp

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

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

Loading…
Cancel
Save