forked from Slaynash/VRCTools
/
VRCTools.cs
165 lines (142 loc) · 5.91 KB
/
VRCTools.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
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using UnityEngine;
using UnityEngine.UI;
using VRC.Core;
using VRCModLoader;
using VRCModNetwork;
namespace VRCTools
{
[VRCModInfo("VRCTools", "0.4.5a", "Slaynash", "https://survival-machines.fr/vrcmod/VRCTools.dll")]
public class VRCTools : VRCMod
{
private bool initialising = false;
public static bool Initialised { get; private set; }
private static bool popupClosed = false;
private void OnApplicationStart() {
String lp = "";
bool first = true;
foreach (var lp2 in Environment.GetCommandLineArgs())
{
if (first) first = false;
else lp += " " + lp2;
}
VRCModLogger.Log("Launch parameters:" + lp);
ModPrefs.RegisterCategory("vrctools", "VRCTools");
ModPrefs.RegisterPrefBool("vrctools", "remoteauthcheckasked", false, null, true);
ModPrefs.RegisterPrefBool("vrctools", "remoteauthcheck", false, "Allow VRCModNetwork Auth");
ModPrefs.RegisterPrefBool("vrctools", "avatarfavdownloadasked", false, null, true);
ModPrefs.RegisterPrefBool("vrctools", "avatarfavdownload", false, "Enable AvatarFav Updater");
ModPrefs.RegisterPrefBool("vrctools", "enablediscordrichpresence", true, "Enable Discord RichPresence");
ModPrefs.RegisterPrefBool("vrctools", "enabledebugconsole", false, "Enable Debug Console");
}
private void OnApplicationQuit()
{
DiscordManager.OnApplicationQuit();
}
private void OnLevelWasLoaded(int level)
{
VRCModLogger.Log("[VRCTools] OnLevelWasLoaded " + level);
if (level == 0 && !initialising && !Initialised)
{
VRCModLogger.Log("[VRCTools] Disabling VRCFlowManager");
VRCFlowManagerUtils.DisableVRCFlowManager();
VRCModLogger.Log("[VRCTools] Initialising VRCTools");
ModManager.StartCoroutine(VRCToolsSetup());
VRCModLogger.Log("[VRCTools] VRCToolsSetup Coroutine started");
initialising = true;
}
}
private IEnumerator VRCToolsSetup()
{
VRCModLogger.Log("[VRCTools] Waiting for UI Manager...");
yield return VRCUiManagerUtils.WaitForUiManagerInit();
VRCModLogger.Log("[VRCTools] UIManager initialised ! Resuming setup");
VRCModLogger.Log("[VRCTools] CheckDownloadFiles");
yield return DependenciesDownloader.CheckDownloadFiles();
VRCModLogger.Log("[VRCTools] CheckVRCModLoaderHash");
yield return VRCModLoaderUpdater.CheckVRCModLoaderHash();
if (ModPrefs.GetBool("vrctools", "enablediscordrichpresence"))
{
VRCModLogger.Log("[VRCTools] DiscordManager Init");
DiscordManager.Init();
}
VRCModLogger.Log("[VRCTools] CheckForPermissions");
yield return CheckForPermissions();
VRCModLogger.Log("[VRCTools] VRCModNetworkStatus Setup");
VRCModNetworkStatus.Setup();
VRCModLogger.Log("[VRCTools] ModConfigPage Setup");
ModConfigPage.Setup();
VRCModLogger.Log("[VRCTools] ModdedUsersManager Init");
ModdedUsersManager.Init();
VRCModLogger.Log("[VRCTools] Init done !");
VRCFlowManagerUtils.EnableVRCFlowManager();
initialising = false;
Initialised = true;
}
private void OnUpdate()
{
if (!Initialised) return;
VRCModNetworkManager.Update();
ModdedUsersManager.Update();
DiscordManager.Update();
}
private void OnFixedUpdate()
{
if (!Initialised) return;
}
private void OnLateUpdate()
{
if (!Initialised) return;
}
private void OnGUI()
{
if (!Initialised) return;
}
private static IEnumerator CheckForPermissions()
{
if (!ModPrefs.GetBool("vrctools", "remoteauthcheckasked"))
{
VRCModLogger.Log("[VRCTools] Asking for auth");
yield return ShowAuthAgreePopup();
ModPrefs.SetBool("vrctools", "remoteauthcheckasked", true);
}
if(ModPrefs.GetBool("vrctools", "remoteauthcheck"))
{
VRCModNetworkManager.ConnectAsync();
VRCModLogger.Log("[VRCTools] Key remoteauthcheck found (true)");
yield return AvatarFavUpdater.CheckForAvatarFavUpdate();
}
else
{
VRCModLogger.Log("[VRCTools] Key remoteauthcheck found (false)");
}
}
private static IEnumerator ShowAuthAgreePopup(IEnumerator onDone = null)
{
popupClosed = false;
VRCUiPopupManagerUtils.ShowPopup("VRCTools", "To use the VRCModNetwork, you need to accept sending your VRChat credentials to the server (Required for the AvatarFav mod)", "Accept", () => {
ModPrefs.SetBool("vrctools", "remoteauthcheck", true);
ShowAuthChangePopup();
}, "Deny", () => {
ModPrefs.SetBool("vrctools", "remoteauthcheck", false);
ShowAuthChangePopup();
});
while (!popupClosed) yield return false;
}
private static void ShowAuthChangePopup()
{
VRCUiPopupManagerUtils.ShowPopup("VRCTools", "You can change this in the Mods Config page at any time", "OK", () => {
VRCUiPopupManagerUtils.GetVRCUiPopupManager().HideCurrentPopup();
popupClosed = true;
});
}
}
}