Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Check for HID wiimote name on Windows instead of assuming everything …
…is a wiimote.

Fixed issue 6031.
  • Loading branch information
jordan-woyak committed Mar 16, 2013
1 parent f1ef51a commit 059e100
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 18 additions & 1 deletion Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp
Expand Up @@ -28,6 +28,7 @@

#include "Common.h"
#include "WiimoteReal.h"
#include "StringUtil.h"

// Used for pair up
#undef NTDDI_VERSION
Expand All @@ -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*);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp
Expand Up @@ -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

0 comments on commit 059e100

Please sign in to comment.