-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathmain.cs
319 lines (293 loc) · 13.6 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using AmongUs.GameOptions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using UnityEngine;
using TownOfHost.Attributes;
using TownOfHost.Roles.Core;
using TownOfHost.Modules;
[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 = "5.1.9";
// サポートされている最低のAmongUsバージョン
public static readonly string LowestSupportedVersion = "2024.8.13";
// このバージョンのみで公開ルームを無効にする場合
public static readonly bool IsPublicAvailableOnThisVersion = false;
// プレリリースかどうか
public static bool IsPrerelease { get; } = false;
public Harmony Harmony { get; } = new Harmony(PluginGuid);
public static Version version = Version.Parse(PluginVersion);
public static Color UnityModColor
{
get
{
if (!_unityModColor.HasValue)
{
if (ColorUtility.TryParseHtmlString(ModColor, out var unityColor))
{
_unityModColor = unityColor;
}
else
{
// failure
return Color.gray;
}
}
return _unityModColor.Value;
}
}
private static Color? _unityModColor;
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 NormalGameOptionsV08 NormalOptions => GameOptionsManager.Instance.currentNormalGameOptions;
public static HideNSeekGameOptionsV08 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 ConfigEntry<bool> ShowResults { 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, string> AllPlayerNames;
public static Dictionary<(byte, byte), string> LastNotifyNames;
public static Dictionary<byte, Color32> PlayerColors = new();
public static Dictionary<byte, CustomDeathReason> AfterMeetingDeathPlayers = new();
public static Dictionary<CustomRoles, string> roleColors;
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 int AliveImpostorCount;
public static int SKMadmateNowCount;
public static Dictionary<byte, bool> CheckShapeshift = new();
public static Dictionary<byte, byte> ShapeshiftTarget = new();
public static bool VisibleTasksCount;
public static string nickName = "";
public static bool introDestroyed = false;
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 const float RoleTextSize = 2f;
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", "");
ShowResults = Config.Bind("Result", "Show Results", true);
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);
winnerList = new();
VisibleTasksCount = false;
MessagesToSend = new List<(string, byte, string)>();
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);
PluginModuleInitializerAttribute.InitializeAll();
IRandom.SetInstance(new NetRandomWrapper());
hasArgumentException = false;
ExceptionMessage = "";
try
{
roleColors = new Dictionary<CustomRoles, string>()
{
// マッドメイト役職
{CustomRoles.SKMadmate, "#ff1919"},
//特殊クルー役職
//HideAndSeek
{CustomRoles.HASFox, "#e478ff"},
{CustomRoles.HASTroll, "#00ff00"},
// GM
{CustomRoles.GM, "#ff5b70"},
//サブ役職
{CustomRoles.LastImpostor, "#ff1919"},
{CustomRoles.Lovers, "#ff6be4"},
{CustomRoles.Watcher, "#800080"},
{CustomRoles.Workhorse, "#00ffff"},
{CustomRoles.NotAssigned, "#ffffff"}
};
var type = typeof(RoleBase);
var roleClassArray =
CustomRoleManager.AllRolesClassType = Assembly.GetAssembly(type)
.GetTypes()
.Where(x => x.IsSubclassOf(type)).ToArray();
foreach (var roleClassType in roleClassArray)
roleClassType.GetField("RoleInfo")?.GetValue(type);
}
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");
var handler = TownOfHost.Logger.Handler("GitVersion");
handler.Info($"{nameof(ThisAssembly.Git.Branch)}: {ThisAssembly.Git.Branch}");
handler.Info($"{nameof(ThisAssembly.Git.BaseTag)}: {ThisAssembly.Git.BaseTag}");
handler.Info($"{nameof(ThisAssembly.Git.Commit)}: {ThisAssembly.Git.Commit}");
handler.Info($"{nameof(ThisAssembly.Git.Commits)}: {ThisAssembly.Git.Commits}");
handler.Info($"{nameof(ThisAssembly.Git.IsDirty)}: {ThisAssembly.Git.IsDirty}");
handler.Info($"{nameof(ThisAssembly.Git.Sha)}: {ThisAssembly.Git.Sha}");
handler.Info($"{nameof(ThisAssembly.Git.Tag)}: {ThisAssembly.Git.Tag}");
ClassInjector.RegisterTypeInIl2Cpp<ErrorText>();
SystemEnvironment.SetEnvironmentVariables();
Harmony.PatchAll();
Application.quitting += new Action(Utils.SaveNowLog);
}
}
public enum CustomDeathReason
{
Kill,
Vote,
Suicide,
Spell,
FollowingSuicide,
Bite,
Bombed,
Misfire,
Torched,
Sniped,
Revenge,
Execution,
Infected,
Disconnected,
Fall,
etc = -1
}
//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,
PlagueDoctor = CustomRoles.PlagueDoctor,
HASTroll = CustomRoles.HASTroll,
}
/*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
}
}