Skip to content

Instantly share code, notes, and snippets.

@Ryochan7
Created January 9, 2016 01:31
Show Gist options
  • Save Ryochan7/17cdb0c4d24db804dfd3 to your computer and use it in GitHub Desktop.
Save Ryochan7/17cdb0c4d24db804dfd3 to your computer and use it in GitHub Desktop.
SteamOS BPM Launcher for Windows Version of Sonic Adventure 2
#!/bin/sh
## This script is used to launch Windows games by using
## the Windows Steam client in a Wine virtual desktop.
## Credit goes to iVaN, dubigrasu, and Ryochan7 for creating various portions
## of this script. Discussion of this technique is currently being done at
## https://steamcommunity.com/groups/steamuniverse/discussions/1/494632768626127072/.
##########################################
# #
# User configurable variables for use in #
# this script #
# #
##########################################
# Define some Wine variables for use in the script.
export WINEPREFIX="/home/steam/.PlayOnLinux/wineprefix/Steam"
export WINEDEBUG="-all"
WINEVERSION="$HOME/.PlayOnLinux/wine/linux-x86/1.8"
export LD_LIBRARY_PATH="$WINEVERSION/lib:$WINEVERSION/lib64:$LD_LIBRARY_PATH"
# Define Steam location and game location here.
# NOTE: GAME_DIR is not used with current method. Possibly remove?
STEAM_DIR="$WINEPREFIX/drive_c/Program Files/Steam"
GAME_APPID="213610"
GAME_DIR="steamapps/common/Sonic Adventure 2"
GAME_EXE="sonic2App.exe"
###########################################
# #
# MAIN SCRIPT. DO NOT EDIT UNLESS #
# ABSOLUTELY NECESSARY #
# #
###########################################
# Obtain the resolution of the current display so the Wine virtual
# desktop will be full-screen.
RES=$(xdpyinfo | grep "dimensions" | awk '{print $2}')
VIRT_DESK="explorer /desktop=Steam,$RES"
# Change to Steam directory and launch Wine virtual desktop.
cd "$STEAM_DIR"
$WINEVERSION/bin/wine $VIRT_DESK &
# Allow a little sleep time so steamcompmgr uses the virtual desktop
# window.
sleep 3
# Don't use extra libraries for other applications running in Wine.
# The virtual desktop will be used by steamcompmgr.
export LD_PRELOAD=
# Launch Steam client.
"$WINEVERSION/bin/wine" $VIRT_DESK "$STEAM_DIR/Steam.exe" -silent &
# Wait for Steam to be ready so that an applaunch command will work.
# In this case, wait for Steam client to create the Friends window.
while [ -z $(xwininfo -children -root -tree | grep "Steam.exe" | grep "Friends" | awk '{print $1}') ]; do
sleep 2
done;
# Launch game from Steam. The game appid used by Steam can be found from the
# Steam store page for a game or from https://steamdb.info/.
"$WINEVERSION/bin/wine" $VIRT_DESK "$STEAM_DIR/Steam.exe" -applaunch "$GAME_APPID"
# Wait for application to be launched.
until pgrep -lf $GAME_EXE; do
sleep 2
done;
# Stay in loop while the game is running.
while pgrep -lf $GAME_EXE; do
sleep 2
done;
# Shut down the Windows Steam client.
if [ -n "$(pgrep -lf Steam.exe)" ]; then
"$WINEVERSION/bin/wine" $VIRT_DESK "$STEAM_DIR/Steam.exe" -shutdown
# Wait for Steam client to close completely.
while pgrep -lf "Steam.exe"; do
sleep 2
done;
fi;
# Kill Wine server so Steam will properly return to the library interface.
"$WINEVERSION/bin/wineserver" -k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment