소스 검색

Set GameRootPath to outside the game.app folder on OSX

Bepis 4 년 전
부모
커밋
f963d6c173
3개의 변경된 파일22개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 2
      BepInEx.Preloader/Entrypoint.cs
  2. 7 1
      BepInEx/Paths.cs
  3. 14 0
      BepInEx/Utility.cs

+ 1 - 2
BepInEx.Preloader/Entrypoint.cs

@@ -1,5 +1,4 @@
 using System;
-using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Reflection;
@@ -11,7 +10,7 @@ namespace BepInEx.Preloader
 	{
 		public static void PreloaderPreMain(string[] args)
 		{
-			string bepinPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetFullPath(EnvVars.DOORSTOP_INVOKE_DLL_PATH)));
+			string bepinPath = Utility.ParentDirectory(Path.GetFullPath(EnvVars.DOORSTOP_INVOKE_DLL_PATH), 2);
 
 			Paths.SetExecutablePath(args[0], bepinPath, EnvVars.DOORSTOP_MANAGED_FOLDER_DIR);
 			AppDomain.CurrentDomain.AssemblyResolve += LocalResolve;

+ 7 - 1
BepInEx/Paths.cs

@@ -1,5 +1,6 @@
 using System.IO;
 using System.Reflection;
+using MonoMod.Utils;
 
 namespace BepInEx
 {
@@ -12,7 +13,11 @@ namespace BepInEx
 		{
 			ExecutablePath = executablePath;
 			ProcessName = Path.GetFileNameWithoutExtension(executablePath);
-			GameRootPath = Path.GetDirectoryName(executablePath);
+
+			GameRootPath = Utility.CurrentOs == Platform.MacOS
+				? Utility.ParentDirectory(executablePath, 4)
+				: Path.GetDirectoryName(executablePath);
+
 			ManagedPath = managedPath ?? Utility.CombinePaths(GameRootPath, $"{ProcessName}_Data", "Managed");
 			BepInExRootPath = bepinRootPath ?? Path.Combine(GameRootPath, "BepInEx");
 			ConfigPath = Path.Combine(BepInExRootPath, "config");
@@ -58,6 +63,7 @@ namespace BepInEx
 
 		/// <summary>
 		///     The directory that the currently executing process resides in.
+		///		<para>On OSX however, this is the parent directory of the game.app folder.</para>
 		/// </summary>
 		public static string GameRootPath { get; private set; }
 

+ 14 - 0
BepInEx/Utility.cs

@@ -68,6 +68,20 @@ namespace BepInEx
         public static string CombinePaths(params string[] parts) => parts.Aggregate(Path.Combine);
 
 		/// <summary>
+		/// Returns the parent directory of a path, optionally specifying the amount of levels.
+		/// </summary>
+		/// <param name="path">The path to get the parent directory of.</param>
+		/// <param name="levels">The amount of levels to traverse. Defaults to 1</param>
+		/// <returns>The parent directory.</returns>
+		public static string ParentDirectory(string path, int levels = 1)
+		{
+			for (int i = 0; i < levels; i++)
+				path = Path.GetDirectoryName(path);
+
+			return path;
+		}
+
+		/// <summary>
 		/// Tries to parse a bool, with a default value if unable to parse.
 		/// </summary>
 		/// <param name="input">The string to parse</param>