-
Notifications
You must be signed in to change notification settings - Fork 5
/
PlayerControlPatch.cs
152 lines (134 loc) · 7.52 KB
/
PlayerControlPatch.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
using HarmonyLib;
using Hazel;
using System.Collections.Generic;
using UnityEngine;
using static DillyzRoleApi_Rewritten.Il2CppItemAttribute;
namespace DillyzRoleApi_Rewritten
{
class PlayerControlPatch
{
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.MurderPlayer))]
public class PlayerControlPatch_MurderPlayer
{
public static bool Prefix(PlayerControl __instance, PlayerControl target)
{
DillyzRoleApiMain.Instance.Log.LogWarning($"{__instance.name} tried to kill {target.name} using the normal PlayerControl.MurderPlayer() function!" +
$" (Did you forget to do DillyzUtil.RpcCommitAssassination()?)");
DillyzUtil.commitAssassination(__instance, target, true);
return false;
}
}
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.ToggleHighlight))]
public class PlayerControlPatch_ToggleHighlight
{
public static void Postfix(PlayerControl __instance, bool active, RoleTeamTypes targeterTeam)
{
if (active)
__instance.cosmetics.currentBodySprite.BodySprite.material.SetColor("_OutlineColor", DillyzUtil.color32ToColor(DillyzUtil.roleColor(PlayerControl.LocalPlayer, true)));
}
}
[HarmonyPatch(typeof(PlayerPhysics._CoSpawnPlayer_d__49), nameof(PlayerPhysics._CoSpawnPlayer_d__49.MoveNext))]
public class PlayerPhysicsPatch_CoSpawnPlayer
{
public static void Postfix(PlayerPhysics._CoSpawnPlayer_d__49 __instance, ref bool __result)
{
if (!AmongUsClient.Instance.AmHost || __instance.__4__this.name == "Player(Clone)")
return;
DillyzRoleApiMain.Instance.Log.LogInfo("bruh " + __instance.__4__this.name);
LobbyConfigManager.UpdateAdvancedRoleValues();
LobbyConfigManager.UpdateRoleValues();
// send mods
List<PluginBuildInfo> allPluginInfos = DillyzRoleApiMain.pluginData;
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRpc.ModCheck, Hazel.SendOption.None, -1);
writer.Write(allPluginInfos.Count);
foreach (PluginBuildInfo plugin in allPluginInfos)
{
writer.Write(plugin.Name);
writer.Write(plugin.Version);
writer.Write(plugin.Id);
}
AmongUsClient.Instance.FinishRpcImmediately(writer);
// send roles
List<string> allRoles = CustomRole.allRoleNames;
writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRpc.RoleCheck, Hazel.SendOption.None, -1);
writer.Write(allRoles.Count);
foreach (string str in allRoles)
writer.Write(str);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
}
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.OnGameStart))]
public class PlayerControlPlayer_OnGameStart
{
public static void Postfix(PlayerControl __instance)
{
PlayerControlPlayer_Die.gaurdianAngelAttempts = 0;
ExileControllerPatch.initial_shifters = DillyzUtil.GetAllOfRole("ShapeShifter").Count;
ExileControllerPatch.initial_engineers = DillyzUtil.GetAllOfRole("Engineer").Count;
ExileControllerPatch.initial_scientists = DillyzUtil.GetAllOfRole("Scientist").Count;
}
}
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.Die))]
public class PlayerControlPlayer_Die
{
public static bool skipNextAssignment = false;
public static int gaurdianAngelAttempts = 0;
public static bool Prefix(PlayerControl __instance, DeathReason reason, bool assignGhostRole)
{
if (!DestroyableSingleton<TutorialManager>.InstanceExists && __instance.AmOwner)
{
StatsManager.Instance.LastGameStarted = Il2CppSystem.DateTime.MinValue;
StatsManager instance = StatsManager.Instance;
float banPoints = instance.BanPoints;
instance.BanPoints = banPoints - 1f;
}
TempData.LastDeathReason = reason;
__instance.cosmetics.AnimatePetMourning();
__instance.Data.IsDead = true;
__instance.gameObject.layer = LayerMask.NameToLayer("Ghost");
__instance.cosmetics.SetNameMask(false);
__instance.cosmetics.PettingHand.StopPetting();
if (!skipNextAssignment)
{
GameManager.Instance.OnPlayerDeath(__instance, false);
if (AmongUsClient.Instance.AmHost || DillyzUtil.InFreeplay())
{
CustomRole playerrole = CustomRole.getByName(DillyzUtil.getRoleName(__instance));
if (playerrole != null && playerrole.roletoGhostInto != "")
{
CustomRole newrole = CustomRole.getByName(playerrole.roletoGhostInto);
if (newrole == null || !newrole.ghostRole)
DillyzUtil.RpcSetRole(__instance, playerrole.roletoGhostInto);
}
else if ((playerrole != null ? (!playerrole.ghostRole && playerrole.roletoGhostInto == "") : (DillyzUtil.getRoleName(__instance) != "GuardianAngel"))
&& DillyzUtil.roleSide(__instance) == CustomRoleSide.Crewmate)
{
int angelmax = GameOptionsManager.Instance.CurrentGameOptions.RoleOptions.GetNumPerGame(AmongUs.GameOptions.RoleTypes.GuardianAngel);
int angelchance = GameOptionsManager.Instance.CurrentGameOptions.RoleOptions.GetChancePerGame(AmongUs.GameOptions.RoleTypes.GuardianAngel);
string targetrole = "";
DillyzRoleApiMain.Instance.Log.LogInfo("Consider being the guardian angel.");
if (gaurdianAngelAttempts < angelmax || DillyzUtil.InFreeplay())
{
int rolecahcnde = UnityEngine.Random.Range(0, 100);
if (angelchance != 0 && (angelchance == 100 || angelchance >= rolecahcnde) || DillyzUtil.InFreeplay())
targetrole = "GuardianAngel";
gaurdianAngelAttempts++;
}
DillyzUtil.RpcSetRole(__instance, targetrole);
}
else
DillyzUtil.RpcSetRole(__instance, "");
}
if (__instance.PlayerId == PlayerControl.LocalPlayer.PlayerId)
DestroyableSingleton<HudManager>.Instance.ShadowQuad.gameObject.SetActive(false);
if (__instance.AmOwner)
{
DestroyableSingleton<HudManager>.Instance.Chat.SetVisible(true);
__instance.AdjustLighting();
}
}
return false;
}
}
}
}