瀏覽代碼

Set GameRootPath to outside the game.app folder on OSX
Rebase of f963d6c

Bepis 3 年之前
父節點
當前提交
0b7db81420
共有 4 個文件被更改,包括 29 次插入2 次删除
  1. 7 0
      BepInEx.Core/BepInEx.Core.csproj
  2. 7 1
      BepInEx.Core/Paths.cs
  3. 14 0
      BepInEx.Core/Utility.cs
  4. 1 1
      BepInEx.Preloader.Unity/DoorstopEntrypoint.cs

+ 7 - 0
BepInEx.Core/BepInEx.Core.csproj

@@ -39,6 +39,10 @@
     <DebugSymbols>true</DebugSymbols>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="0Harmony, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>C:\Users\Richard\.nuget\packages\harmonyx\2.1.0-beta.8\lib\net35\0Harmony.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
   </ItemGroup>
   <ItemGroup>
@@ -86,6 +90,9 @@
     <Compile Include="Utility.cs" />
   </ItemGroup>
   <ItemGroup>
+    <PackageReference Include="HarmonyX">
+      <Version>2.1.0-beta.8</Version>
+    </PackageReference>
     <PackageReference Include="Mono.Cecil">
       <Version>0.10.4</Version>
     </PackageReference>

+ 7 - 1
BepInEx.Core/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.CurrentPlatform == Platform.MacOS
+				? Utility.ParentDirectory(executablePath, 4)
+				: Path.GetDirectoryName(executablePath);
+
 			BepInExRootPath = bepinRootPath ?? Path.Combine(GameRootPath, "BepInEx");
 			ConfigPath = Path.Combine(BepInExRootPath, "config");
 			BepInExConfigPath = Path.Combine(ConfigPath, "BepInEx.cfg");
@@ -50,6 +55,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.Core/Utility.cs

@@ -67,6 +67,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>

+ 1 - 1
BepInEx.Preloader.Unity/DoorstopEntrypoint.cs

@@ -10,7 +10,7 @@ namespace BepInEx.Preloader.Unity
 	{
 		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);
 			AppDomain.CurrentDomain.AssemblyResolve += LocalResolve;