diff --git a/UnleashedRecomp/hid/driver/sdl_hid.cpp b/UnleashedRecomp/hid/driver/sdl_hid.cpp index 762355242..fbc870c20 100644 --- a/UnleashedRecomp/hid/driver/sdl_hid.cpp +++ b/UnleashedRecomp/hid/driver/sdl_hid.cpp @@ -38,7 +38,7 @@ class Controller SDL_GameControllerType GetControllerType() const { - return SDL_GameControllerGetType(controller); + return SDL_GameControllerTypeForIndex(index); } hid::EInputDevice GetInputDevice() const @@ -49,22 +49,9 @@ class Controller 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; } - } - - const char* GetControllerName() const - { - auto result = SDL_GameControllerName(controller); - - if (!result) - return "Unknown Device"; - return result; + return hid::EInputDevice::Xbox; } void Close() @@ -191,21 +178,12 @@ 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; - if (controllerType == hid::EInputDeviceExplicit::Unknown) - { - LOGFN("Detected controller: {} (Unknown Controller Type)", controllerName); - } - else - { - LOGFN("Detected controller: {}", controllerName); - } + LOGFN("Detected controller: {}", hid::GetInputDeviceName()); } } @@ -332,8 +310,6 @@ void hid::Init() SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_WII, "1"); SDL_SetHint(SDL_HINT_XINPUT_ENABLED, "1"); - - SDL_SetHint(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, "0"); // Uses Button Labels. This hint is disabled for Nintendo Controllers. SDL_InitSubSystem(SDL_INIT_EVENTS); SDL_AddEventWatch(HID_OnSDLEvent, nullptr); diff --git a/UnleashedRecomp/hid/hid.cpp b/UnleashedRecomp/hid/hid.cpp index 900de327f..0a56224a8 100644 --- a/UnleashedRecomp/hid/hid.cpp +++ b/UnleashedRecomp/hid/hid.cpp @@ -27,3 +27,59 @@ 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 d61131fb2..730694a9c 100644 --- a/UnleashedRecomp/hid/hid.h +++ b/UnleashedRecomp/hid/hid.h @@ -4,7 +4,6 @@ namespace hid { enum class EInputDevice { - Unknown, Keyboard, Mouse, Xbox, @@ -46,4 +45,5 @@ namespace hid void SetProhibitedInputs(uint16_t wButtons = 0, bool leftStick = false, bool rightStick = false); bool IsInputAllowed(); bool IsInputDeviceController(); + std::string GetInputDeviceName(); }