Skip to content

Commit

Permalink
Fix startup error when beatleader isn't installed
Browse files Browse the repository at this point in the history
  • Loading branch information
PulseLane committed May 27, 2023
1 parent e6a9f6a commit cb1e361
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
6 changes: 5 additions & 1 deletion PPCounter/Installers/CalculatorsInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ class CalculatorsInstaller : MonoInstaller
public override void InstallBindings()
{
Container.BindInterfacesAndSelfTo<ScoreSaberCalculator>().AsSingle();
Container.BindInterfacesAndSelfTo<BeatLeaderCalculator>().AsSingle();
Container.BindInterfacesAndSelfTo<AccSaberCalculator>().AsSingle();

if (Plugin.BeatLeaderInstalled)
{
Container.BindInterfacesAndSelfTo<BeatLeaderCalculator>().AsSingle();
}
}
}
}
6 changes: 5 additions & 1 deletion PPCounter/Installers/DataInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ public override void InstallBindings()

Container.BindInterfacesAndSelfTo<PPData>().AsSingle().NonLazy();
Container.BindInterfacesAndSelfTo<SSData>().AsSingle().NonLazy();
Container.BindInterfacesAndSelfTo<BeatLeaderData>().AsSingle().NonLazy();
Container.BindInterfacesAndSelfTo<AccSaberData>().AsSingle().NonLazy();

if (Plugin.BeatLeaderInstalled)
{
Container.BindInterfacesAndSelfTo<BeatLeaderData>().AsSingle().NonLazy();
}
}
}
}
2 changes: 1 addition & 1 deletion PPCounter/Installers/PPCounterInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public override void InstallBindings()
{
Container.BindInterfacesAndSelfTo<ScoreSaberCounter>().AsSingle();
}
if (PluginSettings.Instance.beatLeaderEnabled)
if (Plugin.BeatLeaderInstalled && PluginSettings.Instance.beatLeaderEnabled)
{
Container.BindInterfacesAndSelfTo<BeatLeaderCounter>().AsSingle();
}
Expand Down
38 changes: 24 additions & 14 deletions PPCounter/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using IPA;
using IPA.Config;
using IPA.Config.Stores;
using IPA.Loader;
using PPCounter.Settings;
using PPCounter.Utilities;
using SiraUtil.Zenject;
using System;
using System.Collections.Generic;
using System.Linq;
using IPALogger = IPA.Logging.Logger;

namespace PPCounter
Expand All @@ -16,6 +18,8 @@ public class Plugin
internal static Plugin instance { get; private set; }
internal static string Name => "PP Counter";

internal static bool BeatLeaderInstalled = false;

//private readonly Harmony _harmony;
//private const string _harmonyID = "dev.PulseLane.BeatSaber.PPCounter";

Expand All @@ -29,7 +33,6 @@ public Plugin(IPALogger logger, Config config, Zenjector zenject)
zenject.Install<Installers.PPCounterInstaller>(Location.StandardPlayer, Location.MultiPlayer);
PluginSettings.Instance = config.Generated<PluginSettings>();


RenewSettings();
//_harmony = new Harmony(_harmonyID);

Expand All @@ -39,6 +42,13 @@ public Plugin(IPALogger logger, Config config, Zenjector zenject)
//}
}

[OnEnable]
public void OnEnable()
{
BeatLeaderInstalled = IsBeatLeaderInstalled();
Logger.log.Debug($"Beatleader installed: {BeatLeaderInstalled}");
}

private void RenewSettings()
{
var enumCount = Enum.GetValues(typeof(PPCounters)).Length;
Expand Down Expand Up @@ -68,18 +78,18 @@ private void RenewSettings()
// _harmony.Patch(originalNotifyCacheWasChanged, harmonyNotifyCacheWasChanged);
//}

//private bool IsBeatLeaderInstalled()
//{
// try
// {
// var metadatas = PluginManager.EnabledPlugins.Where(x => x.Id == "BeatLeader");
// return metadatas.Count() > 0;
// }
// catch (Exception e)
// {
// Logger.log.Debug($"Error checking for BeatLeader install: {e.Message}");
// return false;
// }
//}
private bool IsBeatLeaderInstalled()
{
try
{
var metadatas = PluginManager.EnabledPlugins.Where(x => x.Id == "BeatLeader");
return metadatas.Count() > 0;
}
catch (Exception e)
{
Logger.log.Debug($"Error checking for BeatLeader install: {e.Message}");
return false;
}
}
}
}
2 changes: 1 addition & 1 deletion PPCounter/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "PPCounter",
"name": "PPCounter",
"author": "PulseLane",
"version": "2.0.0",
"version": "2.0.1",
"description": "Adds a counter showing how much pp your current accuracy is worth on a ranked map",
"gameVersion": "1.22.1",
"dependsOn": {
Expand Down

0 comments on commit cb1e361

Please sign in to comment.