From 68bf8b9f6b919d44b950b9a796c04a8a34df1c84 Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Thu, 15 Feb 2024 16:40:09 +0100 Subject: [PATCH] Remove a few usings and unused parameters --- Modules/CustomRpcSender.cs | 1 + Modules/ExtendedPlayerControl.cs | 2 +- Modules/ModUpdater.cs | 588 +++++++++++++++--------------- Modules/Translator.cs | 4 +- Modules/Utils.cs | 2 +- Patches/AirShipElectricalDoors.cs | 2 +- Patches/AnnouncementPatch.cs | 2 +- Patches/ClientPatch.cs | 6 +- Patches/DisconnectPatch.cs | 2 +- Patches/GameManagerPatch.cs | 2 +- Patches/LadderPatch.cs | 2 +- Patches/LobbyListPatch.cs | 2 +- Patches/PlayerContorolPatch.cs | 2 +- Patches/TaskAssignPatch.cs | 4 +- Roles/AddOns/Common/Asthmatic.cs | 15 +- Roles/AddOns/Crewmate/Stressed.cs | 14 +- Roles/AddOns/Impostor/Damocles.cs | 10 +- Roles/Crewmate/Addict.cs | 2 +- Roles/Crewmate/Aid.cs | 28 +- Roles/Crewmate/Analyzer.cs | 25 +- Roles/Crewmate/Benefactor.cs | 22 +- Roles/Crewmate/CameraMan.cs | 9 +- Roles/Crewmate/Doormaster.cs | 7 +- Roles/Crewmate/Escort.cs | 16 +- Roles/Crewmate/Ricochet.cs | 11 +- Roles/Crewmate/Tether.cs | 11 +- Roles/Impostor/Consort.cs | 12 +- Roles/Impostor/RiftMaker.cs | 13 +- Roles/Impostor/Twister.cs | 4 +- Roles/Neutral/Magician.cs | 4 +- TOHE.csproj | 53 ++- 31 files changed, 428 insertions(+), 449 deletions(-) diff --git a/Modules/CustomRpcSender.cs b/Modules/CustomRpcSender.cs index 9d19ff54c..7f12bc0f6 100644 --- a/Modules/CustomRpcSender.cs +++ b/Modules/CustomRpcSender.cs @@ -83,6 +83,7 @@ public class CustomRpcSender currentState = State.InRootMessage; return this; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "")] public CustomRpcSender EndMessage(int targetClientId = -1) { if (currentState != State.InRootMessage) diff --git a/Modules/ExtendedPlayerControl.cs b/Modules/ExtendedPlayerControl.cs index f88791e6e..0adde8866 100644 --- a/Modules/ExtendedPlayerControl.cs +++ b/Modules/ExtendedPlayerControl.cs @@ -1538,5 +1538,5 @@ static class ExtendedPlayerControl ///Is the player currently protected public static bool IsProtected(this PlayerControl self) => self.protectedByGuardianId > -1; - public const MurderResultFlags ResultFlags = MurderResultFlags.Succeeded | MurderResultFlags.DecisionByHost; + public const MurderResultFlags ResultFlags = MurderResultFlags.Succeeded; } \ No newline at end of file diff --git a/Modules/ModUpdater.cs b/Modules/ModUpdater.cs index 724406a86..4fd377cdb 100644 --- a/Modules/ModUpdater.cs +++ b/Modules/ModUpdater.cs @@ -1,305 +1,305 @@ -using HarmonyLib; -using Newtonsoft.Json.Linq; -using System; -using System.IO; -using System.IO.Compression; -using System.Net.Http; -using System.Reflection; -using System.Threading.Tasks; -using UnityEngine; -using static TOHE.Translator; - -namespace TOHE; - -[HarmonyPatch] -public class ModUpdater -{ - private static readonly string URL_Github = "https://api.github.com/repos/Gurge44/TOHE_PLUS"; - public static bool hasUpdate = false; - public static bool hasOutdate = false; - public static bool forceUpdate = false; - public static bool isBroken = false; - public static bool isChecked = false; - public static Version latestVersion = null; - public static string latestTitle = null; - public static string downloadUrl = null; - public static string notice = null; - public static GenericPopup InfoPopup; - - [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start)), HarmonyPrefix] - [HarmonyPriority(2)] - public static void Start_Prefix() - { - NewVersionCheck(); - DeleteOldFiles(); - InfoPopup = UnityEngine.Object.Instantiate(Twitch.TwitchManager.Instance.TwitchPopup); - InfoPopup.name = "InfoPopup"; - InfoPopup.TextAreaTMP.GetComponent().sizeDelta = new(2.5f, 2f); - if (!isChecked) +using HarmonyLib; +using Newtonsoft.Json.Linq; +using System; +using System.IO; +using System.IO.Compression; +using System.Net.Http; +using System.Reflection; +using System.Threading.Tasks; +using UnityEngine; +using static TOHE.Translator; + +namespace TOHE; + +[HarmonyPatch] +public class ModUpdater +{ + private static readonly string URL_Github = "https://api.github.com/repos/Gurge44/TOHE_PLUS"; + public static bool hasUpdate = false; + public static bool hasOutdate = false; + public static bool forceUpdate = false; + public static bool isBroken = false; + public static bool isChecked = false; + public static Version latestVersion = null; + public static string latestTitle = null; + public static string downloadUrl = null; + public static string notice = null; + public static GenericPopup InfoPopup; + + [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start)), HarmonyPrefix] + [HarmonyPriority(2)] + public static void Start_Prefix() + { + NewVersionCheck(); + DeleteOldFiles(); + InfoPopup = UnityEngine.Object.Instantiate(Twitch.TwitchManager.Instance.TwitchPopup); + InfoPopup.name = "InfoPopup"; + InfoPopup.TextAreaTMP.GetComponent().sizeDelta = new(2.5f, 2f); + if (!isChecked) { bool done = CheckReleaseFromGithub(Main.BetaBuildURL.Value != "").GetAwaiter().GetResult(); - Logger.Warn("done: " + done, "CheckRelease"); - Logger.Info("hasupdate: " + hasUpdate, "CheckRelease"); - Logger.Info("forceupdate: " + forceUpdate, "CheckRelease"); - Logger.Info("downloadUrl: " + downloadUrl, "CheckRelease"); - Logger.Info("latestVersionl: " + latestVersion, "CheckRelease"); - } - } - - public static string Get(string url) - { - string result = ""; - HttpClient req = new(); - var res = req.GetAsync(url).Result; - Stream stream = res.Content.ReadAsStreamAsync().Result; - try - { - using StreamReader reader = new(stream); - result = reader.ReadToEnd(); - } - finally - { - stream.Close(); - } - return result; - } - public static async Task CheckReleaseFromGithub(bool beta = false) - { - Logger.Warn("Checking GitHub Release", "CheckRelease"); - string url = URL_Github + "/releases/latest"; - try - { - string result; - using (HttpClient client = new()) - { - client.DefaultRequestHeaders.Add("User-Agent", "TOHE+ Updater"); - using var response = await client.GetAsync(new Uri(url), HttpCompletionOption.ResponseContentRead); - if (!response.IsSuccessStatusCode || response.Content == null) - { - Logger.Error($"Response Status Code: {response.StatusCode}", "CheckRelease"); - return false; - } - result = await response.Content.ReadAsStringAsync(); - } - JObject data = JObject.Parse(result); - if (beta) - { - latestTitle = data["name"].ToString(); - downloadUrl = data["url"].ToString(); - hasUpdate = latestTitle != ThisAssembly.Git.Commit; - } - else - { - latestVersion = new(data["tag_name"]?.ToString().TrimStart('v')); - latestTitle = $"Ver. {latestVersion}"; - JArray assets = data["assets"].Cast(); - //Logger.Info(assets.ToString(), "ModUpdater"); - for (int i = 0; i < assets.Count; i++) - { - if (assets[i]["name"].ToString() == $"TOHE-PLUS.v{latestVersion}.zip") - { - downloadUrl = assets[i]["browser_download_url"].ToString(); - break; - } - } - hasUpdate = latestVersion.CompareTo(Main.version) > 0; - hasOutdate = latestVersion.CompareTo(Main.version) < 0; - } - - Logger.Info("hasupdate: " + hasUpdate, "GitHub"); - Logger.Info("hasoutdate: " + hasOutdate, "GitHub"); - Logger.Info("forceupdate: " + forceUpdate, "GitHub"); - Logger.Info("downloadUrl: " + downloadUrl, "GitHub"); - Logger.Info("latestVersionl: " + latestVersion, "GitHub"); - Logger.Info("latestTitle: " + latestTitle, "GitHub"); - - if (downloadUrl == null || downloadUrl == "") - { - Logger.Error("No Download URL", "CheckRelease"); - return false; - } - isChecked = true; - isBroken = false; - } - catch (Exception ex) - { - isBroken = true; - Logger.Error($"Error while checking release from GitHub:\n{ex}", "CheckRelease", false); - return false; - } - return true; - } - public static void StartUpdate(string url, bool github) - { - ShowPopup(GetString("updatePleaseWait"), StringNames.Cancel, true, false); - if (!github) + Logger.Warn("done: " + done, "CheckRelease"); + Logger.Info("hasupdate: " + hasUpdate, "CheckRelease"); + Logger.Info("forceupdate: " + forceUpdate, "CheckRelease"); + Logger.Info("downloadUrl: " + downloadUrl, "CheckRelease"); + Logger.Info("latestVersionl: " + latestVersion, "CheckRelease"); + } + } + + public static string Get(string url) + { + string result = ""; + HttpClient req = new(); + var res = req.GetAsync(url).Result; + Stream stream = res.Content.ReadAsStreamAsync().Result; + try { - _ = DownloadDLL(url); - } - else + using StreamReader reader = new(stream); + result = reader.ReadToEnd(); + } + finally { - _ = DownloadDLLGithub(url); - } - return; - } - public static bool NewVersionCheck() - { - try - { - var fileName = Assembly.GetExecutingAssembly().Location; - if (Directory.Exists("TOH_DATA") && File.Exists(@"./TOHE_DATA/BanWords.txt")) - { - DirectoryInfo di = new("TOH_DATA"); - di.Delete(true); - Logger.Warn("Directory deleted:TOH_DATA", "NewVersionCheck"); - } - } - catch (Exception ex) - { - Logger.Exception(ex, "NewVersionCheck"); - return false; - } - return true; - } - public static void DeleteOldFiles() - { - string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - string searchPattern = "TOHE+.dll*"; - string[] files = Directory.GetFiles(path, searchPattern); - try - { - foreach (string filePath in files) - { - if (Path.GetFileName(filePath).EndsWith(".bak") || Path.GetFileName(filePath).EndsWith(".temp")) + stream.Close(); + } + return result; + } + public static async Task CheckReleaseFromGithub(bool beta = false) + { + Logger.Warn("Checking GitHub Release", "CheckRelease"); + string url = URL_Github + "/releases/latest"; + try + { + string result; + using (HttpClient client = new()) + { + client.DefaultRequestHeaders.Add("User-Agent", "TOHE+ Updater"); + using var response = await client.GetAsync(new Uri(url), HttpCompletionOption.ResponseContentRead); + if (!response.IsSuccessStatusCode || response.Content == null) + { + Logger.Error($"Response Status Code: {response.StatusCode}", "CheckRelease"); + return false; + } + result = await response.Content.ReadAsStringAsync(); + } + JObject data = JObject.Parse(result); + if (beta) + { + latestTitle = data["name"].ToString(); + downloadUrl = data["url"].ToString(); + hasUpdate = latestTitle != ThisAssembly.Git.Commit; + } + else + { + latestVersion = new(data["tag_name"]?.ToString().TrimStart('v')); + latestTitle = $"Ver. {latestVersion}"; + JArray assets = data["assets"].Cast(); + //Logger.Info(assets.ToString(), "ModUpdater"); + for (int i = 0; i < assets.Count; i++) + { + if (assets[i]["name"].ToString() == $"TOHE-PLUS.v{latestVersion}.zip") + { + downloadUrl = assets[i]["browser_download_url"].ToString(); + break; + } + } + hasUpdate = latestVersion.CompareTo(Main.version) > 0; + hasOutdate = latestVersion.CompareTo(Main.version) < 0; + } + + Logger.Info("hasupdate: " + hasUpdate, "GitHub"); + Logger.Info("hasoutdate: " + hasOutdate, "GitHub"); + Logger.Info("forceupdate: " + forceUpdate, "GitHub"); + Logger.Info("downloadUrl: " + downloadUrl, "GitHub"); + Logger.Info("latestVersionl: " + latestVersion, "GitHub"); + Logger.Info("latestTitle: " + latestTitle, "GitHub"); + + if (downloadUrl == null || downloadUrl == "") + { + Logger.Error("No Download URL", "CheckRelease"); + return false; + } + isChecked = true; + isBroken = false; + } + catch (Exception ex) + { + isBroken = true; + Logger.Error($"Error while checking release from GitHub:\n{ex}", "CheckRelease", false); + return false; + } + return true; + } + public static void StartUpdate(string url, bool github) + { + ShowPopup(GetString("updatePleaseWait"), StringNames.Cancel, true, false); + if (!github) + { + _ = DownloadDLL(url); + } + else + { + _ = DownloadDLLGithub(url); + } + return; + } + public static bool NewVersionCheck() + { + try + { + var fileName = Assembly.GetExecutingAssembly().Location; + if (Directory.Exists("TOH_DATA") && File.Exists(@"./TOHE_DATA/BanWords.txt")) + { + DirectoryInfo di = new("TOH_DATA"); + di.Delete(true); + Logger.Warn("Directory deleted:TOH_DATA", "NewVersionCheck"); + } + } + catch (Exception ex) + { + Logger.Exception(ex, "NewVersionCheck"); + return false; + } + return true; + } + public static void DeleteOldFiles() + { + string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + string searchPattern = "TOHE+.dll*"; + string[] files = Directory.GetFiles(path, searchPattern); + try + { + foreach (string filePath in files) + { + if (Path.GetFileName(filePath).EndsWith(".bak") || Path.GetFileName(filePath).EndsWith(".temp")) { Logger.Info($"{filePath} will be deleted", "DeleteOldFiles"); - File.Delete(filePath); - } - } - } - catch (Exception e) - { - Logger.Error($"Failed to clear update residue\n{e}", "DeleteOldFiles"); - } - } - private static readonly object downloadLock = new(); - public static async Task DownloadDLL(string url) - { - try - { - var savePath = "BepInEx/plugins/TOHE+.dll.temp"; - - // Delete the temporary file if it exists - if (File.Exists(savePath)) - { - File.Delete(savePath); - } - - HttpResponseMessage response; - var downloadCallBack = DownloadCallBack; - - using (HttpClient client = new()) - { - response = await client.GetAsync(url); - } - - if (response == null || !response.IsSuccessStatusCode) - { - throw new Exception($"File retrieval failed with status code: {response?.StatusCode}"); - } - - var total = response.Content.Headers.ContentLength ?? 0; - using (var stream = await response.Content.ReadAsStreamAsync()) - using (var fileStream = new FileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true)) - { - if (downloadCallBack == null) - { - await stream.CopyToAsync(fileStream); - } - else - { - byte[] buffer = new byte[1024]; - long readLength = 0; - int length; - - while ((length = await stream.ReadAsync(buffer)) != 0) - { - await fileStream.WriteAsync(buffer.AsMemory(0, length)); - - readLength += length; - double? progress = Math.Round((double)readLength / total * 100, 2, MidpointRounding.ToZero); - } - } - } - - var fileName = Assembly.GetExecutingAssembly().Location; - File.Move(fileName, fileName + ".bak"); - File.Move(savePath, fileName); - ShowPopup(GetString("updateRestart"), StringNames.Close, true, true); - } - catch (Exception ex) - { - Logger.Error($"Update failed\n{ex}", "DownloadDLL", false); - ShowPopup(GetString("updateManually"), StringNames.Close, true, true); - return false; - } - return true; - } - public static async Task DownloadDLLGithub(string url) - { - try - { - var savePath = "BepInEx/plugins/TOHE+.dll.temp"; - - // Delete the temporary file if it exists - if (File.Exists(savePath)) - { - File.Delete(savePath); - } - - HttpResponseMessage response; - var downloadCallBack = DownloadCallBack; - - using (HttpClient client = new()) - { - response = await client.GetAsync(url); - } - - if (response == null || !response.IsSuccessStatusCode) - { - throw new Exception($"File retrieval failed with status code: {response?.StatusCode}"); - } - - var total = response.Content.Headers.ContentLength ?? 0; - using (var stream = await response.Content.ReadAsStreamAsync()) - using (var archive = new ZipArchive(stream, ZipArchiveMode.Read)) - { - // Specify the relative path within the ZIP archive where "TOHE+.dll" is located - var entryPath = "BepInEx/plugins/TOHE+.dll"; + File.Delete(filePath); + } + } + } + catch (Exception e) + { + Logger.Error($"Failed to clear update residue\n{e}", "DeleteOldFiles"); + } + } + private static readonly object downloadLock = new(); + public static async Task DownloadDLL(string url) + { + try + { + var savePath = "BepInEx/plugins/TOHE+.dll.temp"; + + // Delete the temporary file if it exists + if (File.Exists(savePath)) + { + File.Delete(savePath); + } + + HttpResponseMessage response; + var downloadCallBack = DownloadCallBack; + + using (HttpClient client = new()) + { + response = await client.GetAsync(url); + } + + if (response == null || !response.IsSuccessStatusCode) + { + throw new Exception($"File retrieval failed with status code: {response?.StatusCode}"); + } + + var total = response.Content.Headers.ContentLength ?? 0; + using (var stream = await response.Content.ReadAsStreamAsync()) + using (var fileStream = new FileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true)) + { + if (downloadCallBack == null) + { + await stream.CopyToAsync(fileStream); + } + else + { + byte[] buffer = new byte[1024]; + long readLength = 0; + int length; + + while ((length = await stream.ReadAsync(buffer)) != 0) + { + await fileStream.WriteAsync(buffer.AsMemory(0, length)); + + readLength += length; + double? progress = Math.Round((double)readLength / total * 100, 2, MidpointRounding.ToZero); + } + } + } + + var fileName = Assembly.GetExecutingAssembly().Location; + File.Move(fileName, fileName + ".bak"); + File.Move(savePath, fileName); + ShowPopup(GetString("updateRestart"), StringNames.Close, true, true); + } + catch (Exception ex) + { + Logger.Error($"Update failed\n{ex}", "DownloadDLL", false); + ShowPopup(GetString("updateManually"), StringNames.Close, true, true); + return false; + } + return true; + } + public static async Task DownloadDLLGithub(string url) + { + try + { + var savePath = "BepInEx/plugins/TOHE+.dll.temp"; + + // Delete the temporary file if it exists + if (File.Exists(savePath)) + { + File.Delete(savePath); + } + + HttpResponseMessage response; + var downloadCallBack = DownloadCallBack; + + using (HttpClient client = new()) + { + response = await client.GetAsync(url); + } + + if (response == null || !response.IsSuccessStatusCode) + { + throw new Exception($"File retrieval failed with status code: {response?.StatusCode}"); + } + + var total = response.Content.Headers.ContentLength ?? 0; + using (var stream = await response.Content.ReadAsStreamAsync()) + using (var archive = new ZipArchive(stream, ZipArchiveMode.Read)) + { + // Specify the relative path within the ZIP archive where "TOHE+.dll" is located + var entryPath = "BepInEx/plugins/TOHE+.dll"; var entry = archive.GetEntry(entryPath) ?? throw new Exception($"'{entryPath}' not found in the ZIP archive"); // Extract "TOHE+.dll" to the temporary file - using var entryStream = entry.Open(); + using var entryStream = entry.Open(); using var fileStream = new FileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true); - await entryStream.CopyToAsync(fileStream); - } - - var fileName = Assembly.GetExecutingAssembly().Location; - File.Move(fileName, fileName + ".bak"); - File.Move(savePath, fileName); - ShowPopup(GetString("updateRestart"), StringNames.Close, true, true); - } - catch (Exception ex) - { - Logger.Error($"Update failed\n{ex}", "DownloadDLL", false); - ShowPopup(GetString("updateManually"), StringNames.Close, true, true); - return false; - } - return true; - } - private static void DownloadCallBack(long total, long downloaded, double progress) { } - private static void ShowPopup(string message, StringNames buttonText, bool showButton = false, bool buttonIsExit = true) - { + await entryStream.CopyToAsync(fileStream); + } + + var fileName = Assembly.GetExecutingAssembly().Location; + File.Move(fileName, fileName + ".bak"); + File.Move(savePath, fileName); + ShowPopup(GetString("updateRestart"), StringNames.Close, true, true); + } + catch (Exception ex) + { + Logger.Error($"Update failed\n{ex}", "DownloadDLL", false); + ShowPopup(GetString("updateManually"), StringNames.Close, true, true); + return false; + } + return true; + } + private static void DownloadCallBack(long total, long downloaded, double progress) { } + private static void ShowPopup(string message, StringNames buttonText, bool showButton = false, bool buttonIsExit = true) + { if (InfoPopup == null) return; InfoPopup.Show(message); @@ -312,6 +312,6 @@ public class ModUpdater button.GetComponent().OnClick = new(); if (buttonIsExit) button.GetComponent().OnClick.AddListener((Action)(() => Application.Quit())); else button.GetComponent().OnClick.AddListener((Action)(() => InfoPopup.Close())); - } - } + } + } } \ No newline at end of file diff --git a/Modules/Translator.cs b/Modules/Translator.cs index 98f834763..bc422f4d2 100644 --- a/Modules/Translator.cs +++ b/Modules/Translator.cs @@ -85,7 +85,7 @@ public static class Translator { if (File.Exists(@$"./{LANGUAGE_FOLDER_NAME}/{lang}.dat")) { - UpdateCustomTranslation($"{lang}.dat", lang); + UpdateCustomTranslation($"{lang}.dat"/*, lang*/); LoadCustomTranslation($"{lang}.dat", lang); } } @@ -182,7 +182,7 @@ public static class Translator return SupportedLangs.English; } } - static void UpdateCustomTranslation(string filename, SupportedLangs lang) + static void UpdateCustomTranslation(string filename/*, SupportedLangs lang*/) { string path = @$"./{LANGUAGE_FOLDER_NAME}/{filename}"; if (File.Exists(path)) diff --git a/Modules/Utils.cs b/Modules/Utils.cs index 0072c8b1a..ed9705a40 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -1890,7 +1890,7 @@ public static class Utils DevUser devUser = player.FriendCode.GetDevUser(); bool isMod = ChatCommands.IsPlayerModerator(player.FriendCode); - if (!name.Contains('\r') && (devUser.HasTag() || isMod)) + if (devUser.HasTag() || isMod) { string tag = devUser.GetTag(); if (player.AmOwner || player.IsModClient()) diff --git a/Patches/AirShipElectricalDoors.cs b/Patches/AirShipElectricalDoors.cs index 21f44edc0..ea03231d7 100644 --- a/Patches/AirShipElectricalDoors.cs +++ b/Patches/AirShipElectricalDoors.cs @@ -41,7 +41,7 @@ public class AirshipElectricalDoors [HarmonyPatch(typeof(ElectricalDoors), nameof(ElectricalDoors.Initialize))] class ElectricalDoorsInitializePatch { - public static void Postfix(ElectricalDoors __instance) + public static void Postfix(/*ElectricalDoors __instance*/) { if (!GameStates.IsInGame) return; var closedoors = string.Empty; diff --git a/Patches/AnnouncementPatch.cs b/Patches/AnnouncementPatch.cs index 7ebdbae1f..5dcf760c0 100644 --- a/Patches/AnnouncementPatch.cs +++ b/Patches/AnnouncementPatch.cs @@ -98,7 +98,7 @@ public class ModNewsHistory } [HarmonyPatch(typeof(PlayerAnnouncementData), nameof(PlayerAnnouncementData.SetAnnouncements)), HarmonyPrefix] - public static bool SetModAnnouncements(PlayerAnnouncementData __instance, [HarmonyArgument(0)] ref Il2CppReferenceArray aRange) + public static bool SetModAnnouncements(/*PlayerAnnouncementData __instance,*/ [HarmonyArgument(0)] ref Il2CppReferenceArray aRange) { if (AllModNews.Count == 0) { diff --git a/Patches/ClientPatch.cs b/Patches/ClientPatch.cs index de9754800..572d6a953 100644 --- a/Patches/ClientPatch.cs +++ b/Patches/ClientPatch.cs @@ -9,7 +9,7 @@ namespace TOHE; [HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.MakePublic))] internal class MakePublicPatch { - public static bool Prefix(GameStartManager __instance) + public static bool Prefix(/*GameStartManager __instance*/) { // 定数設定による公開ルームブロック if (!Main.AllowPublicRoom) @@ -35,7 +35,7 @@ internal class MakePublicPatch [HarmonyPatch(typeof(MMOnlineManager), nameof(MMOnlineManager.Start))] internal class MMOnlineManagerStartPatch { - public static void Postfix(MMOnlineManager __instance) + public static void Postfix() { if (!((ModUpdater.hasUpdate && ModUpdater.forceUpdate) || ModUpdater.isBroken)) return; var obj = GameObject.Find("FindGameButton"); @@ -101,7 +101,7 @@ internal class InnerNetClientCanBanPatch [HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.KickPlayer))] internal class KickPlayerPatch { - public static bool Prefix(InnerNetClient __instance, int clientId, bool ban) + public static bool Prefix(/*InnerNetClient __instance,*/ int clientId, bool ban) { if (!AmongUsClient.Instance.AmHost) return true; diff --git a/Patches/DisconnectPatch.cs b/Patches/DisconnectPatch.cs index e798e3c97..f24480267 100644 --- a/Patches/DisconnectPatch.cs +++ b/Patches/DisconnectPatch.cs @@ -6,7 +6,7 @@ namespace TOHE; [HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnDisconnected))] internal class OnDisconnectedPatch { - public static void Postfix(AmongUsClient __instance) + public static void Postfix(/*AmongUsClient __instance*/) { Main.VisibleTasksCount = false; } diff --git a/Patches/GameManagerPatch.cs b/Patches/GameManagerPatch.cs index fd4dfc191..6c02bd705 100644 --- a/Patches/GameManagerPatch.cs +++ b/Patches/GameManagerPatch.cs @@ -30,7 +30,7 @@ class GameManagerSerializeFix [HarmonyPatch(typeof(LogicOptions), nameof(LogicOptions.Serialize))] class LogicOptionsSerializePatch { - public static bool Prefix(LogicOptions __instance, ref bool __result, MessageWriter writer, bool initialState) + public static bool Prefix(ref bool __result, /*MessageWriter writer,*/ bool initialState) { // Block all but the first time and synchronize only with CustomSyncSettings if (!initialState) diff --git a/Patches/LadderPatch.cs b/Patches/LadderPatch.cs index c460a4fef..164eac5c4 100644 --- a/Patches/LadderPatch.cs +++ b/Patches/LadderPatch.cs @@ -61,7 +61,7 @@ public class FallFromLadder [HarmonyPatch(typeof(PlayerPhysics), nameof(PlayerPhysics.ClimbLadder))] class LadderPatch { - public static void Postfix(PlayerPhysics __instance, Ladder source, byte climbLadderSid) + public static void Postfix(PlayerPhysics __instance, Ladder source/*, byte climbLadderSid*/) { FallFromLadder.OnClimbLadder(__instance, source); } diff --git a/Patches/LobbyListPatch.cs b/Patches/LobbyListPatch.cs index 7b614f997..6648477eb 100644 --- a/Patches/LobbyListPatch.cs +++ b/Patches/LobbyListPatch.cs @@ -27,7 +27,7 @@ public static class FindAGameManagerUpdatePatch [HarmonyPatch(typeof(FindAGameManager), nameof(FindAGameManager.HandleList))] public static class FindAGameManagerHandleListPatch { - public static void Prefix(FindAGameManager __instance, [HarmonyArgument(0)] InnerNetClient.TotalGameData totalGames, [HarmonyArgument(1)] ref List games) + public static void Prefix(/*FindAGameManager __instance,*/ /*[HarmonyArgument(0)] InnerNetClient.TotalGameData totalGames,*/ [HarmonyArgument(1)] ref List games) { List newList = []; diff --git a/Patches/PlayerContorolPatch.cs b/Patches/PlayerContorolPatch.cs index ee7f684a1..a96bd1a88 100644 --- a/Patches/PlayerContorolPatch.cs +++ b/Patches/PlayerContorolPatch.cs @@ -3274,7 +3274,7 @@ class EnterVentPatch Wraith.OnEnterVent(pc, __instance); break; case CustomRoles.Addict: - Addict.OnEnterVent(pc, __instance); + Addict.OnEnterVent(pc/*, __instance*/); break; case CustomRoles.CameraMan when !Options.UsePets.GetBool(): CameraMan.OnEnterVent(pc); diff --git a/Patches/TaskAssignPatch.cs b/Patches/TaskAssignPatch.cs index faa785bb0..1aba66f31 100644 --- a/Patches/TaskAssignPatch.cs +++ b/Patches/TaskAssignPatch.cs @@ -8,7 +8,7 @@ namespace TOHE; [HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.AddTasksFromList))] class AddTasksFromListPatch { - public static void Prefix(ShipStatus __instance, + public static void Prefix(/*ShipStatus __instance,*/ [HarmonyArgument(4)] Il2CppSystem.Collections.Generic.List unusedTasks) { if (!AmongUsClient.Instance.AmHost) return; @@ -113,7 +113,7 @@ class RpcSetTasksPatch { //タスクを割り当ててRPCを送る処理が行われる直前にタスクを上書きするPatch //バニラのタスク割り当て処理自体には干渉しない - public static void Prefix(GameData __instance, + public static void Prefix(/*GameData __instance,*/ [HarmonyArgument(0)] byte playerId, [HarmonyArgument(1)] ref Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppStructArray taskTypeIds) { diff --git a/Roles/AddOns/Common/Asthmatic.cs b/Roles/AddOns/Common/Asthmatic.cs index f0fdcfd20..9bd5b60c2 100644 --- a/Roles/AddOns/Common/Asthmatic.cs +++ b/Roles/AddOns/Common/Asthmatic.cs @@ -1,8 +1,6 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; -using static TOHE.Options; -using static TOHE.Utils; namespace TOHE.Roles.AddOns.Common { @@ -23,17 +21,17 @@ namespace TOHE.Roles.AddOns.Common LastSuffix.Clear(); LastPosition.Clear(); - MinRedTime = AsthmaticMinRedTime.GetInt(); - MaxRedTime = AsthmaticMaxRedTime.GetInt(); - MinGreenTime = AsthmaticMinGreenTime.GetInt(); - MaxGreenTime = AsthmaticMaxGreenTime.GetInt(); + MinRedTime = Options.AsthmaticMinRedTime.GetInt(); + MaxRedTime = Options.AsthmaticMaxRedTime.GetInt(); + MinGreenTime = Options.AsthmaticMinGreenTime.GetInt(); + MaxGreenTime = Options.AsthmaticMaxGreenTime.GetInt(); } public static void Add() { _ = new LateTask(() => { var r = IRandom.Instance; - var now = GetTimeStamp(); + var now = Utils.GetTimeStamp(); foreach (var pc in Main.AllAlivePlayerControls.Where(x => x.Is(CustomRoles.Asthmatic)).ToArray()) { Timers[pc.PlayerId] = new(30, r.Next(MinRedTime, MaxRedTime), now, '●', false); @@ -101,12 +99,11 @@ namespace TOHE.Roles.AddOns.Common if (!pc.IsModClient() && (!LastSuffix.TryGetValue(pc.PlayerId, out var beforeSuffix) || beforeSuffix != suffix)) { - NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc); + Utils.NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc); } LastSuffix[pc.PlayerId] = suffix; } - // Why is it not showing up? public static string GetSuffixText(byte id) => Timers.TryGetValue(id, out Counter counter) ? $"{counter.ColoredArrow} {counter.ColoredTimerString}" : string.Empty; } } diff --git a/Roles/AddOns/Crewmate/Stressed.cs b/Roles/AddOns/Crewmate/Stressed.cs index 23fab4ec6..7daa8b67f 100644 --- a/Roles/AddOns/Crewmate/Stressed.cs +++ b/Roles/AddOns/Crewmate/Stressed.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using static TOHE.Options; using static TOHE.Translator; -using static TOHE.Utils; namespace TOHE.Roles.AddOns.Crewmate { @@ -83,6 +82,8 @@ namespace TOHE.Roles.AddOns.Crewmate public static void Add() { + long now = Utils.GetTimeStamp(); + _ = new LateTask(() => { foreach (var pc in Main.AllAlivePlayerControls) @@ -95,7 +96,7 @@ namespace TOHE.Roles.AddOns.Crewmate continue; } Timers.Add(pc.PlayerId, StartingTime); - LastUpdates.Add(pc.PlayerId, GetTimeStamp() + 1); + LastUpdates.Add(pc.PlayerId, now + 1); } } }, 8f, "Add Stressed Timers"); @@ -103,8 +104,9 @@ namespace TOHE.Roles.AddOns.Crewmate public static void Update(PlayerControl pc) { - if (pc == null || !LastUpdates.TryGetValue(pc.PlayerId, out var x) || x >= GetTimeStamp() || !Timers.ContainsKey(pc.PlayerId) || !IsEnable || !GameStates.IsInTask || !pc.Is(CustomRoles.Stressed)) return; - LastUpdates[pc.PlayerId] = GetTimeStamp(); + long now = Utils.GetTimeStamp(); + if (pc == null || !LastUpdates.TryGetValue(pc.PlayerId, out var x) || x >= now || !Timers.ContainsKey(pc.PlayerId) || !IsEnable || !GameStates.IsInTask || !pc.Is(CustomRoles.Stressed)) return; + LastUpdates[pc.PlayerId] = now; if (pc.GetTaskState().IsTaskFinished || !pc.IsAlive()) { @@ -123,12 +125,12 @@ namespace TOHE.Roles.AddOns.Crewmate } if (pc.IsNonHostModClient()) SendRPC(pc.PlayerId, Timers[pc.PlayerId], LastUpdates[pc.PlayerId]); - if (!pc.IsModClient()) NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc); + if (!pc.IsModClient()) Utils.NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc); } public static void SendRPC(byte id, int time, long lastUpdate) { - if (!DoRPC || !IsEnable) return; + if (!Utils.DoRPC || !IsEnable) return; MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncStressedTimer, SendOption.Reliable, -1); writer.Write(id); writer.Write(time); diff --git a/Roles/AddOns/Impostor/Damocles.cs b/Roles/AddOns/Impostor/Damocles.cs index 3bcd021fd..cb76fe7a3 100644 --- a/Roles/AddOns/Impostor/Damocles.cs +++ b/Roles/AddOns/Impostor/Damocles.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using static TOHE.Options; using static TOHE.Translator; -using static TOHE.Utils; namespace TOHE.Roles.AddOns.Impostor { @@ -56,13 +55,14 @@ namespace TOHE.Roles.AddOns.Impostor public static void Update(PlayerControl pc) { byte id = pc.PlayerId; - if ((lastUpdate.TryGetValue(id, out var ts) && ts >= GetTimeStamp()) || !GameStates.IsInTask || pc == null) return; + long now = Utils.GetTimeStamp(); + if ((lastUpdate.TryGetValue(id, out var ts) && ts >= now) || !GameStates.IsInTask || pc == null) return; if (!pc.IsAlive()) { Main.PlayerStates[id].RemoveSubRole(CustomRoles.Damocles); return; } - lastUpdate[id] = GetTimeStamp(); + lastUpdate[id] = now; if (!Timer.ContainsKey(id)) Timer[id] = StartingTime + 8; Timer[id]--; @@ -74,12 +74,12 @@ namespace TOHE.Roles.AddOns.Impostor } if (pc.IsNonHostModClient()) SendRPC(id); - if (!pc.IsModClient()) NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc); + if (!pc.IsModClient()) Utils.NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc); } public static void SendRPC(byte playerId) { - if (!DoRPC) return; + if (!Utils.DoRPC) return; MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncDamoclesTimer, SendOption.Reliable, -1); writer.Write(playerId); writer.Write(Timer[playerId]); diff --git a/Roles/Crewmate/Addict.cs b/Roles/Crewmate/Addict.cs index 14210422c..592491f69 100644 --- a/Roles/Crewmate/Addict.cs +++ b/Roles/Crewmate/Addict.cs @@ -90,7 +90,7 @@ namespace TOHE.Roles.Crewmate } } - public static void OnEnterVent(PlayerControl pc, Vent vent) + public static void OnEnterVent(PlayerControl pc) { if (!pc.Is(CustomRoles.Addict)) return; diff --git a/Roles/Crewmate/Aid.cs b/Roles/Crewmate/Aid.cs index 3e7edabb7..d5dbba1d9 100644 --- a/Roles/Crewmate/Aid.cs +++ b/Roles/Crewmate/Aid.cs @@ -4,8 +4,6 @@ namespace TOHE.Roles.Crewmate using System.Collections.Generic; using System.Text; using UnityEngine; - using static TOHE.Options; - using static TOHE.Utils; public static class Aid { @@ -21,17 +19,17 @@ namespace TOHE.Roles.Crewmate public static void SetupCustomOption() { - SetupRoleOptions(Id, TabGroup.CrewmateRoles, CustomRoles.Aid); + Options.SetupRoleOptions(Id, TabGroup.CrewmateRoles, CustomRoles.Aid); AidCD = FloatOptionItem.Create(Id + 10, "AidCD", new(0f, 60f, 1f), 15f, TabGroup.CrewmateRoles, false) - .SetParent(CustomRoleSpawnChances[CustomRoles.Aid]) + .SetParent(Options.CustomRoleSpawnChances[CustomRoles.Aid]) .SetValueFormat(OptionFormat.Seconds); AidDur = FloatOptionItem.Create(Id + 11, "AidDur", new(0f, 60f, 1f), 10f, TabGroup.CrewmateRoles, false) - .SetParent(CustomRoleSpawnChances[CustomRoles.Aid]) + .SetParent(Options.CustomRoleSpawnChances[CustomRoles.Aid]) .SetValueFormat(OptionFormat.Seconds); UseLimitOpt = IntegerOptionItem.Create(Id + 12, "AbilityUseLimit", new(1, 20, 1), 5, TabGroup.CrewmateRoles, false) - .SetParent(CustomRoleSpawnChances[CustomRoles.Aid]) + .SetParent(Options.CustomRoleSpawnChances[CustomRoles.Aid]) .SetValueFormat(OptionFormat.Times); - UsePet = CreatePetUseSetting(Id + 13, CustomRoles.Aid); + UsePet = Options.CreatePetUseSetting(Id + 13, CustomRoles.Aid); } public static void Init() { @@ -44,7 +42,7 @@ namespace TOHE.Roles.Crewmate playerIdList.Add(playerId); UseLimit.Add(playerId, UseLimitOpt.GetInt()); - if (!AmongUsClient.Instance.AmHost || (UsePets.GetBool() && UsePet.GetBool())) return; + if (!AmongUsClient.Instance.AmHost || (Options.UsePets.GetBool() && UsePet.GetBool())) return; if (!Main.ResetCamPlayerList.Contains(playerId)) Main.ResetCamPlayerList.Add(playerId); } @@ -59,8 +57,8 @@ namespace TOHE.Roles.Crewmate if (UseLimit[killer.PlayerId] >= 1) { UseLimit[killer.PlayerId] -= 1; - ShieldedPlayers.TryAdd(target.PlayerId, GetTimeStamp()); - NotifyRoles(SpecifySeer: killer, SpecifyTarget: target); + ShieldedPlayers.TryAdd(target.PlayerId, Utils.GetTimeStamp()); + Utils.NotifyRoles(SpecifySeer: killer, SpecifyTarget: target); return false; } else @@ -76,18 +74,18 @@ namespace TOHE.Roles.Crewmate foreach (var x in ShieldedPlayers) { - if (x.Value + AidDur.GetInt() < GetTimeStamp() || !GameStates.IsInTask) + if (x.Value + AidDur.GetInt() < Utils.GetTimeStamp() || !GameStates.IsInTask) { ShieldedPlayers.Remove(x.Key); change = true; } } - if (change && GameStates.IsInTask) { NotifyRoles(SpecifySeer: pc); } + if (change && GameStates.IsInTask) { Utils.NotifyRoles(SpecifySeer: pc); } } public static string GetProgressText(byte playerId, bool comms) { - if (GetPlayerById(playerId) == null) return string.Empty; + if (Utils.GetPlayerById(playerId) == null) return string.Empty; var sb = new StringBuilder(); @@ -103,8 +101,8 @@ namespace TOHE.Roles.Crewmate if (UseLimit[playerId] < 1) TextColor1 = Color.red; else TextColor1 = Color.white; - sb.Append(ColorString(TextColor, $"- {Completed}/{taskState.AllTasksCount}")); - sb.Append(ColorString(TextColor1, $" - {Math.Round(UseLimit[playerId], 1)}")); + sb.Append(Utils.ColorString(TextColor, $"- {Completed}/{taskState.AllTasksCount}")); + sb.Append(Utils.ColorString(TextColor1, $" - {Math.Round(UseLimit[playerId], 1)}")); return sb.ToString(); } diff --git a/Roles/Crewmate/Analyzer.cs b/Roles/Crewmate/Analyzer.cs index daeb801d6..f5db8dbc0 100644 --- a/Roles/Crewmate/Analyzer.cs +++ b/Roles/Crewmate/Analyzer.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using static TOHE.Options; using static TOHE.Translator; -using static TOHE.Utils; namespace TOHE.Roles.Crewmate { @@ -56,14 +55,14 @@ namespace TOHE.Roles.Crewmate private static string GetRoleBasis(CustomRoles role) => SeeRoleBasis.GetBool() ? role.GetDYRole() == AmongUs.GameOptions.RoleTypes.Impostor - ? ColorString(GetRoleColor(CustomRoles.Impostor), GetString("Impostor")) + ? Utils.ColorString(Utils.GetRoleColor(CustomRoles.Impostor), GetString("Impostor")) : role.GetVNRole() switch { - CustomRoles.Impostor => ColorString(GetRoleColor(CustomRoles.Impostor), GetString("Impostor")), - CustomRoles.Shapeshifter => ColorString(GetRoleColor(CustomRoles.Speedrunner), GetString("Shapeshifter")), - CustomRoles.Crewmate => ColorString(GetRoleColor(CustomRoles.Crewmate), GetString("Crewmate")), - CustomRoles.Engineer => ColorString(GetRoleColor(CustomRoles.Autocrat), GetString("Engineer")), - CustomRoles.Scientist => ColorString(GetRoleColor(CustomRoles.Doctor), GetString("Scientist")), + CustomRoles.Impostor => Utils.ColorString(Utils.GetRoleColor(CustomRoles.Impostor), GetString("Impostor")), + CustomRoles.Shapeshifter => Utils.ColorString(Utils.GetRoleColor(CustomRoles.Speedrunner), GetString("Shapeshifter")), + CustomRoles.Crewmate => Utils.ColorString(Utils.GetRoleColor(CustomRoles.Crewmate), GetString("Crewmate")), + CustomRoles.Engineer => Utils.ColorString(Utils.GetRoleColor(CustomRoles.Autocrat), GetString("Engineer")), + CustomRoles.Scientist => Utils.ColorString(Utils.GetRoleColor(CustomRoles.Doctor), GetString("Scientist")), _ => string.Empty } : string.Empty; @@ -79,7 +78,7 @@ namespace TOHE.Roles.Crewmate playerId = byte.MaxValue; UseLimit = 0; VentCount = []; - CurrentTarget = (byte.MaxValue, GetTimeStamp()); + CurrentTarget = (byte.MaxValue, Utils.GetTimeStamp()); } public static void Add(byte id) @@ -123,9 +122,9 @@ namespace TOHE.Roles.Crewmate if (UseLimit <= 0) return; if (CurrentTarget.ID != byte.MaxValue) return; - CurrentTarget = (target.PlayerId, GetTimeStamp()); + CurrentTarget = (target.PlayerId, Utils.GetTimeStamp()); killer.SetKillCooldown(time: Duration.GetFloat()); - NotifyRoles(SpecifySeer: killer, SpecifyTarget: target); + Utils.NotifyRoles(SpecifySeer: killer, SpecifyTarget: target); } public static void OnFixedUpdate(PlayerControl pc) @@ -134,17 +133,17 @@ namespace TOHE.Roles.Crewmate if (pc == null) return; if (CurrentTarget.ID == byte.MaxValue) return; - PlayerControl target = GetPlayerById(CurrentTarget.ID); + PlayerControl target = Utils.GetPlayerById(CurrentTarget.ID); if (target == null) return; if (UnityEngine.Vector2.Distance(target.Pos(), pc.Pos()) > (pc.Is(CustomRoles.Reach) ? 2.5f : 1.5f)) { CurrentTarget.ID = byte.MaxValue; - NotifyRoles(SpecifySeer: pc, SpecifyTarget: target); + Utils.NotifyRoles(SpecifySeer: pc, SpecifyTarget: target); return; } - if (CurrentTarget.TIME + Duration.GetInt() < GetTimeStamp()) + if (CurrentTarget.TIME + Duration.GetInt() < Utils.GetTimeStamp()) { CurrentTarget.ID = byte.MaxValue; UseLimit--; diff --git a/Roles/Crewmate/Benefactor.cs b/Roles/Crewmate/Benefactor.cs index c049dd421..c47b9f75c 100644 --- a/Roles/Crewmate/Benefactor.cs +++ b/Roles/Crewmate/Benefactor.cs @@ -2,9 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; -using static TOHE.Options; using static TOHE.Translator; -using static TOHE.Utils; namespace TOHE.Roles.Crewmate { @@ -24,14 +22,14 @@ namespace TOHE.Roles.Crewmate public static void SetupCustomOption() { - SetupRoleOptions(Id, TabGroup.CrewmateRoles, CustomRoles.Benefactor); + Options.SetupRoleOptions(Id, TabGroup.CrewmateRoles, CustomRoles.Benefactor); TaskMarkPerRoundOpt = IntegerOptionItem.Create(Id + 10, "TaskMarkPerRound", new(1, 14, 1), 3, TabGroup.CrewmateRoles, false) - .SetParent(CustomRoleSpawnChances[CustomRoles.Benefactor]) + .SetParent(Options.CustomRoleSpawnChances[CustomRoles.Benefactor]) .SetValueFormat(OptionFormat.Votes); ShieldDuration = IntegerOptionItem.Create(Id + 11, "AidDur", new(1, 30, 1), 10, TabGroup.CrewmateRoles, false) - .SetParent(CustomRoleSpawnChances[CustomRoles.Benefactor]) + .SetParent(Options.CustomRoleSpawnChances[CustomRoles.Benefactor]) .SetValueFormat(OptionFormat.Seconds); - OverrideTasksData.Create(Id + 12, TabGroup.CrewmateRoles, CustomRoles.Benefactor); + Options.OverrideTasksData.Create(Id + 12, TabGroup.CrewmateRoles, CustomRoles.Benefactor); } public static void Init() @@ -51,7 +49,7 @@ namespace TOHE.Roles.Crewmate } private static void SendRPC(byte benefactorID, int taskIndex = -1, bool IsShield = false, bool clearAll = false, bool shieldExpire = false, byte shieldedId = byte.MaxValue) { - if (!IsEnable || !DoRPC) return; + if (!IsEnable || !Utils.DoRPC) return; MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SyncBenefactorMarkedTask, SendOption.Reliable, -1); writer.Write(benefactorID); writer.Write(taskIndex); @@ -88,7 +86,7 @@ namespace TOHE.Roles.Crewmate if (clearAll && taskIndex.ContainsKey(benefactorID)) taskIndex[benefactorID].Clear(); if (IsShield) { - shieldedPlayers.TryAdd(shieldedId, GetTimeStamp()); + shieldedPlayers.TryAdd(shieldedId, Utils.GetTimeStamp()); } if (shieldExpire) { @@ -102,7 +100,7 @@ namespace TOHE.Roles.Crewmate if (!TaskMarkPerRound.ContainsKey(playerId)) TaskMarkPerRound[playerId] = 0; int markedTasks = TaskMarkPerRound[playerId]; int x = Math.Max(maxTasksMarkedPerRound - markedTasks, 0); - return ColorString(GetRoleColor(CustomRoles.Benefactor).ShadeColor(0.25f), $"({x})"); + return Utils.ColorString(Utils.GetRoleColor(CustomRoles.Benefactor).ShadeColor(0.25f), $"({x})"); } public static void AfterMeetingTasks() { @@ -119,10 +117,10 @@ namespace TOHE.Roles.Crewmate { if (!IsEnable) return; - foreach (var x in shieldedPlayers.Where(x => x.Value + ShieldDuration.GetInt() < GetTimeStamp())) + foreach (var x in shieldedPlayers.Where(x => x.Value + ShieldDuration.GetInt() < Utils.GetTimeStamp())) { shieldedPlayers.Remove(x.Key); - SendRPC(pc.PlayerId, shieldExpire: true, shieldedId: GetPlayerById(x.Key).PlayerId); + SendRPC(pc.PlayerId, shieldExpire: true, shieldedId: Utils.GetPlayerById(x.Key).PlayerId); } } public static void OnTaskComplete(PlayerControl player, PlayerTask task) @@ -151,7 +149,7 @@ namespace TOHE.Roles.Crewmate { if (taskIndex[benefactorId].Contains(task.Index)) { - var benefactorPC = GetPlayerById(benefactorId); + var benefactorPC = Utils.GetPlayerById(benefactorId); if (benefactorPC == null) continue; player.Notify(GetString("BenefactorTargetGotShieldNotify")); diff --git a/Roles/Crewmate/CameraMan.cs b/Roles/Crewmate/CameraMan.cs index f91f11e9e..8d5a81580 100644 --- a/Roles/Crewmate/CameraMan.cs +++ b/Roles/Crewmate/CameraMan.cs @@ -6,7 +6,6 @@ namespace TOHE.Roles.Crewmate using System.Text; using UnityEngine; using static TOHE.Options; - using static TOHE.Utils; public static class CameraMan { @@ -46,7 +45,7 @@ namespace TOHE.Roles.Crewmate public static bool IsEnable => playerIdList.Count > 0; public static void SendRPC(byte playerId) { - if (!IsEnable || !DoRPC) return; + if (!IsEnable || !Utils.DoRPC) return; MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetCameraManLimit, SendOption.Reliable, -1); writer.Write(playerId); writer.Write(UseLimit[playerId]); @@ -81,7 +80,7 @@ namespace TOHE.Roles.Crewmate _ => throw new NotImplementedException(), }; - _ = new LateTask(() => { TP(pc.NetTransform, pos); }, UsePets.GetBool() ? 0.1f : 2f, "CameraMan Teleport"); + _ = new LateTask(() => { pc.TP(pos); }, UsePets.GetBool() ? 0.1f : 2f, "CameraMan Teleport"); } else { @@ -104,8 +103,8 @@ namespace TOHE.Roles.Crewmate if (UseLimit[playerId] < 1) TextColor1 = Color.red; else TextColor1 = Color.white; - sb.Append(ColorString(TextColor, $"- {Completed}/{taskState.AllTasksCount}")); - sb.Append(ColorString(TextColor1, $" - {Math.Round(UseLimit[playerId], 1)}")); + sb.Append(Utils.ColorString(TextColor, $"- {Completed}/{taskState.AllTasksCount}")); + sb.Append(Utils.ColorString(TextColor1, $" - {Math.Round(UseLimit[playerId], 1)}")); return sb.ToString(); } diff --git a/Roles/Crewmate/Doormaster.cs b/Roles/Crewmate/Doormaster.cs index 15388b099..4e8cb4501 100644 --- a/Roles/Crewmate/Doormaster.cs +++ b/Roles/Crewmate/Doormaster.cs @@ -7,7 +7,6 @@ namespace TOHE.Roles.Crewmate using TOHE.Modules; using UnityEngine; using static TOHE.Options; - using static TOHE.Utils; public static class Doormaster { @@ -47,7 +46,7 @@ namespace TOHE.Roles.Crewmate public static bool IsEnable => playerIdList.Count > 0; public static void SendRPC(byte playerId) { - if (!IsEnable || !DoRPC) return; + if (!IsEnable || !Utils.DoRPC) return; MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetDoormasterLimit, SendOption.Reliable, -1); writer.Write(playerId); writer.Write(UseLimit[playerId]); @@ -93,8 +92,8 @@ namespace TOHE.Roles.Crewmate if (UseLimit[playerId] < 1) TextColor1 = Color.red; else TextColor1 = Color.white; - sb.Append(ColorString(TextColor, $"- {Completed}/{taskState.AllTasksCount}")); - sb.Append(ColorString(TextColor1, $" - {Math.Round(UseLimit[playerId], 1)}")); + sb.Append(Utils.ColorString(TextColor, $"- {Completed}/{taskState.AllTasksCount}")); + sb.Append(Utils.ColorString(TextColor1, $" - {Math.Round(UseLimit[playerId], 1)}")); return sb.ToString(); } diff --git a/Roles/Crewmate/Escort.cs b/Roles/Crewmate/Escort.cs index 0c1d64043..dcc0248bb 100644 --- a/Roles/Crewmate/Escort.cs +++ b/Roles/Crewmate/Escort.cs @@ -1,9 +1,7 @@ using Hazel; using System.Collections.Generic; using TOHE.Roles.Neutral; -using static TOHE.Options; using static TOHE.Translator; -using static TOHE.Utils; namespace TOHE.Roles.Crewmate { @@ -20,14 +18,14 @@ namespace TOHE.Roles.Crewmate public static void SetupCustomOption() { - SetupSingleRoleOptions(Id, TabGroup.CrewmateRoles, CustomRoles.Escort, 1); + Options.SetupSingleRoleOptions(Id, TabGroup.CrewmateRoles, CustomRoles.Escort, 1); CD = FloatOptionItem.Create(Id + 10, "EscortCD", new(2.5f, 60f, 2.5f), 30f, TabGroup.CrewmateRoles, false) - .SetParent(CustomRoleSpawnChances[CustomRoles.Escort]) + .SetParent(Options.CustomRoleSpawnChances[CustomRoles.Escort]) .SetValueFormat(OptionFormat.Seconds); UseLimit = IntegerOptionItem.Create(Id + 11, "AbilityUseLimit", new(1, 20, 1), 3, TabGroup.CrewmateRoles, false) - .SetParent(CustomRoleSpawnChances[CustomRoles.Escort]) + .SetParent(Options.CustomRoleSpawnChances[CustomRoles.Escort]) .SetValueFormat(OptionFormat.Times); - UsePet = CreatePetUseSetting(Id + 12, CustomRoles.Escort); + UsePet = Options.CreatePetUseSetting(Id + 12, CustomRoles.Escort); } public static void Init() @@ -41,14 +39,14 @@ namespace TOHE.Roles.Crewmate BlockLimit = UseLimit.GetInt(); - if (!AmongUsClient.Instance.AmHost || (UsePets.GetBool() && UsePet.GetBool())) return; + if (!AmongUsClient.Instance.AmHost || (Options.UsePets.GetBool() && UsePet.GetBool())) return; if (!Main.ResetCamPlayerList.Contains(playerId)) Main.ResetCamPlayerList.Add(playerId); } public static bool IsEnable => playerIdList.Count > 0; public static void SendRPC() { - if (!IsEnable || !DoRPC) return; + if (!IsEnable || !Utils.DoRPC) return; MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetEscortLimit, SendOption.Reliable, -1); writer.Write(BlockLimit); AmongUsClient.Instance.FinishRpcImmediately(writer); @@ -68,7 +66,7 @@ namespace TOHE.Roles.Crewmate BlockLimit--; killer.SetKillCooldown(); - Glitch.hackedIdList.TryAdd(target.PlayerId, GetTimeStamp()); + Glitch.hackedIdList.TryAdd(target.PlayerId, Utils.GetTimeStamp()); killer.Notify(GetString("EscortTargetHacked")); } public static string GetProgressText() => $"- {BlockLimit}"; diff --git a/Roles/Crewmate/Ricochet.cs b/Roles/Crewmate/Ricochet.cs index 3fe2da3c3..0ac13e7fa 100644 --- a/Roles/Crewmate/Ricochet.cs +++ b/Roles/Crewmate/Ricochet.cs @@ -6,7 +6,6 @@ namespace TOHE.Roles.Crewmate using System.Text; using UnityEngine; using static TOHE.Options; - using static TOHE.Utils; public static class Ricochet { @@ -47,7 +46,7 @@ namespace TOHE.Roles.Crewmate public static bool IsEnable => playerIdList.Count > 0; public static void SendRPC(byte playerId) { - if (!IsEnable || !DoRPC) return; + if (!IsEnable || !Utils.DoRPC) return; MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetRicochetLimit, SendOption.Reliable, -1); writer.Write(playerId); writer.Write(UseLimit[playerId]); @@ -55,7 +54,7 @@ namespace TOHE.Roles.Crewmate } public static void SendRPCSyncTarget(byte targetId) { - if (!IsEnable || !DoRPC) return; + if (!IsEnable || !Utils.DoRPC) return; MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetRicochetTarget, SendOption.Reliable, -1); writer.Write(targetId); AmongUsClient.Instance.FinishRpcImmediately(writer); @@ -110,7 +109,7 @@ namespace TOHE.Roles.Crewmate } public static string GetProgressText(byte playerId, bool comms) { - if (GetPlayerById(playerId) == null) return string.Empty; + if (Utils.GetPlayerById(playerId) == null) return string.Empty; var sb = new StringBuilder(); @@ -126,8 +125,8 @@ namespace TOHE.Roles.Crewmate if (UseLimit[playerId] < 1) TextColor1 = Color.red; else TextColor1 = Color.white; - sb.Append(ColorString(TextColor, $"- {Completed}/{taskState.AllTasksCount}")); - sb.Append(ColorString(TextColor1, $" - {Math.Round(UseLimit[playerId], 1)}")); + sb.Append(Utils.ColorString(TextColor, $"- {Completed}/{taskState.AllTasksCount}")); + sb.Append(Utils.ColorString(TextColor1, $" - {Math.Round(UseLimit[playerId], 1)}")); return sb.ToString(); } diff --git a/Roles/Crewmate/Tether.cs b/Roles/Crewmate/Tether.cs index faf5ef81f..35828f746 100644 --- a/Roles/Crewmate/Tether.cs +++ b/Roles/Crewmate/Tether.cs @@ -6,7 +6,6 @@ namespace TOHE.Roles.Crewmate using System.Text; using UnityEngine; using static TOHE.Options; - using static TOHE.Utils; public static class Tether { @@ -50,7 +49,7 @@ namespace TOHE.Roles.Crewmate public static bool IsEnable => playerIdList.Count > 0; public static void SendRPC(byte playerId) { - if (!IsEnable || !DoRPC) return; + if (!IsEnable || !Utils.DoRPC) return; MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetTetherLimit, SendOption.Reliable, -1); writer.Write(playerId); writer.Write(UseLimit[playerId]); @@ -58,7 +57,7 @@ namespace TOHE.Roles.Crewmate } public static void SendRPCSyncTarget(byte targetId) { - if (!IsEnable || !DoRPC) return; + if (!IsEnable || !Utils.DoRPC) return; MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetTetherTarget, SendOption.Reliable, -1); writer.Write(targetId); AmongUsClient.Instance.FinishRpcImmediately(writer); @@ -88,7 +87,7 @@ namespace TOHE.Roles.Crewmate { if (GameStates.IsInTask) { - TP(pc.NetTransform, GetPlayerById(Target).Pos()); + pc.TP(Utils.GetPlayerById(Target).Pos()); } }, isPet ? 0.1f : 2f, "Tether TP"); } @@ -136,8 +135,8 @@ namespace TOHE.Roles.Crewmate if (UseLimit[playerId] < 1) TextColor1 = Color.red; else TextColor1 = Color.white; - sb.Append(ColorString(TextColor, $"- {Completed}/{taskState.AllTasksCount}")); - sb.Append(ColorString(TextColor1, $" - {Math.Round(UseLimit[playerId], 1)}")); + sb.Append(Utils.ColorString(TextColor, $"- {Completed}/{taskState.AllTasksCount}")); + sb.Append(Utils.ColorString(TextColor1, $" - {Math.Round(UseLimit[playerId], 1)}")); return sb.ToString(); } diff --git a/Roles/Impostor/Consort.cs b/Roles/Impostor/Consort.cs index ca1b37814..f68299df1 100644 --- a/Roles/Impostor/Consort.cs +++ b/Roles/Impostor/Consort.cs @@ -1,9 +1,7 @@ using Hazel; using System.Collections.Generic; using TOHE.Roles.Neutral; -using static TOHE.Options; using static TOHE.Translator; -using static TOHE.Utils; namespace TOHE.Roles.Impostor { @@ -19,12 +17,12 @@ namespace TOHE.Roles.Impostor public static void SetupCustomOption() { - SetupRoleOptions(Id, TabGroup.ImpostorRoles, CustomRoles.Consort); + Options.SetupRoleOptions(Id, TabGroup.ImpostorRoles, CustomRoles.Consort); CD = FloatOptionItem.Create(Id + 10, "EscortCD", new(2.5f, 60f, 2.5f), 30f, TabGroup.ImpostorRoles, false) - .SetParent(CustomRoleSpawnChances[CustomRoles.Consort]) + .SetParent(Options.CustomRoleSpawnChances[CustomRoles.Consort]) .SetValueFormat(OptionFormat.Seconds); UseLimit = IntegerOptionItem.Create(Id + 11, "AbilityUseLimit", new(1, 20, 1), 3, TabGroup.ImpostorRoles, false) - .SetParent(CustomRoleSpawnChances[CustomRoles.Consort]) + .SetParent(Options.CustomRoleSpawnChances[CustomRoles.Consort]) .SetValueFormat(OptionFormat.Times); } @@ -41,7 +39,7 @@ namespace TOHE.Roles.Impostor public static bool IsEnable => playerIdList.Count > 0; public static void SendRPC() { - if (!IsEnable || !DoRPC) return; + if (!IsEnable || !Utils.DoRPC) return; MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetConsortLimit, SendOption.Reliable, -1); writer.Write(BlockLimit); AmongUsClient.Instance.FinishRpcImmediately(writer); @@ -62,7 +60,7 @@ namespace TOHE.Roles.Impostor return killer.CheckDoubleTrigger(target, () => { BlockLimit--; - Glitch.hackedIdList.TryAdd(target.PlayerId, GetTimeStamp()); + Glitch.hackedIdList.TryAdd(target.PlayerId, Utils.GetTimeStamp()); killer.Notify(GetString("EscortTargetHacked")); killer.SetKillCooldown(CD.GetFloat()); SendRPC(); diff --git a/Roles/Impostor/RiftMaker.cs b/Roles/Impostor/RiftMaker.cs index d4a0d6f32..4816446fe 100644 --- a/Roles/Impostor/RiftMaker.cs +++ b/Roles/Impostor/RiftMaker.cs @@ -75,11 +75,11 @@ namespace TOHE.Roles.Impostor LastTP = GetTimeStamp(); if (from == Marks[0]) { - TP(player.NetTransform, Marks[1]); + player.TP(Marks[1]); } else if (from == Marks[1]) { - TP(player.NetTransform, Marks[0]); + player.TP(Marks[0]); } else { @@ -104,7 +104,7 @@ namespace TOHE.Roles.Impostor }, 0.5f, "RiftMaker-ResetMarks.RpcBootFromVent"); } - public static void OnShapeshift(PlayerControl player, bool shapeshifting, bool isPet = false) + public static void OnShapeshift(PlayerControl player, bool shapeshifting) { if (player == null) return; if (!shapeshifting) return; @@ -113,13 +113,8 @@ namespace TOHE.Roles.Impostor Marks.Add((Vector2)player.transform.position); if (Marks.Count == 2) LastTP = GetTimeStamp(); player.Notify(GetString("MarkDone")); - - //if (!isPet) _ = new LateTask(() => { player.CmdCheckRevertShapeshift(false); }, 1.5f, "Rift Maker RpcRevertShapeshift"); } - public static string GetProgressText() - { - return $" - {(Marks.Count == 2 ? "" : "")}{Marks.Count}/2"; - } + public static string GetProgressText() => $" - {(Marks.Count == 2 ? "" : "")}{Marks.Count}/2"; } } diff --git a/Roles/Impostor/Twister.cs b/Roles/Impostor/Twister.cs index 163dbdd9b..c1e6dbdc0 100644 --- a/Roles/Impostor/Twister.cs +++ b/Roles/Impostor/Twister.cs @@ -75,8 +75,8 @@ namespace TOHE.Roles.Impostor pc.RPCPlayCustomSound("Teleport"); var originPs = target.Pos(); - TP(target.NetTransform, pc.Pos()); - TP(pc.NetTransform, originPs); + target.TP(pc.Pos()); + pc.TP(originPs); target.Notify(ColorString(GetRoleColor(CustomRoles.Twister), string.Format(GetString("TeleportedByTwister"), pc.GetRealName()))); pc.Notify(ColorString(GetRoleColor(CustomRoles.Twister), string.Format(GetString("TeleportedByTwister"), target.GetRealName()))); diff --git a/Roles/Neutral/Magician.cs b/Roles/Neutral/Magician.cs index 9f25b1d23..a6dd2aae9 100644 --- a/Roles/Neutral/Magician.cs +++ b/Roles/Neutral/Magician.cs @@ -277,11 +277,11 @@ public static class Magician lastTP = GetTimeStamp(); if (from == PortalMarks[0]) { - TP(pc.NetTransform, PortalMarks[1]); + pc.TP(PortalMarks[1]); } else if (from == PortalMarks[1]) { - TP(pc.NetTransform, PortalMarks[0]); + pc.TP(PortalMarks[0]); } else { diff --git a/TOHE.csproj b/TOHE.csproj index 97e66c6dc..df36d5ea0 100644 --- a/TOHE.csproj +++ b/TOHE.csproj @@ -1,56 +1,53 @@  - + net6.0 false false - false + false TOHE+ Gurge44 preview - E:\Program Files\AmongUs - true - True - $(MSBuildProjectName)+ - + E:\Program Files\AmongUs + true + True + $(MSBuildProjectName)+ + - + - + - + - - - - - - - + - - + + - + - runtime; compile; build; native; contentfiles; analyzers; buildtransitive - all + runtime; compile; build; native; contentfiles; analyzers; buildtransitive + all - all - runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + + + +