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.

52 lines
2.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using SemVer;
  7. using Version = SemVer.Version;
  8. namespace IPA.Utilities
  9. {
  10. /// <summary>
  11. /// Provides some basic utility methods and properties of Beat Saber
  12. /// </summary>
  13. public static class BeatSaber
  14. {
  15. private static Version _gameVersion = null;
  16. /// <summary>
  17. /// Provides the current game version
  18. /// </summary>
  19. public static Version GameVersion => _gameVersion ?? (_gameVersion = new Version(UnityEngine.Application.version));
  20. /// <summary>
  21. /// The different types of releases of the game.
  22. /// </summary>
  23. public enum Release
  24. {
  25. /// <summary>
  26. /// Indicates a Steam release.
  27. /// </summary>
  28. Steam,
  29. /// <summary>
  30. /// Indicates an Oculus release.
  31. /// </summary>
  32. Oculus
  33. }
  34. private static Release? _releaseCache = null;
  35. /// <summary>
  36. /// Gets the <see cref="Release"/> type of this installation of Beat Saber
  37. /// </summary>
  38. public static Release ReleaseType => (_releaseCache ?? (_releaseCache = FindSteamVRAsset() ? Release.Steam : Release.Oculus)).Value;
  39. private static bool FindSteamVRAsset()
  40. {
  41. // these require assembly qualified names....
  42. var SteamVRCamera = Type.GetType("SteamVR_Camera, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false);
  43. var SteamVRExternalCamera = Type.GetType("SteamVR_ExternalCamera, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false);
  44. var SteamVRFade = Type.GetType("SteamVR_Fade, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false);
  45. return SteamVRCamera != null && SteamVRExternalCamera != null && SteamVRFade != null;
  46. }
  47. }
  48. }