forked from tukasa0001/TownOfHost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cs
407 lines (385 loc) · 17.5 KB
/
main.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using AmongUs.GameOptions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.IL2CPP;
using HarmonyLib;
using UnhollowerRuntimeLib;
using UnityEngine;
[assembly: AssemblyFileVersionAttribute(TownOfHost.Main.PluginVersion)]
[assembly: AssemblyInformationalVersionAttribute(TownOfHost.Main.PluginVersion)]
namespace TownOfHost
{
[BepInPlugin(PluginGuid, "Town Of Host", PluginVersion)]
[BepInIncompatibility("jp.ykundesu.supernewroles")]
[BepInProcess("Among Us.exe")]
public class Main : BasePlugin
{
// == プログラム設定 / Program Config ==
// modの名前 / Mod Name (Default: Town Of Host)
public static readonly string ModName = "Town Of Host";
// modの色 / Mod Color (Default: #00bfff)
public static readonly string ModColor = "#00bfff";
// 公開ルームを許可する / Allow Public Room (Default: true)
public static readonly bool AllowPublicRoom = true;
// フォークID / ForkId (Default: OriginalTOH)
public static readonly string ForkId = "OriginalTOH";
// Discordボタンを表示するか / Show Discord Button (Default: true)
public static readonly bool ShowDiscordButton = true;
// Discordサーバーの招待リンク / Discord Server Invite URL (Default: https://discord.gg/W5ug6hXB9V)
public static readonly string DiscordInviteUrl = "https://discord.gg/W5ug6hXB9V";
// ==========
public const string OriginalForkId = "OriginalTOH"; // Don't Change The Value. / この値を変更しないでください。
// == 認証設定 / Authentication Config ==
// デバッグキーの認証インスタンス
public static HashAuth DebugKeyAuth { get; private set; }
// デバッグキーのハッシュ値
public const string DebugKeyHash = "c0fd562955ba56af3ae20d7ec9e64c664f0facecef4b3e366e109306adeae29d";
// デバッグキーのソルト
public const string DebugKeySalt = "59687b";
// デバッグキーのコンフィグ入力
public static ConfigEntry<string> DebugKeyInput { get; private set; }
// ==========
//Sorry for many Japanese comments.
public const string PluginGuid = "com.emptybottle.townofhost";
public const string PluginVersion = "4.0.2";
public Harmony Harmony { get; } = new Harmony(PluginGuid);
public static Version version = Version.Parse(PluginVersion);
public static BepInEx.Logging.ManualLogSource Logger;
public static bool hasArgumentException = false;
public static string ExceptionMessage;
public static bool ExceptionMessageIsShown = false;
public static string credentialsText;
public static NormalGameOptionsV07 NormalOptions => GameOptionsManager.Instance.currentNormalGameOptions;
public static HideNSeekGameOptionsV07 HideNSeekSOptions => GameOptionsManager.Instance.currentHideNSeekGameOptions;
//Client Options
public static ConfigEntry<string> HideName { get; private set; }
public static ConfigEntry<string> HideColor { get; private set; }
public static ConfigEntry<bool> ForceJapanese { get; private set; }
public static ConfigEntry<bool> JapaneseRoleName { get; private set; }
public static ConfigEntry<int> MessageWait { get; private set; }
public static Dictionary<byte, PlayerVersion> playerVersion = new();
//Preset Name Options
public static ConfigEntry<string> Preset1 { get; private set; }
public static ConfigEntry<string> Preset2 { get; private set; }
public static ConfigEntry<string> Preset3 { get; private set; }
public static ConfigEntry<string> Preset4 { get; private set; }
public static ConfigEntry<string> Preset5 { get; private set; }
//Other Configs
public static ConfigEntry<string> WebhookURL { get; private set; }
public static ConfigEntry<string> BetaBuildURL { get; private set; }
public static ConfigEntry<float> LastKillCooldown { get; private set; }
public static ConfigEntry<float> LastShapeshifterCooldown { get; private set; }
public static OptionBackupData RealOptionsData;
public static Dictionary<byte, PlayerState> PlayerStates = new();
public static Dictionary<byte, string> AllPlayerNames;
public static Dictionary<(byte, byte), string> LastNotifyNames;
public static Dictionary<byte, Color32> PlayerColors = new();
public static Dictionary<byte, PlayerState.DeathReason> AfterMeetingDeathPlayers = new();
public static Dictionary<CustomRoles, String> roleColors;
public static bool IsFixedCooldown => CustomRoles.Vampire.IsEnable();
public static float RefixCooldownDelay = 0f;
public static List<byte> ResetCamPlayerList;
public static List<byte> winnerList;
public static List<int> clientIdList;
public static List<(string, byte, string)> MessagesToSend;
public static bool isChatCommand = false;
public static List<PlayerControl> LoversPlayers = new();
public static bool isLoversDead = true;
public static Dictionary<byte, float> AllPlayerKillCooldown = new();
/// <summary>
/// 基本的に速度の代入は禁止.スピードは増減で対応してください.
/// </summary>
public static Dictionary<byte, float> AllPlayerSpeed = new();
public const float MinSpeed = 0.0001f;
public static Dictionary<byte, (byte, float)> BitPlayers = new();
public static Dictionary<byte, float> WarlockTimer = new();
public static Dictionary<byte, PlayerControl> CursedPlayers = new();
public static Dictionary<byte, bool> isCurseAndKill = new();
public static Dictionary<(byte, byte), bool> isDoused = new();
public static Dictionary<byte, (PlayerControl, float)> ArsonistTimer = new();
/// <summary>
/// Key: ターゲットのPlayerId, Value: パペッティアのPlayerId
/// </summary>
public static Dictionary<byte, byte> PuppeteerList = new();
public static Dictionary<byte, byte> SpeedBoostTarget = new();
public static Dictionary<byte, int> MayorUsedButtonCount = new();
public static int AliveImpostorCount;
public static int SKMadmateNowCount;
public static bool isCursed;
public static Dictionary<byte, bool> CheckShapeshift = new();
public static Dictionary<byte, byte> ShapeshiftTarget = new();
public static Dictionary<(byte, byte), string> targetArrows = new();
public static bool VisibleTasksCount;
public static string nickName = "";
public static bool introDestroyed = false;
public static int DiscussionTime;
public static int VotingTime;
public static byte currentDousingTarget;
public static float DefaultCrewmateVision;
public static float DefaultImpostorVision;
public static bool IsChristmas = DateTime.Now.Month == 12 && DateTime.Now.Day is 24 or 25;
public static bool IsInitialRelease = DateTime.Now.Month == 12 && DateTime.Now.Day is 4;
public static IEnumerable<PlayerControl> AllPlayerControls => PlayerControl.AllPlayerControls.ToArray().Where(p => p != null);
public static IEnumerable<PlayerControl> AllAlivePlayerControls => PlayerControl.AllPlayerControls.ToArray().Where(p => p != null && p.IsAlive());
public static Main Instance;
public override void Load()
{
Instance = this;
//Client Options
HideName = Config.Bind("Client Options", "Hide Game Code Name", "Town Of Host");
HideColor = Config.Bind("Client Options", "Hide Game Code Color", $"{ModColor}");
ForceJapanese = Config.Bind("Client Options", "Force Japanese", false);
JapaneseRoleName = Config.Bind("Client Options", "Japanese Role Name", true);
DebugKeyInput = Config.Bind("Authentication", "Debug Key", "");
Logger = BepInEx.Logging.Logger.CreateLogSource("TownOfHost");
TownOfHost.Logger.Enable();
TownOfHost.Logger.Disable("NotifyRoles");
TownOfHost.Logger.Disable("SendRPC");
TownOfHost.Logger.Disable("ReceiveRPC");
TownOfHost.Logger.Disable("SwitchSystem");
TownOfHost.Logger.Disable("CustomRpcSender");
//TownOfHost.Logger.isDetail = true;
// 認証関連-初期化
DebugKeyAuth = new HashAuth(DebugKeyHash, DebugKeySalt);
// 認証関連-認証
DebugModeManager.Auth(DebugKeyAuth, DebugKeyInput.Value);
BitPlayers = new Dictionary<byte, (byte, float)>();
WarlockTimer = new Dictionary<byte, float>();
CursedPlayers = new Dictionary<byte, PlayerControl>();
isDoused = new Dictionary<(byte, byte), bool>();
ArsonistTimer = new Dictionary<byte, (PlayerControl, float)>();
MayorUsedButtonCount = new Dictionary<byte, int>();
winnerList = new();
VisibleTasksCount = false;
MessagesToSend = new List<(string, byte, string)>();
currentDousingTarget = 255;
Preset1 = Config.Bind("Preset Name Options", "Preset1", "Preset_1");
Preset2 = Config.Bind("Preset Name Options", "Preset2", "Preset_2");
Preset3 = Config.Bind("Preset Name Options", "Preset3", "Preset_3");
Preset4 = Config.Bind("Preset Name Options", "Preset4", "Preset_4");
Preset5 = Config.Bind("Preset Name Options", "Preset5", "Preset_5");
WebhookURL = Config.Bind("Other", "WebhookURL", "none");
BetaBuildURL = Config.Bind("Other", "BetaBuildURL", "");
MessageWait = Config.Bind("Other", "MessageWait", 1);
LastKillCooldown = Config.Bind("Other", "LastKillCooldown", (float)30);
LastShapeshifterCooldown = Config.Bind("Other", "LastShapeshifterCooldown", (float)30);
NameColorManager.Begin();
CustomWinnerHolder.Reset();
Translator.Init();
BanManager.Init();
TemplateManager.Init();
IRandom.SetInstance(new NetRandomWrapper());
hasArgumentException = false;
ExceptionMessage = "";
try
{
roleColors = new Dictionary<CustomRoles, string>()
{
//バニラ役職
{CustomRoles.Crewmate, "#ffffff"},
{CustomRoles.Engineer, "#8cffff"},
{CustomRoles.Scientist, "#8cffff"},
{CustomRoles.GuardianAngel, "#ffffff"},
//インポスター、シェイプシフター
//特殊インポスター役職
//マッドメイト系役職
//後で追加
//両陣営可能役職
{CustomRoles.Watcher, "#800080"},
//特殊クルー役職
{CustomRoles.NiceWatcher, "#800080"}, //ウォッチャーの派生
{CustomRoles.Bait, "#00f7ff"},
{CustomRoles.SabotageMaster, "#0000ff"},
{CustomRoles.Snitch, "#b8fb4f"},
{CustomRoles.Mayor, "#204d42"},
{CustomRoles.Sheriff, "#f8cd46"},
{CustomRoles.Lighter, "#eee5be"},
{CustomRoles.SpeedBooster, "#00ffff"},
{CustomRoles.Doctor, "#80ffdd"},
{CustomRoles.Trapper, "#5a8fd0"},
{CustomRoles.Dictator, "#df9b00"},
{CustomRoles.CSchrodingerCat, "#ffffff"}, //シュレディンガーの猫の派生
{CustomRoles.Seer, "#61b26c"},
//第三陣営役職
{CustomRoles.Arsonist, "#ff6633"},
{CustomRoles.Jester, "#ec62a5"},
{CustomRoles.Terrorist, "#00ff00"},
{CustomRoles.Executioner, "#611c3a"},
{CustomRoles.Opportunist, "#00ff00"},
{CustomRoles.SchrodingerCat, "#696969"},
{CustomRoles.Egoist, "#5600ff"},
{CustomRoles.EgoSchrodingerCat, "#5600ff"},
{CustomRoles.Jackal, "#00b4eb"},
{CustomRoles.JSchrodingerCat, "#00b4eb"},
//HideAndSeek
{CustomRoles.HASFox, "#e478ff"},
{CustomRoles.HASTroll, "#00ff00"},
// GM
{CustomRoles.GM, "#ff5b70"},
//サブ役職
{CustomRoles.LastImpostor, "#ff0000"},
{CustomRoles.Lovers, "#ff6be4"},
{CustomRoles.NotAssigned, "#ffffff"}
};
foreach (var role in Enum.GetValues(typeof(CustomRoles)).Cast<CustomRoles>())
{
switch (role.GetRoleType())
{
case RoleType.Impostor:
roleColors.TryAdd(role, "#ff0000");
break;
case RoleType.Madmate:
roleColors.TryAdd(role, "#ff0000");
break;
default:
break;
}
}
}
catch (ArgumentException ex)
{
TownOfHost.Logger.Error("エラー:Dictionaryの値の重複を検出しました", "LoadDictionary");
TownOfHost.Logger.Exception(ex, "LoadDictionary");
hasArgumentException = true;
ExceptionMessage = ex.Message;
ExceptionMessageIsShown = false;
}
TownOfHost.Logger.Info($"{Application.version}", "AmongUs Version");
TownOfHost.Logger.Info($"{nameof(ThisAssembly.Git.Branch)}: {ThisAssembly.Git.Branch}", "GitVersion");
TownOfHost.Logger.Info($"{nameof(ThisAssembly.Git.BaseTag)}: {ThisAssembly.Git.BaseTag}", "GitVersion");
TownOfHost.Logger.Info($"{nameof(ThisAssembly.Git.Commit)}: {ThisAssembly.Git.Commit}", "GitVersion");
TownOfHost.Logger.Info($"{nameof(ThisAssembly.Git.Commits)}: {ThisAssembly.Git.Commits}", "GitVersion");
TownOfHost.Logger.Info($"{nameof(ThisAssembly.Git.IsDirty)}: {ThisAssembly.Git.IsDirty}", "GitVersion");
TownOfHost.Logger.Info($"{nameof(ThisAssembly.Git.Sha)}: {ThisAssembly.Git.Sha}", "GitVersion");
TownOfHost.Logger.Info($"{nameof(ThisAssembly.Git.Tag)}: {ThisAssembly.Git.Tag}", "GitVersion");
ClassInjector.RegisterTypeInIl2Cpp<ErrorText>();
Harmony.PatchAll();
}
}
public enum CustomRoles
{
//Default
Crewmate = 0,
//Impostor(Vanilla)
Impostor,
Shapeshifter,
//Impostor
BountyHunter,
EvilWatcher,
FireWorks,
Mafia,
SerialKiller,
//ShapeMaster,
Sniper,
Vampire,
Witch,
Warlock,
Mare,
Puppeteer,
TimeThief,
EvilTracker,
//Madmate
MadGuardian,
Madmate,
MadSnitch,
SKMadmate,
MSchrodingerCat,//インポスター陣営のシュレディンガーの猫
//両陣営
Watcher,
//Crewmate(Vanilla)
Engineer,
GuardianAngel,
Scientist,
//Crewmate
Bait,
Lighter,
Mayor,
NiceWatcher,
SabotageMaster,
Sheriff,
Snitch,
SpeedBooster,
Trapper,
Dictator,
Doctor,
Seer,
CSchrodingerCat,//クルー陣営のシュレディンガーの猫
//Neutral
Arsonist,
Egoist,
EgoSchrodingerCat,//エゴイスト陣営のシュレディンガーの猫
Jester,
Opportunist,
SchrodingerCat,//第三陣営のシュレディンガーの猫
Terrorist,
Executioner,
Jackal,
JSchrodingerCat,//ジャッカル陣営のシュレディンガーの猫
//HideAndSeek
HASFox,
HASTroll,
//GM
GM,
// Sub-roll after 500
NotAssigned = 500,
LastImpostor,
Lovers,
}
//WinData
public enum CustomWinner
{
Draw = -1,
Default = -2,
None = -3,
Impostor = CustomRoles.Impostor,
Crewmate = CustomRoles.Crewmate,
Jester = CustomRoles.Jester,
Terrorist = CustomRoles.Terrorist,
Lovers = CustomRoles.Lovers,
Executioner = CustomRoles.Executioner,
Arsonist = CustomRoles.Arsonist,
Egoist = CustomRoles.Egoist,
Jackal = CustomRoles.Jackal,
HASTroll = CustomRoles.HASTroll,
}
public enum AdditionalWinners
{
None = -1,
Opportunist = CustomRoles.Opportunist,
SchrodingerCat = CustomRoles.SchrodingerCat,
Executioner = CustomRoles.Executioner,
HASFox = CustomRoles.HASFox,
}
/*public enum CustomRoles : byte
{
Default = 0,
HASTroll = 1,
HASHox = 2
}*/
public enum SuffixModes
{
None = 0,
TOH,
Streaming,
Recording,
RoomHost,
OriginalName
}
public enum VoteMode
{
Default,
Suicide,
SelfVote,
Skip
}
public enum TieMode
{
Default,
All,
Random
}
}