-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMod.cs
259 lines (231 loc) · 11 KB
/
Mod.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
using BepInEx;
using GorillaNetworking;
using HarmonyLib;
using Photon.Pun;
using System;
using System.Collections.Generic;
using System.Linq;
using TheGorillaWatch.Configuration;
using TheGorillaWatch.Models;
using TheGorillaWatch.Patches;
using UnityEngine;
using UnityEngine.XR;
using Valve.VR;
namespace TheGorillaWatch
{
[BepInPlugin(Constants.GUID, Constants.Name, Constants.Version)]
public class Mod : BaseUnityPlugin
{
bool IsSteamVR;
bool watchOn = true;
bool stickClickJustPressed;
bool reset = true;
bool initialized;
bool useLeftTriggerToToggleMod;
bool useRightTriggerToToggleWatch;
bool toggleableWatch;
bool ToggleMod;
bool ToggleWatch;
public static int counter;
public static float PageCoolDown;
public static List<Page> mods = new List<Page>();
void Start()
{
ConfigManager.CreateConfig();
GorillaTagger.OnPlayerSpawned(Initialized);
GameObject modHolder = new GameObject("GorillaWatch Mod Holder");
int mainPageNum = 0;
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
try
{
var types = assembly.GetTypes().Where(type => type.IsSubclassOf(typeof(Page)));
foreach (var type in types)
{
try
{
Debug.Log(type.Name);
GameObject mod = new GameObject($"Mod {type.Name}");
Page modObject = (Page)mod.AddComponent(type);
mods.Add(modObject);
mod.transform.SetParent(modHolder.transform);
if (modObject.modName == "GorillaWatchMainInfoPageWABSHUWAJSD")
{
mainPageNum = mods.IndexOf(modObject);
}
}
catch (Exception e)
{
Debug.LogError($"Error adding mod {type.Name}: {e}");
}
}
}
catch (Exception e)
{
Debug.LogError($"Error With Getting Types: {e.Message}!");
}
}
counter = mainPageNum;
}
void Initialized()
{
IsSteamVR = Traverse.Create(PlayFabAuthenticator.instance).Field("platform").GetValue().ToString().ToLower() == "steam";
initialized = true;
var hash = new ExitGames.Client.Photon.Hashtable();
hash.Add(Constants.Name, Constants.Version);
hash.Add("size", 1f);
PhotonNetwork.LocalPlayer.CustomProperties = hash;
PhotonNetwork.SetPlayerCustomProperties(hash);
gameObject.AddComponent<NetworkingManager>();
foreach (Page page in mods)
{
page.Init();
}
HarmonyPatches.ApplyHarmonyPatches();
}
void Update()
{
var huntComputer = GorillaTagger.Instance.offlineVRRig.huntComputer.GetComponent<GorillaHuntComputer>();
var huntWatchComponents = new GameObject[] {
huntComputer.badge.gameObject,
huntComputer.leftHand.gameObject,
huntComputer.rightHand.gameObject,
huntComputer.hat.gameObject,
huntComputer.face.gameObject
};
if (!initialized) return;
if (PhotonNetwork.InRoom && PhotonNetwork.CurrentRoom.CustomProperties["gameMode"].ToString().Contains("MODDED") && !PhotonNetwork.CurrentRoom.CustomProperties["gameMode"].ToString().Contains("HUNT"))
{
reset = false;
useLeftTriggerToToggleMod = ConfigManager.toggleModButton.Value;
useRightTriggerToToggleWatch = ConfigManager.toggleWatchButton.Value;
if (!useLeftTriggerToToggleMod)
{
if (IsSteamVR) { ToggleMod = SteamVR_Actions.gorillaTag_LeftJoystickClick.GetState(SteamVR_Input_Sources.LeftHand); }
else { ControllerInputPoller.instance.leftControllerDevice.TryGetFeatureValue(CommonUsages.primary2DAxisClick, out ToggleMod); }
}
else
{
ToggleMod = ControllerInputPoller.instance.leftControllerIndexFloat > 0.5f;
}
if (!useRightTriggerToToggleWatch)
{
if (IsSteamVR) { ToggleWatch = SteamVR_Actions.gorillaTag_RightJoystickClick.GetState(SteamVR_Input_Sources.RightHand); }
else { ControllerInputPoller.instance.rightControllerDevice.TryGetFeatureValue(CommonUsages.primary2DAxisClick, out ToggleWatch); }
}
else
{
ToggleWatch = ControllerInputPoller.instance.rightControllerIndexFloat > 0.5f;
}
if (ToggleWatch && !stickClickJustPressed && toggleableWatch) { watchOn = !watchOn; stickClickJustPressed = true; }
else if (!ToggleWatch) { stickClickJustPressed = false; }
foreach (var component in huntWatchComponents)
{
component.SetActive(false);
}
foreach (Page p in mods)
{
if (p.modEnabled && p.pageType == PageType.Toggle)
{
p.OnUpdate();
}
}
toggleableWatch = ConfigManager.toggleableWatch.Value;
GorillaTagger.Instance.offlineVRRig.EnableHuntWatch(watchOn);
huntComputer.enabled = false;
if (watchOn)
{
if (ControllerInputPoller.instance.leftControllerSecondaryButton && Time.time > PageCoolDown + 0.5)
{
PageCoolDown = Time.time;
counter++;
GorillaTagger.Instance.offlineVRRig.PlayHandTapLocal(67, true, 1f);
}
if (ControllerInputPoller.instance.leftControllerPrimaryButton && Time.time > PageCoolDown + 0.5f)
{
PageCoolDown = Time.time;
counter--;
GorillaTagger.Instance.offlineVRRig.PlayHandTapLocal(67, true, 1f);
}
if (counter < 0) { counter = mods.Count - 1; }
if (counter >= mods.Count) { counter = 0; }
switch (mods[counter].pageType)
{
case PageType.Toggle:
huntComputer.material.gameObject.SetActive(true);
string modEnabled = mods[counter].modEnabled ? "<color=green>enabled</color>" : $"<color=red>disabled</color>";
huntComputer.text.text = mods[counter].modName + ":\n" + modEnabled + $"\n{mods[counter].info}";
huntComputer.material.color = mods[counter].modEnabled ? Color.green : Color.red;
if (ToggleMod && Time.time > PageCoolDown + .5)
{
PageCoolDown = Time.time;
if (mods[counter].modEnabled)
{
if (mods[counter].requiredModNames.Count > 0)
{
foreach (Page mod in mods)
{
if (mods[counter].requiredModNames.Contains(mod.modName))
{
mod.Disable();
}
}
}
mods[counter].Disable();
}
else
{
if (mods[counter].incompatibleModNames.Count > 0)
{
foreach (Page mod in mods)
{
if (mods[counter].incompatibleModNames.Contains(mod.modName))
{
mod.Disable();
}
}
}
if (mods[counter].requiredModNames.Count > 0)
{
foreach (Page mod in mods)
{
if (mods[counter].requiredModNames.Contains(mod.modName))
{
mod.Enable();
}
}
}
mods[counter].Enable();
}
GorillaTagger.Instance.offlineVRRig.PlayHandTapLocal(66, true, 1f);
}
break;
case PageType.Information:
huntComputer.material.gameObject.SetActive(false);
huntComputer.text.text = mods[counter].info;
break;
case PageType.notatogglebutnotinfo:
huntComputer.text.text = mods[counter].modName + "\n" + mods[counter].info;
huntComputer.material.gameObject.SetActive(false);
if (ToggleMod)
{
mods[counter].OnUpdate();
}
break;
}
}
}
else if (!reset)
{
GorillaTagger.Instance.offlineVRRig.EnableHuntWatch(false);
huntComputer.enabled = false;
foreach (var component in huntWatchComponents)
{
component.SetActive(false);
}
foreach (Page mod in mods) { mod.Disable(); }
reset = true;
}
}
}
}