From 661385ad3435688b4e6e06d0a84142e15e236252 Mon Sep 17 00:00:00 2001 From: cmitu <31816814+cmitu@users.noreply.github.com> Date: Mon, 17 Apr 2023 07:41:09 +0100 Subject: [PATCH] mupen64plus: update runtime hotkey configuration The Mupen64plus start-up script adds 3 'hotkey' combinations for the connected joysticks by looking at the RetroArch auto-config profile(s) for the joysticks. To handle cases when the SDL joystick name (used by Mupen64Plus) is different than the 'udev' name and the auto-config profile is not found just by looking at the filename, an additional search for the profile .cfg files was added - using the 'vendor' and 'product' IDs of the joystick. This takes advantage of the changes in e392c7ac for the input configuration, which save 'vendor'/'product' IDs to the RetroArch's auto-config profile. I re-organized a bit the hotkey bindings loop so it's indexed by the number of joysticks detected. This avoids searching for the auto-config profile 3 times (# of hotkey bindings), which can is more expensive when using `grep` to look up the `vendor`/`product` IDs. Since 'bind' is a reserved built-in in Bash, I renamed it to `hotkeys_bind`, similar to the other arrays used for hotkeys set-up. --- .../emulators/mupen64plus/mupen64plus.sh | 53 ++++++++++++------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/scriptmodules/emulators/mupen64plus/mupen64plus.sh b/scriptmodules/emulators/mupen64plus/mupen64plus.sh index 8834f236b7..09224e7056 100755 --- a/scriptmodules/emulators/mupen64plus/mupen64plus.sh +++ b/scriptmodules/emulators/mupen64plus/mupen64plus.sh @@ -99,11 +99,13 @@ function remap() { # read retroarch auto config file and use config # for mupen64plus.cfg local file - local bind + local hotkeys_bind=( "" "" "" ) local hotkeys_rp=( "input_exit_emulator" "input_load_state" "input_save_state" ) local hotkeys_m64p=( "Joy Mapping Stop" "Joy Mapping Load State" "Joy Mapping Save State" ) local i local j + local product_id + local vendor_id iniConfig " = " "" "$config" if ! grep -q "\[CoreEvents\]" "$config"; then @@ -112,23 +114,38 @@ function remap() { fi local atebitdo_hack - for i in {0..2}; do - bind="" - for device_num in "${!devices[@]}"; do - # get name of retroarch auto config file - file=$(grep -lF "\"${devices[$device_num]}\"" "$configdir/all/retroarch-joypads/"*.cfg) - atebitdo_hack=0 - [[ "$file" == *8Bitdo* ]] && getAutoConf "8bitdo_hack" && atebitdo_hack=1 - if [[ -f "$file" ]]; then - if [[ -n "$bind" && "$bind" != *, ]]; then - bind+="," + for device_num in "${!devices[@]}"; do + # get the name of the retroarch auto config file + file=$(grep -lF "\"${devices[$device_num]}\"" "$configdir/all/retroarch-joypads/"*.cfg) + + # if we can't find the profile .cfg by name, try to match it using the vendor/product IDs + # handles the situation when joystick's SDL name is different than the udev name (SDL 2.0.14+) + if [[ ! -f "$file" ]]; then + vendor_id="$(