From 059e1004259c6c356504cdfcfd4f49d149c9e737 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Fri, 15 Mar 2013 21:26:26 -0500 Subject: [PATCH] Check for HID wiimote name on Windows instead of assuming everything is a wiimote. Fixed issue 6031. --- Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp | 19 ++++++++++++++++++- .../Core/Src/HW/WiimoteReal/WiimoteReal.cpp | 6 +++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp b/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp index 08a5db8217..8caeb90846 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp @@ -28,6 +28,7 @@ #include "Common.h" #include "WiimoteReal.h" +#include "StringUtil.h" // Used for pair up #undef NTDDI_VERSION @@ -49,6 +50,7 @@ typedef struct _HIDD_ATTRIBUTES typedef VOID (__stdcall *PHidD_GetHidGuid)(LPGUID); typedef BOOLEAN (__stdcall *PHidD_GetAttributes)(HANDLE, PHIDD_ATTRIBUTES); typedef BOOLEAN (__stdcall *PHidD_SetOutputReport)(HANDLE, PVOID, ULONG); +typedef BOOLEAN (__stdcall *PHidD_GetProductString)(HANDLE, PVOID, ULONG); typedef BOOL (__stdcall *PBth_BluetoothFindDeviceClose)(HBLUETOOTH_DEVICE_FIND); typedef HBLUETOOTH_DEVICE_FIND (__stdcall *PBth_BluetoothFindFirstDevice)(const BLUETOOTH_DEVICE_SEARCH_PARAMS*, BLUETOOTH_DEVICE_INFO*); @@ -65,6 +67,7 @@ typedef DWORD (__stdcall *PBth_BluetoothEnumerateInstalledServices)(HANDLE, BLUE PHidD_GetHidGuid HidD_GetHidGuid = NULL; PHidD_GetAttributes HidD_GetAttributes = NULL; PHidD_SetOutputReport HidD_SetOutputReport = NULL; +PHidD_GetProductString HidD_GetProductString = NULL; PBth_BluetoothFindDeviceClose Bth_BluetoothFindDeviceClose = NULL; PBth_BluetoothFindFirstDevice Bth_BluetoothFindFirstDevice = NULL; @@ -104,7 +107,9 @@ inline void init_lib() HidD_GetHidGuid = (PHidD_GetHidGuid)GetProcAddress(hid_lib, "HidD_GetHidGuid"); HidD_GetAttributes = (PHidD_GetAttributes)GetProcAddress(hid_lib, "HidD_GetAttributes"); HidD_SetOutputReport = (PHidD_SetOutputReport)GetProcAddress(hid_lib, "HidD_SetOutputReport"); - if (!HidD_GetHidGuid || !HidD_GetAttributes || !HidD_SetOutputReport) + HidD_GetProductString = (PHidD_GetProductString)GetProcAddress(hid_lib, "HidD_GetProductString"); + if (!HidD_GetHidGuid || !HidD_GetAttributes || + !HidD_SetOutputReport || !HidD_GetProductString) { PanicAlertT("Failed to load hid.dll"); exit(EXIT_FAILURE); @@ -289,6 +294,18 @@ bool Wiimote::Connect() return false; } + TCHAR name[128] = {}; + HidD_GetProductString(dev_handle, name, 128); + + //ERROR_LOG(WIIMOTE, "product string: %s", TStrToUTF8(name).c_str()); + + if (!IsValidBluetoothName(TStrToUTF8(name))) + { + CloseHandle(dev_handle); + dev_handle = 0; + return false; + } + #if 0 HIDD_ATTRIBUTES attr; attr.Size = sizeof(attr); diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp index 3608c060fc..131befc3ae 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp @@ -649,9 +649,9 @@ void StateChange(EMUSTATE_CHANGE newState) bool IsValidBluetoothName(const std::string& name) { - std::string const prefix("Nintendo RVL-"); - return name.size() > prefix.size() && - std::equal(prefix.begin(), prefix.end(), name.begin()); + return + "Nintendo RVL-CNT-01" == name || + "Nintendo RVL-CNT-01-TR" == name; } }; // end of namespace