-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainClass.cs
330 lines (271 loc) · 10.1 KB
/
MainClass.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using MelonLoader;
using VRChatAccessibility;
using PlagueButtonAPI;
using PlagueButtonAPI.Controls;
using PlagueButtonAPI.Controls.Grouping;
using PlagueButtonAPI.External_Libraries;
using PlagueButtonAPI.Main;
using PlagueButtonAPI.Misc;
using PlagueButtonAPI.Pages;
using UnityEngine;
using VRC;
using VRC.Core;
using VRC.UI.Core;
using Resources = VRChatAccessibility.Properties.Resources;
[assembly: MelonInfo(typeof(MainClass), "VRChat Accessibility", "1.1", "ToastyFail & Plague")]
[assembly: MelonGame("VRChat", "VRChat")]
[assembly: MelonColor(ConsoleColor.Magenta)]
namespace VRChatAccessibility
{
internal class MainClass : MelonMod
{
public static HarmonyLib.Harmony harmony;
private static IEnumerable<BaseModule> BaseModules = null;
private static IEnumerable<BaseModule> BaseModulesOnUpdate = null;
internal static int FPS = 0;
private float Offset = 0f;
internal static CollapsibleButtonGroup MainMenu = null;
internal static CollapsibleButtonGroup UserSelectedPage = null;
public class Configuration
{
public bool Protanopia { get; set; } = false;
public bool Deuteranopia { get; set; } = false;
public bool Tritanopia { get; set; } = false;
public float AssistStrength { get; set; } = 1f;
}
public static ConfigLib<Configuration> Config = new(Environment.CurrentDirectory + "\\VRChat Accessibility.json");
public override void OnApplicationStart()
{
harmony = HarmonyInstance;
var AllModules = Assembly.GetTypes().Where(o => o.IsSubclassOf(typeof(BaseModule))).OrderBy(o => (o.GetCustomAttributes(false).FirstOrDefault(q => q is LoadOrder) as LoadOrder)?.Priority).Select(a => (BaseModule)Activator.CreateInstance(a));
var ModulesWithUpdate = AllModules.Where(o =>
o.GetType().GetMethod("OnFixedUpdate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) != null || o.GetType().GetMethod("OnUpdate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) != null ||
o.GetType().GetMethod("OnLateUpdate", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) != null ||
o.GetType().GetMethod("OnSecondPassed", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) != null).ToList(); // I hate reflection
var ModulesWithoutUpdate = AllModules.Where(o => !ModulesWithUpdate.Contains(o)).ToList();
BaseModules = ModulesWithoutUpdate;
BaseModulesOnUpdate = ModulesWithUpdate;
MelonLogger.Msg($"Loaded {ModulesWithoutUpdate.Count} Modules, {ModulesWithUpdate.Count} With Updates Per Frame.");
MelonCoroutines.Start(WaitForUiManager());
Hooks.OnAvatarChanged_Post += NetworkEvents_OnAvatarChanged;
Hooks.OnAvatarInstantiated += NetworkEvents_OnAvatarInstantiated;
Hooks.OnPlayerJoin += NetworkEvents_OnPlayerJoined;
Hooks.OnPlayerLeave += NetworkEvents_OnPlayerLeft;
Hooks.OnRoomJoin += NetworkEvents_OnRoomJoined;
Hooks.OnRoomLeave += NetworkEvents_OnRoomLeft;
foreach (var module in BaseModules)
{
module?.OnApplicationStart();
}
MelonLogger.Msg("Finished Loading VRChatAccessibility!");
}
private void NetworkEvents_OnRoomLeft()
{
foreach (var module in BaseModules)
{
module?.OnRoomLeft();
}
}
private void NetworkEvents_OnRoomJoined()
{
foreach (var module in BaseModules)
{
module?.OnRoomJoined();
}
}
private void NetworkEvents_OnPlayerLeft(Player obj)
{
MelonLogger.Msg($"Player Left: {obj?.field_Private_APIUser_0?.displayName}");
foreach (var module in BaseModules)
{
module?.OnPlayerLeft(obj);
}
}
private void NetworkEvents_OnPlayerJoined(Player obj)
{
MelonLogger.Msg($"Player Joined: {obj?.field_Private_APIUser_0?.displayName}");
foreach (var module in BaseModules)
{
module?.OnPlayerJoined(obj);
}
}
private void NetworkEvents_OnAvatarChanged(VRCAvatarManager arg1, GameObject arg2, string arg3, float arg4, ApiAvatar arg5)
{
foreach (var module in BaseModules)
{
module?.OnAvatarChanged(arg1, arg2, arg3, arg4, arg5);
}
if (arg1.field_Private_VRCPlayer_0 == VRCPlayer.field_Internal_Static_VRCPlayer_0)
{
MelonLogger.Msg("Avatar Changed!");
}
}
private void NetworkEvents_OnAvatarInstantiated(VRCAvatarManager arg1, ApiAvatar arg2, GameObject arg3)
{
foreach (var module in BaseModules)
{
module?.OnAvatarInstantiated(arg1, arg2, arg3);
}
if (arg1.field_Private_VRCPlayer_0 == VRCPlayer.field_Internal_Static_VRCPlayer_0)
{
MelonLogger.Msg("Avatar Instantiated!");
}
}
public override void OnApplicationLateStart()
{
foreach (var module in BaseModules)
{
module?.OnApplicationLateStart();
}
}
public override void OnApplicationQuit()
{
foreach (var module in BaseModules)
{
module?.OnApplicationQuit();
}
}
public override void OnGUI()
{
foreach (var module in BaseModules)
{
module?.OnGUI();
}
}
private IEnumerator WaitForUiManager()
{
while (VRCUiManager.field_Private_Static_VRCUiManager_0 == null)
{
yield return null;
}
foreach (var module in BaseModules)
{
module?.OnUIManagerInit();
}
while (UIManager.field_Private_Static_UIManager_0 == null)
{
yield return null;
}
while (GameObject.Find("UserInterface").GetComponentInChildren<VRC.UI.Elements.QuickMenu>(true) == null)
{
yield return null;
}
OnQuickMenuInit();
}
public static Sprite Logo;
public static void OnQuickMenuInit()
{
ButtonAPI.OnInit += () =>
{
Logo = Resources.ColourBlindLogo_Transparent.GetSpriteFromResource();
var Page = MenuPage.CreatePage(WingSingleButton.Wing.Both, Logo, "VRChat Accessibility", "VRChat Accessibility", true, true, null, "", Logo, true).Item1;
MainMenu = Page.AddCollapsibleButtonGroup("Main Options", true);
UserSelectedPage = new CollapsibleButtonGroup(TransformHelper.SelectedUser_Local, "VRChat Accessibility");
foreach (var module in BaseModules)
{
try
{
module?.OnQuickMenuInit();
}
catch (Exception ex)
{
MelonLogger.Error("A BaseModule Failed To Execute OnQuickMenuInit!\n\n" + ex);
}
}
};
}
public override void OnFixedUpdate()
{
foreach (var module in BaseModulesOnUpdate)
{
module?.OnFixedUpdate();
}
}
public override void OnUpdate()
{
FPS = (int)(1f / Time.smoothDeltaTime);
foreach (var module in BaseModulesOnUpdate)
{
module?.OnUpdate();
}
if (Time.time > Offset)
{
Offset = Time.time + 1f;
foreach (var module in BaseModulesOnUpdate)
{
module?.OnSecondPassed();
}
}
}
public override void OnLateUpdate()
{
foreach (var module in BaseModulesOnUpdate)
{
module?.OnLateUpdate();
}
}
public override void OnLevelWasInitialized(int level)
{
foreach (var module in BaseModules)
{
module?.OnLevelWasInitialized(level);
}
}
public override void OnLevelWasLoaded(int level)
{
foreach (var module in BaseModules)
{
module?.OnLevelWasLoaded(level);
}
}
public override void OnSceneWasInitialized(int buildIndex, string sceneName)
{
foreach (var module in BaseModules)
{
module?.OnSceneWasInitialized(buildIndex, sceneName);
}
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
foreach (var module in BaseModules)
{
module?.OnSceneWasLoaded(buildIndex, sceneName);
}
}
public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
{
foreach (var module in BaseModules)
{
module?.OnSceneWasUnloaded(buildIndex, sceneName);
}
}
public override void OnModSettingsApplied()
{
foreach (var module in BaseModules)
{
module?.OnModSettingsApplied();
}
}
public override void OnPreferencesLoaded()
{
foreach (var module in BaseModules)
{
module?.OnPreferencesLoaded();
}
}
public override void OnPreferencesSaved()
{
foreach (var module in BaseModules)
{
module?.OnPreferencesSaved();
}
}
}
}