Skip to content

Instantly share code, notes, and snippets.

@riskable
Created January 6, 2017 20:18
Show Gist options
  • Save riskable/eb9bfdb97fcdb3815b85dd1d2c2d87a9 to your computer and use it in GitHub Desktop.
Save riskable/eb9bfdb97fcdb3815b85dd1d2c2d87a9 to your computer and use it in GitHub Desktop.
A script to work around the "Player 2" game controller bug in the Linux version of Rocket League
#!/bin/bash
#
# Author: Riskable
#
# License: CC0 (public domain)
#
# Description:
#
# This script will temporarily disable (for a few seconds) any attached USB
# mice that also support emulating a joystick (the type that messes up game
# controller support in Rocket League), launch Rocket League (via Steam), and
# then re-enable the mouse after Rocket League is started up.
#
# Installation:
#
# Save this script somewhere on your (Linux) computer and make it executable
# (e.g. chmod a+x ~/bin/rocket_league_controller_fix.sh). Then you can just
# run it. To make things convenient for yourself you may also want to edit
# "Rocket League.desktop" (find it: 'locate "Rocket League.desktop"') and
# replace this line:
#
# Exec=steam steam://rungameid/252950
#
# ...with this:
#
# Exec=/path/to/rocket_league_controller_fix.sh
#
# (Replace '/path/to/' with the *actual* path to this script)
#
# Notes:
#
# * For this script to work properly you'll need one of kdesudo or gksudo installed.
# * A script (~/bin/temp_disable_mice.sh) will automaticlaly be created that
# temporarily disables problematic mice. It will be executed via sudo (see
# the next bullet).
# * The first time this script runs it'll add some entries to /etc/sudoers and
# this will require the user's password (assuming they have sudo rights).
# Subsequent launches of this script shouldn't require a password.
# * You *MAY* have to adjust the SLEEP_TIME variables if you have a slower
# computer than Riskable =)
#
DISABLE_MOUSE_SCRIPT="$HOME/bin/temp_disable_mice.sh" # Will be created
SUDOAPP=`which kdesudo`
[[ -z "$SUDOAPP" ]] && SUDOAPP=`which gksudo`
echo "Using $SUDOAPP for graphical sudo"
mkdir -p ~/bin # Just in case the user doesn't already have a bin dir
# Check if we can run our disable and enable commands without asking for a
# password and if not add the necessary entries to /etc/sudoers:
sudo -l | grep -q $DISABLE_MOUSE_SCRIPT
if [[ "$?" -ne "0" ]]; then
echo "Entries missing from /etc/sudoers. Adding..."
cat << EOF >> /tmp/rl_temp.txt
# The entries below were added by $0 (Riskable's Rocket League Controller Fix)
User_Alias RLUSERS = $USER
Cmnd_Alias MOUSECMDS = $DISABLE_MOUSE_SCRIPT
RLUSERS ALL=(ALL:ALL) NOPASSWD: MOUSECMDS
EOF
$SUDOAPP -c "cat /tmp/rl_temp.txt >> /etc/sudoers"
rm -f /tmp/rl_temp.txt # Keep things neat & tidy
fi
if [[ ! -e "$DISABLE_MOUSE_SCRIPT" ]]; then
echo "$DISABLE_MOUSE_SCRIPT doesn't exist. Creating it..."
# Create the script that temporarily disables the mouse while RL is launched:
cat << 'EOF' >> $DISABLE_MOUSE_SCRIPT
#!/bin/bash
DISABLED="" # Stores devices that get disabled
SLEEP_TIME=15 # How long to disable the mouse
ps aux | grep -v grep | grep -q /usr/bin/steam
if [[ "$?" -ne "0" ]]; then # Steam isn't running
SLEEP_TIME=30 # Give extra time for it to start if Steam isn't running
fi
# First, find all USB mice:
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
[[ ! -e "${sysdevpath%/dev}" ]] && continue
syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
[[ "$devname" != "input/mouse"* ]] && continue
usbport="$(echo $syspath | cut -d/ -f7)"
# Now only disable this device if it also emulates a joystick/gamepad:
for sysdevpath2 in $(find /sys/bus/usb/devices/usb*/$usbport -name dev); do
syspath2="${sysdevpath2%/dev}"
devname2="$(udevadm info -q name -p $syspath2)"
if [[ "$devname2" = "input/js"* ]]; then
if [[ -e "/sys/bus/usb/devices/$usbport/" ]]; then
product="$(cat /sys/bus/usb/devices/$usbport/product)"
echo "Disabling $product (temporarily) on USB port $usbport"
else
echo "Disabling mouse (temporarily) on USB port $usbport"
fi
DISABLED="$usbport $DISABLED"
echo 0 > /sys/bus/usb/devices/$usbport/authorized
logger -p user.info "Mouse on USB bus-port $usbport (temporarily) disabled"
break
fi
done
done
if [[ -z "$DISABLED" ]]; then
echo "No problematic mice were found. Nothing to do."
exit 0
fi
sleep $SLEEP_TIME # Wait a bit for it to finish opening
# Now we need to repeat the process, re-enabling anything that was disabled:
for usbport in $DISABLED; do
echo "Re-enabling mouse (temporarily) on USB port $usbport"
echo 1 > /sys/bus/usb/devices/$usbport/authorized
logger -p user.info "Mouse on USB bus-port $usbport re-enabled"
done
EOF
chmod 755 $DISABLE_MOUSE_SCRIPT # Make sure it's executable
fi
echo "Running the mouse disable script..."
# Run our script via sudo in the background
sudo $DISABLE_MOUSE_SCRIPT &
sleep 2 # Give it a moment to do its thing
# Launch Rocket League!
echo "Launching Rocket League..."
steam steam://rungameid/252950
exit 0 # All done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment