forked from tukasa0001/TownOfHost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cs
1571 lines (1490 loc) · 83.3 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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.IL2CPP;
using System;
using HarmonyLib;
using System.Collections.Generic;
using UnityEngine;
using Hazel;
using System.Linq;
using System.Reflection;
[assembly: AssemblyFileVersionAttribute(TownOfHost.main.PluginVersion)]
[assembly: AssemblyInformationalVersionAttribute(TownOfHost.main.PluginVersion)]
namespace TownOfHost
{
[BepInPlugin(PluginGuid, "Town Of Host", PluginVersion)]
[BepInProcess("Among Us.exe")]
public class main : BasePlugin
{
//Sorry for many Japanese comments.
public const string PluginGuid = "com.emptybottle.townofhost";
public const string PluginVersion = "1.4.0";
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;
//Client Options
public static ConfigEntry<bool> HideCodes {get; private set;}
public static ConfigEntry<string> HideName {get; private set;}
public static ConfigEntry<string> HideColor {get; private set;}
public static ConfigEntry<bool> JapaneseRoleName {get; private set;}
public static ConfigEntry<bool> AmDebugger {get; private set;}
public static ConfigEntry<int> BanTimestamp {get; private set;}
public static LanguageUnit EnglishLang {get; private set;}
//Lang-arrangement
private static Dictionary<lang, string> JapaneseTexts = new Dictionary<lang, string>();
private static Dictionary<CustomRoles, string> JapaneseRoleNames = new Dictionary<CustomRoles, string>();
private static Dictionary<PlayerState.DeathReason, string> JapaneseDeathReason = new Dictionary<PlayerState.DeathReason, string>();
private static Dictionary<lang, string> EnglishTexts = new Dictionary<lang, string>();
private static Dictionary<CustomRoles, string> EnglishRoleNames = new Dictionary<CustomRoles, string>();
private static Dictionary<PlayerState.DeathReason, string> EnglishDeathReason = new Dictionary<PlayerState.DeathReason, string>();
public static Dictionary<byte, PlayerVersion> playerVersion = new Dictionary<byte, PlayerVersion>();
//Other Configs
public static ConfigEntry<bool> IgnoreWinnerCommand { get; private set; }
public static ConfigEntry<string> WebhookURL { get; private set; }
public static CustomWinner currentWinner;
public static HashSet<AdditionalWinners> additionalwinners = new HashSet<AdditionalWinners>();
public static GameOptionsData RealOptionsData;
public static PlayerState ps;
public static bool IsHideAndSeek;
public static bool AllowCloseDoors;
public static bool IgnoreVent;
public static bool IgnoreCosmetics;
public static int HideAndSeekKillDelay;
public static float HideAndSeekKillDelayTimer;
public static float HideAndSeekImpVisionMin;
public static Dictionary<byte, string> AllPlayerNames;
public static Dictionary<byte, CustomRoles> AllPlayerCustomRoles;
public static Dictionary<string, CustomRoles> lastAllPlayerCustomRoles;
public static Dictionary<byte, bool> BlockKilling;
public static bool SyncButtonMode;
public static int SyncedButtonCount;
public static int UsedButtonCount;
public static bool RandomMapsMode;
public static bool NoGameEnd;
public static bool OptionControllerIsEnable;
//タスク無効化
public static bool DisableSwipeCard;
public static bool DisableSubmitScan;
public static bool DisableUnlockSafe;
public static bool DisableUploadData;
public static bool DisableStartReactor;
//ランダムマップ
public static bool AddedTheSkeld;
public static bool AddedMIRAHQ;
public static bool AddedPolus;
public static bool AddedDleks;
public static bool AddedTheAirShip;
public static Dictionary<CustomRoles,String> roleColors;
//これ変えたらmod名とかの色が変わる
public static string modColor = "#00bfff";
public static bool isFixedCooldown;
public static float RefixCooldownDelay = 0f;
public static int BeforeFixMeetingCooldown = 10;
public static bool forceJapanese = false;
public static VoteMode whenSkipVote = VoteMode.Default;
public static VoteMode whenNonVote = VoteMode.Default;
public static bool canTerroristSuicideWin = false;
public static List<byte> IgnoreReportPlayers;
public static List<byte> winnerList;
public static List<(string, byte)> MessagesToSend;
public static bool autoDisplayLastRoles = false;
public static bool isChatCommand = false;
public static int SetRoleCountToggle(int currentCount)
{
if(currentCount > 0) return 0;
else return 1;
}
public static int SetRoleCount(int currentCount, int addCount)
{
var fixedCount = currentCount * 10;
fixedCount += addCount;
fixedCount = Math.Clamp(fixedCount, 0, 99);
return fixedCount;
}
public static void SetRoleCountToggle(CustomRoles role)
{
int count = GetCountFromRole(role);
count = SetRoleCountToggle(count);
SetCountFromRole(role, count);
}
public static void SetRoleCount(CustomRoles role, int addCount)
{
int count = GetCountFromRole(role);
count = SetRoleCount(count, addCount);
SetCountFromRole(role, count);
}
//Lang-Get
//langのenumに対応した値をリストから持ってくる
public static string getLang(lang lang)
{
var dic = TranslationController.Instance.currentLanguage.languageID == SupportedLangs.Japanese || forceJapanese ? JapaneseTexts : EnglishTexts;
var isSuccess = dic.TryGetValue(lang, out var text);
return isSuccess ? text : "<Not Found:" + lang.ToString() + ">";
}
public static string getRoleName(CustomRoles role) {
var dic = (TranslationController.Instance.currentLanguage.languageID == SupportedLangs.Japanese || forceJapanese) &&
JapaneseRoleName.Value == true ? JapaneseRoleNames : EnglishRoleNames;
var isSuccess = dic.TryGetValue(role, out var text);
return isSuccess ? text : "<Not Found:" + role.ToString() + ">";
}
public static string getDeathReason(PlayerState.DeathReason status)
{
var dic = TranslationController.Instance.currentLanguage.languageID == SupportedLangs.Japanese || forceJapanese ? JapaneseDeathReason : EnglishDeathReason;
var isSuccess = dic.TryGetValue(status, out var text);
return isSuccess ? text : "<Not Found:" + status.ToString() + ">";
}
public static Color getRoleColor(CustomRoles role)
{
if(!roleColors.TryGetValue(role, out var hexColor))hexColor = "#ffffff";
ColorUtility.TryParseHtmlString(hexColor,out Color c);
return c;
}
public static string getRoleColorCode(CustomRoles role)
{
if(!roleColors.TryGetValue(role, out var hexColor))hexColor = "#ffffff";
return hexColor;
}
public static int GetCountFromRole(CustomRoles role) {
int count;
switch(role) {
case CustomRoles.Jester:
count = JesterCount;
break;
case CustomRoles.Madmate:
count = MadmateCount;
break;
case CustomRoles.Bait:
count = BaitCount;
break;
case CustomRoles.Terrorist:
count = TerroristCount;
break;
case CustomRoles.Mafia:
count = MafiaCount;
break;
case CustomRoles.Vampire:
count = VampireCount;
break;
case CustomRoles.SabotageMaster:
count = SabotageMasterCount;
break;
case CustomRoles.MadGuardian:
count = MadGuardianCount;
break;
case CustomRoles.Mayor:
count = MayorCount;
break;
case CustomRoles.Opportunist:
count = OpportunistCount;
break;
case CustomRoles.Sheriff:
count = SheriffCount;
break;
case CustomRoles.Snitch:
count = SnitchCount;
break;
case CustomRoles.BountyHunter:
count = BountyHunterCount;
break;
case CustomRoles.Witch:
count = WitchCount;
break;
default:
return -1;
}
return count;
}
public static void SetCountFromRole(CustomRoles role, int count) {
switch(role) {
case CustomRoles.Jester:
JesterCount = count;
break;
case CustomRoles.Madmate:
MadmateCount = count;
break;
case CustomRoles.Bait:
BaitCount = count;
break;
case CustomRoles.Terrorist:
TerroristCount = count;
break;
case CustomRoles.Mafia:
MafiaCount = count;
break;
case CustomRoles.Vampire:
VampireCount = count;
break;
case CustomRoles.SabotageMaster:
SabotageMasterCount = count;
break;
case CustomRoles.MadGuardian:
MadGuardianCount = count;
break;
case CustomRoles.Mayor:
MayorCount = count;
break;
case CustomRoles.Opportunist:
OpportunistCount = count;
break;
case CustomRoles.Sheriff:
SheriffCount = count;
break;
case CustomRoles.Snitch:
SnitchCount = count;
break;
case CustomRoles.BountyHunter:
BountyHunterCount = count;
break;
case CustomRoles.Witch:
WitchCount = count;
break;
}
}
public static (string, Color) GetRoleText(PlayerControl player)
{
string RoleText = "Invalid Role";
Color TextColor = Color.red;
var cRole = player.getCustomRole();
RoleText = getRoleName(cRole);
return (RoleText, getRoleColor(cRole));
}
public static (string, Color) GetRoleTextHideAndSeek(RoleTypes oRole, CustomRoles hRole)
{
string text = "Invalid";
Color color = Color.red;
switch (oRole)
{
case RoleTypes.Impostor:
case RoleTypes.Shapeshifter:
text = "Impostor";
color = Palette.ImpostorRed;
break;
default:
switch (hRole)
{
case CustomRoles.Default:
text = "Crewmate";
color = Color.white;
break;
case CustomRoles.Fox:
text = "Fox";
color = Color.magenta;
break;
case CustomRoles.Troll:
text = "Troll";
color = Color.green;
break;
}
break;
}
return (text, color);
}
public static bool hasTasks(GameData.PlayerInfo p, bool ForRecompute = true)
{
//Tasksがnullの場合があるのでその場合タスク無しとする
if (p.Tasks == null) return false;
var hasTasks = true;
if (p.Disconnected) hasTasks = false;
if (main.IsHideAndSeek)
{
if(p.Role.IsImpostor)
hasTasks = false; //タスクはバニラ役職で判定される
if (p.IsDead) hasTasks = false;
var hasRole = main.AllPlayerCustomRoles.TryGetValue(p.PlayerId, out var role);
if (hasRole)
{
if (role == CustomRoles.Fox || role == CustomRoles.Troll) hasTasks = false;
}
} else {
var cRoleFound = AllPlayerCustomRoles.TryGetValue(p.PlayerId, out var cRole);
if(cRoleFound) {
if (cRole.isImpostor()) hasTasks = false;
if (cRole == CustomRoles.Jester) hasTasks = false;
if (cRole == CustomRoles.MadGuardian && ForRecompute) hasTasks = false;
if (cRole == CustomRoles.Opportunist) hasTasks = false;
if (cRole == CustomRoles.Sheriff) hasTasks = false;
if (cRole == CustomRoles.Madmate) hasTasks = false;
if (cRole == CustomRoles.Terrorist && ForRecompute) hasTasks = false;
}
}
return hasTasks;
}
public static string getTaskText(Il2CppSystem.Collections.Generic.List<GameData.TaskInfo> tasks)
{
if(tasks == null) return "null";
int CompletedTaskCount = 0;
int AllTasksCount = 0;
foreach (var task in tasks)
{
AllTasksCount++;
if (task.Complete) CompletedTaskCount++;
}
return $"{CompletedTaskCount}/{AllTasksCount}";
}
public static void ShowActiveRoles()
{
main.SendToAll("現在有効な設定の説明:");
if(main.IsHideAndSeek)
{
main.SendToAll(main.getLang(lang.HideAndSeekInfo));
if(main.FoxCount > 0 ){ main.SendToAll(main.getLang(lang.FoxInfoLong)); }
if(main.TrollCount > 0 ){ main.SendToAll(main.getLang(lang.TrollInfoLong)); }
}else{
if(main.SyncButtonMode){ main.SendToAll(main.getLang(lang.SyncButtonModeInfo)); }
if(main.RandomMapsMode) { main.SendToAll(main.getLang(lang.RandomMapsModeInfo)); }
if(main.VampireCount > 0) main.SendToAll(main.getLang(lang.VampireInfoLong));
if(main.BountyHunterCount > 0) main.SendToAll(main.getLang(lang.BountyHunterInfoLong));
if(main.WitchCount > 0) main.SendToAll(main.getLang(lang.WitchInfoLong));
if(main.MafiaCount > 0) main.SendToAll(main.getLang(lang.MafiaInfoLong));
if(main.MadmateCount > 0) main.SendToAll(main.getLang(lang.MadmateInfoLong));
if(main.MadGuardianCount > 0) main.SendToAll(main.getLang(lang.MadGuardianInfoLong));
if(main.JesterCount > 0) main.SendToAll(main.getLang(lang.JesterInfoLong));
if(main.TerroristCount > 0) main.SendToAll(main.getLang(lang.TerroristInfoLong));
if(main.OpportunistCount > 0) main.SendToAll(main.getLang(lang.OpportunistInfoLong));
if(main.BaitCount > 0) main.SendToAll(main.getLang(lang.BaitInfoLong));
if(main.MayorCount > 0) main.SendToAll(main.getLang(lang.MayorInfoLong));
if(main.SabotageMasterCount > 0) main.SendToAll(main.getLang(lang.SabotageMasterInfoLong));
if(main.SheriffCount > 0) main.SendToAll(main.getLang(lang.SheriffInfoLong));
if(main.SnitchCount > 0) main.SendToAll(main.getLang(lang.SnitchInfoLong));
// if(main.WarlockCount > 0) main.SendToAll(main.getLang(lang.WarlockInfoLong));
}
if(main.NoGameEnd){ main.SendToAll(main.getLang(lang.NoGameEndInfo)); }
}
public static void ShowActiveSettings()
{
var text = "役職:";
if(main.IsHideAndSeek)
{
if(main.FoxCount > 0 ) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.Fox),main.FoxCount);
if(main.TrollCount > 0 ) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.Troll),main.TrollCount);
main.SendToAll(text);
text = "設定:";
text += main.getLang(lang.HideAndSeek);
}else{
RoleOptionsData roleOpt = PlayerControl.GameOptions.RoleOptions;
int EngineerNum = roleOpt.GetNumPerGame(RoleTypes.Engineer);
int ShapeshifterNum = roleOpt.GetNumPerGame(RoleTypes.Shapeshifter);
int ScientistNum = roleOpt.GetNumPerGame(RoleTypes.Scientist);
int GuardianAngelNum = roleOpt.GetNumPerGame(RoleTypes.GuardianAngel);
if(ShapeshifterNum > 0) text += String.Format("\n{0}:{1}", main.getRoleName(CustomRoles.Shapeshifter), ShapeshifterNum);
if(main.VampireCount > 0) text += String.Format("\n{0}:{1}", main.getRoleName(CustomRoles.Vampire), main.VampireCount);
if(main.BountyHunterCount > 0) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.BountyHunter),main.BountyHunterCount);
if(main.WitchCount > 0) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.Witch),main.WitchCount);
if(main.MafiaCount > 0) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.Mafia),main.MafiaCount);
if(main.MadmateCount > 0) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.Madmate),main.MadmateCount);
if(main.MadGuardianCount > 0)text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.MadGuardian),main.MadGuardianCount);
if(main.JesterCount > 0) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.Jester),main.JesterCount);
if(main.OpportunistCount > 0) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.Opportunist),main.OpportunistCount);
if(main.TerroristCount > 0) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.Terrorist),main.TerroristCount);
if(EngineerNum > 0) text += String.Format("\n{0}:{1}", main.getRoleName(CustomRoles.Engineer), EngineerNum);
if(ScientistNum > 0) text += String.Format("\n{0}:{1}", main.getRoleName(CustomRoles.Scientist), ScientistNum);
if(main.BaitCount > 0) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.Bait),main.BaitCount);
if(main.MayorCount > 0) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.Mayor),main.MayorCount);
if(main.SabotageMasterCount > 0) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.SabotageMaster),main.SabotageMasterCount);
if(main.SheriffCount > 0) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.Sheriff),main.SheriffCount);
if(main.SnitchCount > 0) text += String.Format("\n{0}:{1}",main.getRoleName(CustomRoles.Snitch),main.SnitchCount);
if(GuardianAngelNum > 0) text += String.Format("\n{0}:{1}", main.getRoleName(CustomRoles.GuardianAngel), GuardianAngelNum);
main.SendToAll(text);
text = "設定:";
if(main.VampireCount > 0) text += String.Format("\n{0}:{1}",main.getLang(lang.VampireKillDelay),main.VampireKillDelay);
if(main.SabotageMasterCount > 0)
{
if(main.SabotageMasterSkillLimit > 0) text += String.Format("\n{0}:{1}",main.getLang(lang.SabotageMasterSkillLimit),main.SabotageMasterSkillLimit);
if(main.SabotageMasterFixesDoors) text += String.Format("\n{0}:{1}",main.getLang(lang.SabotageMasterFixesDoors),getOnOff(main.SabotageMasterFixesDoors));
if(main.SabotageMasterFixesReactors) text += String.Format("\n{0}:{1}",main.getLang(lang.SabotageMasterFixesReactors),getOnOff(main.SabotageMasterFixesReactors));
if(main.SabotageMasterFixesOxygens) text += String.Format("\n{0}:{1}",main.getLang(lang.SabotageMasterFixesOxygens),getOnOff(main.SabotageMasterFixesOxygens));
if(main.SabotageMasterFixesCommunications) text += String.Format("\n{0}:{1}",main.getLang(lang.SabotageMasterFixesCommunications),getOnOff(main.SabotageMasterFixesCommunications));
if(main.SabotageMasterFixesElectrical) text += String.Format("\n{0}:{1}",main.getLang(lang.SabotageMasterFixesElectrical),getOnOff(main.SabotageMasterFixesElectrical));
}
if (main.SheriffCount > 0)
{
text += String.Format("\n{0}:{1}",main.getLang(lang.SheriffKillCooldown),main.SheriffKillCooldown);
if (main.SheriffCanKillJester) text += String.Format("\n{0}:{1}", main.getLang(lang.SheriffCanKillJester), getOnOff(main.SheriffCanKillJester));
if (main.SheriffCanKillTerrorist) text += String.Format("\n{0}:{1}", main.getLang(lang.SheriffCanKillTerrorist), getOnOff(main.SheriffCanKillTerrorist));
if (main.SheriffCanKillOpportunist) text += String.Format("\n{0}:{1}", main.getLang(lang.SheriffCanKillOpportunist), getOnOff(main.SheriffCanKillOpportunist));
if (main.SheriffCanKillMadmate) text += String.Format("\n{0}:{1}", main.getLang(lang.SheriffCanKillMadmate), getOnOff(main.SheriffCanKillMadmate));
}
if(main.MadGuardianCount > 0 || main.MadmateCount > 0)
{
if(main.MadmateCanFixLightsOut) text += String.Format("\n{0}:{1}",main.getLang(lang.MadmateCanFixLightsOut),getOnOff(main.MadmateCanFixLightsOut));
if(main.MadmateCanFixComms) text += String.Format("\n{0}:{1}", main.getLang(lang.MadmateCanFixComms), getOnOff(main.MadmateCanFixComms));
if(main.MadmateHasImpostorVision) text += String.Format("\n{0}:{1}", main.getLang(lang.MadmateHasImpostorVision), getOnOff(main.MadmateHasImpostorVision));
}
if(main.MadGuardianCount > 0)
{
if(main.MadGuardianCanSeeWhoTriedToKill) text += String.Format("\n{0}:{1}",main.getLang(lang.MadGuardianCanSeeWhoTriedToKill),getOnOff(main.MadGuardianCanSeeWhoTriedToKill));
}
if(main.MayorCount > 0) text += String.Format("\n{0}:{1}",main.getLang(lang.MayorAdditionalVote),main.MayorAdditionalVote);
if(main.SyncButtonMode) text += String.Format("\n{0}:{1}",main.getLang(lang.SyncedButtonCount),main.SyncedButtonCount);
if(main.whenSkipVote != VoteMode.Default) text += String.Format("\n{0}:{1}",main.getLang(lang.WhenSkipVote),main.whenSkipVote);
if(main.whenNonVote != VoteMode.Default) text += String.Format("\n{0}:{1}",main.getLang(lang.WhenNonVote),main.whenNonVote);
if((main.whenNonVote == VoteMode.Suicide || main.whenSkipVote == VoteMode.Suicide) && main.TerroristCount > 0) text += String.Format("\n{0}:{1}",main.getLang(lang.CanTerroristSuicideWin),main.canTerroristSuicideWin);
}
if(main.NoGameEnd)text += String.Format("\n{0,-14}",lang.NoGameEnd);
main.SendToAll(text);
}
public static void ShowLastRoles()
{
if (AmongUsClient.Instance.IsGameStarted)
{
main.SendToAll("試合中に/lastrolesを使用することはできません。");
return;
}
var text = getLang(lang.LastResult);
Dictionary<byte,CustomRoles> cloneRoles = new(AllPlayerCustomRoles);
foreach(var id in winnerList)
{
text += $"\n★ {AllPlayerNames[id]}:{main.getRoleName(AllPlayerCustomRoles[id])}";
text += $" {main.getDeathReason(ps.deathReasons[id])}";
cloneRoles.Remove(id);
}
foreach (var kvp in cloneRoles)
{
var id = kvp.Key;
text += $"\n {AllPlayerNames[id]} : {main.getRoleName(AllPlayerCustomRoles[id])}";
text += $" {main.getDeathReason(ps.deathReasons[id])}";
}
main.SendToAll(text);
}
public static void ShowHelp()
{
main.SendToAll(
"コマンド一覧:"
+"\n/winner - 勝者を表示"
+"\n/lastroles - 最後の役職割り当てを表示"
+"\n/rename - ホストの名前を変更"
+"\n/now - 現在有効な設定を表示"
+"\n/h now - 現在有効な設定の説明を表示"
+"\n/h roles <役職名> - 役職の説明を表示"
+"\n/h modes <モード名> - モードの説明を表示"
+"\n/dump - デスクトップにログを出力"
);
}
public static string getVoteName(int num)
{
string name = "invalid";
var player = getPlayerById(num);
if(num < 15 && player != null) name = player.getRealName();
if(num == 253) name = "Skip";
if(num == 254) name = "None";
if(num == 255) name = "Dead";
return name;
}
public static Dictionary<byte, string> RealNames;
public static string getOnOff(bool value) => value ? "ON" : "OFF";
public static string TextCursor => TextCursorVisible ? "_" : "";
public static bool TextCursorVisible;
public static float TextCursorTimer;
//Enabled Role
public static int JesterCount;
public static int MadmateCount;
public static int BaitCount;
public static int TerroristCount;
public static int MafiaCount;
public static int VampireCount;
public static int SabotageMasterCount;
public static int MadGuardianCount;
public static int MayorCount;
public static int OpportunistCount;
public static int SheriffCount;
public static int SnitchCount;
public static int BountyHunterCount;
public static int WitchCount;
public static int FoxCount;
public static int TrollCount;
public static Dictionary<byte, (byte, float)> BitPlayers = new Dictionary<byte, (byte, float)>();
public static Dictionary<byte, PlayerControl> BountyTargets;
public static List <PlayerControl> SpelledPlayer = new List<PlayerControl>();
public static Dictionary<byte, bool> KillOrSpell = new Dictionary<byte, bool>();
public static bool witchMeeting;
public static byte ExiledJesterID;
public static byte WonTerroristID;
public static bool CustomWinTrigger;
public static bool VisibleTasksCount;
public static int VampireKillDelay = 10;
public static int SabotageMasterSkillLimit = 0;
public static bool SabotageMasterFixesDoors;
public static bool SabotageMasterFixesReactors;
public static bool SabotageMasterFixesOxygens;
public static bool SabotageMasterFixesCommunications;
public static bool SabotageMasterFixesElectrical;
public static int SabotageMasterUsedSkillCount;
public static int SheriffKillCooldown;
public static bool SheriffCanKillJester;
public static bool SheriffCanKillTerrorist;
public static bool SheriffCanKillOpportunist;
public static bool SheriffCanKillMadmate;
public static int MayorAdditionalVote;
public static int SnitchExposeTaskLeft;
public static bool MadmateCanFixLightsOut;
public static bool MadmateCanFixComms;
public static bool MadmateHasImpostorVision;
public static bool MadGuardianCanSeeWhoTriedToKill;
public static OverrideTasksData MadGuardianTasksData;
public static OverrideTasksData TerroristTasksData;
public static OverrideTasksData SnitchTasksData;
public class OverrideTasksData {
public CustomRoles TargetRole;
public bool doOverride;
public bool hasCommonTasks;
public int NumLongTasks;
public int NumShortTasks;
public void CheckAndSet(
CustomRoles currentTargetRole,
ref bool doOverride,
ref bool hasCommonTasks,
ref int NumLongTasks,
ref int NumShortTasks
) {
if(currentTargetRole == this.TargetRole && this.doOverride) {
doOverride = true;
hasCommonTasks = this.hasCommonTasks;
NumLongTasks = this.NumLongTasks;
NumShortTasks = this.NumShortTasks;
}
}
public void Serialize(MessageWriter writer) {
writer.Write(doOverride);
writer.Write(hasCommonTasks);
writer.Write(NumLongTasks);
writer.Write(NumShortTasks);
}
public static OverrideTasksData Deserialize(MessageReader reader, CustomRoles targetRole) {
OverrideTasksData data = new OverrideTasksData(targetRole);
data.doOverride = reader.ReadBoolean();
data.hasCommonTasks = reader.ReadBoolean();
data.NumLongTasks = reader.ReadInt32();
data.NumShortTasks = reader.ReadInt32();
return data;
}
public OverrideTasksData(CustomRoles TargetRole) {
this.TargetRole = TargetRole;
doOverride = false;
hasCommonTasks = true;
NumLongTasks = 1;
NumShortTasks = 1;
}
}
public static SuffixModes currentSuffix;
public static string nickName = "";
//SyncCustomSettingsRPC Sender
public static void SyncCustomSettingsRPC()
{
if (!AmongUsClient.Instance.AmHost) return;
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, 80, Hazel.SendOption.Reliable, -1);
writer.Write(JesterCount);
writer.Write(MadmateCount);
writer.Write(BaitCount);
writer.Write(TerroristCount);
writer.Write(MafiaCount);
writer.Write(VampireCount);
writer.Write(SabotageMasterCount);
writer.Write(MadGuardianCount);
writer.Write(MayorCount);
writer.Write(OpportunistCount);
writer.Write(SnitchCount);
writer.Write(SheriffCount);
writer.Write(BountyHunterCount);
writer.Write(WitchCount);
writer.Write(FoxCount);
writer.Write(TrollCount);
writer.Write(IsHideAndSeek);
writer.Write(NoGameEnd);
writer.Write(DisableSwipeCard);
writer.Write(DisableSubmitScan);
writer.Write(DisableUnlockSafe);
writer.Write(DisableUploadData);
writer.Write(DisableStartReactor);
writer.Write(VampireKillDelay);
writer.Write(SabotageMasterSkillLimit);
writer.Write(SabotageMasterFixesDoors);
writer.Write(SabotageMasterFixesReactors);
writer.Write(SabotageMasterFixesOxygens);
writer.Write(SabotageMasterFixesCommunications);
writer.Write(SabotageMasterFixesElectrical);
writer.Write(SheriffKillCooldown);
writer.Write(SheriffCanKillJester);
writer.Write(SheriffCanKillTerrorist);
writer.Write(SheriffCanKillOpportunist);
writer.Write(SheriffCanKillMadmate);
writer.Write(SyncButtonMode);
writer.Write(SyncedButtonCount);
writer.Write((int)whenSkipVote);
writer.Write((int)whenNonVote);
writer.Write(canTerroristSuicideWin);
writer.Write(AllowCloseDoors);
writer.Write(HideAndSeekKillDelay);
writer.Write(IgnoreVent);
writer.Write(MadmateCanFixLightsOut);
writer.Write(MadmateCanFixComms);
writer.Write(MadmateHasImpostorVision);
writer.Write(MadGuardianCanSeeWhoTriedToKill);
writer.Write(MayorAdditionalVote);
MadGuardianTasksData.Serialize(writer);
TerroristTasksData.Serialize(writer);
SnitchTasksData.Serialize(writer);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
public static void PlaySoundRPC(byte PlayerID, Sounds sound)
{
if (AmongUsClient.Instance.AmHost)
RPCProcedure.PlaySound(PlayerID, sound);
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.PlaySound, Hazel.SendOption.Reliable, -1);
writer.Write(PlayerID);
writer.Write((byte)sound);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
public static void CheckTerroristWin(GameData.PlayerInfo Terrorist)
{
if (!AmongUsClient.Instance.AmHost) return;
var isAllCompleted = true;
foreach (var task in Terrorist.Tasks)
{
if (!task.Complete) isAllCompleted = false;
}
if (isAllCompleted && (!main.ps.isSuicide(Terrorist.PlayerId) || canTerroristSuicideWin)) //タスクが完了で(自殺じゃない OR 自殺勝ちが許可)されていれば
{
foreach(var pc in PlayerControl.AllPlayerControls)
{
if (pc.isTerrorist())
{
if (main.ps.deathReasons[pc.PlayerId]==PlayerState.DeathReason.Vote)
{
//追放されたら生存
main.ps.setDeathReason(pc.PlayerId, PlayerState.DeathReason.etc);
}
else
{
//それ以外はキルされているとして自爆
main.ps.setDeathReason(pc.PlayerId, PlayerState.DeathReason.Suicide);
}
}
else if (!pc.Data.IsDead)
{
//生きているプレイヤーは爆破に巻き込まれて自爆
pc.MurderPlayer(pc);
main.ps.setDeathReason(pc.PlayerId, PlayerState.DeathReason.Bombed);
}
}
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.TerroristWin, Hazel.SendOption.Reliable, -1);
writer.Write(Terrorist.PlayerId);
AmongUsClient.Instance.FinishRpcImmediately(writer);
RPCProcedure.TerroristWin(Terrorist.PlayerId);
}
}
public static void ExileAsync(PlayerControl player)
{
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(player.NetId, (byte)RpcCalls.Exiled, Hazel.SendOption.Reliable, -1);
AmongUsClient.Instance.FinishRpcImmediately(writer);
player.Exiled();
}
public static void RpcSetRole(PlayerControl targetPlayer, PlayerControl sendTo, RoleTypes role)
{
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(targetPlayer.NetId, (byte)RpcCalls.SetRole, Hazel.SendOption.Reliable, sendTo.getClientId());
writer.Write((byte)role);
AmongUsClient.Instance.FinishRpcImmediately(writer);
}
public static void SendToAll(string text) => SendMessage(text);
public static void SendMessage(string text, byte sendTo = byte.MaxValue)
{
if (!AmongUsClient.Instance.AmHost) return;
var tmp_text = text.Replace("#","#");
string[] textList = tmp_text.Split('\n');
string tmp = "";
var l = 0;
foreach(string t in textList)
{
if(tmp.Length+t.Length < 120 && l < 4){
tmp += t+"\n";
l++;
}else{
MessagesToSend.Add((tmp, sendTo));
tmp = t+"\n";
l = 1;
}
}
if(tmp.Length != 0) MessagesToSend.Add((tmp, sendTo));
}
public static void ApplySuffix() {
if(!AmongUsClient.Instance.AmHost) return;
string name = SaveManager.PlayerName;
if(nickName != "") name = nickName;
if(!AmongUsClient.Instance.IsGameStarted)
{
switch(currentSuffix)
{
case SuffixModes.None:
break;
case SuffixModes.TOH:
name += "\r\n<color=" + modColor + ">TOH v" + PluginVersion + "</color>";
break;
case SuffixModes.Streaming:
name += "\r\n配信中";
break;
case SuffixModes.Recording:
name += "\r\n録画中";
break;
}
}
if(name != PlayerControl.LocalPlayer.name && PlayerControl.LocalPlayer.CurrentOutfitType == PlayerOutfitType.Default) PlayerControl.LocalPlayer.RpcSetName(name);
}
public static PlayerControl getPlayerById(int PlayerId) {
return PlayerControl.AllPlayerControls.ToArray().Where(pc => pc.PlayerId == PlayerId).FirstOrDefault();
}
public static void NotifyRoles(bool isMeeting = false) {
if(!AmongUsClient.Instance.AmHost) return;
if(PlayerControl.AllPlayerControls == null) return;
var caller = new System.Diagnostics.StackFrame(1, false);
var callerMethod = caller.GetMethod();
string callerMethodName = callerMethod.Name;
string callerClassName = callerMethod.DeclaringType.FullName;
TownOfHost.Logger.info(callerClassName + "." + callerMethodName + "から呼び出されました","NotifyRoles");
HudManagerPatch.NowCallNotifyRolesCount++;
HudManagerPatch.LastSetNameDesyncCount = 0;
//Snitch警告表示のON/OFF
bool ShowSnitchWarning = false;
if(SnitchCount > 0) foreach(var snitch in PlayerControl.AllPlayerControls) {
if(snitch.isSnitch() && !snitch.Data.IsDead && !snitch.Data.Disconnected) {
var taskState = snitch.getPlayerTaskState();
if(taskState.doExpose)
ShowSnitchWarning = true;
}
}
//seer:ここで行われた変更を見ることができるプレイヤー
//target:seerが見ることができる変更の対象となるプレイヤー
foreach(var seer in PlayerControl.AllPlayerControls) {
string fontSize = "1.5";
if(isMeeting && (seer.getClient().PlatformData.Platform.ToString() == "Playstation" || seer.getClient().PlatformData.Platform.ToString() == "Switch")) fontSize = "70%";
TownOfHost.Logger.info("Loop1-" + seer.name + ":START","NotifyRoles");
//Loop1-bottleのSTART-END間でKeyNotFoundException
//seerが落ちているときに何もしない
if(seer.Data.Disconnected) continue;
//seerがタスクを持っている:タスク残量の色コードなどを含むテキスト
//seerがタスクを持っていない:空
string SelfTaskText = hasTasks(seer.Data, false) ? $"<color=#ffff00>({main.getTaskText(seer.Data.Tasks)})</color>" : "";
//Loversのハートマークなどを入れてください。
string SelfMark = "";
//インポスターに対するSnitch警告
if(ShowSnitchWarning && seer.getCustomRole().isImpostor())
SelfMark += $"<color={main.getRoleColorCode(CustomRoles.Snitch)}>★</color>";
//呪われている場合
if(SpelledPlayer.Find(x => x.PlayerId == seer.PlayerId) != null && isMeeting)
SelfMark += "<color=#ff0000>†</color>";
//Markとは違い、改行してから追記されます。
string SelfSuffix = "";
if(seer.isBountyHunter() && seer.getBountyTarget() != null) {
string BountyTargetName = seer.getBountyTarget().getRealName(isMeeting);
SelfSuffix = $"<size={fontSize}>Target:{BountyTargetName}</size>";
}
if(seer.isWitch()) {
if(seer.GetKillOrSpell() == false) SelfSuffix = "Mode:" + main.getLang(lang.WitchModeKill);
if(seer.GetKillOrSpell() == true) SelfSuffix = "Mode:" + main.getLang(lang.WitchModeSpell);
}
//RealNameを取得 なければ現在の名前をRealNamesに書き込む
string SeerRealName = seer.getRealName(isMeeting);
//seerの役職名とSelfTaskTextとseerのプレイヤー名とSelfMarkを合成
string SelfName = $"<size={fontSize}><color={seer.getRoleColorCode()}>{seer.getRoleName()}</color>{SelfTaskText}</size>\r\n<color={seer.getRoleColorCode()}>{SeerRealName}</color>{SelfMark}";
SelfName += SelfSuffix == "" ? "" : "\r\n" + SelfSuffix;
//適用
seer.RpcSetNamePrivate(SelfName, true);
HudManagerPatch.LastSetNameDesyncCount++;
//他人用の変数定義
bool SeerKnowsImpostors = false; //trueの時、インポスターの名前が赤色に見える
//タスクを終えたSnitchがインポスターを確認できる
if(seer.isSnitch()) {
var TaskState = seer.getPlayerTaskState();
if(TaskState.isTaskFinished)
SeerKnowsImpostors = true;
}
//二週目のループを実行するかどうかを決める処理
//このリストに入ってあるいずれかのFuncがtrueを返したとき、そのプレイヤーをtargetとしたループを実行する
//このリストの中身が空の時、foreach自体が実行されなくなる
List<Func<PlayerControl, bool>> conditions = new List<Func<PlayerControl, bool>>();
//seerが死んでいる
if(seer.Data.IsDead)
//常時
conditions.Add(target => true);
//呪われている人が居るなら
if(main.SpelledPlayer.Count > 0)
//常時
conditions.Add(target => true);
//seerがインポスターを知っている
if(SeerKnowsImpostors)
//targetがインポスター
conditions.Add(target => target.getCustomRole().isImpostor());
//seerがインポスターで、タスクが終わりそうなSnitchがいる
if(seer.getCustomRole().isImpostor() && ShowSnitchWarning)
//targetがSnitch
conditions.Add(target => target.isSnitch());
//seer視点用の名前色データが一つ以上ある
if(NameColorManager.Instance.GetDatasBySeer(seer.PlayerId).Count > 0)
//seer視点用のtargetに対する名前色データが存在する
conditions.Add(target => NameColorManager.Instance.GetData(seer.PlayerId, target.PlayerId).color != null);
//seerが死んでいる場合など、必要なときのみ第二ループを実行する
if(conditions.Count > 0) foreach(var target in PlayerControl.AllPlayerControls) {
//targetがseer自身の場合は何もしない
if(target == seer) continue;
//conditions内のデータによる判定
bool doCancel = true;
foreach(var func in conditions) {
if(func(target)) {
doCancel = false;
break;
}
}
if(doCancel) continue;
TownOfHost.Logger.info("Loop2-" + target.name + ":START","NotifyRoles");
//他人のタスクはtargetがタスクを持っているかつ、seerが死んでいる場合のみ表示されます。それ以外の場合は空になります。
string TargetTaskText = hasTasks(target.Data, false) && seer.Data.IsDead ? $"<color=#ffff00>({main.getTaskText(target.Data.Tasks)})</color>" : "";
//Loversのハートマークなどを入れてください。
string TargetMark = "";
//呪われている人
if(SpelledPlayer.Find(x => x.PlayerId == target.PlayerId) != null && isMeeting)
TargetMark += "<color=#ff0000>†</color>";
//タスク完了直前のSnitchにマークを表示
if(target.isSnitch() && seer.getCustomRole().isImpostor()) {
var taskState = target.getPlayerTaskState();
if(taskState.doExpose)
TargetMark += $"<color={main.getRoleColorCode(CustomRoles.Snitch)}>★</color>";
}
//他人の役職とタスクはtargetがタスクを持っているかつ、seerが死んでいる場合のみ表示されます。それ以外の場合は空になります。
string TargetRoleText = seer.Data.IsDead ? $"<size={fontSize}><color={target.getRoleColorCode()}>{target.getRoleName()}</color>{TargetTaskText}</size>\r\n" : "";
//RealNameを取得 なければ現在の名前をRealNamesに書き込む
string TargetPlayerName = target.getRealName(isMeeting);
//ターゲットのプレイヤー名の色を書き換えます。
if(SeerKnowsImpostors && target.getCustomRole().isImpostor()) //Seerがインポスターが誰かわかる状態
TargetPlayerName = "<color=#ff0000>" + TargetPlayerName + "</color>";
else {//NameColorManager準拠の処理
var ncd = NameColorManager.Instance.GetData(seer.PlayerId, target.PlayerId);
TargetPlayerName = ncd.OpenTag + TargetPlayerName + ncd.CloseTag;
}
//全てのテキストを合成します。
string TargetName = $"{TargetRoleText}{TargetPlayerName}{TargetMark}";
//適用
target.RpcSetNamePrivate(TargetName, true, seer);
HudManagerPatch.LastSetNameDesyncCount++;
TownOfHost.Logger.info("Loop2-" + target.name + ":END","NotifyRoles");
}
TownOfHost.Logger.info("Loop1-" + seer.name + ":END","NotifyRoles");
}
main.witchMeeting = false;
}
public static void CustomSyncAllSettings() {
foreach(var pc in PlayerControl.AllPlayerControls) {
pc.CustomSyncSettings();
}
}
public static void ChangeInt(ref int ChangeTo, int input, int max) {
var tmp = ChangeTo * 10;
tmp += input;
ChangeTo = Math.Clamp(tmp,0,max);
}
public override void Load()
{
TextCursorTimer = 0f;
TextCursorVisible = true;
//Client Options
HideCodes = Config.Bind("Client Options", "Hide Game Codes", false);
HideName = Config.Bind("Client Options", "Hide Game Code Name", "Town Of Host");
HideColor = Config.Bind("Client Options", "Hide Game Code Color", $"{main.modColor}");
JapaneseRoleName = Config.Bind("Client Options", "Japanese Role Name", false);
Logger = BepInEx.Logging.Logger.CreateLogSource("TownOfHost");
TownOfHost.Logger.enable();
TownOfHost.Logger.disable("NotifyRoles");
TownOfHost.Logger.disable("getPlayerTaskState");
TownOfHost.Logger.disable("SetNameRPC");
currentWinner = CustomWinner.Default;
additionalwinners = new HashSet<AdditionalWinners>();
RealNames = new Dictionary<byte, string>();
IsHideAndSeek = false;
AllowCloseDoors = false;
IgnoreVent = false;
IgnoreCosmetics = false;
HideAndSeekKillDelay = 30;
HideAndSeekKillDelayTimer = 0f;
HideAndSeekImpVisionMin = 0.25f;
TrollCount = 0;
FoxCount = 0;
AllPlayerCustomRoles = new Dictionary<byte, CustomRoles>();
SyncButtonMode = false;
SyncedButtonCount = 10;
UsedButtonCount = 0;
whenSkipVote = VoteMode.Default;
whenNonVote = VoteMode.Default;
canTerroristSuicideWin = false;
NoGameEnd = false;
CustomWinTrigger = false;
OptionControllerIsEnable = false;
BitPlayers = new Dictionary<byte, (byte, float)>();
BountyTargets = new Dictionary<byte, PlayerControl>();
SpelledPlayer = new List<PlayerControl>();
winnerList = new();
VisibleTasksCount = false;
MessagesToSend = new List<(string, byte)>();
DisableSwipeCard = false;
DisableSubmitScan = false;
DisableUnlockSafe = false;
DisableUploadData = false;
DisableStartReactor = false;
VampireKillDelay = 10;
SabotageMasterSkillLimit = 0;
SabotageMasterFixesDoors = false;
SabotageMasterFixesReactors = true;
SabotageMasterFixesOxygens = true;