From 452a4654dac4cdf3dba4d502783e82257d9d40a1 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 26 Aug 2023 12:24:47 +0200 Subject: [PATCH] input: add SDL_GameControllerDB --- .ci/deploy-windows.sh | 5 ++++- .gitmodules | 1 + rpcs3/Emu/system_config.h | 1 + rpcs3/Input/sdl_pad_handler.cpp | 20 ++++++++++++++++++++ rpcs3/rpcs3qt/emu_settings_type.h | 2 ++ rpcs3/rpcs3qt/settings_dialog.cpp | 7 +++++++ rpcs3/rpcs3qt/settings_dialog.ui | 7 +++++++ rpcs3/rpcs3qt/tooltips.h | 1 + 8 files changed, 43 insertions(+), 1 deletion(-) diff --git a/.ci/deploy-windows.sh b/.ci/deploy-windows.sh index 417e8e8a1b..dd54ec4649 100755 --- a/.ci/deploy-windows.sh +++ b/.ci/deploy-windows.sh @@ -7,8 +7,11 @@ ARTIFACT_DIR="$BUILD_ARTIFACTSTAGINGDIRECTORY" rm -f ./bin/rpcs3.exp ./bin/rpcs3.lib ./bin/rpcs3.pdb ./bin/vc_redist.x64.exe rm -rf ./bin/git -# Prepare compatibility database for packaging, as well as +# Prepare compatibility and SDL database for packaging, as well as # certificate for ssl (auto-updater) +mkdir ./bin/config +mkdir ./bin/config/input_configs +curl -fsSL 'https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt' 1> ./bin/config/input_configs/gamecontrollerdb.txt curl -fsSL 'https://rpcs3.net/compatibility?api=v1&export' | iconv -t UTF-8 1> ./bin/GuiConfigs/compat_database.dat curl -fsSL 'https://curl.haxx.se/ca/cacert.pem' 1> ./bin/cacert.pem diff --git a/.gitmodules b/.gitmodules index b9aa5ccf26..cf1e922050 100644 --- a/.gitmodules +++ b/.gitmodules @@ -87,3 +87,4 @@ [submodule "3rdparty/rtmidi/rtmidi"] path = 3rdparty/rtmidi/rtmidi url = ../../thestk/rtmidi + ignore = dirty diff --git a/rpcs3/Emu/system_config.h b/rpcs3/Emu/system_config.h index 6d6ef869e7..7964a6b195 100644 --- a/rpcs3/Emu/system_config.h +++ b/rpcs3/Emu/system_config.h @@ -278,6 +278,7 @@ struct cfg_root : cfg::node cfg::_bool show_move_cursor{this, "Show move cursor", false, true}; cfg::_bool lock_overlay_input_to_player_one{this, "Lock overlay input to player one", false, true}; cfg::string midi_devices{ this, "Emulated Midi devices", "ßßß@@@ßßß@@@ßßß@@@" }; + cfg::_bool load_sdl_mappings{ this, "Load SDL GameController Mappings", true }; } io{ this }; struct node_sys : cfg::node diff --git a/rpcs3/Input/sdl_pad_handler.cpp b/rpcs3/Input/sdl_pad_handler.cpp index 925eeb7f29..f25ab21125 100644 --- a/rpcs3/Input/sdl_pad_handler.cpp +++ b/rpcs3/Input/sdl_pad_handler.cpp @@ -2,6 +2,8 @@ #include "stdafx.h" #include "sdl_pad_handler.h" +#include "Emu/system_utils.hpp" +#include "Emu/system_config.h" LOG_CHANNEL(sdl_log, "SDL"); @@ -217,6 +219,24 @@ bool sdl_pad_handler::Init() } }, nullptr); + if (g_cfg.io.load_sdl_mappings) + { + const std::string db_path = rpcs3::utils::get_input_config_root() + "gamecontrollerdb.txt"; + sdl_log.notice("Adding mappings from file '%s'", db_path); + + if (fs::is_file(db_path)) + { + if (SDL_GameControllerAddMappingsFromFile(db_path.c_str()) < 0) + { + sdl_log.error("Could not add mappings from file '%s'! SDL Error: %s", db_path, SDL_GetError()); + } + } + else + { + sdl_log.error("Could not add mappings from file '%s'! File does not exist!", db_path); + } + } + m_is_init = true; enumerate_devices(); diff --git a/rpcs3/rpcs3qt/emu_settings_type.h b/rpcs3/rpcs3qt/emu_settings_type.h index a3371d57d9..edf9d6cc8e 100644 --- a/rpcs3/rpcs3qt/emu_settings_type.h +++ b/rpcs3/rpcs3qt/emu_settings_type.h @@ -157,6 +157,7 @@ enum class emu_settings_type Turntable, GHLtar, MidiDevices, + SDLMappings, // Misc ExitRPCS3OnFinish, @@ -341,6 +342,7 @@ inline static const QMap settings_location = { emu_settings_type::Turntable, { "Input/Output", "Turntable emulated controller" }}, { emu_settings_type::GHLtar, { "Input/Output", "GHLtar emulated controller" }}, { emu_settings_type::MidiDevices, { "Input/Output", "Emulated Midi devices" }}, + { emu_settings_type::SDLMappings, { "Input/Output", "Load SDL GameController Mappings" }}, // Misc { emu_settings_type::ExitRPCS3OnFinish, { "Miscellaneous", "Exit RPCS3 when process finishes" }}, diff --git a/rpcs3/rpcs3qt/settings_dialog.cpp b/rpcs3/rpcs3qt/settings_dialog.cpp index 3628fb33f0..6936211946 100644 --- a/rpcs3/rpcs3qt/settings_dialog.cpp +++ b/rpcs3/rpcs3qt/settings_dialog.cpp @@ -1226,6 +1226,13 @@ settings_dialog::settings_dialog(std::shared_ptr gui_settings, std m_emu_settings->EnhanceCheckBox(ui->lockOverlayInputToPlayerOne, emu_settings_type::LockOvlIptToP1); SubscribeTooltip(ui->lockOverlayInputToPlayerOne, tooltips.settings.lock_overlay_input_to_player_one); +#if HAVE_SDL2 + m_emu_settings->EnhanceCheckBox(ui->loadSdlMappings, emu_settings_type::SDLMappings); + SubscribeTooltip(ui->loadSdlMappings, tooltips.settings.sdl_mappings); +#else + ui->loadSdlMappings->setVisible(false); +#endif + // Midi const QString midi_none = m_emu_settings->m_midi_creator.get_none(); const midi_device def_midi_device{ .type = midi_device_type::keyboard, .name = midi_none.toStdString() }; diff --git a/rpcs3/rpcs3qt/settings_dialog.ui b/rpcs3/rpcs3qt/settings_dialog.ui index bafa455676..152cfda615 100644 --- a/rpcs3/rpcs3qt/settings_dialog.ui +++ b/rpcs3/rpcs3qt/settings_dialog.ui @@ -1810,6 +1810,13 @@ + + + + Use SDL GameController Database + + + diff --git a/rpcs3/rpcs3qt/tooltips.h b/rpcs3/rpcs3qt/tooltips.h index 6e73f2f4b2..ce20096ec9 100644 --- a/rpcs3/rpcs3qt/tooltips.h +++ b/rpcs3/rpcs3qt/tooltips.h @@ -227,6 +227,7 @@ public: const QString background_input = tr("Allows pad and keyboard input while the game window is unfocused."); const QString show_move_cursor = tr("Shows the raw position of the PS Move input.\nThis can be very helpful during calibration screens."); const QString midi_devices = tr("Select up to 3 emulated MIDI devices and their types."); + const QString sdl_mappings = tr("Loads the SDL GameController database for improved gamepad compatibility. Only used in the SDL pad handler."); const QString lock_overlay_input_to_player_one = tr("Locks the native overlay input to the first player.");