Paths.cs 3.3 KB

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