Paths.cs 2.5 KB

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