You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.8 KiB

  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. using Version = SemVer.Version;
  5. namespace IPA.Utilities
  6. {
  7. /// <summary>
  8. /// Provides some basic utility methods and properties of Beat Saber
  9. /// </summary>
  10. public static class BeatSaber
  11. {
  12. private static Version _gameVersion;
  13. /// <summary>
  14. /// Provides the current game version
  15. /// </summary>
  16. public static Version GameVersion => _gameVersion ?? (_gameVersion = new Version(Application.version, true));
  17. /// <summary>
  18. /// The different types of releases of the game.
  19. /// </summary>
  20. public enum Release
  21. {
  22. /// <summary>
  23. /// Indicates a Steam release.
  24. /// </summary>
  25. Steam,
  26. /// <summary>
  27. /// Indicates an Oculus release.
  28. /// </summary>
  29. Oculus
  30. }
  31. private static Release? _releaseCache;
  32. /// <summary>
  33. /// Gets the <see cref="Release"/> type of this installation of Beat Saber
  34. /// </summary>
  35. public static Release ReleaseType => (_releaseCache ?? (_releaseCache = FindSteamVRAsset() ? Release.Steam : Release.Oculus)).Value;
  36. /// <summary>
  37. /// The path to the Beat Saber install dir
  38. /// </summary>
  39. public static string InstallPath => Environment.CurrentDirectory;
  40. /// <summary>
  41. /// The path to the `Libs` folder. Use only if necessary.
  42. /// </summary>
  43. public static string LibraryPath => Path.Combine(InstallPath, "Libs");
  44. /// <summary>
  45. /// The path to the `Libs\Native` folder. Use only if necessary.
  46. /// </summary>
  47. public static string NativeLibraryPath => Path.Combine(LibraryPath, "Native");
  48. /// <summary>
  49. /// The directory to load plugins from.
  50. /// </summary>
  51. public static string PluginsPath => Path.Combine(InstallPath, "Plugins");
  52. /// <summary>
  53. /// The path to the `UserData` folder.
  54. /// </summary>
  55. public static string UserDataPath => Path.Combine(InstallPath, "UserData");
  56. private static bool FindSteamVRAsset()
  57. {
  58. // these require assembly qualified names....
  59. var steamVRCamera = Type.GetType("SteamVR_Camera, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false);
  60. var steamVRExternalCamera = Type.GetType("SteamVR_ExternalCamera, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false);
  61. var steamVRFade = Type.GetType("SteamVR_Fade, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false);
  62. return steamVRCamera != null && steamVRExternalCamera != null && steamVRFade != null;
  63. }
  64. }
  65. }