Paths.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. public static void SetExecutablePath(string executablePath, string bepinRootPath = 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. BepInExRootPath = bepinRootPath ?? Path.Combine(GameRootPath, "BepInEx");
  19. ConfigPath = Path.Combine(BepInExRootPath, "config");
  20. BepInExConfigPath = Path.Combine(ConfigPath, "BepInEx.cfg");
  21. PluginPath = Path.Combine(BepInExRootPath, "plugins");
  22. PatcherPluginPath = Path.Combine(BepInExRootPath, "patchers");
  23. BepInExAssemblyDirectory = Path.Combine(BepInExRootPath, "core");
  24. BepInExAssemblyPath = Path.Combine(BepInExAssemblyDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.dll");
  25. CachePath = Path.Combine(BepInExRootPath, "cache");
  26. }
  27. internal static void SetPluginPath(string pluginPath)
  28. {
  29. PluginPath = Utility.CombinePaths(BepInExRootPath, pluginPath);
  30. }
  31. public static SemVer.Version BepInExVersion { get; } = SemVer.Version.Parse(MetadataHelper.GetAttributes<AssemblyInformationalVersionAttribute>(typeof(Paths).Assembly)[0].InformationalVersion);
  32. /// <summary>
  33. /// The directory that the core BepInEx DLLs reside in.
  34. /// </summary>
  35. public static string BepInExAssemblyDirectory { get; private set; }
  36. /// <summary>
  37. /// The path to the core BepInEx DLL.
  38. /// </summary>
  39. public static string BepInExAssemblyPath { get; private set; }
  40. /// <summary>
  41. /// The path to the main BepInEx folder.
  42. /// </summary>
  43. public static string BepInExRootPath { get; private set; }
  44. /// <summary>
  45. /// The path of the currently executing program BepInEx is encapsulated in.
  46. /// </summary>
  47. public static string ExecutablePath { get; private set; }
  48. /// <summary>
  49. /// The directory that the currently executing process resides in.
  50. /// <para>On OSX however, this is the parent directory of the game.app folder.</para>
  51. /// </summary>
  52. public static string GameRootPath { get; private set; }
  53. /// <summary>
  54. /// The path to the config directory.
  55. /// </summary>
  56. public static string ConfigPath { get; private set; }
  57. /// <summary>
  58. /// The path to the global BepInEx configuration file.
  59. /// </summary>
  60. public static string BepInExConfigPath { get; private set; }
  61. /// <summary>
  62. /// The path to temporary cache files.
  63. /// </summary>
  64. public static string CachePath { get; private set; }
  65. /// <summary>
  66. /// The path to the patcher plugin folder which resides in the BepInEx folder.
  67. /// </summary>
  68. public static string PatcherPluginPath { get; private set; }
  69. /// <summary>
  70. /// The path to the plugin folder which resides in the BepInEx folder.
  71. /// <para>
  72. /// This is ONLY guaranteed to be set correctly when Chainloader has been initialized.
  73. /// </para>
  74. /// </summary>
  75. public static string PluginPath { get; private set; }
  76. /// <summary>
  77. /// The name of the currently executing process.
  78. /// </summary>
  79. public static string ProcessName { get; private set; }
  80. }
  81. }