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 7
/
Main.cs
150 lines (132 loc) · 6.54 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
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
using MelonLoader;
using System;
using TeleporterVR.Utils;
using TeleporterVR.Logic;
using TeleporterVR.Patches;
using UIExpansionKit.API;
using TeleporterVR.Rendering;
namespace TeleporterVR;
public static class BuildInfo {
public const string Name = "TeleporterVR";
public const string Author = "Lily";
public const string Company = "Minty Labs";
public const string Version = "4.12.1";
public const string DownloadLink = "https://github.com/MintLily/VRChat-TeleporterVR";
public const string Description = "Easy Utility that allows you to teleport in various different ways while being VR compliant.";
}
public class Main : MelonMod {
public static bool IsDebug;
private static TPLocationIndicator _lr;
public static MelonPreferences_Category Melon;
public static MelonPreferences_Entry<bool> PreferRightHand, VRTeleportVisible, ActionMenuApiIntegration, EnableTeleportIndicator, EnableDesktopTp;
public static MelonPreferences_Entry<string> OverrideLanguage, IndicatorHexColor;
internal static readonly MelonLogger.Instance Logger = new (BuildInfo.Name, ConsoleColor.Green);
private static int _scenesLoaded = 0;
public override void OnApplicationStart() {
if (MelonDebug.IsEnabled() || Environment.CommandLine.Contains("--vrt.debug")) {
IsDebug = true;
Logger.Msg(ConsoleColor.Green, "Debug mode is active");
}
Melon = MelonPreferences.CreateCategory(BuildInfo.Name, BuildInfo.Name);
PreferRightHand = Melon.CreateEntry("preferRightHand", true, "Right Handed");
VRTeleportVisible = Melon.CreateEntry("VRTeleportVisible", true, "Is User Selected Teleport Button visible");
OverrideLanguage = Melon.CreateEntry("overrideLanguage", "off", "Override Language");
ExpansionKitApi.RegisterSettingAsStringEnum(Melon.Identifier, OverrideLanguage.Identifier,
new[] {
("off", "Disable Override"),
("en", "English"),
("fr", "Français"),
("de", "Deutsch"),
("ja", "日本語"),
("no_bm", "Bokmål"),
("ru", "русский"),
("es", "Español"),
("po", "Português"),
("sw", "Svensk")
});
ActionMenuApiIntegration = Melon.CreateEntry("ActionMenuApiIntegration", false, "Has ActionMenu Support\n(disable requires game restart)");
EnableTeleportIndicator = Melon.CreateEntry("EnableTeleportIndicator", true, "Shows a circle to where you will teleport to");
IndicatorHexColor = Melon.CreateEntry("IndicatorHEXColor", "2dff2d", "Indicator Color (HEX Value [\"RRGGBB\"])");
EnableDesktopTp = Melon.CreateEntry("EnableDesktopTP", false, "Allows you to teleport to your cursor (desktop only)\n[LeftShift + T]");
ResourceManager.Init();
NewPatches.SetupPatches();
Language.InitLanguageChange();
CreateListener.Init();
ActionMenu.InitUi();
RenderingIndicator.Init();
Logger.Msg("Initialized!");
if (OverrideLanguage.Value == "no") OverrideLanguage.Value = "no_bm";
}
// Elly is ultra cute~
private void OnUiManagerInit() {
VRUtils.Init();
GetSetWorld.Init();
if (EnableTeleportIndicator.Value)
_lr = GeneralUtils.GetPtrObj().GetOrAddComponent<TPLocationIndicator>();
if (EnableTeleportIndicator.Value && !_ranOnce) { // null checks for less errors and breakage
if (_lr == null) _lr = GeneralUtils.GetPtrObj().GetOrAddComponent<TPLocationIndicator>();
if (_lr != null) TPLocationIndicator.Toggle(false);
_ranOnce = true;
}
CreateListener.UiInit();
//MelonCoroutines.Start(SetupCustomToggle.SetPrefabOnQM());
try {
MelonCoroutines.Start(NewUi.OnQuickMenu());
}
catch (Exception e) {
Error($"Something on the UI (QuickMenu building) method failed! Did ReMod.Core fully load properly?\n{e}");
}
}
public override void OnPreferencesSaved() {
//if (UIXMenuReplacement.runOnce_start && UIXMenu.Value) UIXMenuReplacement.UpdateText();
//MelonPreferences.GetEntry<bool>(melon.Identifier, preferRightHand.Identifier).Value = VRUtils.preferRightHand;
if (ActionMenuApiIntegration.Value // if true
&& !ActionMenu.hasStarted // if has not started yet
&& ActionMenu.hasAMApiInstalled // if gompo's mod is installed
&& !ActionMenu.AMApiOutdated) // if gompo's mod is not outdated
{
Logger.Msg(ConsoleColor.Yellow, "You may have to change or reload your current world to allow the ActionMenu to show.");
ActionMenu.InitUi();
}
//if (UIXMenu.Value) {
// try { UIXMenuReplacement.TPVRButton.SetActive(UIXTPVR.Value); } catch (Exception e) { Error(e, IsDebug); }
// try { UIXMenuReplacement.UserTPButton.SetActive(VRTeleportVisible.Value); } catch (Exception e) { Error(e, IsDebug); }
// try { if (UIXMenuReplacement.runOnce_start) UIXMenuReplacement.UpdateText(); } catch (Exception e) { Error(e, IsDebug); }
//} else
NewUi.OnPrefSave();
}
private bool _ranOnce;
public override void OnSceneWasLoaded(int buildIndex, string sceneName) {
if (_scenesLoaded <= 2) {
_scenesLoaded++;
if (_scenesLoaded == 2)
OnUiManagerInit();
}
switch (buildIndex) {
case 0: case 1: break;
default:
MelonCoroutines.Start(GetSetWorld.DelayedLoad());
break;
}
CheckWorldAllowed.WorldChange(-1);
}
//public override void OnApplicationQuit() => preferRightHand.Value = VRUtils.preferRightHand;
public override void OnUpdate()
{
VRUtils.OnUpdate();
// This check is to keep the menu Disabled in Disallowed worlds, this was super easy to patch into or use UnityExplorer to re-enable the button
if (!CheckWorldAllowed.RiskyFunctionAllowed && !NewPatches.IsQmOpen)
VRUtils.Active = false;
DesktopUtils.OnUpdate();
}
public static void Log(string s) => Logger.Msg(s);
public static void Error(object s, bool isDebug = false) {
var c = Console.ForegroundColor;
Logger.Msg(isDebug ? ConsoleColor.DarkMagenta : c, s);
}
public static void Debug(string s) {
if (!IsDebug) return;
Logger.Msg(ConsoleColor.DarkMagenta, s);
}
}
// Janni is a cutie~