-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPlugin.cs
87 lines (76 loc) · 2.82 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using BeatSaberMarkupLanguage.Settings;
using BSExtraColorPresets.Configuration;
using BSExtraColorPresets.UI;
using IPA;
using IPA.Config;
using IPA.Config.Stores;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using BeatSaberMarkupLanguage.Util;
using UnityEngine;
using UnityEngine.SceneManagement;
using IPALogger = IPA.Logging.Logger;
namespace BSExtraColorPresets
{
[Plugin(RuntimeOptions.SingleStartInit)]
public class Plugin
{
public const string PluginName = "extracolorpresets";
internal static Plugin Instance { get; private set; }
internal static IPALogger Log { get; private set; }
private static readonly HarmonyLib.Harmony Harmony = new HarmonyLib.Harmony($"art.djdavid98.{PluginName}");
public static HashSet<string> ExtraColorPresetsRandomlySelectedIds;
[Init]
/// <summary>
/// Called when the plugin is first loaded by IPA (either when the game starts or when the plugin is enabled if it starts disabled).
/// [Init] methods that use a Constructor or called before regular methods like InitWithConfig.
/// Only use [Init] with one Constructor.
/// </summary>
public void Init(IPALogger logger, Config conf)
{
Instance = this;
Log = logger;
LoadConfig(conf);
Log.Debug("Apply Harmony patches");
try { Harmony.PatchAll(Assembly.GetExecutingAssembly()); }
catch (Exception ex) { Log.Debug(ex); }
Log.Info("BSExtraColorPresets initialized.");
}
private void LoadConfig(Config conf)
{
PluginConfig.Instance = conf.Generated<PluginConfig>();
Log.Debug("Config loaded");
if (!PluginConfig.Instance.ExtraColorPresetsV2.Any())
{
Log.Debug("Adding initial blank preset");
PluginConfig.Instance.ExtraColorPresetsV2.Add(new ExtraColorPresetV2());
}
}
public static void ReinitUniqueSelectables()
{
ExtraColorPresetsRandomlySelectedIds = new HashSet<string>();
}
[OnStart]
public async Task OnApplicationStart()
{
new GameObject("BSExtraColorPresetsController").AddComponent<BSExtraColorPresetsController>();
await MainMenuAwaiter.WaitForMainMenuAsync();
MainMenuAwaiter.MainMenuInitializing += ReinitSettings;
ReinitSettings();
}
private void ReinitSettings()
{
PresetManagerSettings.Instance.Initialize();
PresetSelectorSettings.Instance.Initialize();
ReinitUniqueSelectables();
}
[OnExit]
public void OnApplicationQuit()
{
}
}
}