DirectInput: use correct joypad id

Previously `joypad_count` was used as the index into the d_joypads array when initializing a new gamepad.
This caused the accidental override of an already connected device when a gamepad with a lower id was disconnected and connected again.

fixes #17566

(cherry picked from commit 802a0316c5)
This commit is contained in:
Andreas Haas 2020-07-31 20:16:51 +02:00 committed by Rémi Verschelde
parent f19bab5165
commit abdcb7d299
1 changed files with 3 additions and 3 deletions

View File

@ -153,8 +153,8 @@ bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE *instance) {
if (have_device(instance->guidInstance) || num == -1) if (have_device(instance->guidInstance) || num == -1)
return false; return false;
d_joypads[joypad_count] = dinput_gamepad(); d_joypads[num] = dinput_gamepad();
dinput_gamepad *joy = &d_joypads[joypad_count]; dinput_gamepad *joy = &d_joypads[num];
const DWORD devtype = (instance->dwDevType & 0xFF); const DWORD devtype = (instance->dwDevType & 0xFF);
@ -178,7 +178,7 @@ bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE *instance) {
WORD version = 0; WORD version = 0;
sprintf_s(uid, "%04x%04x%04x%04x%04x%04x%04x%04x", type, 0, vendor, 0, product, 0, version, 0); sprintf_s(uid, "%04x%04x%04x%04x%04x%04x%04x%04x", type, 0, vendor, 0, product, 0, version, 0);
id_to_change = joypad_count; id_to_change = num;
slider_count = 0; slider_count = 0;
joy->di_joy->SetDataFormat(&c_dfDIJoystick2); joy->di_joy->SetDataFormat(&c_dfDIJoystick2);