From 933a93e4a71591e867182999a7daf8ae3bad5596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Fri, 15 Feb 2013 12:34:32 +0100 Subject: Major overhaul: Support non-wine games * Moved wine support to own template * Added xpad template * Added no-x template for games that don't support being started on another X. * Improved ways template functions work together: - EXPORT now appends - OVERRIDE replaces all the others - in game: command 'super' to call the phases of the templates - super supports "-r tpl" to remove the phase function of tpl --- games/bg2 | 2 +- games/cim | 1 + games/deusex | 2 + games/ff7 | 1 + games/ff8 | 4 +- games/osmos | 2 +- games/steam | 3 -- games/steam_wine | 3 ++ games/thps2 | 2 + games/torchlight | 2 +- games/torment | 2 +- play.sh | 149 +++++++++++++++++++++++++++++++++++++++--------------- templates/cdemu | 3 -- templates/default | 15 ++++-- templates/fuseiso | 3 -- templates/iso | 9 +++- templates/no-x | 12 +++++ templates/steam | 28 +++++++--- templates/wine | 18 +++++++ templates/xpad | 21 ++++++++ 20 files changed, 214 insertions(+), 68 deletions(-) delete mode 100644 games/steam create mode 100644 games/steam_wine create mode 100644 templates/no-x create mode 100644 templates/wine create mode 100644 templates/xpad diff --git a/games/bg2 b/games/bg2 index a7e6e89..21b0106 100644 --- a/games/bg2 +++ b/games/bg2 @@ -1,6 +1,6 @@ ISO_TYPE=fuseiso -inherit iso +inherit wine iso SIZE="1280x960" GPATH="c:/bg2/bgmain.exe" diff --git a/games/cim b/games/cim index ed591d4..79c9c6c 100644 --- a/games/cim +++ b/games/cim @@ -1,4 +1,5 @@ #inherit steam +inherit wine PREFIX="cim" SIZE="1024x768" diff --git a/games/deusex b/games/deusex index 64cbf8f..39e90c7 100644 --- a/games/deusex +++ b/games/deusex @@ -1,3 +1,5 @@ +inherit wine + PREFIX="deus_ex" GPATH="c:/DeusEx/System/HDTP.exe" ARGS=QINI=C:/deusex/system/hdtp.ini USERINI=C:/deusex/system/hdtpuser.ini diff --git a/games/ff7 b/games/ff7 index e122e49..7910cd7 100644 --- a/games/ff7 +++ b/games/ff7 @@ -1,3 +1,4 @@ +inherit wine #inherit iso PREFIX=~/.ffwine diff --git a/games/ff8 b/games/ff8 index 04f4801..1bb647e 100644 --- a/games/ff8 +++ b/games/ff8 @@ -1,11 +1,11 @@ -inherit iso +inherit wine iso GPATH=c:/spiele/ff8/FF8.exe SIZE=1024x768 MOUNT=ff8/FF8_CD1.iso setupX () { - default_setupX + super exc nvidia-settings -a FSAA=1 exc nvidia-settings -a FSAAAppControlled=0 } diff --git a/games/osmos b/games/osmos index 586acbc..de012d9 100644 --- a/games/osmos +++ b/games/osmos @@ -1,4 +1,4 @@ -inherit steam +inherit wine steam steamapp 29200 diff --git a/games/steam b/games/steam deleted file mode 100644 index 0b71daf..0000000 --- a/games/steam +++ /dev/null @@ -1,3 +0,0 @@ -inherit steam - -# vim:ft=sh diff --git a/games/steam_wine b/games/steam_wine new file mode 100644 index 0000000..0a1e6f9 --- /dev/null +++ b/games/steam_wine @@ -0,0 +1,3 @@ +inherit wine steam + +# vim:ft=sh diff --git a/games/thps2 b/games/thps2 index 9c1de75..4b29ff9 100644 --- a/games/thps2 +++ b/games/thps2 @@ -1,3 +1,5 @@ +inherit wine + PREFIX="thps2" SIZE="1024x768" GPATH="c:/thps2/THawk2.exe" diff --git a/games/torchlight b/games/torchlight index acfc3bc..909548a 100644 --- a/games/torchlight +++ b/games/torchlight @@ -1,4 +1,4 @@ -inherit steam +inherit wine steam steamapp 41600 diff --git a/games/torment b/games/torment index cf65785..036eee3 100644 --- a/games/torment +++ b/games/torment @@ -1,6 +1,6 @@ ISO_TYPE=fuseiso -inherit iso +inherit wine iso PREFIX="infinity" #SIZE="1280x960" diff --git a/play.sh b/play.sh index cfe21ac..5162e84 100755 --- a/play.sh +++ b/play.sh @@ -1,5 +1,10 @@ #!/bin/zsh -f +# ZSH setup {{{1 + +# make the $functions and $functracs variables available +zmodload -F zsh/parameter +p:functions +p:functrace + # variables gathered from the environment {{{1 # debugging @@ -36,6 +41,14 @@ BIN=${0:A} # current template -- used for EXPORT CUR_TEMPLATE=play +# array of loaded templates +declare -a TEMPLATES + +# Array of phases +PHASES=(setenv prepare setupX startX run cleanup) +declare -r PHASES +declare -A PHASE_FUNS + # global functions {{{1 # print passed arguments to stderr @@ -48,7 +61,7 @@ out () { # print passed arguments to stderr ONLY if PLAY_DEBUG is nonzero log () { - [[ $PLAY_DEBUG > 0 ]] && echo "*** $*" >&2 + (( PLAY_DEBUG > 0 )) && echo "*** $*" >&2 } # die with a supplied error message @@ -66,19 +79,25 @@ exp () { # executes the passed command including arguments # (as individual parameters to this function) # if first arg is "-e" use exec instead of eval +# if first arg is "-b" background the job exc () { - local cmd="eval" + local cmd="eval" bg if [[ $1 == "-e" ]]; then cmd="exec" shift + elif [[ $1 == "-b" ]]; then + bg=" in background" + shift fi - log "Executing (using '$cmd'):" + log "Executing (using '$cmd'$bg):" log "> $*" if [[ $cmd == exec ]]; then exec $@ + elif [[ -n $bg ]]; then + $* & else $* fi @@ -110,51 +129,97 @@ set_eenv () { inherit () { zparseopts -D e=nonfatal - local old_templ=$CUR_TEMPLATE + for templ; do + local old_templ=$CUR_TEMPLATE + + CUR_TEMPLATE=$templ + + if [[ ! -e $PLAY_TEMPLATES/$templ ]]; then + if [[ -n $nonfatal ]]; then + log "Template '$templ' not found" + return + else + die "Template '$templ' not found" + fi + fi + + source $PLAY_TEMPLATES/$templ - CUR_TEMPLATE=$1 + TEMPLATES+=$CUR_TEMPLATE - if [[ ! -e $PLAY_TEMPLATES/$1 ]]; then - if [[ -n $nonfatal ]]; then - log "Template '$1' not found" - return + CUR_TEMPLATE=$old_templ + done +} + +# returns true iff the given template has been loaded +loaded () { + (( $+TEMPLATES[(r)$1] )) +} + +# run the chain of functions of the templates for the phase +# it gets called from +# Param: -r -> remove the phase of this template +super () { + zparseopts -D r+:=removes + local caller=$funcstack[2] funs= + + if (( $+PHASES[(r)$caller] )); then + removes=(${removes/-r/}) + if [[ -n $removes ]]; then + removes=(${removes/%/_$caller}) + funs=(${(s.:.)PHASE_FUNS[$caller]}) + funs=(${funs:|removes}) + eval ${(F)funs} else - die "Template '$1' not found" + _$caller fi + else + log "'super' called from non-phase '$caller'" fi - - source $PLAY_TEMPLATES/$1 - - CUR_TEMPLATE=$old_templ } # function, that is used to _export_ the default phase functions -# i.e. 'EXPORT prepare' in template 'bla' will set bla_prepare as the function being called +# i.e. 'EXPORT prepare' in template 'bla' will add bla_prepare to the functions being called # on prepare() # NB: this relies on CUR_TEMPLATE being correct -- DO NOT set CUR_TEMPLATE in a game file! EXPORT () { - for f in $@; do - if [[ -n $PHASES[(r)$f] ]]; then - eval "$f () { ${CUR_TEMPLATE}_${f}; }" + local override + local fun + + for phase; do + if [[ $phase == *_override ]]; then + override=1 + phase=${phase%_override} else - log "Invalid phase function '$f' exported in $CUR_TEMPLATE" + override=0 + fi + + fun=${CUR_TEMPLATE}_${phase} + + if (( $+PHASES[(r)$phase] )); then + if (( override )); then + PHASE_FUNS[$phase]=$fun + else + PHASE_FUNS[$phase]+=:$fun + fi + else + log "Invalid phase function '$phase' exported in $CUR_TEMPLATE" fi done } +OVERRIDE () { + EXPORT ${argv/%/_override} +} + # default enviroment {{{1 -EENV[WINEPREFIX]='eval echo $PREFIX' ENV[DISPLAY]=":1" -[[ $PLAY_DEBUG -le 1 ]] && ENV[WINEDEBUG]="-all" +(( PLAY_DEBUG <= 1 )) && ENV[WINEDEBUG]="-all" # phase functions {{{1 -# Array of phases -PHASES=(setenv prepare setupX startX run cleanup) -declare -r PHASES - # starts a new X # if overridden, this MUST call `$BIN --in-X` play_startX () { @@ -163,9 +228,6 @@ play_startX () { # populate the environment play_setenv () { - # default PREFIX - PREFIX=${PREFIX:-$GAME} - # set environment # ENV is set directly -- EENV is evaluated # it is possible to override ENV[p] by PLAY_ENV_p @@ -179,17 +241,9 @@ play_setenv () { done } -# run wine and therefore the game +# run game play_run () { - # cd into dir - local dir="$(exc winepath -u $GPATH)" - exc cd "${dir:h}" - - # start game - exc wine start ${dir:t} "$ARGS" - - # wait for wine to shutdown - exc wineserver -w + exc $GPATH "$ARGS" } # manipulate the newly created X instance @@ -206,14 +260,25 @@ play_prepare () { play_cleanup () { } -EXPORT $PHASES[@] +OVERRIDE $PHASES[@] + +for phase in $PHASES; do + functions[$phase]=_$phase +done # internal functions {{{1 _load () { # {{{2 inherit -e default - source $GAME_PATH + + local funs + + for phase in $PHASES; do + funs=(${(s.:.)PHASE_FUNS[$phase]}) + funs=(${funs/%/ \$@}) + functions[_$phase]=${(F)funs} + done } _list () { # {{{2 @@ -250,6 +315,8 @@ _new () { # {{{2 # everything is fine -- write file cat > $DGAME << EOF +inherit wine + $GPREFIX GPATH="$GPATH" @@ -289,7 +356,7 @@ _run () { #{{{2 out "Cleaning up after '$GAME'" _load setenv - cleanup + cleanup force else out "Launching '$GAME'" _load diff --git a/templates/cdemu b/templates/cdemu index f6690a8..f532106 100644 --- a/templates/cdemu +++ b/templates/cdemu @@ -4,8 +4,6 @@ _cdemu_dev () { } cdemu_prepare () { - default_prepare - declare -g MOUNT CDEMU_NO [[ $MOUNT != /* ]] && MOUNT="$HOME/isos/spiele/$MOUNT" @@ -16,7 +14,6 @@ cdemu_prepare () { } cdemu_cleanup () { - default_cleanup exc umount $(_cdemu_dev) exc cdemu unload $CDEMU_NO } diff --git a/templates/default b/templates/default index 2f62395..0d1c0ea 100644 --- a/templates/default +++ b/templates/default @@ -4,16 +4,21 @@ default_setupX () { play_setupX } +default_setenv () { + if loaded wine; then + EENV[WINEPREFIX]='{ [[ -z $NO_WINEINSTS ]] && echo $HOME/.wineinsts/$PREFIX; } || echo $PREFIX' + fi + + play_setenv +} + default_prepare () { - play_prepare } default_cleanup () { - play_cleanup } -EENV[WINEPREFIX]='{ [[ -z $NO_WINEINSTS ]] && echo $HOME/.wineinsts/$PREFIX; } || echo $PREFIX' - -EXPORT setupX prepare cleanup +EXPORT prepare cleanup +OVERRIDE setenv setupX # vim:ft=sh diff --git a/templates/fuseiso b/templates/fuseiso index 97df277..0be20ff 100644 --- a/templates/fuseiso +++ b/templates/fuseiso @@ -1,7 +1,5 @@ fuseiso_prepare () { - default_prepare - declare -g MOUNT MOUNTTARGET [[ $MOUNT != /* ]] && MOUNT="$HOME/isos/spiele/$MOUNT" @@ -10,7 +8,6 @@ fuseiso_prepare () { } fuseiso_cleanup () { - default_cleanup exc fusermount -u $MOUNTTARGET } diff --git a/templates/iso b/templates/iso index 2aad3cd..2b65c26 100644 --- a/templates/iso +++ b/templates/iso @@ -1,3 +1,6 @@ +# +# NB: MUST be included before other templates defining cleanup and prepare +# if [[ -z $ISO_TYPE ]]; then # default @@ -18,12 +21,16 @@ esac # wrapper phases iso_prepare () { + default_prepare ${ISO_TYPE}_prepare } iso_cleanup () { + default_cleanup ${ISO_TYPE}_cleanup } -EXPORT prepare cleanup +# we need to OVERRIDE and not EXPORT, to not execute them twice +# as they are already exported in the other template +OVERRIDE prepare cleanup # vim:ft=sh diff --git a/templates/no-x b/templates/no-x new file mode 100644 index 0000000..e811e85 --- /dev/null +++ b/templates/no-x @@ -0,0 +1,12 @@ +unset "ENV[DISPLAY]" + +no-x_startX () { + exc $BIN --in-X $GAME +} + +no-x_setupX () { +} + +OVERRIDE startX setupX + +# vim:ft=sh diff --git a/templates/steam b/templates/steam index 3321e92..2516277 100644 --- a/templates/steam +++ b/templates/steam @@ -1,9 +1,25 @@ -PREFIX="steam" -SIZE="1280x960" -GPATH="c:/program files/steam/steam.exe" +if loaded wine; then + PREFIX="steam" + #SIZE="1280x960" + GPATH="c:/program files/steam/steam.exe" -steamapp () { - [[ $# > 0 ]] && export ARGS="-applaunch ${=@}" -} + steamapp () { + [[ $# -gt 0 ]] && export ARGS="-applaunch ${=@}" + } +else + GPATH=steam + SIZE=1680x1050 + + steamapp () { + [[ $# -gt 0 ]] && export ARGS="steam://rungameid/$1" + } + + # force cleanup -- yields a normal shutdown + steam_cleanup () { + [[ $1 == force ]] && exc steam -shutdown + } + + OVERRIDE cleanup +fi # vim:ft=sh diff --git a/templates/wine b/templates/wine new file mode 100644 index 0000000..e6c8d2e --- /dev/null +++ b/templates/wine @@ -0,0 +1,18 @@ +EENV[WINEPREFIX]='eval echo $PREFIX' +PREFIX=${PREFIX:-$GAME} + +# run wine and therefore the game +wine_run () { + # cd into dir + local dir="$(exc winepath -u $GPATH)" + exc cd "${dir:h}" + + # start game + exc wine start ${dir:t} "$ARGS" + + # wait for wine to shutdown + exc wineserver -w +} + +OVERRIDE run +# vim: ft=sh diff --git a/templates/xpad b/templates/xpad new file mode 100644 index 0000000..1e67429 --- /dev/null +++ b/templates/xpad @@ -0,0 +1,21 @@ +xpad_prepare () { + declare -g XBOX_PID XBOX_DEADZONE XBOX_UIAXISMAP \ + XBOX_UIBUTTONMAP XBOX_NO_FF + + local args="--silent \ + --deadzone ${XBOX_DEADZONE:-4000}" + + [[ -n $XBOX_UIAXISMAP ]] && args+=" --ui-axismap $XBOX_UIAXISMAP" + [[ -n $XBOX_UIBUTTONMAP ]] && args+=" --ui-buttonmap $XBOX_UIBUTTONMAP" + [[ -z $XBOX_NO_FF ]] || args+=" --force-feedback" + + exc -b xboxdrv ${=args} + XBOX_PID=$! +} + +xpad_cleanup () { + [[ -n $XBOX_PID ]] && exc kill -SIGINT $XBOX_PID +} + +EXPORT prepare cleanup +# vim:ft=sh -- cgit v1.2.3