Paths.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Diagnostics;
  2. using System.IO;
  3. using System.Reflection;
  4. using BepInEx.Common;
  5. namespace BepInEx
  6. {
  7. /// <summary>
  8. /// Paths used by BepInEx
  9. /// </summary>
  10. public static class Paths
  11. {
  12. private static string executablePath;
  13. /// <summary>
  14. /// The directory that the core BepInEx DLLs reside in.
  15. /// </summary>
  16. public static string BepInExAssemblyDirectory { get; private set; }
  17. /// <summary>
  18. /// The path to the core BepInEx DLL.
  19. /// </summary>
  20. public static string BepInExAssemblyPath { get; private set; }
  21. /// <summary>
  22. /// The path of the currently executing program BepInEx is encapsulated in.
  23. /// </summary>
  24. public static string ExecutablePath
  25. {
  26. get => executablePath;
  27. internal set
  28. {
  29. executablePath = value;
  30. GameRootPath = Path.GetDirectoryName(executablePath);
  31. ManagedPath = Utility.CombinePaths(GameRootPath, $"{ProcessName}_Data", "Managed");
  32. PluginPath = Utility.CombinePaths(GameRootPath, "BepInEx");
  33. PatcherPluginPath = Utility.CombinePaths(GameRootPath, "BepInEx", "patchers");
  34. BepInExAssemblyDirectory = Utility.CombinePaths(GameRootPath, "BepInEx", "core");
  35. BepInExAssemblyPath =
  36. Utility.CombinePaths(BepInExAssemblyDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.dll");
  37. }
  38. }
  39. /// <summary>
  40. /// The directory that the currently executing process resides in.
  41. /// </summary>
  42. public static string GameRootPath { get; private set; }
  43. /// <summary>
  44. /// The path to the Managed folder of the currently running Unity game.
  45. /// </summary>
  46. public static string ManagedPath { get; private set; }
  47. /// <summary>
  48. /// The path to the patcher plugin folder which resides in the BepInEx folder.
  49. /// </summary>
  50. public static string PatcherPluginPath { get; private set; }
  51. /// <summary>
  52. /// The path to the main BepInEx folder.
  53. /// </summary>
  54. public static string PluginPath { get; private set; }
  55. /// <summary>
  56. /// The name of the currently executing process.
  57. /// </summary>
  58. public static string ProcessName { get; } = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().ProcessName);
  59. }
  60. }