using System; using System.IO; using System.Reflection; using UnityEngine; using Version = SemVer.Version; namespace IPA.Utilities { /// /// Provides some basic utility methods and properties of Beat Saber /// public static class BeatSaber { private static Version _gameVersion; /// /// Provides the current game version. /// /// the SemVer version of the game public static Version GameVersion => _gameVersion ?? (_gameVersion = new Version(Application.version, true)); internal static void SetEarlyGameVersion(Version ver) { _gameVersion = ver; Logging.Logger.log.Debug($"GameVersion set early to {ver}"); } internal static void EnsureRuntimeGameVersion() { var rtVer = new Version(Application.version, true); if (rtVer != _gameVersion) { Logging.Logger.log.Warn($"Early version {_gameVersion} parsed from game files doesn't match runtime version {rtVer}!"); _gameVersion = rtVer; } } /// /// The different types of releases of the game. /// public enum Release { /// /// Indicates a Steam release. /// Steam, /// /// Indicates an Oculus release. /// Oculus } private static Release? _releaseCache; /// /// Gets the type of this installation of Beat Saber /// /// the type of release this is public static Release ReleaseType => (_releaseCache ?? (_releaseCache = FindSteamVRAsset() ? Release.Steam : Release.Oculus)).Value; private static string _installRoot; /// /// Gets the path to the Beat Saber install directory. /// /// the path of the game install directory public static string InstallPath { get { if (_installRoot == null) _installRoot = Path.GetFullPath( Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", "..")); return _installRoot; } } /// /// The path to the `Libs` folder. Use only if necessary. /// /// the path to the library directory public static string LibraryPath => Path.Combine(InstallPath, "Libs"); /// /// The path to the `Libs\Native` folder. Use only if necessary. /// /// the path to the native library directory public static string NativeLibraryPath => Path.Combine(LibraryPath, "Native"); /// /// The directory to load plugins from. /// /// the path to the plugin directory public static string PluginsPath => Path.Combine(InstallPath, "Plugins"); /// /// The path to the `UserData` folder. /// /// the path to the user data directory public static string UserDataPath => Path.Combine(InstallPath, "UserData"); private static bool FindSteamVRAsset() { // these require assembly qualified names.... var steamUser = Type.GetType("Steamworks.SteamUser, Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", false); return steamUser != null; } } }