Skip to content

Commit

Permalink
Make find_connection_entry() more specific
Browse files Browse the repository at this point in the history
Controllers with same VID/PID are distinguished by the device name.
1. The Wii U only sends a prefix of the device name.
2. The check preferred the device name over VID/PID which was not
   intended.

Example: The device name "USB Gamepad" is truncated to "USB" which
was mapped to "Generic SNES USB Controller", although VID/PID did not
match.
  • Loading branch information
revvv authored and inactive123 committed Mar 27, 2022
1 parent 75f9495 commit b6ae697
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions input/connect/joypad_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,29 @@ joypad_connection_entry_t *find_connection_entry(uint16_t vid, uint16_t pid, con

for(i = 0; pad_map[i].name != NULL; i++)
{
const char *name_match = has_name
? strstr(pad_map[i].name, name)
: NULL;
/* The Wii Pro Controller and WiiU Pro controller have
char *name_match = NULL;
/* The Wii Pro Controller and WiiU Pro controller have
* the same VID/PID, so we have to use the
* descriptor string to differentiate them. */
if( pad_map[i].vid == VID_NINTENDO
&& pad_map[i].pid == PID_NINTENDO_PRO)
if( pad_map[i].vid == VID_NINTENDO
&& pad_map[i].pid == PID_NINTENDO_PRO
&& pad_map[i].vid == vid
&& pad_map[i].pid == pid)
{
if(!string_is_equal(pad_map[i].name, name))
continue;
}
name_match = has_name
? strstr(pad_map[i].name, name)
: NULL;
if (has_name && strlen(name) == 3)
{
/* Wii U: Argument 'name' is only the prefix of the device name!?
* This is not enough for a reliable name match! */
RARCH_ERR("find_connection_entry(0x%04x,0x%04x): device name '%s' too short: assuming controller '%s'\n",
SWAP_IF_BIG(vid), SWAP_IF_BIG(pid), name, pad_map[i].name);
}
else
if(!string_is_equal(pad_map[i].name, name))
continue;
}

if(name_match || (pad_map[i].vid == vid && pad_map[i].pid == pid))
return &pad_map[i];
Expand Down

0 comments on commit b6ae697

Please sign in to comment.