-
Notifications
You must be signed in to change notification settings - Fork 5
/
GameOverPatch.cs
177 lines (154 loc) · 7.5 KB
/
GameOverPatch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using System;
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using TMPro;
using UnityEngine;
namespace DillyzRoleApi_Rewritten
{
[HarmonyPatch(typeof(EndGameManager), nameof(EndGameManager.SetEverythingUp))]
class GameOverPatch
{
public static bool customWin = false;
public static string winningRole = "Jester";
public static List<byte> customWinners = new List<byte>();
public static void SetAllToWin(String roleToWin, PlayerControl causedBy, bool rpc)
{
foreach (CustomButton button in CustomButton.AllCustomButtons)
button.GameInstance = null;
CustomRole top10Role = CustomRole.getByName(roleToWin);
if (top10Role.side == CustomRoleSide.Crewmate || top10Role.side == CustomRoleSide.Impostor)
return;
customWin = true;
winningRole = roleToWin;
customWinners.Clear();
DillyzRoleApiMain.Instance.Log.LogInfo("KILL EM FOR " + roleToWin);
foreach (PlayerControl player in PlayerControl.AllPlayerControls)
{
string rolename = DillyzUtil.getRoleName(player);
CustomRoleSide roleside = DillyzUtil.roleSide(player);
if ((top10Role.side == CustomRoleSide.Independent && rolename != roleToWin) || (top10Role.side == CustomRoleSide.LoneWolf && player != causedBy))
{
DillyzRoleApiMain.Instance.Log.LogInfo(player.name + " is now marked as Crewmate!");
player.Data.RoleType = AmongUs.GameOptions.RoleTypes.Crewmate;
player.Data.Role = new CrewmateRole();
if (rpc)
DillyzUtil.RpcSetRole(player, "Crewmate");
}
else
{
DillyzRoleApiMain.Instance.Log.LogInfo(player.name + " is now marked as Impostor!");
player.Data.RoleType = AmongUs.GameOptions.RoleTypes.Impostor;
player.Data.Role = new ImpostorRole();
if (rpc)
DillyzUtil.RpcSetRole(player, "Impostor");
customWinners.Add(player.PlayerId);
}
}
CustomRole.roleNameMap.Clear();
}
public static bool didwin = false;
public static GameOverReason gameOverReason = GameOverReason.HumansByVote;
public static void Postfix(EndGameManager __instance)
{
if (customWin)
{
DillyzRoleApiMain.Instance.Log.LogInfo("TOP 10 PEOPLE IN MY BASEMENT!!!");
Color32 wincolor = CustomRole.getByName(winningRole).roleColor;
string hexthing = DillyzUtil.colorToHex(wincolor);
if (customWinners.Contains(PlayerControl.LocalPlayer.PlayerId))
__instance.WinText.text = $"<{hexthing}>Victory</color>";
else
__instance.WinText.text = $"<{hexthing}>Defeat</color>";
__instance.WinText.material.color = wincolor;
__instance.BackgroundBar.material.color = wincolor;
}
}
// force it to update
[HarmonyPatch(typeof(TextMeshPro), nameof(TextMeshPro.InternalUpdate))]
class TMPPROPatch
{
public static void Postfix(TextMeshPro __instance)
{
if (__instance.name == "YouAreText")
__instance.text = $"<{IntroCutscenePatch.colorHex}>Your role is</color>";
}
}
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.CoStartGame))]
class AmongUsClientPath_CoStartGame
{
public static void Postfix(EndGameManager __instance)
{
DillyzRoleApiMain.Instance.Log.LogInfo("GAME STARTS NOW?!?!");
// waffle_iron.jpeg
GameOverPatch.customWin = false;
GameOverPatch.didwin = false;
GameOverPatch.winningRole = "";
GameOverPatch.customWinners.Clear();
// ahhhh go away
CustomRole.roleNameMap.Clear();
}
}
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnGameEnd))]
class EndGamePatchIdk {
public static void Prefix(AmongUsClient __instance, EndGameResult endGameResult) {
gameOverReason = endGameResult.GameOverReason;
List<PlayerControl> playersLol = PlayerControl.AllPlayerControls.ToArray().ToList();
DillyzRoleApiMain.Instance.Log.LogInfo("got pipe bombed " + playersLol.Count);
if (customWin)
{
foreach (PlayerControl player in playersLol)
{
if (customWinners.Contains(player.PlayerId))
{
DillyzRoleApiMain.Instance.Log.LogInfo(player.name + " is now marked as Impostor!");
player.Data.RoleType = AmongUs.GameOptions.RoleTypes.Impostor;
player.Data.Role = new ImpostorRole();
}
else
{
DillyzRoleApiMain.Instance.Log.LogInfo(player.name + " is now marked as Crewmate!");
player.Data.RoleType = AmongUs.GameOptions.RoleTypes.Crewmate;
player.Data.Role = new CrewmateRole();
}
}
CustomRole.roleNameMap.Clear();
return;
}
bool impsWon = (gameOverReason == GameOverReason.ImpostorByKill || gameOverReason == GameOverReason.ImpostorBySabotage ||
gameOverReason == GameOverReason.ImpostorByVote || gameOverReason == GameOverReason.ImpostorDisconnect);
foreach (PlayerControl player in playersLol)
{
CustomRoleSide rs = DillyzUtil.roleSide(player);
if (rs == CustomRoleSide.Crewmate)
{
DillyzRoleApiMain.Instance.Log.LogInfo(player.name + " is now marked as Crewmate!");
player.Data.RoleType = AmongUs.GameOptions.RoleTypes.Crewmate;
player.Data.Role = new CrewmateRole();
continue;
}
if (rs == CustomRoleSide.Impostor)
{
DillyzRoleApiMain.Instance.Log.LogInfo(player.name + " is now marked as Impostor!");
player.Data.RoleType = AmongUs.GameOptions.RoleTypes.Impostor;
player.Data.Role = new ImpostorRole();
continue;
}
if (impsWon)
{
DillyzRoleApiMain.Instance.Log.LogInfo(player.name + " is now marked as Crewmate!");
player.Data.RoleType = AmongUs.GameOptions.RoleTypes.Crewmate;
player.Data.Role = new CrewmateRole();
}
else
{
DillyzRoleApiMain.Instance.Log.LogInfo(player.name + " is now marked as Impostor!");
player.Data.RoleType = AmongUs.GameOptions.RoleTypes.Impostor;
player.Data.Role = new ImpostorRole();
}
}
CustomRole.roleNameMap.Clear();
}
}
}
}