From 87d99fe95eee8929efc1d00374b3fb62bd98e430 Mon Sep 17 00:00:00 2001 From: NotSugden <28943913+NotSugden@users.noreply.github.com> Date: Thu, 24 Jun 2021 02:16:52 +0100 Subject: [PATCH] fix: show destroyed bodies as dead refactor: unessercary type cast fix: show destroyed bodies as dead chore: remove merge conflict marker refactor: use HashSet style: remove newline refactor(MeetingIntroPatch): use init method refactor: use extension method refactor: check if game is still active --- .../CrewmateRoles/AltruistMod/Coroutine.cs | 60 ++++++++++--------- .../CrewmateRoles/SwapperMod/SwapVotes.cs | 4 +- .../ImpostorRoles/JanitorMod/Coroutine.cs | 7 ++- source/Patches/MeetingHud_Start.cs | 13 ---- source/Patches/MeetingIntroPatch.cs | 36 +++++++++++ 5 files changed, 75 insertions(+), 45 deletions(-) delete mode 100644 source/Patches/MeetingHud_Start.cs create mode 100644 source/Patches/MeetingIntroPatch.cs diff --git a/source/Patches/CrewmateRoles/AltruistMod/Coroutine.cs b/source/Patches/CrewmateRoles/AltruistMod/Coroutine.cs index 1a1f324ea..95023fda1 100644 --- a/source/Patches/CrewmateRoles/AltruistMod/Coroutine.cs +++ b/source/Patches/CrewmateRoles/AltruistMod/Coroutine.cs @@ -1,13 +1,12 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; -using InnerNet; using Reactor.Extensions; using TownOfUs.CrewmateRoles.MedicMod; -using TownOfUs.Extensions; using TownOfUs.Roles; using UnityEngine; +using InnerNet; using Object = UnityEngine.Object; namespace TownOfUs.CrewmateRoles.AltruistMod @@ -25,17 +24,15 @@ public static IEnumerator AltruistRevive(DeadBody target, Altruist role) var revived = new List(); - if (AmongUsClient.Instance.AmHost) Utils.RpcMurderPlayer(role.Player, role.Player); - if (CustomGameOptions.AltruistTargetBody) - if (target != null) - { - foreach (DeadBody deadBody in GameObject.FindObjectsOfType()) - { - if (deadBody.ParentId == target.ParentId) deadBody.gameObject.Destroy(); - } - } + if (CustomGameOptions.AltruistTargetBody && target != null) + { + target.gameObject?.Destroy(); + MeetingIntroPatch.DeadPlayers.Add( + GameData.Instance.GetPlayerById(parentId) + ); + } var startTime = DateTime.UtcNow; while (true) @@ -49,15 +46,19 @@ public static IEnumerator AltruistRevive(DeadBody target, Altruist role) if (MeetingHud.Instance) yield break; } - foreach (DeadBody deadBody in GameObject.FindObjectsOfType()) + var altruist = role.Player; + var altruistBody = Object.FindObjectsOfType() + .FirstOrDefault(b => b.ParentId == altruist.PlayerId); + if (altruistBody != null) { - if (deadBody.ParentId == role.Player.PlayerId) deadBody.gameObject.Destroy(); + altruistBody.gameObject?.Destroy(); + MeetingIntroPatch.DeadPlayers.Add(altruist.Data); } var player = Utils.PlayerById(parentId); - // if (player == null || AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started) - // yield break; + if (player == null || AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started) + yield break; player.Revive(); Murder.KilledPlayers.Remove( @@ -65,22 +66,25 @@ public static IEnumerator AltruistRevive(DeadBody target, Altruist role) revived.Add(player); player.NetTransform.SnapTo(position); - if (target != null) Object.Destroy(target.gameObject); + if (target != null) target.gameObject?.Destroy(); if (player.isLover() && CustomGameOptions.BothLoversDie) { var lover = Role.GetRole(player).OtherLover.Player; - lover.Revive(); - Murder.KilledPlayers.Remove( - Murder.KilledPlayers.FirstOrDefault(x => x.PlayerId == lover.PlayerId)); - revived.Add(lover); - - foreach (DeadBody deadBody in GameObject.FindObjectsOfType()) + if (lover?.Data != null && !lover.Data.Disconnected) { - if (deadBody.ParentId == lover.PlayerId) + lover.Revive(); + Murder.KilledPlayers.Remove( + Murder.KilledPlayers.FirstOrDefault(x => x.PlayerId == lover.PlayerId)); + revived.Add(lover); + + var loverBody = Object.FindObjectsOfType().FirstOrDefault(b => b.ParentId == lover.PlayerId); + + if (loverBody != null) { - deadBody.gameObject.Destroy(); + lover.NetTransform.SnapTo(loverBody.TruePosition); + loverBody.gameObject?.Destroy(); } } } @@ -88,8 +92,8 @@ public static IEnumerator AltruistRevive(DeadBody target, Altruist role) if (revived.Any(x => x.AmOwner)) try { - Minigame.Instance.Close(); - Minigame.Instance.Close(); + Minigame.Instance?.Close(); + Minigame.Instance?.Close(); } catch { @@ -110,4 +114,4 @@ public static IEnumerator AltruistRevive(DeadBody target, Altruist role) } } } -} \ No newline at end of file +} diff --git a/source/Patches/CrewmateRoles/SwapperMod/SwapVotes.cs b/source/Patches/CrewmateRoles/SwapperMod/SwapVotes.cs index 5c6f13c99..17fd7c6d6 100644 --- a/source/Patches/CrewmateRoles/SwapperMod/SwapVotes.cs +++ b/source/Patches/CrewmateRoles/SwapperMod/SwapVotes.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using System.Linq; using HarmonyLib; using Reactor; @@ -91,4 +91,4 @@ public static void Postfix(MeetingHud __instance) } } } -} \ No newline at end of file +} diff --git a/source/Patches/ImpostorRoles/JanitorMod/Coroutine.cs b/source/Patches/ImpostorRoles/JanitorMod/Coroutine.cs index 7a7c79ac9..18af49fdc 100644 --- a/source/Patches/ImpostorRoles/JanitorMod/Coroutine.cs +++ b/source/Patches/ImpostorRoles/JanitorMod/Coroutine.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using TownOfUs.Roles; using UnityEngine; @@ -26,6 +26,9 @@ public static IEnumerator CleanCoroutine(DeadBody body, Janitor role) } Object.Destroy(body.gameObject); + MeetingIntroPatch.DeadPlayers.Add( + GameData.Instance.GetPlayerById(body.ParentId) + ); } } -} \ No newline at end of file +} diff --git a/source/Patches/MeetingHud_Start.cs b/source/Patches/MeetingHud_Start.cs deleted file mode 100644 index 2f70ecaad..000000000 --- a/source/Patches/MeetingHud_Start.cs +++ /dev/null @@ -1,13 +0,0 @@ -using HarmonyLib; - -namespace TownOfUs -{ - [HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.Start))] - public class MeetingHud_Start - { - public static void Postfix(MeetingHud __instance) - { - Utils.ShowDeadBodies = PlayerControl.LocalPlayer.Data.IsDead; - } - } -} \ No newline at end of file diff --git a/source/Patches/MeetingIntroPatch.cs b/source/Patches/MeetingIntroPatch.cs new file mode 100644 index 000000000..9371e0aa3 --- /dev/null +++ b/source/Patches/MeetingIntroPatch.cs @@ -0,0 +1,36 @@ +using HarmonyLib; +using System.Collections.Generic; +using System.Linq; +using UnhollowerBaseLib; + +using PlayerData = GameData.PlayerInfo; + +namespace TownOfUs +{ + public static class MeetingIntroPatch + { + public static List DeadPlayers = + new List(); + + [HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.Start))] + public static class MeetingHud_Start + { + public static void Postfix() => + Utils.ShowDeadBodies = PlayerControl.LocalPlayer.Data.IsDead; + } + + [HarmonyPatch(typeof(MeetingIntroAnimation), nameof(MeetingIntroAnimation.Init))] + public static class IntroPatch + { + public static void Prefix( + [HarmonyArgument(1)] ref Il2CppReferenceArray deadPlayers + ) + { + var players = deadPlayers.ToHashSet(); + players.UnionWith(DeadPlayers); + deadPlayers = players.ToArray(); + DeadPlayers.Clear(); + } + } + } +}