Paths.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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, string pluginPath = null)
  11. {
  12. ExecutablePath = executablePath;
  13. ProcessName = Path.GetFileNameWithoutExtension(executablePath);
  14. GameRootPath = Path.GetDirectoryName(executablePath);
  15. if (ManagedPath == null || managedPath != null)
  16. ManagedPath = managedPath ?? Utility.CombinePaths(GameRootPath, $"{ProcessName}_Data", "Managed");
  17. if (BepInExRootPath == null || bepinRootPath != null)
  18. BepInExRootPath = bepinRootPath ?? Path.Combine(GameRootPath, "BepInEx");
  19. ConfigPath = Path.Combine(BepInExRootPath, "config");
  20. BepInExConfigPath = Path.Combine(ConfigPath, "BepInEx.cfg");
  21. if (PluginPath == null || pluginPath != null)
  22. PluginPath = pluginPath ?? Path.Combine(BepInExRootPath, "plugins");
  23. PatcherPluginPath = Path.Combine(BepInExRootPath, "patchers");
  24. BepInExAssemblyDirectory = Path.Combine(BepInExRootPath, "core");
  25. BepInExAssemblyPath = Path.Combine(BepInExAssemblyDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.dll");
  26. }
  27. /// <summary>
  28. /// The directory that the core BepInEx DLLs reside in.
  29. /// </summary>
  30. public static string BepInExAssemblyDirectory { get; private set; }
  31. /// <summary>
  32. /// The path to the core BepInEx DLL.
  33. /// </summary>
  34. public static string BepInExAssemblyPath { get; private set; }
  35. /// <summary>
  36. /// The path to the main BepInEx folder.
  37. /// </summary>
  38. public static string BepInExRootPath { get; private set; }
  39. /// <summary>
  40. /// The path of the currently executing program BepInEx is encapsulated in.
  41. /// </summary>
  42. public static string ExecutablePath { get; private set; }
  43. /// <summary>
  44. /// The directory that the currently executing process resides in.
  45. /// </summary>
  46. public static string GameRootPath { get; private set; }
  47. /// <summary>
  48. /// The path to the Managed folder of the currently running Unity game.
  49. /// </summary>
  50. public static string ManagedPath { get; private set; }
  51. /// <summary>
  52. /// The path to the config directory.
  53. /// </summary>
  54. public static string ConfigPath { get; private set; }
  55. /// <summary>
  56. /// The path to the global BepInEx configuration file.
  57. /// </summary>
  58. public static string BepInExConfigPath { get; private set; }
  59. /// <summary>
  60. /// The path to the patcher plugin folder which resides in the BepInEx folder.
  61. /// </summary>
  62. public static string PatcherPluginPath { get; private set; }
  63. /// <summary>
  64. /// The path to the plugin folder which resides in the BepInEx folder.
  65. /// <para>
  66. /// This is ONLY guaranteed to be set correctly when Chainloader has been initialized.
  67. /// </para>
  68. /// </summary>
  69. public static string PluginPath { get; private set; }
  70. /// <summary>
  71. /// The name of the currently executing process.
  72. /// </summary>
  73. public static string ProcessName { get; private set; }
  74. }
  75. }