Skip to content

Commit

Permalink
fix: check minimum version of BeatLeader
Browse files Browse the repository at this point in the history
  • Loading branch information
qe201020335 committed Oct 18, 2022
1 parent 702dc42 commit b6bc36c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions HRCounter/HRCounter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
<HintPath>$(BeatSaberDir)\Plugins\Counters+.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Hive.Versioning">
<HintPath>$(BeatSaberDir)\Libs\Hive.Versioning.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Libs\Newtonsoft.Json.dll</HintPath>
Expand Down
26 changes: 23 additions & 3 deletions HRCounter/Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@
using HRCounter.Configuration;
using UnityEngine;
using BeatLeader.Replayer;
using Hive.Versioning;
using IPA.Loader;
using JetBrains.Annotations;

namespace HRCounter.Utils
{
public static class Utils
{

private const string BEATLEADER_MOD_ID = "BeatLeader";


private static bool? _beatleaderHasReplay = null;

internal static bool BeatLeaderHasReplay
{
get
{
_beatleaderHasReplay ??= FindEnabledPluginMetadata(BEATLEADER_MOD_ID)?.HVersion >= new Version(0, 5, 0);
return _beatleaderHasReplay.Value;
}
}

// copied from Camera2
private static readonly MethodBase ScoreSaber_playbackEnabled =
AccessTools.Method("ScoreSaber.Core.ReplaySystem.HarmonyPatches.PatchHandleHMDUnmounted:Prefix");
Expand All @@ -22,14 +36,20 @@ internal static bool IsInReplay()
// copied from Camera2
var ssReplay = ScoreSaber_playbackEnabled != null && (bool) ScoreSaber_playbackEnabled.Invoke(null, null) == false;

var blReplay = IsModEnabled(BEATLEADER_MOD_ID) && ReplayerLauncher.IsStartedAsReplay;
var blReplay = BeatLeaderHasReplay && ReplayerLauncher.IsStartedAsReplay;

return ssReplay || blReplay;
}

internal static bool IsModEnabled(string id)
{
return IPA.Loader.PluginManager.EnabledPlugins.Any(x => x.Id == id);
return FindEnabledPluginMetadata(id) != null;
}

[CanBeNull]
internal static PluginMetadata FindEnabledPluginMetadata(string id)
{
return PluginManager.EnabledPlugins.FirstOrDefault(x => x.Id == id);
}

internal static string DetermineColor(int hr)
Expand Down

0 comments on commit b6bc36c

Please sign in to comment.