diff --git a/UnleashedRecomp/hid/driver/sdl_hid.cpp b/UnleashedRecomp/hid/driver/sdl_hid.cpp index 7220abbe..aa0e4779 100644 --- a/UnleashedRecomp/hid/driver/sdl_hid.cpp +++ b/UnleashedRecomp/hid/driver/sdl_hid.cpp @@ -38,7 +38,7 @@ public: SDL_GameControllerType GetControllerType() const { - return SDL_GameControllerTypeForIndex(index); + return SDL_GameControllerGetType(controller); } hid::EInputDevice GetInputDevice() const @@ -49,9 +49,22 @@ public: case SDL_CONTROLLER_TYPE_PS4: case SDL_CONTROLLER_TYPE_PS5: return hid::EInputDevice::PlayStation; + case SDL_CONTROLLER_TYPE_XBOX360: + case SDL_CONTROLLER_TYPE_XBOXONE: + return hid::EInputDevice::Xbox; + default: + return hid::EInputDevice::Unknown; } + } - return hid::EInputDevice::Xbox; + const char* GetControllerName() const + { + auto result = SDL_GameControllerName(controller); + + if (!result) + return "Unknown Device"; + + return result; } void Close() @@ -178,12 +191,21 @@ static void SetControllerInputDevice(Controller* controller) hid::g_inputDeviceController = hid::g_inputDevice; auto controllerType = (hid::EInputDeviceExplicit)controller->GetControllerType(); + auto controllerName = controller->GetControllerName(); + // Only proceed if the controller type changes. if (hid::g_inputDeviceExplicit != controllerType) { hid::g_inputDeviceExplicit = controllerType; - LOGFN("Detected controller: {}", hid::GetInputDeviceName()); + if (controllerType == hid::EInputDeviceExplicit::Unknown) + { + LOGFN("Detected controller: {} (Unknown Controller Type)", controllerName); + } + else + { + LOGFN("Detected controller: {}", controllerName); + } } } diff --git a/UnleashedRecomp/hid/hid.cpp b/UnleashedRecomp/hid/hid.cpp index 0a56224a..900de327 100644 --- a/UnleashedRecomp/hid/hid.cpp +++ b/UnleashedRecomp/hid/hid.cpp @@ -27,59 +27,3 @@ bool hid::IsInputDeviceController() return hid::g_inputDevice != hid::EInputDevice::Keyboard && hid::g_inputDevice != hid::EInputDevice::Mouse; } - -std::string hid::GetInputDeviceName() -{ - switch (g_inputDevice) - { - case EInputDevice::Keyboard: - return "Keyboard"; - - case EInputDevice::Mouse: - return "Mouse"; - } - - switch (g_inputDeviceExplicit) - { - case EInputDeviceExplicit::Xbox360: - return "Xbox 360"; - - case EInputDeviceExplicit::XboxOne: - return "Xbox One"; - - case EInputDeviceExplicit::DualShock3: - return "DualShock 3"; - - case EInputDeviceExplicit::DualShock4: - return "DualShock 4"; - - case EInputDeviceExplicit::SwitchPro: - return "Nintendo Switch Pro"; - - case EInputDeviceExplicit::Virtual: - return "Virtual"; - - case EInputDeviceExplicit::DualSense: - return "DualSense"; - - case EInputDeviceExplicit::Luna: - return "Amazon Luna"; - - case EInputDeviceExplicit::Stadia: - return "Google Stadia"; - - case EInputDeviceExplicit::NvShield: - return "NVIDIA Shield"; - - case EInputDeviceExplicit::SwitchJCLeft: - return "Nintendo Switch Joy-Con (Left)"; - - case EInputDeviceExplicit::SwitchJCRight: - return "Nintendo Switch Joy-Con (Right)"; - - case EInputDeviceExplicit::SwitchJCPair: - return "Nintendo Switch Joy-Con (Pair)"; - } - - return "Unknown"; -} diff --git a/UnleashedRecomp/hid/hid.h b/UnleashedRecomp/hid/hid.h index 730694a9..d61131fb 100644 --- a/UnleashedRecomp/hid/hid.h +++ b/UnleashedRecomp/hid/hid.h @@ -4,6 +4,7 @@ namespace hid { enum class EInputDevice { + Unknown, Keyboard, Mouse, Xbox, @@ -45,5 +46,4 @@ namespace hid void SetProhibitedInputs(uint16_t wButtons = 0, bool leftStick = false, bool rightStick = false); bool IsInputAllowed(); bool IsInputDeviceController(); - std::string GetInputDeviceName(); }