0% found this document useful (0 votes)
38 views4 pages

Game Controller Configuration Script

This Bash script is designed to configure game controller settings and manage device parameters for various gaming platforms. It checks for the existence of certain files and directories to determine the appropriate settings and paths for game controllers, and it includes logic for different operating systems and devices. The script also sets permissions and prepares the environment for executing game controller-related commands.

Uploaded by

Paulo Ubiratan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views4 pages

Game Controller Configuration Script

This Bash script is designed to configure game controller settings and manage device parameters for various gaming platforms. It checks for the existence of certain files and directories to determine the appropriate settings and paths for game controllers, and it includes logic for different operating systems and devices. The script also sets permissions and prepares the environment for executing game controller-related commands.

Uploaded by

Paulo Ubiratan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#!

/bin/bash
#
# SPDX-License-Identifier: MIT
#
# This file can and should be sourced by ports for various parameters to
# minimize script customizations and allow for easier future updates
# like adding additional supported devices.
# Thanks to JohnnyonFlame, dhwz, romadu, and shantigilbert for the
# suggestion and assistance with this.
# Source used for gptokeyb available at
# [Link]
# Source used for oga_controls available at
# [Link]

# Set default virtual screen


CUR_TTY=/dev/tty0

if [[ -e "/usr/share/plymouth/themes/[Link]" ]]; then


if [ ! -z "$(cat /etc/fstab | grep roms2 | tr -d '\0')" ]; then
directory="roms2"
else
directory="roms"
fi
else
directory="roms"
fi

if [ -f "/etc/os-release" ]; then
source /etc/os-release
fi

if [ -d "/PortMaster/" ]; then
controlfolder="/PortMaster"
elif [ -d "/opt/system/Tools/PortMaster/" ]; then
controlfolder="/opt/system/Tools/PortMaster"
elif [ -d "/opt/tools/PortMaster/" ]; then
controlfolder="/opt/tools/PortMaster"
else
controlfolder="/$directory/ports/PortMaster"
fi

sudo echo "Testing for sudo..." > /dev/null 2>&1


if [ $? != 0 ]; then
echo "No sudo present."
ESUDO=""
ESUDOKILL="-1" # for 351Elec and EmuELEC use "-1" (numeric one) or "-k"
ESUDOKILL2="-1"
export SDL_GAMECONTROLLERCONFIG_FILE="$controlfolder/[Link]"
else
ESUDO="sudo --preserve-
env=SDL_GAMECONTROLLERCONFIG_FILE,DEVICE,param_device,HOTKEY,ANALOGSTICKS,SDL_KMSDR
M_ORIENTATION,SDL_KMSDRM_ROTATION"
ESUDOKILL="-sudokill" # for ArkOS, RetroOZ, and TheRA use "-sudokill"
ESUDOKILL2="-Z" # Doesnt need sudokill as the process is run with sudo.
export SDL_GAMECONTROLLERCONFIG_FILE="$controlfolder/[Link]"
fi

if [[ -e "/usr/share/plymouth/themes/[Link]" ]]; then


whichos=$(grep "title=" "/usr/share/plymouth/themes/[Link]")
if [[ $whichos == *"TheRA"* ]]; then
raloc="/opt/retroarch/bin"
raconf=""
elif [[ $whichos == *"RetroOZ"* ]]; then
raloc="/opt/retroarch/bin"
raconf="--config /home/odroid/.config/retroarch/[Link]"
else
raloc="/usr/local/bin"
raconf=""
fi
elif [ "${OS_NAME}" == "JELOS" ] || [ "${OS_NAME}" == "UnofficialOS" ]; then
raloc="/usr/bin"
raconf="--config /storage/.config/retroarch/[Link]"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib32
elif [[ -e "/storage/.config/.OS_ARCH" ]] || [ -z $ESUDO ]; then
raloc="/usr/bin"
raconf="--config /storage/roms/gamedata/retroarch/config/[Link]"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib32
fi

SDLDBFILE="${SDL_GAMECONTROLLERCONFIG_FILE}"
[ -z "${SDLDBFILE}" ] && SDLDBFILE="${controlfolder}/[Link]"
SDLDBUSERFILE="${HOME}/.config/SDL-GameControllerDB/[Link]"
[ ! -f "${SDLDBUSERFILE}" ] &&
SDLDBUSERFILE="${controlfolder}/[Link]"

get_controls() {

ANALOGSTICKS="2"
LOWRES="N"

if [[ -e "/dev/input/by-path/[Link]-usb-0:1.2:1.0-event-
joystick" ]]; then
DEVICE="03000000091200000031000011010000"
param_device="anbernic"
LOWRES="Y"
if [ -f "/boot/[Link]" ] || [ $(cat
"/storage/.config/.OS_ARCH") == "RG351V" ]; then
ANALOGSTICKS="1"
LOWRES="N"
fi
elif [[ -e "/dev/input/by-path/platform-odroidgo2-joypad-event-joystick" ]]; then
if [[ ! -z $(cat /etc/emulationstation/es_input.cfg | grep
"190000004b4800000010000001010000") ]]; then
DEVICE="190000004b4800000010000001010000"
param_device="oga"
export HOTKEY="l3"
else
if [ -f "/usr/lib/aarch64-linux-gnu/[Link].0.2600.2" ]; then
DEVICE="19005b284b4800000010000000010000"
else
DEVICE="190000004b4800000010000000010000"
fi
param_device="rk2020"
fi
ANALOGSTICKS=1
LOWRES="Y"
elif [[ -e "/dev/input/by-path/platform-odroidgo3-joypad-event-joystick" ]]; then
DEVICE="190000004b4800000011000000010000"
param_device="ogs"
if [ "$(cat ~/.config/.OS)" == "ArkOS" ] && [ "$(cat ~/.config/.DEVICE)" ==
"RGB10MAX" ]; then
sed -i 's/back:b12,guide:b16,start:b13/back:b14,guide:b12,start:b15/' $
{controlfolder}/[Link]
sed -i 's/leftstick:b14,rightstick:b15/leftstick:b16,rightstick:b17/' $
{controlfolder}/[Link]
export HOTKEY="guide"
fi
if [[ -e "/opt/.retrooz/device" ]]; then
param_device="$(cat /opt/.retrooz/device)"
if [[ "$param_device" == *"rgb10max2native"* ]]; then
param_device="rgb10maxnative"
elif [[ "$param_device" == *"rgb10max2top"* ]]; then
param_device="rgb10maxtop"
fi
if [[ "$param_device" == *"rgb10maxnative"* ]]; then
sed -i 's/back:b12/back:b14/; s/guide:b16/guide:b12/;
s/guide:b14/guide:b12/; s/start:b13/start:b15/; s/leftstick:b14/leftstick:b16/;
s/rightstick:b15/rightstick:b17/' ${controlfolder}/[Link]
elif [[ "$param_device" == *"rgb10maxtop"* ]]; then
sed -i 's/back:b14/back:b12/; s/guide:b12/guide:b14/;
s/guide:b16/guide:b14/; s/start:b15/start:b13/; s/leftstick:b14/leftstick:b16/;
s/rightstick:b15/rightstick:b17/' ${controlfolder}/[Link]
elif [[ "$param_device" == *"ogs"* ]]; then
sed -i 's/back:b14/back:b12/; s/guide:b12/guide:b16/;
s/guide:b14/guide:b16/; s/start:b15/start:b13/; s/leftstick:b16/leftstick:b14/;
s/rightstick:b17/rightstick:b15/' ${controlfolder}/[Link]
fi
fi
elif [[ -e "/dev/input/by-path/platform-gameforce-gamepad-event-joystick" ]];
then
DEVICE="19000000030000000300000002030000"
param_device="chi"
export HOTKEY="l3"
elif [[ -e "/dev/input/by-path/platform-singleadc-joypad-event-joystick" ]]; then
DEVICE="190000004b4800000111000000010000"
param_device="rg552"
LOWRES="N"
else
DEVICE="${1}"
param_device="${2}"
fi

export SDL_GAMECONTROLLERCONFIG_FILE="/tmp/[Link]"

# Spit the controller of the device our heuristics found (if it did).
if [[ ! -z ${DEVICE} ]]; then
grep "${SDLDBUSERFILE}" -e "${DEVICE}" > /tmp/[Link]
else
echo "" > /tmp/[Link]
fi

if [[ -f "${HOME}/.config/emulationstation/es_input.cfg" ]]; then


$controlfolder/[Link] -i "${HOME}/.config/emulationstation/es_input.cfg"
"/tmp/[Link]" > /dev/null 2>&1
fi

SDLDBUSERFILE="${HOME}/.config/SDL-GameControllerDB/[Link]"
sdl_controllerconfig="$(< "${SDL_GAMECONTROLLERCONFIG_FILE}")"
}

source $controlfolder/device_info.txt
source $controlfolder/[Link]

if [ ! -z "$ESUDO" ]; then
$ESUDO chmod 666 /dev/tty0
$ESUDO chmod 666 /dev/tty1
$ESUDO chmod 666 /dev/uinput
fi

GPTOKEYB2="$ESUDO env LD_PRELOAD=$controlfolder/libinterpose.${DEVICE_ARCH}.so


$controlfolder/gptokeyb2 $ESUDOKILL2"
GPTOKEYB="$ESUDO $controlfolder/gptokeyb $ESUDOKILL"

You might also like