This repository was archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathPlugin.cs
More file actions
244 lines (227 loc) · 8.17 KB
/
Plugin.cs
File metadata and controls
244 lines (227 loc) · 8.17 KB
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
using BepInEx;
using System;
using UnityEngine;
using Utilla;
using Bark.GUI;
using Bark.Tools;
using Bark.Extensions;
using BepInEx.Configuration;
using System.IO;
using Bark.Modules;
using System.Reflection;
using Bark.Gestures;
using Bark.Networking;
using GorillaLocomotion;
using UnityEngine.UI;
using HarmonyLib;
using System.Collections;
using GorillaNetworking;
using Photon.Pun;
namespace Bark
{
[ModdedGamemode]
[BepInDependency("org.legoandmars.gorillatag.utilla", "1.5.0")]
[BepInPlugin(PluginInfo.GUID, PluginInfo.Name, PluginInfo.Version)]
public class Plugin : BaseUnityPlugin
{
public static Plugin Instance;
public static bool initialized, inRoom;
bool pluginEnabled = false;
public static AssetBundle assetBundle;
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 || !inRoom) return;
Logging.Debug("Menu:", menuController, "Plugin Enabled:", pluginEnabled, "InRoom:", inRoom);
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, "Bark.cfg"), true);
MenuController.BindConfigEntries();
Logging.Debug("Found", BarkModule.GetBarkModuleTypes().Count, "modules");
foreach (Type moduleType in BarkModule.GetBarkModuleTypes())
{
MethodInfo bindConfigs = moduleType.GetMethod("BindConfigEntries");
if (bindConfigs is null) continue;
bindConfigs.Invoke(null, null);
}
}
catch (Exception e) { Logging.Exception(e); }
}
void Start()
{
try
{
Logging.Debug("Start");
Utilla.Events.GameInitialized += OnGameInitialized;
assetBundle = AssetUtils.LoadAssetBundle("Bark/Resources/barkbundle");
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("~~~Bark 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(object sender, EventArgs e)
{
try
{
Logging.Debug("OnGameInitialized");
initialized = true;
string platform = (string)Traverse.Create(GorillaNetworking.PlayFabAuthenticator.instance).Field("platform").GetValue();
Logging.Info("Platform: ", platform);
IsSteam = platform.ToLower().Contains("steam");
if (DebugMode)
CreateDebugGUI();
}
catch (Exception ex)
{
Logging.Exception(ex);
}
}
[ModdedGamemodeJoin]
void RoomJoined(string gamemode)
{
Logging.Debug("RoomJoined");
inRoom = true;
Setup();
}
[ModdedGamemodeLeave]
void RoomLeft(string gamemode)
{
Logging.Debug("RoomLeft");
inRoom = false;
Cleanup();
}
public void JoinLobby(string name, string gamemode)
{
StartCoroutine(JoinLobbyInternal(name, gamemode));
}
IEnumerator JoinLobbyInternal(string name, string gamemode)
{
PhotonNetworkController.Instance.AttemptDisconnect();
do
{
yield return new WaitForSeconds(1f);
Logging.Debug("Waiting to disconnect");
}
while (PhotonNetwork.InRoom);
string gamemodeCache = GorillaComputer.instance.currentGameMode;
Logging.Debug("Changing gamemode from", gamemodeCache, "to", gamemode);
GorillaComputer.instance.currentGameMode = gamemode;
PhotonNetworkController.Instance.AttemptToJoinSpecificRoom(name);
while (!PhotonNetwork.InRoom)
{
yield return new WaitForSeconds(1f);
Logging.Debug("Waiting to connect");
}
GorillaComputer.instance.currentGameMode = gamemodeCache;
}
}
}