From d8af49d546aa9d36bf0d238bcb43e4827a4c3294 Mon Sep 17 00:00:00 2001 From: Hardel <42413417+Hardel-DW@users.noreply.github.com> Date: Thu, 11 Feb 2021 04:20:44 +0100 Subject: [PATCH] Multiple Thanos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rajout, de la possibilité d'avoir plusieurs Thanos dans une partie. Thanos drop ces pierres à sa mort HUD, La couleurs de Thanos est maintenant violette. --- ModsThanos/GlobalVariable.cs | 5 +- ModsThanos/Patch/EndGamePatch.cs | 6 +- ModsThanos/Patch/HandleRpcPatch.cs | 24 +++---- ModsThanos/Patch/HudPatch.cs | 48 ++++++++++---- ModsThanos/Patch/IntroCutScenePatch.cs | 2 +- ModsThanos/Patch/PlayerControlPatch.cs | 63 +++++++++++------- ModsThanos/Patch/StartPatch.cs | 10 +-- ModsThanos/Stone/StoneDrop.cs | 88 ++++++++++++++++++++++++++ ModsThanos/Utility/Player.cs | 22 +++++++ 9 files changed, 205 insertions(+), 63 deletions(-) create mode 100644 ModsThanos/Stone/StoneDrop.cs diff --git a/ModsThanos/GlobalVariable.cs b/ModsThanos/GlobalVariable.cs index ba53473..d770ff4 100644 --- a/ModsThanos/GlobalVariable.cs +++ b/ModsThanos/GlobalVariable.cs @@ -5,8 +5,9 @@ namespace ModsThanos { public static class GlobalVariable { - // Player - public static FFGALNAPKCD Thanos; + // Player + public static List allThanos = new List(); + public static FFGALNAPKCD PlayerSoulStone; // Stone Name diff --git a/ModsThanos/Patch/EndGamePatch.cs b/ModsThanos/Patch/EndGamePatch.cs index c6bd24e..e2b5d95 100644 --- a/ModsThanos/Patch/EndGamePatch.cs +++ b/ModsThanos/Patch/EndGamePatch.cs @@ -21,10 +21,7 @@ public static bool Prefix(EndGameManager __instance) { public static class EndGameCommons { public static void ResetGlobalVariable() { - //ModThanos.Logger.LogInfo("Test End"); - GlobalVariable.GameStarted = false; - GlobalVariable.Thanos = null; GlobalVariable.hasMindStone = false; GlobalVariable.hasPowerStone = false; GlobalVariable.hasRealityStone = false; @@ -36,10 +33,9 @@ public static void ResetGlobalVariable() { GlobalVariable.realityStoneUsed = false; GlobalVariable.UsableButton = false; + GlobalVariable.allThanos.Clear(); GlobalVariable.stoneObjects.Clear(); GlobalVariable.stonePositon.Clear(); - - //ModThanos.Logger.LogInfo("Test End Fin"); } } diff --git a/ModsThanos/Patch/HandleRpcPatch.cs b/ModsThanos/Patch/HandleRpcPatch.cs index 02b8dea..65f562f 100644 --- a/ModsThanos/Patch/HandleRpcPatch.cs +++ b/ModsThanos/Patch/HandleRpcPatch.cs @@ -28,12 +28,7 @@ public static bool Prefix(PlayerControl __instance, [HarmonyArgument(0)] byte ca string stoneName = reader.ReadString(); Vector2 vector = reader.ReadVector2(); - if (GlobalVariable.stoneObjects.ContainsKey("Soul")) - GlobalVariable.stoneObjects["Soul"].DestroyThisObject(); - - Stone.Map.Soul.Place(vector); - GlobalVariable.hasSoulStone = false; - + Stone.StoneDrop.ReplaceStone(stoneName, vector); return false; } @@ -79,12 +74,19 @@ public static bool Prefix(PlayerControl __instance, [HarmonyArgument(0)] byte ca } if (callId == (byte) CustomRPC.setThanos) { - byte readByte = reader.ReadByte(); - foreach (FFGALNAPKCD player in FFGALNAPKCD.AllPlayerControls) { - if (player.PlayerId == readByte) { - GlobalVariable.Thanos = player; - } + GlobalVariable.allThanos.Clear(); + int readInt = reader.ReadInt32(); + + byte readByte; + for (int i = 0; i < readInt; i++) { + readByte = reader.ReadByte(); + GlobalVariable.allThanos.Add(Player.FromPlayerIdFFGALNPKCD(readByte)); } + + foreach (var item in GlobalVariable.allThanos) { + ModThanos.Logger.LogInfo($"Get Thanos Name: {item.nameText.Text}, {item.PlayerId}"); + } + return false; } diff --git a/ModsThanos/Patch/HudPatch.cs b/ModsThanos/Patch/HudPatch.cs index 06b5cea..c8b2509 100644 --- a/ModsThanos/Patch/HudPatch.cs +++ b/ModsThanos/Patch/HudPatch.cs @@ -4,15 +4,25 @@ using UnityEngine; namespace ModsThanos.Patch { - public static class HudPatch { public static void UpdateMeetingHUD(MeetingHud __instance) { foreach (PlayerVoteArea player in __instance.playerStates) { - if (player.NameText.Text == GlobalVariable.PlayerSoulStone.name && !GlobalVariable.mindStoneUsed) - player.NameText.Color = new Color(1f, 0.65f, 0f, 1f); + if (GlobalVariable.PlayerSoulStone != null) + if (player.NameText.Text == GlobalVariable.PlayerSoulStone.name && !GlobalVariable.mindStoneUsed) + player.NameText.Color = new Color(1f, 0.65f, 0f, 1f); + + if (PlayerControl.AllPlayerControls != null && PlayerControl.AllPlayerControls.Count > 1) { + if (PlayerControl.LocalPlayer != null) { + foreach (var playerControl in PlayerControl.AllPlayerControls) { + if (PlayerControlPatch.IsThanosByID(playerControl.PlayerId) && PlayerControlPatch.IsThanosByID(PlayerControl.LocalPlayer.PlayerId)) { + string playerName = playerControl.Data.PlayerName; - if (player.NameText.Text == GlobalVariable.Thanos.name && PlayerControlPatch.IsThanos(FFGALNAPKCD.LocalPlayer)) - player.NameText.Color = new Color(0.639f, 0.501f, 0f, 1f); + if (playerName == player.NameText.Text) + player.NameText.Color = new Color(0.749f, 0f, 0.839f, 1f); + } + } + } + } } } } @@ -20,20 +30,32 @@ public static void UpdateMeetingHUD(MeetingHud __instance) { [HarmonyPatch(typeof(HudManager), nameof(HudManager.Update))] public static class HudUpdatePatch { public static void Postfix(HudManager __instance) { + if (MeetingHud.Instance != null) HudPatch.UpdateMeetingHUD(MeetingHud.Instance); - - foreach (var player in PlayerControl.AllPlayerControls) - if (PlayerControl.AllPlayerControls.Count > 1 && GlobalVariable.PlayerSoulStone != null) + + if (PlayerControl.AllPlayerControls.Count > 1 && GlobalVariable.PlayerSoulStone != null) + foreach (var player in PlayerControl.AllPlayerControls) if (player.PlayerId == GlobalVariable.PlayerSoulStone.PlayerId && !GlobalVariable.mindStoneUsed) player.nameText.Color = new Color(1f, 0.65f, 0f, 1f); - if (GlobalVariable.realityStoneUsed && PlayerControl.AllPlayerControls.Count > 1 && GlobalVariable.Thanos != null) - Player.FromPlayerIdFFGALNPKCD(GlobalVariable.Thanos.PlayerId).nameText.Color = new Color(1f, 1f, 1f, 0f); + if (GlobalVariable.allThanos != null && PlayerControl.AllPlayerControls.Count > 1 && GlobalVariable.realityStoneUsed) + foreach (var player in PlayerControl.AllPlayerControls) + if (PlayerControlPatch.IsThanosByID(player.PlayerId)) + player.nameText.Color = new Color(1f, 1f, 1f, 0f); + + if (GlobalVariable.allThanos != null && PlayerControl.AllPlayerControls.Count > 1) { + if (PlayerControl.LocalPlayer != null) { + if (PlayerControlPatch.IsThanosByID(PlayerControl.LocalPlayer.PlayerId)) { + foreach (var player in PlayerControl.AllPlayerControls) { + if (PlayerControlPatch.IsThanosByID(player.PlayerId)) { + player.nameText.Color = new Color(0.749f, 0f, 0.839f, 1f); + } + } - if (PlayerControl.AllPlayerControls.Count > 1 && GlobalVariable.Thanos != null && PlayerControlPatch.IsThanos(FFGALNAPKCD.LocalPlayer)) { - PlayerControl.LocalPlayer.nameText.Color = new Color(0.749f, 0f, 0.839f, 1f); - __instance.TaskText.Text = "[FFFFFFFF]Objectif: Trouver les pierres pour obtenir le snap.[]\n\n[808080FF]Snap:[] Termine la partie.\n[008516FF]Pierre du temps :[] Permet de revenir dans le temps.\n[822FA8FF]Pierre de pouvoir :[] Permet de tuer en zone.\n[C46f1AFF]Pierre de l'âme :[] les crewmate peuvent la ramasser.\n[A6A02EFF]Pierre de l'esprit :[] Permet de se transformer en quelqu'un.\n[3482BAFF]Pierre de l'espace[]: Pose des portails.\n[D43D3DFF]Pierre de Réalité[]: Permet de se rendre invisible"; + __instance.TaskText.Text = "[FFFFFFFF]Objectif: Trouver les pierres pour obtenir le snap.[]\n\n[808080FF]Snap:[] Termine la partie.\n[008516FF]Pierre du temps :[] Permet de revenir dans le temps.\n[822FA8FF]Pierre de pouvoir :[] Permet de tuer en zone.\n[C46f1AFF]Pierre de l'âme :[] les crewmate peuvent la ramasser.\n[A6A02EFF]Pierre de l'esprit :[] Permet de se transformer en quelqu'un.\n[3482BAFF]Pierre de l'espace[]: Pose des portails.\n[D43D3DFF]Pierre de Réalité[]: Permet de se rendre invisible"; + } + } } CooldownButton.HudUpdate(); diff --git a/ModsThanos/Patch/IntroCutScenePatch.cs b/ModsThanos/Patch/IntroCutScenePatch.cs index 58467e4..da61870 100644 --- a/ModsThanos/Patch/IntroCutScenePatch.cs +++ b/ModsThanos/Patch/IntroCutScenePatch.cs @@ -7,7 +7,7 @@ namespace ModsThanos.Patch { [HarmonyPatch(typeof(IntroCutScene), nameof(IntroCutScene.MoveNext))] public static class IntroCutScenePatch { public static void Postfix(IntroCutScene __instance) { - if (PlayerControlPatch.IsThanos(FFGALNAPKCD.LocalPlayer)) { + if (PlayerControlPatch.IsThanosByID(PlayerControl.LocalPlayer.PlayerId)) { __instance.__this.Title.Text = "Thanos"; __instance.__this.Title.Color = new Color(0.749f, 0f, 0.839f, 1f); __instance.__this.ImpostorText.Text = "Trouver les pierres, et Défier les crewmates."; diff --git a/ModsThanos/Patch/PlayerControlPatch.cs b/ModsThanos/Patch/PlayerControlPatch.cs index fb3e83a..5de9e26 100644 --- a/ModsThanos/Patch/PlayerControlPatch.cs +++ b/ModsThanos/Patch/PlayerControlPatch.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using HarmonyLib; using Hazel; using ModsThanos.Map; @@ -15,8 +16,27 @@ namespace ModsThanos.Patch { [HarmonyPatch] class PlayerControlPatch { + // Method Global. public static bool IsThanos(PlayerControl player) { - return player.PlayerId == GlobalVariable.Thanos.PlayerId; + bool isThanos = false; + + foreach (var thanos in GlobalVariable.allThanos) { + if (player.PlayerId == thanos.PlayerId) + isThanos = true; + } + + return isThanos; + } + + public static bool IsThanosByID(byte playerId) { + bool isThanos = false; + + foreach (var thanos in GlobalVariable.allThanos) { + if (playerId == thanos.PlayerId) + isThanos = true; + } + + return isThanos; } public static List GetImpostor(Il2CppReferenceArray infection) { @@ -35,17 +55,25 @@ public static List GetImpostor(Il2CppReferenceArray infected) { List impostors = GetImpostor(infected); if (impostors != null && impostors.Count > 0) { - System.Random random = new System.Random(); - GlobalVariable.Thanos = impostors[random.Next(0, impostors.Count)]; - byte playerId = GlobalVariable.Thanos.PlayerId; + GlobalVariable.allThanos.Clear(); MessageWriter messageWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte) CustomRPC.setThanos, SendOption.None, -1); - messageWriter.Write(playerId); + + messageWriter.Write(impostors.Count); + foreach (var player in impostors) { + GlobalVariable.allThanos.Add(player); + messageWriter.Write(player.PlayerId); + } AmongUsClient.Instance.FinishRpcImmediately(messageWriter); + + foreach (var item in GlobalVariable.allThanos) { + ModThanos.Logger.LogInfo($"Send Thanos Name: {item.nameText.Text}, {item.PlayerId}"); + } } } @@ -54,24 +82,15 @@ public static void Postfix(PlayerControl __instance) { if (GlobalVariable.useSnap) Stone.System.Snap.Incremente(); - if (GlobalVariable.hasSoulStone && Player.LocalPlayer.PlayerData.IsDead) { - - if (GlobalVariable.stoneObjects.ContainsKey("Soul")) - GlobalVariable.stoneObjects["Soul"].DestroyThisObject(); - - Vector2 placement = StonePlacement.GetRandomLocation("Soul"); - Stone.Map.Soul.Place(placement); - GlobalVariable.hasSoulStone = false; - - GlobalVariable.PlayerSoulStone = null; - MessageWriter write = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte) CustomRPC.RemovePlayerSoulStone, SendOption.None, -1); - AmongUsClient.Instance.FinishRpcImmediately(write); - Player.LocalPlayer.RpcSetColorName(new Color(1f, 1f, 1f, 1f), Player.LocalPlayer.PlayerId); + if (GlobalVariable.hasSoulStone && Player.LocalPlayer.PlayerData.IsDead && !IsThanosByID(PlayerControl.LocalPlayer.PlayerId)) { + Stone.StoneDrop.tryReplaceStone("Soul"); + } - write = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte) CustomRPC.ReplaceStone, SendOption.None, -1); - write.Write("Soul"); - write.WriteVector2(GlobalVariable.stonePositon["Soul"]); - AmongUsClient.Instance.FinishRpcImmediately(write); + if (IsThanos(PlayerControl.LocalPlayer) && Player.LocalPlayer.PlayerData.IsDead) { + if (GlobalVariable.hasSoulStone || GlobalVariable.hasMindStone || GlobalVariable.hasPowerStone || GlobalVariable.hasSpaceStone || GlobalVariable.hasTimeStone || GlobalVariable.hasRealityStone) { + foreach (var stone in GlobalVariable.stonesNames) + Stone.StoneDrop.tryReplaceStone(stone); + } } } diff --git a/ModsThanos/Patch/StartPatch.cs b/ModsThanos/Patch/StartPatch.cs index 1c3ee32..fbf0988 100644 --- a/ModsThanos/Patch/StartPatch.cs +++ b/ModsThanos/Patch/StartPatch.cs @@ -26,10 +26,6 @@ public static void Prefix(ShipStatus __instance) { Dictionary stonePosition = StonePlacement.SetAllStonePositions(); StonePlacement.PlaceAllStone(); - foreach (string item in GlobalVariable.stonesNames) { - //ModThanos.Logger.LogInfo($"Name: {item}, Position: {GlobalVariable.stonePositon[item].x}, {GlobalVariable.stonePositon[item].y}"); - } - if (Player.amHost()) { foreach (var stone in stonePosition) { MessageWriter write = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte) CustomRPC.SyncStone, SendOption.None, -1); @@ -44,10 +40,9 @@ public static void Prefix(ShipStatus __instance) { [HarmonyPatch(typeof(LobbyBehaviour), nameof(LobbyBehaviour.Start))] public static class LobbyBehaviourPatch { public static void Prefix() { - //ModThanos.Logger.LogInfo("Test"); - GlobalVariable.stoneObjects.Clear(); GlobalVariable.stonePositon.Clear(); + GlobalVariable.allThanos.Clear(); GlobalVariable.hasMindStone = false; GlobalVariable.hasPowerStone = false; GlobalVariable.hasRealityStone = false; @@ -58,9 +53,6 @@ public static void Prefix() { GlobalVariable.useSnap = false; GlobalVariable.mindStoneUsed = false; GlobalVariable.UsableButton = false; - GlobalVariable.Thanos = null; - - //ModThanos.Logger.LogInfo("Fin"); } } } diff --git a/ModsThanos/Stone/StoneDrop.cs b/ModsThanos/Stone/StoneDrop.cs new file mode 100644 index 0000000..3e21062 --- /dev/null +++ b/ModsThanos/Stone/StoneDrop.cs @@ -0,0 +1,88 @@ +using Hazel; +using ModsThanos.Map; +using ModsThanos.Utility; +using UnityEngine; + +namespace ModsThanos.Stone { + public static class StoneDrop { + + public static void tryReplaceStone(string stone) { + if (stone == "Mind" && GlobalVariable.hasMindStone) { + DestroyStone(stone); + Vector2 placement = StonePlacement.GetRandomLocation(stone); + Map.Mind.Place(placement); + GlobalVariable.hasMindStone = false; + + } else if (stone == "Soul" && GlobalVariable.hasSoulStone) { + DestroyStone(stone); + Vector2 placement = StonePlacement.GetRandomLocation(stone); + Map.Soul.Place(placement); + GlobalVariable.hasSoulStone = false; + + GlobalVariable.PlayerSoulStone = null; + MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte) CustomRPC.RemovePlayerSoulStone, SendOption.None, -1); + AmongUsClient.Instance.FinishRpcImmediately(writer); + Player.LocalPlayer.RpcSetColorName(new Color(1f, 1f, 1f, 1f), Player.LocalPlayer.PlayerId); + + } else if (stone == "Power" && GlobalVariable.hasPowerStone) { + DestroyStone(stone); + Vector2 placement = StonePlacement.GetRandomLocation(stone); + Map.Power.Place(placement); + GlobalVariable.hasPowerStone = false; + + } else if (stone == "Time" && GlobalVariable.hasTimeStone) { + DestroyStone(stone); + Vector2 placement = StonePlacement.GetRandomLocation(stone); + Map.Time.Place(placement); + GlobalVariable.hasTimeStone = false; + + } else if (stone == "Space" && GlobalVariable.hasSpaceStone) { + DestroyStone(stone); + Vector2 placement = StonePlacement.GetRandomLocation(stone); + Map.Space.Place(placement); + GlobalVariable.hasSpaceStone = false; + + } else if (stone == "Reality" && GlobalVariable.hasRealityStone) { + DestroyStone(stone); + Vector2 placement = StonePlacement.GetRandomLocation(stone); + Map.Reality.Place(placement); + GlobalVariable.hasRealityStone = false; + } else return; + + ModThanos.Logger.LogInfo($"Send {stone}, Position : {GlobalVariable.stonePositon[stone].x}, {GlobalVariable.stonePositon[stone].y}"); + MessageWriter write = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte) CustomRPC.ReplaceStone, SendOption.None, -1); + write.Write(stone); + write.WriteVector2(GlobalVariable.stonePositon[stone]); + AmongUsClient.Instance.FinishRpcImmediately(write); + } + + public static void ReplaceStone(string stone, Vector2 position) { + DestroyStone(stone); + + if (stone == "Mind") { + Map.Mind.Place(position); + GlobalVariable.hasMindStone = false; + } else if (stone == "Soul") { + Map.Soul.Place(position); + GlobalVariable.hasSoulStone = false; + } else if (stone == "Power") { + Map.Power.Place(position); + GlobalVariable.hasPowerStone = false; + } else if (stone == "Time") { + Map.Time.Place(position); + GlobalVariable.hasTimeStone = false; + } else if (stone == "Space") { + Map.Space.Place(position); + GlobalVariable.hasSpaceStone = false; + } else if (stone == "Reality") { + Map.Reality.Place(position); + GlobalVariable.hasRealityStone = false; + } else return; + } + + public static void DestroyStone(string stone) { + if (GlobalVariable.stoneObjects.ContainsKey(stone)) + GlobalVariable.stoneObjects[stone].DestroyThisObject(); + } + } +} diff --git a/ModsThanos/Utility/Player.cs b/ModsThanos/Utility/Player.cs index 3cc4666..0cc89d4 100644 --- a/ModsThanos/Utility/Player.cs +++ b/ModsThanos/Utility/Player.cs @@ -342,5 +342,27 @@ public static void KillEveryone(Player murder) { public static bool amHost() { return AmongUsClient.Instance.AmHost; } + + public static byte[] getAllPlayersID(List players) { + byte[] playersIds = new byte[players.Count - 1]; + + for (int i = 0; i < players.Count - 1; i++) { + playersIds[i] = players[i].PlayerId; + } + + return playersIds; + } + + public static byte getAllImpostors() { + byte impostorCount = 0; + + foreach (var player in AllPlayerControls) { + if (player.PlayerData.IsImpostor) { + impostorCount++; + } + } + + return impostorCount; + } } }