run_bepinex.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/sh
  2. # BepInEx running script
  3. #
  4. # This script is used to run a Unity game with BepInEx enabled.
  5. #
  6. # Usage: Configure the script below and simply run this script when you want to run your game modded.
  7. # -------- SETTINGS --------
  8. # ---- EDIT AS NEEDED ------
  9. # EDIT THIS: The name of the executable to run
  10. # LINUX: This is the name of the Unity game executable
  11. # MACOS: This is the name of the game app folder, including the .app suffix
  12. executable_name=""
  13. # The rest is automatically handled by BepInEx
  14. # Whether or not to enable Doorstop. Valid values: TRUE or FALSE
  15. export DOORSTOP_ENABLE=TRUE
  16. # What .NET assembly to execute. Valid value is a path to a .NET DLL that mono can execute.
  17. export DOORSTOP_INVOKE_DLL_PATH="${PWD}/BepInEx/core/BepInEx.Preloader.dll"
  18. # ----- DO NOT EDIT FROM THIS LINE FORWARD ------
  19. # ----- (unless you know what you're doing) ------
  20. if [ ! -x "$1" -a ! -x "$executable_name" ]; then
  21. echo "Please open run.sh in a text editor and configure executable name."
  22. exit 1
  23. fi
  24. doorstop_libs="${PWD}/doorstop_libs"
  25. arch=""
  26. executable_path=""
  27. lib_postfix=""
  28. os_type=`uname -s`
  29. case $os_type in
  30. Linux*)
  31. executable_path="${PWD}/${executable_name}"
  32. lib_postfix="so"
  33. ;;
  34. Darwin*)
  35. executable_name=`basename "${executable_name}" .app`
  36. real_executable_name=`defaults read "${PWD}/${executable_name}.app/Contents/Info" CFBundleExecutable`
  37. executable_path="${PWD}/${executable_name}.app/Contents/MacOS/${real_executable_name}"
  38. lib_postfix="dylib"
  39. ;;
  40. *)
  41. echo "Cannot identify OS (got $(uname -s))!"
  42. echo "Please create an issue at https://github.com/BepInEx/BepInEx/issues."
  43. exit 1
  44. ;;
  45. esac
  46. # Special case: if there is an arg, use that as executable path
  47. # Linux: arg is path to the executable
  48. # MacOS: arg is path to the .app folder which we need to resolve to the exectuable
  49. if [ -n "$1" ]; then
  50. case $os_type in
  51. Linux*)
  52. executable_path="$1"
  53. ;;
  54. Darwin*)
  55. # Special case: allow to specify path to the executable within .app
  56. full_path_part=`echo "$1" | grep "\.app/Contents/MacOS"`
  57. if [ -z "$full_path_part" ]; then
  58. executable_name=`basename "$1" .app`
  59. real_executable_name=`defaults read "$1/Contents/Info" CFBundleExecutable`
  60. executable_path="$1/Contents/MacOS/${real_executable_name}"
  61. else
  62. executable_path="$1"
  63. fi
  64. ;;
  65. esac
  66. fi
  67. executable_type=`LD_PRELOAD="" file -b "${executable_path}"`;
  68. case $executable_type in
  69. *64-bit*)
  70. arch="x64"
  71. ;;
  72. *32-bit*|*i386*)
  73. arch="x86"
  74. ;;
  75. *)
  76. echo "Cannot identify executable type (got ${executable_type})!"
  77. echo "Please create an issue at https://github.com/BepInEx/BepInEx/issues."
  78. exit 1
  79. ;;
  80. esac
  81. doorstop_libname=libdoorstop_${arch}.${lib_postfix}
  82. export LD_LIBRARY_PATH="${doorstop_libs}":${LD_LIBRARY_PATH}
  83. export LD_PRELOAD=$doorstop_libname:$LD_PRELOAD
  84. export DYLD_LIBRARY_PATH="${doorstop_libs}"
  85. export DYLD_INSERT_LIBRARIES="${doorstop_libs}/$doorstop_libname"
  86. "${executable_path}"