@mitu I don't think that works (though thank you for the suggestion).
The problem is that my gamepad's number was dynamic so I wouldn't know what number it was until I start the game!
Though I managed to solve the problem by creating a runcommand-onstart.sh script:
root@retropie:/opt/retropie# cat /opt/retropie/configs/all/runcommand-onstart.sh
#!/bin/bash
# fix player input index order!
# on my system, the bluetooth gamepad always gets index 0 when it is active
# which messes up the controls for all joystick based games!
if [ -e "/dev/input/js2" ]
then
# Bluetooth controller is currently active!
# Change retroarch's config order for player 1 through 3...
# wired joystick 1 for player 1, wired joystick 2 for player 2, wireless gamepad for player 3
/bin/cp /opt/retropie/configs/all/base_configs/retroarch.cfg.all-bluetooth_enabled /opt/retropie/configs/all/retroarch.cfg
# bluetooth gamepad for player 1, for psx!
/bin/cp /opt/retropie/configs/all/base_configs/retroarch.cfg.psx-bluetooth_enabled /opt/retropie/configs/psx/retroarch.cfg
else
# Bluetooth controller not presently active!
# Reset retroarch's config
# wired joystick 1 for player 1, wired joystick 2 for player 2
/bin/cp /opt/retropie/configs/all/base_configs/retroarch.cfg.all-bluetooth_disabled /opt/retropie/configs/all/retroarch.cfg
# no custom input config for psx!
/bin/cp /opt/retropie/configs/all/base_configs/retroarch.cfg.psx-bluetooth_disabled /opt/retropie/configs/psx/retroarch.cfg
fi
root@retropie:/opt/retropie#
This is hardcoded to my system but it solves my problem!
It looks for /dev/input/js2 (which is the device for my bluetooth gamepad) and, if it exists, it overwrites the retroarch.cfg global (and the psx) config to map the input_playerX_joypad_index parameter! :)