From 93e1a7047cecc4b4794b1efa5ee52982a0908e93 Mon Sep 17 00:00:00 2001 From: RedPanda4552 Date: Tue, 10 Oct 2023 16:01:44 -0400 Subject: [PATCH] DInput: Add option to ignore inversion flag --- .../ControllerGlobalSettingsWidget.cpp | 1 + .../ControllerGlobalSettingsWidget.ui | 258 +++++++++--------- pcsx2/Input/DInputSource.cpp | 11 +- pcsx2/Input/DInputSource.h | 2 + 4 files changed, 146 insertions(+), 126 deletions(-) diff --git a/pcsx2-qt/Settings/ControllerGlobalSettingsWidget.cpp b/pcsx2-qt/Settings/ControllerGlobalSettingsWidget.cpp index 45f60f40a0..c1fa57665b 100644 --- a/pcsx2-qt/Settings/ControllerGlobalSettingsWidget.cpp +++ b/pcsx2-qt/Settings/ControllerGlobalSettingsWidget.cpp @@ -54,6 +54,7 @@ ControllerGlobalSettingsWidget::ControllerGlobalSettingsWidget(QWidget* parent, #ifdef _WIN32 SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.enableXInputSource, "InputSources", "XInput", false); SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.enableDInputSource, "InputSources", "DInput", false); + SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.ignoreDInputInversion, "InputSources", "IgnoreDInputInversion", false); #else m_ui.mainLayout->removeWidget(m_ui.xinputGroup); m_ui.xinputGroup->deleteLater(); diff --git a/pcsx2-qt/Settings/ControllerGlobalSettingsWidget.ui b/pcsx2-qt/Settings/ControllerGlobalSettingsWidget.ui index f45eb9274c..36c4856d91 100644 --- a/pcsx2-qt/Settings/ControllerGlobalSettingsWidget.ui +++ b/pcsx2-qt/Settings/ControllerGlobalSettingsWidget.ui @@ -7,7 +7,7 @@ 0 0 902 - 583 + 593 @@ -23,7 +23,89 @@ 0 + + + + Qt::Vertical + + + + 20 + 45 + + + + + + + Controller Multitap + + + + + + Multitap on Console Port 1 + + + + + + + Multitap on Console Port 2 + + + + + + + The multitap enables up to 8 controllers to be connected to the console. Each multitap provides 4 ports. Multitap is not supported by all games. + + + true + + + + + + + + + + DInput Source + + + + + + Enable DInput Input Source + + + + + + + <html><head/><body><p>Some third party controllers incorrectly flag their analog sticks as inverted on the positive component, but not negative.</p><p>As a result, the analog stick will be &quot;stuck on&quot; even while resting at neutral position. </p><p>Enabling this setting will tell PCSX2 to ignore inversion flags when creating mappings, allowing such controllers to function normally.</p></body></html> + + + Ignore Inversion + + + + + + + The DInput source provides support for legacy controllers which do not support XInput. Accessing these controllers via SDL instead is recommended, but DirectInput can be used if they are not compatible with SDL. + + + true + + + + + + + Profile Settings @@ -104,130 +186,7 @@ - - - - Qt::Vertical - - - - 20 - 45 - - - - - - - - XInput Source - - - - - - The XInput source provides support for Xbox 360 / Xbox One / Xbox Series controllers, and third party controllers which implement the XInput protocol. - - - true - - - - - - - Enable XInput Input Source - - - - - - - - - Controller Multitap - - - - - - The multitap enables up to 8 controllers to be connected to the console. Each multitap provides 4 ports. Multitap is not supported by all games. - - - true - - - - - - - Multitap on Console Port 1 - - - - - - - Multitap on Console Port 2 - - - - - - - - - - Detected Devices - - - - - - - 200 - 0 - - - - - 200 - 16777215 - - - - - - - - - - - DInput Source - - - - - - The DInput source provides support for legacy controllers which do not support XInput. Accessing these controllers via SDL instead is recommended, but DirectInput can be used if they are not compatible with SDL. - - - true - - - - - - - Enable DInput Input Source - - - - - - - Mouse/Pointer Source @@ -267,6 +226,57 @@ + + + + XInput Source + + + + + + The XInput source provides support for Xbox 360 / Xbox One / Xbox Series controllers, and third party controllers which implement the XInput protocol. + + + true + + + + + + + Enable XInput Input Source + + + + + + + + + + Detected Devices + + + + + + + 200 + 0 + + + + + 200 + 16777215 + + + + + + + diff --git a/pcsx2/Input/DInputSource.cpp b/pcsx2/Input/DInputSource.cpp index 47f7c9860c..3e42eb98c1 100644 --- a/pcsx2/Input/DInputSource.cpp +++ b/pcsx2/Input/DInputSource.cpp @@ -63,6 +63,8 @@ static constexpr std::array s_hat bool DInputSource::Initialize(SettingsInterface& si, std::unique_lock& settings_lock) { + LoadSettings(si); + m_dinput_module.reset(LoadLibraryW(L"dinput8")); if (!m_dinput_module) { @@ -103,7 +105,12 @@ bool DInputSource::Initialize(SettingsInterface& si, std::unique_lock& settings_lock) { - // noop + LoadSettings(si); +} + +void DInputSource::LoadSettings(SettingsInterface& si) +{ + m_ignore_inversion = si.GetBoolValue("InputSources", "IgnoreDInputInversion", false); } static BOOL CALLBACK EnumCallback(LPCDIDEVICEINSTANCEW lpddi, LPVOID pvRef) @@ -400,7 +407,7 @@ std::string DInputSource::ConvertKeyToString(InputBindingKey key) if (key.source_subtype == InputSubclass::ControllerAxis) { const char* modifier = (key.modifier == InputModifier::FullAxis ? "Full" : (key.modifier == InputModifier::Negate ? "-" : "+")); - ret = fmt::format("DInput-{}/{}Axis{}{}", u32(key.source_index), modifier, u32(key.data), key.invert ? "~" : ""); + ret = fmt::format("DInput-{}/{}Axis{}{}", u32(key.source_index), modifier, u32(key.data), (key.invert && !m_ignore_inversion) ? "~" : ""); } else if (key.source_subtype == InputSubclass::ControllerButton && key.data >= MAX_NUM_BUTTONS) { diff --git a/pcsx2/Input/DInputSource.h b/pcsx2/Input/DInputSource.h index 8731e68194..daca234dea 100644 --- a/pcsx2/Input/DInputSource.h +++ b/pcsx2/Input/DInputSource.h @@ -48,6 +48,7 @@ public: bool Initialize(SettingsInterface& si, std::unique_lock& settings_lock) override; void UpdateSettings(SettingsInterface& si, std::unique_lock& settings_lock) override; + void LoadSettings(SettingsInterface& si); bool ReloadDevices() override; void Shutdown() override; @@ -91,4 +92,5 @@ private: HWND m_toplevel_window = nullptr; ControllerDataArray m_controllers; + bool m_ignore_inversion = false; };