11#! /bin/sh
22# Doorstop start script
3- #
3+ #
44# Run the script to start the game with Doorstop enabled
55#
66# There are two ways to use this script
77#
88# 1. Via CLI: Run ./run.sh <path to game> [doorstop arguments] [game arguments]
99# 2. Via config: edit the options below and run ./run.sh without any arguments
1010
11- # 0 is false, 1 is true
12-
1311# LINUX: name of Unity executable
1412# MACOS: name of the .app directory
1513executable_name=" "
@@ -19,6 +17,7 @@ executable_name=""
1917# General Config Options
2018
2119# Enable Doorstop?
20+ # 0 is false, 1 is true
2221enabled=" 1"
2322
2423# Path to the assembly to load and execute
@@ -64,22 +63,48 @@ corlib_dir=""
6463
6564# Special case: program is launched via Steam
6665# In that case rerun the script via their bootstrapper to ensure Steam overlay works
67- if [ " $2 " = " SteamLaunch" ]; then
68- steam=" $1 $2 $3 $4 $0 $5 "
69- shift 5
70- $steam " $@ "
71- exit
72- fi
66+ steam_arg_helper () {
67+ if [ " $executable_name " != " " ] && [ " $1 " != " ${1% " $executable_name " } " ]; then
68+ return 0
69+ elif [ " $executable_name " = " " ] && [ " $1 " != " ${1% .x86_64} " ]; then
70+ return 0
71+ elif [ " $executable_name " = " " ] && [ " $1 " != " ${1% .x86} " ]; then
72+ return 0
73+ else
74+ return 1
75+ fi
76+ }
77+ for a in " $@ " ; do
78+ if [ " $a " = " SteamLaunch" ]; then
79+ rotated=0; max=$#
80+ while [ $rotated -lt $max ]; do
81+ if steam_arg_helper " $1 " ; then
82+ to_rotate=$(( $# - rotated))
83+ set -- " $@ " " $0 "
84+ while [ $(( to_rotate-= 1 )) -ge 0 ]; do
85+ set -- " $@ " " $1 "
86+ shift
87+ done
88+ exec " $@ "
89+ else
90+ set -- " $@ " " $1 "
91+ shift
92+ rotated=$(( rotated+ 1 ))
93+ fi
94+ done
95+ echo " Please set executable_name to a valid name in a text editor" 1>&2
96+ exit 1
97+ fi
98+ done
7399
74100# Handle first param being executable name
75101if [ -x " $1 " ] ; then
76102 executable_name=" $1 "
77- echo " Target executable: $1 "
78103 shift
79104fi
80105
81106if [ -z " ${executable_name} " ] || [ ! -x " ${executable_name} " ]; then
82- echo " Please set executable_name to a valid name in a text editor or as the first command line parameter"
107+ echo " Please set executable_name to a valid name in a text editor or as the first command line parameter" 1>&2
83108 exit 1
84109fi
85110
@@ -90,52 +115,50 @@ arch=""
90115executable_path=" "
91116lib_extension=" "
92117
118+ abs_path () {
119+ # Resolve relative path to absolute from BASEDIR
120+ if [ " $1 " = " ${1#/ } " ]; then
121+ set -- " ${BASEDIR} /${1} "
122+ fi
123+ echo " $( cd " $( dirname " $1 " ) " && pwd) /$( basename " $1 " ) "
124+ }
125+
93126# Set executable path and the extension to use for the libdoorstop shared object
94127os_type=" $( uname -s) "
95128case ${os_type} in
96129 Linux* )
97- executable_path=" ${executable_name} "
98- # Handle relative paths
99- if ! echo " $executable_path " | grep " ^/.*$" ; then
100- executable_path=" ${BASEDIR} /${executable_path} "
101- fi
130+ executable_path=" $( abs_path " $executable_name " ) "
102131 lib_extension=" so"
103132 ;;
104133 Darwin* )
105- real_executable_name=" ${executable_name} "
106-
107- # Handle relative directories
108- if ! echo " $real_executable_name " | grep " ^/.*$" ; then
109- real_executable_name=" ${BASEDIR} /${real_executable_name} "
110- fi
134+ real_executable_name=" $( abs_path " $executable_name " ) "
111135
112136 # If we're not even an actual executable, check .app Info for actual executable
113- if ! echo " $real_executable_name " | grep " ^.*\.app/Contents/MacOS/.*" ; then
114- # Add .app to the end if not given
115- if ! echo " $real_executable_name " | grep " ^.*\.app$" ; then
116- real_executable_name=" ${real_executable_name} .app"
117- fi
118- inner_executable_name=$( defaults read " ${real_executable_name} /Contents/Info" CFBundleExecutable)
119- executable_path=" ${real_executable_name} /Contents/MacOS/${inner_executable_name} "
120- else
121- executable_path=" ${executable_name} "
122- fi
137+ case $real_executable_name in
138+ * .app/Contents/MacOS/* )
139+ executable_path=" ${executable_name} "
140+ ;;
141+ * )
142+ # Add .app to the end if not given
143+ if [ " $real_executable_name " = " ${real_executable_name% .app} " ]; then
144+ real_executable_name=" ${real_executable_name} .app"
145+ fi
146+ inner_executable_name=$( defaults read " ${real_executable_name} /Contents/Info" CFBundleExecutable)
147+ executable_path=" ${real_executable_name} /Contents/MacOS/${inner_executable_name} "
148+ ;;
149+ esac
123150 lib_extension=" dylib"
124151 ;;
125152 * )
126153 # alright whos running games on freebsd
127- echo " Unknown operating system ($( uname -s) )"
128- echo " Make an issue at https://github.com/NeighTools/UnityDoorstop"
154+ echo " Unknown operating system ($( uname -s) )" 1>&2
155+ echo " Make an issue at https://github.com/NeighTools/UnityDoorstop" 1>&2
129156 exit 1
130157 ;;
131158esac
132159
133- abs_path () {
134- echo " $( cd " $( dirname " $1 " ) " && pwd) /$( basename " $1 " ) "
135- }
136-
137160_readlink () {
138- # relative links with readlink (without -f) do not preserve the path info
161+ # relative links with readlink (without -f) do not preserve the path info
139162 ab_path=" $( abs_path " $1 " ) "
140163 link=" $( readlink " ${ab_path} " ) "
141164 case $link in
@@ -145,19 +168,17 @@ _readlink() {
145168 echo " $link "
146169}
147170
148-
149171resolve_executable_path () {
150172 e_path=" $( abs_path " $1 " ) "
151-
152- while [ -L " ${e_path} " ]; do
173+
174+ while [ -L " ${e_path} " ]; do
153175 e_path=$( _readlink " ${e_path} " ) ;
154176 done
155177 echo " ${e_path} "
156178}
157179
158- # Get absolute path of executable and show to user
180+ # Get absolute path of executable
159181executable_path=$( resolve_executable_path " ${executable_path} " )
160- echo " ${executable_path} "
161182
162183# Figure out the arch of the executable with file
163184file_out=" $( LD_PRELOAD=" " file -b " ${executable_path} " ) "
@@ -169,10 +190,10 @@ case "${file_out}" in
169190 arch=" x86"
170191 ;;
171192 * )
172- echo " The executable \" ${executable_path} \" is not compiled for x86 or x64 (might be ARM?)"
173- echo " If you think this is a mistake (or would like to encourage support for other architectures)"
174- echo " Please make an issue at https://github.com/NeighTools/UnityDoorstop"
175- echo " Got: ${file_out} "
193+ echo " The executable \" ${executable_path} \" is not compiled for x86 or x64 (might be ARM?)" 1>&2
194+ echo " If you think this is a mistake (or would like to encourage support for other architectures)" 1>&2
195+ echo " Please make an issue at https://github.com/NeighTools/UnityDoorstop" 1>&2
196+ echo " Got: ${file_out} " 1>&2
176197 exit 1
177198 ;;
178199esac
@@ -190,62 +211,74 @@ doorstop_bool() {
190211}
191212
192213# Read from command line
193- while : ; do
214+ i=0; max=$#
215+ while [ $i -lt $max ]; do
194216 case " $1 " in
195217 --doorstop_enabled) # For backwards compatibility. Renamed to --doorstop-enabled
196218 enabled=" $( doorstop_bool " $2 " ) "
197219 shift
220+ i=$(( i+ 1 ))
198221 ;;
199222 --doorstop_target_assembly) # For backwards compatibility. Renamed to --doorstop-target-assembly
200223 target_assembly=" $2 "
201224 shift
225+ i=$(( i+ 1 ))
202226 ;;
203227 --doorstop-enabled)
204228 enabled=" $( doorstop_bool " $2 " ) "
205229 shift
230+ i=$(( i+ 1 ))
206231 ;;
207232 --doorstop-target-assembly)
208233 target_assembly=" $2 "
209234 shift
235+ i=$(( i+ 1 ))
210236 ;;
211237 --doorstop-boot-config-override)
212238 boot_config_override=" $2 "
213239 shift
240+ i=$(( i+ 1 ))
214241 ;;
215242 --doorstop-mono-dll-search-path-override)
216243 dll_search_path_override=" $2 "
217244 shift
245+ i=$(( i+ 1 ))
218246 ;;
219247 --doorstop-mono-debug-enabled)
220248 debug_enable=" $( doorstop_bool " $2 " ) "
221249 shift
250+ i=$(( i+ 1 ))
222251 ;;
223252 --doorstop-mono-debug-suspend)
224253 debug_suspend=" $( doorstop_bool " $2 " ) "
225254 shift
255+ i=$(( i+ 1 ))
226256 ;;
227257 --doorstop-mono-debug-address)
228258 debug_address=" $2 "
229259 shift
260+ i=$(( i+ 1 ))
230261 ;;
231262 --doorstop-clr-runtime-coreclr-path)
232263 coreclr_path=" $2 "
233264 shift
265+ i=$(( i+ 1 ))
234266 ;;
235267 --doorstop-clr-corlib-dir)
236268 corlib_dir=" $2 "
237269 shift
270+ i=$(( i+ 1 ))
238271 ;;
239272 * )
240- if [ -z " $1 " ]; then
241- break
242- fi
243- rest_args=" $rest_args $1 "
273+ set -- " $@ " " $1 "
244274 ;;
245275 esac
246276 shift
277+ i=$(( i+ 1 ))
247278done
248279
280+ target_assembly=" $( abs_path " $target_assembly " ) "
281+
249282# Move variables to environment
250283export DOORSTOP_ENABLED=" $enabled "
251284export DOORSTOP_TARGET_ASSEMBLY=" $target_assembly "
276309 export DYLD_INSERT_LIBRARIES=" ${doorstop_name} :${DYLD_INSERT_LIBRARIES} "
277310fi
278311
279- # shellcheck disable=SC2086
280- exec " $executable_path " $rest_args
312+ exec " $executable_path " " $@ "
0 commit comments