@@ -163,7 +163,7 @@ static int action_scan_input_desc(const char *path,
163163{
164164 const char * menu_label = NULL ;
165165 unsigned key = 0 ;
166- unsigned inp_desc_user = 0 ;
166+ unsigned user_idx = 0 ;
167167 struct retro_keybind * target = NULL ;
168168
169169 menu_entries_get_last_stack (NULL , & menu_label , NULL , NULL , NULL );
@@ -172,39 +172,52 @@ static int action_scan_input_desc(const char *path,
172172 msg_hash_to_str (MENU_ENUM_LABEL_DEFERRED_REMAPPINGS_PORT_LIST )))
173173 {
174174 settings_t * settings = config_get_ptr ();
175- inp_desc_user = atoi (label );
176- /* Skip 'Device Type', 'Analog to Digital Type' and 'Mapped Port' */
177- key = (unsigned )(idx - 3 );
178- /* Select the reorderer bind */
179- key =
180- (key < RARCH_ANALOG_BIND_LIST_END ) ? input_config_bind_order [key ] : key ;
175+ int type_begin = (type >= MENU_SETTINGS_INPUT_DESC_KBD_BEGIN )
176+ ? MENU_SETTINGS_INPUT_DESC_KBD_BEGIN : MENU_SETTINGS_INPUT_DESC_BEGIN ;
177+
178+ user_idx = (type - type_begin ) / RARCH_ANALOG_BIND_LIST_END ;
179+ key = (type - type_begin ) - RARCH_ANALOG_BIND_LIST_END * user_idx ;
181180
182- if (type >= MENU_SETTINGS_INPUT_DESC_BEGIN
181+ if ( type >= MENU_SETTINGS_INPUT_DESC_BEGIN
183182 && type <= MENU_SETTINGS_INPUT_DESC_END )
184- settings -> uints .input_remap_ids [inp_desc_user ][key ] = RARCH_UNMAPPED ;
183+ settings -> uints .input_remap_ids [user_idx ][key ] = RARCH_UNMAPPED ;
185184 else if (type >= MENU_SETTINGS_INPUT_DESC_KBD_BEGIN
186185 && type <= MENU_SETTINGS_INPUT_DESC_KBD_END )
187- settings -> uints .input_keymapper_ids [inp_desc_user ][key ] = RETROK_UNKNOWN ;
186+ settings -> uints .input_keymapper_ids [user_idx ][key ] = RETROK_UNKNOWN ;
188187
189188 return 0 ;
190189 }
191190 else if (string_is_equal (menu_label ,
192191 msg_hash_to_str (MENU_ENUM_LABEL_DEFERRED_USER_BINDS_LIST )))
193192 {
194- unsigned char player_no_str = atoi (& label [1 ]);
193+ size_t first_bind = 0 ;
194+ char port_str = atoi (& label [1 ]);
195+ menu_entry_t entry ;
196+
197+ user_idx = (unsigned )(port_str - 1 );
198+
199+ /* Skip non-bind menu elements */
200+ MENU_ENTRY_INITIALIZE (entry );
201+
202+ while (first_bind < idx )
203+ {
204+ menu_entry_get (& entry , 0 , first_bind , NULL , false);
205+
206+ if (entry .setting_type == ST_BIND )
207+ break ;
208+
209+ first_bind ++ ;
210+ }
211+
212+ key = (unsigned )(idx - first_bind );
195213
196- inp_desc_user = (unsigned )(player_no_str - 1 );
197- /* This hardcoded value may cause issues if any entries are added on
198- top of the input binds */
199- key = (unsigned )(idx - 8 );
200214 /* Select the reorderer bind */
201- key =
202- (key < RARCH_ANALOG_BIND_LIST_END ) ? input_config_bind_order [key ] : key ;
215+ key = (key < RARCH_ANALOG_BIND_LIST_END ) ? input_config_bind_order [key ] : key ;
203216 }
204217 else
205218 key = input_config_translate_str_to_bind_id (label );
206219
207- target = & input_config_binds [inp_desc_user ][key ];
220+ target = & input_config_binds [user_idx ][key ];
208221
209222 if (target )
210223 {
@@ -335,7 +348,7 @@ static int menu_cbs_init_bind_scan_compare_type(menu_file_list_cbs_t *cbs,
335348 break ;
336349 }
337350
338- if (type >= MENU_SETTINGS_INPUT_DESC_BEGIN
351+ if ( type >= MENU_SETTINGS_INPUT_DESC_BEGIN
339352 && type <= MENU_SETTINGS_INPUT_DESC_END )
340353 {
341354 BIND_ACTION_SCAN (cbs , action_scan_input_desc );
0 commit comments