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.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using SemVer;
  8. using Version = SemVer.Version;
  9. namespace IPA.Utilities
  10. {
  11. /// <summary>
  12. /// Provides some basic utility methods and properties of Beat Saber
  13. /// </summary>
  14. public static class BeatSaber
  15. {
  16. private static Version _gameVersion = null;
  17. /// <summary>
  18. /// Provides the current game version
  19. /// </summary>
  20. public static Version GameVersion => _gameVersion ?? (_gameVersion = new Version(UnityEngine.Application.version));
  21. /// <summary>
  22. /// The different types of releases of the game.
  23. /// </summary>
  24. public enum Release
  25. {
  26. /// <summary>
  27. /// Indicates a Steam release.
  28. /// </summary>
  29. Steam,
  30. /// <summary>
  31. /// Indicates an Oculus release.
  32. /// </summary>
  33. Oculus
  34. }
  35. private static Release? _releaseCache = null;
  36. /// <summary>
  37. /// Gets the <see cref="Release"/> type of this installation of Beat Saber
  38. /// </summary>
  39. public static Release ReleaseType => (_releaseCache ?? (_releaseCache = FindSteamVRAsset() ? Release.Steam : Release.Oculus)).Value;
  40. /// <summary>
  41. /// The path to the `Libs` folder. Use only if necessary.
  42. /// </summary>
  43. public static string LibraryPath => Path.Combine(Environment.CurrentDirectory, "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. }