Make find_connection_entry() more specific

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.
This commit is contained in:
revvv 2022-03-26 16:02:07 +01:00 committed by Autechre
parent 75f94950bf
commit b6ae697fad

View File

@ -152,17 +152,28 @@ 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;
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)
&& 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))