Skip to content

Commit

Permalink
Implement PlayStation Adaptive Trigger support for Bluetooth also
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Nov 30, 2024
1 parent 2802cda commit 4789896
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 58 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
24.11.30.1
24.11.30.2
==========
+ Implement PlayStation Adaptive Trigger support for DualSense controllers
connected using Bluetooth.

24.11.30.1
==========
+ Bring back original slUpgradeInterface / slGetNativeInterface implementation
that could handle situations where sl.interposer.dll is loaded late.
+ Increase default impulse trigger strength modifier to 0.75x, and properly
handle the case where setVibration (...) has zero trigger data.


24.11.30
========
+ For all Unreal Engine games that use GameInput, enable Xbox Emulation by
Expand Down
4 changes: 2 additions & 2 deletions include/SpecialK/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#define SK_YEAR 24
#define SK_MONTH 11
#define SK_DATE 30
#define SK_REV_N 1
#define SK_REV 1
#define SK_REV_N 2
#define SK_REV 2

#ifndef _A2
#define _A2(a) #a
Expand Down
109 changes: 55 additions & 54 deletions src/input/hid_reports/playstation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2630,7 +2630,9 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
const ULONG dwLeftMotor = ReadULongAcquire (&pDevice->_vibration.left);

const bool bRumble =
(dwRightMotor != 0 || dwLeftMotor != 0);
(dwRightMotor != 0 ||
dwLeftMotor != 0) || (ReadULongAcquire (&pDevice->_vibration.trigger.left) != 0
|| ReadULongAcquire (&pDevice->_vibration.trigger.right) != 0);

// 500 msec grace period before allowing controller to use native haptics
output->UseRumbleNotHaptics = bRumble ||
Expand Down Expand Up @@ -2666,58 +2668,33 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
);

uint8_t effects[3][11] = {
/* Clear trigger effect */
{ 0x05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
/* Constant resistance across entire trigger pull */
{ 0x05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x01, 0, 110, 0, 0, 0, 0, 0, 0, 0, 0 },
/* Resistance and vibration when trigger is pulled */
{ 0x06, 15, 63, 0, 0, 0, 0, 0, 0, 0, 0 },
};

//static int trigger_effect = 0;
// trigger_effect = (trigger_effect + 1) % 3;

if (pDevice->_vibration.trigger.left != 0)
{
output->AllowLeftTriggerFFB = true;

const auto trigger_effect = 2;
{ output->AllowLeftTriggerFFB = true;
const auto trigger_effect = 2;
memcpy (output->LeftTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect]));

output->LeftTriggerFFB [2] =
static_cast <uint8_t> (std::clamp (
static_cast <float> (pDevice->_vibration.trigger.left) *
config.input.gamepad.impulse_strength_l, 0.0f, 1.0f)
);
}

else
{
output->AllowLeftTriggerFFB = true;

const auto trigger_effect = 0;
output->LeftTriggerFFB [2] =
static_cast <uint8_t> (std::clamp (
static_cast <float> (pDevice->_vibration.trigger.left) *
config.input.gamepad.impulse_strength_l, 0.0f, 1.0f) );
} else { output->AllowLeftTriggerFFB = true;
const auto trigger_effect = 0;
memcpy (output->LeftTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect]));
}

if (pDevice->_vibration.trigger.right != 0)
{
output->AllowRightTriggerFFB = true;

const auto trigger_effect = 2;
{ output->AllowRightTriggerFFB = true;
const auto trigger_effect = 2;
memcpy (output->RightTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect]));

output->RightTriggerFFB [2] =
static_cast <uint8_t> (std::clamp (
static_cast <float> (pDevice->_vibration.trigger.right) *
config.input.gamepad.impulse_strength_r, 0.0f, 1.0f)
);
}

else
{
output->AllowRightTriggerFFB = true;

const auto trigger_effect = 0;
output->RightTriggerFFB [2] =
static_cast <uint8_t> (std::clamp (
static_cast <float> (pDevice->_vibration.trigger.right) *
config.input.gamepad.impulse_strength_r, 0.0f, 1.0f) );
} else { output->AllowRightTriggerFFB = true;
const auto trigger_effect = 0;
memcpy (output->RightTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect]));
}

Expand Down Expand Up @@ -2840,7 +2817,9 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
const ULONG dwLeftMotor = ReadULongAcquire (&pDevice->_vibration.left);

const bool bRumble =
(dwRightMotor != 0 || dwLeftMotor != 0);
(dwRightMotor != 0 ||
dwLeftMotor != 0) || (ReadULongAcquire (&pDevice->_vibration.trigger.left) != 0
|| ReadULongAcquire (&pDevice->_vibration.trigger.right) != 0);

// 500 msec grace period before allowing controller to use native haptics
output->UseRumbleNotHaptics = bRumble ||
Expand All @@ -2849,7 +2828,38 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
if (bRumble)
{
WriteULongRelease (&pDevice->_vibration.last_set, SK::ControlPanel::current_time);
output->AllowMotorPowerLevel = true;
output->AllowMotorPowerLevel = true;
}

uint8_t effects[3][11] = {
{ 0x05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x01, 0, 110, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x06, 15, 63, 0, 0, 0, 0, 0, 0, 0, 0 },
};

if (pDevice->_vibration.trigger.left != 0)
{ output->AllowLeftTriggerFFB = true;
const auto trigger_effect = 2;
memcpy (output->LeftTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect]));
output->LeftTriggerFFB [2] =
static_cast <uint8_t> (std::clamp (
static_cast <float> (pDevice->_vibration.trigger.left) *
config.input.gamepad.impulse_strength_l, 0.0f, 1.0f) );
} else { output->AllowLeftTriggerFFB = true;
const auto trigger_effect = 0;
memcpy (output->LeftTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect]));
}
if (pDevice->_vibration.trigger.right != 0)
{ output->AllowRightTriggerFFB = true;
const auto trigger_effect = 2;
memcpy (output->RightTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect]));
output->RightTriggerFFB [2] =
static_cast <uint8_t> (std::clamp (
static_cast <float> (pDevice->_vibration.trigger.right) *
config.input.gamepad.impulse_strength_r, 0.0f, 1.0f) );
} else { output->AllowRightTriggerFFB = true;
const auto trigger_effect = 0;
memcpy (output->RightTriggerFFB, effects [trigger_effect], sizeof (effects [trigger_effect]));
}

output->EnableRumbleEmulation = true;
Expand All @@ -2869,15 +2879,6 @@ SK_HID_PlayStationDevice::write_output_report (bool force)
output->
EnableImprovedRumbleEmulation = true;

output->RumbleEmulationRight =
sk::narrow_cast <BYTE> (
ReadULongAcquire (&pDevice->_vibration.right)
);
output->RumbleEmulationLeft =
sk::narrow_cast <BYTE> (
ReadULongAcquire (&pDevice->_vibration.left)
);

static bool bMuted = SK_IsGameMuted ();
static DWORD dwLastMuteCheck = SK_timeGetTime ();

Expand Down

0 comments on commit 4789896

Please sign in to comment.