-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathHudManagerPatch.cs
231 lines (194 loc) · 11.6 KB
/
HudManagerPatch.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
using System;
using System.Collections.Generic;
using HarmonyLib;
using TMPro;
using UnityEngine;
using AmongUs.GameOptions;
using System.Reflection;
namespace DillyzRoleApi_Rewritten
{
[HarmonyPatch(typeof(HudManager), nameof(HudManager.OnDestroy))]
class HudManagerDestroyPatch
{
public static void Prefix(HudManager __instance)
{
if (HudManagerPatch.AllKillButtons == null)
return;
for (int i = 0; i < HudManagerPatch.AllKillButtons.Count; i++)
GameObject.Destroy(HudManagerPatch.AllKillButtons[i]);
HudManagerPatch.AllKillButtons.Clear();
HudManagerPatch.AllKillButtons = null;
}
}
[HarmonyPatch(typeof(HudManager), nameof(HudManager.SetHudActive))]
class HudManagerEnablingPatch
{
public static bool isActive = true;
public static void Postfix(HudManager __instance, bool isActive) {
HudManagerEnablingPatch.isActive = isActive;
}
}
[HarmonyPatch(typeof(HudManager), nameof(HudManager.Update))]
class HudManagerPatch
{
public static DateTime lastKillThingForCustoms = DateTime.UtcNow;
public static List<KillButtonCustomData> AllKillButtons;
public static void Postfix(HudManager __instance)
{
if (PlayerControl.LocalPlayer == null || PlayerControl.LocalPlayer.Data == null || PlayerControl.LocalPlayer.Data.Role == null)
return;
// colorization
string rnnnmn = DillyzUtil.getRoleName(PlayerControl.LocalPlayer);
CustomRole localRole = (rnnnmn != null && rnnnmn != "") ? CustomRole.getByName(rnnnmn) : null;
foreach (PlayerControl player in PlayerControl.AllPlayerControls)
{
bool youre = player.PlayerId == PlayerControl.LocalPlayer.PlayerId;
string rnnnn = DillyzUtil.getRoleName(player);
CustomRole theRole = (rnnnn != null && rnnnn != "") ? CustomRole.getByName(rnnnn) : null;
// if the role is not there or doesn't change color, leave it alone
if (theRole == null || !theRole.nameColorChanges)
{
if (DillyzUtil.roleSide(PlayerControl.LocalPlayer) == DillyzUtil.roleSide(player))
HudManagerPatch.displayColor(__instance, player, DillyzUtil.roleColor(player, true));
else if (youre)
HudManagerPatch.displayColor(__instance, player, DillyzUtil.roleColor(player, true));
else
HudManagerPatch.displayColor(__instance, player, CustomPalette.White);
continue;
}
if (theRole.nameColorPublic || youre || // If the name color was public. || if it's you
// If it's private but you get it.
(theRole.teamCanSeeYou && DillyzUtil.roleSide(player) == DillyzUtil.roleSide(PlayerControl.LocalPlayer) && DillyzUtil.roleSide(player) != CustomRoleSide.LoneWolf))
HudManagerPatch.displayColor(__instance, player, theRole.roleColor);
else
HudManagerPatch.displayColor(__instance, player, CustomPalette.White);
}
if (AmongUsClient.Instance == null || (!DillyzUtil.InGame() && !DillyzUtil.InFreeplay()))
return;
// task list
bool udiededed = PlayerControl.LocalPlayer.Data.IsDead;
if (!udiededed || DillyzUtil.getRoleName(PlayerControl.LocalPlayer) == "GuardianAngel" || (localRole != null && localRole.ghostRole))
{
string intendedString = DillyzUtil.roleText(PlayerControl.LocalPlayer);
TextMeshPro taskText = __instance.TaskPanel.taskText;
if (taskText.text.Length > 0 && !taskText.text.Contains(intendedString))
{
if (PlayerControl.LocalPlayer.Data.Role.Role == RoleTypes.Scientist)
taskText.text = DillyzUtil.SafeSubString(taskText.text, 0, taskText.text.IndexOf("Scientist Hint") - 1);
else if (PlayerControl.LocalPlayer.Data.Role.Role == RoleTypes.Engineer)
taskText.text = DillyzUtil.SafeSubString(taskText.text, 0, taskText.text.IndexOf("Engineer Hint") - 1);
else if (PlayerControl.LocalPlayer.Data.Role.Role == RoleTypes.GuardianAngel)
taskText.text = DillyzUtil.SafeSubString(taskText.text, 0, taskText.text.IndexOf("Guardian Angel") - 1);
taskText.text += intendedString;
}
}
// DOING THIS FOR THE RETURN THING BC I LIKE RETURNS
displayActionButton(__instance, localRole, udiededed);
if (AllKillButtons == null)
MakeFunnyThing(__instance.KillButton, __instance.AbilityButton);
}
public static void MakeFunnyThing(KillButton killButton, AbilityButton abilityButton) {
if (CustomButton.AllCustomButtons.Count < 1)
return;
HudManagerPatch.lastKillThingForCustoms = DateTime.UtcNow;
Transform buttonParent = killButton.gameObject.transform.parent;
HudManagerPatch.AllKillButtons = new List<KillButtonCustomData>();
foreach (CustomButton button in CustomButton.AllCustomButtons)
{
KillButton newKill = GameObject.Instantiate(killButton);
newKill.transform.parent = killButton.transform.parent;
newKill.name = button.name + "CustomButton";
KillButtonCustomData customKillControl = newKill.gameObject.AddComponent<KillButtonCustomData>();
customKillControl.Setup(button, newKill);
Sprite newKillSprite = DillyzUtil.getSprite(customKillControl.buttonData.epicAssemblyFail, button.imageName);
if (newKillSprite != null)
newKill.graphic.sprite = newKillSprite;
PassiveButton pbjsandwich = newKill.gameObject.GetComponent<PassiveButton>();
pbjsandwich.OnClick.RemoveAllListeners();
pbjsandwich.OnClick.AddListener((UnityEngine.Events.UnityAction)listener);
void listener() {
if (!newKill.isActiveAndEnabled || (newKill.currentTarget == null && customKillControl.buttonData.targetButton)
|| newKill.isCoolingDown || (customKillControl.buttonData.caresAboutMoving
&& !PlayerControl.LocalPlayer.CanMove) || !newKill.canInteract)
{
if (customKillControl.useTimerMode)
{
if (customKillControl.buttonData.useTimerCallback != null)
customKillControl.buttonData.useTimerCallback(customKillControl, false);
customKillControl.useTimerMode = false;
customKillControl.lastUse = DateTime.UtcNow;
customKillControl.killButton.cooldownTimerText.color = Palette.White;
}
else
customKillControl.buttonData.OnClicked(customKillControl, false);
return;
}
customKillControl.lastUse = DateTime.UtcNow;
customKillControl.buttonData.OnClicked(customKillControl, true);
if (customKillControl.buttonData.targetButton)
customKillControl.SetTarget(null);
customKillControl.useTimerMode = customKillControl.buttonData.useTime > 0f;
}
AllKillButtons.Add(customKillControl);
GameObject blockthing = GameObject.Instantiate(abilityButton.commsDown);
blockthing.SetActive(true);
blockthing.transform.parent = newKill.transform;
blockthing.transform.localPosition = new Vector3(0f, 0f, -5f);
blockthing.transform.localScale = abilityButton.commsDown.transform.localScale;
customKillControl.blockSpr = blockthing.GetComponent<SpriteRenderer>();
customKillControl.blockSpr.sprite = DillyzUtil.getSprite(Assembly.GetExecutingAssembly(), "DillyzRoleApi_Rewritten.Assets.button_disabled.png");
}
DillyzRoleApiMain.Instance.Log.LogInfo("bruh moment123456789D");
}
public static void displayActionButton(HudManager __instance, CustomRole localRole, bool udiededed) {
if (MeetingHud.Instance != null || !HudManagerEnablingPatch.isActive)
{
__instance.ImpostorVentButton.gameObject.active = false;
__instance.KillButton.gameObject.SetActive(false);
if (AllKillButtons != null)
foreach (KillButtonCustomData button in AllKillButtons)
button.killButton.gameObject.SetActive(false);
return;
}
if (localRole != null)
{
__instance.AbilityButton.gameObject.SetActive(false);
__instance.ImpostorVentButton.gameObject.active = (localRole.ventPrivilege == VentPrivilege.Impostor) && !udiededed;
__instance.KillButton.gameObject.SetActive(localRole.canKill && !udiededed);
if (__instance.KillButton.gameObject.active)
{
float fullCooldown = GameOptionsManager.Instance.currentNormalGameOptions.KillCooldown;
TimeSpan timeLeft = DateTime.UtcNow - lastKillThingForCustoms;
int timeRemaining = (int)Math.Ceiling((double)new decimal(fullCooldown - timeLeft.TotalMilliseconds / 1000f));
__instance.KillButton.SetCoolDown(timeRemaining < 0 ? 0 : timeRemaining, fullCooldown);
if (!PlayerControl.LocalPlayer.inVent)
__instance.KillButton.SetTarget(DillyzUtil.getClosestPlayer(PlayerControl.LocalPlayer, null, GameOptionsData.KillDistances[GameOptionsManager.Instance.currentNormalGameOptions.KillDistance], true, false, DillyzUtil.roleSide(PlayerControl.LocalPlayer) != CustomRoleSide.Impostor));
else
__instance.KillButton.SetTarget(null);
}
}
else {
string rolename = DillyzUtil.getRoleName(PlayerControl.LocalPlayer);
bool impostorbuttons = (rolename == "Impostor" || rolename == "ShapeShifter") && !udiededed;
__instance.ImpostorVentButton.gameObject.active = impostorbuttons;
__instance.KillButton.gameObject.SetActive(impostorbuttons);
}
if (AllKillButtons != null && AllKillButtons.Count > 0)
{
foreach (KillButtonCustomData button in AllKillButtons)
button.killButton.gameObject.SetActive(button.CanUse());
}
}
public static void displayColor(HudManager __instance, PlayerControl player, Color32 roleColor) {
string hex = DillyzUtil.colorToHex(roleColor);
TextMeshPro tmp = player.gameObject.transform.Find("Names").Find("NameText_TMP").GetComponent<TextMeshPro>();
tmp.text = $"<{hex}>{player.name}</color>";
if (MeetingHud.Instance != null)
foreach (PlayerVoteArea pva in MeetingHud.Instance.playerStates)
if (pva.TargetPlayerId == player.PlayerId) {
pva.NameText.text = $"<{hex}>{player.name}</color>";
return;
}
}
}
}