Skip to content

Commit

Permalink
Support native GameInput implementations when Xbox Emulation is turne…
Browse files Browse the repository at this point in the history
…d off
  • Loading branch information
Kaldaien committed Dec 1, 2024
1 parent 1db2756 commit 014b477
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
24.12.1.3
24.12.1.4
=========
+ Support native GameInput implementations when Xbox Emulation is turned off.

24.12.1.3
=========
+ XInput emulation now bypasses GameInput.dll for systems that do not have
this DLL.

24.12.1.2
=========
+ Enable Impulse Trigger strength sliders in Windows.Gaming.Input games

24.12.1.1
=========
+ Allow Starfield to read Windows.Gaming.Input and write XInput
Expand Down
7 changes: 7 additions & 0 deletions include/SpecialK/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,13 @@ struct SK_HID_PlayStationDevice
WORD wLastLeft = 0 ;
WORD wLastRight = 0 ;
} vibration;

bool isNewer (const hid_to_xi& reading) const
{
return
ReadULong64Acquire ( &last_active) >
ReadULong64Acquire (&reading.last_active);
}
} xinput;

bool chord_activated = false;
Expand Down
62 changes: 29 additions & 33 deletions src/input/game_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,7 @@ SK_IWrapGameInput::GetNextReading (_In_ IGameInputReading *referenceRea
{
if (controller.bConnected)
{
if (pNewestInputDevice == nullptr ||
pNewestInputDevice->xinput.last_active < controller.xinput.last_active)
if (pNewestInputDevice == nullptr || controller.xinput.isNewer (pNewestInputDevice->xinput))
{
pNewestInputDevice = &controller;
}
Expand All @@ -435,12 +434,13 @@ SK_IWrapGameInput::GetNextReading (_In_ IGameInputReading *referenceRea

if (pNewestInputDevice != nullptr)
{
virtual_active = pNewestInputDevice->xinput.last_active;
virtual_active =
ReadULong64Acquire (&pNewestInputDevice->xinput.last_active);
}
}
}

if (std::exchange (last_virtual_active, virtual_active) != last_virtual_active)
if (std::exchange (last_virtual_active, virtual_active) != virtual_active)
{
if (reading != nullptr)
*reading = (IGameInputReading *)&virtual_next_reading;
Expand Down Expand Up @@ -793,45 +793,43 @@ GameInputCreate_Detour (IGameInput** gameInput)
{
SK_LOG_FIRST_CALL

IGameInput* pReal;
IGameInput* pReal = nullptr;

HRESULT hr =
GameInputCreate_Original (&pReal);

if (SUCCEEDED (hr) || config.input.gamepad.xinput.emulate)
{
//if (gameInput != nullptr)
// Turn on XInput emulation by default on first-run for Unreal Engine.
//
// -> Their GameInput integration is extremely simple and SK is fully compatible.
//
if (config.system.first_run && (! SK_XInput_PollController (0)))
{
// Turn on XInput emulation by default on first-run for Unreal Engine.
//
// -> Their GameInput integration is extremely simple and SK is fully compatible.
//
if (config.system.first_run && (! SK_XInput_PollController (0)))
{
SK_RunOnce (if (! SK_ImGui_HasPlayStationController ())
SK_HID_SetupPlayStationControllers ());

if (SK_ImGui_HasPlayStationController () && StrStrIW (SK_GetFullyQualifiedApp (), L"WinGDK"))
{
SK_LOGi0 (L"Enabling Xbox Mode because Unreal Engine is using GameInput...");
SK_RunOnce (if (! SK_ImGui_HasPlayStationController ())
SK_HID_SetupPlayStationControllers ());

config.input.gamepad.xinput.emulate = true;
}
}

if (config.input.gamepad.xinput.emulate)
if (SK_ImGui_HasPlayStationController () && StrStrIW (SK_GetFullyQualifiedApp (), L"Binaries\\Win"))
{
*gameInput = (IGameInput *)new SK_IWrapGameInput (pReal);
return S_OK;
SK_LOGi0 (L"Enabling Xbox Mode because Unreal Engine is using GameInput...");

config.input.gamepad.xinput.emulate = true;
}
}

//else
//{
// pReal->Release ();
//}
if (config.input.gamepad.xinput.emulate)
{
if (gameInput != nullptr)
*gameInput = (IGameInput *)new SK_IWrapGameInput (pReal);
else new SK_IWrapGameInput (pReal);

return S_OK;
}
}

if (gameInput != nullptr && pReal != nullptr)
*gameInput = pReal;

return hr;
}

Expand Down Expand Up @@ -1035,8 +1033,7 @@ SK_IGameInputDevice::SetRumbleState (GameInputRumbleParams const *params) noexce
{
if (controller.bConnected)
{
if (pNewestInputDevice == nullptr ||
pNewestInputDevice->xinput.last_active < controller.xinput.last_active)
if (pNewestInputDevice == nullptr || controller.xinput.isNewer (pNewestInputDevice->xinput))
{
pNewestInputDevice = &controller;
}
Expand Down Expand Up @@ -1864,8 +1861,7 @@ SK_IPlayStationGameInputReading::GetGamepadState (GameInputGamepadState *state)
{
if (controller.bConnected)
{
if (pNewestInputDevice == nullptr ||
pNewestInputDevice->xinput.last_active < controller.xinput.last_active)
if (pNewestInputDevice == nullptr || controller.xinput.isNewer (pNewestInputDevice->xinput))
{
pNewestInputDevice = &controller;
}
Expand Down

0 comments on commit 014b477

Please sign in to comment.