From 1cc9e0d37fb23946c53ce2c2a8b7333ac122e87f Mon Sep 17 00:00:00 2001 From: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com> Date: Fri, 14 Feb 2025 11:30:49 +0100 Subject: [PATCH] Initial implementation of controller color config (#2411) --- src/common/config.cpp | 22 ++++++++++++++++++ src/common/config.h | 4 ++++ src/core/libraries/pad/pad.cpp | 12 +++++++++- src/input/input_handler.cpp | 42 +++++++++++++++++++++++++++------- src/sdl_window.cpp | 3 ++- 5 files changed, 73 insertions(+), 10 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index e26a998f5..aae903da6 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -71,6 +71,8 @@ static bool rdocEnable = false; static s16 cursorState = HideCursorState::Idle; static int cursorHideTimeout = 5; // 5 seconds (default) static bool useUnifiedInputConfig = true; +static bool overrideControllerColor = false; +static int controllerCustomColorRGB[3] = {0, 0, 255}; static bool separateupdatefolder = false; static bool compatibilityData = false; static bool checkCompatibilityOnStartup = false; @@ -115,6 +117,24 @@ void SetUseUnifiedInputConfig(bool use) { useUnifiedInputConfig = use; } +bool GetOverrideControllerColor() { + return overrideControllerColor; +} + +void SetOverrideControllerColor(bool enable) { + overrideControllerColor = enable; +} + +int* GetControllerCustomColor() { + return controllerCustomColorRGB; +} + +void SetControllerCustomColor(int r, int b, int g) { + controllerCustomColorRGB[0] = r; + controllerCustomColorRGB[1] = b; + controllerCustomColorRGB[2] = g; +} + std::string getTrophyKey() { return trophyKey; } @@ -1046,6 +1066,8 @@ axis_right_y = axis_right_y # Range of deadzones: 1 (almost none) to 127 (max) analog_deadzone = leftjoystick, 2, 127 analog_deadzone = rightjoystick, 2, 127 + +override_controller_color = false, 0, 0, 255 )"; } std::filesystem::path GetFoolproofKbmConfigFile(const std::string& game_id) { diff --git a/src/common/config.h b/src/common/config.h index 3a140c0c8..dfb1d9fad 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -47,6 +47,10 @@ int getSpecialPadClass(); bool getIsMotionControlsEnabled(); bool GetUseUnifiedInputConfig(); void SetUseUnifiedInputConfig(bool use); +bool GetOverrideControllerColor(); +void SetOverrideControllerColor(bool enable); +int* GetControllerCustomColor(); +void SetControllerCustomColor(int r, int b, int g); u32 getScreenWidth(); u32 getScreenHeight(); diff --git a/src/core/libraries/pad/pad.cpp b/src/core/libraries/pad/pad.cpp index 173b78382..bcc90c49b 100644 --- a/src/core/libraries/pad/pad.cpp +++ b/src/core/libraries/pad/pad.cpp @@ -261,6 +261,7 @@ int PS4_SYSV_ABI scePadOpen(s32 userId, s32 type, s32 index, const OrbisPadOpenP if (type != ORBIS_PAD_PORT_TYPE_STANDARD && type != ORBIS_PAD_PORT_TYPE_REMOTE_CONTROL) return ORBIS_PAD_ERROR_DEVICE_NOT_CONNECTED; } + scePadResetLightBar(1); return 1; // dummy } @@ -412,7 +413,13 @@ int PS4_SYSV_ABI scePadReadStateExt() { } int PS4_SYSV_ABI scePadResetLightBar(s32 handle) { - LOG_ERROR(Lib_Pad, "(STUBBED) called"); + LOG_INFO(Lib_Pad, "(DUMMY) called"); + if (handle != 1) { + return ORBIS_PAD_ERROR_INVALID_HANDLE; + } + auto* controller = Common::Singleton::Instance(); + int* rgb = Config::GetControllerCustomColor(); + controller->SetLightBarRGB(rgb[0], rgb[1], rgb[2]); return ORBIS_OK; } @@ -472,6 +479,9 @@ int PS4_SYSV_ABI scePadSetForceIntercepted() { } int PS4_SYSV_ABI scePadSetLightBar(s32 handle, const OrbisPadLightBarParam* pParam) { + if (Config::GetOverrideControllerColor()) { + return ORBIS_OK; + } if (pParam != nullptr) { LOG_DEBUG(Lib_Pad, "called handle = {} rgb = {} {} {}", handle, pParam->r, pParam->g, pParam->b); diff --git a/src/input/input_handler.cpp b/src/input/input_handler.cpp index 38a310324..6e961043e 100644 --- a/src/input/input_handler.cpp +++ b/src/input/input_handler.cpp @@ -214,6 +214,9 @@ void ParseInputConfig(const std::string game_id = "") { lefttrigger_deadzone = {1, 127}; righttrigger_deadzone = {1, 127}; + Config::SetOverrideControllerColor(false); + Config::SetControllerCustomColor(0, 0, 255); + int lineCount = 0; std::ifstream file(config_file); @@ -254,6 +257,14 @@ void ParseInputConfig(const std::string game_id = "") { std::string input_string = line.substr(equal_pos + 1); std::size_t comma_pos = input_string.find(','); + auto parseInt = [](const std::string& s) -> std::optional { + try { + return std::stoi(s); + } catch (...) { + return std::nullopt; + } + }; + if (output_string == "mouse_to_joystick") { if (input_string == "left") { SetMouseToJoystick(1); @@ -307,14 +318,6 @@ void ParseInputConfig(const std::string game_id = "") { continue; } - auto parseInt = [](const std::string& s) -> std::optional { - try { - return std::stoi(s); - } catch (...) { - return std::nullopt; - } - }; - auto inner_deadzone = parseInt(inner_deadzone_str); auto outer_deadzone = parseInt(outer_deadzone_str); @@ -341,6 +344,29 @@ void ParseInputConfig(const std::string game_id = "") { lineCount, line); } continue; + } else if (output_string == "override_controller_color") { + std::stringstream ss(input_string); + std::string enable, r_s, g_s, b_s; + std::optional r, g, b; + if (!std::getline(ss, enable, ',') || !std::getline(ss, r_s, ',') || + !std::getline(ss, g_s, ',') || !std::getline(ss, b_s)) { + LOG_WARNING(Input, "Malformed controller color config at line {}: \"{}\"", + lineCount, line); + continue; + } + r = parseInt(r_s); + g = parseInt(g_s); + b = parseInt(b_s); + if (!r || !g || !b) { + LOG_WARNING(Input, "Invalid RGB values at line {}: \"{}\", skipping line.", + lineCount, line); + continue; + } + Config::SetOverrideControllerColor(enable == "true"); + Config::SetControllerCustomColor(*r, *g, *b); + LOG_DEBUG(Input, "Parsed color settings: {} {} {} {}", + enable == "true" ? "override" : "no override", *r, *b, *g); + continue; } // normal cases diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index 6eaad62e5..ccc369c53 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -129,7 +129,8 @@ void SDLInputEngine::Init() { }; } SDL_free(gamepads); - SetLightBarRGB(0, 0, 255); + int* rgb = Config::GetControllerCustomColor(); + SetLightBarRGB(rgb[0], rgb[1], rgb[2]); } void SDLInputEngine::SetLightBarRGB(u8 r, u8 g, u8 b) {