Skip to content

Commit

Permalink
Multiple Thanos
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Hardel-DW committed Feb 11, 2021
1 parent 5d62040 commit d8af49d
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 63 deletions.
5 changes: 3 additions & 2 deletions ModsThanos/GlobalVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace ModsThanos {
public static class GlobalVariable {

// Player
public static FFGALNAPKCD Thanos;
// Player
public static List<FFGALNAPKCD> allThanos = new List<FFGALNAPKCD>();

public static FFGALNAPKCD PlayerSoulStone;

// Stone Name
Expand Down
6 changes: 1 addition & 5 deletions ModsThanos/Patch/EndGamePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}

}
Expand Down
24 changes: 13 additions & 11 deletions ModsThanos/Patch/HandleRpcPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
48 changes: 35 additions & 13 deletions ModsThanos/Patch/HudPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,58 @@
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);
}
}
}
}
}
}
}

[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();
Expand Down
2 changes: 1 addition & 1 deletion ModsThanos/Patch/IntroCutScenePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down
63 changes: 41 additions & 22 deletions ModsThanos/Patch/PlayerControlPatch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using Hazel;
using ModsThanos.Map;
Expand All @@ -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<PlayerControl> GetImpostor(Il2CppReferenceArray<GameDataPlayerInfo> infection) {
Expand All @@ -35,17 +55,25 @@ public static List<PlayerControl> GetImpostor(Il2CppReferenceArray<GameDataPlaye
return list;
}

// Patch PlayerControl
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.RpcSetInfected))]
public static void Postfix([HarmonyArgument(0)] Il2CppReferenceArray<GameDataPlayerInfo> infected) {
List<PlayerControl> 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}");
}
}
}

Expand All @@ -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);
}
}
}

Expand Down
10 changes: 1 addition & 9 deletions ModsThanos/Patch/StartPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public static void Prefix(ShipStatus __instance) {
Dictionary<string, Vector2> 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);
Expand All @@ -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;
Expand All @@ -58,9 +53,6 @@ public static void Prefix() {
GlobalVariable.useSnap = false;
GlobalVariable.mindStoneUsed = false;
GlobalVariable.UsableButton = false;
GlobalVariable.Thanos = null;

//ModThanos.Logger.LogInfo("Fin");
}
}
}
88 changes: 88 additions & 0 deletions ModsThanos/Stone/StoneDrop.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Loading

0 comments on commit d8af49d

Please sign in to comment.