forked from tukasa0001/TownOfHost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRPC.cs
164 lines (161 loc) · 6.53 KB
/
RPC.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
using BepInEx;
using BepInEx.Configuration;
using BepInEx.IL2CPP;
using System;
using HarmonyLib;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnhollowerBaseLib;
using TownOfHost;
using Hazel;
using System.Threading;
using System.Threading.Tasks;
namespace TownOfHost {
enum CustomRPC {
SyncCustomSettings = 80,
JesterExiled,
TerroristWin,
EndGame,
PlaySound
}
public enum Sounds {
KillSound
}
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.HandleRpc))]
class RPCHandlerPatch {
public static void Postfix([HarmonyArgument(0)]byte callId, [HarmonyArgument(1)]MessageReader reader) {
byte packetID = callId;
switch(packetID) {
case (byte)CustomRPC.SyncCustomSettings:
byte scientist = reader.ReadByte();
byte engineer = reader.ReadByte();
byte impostor = reader.ReadByte();
byte shapeshifter = reader.ReadByte();
bool IsHideAndSeek = reader.ReadBoolean();
bool NoGameEnd = reader.ReadBoolean();
bool SwipeCardDisabled = reader.ReadBoolean();
bool SubmitScanDisabled = reader.ReadBoolean();
bool UnlockSafeDisabled = reader.ReadBoolean();
RPCProcedure.SyncCustomSettings(
scientist,
engineer,
impostor,
shapeshifter,
IsHideAndSeek,
NoGameEnd,
SwipeCardDisabled,
SubmitScanDisabled,
UnlockSafeDisabled);
break;
case (byte)CustomRPC.JesterExiled:
byte exiledJester = reader.ReadByte();
RPCProcedure.JesterExiled(exiledJester);
break;
case (byte)CustomRPC.TerroristWin:
byte wonTerrorist = reader.ReadByte();
RPCProcedure.TerroristWin(wonTerrorist);
break;
case (byte)CustomRPC.EndGame:
RPCProcedure.EndGame();
break;
case (byte)CustomRPC.PlaySound:
byte playerID = reader.ReadByte();
Sounds sound = (Sounds)reader.ReadByte();
RPCProcedure.PlaySound(playerID, sound);
break;
}
}
}
class RPCProcedure {
public static void SyncCustomSettings(
byte scientist,
byte engineer,
byte impostor,
byte shapeshifter,
bool isHideAndSeek,
bool NoGameEnd,
bool SwipeCardDisabled,
bool SubmitScanDisabled,
bool UnlockSafeDisabled) {
main.currentScientist = (ScientistRole)scientist;
main.currentEngineer = (EngineerRole)engineer;
main.currentImpostor = (ImpostorRoles)impostor;
main.currentShapeshifter = (ShapeshifterRoles)shapeshifter;
main.IsHideAndSeek = isHideAndSeek;
main.NoGameEnd = NoGameEnd;
main.DisableSwipeCard = SwipeCardDisabled;
main.DisableSubmitScan = SubmitScanDisabled;
main.DisableUnlockSafe = UnlockSafeDisabled;
main.currentWinner = CustomWinner.Default;
main.CustomWinTrigger = false;
}
public static void JesterExiled(byte jesterID) {
main.ExiledJesterID = jesterID;
main.currentWinner = CustomWinner.Jester;
PlayerControl Jester = null;
PlayerControl Imp = null;
List<PlayerControl> Impostors = new List<PlayerControl>();
foreach(var p in PlayerControl.AllPlayerControls) {
if(p.PlayerId == jesterID) Jester = p;
if(p.Data.Role.IsImpostor) {
if(Imp == null) Imp = p;
Impostors.Add(p);
}
}
if(AmongUsClient.Instance.AmHost && false){
Imp.RpcSetColor((byte)Jester.Data.Outfits[PlayerOutfitType.Default].ColorId);
Imp.RpcSetHat(Jester.Data.Outfits[PlayerOutfitType.Default].HatId);
Imp.RpcSetVisor(Jester.Data.Outfits[PlayerOutfitType.Default].VisorId);
Imp.RpcSetSkin(Jester.Data.Outfits[PlayerOutfitType.Default].SkinId);
Imp.RpcSetPet(Jester.Data.Outfits[PlayerOutfitType.Default].PetId);
Imp.RpcSetName(Jester.Data.Outfits[PlayerOutfitType.Default].PlayerName + "\r\nJester wins");
}
if(AmongUsClient.Instance.AmHost){
Task task = Task.Run(() => {
Thread.Sleep(100);
foreach(var imp in Impostors) {
imp.RpcSetRole(RoleTypes.GuardianAngel);
}
Thread.Sleep(100);
main.CustomWinTrigger = true;
});
}
}
public static void TerroristWin(byte terroristID) {
main.WonTerroristID = terroristID;
main.currentWinner = CustomWinner.Terrorist;
PlayerControl Terrorist = null;
List<PlayerControl> Impostors = new List<PlayerControl>();
foreach(var p in PlayerControl.AllPlayerControls) {
if(p.PlayerId == terroristID) Terrorist = p;
if(p.Data.Role.IsImpostor) {
Impostors.Add(p);
}
}
if(AmongUsClient.Instance.AmHost){
foreach(var imp in Impostors) {
imp.RpcSetRole(RoleTypes.GuardianAngel);
}
Thread.Sleep(100);
main.CustomWinTrigger = true;
}
}
public static void EndGame() {
main.currentWinner = CustomWinner.Draw;
if(AmongUsClient.Instance.AmHost){
ShipStatus.Instance.enabled = false;
ShipStatus.RpcEndGame(GameOverReason.ImpostorByKill, false);
}
}
public static void PlaySound(byte playerID, Sounds sound) {
if(PlayerControl.LocalPlayer.PlayerId == playerID) {
switch(sound) {
case Sounds.KillSound:
SoundManager.Instance.PlaySound(PlayerControl.LocalPlayer.KillSfx, false, 0.8f);
break;
}
}
}
}
}