diff --git a/EHR.sln.DotSettings b/EHR.sln.DotSettings index 4f43706a5..24140ddf2 100644 --- a/EHR.sln.DotSettings +++ b/EHR.sln.DotSettings @@ -67,6 +67,7 @@ TS UI VN + WAV XOR <Policy><Descriptor Staticness="Any" AccessRightKinds="Private, Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="non_field_members_should_be_pascal_case"><ElementKinds><Kind Name="PROPERTY" /><Kind Name="EVENT" /><Kind Name="METHOD" /></ElementKinds></Descriptor><Policy Inspect="False" Prefix="Get" Suffix="" Style="AaBb" /></Policy> diff --git a/Gamemodes/BedWars.cs b/Gamemodes/BedWars.cs index e28a47fac..ee200ed61 100644 --- a/Gamemodes/BedWars.cs +++ b/Gamemodes/BedWars.cs @@ -78,7 +78,7 @@ public static class BedWars private static readonly Item[] Selections = Enum.GetValues(); private static readonly ItemCategory[] Categories = Enum.GetValues()[1..]; private static readonly Upgrade[] AllUpgrade = Enum.GetValues(); - public static (Color Color, string Team) WinnerData = (Color.white, "No one wins"); + public static (UnityEngine.Color Color, string Team) WinnerData = (Color.white, "No one wins"); public static void SetupCustomOption() { diff --git a/Gamemodes/HotPotato.cs b/Gamemodes/HotPotato.cs index 374d31934..3c1dafef2 100644 --- a/Gamemodes/HotPotato.cs +++ b/Gamemodes/HotPotato.cs @@ -4,7 +4,6 @@ using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using Hazel; -using InnerNet; using UnityEngine; namespace EHR.Gamemodes; @@ -213,7 +212,7 @@ internal static class HotPotato LateTask.New(() => target.SetKillCooldownNonSync(1f), 0.2f, log: false); } - if (aapcCount < HolderHasArrowToNearestPlayerIfPlayersLessThan.GetInt() && aapcCount > 1) + if (aapcCount < HolderHasArrowToNearestPlayerIfPlayersLessThan.GetInt()) { Vector2 pos = target.Pos(); TargetArrow.Add(HotPotatoState.HolderID, aapc.Without(target).Where(x => x.PlayerId != HotPotatoState.LastHolderID).MinBy(x => Vector2.Distance(x.Pos(), pos)).PlayerId); diff --git a/Gamemodes/KingOfTheZones.cs b/Gamemodes/KingOfTheZones.cs index f0482d978..056391f31 100644 --- a/Gamemodes/KingOfTheZones.cs +++ b/Gamemodes/KingOfTheZones.cs @@ -1,12 +1,11 @@ -using AmongUs.GameOptions; -using EHR.Modules; -using Hazel; -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using AmongUs.GameOptions; +using EHR.Modules; +using Hazel; using UnityEngine; -using static EHR.Roles.Adventurer; using static EHR.Translator; namespace EHR.Gamemodes; @@ -33,7 +32,7 @@ public static class KingOfTheZones private static readonly KOTZTeam[] AllKOTZTeam = Enum.GetValues(); private static readonly StringBuilder Suffix = new(); - public static (Color Color, string Team) WinnerData = (Color.white, "No one wins"); + public static (UnityEngine.Color Color, string Team) WinnerData = (Color.white, "No one wins"); private static readonly Dictionary>> DefaultZones = new() { diff --git a/Gamemodes/Snowdown.cs b/Gamemodes/Snowdown.cs index 7cf0830da..09ba8819b 100644 --- a/Gamemodes/Snowdown.cs +++ b/Gamemodes/Snowdown.cs @@ -1,8 +1,8 @@ -using EHR.Roles; -using Hazel; -using System; +using System; using System.Collections.Generic; using System.Linq; +using EHR.Roles; +using Hazel; using UnityEngine; namespace EHR.Gamemodes; diff --git a/Gamemodes/SoloPVP.cs b/Gamemodes/SoloPVP.cs index 9ac43ab8b..bf780624f 100644 --- a/Gamemodes/SoloPVP.cs +++ b/Gamemodes/SoloPVP.cs @@ -136,14 +136,14 @@ internal static class SoloPVP var x = (int)(PlayerHP[pc.PlayerId] / PlayerHPMax[pc.PlayerId] * 10 * 50); var r = 255; var g = 255; - var b = 0; + const int b = 0; if (x > 255) r -= x - 255; else g = x; - return new((byte)r, (byte)g, (byte)b, byte.MaxValue); + return new((byte)r, (byte)g, b, byte.MaxValue); } private static string GetStatsForVanilla(PlayerControl pc) diff --git a/Main.cs b/Main.cs index f05b80785..0fde12dfa 100644 --- a/Main.cs +++ b/Main.cs @@ -244,11 +244,10 @@ public class Main : BasePlugin public static ConfigEntry Preset20 { get; private set; } // Other Configs - public static ConfigEntry WebhookUrl { get; private set; } public static ConfigEntry BetaBuildUrl { get; private set; } public static ConfigEntry LastKillCooldown { get; private set; } public static ConfigEntry LastShapeshifterCooldown { get; private set; } - public static ConfigEntry AckdPrivacyPolicy { get; set; } + public static ConfigEntry AckdPrivacyPolicy { get; private set; } public static PlayerControl[] AllPlayerControlsToArray => CachedAllPlayerControlsList.ToArray(); public static PlayerControl[] AllAlivePlayerControlsToArray => CachedAlivePlayerControlsList.ToArray(); @@ -430,7 +429,7 @@ public class Main : BasePlugin Preset18 = Config.Bind("Preset Name Options", "Preset18", "Preset_18"); Preset19 = Config.Bind("Preset Name Options", "Preset19", "Preset_19"); Preset20 = Config.Bind("Preset Name Options", "Preset20", "Preset_20"); - WebhookUrl = Config.Bind("Other", "WebhookURL", "none"); + Config.Bind("Other", "WebhookURL", "none"); BetaBuildUrl = Config.Bind("Other", "BetaBuildURL", string.Empty); MessageWait = Config.Bind("Other", "MessageWait", 0); LastKillCooldown = Config.Bind("Other", "LastKillCooldown", (float)30); @@ -1336,4 +1335,4 @@ public enum TieMode Random } -public class Coroutines : MonoBehaviour { } +public class Coroutines : MonoBehaviour; diff --git a/Modules/AntiBlackout.cs b/Modules/AntiBlackout.cs index 0fa04b902..e03fd3298 100644 --- a/Modules/AntiBlackout.cs +++ b/Modules/AntiBlackout.cs @@ -4,7 +4,6 @@ using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using EHR.Patches; -using Hazel; namespace EHR; diff --git a/Modules/ClientOptionItem.cs b/Modules/ClientOptionItem.cs index a04751880..536afcc58 100644 --- a/Modules/ClientOptionItem.cs +++ b/Modules/ClientOptionItem.cs @@ -85,9 +85,10 @@ public class ClientOptionItem ToggleButton = Object.Instantiate(mouseMoveToggle, CustomBackground.transform); OptionButtons.Add(ToggleButton); + // ReSharper disable once PossibleLossOfFraction ToggleButton.transform.localPosition = new( (OptionButtons.Count - 1) % 3 == 0 ? -2.6f : ((OptionButtons.Count - 1) % 3 == 1 ? 0f : 2.6f), - 2.2f - (0.5f * ((OptionButtons.Count - 1) / 3)), + 2.2f - (0.5f * ((OptionButtons.Count - 1) / 3)), -6f); ToggleButton.name = name; @@ -97,7 +98,7 @@ public class ClientOptionItem passiveButton.OnClick.AddListener(new Action(() => { - if (config != null) config.Value = !config.Value; + config?.Value = !config.Value; UpdateToggle(); additionalOnClickAction?.Invoke(); @@ -126,9 +127,9 @@ public class ClientOptionItem int totalRows = (OptionButtons.Count + 2) / 3; - float topPosition = 2.2f; - float bottomLimit = -1.6f; - float availableHeight = topPosition - bottomLimit; + const float topPosition = 2.2f; + const float bottomLimit = -1.6f; + const float availableHeight = topPosition - bottomLimit; float rowSpacing = totalRows > 1 ? availableHeight / (totalRows - 1) : 0f; for (int i = 0; i < OptionButtons.Count; i++) diff --git a/Modules/CustomRoleSelector.cs b/Modules/CustomRoleSelector.cs index f9dee9c9f..98702794d 100644 --- a/Modules/CustomRoleSelector.cs +++ b/Modules/CustomRoleSelector.cs @@ -596,7 +596,7 @@ internal static class CustomRoleSelector private class RoleAssignInfo(CustomRoles role, int spawnChance, int maxCount) { public CustomRoles Role => role; - public int SpawnChance { get; set; } = spawnChance; + public int SpawnChance { get; } = spawnChance; public int MaxCount => maxCount; public int AssignedCount { get; set; } diff --git a/Modules/CustomRolesHelper.cs b/Modules/CustomRolesHelper.cs index 51e52a9f1..0a80418fe 100644 --- a/Modules/CustomRolesHelper.cs +++ b/Modules/CustomRolesHelper.cs @@ -1,12 +1,12 @@ -using AmongUs.GameOptions; -using EHR.Gamemodes; -using EHR.Modules; -using EHR.Roles; -using System; +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.CompilerServices; +using AmongUs.GameOptions; +using EHR.Gamemodes; +using EHR.Modules; +using EHR.Roles; using UnityEngine; namespace EHR; @@ -1754,8 +1754,13 @@ internal static class CustomRolesHelper : CountTypes.Crew }; } - } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public string ToColoredString() + { + return role.ColoredTextByRole(Translator.GetString(role.ToString())); + } + } extension(Team team) { @@ -1786,11 +1791,6 @@ internal static class CustomRolesHelper } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static string ToColoredString(this CustomRoles role) - { - return role.ColoredTextByRole(Translator.GetString(role.ToString())); - } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ColoredTextByRole(this CustomRoles role, string str) { diff --git a/Modules/CustomSounds.cs b/Modules/CustomSounds.cs index 397eeb2c6..6047ad4a1 100644 --- a/Modules/CustomSounds.cs +++ b/Modules/CustomSounds.cs @@ -1,9 +1,9 @@ -using Hazel; -using Il2CppInterop.Runtime.InteropTypes.Arrays; using System; using System.Collections.Generic; using System.IO; using System.Reflection; +using Hazel; +using Il2CppInterop.Runtime.InteropTypes.Arrays; using UnityEngine; namespace EHR.Modules; @@ -88,18 +88,18 @@ public static class CustomSoundsManager catch (Exception e) { Utils.ThrowException(e); } } - private static readonly Dictionary audioCache = []; + private static readonly Dictionary AudioCache = []; private static void StartPlay(string path, float volume = 1f, float pitch = 1f) { - if (!audioCache.TryGetValue(path, out var clip)) + if (!AudioCache.TryGetValue(path, out var clip)) { clip = LoadWAV(path); - audioCache[path] = clip; + AudioCache[path] = clip; } if (clip) - SoundManager.Instance.PlaySoundImmediate(clip, false, volume); + SoundManager.Instance.PlaySoundImmediate(clip, false, volume, pitch); } private static AudioClip LoadWAV(string path) @@ -169,8 +169,7 @@ public static class CustomSoundsManager // Allocate memory (right will be null if only mono sound) LeftChannel = new Il2CppStructArray(SampleCount); - if (ChannelCount == 2) RightChannel = new Il2CppStructArray(SampleCount); - else RightChannel = null; + RightChannel = ChannelCount == 2 ? new Il2CppStructArray(SampleCount) : null; int end = pos + dataSize; // Write to double array/s: @@ -183,7 +182,7 @@ public static class CustomSoundsManager if (ChannelCount == 2) { - RightChannel[i] = BytesToFloat(wav[pos], wav[pos + 1]); + RightChannel?[i] = BytesToFloat(wav[pos], wav[pos + 1]); pos += 2; } i++; @@ -191,6 +190,7 @@ public static class CustomSoundsManager } // Returns left and right double arrays. 'right' will be null if sound is mono. +/* public Il2CppStructArray GetStereoData() { if (RightChannel == null) return LeftChannel; @@ -205,5 +205,6 @@ public static class CustomSoundsManager return stereoData; } +*/ } } diff --git a/Modules/DataFlagRateLimiter.cs b/Modules/DataFlagRateLimiter.cs index 96c240226..adf6a514b 100644 --- a/Modules/DataFlagRateLimiter.cs +++ b/Modules/DataFlagRateLimiter.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; using Hazel; @@ -15,7 +16,7 @@ public static class DataFlagRateLimiter public bool Done; public bool Dropped; - public System.Collections.IEnumerator Wait() + public IEnumerator Wait() { while (!Done) yield return null; diff --git a/Modules/Debugger.cs b/Modules/Debugger.cs index de2871cd9..91515aaff 100644 --- a/Modules/Debugger.cs +++ b/Modules/Debugger.cs @@ -233,10 +233,21 @@ public class CustomLogger { if (message[i] != '<') continue; char c = message[i + 1]; - if (c == 'b') hasB = true; - else if (c == 'u') hasU = true; - else if (c == 'i') hasI = true; - else if (c == 's') hasS = true; + switch (c) + { + case 'b': + hasB = true; + break; + case 'u': + hasU = true; + break; + case 'i': + hasI = true; + break; + case 's': + hasS = true; + break; + } } if (hasB) message.Append(""); if (hasU) message.Append(""); diff --git a/Modules/DisableDevice.cs b/Modules/DisableDevice.cs index 895d6624f..b99d3d565 100644 --- a/Modules/DisableDevice.cs +++ b/Modules/DisableDevice.cs @@ -63,7 +63,7 @@ internal static class DisableDevice foreach (var ps in Main.PlayerStates.Values) { var role = ps.Role; - if (role is Rogue rogue && rogue.DisableDevices) + if (role is Rogue { DisableDevices: true }) { rogueForce = true; break; @@ -139,7 +139,6 @@ internal static class DisableDevice { DesyncComms.Remove(pc.PlayerId); hasValue = true; - activateSabComms = false; } if (!hasValue) return; diff --git a/Modules/DoorsReset.cs b/Modules/DoorsReset.cs index 8c37f7fc2..b2dd06640 100644 --- a/Modules/DoorsReset.cs +++ b/Modules/DoorsReset.cs @@ -63,7 +63,7 @@ public static class DoorsReset } DoorsSystemType doorsSystem = DoorsSystem; - if (doorsSystem != null) doorsSystem.IsDirty = true; + doorsSystem?.IsDirty = true; } /// Close all doors on the map @@ -79,7 +79,7 @@ public static class DoorsReset } DoorsSystemType doorsSystem = DoorsSystem; - if (doorsSystem != null) doorsSystem.IsDirty = true; + doorsSystem?.IsDirty = true; } /// Randomly opens and closes all doors on the map @@ -94,7 +94,7 @@ public static class DoorsReset } DoorsSystemType doorsSystem = DoorsSystem; - if (doorsSystem != null) doorsSystem.IsDirty = true; + doorsSystem?.IsDirty = true; } /// Sets the open/close status of the door. Do nothing for doors that cannot be closed by sabotage diff --git a/Modules/EAC.cs b/Modules/EAC.cs index 74e9bfef7..684369310 100644 --- a/Modules/EAC.cs +++ b/Modules/EAC.cs @@ -239,8 +239,8 @@ internal static class EAC var target = sr.ReadNetObject(); var resultFlags = (MurderResultFlags)sr.ReadInt32(); - if (GameStates.IsInTask && !resultFlags.HasFlag(MurderResultFlags.FailedError) && !resultFlags.HasFlag(MurderResultFlags.FailedProtected) && target != null && !target.Data.IsDead) - LateTask.New(() => target.RpcRevive(), 0.1f, log: false); + if (GameStates.IsInTask && !resultFlags.HasFlag(MurderResultFlags.FailedError) && !resultFlags.HasFlag(MurderResultFlags.FailedProtected) && target && !target.Data.IsDead) + LateTask.New(target.RpcRevive, 0.1f, log: false); Report(pc, "Directly Murder Player"); HandleCheat(pc, "Directly Murder Player"); diff --git a/Modules/ErrorText.cs b/Modules/ErrorText.cs index 70e59644d..ee7c6f401 100644 --- a/Modules/ErrorText.cs +++ b/Modules/ErrorText.cs @@ -28,11 +28,11 @@ public class ErrorText : MonoBehaviour if (AllErrors.Count == 0) return; AllErrors.ForEach(err => err.IncreaseTimer()); - ErrorData[] ToRemove = AllErrors.Where(err => err.ErrorLevel <= 1 && 30f < err.Timer).ToArray(); + ErrorData[] toRemove = AllErrors.Where(err => err.ErrorLevel <= 1 && 30f < err.Timer).ToArray(); - if (ToRemove.Length > 0) + if (toRemove.Length > 0) { - AllErrors.RemoveAll(err => ToRemove.Contains(err)); + AllErrors.RemoveAll(toRemove.Contains); UpdateText(); if (HnSFlag) Destroy(gameObject); } diff --git a/Modules/ExtendedPlayerControl.cs b/Modules/ExtendedPlayerControl.cs index 0970b42ad..84cf9e4a0 100644 --- a/Modules/ExtendedPlayerControl.cs +++ b/Modules/ExtendedPlayerControl.cs @@ -2510,13 +2510,10 @@ internal static class ExtendedPlayerControl { if (ShipStatus.Instance.FastRooms.TryGetValue(systemTypes, out var fastRoom)) return fastRoom; - else - { - foreach (var room in ShipStatus.Instance.AllRooms) - if (room.RoomId == systemTypes) - return room; - } - return default; + foreach (var room in ShipStatus.Instance.AllRooms) + if (room.RoomId == systemTypes) + return room; + return null; } public static void RpcExitVentDesync(this PlayerPhysics physics, int ventId, PlayerControl seer) diff --git a/Modules/Extensions/HazelExtensions.cs b/Modules/Extensions/HazelExtensions.cs index 0f0a4c33c..24d598c3f 100644 --- a/Modules/Extensions/HazelExtensions.cs +++ b/Modules/Extensions/HazelExtensions.cs @@ -1,5 +1,4 @@ -using System.Text; -using Hazel; +using Hazel; using UnityEngine; namespace EHR; diff --git a/Modules/FixedUpdateCaller.cs b/Modules/FixedUpdateCaller.cs index c336c727c..be8e72942 100644 --- a/Modules/FixedUpdateCaller.cs +++ b/Modules/FixedUpdateCaller.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using EHR.Gamemodes; using EHR.Patches; using HarmonyLib; diff --git a/Modules/GameOptionsSender/NormalGameOptionsSender.cs b/Modules/GameOptionsSender/NormalGameOptionsSender.cs index 19fe3123c..aab050e4c 100644 --- a/Modules/GameOptionsSender/NormalGameOptionsSender.cs +++ b/Modules/GameOptionsSender/NormalGameOptionsSender.cs @@ -3,7 +3,6 @@ using System.Collections; using AmongUs.GameOptions; using Hazel; using Il2CppInterop.Runtime.InteropTypes.Arrays; -using InnerNet; namespace EHR.Modules; diff --git a/Modules/GameState.cs b/Modules/GameState.cs index a9ceb083f..7be781807 100644 --- a/Modules/GameState.cs +++ b/Modules/GameState.cs @@ -400,13 +400,12 @@ public class PlayerState(byte playerId) { int count = 0; var states = Main.PlayerStates.Values; - byte myId = PlayerId; foreach (var state in states) { - if (state.PlayerId == myId) continue; + if (state.PlayerId == PlayerId) continue; - if (state.GetRealKiller() == myId) + if (state.GetRealKiller() == PlayerId) count++; } diff --git a/Modules/LocateArrow.cs b/Modules/LocateArrow.cs index 5652f773a..b120a04f3 100644 --- a/Modules/LocateArrow.cs +++ b/Modules/LocateArrow.cs @@ -1,7 +1,7 @@ -using EHR.Modules; -using Hazel; using System.Collections.Generic; using System.Linq; +using EHR.Modules; +using Hazel; using UnityEngine; namespace EHR; diff --git a/Modules/LogHandler/ILogHandler.cs b/Modules/LogHandler/ILogHandler.cs deleted file mode 100644 index e262deff2..000000000 --- a/Modules/LogHandler/ILogHandler.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace EHR.Modules; - -public interface ILogHandler -{ - public void Info(string text); - public void Warn(string text); - public void Error(string text); - public void Fatal(string text); - public void Msg(string text); - public void Exception(Exception ex); -} \ No newline at end of file diff --git a/Modules/LogHandler/LogHandler.cs b/Modules/LogHandler/LogHandler.cs index 270fb83d9..0311016fe 100644 --- a/Modules/LogHandler/LogHandler.cs +++ b/Modules/LogHandler/LogHandler.cs @@ -2,7 +2,7 @@ using System; namespace EHR.Modules; -internal class LogHandler(string tag) : ILogHandler +internal class LogHandler(string tag) { public string Tag { get; } = tag; diff --git a/Modules/NameColorManager.cs b/Modules/NameColorManager.cs index 4b9d0f177..346df0580 100644 --- a/Modules/NameColorManager.cs +++ b/Modules/NameColorManager.cs @@ -298,9 +298,7 @@ public static class NameColorManager private static void Remove(byte seerId, byte targetId) { PlayerState state = Main.PlayerStates[seerId]; - if (!state.TargetColorData.ContainsKey(targetId)) return; - - state.TargetColorData.Remove(targetId); + if (!state.TargetColorData.Remove(targetId)) return; SendRPC(seerId, targetId); } diff --git a/Modules/NameNotifyManager.cs b/Modules/NameNotifyManager.cs index 12541b491..323f8c2f9 100644 --- a/Modules/NameNotifyManager.cs +++ b/Modules/NameNotifyManager.cs @@ -1,7 +1,7 @@ -using EHR.Modules; -using Hazel; -using System; +using System; using System.Collections.Generic; +using EHR.Modules; +using Hazel; using UnityEngine; namespace EHR; @@ -69,9 +69,7 @@ public static class NameNotifyManager var notifyEnumerator = Notifies.GetEnumerator(); while (notifyEnumerator.MoveNext()) { - var pair = notifyEnumerator.Current; - byte id = pair.Key; - var dict = pair.Value; + (byte id, Dictionary dict) = notifyEnumerator.Current; List toRemove = null; var innerEnumerator = dict.GetEnumerator(); diff --git a/Modules/OptionItem/OptionItem.cs b/Modules/OptionItem/OptionItem.cs index 8480810eb..f675048d5 100644 --- a/Modules/OptionItem/OptionItem.cs +++ b/Modules/OptionItem/OptionItem.cs @@ -1,7 +1,7 @@ -using EHR.Modules; -using EHR.Patches; using System; using System.Collections.Generic; +using EHR.Modules; +using EHR.Patches; using UnityEngine; namespace EHR; @@ -12,8 +12,6 @@ public abstract class OptionItem public const int PresetId = 0; public readonly List Children; - private Dictionary _replacementDictionary; - public OptionBehaviour OptionBehaviour; protected OptionItem(int id, string name, int defaultValue, TabGroup tab, bool isSingleValue) @@ -70,13 +68,13 @@ public abstract class OptionItem public Dictionary ReplacementDictionary { - get => _replacementDictionary; + get; set { if (value == null) - _replacementDictionary?.Clear(); + field?.Clear(); else - _replacementDictionary = value; + field = value; } } @@ -306,12 +304,12 @@ public abstract class OptionItem public static OptionItem operator ++(OptionItem item) { - return item.Do(item => item.SetValue(item.CurrentValue + 1)); + return item.Do(optionItem => optionItem.SetValue(optionItem.CurrentValue + 1)); } public static OptionItem operator --(OptionItem item) { - return item.Do(item => item.SetValue(item.CurrentValue - 1)); + return item.Do(optionItem => optionItem.SetValue(optionItem.CurrentValue - 1)); } protected static void SwitchPreset(int newPreset) @@ -329,7 +327,7 @@ public abstract class OptionItem if ( PlayerControl.AllPlayerControls.Count <= 1 || !AmongUsClient.Instance.AmHost - || PlayerControl.LocalPlayer == null + || !PlayerControl.LocalPlayer ) return; diff --git a/Modules/OptionItem/TextOptionItem.cs b/Modules/OptionItem/TextOptionItem.cs index 5ebed2761..8ec1cc539 100644 --- a/Modules/OptionItem/TextOptionItem.cs +++ b/Modules/OptionItem/TextOptionItem.cs @@ -2,27 +2,15 @@ namespace EHR; public class TextOptionItem : OptionItem { - public IntegerValueRule Rule; - public TextOptionItem(int id, string name, TabGroup tab, int defaultValue = 0, bool isSingleValue = false) : base(id, name, defaultValue, tab, isSingleValue) { IsText = true; IsHeader = true; } - public bool CollapsesSection { get; set; } = false; + public bool CollapsesSection { get; set; } // Getter - public override int GetInt() - { - return Rule.GetValueByIndex(CurrentValue); - } - - public override float GetFloat() - { - return Rule.GetValueByIndex(CurrentValue); - } - public override string GetString() { return Translator.GetString(Name); diff --git a/Modules/OptionItem/ValueRule.cs b/Modules/OptionItem/ValueRule.cs index 98d07d93e..582549e2e 100644 --- a/Modules/OptionItem/ValueRule.cs +++ b/Modules/OptionItem/ValueRule.cs @@ -4,16 +4,12 @@ namespace EHR; public abstract class ValueRule(T minValue, T maxValue, T step) { - public ValueRule((T, T, T) tuple) + protected ValueRule((T, T, T) tuple) : this(tuple.Item1, tuple.Item2, tuple.Item3) { } - public T MinValue { get; protected set; } = minValue; - public T MaxValue { get; protected set; } = maxValue; - public T Step { get; protected set; } = step; - - public abstract int RepeatIndex(int value); - public abstract T GetValueByIndex(int index); - public abstract int GetNearestIndex(T num); + public T MinValue { get; } = minValue; + public T MaxValue { get; } = maxValue; + public T Step { get; } = step; } public class IntegerValueRule : ValueRule @@ -29,21 +25,21 @@ public class IntegerValueRule : ValueRule return new(tuple); } - public override int RepeatIndex(int value) + public virtual int RepeatIndex(int value) { - int MaxIndex = (MaxValue - MinValue) / Step; - value %= MaxIndex + 1; - if (value < 0) value = MaxIndex; + int maxIndex = (MaxValue - MinValue) / Step; + value %= maxIndex + 1; + if (value < 0) value = maxIndex; return value; } - public override int GetValueByIndex(int index) + public virtual int GetValueByIndex(int index) { return (RepeatIndex(index) * Step) + MinValue; } - public override int GetNearestIndex(int num) + public virtual int GetNearestIndex(int num) { return (int)Math.Round((num - MinValue) / (float)Step); } @@ -62,21 +58,21 @@ public class FloatValueRule : ValueRule return new(tuple); } - public override int RepeatIndex(int value) + public virtual int RepeatIndex(int value) { - var MaxIndex = (int)((MaxValue - MinValue) / Step); - value %= MaxIndex + 1; - if (value < 0) value = MaxIndex; + var maxIndex = (int)((MaxValue - MinValue) / Step); + value %= maxIndex + 1; + if (value < 0) value = maxIndex; return value; } - public override float GetValueByIndex(int index) + public virtual float GetValueByIndex(int index) { return (RepeatIndex(index) * Step) + MinValue; } - public override int GetNearestIndex(float num) + public virtual int GetNearestIndex(float num) { return (int)Math.Round((num - MinValue) / Step); } diff --git a/Modules/SimpleButton.cs b/Modules/SimpleButton.cs index f4015b586..bdbe43c8b 100644 --- a/Modules/SimpleButton.cs +++ b/Modules/SimpleButton.cs @@ -7,9 +7,6 @@ namespace EHR; public class SimpleButton { private static PassiveButton BaseButton; - private readonly BoxCollider2D buttonCollider; - private float _fontSize; - private Vector2 _scale; /// Creates a new button /// Parent object @@ -36,7 +33,7 @@ public class SimpleButton Label = Button.transform.Find("FontPlacer/Text_TMP").GetComponent(); NormalSprite = Button.inactiveSprites.GetComponent(); HoverSprite = Button.activeSprites.GetComponent(); - buttonCollider = Button.GetComponent(); + Button.GetComponent(); // Center the label Transform container = Label.transform.parent; @@ -59,18 +56,6 @@ public class SimpleButton public SpriteRenderer NormalSprite { get; } public SpriteRenderer HoverSprite { get; } - public Vector2 Scale - { - get => _scale; - set => _scale = NormalSprite.size = HoverSprite.size = buttonCollider.size = value; - } - - public float FontSize - { - get => _fontSize; - set => _fontSize = Label.fontSize = Label.fontSizeMin = Label.fontSizeMax = value; - } - public static void SetBase(PassiveButton passiveButton) { if (BaseButton || !passiveButton) return; diff --git a/Modules/SpamManager.cs b/Modules/SpamManager.cs index e30679d56..1d74abcb7 100644 --- a/Modules/SpamManager.cs +++ b/Modules/SpamManager.cs @@ -5,7 +5,6 @@ using System.IO; using System.Linq; using System.Reflection; using System.Text; -using Hazel; using static EHR.Translator; namespace EHR; diff --git a/Modules/StateMachineWrapper.cs b/Modules/StateMachineWrapper.cs index 0674cd1bc..64385ac9b 100644 --- a/Modules/StateMachineWrapper.cs +++ b/Modules/StateMachineWrapper.cs @@ -3,6 +3,7 @@ using System; using System.Reflection; using HarmonyLib; + #pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. namespace EHR.Modules; diff --git a/Modules/TemplateManager.cs b/Modules/TemplateManager.cs index 6164ee969..1d3393454 100644 --- a/Modules/TemplateManager.cs +++ b/Modules/TemplateManager.cs @@ -18,7 +18,7 @@ public static class TemplateManager private static readonly string TemplateFilePath = $"{Main.DataPath}/EHR_DATA/template.txt"; private static readonly Regex HeaderRegex = new( - @"^([a-zA-Z0-9_]+)(?:\[([^\]""]*(?:""[^""]*""[^\]""]*)*)\])?:\s*(.*)$", + """^([a-zA-Z0-9_]+)(?:\[([^\]"]*(?:"[^"]*"[^\]"]*)*)\])?:\s*(.*)$""", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static readonly Regex PropertyRegex = new( @@ -74,7 +74,7 @@ public static class TemplateManager ["GameDuration"] = () => { if (!GameStates.IsInGame) return "00:00"; int e = (int)(Utils.TimeStamp - IntroCutsceneDestroyPatch.IntroDestroyTS); return $"{e / 60:00}:{e % 60:00}"; }, ["Date"] = () => DateTime.Now.ToShortDateString(), ["Time"] = () => DateTime.Now.ToShortTimeString(), - ["Preset"] = () => GetString($"Preset_{OptionItem.CurrentPreset + 1}"), + ["Preset"] = () => GetString($"Preset_{OptionItem.CurrentPreset + 1}") }; private class TemplateEntry @@ -285,7 +285,9 @@ public static class TemplateManager // Pulls `key="..."` out of propString, returning the quoted value and the remaining string private static string ExtractQuotedProperty(string input, string key, out string value, out string remaining) { - Match m = Regex.Match(input, $@"(?:^|,)\s*{Regex.Escape(key)}\s*=\s*""((?:[^""\\]|\\.)*)""", RegexOptions.IgnoreCase); + Match m = Regex.Match(input, $""" + (?:^|,)\s*{Regex.Escape(key)}\s*=\s*"((?:[^"\\]|\\.)*)" + """, RegexOptions.IgnoreCase); if (m.Success) { value = Regex.Unescape(m.Groups[1].Value); diff --git a/Modules/Translator.cs b/Modules/Translator.cs index 01e5c7933..c7603a93b 100644 --- a/Modules/Translator.cs +++ b/Modules/Translator.cs @@ -1,5 +1,4 @@ -using EHR.Gamemodes; -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -7,6 +6,7 @@ using System.Linq; using System.Reflection; using System.Text; using System.Text.Json; +using EHR.Gamemodes; namespace EHR; @@ -36,7 +36,7 @@ public static class Translator try { // Get the directory containing the JSON files (e.g., EHR.Resources.Lang) - var jsonDirectory = "EHR.Resources.Lang"; + const string jsonDirectory = "EHR.Resources.Lang"; // Get the assembly containing the resources var assembly = Assembly.GetExecutingAssembly(); string[] jsonFileNames = GetJsonFileNames(assembly, jsonDirectory); @@ -174,7 +174,7 @@ public static class Translator string str = GetString(s, langId); - if (replacementDic != null && replacementDic.Count > 0) + if (replacementDic is { Count: > 0 }) { foreach (KeyValuePair rd in replacementDic) str = str.Replace(rd.Key, rd.Value); diff --git a/Modules/Utils.cs b/Modules/Utils.cs index f6e0480aa..1d02197bc 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -1,3 +1,14 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.RegularExpressions; using AmongUs.Data; using AmongUs.GameOptions; using AmongUs.InnerNet.GameDataMessages; @@ -12,17 +23,6 @@ using Il2CppInterop.Runtime.InteropTypes; using Il2CppInterop.Runtime.InteropTypes.Arrays; using InnerNet; using Newtonsoft.Json; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Text; -using System.Text.RegularExpressions; using UnityEngine; using static EHR.Translator; using Tree = EHR.Roles.Tree; @@ -330,7 +330,7 @@ public static class Utils foreach (PlayerControl seer in Main.CachedAllPlayerControls()) { - if (KillFlashCheck(killer, target, seer)) + if (seer.Is(CustomRoles.GM) || seer.Is(CustomRoles.Seer)) { seer.KillFlash(); continue; @@ -358,15 +358,6 @@ public static class Utils } } - private static bool KillFlashCheck(PlayerControl killer, PlayerControl target, PlayerControl seer) - { - if (seer.Is(CustomRoles.GM) || seer.Is(CustomRoles.Seer)) return true; - - // if (!seer.IsAlive() || killer == seer || target == seer) return false; - - return false; - } - public static void BlackOut(this IGameOptions opt, bool blackOut) { opt.SetFloat(FloatOptionNames.ImpostorLightMod, blackOut ? 0 : Main.DefaultImpostorVision); @@ -3137,7 +3128,7 @@ public static class Utils var state = states[devourerList[index]]; var role = state.Role; - if (role is Devourer dv && dv.IsEnable && dv.PlayerSkinsCosumed.Contains(seerId)) + if (role is Devourer { IsEnable: true } dv && dv.PlayerSkinsCosumed.Contains(seerId)) { selfName = GetString("DevouredName"); break; @@ -3477,7 +3468,7 @@ public static class Utils var state = states[devourerList[index]]; var role = state.Role; - if (role is Devourer dv && dv.IsEnable && dv.PlayerSkinsCosumed.Contains(seerId)) + if (role is Devourer { IsEnable: true } dv && dv.PlayerSkinsCosumed.Contains(seerId)) { targetPlayerName = GetString("DevouredName"); break; @@ -3600,9 +3591,7 @@ public static class Utils var markList = Markseeker.PlayerIdList; for (int i = 0; i < markList.Count; i++) { - if (states[markList[i]].Role is Markseeker role && - role.IsEnable && - role.TargetRevealed && + if (states[markList[i]].Role is Markseeker { IsEnable: true, TargetRevealed: true } role && role.MarkedId == targetId) return true; } @@ -3680,10 +3669,6 @@ public static class Utils break; case CustomRoles.Jackal: - if (local.Is(CustomRoles.Jackal) || local.Is(CustomRoles.Sidekick)) - return true; - break; - case CustomRoles.Sidekick: if (local.Is(CustomRoles.Jackal) || local.Is(CustomRoles.Sidekick)) return true; @@ -3746,9 +3731,7 @@ public static class Utils var markList = Markseeker.PlayerIdList; for (int i = 0; i < markList.Count; i++) { - if (states[markList[i]].Role is Markseeker role && - role.IsEnable && - role.TargetRevealed && + if (states[markList[i]].Role is Markseeker { IsEnable: true, TargetRevealed: true } role && role.MarkedId == targetId) return true; } diff --git a/Patches/AprilFoolsPatch.cs b/Patches/AprilFoolsPatch.cs index d82a3743c..8eb3592ff 100644 --- a/Patches/AprilFoolsPatch.cs +++ b/Patches/AprilFoolsPatch.cs @@ -33,7 +33,6 @@ public static class GetNormalBodyTypePatch if (Main.ClassicMode.Value || AprilFoolsMode.ShouldClassicMode()) { __result = PlayerBodyTypes.Classic; - return; } } catch { } diff --git a/Patches/CheckGameEndPatch.cs b/Patches/CheckGameEndPatch.cs index 4c093454c..f3f415e5e 100644 --- a/Patches/CheckGameEndPatch.cs +++ b/Patches/CheckGameEndPatch.cs @@ -1,3 +1,7 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; using AmongUs.GameOptions; using BepInEx.Unity.IL2CPP.Utils.Collections; using EHR.Gamemodes; @@ -6,10 +10,6 @@ using EHR.Roles; using HarmonyLib; using Hazel; using InnerNet; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; using UnityEngine; using static EHR.CustomWinnerHolder; using static EHR.Translator; diff --git a/Patches/ClientPatch.cs b/Patches/ClientPatch.cs index 45d850dd4..f08fdd0d0 100644 --- a/Patches/ClientPatch.cs +++ b/Patches/ClientPatch.cs @@ -1,11 +1,12 @@ -using AmongUs.Data; -using EHR.Modules; -using HarmonyLib; -using Il2CppInterop.Runtime.InteropTypes; -using InnerNet; using System; using System.Linq; using System.Reflection; +using AmongUs.Data; +using EHR.Modules; +using HarmonyLib; +using Hazel; +using Il2CppInterop.Runtime.InteropTypes; +using InnerNet; using TMPro; using UnityEngine; using static EHR.Translator; @@ -35,7 +36,7 @@ internal static class MakePublicPatch [HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.StartRpcImmediately))] static class StartRpcImmediatelyPatch { - public static void Postfix(uint targetNetId, byte callId, Hazel.SendOption option, int targetClientId = -1) + public static void Postfix(uint targetNetId, byte callId, SendOption option, int targetClientId = -1) { if (callId is 21 or 44 or 45 or 104) return; Logger.Info($"Starting RPC: {callId} ({RPC.GetRpcName(callId)}) as {Main.CachedAllPlayerControls().FirstOrDefault(x => x.NetId == targetNetId)?.GetRealName() ?? targetNetId.ToString()} with SendOption {option} to {Utils.GetClientById(targetClientId)?.Character?.GetRealName() ?? targetClientId.ToString()}", "StartRpcImmediately"); diff --git a/Patches/ControlPatch.cs b/Patches/ControlPatch.cs index 71eb36ddc..f6ffe5536 100644 --- a/Patches/ControlPatch.cs +++ b/Patches/ControlPatch.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; using EHR.Modules; using EHR.Patches; using HarmonyLib; @@ -35,6 +34,9 @@ internal static class ControllerManagerUpdatePatch private static readonly KeyCode[] ShowActiveSettingsKey = [KeyCode.N, KeyCode.LeftControl]; private static readonly KeyCode[] ResetAllOptionsKey = [KeyCode.Delete, KeyCode.LeftControl, KeyCode.LeftShift]; private static readonly KeyCode[] HostKillSelfKey = [KeyCode.Return, KeyCode.E, KeyCode.LeftShift]; + private static readonly KeyCode[] OpenClientControlGUILeftKey = [KeyCode.LeftControl, KeyCode.BackQuote]; + private static readonly KeyCode[] OpenClientControlGUIRightKey = [KeyCode.RightControl, KeyCode.BackQuote]; +#if DEBUG private static readonly KeyCode[] IsAlsoInGameKey = [KeyCode.F2, KeyCode.LeftControl]; private static readonly KeyCode[] KillFlashKey = [KeyCode.Return, KeyCode.F, KeyCode.LeftShift]; private static readonly KeyCode[] ShowIntroKey = [KeyCode.Return, KeyCode.G, KeyCode.LeftShift]; @@ -42,8 +44,7 @@ internal static class ControllerManagerUpdatePatch private static readonly KeyCode[] RpcUpdateSystemKey = [KeyCode.Return, KeyCode.D, KeyCode.LeftShift]; private static readonly KeyCode[] SetKillTimerKey = [KeyCode.Return, KeyCode.K, KeyCode.LeftShift]; private static readonly KeyCode[] RpcCompleteTaskKey = [KeyCode.Return, KeyCode.T, KeyCode.LeftShift]; - private static readonly KeyCode[] OpenClientControlGUILeftKey = [KeyCode.LeftControl, KeyCode.BackQuote]; - private static readonly KeyCode[] OpenClientControlGUIRightKey = [KeyCode.RightControl, KeyCode.BackQuote]; +#endif private static bool IsResetting; diff --git a/Patches/CredentialsPatch.cs b/Patches/CredentialsPatch.cs index 6179938be..1a96f7c93 100644 --- a/Patches/CredentialsPatch.cs +++ b/Patches/CredentialsPatch.cs @@ -1,9 +1,8 @@ -using EHR.Modules; -using HarmonyLib; using System; using System.Collections.Generic; -using System.Linq; using System.Runtime.CompilerServices; +using EHR.Modules; +using HarmonyLib; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; diff --git a/Patches/Crowded.cs b/Patches/Crowded.cs index 32bea3448..b0f6f10ef 100644 --- a/Patches/Crowded.cs +++ b/Patches/Crowded.cs @@ -1,11 +1,11 @@ -using AmongUs.GameOptions; -using HarmonyLib; -using Il2CppInterop.Runtime.Attributes; -using Il2CppInterop.Runtime.InteropTypes.Arrays; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; +using AmongUs.GameOptions; +using HarmonyLib; +using Il2CppInterop.Runtime.Attributes; +using Il2CppInterop.Runtime.InteropTypes.Arrays; using TMPro; using UnityEngine; using static EHR.GameStates; diff --git a/Patches/DisconnectPenaltyPatch.cs b/Patches/DisconnectPenaltyPatch.cs deleted file mode 100644 index be0c9ef93..000000000 --- a/Patches/DisconnectPenaltyPatch.cs +++ /dev/null @@ -1 +0,0 @@ -namespace EHR.Patches; \ No newline at end of file diff --git a/Patches/DleksPatch.cs b/Patches/DleksPatch.cs index 1c0f9e558..be4efa1a8 100644 --- a/Patches/DleksPatch.cs +++ b/Patches/DleksPatch.cs @@ -1,7 +1,8 @@ -using EHR.Patches; +using System.Linq; +using EHR.Patches; using HarmonyLib; -using System; -using System.Linq; +using Il2CppSystem; +using Exception = System.Exception; namespace EHR; @@ -14,22 +15,22 @@ internal static class AllMapIconsPatch [HarmonyPrefix] public static void GameStartManagerStart_Prefix(GameStartManager __instance) { - if (__instance.AllMapIcons.TrueForAll((Il2CppSystem.Predicate)(x => x.Name != MapNames.Dleks))) + if (__instance.AllMapIcons.TrueForAll((Predicate)(x => x.Name != MapNames.Dleks))) { __instance.AllMapIcons.Insert((int)MapNames.Dleks, new MapIconByName { Name = MapNames.Dleks, - MapIcon = Utils.LoadSprite("EHR.Resources.Images.DleksBanner-Wordart.png", 160f), + MapIcon = Utils.LoadSprite("EHR.Resources.Images.DleksBanner-Wordart.png", 160f) }); } if (SubmergedCompatibility.Loaded) { - if (__instance.AllMapIcons.TrueForAll((Il2CppSystem.Predicate)(x => x.Name != (MapNames)6))) + if (__instance.AllMapIcons.TrueForAll((Predicate)(x => x.Name != (MapNames)6))) { __instance.AllMapIcons.Insert((int)(MapNames)6, new MapIconByName { Name = (MapNames)6, - MapIcon = Utils.LoadSprite("EHR.Resources.Images.Submerged-Wordart.png", 380f), + MapIcon = Utils.LoadSprite("EHR.Resources.Images.Submerged-Wordart.png", 380f) }); } } diff --git a/Patches/ExilePatch.cs b/Patches/ExilePatch.cs index 601a8b3a1..a0deb6502 100644 --- a/Patches/ExilePatch.cs +++ b/Patches/ExilePatch.cs @@ -1,11 +1,12 @@ -using System; using System.Diagnostics; using System.Linq; +using System.Reflection; using AmongUs.Data; using EHR.Modules; using EHR.Roles; using HarmonyLib; using Hazel; +using Il2CppInterop.Runtime.InteropTypes; namespace EHR.Patches; @@ -220,12 +221,12 @@ internal static class ExileControllerWrapUpPatch [HarmonyPatch] static class AirshipExileControllerPatch { - public static System.Reflection.MethodBase TargetMethod() + public static MethodBase TargetMethod() { return Utils.GetStateMachineMoveNext(nameof(AirshipExileController.WrapUpAndSpawn)); } - public static void Postfix(Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase __instance, ref bool __result) + public static void Postfix(Il2CppObjectBase __instance, ref bool __result) { var wrapper = new StateMachineWrapper(__instance); diff --git a/Patches/GameStartManagerPatch.cs b/Patches/GameStartManagerPatch.cs index d6550e66c..307c76769 100644 --- a/Patches/GameStartManagerPatch.cs +++ b/Patches/GameStartManagerPatch.cs @@ -1,3 +1,6 @@ +using System; +using System.Collections.Generic; +using System.Linq; using AmongUs.Data; using AmongUs.GameOptions; using EHR.Gamemodes; @@ -5,10 +8,6 @@ using EHR.Patches; using EHR.Roles; using HarmonyLib; using InnerNet; -using Rewired.Utils.Platforms.Windows; -using System; -using System.Collections.Generic; -using System.Linq; using TMPro; using UnityEngine; using static EHR.Translator; diff --git a/Patches/HandshakePatch.cs b/Patches/HandshakePatch.cs index d8721f6a7..2400216ff 100644 --- a/Patches/HandshakePatch.cs +++ b/Patches/HandshakePatch.cs @@ -38,7 +38,7 @@ public enum ModFlags : ushort /// /// Notifies the game server that the host has authority over game logic. /// - DisableServerAuthority = 1 << 3, + DisableServerAuthority = 1 << 3 } @@ -60,7 +60,7 @@ public enum ReactorProtocolVersion : byte /// /// Latest version. /// - Latest = V3, + Latest = V3 } [HarmonyPatch(typeof(InnerNetClient), nameof(InnerNetClient.GetConnectionData))] diff --git a/Patches/HudPatch.cs b/Patches/HudPatch.cs index f754f04da..9ed7a0c43 100644 --- a/Patches/HudPatch.cs +++ b/Patches/HudPatch.cs @@ -1,15 +1,14 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Reflection; using AmongUs.GameOptions; using EHR.Gamemodes; using EHR.Modules; using EHR.Roles; using HarmonyLib; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.Linq; -using System.Reflection; using TMPro; using UnityEngine; using static EHR.Translator; @@ -269,12 +268,12 @@ internal static class HudManagerPatch break; } - if (ShouldHideAbilityButton(role, player)) + if (ShouldHideAbilityButton()) { __instance.AbilityButton?.Hide(); } - bool ShouldHideAbilityButton(CustomRoles role, PlayerControl player) + bool ShouldHideAbilityButton() { if (!role.PetActivatedAbility() || Options.CurrentGameMode != CustomGameMode.Standard @@ -341,12 +340,11 @@ internal static class HudManagerPatch { Sb.Clear(); Suffixes.Clear(); - string suffixText = string.Empty; var subRoles = state.SubRoles; for (int i = 0; i < subRoles.Count; i++) { - suffixText = subRoles[i] switch + string suffixText = subRoles[i] switch { CustomRoles.Asthmatic => Asthmatic.GetSuffixText(player.PlayerId), CustomRoles.Spurt => Spurt.GetSuffix(player, true), @@ -924,7 +922,7 @@ internal static class SabotageMapPatch [HarmonyPatch(typeof(MapRoom), nameof(MapRoom.Start))] internal static class MapRoomDoorsStartPatch { - public static void Postfix(MapRoom __instance) + public static void Postfix() { ShipStatus shipStatusInstance = ShipStatus.Instance; if (!shipStatusInstance || SubmergedCompatibility.IsSubmerged()) return; @@ -945,9 +943,9 @@ internal static class MapRoomDoorsUpdatePatch { public static Dictionary DoorTimerTexts = []; private static readonly int Percent = Shader.PropertyToID("_Percent"); - public static DoorsSystemType DoorsSystemType = null; - public static AutoDoorsSystemType AutoDoorsSystemType = null; - public static Dictionary AutoOpenDoors = []; + public static DoorsSystemType DoorsSystemType; + public static AutoDoorsSystemType AutoDoorsSystemType; + public static readonly Dictionary AutoOpenDoors = []; public static bool Prefix(MapRoom __instance) { @@ -957,8 +955,8 @@ internal static class MapRoomDoorsUpdatePatch if (!doorSprite || !shipStatusInstance || SubmergedCompatibility.IsSubmerged()) return false; SystemTypes room = __instance.room; - float total = 0f; - float timer = 0f; + float total; + float timer; if (DoorsSystemType != null) { @@ -1048,7 +1046,6 @@ internal static class SpawnTaskHeaderPatch internal static class TaskPanelBehaviourPatch { // Role info tab panel code from https://github.com/All-Of-Us-Mods/MiraAPI and https://github.com/AU-Avengers/TOU-Mira - private static readonly StringBuilder Sb = new(); private static readonly StringBuilder InnerSb = new(); private static readonly StringBuilder RoleWithInfoBuilder = new(); private static readonly StringBuilder FinalTextBuilder = new(); @@ -1059,7 +1056,6 @@ internal static class TaskPanelBehaviourPatch private static readonly List<(PlayerControl pc, string points_string, int points_int)> TempPointsData = []; private static readonly List SortedPlayers = []; - private static readonly List SummaryTextList = []; private static readonly Dictionary SummaryText = []; public static PassiveButton RolePanelButton; @@ -1116,7 +1112,7 @@ internal static class TaskPanelBehaviourPatch string roleInfo = player.GetRoleInfo(); Dictionary playerStates = Main.PlayerStates; - List AllPlayers = Main.CachedAllPlayerControls(); + List allPlayers = Main.CachedAllPlayerControls(); RoleWithInfoBuilder.Clear(); int wordCount = 0; @@ -1203,7 +1199,7 @@ internal static class TaskPanelBehaviourPatch InnerSb.Clear().Append("\r\n\r\n") .Append(subRole.ToColoredString()) .Append(":\r\n") - .Append(GetString(subRole.ToString() + "Info")); + .Append(GetString(subRole + "Info")); FinalTextBuilder.Append(Utils.ColorString(Utils.GetRoleColor(subRole), InnerSb.ToString())); } @@ -1215,7 +1211,7 @@ internal static class TaskPanelBehaviourPatch var chunk = 4; for (int index = 0; index < countSubRoles; index++) { - if (GetString(subRoles[index].ToString()).IndexOf(' ') >= 0) + if (GetString(subRoles[index].ToString()).Contains(' ')) { chunk = 3; break; @@ -1270,11 +1266,8 @@ internal static class TaskPanelBehaviourPatch SortedPlayers.Add(key); if (SortedPlayers.Count >= 2) - SortedPlayers.Sort((a, b) => - { - return SoloPVP.GetRankFromScore(a) - .CompareTo(SoloPVP.GetRankFromScore(b)); - }); + SortedPlayers.Sort((a, b) => SoloPVP.GetRankFromScore(a) + .CompareTo(SoloPVP.GetRankFromScore(b))); for (int sPId = 0; sPId < SortedPlayers.Count; sPId++) { @@ -1298,11 +1291,8 @@ internal static class TaskPanelBehaviourPatch SortedPlayers.Add(key); if (SortedPlayers.Count >= 2) - SortedPlayers.Sort((a, b) => - { - return FreeForAll.GetRankFromScore(a) - .CompareTo(FreeForAll.GetRankFromScore(b)); - }); + SortedPlayers.Sort((a, b) => FreeForAll.GetRankFromScore(a) + .CompareTo(FreeForAll.GetRankFromScore(b))); for (int sPId = 0; sPId < SortedPlayers.Count; sPId++) { @@ -1397,9 +1387,9 @@ internal static class TaskPanelBehaviourPatch case CustomGameMode.NaturalDisasters: { TempPlayerData.Clear(); - for (int i = 0; i < AllPlayers.Count; i++) + for (int i = 0; i < allPlayers.Count; i++) { - var pc = AllPlayers[i]; + var pc = allPlayers[i]; TempPlayerData.Add((pc, pc.IsAlive(), NaturalDisasters.SurvivalTime(pc.PlayerId))); } if (TempPlayerData.Count >= 2) @@ -1415,7 +1405,7 @@ internal static class TaskPanelBehaviourPatch for (int i = 0; i < TempPlayerData.Count; i++) { - var (pc, alive, time) = TempPlayerData[i]; + (PlayerControl pc, bool alive, int time) = TempPlayerData[i]; FinalTextBuilder.Append("\r\n") .Append(pc.PlayerId.ColoredPlayerName()) @@ -1434,9 +1424,9 @@ internal static class TaskPanelBehaviourPatch if (!RoomRush.PointsSystem) { - for (int i = 0; i < AllPlayers.Count; i++) + for (int i = 0; i < allPlayers.Count; i++) { - var pc = AllPlayers[i]; + var pc = allPlayers[i]; TempPlayerData.Add((pc, pc.IsAlive(), RoomRush.GetSurvivalTime(pc.PlayerId))); } if (TempPlayerData.Count >= 2) @@ -1450,7 +1440,7 @@ internal static class TaskPanelBehaviourPatch for (int i = 0; i < TempPlayerData.Count; i++) { - var (pc, alive, time) = TempPlayerData[i]; + (PlayerControl pc, bool alive, int time) = TempPlayerData[i]; FinalTextBuilder.Append("\r\n") .Append(pc.PlayerId.ColoredPlayerName()) @@ -1461,9 +1451,9 @@ internal static class TaskPanelBehaviourPatch } else { - for (int i = 0; i < AllPlayers.Count; i++) + for (int i = 0; i < allPlayers.Count; i++) { - var pc = AllPlayers[i]; + var pc = allPlayers[i]; string pointsStr = RoomRush.GetPoints(pc.PlayerId); int pointsInt = ParsePointsFast(pointsStr); @@ -1474,7 +1464,7 @@ internal static class TaskPanelBehaviourPatch for (int i = 0; i < TempPointsData.Count; i++) { - var (pc, points_string, points_int) = TempPointsData[i]; + (PlayerControl pc, string points_string, _) = TempPointsData[i]; FinalTextBuilder.Append("\r\n") .Append(pc.PlayerId.ColoredPlayerName()) diff --git a/Patches/HudSpritePatch.cs b/Patches/HudSpritePatch.cs index 463606d54..c6178053b 100644 --- a/Patches/HudSpritePatch.cs +++ b/Patches/HudSpritePatch.cs @@ -45,7 +45,7 @@ public static class HudSpritePatch Sprite newSabotageButton = DefaultIcons[3]; Sprite newPetButton = DefaultIcons[4]; Sprite newReportButton = DefaultIcons[5]; - Sprite newSecondaryAbilityButton = DefaultIcons[6]; + //Sprite newSecondaryAbilityButton = DefaultIcons[6]; if (!player.IsAlive()) { @@ -257,7 +257,7 @@ public static class HudSpritePatch case CustomRoles.Convener: { if (Options.UsePets.GetBool()) newPetButton = CustomButton.Get("Convener"); - else newPetButton = CustomButton.Get("Convener"); + else newAbilityButton = CustomButton.Get("Convener"); break; } case CustomRoles.Doorjammer: diff --git a/Patches/JoinGameButtonPatch.cs b/Patches/JoinGameButtonPatch.cs index 21519ff41..b471e68e3 100644 --- a/Patches/JoinGameButtonPatch.cs +++ b/Patches/JoinGameButtonPatch.cs @@ -11,7 +11,7 @@ internal class JoinGameButtonPatch { if (__instance.GameIdText == null) return; - if (__instance.GameIdText.text == "" && Regex.IsMatch(GUIUtility.systemCopyBuffer.Trim('\r', '\n'), @"^[A-Z]{6}$")) + if (__instance.GameIdText.text == "" && Regex.IsMatch(GUIUtility.systemCopyBuffer.Trim('\r', '\n'), "^[A-Z]{6}$")) { Logger.Info($"{GUIUtility.systemCopyBuffer}", "ClipBoard"); __instance.GameIdText.SetText(GUIUtility.systemCopyBuffer.Trim('\r', '\n')); diff --git a/Patches/LogoAndStampPatch.cs b/Patches/LogoAndStampPatch.cs deleted file mode 100644 index 17613f7d3..000000000 --- a/Patches/LogoAndStampPatch.cs +++ /dev/null @@ -1,152 +0,0 @@ -using System.Collections; -using BepInEx.Unity.IL2CPP.Utils; -using HarmonyLib; -using UnityEngine; -using static EHR.Translator; - -namespace EHR; - -// Credit: https://github.com/ykundesu/SuperNewRoles/blob/master/SuperNewRoles/Patches/LogoAndStampPatch.cs -[HarmonyPatch] -public static class CredentialsPatch -{ - [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start))] - public static class LogoPatch - { - private static string BoosterData = string.Empty; - private static string SponsersData = string.Empty; - private static string DevsData = string.Empty; - private static string TransData = string.Empty; - - private static IEnumerator ViewCredentialsCoro(MainMenuManager __instance) - { - while (true) - { - yield return new WaitForSecondsRealtime(1f); - - if (__instance != null) - { - // ViewBoosterPatch(__instance); - } - - break; - } - } - - public static void InitCredentialsData() - { - BoosterData = string.Empty; - SponsersData = string.Empty; - DevsData = string.Empty; - TransData = string.Empty; - - DevsData += $"♥咔皮呆 & Gurge44 - {GetString("MainDev")}"; - DevsData += $"\n♥IRIDESCENT - {GetString("Art")}"; - DevsData += $"\nNCSIMON - {GetString("RoleDev")}"; - DevsData += $"\n天寸梦初 - {GetString("RoleDev")}&{GetString("TechSup")}"; - DevsData += $"\nCommandf1 - {GetString("RoleDev")}&{GetString("FeatureDev")}"; - DevsData += $"\n喜 - {GetString("RoleDev")}"; - DevsData += $"\nSHAAARKY - {GetString("RoleDev")}"; - DevsData += $"\nGurge44 - {GetString("FeatureDev")}"; - - TransData += $"Tommy-XL - {GetString("TranEN")}&{GetString("TranRU")}"; - TransData += $"\nTem - {GetString("TranEN")}&{GetString("TranRU")}"; - TransData += $"\n阿龍 - {GetString("TranCHT")}"; - TransData += $"\nGurge44 - {GetString("TranEN")}"; - TransData += $"\n法官 - {GetString("TranCHT")}"; - TransData += $"\nSolarFlare - {GetString("TranEN")}"; - TransData += $"\nchill_ultimated - {GetString("TranRU")}"; - - BoosterData += "bunny"; - BoosterData += "\nNamra"; - BoosterData += "\nKNIGHT"; - BoosterData += "\nSolarFlare"; - - SponsersData += "罗寄"; - SponsersData += "\n鬼"; - SponsersData += "\n喜"; - SponsersData += "\n小叨院长"; - SponsersData += "\n波奇酱"; - SponsersData += "\n法师"; - SponsersData += "\n沐煊"; - SponsersData += "\nSolarFlare"; - SponsersData += "\n林林林"; - SponsersData += "\n撒币"; - SponsersData += "\n斯卡蒂Skadi"; - SponsersData += "\nltemten"; - SponsersData += $"\n\n({GetString("OnlyShowPart")})"; - } - - /* - static void ViewBoosterPatch(MainMenuManager __instance) - { - var template = __instance.transform.FindChild("StatsPopup"); - var obj = Object.Instantiate(template, template.transform.parent).gameObject; - Object.Destroy(obj.GetComponent()); - - var devtitletext = obj.transform.FindChild("StatNumsText_TMP"); - devtitletext.GetComponent().text = GetString("Developer"); - devtitletext.GetComponent().alignment = TextAlignmentOptions.Center; - devtitletext.localPosition = new(-2.4f, 1.65f, -2f); - devtitletext.localScale = new(0.8f, 0.8f, 0.8f); - - var devtext = obj.transform.FindChild("StatsText_TMP"); - devtext.GetComponent().text = DevsData; - devtext.GetComponent().alignment = TextAlignmentOptions.Capline; - devtext.localPosition = new(-2.4f, 1.27f, -2f); - devtext.localScale = new(0.5f, 0.5f, 1f); - - var transtitletext = Object.Instantiate(devtitletext, obj.transform); - transtitletext.GetComponent().text = GetString("Translator"); - transtitletext.GetComponent().alignment = TextAlignmentOptions.Center; - transtitletext.localPosition = new(0f, 1.65f, -2f); - transtitletext.localScale = new(0.8f, 0.8f, 1f); - - var transtext = Object.Instantiate(devtext, obj.transform); - transtext.GetComponent().text = TransData; - transtext.GetComponent().alignment = TextAlignmentOptions.Capline; - transtext.localPosition = new(0f, 1.27f, -2f); - transtext.localScale = new(0.5f, 0.5f, 1f); - - var boostertitletext = Object.Instantiate(devtitletext, obj.transform); - boostertitletext.GetComponent().text = GetString("Booster"); - boostertitletext.GetComponent().alignment = TextAlignmentOptions.Center; - boostertitletext.localPosition = new(-2.4f, -1f, -2f); - boostertitletext.localScale = new(0.8f, 0.8f, 1f); - - var boostertext = Object.Instantiate(devtext, obj.transform); - boostertext.GetComponent().text = BoosterData; - boostertext.GetComponent().alignment = TextAlignmentOptions.Capline; - boostertext.localPosition = new(-2.4f, -1.38f, -2f); - boostertext.localScale = new(0.5f, 0.5f, 1f); - - var sponsortitletext = Object.Instantiate(devtitletext, obj.transform); - sponsortitletext.GetComponent().text = GetString("Sponsor"); - sponsortitletext.GetComponent().alignment = TextAlignmentOptions.Center; - sponsortitletext.localPosition = new(2.4f, 1.65f, -2f); - sponsortitletext.localScale = new(0.8f, 0.8f, 1f); - - var sponsortext = Object.Instantiate(devtext, obj.transform); - sponsortext.GetComponent().text = SponsersData; - sponsortext.GetComponent().alignment = TextAlignmentOptions.Capline; - sponsortext.localPosition = new(2.4f, 1.27f, -2f); - sponsortext.localScale = new(0.5f, 0.5f, 1f); - - var textobj = obj.transform.FindChild("Title_TMP"); - Object.Destroy(textobj.GetComponent()); - textobj.GetComponent().text = GetString("DevAndSpnTitle"); - textobj.GetComponent().alignment = TextAlignmentOptions.Center; - textobj.localScale = new(1.2f, 1.2f, 1f); - textobj.localPosition = new(0f, 2.2f, -2f); - obj.transform.FindChild("Background").localScale = new(1.5f, 1f, 1f); - obj.transform.FindChild("CloseButton").localPosition = new(-3.75f, 2.65f, 0); - } - */ - - public static void Postfix(MainMenuManager __instance) - { - InitCredentialsData(); - AmongUsClient.Instance.StartCoroutine(ViewCredentialsCoro(__instance)); - } - } -} \ No newline at end of file diff --git a/Patches/MapPickerMenuPatch.cs b/Patches/MapPickerMenuPatch.cs index 847defeb8..50b18f8ab 100644 --- a/Patches/MapPickerMenuPatch.cs +++ b/Patches/MapPickerMenuPatch.cs @@ -1,6 +1,8 @@ -using System; -using HarmonyLib; +using HarmonyLib; +using Il2CppSystem; using UnityEngine.SceneManagement; +using Action = System.Action; +using Exception = System.Exception; namespace EHR.Patches; @@ -23,26 +25,26 @@ public static class GameOptionsMapPickerPatch [HarmonyPrefix] public static void Postfix_Prefix(GameOptionsMapPicker __instance) { - if (__instance.AllMapIcons.TrueForAll((Il2CppSystem.Predicate)(x => x.Name != MapNames.Dleks))) + if (__instance.AllMapIcons.TrueForAll((Predicate)(x => x.Name != MapNames.Dleks))) { __instance.AllMapIcons.Insert((int)MapNames.Dleks, new MapIconByName { Name = MapNames.Dleks, MapImage = Utils.LoadSprite("EHR.Resources.Images.DleksBanner.png", 100f), MapIcon = Utils.LoadSprite("EHR.Resources.Images.DleksBanner-Icon.png", 95f), - NameImage = Utils.LoadSprite("EHR.Resources.Images.DleksBanner-Wordart.png", 160f), + NameImage = Utils.LoadSprite("EHR.Resources.Images.DleksBanner-Wordart.png", 160f) }); } if (SubmergedCompatibility.Loaded) { - if (__instance.AllMapIcons.TrueForAll((Il2CppSystem.Predicate)(x => x.Name != (MapNames)6))) + if (__instance.AllMapIcons.TrueForAll((Predicate)(x => x.Name != (MapNames)6))) { __instance.AllMapIcons.Insert((int)(MapNames)6, new MapIconByName { Name = (MapNames)6, MapImage = Utils.LoadSprite("EHR.Resources.Images.SubmergedBanner.png", 100f), //MapIcon = Utils.LoadSprite("EHR.Resources.Images.Submerged-Icon.png", 100f), - NameImage = Utils.LoadSprite("EHR.Resources.Images.Submerged-Wordart.png", 100f), + NameImage = Utils.LoadSprite("EHR.Resources.Images.Submerged-Wordart.png", 100f) }); } } diff --git a/Patches/MeetingHudPatch.cs b/Patches/MeetingHudPatch.cs index 6bdfc719a..4d14a1ae6 100644 --- a/Patches/MeetingHudPatch.cs +++ b/Patches/MeetingHudPatch.cs @@ -655,32 +655,38 @@ internal static class ExtendedMeetingHud if (Poache.PoachedPlayers.Contains(ps.TargetPlayerId)) voteNum = 0; if (Silencer.ForSilencer.Contains(ps.TargetPlayerId) && Main.AllAlivePlayerControlsCount > Silencer.MaxPlayersAliveForSilencedToVote.GetInt()) voteNum = 0; - if (CheckForEndVotingPatch.CheckRole(ps.TargetPlayerId, CustomRoles.Magistrate) && Magistrate.CallCourtNextMeeting) voteNum += Magistrate.ExtraVotes.GetInt(); if (CheckForEndVotingPatch.CheckRole(ps.TargetPlayerId, CustomRoles.Knighted)) voteNum += 1; - if (CheckForEndVotingPatch.CheckRole(ps.TargetPlayerId, CustomRoles.Glitch) && !Glitch.CanVote.GetBool()) voteNum = 0; - if (CheckForEndVotingPatch.CheckRole(ps.TargetPlayerId, CustomRoles.Shifter) && !Shifter.CanVote.GetBool()) voteNum = 0; - if (CheckForEndVotingPatch.CheckRole(ps.TargetPlayerId, CustomRoles.Vindicator)) voteNum += Options.VindicatorAdditionalVote.GetInt(); if (CheckForEndVotingPatch.CheckRole(ps.TargetPlayerId, CustomRoles.Schizophrenic) && Options.DualVotes.GetBool()) voteNum += voteNum; if (CheckForEndVotingPatch.CheckRole(ps.TargetPlayerId, CustomRoles.Stealer)) voteNum += (int)(Main.EnumeratePlayerControls().Count(x => x.GetRealKiller()?.PlayerId == ps.TargetPlayerId) * Options.VotesPerKill.GetFloat()); - if (CheckForEndVotingPatch.CheckRole(ps.TargetPlayerId, CustomRoles.Pickpocket)) voteNum += (int)(Main.EnumeratePlayerControls().Count(x => x.GetRealKiller()?.PlayerId == ps.TargetPlayerId) * Pickpocket.VotesPerKill.GetFloat()); - + switch (Main.PlayerStates[ps.TargetPlayerId].Role) { + case Dad { IsEnable: true } dad when dad.UsingAbilities.Contains(Dad.Ability.GoForMilk): + case Shifter when !Shifter.CanVote.GetBool(): + case Glitch when !Glitch.CanVote.GetBool(): + voteNum = 0; + break; case Adventurer { IsEnable: true } av when av.ActiveWeapons.Contains(Adventurer.Weapon.Proxy): voteNum++; break; - case Dad { IsEnable: true } dad when dad.UsingAbilities.Contains(Dad.Ability.GoForMilk): - voteNum = 0; - break; case Amogus { IsEnable: true, ExtraVotes: > 0 } amogus: voteNum += amogus.ExtraVotes; break; case Mayor mayor: voteNum += Mayor.MayorAdditionalVote.GetInt() + mayor.TaskVotes; break; - case Survivor survivor when Main.AllAlivePlayerControlsCount <= Survivor.ThirdAbility.GetInt(): + case Survivor when Main.AllAlivePlayerControlsCount <= Survivor.ThirdAbility.GetInt(): voteNum += Survivor.AdditionalVote.GetInt(); break; + case Pickpocket: + voteNum += (int)(Main.EnumeratePlayerControls().Count(x => x.GetRealKiller()?.PlayerId == ps.TargetPlayerId) * Pickpocket.VotesPerKill.GetFloat()); + break; + case Vindicator: + voteNum += Options.VindicatorAdditionalVote.GetInt(); + break; + case Magistrate when Magistrate.CallCourtNextMeeting: + voteNum += Magistrate.ExtraVotes.GetInt(); + break; } if (ps.TargetPlayerId == ps.VotedFor && Options.MadmateSpawnMode.GetInt() == 2 && CustomRoles.Madmate.IsEnable() && MeetingStates.FirstMeeting) voteNum = 0; diff --git a/Patches/OnGameStartedPatch.cs b/Patches/OnGameStartedPatch.cs index b5bd43415..3f0b95887 100644 --- a/Patches/OnGameStartedPatch.cs +++ b/Patches/OnGameStartedPatch.cs @@ -36,13 +36,11 @@ internal static class ChangeRoleSettings IEnumerator CoStartGame() { - AmongUsClient amongUsClient = __instance; - if (HudManager.Instance.GameMenu.IsOpen) HudManager.Instance.GameMenu.Close(); UnityTelemetry.Instance.Init(); - amongUsClient.logger.Info("Received game start: " + amongUsClient.AmHost); + __instance.logger.Info("Received game start: " + __instance.AmHost); yield return null; while (!HudManager.InstanceExists) @@ -65,7 +63,7 @@ internal static class ChangeRoleSettings if (GameStartManager.InstanceExists) { - amongUsClient.DisconnectHandlers.Remove(GameStartManager.Instance.CastFast()); + __instance.DisconnectHandlers.Remove(GameStartManager.Instance.CastFast()); Object.Destroy(GameStartManager.Instance.gameObject); } @@ -95,14 +93,14 @@ internal static class ChangeRoleSettings DataManager.Player.Ban.PreviousGameStartDate = DateTime.UtcNow; DataManager.Player.Save(); - if (amongUsClient.AmHost) - yield return amongUsClient.CoStartGameHost(); + if (__instance.AmHost) + yield return __instance.CoStartGameHost(); else { - yield return amongUsClient.CoStartGameClient(); + yield return __instance.CoStartGameClient(); - if (amongUsClient.AmHost) - yield return amongUsClient.CoStartGameHost(); + if (__instance.AmHost) + yield return __instance.CoStartGameHost(); } for (var index = 0; index < GameData.Instance.PlayerCount; ++index) diff --git a/Patches/OutroPatch.cs b/Patches/OutroPatch.cs index d63b101c1..89799f484 100644 --- a/Patches/OutroPatch.cs +++ b/Patches/OutroPatch.cs @@ -715,11 +715,7 @@ internal static class SetEverythingUpPatch Main.ShowResult = setToActive; ResultsToggleButton.Label.text = GetString(setToActive ? "HideResults" : "ShowResults"); }, - GetString(showInitially ? "HideResults" : "ShowResults")) - { - Scale = new(1.5f, 0.5f), - FontSize = 2f - }; + GetString(showInitially ? "HideResults" : "ShowResults")); if (Options.CurrentGameMode == CustomGameMode.Standard) { diff --git a/Patches/PhantomRolePatch.cs b/Patches/PhantomRolePatch.cs index 4b37c17d7..18d689992 100644 --- a/Patches/PhantomRolePatch.cs +++ b/Patches/PhantomRolePatch.cs @@ -124,7 +124,6 @@ public static class PhantomRoleUseAbilityPatch HudManager.Instance.AbilityButton.SetSecondImage(__instance.Ability); HudManager.Instance.AbilityButton.OverrideText(TranslationController.Instance.GetString(StringNames.PhantomAbilityUndo, new Il2CppReferenceArray(0))); __instance.Player.CmdCheckVanish(GameManager.Instance.LogicOptions.GetRoleFloat(FloatOptionNames.PhantomDuration)); - return false; } } diff --git a/Patches/RandomSpawnPatch.cs b/Patches/RandomSpawnPatch.cs index 51a2b7677..f9aad0496 100644 --- a/Patches/RandomSpawnPatch.cs +++ b/Patches/RandomSpawnPatch.cs @@ -95,7 +95,7 @@ internal abstract class RandomSpawn { public abstract Dictionary Positions { get; } - public virtual void RandomTeleport(PlayerControl player) + public void RandomTeleport(PlayerControl player) { KeyValuePair spawn = GetLocation(); Logger.Info($"{player.Data.PlayerName} => {Translator.GetString(spawn.Key.ToString())} {spawn.Value}", "RandomSpawn"); diff --git a/Patches/ShipStatusPatch.cs b/Patches/ShipStatusPatch.cs index b2c45aa4f..9b5862f89 100644 --- a/Patches/ShipStatusPatch.cs +++ b/Patches/ShipStatusPatch.cs @@ -1,3 +1,8 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using AmongUs.GameOptions; using BepInEx; using EHR.Gamemodes; @@ -5,10 +10,6 @@ using EHR.Modules; using EHR.Roles; using HarmonyLib; using Hazel; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; using UnityEngine; #if DEBUG using EHR.Patches; @@ -136,7 +137,7 @@ internal static class UpdateSystemPatch } var switchSystem = ShipStatusSystem.SwitchSystem; - if (switchSystem != null && switchSystem is { IsActive: true }) + if (switchSystem is { IsActive: true }) { switch (Main.PlayerStates[player.PlayerId].Role) { @@ -392,20 +393,20 @@ internal static class ShipStatusOnEnablePatch switch (systemType) { case SystemTypes.Reactor: - { - switch (mapId) + { + switch (mapId) { case 2: continue; case 4: ShipStatusSystem.HeliSabotageSystem = ISystemType.TryCast(); - ShipStatusSystem.ICriticalSabotage = ISystemType.TryCast(); break; default: ShipStatusSystem.ReactorSystemType = ISystemType.TryCast(); - ShipStatusSystem.ICriticalSabotage = ISystemType.TryCast(); break; } - } + + ShipStatusSystem.ICriticalSabotage = ISystemType.TryCast(); + } break; case SystemTypes.Laboratory: { @@ -587,21 +588,21 @@ internal static class ShipStatusSerializePatch } var hudOverrideSystem = ShipStatusSystem.HudOverrideSystemType; - if (Options.CurrentGameMode == CustomGameMode.Standard && hudOverrideSystem != null && hudOverrideSystem is { IsDirty: true }) + if (Options.CurrentGameMode == CustomGameMode.Standard && hudOverrideSystem is { IsDirty: true }) { SerializeHudOverrideSystemV2(hudOverrideSystem); hudOverrideSystem.IsDirty = false; } var hqHudSystem = ShipStatusSystem.HqHudSystemType; - if (Options.CurrentGameMode == CustomGameMode.Standard && hqHudSystem != null && hqHudSystem is { IsDirty: true }) + if (Options.CurrentGameMode == CustomGameMode.Standard && hqHudSystem is { IsDirty: true }) { SerializeHqHudSystemV2(hqHudSystem); hqHudSystem.IsDirty = false; } var ventilationSystem = ShipStatusSystem.VentilationSystem; - if (cancel && ventilationSystem != null && ventilationSystem is { IsDirty: true }) + if (cancel && ventilationSystem is { IsDirty: true }) { Utils.SetAllVentInteractions(); ventilationSystem.IsDirty = false; @@ -768,7 +769,7 @@ internal static class ShipStatusFixedUpdatePatch private static Stopwatch Stopwatch; - public static System.Collections.IEnumerator Postfix() + public static IEnumerator Postfix() { Stopwatch = Stopwatch.StartNew(); diff --git a/Patches/TaskAdderPatch.cs b/Patches/TaskAdderPatch.cs index 2ff14702a..9bb1d6d44 100644 --- a/Patches/TaskAdderPatch.cs +++ b/Patches/TaskAdderPatch.cs @@ -42,6 +42,7 @@ internal static class ShowFolderPatch button.Text.text = Utils.GetRoleName(cRoleID); __instance.AddFileAsChild(CustomRolesFolder, button, ref xCursor, ref yCursor, ref maxHeight); + // ReSharper disable once Unity.IncorrectMonoBehaviourInstantiation var roleBehaviour = new RoleBehaviour { Role = (RoleTypes)cRoleID + 1000 diff --git a/Patches/TaskAssignPatch.cs b/Patches/TaskAssignPatch.cs index 559102d0a..d9a32624a 100644 --- a/Patches/TaskAssignPatch.cs +++ b/Patches/TaskAssignPatch.cs @@ -1,6 +1,6 @@ +using System; using System.Collections.Generic; using System.Linq; -using System; using AmongUs.GameOptions; using EHR.Modules; using EHR.Roles; diff --git a/Patches/TextBoxPatch.cs b/Patches/TextBoxPatch.cs index ebba0e857..a43e758f3 100644 --- a/Patches/TextBoxPatch.cs +++ b/Patches/TextBoxPatch.cs @@ -85,7 +85,7 @@ public static class TextBoxPatch __instance.outputText.text = str + compoText; __instance.outputText.ForceMeshUpdate(true, true); - if (__instance.keyboard != null) __instance.keyboard.text = __instance.text; + __instance.keyboard?.text = __instance.text; __instance.OnChange.Invoke(); if (__instance.tempTxt.Length == __instance.characterLimit && __instance.SendOnFullChars) diff --git a/Roles/HideAndSeek/Agent.cs b/Roles/HideAndSeek/Agent.cs index a061278e3..a24736fbb 100644 --- a/Roles/HideAndSeek/Agent.cs +++ b/Roles/HideAndSeek/Agent.cs @@ -16,7 +16,7 @@ public class Agent : RoleBase, IHideAndSeekRole public override void SetupCustomOption() { - new TextOptionItem(69_211_2000, $"TypeImpostor", TabGroup.ImpostorRoles) + new TextOptionItem(69_211_2000, "TypeImpostor", TabGroup.ImpostorRoles) .SetHeader(true) .SetGameMode(CustomGameMode.HideAndSeek); diff --git a/Roles/HideAndSeek/Detector.cs b/Roles/HideAndSeek/Detector.cs index ee4db7d07..45ff25dc8 100644 --- a/Roles/HideAndSeek/Detector.cs +++ b/Roles/HideAndSeek/Detector.cs @@ -21,7 +21,7 @@ public class Detector : RoleBase, IHideAndSeekRole public override void SetupCustomOption() { - new TextOptionItem(69_211_600, $"TypeCrewmate", TabGroup.CrewmateRoles) + new TextOptionItem(69_211_600, "TypeCrewmate", TabGroup.CrewmateRoles) .SetHeader(true) .SetGameMode(CustomGameMode.HideAndSeek); diff --git a/Roles/HideAndSeek/Fox.cs b/Roles/HideAndSeek/Fox.cs index 54c9a2d7f..46951d2f5 100644 --- a/Roles/HideAndSeek/Fox.cs +++ b/Roles/HideAndSeek/Fox.cs @@ -16,9 +16,9 @@ internal class Fox : RoleBase, IHideAndSeekRole public override void SetupCustomOption() { - new TextOptionItem(69_211_300, $"TypeNeutral", TabGroup.NeutralRoles) + new TextOptionItem(69_211_300, "TypeNeutral", TabGroup.NeutralRoles) .SetHeader(true) - .SetGameMode(CustomGameMode.HideAndSeek); ; + .SetGameMode(CustomGameMode.HideAndSeek); Options.SetupRoleOptions(69_211_301, TabGroup.NeutralRoles, CustomRoles.Fox, CustomGameMode.HideAndSeek); diff --git a/Roles/HideAndSeek/IHideAndSeekRole.cs b/Roles/HideAndSeek/IHideAndSeekRole.cs index 0aeb7db36..0923221a0 100644 --- a/Roles/HideAndSeek/IHideAndSeekRole.cs +++ b/Roles/HideAndSeek/IHideAndSeekRole.cs @@ -1,6 +1,4 @@ -using EHR.Modules.Extensions; - -namespace EHR.Roles; +namespace EHR.Roles; internal interface IHideAndSeekRole { diff --git a/Roles/Standard/Addons/Common/Allergic.cs b/Roles/Standard/Addons/Common/Allergic.cs index 4f78f6e4c..d94e29e9f 100644 --- a/Roles/Standard/Addons/Common/Allergic.cs +++ b/Roles/Standard/Addons/Common/Allergic.cs @@ -34,10 +34,12 @@ public class Allergic : IAddon LateTask.New(() => { - var aapc = Main.EnumerateAlivePlayerControls(); + var aapc = Main.AllAlivePlayerControlsToList; - foreach (PlayerControl pc in aapc) + for (var index = 0; index < aapc.Count; index++) { + PlayerControl pc = aapc[index]; + if (pc.Is(CustomRoles.Allergic)) { PlayerControl target = aapc.Without(pc).RandomElement(); diff --git a/Roles/Standard/Addons/Common/Asthmatic.cs b/Roles/Standard/Addons/Common/Asthmatic.cs index 7744dd01a..0eca55029 100644 --- a/Roles/Standard/Addons/Common/Asthmatic.cs +++ b/Roles/Standard/Addons/Common/Asthmatic.cs @@ -1,8 +1,7 @@ -using EHR.Gamemodes; +using System.Collections.Generic; +using EHR.Gamemodes; using EHR.Modules; using Hazel; -using Rewired.Utils.Classes.Data; -using System.Collections.Generic; using UnityEngine; using static EHR.Options; diff --git a/Roles/Standard/Addons/Common/Blessed.cs b/Roles/Standard/Addons/Common/Blessed.cs index 69790e75f..fdfba5600 100644 --- a/Roles/Standard/Addons/Common/Blessed.cs +++ b/Roles/Standard/Addons/Common/Blessed.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using EHR.Modules; using EHR.Modules.Extensions; using Hazel; diff --git a/Roles/Standard/Addons/Common/Guesser.cs b/Roles/Standard/Addons/Common/Guesser.cs index 7b9467e7a..5237b9735 100644 --- a/Roles/Standard/Addons/Common/Guesser.cs +++ b/Roles/Standard/Addons/Common/Guesser.cs @@ -1,5 +1,4 @@ -using UnityEngine; -using static EHR.Options; +using static EHR.Options; namespace EHR.Roles; diff --git a/Roles/Standard/Addons/Common/Sleep.cs b/Roles/Standard/Addons/Common/Sleep.cs index 611dd7bb3..2eccb9b77 100644 --- a/Roles/Standard/Addons/Common/Sleep.cs +++ b/Roles/Standard/Addons/Common/Sleep.cs @@ -1,5 +1,4 @@ -using System.Linq; -using EHR.Modules; +using EHR.Modules; namespace EHR.Roles; diff --git a/Roles/Standard/Coven/Banshee.cs b/Roles/Standard/Coven/Banshee.cs index a47d0c6bd..16ff7a4cc 100644 --- a/Roles/Standard/Coven/Banshee.cs +++ b/Roles/Standard/Coven/Banshee.cs @@ -74,7 +74,7 @@ public class Banshee : CovenBase w.Write(BansheeId); w.WritePacked(1); w.WritePacked(ScreechedPlayers.Count); - ScreechedPlayers.Do(x => w.Write(x)); + ScreechedPlayers.Do(w.Write); Utils.EndRPC(w); } diff --git a/Roles/Standard/Coven/CovenBase.cs b/Roles/Standard/Coven/CovenBase.cs index 1b632efa4..4ad668df1 100644 --- a/Roles/Standard/Coven/CovenBase.cs +++ b/Roles/Standard/Coven/CovenBase.cs @@ -6,7 +6,7 @@ namespace EHR.Roles; public abstract class CovenBase : RoleBase { - public enum NecronomiconReceivePriorities + protected enum NecronomiconReceivePriorities { First, Random, diff --git a/Roles/Standard/Coven/PotionMaster.cs b/Roles/Standard/Coven/PotionMaster.cs index 9897db315..9aad707f1 100644 --- a/Roles/Standard/Coven/PotionMaster.cs +++ b/Roles/Standard/Coven/PotionMaster.cs @@ -141,10 +141,7 @@ public class PotionMaster : CovenBase public override string GetSuffix(PlayerControl seer, PlayerControl target, bool hud = false, bool meeting = false) { - if (seer.PlayerId == target.PlayerId && seer.IsModdedClient() && !hud) return string.Empty; - if (seer.PlayerId != target.PlayerId && seer.PlayerId != PotionMasterId) return string.Empty; - if (!ShieldedPlayers.TryGetValue(target.PlayerId, out CountdownTimer timer)) return string.Empty; - + if (seer.PlayerId == target.PlayerId && seer.IsModdedClient() && !hud || seer.PlayerId != target.PlayerId && seer.PlayerId != PotionMasterId || !ShieldedPlayers.TryGetValue(target.PlayerId, out CountdownTimer timer)) return string.Empty; return string.Format(Translator.GetString("PotionMaster.Suffix"), (int)Math.Ceiling(timer.Remaining.TotalSeconds), Main.CovenColor); } } diff --git a/Roles/Standard/Coven/Shadow.cs b/Roles/Standard/Coven/Shadow.cs index 355352f57..bf5d5b565 100644 --- a/Roles/Standard/Coven/Shadow.cs +++ b/Roles/Standard/Coven/Shadow.cs @@ -1,5 +1,4 @@ using AmongUs.GameOptions; -using System.Collections.Generic; using EHR.Modules.Extensions; namespace EHR.Roles; diff --git a/Roles/Standard/Coven/Wyrd.cs b/Roles/Standard/Coven/Wyrd.cs index d171b07e4..3e1c1e78d 100644 --- a/Roles/Standard/Coven/Wyrd.cs +++ b/Roles/Standard/Coven/Wyrd.cs @@ -184,7 +184,7 @@ public class Wyrd : CovenBase { base.GetProgressText(playerId, comms, resultText); - resultText.Append($" <#ffffff>") + resultText.Append(" <#ffffff>") .Append(MarkedPlayers.Count).Append('/').Append(MaxMarkedPlayersAtOnce.GetInt()) .Append(""); } diff --git a/Roles/Standard/Crewmate/Chaos/Dad.cs b/Roles/Standard/Crewmate/Chaos/Dad.cs index 2599585b4..a43aa26af 100644 --- a/Roles/Standard/Crewmate/Chaos/Dad.cs +++ b/Roles/Standard/Crewmate/Chaos/Dad.cs @@ -1,11 +1,10 @@ -using AmongUs.GameOptions; +using System; +using System.Collections.Generic; +using System.Linq; +using AmongUs.GameOptions; using EHR.Gamemodes; using EHR.Modules; using Hazel; -using System; -using System.Collections.Generic; -using System.Linq; -using static EHR.Roles.Adventurer; namespace EHR.Roles; diff --git a/Roles/Standard/Crewmate/Chaos/Randomizer.cs b/Roles/Standard/Crewmate/Chaos/Randomizer.cs index 560699e1b..4fa6c40e9 100644 --- a/Roles/Standard/Crewmate/Chaos/Randomizer.cs +++ b/Roles/Standard/Crewmate/Chaos/Randomizer.cs @@ -753,11 +753,9 @@ internal class Randomizer : RoleBase var enumerator = effects.GetEnumerator(); while (enumerator.MoveNext()) { - var pair = enumerator.Current; - var effect = pair.Key; - var (StartTimeStamp, Duration) = pair.Value; + (Effect effect, (long startTimeStamp, int duration)) = enumerator.Current; - if (StartTimeStamp + Duration < now) + if (startTimeStamp + duration < now) { ToRemoveEffects.Add(effect); if (effect.IsVisionChangingEffect()) RevertVisionChangesForPlayer(pc, true); diff --git a/Roles/Standard/Crewmate/Chaos/ToiletMaster.cs b/Roles/Standard/Crewmate/Chaos/ToiletMaster.cs index 5aa9f53e2..9a1fd388e 100644 --- a/Roles/Standard/Crewmate/Chaos/ToiletMaster.cs +++ b/Roles/Standard/Crewmate/Chaos/ToiletMaster.cs @@ -37,7 +37,7 @@ public class ToiletMaster : RoleBase private List ActivePoopDataList = []; private Dictionary PlayersUsingToilet = []; - private KeyValuePair FoundedFirst = default; + private KeyValuePair FoundFirst; private Dictionary Toilets = []; private readonly List ToRemove = []; @@ -197,22 +197,22 @@ public class ToiletMaster : RoleBase try { Vector2 pos = pc.Pos(); - FoundedFirst = default; + FoundFirst = default; float toiletRadius = ToiletUseRadius.GetFloat(); bool hasToilet = false; foreach (var kvp in Toilets) { if (FastVector2.DistanceWithinRange(kvp.Key, pos, toiletRadius)) { - FoundedFirst = kvp; + FoundFirst = kvp; hasToilet = true; break; } } if (!hasToilet) return; - var (NetObject, Uses, PlaceTimeStamp) = FoundedFirst.Value; - if (Uses >= AbilityUses.GetInt()) return; + (Toilet NetObject, int Uses, long PlaceTimeStamp) toilet = FoundFirst.Value; + if (toilet.Uses >= AbilityUses.GetInt()) return; if (!PlayersUsingToilet.TryGetValue(playerId, out long ts)) { @@ -222,7 +222,8 @@ public class ToiletMaster : RoleBase if (ts + ToiletUseTime.GetInt() > now) return; - Uses++; + toilet.Uses++; + Toilets[FoundFirst.Key] = toilet; Poop poop = AllPoopValues.RandomElement(); if (poop != Poop.Green) pc.Notify(Utils.ColorString(GetPoopColor(poop), string.Format(Translator.GetString("TM.GetPoopNotify"), poop))); @@ -320,10 +321,10 @@ public class ToiletMaster : RoleBase ToRemove.Clear(); foreach (var pair in Toilets) { - var (NetObject, Uses, PlaceTimeStamp) = pair.Value; - if (PlaceTimeStamp + duration <= now || Uses >= maxUses) + (Toilet netObject, int uses, long placeTimeStamp) = pair.Value; + if (placeTimeStamp + duration <= now || uses >= maxUses) { - NetObject.Despawn(); + netObject.Despawn(); ToRemove.Add(pair.Key); } } diff --git a/Roles/Standard/Crewmate/Chaos/Tornado.cs b/Roles/Standard/Crewmate/Chaos/Tornado.cs index e408c75e2..dbbd1bc32 100644 --- a/Roles/Standard/Crewmate/Chaos/Tornado.cs +++ b/Roles/Standard/Crewmate/Chaos/Tornado.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using EHR.Modules; using Hazel; diff --git a/Roles/Standard/Crewmate/Investigate/Captain.cs b/Roles/Standard/Crewmate/Investigate/Captain.cs index 310d548cb..a3b7c99b7 100644 --- a/Roles/Standard/Crewmate/Investigate/Captain.cs +++ b/Roles/Standard/Crewmate/Investigate/Captain.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using EHR.Modules; using Hazel; diff --git a/Roles/Standard/Crewmate/Investigate/Enigma.cs b/Roles/Standard/Crewmate/Investigate/Enigma.cs index 9f1ec976a..d924231db 100644 --- a/Roles/Standard/Crewmate/Investigate/Enigma.cs +++ b/Roles/Standard/Crewmate/Investigate/Enigma.cs @@ -173,8 +173,7 @@ public class Enigma : RoleBase return ClueStage switch { - 1 => GetString("EnigmaClueHat1"), - 2 => GetString("EnigmaClueHat1"), + 1 or 2 => GetString("EnigmaClueHat1"), 3 => showStageClue ? string.Format(GetString("EnigmaClueHat3"), killerOutfit.HatId) : GetString("EnigmaClueHat1"), _ => null }; @@ -192,8 +191,7 @@ public class Enigma : RoleBase return ClueStage switch { - 1 => GetString("EnigmaClueVisor1"), - 2 => GetString("EnigmaClueVisor1"), + 1 or 2 => GetString("EnigmaClueVisor1"), 3 => showStageClue ? string.Format(GetString("EnigmaClueVisor3"), killerOutfit.VisorId) : GetString("EnigmaClueVisor1"), _ => null }; @@ -211,8 +209,7 @@ public class Enigma : RoleBase return ClueStage switch { - 1 => GetString("EnigmaClueSkin1"), - 2 => GetString("EnigmaClueSkin1"), + 1 or 2 => GetString("EnigmaClueSkin1"), 3 => showStageClue ? string.Format(GetString("EnigmaClueSkin3"), killerOutfit.SkinId) : GetString("EnigmaClueSkin1"), _ => null }; @@ -230,8 +227,7 @@ public class Enigma : RoleBase return ClueStage switch { - 1 => GetString("EnigmaCluePet1"), - 2 => GetString("EnigmaCluePet1"), + 1 or 2 => GetString("EnigmaCluePet1"), 3 => showStageClue ? string.Format(GetString("EnigmaCluePet3"), killerOutfit.PetId) : GetString("EnigmaCluePet1"), _ => null }; @@ -351,8 +347,7 @@ public class Enigma : RoleBase return ClueStage switch { - 1 => GetStage1Clue(killerOutfit.ColorId), - 2 => GetStage1Clue(killerOutfit.ColorId), + 1 or 2 => GetStage1Clue(killerOutfit.ColorId), 3 => showStageClue ? string.Format(GetString("EnigmaClueColor3"), killer.Data.ColorName) : GetStage1Clue(killerOutfit.ColorId), _ => GetStage1Clue(killerOutfit.ColorId) }; diff --git a/Roles/Standard/Crewmate/Investigate/FortuneTeller.cs b/Roles/Standard/Crewmate/Investigate/FortuneTeller.cs index 3993f60ed..53f457b14 100644 --- a/Roles/Standard/Crewmate/Investigate/FortuneTeller.cs +++ b/Roles/Standard/Crewmate/Investigate/FortuneTeller.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; using EHR.Modules; -using Hazel; using static EHR.Options; using static EHR.Translator; diff --git a/Roles/Standard/Crewmate/Investigate/Imitator.cs b/Roles/Standard/Crewmate/Investigate/Imitator.cs index 268ae1674..5d8956a31 100644 --- a/Roles/Standard/Crewmate/Investigate/Imitator.cs +++ b/Roles/Standard/Crewmate/Investigate/Imitator.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using EHR.Modules; using UnityEngine; diff --git a/Roles/Standard/Crewmate/Investigate/Oracle.cs b/Roles/Standard/Crewmate/Investigate/Oracle.cs index fa4087772..45ffb219b 100644 --- a/Roles/Standard/Crewmate/Investigate/Oracle.cs +++ b/Roles/Standard/Crewmate/Investigate/Oracle.cs @@ -1,6 +1,4 @@ -using System; using System.Collections.Generic; -using Hazel; using static EHR.Options; using static EHR.Translator; diff --git a/Roles/Standard/Crewmate/Investigate/Sentry.cs b/Roles/Standard/Crewmate/Investigate/Sentry.cs index a94603266..79701ad08 100644 --- a/Roles/Standard/Crewmate/Investigate/Sentry.cs +++ b/Roles/Standard/Crewmate/Investigate/Sentry.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using EHR.Modules; -using HarmonyLib; namespace EHR.Roles; diff --git a/Roles/Standard/Crewmate/Investigate/Spy.cs b/Roles/Standard/Crewmate/Investigate/Spy.cs index f215994ee..30a5c223f 100644 --- a/Roles/Standard/Crewmate/Investigate/Spy.cs +++ b/Roles/Standard/Crewmate/Investigate/Spy.cs @@ -19,8 +19,6 @@ public class Spy : RoleBase public static OptionItem SpyAbilityUseGainWithEachTaskCompleted; public static OptionItem AbilityChargesWhenFinishedTasks; - private long LastUpdate; - public override bool IsEnable => PlayerIdList.Count > 0; public override void SetupCustomOption() @@ -52,7 +50,6 @@ public class Spy : RoleBase public override void Add(byte playerId) { - LastUpdate = TimeStamp; PlayerIdList.Add(playerId); playerId.SetAbilityUseLimit(UseLimitOpt.GetFloat()); } @@ -90,7 +87,7 @@ public class Spy : RoleBase public static bool OnKillAttempt(PlayerControl killer, PlayerControl target) // Special handling for Spy ---- remains as a static method { - if (killer == null || target == null || !target.Is(CustomRoles.Spy) || killer.PlayerId == target.PlayerId || target.GetAbilityUseLimit() < 1) return true; + if (!target.Is(CustomRoles.Spy) || killer.PlayerId == target.PlayerId || target.GetAbilityUseLimit() < 1) return true; target.RpcRemoveAbilityUse(); SpyRedNameList.Add(killer.PlayerId); diff --git a/Roles/Standard/Crewmate/Investigate/Unshifter.cs b/Roles/Standard/Crewmate/Investigate/Unshifter.cs index 0879ab6ed..e2742b301 100644 --- a/Roles/Standard/Crewmate/Investigate/Unshifter.cs +++ b/Roles/Standard/Crewmate/Investigate/Unshifter.cs @@ -1,6 +1,4 @@ using AmongUs.GameOptions; -using Hazel; -using InnerNet; using static EHR.Translator; namespace EHR.Roles; diff --git a/Roles/Standard/Crewmate/Investigate/Whisperer.cs b/Roles/Standard/Crewmate/Investigate/Whisperer.cs index bde18001c..033bc9942 100644 --- a/Roles/Standard/Crewmate/Investigate/Whisperer.cs +++ b/Roles/Standard/Crewmate/Investigate/Whisperer.cs @@ -104,7 +104,7 @@ public class Whisperer : RoleBase break; } } - if (!found || soul == null) return; + if (!found) return; byte soulPlayerId = soul.Player.PlayerId; diff --git a/Roles/Standard/Crewmate/Killing/NiceGuesser.cs b/Roles/Standard/Crewmate/Killing/NiceGuesser.cs index 07c5ec816..1e65b3f46 100644 --- a/Roles/Standard/Crewmate/Killing/NiceGuesser.cs +++ b/Roles/Standard/Crewmate/Killing/NiceGuesser.cs @@ -1,5 +1,4 @@ -using UnityEngine; -using static EHR.Options; +using static EHR.Options; namespace EHR.Roles; diff --git a/Roles/Standard/Crewmate/Killing/Retributionist.cs b/Roles/Standard/Crewmate/Killing/Retributionist.cs index f16a143b6..64029db24 100644 --- a/Roles/Standard/Crewmate/Killing/Retributionist.cs +++ b/Roles/Standard/Crewmate/Killing/Retributionist.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using Hazel; diff --git a/Roles/Standard/Crewmate/Killing/Sheriff.cs b/Roles/Standard/Crewmate/Killing/Sheriff.cs index c39d0eea8..18b1c5915 100644 --- a/Roles/Standard/Crewmate/Killing/Sheriff.cs +++ b/Roles/Standard/Crewmate/Killing/Sheriff.cs @@ -125,7 +125,7 @@ public class Sheriff : RoleBase public override bool OnCheckMurder(PlayerControl killer, PlayerControl target) { - if (CanBeKilledBySheriff(target) || (SetNonCrewCanKill.GetBool() && (killer.IsMadmate() || killer.IsConverted()) && ((target.IsImpostor() && NonCrewCanKillImp.GetBool()) || (target.IsCrewmate() && NonCrewCanKillCrew.GetBool()) || (target.GetCustomRole().IsNeutral() && NonCrewCanKillNeutral.GetBool())))) + if (CanBeKilledBySheriff(target) || SidekickSheriffCanGoBerserk.GetBool() || (SetNonCrewCanKill.GetBool() && (killer.IsMadmate() || killer.IsConverted()) && ((target.IsImpostor() && NonCrewCanKillImp.GetBool()) || (target.IsCrewmate() && NonCrewCanKillCrew.GetBool()) || (target.GetCustomRole().IsNeutral() && NonCrewCanKillNeutral.GetBool())))) { SetKillCooldown(killer.PlayerId); return true; @@ -169,6 +169,7 @@ public class Sheriff : RoleBase { CustomRoles.Trickster => false, CustomRoles.Pestilence => true, + CustomRoles.Sidekick => CanKillSidekicks.GetBool(), _ => player.GetCustomRoleTypes() switch { CustomRoleTypes.Impostor => true, diff --git a/Roles/Standard/Crewmate/Miscellaneous/CameraMan.cs b/Roles/Standard/Crewmate/Miscellaneous/CameraMan.cs index e2bb4ced4..844c53f1e 100644 --- a/Roles/Standard/Crewmate/Miscellaneous/CameraMan.cs +++ b/Roles/Standard/Crewmate/Miscellaneous/CameraMan.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using AmongUs.GameOptions; using EHR.Modules; @@ -118,7 +119,7 @@ public class CameraMan : RoleBase { Main.Instance.StartCoroutine(Coroutine()); - System.Collections.IEnumerator Coroutine() + IEnumerator Coroutine() { yield return new WaitForSecondsRealtime(2f); diff --git a/Roles/Standard/Crewmate/Miscellaneous/PortalMaker.cs b/Roles/Standard/Crewmate/Miscellaneous/PortalMaker.cs index 13b80a3d5..02903ee73 100644 --- a/Roles/Standard/Crewmate/Miscellaneous/PortalMaker.cs +++ b/Roles/Standard/Crewmate/Miscellaneous/PortalMaker.cs @@ -1,7 +1,7 @@ -using EHR.Modules; -using Hazel; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; +using EHR.Modules; +using Hazel; using UnityEngine; namespace EHR.Roles; diff --git a/Roles/Standard/Crewmate/Power/Adventurer.cs b/Roles/Standard/Crewmate/Power/Adventurer.cs index f94ae222c..ef1b36aeb 100644 --- a/Roles/Standard/Crewmate/Power/Adventurer.cs +++ b/Roles/Standard/Crewmate/Power/Adventurer.cs @@ -1,10 +1,10 @@ -using AmongUs.GameOptions; +using System; +using System.Collections.Generic; +using System.Linq; +using AmongUs.GameOptions; using EHR.Modules; using EHR.Patches; using Hazel; -using System; -using System.Collections.Generic; -using System.Linq; using UnityEngine; namespace EHR.Roles; diff --git a/Roles/Standard/Crewmate/Power/NiceEraser.cs b/Roles/Standard/Crewmate/Power/NiceEraser.cs index 43c7fd8ce..b891b2ca9 100644 --- a/Roles/Standard/Crewmate/Power/NiceEraser.cs +++ b/Roles/Standard/Crewmate/Power/NiceEraser.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Hazel; using static EHR.Translator; namespace EHR.Roles; diff --git a/Roles/Standard/Crewmate/Power/Oxyman.cs b/Roles/Standard/Crewmate/Power/Oxyman.cs index 081533328..bdd5bfb20 100644 --- a/Roles/Standard/Crewmate/Power/Oxyman.cs +++ b/Roles/Standard/Crewmate/Power/Oxyman.cs @@ -111,7 +111,7 @@ public class Oxyman : RoleBase if (nowLevel != previousLevel) ApplyLevelEffect(pc, nowLevel); } - private void ApplyLevelEffect(PlayerControl pc, Level nowLevel) + private static void ApplyLevelEffect(PlayerControl pc, Level nowLevel) { switch (nowLevel) { diff --git a/Roles/Standard/Crewmate/Power/Survivor.cs b/Roles/Standard/Crewmate/Power/Survivor.cs index 7a96682c9..ea820fbf2 100644 --- a/Roles/Standard/Crewmate/Power/Survivor.cs +++ b/Roles/Standard/Crewmate/Power/Survivor.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using EHR.Modules.Extensions; @@ -127,9 +126,9 @@ public class Survivor : RoleBase ShieldTimer = new CountdownTimer(ShieldDuration.GetFloat(), () => { ShieldTimer = null; - Utils.NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc); + NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc); }, onCanceled: () => ShieldTimer = null); - if (!shielded) Utils.NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc); + if (!shielded) NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc); } } @@ -141,7 +140,7 @@ public class Survivor : RoleBase public override string GetSuffix(PlayerControl seer, PlayerControl target, bool hud = false, bool meeting = false) { if (seer.PlayerId != target.PlayerId || seer.PlayerId != SurvivorId || meeting || (seer.IsModdedClient() && !hud) || ShieldTimer == null) return string.Empty; - return seer.IsHost() ? string.Format(Translator.GetString("SafeguardSuffixTimer"), (int)Math.Ceiling(ShieldTimer.Remaining.TotalSeconds)) : Translator.GetString("SafeguardSuffix"); + return seer.IsHost() ? string.Format(GetString("SafeguardSuffixTimer"), (int)Math.Ceiling(ShieldTimer.Remaining.TotalSeconds)) : GetString("SafeguardSuffix"); } public override bool CanUseVent(PlayerControl pc, int ventId) @@ -175,8 +174,8 @@ public class Survivor : RoleBase Killing = true; pc.RpcChangeRoleBasis(CustomRoles.Scanner); LateTask.New(() => pc.SetKillCooldown(KillCooldown.GetFloat()), 0.2f); - Utils.SendRPC(CustomRPC.SyncRoleData, pc.PlayerId, Killing); - Utils.NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc); + SendRPC(CustomRPC.SyncRoleData, pc.PlayerId, Killing); + NotifyRoles(SpecifySeer: pc, SpecifyTarget: pc); pc.MarkDirtySettings(); } } @@ -191,7 +190,7 @@ public class Survivor : RoleBase public override bool OnCheckMurder(PlayerControl killer, PlayerControl target) { if (Main.AllAlivePlayerControlsCount <= LastAbility.GetInt()) return true; - killer.Notify(Translator.GetString("SurvivorCantKillYet")); + killer.Notify(GetString("SurvivorCantKillYet")); return false; } } diff --git a/Roles/Standard/Crewmate/Support/Beacon.cs b/Roles/Standard/Crewmate/Support/Beacon.cs index 76a0797f8..6a4e6d5f4 100644 --- a/Roles/Standard/Crewmate/Support/Beacon.cs +++ b/Roles/Standard/Crewmate/Support/Beacon.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using EHR.Modules; namespace EHR.Roles; diff --git a/Roles/Standard/Crewmate/Support/Cleanser.cs b/Roles/Standard/Crewmate/Support/Cleanser.cs index 6d119625c..0fb17f052 100644 --- a/Roles/Standard/Crewmate/Support/Cleanser.cs +++ b/Roles/Standard/Crewmate/Support/Cleanser.cs @@ -10,7 +10,6 @@ public class Cleanser : RoleBase { private const int Id = 23420; public static List PlayerIdList = []; - public static List CleansedPlayers = []; public static Dictionary DidVote = []; public static OptionItem CleanserUsesOpt; @@ -51,7 +50,6 @@ public class Cleanser : RoleBase { PlayerIdList = []; CleanserTarget = byte.MaxValue; - CleansedPlayers = []; DidVote = []; CleanserId = byte.MaxValue; } @@ -111,7 +109,6 @@ public class Cleanser : RoleBase voter.RpcRemoveAbilityUse(); CleanserTarget = target.PlayerId; Logger.Info($"{voter.GetNameWithRole().RemoveHtmlTags()} cleansed {target.GetNameWithRole().RemoveHtmlTags()}", "Cleansed"); - CleansedPlayers.Add(target.PlayerId); Utils.SendMessage(string.Format(GetString("CleanserRemovedRole"), target.GetRealName()), voter.PlayerId, CustomRoles.Cleanser.ColoredTextByRole(GetString("CleanserTitle")), importance: MessageImportance.Low); SendRPC(voter.PlayerId); diff --git a/Roles/Standard/Crewmate/Support/Gaulois.cs b/Roles/Standard/Crewmate/Support/Gaulois.cs index 70a4713e0..f1033cbea 100644 --- a/Roles/Standard/Crewmate/Support/Gaulois.cs +++ b/Roles/Standard/Crewmate/Support/Gaulois.cs @@ -14,8 +14,6 @@ public class Gaulois : RoleBase private static OptionItem UseLimitOpt; public static OptionItem UsePet; - public static List IncreasedSpeedPlayerList = []; - public override bool IsEnable => PlayerIdList.Count > 0; public override void SetupCustomOption() @@ -40,7 +38,6 @@ public class Gaulois : RoleBase public override void Init() { PlayerIdList = []; - IncreasedSpeedPlayerList = []; } public override void Add(byte playerId) @@ -73,10 +70,9 @@ public class Gaulois : RoleBase public override bool OnCheckMurder(PlayerControl killer, PlayerControl target) { - if (!IsEnable || killer == null || target == null || killer.GetAbilityUseLimit() <= 0) return false; + if (!IsEnable || killer.GetAbilityUseLimit() <= 0) return false; Main.AllPlayerSpeed[target.PlayerId] += AdditionalSpeed.GetFloat(); - IncreasedSpeedPlayerList.Add(target.PlayerId); killer.RpcRemoveAbilityUse(); killer.SetKillCooldown(); diff --git a/Roles/Standard/Crewmate/Support/Medic.cs b/Roles/Standard/Crewmate/Support/Medic.cs index c100339e5..e1b78c50b 100644 --- a/Roles/Standard/Crewmate/Support/Medic.cs +++ b/Roles/Standard/Crewmate/Support/Medic.cs @@ -116,7 +116,7 @@ public class Medic : RoleBase MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetMedicalerProtectList, SendOption.Reliable); writer.Write(1); writer.Write(ProtectList.Count); - ProtectList.ForEach(x => writer.Write(x)); + ProtectList.ForEach(writer.Write); AmongUsClient.Instance.FinishRpcImmediately(writer); } diff --git a/Roles/Standard/Crewmate/Support/Scanner.cs b/Roles/Standard/Crewmate/Support/Scanner.cs index 54c38ef10..3b7eb538c 100644 --- a/Roles/Standard/Crewmate/Support/Scanner.cs +++ b/Roles/Standard/Crewmate/Support/Scanner.cs @@ -1,6 +1,6 @@ -using AmongUs.GameOptions; -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics; +using AmongUs.GameOptions; using EHR.Modules.Extensions; using UnityEngine; using static EHR.Translator; diff --git a/Roles/Standard/Ghost/Bloodmoon.cs b/Roles/Standard/Ghost/Bloodmoon.cs index ac287e84e..c3418913c 100644 --- a/Roles/Standard/Ghost/Bloodmoon.cs +++ b/Roles/Standard/Ghost/Bloodmoon.cs @@ -1,8 +1,7 @@ -using AmongUs.GameOptions; -using Hazel; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using static UnityEngine.GraphicsBuffer; +using AmongUs.GameOptions; +using Hazel; namespace EHR.Roles; diff --git a/Roles/Standard/Impostor/Concealing/Duellist.cs b/Roles/Standard/Impostor/Concealing/Duellist.cs index 93c501850..08bcc0d10 100644 --- a/Roles/Standard/Impostor/Concealing/Duellist.cs +++ b/Roles/Standard/Impostor/Concealing/Duellist.cs @@ -1,3 +1,4 @@ +using System.Collections; using System.Collections.Generic; using AmongUs.GameOptions; using EHR.Modules; @@ -77,7 +78,7 @@ public class Duellist : RoleBase duellist.RPCPlayCustomSound("Teleport"); target.RPCPlayCustomSound("Teleport"); - System.Collections.IEnumerator Coroutine() + IEnumerator Coroutine() { while (GameStates.IsInTask && duellist.IsAlive() && target.IsAlive()) yield return null; if (!GameStates.IsInTask) yield break; diff --git a/Roles/Standard/Impostor/Concealing/Exclusionary.cs b/Roles/Standard/Impostor/Concealing/Exclusionary.cs index 1d4ca7cfa..103ac7262 100644 --- a/Roles/Standard/Impostor/Concealing/Exclusionary.cs +++ b/Roles/Standard/Impostor/Concealing/Exclusionary.cs @@ -116,7 +116,7 @@ public class Exclusionary : RoleBase long ts = 0; for (int excludedindex = 0; excludedindex < ExcludedPlayers.Count; excludedindex++) { - var (ID, TS) = ExcludedPlayers[excludedindex]; + (byte ID, long TS) = ExcludedPlayers[excludedindex]; if (ID == playerId) { diff --git a/Roles/Standard/Impostor/Concealing/Fakeshifter.cs b/Roles/Standard/Impostor/Concealing/Fakeshifter.cs index 5f0d8ddb8..05a05a27c 100644 --- a/Roles/Standard/Impostor/Concealing/Fakeshifter.cs +++ b/Roles/Standard/Impostor/Concealing/Fakeshifter.cs @@ -1,5 +1,4 @@ using AmongUs.GameOptions; -using System.Linq; namespace EHR.Roles; diff --git a/Roles/Standard/Impostor/Concealing/Lightning.cs b/Roles/Standard/Impostor/Concealing/Lightning.cs index fd4aec5f4..e514c8905 100644 --- a/Roles/Standard/Impostor/Concealing/Lightning.cs +++ b/Roles/Standard/Impostor/Concealing/Lightning.cs @@ -1,8 +1,7 @@ -using EHR.Modules; +using System.Collections.Generic; +using EHR.Modules; using EHR.Patches; using Hazel; -using Rewired.Utils.Classes.Data; -using System.Collections.Generic; using UnityEngine; using static EHR.Options; diff --git a/Roles/Standard/Impostor/Concealing/Puppeteer.cs b/Roles/Standard/Impostor/Concealing/Puppeteer.cs index b199758c3..35e2404a3 100644 --- a/Roles/Standard/Impostor/Concealing/Puppeteer.cs +++ b/Roles/Standard/Impostor/Concealing/Puppeteer.cs @@ -1,8 +1,5 @@ using System.Collections.Generic; -using System.Linq; -using AmongUs.GameOptions; using EHR.Modules; -using UnityEngine; using static EHR.Options; namespace EHR.Roles; @@ -13,7 +10,6 @@ internal class Puppeteer : RoleBase public static Dictionary PuppeteerDelayList = []; private static Dictionary PuppeteerDelay = []; private static Dictionary PuppeteerMaxPuppets = []; - private static Dictionary TargetDistance = []; public static bool On; @@ -163,7 +159,7 @@ internal class Puppeteer : RoleBase public override void OnGlobalFixedUpdate(PlayerControl player, bool lowLoad) { - if (player == null || lowLoad) return; + if (lowLoad) return; byte playerId = player.PlayerId; long now = Utils.TimeStamp; diff --git a/Roles/Standard/Impostor/Killing/EvilGuesser.cs b/Roles/Standard/Impostor/Killing/EvilGuesser.cs index 83ca341e8..13d04fbe8 100644 --- a/Roles/Standard/Impostor/Killing/EvilGuesser.cs +++ b/Roles/Standard/Impostor/Killing/EvilGuesser.cs @@ -1,5 +1,4 @@ -using UnityEngine; -using static EHR.Options; +using static EHR.Options; namespace EHR.Roles; diff --git a/Roles/Standard/Impostor/Killing/Psychopath.cs b/Roles/Standard/Impostor/Killing/Psychopath.cs index ef63fab79..b0710c667 100644 --- a/Roles/Standard/Impostor/Killing/Psychopath.cs +++ b/Roles/Standard/Impostor/Killing/Psychopath.cs @@ -1,8 +1,4 @@ -using System.Linq; -using AmongUs.GameOptions; -using UnityEngine; - -namespace EHR.Roles; +namespace EHR.Roles; public class Psychopath : RoleBase { diff --git a/Roles/Standard/Impostor/Killing/Witch.cs b/Roles/Standard/Impostor/Killing/Witch.cs index cd082cf13..4f01b13b0 100644 --- a/Roles/Standard/Impostor/Killing/Witch.cs +++ b/Roles/Standard/Impostor/Killing/Witch.cs @@ -5,7 +5,6 @@ using AmongUs.GameOptions; using EHR.Modules; using EHR.Patches; using Hazel; -using UnityEngine; using static EHR.Options; using static EHR.Translator; diff --git a/Roles/Standard/Impostor/Madmate/Crewpostor.cs b/Roles/Standard/Impostor/Madmate/Crewpostor.cs index 7b9afb1ef..dec1fbe0a 100644 --- a/Roles/Standard/Impostor/Madmate/Crewpostor.cs +++ b/Roles/Standard/Impostor/Madmate/Crewpostor.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using Hazel; diff --git a/Roles/Standard/Impostor/Miscellaneous/AntiAdminer.cs b/Roles/Standard/Impostor/Miscellaneous/AntiAdminer.cs index 55dadb3fb..b04bafc8b 100644 --- a/Roles/Standard/Impostor/Miscellaneous/AntiAdminer.cs +++ b/Roles/Standard/Impostor/Miscellaneous/AntiAdminer.cs @@ -328,12 +328,7 @@ internal class AntiAdminer : RoleBase { foreach (var kv in oldPlayersNearDevices) { - if (!PlayersNearDevices.TryGetValue(kv.Key, out var newSet)) - { - notify = true; - break; - } - if (!kv.Value.SetEquals(newSet)) + if (!PlayersNearDevices.TryGetValue(kv.Key, out var newSet) || !kv.Value.SetEquals(newSet)) { notify = true; break; diff --git a/Roles/Standard/Impostor/Miscellaneous/Generator.cs b/Roles/Standard/Impostor/Miscellaneous/Generator.cs index fddf8a622..6991c0f69 100644 --- a/Roles/Standard/Impostor/Miscellaneous/Generator.cs +++ b/Roles/Standard/Impostor/Miscellaneous/Generator.cs @@ -16,7 +16,7 @@ internal static class GeneratorStatic Action.Vent => 20, Action.Sabotage => 15, - _ => 15 + _ => 0 }; } diff --git a/Roles/Standard/Impostor/Miscellaneous/Obstructer.cs b/Roles/Standard/Impostor/Miscellaneous/Obstructer.cs index 58cb1ae71..25859cc36 100644 --- a/Roles/Standard/Impostor/Miscellaneous/Obstructer.cs +++ b/Roles/Standard/Impostor/Miscellaneous/Obstructer.cs @@ -1,4 +1,5 @@ -using AmongUs.GameOptions; +using System.Collections; +using AmongUs.GameOptions; using UnityEngine; namespace EHR.Roles; @@ -48,7 +49,7 @@ public class Obstructer : RoleBase return true; } - private System.Collections.IEnumerator Coroutine() + private IEnumerator Coroutine() { do { diff --git a/Roles/Standard/Impostor/Support/Catalyst.cs b/Roles/Standard/Impostor/Support/Catalyst.cs index b88626b56..2b2f81385 100644 --- a/Roles/Standard/Impostor/Support/Catalyst.cs +++ b/Roles/Standard/Impostor/Support/Catalyst.cs @@ -1,5 +1,4 @@ -using Rewired.Utils.Platforms.Windows; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; namespace EHR.Roles; diff --git a/Roles/Standard/Impostor/Support/Centralizer.cs b/Roles/Standard/Impostor/Support/Centralizer.cs index ca18224c1..abe918d67 100644 --- a/Roles/Standard/Impostor/Support/Centralizer.cs +++ b/Roles/Standard/Impostor/Support/Centralizer.cs @@ -1,5 +1,4 @@ -using System.Linq; -using AmongUs.GameOptions; +using AmongUs.GameOptions; namespace EHR.Roles; diff --git a/Roles/Standard/Impostor/Support/Chainbinder.cs b/Roles/Standard/Impostor/Support/Chainbinder.cs index b16976927..5927607af 100644 --- a/Roles/Standard/Impostor/Support/Chainbinder.cs +++ b/Roles/Standard/Impostor/Support/Chainbinder.cs @@ -3,6 +3,7 @@ using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using Hazel; +using UnityEngine; namespace EHR.Roles; @@ -112,7 +113,7 @@ public class Chainbinder : RoleBase return; } - RemainingDuration -= UnityEngine.Time.fixedDeltaTime; + RemainingDuration -= Time.fixedDeltaTime; if (RemainingDuration <= 0f) { ClearLink(notifyBinder: true); @@ -130,7 +131,7 @@ public class Chainbinder : RoleBase if (first.onLadder || first.inMovingPlat || first.inVent || second.onLadder || second.inMovingPlat || second.inVent) return; - PullTimer -= UnityEngine.Time.fixedDeltaTime; + PullTimer -= Time.fixedDeltaTime; if (PullTimer > 0f) return; float currentDistance = Vector2.Distance(first.Pos(), second.Pos()); diff --git a/Roles/Standard/Impostor/Support/Devourer.cs b/Roles/Standard/Impostor/Support/Devourer.cs index 9e598e560..4f0c48e04 100644 --- a/Roles/Standard/Impostor/Support/Devourer.cs +++ b/Roles/Standard/Impostor/Support/Devourer.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using Hazel; diff --git a/Roles/Standard/Impostor/Support/Librarian.cs b/Roles/Standard/Impostor/Support/Librarian.cs index b57f703c6..0606cc818 100644 --- a/Roles/Standard/Impostor/Support/Librarian.cs +++ b/Roles/Standard/Impostor/Support/Librarian.cs @@ -221,10 +221,7 @@ public class Librarian : RoleBase private static string GetSelfSuffixAndHudText(byte playerId) { - if (Main.PlayerStates[playerId].Role is not Librarian lr) return string.Empty; - - if (!lr.IsEnable || !GameStates.IsInTask) return string.Empty; - + if (Main.PlayerStates[playerId].Role is not Librarian lr || !lr.IsEnable || !GameStates.IsInTask) return string.Empty; return string.Format(GetString("LibrarianModeText"), lr.IsInSilencingMode.SILENCING ? GetString("LibrarianSilenceMode") : GetString("LibrarianNormalMode")); } } \ No newline at end of file diff --git a/Roles/Standard/Impostor/Support/Perplexer.cs b/Roles/Standard/Impostor/Support/Perplexer.cs index a2a8b6f0e..a8b2cc910 100644 --- a/Roles/Standard/Impostor/Support/Perplexer.cs +++ b/Roles/Standard/Impostor/Support/Perplexer.cs @@ -1,6 +1,4 @@ using AmongUs.GameOptions; -using EHR.Modules; -using System.Linq; namespace EHR.Roles; diff --git a/Roles/Standard/Impostor/Support/Silencer.cs b/Roles/Standard/Impostor/Support/Silencer.cs index c930a8a35..fd4264bae 100644 --- a/Roles/Standard/Impostor/Support/Silencer.cs +++ b/Roles/Standard/Impostor/Support/Silencer.cs @@ -1,9 +1,7 @@ using System.Collections.Generic; -using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using Hazel; -using UnityEngine; using static EHR.Options; namespace EHR.Roles; @@ -147,15 +145,12 @@ public class Silencer : RoleBase public void ReceiveRPC(MessageReader reader) { - switch (reader.ReadPackedInt32()) + ForSilencer = reader.ReadPackedInt32() switch { - case 1: - ForSilencer = [reader.ReadByte()]; - break; - case 2: - ForSilencer = []; - break; - } + 1 => [reader.ReadByte()], + 2 => [], + _ => ForSilencer + }; } public override void AfterMeetingTasks() diff --git a/Roles/Standard/Impostor/Support/Ventriloquist.cs b/Roles/Standard/Impostor/Support/Ventriloquist.cs index a6f7a8a4b..2c3779033 100644 --- a/Roles/Standard/Impostor/Support/Ventriloquist.cs +++ b/Roles/Standard/Impostor/Support/Ventriloquist.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using UnityEngine; namespace EHR.Roles; diff --git a/Roles/Standard/Neutral/Benign/Follower.cs b/Roles/Standard/Neutral/Benign/Follower.cs index 7d3d71bcf..833fa8540 100644 --- a/Roles/Standard/Neutral/Benign/Follower.cs +++ b/Roles/Standard/Neutral/Benign/Follower.cs @@ -155,16 +155,12 @@ public class Follower : RoleBase { if (!seer.Is(CustomRoles.Follower)) { - if (!BetTargetKnowFollower.GetBool()) return string.Empty; - - if (Main.PlayerStates[target.PlayerId].Role is not Follower tc) return string.Empty; - + if (!BetTargetKnowFollower.GetBool() || Main.PlayerStates[target.PlayerId].Role is not Follower tc) return string.Empty; return seer.PlayerId == tc.BetPlayer ? CustomRoles.Follower.ColoredTextByRole("♦") : string.Empty; } else { if (Main.PlayerStates[seer.PlayerId].Role is not Follower tc) return string.Empty; - return tc.BetPlayer == target.PlayerId ? CustomRoles.Follower.ColoredTextByRole("♦") : string.Empty; } } diff --git a/Roles/Standard/Neutral/Benign/Predator.cs b/Roles/Standard/Neutral/Benign/Predator.cs index a7c3b16d1..6c20b441b 100644 --- a/Roles/Standard/Neutral/Benign/Predator.cs +++ b/Roles/Standard/Neutral/Benign/Predator.cs @@ -155,11 +155,7 @@ internal class Predator : RoleBase public override string GetSuffix(PlayerControl seer, PlayerControl target, bool hud = false, bool meeting = false) { - if (seer.PlayerId != target.PlayerId) return string.Empty; - - if (seer.IsModdedClient() && !hud) return string.Empty; - - if (Main.PlayerStates[seer.PlayerId].Role is not Predator { IsEnable: true } pt) return string.Empty; + if (seer.PlayerId != target.PlayerId || seer.IsModdedClient() && !hud || Main.PlayerStates[seer.PlayerId].Role is not Predator { IsEnable: true } pt) return string.Empty; if (pt.IsWon) return !hud ? "<#00ff00>\u2713" : Translator.GetString("PredatorDone"); diff --git a/Roles/Standard/Neutral/Benign/SoulHunter.cs b/Roles/Standard/Neutral/Benign/SoulHunter.cs index 633f917e1..9ae40e796 100644 --- a/Roles/Standard/Neutral/Benign/SoulHunter.cs +++ b/Roles/Standard/Neutral/Benign/SoulHunter.cs @@ -255,10 +255,7 @@ internal class SoulHunter : RoleBase public override string GetSuffix(PlayerControl seer, PlayerControl target, bool hud = false, bool meeting = false) { - if (!hud || Main.PlayerStates[seer.PlayerId].Role is not SoulHunter { IsEnable: true } sh) return string.Empty; - - if (!sh.IsTargetBlocked) return string.Empty; - + if (!hud || Main.PlayerStates[seer.PlayerId].Role is not SoulHunter { IsEnable: true, IsTargetBlocked: true } sh) return string.Empty; return sh.CurrentTarget.Frozen ? string.Format(GetString("SoulHunterNotifyFreeze"), GetPlayerById(sh.CurrentTarget.ID).GetRealName(), WaitingTimeAfterMeeting.GetInt() - (TimeStamp - sh.CurrentTarget.StartTimeStamp) + 1) : string.Format(GetString("SoulHunterNotify"), TimeToKillTarget.GetInt() - (TimeStamp - sh.CurrentTarget.StartTimeStamp) + 1, GetPlayerById(sh.CurrentTarget.ID).GetRealName()); } diff --git a/Roles/Standard/Neutral/Evil/Arsonist.cs b/Roles/Standard/Neutral/Evil/Arsonist.cs index 101ffc1b0..5faa2bc7d 100644 --- a/Roles/Standard/Neutral/Evil/Arsonist.cs +++ b/Roles/Standard/Neutral/Evil/Arsonist.cs @@ -99,11 +99,7 @@ internal class Arsonist : RoleBase .Append(doused.Item1) .Append('/'); - if (!ArsonistCanIgniteAnytime.GetBool()) - resultText.Append(doused.Item2); - else - resultText.Append(ArsonistMaxPlayersToIgnite.GetInt()); - + resultText.Append(!ArsonistCanIgniteAnytime.GetBool() ? doused.Item2 : ArsonistMaxPlayersToIgnite.GetInt()); resultText.Append(""); } diff --git a/Roles/Standard/Neutral/Evil/Collector.cs b/Roles/Standard/Neutral/Evil/Collector.cs index ef0883b76..9d7ffc87f 100644 --- a/Roles/Standard/Neutral/Evil/Collector.cs +++ b/Roles/Standard/Neutral/Evil/Collector.cs @@ -1,8 +1,8 @@ -using EHR.Modules; +using System.Collections.Generic; +using System.Linq; +using EHR.Modules; using EHR.Patches; using Hazel; -using System.Collections.Generic; -using System.Linq; using UnityEngine; namespace EHR.Roles; diff --git a/Roles/Standard/Neutral/Evil/Doomsayer.cs b/Roles/Standard/Neutral/Evil/Doomsayer.cs index 7372b0c9f..4851dbf98 100644 --- a/Roles/Standard/Neutral/Evil/Doomsayer.cs +++ b/Roles/Standard/Neutral/Evil/Doomsayer.cs @@ -2,7 +2,6 @@ using AmongUs.GameOptions; using EHR.Modules; using Hazel; -using UnityEngine; namespace EHR.Roles; diff --git a/Roles/Standard/Neutral/Evil/Vector.cs b/Roles/Standard/Neutral/Evil/Vector.cs index 0e8ecfa05..25aef829b 100644 --- a/Roles/Standard/Neutral/Evil/Vector.cs +++ b/Roles/Standard/Neutral/Evil/Vector.cs @@ -1,9 +1,7 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using AmongUs.GameOptions; using EHR.Modules; -using Hazel; using UnityEngine; using static EHR.Options; diff --git a/Roles/Standard/Neutral/Evil/Workaholic.cs b/Roles/Standard/Neutral/Evil/Workaholic.cs index 9985b046a..8e61175f3 100644 --- a/Roles/Standard/Neutral/Evil/Workaholic.cs +++ b/Roles/Standard/Neutral/Evil/Workaholic.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using static EHR.Options; diff --git a/Roles/Standard/Neutral/Killing/Agitator.cs b/Roles/Standard/Neutral/Killing/Agitator.cs index 6a1b14077..bc8fa7405 100644 --- a/Roles/Standard/Neutral/Killing/Agitator.cs +++ b/Roles/Standard/Neutral/Killing/Agitator.cs @@ -1,9 +1,7 @@ using System.Collections.Generic; -using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using Hazel; -using UnityEngine; using static EHR.Translator; namespace EHR.Roles; diff --git a/Roles/Standard/Neutral/Killing/Amogus.cs b/Roles/Standard/Neutral/Killing/Amogus.cs index c11254ce0..f239940e3 100644 --- a/Roles/Standard/Neutral/Killing/Amogus.cs +++ b/Roles/Standard/Neutral/Killing/Amogus.cs @@ -1,11 +1,10 @@ -using AmongUs.GameOptions; +using System; +using System.Collections.Generic; +using System.Linq; +using AmongUs.GameOptions; using EHR.Modules; using EHR.Modules.Extensions; using Hazel; -using System; -using System.Collections.Generic; -using System.Linq; -using static EHR.Roles.Adventurer; namespace EHR.Roles; diff --git a/Roles/Standard/Neutral/Killing/Bandit.cs b/Roles/Standard/Neutral/Killing/Bandit.cs index 0259af73a..69f193cef 100644 --- a/Roles/Standard/Neutral/Killing/Bandit.cs +++ b/Roles/Standard/Neutral/Killing/Bandit.cs @@ -197,22 +197,18 @@ public class Bandit : RoleBase if (StealMode.GetValue() == 1) return; - foreach (KeyValuePair> kvp1 in Targets) + foreach ((byte banditId, Dictionary innerDictionary) in Targets) { - byte banditId = kvp1.Key; PlayerControl banditpc = Utils.GetPlayerById(banditId); if (banditpc == null || !banditpc.IsAlive()) continue; - Dictionary innerDictionary = kvp1.Value; Utils.NotifyRoles(SpecifySeer: banditpc); - foreach (KeyValuePair kvp2 in innerDictionary) + foreach ((byte targetId, CustomRoles role) in innerDictionary) { - byte targetId = kvp2.Key; PlayerControl target = Utils.GetPlayerById(banditId); if (target == null) continue; - CustomRoles role = kvp2.Value; Main.PlayerStates[targetId].RemoveSubRole(role); Logger.Info($"Successfully removed {role} addon from {target.GetNameWithRole().RemoveHtmlTags()}", "Bandit"); banditpc.RpcSetCustomRole(role); diff --git a/Roles/Standard/Neutral/Killing/Bargainer.cs b/Roles/Standard/Neutral/Killing/Bargainer.cs index c56b094ab..4e8e458e4 100644 --- a/Roles/Standard/Neutral/Killing/Bargainer.cs +++ b/Roles/Standard/Neutral/Killing/Bargainer.cs @@ -1,12 +1,11 @@ -using AmongUs.GameOptions; -using EHR.Modules; -using Hazel; -using System; +using System; using System.Collections.Generic; using System.Linq; +using AmongUs.GameOptions; +using EHR.Modules; +using Hazel; using UnityEngine; using static EHR.Options; -using static EHR.Roles.Adventurer; // ReSharper disable PossibleMultipleEnumeration diff --git a/Roles/Standard/Neutral/Killing/Chemist.cs b/Roles/Standard/Neutral/Killing/Chemist.cs index 86795abbf..9a8b55ce6 100644 --- a/Roles/Standard/Neutral/Killing/Chemist.cs +++ b/Roles/Standard/Neutral/Killing/Chemist.cs @@ -1,9 +1,9 @@ -using AmongUs.GameOptions; -using EHR.Modules; -using Hazel; -using System; +using System; using System.Collections.Generic; using System.Linq; +using AmongUs.GameOptions; +using EHR.Modules; +using Hazel; using UnityEngine; using static EHR.Options; diff --git a/Roles/Standard/Neutral/Killing/Cultist.cs b/Roles/Standard/Neutral/Killing/Cultist.cs index 671e3f4ba..b1fd73c57 100644 --- a/Roles/Standard/Neutral/Killing/Cultist.cs +++ b/Roles/Standard/Neutral/Killing/Cultist.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using Hazel; diff --git a/Roles/Standard/Neutral/Killing/Infection.cs b/Roles/Standard/Neutral/Killing/Infection.cs index 855594d0a..a3ba573e5 100644 --- a/Roles/Standard/Neutral/Killing/Infection.cs +++ b/Roles/Standard/Neutral/Killing/Infection.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using Hazel; diff --git a/Roles/Standard/Neutral/Killing/Pelican.cs b/Roles/Standard/Neutral/Killing/Pelican.cs index b3febd0fa..9216853ab 100644 --- a/Roles/Standard/Neutral/Killing/Pelican.cs +++ b/Roles/Standard/Neutral/Killing/Pelican.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using Hazel; diff --git a/Roles/Standard/Neutral/Killing/Rogue.cs b/Roles/Standard/Neutral/Killing/Rogue.cs index b61d4c2ba..665d37d5d 100644 --- a/Roles/Standard/Neutral/Killing/Rogue.cs +++ b/Roles/Standard/Neutral/Killing/Rogue.cs @@ -308,7 +308,6 @@ public class Rogue : RoleBase 0 => reader.ReadString(), 1 => reader.ReadByte(), 2 => reader.ReadPackedInt32(), - 3 => null, _ => null }; diff --git a/Roles/Standard/Neutral/Killing/Samurai.cs b/Roles/Standard/Neutral/Killing/Samurai.cs index c4028dea9..ebe2469a1 100644 --- a/Roles/Standard/Neutral/Killing/Samurai.cs +++ b/Roles/Standard/Neutral/Killing/Samurai.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using AmongUs.GameOptions; -using UnityEngine; using static EHR.Options; namespace EHR.Roles; diff --git a/Roles/Standard/Neutral/Killing/Sharpshooter.cs b/Roles/Standard/Neutral/Killing/Sharpshooter.cs index ec9cccc4d..14b7e5c04 100644 --- a/Roles/Standard/Neutral/Killing/Sharpshooter.cs +++ b/Roles/Standard/Neutral/Killing/Sharpshooter.cs @@ -1,6 +1,4 @@ -using System.Linq; -using AmongUs.GameOptions; -using UnityEngine; +using AmongUs.GameOptions; namespace EHR.Roles; diff --git a/Roles/Standard/Neutral/Killing/Slenderman.cs b/Roles/Standard/Neutral/Killing/Slenderman.cs index 1aa69af0e..7120f853e 100644 --- a/Roles/Standard/Neutral/Killing/Slenderman.cs +++ b/Roles/Standard/Neutral/Killing/Slenderman.cs @@ -96,7 +96,7 @@ public class Slenderman : RoleBase MessageWriter w = Utils.CreateRPC(CustomRPC.SyncRoleData); w.Write(SlendermanPC.PlayerId); w.WritePacked(Blinded.Count); - Blinded.Do(x => w.Write(x)); + Blinded.Do(w.Write); Utils.EndRPC(w); } } diff --git a/Roles/Standard/Neutral/Killing/Spider.cs b/Roles/Standard/Neutral/Killing/Spider.cs index 2ef9babf5..fe34fb2a7 100644 --- a/Roles/Standard/Neutral/Killing/Spider.cs +++ b/Roles/Standard/Neutral/Killing/Spider.cs @@ -135,11 +135,8 @@ public class Spider : RoleBase int trappedDuration = TrappedDuration.GetInt(); long expireTime = Utils.TimeStamp + trappedDuration; - foreach (var kvp in Webs) + foreach ((Vector2 webPos, Dictionary trappedPlayers) in Webs) { - Vector2 webPos = kvp.Key; - var trappedPlayers = kvp.Value; - if (!FastVector2.DistanceWithinRange(webPos, pos, range)) continue; if (!trappedPlayers.TryAdd(pc.PlayerId, expireTime)) continue; diff --git a/Roles/Standard/Neutral/Killing/Spiritcaller.cs b/Roles/Standard/Neutral/Killing/Spiritcaller.cs index 67aabc39e..25420a5da 100644 --- a/Roles/Standard/Neutral/Killing/Spiritcaller.cs +++ b/Roles/Standard/Neutral/Killing/Spiritcaller.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System.Collections; +using System.Collections.Generic; using AmongUs.GameOptions; using EHR.Modules; using Hazel; @@ -187,7 +188,7 @@ public class Spiritcaller : RoleBase else AddProtect++; } - static System.Collections.IEnumerator ProtectCoroutine() + static IEnumerator ProtectCoroutine() { Protected = true; diff --git a/Roles/Standard/Neutral/Pariah/Magistrate.cs b/Roles/Standard/Neutral/Pariah/Magistrate.cs index f70b400af..52f550c59 100644 --- a/Roles/Standard/Neutral/Pariah/Magistrate.cs +++ b/Roles/Standard/Neutral/Pariah/Magistrate.cs @@ -1,4 +1,5 @@ -using AmongUs.GameOptions; +using System.Collections; +using AmongUs.GameOptions; using EHR.Modules; using UnityEngine; @@ -42,7 +43,7 @@ public class Magistrate : RoleBase Main.Instance.StartCoroutine(Coroutine()); return; - System.Collections.IEnumerator Coroutine() + IEnumerator Coroutine() { while (GameStates.IsMeeting || ExileController.Instance || AntiBlackout.SkipTasks) yield return new WaitForSecondsRealtime(5f); yield return new WaitForSecondsRealtime(1f); diff --git a/Roles/Standard/Neutral/Pariah/Seamstress.cs b/Roles/Standard/Neutral/Pariah/Seamstress.cs index 372a71623..b4263485c 100644 --- a/Roles/Standard/Neutral/Pariah/Seamstress.cs +++ b/Roles/Standard/Neutral/Pariah/Seamstress.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using Hazel; diff --git a/Roles/Standard/Neutral/Pariah/Spirit.cs b/Roles/Standard/Neutral/Pariah/Spirit.cs index 06bd823fb..34648c20a 100644 --- a/Roles/Standard/Neutral/Pariah/Spirit.cs +++ b/Roles/Standard/Neutral/Pariah/Spirit.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using AmongUs.GameOptions; using EHR.Modules; using Hazel;