diff --git a/configuration.c b/configuration.c index 012ff434b860..a0c23f0e4989 100644 --- a/configuration.c +++ b/configuration.c @@ -1481,6 +1481,7 @@ bool config_overlay_enable_default(void) static struct config_array_setting *populate_settings_array( settings_t *settings, int *size) { + unsigned i = 0; unsigned count = 0; struct config_array_setting *tmp = (struct config_array_setting*)calloc(1, (*size + 1) * sizeof(struct config_array_setting)); @@ -1511,22 +1512,23 @@ static struct config_array_setting *populate_settings_array( SETTING_ARRAY("input_android_physical_keyboard", settings->arrays.input_android_physical_keyboard, false, NULL, true); #endif - SETTING_ARRAY("input_player1_reserved_device", settings->arrays.input_player1_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player2_reserved_device", settings->arrays.input_player2_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player3_reserved_device", settings->arrays.input_player3_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player4_reserved_device", settings->arrays.input_player4_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player5_reserved_device", settings->arrays.input_player5_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player6_reserved_device", settings->arrays.input_player6_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player7_reserved_device", settings->arrays.input_player7_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player8_reserved_device", settings->arrays.input_player8_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player9_reserved_device", settings->arrays.input_player9_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player10_reserved_device", settings->arrays.input_player10_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player11_reserved_device", settings->arrays.input_player11_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player12_reserved_device", settings->arrays.input_player12_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player13_reserved_device", settings->arrays.input_player13_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player14_reserved_device", settings->arrays.input_player14_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player15_reserved_device", settings->arrays.input_player15_reserved_device, false, NULL, true); - SETTING_ARRAY("input_player16_reserved_device", settings->arrays.input_player16_reserved_device, false, NULL, true); + for (i = 0; i < MAX_USERS; i++) + { + size_t _len; + char formatted_number[4]; + char prefix[16]; + char key[32]; + + formatted_number[0] = '\0'; + + snprintf(formatted_number, sizeof(formatted_number), "%u", i + 1); + _len = strlcpy(prefix, "input_player", sizeof(prefix)); + strlcpy(prefix + _len, formatted_number, sizeof(prefix) - _len); + _len = strlcpy(key, prefix, sizeof(key)); + strlcpy(key + _len, "_reserved_device", sizeof(key) - _len); + + SETTING_ARRAY(key, settings->arrays.input_reserved_devices[i], false, NULL, true); + } #ifdef HAVE_MENU SETTING_ARRAY("menu_driver", settings->arrays.menu_driver, false, NULL, true); diff --git a/configuration.h b/configuration.h index 1a732ba1b061..50d51976a200 100644 --- a/configuration.h +++ b/configuration.h @@ -476,22 +476,7 @@ typedef struct settings char input_android_physical_keyboard[255]; #endif - char input_player1_reserved_device[255]; - char input_player2_reserved_device[255]; - char input_player3_reserved_device[255]; - char input_player4_reserved_device[255]; - char input_player5_reserved_device[255]; - char input_player6_reserved_device[255]; - char input_player7_reserved_device[255]; - char input_player8_reserved_device[255]; - char input_player9_reserved_device[255]; - char input_player10_reserved_device[255]; - char input_player11_reserved_device[255]; - char input_player12_reserved_device[255]; - char input_player13_reserved_device[255]; - char input_player14_reserved_device[255]; - char input_player15_reserved_device[255]; - char input_player16_reserved_device[255]; + char input_reserved_devices[MAX_USERS][255]; char audio_device[255]; char camera_device[255]; diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index b653953ef739..18879809cb85 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -1398,9 +1398,8 @@ static void handle_hotplug(android_input_t *android, reserved_port = input_device_get_reserved_port( vendorId, productId, device_name); - if (reserved_port > -1) { + if (reserved_port > -1) *port = reserved_port; - } if (*port < 0) *port = android->pads_connected; diff --git a/input/input_driver.c b/input/input_driver.c index 186464e50572..2be416b077e3 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -7297,32 +7297,14 @@ static int input_device_get_reserved_port(int vendor_id, int port; bool is_reserved; - char settings_key[256]; char settings_value[256]; int settings_value_vendor_id; int settings_value_product_id; char settings_value_device_name[256]; - char *settings_values[MAX_USERS]; - settings_values[0] = settings->arrays.input_player1_reserved_device; - settings_values[1] = settings->arrays.input_player2_reserved_device; - settings_values[2] = settings->arrays.input_player3_reserved_device; - settings_values[3] = settings->arrays.input_player4_reserved_device; - settings_values[4] = settings->arrays.input_player5_reserved_device; - settings_values[5] = settings->arrays.input_player6_reserved_device; - settings_values[6] = settings->arrays.input_player7_reserved_device; - settings_values[7] = settings->arrays.input_player8_reserved_device; - settings_values[8] = settings->arrays.input_player9_reserved_device; - settings_values[9] = settings->arrays.input_player10_reserved_device; - settings_values[10] = settings->arrays.input_player11_reserved_device; - settings_values[11] = settings->arrays.input_player12_reserved_device; - settings_values[12] = settings->arrays.input_player13_reserved_device; - settings_values[13] = settings->arrays.input_player14_reserved_device; - settings_values[14] = settings->arrays.input_player15_reserved_device; - settings_values[15] = settings->arrays.input_player16_reserved_device; for (port = 0; port < MAX_USERS; port++) { - strlcpy(settings_value, settings_values[port], sizeof(settings_value)); + strlcpy(settings_value, settings->arrays.input_reserved_devices[port], sizeof(settings_value)); if (!string_is_empty(settings_value)) { @@ -7332,9 +7314,7 @@ static int input_device_get_reserved_port(int vendor_id, is_reserved = string_is_equal(device_name, settings_value_device_name); } else - { is_reserved = (vendor_id == settings_value_vendor_id && product_id == settings_value_product_id); - } if (is_reserved) {