Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input state overflow band-aid #16168

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions input/input_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ bool input_driver_button_combo(
return false;
}

static int16_t input_state_wrap(
static int32_t input_state_wrap(
input_driver_t *current_input,
void *data,
const input_device_driver_t *joypad,
Expand All @@ -701,7 +701,7 @@ static int16_t input_state_wrap(
unsigned idx,
unsigned id)
{
int16_t ret = 0;
int32_t ret = 0;

if (!binds)
return 0;
Expand Down Expand Up @@ -780,18 +780,33 @@ static int16_t input_state_wrap(
idx,
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)
{
/* Drivers can also overflow when sending all keys at once,
* resulting in negative values which also need to be ignored.. */
if ( (id == RETRO_DEVICE_ID_JOYPAD_MASK && ret < 0)
|| ( binds[_port][id].key == RETROK_UNKNOWN
&& binds[_port][id].mbutton == NO_BTN
&& binds[_port][id].joykey == NO_BTN
&& binds[_port][id].joyaxis == AXIS_NONE))
/* Drivers can overflow when sending too many keys at once.. */
if (id == RETRO_DEVICE_ID_JOYPAD_MASK && ret)
{
/* Deal with menu toggle combo buttons that won't stay inside +32767. */
if (ret == -0x8000) /* R3 */
ret = 0x8000;
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;
}

Expand Down Expand Up @@ -1213,7 +1228,7 @@ static int16_t input_state_device(
settings_t *settings,
input_mapper_t *handle,
unsigned input_analog_dpad_mode,
int16_t ret,
int32_t ret,
unsigned port, unsigned device,
unsigned idx, unsigned id,
bool button_mask)
Expand Down Expand Up @@ -1594,8 +1609,8 @@ static int16_t input_state_internal(
* 'virtual' port index */
while ((mapped_port = *(input_remap_port_map++)) < MAX_USERS)
{
int16_t ret = 0;
int16_t port_result = 0;
int32_t ret = 0;
int32_t port_result = 0;
unsigned input_analog_dpad_mode = settings->uints.input_analog_dpad_mode[mapped_port];

joypad_info.joy_idx = settings->uints.input_joypad_index[mapped_port];
Expand Down Expand Up @@ -4833,7 +4848,7 @@ static void input_keys_pressed(
}

{
int16_t ret = 0;
int32_t ret = 0;
bool libretro_input_pressed = false;

/* Check libretro input if emulated device type is active,
Expand Down Expand Up @@ -5588,7 +5603,7 @@ void input_driver_poll(void)
if (joypad)
{
unsigned k, j;
int16_t ret = input_state_wrap(
int32_t ret = input_state_wrap(
input_st->current_driver,
input_st->current_data,
input_st->primary_joypad,
Expand Down
Loading