r2modmanPlus
r2modmanPlus copied to clipboard
Support spaces in arguments (eg spaces in file path)
This fixes spaces in file paths for me from r2modmanPlus side (bepinex also doesn't support this but those scripts dont update every time you restart r2modman so manual patches stay there).
I think this might also fix #995 as I have spaces in my profile name and it works but this needs someone more experienced with the project to test.
@NyaomiDEV tag because the script says to blame you if something does not work
It was so very much ago when I made this script, haha! Can't believe someone actually tagged me.
I should contribute more lately... sorry guys.
well, that social experiment is complete! (please don't tag me anymore lol)
gamemoderun uses the "$@" syntax which I think is the same as what I've changed it to but I use it with a named variable ("$args[@]") and gamemoderun is probably the most used steam launch argument, at least on Linux.
https://github.com/FeralInteractive/gamemode/blob/8cea4c2418d8893e0352ac0718adca48478c33ea/data/gamemoderun#L9
I have tested this on my system and it works with spaces in game path and profile name.
For completeness sake; I tested on linux native Valheim installed at the windows default path (because of shared drive) which includes Program Files (x86) with spaces.
The `start_server_bepinex.sh` has the same issue of not working with spaces so I updated it with the same bash array stuff I did in this PR:
Note that this script does not update every time you restart r2modman unlike the script this PR fixes, so it's not that bothersome to patch.
#!/bin/sh
# BepInEx running script
#
# HOW TO USE:
# 1. Make this script executable with `chmod u+x ./start_game_bepinex.sh`
# 2. In Steam, go to game's preferences and change game's launch args to:
# ./start_game_bepinex.sh %command%
# 3. Start the game via Steam
#
# Note that you won't get a console this way
#
# NOTE: Edit the script only if you know what you're doing!
# Resolve base directory relative to this script
# Hopefully this resolves relative paths and links
a="/$0"; a=${a%/*}; a=${a#/}; a=${a:-.}; BASEDIR=$(cd "$a"; pwd -P)
# 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
# echo "start_game_bepinex.sh: SteamLaunch"
# cmd=( $1 $2 $3 $4 $0 )
# shift 4
# exec "${cmd[@]}" $@
# exit
# fi
exec="$BASEDIR/valheim.x86_64"
rest=()
export DOORSTOP_ENABLE=TRUE
export DOORSTOP_INVOKE_DLL_PATH="$BASEDIR/BepInEx/core/BepInEx.Preloader.dll"
export DOORSTOP_CORLIB_OVERRIDE_PATH="$BASEDIR/unstripped_corlib"
# Allow to specify --doorstop-enable true|false
# Everything else is passed as-is to `exec`
while :; do
case $1 in
--doorstop-enable)
if [ -n "$2" ]; then
export DOORSTOP_ENABLE=$(echo "$2" | tr a-z A-Z)
shift
else
echo "No --doorstop-enable value specified, using default!"
fi
;;
--doorstop-target)
if [ -n "$2" ]; then
export DOORSTOP_INVOKE_DLL_PATH="$2"
shift
else
echo "No --doorstop-target value specified, using default!"
fi
;;
--doorstop-dll-search-override)
if [ -n "$2" ]; then
export DOORSTOP_CORLIB_OVERRIDE_PATH="$2"
shift
else
echo "No --doorstop-dll-search-override value specified, using default!"
fi
;;
*)
if [ -z "$1" ]; then
break
fi
if [ -z "$launch" ]; then
launch="$1"
else
rest+=( "$1" )
fi
;;
esac
shift
done
export LD_LIBRARY_PATH="$BASEDIR/doorstop_libs:$LD_LIBRARY_PATH"
export LD_PRELOAD="libdoorstop_x64.so:$LD_PRELOAD"
# Run the main executable
# Don't quote here since $exec may contain args passed by Steam
if [ -n "$launch" ]; then
echo "start_game_bepinex.sh: SteamLaunch"
exec "$launch" "${rest[@]}"
else
echo "start_game_bepinex.sh: "
exec "$exec"
fi
tbf it looks good to me, but since they're using arrays instead of strings this bumps up the bash requirement (if the login shell is bash).
BTW: I'd recommend using https://github.com/koalaman/shellcheck to check for patterns that can lead to potential errors.
Also, this problem can be resolved in I think another way and it by using ${1@Q}. Though I myself only recently discovered it, and it actually re-quotes the argument instead of keeping the default one. Again, it would probably bump the bash requirement though.