Paths.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. }
  24. internal static void SetManagedPath(string managedPath)
  25. {
  26. if (managedPath == null)
  27. return;
  28. ManagedPath = managedPath;
  29. }
  30. internal static void SetPluginPath(string pluginPath)
  31. {
  32. PluginPath = Utility.CombinePaths(BepInExRootPath, pluginPath);
  33. }
  34. /// <summary>
  35. /// The directory that the core BepInEx DLLs reside in.
  36. /// </summary>
  37. public static string BepInExAssemblyDirectory { get; private set; }
  38. /// <summary>
  39. /// The path to the core BepInEx DLL.
  40. /// </summary>
  41. public static string BepInExAssemblyPath { get; private set; }
  42. /// <summary>
  43. /// The path to the main BepInEx folder.
  44. /// </summary>
  45. public static string BepInExRootPath { get; private set; }
  46. /// <summary>
  47. /// The path of the currently executing program BepInEx is encapsulated in.
  48. /// </summary>
  49. public static string ExecutablePath { get; private set; }
  50. /// <summary>
  51. /// The directory that the currently executing process resides in.
  52. /// </summary>
  53. public static string GameRootPath { get; private set; }
  54. /// <summary>
  55. /// The path to the Managed folder of the currently running Unity game.
  56. /// </summary>
  57. public static string ManagedPath { get; private set; }
  58. /// <summary>
  59. /// The path to the config directory.
  60. /// </summary>
  61. public static string ConfigPath { get; private set; }
  62. /// <summary>
  63. /// The path to the global BepInEx configuration file.
  64. /// </summary>
  65. public static string BepInExConfigPath { get; private set; }
  66. /// <summary>
  67. /// The path to the patcher plugin folder which resides in the BepInEx folder.
  68. /// </summary>
  69. public static string PatcherPluginPath { get; private set; }
  70. /// <summary>
  71. /// The path to the plugin folder which resides in the BepInEx folder.
  72. /// <para>
  73. /// This is ONLY guaranteed to be set correctly when Chainloader has been initialized.
  74. /// </para>
  75. /// </summary>
  76. public static string PluginPath { get; private set; }
  77. /// <summary>
  78. /// The name of the currently executing process.
  79. /// </summary>
  80. public static string ProcessName { get; private set; }
  81. }
  82. }