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.

62 lines
2.4 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. private static bool FindSteamVRAsset()
  49. {
  50. // these require assembly qualified names....
  51. var steamVRCamera = Type.GetType("SteamVR_Camera, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false);
  52. var steamVRExternalCamera = Type.GetType("SteamVR_ExternalCamera, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false);
  53. var steamVRFade = Type.GetType("SteamVR_Fade, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false);
  54. return steamVRCamera != null && steamVRExternalCamera != null && steamVRFade != null;
  55. }
  56. }
  57. }