This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.cs
104 lines (93 loc) · 4.77 KB
/
Main.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
using MelonLoader;
using UnityEngine;
using System;
using System.Collections;
using System.Linq;
using System.Reflection;
using UnityEngine.UI;
using Button = UnityEngine.UI.Button;
using System.Diagnostics;
namespace SettingsRestart
{
public static class BuildInfo
{
public const string Name = "SettingsRestart";
public const string Author = "Lily";
public const string Company = null;
public const string Version = "1.0.1";
public const string DownloadLink = "https://github.com/MintLily/SettingsRestart";
public const string Description = "Simply adds a restart button on Settings, next to the Exit button.";
}
public class Main : MelonMod
{
public override void OnApplicationStart()
{
MelonCoroutines.Start(GetAssembly());
MelonLogger.Msg("Initialized!");
}
private void OnUiManagerInit() => MelonCoroutines.Start(CreateButton());
private GameObject RealSettingsExit, SettingsExit, SettingsRestart;
private IEnumerator CreateButton()
{
yield return new WaitForSeconds(8f);
try {
// Hey skids, if you're gonna take this and add to your mod, at least give me some credit. Much appreciated!
#region Exit Button
RealSettingsExit = GameObject.Find("UserInterface/MenuContent/Screens/Settings/Footer/Exit").gameObject;
SettingsExit = UnityEngine.Object.Instantiate<GameObject>(GameObject.Find("UserInterface/MenuContent/Screens/Settings/Footer/Exit"), GameObject.Find("UserInterface/MenuContent/Screens/Settings/Footer").transform);
SettingsExit.GetComponentInChildren<Text>().text = "EXIT";
SettingsExit.name = "LilyMod_SettingsExitGame";
SettingsExit.GetComponent<RectTransform>().localPosition = new Vector2(-90f, -456f);
SettingsExit.GetComponent<RectTransform>().sizeDelta -= new Vector2(150.0f, 0.0f);
SettingsExit.SetActive(true);
SettingsExit.GetComponentInChildren<Button>().onClick.AddListener(new System.Action(() =>
RealSettingsExit.GetComponent<Button>().onClick.Invoke()));
#endregion
#region Restart Button
SettingsRestart = UnityEngine.Object.Instantiate<GameObject>(GameObject.Find("UserInterface/MenuContent/Screens/Settings/Footer/Exit"), GameObject.Find("UserInterface/MenuContent/Screens/Settings/Footer").transform);
SettingsRestart.transform.SetParent(GameObject.Find("UserInterface/MenuContent/Screens/Settings/Footer/").transform);
SettingsRestart.name = "LilyMod_SettingsRestartGame";
SettingsRestart.GetComponentInChildren<Text>().text = "RESTART";
SettingsRestart.GetComponent<RectTransform>().localPosition = new Vector2(90f, -456f);
SettingsRestart.GetComponent<RectTransform>().sizeDelta = new Vector2(200f, 109f);
SettingsRestart.SetActive(true);
SettingsRestart.GetComponentInChildren<Button>().onClick.AddListener(new System.Action(() => {
try { Process.Start(System.Environment.CurrentDirectory + "\\VRChat.exe", System.Environment.CommandLine.ToString()); }
catch (System.Exception) { new System.Exception(); }
RealSettingsExit.GetComponent<Button>().onClick.Invoke();
}));
#endregion
}
catch (Exception e) { MelonLogger.Error("Settings Restart Button failure:\n" + e.ToString()); }
#region Logic
RealSettingsExit.SetActive(false);
if (RealSettingsExit.activeInHierarchy)
{
yield return new WaitForSeconds(2f);
RealSettingsExit.SetActive(false);
}
#endregion
yield break;
}
private IEnumerator GetAssembly()
{
Assembly assemblyCSharp = null;
while (true) {
assemblyCSharp = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(assembly => assembly.GetName().Name == "Assembly-CSharp");
if (assemblyCSharp == null)
yield return null;
else
break;
}
MelonCoroutines.Start(WaitForUiManagerInit(assemblyCSharp));
}
private IEnumerator WaitForUiManagerInit(Assembly assemblyCSharp)
{
Type vrcUiManager = assemblyCSharp.GetType("VRCUiManager");
PropertyInfo uiManagerSingleton = vrcUiManager.GetProperties().First(pi => pi.PropertyType == vrcUiManager);
while (uiManagerSingleton.GetValue(null) == null)
yield return null;
OnUiManagerInit();
}
}
}