1
0
mirror of https://github.com/libretro/RetroArch synced 2025-04-01 13:20:43 +00:00

Input state overflow band-aid ()

This commit is contained in:
sonninnos 2024-01-26 19:44:48 +02:00 committed by GitHub
parent 4c69431798
commit 8ad8b6bdad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -688,7 +688,7 @@ bool input_driver_button_combo(
return false; return false;
} }
static int16_t input_state_wrap( static int32_t input_state_wrap(
input_driver_t *current_input, input_driver_t *current_input,
void *data, void *data,
const input_device_driver_t *joypad, const input_device_driver_t *joypad,
@ -701,7 +701,7 @@ static int16_t input_state_wrap(
unsigned idx, unsigned idx,
unsigned id) unsigned id)
{ {
int16_t ret = 0; int32_t ret = 0;
if (!binds) if (!binds)
return 0; return 0;
@ -780,18 +780,33 @@ static int16_t input_state_wrap(
idx, idx,
id); id);
/* No binds, no input. This is for ignoring RETROK_UNKNOWN
* if the driver allows setting the key down somehow.
* Otherwise all hotkeys and inputs with null bind get triggered. */
if (device == RETRO_DEVICE_JOYPAD) if (device == RETRO_DEVICE_JOYPAD)
{ {
/* Drivers can also overflow when sending all keys at once, /* Drivers can overflow when sending too many keys at once.. */
* resulting in negative values which also need to be ignored.. */ if (id == RETRO_DEVICE_ID_JOYPAD_MASK && ret)
if ( (id == RETRO_DEVICE_ID_JOYPAD_MASK && ret < 0) {
|| ( binds[_port][id].key == RETROK_UNKNOWN /* Deal with menu toggle combo buttons that won't stay inside +32767. */
&& binds[_port][id].mbutton == NO_BTN if (ret == -0x8000) /* R3 */
&& binds[_port][id].joykey == NO_BTN ret = 0x8000;
&& binds[_port][id].joyaxis == AXIS_NONE)) else if (ret == -0x4000) /* LR+R3 */
ret = 0x8000 + 0x4000;
else if (ret < 0)
ret = 0;
return ret;
}
/* No binds, no input. This is for ignoring RETROK_UNKNOWN
* if the driver allows setting the key down somehow.
* Otherwise all hotkeys and inputs with null bind get triggered. */
if ( id != RETRO_DEVICE_ID_JOYPAD_MASK && ret
&& binds[_port][id].key == RETROK_UNKNOWN
&& binds[_port][id].mbutton == NO_BTN
&& ( ( binds[_port][id].joykey == NO_BTN
&& binds[_port][id].joyaxis == AXIS_NONE)
|| ( joypad_info->auto_binds[id].joykey == NO_BTN
&& joypad_info->auto_binds[id].joyaxis == AXIS_NONE)
)
)
return 0; return 0;
} }
@ -1213,7 +1228,7 @@ static int16_t input_state_device(
settings_t *settings, settings_t *settings,
input_mapper_t *handle, input_mapper_t *handle,
unsigned input_analog_dpad_mode, unsigned input_analog_dpad_mode,
int16_t ret, int32_t ret,
unsigned port, unsigned device, unsigned port, unsigned device,
unsigned idx, unsigned id, unsigned idx, unsigned id,
bool button_mask) bool button_mask)
@ -1594,8 +1609,8 @@ static int16_t input_state_internal(
* 'virtual' port index */ * 'virtual' port index */
while ((mapped_port = *(input_remap_port_map++)) < MAX_USERS) while ((mapped_port = *(input_remap_port_map++)) < MAX_USERS)
{ {
int16_t ret = 0; int32_t ret = 0;
int16_t port_result = 0; int32_t port_result = 0;
unsigned input_analog_dpad_mode = settings->uints.input_analog_dpad_mode[mapped_port]; unsigned input_analog_dpad_mode = settings->uints.input_analog_dpad_mode[mapped_port];
joypad_info.joy_idx = settings->uints.input_joypad_index[mapped_port]; joypad_info.joy_idx = settings->uints.input_joypad_index[mapped_port];
@ -4833,7 +4848,7 @@ static void input_keys_pressed(
} }
{ {
int16_t ret = 0; int32_t ret = 0;
bool libretro_input_pressed = false; bool libretro_input_pressed = false;
/* Check libretro input if emulated device type is active, /* Check libretro input if emulated device type is active,
@ -5588,7 +5603,7 @@ void input_driver_poll(void)
if (joypad) if (joypad)
{ {
unsigned k, j; unsigned k, j;
int16_t ret = input_state_wrap( int32_t ret = input_state_wrap(
input_st->current_driver, input_st->current_driver,
input_st->current_data, input_st->current_data,
input_st->primary_joypad, input_st->primary_joypad,