-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPlugin.cs
More file actions
109 lines (92 loc) · 4.37 KB
/
Plugin.cs
File metadata and controls
109 lines (92 loc) · 4.37 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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.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.10.0")]
public class Plugin : BaseUnityPlugin
{
public static Plugin Instance;
public ShaderHelper ShaderHelper;
public ConfigEntry<int> beatsToShow;
public ConfigEntry<bool> DeveloperMode;
public ConfigEntry<string> DefaultBackground;
public ConfigEntry<bool> turboBackgroundFallback;
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.");
var backgrounds = new List<string>{"freeplay", "freeplay-static", "grey", "black"};
DefaultBackground = customFile.Bind("General", "Default Background", "freeplay",
$"The default background to show when a chart does not include one. Can be one of the following:\n{string.Join(", ", backgrounds)}");
DefaultBackground.Value = DefaultBackground.Value.ToLower().Trim();
if (!backgrounds.Contains(DefaultBackground.Value))
{
LogWarning("Default Background is not set to a valid option!");
}
turboBackgroundFallback = customFile.Bind("General", "Turbo Mode Background Fallback", false,
"When enabled, TrombLoader will load an image or default background instead of a video background when Turbo Mode is on.");
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);
var loader = new TrackLoader();
TrackRegistrationEvent.EVENT.Register(loader);
CustomTrackLoaderEvent.EVENT.Register(loader);
TrackCollectionRegistrationEvent.EVENT.Register(new TrombLoaderCollection.CollectionLoader(this));
ShaderHelper = new();
QualitySettings.pixelLightCount = 16;
}
private void TryInitialize()
{
_harmony.PatchAll();
}
public IEnumerator GetAudioClipSync(string path, Action callback = null)
{
var uri = new UriBuilder(Uri.UriSchemeFile, string.Empty)
{
Path = path
}.Uri;
var www = UnityWebRequestMultimedia.GetAudioClip(uri, 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
}
}