Skip to content

Commit 4901521

Browse files
astiobManlyMarco
authored andcommitted
run_bepinex*.sh: support older Steam and paths that contain spaces
1 parent c82fc4e commit 4901521

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

Runtimes/Unity/Doorstop/run_bepinex_il2cpp.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,28 @@ corlib_dir="dotnet"
6565
# Special case: program is launched via Steam
6666
# In that case rerun the script via their bootstrapper to ensure Steam overlay works
6767
if [ "$2" = "SteamLaunch" ]; then
68-
steam="$1 $2 $3 $4 $5 $6 $0 $7"
69-
shift 7
70-
exec $steam "$@"
68+
# Conceptually: exec "$1" "$2" "$3" "$4" "$0" "rest of $@"
69+
# But newer versions of Steam interleave the $1..$4 with some "--" arguments, so preserve them as well
70+
# Bash has array subscripting, but POSIX sh doesn't, so avoid it
71+
to_rotate=4
72+
rotated=0
73+
while [ $((to_rotate-=1)) -ge 0 ]; do
74+
while [ "z$1" = "z--" ]; do
75+
set -- "$@" "$1"
76+
shift
77+
rotated=$((rotated+1))
78+
done
79+
set -- "$@" "$1"
80+
shift
81+
rotated=$((rotated+1))
82+
done
83+
to_rotate=$(($# - rotated))
84+
set -- "$@" "$0"
85+
while [ $((to_rotate-=1)) -ge 0 ]; do
86+
set -- "$@" "$1"
87+
shift
88+
done
89+
exec "$@"
7190
fi
7291

7392
# Handle first param being executable name

Runtimes/Unity/Doorstop/run_bepinex_mono.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,28 @@ corlib_dir=""
6565
# Special case: program is launched via Steam
6666
# In that case rerun the script via their bootstrapper to ensure Steam overlay works
6767
if [ "$2" = "SteamLaunch" ]; then
68-
steam="$1 $2 $3 $4 $5 $6 $0 $7"
69-
shift 7
70-
exec $steam "$@"
68+
# Conceptually: exec "$1" "$2" "$3" "$4" "$0" "rest of $@"
69+
# But newer versions of Steam interleave the $1..$4 with some "--" arguments, so preserve them as well
70+
# Bash has array subscripting, but POSIX sh doesn't, so avoid it
71+
to_rotate=4
72+
rotated=0
73+
while [ $((to_rotate-=1)) -ge 0 ]; do
74+
while [ "z$1" = "z--" ]; do
75+
set -- "$@" "$1"
76+
shift
77+
rotated=$((rotated+1))
78+
done
79+
set -- "$@" "$1"
80+
shift
81+
rotated=$((rotated+1))
82+
done
83+
to_rotate=$(($# - rotated))
84+
set -- "$@" "$0"
85+
while [ $((to_rotate-=1)) -ge 0 ]; do
86+
set -- "$@" "$1"
87+
shift
88+
done
89+
exec "$@"
7190
fi
7291

7392
# Handle first param being executable name

0 commit comments

Comments
 (0)