forked from KyleTheScientist/Bark
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPlugin.cs
262 lines (241 loc) · 8.76 KB
/
Plugin.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
using System;
using System.Collections;
using System.IO;
using System.Reflection;
using BepInEx;
using BepInEx.Configuration;
using GorillaLocomotion;
using GorillaNetworking;
using Grate.Extensions;
using Grate.Gestures;
using Grate.GUI;
using Grate.Modules;
using Grate.Networking;
using Grate.Tools;
using HarmonyLib;
using Photon.Pun;
using UnityEngine;
using UnityEngine.UI;
namespace Grate
{
[BepInPlugin(PluginInfo.GUID, PluginInfo.Name, PluginInfo.Version)]
public class Plugin : BaseUnityPlugin
{
public static Plugin Instance;
public static bool initialized, WaWa_graze_dot_cc;
bool pluginEnabled = false;
public static AssetBundle assetBundle;
public static AssetBundle grateBundle;
public static MenuController menuController;
public static GameObject monkeMenuPrefab;
public static ConfigFile configFile;
public static bool IsSteam { get; protected set; }
public static bool DebugMode { get; protected set; } = false;
GestureTracker gt;
NetworkPropertyHandler nph;
public void Setup()
{
if (menuController || !pluginEnabled || !WaWa_graze_dot_cc) return;
Logging.Debug("Menu:", menuController, "Plugin Enabled:", pluginEnabled, "InRoom:", WaWa_graze_dot_cc);
try
{
gt = this.gameObject.GetOrAddComponent<GestureTracker>();
nph = this.gameObject.GetOrAddComponent<NetworkPropertyHandler>();
menuController = Instantiate(monkeMenuPrefab).AddComponent<MenuController>();
}
catch (Exception e)
{
Logging.Exception(e);
}
}
public void Cleanup()
{
try
{
Logging.Debug("Cleaning up");
menuController?.gameObject?.Obliterate();
gt?.Obliterate();
nph?.Obliterate();
}
catch (Exception e)
{
Logging.Exception(e);
}
}
void Awake()
{
try
{
Instance = this;
Logging.Init();
CI.Init();
configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "Grate.cfg"), true);
Logging.Debug("Found", GrateModule.GetGrateModuleTypes().Count, "modules");
foreach (Type moduleType in GrateModule.GetGrateModuleTypes())
{
MethodInfo bindConfigs = moduleType.GetMethod("BindConfigEntries");
if (bindConfigs is null) continue;
bindConfigs.Invoke(null, null);
}
MenuController.BindConfigEntries();
}
catch (Exception e) { Logging.Exception(e); }
}
void Start()
{
try
{
GorillaTagger.OnPlayerSpawned(OnGameInitialized);
assetBundle = AssetUtils.LoadAssetBundle("Grate/Resources/barkbundle");
grateBundle = AssetUtils.LoadAssetBundle("Grate/Resources/gratebundle");
monkeMenuPrefab = assetBundle.LoadAsset<GameObject>("Bark Menu");
}
catch (Exception e)
{
Logging.Exception(e);
}
}
public static Text debugText;
void CreateDebugGUI()
{
try
{
if (Player.Instance)
{
var canvas = Player.Instance.headCollider.transform.GetComponentInChildren<Canvas>();
if (!canvas)
{
canvas = new GameObject("~~~Grate Debug Canvas").AddComponent<Canvas>();
canvas.renderMode = RenderMode.WorldSpace;
canvas.transform.SetParent(Player.Instance.headCollider.transform);
canvas.transform.localPosition = Vector3.forward * .35f;
canvas.transform.localRotation = Quaternion.identity;
canvas.transform.localScale = Vector3.one;
canvas.gameObject.AddComponent<CanvasScaler>();
canvas.gameObject.AddComponent<GraphicRaycaster>();
canvas.GetComponent<RectTransform>().localScale = Vector3.one * .035f;
var text = new GameObject("~~~Text").AddComponent<Text>();
text.transform.SetParent(canvas.transform);
text.transform.localPosition = Vector3.zero;
text.transform.localRotation = Quaternion.identity;
text.transform.localScale = Vector3.one;
text.color = Color.green;
//text.text = "Hello World";
text.fontSize = 24;
text.font = Font.CreateDynamicFontFromOSFont("Arial", 24);
text.alignment = TextAnchor.MiddleCenter;
text.horizontalOverflow = HorizontalWrapMode.Overflow;
text.verticalOverflow = VerticalWrapMode.Overflow;
text.color = Color.white;
text.GetComponent<RectTransform>().localScale = Vector3.one * .02f;
debugText = text;
}
}
}
catch (Exception e)
{
Logging.Exception(e);
}
}
void OnEnable()
{
try
{
Logging.Debug("OnEnable");
this.pluginEnabled = true;
HarmonyPatches.ApplyHarmonyPatches();
if (initialized)
Setup();
}
catch (Exception e)
{
Logging.Exception(e);
}
}
void OnDisable()
{
try
{
Logging.Debug("OnDisable");
this.pluginEnabled = false;
HarmonyPatches.RemoveHarmonyPatches();
Cleanup();
}
catch (Exception e)
{
Logging.Exception(e);
}
}
void OnGameInitialized()
{
try
{
Logging.Debug("OnGameInitialized");
initialized = true;
PlatformTagJoin platform = (PlatformTagJoin)Traverse.Create(GorillaNetworking.PlayFabAuthenticator.instance).Field("platform").GetValue();
Logging.Info("Platform: ", platform);
IsSteam = platform.PlatformTag == "Steam";
NetworkSystem.Instance.OnJoinedRoomEvent += asdadasewwfdsfsf;
NetworkSystem.Instance.OnReturnedToSinglePlayer += roomJoined;
if (DebugMode)
CreateDebugGUI();
}
catch (Exception ex)
{
Logging.Exception(ex);
}
}
private void roomJoined()
{
if (WaWa_graze_dot_cc)
{
ModdedJoin();
}
}
private void asdadasewwfdsfsf()
{
if (NetworkSystem.Instance.GameModeString.Contains("MODDED_"))
{
qwertyujikl();
}
}
void qwertyujikl()
{
Logging.Debug("RoomJoined");
WaWa_graze_dot_cc = true;
Setup();
}
//this isnt rly a join, it's to break "cracks"
//I will keep renaming whatever i have to :3
void ModdedJoin()
{
Logging.Debug("RoomLeft");
WaWa_graze_dot_cc = false;
Cleanup();
}
public void JoinLobby(string name, string gamemode)
{
StartCoroutine(JoinLobbyInternal(name, gamemode));
}
IEnumerator JoinLobbyInternal(string name, string gamemode)
{
NetworkSystem.Instance.ReturnToSinglePlayer();
do
{
yield return new WaitForSeconds(1f);
Logging.Debug("Waiting to disconnect");
}
while (PhotonNetwork.InRoom);
string gamemodeCache = GorillaComputer.instance.currentGameMode.Value;
Logging.Debug("Changing gamemode from", gamemodeCache, "to", gamemode);
GorillaComputer.instance.currentGameMode.Value = gamemode;
PhotonNetworkController.Instance.AttemptToJoinSpecificRoom(name,JoinType.Solo);
while (!PhotonNetwork.InRoom)
{
yield return new WaitForSeconds(1f);
Logging.Debug("Waiting to connect");
}
GorillaComputer.instance.currentGameMode.Value = gamemodeCache;
}
}
}