-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.cs
145 lines (134 loc) · 6.24 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using BepInEx;
using System.IO;
using UnityEngine;
using HarmonyLib;
using GameConsole;
using USTManager.Data;
using USTManager.Patches;
using USTManager.Commands;
using System.Collections.Generic;
using TMPro;
using UnityEngine.UI;
using USTManager.Misc;
using USTManager.Utility;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;
namespace USTManager
{
[BepInPlugin("com.zeddevstuff.ustmanager", "USTManager", "1.5.2")]
public class Plugin : BaseUnityPlugin
{
public static string UKPath, USTDir, LastUSTs;
public static GameObject MenuEntryPrefab, SelectionScreenPrefab, SelectionScreenEntryPrefab, ConflictEntryPrefab, ConflictResolutionScreenPrefab, ToastPrefab;
private void Awake()
{
instance = this;
Harmony.CreateAndPatchAll(typeof(AudioSourcePatches));
Harmony.CreateAndPatchAll(typeof(MainMenuPatches));
UKPath = new DirectoryInfo(Application.dataPath).Parent.FullName;
LastUSTs = Path.Combine(UKPath, "USTs","lastUSTs.json");
if(File.Exists(LastUSTs))
{
try
{
Manager.USTSave? data = JsonConvert.DeserializeObject<Manager.USTSave>(File.ReadAllText(LastUSTs));
if(data != null)
{
USTSelectionScreen.InternalConfirm(data.Selected, data.UST);
}
}
catch(System.Exception e)
{
Debug.LogError(e);
}
}
DirectoryInfo ustDir = new(Path.Combine(UKPath, "USTs"));
USTDir = ustDir.FullName;
if(!ustDir.Exists) ustDir.Create();
AssetBundle bundle = AssetBundle.LoadFromMemory(Resources.Resource1.ust);
MenuEntryPrefab = bundle.LoadAsset<GameObject>("MenuEntry");
Debug.Log("MenuEntryprefab " + (MenuEntryPrefab == null ? "null" : "not null"));
MenuEntryPrefab.AddComponent<HudOpenEffect>();
SelectionScreenEntryPrefab = bundle.LoadAsset<GameObject>("USTEntry");
Debug.Log("SelectionScreenEntryPrefab " + (SelectionScreenEntryPrefab == null ? "null" : "not null"));
USTEntry entry = SelectionScreenEntryPrefab.AddComponent<USTEntry>();
entry.Image = SelectionScreenEntryPrefab.transform.GetChild(0).GetComponent<Image>();
entry.Name = SelectionScreenEntryPrefab.transform.GetChild(1).GetComponent<TMP_Text>();
entry.Author = SelectionScreenEntryPrefab.transform.GetChild(2).GetComponent<TMP_Text>();
entry.IconButton = SelectionScreenEntryPrefab.transform.GetChild(0).GetComponent<Button>();
entry.Status = SelectionScreenEntryPrefab.transform.GetChild(0).GetChild(0).GetComponent<TMP_Text>();
SelectionScreenPrefab = bundle.LoadAsset<GameObject>("OptionMenu");
Debug.Log("SelectionScreenPrefab " + (SelectionScreenPrefab == null ? "null" : "not null"));
SelectionScreenPrefab?.AddComponent<USTSelectionScreen>();
ConflictEntryPrefab = bundle.LoadAsset<GameObject>("Conflict");
Debug.Log("ConflictEntryPrefab " + (ConflictEntryPrefab == null ? "null" : "not null"));
ConflictResolutionScreenPrefab = bundle.LoadAsset<GameObject>("ConflictResolutionScreen");
Debug.Log("ConflictResolutionScreenPrefab " + (ConflictResolutionScreenPrefab == null ? "null" : "not null"));
ConflictResolutionScreenPrefab?.AddComponent<ConflictResolutionScreen>();
//ToastPrefab = bundle.LoadAsset<GameObject>("Popup");
//ToastPrefab.AddComponent<Toast>();
CreateTemplate();
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
}
public static USTSelectionScreen Screen;
public static void OpenMenu(Transform transform)
{
if(Screen == null)
{
Screen = Instantiate(SelectionScreenPrefab, transform).GetComponent<USTSelectionScreen>();
Screen.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 0);
}
else
{
Screen.gameObject.SetActive(true);
}
}
private static Plugin instance;
public static void RunCoroutine(System.Collections.IEnumerator routine)
{
instance.StartCoroutine(routine);
}
public void CreateTemplate()
{
Directory.CreateDirectory(Path.Combine(UKPath, "USTs", "Template"));
File.WriteAllText(Path.Combine(UKPath, "USTs", "Template", "template.ust"), CustomUST.GetTemplateJson());
File.WriteAllText(Path.Combine(UKPath, "USTs", "Template", "readme.md"), StaticResources.Readme);
}
private void OnGUI()
{
if(!Manager.IsDebug) return;
AudioSource[] sources = FindObjectsOfType<AudioSource>()
.Where(s => s.isPlaying)
.Where(s => Manager.IsExtendedDebug ? true : s.spatialBlend < 1.0)
//.OrderByDescending(s => s.clip.length)
.ToArray();
void DrawColumn(System.Action<AudioSource> action)
{
using var _ = new GUILayout.VerticalScope();
foreach(AudioSource s in sources)
{
if(s is null) continue;
action(s);
}
}
GUIStyle style = GUI.skin.label;
style.fontSize = 24;
using var _ = new GUILayout.HorizontalScope();
style.normal.textColor = Color.green;
DrawColumn(s => GUILayout.Label(s.name ?? "null"));
GUILayout.Space(20);
style.normal.textColor = Color.white;
DrawColumn(s => GUILayout.Label(s.clip ? s.clip.name ?? "null" : "null"));
GUILayout.Space(20);
style.normal.textColor = Color.red;
DrawColumn(s =>
{
using var _ = new GUILayout.HorizontalScope();
GUILayout.Label(s.volume * 100 + "%");
GUILayout.HorizontalSlider(s.time, 0, s.clip ? s.clip.length : 0, GUILayout.Width(150));
});
}
}
}