Skip to content

Commit 4ed9584

Browse files
authored
Merge pull request #341 from ishitatsuyuki/linux
Fix the Linux launcher script
2 parents a1cd9be + 1fd5c19 commit 4ed9584

File tree

1 file changed

+57
-12
lines changed

1 file changed

+57
-12
lines changed

doorstop/run_bepinex.sh

+57-12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# This script is used to run a Unity game with BepInEx enabled.
55
#
66
# Usage: Configure the script below and simply run this script when you want to run your game modded.
7+
a="/$0"; a=${a%/*}; a=${a#/}; a=${a:-.}; BASEDIR=$(cd "$a"; pwd -P)
78

89
# -------- SETTINGS --------
910
# ---- EDIT AS NEEDED ------
@@ -19,31 +20,42 @@ executable_name=""
1920
export DOORSTOP_ENABLE=TRUE
2021

2122
# What .NET assembly to execute. Valid value is a path to a .NET DLL that mono can execute.
22-
export DOORSTOP_INVOKE_DLL_PATH="${PWD}/BepInEx/core/BepInEx.Preloader.dll"
23+
export DOORSTOP_INVOKE_DLL_PATH="${BASEDIR}/BepInEx/core/BepInEx.Preloader.Unity.dll"
24+
25+
# If specified, Doorstop will load core libraries from this folder instead of the normal Managed folder
26+
# Mainly usable to unstrip assemblies in some games
27+
export DOORSTOP_CORLIB_OVERRIDE_PATH=""
2328

2429
# ----- DO NOT EDIT FROM THIS LINE FORWARD ------
2530
# ----- (unless you know what you're doing) ------
2631

32+
# Special case: program is launched via Steam
33+
# In that case rerun the script via their bootstrapper to ensure Steam overlay works
34+
if [ "$2" = "SteamLaunch" ]; then
35+
"$1" "$2" "$3" "$4" "$0" "$5" "${@:6}"
36+
exit
37+
fi
38+
2739
if [ ! -x "$1" -a ! -x "$executable_name" ]; then
2840
echo "Please open run.sh in a text editor and configure executable name."
2941
exit 1
3042
fi
3143

32-
doorstop_libs="${PWD}/doorstop_libs"
44+
doorstop_libs="$BASEDIR/doorstop_libs"
3345
arch=""
3446
executable_path=""
3547
lib_postfix=""
3648

37-
os_type=`uname -s`
49+
os_type=$(uname -s)
3850
case $os_type in
3951
Linux*)
40-
executable_path="${PWD}/${executable_name}"
52+
executable_path="$BASEDIR/${executable_name}"
4153
lib_postfix="so"
4254
;;
4355
Darwin*)
44-
executable_name=`basename "${executable_name}" .app`
45-
real_executable_name=`defaults read "${PWD}/${executable_name}.app/Contents/Info" CFBundleExecutable`
46-
executable_path="${PWD}/${executable_name}.app/Contents/MacOS/${real_executable_name}"
56+
executable_name=$(basename "${executable_name}" .app)
57+
real_executable_name=$(defaults read "$BASEDIR/${executable_name}.app/Contents/Info" CFBundleExecutable)
58+
executable_path="$BASEDIR/${executable_name}.app/Contents/MacOS/${real_executable_name}"
4759
lib_postfix="dylib"
4860
;;
4961
*)
@@ -63,10 +75,10 @@ if [ -n "$1" ]; then
6375
;;
6476
Darwin*)
6577
# Special case: allow to specify path to the executable within .app
66-
full_path_part=`echo "$1" | grep "\.app/Contents/MacOS"`
78+
full_path_part=$(echo "$1" | grep "\.app/Contents/MacOS")
6779
if [ -z "$full_path_part" ]; then
68-
executable_name=`basename "$1" .app`
69-
real_executable_name=`defaults read "$1/Contents/Info" CFBundleExecutable`
80+
executable_name=$(basename "$1" .app)
81+
real_executable_name=$(defaults read "$1/Contents/Info" CFBundleExecutable)
7082
executable_path="$1/Contents/MacOS/${real_executable_name}"
7183
else
7284
executable_path="$1"
@@ -75,9 +87,42 @@ if [ -n "$1" ]; then
7587
esac
7688
fi
7789

78-
executable_type=`LD_PRELOAD="" file -b "${executable_path}"`;
90+
abs_path() {
91+
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
92+
}
93+
94+
_readlink() {
95+
# relative links with readlink (without -f) do not preserve the path info
96+
ab_path="$(abs_path "$1")"
97+
link="$(readlink "${ab_path}")"
98+
case $link in
99+
/*);;
100+
*) link="$(dirname "$ab_path")/$link";;
101+
esac
102+
echo "$link"
103+
}
104+
105+
106+
resolve_executable_path () {
107+
e_path="$(abs_path "$1")"
108+
109+
while [ -L "${e_path}" ]; do
110+
e_path=$(_readlink "${e_path}");
111+
done
112+
echo "${e_path}"
113+
}
114+
115+
executable_path=$(resolve_executable_path "${executable_path}")
116+
echo "${executable_path}"
117+
executable_type=$(LD_PRELOAD="" file -b "${executable_path}");
79118

80119
case $executable_type in
120+
*PE32*)
121+
echo "The executable is a Windows executable file. You must use Wine/Proton and BepInEx for Windows with this executable."
122+
echo "Uninstall BepInEx for *nix and install BepInEx for Windows instead."
123+
echo "More info: https://docs.bepinex.dev/articles/advanced/steam_interop.html#protonwine"
124+
exit 1
125+
;;
81126
*64-bit*)
82127
arch="x64"
83128
;;
@@ -97,4 +142,4 @@ export LD_PRELOAD=$doorstop_libname:$LD_PRELOAD
97142
export DYLD_LIBRARY_PATH="${doorstop_libs}"
98143
export DYLD_INSERT_LIBRARIES="${doorstop_libs}/$doorstop_libname"
99144

100-
"${executable_path}"
145+
"${executable_path}" "$@"

0 commit comments

Comments
 (0)