-
Notifications
You must be signed in to change notification settings - Fork 13
/
Plugin.cs
86 lines (74 loc) · 3.13 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
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using BaboonAPI.Hooks.Initializer;
using BaboonAPI.Hooks.Tracks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TrombLoader.CustomTracks;
using TrombLoader.Patch;
using TrombLoader.Helpers;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
namespace TrombLoader
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
[BepInDependency("ch.offbeatwit.baboonapi.plugin", "2.0.0")]
public class Plugin : BaseUnityPlugin
{
public static Plugin Instance;
public ShaderHelper ShaderHelper;
public ConfigEntry<int> beatsToShow;
public ConfigEntry<bool> DeveloperMode;
private Harmony _harmony = new(PluginInfo.PLUGIN_GUID);
private void Awake()
{
var customFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "TrombLoader.cfg"), true);
beatsToShow = customFile.Bind("General", "Note Display Limit", 64, "The maximum amount of notes displayed on screen at once.");
DeveloperMode = customFile.Bind("Charting", "Developer Mode", false,
"When enabled, TrombLoader will re-read chart data from disk each time a track is loaded.");
Instance = this;
LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
GameInitializationEvent.Register(Info, TryInitialize);
TrackRegistrationEvent.EVENT.Register(new TrackLoader());
ShaderHelper = new();
}
private void TryInitialize()
{
_harmony.PatchAll();
}
public IEnumerator GetAudioClipSync(string path, Action callback = null)
{
path = "file://" + Path.GetFullPath(path);
UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.OGGVORBIS);
((DownloadHandlerAudioClip)www.downloadHandler).streamAudio = true;
yield return www.SendWebRequest();
while (!www.isDone)
yield return null;
if (www.isNetworkError || www.isHttpError)
{
yield return www.error;
}
else
{
callback?.Invoke();
yield return DownloadHandlerAudioClip.GetContent(www);
}
}
public void LoadGameplayScene()
{
SceneManager.LoadSceneAsync("gameplay", LoadSceneMode.Single);
}
#region logging
internal static void LogDebug(string message) => Instance.Log(message, LogLevel.Debug);
internal static void LogInfo(string message) => Instance.Log(message, LogLevel.Info);
internal static void LogWarning(string message) => Instance.Log(message, LogLevel.Warning);
internal static void LogError(string message) => Instance.Log(message, LogLevel.Error);
private void Log(string message, LogLevel logLevel) => Logger.Log(logLevel, message);
#endregion
}
}