diff --git a/GameMode/AllInOneGameMode.cs b/GameMode/AllInOneGameMode.cs index d7a1d91da..2bcc1669d 100644 --- a/GameMode/AllInOneGameMode.cs +++ b/GameMode/AllInOneGameMode.cs @@ -103,7 +103,7 @@ public static class AllInOneGameMode [SuppressMessage("ReSharper", "UnusedMember.Local")] public static void Postfix(PlayerControl __instance) { - if (!AmongUsClient.Instance.AmHost || !GameStates.IsInTask || GameStates.IsEnded || Options.CurrentGameMode != CustomGameMode.AllInOne || Main.HasJustStarted || __instance.PlayerId == 255 || __instance.Is(CustomRoles.Killer) || CustomGameMode.HideAndSeek.IsActiveOrIntegrated()) return; + if (!AmongUsClient.Instance.AmHost || !GameStates.IsInTask || GameStates.IsEnded || Options.CurrentGameMode != CustomGameMode.AllInOne || Main.HasJustStarted || __instance.PlayerId >= 254 || __instance.Is(CustomRoles.Killer) || CustomGameMode.HideAndSeek.IsActiveOrIntegrated()) return; var gameModes = Enum.GetValues().Where(x => x.IsActiveOrIntegrated()).Split(x => x is CustomGameMode.CaptureTheFlag or CustomGameMode.FFA or CustomGameMode.SoloKombat); if (gameModes.TrueList.Count == 0 || gameModes.FalseList.Count == 0) return; diff --git a/GameMode/CaptureTheFlag.cs b/GameMode/CaptureTheFlag.cs index cd84b8327..45689d0de 100644 --- a/GameMode/CaptureTheFlag.cs +++ b/GameMode/CaptureTheFlag.cs @@ -593,7 +593,7 @@ public static class CaptureTheFlag [SuppressMessage("ReSharper", "UnusedMember.Local")] public static void Postfix(PlayerControl __instance) { - if (!AmongUsClient.Instance.AmHost || !GameStates.IsInTask || !CustomGameMode.CaptureTheFlag.IsActiveOrIntegrated() || Main.HasJustStarted || __instance.PlayerId == 255 || WinnerData.Team != "No one wins") return; + if (!AmongUsClient.Instance.AmHost || !GameStates.IsInTask || !CustomGameMode.CaptureTheFlag.IsActiveOrIntegrated() || Main.HasJustStarted || __instance.PlayerId >= 254 || WinnerData.Team != "No one wins") return; if (__instance.IsHost()) { diff --git a/GameMode/HotPotato.cs b/GameMode/HotPotato.cs index 4a72e6270..8ad722d90 100644 --- a/GameMode/HotPotato.cs +++ b/GameMode/HotPotato.cs @@ -82,7 +82,7 @@ internal static class HotPotato [SuppressMessage("ReSharper", "UnusedMember.Local")] public static void Postfix(PlayerControl __instance) { - if (!CustomGameMode.HotPotato.IsActiveOrIntegrated() || !Main.IntroDestroyed || !AmongUsClient.Instance.AmHost || !GameStates.IsInTask || __instance.PlayerId == 255) return; + if (!CustomGameMode.HotPotato.IsActiveOrIntegrated() || !Main.IntroDestroyed || !AmongUsClient.Instance.AmHost || !GameStates.IsInTask || __instance.PlayerId >= 254) return; PlayerControl Holder = Utils.GetPlayerById(HotPotatoState.HolderID); diff --git a/GameMode/MoveAndStop.cs b/GameMode/MoveAndStop.cs index b6f736019..b16ce8aaa 100644 --- a/GameMode/MoveAndStop.cs +++ b/GameMode/MoveAndStop.cs @@ -411,7 +411,7 @@ internal static class MoveAndStop [SuppressMessage("ReSharper", "UnusedMember.Local")] public static void Postfix(PlayerControl __instance) { - if (!GameStates.IsInTask || !CustomGameMode.MoveAndStop.IsActiveOrIntegrated() || !__instance.IsAlive() || !AmongUsClient.Instance.AmHost || !DoChecks || __instance.PlayerId == 255) return; + if (!GameStates.IsInTask || !CustomGameMode.MoveAndStop.IsActiveOrIntegrated() || !__instance.IsAlive() || !AmongUsClient.Instance.AmHost || !DoChecks || __instance.PlayerId >= 254) return; PlayerControl pc = __instance; long now = Utils.TimeStamp; diff --git a/GameMode/NaturalDisasters.cs b/GameMode/NaturalDisasters.cs index afe2b9564..751d298b9 100644 --- a/GameMode/NaturalDisasters.cs +++ b/GameMode/NaturalDisasters.cs @@ -195,7 +195,7 @@ public static class NaturalDisasters [SuppressMessage("ReSharper", "UnusedMember.Local")] public static void Postfix(PlayerControl __instance) { - if (!AmongUsClient.Instance.AmHost || !GameStates.IsInTask || !CustomGameMode.NaturalDisasters.IsActiveOrIntegrated() || Main.HasJustStarted || GameStartTimeStamp + 5 > Utils.TimeStamp || __instance.PlayerId == 255 || !__instance.IsHost()) return; + if (!AmongUsClient.Instance.AmHost || !GameStates.IsInTask || !CustomGameMode.NaturalDisasters.IsActiveOrIntegrated() || Main.HasJustStarted || GameStartTimeStamp + 5 > Utils.TimeStamp || __instance.PlayerId >= 254 || !__instance.IsHost()) return; UpdatePreparingDisasters(); diff --git a/GameMode/RoomRush.cs b/GameMode/RoomRush.cs index 846c904a7..8eab09ace 100644 --- a/GameMode/RoomRush.cs +++ b/GameMode/RoomRush.cs @@ -474,7 +474,7 @@ public static class RoomRush [SuppressMessage("ReSharper", "UnusedMember.Local")] public static void Postfix(PlayerControl __instance) { - if (!GameGoing || Main.HasJustStarted || !CustomGameMode.RoomRush.IsActiveOrIntegrated() || !AmongUsClient.Instance.AmHost || !GameStates.IsInTask || __instance.PlayerId == 255 || !__instance.IsHost()) return; + if (!GameGoing || Main.HasJustStarted || !CustomGameMode.RoomRush.IsActiveOrIntegrated() || !AmongUsClient.Instance.AmHost || !GameStates.IsInTask || __instance.PlayerId >= 254 || !__instance.IsHost()) return; long now = Utils.TimeStamp; PlayerControl[] aapc = Main.AllAlivePlayerControls; diff --git a/GameMode/Speedrun.cs b/GameMode/Speedrun.cs index 2af88095e..60ef0b920 100644 --- a/GameMode/Speedrun.cs +++ b/GameMode/Speedrun.cs @@ -164,7 +164,7 @@ public static class Speedrun [SuppressMessage("ReSharper", "UnusedMember.Local")] public static void Postfix(PlayerControl __instance) { - if (!AmongUsClient.Instance.AmHost || !GameStates.IsInTask || !CustomGameMode.Speedrun.IsActiveOrIntegrated() || Main.HasJustStarted || __instance.Is(CustomRoles.Killer) || __instance.PlayerId == 255) return; + if (!AmongUsClient.Instance.AmHost || !GameStates.IsInTask || !CustomGameMode.Speedrun.IsActiveOrIntegrated() || Main.HasJustStarted || __instance.Is(CustomRoles.Killer) || __instance.PlayerId >= 254) return; if (__instance.IsAlive() && Timers[__instance.PlayerId] <= 0) { diff --git a/Main.cs b/Main.cs index f3beafb0c..ed9cd2982 100644 --- a/Main.cs +++ b/Main.cs @@ -208,7 +208,7 @@ public class Main : BasePlugin foreach (PlayerControl pc in PlayerControl.AllPlayerControls) { - if (pc == null || pc.PlayerId == 255) continue; + if (pc == null || pc.PlayerId >= 254) continue; result[i++] = pc; } @@ -230,7 +230,7 @@ public class Main : BasePlugin foreach (PlayerControl pc in PlayerControl.AllPlayerControls) { - if (pc == null || pc.PlayerId == 255 || !pc.IsAlive() || pc.Data.Disconnected || Pelican.IsEaten(pc.PlayerId)) continue; + if (pc == null || pc.PlayerId >= 254 || !pc.IsAlive() || pc.Data.Disconnected || Pelican.IsEaten(pc.PlayerId)) continue; result[i++] = pc; } diff --git a/Modules/CustomNetObject.cs b/Modules/CustomNetObject.cs index 81c94f621..bbac68c3c 100644 --- a/Modules/CustomNetObject.cs +++ b/Modules/CustomNetObject.cs @@ -51,6 +51,7 @@ namespace EHR PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].SkinId = ""; PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].PetId = ""; PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].VisorId = ""; + NetworkedPlayerInfoSerializePatch.IgnorePatchTimes = 2; writer.StartMessage(1); { @@ -156,182 +157,6 @@ namespace EHR { if (!AmongUsClient.Instance.AmHost) return; - PlayerControlTimer += Time.fixedDeltaTime; - - if (PlayerControlTimer > 20f) - { - Logger.Info($" Recreate Custom Net Object {GetType().Name} (ID {Id})", "CNO.OnFixedUpdate"); - PlayerControl oldPlayerControl = playerControl; - playerControl = Object.Instantiate(AmongUsClient.Instance.PlayerPrefab, Vector2.zero, Quaternion.identity); - playerControl.PlayerId = 255; - playerControl.isNew = false; - playerControl.notRealPlayer = true; - AmongUsClient.Instance.NetIdCnt += 1U; - MessageWriter msg = MessageWriter.Get(); - msg.StartMessage(5); - msg.Write(AmongUsClient.Instance.GameId); - AmongUsClient.Instance.WriteSpawnMessage(playerControl, -2, SpawnFlags.None, msg); - msg.EndMessage(); - - if (GameStates.CurrentServerType == GameStates.ServerType.Vanilla) - { - msg.StartMessage(6); - msg.Write(AmongUsClient.Instance.GameId); - msg.WritePacked(int.MaxValue); - - for (uint i = 1; i <= 3; ++i) - { - msg.StartMessage(4); - msg.WritePacked(2U); - msg.WritePacked(-2); - msg.Write((byte)SpawnFlags.None); - msg.WritePacked(1); - msg.WritePacked(AmongUsClient.Instance.NetIdCnt - i); - msg.StartMessage(1); - msg.EndMessage(); - msg.EndMessage(); - } - - msg.EndMessage(); - } - AmongUsClient.Instance.SendOrDisconnect(msg); - msg.Recycle(); - - if (PlayerControl.AllPlayerControls.Contains(playerControl)) - PlayerControl.AllPlayerControls.Remove(playerControl); - - LateTask.New(() => - { - playerControl.NetTransform.RpcSnapTo(Position); - playerControl.RawSetName(Sprite); - string name = PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].PlayerName; - int colorId = PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].ColorId; - string hatId = PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].HatId; - string skinId = PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].SkinId; - string petId = PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].PetId; - string visorId = PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].VisorId; - var sender = CustomRpcSender.Create("SetFakeData", SendOption.Reliable); - MessageWriter writer = sender.stream; - sender.StartMessage(); - PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].PlayerName = "
" + Sprite; - PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].ColorId = 255; - PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].HatId = ""; - PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].SkinId = ""; - PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].PetId = ""; - PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].VisorId = ""; - writer.StartMessage(1); - - { - writer.WritePacked(PlayerControl.LocalPlayer.Data.NetId); - PlayerControl.LocalPlayer.Data.Serialize(writer, false); - } - - writer.EndMessage(); - - sender.StartRpc(playerControl.NetId, (byte)RpcCalls.Shapeshift) - .WriteNetObject(PlayerControl.LocalPlayer) - .Write(false) - .EndRpc(); - - PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].PlayerName = name; - PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].ColorId = colorId; - PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].HatId = hatId; - PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].SkinId = skinId; - PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].PetId = petId; - PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].VisorId = visorId; - writer.StartMessage(1); - - { - writer.WritePacked(PlayerControl.LocalPlayer.Data.NetId); - PlayerControl.LocalPlayer.Data.Serialize(writer, false); - } - - writer.EndMessage(); - sender.EndMessage(); - sender.SendMessage(); - }, 0.2f); - - LateTask.New(() => oldPlayerControl.Despawn(), 0.3f); - - //playerControl.cosmetics.currentBodySprite.BodySprite.color = Color.clear; - //playerControl.cosmetics.colorBlindText.color = Color.clear; - foreach (PlayerControl pc in Main.AllPlayerControls) - { - if (pc.AmOwner) continue; - - LateTask.New(() => - { - var sender = CustomRpcSender.Create("SetFakeData", SendOption.Reliable); - MessageWriter writer = sender.stream; - sender.StartMessage(pc.GetClientId()); - writer.StartMessage(1); - - { - writer.WritePacked(playerControl.NetId); - writer.Write(pc.PlayerId); - } - - writer.EndMessage(); - - sender.StartRpc(playerControl.NetId, (byte)RpcCalls.MurderPlayer) - .WriteNetObject(playerControl) - .Write((int)MurderResultFlags.FailedError) - .EndRpc(); - - writer.StartMessage(1); - - { - writer.WritePacked(playerControl.NetId); - writer.Write((byte)255); - } - - writer.EndMessage(); - sender.EndMessage(); - sender.SendMessage(); - }, 0.1f); - } - - foreach (PlayerControl pc in Main.AllPlayerControls) - if (HiddenList.Contains(pc.PlayerId)) - Hide(pc); - - LateTask.New(() => - { - // Fix for Host - if (!HiddenList.Contains(PlayerControl.LocalPlayer.PlayerId)) - playerControl.transform.FindChild("Names").FindChild("NameText_TMP").gameObject.SetActive(true); - }, 0.1f); - - LateTask.New(() => - { - // Fix for Non-Host Modded - foreach (PlayerControl visiblePC in Main.AllPlayerControls.ExceptBy(HiddenList, x => x.PlayerId)) - { - var sender = CustomRpcSender.Create("FixModdedClientCNOText", SendOption.Reliable); - - sender.AutoStartRpc(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.FixModdedClientCNO, visiblePC.GetClientId()) - .WriteNetObject(playerControl) - .Write(true) - .EndRpc(); - - sender.SendMessage(); - } - }, 0.4f); - - /* - if (this is TrapArea trapArea) - { - foreach (var pc in PlayerControl.AllPlayerControls) - { - if (!trapArea.VisibleList.Contains(pc.PlayerId)) - Hide(pc); - } - } - */ - PlayerControlTimer = 0f; - return; - } - var nt = playerControl.NetTransform; if (nt == null) return; @@ -358,7 +183,7 @@ namespace EHR if (GameStates.IsEnded || GameStates.CurrentServerType == GameStates.ServerType.ModdedWithoutCNOSupport || !AmongUsClient.Instance.AmHost) return; Logger.Info($" Create Custom Net Object {GetType().Name} (ID {MaxId + 1}) at {position}", "CNO.CreateNetObject"); playerControl = Object.Instantiate(AmongUsClient.Instance.PlayerPrefab, Vector2.zero, Quaternion.identity); - playerControl.PlayerId = 255; + playerControl.PlayerId = 254; playerControl.isNew = false; playerControl.notRealPlayer = true; AmongUsClient.Instance.NetIdCnt += 1U; @@ -367,24 +192,28 @@ namespace EHR msg.Write(AmongUsClient.Instance.GameId); AmongUsClient.Instance.WriteSpawnMessage(playerControl, -2, SpawnFlags.None, msg); msg.EndMessage(); - msg.StartMessage(6); - msg.Write(AmongUsClient.Instance.GameId); - msg.WritePacked(int.MaxValue); - for (uint i = 1; i <= 3; ++i) + if (GameStates.CurrentServerType == GameStates.ServerType.Vanilla) { - msg.StartMessage(4); - msg.WritePacked(2U); - msg.WritePacked(-2); - msg.Write((byte)SpawnFlags.None); - msg.WritePacked(1); - msg.WritePacked(AmongUsClient.Instance.NetIdCnt - i); - msg.StartMessage(1); - msg.EndMessage(); + msg.StartMessage(6); + msg.Write(AmongUsClient.Instance.GameId); + msg.WritePacked(int.MaxValue); + + for (uint i = 1; i <= 3; ++i) + { + msg.StartMessage(4); + msg.WritePacked(2U); + msg.WritePacked(-2); + msg.Write((byte)SpawnFlags.None); + msg.WritePacked(1); + msg.WritePacked(AmongUsClient.Instance.NetIdCnt - i); + msg.StartMessage(1); + msg.EndMessage(); + msg.EndMessage(); + } + msg.EndMessage(); } - - msg.EndMessage(); AmongUsClient.Instance.SendOrDisconnect(msg); msg.Recycle(); if (PlayerControl.AllPlayerControls.Contains(playerControl)) PlayerControl.AllPlayerControls.Remove(playerControl); @@ -408,6 +237,7 @@ namespace EHR PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].SkinId = ""; PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].PetId = ""; PlayerControl.LocalPlayer.Data.Outfits[PlayerOutfitType.Default].VisorId = ""; + NetworkedPlayerInfoSerializePatch.IgnorePatchTimes = 2; writer.StartMessage(1); { @@ -478,7 +308,7 @@ namespace EHR { writer.WritePacked(playerControl.NetId); - writer.Write((byte)255); + writer.Write((byte)254); } writer.EndMessage(); @@ -489,6 +319,8 @@ namespace EHR LateTask.New(() => playerControl.transform.FindChild("Names").FindChild("NameText_TMP").gameObject.SetActive(true), 0.1f); // Fix for Host LateTask.New(() => Utils.SendRPC(CustomRPC.FixModdedClientCNO, playerControl), 0.4f); // Fix for Non-Host Modded + + LateTask.New(() => RpcChangeSprite(sprite), 0.4f); } public static void FixedUpdate() diff --git a/Modules/EAC.cs b/Modules/EAC.cs index 6d853cd5b..b95dbffdd 100644 --- a/Modules/EAC.cs +++ b/Modules/EAC.cs @@ -773,7 +773,7 @@ internal static class CheckInvalidMovementPatch public static void Postfix(PlayerControl __instance) { - if (!GameStates.IsInTask || ExileController.Instance || !Options.EnableMovementChecking.GetBool() || Main.HasJustStarted || MeetingStates.FirstMeeting || Main.RealOptionsData.GetFloat(FloatOptionNames.PlayerSpeedMod) >= 1.9f || AmongUsClient.Instance.Ping >= 300 || CustomGameMode.NaturalDisasters.IsActiveOrIntegrated() || Utils.GetRegionName() is not ("EU" or "NA" or "AS") || __instance == null || __instance.PlayerId == 255 || !__instance.IsAlive() || __instance.inVent) return; + if (!GameStates.IsInTask || ExileController.Instance || !Options.EnableMovementChecking.GetBool() || Main.HasJustStarted || MeetingStates.FirstMeeting || Main.RealOptionsData.GetFloat(FloatOptionNames.PlayerSpeedMod) >= 1.9f || AmongUsClient.Instance.Ping >= 300 || CustomGameMode.NaturalDisasters.IsActiveOrIntegrated() || Utils.GetRegionName() is not ("EU" or "NA" or "AS") || __instance == null || __instance.PlayerId >= 254 || !__instance.IsAlive() || __instance.inVent) return; Vector2 pos = __instance.Pos(); long now = Utils.TimeStamp; diff --git a/Modules/Utils.cs b/Modules/Utils.cs index 130ed7e09..9d1251b62 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -1334,13 +1334,13 @@ public static class Utils } } - SendMessage(sb.Append("\n.").ToString(), PlayerId, GetString("GMRoles")); - SendMessage(impsb.Append("\n.").ToString(), PlayerId, ColorString(GetRoleColor(CustomRoles.Impostor), GetString("ImpostorRoles"))); - SendMessage(crewsb.Append("\n.").ToString(), PlayerId, ColorString(GetRoleColor(CustomRoles.Crewmate), GetString("CrewmateRoles"))); - SendMessage(neutralsb.Append("\n.").ToString(), PlayerId, GetString("NeutralRoles")); - SendMessage(covensb.Append("\n.").ToString(), PlayerId, GetString("CovenRoles")); - SendMessage(ghostsb.Append("\n.").ToString(), PlayerId, GetString("GhostRoles")); - SendMessage(addonsb.Append("\n.").ToString(), PlayerId, GetString("AddonRoles")); + SendMessage($"{sb.Append("\n.").ToString().RemoveHtmlTags()}", PlayerId, GetString("GMRoles")); + SendMessage($"{impsb.Append("\n.").ToString().RemoveHtmlTags()}", PlayerId, ColorString(GetRoleColor(CustomRoles.Impostor), GetString("ImpostorRoles"))); + SendMessage($"{crewsb.Append("\n.").ToString().RemoveHtmlTags()}", PlayerId, ColorString(GetRoleColor(CustomRoles.Crewmate), GetString("CrewmateRoles"))); + SendMessage($"{neutralsb.Append("\n.").ToString().RemoveHtmlTags()}", PlayerId, GetString("NeutralRoles")); + SendMessage($"{covensb.Append("\n.").ToString().RemoveHtmlTags()}", PlayerId, GetString("CovenRoles")); + SendMessage($"{ghostsb.Append("\n.").ToString().RemoveHtmlTags()}", PlayerId, GetString("GhostRoles")); + SendMessage($"{addonsb.Append("\n.").ToString().RemoveHtmlTags()}", PlayerId, GetString("AddonRoles")); } public static void ShowChildrenSettings(OptionItem option, ref StringBuilder sb, int deep = 0, bool f1 = false, bool disableColor = true) @@ -1632,7 +1632,7 @@ public static class Utils public static void ShowHelp(byte ID) { PlayerControl player = GetPlayerById(ID); - SendMessage(ChatCommands.AllCommands.Where(x => x.CanUseCommand(player, false) && !x.CommandForms.Contains("help")).Aggregate("", (s, c) => s + $"\n/{c.CommandForms.TakeWhile(f => f.All(char.IsAscii)).MinBy(f => f.Length)}{(c.Arguments.Length == 0 ? string.Empty : $" {c.Arguments.Split(' ').Select((x, i) => ColorString(GetColor(i), x)).Join(delimiter: " ")}")} \u2192 {c.Description}"), ID, GetString("CommandList")); + SendMessage(ChatCommands.AllCommands.Where(x => x.CanUseCommand(player, false) && !x.CommandForms.Contains("help")).Aggregate("", (s, c) => s + $"\n/{c.CommandForms.TakeWhile(f => f.All(char.IsAscii)).MinBy(f => f.Length)}{(c.Arguments.Length == 0 ? string.Empty : $" {c.Arguments.Split(' ').Select((x, i) => ID == 0 ? ColorString(GetColor(i), x) : x).Join(delimiter: " ")}")} \u2192 {c.Description}"), ID, GetString("CommandList")); return; Color GetColor(int i) @@ -1641,14 +1641,14 @@ public static class Utils { 0 => Palette.Orange, 1 => Color.magenta, - 2 => Color.blue, + 2 => ID == 0 && Main.DarkTheme.Value ? Color.yellow : Color.blue, 3 => Color.red, - 4 => Palette.Brown, - 5 => Color.cyan, - 6 => Color.green, + 4 => Color.cyan, + 5 => Color.green, + 6 => Palette.Brown, 7 => Palette.Purple, - _ => Color.yellow + _ => Color.white }; } } @@ -1755,7 +1755,7 @@ public static class Utils } } - const int sizeLimit = 1000; + const int sizeLimit = 600; if (text.Length >= sizeLimit && !noSplit) { @@ -3109,7 +3109,7 @@ public static class Utils Logger.Exception(ex, "AfterPlayerDeathTasks"); } - if (Main.DiedThisRound.Contains(target.PlayerId) && IsRevivingRoleAlive()) return; + if (Main.DiedThisRound.Contains(target.PlayerId) && IsRevivingRoleAlive() || Options.CurrentGameMode != CustomGameMode.Standard) return; var killer = target.GetRealKiller(); if (killer != null) target.Notify($"<#ffffff>{string.Format(GetString("DeathCommand"), killer.PlayerId.ColoredPlayerName(), (killer.Is(CustomRoles.Bloodlust) ? $"{CustomRoles.Bloodlust.ToColoredString()} " : string.Empty) + killer.GetCustomRole().ToColoredString())}", 10f); diff --git a/Patches/ChatCommandPatch.cs b/Patches/ChatCommandPatch.cs index e9e15c1bf..904c8f981 100644 --- a/Patches/ChatCommandPatch.cs +++ b/Patches/ChatCommandPatch.cs @@ -1616,7 +1616,11 @@ internal static class ChatCommands if (player.PlayerId != PlayerControl.LocalPlayer.PlayerId) ChatManager.SendPreviousMessagesToAll(); - LateTask.New(() => Utils.GetPlayerById(vl2.Target)?.RpcSendChat(text[6..]), 0.2f, log: false); + var tg = Utils.GetPlayerById(vl2.Target); + var msg = text[6..]; + LateTask.New(() => tg?.RpcSendChat(msg), 0.2f, log: false); + ChatManager.AddChatHistory(tg, msg); + player.RpcRemoveAbilityUse(); } diff --git a/Patches/ChatControlPatch.cs b/Patches/ChatControlPatch.cs index 1d284d6b1..f793021f3 100644 --- a/Patches/ChatControlPatch.cs +++ b/Patches/ChatControlPatch.cs @@ -161,6 +161,7 @@ public static class ChatManager public static void SendMessage(PlayerControl player, string message) { string playername = player.GetNameWithRole(); + string originalMessage = message.Trim(); message = message.ToLower().Trim(); if (!player.IsAlive() || !AmongUsClient.Instance.AmHost || (Silencer.ForSilencer.Contains(player.PlayerId) && player.IsAlive())) return; @@ -196,9 +197,7 @@ public static class ChatManager Logger.Info($"Command: {message}", "ChatManager"); break; case 3: // In Lobby & Evertything Else - var chatEntry = $"{player.PlayerId}: {message}"; - ChatHistory.Add(chatEntry); - if (ChatHistory.Count > MaxHistorySize) ChatHistory.RemoveAt(0); + AddChatHistory(player, originalMessage); break; } @@ -209,6 +208,13 @@ public static class ChatManager Banshee.OnReceiveChat(); } + public static void AddChatHistory(PlayerControl player, string message) + { + var chatEntry = $"{player.PlayerId}: {message}"; + ChatHistory.Add(chatEntry); + if (ChatHistory.Count > MaxHistorySize) ChatHistory.RemoveAt(0); + } + public static void SendPreviousMessagesToAll(bool clear = false) { if (!AmongUsClient.Instance.AmHost) return; diff --git a/Patches/ClientPatch.cs b/Patches/ClientPatch.cs index d75380cc4..1ba530b99 100644 --- a/Patches/ClientPatch.cs +++ b/Patches/ClientPatch.cs @@ -373,8 +373,11 @@ internal static class DirtyAllDataPatch [HarmonyPatch(typeof(NetworkedPlayerInfo), nameof(NetworkedPlayerInfo.Serialize))] internal static class NetworkedPlayerInfoSerializePatch { + public static int IgnorePatchTimes; public static bool Prefix(NetworkedPlayerInfo __instance, MessageWriter writer, bool initialState, ref bool __result) { + if (IgnorePatchTimes-- > 0) return true; + writer.Write(__instance.PlayerId); writer.WritePacked(__instance.ClientId); writer.Write((byte)__instance.Outfits.Count); diff --git a/Patches/GameOptionsMenuPatch.cs b/Patches/GameOptionsMenuPatch.cs index 79449dc64..1e9c0557e 100644 --- a/Patches/GameOptionsMenuPatch.cs +++ b/Patches/GameOptionsMenuPatch.cs @@ -408,25 +408,32 @@ public static class GameOptionsMenuPatch return baseGameSetting; } + // From MoreGamemodes, by Rabek009 public static void ReloadUI(int index) { UIReloadTS = Utils.TimeStamp; - GameSettingMenu.Instance?.Close(); - - LateTask.New(() => + var tab = ModGameOptionsMenu.TabIndex; + if (GameSettingMenu.Instance == null) return; + GameSettingMenu.Instance.Close(); + OptionsConsole optionsConsole = null; + foreach (var console in Object.FindObjectsOfType()) { - if (GameStates.IsLobby) GameObject.Find("Host Buttons")?.transform.FindChild("Edit")?.GetComponent()?.ReceiveClickDown(); - }, 0.1f, log: false); + if (console.HostOnly) + optionsConsole = console; + } + if (optionsConsole == null) return; - LateTask.New(() => + if (Camera.main != null) { - if (GameStates.IsLobby) - { - GameSettingMenu.Instance?.ChangeTab(index, Controller.currentTouchType == Controller.TouchType.Joystick); - ModGameOptionsMenu.TabIndex = index; - } - }, 0.38f, log: false); + GameObject gameObject = Object.Instantiate(optionsConsole.MenuPrefab, Camera.main.transform, false); + gameObject.transform.localPosition = optionsConsole.CustomPosition; + } + + LateTask.New(() => { + if (GameSettingMenu.Instance == null) return; + GameSettingMenu.Instance.ChangeTab(tab, false); + }, 0.01f); } } diff --git a/Patches/OnGameStartedPatch.cs b/Patches/OnGameStartedPatch.cs index c2169f44f..66ce801e5 100644 --- a/Patches/OnGameStartedPatch.cs +++ b/Patches/OnGameStartedPatch.cs @@ -572,9 +572,9 @@ internal static class StartGameHostPatch try { - if ((totalSeconds > 1.0) && (totalSeconds < (double)num)) + if (totalSeconds < (double)num) { - loadingBarManager.SetLoadingPercent(5 + (float)(totalSeconds / (double)num * 60.0), StringNames.LoadingBarGameStartWaitingPlayers); + loadingBarManager.SetLoadingPercent(5 + (float)(totalSeconds / (double)num * 55.0), StringNames.LoadingBarGameStartWaitingPlayers); int timeoutIn = num - (int)totalSeconds; loadingBarManager.loadingBar.loadingText.text = string.Format(GetString("LoadingBarText.2"), clientsReady, allClientsCount, timeoutIn); @@ -589,7 +589,7 @@ internal static class StartGameHostPatch } AUClient.SendClientReady(); - yield return loadingBarManager.WaitAndSmoothlyUpdate(65f, 70f, 2f, GetString("LoadingBarText.3")); + yield return loadingBarManager.WaitAndSmoothlyUpdate(60f, 65f, 2f, GetString("LoadingBarText.3")); yield return AssignRoles(); } @@ -757,7 +757,7 @@ internal static class StartGameHostPatch try { - loadingBarManager.SetLoadingPercent(80f, StringNames.LoadingBarGameStart); + loadingBarManager.SetLoadingPercent(75f, StringNames.LoadingBarGameStart); loadingBarManager.loadingBar.loadingText.text = GetString("LoadingBarText.4"); } catch (Exception e) { Utils.ThrowException(e); } @@ -1015,13 +1015,13 @@ internal static class StartGameHostPatch } Logger.Info("Others assign finished", "AssignRoleTypes"); - yield return loadingBarManager.WaitAndSmoothlyUpdate(80f, 85f, 1f, GetString("LoadingBarText.4")); + yield return loadingBarManager.WaitAndSmoothlyUpdate(75f, 80f, 1f, GetString("LoadingBarText.4")); Logger.Info("Send rpc disconnected for all", "AssignRoleTypes"); DataDisconnected.Clear(); RpcSetDisconnected(true); - yield return loadingBarManager.WaitAndSmoothlyUpdate(85f, 100f, 4f, GetString("LoadingBarText.5")); + yield return loadingBarManager.WaitAndSmoothlyUpdate(80f, 100f, 4f, GetString("LoadingBarText.5")); Logger.Info("Assign self", "AssignRoleTypes"); SetRoleSelf(); @@ -1462,7 +1462,7 @@ internal static class StartGameHostPatch if (Senders == null) yield break; LoadingBarManager loadingBarManager = FastDestroyableSingleton.Instance; - float step = (80f - 70f) / Senders.Count; + float step = (75f - 65f) / Senders.Count; int index = 0; foreach (CustomRpcSender sender in Senders.Values) @@ -1471,7 +1471,7 @@ internal static class StartGameHostPatch catch (Exception e) { Utils.ThrowException(e); } index++; - yield return loadingBarManager.WaitAndSmoothlyUpdate(70f + (step * (index - 1)), 70f + (step * index), 0.3f, GetString("LoadingBarText.4")); + yield return loadingBarManager.WaitAndSmoothlyUpdate(65f + (step * (index - 1)), 65f + (step * index), 0.3f, GetString("LoadingBarText.4")); } } diff --git a/Patches/PlayerControlPatch.cs b/Patches/PlayerControlPatch.cs index e9eb6558e..d28acc7c6 100644 --- a/Patches/PlayerControlPatch.cs +++ b/Patches/PlayerControlPatch.cs @@ -620,7 +620,7 @@ internal static class MurderPlayerPatch public static void Postfix(PlayerControl __instance, [HarmonyArgument(0)] PlayerControl target, bool __state) { - if (__instance == null || target == null || __instance.PlayerId == 255 || target.PlayerId == 255 || !__state) return; + if (__instance == null || target == null || __instance.PlayerId >= 254 || target.PlayerId >= 254 || !__state) return; if (target.AmOwner) RemoveDisableDevicesPatch.UpdateDisableDevices(); @@ -774,7 +774,7 @@ internal static class ShapeshiftPatch { public static bool ProcessShapeshift(PlayerControl shapeshifter, PlayerControl target) { - if (!Main.ProcessShapeshifts) return true; + if (!Main.ProcessShapeshifts || shapeshifter.PlayerId >= 254) return true; if (AntiBlackout.SkipTasks) { @@ -1063,15 +1063,18 @@ internal static class ReportDeadBodyPatch Damocles.CountRepairSabotage = false; Stressed.CountRepairSabotage = false; - foreach (byte id in Main.DiedThisRound) + if (Options.CurrentGameMode == CustomGameMode.Standard) { - PlayerControl receiver = id.GetPlayer(); - if (receiver == null) continue; + foreach (byte id in Main.DiedThisRound) + { + PlayerControl receiver = id.GetPlayer(); + if (receiver == null) continue; - PlayerControl killer = receiver.GetRealKiller(); - if (killer == null) continue; + PlayerControl killer = receiver.GetRealKiller(); + if (killer == null) continue; - SendMessage("\n", receiver.PlayerId, string.Format(GetString("DeathCommand"), killer.PlayerId.ColoredPlayerName(), (killer.Is(CustomRoles.Bloodlust) ? $"{CustomRoles.Bloodlust.ToColoredString()} " : string.Empty) + killer.GetCustomRole().ToColoredString())); + SendMessage("\n", receiver.PlayerId, string.Format(GetString("DeathCommand"), killer.PlayerId.ColoredPlayerName(), (killer.Is(CustomRoles.Bloodlust) ? $"{CustomRoles.Bloodlust.ToColoredString()} " : string.Empty) + killer.GetCustomRole().ToColoredString())); + } } Main.DiedThisRound = []; @@ -1238,7 +1241,7 @@ internal static class FixedUpdatePatch public static void Postfix(PlayerControl __instance) { - if (__instance == null || __instance.PlayerId == 255) return; + if (__instance == null || __instance.PlayerId >= 254) return; CheckMurderPatch.Update(__instance.PlayerId);