From 96c8ffcd422fea11ef8442390e39cee85a1ba78d Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Thu, 21 Nov 2024 19:13:47 +0100 Subject: [PATCH] fixes --- Modules/DevManager.cs | 2 +- Modules/GameState.cs | 4 +- Modules/LobbyNotifierForDiscord.cs | 4 +- Modules/Statistics.cs | 2 +- Modules/Utils.cs | 8 +-- Patches/ClientPatch.cs | 2 +- Patches/PlayerJoinAndLeftPatch.cs | 27 +++++++++- Roles/Neutral/Arsonist.cs | 83 +++++++++++++++++------------- 8 files changed, 84 insertions(+), 48 deletions(-) diff --git a/Modules/DevManager.cs b/Modules/DevManager.cs index aaff8b111..7923aff6a 100644 --- a/Modules/DevManager.cs +++ b/Modules/DevManager.cs @@ -124,7 +124,7 @@ namespace EHR new("funnytiger#8420", "#ffd4ec", "Registered Bozo", true), // Differntperson new("raritykey#6021", "#08f638", "DESPAIR", true), // Junko new("stiltedgap#2406", "#ffff00", "Youtuber", true), // Marcopolo1982 - new("spaglad#3866", isUp: true), // spider_191 + new("spaglad#3866", "#ff0000", "YouTuber", true), // spider_191 new("stapleecho#3635", isUp: true), // Thaylor1819 new("coralcolt#2815", "#ed5356", "YouTuber", true), // TheDarkYT new("deltasunny#0515", "#ff0000", "YouTuber", true), // LuffyFelx diff --git a/Modules/GameState.cs b/Modules/GameState.cs index 96da6a2b6..555a624fc 100644 --- a/Modules/GameState.cs +++ b/Modules/GameState.cs @@ -327,9 +327,9 @@ namespace EHR { RPC.SendDeathReason(PlayerId, deathReason); Utils.CheckAndSpawnAdditionalRefugee(Utils.GetPlayerInfoById(PlayerId)); - + if (Utils.DoRPC && Options.CurrentGameMode != CustomGameMode.Standard) - Main.AllPlayerControls.DoIf(x => x.IsNonHostModClient(), Player.RpcExileDesync); + Main.AllPlayerControls.DoIf(x => x.IsNonHostModClient(), x => Player.RpcSetRoleDesync(RoleTypes.CrewmateGhost, x.GetClientId())); } } diff --git a/Modules/LobbyNotifierForDiscord.cs b/Modules/LobbyNotifierForDiscord.cs index 2d9977430..4c96e183c 100644 --- a/Modules/LobbyNotifierForDiscord.cs +++ b/Modules/LobbyNotifierForDiscord.cs @@ -35,7 +35,7 @@ namespace EHR.Modules { var gameId = AmongUsClient.Instance.GameId; if (gameId == 32) return; - + var roomCode = GameCode.IntToGameName(gameId); if (roomCode == LastRoomCode) return; LastRoomCode = roomCode; @@ -94,7 +94,7 @@ namespace EHR.Modules public static void NotifyLobbyStatusChanged(LobbyStatus status) { - if (!Options.PostLobbyCodeToEHRDiscordServer.GetBool()) return; + if (!Options.PostLobbyCodeToEHRDiscordServer.GetBool() || !AmongUsClient.Instance.AmHost) return; if (GameCode.IntToGameName(AmongUsClient.Instance.GameId) != LastRoomCode) { diff --git a/Modules/Statistics.cs b/Modules/Statistics.cs index 3e60eea40..acbf712d8 100644 --- a/Modules/Statistics.cs +++ b/Modules/Statistics.cs @@ -92,7 +92,7 @@ namespace EHR.Modules if (Main.PlayerStates.Values.All(x => x.GetRealKiller() != lp.PlayerId)) Achievements.Type.InnocentImpostor.CompleteAfterGameEnd(); - if (Main.AllPlayerControls.Where(x => x.IsImpostor()).All(x => x.IsAlive())) + if (Main.NormalOptions.NumImpostors > 1 && Main.AllPlayerControls.Where(x => x.IsImpostor()).All(x => x.IsAlive())) Achievements.Type.ImpostorGang.CompleteAfterGameEnd(); } diff --git a/Modules/Utils.cs b/Modules/Utils.cs index d73205c2a..71cb225da 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -3013,7 +3013,7 @@ other: ∟ ⌠ ⌡ ╬ ╨ ▓ ▒ ░ « » █ ▄ ▌▀▐│ ┤ ╡ ╢ Process.Start(psi); } - public static (int, int) GetDousedPlayerCount(byte playerId) + public static (int Doused, int All) GetDousedPlayerCount(byte playerId) { int doused = 0, all = 0; @@ -3022,13 +3022,15 @@ other: ∟ ⌠ ⌡ ╬ ╨ ▓ ▒ ░ « » █ ▄ ▌▀▐│ ┤ ╡ ╢ if (pc.PlayerId == playerId) continue; all++; - if (Arsonist.IsDoused.TryGetValue((playerId, pc.PlayerId), out bool isDoused) && isDoused) doused++; + + if (Arsonist.IsDoused.TryGetValue((playerId, pc.PlayerId), out bool isDoused) && isDoused) + doused++; } return (doused, all); } - public static (int, int) GetDrawPlayerCount(byte playerId, out List winnerList) + public static (int Drawn, int All) GetDrawPlayerCount(byte playerId, out List winnerList) { var draw = 0; int all = Options.RevolutionistDrawCount.GetInt(); diff --git a/Patches/ClientPatch.cs b/Patches/ClientPatch.cs index 57febb073..2849fe7ed 100644 --- a/Patches/ClientPatch.cs +++ b/Patches/ClientPatch.cs @@ -112,7 +112,7 @@ namespace EHR { public static bool Prefix( /*InnerNetClient __instance,*/ int clientId, bool ban) { - if (!AmongUsClient.Instance.AmHost) return true; + if (!AmongUsClient.Instance.AmHost && !OnGameJoinedPatch.JoiningGame) return true; if (AmongUsClient.Instance.ClientId == clientId) { diff --git a/Patches/PlayerJoinAndLeftPatch.cs b/Patches/PlayerJoinAndLeftPatch.cs index 5360ddcb9..95a80b709 100644 --- a/Patches/PlayerJoinAndLeftPatch.cs +++ b/Patches/PlayerJoinAndLeftPatch.cs @@ -19,8 +19,12 @@ namespace EHR [HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnGameJoined))] internal static class OnGameJoinedPatch { + public static bool JoiningGame; + public static void Postfix(AmongUsClient __instance) { + JoiningGame = true; + while (!Options.IsLoaded) Task.Delay(1); Logger.Info($"{__instance.GameId} joined lobby", "OnGameJoined"); @@ -68,6 +72,8 @@ namespace EHR LateTask.New(() => { + JoiningGame = false; + if (GameStates.IsOnlineGame && GameStates.IsVanillaServer) { try @@ -527,7 +533,26 @@ namespace EHR { if (Main.IntroDestroyed || __instance == null) return; - Logger.Info($"{__instance.GetRealName()}'s color is {Palette.GetColorName(bodyColor)}", "RpcSetColor"); + string colorName = Palette.GetColorName(bodyColor); + Logger.Info($"{__instance.GetRealName()}'s color is {colorName}", "RpcSetColor"); + + if (colorName == "???") + { + LateTask.New(() => + { + if (__instance != null && !Main.PlayerColors.ContainsKey(__instance.PlayerId)) + { + var client = __instance.GetClient(); + + if (client != null) + { + Logger.SendInGame(GetString("Error.InvalidColor") + $" {client.Id}/{client.PlayerName}"); + AmongUsClient.Instance.KickPlayer(client.Id, false); + } + } + }, 4f, "fortegreen bean color kick"); + } + if (bodyColor == 255) return; Main.PlayerColors[__instance.PlayerId] = Palette.PlayerColors[bodyColor]; diff --git a/Roles/Neutral/Arsonist.cs b/Roles/Neutral/Arsonist.cs index affd5f41d..7f6fd3e84 100644 --- a/Roles/Neutral/Arsonist.cs +++ b/Roles/Neutral/Arsonist.cs @@ -99,60 +99,69 @@ namespace EHR.Neutral public override void OnCoEnterVent(PlayerPhysics physics, int ventId) { - if (AmongUsClient.Instance.IsGameStarted) Ignite(physics); + if (AmongUsClient.Instance.IsGameStarted) + Ignite(physics); } private static void Ignite(PlayerPhysics physics) { - if (physics.myPlayer.IsDouseDone()) + switch (ArsonistCanIgniteAnytime.GetBool()) { - CustomSoundsManager.RPCPlayCustomSoundAll("Boom"); - - foreach (PlayerControl pc in Main.AllAlivePlayerControls) - if (pc != physics.myPlayer) - pc.Suicide(PlayerState.DeathReason.Torched, physics.myPlayer); - - foreach (PlayerControl pc in Main.AllPlayerControls) pc.KillFlash(); - - CustomWinnerHolder.ShiftWinnerAndSetWinner(CustomWinner.Arsonist); - CustomWinnerHolder.WinnerIds.Add(physics.myPlayer.PlayerId); - return; - } - - if (ArsonistCanIgniteAnytime.GetBool()) - { - int douseCount = Utils.GetDousedPlayerCount(physics.myPlayer.PlayerId).Item1; - - if (douseCount >= ArsonistMinPlayersToIgnite.GetInt()) // Don't check for max, since the player would not be able to ignite at all if they somehow get more players doused than the max + case false when physics.myPlayer.IsDouseDone(): { - if (douseCount > ArsonistMaxPlayersToIgnite.GetInt()) Logger.Warn("Arsonist Ignited with more players doused than the maximum amount in the settings", "Arsonist Ignite"); + CustomSoundsManager.RPCPlayCustomSoundAll("Boom"); foreach (PlayerControl pc in Main.AllAlivePlayerControls) + if (pc != physics.myPlayer) + pc.Suicide(PlayerState.DeathReason.Torched, physics.myPlayer); + + foreach (PlayerControl pc in Main.AllPlayerControls) + pc.KillFlash(); + + if (CustomWinnerHolder.WinnerTeam is CustomWinner.Crewmate or CustomWinner.Impostor) + CustomWinnerHolder.Reset(); + + CustomWinnerHolder.ShiftWinnerAndSetWinner(CustomWinner.Arsonist); + CustomWinnerHolder.WinnerIds.Add(physics.myPlayer.PlayerId); + return; + } + case true: + { + int douseCount = Utils.GetDousedPlayerCount(physics.myPlayer.PlayerId).Doused; + + if (douseCount >= ArsonistMinPlayersToIgnite.GetInt()) // Don't check for max, since the player would not be able to ignite at all if they somehow get more players doused than the max { - if (!physics.myPlayer.IsDousedPlayer(pc)) continue; + if (douseCount > ArsonistMaxPlayersToIgnite.GetInt()) Logger.Warn("Arsonist Ignited with more players doused than the maximum amount in the settings", "Arsonist Ignite"); - pc.Suicide(PlayerState.DeathReason.Torched, physics.myPlayer); - } + foreach (PlayerControl pc in Main.AllAlivePlayerControls) + { + if (!physics.myPlayer.IsDousedPlayer(pc)) continue; - physics.myPlayer.KillFlash(); + pc.Suicide(PlayerState.DeathReason.Torched, physics.myPlayer); + } - int apc = Main.AllAlivePlayerControls.Length; + physics.myPlayer.KillFlash(); - switch (apc) - { - case 1: - CustomWinnerHolder.ResetAndSetWinner(CustomWinner.Arsonist); - CustomWinnerHolder.WinnerIds.Add(physics.myPlayer.PlayerId); - break; - case 2: - if (Main.AllAlivePlayerControls.Where(x => x.PlayerId != physics.myPlayer.PlayerId).All(x => x.GetCountTypes() == CountTypes.Crew)) - { + int apc = Main.AllAlivePlayerControls.Length; + + switch (apc) + { + case 1: CustomWinnerHolder.ResetAndSetWinner(CustomWinner.Arsonist); CustomWinnerHolder.WinnerIds.Add(physics.myPlayer.PlayerId); - } + break; + case 2: + if (Main.AllAlivePlayerControls.Where(x => x.PlayerId != physics.myPlayer.PlayerId).All(x => x.GetCountTypes() == CountTypes.Crew)) + { + CustomWinnerHolder.ResetAndSetWinner(CustomWinner.Arsonist); + CustomWinnerHolder.WinnerIds.Add(physics.myPlayer.PlayerId); + } - break; + break; + } } + + break; } } }