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.

81 lines
3.1 KiB

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