Paths.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System.IO;
  2. using System.Reflection;
  3. using MonoMod.Utils;
  4. namespace BepInEx
  5. {
  6. /// <summary>
  7. /// Paths used by BepInEx
  8. /// </summary>
  9. public static class Paths
  10. {
  11. internal static void SetExecutablePath(string executablePath, string bepinRootPath = null, string managedPath = null)
  12. {
  13. ExecutablePath = executablePath;
  14. ProcessName = Path.GetFileNameWithoutExtension(executablePath);
  15. GameRootPath = PlatformHelper.Is(Platform.MacOS)
  16. ? Utility.ParentDirectory(executablePath, 4)
  17. : Path.GetDirectoryName(executablePath);
  18. ManagedPath = managedPath ?? Utility.CombinePaths(GameRootPath, $"{ProcessName}_Data", "Managed");
  19. BepInExRootPath = bepinRootPath ?? Path.Combine(GameRootPath, "BepInEx");
  20. ConfigPath = Path.Combine(BepInExRootPath, "config");
  21. BepInExConfigPath = Path.Combine(ConfigPath, "BepInEx.cfg");
  22. PluginPath = Path.Combine(BepInExRootPath, "plugins");
  23. PatcherPluginPath = Path.Combine(BepInExRootPath, "patchers");
  24. BepInExAssemblyDirectory = Path.Combine(BepInExRootPath, "core");
  25. BepInExAssemblyPath = Path.Combine(BepInExAssemblyDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.dll");
  26. CachePath = Path.Combine(BepInExRootPath, "cache");
  27. }
  28. internal static void SetManagedPath(string managedPath)
  29. {
  30. if (managedPath == null)
  31. return;
  32. ManagedPath = managedPath;
  33. }
  34. internal static void SetPluginPath(string pluginPath)
  35. {
  36. PluginPath = Utility.CombinePaths(BepInExRootPath, pluginPath);
  37. }
  38. /// <summary>
  39. /// The directory that the core BepInEx DLLs reside in.
  40. /// </summary>
  41. public static string BepInExAssemblyDirectory { get; private set; }
  42. /// <summary>
  43. /// The path to the core BepInEx DLL.
  44. /// </summary>
  45. public static string BepInExAssemblyPath { get; private set; }
  46. /// <summary>
  47. /// The path to the main BepInEx folder.
  48. /// </summary>
  49. public static string BepInExRootPath { get; private set; }
  50. /// <summary>
  51. /// The path of the currently executing program BepInEx is encapsulated in.
  52. /// </summary>
  53. public static string ExecutablePath { get; private set; }
  54. /// <summary>
  55. /// The directory that the currently executing process resides in.
  56. /// <para>On OSX however, this is the parent directory of the game.app folder.</para>
  57. /// </summary>
  58. public static string GameRootPath { get; private set; }
  59. /// <summary>
  60. /// The path to the Managed folder of the currently running Unity game.
  61. /// </summary>
  62. public static string ManagedPath { get; private set; }
  63. /// <summary>
  64. /// The path to the config directory.
  65. /// </summary>
  66. public static string ConfigPath { get; private set; }
  67. /// <summary>
  68. /// The path to the global BepInEx configuration file.
  69. /// </summary>
  70. public static string BepInExConfigPath { get; private set; }
  71. /// <summary>
  72. /// The path to temporary cache files.
  73. /// </summary>
  74. public static string CachePath { get; private set; }
  75. /// <summary>
  76. /// The path to the patcher plugin folder which resides in the BepInEx folder.
  77. /// </summary>
  78. public static string PatcherPluginPath { get; private set; }
  79. /// <summary>
  80. /// The path to the plugin folder which resides in the BepInEx folder.
  81. /// <para>
  82. /// This is ONLY guaranteed to be set correctly when Chainloader has been initialized.
  83. /// </para>
  84. /// </summary>
  85. public static string PluginPath { get; private set; }
  86. /// <summary>
  87. /// The name of the currently executing process.
  88. /// </summary>
  89. public static string ProcessName { get; private set; }
  90. }
  91. }