From 49015217f3becf052d33fa4658ac19229f5daa3a Mon Sep 17 00:00:00 2001 From: Oleg Oshmyan Date: Mon, 30 Oct 2023 16:53:59 +0200 Subject: [PATCH] run_bepinex*.sh: support older Steam and paths that contain spaces --- Runtimes/Unity/Doorstop/run_bepinex_il2cpp.sh | 25 ++++++++++++++++--- Runtimes/Unity/Doorstop/run_bepinex_mono.sh | 25 ++++++++++++++++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/Runtimes/Unity/Doorstop/run_bepinex_il2cpp.sh b/Runtimes/Unity/Doorstop/run_bepinex_il2cpp.sh index 037e7a9..d751dcc 100644 --- a/Runtimes/Unity/Doorstop/run_bepinex_il2cpp.sh +++ b/Runtimes/Unity/Doorstop/run_bepinex_il2cpp.sh @@ -65,9 +65,28 @@ corlib_dir="dotnet" # Special case: program is launched via Steam # In that case rerun the script via their bootstrapper to ensure Steam overlay works if [ "$2" = "SteamLaunch" ]; then - steam="$1 $2 $3 $4 $5 $6 $0 $7" - shift 7 - exec $steam "$@" + # Conceptually: exec "$1" "$2" "$3" "$4" "$0" "rest of $@" + # But newer versions of Steam interleave the $1..$4 with some "--" arguments, so preserve them as well + # Bash has array subscripting, but POSIX sh doesn't, so avoid it + to_rotate=4 + rotated=0 + while [ $((to_rotate-=1)) -ge 0 ]; do + while [ "z$1" = "z--" ]; do + set -- "$@" "$1" + shift + rotated=$((rotated+1)) + done + set -- "$@" "$1" + shift + rotated=$((rotated+1)) + done + to_rotate=$(($# - rotated)) + set -- "$@" "$0" + while [ $((to_rotate-=1)) -ge 0 ]; do + set -- "$@" "$1" + shift + done + exec "$@" fi # Handle first param being executable name diff --git a/Runtimes/Unity/Doorstop/run_bepinex_mono.sh b/Runtimes/Unity/Doorstop/run_bepinex_mono.sh index c28e599..0163209 100644 --- a/Runtimes/Unity/Doorstop/run_bepinex_mono.sh +++ b/Runtimes/Unity/Doorstop/run_bepinex_mono.sh @@ -65,9 +65,28 @@ corlib_dir="" # Special case: program is launched via Steam # In that case rerun the script via their bootstrapper to ensure Steam overlay works if [ "$2" = "SteamLaunch" ]; then - steam="$1 $2 $3 $4 $5 $6 $0 $7" - shift 7 - exec $steam "$@" + # Conceptually: exec "$1" "$2" "$3" "$4" "$0" "rest of $@" + # But newer versions of Steam interleave the $1..$4 with some "--" arguments, so preserve them as well + # Bash has array subscripting, but POSIX sh doesn't, so avoid it + to_rotate=4 + rotated=0 + while [ $((to_rotate-=1)) -ge 0 ]; do + while [ "z$1" = "z--" ]; do + set -- "$@" "$1" + shift + rotated=$((rotated+1)) + done + set -- "$@" "$1" + shift + rotated=$((rotated+1)) + done + to_rotate=$(($# - rotated)) + set -- "$@" "$0" + while [ $((to_rotate-=1)) -ge 0 ]; do + set -- "$@" "$1" + shift + done + exec "$@" fi # Handle first param being executable name