-
Notifications
You must be signed in to change notification settings - Fork 69
/
run.sh
executable file
·280 lines (241 loc) · 8.29 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/bin/sh
# Doorstop start script
#
# Run the script to start the game with Doorstop enabled
#
# There are two ways to use this script
#
# 1. Via CLI: Run ./run.sh <path to game> [doorstop arguments] [game arguments]
# 2. Via config: edit the options below and run ./run.sh without any arguments
# 0 is false, 1 is true
# LINUX: name of Unity executable
# MACOS: name of the .app directory
executable_name=""
# All of the below can be overriden with command line args
# General Config Options
# Enable Doorstop?
enabled="1"
# Path to the assembly to load and execute
# NOTE: The entrypoint must be of format `static void Doorstop.Entrypoint.Start()`
target_assembly="Doorstop.dll"
# Overrides the default boot.config file path
boot_config_override=
# If enabled, DOORSTOP_DISABLE env var value is ignored
# USE THIS ONLY WHEN ASKED TO OR YOU KNOW WHAT THIS MEANS
ignore_disable_switch="0"
# Mono Options
# Overrides default Mono DLL search path
# Sometimes it is needed to instruct Mono to seek its assemblies from a different path
# (e.g. mscorlib is stripped in original game)
# This option causes Mono to seek mscorlib and core libraries from a different folder before Managed
# Original Managed folder is added as a secondary folder in the search path
# To specify multiple paths, separate them with colons (:)
dll_search_path_override=""
# If 1, Mono debugger server will be enabled
debug_enable="0"
# When debug_enabled is 1, specifies the address to use for the debugger server
debug_address="127.0.0.1:10000"
# If 1 and debug_enabled is 1, Mono debugger server will suspend the game execution until a debugger is attached
debug_suspend="0"
# CoreCLR options (IL2CPP)
# Path to coreclr shared library WITHOUT THE EXTENSION that contains the CoreCLR runtime
coreclr_path=""
# Path to the directory containing the managed core libraries for CoreCLR (mscorlib, System, etc.)
corlib_dir=""
################################################################################
# Everything past this point is the actual script
# 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 $0 $5"
shift 5
$steam "$@"
exit
fi
# Handle first param being executable name
if [ -x "$1" ] ; then
executable_name="$1"
echo "Target executable: $1"
shift
fi
if [ -z "${executable_name}" ] || [ ! -x "${executable_name}" ]; then
echo "Please set executable_name to a valid name in a text editor or as the first command line parameter"
exit 1
fi
# Use POSIX-compatible way to get the directory of the executable
a="/$0"; a=${a%/*}; a=${a#/}; a=${a:-.}; BASEDIR=$(cd "$a" || exit; pwd -P)
arch=""
executable_path=""
lib_extension=""
# Set executable path and the extension to use for the libdoorstop shared object
os_type="$(uname -s)"
case ${os_type} in
Linux*)
executable_path="${executable_name}"
# Handle relative paths
if ! echo "$executable_path" | grep "^/.*$"; then
executable_path="${BASEDIR}/${executable_path}"
fi
lib_extension="so"
;;
Darwin*)
real_executable_name="${executable_name}"
# Handle relative directories
if ! echo "$real_executable_name" | grep "^/.*$"; then
real_executable_name="${BASEDIR}/${real_executable_name}"
fi
# If we're not even an actual executable, check .app Info for actual executable
if ! echo "$real_executable_name" | grep "^.*\.app/Contents/MacOS/.*"; then
# Add .app to the end if not given
if ! echo "$real_executable_name" | grep "^.*\.app$"; then
real_executable_name="${real_executable_name}.app"
fi
inner_executable_name=$(defaults read "${real_executable_name}/Contents/Info" CFBundleExecutable)
executable_path="${real_executable_name}/Contents/MacOS/${inner_executable_name}"
else
executable_path="${executable_name}"
fi
lib_extension="dylib"
;;
*)
# alright whos running games on freebsd
echo "Unknown operating system ($(uname -s))"
echo "Make an issue at https://github.com/NeighTools/UnityDoorstop"
exit 1
;;
esac
abs_path() {
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}
_readlink() {
# relative links with readlink (without -f) do not preserve the path info
ab_path="$(abs_path "$1")"
link="$(readlink "${ab_path}")"
case $link in
/*);;
*) link="$(dirname "$ab_path")/$link";;
esac
echo "$link"
}
resolve_executable_path () {
e_path="$(abs_path "$1")"
while [ -L "${e_path}" ]; do
e_path=$(_readlink "${e_path}");
done
echo "${e_path}"
}
# Get absolute path of executable and show to user
executable_path=$(resolve_executable_path "${executable_path}")
echo "${executable_path}"
# Figure out the arch of the executable with file
file_out="$(LD_PRELOAD="" file -b "${executable_path}")"
case "${file_out}" in
*64-bit*)
arch="x64"
;;
*32-bit*)
arch="x86"
;;
*)
echo "The executable \"${executable_path}\" is not compiled for x86 or x64 (might be ARM?)"
echo "If you think this is a mistake (or would like to encourage support for other architectures)"
echo "Please make an issue at https://github.com/NeighTools/UnityDoorstop"
echo "Got: ${file_out}"
exit 1
;;
esac
# Helper to convert common boolean strings into just 0 and 1
doorstop_bool() {
case "$1" in
TRUE|true|t|T|1|Y|y|yes)
echo "1"
;;
FALSE|false|f|F|0|N|n|no)
echo "0"
;;
esac
}
# Read from command line
while :; do
case "$1" in
--doorstop_enabled) # For backwards compatibility. Renamed to --doorstop-enabled
enabled="$(doorstop_bool "$2")"
shift
;;
--doorstop_target_assembly) # For backwards compatibility. Renamed to --doorstop-target-assembly
target_assembly="$2"
shift
;;
--doorstop-enabled)
enabled="$(doorstop_bool "$2")"
shift
;;
--doorstop-target-assembly)
target_assembly="$2"
shift
;;
--doorstop-boot-config-override)
boot_config_override="$2"
shift
;;
--doorstop-mono-dll-search-path-override)
dll_search_path_override="$2"
shift
;;
--doorstop-mono-debug-enabled)
debug_enable="$(doorstop_bool "$2")"
shift
;;
--doorstop-mono-debug-suspend)
debug_suspend="$(doorstop_bool "$2")"
shift
;;
--doorstop-mono-debug-address)
debug_address="$2"
shift
;;
--doorstop-clr-runtime-coreclr-path)
coreclr_path="$2"
shift
;;
--doorstop-clr-corlib-dir)
corlib_dir="$2"
shift
;;
*)
if [ -z "$1" ]; then
break
fi
rest_args="$rest_args $1"
;;
esac
shift
done
# Move variables to environment
export DOORSTOP_ENABLED="$enabled"
export DOORSTOP_TARGET_ASSEMBLY="$target_assembly"
export DOORSTOP_BOOT_CONFIG_OVERRIDE="$boot_config_override"
export DOORSTOP_IGNORE_DISABLED_ENV="$ignore_disable_switch"
export DOORSTOP_MONO_DLL_SEARCH_PATH_OVERRIDE="$dll_search_path_override"
export DOORSTOP_MONO_DEBUG_ENABLED="$debug_enable"
export DOORSTOP_MONO_DEBUG_ADDRESS="$debug_address"
export DOORSTOP_MONO_DEBUG_SUSPEND="$debug_suspend"
export DOORSTOP_CLR_RUNTIME_CORECLR_PATH="$coreclr_path.$lib_extension"
export DOORSTOP_CLR_CORLIB_DIR="$corlib_dir"
# Final setup
doorstop_directory="${BASEDIR}/"
doorstop_name="libdoorstop.${lib_extension}"
export LD_LIBRARY_PATH="${doorstop_directory}:${corlib_dir}:${LD_LIBRARY_PATH}"
if [ -z "$LD_PRELOAD" ]; then
export LD_PRELOAD="${doorstop_name}"
else
export LD_PRELOAD="${doorstop_name}:${LD_PRELOAD}"
fi
export DYLD_LIBRARY_PATH="${doorstop_directory}:${DYLD_LIBRARY_PATH}"
if [ -z "$DYLD_INSERT_LIBRARIES" ]; then
export DYLD_INSERT_LIBRARIES="${doorstop_name}"
else
export DYLD_INSERT_LIBRARIES="${doorstop_name}:${DYLD_INSERT_LIBRARIES}"
fi
# shellcheck disable=SC2086
exec "$executable_path" $rest_args