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.

66 lines
2.5 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 Beat Saber install dir
  42. /// </summary>
  43. public static string InstallPath => Environment.CurrentDirectory;
  44. /// <summary>
  45. /// The path to the `Libs` folder. Use only if necessary.
  46. /// </summary>
  47. public static string LibraryPath => Path.Combine(InstallPath, "Libs");
  48. /// <summary>
  49. /// The path to the `Libs\Native` folder. Use only if necessary.
  50. /// </summary>
  51. public static string NativeLibraryPath => Path.Combine(LibraryPath, "Native");
  52. private static bool FindSteamVRAsset()
  53. {
  54. // these require assembly qualified names....
  55. var SteamVRCamera = Type.GetType("SteamVR_Camera, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false);
  56. var SteamVRExternalCamera = Type.GetType("SteamVR_ExternalCamera, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false);
  57. var SteamVRFade = Type.GetType("SteamVR_Fade, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false);
  58. return SteamVRCamera != null && SteamVRExternalCamera != null && SteamVRFade != null;
  59. }
  60. }
  61. }