diff --git a/rpcs3/mm_joystick_handler.cpp b/rpcs3/mm_joystick_handler.cpp index 4b5012084f7e..c072b7ab015e 100644 --- a/rpcs3/mm_joystick_handler.cpp +++ b/rpcs3/mm_joystick_handler.cpp @@ -85,25 +85,11 @@ bool mm_joystick_handler::Init() for (u32 i = 0; i < supportedJoysticks; i++) { - JOYINFOEX js_info; - JOYCAPS js_caps; - js_info.dwSize = sizeof(js_info); - js_info.dwFlags = JOY_RETURNALL; - joyGetDevCaps(i, &js_caps, sizeof(js_caps)); + MMJOYDevice dev; - if (joyGetPosEx(i, &js_info) != JOYERR_NOERROR) + if (GetMMJOYDevice(i, dev) == false) continue; - char drv[32]; - wcstombs(drv, js_caps.szPname, 31); - - LOG_NOTICE(GENERAL, "Joystick nr.%d found. Driver: %s", i, drv); - - MMJOYDevice dev; - dev.device_id = i; - dev.device_name = fmt::format("Joystick #%d", i); - dev.device_info = js_info; - dev.device_caps = js_caps; m_devices.emplace(i, dev); } @@ -128,13 +114,12 @@ std::vector mm_joystick_handler::ListDevices() bool mm_joystick_handler::bindPadToDevice(std::shared_ptr pad, const std::string& device) { - if (!Init()) return false; + if (!Init()) + return false; int id = GetIDByName(device); if (id < 0) - { return false; - } std::shared_ptr joy_device = std::make_shared(m_devices.at(id)); @@ -216,7 +201,11 @@ void mm_joystick_handler::ThreadProc() case JOYERR_NOERROR: ++online; if (last_connection_status[i] == false) + { + if (GetMMJOYDevice(dev->device_id, *dev) == false) + continue; pad->m_port_status |= CELL_PAD_STATUS_ASSIGN_CHANGES; + } last_connection_status[i] = true; pad->m_port_status |= CELL_PAD_STATUS_CONNECTED; @@ -543,4 +532,28 @@ int mm_joystick_handler::GetIDByName(const std::string& name) return -1; } +bool mm_joystick_handler::GetMMJOYDevice(int index, MMJOYDevice& dev) +{ + JOYINFOEX js_info; + JOYCAPS js_caps; + js_info.dwSize = sizeof(js_info); + js_info.dwFlags = JOY_RETURNALL; + joyGetDevCaps(index, &js_caps, sizeof(js_caps)); + + if (joyGetPosEx(index, &js_info) != JOYERR_NOERROR) + return false; + + char drv[32]; + wcstombs(drv, js_caps.szPname, 31); + + LOG_NOTICE(GENERAL, "Joystick nr.%d found. Driver: %s", index, drv); + + dev.device_id = index; + dev.device_name = fmt::format("Joystick #%d", index); + dev.device_info = js_info; + dev.device_caps = js_caps; + + return true; +} + #endif diff --git a/rpcs3/mm_joystick_handler.h b/rpcs3/mm_joystick_handler.h index 27641006a339..00f51ec5375b 100644 --- a/rpcs3/mm_joystick_handler.h +++ b/rpcs3/mm_joystick_handler.h @@ -109,6 +109,7 @@ class mm_joystick_handler final : public PadHandlerBase void TranslateButtonPress(u64 keyCode, bool& pressed, u16& val, bool ignore_threshold = false) override; std::unordered_map GetButtonValues(const JOYINFOEX& js_info, const JOYCAPS& js_caps); int GetIDByName(const std::string& name); + bool GetMMJOYDevice(int index, MMJOYDevice& dev); bool is_init = false; u32 supportedJoysticks = 0;