From ef8d9dc0fdd654cce97877b6c39d66037412ea1d Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 28 Jul 2024 16:30:38 -0500 Subject: [PATCH] File Renames --- Modules/AntiCheat.cs | 52 +-- ...BAUDataManager.cs => BetterDataManager.cs} | 404 +++++++++--------- ...anager.cs => BetterNotificationManager.cs} | 204 ++++----- Modules/DebugMenu.cs | 4 +- Patches/ChatNotificationPatch.cs | 4 +- Patches/ClientOptionsPatch.cs | 6 +- Patches/HudManagerPatch.cs | 4 +- Patches/ModManagerPatch.cs | 2 +- 8 files changed, 340 insertions(+), 340 deletions(-) rename Modules/{BAUDataManager.cs => BetterDataManager.cs} (97%) rename Modules/{BAUNotificationManager.cs => BetterNotificationManager.cs} (93%) diff --git a/Modules/AntiCheat.cs b/Modules/AntiCheat.cs index 215e526..fa3c853 100644 --- a/Modules/AntiCheat.cs +++ b/Modules/AntiCheat.cs @@ -41,11 +41,11 @@ class AntiCheat if (reader.BytesRemaining == 0 && !flag) { AmongUsClient.Instance.ReportPlayer(player.GetClientId(), ReportReasons.Cheating_Hacking); - BAUNotificationManager.NotifyCheat(player, $"Sicko Menu", newText: "Has been detected with a cheat client"); + BetterNotificationManager.NotifyCheat(player, $"Sicko Menu", newText: "Has been detected with a cheat client"); PlayerData[Utils.GetHashPuid(player)] = player.FriendCode; SickoData[Utils.GetHashPuid(player)] = player.FriendCode; - BAUDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "cheatData", "Sicko Menu RPC"); - BAUDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "sickoData", "Sicko Menu RPC"); + BetterDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "cheatData", "Sicko Menu RPC"); + BetterDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "sickoData", "Sicko Menu RPC"); } } @@ -65,11 +65,11 @@ class AntiCheat if (!flag) { AmongUsClient.Instance.ReportPlayer(player.GetClientId(), ReportReasons.Cheating_Hacking); - BAUNotificationManager.NotifyCheat(player, $"AUM", newText: "Has been detected with a cheat client"); + BetterNotificationManager.NotifyCheat(player, $"AUM", newText: "Has been detected with a cheat client"); PlayerData[Utils.GetHashPuid(player)] = player.FriendCode; AUMData[Utils.GetHashPuid(player)] = player.FriendCode; - BAUDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "cheatData", "AUM RPC"); - BAUDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "aumData", "AUM RPC"); + BetterDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "cheatData", "AUM RPC"); + BetterDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "aumData", "AUM RPC"); } } } @@ -98,11 +98,11 @@ class AntiCheat if (!flag && !flag2) { AmongUsClient.Instance.ReportPlayer(player.GetClientId(), ReportReasons.Cheating_Hacking); - BAUNotificationManager.NotifyCheat(AUMPlayer, $"AUM", newText: "Has been detected with a cheat client"); + BetterNotificationManager.NotifyCheat(AUMPlayer, $"AUM", newText: "Has been detected with a cheat client"); PlayerData[Utils.GetHashPuid(AUMPlayer)] = AUMPlayer.FriendCode; AUMData[Utils.GetHashPuid(AUMPlayer)] = AUMPlayer.FriendCode; - BAUDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "cheatData", "AUM Chat RPC"); - BAUDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "aumData", "AUM Chat RPC"); + BetterDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "cheatData", "AUM Chat RPC"); + BetterDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "aumData", "AUM Chat RPC"); } } catch { } @@ -128,7 +128,7 @@ class AntiCheat if (callId is (byte)RpcCalls.EnterVent or (byte)RpcCalls.ExitVent) { if ((IsCrewmate && Role != RoleTypes.Engineer) || player.Data.IsDead) - BAUNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); return; } @@ -136,7 +136,7 @@ class AntiCheat if (callId is (byte)RpcCalls.ProtectPlayer) { if (Role is not RoleTypes.GuardianAngel) - BAUNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); return; } @@ -150,7 +150,7 @@ class AntiCheat if (target != null) { if (IsCrewmate || !player.IsAlive() || player.IsInVanish() || !target.IsAlive() || target.IsImpostorTeam()) - BAUNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); } } @@ -160,7 +160,7 @@ class AntiCheat if (callId is (byte)RpcCalls.SendChat or (byte)RpcCalls.SendQuickChat) { if (player.IsAlive() && GameStates.IsInGamePlay && !GameStates.IsMeeting && !GameStates.IsExilling) - BAUNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); return; } @@ -172,7 +172,7 @@ class AntiCheat uint level = reader.ReadPackedUInt32(); if (level >= 200) { - BAUNotificationManager.NotifyCheat(player, $"Invalid Level: {level}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Level: {level}"); } } @@ -186,7 +186,7 @@ class AntiCheat if (callId is (byte)RpcCalls.CloseDoorsOfType) { byte Type = reader.ReadByte(); - BAUNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)} - {Enum.GetName((SystemTypes)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)} - {Enum.GetName((SystemTypes)callId)}"); return; } @@ -200,7 +200,7 @@ class AntiCheat or (byte)SystemTypes.MushroomMixupSabotage or (byte)SystemTypes.HeliSabotage) { - BAUNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)} - {Enum.GetName((SystemTypes)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)} - {Enum.GetName((SystemTypes)callId)}"); } return; @@ -212,7 +212,7 @@ class AntiCheat { if (callId is (byte)RpcCalls.CompleteTask or (byte)RpcCalls.BootFromVent) { - BAUNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); return; } @@ -222,7 +222,7 @@ class AntiCheat { if (player?.CurrentOutfit?.PetId == "pet_EmptyPet") { - BAUNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); } return; @@ -248,7 +248,7 @@ class AntiCheat if (TrustedRPCs(callId) != true) { - BAUNotificationManager.NotifyCheat(player, $"Untrusted RPC received: {callId}"); + BetterNotificationManager.NotifyCheat(player, $"Untrusted RPC received: {callId}"); return false; } @@ -258,13 +258,13 @@ class AntiCheat if (Role is not RoleTypes.Shapeshifter || !player.IsAlive()) { - BAUNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); return false; } if (!flag && !player.IsInVent()) { - BAUNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); return false; } } @@ -273,7 +273,7 @@ class AntiCheat { if (Role is not RoleTypes.Phantom || player.Data.IsDead) { - BAUNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Action RPC: {Enum.GetName((RpcCalls)callId)}"); return false; } } @@ -284,7 +284,7 @@ class AntiCheat or (byte)RpcCalls.ExtendLobbyTimer or (byte)RpcCalls.CloseMeeting) { - BAUNotificationManager.NotifyCheat(player, $"Invalid Host RPC: {Enum.GetName((RpcCalls)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Host RPC: {Enum.GetName((RpcCalls)callId)}"); return false; } } @@ -293,7 +293,7 @@ class AntiCheat { if (callId is (byte)RpcCalls.SetName or (byte)RpcCalls.CheckName or (byte)RpcCalls.SetLevel) { - BAUNotificationManager.NotifyCheat(player, $"Invalid Set RPC: {Enum.GetName((RpcCalls)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Set RPC: {Enum.GetName((RpcCalls)callId)}"); return false; } } @@ -307,7 +307,7 @@ class AntiCheat or (byte)RpcCalls.SetPet or (byte)RpcCalls.SetNamePlate) { - BAUNotificationManager.NotifyCheat(player, $"Invalid Set RPC: {Enum.GetName((RpcCalls)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Set RPC: {Enum.GetName((RpcCalls)callId)}"); return false; } } @@ -341,7 +341,7 @@ class AntiCheat or (byte)RpcCalls.CheckAppear or (byte)RpcCalls.CheckVanish) { - BAUNotificationManager.NotifyCheat(player, $"Invalid Lobby RPC: {Enum.GetName((RpcCalls)callId)}"); + BetterNotificationManager.NotifyCheat(player, $"Invalid Lobby RPC: {Enum.GetName((RpcCalls)callId)}"); return false; } } diff --git a/Modules/BAUDataManager.cs b/Modules/BetterDataManager.cs similarity index 97% rename from Modules/BAUDataManager.cs rename to Modules/BetterDataManager.cs index ed58978..dcf12cb 100644 --- a/Modules/BAUDataManager.cs +++ b/Modules/BetterDataManager.cs @@ -1,202 +1,202 @@ -using System.Text.Json; - -namespace BetterAmongUs; - -class BAUDataManager -{ - public static string GetFilePath(string name) - { - return Path.Combine(Main.GetDataPathToAmongUs(), $"{name}.json"); - } - - public static void SetUp() - { - string filePath = GetFilePath("BetterData"); - - if (!File.Exists(filePath)) - { - // Initialize with predefined categories - var initialData = new Dictionary>> - { - { "Data", new Dictionary>() }, // Default category - { "cheatData", new Dictionary>() }, - { "sickoData", new Dictionary>() }, - { "aumData", new Dictionary>() } - }; - - string json = JsonSerializer.Serialize(initialData, new JsonSerializerOptions { WriteIndented = true }); - File.WriteAllText(filePath, json); - } - else - { - // Load the existing JSON data - string json = File.ReadAllText(filePath); - var jsonData = JsonSerializer.Deserialize>>>(json) ?? new Dictionary>>(); - - // Check and add missing categories - if (!jsonData.ContainsKey("Data")) - { - jsonData["Data"] = new Dictionary>(); - } - if (!jsonData.ContainsKey("cheatData")) - { - jsonData["cheatData"] = new Dictionary>(); - } - if (!jsonData.ContainsKey("sickoData")) - { - jsonData["sickoData"] = new Dictionary>(); - } - if (!jsonData.ContainsKey("aumData")) - { - jsonData["aumData"] = new Dictionary>(); - } - - // Write the updated JSON data back to the file - json = JsonSerializer.Serialize(jsonData, new JsonSerializerOptions { WriteIndented = true }); - File.WriteAllText(filePath, json); - } - } - - public static void Save(string name, string dataToSave, string category = "Data") - { - string filePath = GetFilePath("BetterData"); - - string json = File.ReadAllText(filePath); - var jsonData = JsonSerializer.Deserialize>>(json) ?? new Dictionary>(); - - if (!jsonData.ContainsKey(category)) - { - jsonData[category] = new Dictionary(); - } - - jsonData[category][name] = dataToSave; - - json = JsonSerializer.Serialize(jsonData, new JsonSerializerOptions { WriteIndented = true }); - File.WriteAllText(filePath, json); - } - - public static string Load(string name, string category = "Data") - { - try - { - string filePath = GetFilePath("BetterData"); - - string json = File.ReadAllText(filePath); - var jsonData = JsonSerializer.Deserialize>>(json); - - if (jsonData != null && jsonData.ContainsKey(category) && jsonData[category].ContainsKey(name)) - { - return jsonData[category][name]; - } - } - catch (Exception ex) - { - Logger.Error(ex.ToString()); - } - - return string.Empty; - } - - public static void SaveCheatData(string puid, string friendCode, string name, string category = "cheatData", string reason = "None") - { - string filePath = GetFilePath("BetterData"); - - string json = File.ReadAllText(filePath); - var jsonData = JsonSerializer.Deserialize>>>(json) ?? new Dictionary>>(); - - if (!jsonData.ContainsKey(category)) - { - jsonData[category] = new Dictionary>(); - } - - if (!jsonData[category].ContainsKey(name)) - { - jsonData[category][name] = new Dictionary(); - } - - jsonData[category][name]["FriendCode"] = friendCode; - jsonData[category][name]["HashPUID"] = puid; - jsonData[category][name]["Reason"] = reason; - - json = JsonSerializer.Serialize(jsonData, new JsonSerializerOptions { WriteIndented = true }); - File.WriteAllText(filePath, json); - } - - public static void ClearCheatData() - { - string filePath = GetFilePath("BetterData"); - string json = File.ReadAllText(filePath); - var jsonData = JsonSerializer.Deserialize>>>(json) - ?? new Dictionary>>(); - - // Clear in-save data - if (jsonData != null) - { - if (jsonData.ContainsKey("cheatData")) - { - jsonData["cheatData"].Clear(); - } - - if (jsonData.ContainsKey("sickoData")) - { - jsonData["sickoData"].Clear(); - } - - if (jsonData.ContainsKey("aumData")) - { - jsonData["aumData"].Clear(); - } - - json = JsonSerializer.Serialize(jsonData, new JsonSerializerOptions { WriteIndented = true }); - File.WriteAllText(filePath, json); - } - - // Clear in-memory data - AntiCheat.PlayerData.Clear(); - AntiCheat.SickoData.Clear(); - AntiCheat.AUMData.Clear(); - - Logger.LogCheat("Cleared cheat memory and data"); - } - - public static void LoadCheatData() - { - try - { - string filePath = GetFilePath("BetterData"); - string json = File.ReadAllText(filePath); - var jsonData = JsonSerializer.Deserialize>>>(json); - - if (jsonData != null) - { - if (jsonData.ContainsKey("cheatData")) - { - foreach (var item in jsonData["cheatData"]) - { - AntiCheat.PlayerData[item.Value["HashPUID"]] = item.Value["FriendCode"]; - } - } - - if (jsonData.ContainsKey("sickoData")) - { - foreach (var item in jsonData["sickoData"]) - { - AntiCheat.SickoData[item.Value["HashPUID"]] = item.Value["FriendCode"]; - } - } - - if (jsonData.ContainsKey("aumData")) - { - foreach (var item in jsonData["aumData"]) - { - AntiCheat.AUMData[item.Value["HashPUID"]] = item.Value["FriendCode"]; - } - } - } - } - catch (Exception ex) - { - Logger.Error(ex.ToString()); - } - } -} +using System.Text.Json; + +namespace BetterAmongUs; + +class BetterDataManager +{ + public static string GetFilePath(string name) + { + return Path.Combine(Main.GetDataPathToAmongUs(), $"{name}.json"); + } + + public static void SetUp() + { + string filePath = GetFilePath("BetterData"); + + if (!File.Exists(filePath)) + { + // Initialize with predefined categories + var initialData = new Dictionary>> + { + { "Data", new Dictionary>() }, // Default category + { "cheatData", new Dictionary>() }, + { "sickoData", new Dictionary>() }, + { "aumData", new Dictionary>() } + }; + + string json = JsonSerializer.Serialize(initialData, new JsonSerializerOptions { WriteIndented = true }); + File.WriteAllText(filePath, json); + } + else + { + // Load the existing JSON data + string json = File.ReadAllText(filePath); + var jsonData = JsonSerializer.Deserialize>>>(json) ?? new Dictionary>>(); + + // Check and add missing categories + if (!jsonData.ContainsKey("Data")) + { + jsonData["Data"] = new Dictionary>(); + } + if (!jsonData.ContainsKey("cheatData")) + { + jsonData["cheatData"] = new Dictionary>(); + } + if (!jsonData.ContainsKey("sickoData")) + { + jsonData["sickoData"] = new Dictionary>(); + } + if (!jsonData.ContainsKey("aumData")) + { + jsonData["aumData"] = new Dictionary>(); + } + + // Write the updated JSON data back to the file + json = JsonSerializer.Serialize(jsonData, new JsonSerializerOptions { WriteIndented = true }); + File.WriteAllText(filePath, json); + } + } + + public static void Save(string name, string dataToSave, string category = "Data") + { + string filePath = GetFilePath("BetterData"); + + string json = File.ReadAllText(filePath); + var jsonData = JsonSerializer.Deserialize>>(json) ?? new Dictionary>(); + + if (!jsonData.ContainsKey(category)) + { + jsonData[category] = new Dictionary(); + } + + jsonData[category][name] = dataToSave; + + json = JsonSerializer.Serialize(jsonData, new JsonSerializerOptions { WriteIndented = true }); + File.WriteAllText(filePath, json); + } + + public static string Load(string name, string category = "Data") + { + try + { + string filePath = GetFilePath("BetterData"); + + string json = File.ReadAllText(filePath); + var jsonData = JsonSerializer.Deserialize>>(json); + + if (jsonData != null && jsonData.ContainsKey(category) && jsonData[category].ContainsKey(name)) + { + return jsonData[category][name]; + } + } + catch (Exception ex) + { + Logger.Error(ex.ToString()); + } + + return string.Empty; + } + + public static void SaveCheatData(string puid, string friendCode, string name, string category = "cheatData", string reason = "None") + { + string filePath = GetFilePath("BetterData"); + + string json = File.ReadAllText(filePath); + var jsonData = JsonSerializer.Deserialize>>>(json) ?? new Dictionary>>(); + + if (!jsonData.ContainsKey(category)) + { + jsonData[category] = new Dictionary>(); + } + + if (!jsonData[category].ContainsKey(name)) + { + jsonData[category][name] = new Dictionary(); + } + + jsonData[category][name]["FriendCode"] = friendCode; + jsonData[category][name]["HashPUID"] = puid; + jsonData[category][name]["Reason"] = reason; + + json = JsonSerializer.Serialize(jsonData, new JsonSerializerOptions { WriteIndented = true }); + File.WriteAllText(filePath, json); + } + + public static void ClearCheatData() + { + string filePath = GetFilePath("BetterData"); + string json = File.ReadAllText(filePath); + var jsonData = JsonSerializer.Deserialize>>>(json) + ?? new Dictionary>>(); + + // Clear in-save data + if (jsonData != null) + { + if (jsonData.ContainsKey("cheatData")) + { + jsonData["cheatData"].Clear(); + } + + if (jsonData.ContainsKey("sickoData")) + { + jsonData["sickoData"].Clear(); + } + + if (jsonData.ContainsKey("aumData")) + { + jsonData["aumData"].Clear(); + } + + json = JsonSerializer.Serialize(jsonData, new JsonSerializerOptions { WriteIndented = true }); + File.WriteAllText(filePath, json); + } + + // Clear in-memory data + AntiCheat.PlayerData.Clear(); + AntiCheat.SickoData.Clear(); + AntiCheat.AUMData.Clear(); + + Logger.LogCheat("Cleared cheat memory and data"); + } + + public static void LoadCheatData() + { + try + { + string filePath = GetFilePath("BetterData"); + string json = File.ReadAllText(filePath); + var jsonData = JsonSerializer.Deserialize>>>(json); + + if (jsonData != null) + { + if (jsonData.ContainsKey("cheatData")) + { + foreach (var item in jsonData["cheatData"]) + { + AntiCheat.PlayerData[item.Value["HashPUID"]] = item.Value["FriendCode"]; + } + } + + if (jsonData.ContainsKey("sickoData")) + { + foreach (var item in jsonData["sickoData"]) + { + AntiCheat.SickoData[item.Value["HashPUID"]] = item.Value["FriendCode"]; + } + } + + if (jsonData.ContainsKey("aumData")) + { + foreach (var item in jsonData["aumData"]) + { + AntiCheat.AUMData[item.Value["HashPUID"]] = item.Value["FriendCode"]; + } + } + } + } + catch (Exception ex) + { + Logger.Error(ex.ToString()); + } + } +} diff --git a/Modules/BAUNotificationManager.cs b/Modules/BetterNotificationManager.cs similarity index 93% rename from Modules/BAUNotificationManager.cs rename to Modules/BetterNotificationManager.cs index d906021..fe37afe 100644 --- a/Modules/BAUNotificationManager.cs +++ b/Modules/BetterNotificationManager.cs @@ -1,102 +1,102 @@ -using TMPro; -using UnityEngine; - -namespace BetterAmongUs; - -class BAUNotificationManager -{ - public static GameObject BAUNotificationManagerObj; - private static Dictionary NotifyQueue = []; - private static float showTime = 0f; - private static Camera localCamera; - private static bool Notifying = false; - - public static void Notify(string text, float Time = 5f) - { - if (BAUNotificationManagerObj != null) - { - if (Notifying) - { - if (text == BAUNotificationManagerObj.transform.Find("Sizer/ChatText (TMP)").GetComponent().text) - return; - NotifyQueue[text] = Time; - return; - } - - showTime = Time; - BAUNotificationManagerObj.SetActive(true); - BAUNotificationManagerObj.transform.Find("Sizer/ChatText (TMP)").GetComponent().text = text; - SoundManager.Instance.PlaySound(DestroyableSingleton.Instance.TaskCompleteSound, false, 1f); - Notifying = true; - } - } - - public static void NotifyCheat(PlayerControl player, string reason, string newText = "", bool kickPlayer = true) - { - string text = $"Player: {player?.CurrentOutfit.PlayerName} Has been detected doing an unauthorized action: {reason}"; - if (newText != "") - text = $"Player: {player?.CurrentOutfit.PlayerName} " + newText + $": {reason}"; - - if (!AntiCheat.PlayerData.ContainsKey(Utils.GetHashPuid(player))) - { - AntiCheat.PlayerData[Utils.GetHashPuid(player)] = player.Data.FriendCode; - BAUDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "cheatData", reason); - Notify(text, Time: 8f); - } - - if (GameStates.IsHost && kickPlayer) - { - player.RpcSetName($"{player.Data.PlayerName} Has been banned by Anti-Cheat, Reason: {reason}"); - AmongUsClient.Instance.KickPlayer(player.GetClientId(), true); - } - - Logger.LogCheat(Utils.GetRawText(text)); - } - - public static void Update() - { - if (BAUNotificationManagerObj != null) - { - if (!localCamera) - { - if (DestroyableSingleton.InstanceExists) - { - localCamera = DestroyableSingleton.Instance.GetComponentInChildren(); - } - else - { - localCamera = Camera.main; - } - } - - BAUNotificationManagerObj.transform.position = AspectPosition.ComputeWorldPosition(localCamera, AspectPosition.EdgeAlignments.Bottom, new Vector3(-1.3f, 0.7f, localCamera.nearClipPlane + 0.1f)); - - showTime -= Time.deltaTime; - if (showTime <= 0f) - { - BAUNotificationManagerObj.transform.Find("Sizer/ChatText (TMP)").GetComponent().text = ""; - BAUNotificationManagerObj.SetActive(false); - Notifying = false; - - CheckNotifyQueue(); - } - - if (!GameStates.IsInGame) - { - BAUNotificationManagerObj.SetActive(false); - showTime = 0f; - } - } - } - - private static void CheckNotifyQueue() - { - if (NotifyQueue.Any()) - { - var key = NotifyQueue.Keys.First(); - var value = NotifyQueue[key]; - Notify(key, value); - NotifyQueue.Remove(key); - } - } -} +using TMPro; +using UnityEngine; + +namespace BetterAmongUs; + +class BetterNotificationManager +{ + public static GameObject BAUNotificationManagerObj; + private static Dictionary NotifyQueue = []; + private static float showTime = 0f; + private static Camera localCamera; + private static bool Notifying = false; + + public static void Notify(string text, float Time = 5f) + { + if (BAUNotificationManagerObj != null) + { + if (Notifying) + { + if (text == BAUNotificationManagerObj.transform.Find("Sizer/ChatText (TMP)").GetComponent().text) + return; + NotifyQueue[text] = Time; + return; + } + + showTime = Time; + BAUNotificationManagerObj.SetActive(true); + BAUNotificationManagerObj.transform.Find("Sizer/ChatText (TMP)").GetComponent().text = text; + SoundManager.Instance.PlaySound(DestroyableSingleton.Instance.TaskCompleteSound, false, 1f); + Notifying = true; + } + } + + public static void NotifyCheat(PlayerControl player, string reason, string newText = "", bool kickPlayer = true) + { + string text = $"Player: {player?.CurrentOutfit.PlayerName} Has been detected doing an unauthorized action: {reason}"; + if (newText != "") + text = $"Player: {player?.CurrentOutfit.PlayerName} " + newText + $": {reason}"; + + if (!AntiCheat.PlayerData.ContainsKey(Utils.GetHashPuid(player))) + { + AntiCheat.PlayerData[Utils.GetHashPuid(player)] = player.Data.FriendCode; + BetterDataManager.SaveCheatData(Utils.GetHashPuid(player), player.Data.FriendCode, player.Data.PlayerName, "cheatData", reason); + Notify(text, Time: 8f); + } + + if (GameStates.IsHost && kickPlayer) + { + player.RpcSetName($"{player.Data.PlayerName} Has been banned by Anti-Cheat, Reason: {reason}"); + AmongUsClient.Instance.KickPlayer(player.GetClientId(), true); + } + + Logger.LogCheat(Utils.GetRawText(text)); + } + + public static void Update() + { + if (BAUNotificationManagerObj != null) + { + if (!localCamera) + { + if (DestroyableSingleton.InstanceExists) + { + localCamera = DestroyableSingleton.Instance.GetComponentInChildren(); + } + else + { + localCamera = Camera.main; + } + } + + BAUNotificationManagerObj.transform.position = AspectPosition.ComputeWorldPosition(localCamera, AspectPosition.EdgeAlignments.Bottom, new Vector3(-1.3f, 0.7f, localCamera.nearClipPlane + 0.1f)); + + showTime -= Time.deltaTime; + if (showTime <= 0f) + { + BAUNotificationManagerObj.transform.Find("Sizer/ChatText (TMP)").GetComponent().text = ""; + BAUNotificationManagerObj.SetActive(false); + Notifying = false; + + CheckNotifyQueue(); + } + + if (!GameStates.IsInGame) + { + BAUNotificationManagerObj.SetActive(false); + showTime = 0f; + } + } + } + + private static void CheckNotifyQueue() + { + if (NotifyQueue.Any()) + { + var key = NotifyQueue.Keys.First(); + var value = NotifyQueue[key]; + Notify(key, value); + NotifyQueue.Remove(key); + } + } +} diff --git a/Modules/DebugMenu.cs b/Modules/DebugMenu.cs index 3ff28c4..7fda359 100644 --- a/Modules/DebugMenu.cs +++ b/Modules/DebugMenu.cs @@ -44,13 +44,13 @@ public class DebugMenu : MonoBehaviour { if (GameStates.IsInGame || GameStates.IsLobby || GameStates.IsFreePlay) { - BAUNotificationManager.NotifyCheat(PlayerControl.LocalPlayer, "Debug Test", kickPlayer: false); + BetterNotificationManager.NotifyCheat(PlayerControl.LocalPlayer, "Debug Test", kickPlayer: false); } }, true); AddButtonToTab(Main, "Clear Anti-Cheat Data", () => { - BAUDataManager.ClearCheatData(); + BetterDataManager.ClearCheatData(); }); AddButtonToTab(HostOnly, "Sync All Names", () => diff --git a/Patches/ChatNotificationPatch.cs b/Patches/ChatNotificationPatch.cs index e6fb7fa..2ab1ac1 100644 --- a/Patches/ChatNotificationPatch.cs +++ b/Patches/ChatNotificationPatch.cs @@ -11,7 +11,7 @@ public class ChatNotificationPatch [HarmonyPostfix] public static void Awake_Postfix(ChatNotification __instance) { - if (__instance.gameObject.name == "ChatNotification" && BAUNotificationManager.BAUNotificationManagerObj == null) + if (__instance.gameObject.name == "ChatNotification" && BetterNotificationManager.BAUNotificationManagerObj == null) { GameObject ChatNotifications = __instance.gameObject; if (ChatNotifications != null) @@ -25,7 +25,7 @@ public class ChatNotificationPatch GameObject.Find($"{BAUNotification.name}/Sizer/NameText").transform.localPosition = new Vector3(-3.3192f, -0.0105f); GameObject.Find($"{BAUNotification.name}/Sizer/NameText").GetComponent().text = "System Notification"; UnityEngine.Object.DontDestroyOnLoad(BAUNotification); - BAUNotificationManager.BAUNotificationManagerObj = BAUNotification; + BetterNotificationManager.BAUNotificationManagerObj = BAUNotification; BAUNotification.SetActive(false); } } diff --git a/Patches/ClientOptionsPatch.cs b/Patches/ClientOptionsPatch.cs index e21f26a..c9b56b1 100644 --- a/Patches/ClientOptionsPatch.cs +++ b/Patches/ClientOptionsPatch.cs @@ -25,7 +25,7 @@ public static class OptionsMenuBehaviourPatch { bool flag = GameStates.IsInGame && !GameStates.IsLobby || GameStates.IsFreePlay; if (flag) - BAUNotificationManager.Notify($"Unable to toggle {buttonName} while in game!", 2.5f); + BetterNotificationManager.Notify($"Unable to toggle {buttonName} while in game!", 2.5f); return flag; } @@ -84,11 +84,11 @@ public static class OptionsMenuBehaviourPatch DisableLobbyTheme = ClientOptionItem.Create("Open Save Data", null, __instance, OpenSaveDataButtonToggle, IsToggle: false); static void OpenSaveDataButtonToggle() { - if (File.Exists(BAUDataManager.GetFilePath("BetterData"))) + if (File.Exists(BetterDataManager.GetFilePath("BetterData"))) { System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() { - FileName = BAUDataManager.GetFilePath("BetterData"), + FileName = BetterDataManager.GetFilePath("BetterData"), UseShellExecute = true, Verb = "open" }); diff --git a/Patches/HudManagerPatch.cs b/Patches/HudManagerPatch.cs index a7855bd..21430de 100644 --- a/Patches/HudManagerPatch.cs +++ b/Patches/HudManagerPatch.cs @@ -21,7 +21,7 @@ public class HudManagerPatch { try { - if (BAUNotificationManager.BAUNotificationManagerObj == null) + if (BetterNotificationManager.BAUNotificationManagerObj == null) { bool ChatState = GameObject.Find("ChatUi"); __instance.Chat.gameObject.SetActive(true); @@ -34,7 +34,7 @@ public class HudManagerPatch if (!HasBeenWelcomed && GameStates.IsInGame && GameStates.IsLobby && !GameStates.IsFreePlay) { - BAUNotificationManager.Notify("Welcome To Better Among Us!", 8f); + BetterNotificationManager.Notify("Welcome To Better Among Us!", 8f); Utils.AddChatPrivate(WelcomeMessage, overrideName: " "); HasBeenWelcomed = true; diff --git a/Patches/ModManagerPatch.cs b/Patches/ModManagerPatch.cs index bf9c476..eb70a8c 100644 --- a/Patches/ModManagerPatch.cs +++ b/Patches/ModManagerPatch.cs @@ -17,6 +17,6 @@ public class ModManagerPatch FileChecker.UpdateUnauthorizedFiles(); LateTask.Update(Time.deltaTime); - BAUNotificationManager.Update(); + BetterNotificationManager.Update(); } }