From 4dccf6d5b9efd54613636866353c62e1c8786e3d Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Wed, 5 Oct 2022 06:42:56 -0500 Subject: [PATCH 1/4] input: don't override device's vendor id, expected to do comparsion instead --- src/common/input/LibusbDevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/input/LibusbDevice.cpp b/src/common/input/LibusbDevice.cpp index c21b32f6c..b7b17e31c 100644 --- a/src/common/input/LibusbDevice.cpp +++ b/src/common/input/LibusbDevice.cpp @@ -170,7 +170,7 @@ namespace Libusb } else { for (size_t i = 0; i < ARRAY_SIZE(SupportedDevices_VidPid); ++i) { - if ((Desc->idVendor = SupportedDevices_VidPid[i][0]) && (Desc->idProduct == SupportedDevices_VidPid[i][1])) { + if ((Desc->idVendor == SupportedDevices_VidPid[i][0]) && (Desc->idProduct == SupportedDevices_VidPid[i][1])) { m_Type = XBOX_INPUT_DEVICE::HW_XBOX_CONTROLLER; m_UcType = XINPUT_DEVTYPE_GAMEPAD; m_UcSubType = XINPUT_DEVSUBTYPE_GC_GAMEPAD; From f17b7f7fa688a5d82999e10dbde7bbcb88072ac9 Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Wed, 5 Oct 2022 06:44:58 -0500 Subject: [PATCH 2/4] input: check for error from libusb_open and report as device invalid --- src/common/input/LibusbDevice.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/common/input/LibusbDevice.cpp b/src/common/input/LibusbDevice.cpp index b7b17e31c..87b30a8f2 100644 --- a/src/common/input/LibusbDevice.cpp +++ b/src/common/input/LibusbDevice.cpp @@ -185,9 +185,18 @@ namespace Libusb if (m_Type == XBOX_INPUT_DEVICE::DEVICE_INVALID) { return; } - // Duke, S and SBC have 1 configuration, 1 interface and 2 endpoints (input and output) and use the default alternate setting zero. - // The code below assumes that third-party controllers follow suit. - if (libusb_open(Dev, &m_hDev) == 0) { + // check if we are able to open device through libusb + if (int err = libusb_open(Dev, &m_hDev)) { + // Couldn't open device, create an error log report then don't use it. + EmuLog(LOG_LEVEL::ERROR2, "Unable to open original xbox device \"%s\" (%hX:%hX), libusb's error was: %s", + m_Name.c_str(), Desc->idVendor, Desc->idProduct, libusb_strerror(err)); + m_Type = XBOX_INPUT_DEVICE::DEVICE_INVALID; + return; + } + // If we are able to open device, continue with query process. + else { + // Duke, S and SBC have 1 configuration, 1 interface and 2 endpoints (input and output) and use the default alternate setting zero. + // The code below assumes that third-party controllers follow suit. libusb_config_descriptor *ConfDesc; if (libusb_get_active_config_descriptor(Dev, &ConfDesc) == 0) { if (ConfDesc->bNumInterfaces == 1) { From 5f58ae918cb01011881b34c2e7f4cd589ef5bccd Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Wed, 5 Oct 2022 16:46:17 -0500 Subject: [PATCH 3/4] input: have libusb_claim_interface's return actually give err number than comparsion check for non-zero --- src/common/input/LibusbDevice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/input/LibusbDevice.cpp b/src/common/input/LibusbDevice.cpp index 87b30a8f2..c51961f1e 100644 --- a/src/common/input/LibusbDevice.cpp +++ b/src/common/input/LibusbDevice.cpp @@ -220,7 +220,7 @@ namespace Libusb } } EmuLog(LOG_LEVEL::INFO, "Out endpoint %s", m_HasEndpointOut ? "present" : "not present"); - if (int err = libusb_claim_interface(m_hDev, m_IfaceNum) != 0) { + if (int err = libusb_claim_interface(m_hDev, m_IfaceNum)) { EmuLog(LOG_LEVEL::INFO, "Rejected device %s because libusb could not claim its interface. The error was: %s", m_Name.c_str(), libusb_strerror(err)); m_Type = XBOX_INPUT_DEVICE::DEVICE_INVALID; From a37124e2dce3dc2506ee63a44b69250cb94ad4af Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Wed, 5 Oct 2022 16:59:17 -0500 Subject: [PATCH 4/4] readme: create a link to libusb's driver installation section to find suggested driver --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c409a1e5f..c3bd5c299 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Cxbx-Reloaded is an emulator for running Microsoft Xbox (and eventually, Chihiro * [32-bit (x86) Visual C++ 2022 Redistributable](https://aka.ms/vs/17/release/vc_redist.x86.exe) * [Npcap *(used for network emulation)*](https://nmap.org/npcap/#download) * Make sure to enable winpcap compatibility mode. - * WinUSB compliant driver + * [WinUSB compliant driver](https://github.com/libusb/libusb/wiki/Windows#Driver_Installation) * *Optional, only needed for USB pass-through of original Xbox and Steel Battalion controllers.* ### Wine