From b452110b439f654c42cbaa96228f8c7036789911 Mon Sep 17 00:00:00 2001 From: Arcitec <14483309-Arcitec@users.noreply.gitlab.com> Date: Wed, 23 Aug 2023 21:13:06 +0200 Subject: [PATCH] Fix serial numbers from buggy ASUS keyboard firmwares * ASUS firmware bugs sometimes return trailing garbage after the serial number. This new algorithm cleans up the garbage by only allowing legal, lower-ASCII characters, so that OpenRGB can accurately identify keyboards that have buggy firmwares. --- .../AsusAuraTUFKeyboardController.cpp | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Controllers/AsusAuraUSBController/AsusAuraTUFKeyboardController.cpp b/Controllers/AsusAuraUSBController/AsusAuraTUFKeyboardController.cpp index ba784add..d487ce6f 100644 --- a/Controllers/AsusAuraUSBController/AsusAuraTUFKeyboardController.cpp +++ b/Controllers/AsusAuraUSBController/AsusAuraTUFKeyboardController.cpp @@ -37,6 +37,26 @@ std::string AuraTUFKeyboardController::GetDeviceLocation() return("HID: " + location); } +std::string clean_serial(const std::wstring& wstr) +{ + // Skip non-ASCII, trailing garbage in serial numbers. Required by the + // Scope II 96, whose original firmware outputs garbage, which even differs + // after computer reboots and therefore breaks OpenRGB profile matching. + std::string result; + for(auto c : wstr) + { + // Forbid control chars and anything above final printable low-ASCII. + if(c < 32 || c > 126) + { + break; + } + + result += c; + } + + return(result); +} + std::string AuraTUFKeyboardController::GetSerialString() { wchar_t serial_string[128]; @@ -47,8 +67,8 @@ std::string AuraTUFKeyboardController::GetSerialString() return(""); } - std::wstring return_wstring = serial_string; - std::string return_string(return_wstring.begin(), return_wstring.end()); + std::wstring serial_wstring = serial_string; + std::string return_string = clean_serial(serial_wstring); return(return_string); }