using TMPro; using UnityEngine; namespace BetterAmongUs; class BetterNotificationManager { public static GameObject BAUNotificationManagerObj; public static Dictionary NotifyQueue = []; public static float showTime = 0f; private static Camera localCamera; public static bool Notifying = false; public static void Notify(string text, float Time = 5f) { if (!Main.BetterNotifications.Value) return; 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?.BetterData().RealName} Has been detected doing an unauthorized action: {reason}"; if (newText != "") text = $"Player: {player?.BetterData().RealName} " + 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?.BetterData().RealName, "cheatData", reason); Notify(text, Time: 8f); } Logger.LogCheat(Utils.RemoveHtmlText(text)); if (GameStates.IsHost && kickPlayer) { player.Kick(true, "{0} " + $"by Anti-Cheat!\n Reason: {reason}", true); } } 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 && GameStates.IsInGame) { 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); } } }