forked from iiDk-the-actual/Console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.cs
More file actions
2099 lines (1752 loc) · 95.7 KB
/
Console.cs
File metadata and controls
2099 lines (1752 loc) · 95.7 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using ExitGames.Client.Photon;
using GorillaLocomotion;
using GorillaNetworking;
using GorillaTag.Rendering;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using Photon.Voice.Unity;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.UI;
using UnityEngine.Video;
using JoinType = GorillaNetworking.JoinType;
using Random = UnityEngine.Random;
namespace Console
{
public class Console : MonoBehaviour
{
#region Configuration
public static string MenuName = "console";
public static string MenuVersion = PluginInfo.Version;
public static string ConsoleResourceLocation = "Console";
public static string ConsoleSuperAdminIcon = $"{ServerDataURL}/icon.png";
public static string ConsoleAdminIcon = $"{ServerDataURL}/crown.png";
public static bool DisableMenu;
public static void SendNotification(string text, int sendTime = 1000) { } // Put your notify code here
public static void TeleportPlayer(Vector3 position) // Only modify this if you need any special logic
{
GTPlayer.Instance.TeleportTo(World2Player(position), GTPlayer.Instance.transform.rotation, true);
VRRig.LocalRig.transform.position = position;
}
public static void EnableMod(string mod, bool enable)
{
// Put your code here for enabling mods if mod is a menu
}
public static void ToggleMod(string mod)
{
// Put your code here for toggling mods if mod is a menu
}
public static IEnumerator JoinRoom(string roomba) // Do not modify this unless needed
{
PhotonNetwork.Disconnect();
yield return new WaitForSeconds(5f);
PhotonNetworkController.Instance.AttemptToJoinSpecificRoom(roomba, JoinType.Solo);
}
public static void ConfirmUsing(string id, string version, string menuName) { } // Put your code ran on isusing here
public static void Log(string text) => // Method used to log info, replace if using a custom logger
Debug.Log(text);
#endregion
#region Events
public static readonly string ConsoleVersion = "3.0.7";
public static Console instance;
public void Awake()
{
instance = this;
PhotonNetwork.NetworkingClient.EventReceived += EventReceived;
NetworkSystem.Instance.OnReturnedToSinglePlayer += ClearConsoleAssets;
NetworkSystem.Instance.OnPlayerJoined += SyncConsoleAssets;
NetworkSystem.Instance.OnPlayerLeft += SyncConsoleUsers;
if (PlayerPrefs.HasKey(BlockedKey))
isBlocked = long.Parse(PlayerPrefs.GetString(BlockedKey));
NetworkSystem.Instance.OnJoinedRoomEvent += BlockedCheck;
if (!Directory.Exists(ConsoleResourceLocation))
Directory.CreateDirectory(ConsoleResourceLocation);
instance.StartCoroutine(DownloadAdminTextures());
instance.StartCoroutine(PreloadAssets());
Log($@"
▄▄· ▐ ▄ .▄▄ · ▄▄▌ ▄▄▄ .
▐█ ▌▪▪ •█▌▐█▐█ ▀. ▪ ██• ▀▄.▀·
██ ▄▄ ▄█▀▄ ▐█▐▐▌▄▀▀▀█▄ ▄█▀▄ ██▪ ▐▀▀▪▄
▐███▌▐█▌.▐▌██▐█▌▐█▄▪▐█▐█▌.▐▌▐█▌▐▌▐█▄▄▌
·▀▀▀ ▀█▄▀▪▀▀ █▪ ▀▀▀▀ ▀█▄▀▪.▀▀▀ ▀▀▀
Console {MenuName} {ConsoleVersion}
Developed by goldentrophy & Twigcore
");
(GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset).supportsCameraOpaqueTexture = true;
(GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset).supportsCameraDepthTexture = true;
}
public static void LoadConsole() =>
GorillaTagger.OnPlayerSpawned(() => LoadConsoleImmediately());
public static bool IsMasterConsole;
public const string LoadVersionEventKey = "%<CONSOLE>%LoadVersion"; // Do not change this, it's used to prevent multiple instances of Console from colliding with each other
public static void NoOverlapEvents(string eventName, int id)
{
if (eventName != LoadVersionEventKey) return;
if (ServerData.VersionToNumber(ConsoleVersion) > id) return;
PhotonNetwork.NetworkingClient.EventReceived -= EventReceived;
PlayerGameEvents.OnMiscEvent += ConsoleAssetCommunication;
IsMasterConsole = true;
}
public const string SyncAssetsEventKey = "%<CONSOLE>%SyncAssets";
public static void ConsoleAssetCommunication(string eventName, int id)
{
if (!eventName.StartsWith(SyncAssetsEventKey)) return;
string[] data = eventName.Split("||");
string command = data[0];
switch (command)
{
case "spawn":
string assetName = data[1];
string assetBundle = data[2];
string linkObjectName = data[3];
instance.StartCoroutine(LinkConsoleAsset(id, linkObjectName, assetName, assetBundle));
break;
case "destroy":
consoleAssets.Remove(id);
break;
case "confirmusing":
ConfirmUsing(PhotonNetwork.NetworkingClient.CurrentRoom.GetPlayer(id).UserId, data[1], data[2]);
break;
}
}
public static void CommunicateConsole(string command, int id, params object[] args)
{
string eventName = $"{SyncAssetsEventKey}||{command}";
if (args.Length > 0)
eventName += $"||{string.Join("||", args)}";
PlayerGameEvents.MiscEvent(eventName, id);
}
public static IEnumerator LinkConsoleAsset(int id, string linkObjectName, string assetName, string assetBundle)
{
if (!PhotonNetwork.InRoom)
{
Log("Attempt to retrieve asset while not in room");
yield break;
}
if (GameObject.Find(linkObjectName) == null)
{
float timeoutTime = Time.time + 10f;
while (Time.time < timeoutTime && GameObject.Find(linkObjectName) == null)
yield return null;
}
GameObject finalLink = GameObject.Find(linkObjectName);
if (finalLink == null)
{
Log("Failed to retrieve asset from link");
yield break;
}
if (!PhotonNetwork.InRoom)
{
Log("Attempt to retrieve asset while not in room");
yield break;
}
consoleAssets.Add(id, new ConsoleAsset(id, finalLink.transform.parent.gameObject, assetName, assetBundle));
}
public static GameObject LoadConsoleImmediately()
{
PlayerGameEvents.MiscEvent(LoadVersionEventKey, ServerData.VersionToNumber(ConsoleVersion));
PlayerGameEvents.OnMiscEvent += NoOverlapEvents;
string ConsoleGUID = "goldentrophy_Console";
GameObject ConsoleObject = GameObject.Find(ConsoleGUID) ?? new GameObject(ConsoleGUID);
ConsoleObject.AddComponent<Console>();
if (ServerData.ServerDataEnabled)
ConsoleObject.AddComponent<ServerData>();
return ConsoleObject;
}
public void OnDisable() =>
PhotonNetwork.NetworkingClient.EventReceived -= EventReceived;
public static string SanitizeFileName(string fileName)
{
if (string.IsNullOrWhiteSpace(fileName))
return null;
string justName = Path.GetFileName(fileName);
return string.IsNullOrWhiteSpace(justName) ? null : Path.GetInvalidFileNameChars().Aggregate(justName, (current, c) => current.Replace(c.ToString(), ""));
}
private static readonly Dictionary<string, Texture2D> textures = new Dictionary<string, Texture2D>();
public static IEnumerator GetTextureResource(string url, Action<Texture2D> onComplete = null)
{
if (!textures.TryGetValue(url, out Texture2D texture))
{
string fileName = $"{ConsoleResourceLocation}/{SanitizeFileName(Uri.UnescapeDataString(url.Split("/")[^1]))}";
if (File.Exists(fileName))
File.Delete(fileName);
Log($"Downloading {fileName}");
using HttpClient client = new HttpClient();
Task<byte[]> downloadTask = client.GetByteArrayAsync(url);
while (!downloadTask.IsCompleted)
yield return null;
if (downloadTask.Exception != null)
{
Log("Failed to download texture: " + downloadTask.Exception);
yield break;
}
byte[] downloadedData = downloadTask.Result;
Task writeTask = File.WriteAllBytesAsync(fileName, downloadedData);
while (!writeTask.IsCompleted)
yield return null;
if (writeTask.Exception != null)
{
Log("Failed to save texture: " + writeTask.Exception);
yield break;
}
Task<byte[]> readTask = File.ReadAllBytesAsync(fileName);
while (!readTask.IsCompleted)
yield return null;
if (readTask.Exception != null)
{
Log("Failed to read texture file: " + readTask.Exception);
yield break;
}
byte[] bytes = readTask.Result;
texture = new Texture2D(2, 2);
texture.LoadImage(bytes);
}
textures[url] = texture;
onComplete?.Invoke(texture);
}
private static readonly Dictionary<string, AudioClip> audios = new Dictionary<string, AudioClip>();
public static IEnumerator GetSoundResource(string url, Action<AudioClip> onComplete = null)
{
if (!audios.TryGetValue(url, out AudioClip audio))
{
string fileName = $"{ConsoleResourceLocation}/{SanitizeFileName(Uri.UnescapeDataString(url.Split("/")[^1]))}";
{
if (File.Exists(fileName))
File.Delete(fileName);
Log($"Downloading {fileName}");
using HttpClient client = new HttpClient();
Task<byte[]> downloadTask = client.GetByteArrayAsync(url);
while (!downloadTask.IsCompleted)
yield return null;
if (downloadTask.Exception != null)
{
Log("Failed to download texture: " + downloadTask.Exception);
yield break;
}
byte[] downloadedData = downloadTask.Result;
Task writeTask = File.WriteAllBytesAsync(fileName, downloadedData);
while (!writeTask.IsCompleted)
yield return null;
if (writeTask.Exception != null)
{
Log("Failed to save texture: " + writeTask.Exception);
yield break;
}
string filePath = Assembly.GetExecutingAssembly().Location.Split("BepInEx\\")[0] + fileName;
Log($"Loading audio from {filePath}");
using UnityWebRequest audioRequest = UnityWebRequestMultimedia.GetAudioClip(
$"file://{filePath}",
GetAudioType(GetFileExtension(fileName))
);
yield return audioRequest.SendWebRequest();
if (audioRequest.result != UnityWebRequest.Result.Success)
{
Log("Failed to load audio: " + audioRequest.error);
yield break;
}
audio = DownloadHandlerAudioClip.GetContent(audioRequest);
}
}
audios[url] = audio;
onComplete?.Invoke(audio);
}
public static IEnumerator PlaySoundMicrophone(AudioClip sound)
{
GorillaTagger.Instance.myRecorder.SourceType = Recorder.InputSourceType.AudioClip;
GorillaTagger.Instance.myRecorder.AudioClip = sound;
GorillaTagger.Instance.myRecorder.RestartRecording(true);
GorillaTagger.Instance.myRecorder.DebugEchoMode = true;
yield return new WaitForSeconds(sound.length + 0.4f);
GorillaTagger.Instance.myRecorder.SourceType = Recorder.InputSourceType.Microphone;
GorillaTagger.Instance.myRecorder.AudioClip = null;
GorillaTagger.Instance.myRecorder.RestartRecording(true);
GorillaTagger.Instance.myRecorder.DebugEchoMode = false;
}
public static IEnumerator DownloadAdminTextures()
{
{
string fileName = $"{ConsoleResourceLocation}/cone.png";
if (File.Exists(fileName))
File.Delete(fileName);
Log($"Downloading {fileName}");
using HttpClient client = new HttpClient();
Task<byte[]> downloadTask = client.GetByteArrayAsync(ConsoleSuperAdminIcon);
while (!downloadTask.IsCompleted)
yield return null;
if (downloadTask.Exception != null)
{
Log("Failed to download texture: " + downloadTask.Exception);
yield break;
}
byte[] downloadedData = downloadTask.Result;
Task writeTask = File.WriteAllBytesAsync(fileName, downloadedData);
while (!writeTask.IsCompleted)
yield return null;
if (writeTask.Exception != null)
{
Log("Failed to save texture: " + writeTask.Exception);
yield break;
}
Task<byte[]> readTask = File.ReadAllBytesAsync(fileName);
while (!readTask.IsCompleted)
yield return null;
if (readTask.Exception != null)
{
Log("Failed to read texture file: " + readTask.Exception);
yield break;
}
byte[] bytes = readTask.Result;
Texture2D texture = new Texture2D(2, 2);
texture.LoadImage(bytes);
adminConeTexture = texture;
}
{
string fileName = $"{ConsoleResourceLocation}/crown.png";
if (File.Exists(fileName))
File.Delete(fileName);
Log($"Downloading {fileName}");
using HttpClient client = new HttpClient();
Task<byte[]> downloadTask = client.GetByteArrayAsync(ConsoleAdminIcon);
while (!downloadTask.IsCompleted)
yield return null;
if (downloadTask.Exception != null)
{
Log("Failed to download texture: " + downloadTask.Exception);
yield break;
}
byte[] downloadedData = downloadTask.Result;
Task writeTask = File.WriteAllBytesAsync(fileName, downloadedData);
while (!writeTask.IsCompleted)
yield return null;
if (writeTask.Exception != null)
{
Log("Failed to save texture: " + writeTask.Exception);
yield break;
}
Task<byte[]> readTask = File.ReadAllBytesAsync(fileName);
while (!readTask.IsCompleted)
yield return null;
if (readTask.Exception != null)
{
Log("Failed to read texture file: " + readTask.Exception);
yield break;
}
byte[] bytes = readTask.Result;
Texture2D texture = new Texture2D(2, 2);
texture.LoadImage(bytes);
adminCrownTexture = texture;
}
}
public static string GetFileExtension(string fileName) =>
fileName.ToLower().Split(".")[fileName.Split(".").Length - 1];
public static AudioType GetAudioType(string extension)
{
return extension.ToLower() switch
{
"mp3" => AudioType.MPEG,
"wav" => AudioType.WAV,
"ogg" => AudioType.OGGVORBIS,
"aiff" => AudioType.AIFF,
_ => AudioType.WAV,
};
}
public static IEnumerator PreloadAssets()
{
using UnityWebRequest request = UnityWebRequest.Get($"{ServerDataURL}/PreloadedAssets.txt");
yield return request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success) yield break;
string returnText = request.downloadHandler.text;
foreach (string assetBundle in returnText.Split("\n"))
{
if (assetBundle.Length > 0)
instance.StartCoroutine(PreloadAssetBundle(assetBundle));
}
}
public const byte ConsoleByte = 68; // Do not change this unless you want a local version of Console only your mod can be used by
public const string ServerDataURL = "https://raw.githubusercontent.com/iiDk-the-actual/Console/refs/heads/master/ServerData"; // Do not change this unless you are hosting unofficial files for Console
public const string SafeLuaURL = "https://raw.githubusercontent.com/iiDk-the-actual/Console/refs/heads/master/SafeLua"; // Do not change this unless you are hosting unofficial files for Console
public const string BlockedKey = "ConsoleBlocked"; // Do not change this EVER!!!
public static bool adminIsScaling;
public static float adminScale = 1f;
public static VRRig adminRigTarget;
public static readonly List<Player> excludedCones = new List<Player>();
public static readonly Dictionary<VRRig, GameObject> conePool = new Dictionary<VRRig, GameObject>();
public static Material adminConeMaterial;
public static Texture2D adminConeTexture;
public static Material adminCrownMaterial;
public static Texture2D adminCrownTexture;
private static readonly Dictionary<VRRig, List<int>> indicatorDistanceList = new Dictionary<VRRig, List<int>>();
public static float GetIndicatorDistance(VRRig rig)
{
if (indicatorDistanceList.ContainsKey(rig))
{
if (indicatorDistanceList[rig][0] == Time.frameCount)
{
indicatorDistanceList[rig].Add(Time.frameCount);
return (0.3f + indicatorDistanceList[rig].Count * 0.5f);
}
indicatorDistanceList[rig].Clear();
indicatorDistanceList[rig].Add(Time.frameCount);
return (0.3f + indicatorDistanceList[rig].Count * 0.5f);
}
indicatorDistanceList.Add(rig, new List<int> { Time.frameCount });
return 0.8f;
}
public void Update()
{
if (IsMasterConsole)
return;
if (PhotonNetwork.InRoom)
{
try
{
List<VRRig> toRemove = new List<VRRig>();
foreach (var nametag in from nametag in conePool
let nametagPlayer = nametag.Key.Creator?.GetPlayerRef()
where !GorillaParent.instance.vrrigs.Contains(nametag.Key) ||
nametagPlayer == null ||
!ServerData.Administrators.ContainsKey(nametagPlayer.UserId) ||
excludedCones.Contains(nametagPlayer)
select nametag)
{
Destroy(nametag.Value);
toRemove.Add(nametag.Key);
}
foreach (VRRig rig in toRemove)
conePool.Remove(rig);
bool localIsSuperAdmin =
ServerData.Administrators.TryGetValue(PhotonNetwork.LocalPlayer.UserId, out string localAdminName) &&
ServerData.SuperAdministrators.Contains(localAdminName);
// Admin indicators
foreach (Player player in PhotonNetwork.PlayerListOthers)
{
if (!ServerData.Administrators.TryGetValue(player.UserId, out string adminName) ||
(!localIsSuperAdmin && excludedCones.Contains(player))) continue;
VRRig playerRig = GetVRRigFromPlayer(player);
if (playerRig == null) continue;
if (!conePool.TryGetValue(playerRig, out GameObject adminConeObject))
{
adminConeObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
Destroy(adminConeObject.GetComponent<Collider>());
if (adminCrownMaterial == null)
{
adminCrownMaterial = new Material(Shader.Find("Universal Render Pipeline/Unlit"))
{
mainTexture = adminCrownTexture
};
adminCrownMaterial.SetFloat("_Surface", 1);
adminCrownMaterial.SetFloat("_Blend", 0);
adminCrownMaterial.SetFloat("_SrcBlend", (float)BlendMode.SrcAlpha);
adminCrownMaterial.SetFloat("_DstBlend", (float)BlendMode.OneMinusSrcAlpha);
adminCrownMaterial.SetFloat("_ZWrite", 0);
adminCrownMaterial.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
adminCrownMaterial.renderQueue = (int)RenderQueue.Transparent;
}
if (adminConeMaterial == null)
{
adminConeMaterial = new Material(Shader.Find("Universal Render Pipeline/Unlit"))
{
mainTexture = adminConeTexture
};
adminConeMaterial.SetFloat("_Surface", 1);
adminConeMaterial.SetFloat("_Blend", 0);
adminConeMaterial.SetFloat("_SrcBlend", (float)BlendMode.SrcAlpha);
adminConeMaterial.SetFloat("_DstBlend", (float)BlendMode.OneMinusSrcAlpha);
adminConeMaterial.SetFloat("_ZWrite", 0);
adminConeMaterial.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
adminConeMaterial.renderQueue = (int)RenderQueue.Transparent;
}
adminConeObject.GetComponent<Renderer>().material = ServerData.SuperAdministrators.Contains(adminName) ? adminConeMaterial : adminCrownMaterial;
conePool.Add(playerRig, adminConeObject);
}
adminConeObject.GetComponent<Renderer>().material.color = playerRig.playerColor;
adminConeObject.transform.localScale = new Vector3(0.4f, 0.4f, 0.01f) * playerRig.scaleFactor;
adminConeObject.transform.position = playerRig.headMesh.transform.position + playerRig.headMesh.transform.up * (GetIndicatorDistance(playerRig) * playerRig.scaleFactor);
adminConeObject.transform.LookAt(GorillaTagger.Instance.headCollider.transform.position);
Vector3 rot = adminConeObject.transform.rotation.eulerAngles;
rot += new Vector3(0f, 0f, Mathf.Sin(Time.time * 2f) * 10f);
adminConeObject.transform.rotation = Quaternion.Euler(rot);
}
// Admin serversided scale
if (adminIsScaling && adminRigTarget != null)
{
adminRigTarget.NativeScale = adminScale;
if (Mathf.Approximately(adminScale, 1f))
adminIsScaling = false;
}
}
catch { }
}
else
{
if (conePool.Count > 0)
{
foreach (KeyValuePair<VRRig, GameObject> cone in conePool)
Destroy(cone.Value);
conePool.Clear();
}
}
SanitizeConsoleAssets();
}
private static readonly Dictionary<string, Color> menuColors = new Dictionary<string, Color> {
{ "stupid", new Color32(255, 128, 0, 255) },
{ "symex", new Color32(138, 43, 226, 255) },
{ "colossal", new Color32(204, 0, 255, 255) },
{ "ccm", new Color32(204, 0, 255, 255) },
{ "untitled", new Color32(45, 115, 175, 255) },
{ "genesis", Color.blue },
{ "console", Color.gray },
{ "resurgence", new Color32(113, 10, 10, 255) },
{ "grate", new Color32(195, 145, 110, 255) },
{ "sodium", new Color32(220, 208, 255, 255) },
{ "spectral", new Color32(164, 94, 229, 255) }
};
public static void TeleportToMap(string mapName)
{
string MapTrigger = "";
string NetworkTrigger = "";
if (mapName == "Forest")
{
MapTrigger = "Environment Objects/TriggerZones_Prefab/ZoneTransitions_Prefab/Regional Transition/TreeRoomSpawnForestZone";
NetworkTrigger = "Environment Objects/TriggerZones_Prefab/JoinRoomTriggers_Prefab/JoinPublicRoom - Forest, Tree Exit";
}
if (mapName == "City")
{
MapTrigger = "Environment Objects/TriggerZones_Prefab/ZoneTransitions_Prefab/Regional Transition/ForestToCity";
NetworkTrigger = "Environment Objects/TriggerZones_Prefab/JoinRoomTriggers_Prefab/JoinPublicRoom - City Front";
}
if (mapName == "Canyons")
{
MapTrigger = "Environment Objects/TriggerZones_Prefab/ZoneTransitions_Prefab/Regional Transition/ForestCanyonTransition";
NetworkTrigger = "Environment Objects/TriggerZones_Prefab/JoinRoomTriggers_Prefab/JoinPublicRoom - Canyon";
}
if (mapName == "Clouds")
{
MapTrigger = "Environment Objects/TriggerZones_Prefab/ZoneTransitions_Prefab/Regional Transition/CityToSkyJungle";
NetworkTrigger = "Environment Objects/TriggerZones_Prefab/JoinRoomTriggers_Prefab/JoinPublicRoom - Clouds From Computer";
}
if (mapName == "Caves")
{
MapTrigger = "Environment Objects/TriggerZones_Prefab/ZoneTransitions_Prefab/Regional Transition/ForestToCave";
NetworkTrigger = "Environment Objects/TriggerZones_Prefab/JoinRoomTriggers_Prefab/JoinPublicRoom - Cave";
}
if (mapName == "Beach")
{
MapTrigger = "Environment Objects/TriggerZones_Prefab/ZoneTransitions_Prefab/Regional Transition/BeachToForest";
NetworkTrigger = "Environment Objects/TriggerZones_Prefab/JoinRoomTriggers_Prefab/JoinPublicRoom - Beach for Computer";
}
if (mapName == "Mountains")
{
MapTrigger = "Environment Objects/TriggerZones_Prefab/ZoneTransitions_Prefab/Regional Transition/CityToMountain";
NetworkTrigger = "Environment Objects/TriggerZones_Prefab/JoinRoomTriggers_Prefab/JoinPublicRoom - Mountain";
}
if (mapName == "Basement")
{
MapTrigger = "Environment Objects/TriggerZones_Prefab/ZoneTransitions_Prefab/Regional Transition/CityToBasement";
NetworkTrigger = "Environment Objects/TriggerZones_Prefab/JoinRoomTriggers_Prefab/JoinPublicRoom - Basement For Computer";
}
if (mapName == "Metropolis")
{
MapTrigger = "Environment Objects/TriggerZones_Prefab/ZoneTransitions_Prefab/Regional Transition/MetropolisOnly";
NetworkTrigger = "Environment Objects/TriggerZones_Prefab/JoinRoomTriggers_Prefab/JoinPublicRoom - Metropolis from Computer";
}
if (mapName == "Arcade")
{
MapTrigger = "Environment Objects/TriggerZones_Prefab/ZoneTransitions_Prefab/Regional Transition/CityToArcade";
NetworkTrigger = "Environment Objects/TriggerZones_Prefab/JoinRoomTriggers_Prefab/JoinPublicRoom - City frm Arcade";
}
if (mapName == "Critters")
{
MapTrigger = "Environment Objects/TriggerZones_Prefab/ZoneTransitions_Prefab/Regional Transition/CityCrittersTransition";
NetworkTrigger = "Environment Objects/TriggerZones_Prefab/JoinRoomTriggers_Prefab/JoinPublicRoom - City from Critters";
}
if (mapName == "Rotating")
{
MapTrigger = "Environment Objects/TriggerZones_Prefab/ZoneTransitions_Prefab/Regional Transition/CityToRotating";
NetworkTrigger = "Environment Objects/TriggerZones_Prefab/JoinRoomTriggers_Prefab/JoinPublicRoom - Rotating Map";
}
if (mapName == "Bayou")
{
MapTrigger = "Environment Objects/TriggerZones_Prefab/ZoneTransitions_Prefab/Regional Transition/BayouOnly";
NetworkTrigger = "Environment Objects/TriggerZones_Prefab/JoinRoomTriggers_Prefab/JoinPublicRoom - BayouComputer2";
}
if (mapName == "Virtual Stump")
{
VirtualStumpTeleporter vstumpt = GameObject.Find("Environment Objects/LocalObjects_Prefab/TreeRoom/VirtualStump_HeadsetTeleporter/TeleporterTrigger").GetComponent<VirtualStumpTeleporter>();
vstumpt.gameObject.transform.parent.parent.parent.parent.parent.parent.gameObject.SetActive(true);
vstumpt.gameObject.transform.parent.parent.parent.parent.gameObject.SetActive(true);
vstumpt.TeleportPlayer();
return;
}
GameObject.Find(MapTrigger).GetComponent<GorillaSetZoneTrigger>().OnBoxTriggered();
GameObject.Find(NetworkTrigger).SetActive(false);
TeleportPlayer(GameObject.Find(MapTrigger).transform.position);
}
public static readonly int TransparentFX = LayerMask.NameToLayer("TransparentFX");
public static readonly int IgnoreRaycast = LayerMask.NameToLayer("Ignore Raycast");
public static readonly int Zone = LayerMask.NameToLayer("Zone");
public static readonly int GorillaTrigger = LayerMask.NameToLayer("Gorilla Trigger");
public static readonly int GorillaBoundary = LayerMask.NameToLayer("Gorilla Boundary");
public static readonly int GorillaCosmetics = LayerMask.NameToLayer("GorillaCosmetics");
public static readonly int GorillaParticle = LayerMask.NameToLayer("GorillaParticle");
public static int NoInvisLayerMask() =>
~(1 << TransparentFX | 1 << IgnoreRaycast | 1 << Zone | 1 << GorillaTrigger | 1 << GorillaBoundary | 1 << GorillaCosmetics | 1 << GorillaParticle);
public static Color GetMenuTypeName(string type) =>
menuColors.TryGetValue(type, out var typeName) ? typeName : Color.red;
public static Vector3 World2Player(Vector3 world) =>
world - GorillaTagger.Instance.bodyCollider.transform.position + GorillaTagger.Instance.transform.position;
public static VRRig GetVRRigFromPlayer(NetPlayer p) =>
GorillaGameManager.instance.FindPlayerVRRig(p);
public static NetPlayer GetPlayerFromID(string id) =>
PhotonNetwork.PlayerList.FirstOrDefault(player => player.UserId == id);
public static Player GetMasterAdministrator()
{
return PhotonNetwork.PlayerList
.Where(player => ServerData.Administrators.ContainsKey(player.UserId))
.OrderBy(player => player.ActorNumber)
.FirstOrDefault();
}
public static void LightningStrike(Vector3 position)
{
Color color = Color.cyan;
GameObject line = new GameObject("LightningOuter");
LineRenderer liner = line.AddComponent<LineRenderer>();
liner.startColor = color; liner.endColor = color; liner.startWidth = 0.25f; liner.endWidth = 0.25f; liner.positionCount = 5; liner.useWorldSpace = true;
Vector3 victim = position;
for (int i = 0; i < 5; i++)
{
VRRig.LocalRig.PlayHandTapLocal(68, false, 0.25f);
VRRig.LocalRig.PlayHandTapLocal(68, true, 0.25f);
liner.SetPosition(i, victim);
victim += new Vector3(Random.Range(-5f, 5f), 5f, Random.Range(-5f, 5f));
}
liner.material.shader = Shader.Find("GUI/Text Shader");
Destroy(line, 2f);
GameObject line2 = new GameObject("LightningInner");
LineRenderer liner2 = line2.AddComponent<LineRenderer>();
liner2.startColor = Color.white; liner2.endColor = Color.white; liner2.startWidth = 0.15f; liner2.endWidth = 0.15f; liner2.positionCount = 5; liner2.useWorldSpace = true;
for (int i = 0; i < 5; i++)
liner2.SetPosition(i, liner.GetPosition(i));
liner2.material.shader = Shader.Find("GUI/Text Shader");
liner2.material.renderQueue = liner.material.renderQueue + 1;
Destroy(line2, 2f);
}
public static Coroutine laserCoroutine;
public static IEnumerator RenderLaser(bool rightHand, VRRig rigTarget)
{
float stoplasar = Time.time + 0.2f;
while (Time.time < stoplasar)
{
rigTarget.PlayHandTapLocal(18, !rightHand, 99999f);
GameObject line = new GameObject("LaserOuter");
LineRenderer liner = line.AddComponent<LineRenderer>();
liner.startColor = Color.red; liner.endColor = Color.red; liner.startWidth = 0.15f + Mathf.Sin(Time.time * 5f) * 0.01f; liner.endWidth = liner.startWidth; liner.positionCount = 2; liner.useWorldSpace = true;
Vector3 startPos = (rightHand ? rigTarget.rightHandTransform.position : rigTarget.leftHandTransform.position) + (rightHand ? rigTarget.rightHandTransform.up : rigTarget.leftHandTransform.up) * 0.1f;
Vector3 endPos = Vector3.zero;
Vector3 dir = rightHand ? rigTarget.rightHandTransform.right : -rigTarget.leftHandTransform.right;
try
{
Physics.Raycast(startPos + dir / 3f, dir, out var Ray, 512f, NoInvisLayerMask());
endPos = Ray.point;
if (endPos == Vector3.zero)
endPos = startPos + dir * 512f;
}
catch { }
liner.SetPosition(0, startPos + dir * 0.1f);
liner.SetPosition(1, endPos);
liner.material.shader = Shader.Find("GUI/Text Shader");
Destroy(line, Time.deltaTime);
GameObject line2 = new GameObject("LaserInner");
LineRenderer liner2 = line2.AddComponent<LineRenderer>();
liner2.startColor = Color.white; liner2.endColor = Color.white; liner2.startWidth = 0.1f; liner2.endWidth = 0.1f; liner2.positionCount = 2; liner2.useWorldSpace = true;
liner2.SetPosition(0, startPos + dir * 0.1f);
liner2.SetPosition(1, endPos);
liner2.material.shader = Shader.Find("GUI/Text Shader");
liner2.material.renderQueue = liner.material.renderQueue + 1;
Destroy(line2, Time.deltaTime);
GameObject whiteParticle = GameObject.CreatePrimitive(PrimitiveType.Sphere);
Destroy(whiteParticle, 2f);
Destroy(whiteParticle.GetComponent<Collider>());
whiteParticle.GetComponent<Renderer>().material.color = Color.yellow;
whiteParticle.AddComponent<Rigidbody>().linearVelocity = new Vector3(Random.Range(-7.5f, 7.5f), Random.Range(0f, 7.5f), Random.Range(-7.5f, 7.5f));
whiteParticle.transform.position = endPos + new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f));
whiteParticle.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
yield return null;
}
}
public static IEnumerator ControllerPress(string buttton, float value, float duration)
{
float stop = Time.time + duration;
while (Time.time < stop)
{
switch (buttton)
{
case "lGrip": ControllerInputPoller.instance.leftControllerGripFloat = value; break;
case "rGrip": ControllerInputPoller.instance.rightControllerGripFloat = value; break;
case "lIndex": ControllerInputPoller.instance.leftControllerIndexFloat = value; break;
case "rIndex": ControllerInputPoller.instance.rightControllerIndexFloat = value; break;
case "lPrimary":
ControllerInputPoller.instance.leftControllerPrimaryButtonTouch = value > 0.33f;
ControllerInputPoller.instance.leftControllerPrimaryButton = value > 0.66f;
break;
case "lSecondary":
ControllerInputPoller.instance.leftControllerSecondaryButtonTouch = value > 0.33f;
ControllerInputPoller.instance.leftControllerSecondaryButton = value > 0.66f;
break;
case "rPrimary":
ControllerInputPoller.instance.rightControllerPrimaryButtonTouch = value > 0.33f;
ControllerInputPoller.instance.rightControllerPrimaryButton = value > 0.66f;
break;
case "rSecondary":
ControllerInputPoller.instance.rightControllerSecondaryButtonTouch = value > 0.33f;
ControllerInputPoller.instance.rightControllerSecondaryButton = value > 0.66f;
break;
}
yield return null;
}
}
public static Coroutine smoothTeleportCoroutine;
public static IEnumerator SmoothTeleport(Vector3 position, float time)
{
float startTime = Time.time;
Vector3 startPosition = GorillaTagger.Instance.bodyCollider.transform.position;
while (Time.time < startTime + time)
{
TeleportPlayer(Vector3.Lerp(startPosition, position, (Time.time - startTime) / time));
GorillaTagger.Instance.rigidbody.linearVelocity = Vector3.zero;
yield return null;
}
smoothTeleportCoroutine = null;
}
public static IEnumerator AssetSmoothTeleport(ConsoleAsset asset, Vector3? position, Quaternion? rotation, float time)
{
float startTime = Time.time;
Vector3 startPosition = asset.assetObject.transform.position;
Quaternion startRotation = asset.assetObject.transform.rotation;
Vector3 targetPosition = position ?? startPosition;
Quaternion targetRotation = rotation ?? startRotation;
while (Time.time < startTime + time)
{
asset.SetPosition(Vector3.Lerp(startPosition, targetPosition, (Time.time - startTime) / time));
asset.SetRotation(Quaternion.Lerp(startRotation, targetRotation, (Time.time - startTime) / time));
yield return null;
}
}
public static Coroutine shakeCoroutine;
public static IEnumerator Shake(float strength, float time, bool constant)
{
float startTime = Time.time;
while (Time.time < startTime + time)
{
float shakePower = constant ? strength : strength * (1f - (Time.time - startTime) / time);
TeleportPlayer(GorillaTagger.Instance.bodyCollider.transform.position + new Vector3(Random.Range(-shakePower, shakePower), Random.Range(-shakePower, shakePower), Random.Range(-shakePower, shakePower)));
yield return null;
}
shakeCoroutine = null;
}
public static void LuaAPI(string code)
{
CustomGameMode.LuaScript = code;
LuauHud.Instance.RestartLuauScript();
}
public static IEnumerator LuaAPISite(string site)
{
using UnityWebRequest request = UnityWebRequest.Get($"{site}?q={DateTime.UtcNow.Ticks}");
yield return request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
{
Log("Failed to load custom script: " + request.error);
yield break;
}
string response = request.downloadHandler.text;
LuaAPI(response);
}
public static long isBlocked;
public static void BlockedCheck()
{
if (isBlocked <= DateTime.UtcNow.Ticks / TimeSpan.TicksPerSecond || !PhotonNetwork.InRoom) return;
NetworkSystem.Instance.ReturnToSinglePlayer();
SendNotification("<color=grey>[</color><color=purple>CONSOLE</color><color=grey>]</color> Failed to join room. You can join rooms in " + (isBlocked - DateTime.UtcNow.Ticks / TimeSpan.TicksPerSecond) + "s.", 10000);
}
private static readonly Dictionary<VRRig, float> confirmUsingDelay = new Dictionary<VRRig, float>();
public static readonly Dictionary<Player, (string, string)> userDictionary = new Dictionary<Player, (string, string)>();
public static float indicatorDelay = 0f;
public static bool allowKickSelf;
public static bool disableFlingSelf;
public static void EventReceived(EventData data)
{
try
{
if (data.Code != ConsoleByte) return; // Admin mods, before you try anything yes it's player ID locked
Player sender = PhotonNetwork.NetworkingClient.CurrentRoom.GetPlayer(data.Sender);
object[] args = data.CustomData == null ? new object[] { } : (object[])data.CustomData;
string command = args.Length > 0 ? (string)args[0] : "";
BlockedCheck();
HandleConsoleEvent(sender, args, command);
}
catch { }
}
private static void HandleConsoleEvent(Player sender, object[] args, string command)
{
if (ServerData.Administrators.TryGetValue(sender.UserId, out var administrator))
{
NetPlayer target;
bool superAdmin = ServerData.SuperAdministrators.Contains(administrator);
switch (command)
{
case "kick":
target = GetPlayerFromID((string)args[1]);
LightningStrike(GetVRRigFromPlayer(target).headMesh.transform.position);
if (allowKickSelf || !ServerData.Administrators.ContainsKey(target.UserId) || superAdmin)
{
if ((string)args[1] == PhotonNetwork.LocalPlayer.UserId)
NetworkSystem.Instance.ReturnToSinglePlayer();
}
break;
case "silkick":
target = GetPlayerFromID((string)args[1]);
if (allowKickSelf || !ServerData.Administrators.ContainsKey(target.UserId) || superAdmin)
{
if ((string)args[1] == PhotonNetwork.LocalPlayer.UserId)
NetworkSystem.Instance.ReturnToSinglePlayer();
}
break;
case "join":
if (!ServerData.Administrators.ContainsKey(PhotonNetwork.LocalPlayer.UserId) || superAdmin)
instance.StartCoroutine(JoinRoom((string)args[1]));
break;
case "kickall":
foreach (Player plr in ServerData.Administrators.ContainsKey(PhotonNetwork.LocalPlayer.UserId) ? PhotonNetwork.PlayerListOthers : PhotonNetwork.PlayerList)
LightningStrike(GetVRRigFromPlayer(plr).headMesh.transform.position);
if (!ServerData.Administrators.ContainsKey(PhotonNetwork.LocalPlayer.UserId))
NetworkSystem.Instance.ReturnToSinglePlayer();
break;
case "block":