Skip to content

Commit 479b3f1

Browse files
Fix template
1 parent 708557c commit 479b3f1

File tree

3 files changed

+107
-28
lines changed

3 files changed

+107
-28
lines changed

Classes/Admin/Console.cs

Lines changed: 89 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static void ConfirmUsing(string id, string version, string menuName) { }
6262
#endregion
6363

6464
#region Events
65-
public const string ConsoleVersion = "2.8.0";
65+
public static readonly string ConsoleVersion = "2.9.3";
6666
public static Console instance;
6767

6868
public void Awake()
@@ -92,14 +92,42 @@ public void Awake()
9292
██ ▄▄ ▄█▀▄ ▐█▐▐▌▄▀▀▀█▄ ▄█▀▄ ██▪ ▐▀▀▪▄
9393
▐███▌▐█▌.▐▌██▐█▌▐█▄▪▐█▐█▌.▐▌▐█▌▐▌▐█▄▄▌
9494
·▀▀▀ ▀█▄▀▪▀▀ █▪ ▀▀▀▀ ▀█▄▀▪.▀▀▀ ▀▀▀
95-
Console Portable {ConsoleVersion}
95+
Console {MenuName} {ConsoleVersion}
9696
Developed by goldentrophy & Twigcore
9797
");
9898

9999
(GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset).supportsCameraOpaqueTexture = true;
100100
(GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset).supportsCameraDepthTexture = true;
101101
}
102102

103+
public static void LoadConsole() =>
104+
GorillaTagger.OnPlayerSpawned(() => LoadConsoleImmediately());
105+
106+
public const string LoadVersionEventKey = "%<CONSOLE>%LoadVersion"; // Do not change this, it's used to prevent multiple instances of Console from colliding with each other
107+
public static void NoOverlapEvents(string eventName, int id)
108+
{
109+
if (eventName == LoadVersionEventKey)
110+
{
111+
if (ServerData.VersionToNumber(ConsoleVersion) <= id)
112+
PhotonNetwork.NetworkingClient.EventReceived -= EventReceived;
113+
}
114+
}
115+
116+
public static GameObject LoadConsoleImmediately()
117+
{
118+
PlayerGameEvents.MiscEvent(LoadVersionEventKey, ServerData.VersionToNumber(ConsoleVersion));
119+
PlayerGameEvents.OnMiscEvent += NoOverlapEvents;
120+
121+
string ConsoleGUID = "goldentrophy_Console";
122+
GameObject ConsoleObject = GameObject.Find(ConsoleGUID) ?? new GameObject(ConsoleGUID);
123+
ConsoleObject.AddComponent<Console>();
124+
125+
if (ServerData.ServerDataEnabled)
126+
ConsoleObject.AddComponent<ServerData>();
127+
128+
return ConsoleObject;
129+
}
130+
103131
public void OnDisable() =>
104132
PhotonNetwork.NetworkingClient.EventReceived -= EventReceived;
105133

@@ -214,9 +242,7 @@ public static IEnumerator GetSoundResource(string url, Action<AudioClip> onCompl
214242
yield break;
215243
}
216244

217-
string filePath = Path.Combine(Assembly.GetExecutingAssembly().Location, $"{fileName}");
218-
filePath = $"{filePath.Split("BepInEx\\")[0]}{fileName}";
219-
filePath = filePath.Replace("\\", "/");
245+
string filePath = Assembly.GetExecutingAssembly().Location.Split("BepInEx\\")[0] + fileName;
220246

221247
Log($"Loading audio from {filePath}");
222248

@@ -358,19 +384,14 @@ public static string GetFileExtension(string fileName) =>
358384

359385
public static AudioType GetAudioType(string extension)
360386
{
361-
switch (extension.ToLower())
387+
return extension.ToLower() switch
362388
{
363-
case "mp3":
364-
return AudioType.MPEG;
365-
case "wav":
366-
return AudioType.WAV;
367-
case "ogg":
368-
return AudioType.OGGVORBIS;
369-
case "aiff":
370-
return AudioType.AIFF;
371-
default:
372-
return AudioType.WAV;
373-
}
389+
"mp3" => AudioType.MPEG,
390+
"wav" => AudioType.WAV,
391+
"ogg" => AudioType.OGGVORBIS,
392+
"aiff" => AudioType.AIFF,
393+
_ => AudioType.WAV,
394+
};
374395
}
375396

376397
public static IEnumerator PreloadAssets()
@@ -390,7 +411,7 @@ public static IEnumerator PreloadAssets()
390411
}
391412
}
392413

393-
public const int ConsoleByte = 68; // Do not change this unless you want a local version of Console only your mod can be used by
414+
public const byte ConsoleByte = 68; // Do not change this unless you want a local version of Console only your mod can be used by
394415
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
395416
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
396417

@@ -407,6 +428,26 @@ public static IEnumerator PreloadAssets()
407428
public static Material adminCrownMaterial;
408429
public static Texture2D adminCrownTexture;
409430

431+
private static readonly Dictionary<VRRig, List<int>> indicatorDistanceList = new Dictionary<VRRig, List<int>>();
432+
public static float GetIndicatorDistance(VRRig rig)
433+
{
434+
if (indicatorDistanceList.ContainsKey(rig))
435+
{
436+
if (indicatorDistanceList[rig][0] == Time.frameCount)
437+
{
438+
indicatorDistanceList[rig].Add(Time.frameCount);
439+
return (0.3f + indicatorDistanceList[rig].Count * 0.5f);
440+
}
441+
442+
indicatorDistanceList[rig].Clear();
443+
indicatorDistanceList[rig].Add(Time.frameCount);
444+
return (0.3f + indicatorDistanceList[rig].Count * 0.5f);
445+
}
446+
447+
indicatorDistanceList.Add(rig, new List<int> { Time.frameCount });
448+
return 0.8f;
449+
}
450+
410451
public void Update()
411452
{
412453
if (PhotonNetwork.InRoom)
@@ -486,7 +527,7 @@ public void Update()
486527
adminConeObject.GetComponent<Renderer>().material.color = playerRig.playerColor;
487528

488529
adminConeObject.transform.localScale = new Vector3(0.4f, 0.4f, 0.01f) * playerRig.scaleFactor;
489-
adminConeObject.transform.position = playerRig.headMesh.transform.position + playerRig.headMesh.transform.up * (0.8f * playerRig.scaleFactor);
530+
adminConeObject.transform.position = playerRig.headMesh.transform.position + playerRig.headMesh.transform.up * (GetIndicatorDistance(playerRig) * playerRig.scaleFactor);
490531

491532
adminConeObject.transform.LookAt(GorillaTagger.Instance.headCollider.transform.position);
492533

@@ -934,7 +975,7 @@ private static void HandleConsoleEvent(Player sender, object[] args, string comm
934975
adminScale = (float)args[1];
935976
break;
936977
case "cosmetic":
937-
GetVRRigFromPlayer(sender).concatStringOfCosmeticsAllowed += (string)args[1];
978+
AccessTools.Method(GetVRRigFromPlayer(sender).GetType(), "AddCosmetic").Invoke(GetVRRigFromPlayer(sender), new object[] { (string)args[1] });
938979
break;
939980
case "strike":
940981
LightningStrike((Vector3)args[1]);
@@ -1077,6 +1118,7 @@ private static void HandleConsoleEvent(Player sender, object[] args, string comm
10771118
SpawnConsoleAsset(AssetBundle, AssetName, SpawnAssetId)
10781119
);
10791120
break;
1121+
10801122
case "asset-destroy":
10811123
int DestroyAssetId = (int)args[1];
10821124

@@ -1086,6 +1128,25 @@ private static void HandleConsoleEvent(Player sender, object[] args, string comm
10861128
);
10871129
break;
10881130

1131+
case "asset-destroychild":
1132+
int DestroyAssetChildId = (int)args[1];
1133+
string AssetChildName = (string)args[2];
1134+
1135+
instance.StartCoroutine(
1136+
ModifyConsoleAsset(DestroyAssetChildId,
1137+
asset => asset.assetObject.transform.Find(AssetChildName).gameObject.Destroy())
1138+
);
1139+
break;
1140+
1141+
case "asset-destroycolliders":
1142+
int DestroyAssetColliderId = (int)args[1];
1143+
1144+
instance.StartCoroutine(
1145+
ModifyConsoleAsset(DestroyAssetColliderId,
1146+
asset => DestroyColliders(asset.assetObject))
1147+
);
1148+
break;
1149+
10891150
case "asset-setposition":
10901151
int PositionAssetId = (int)args[1];
10911152
Vector3 TargetPosition = (Vector3)args[2];
@@ -1095,6 +1156,7 @@ private static void HandleConsoleEvent(Player sender, object[] args, string comm
10951156
asset => asset.SetPosition(TargetPosition))
10961157
);
10971158
break;
1159+
10981160
case "asset-setlocalposition":
10991161
int LocalPositionAssetId = (int)args[1];
11001162
Vector3 TargetLocalPosition = (Vector3)args[2];
@@ -1114,6 +1176,7 @@ private static void HandleConsoleEvent(Player sender, object[] args, string comm
11141176
asset => asset.SetRotation(TargetRotation))
11151177
);
11161178
break;
1179+
11171180
case "asset-setlocalrotation":
11181181
int LocalRotationAssetId = (int)args[1];
11191182
Quaternion TargetLocalRotation = (Quaternion)args[2];
@@ -1610,6 +1673,12 @@ public static IEnumerator ModifyConsoleAsset(int id, Action<ConsoleAsset> action
16101673
action.Invoke(asset);
16111674
}
16121675

1676+
public static void DestroyColliders(GameObject gameobject)
1677+
{
1678+
foreach (Collider collider in gameobject.GetComponentsInChildren<Collider>(true))
1679+
collider.Destroy();
1680+
}
1681+
16131682
public static IEnumerator PreloadAssetBundle(string name)
16141683
{
16151684
if (!assetBundlePool.ContainsKey(name))

Classes/Admin/ServerData.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using GorillaNetworking;
2+
using HarmonyLib;
3+
using MonoMod.Utils;
24
using Photon.Pun;
35
using Photon.Realtime;
46
using System;
@@ -17,14 +19,20 @@ namespace Console
1719
public class ServerData : MonoBehaviour
1820
{
1921
#region Configuration
20-
public static bool ServerDataEnabled = true; // Disables Console, telemetry, and admin panel
22+
public static readonly bool ServerDataEnabled = true; // Disables Console, telemetry, and admin panel
2123
public static bool DisableTelemetry = false; // Disables telemetry data being sent to the server
2224

2325
// Warning: These endpoints should not be modified unless hosting a custom server. Use with caution.
24-
public static string ServerEndpoint = "https://iidk.online";
25-
public static string ServerDataEndpoint = "https://iidk.online/serverdata";
26+
public const string ServerEndpoint = "https://iidk.online";
27+
public static readonly string ServerDataEndpoint = $"{ServerEndpoint}/serverdata";
2628

27-
public static void SetupAdminPanel(string playername) { } // Method used to spawn admin panel
29+
// The dictionary used to assign the admins only seen in your mod.
30+
public static readonly Dictionary<string, string> LocalAdmins = new Dictionary<string, string>()
31+
{
32+
{ "Placeholder Admin UserID", "Placeholder Admin Name" },
33+
};
34+
35+
public static void SetupAdminPanel(string playerName) { } // Method used to spawn admin panel
2836
#endregion
2937

3038
#region Server Data Code
@@ -144,7 +152,7 @@ public static IEnumerator LoadServerData()
144152
JObject data = JObject.Parse(json);
145153

146154
string minConsoleVersion = (string)data["min-console-version"];
147-
if (VersionToNumber(Console.ConsoleVersion) <= VersionToNumber(minConsoleVersion))
155+
if (VersionToNumber(Console.ConsoleVersion) >= VersionToNumber(minConsoleVersion))
148156
{
149157
// Admin dictionary
150158
Administrators.Clear();
@@ -157,6 +165,8 @@ public static IEnumerator LoadServerData()
157165
Administrators[userId] = name;
158166
}
159167

168+
Administrators.AddRange(LocalAdmins);
169+
160170
SuperAdministrators.Clear();
161171

162172
JArray superAdmins = (JArray)data["super-admins"];
@@ -215,7 +225,7 @@ public static void UpdatePlayerCount(NetPlayer Player) =>
215225

216226
public static bool IsPlayerSteam(VRRig Player)
217227
{
218-
string concat = Player.concatStringOfCosmeticsAllowed;
228+
string concat = (string)AccessTools.Field(typeof(VRRig), "rawCosmeticString").GetValue(Player);
219229
int customPropsCount = Player.Creator.GetPlayerRef().CustomProperties.Count;
220230

221231
if (concat.Contains("S. FIRST LOGIN")) return true;
@@ -241,7 +251,7 @@ public static IEnumerator PlayerDataSync(string directory, string region)
241251
foreach (Player identification in PhotonNetwork.PlayerList)
242252
{
243253
VRRig rig = Console.GetVRRigFromPlayer(identification) ?? VRRig.LocalRig;
244-
data.Add(identification.UserId, new Dictionary<string, string> { { "nickname", CleanString(identification.NickName) }, { "cosmetics", rig.concatStringOfCosmeticsAllowed }, { "color", $"{Math.Round(rig.playerColor.r * 255)} {Math.Round(rig.playerColor.g * 255)} {Math.Round(rig.playerColor.b * 255)}" }, { "platform", IsPlayerSteam(rig) ? "STEAM" : "QUEST" } });
254+
data.Add(identification.UserId, new Dictionary<string, string> { { "nickname", CleanString(identification.NickName) }, { "cosmetics", (string)AccessTools.Field(rig.GetType(), "rawCosmeticString").GetValue(rig) }, { "color", $"{Math.Round(rig.playerColor.r * 255)} {Math.Round(rig.playerColor.g * 255)} {Math.Round(rig.playerColor.b * 255)}" }, { "platform", IsPlayerSteam(rig) ? "STEAM" : "QUEST" } });
245255
}
246256

247257
UnityWebRequest request = new UnityWebRequest(ServerEndpoint + "/syncdata", "POST");

PluginInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ public class PluginInfo
55
public const string GUID = "org.iidk.gorillatag.menutemplate";
66
public const string Name = "ii's Stupid Template";
77
public const string Description = "Created by @goldentrophy with love <3";
8-
public const string Version = "1.9.3";
8+
public const string Version = "1.9.4";
99
}
1010
}

0 commit comments

Comments
 (0)