Skip to content

Instantly share code, notes, and snippets.

@MichaelMackus
Created July 29, 2022 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichaelMackus/5d9d7bb5557015eb572af98e68b38496 to your computer and use it in GitHub Desktop.
Save MichaelMackus/5d9d7bb5557015eb572af98e68b38496 to your computer and use it in GitHub Desktop.
launch-lutris
#!/bin/sh
# This tool launches battle.net, waits for it to be ready, then launches your
# game via the launcher for easy steam integration.
#
# Inspired from bnetlauncher, which only works on Windows due to a dependency on WMI:
# https://github.com/dafzor/bnetlauncher
#
# To use, please set the variables in the "Configuration" section - mainly, you
# need to set LUTRIS_BNET_IDENTIFIER to the "Identifier" for the Battle.net
# launcher in Lutris and LUTRIS_GAME_IDENTIFIER to the "Identifier" for the
# game EXE in Lutris. To find this value, open Lutris and right click your
# Battle.net launcher and click "configure" - there should be an "Identifier"
# value that is greyed out- do the same for your game exe.
# Configuration:
USE_LUTRIS=1 # set to 0 if you don't want lutris - you will need to set BIN below to your custom binary
LUTRIS_BIN="flatpak run net.lutris.Lutris" # the system binary for lutris (default assumes flatpak install)
LUTRIS_BNET_IDENTIFIER="battlenet" # the "Identifier" for Battle.net launcher
LUTRIS_GAME_IDENTIFIER="${1:-d2r}" # the "Identifier" for the game you want to run, default allows passing via CLI argument
GAME_EXE="D2R.exe" # wait until this game is exited
WAIT_GAME=1 # set to 0 to disable waiting for game
WAIT_TIMEOUT=60 # timeout to wait for game launch
KILL_LUTRIS=1 # set to 0 to keep Lutris & Battle.net open
echo "Playing $LUTRIS_GAME_IDENTIFIER"
# first, we run lutris & battle.net in the background
$LUTRIS_BIN lutris:rungame/$LUTRIS_BNET_IDENTIFIER &
# now, we wait for MAX_HELPER_COUNT to indicate battle.net is running
# I chose the value for MAX_HELPER_COUNT based on trial and error - you may
# have to increase or decrease the value if battle.net changes
MAX_HELPER_COUNT=3
HELPER_COUNT=0
while [ $HELPER_COUNT -lt $MAX_HELPER_COUNT ]; do
sleep 1
HELPER_COUNT="$(pgrep -c Battle.net.exe)"
done
# done, now launch the game
$LUTRIS_BIN lutris:rungame/$LUTRIS_GAME_IDENTIFIER
# wait for game to exit
if [ "$WAIT_GAME" = "1" ]; then
echo "Waiting for game to start..."
COUNT=0
while !( pgrep "$GAME_EXE" ); do
if [ "$COUNT" -gt "$WAIT_TIMEOUT" ]; then
echo "ERROR: Timeout while waiting for game to launch!"
exit 1
fi
COUNT="$(($COUNT + 1))"
sleep 1
done
echo "Waiting for game to end..."
while pgrep "$GAME_EXE"; do
sleep 1
done
echo "Game ended"
fi
# kill battle.net if necessary
if [ "$KILL_LUTRIS" = "1" ]; then
ps aux | grep "lutris-wrapper" | grep 'Battle.net' | awk '{ print $2 }' | xargs kill
pkill lutris
fi
@MichaelMackus
Copy link
Author

MichaelMackus commented Jul 29, 2022

Script to launch lutris battle.net game (for steam integration)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment