From b6ae697fad0716891c390b9725fb038122f7e04b Mon Sep 17 00:00:00 2001 From: revvv <8734113+revvv@users.noreply.github.com> Date: Sat, 26 Mar 2022 16:02:07 +0100 Subject: [PATCH] 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. --- input/connect/joypad_connection.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/input/connect/joypad_connection.c b/input/connect/joypad_connection.c index 92408e0286..b387fd38bc 100644 --- a/input/connect/joypad_connection.c +++ b/input/connect/joypad_connection.c @@ -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];