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.

86 lines
3.2 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. /// <value>the SemVer version of the game</value>
  18. public static Version GameVersion => _gameVersion ?? (_gameVersion = new Version(Application.version, true));
  19. /// <summary>
  20. /// The different types of releases of the game.
  21. /// </summary>
  22. public enum Release
  23. {
  24. /// <summary>
  25. /// Indicates a Steam release.
  26. /// </summary>
  27. Steam,
  28. /// <summary>
  29. /// Indicates an Oculus release.
  30. /// </summary>
  31. Oculus
  32. }
  33. private static Release? _releaseCache;
  34. /// <summary>
  35. /// Gets the <see cref="Release"/> type of this installation of Beat Saber
  36. /// </summary>
  37. /// <value>the type of release this is</value>
  38. public static Release ReleaseType => (_releaseCache ?? (_releaseCache = FindSteamVRAsset() ? Release.Steam : Release.Oculus)).Value;
  39. private static string _installRoot;
  40. /// <summary>
  41. /// Gets the path to the Beat Saber install directory.
  42. /// </summary>
  43. /// <value>the path of the game install directory</value>
  44. public static string InstallPath
  45. {
  46. get
  47. {
  48. if (_installRoot == null)
  49. _installRoot = Path.GetFullPath(
  50. Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", ".."));
  51. return _installRoot;
  52. }
  53. }
  54. /// <summary>
  55. /// The path to the `Libs` folder. Use only if necessary.
  56. /// </summary>
  57. /// <value>the path to the library directory</value>
  58. public static string LibraryPath => Path.Combine(InstallPath, "Libs");
  59. /// <summary>
  60. /// The path to the `Libs\Native` folder. Use only if necessary.
  61. /// </summary>
  62. /// <value>the path to the native library directory</value>
  63. public static string NativeLibraryPath => Path.Combine(LibraryPath, "Native");
  64. /// <summary>
  65. /// The directory to load plugins from.
  66. /// </summary>
  67. /// <value>the path to the plugin directory</value>
  68. public static string PluginsPath => Path.Combine(InstallPath, "Plugins");
  69. /// <summary>
  70. /// The path to the `UserData` folder.
  71. /// </summary>
  72. /// <value>the path to the user data directory</value>
  73. public static string UserDataPath => Path.Combine(InstallPath, "UserData");
  74. private static bool FindSteamVRAsset()
  75. {
  76. // these require assembly qualified names....
  77. var steamUser = Type.GetType("Steamworks.SteamUser, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false);
  78. return steamUser != null;
  79. }
  80. }
  81. }