forked from megalon/BeatSaber-CustomUI
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlugin.cs
More file actions
85 lines (66 loc) · 2.33 KB
/
Plugin.cs
File metadata and controls
85 lines (66 loc) · 2.33 KB
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
using Harmony;
using IPA;
using IPA.Config;
using IPA.Utilities;
using UnityEngine.SceneManagement;
using IPALogger = IPA.Logging.Logger;
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using UnityEngine;
using CustomUI.Utilities;
namespace CustomUI
{
public class Plugin : IBeatSaberPlugin
{
internal static Ref<PluginConfig> config;
internal static IConfigProvider configProvider;
public void Init(IPALogger logger, [Config.Prefer("json")] IConfigProvider cfgProvider)
{
Logger.log = logger;
configProvider = cfgProvider;
config = cfgProvider.MakeLink<PluginConfig>((p, v) =>
{
if (v.Value == null || v.Value.RegenerateConfig)
p.Store(v.Value = new PluginConfig() { RegenerateConfig = false });
config = v;
});
}
private HarmonyInstance _harmonyInstance;
public void OnApplicationStart()
{
// Disable stack traces for log and warning type log messages, as they just result in tons of useless spam
Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
Application.SetStackTraceLogType(LogType.Warning, StackTraceLogType.None);
_harmonyInstance = HarmonyInstance.Create("com.brian91292.beatsaber.customui");
_harmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
BSEvents.OnLoad();
}
public void OnApplicationQuit()
{
_harmonyInstance.UnpatchAll("com.brian91292.beatsaber.customui");
}
public void OnFixedUpdate()
{
}
public void OnUpdate()
{
}
public void OnActiveSceneChanged(Scene prevScene, Scene nextScene)
{
}
public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
{
}
public void OnSceneUnloaded(Scene scene)
{
}
public static void Log(string text, IPALogger.Level level = IPALogger.Level.Info, [CallerFilePath] string file = "",
[CallerMemberName] string member = "",
[CallerLineNumber] int line = 0)
{
Logger.log.Log(level, $"{Path.GetFileName(file)}->{member}({line}): {text}");
}
}
}