diff --git a/HNSRevamped.cs b/HNSRevamped.cs index c4e6595..71121da 100644 --- a/HNSRevamped.cs +++ b/HNSRevamped.cs @@ -5,6 +5,7 @@ global using System.Linq; using BepInEx; using BepInEx.Configuration; using BepInEx.Unity.IL2CPP; +using System; using UnityEngine; namespace HNSRevamped; @@ -17,6 +18,38 @@ public partial class Main : BasePlugin public static BepInEx.Logging.ManualLogSource Logger; public static BasePlugin Instance; + public static ConfigEntry GM { get; private set; } + public static ConfigEntry UnlockFps { get; private set; } + public static ConfigEntry ShowFps { get; private set; } + public static ConfigEntry AutoStart { get; private set; } + public static ConfigEntry DarkTheme { get; private set; } + public static ConfigEntry LobbyMusic { get; private set; } + + public static bool HasArgumentException; + public static string CredentialsText; + + public static PlayerControl[] AllPlayerControls + { + get + { + int count = PlayerControl.AllPlayerControls.Count; + var result = new PlayerControl[count]; + var i = 0; + + foreach (PlayerControl pc in PlayerControl.AllPlayerControls) + { + if (pc == null || pc.PlayerId >= 254) continue; + + result[i++] = pc; + } + + if (i == 0) return []; + + Array.Resize(ref result, i); + return result; + } + } + public override void Load() { var handler = HNSRevamped.Logger.Handler("GitVersion"); @@ -24,6 +57,14 @@ public partial class Main : BasePlugin HNSRevamped.Logger.Enable(); Instance = this; + AutoStart = Config.Bind("Client Options", "AutoStart", false); + GM = Config.Bind("Client Options", "GM", false); + UnlockFps = Config.Bind("Client Options", "UnlockFPS", false); + ShowFps = Config.Bind("Client Options", "ShowFPS", false); + AutoStart = Config.Bind("Client Options", "AutoStart", false); + DarkTheme = Config.Bind("Client Options", "DarkTheme", true); + LobbyMusic = Config.Bind("Client Options", "LobbyMusic", false); + BanManager.Init(); Harmony.PatchAll(); diff --git a/Modules/BanManager.cs b/Modules/BanManager.cs index baf74e4..382e3a8 100644 --- a/Modules/BanManager.cs +++ b/Modules/BanManager.cs @@ -1,12 +1,9 @@ -using HarmonyLib; using InnerNet; using System; using System.IO; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; -using System.Collections.Generic; -using System.Linq; using System.Reflection; // https://github.com/EnhancedNetwork/TownofHost-Enhanced/blob/main/Modules/BanManager.cs diff --git a/Modules/ClientOptionItem.cs b/Modules/ClientOptionItem.cs new file mode 100644 index 0000000..2db9de2 --- /dev/null +++ b/Modules/ClientOptionItem.cs @@ -0,0 +1,162 @@ +using System; +using BepInEx.Configuration; +using UnityEngine; + +namespace HNSRevamped; + +// Credit: https://github.com/tukasa0001/TownOfHost +public class ClientOptionItem +{ + public static SpriteRenderer CustomBackground; + private static List OptionButtons; + private readonly ConfigEntry Config; + public readonly ToggleButtonBehaviour ToggleButton; + + private ClientOptionItem( + string name, + ConfigEntry config, + OptionsMenuBehaviour optionsMenuBehaviour, + Action additionalOnClickAction = null) + { + try + { + Config = config; + + ToggleButtonBehaviour mouseMoveToggle = optionsMenuBehaviour.DisableMouseMovement; + + if (CustomBackground == null) + { + CustomBackground = UnityEngine.Object.Instantiate(optionsMenuBehaviour.Background, optionsMenuBehaviour.transform); + CustomBackground.name = "CustomBackground"; + CustomBackground.transform.localScale = new(0.9f, 0.9f, 1f); + CustomBackground.transform.localPosition += Vector3.back * 8; + CustomBackground.size += new Vector2(3f, 0f); + CustomBackground.gameObject.SetActive(false); + + ToggleButtonBehaviour closeButton = UnityEngine.Object.Instantiate(mouseMoveToggle, CustomBackground.transform); + closeButton.transform.localPosition = new(2.6f, -2.3f, -6f); + closeButton.name = "Back"; + closeButton.Text.text = "Back"; + closeButton.Background.color = Palette.DisabledGrey; + var closePassiveButton = closeButton.GetComponent(); + closePassiveButton.OnClick = new(); + closePassiveButton.OnClick.AddListener(new Action(() => { CustomBackground.gameObject.SetActive(false); })); + + UiElement[] selectableButtons = optionsMenuBehaviour.ControllerSelectable.ToArray(); + PassiveButton leaveButton = null; + PassiveButton returnButton = null; + + foreach (UiElement button in selectableButtons) + { + if (button == null) continue; + + switch (button.name) + { + case "LeaveGameButton": + leaveButton = button.GetComponent(); + break; + case "ReturnToGameButton": + returnButton = button.GetComponent(); + break; + } + } + + Transform generalTab = mouseMoveToggle.transform.parent.parent.parent; + + ToggleButtonBehaviour modOptionsButton = UnityEngine.Object.Instantiate(mouseMoveToggle, generalTab); + modOptionsButton.transform.localPosition = leaveButton?.transform.localPosition ?? new(0f, -2.4f, 1f); + modOptionsButton.name = "HNSR Options"; + modOptionsButton.Text.text = "HNSR Options"; + modOptionsButton.Background.color = new Color32(0, 165, 255, byte.MaxValue); + var modOptionsPassiveButton = modOptionsButton.GetComponent(); + modOptionsPassiveButton.OnClick = new(); + modOptionsPassiveButton.OnClick.AddListener(new Action(() => + { + AdjustButtonPositions(); + CustomBackground.gameObject.SetActive(true); + })); + + if (leaveButton != null && leaveButton.transform != null) leaveButton.transform.localPosition = new(-1.35f, -2.411f, -1f); + if (returnButton != null) returnButton.transform.localPosition = new(1.35f, -2.411f, -1f); + OptionButtons = []; + } + + ToggleButton = UnityEngine.Object.Instantiate(mouseMoveToggle, CustomBackground.transform); + OptionButtons.Add(ToggleButton); + + 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)), + -6f); + + ToggleButton.name = name; + ToggleButton.Text.text = name; + var passiveButton = ToggleButton.GetComponent(); + passiveButton.OnClick = new(); + + passiveButton.OnClick.AddListener(new Action(() => + { + if (config != null) config.Value = !config.Value; + + UpdateToggle(); + additionalOnClickAction?.Invoke(); + })); + + UpdateToggle(); + } + catch (Exception e) + { + Logger.Error(e.ToString(), "ClientOptionItem.Create"); + } + } + + public static ClientOptionItem Create( + string name, + ConfigEntry config, + OptionsMenuBehaviour optionsMenuBehaviour, + Action additionalOnClickAction = null) + { + return new(name, config, optionsMenuBehaviour, additionalOnClickAction); + } + + private static void AdjustButtonPositions() + { + if (OptionButtons == null || OptionButtons.Count == 0) return; + + int totalRows = (OptionButtons.Count + 2) / 3; + + float topPosition = 2.2f; + float bottomLimit = -1.6f; + float availableHeight = topPosition - bottomLimit; + float rowSpacing = totalRows > 1 ? availableHeight / (totalRows - 1) : 0f; + + for (int i = 0; i < OptionButtons.Count; i++) + { + var button = OptionButtons[i]; + if (button == null) continue; + + int row = i / 3; + int col = i % 3; + + float xPos = col switch + { + 0 => -2.6f, + 1 => 0f, + _ => 2.6f + }; + + float yPos = topPosition - (row * rowSpacing); + + button.transform.localPosition = new Vector3(xPos, yPos, -6f); + } + } + + public void UpdateToggle() + { + if (ToggleButton == null) return; + + Color32 color = Config is { Value: true } ? new(0, 165, 255, byte.MaxValue) : new Color32(77, 77, 77, byte.MaxValue); + ToggleButton.Background.color = color; + ToggleButton.Rollover?.ChangeOutColor(color); + } +} diff --git a/Modules/CustomOptionsHolder.cs b/Modules/CustomOptionsHolder.cs index d995a0f..a1fad5c 100644 --- a/Modules/CustomOptionsHolder.cs +++ b/Modules/CustomOptionsHolder.cs @@ -1,7 +1,5 @@ using System.Threading.Tasks; -using HarmonyLib; using UnityEngine; -using System.Collections.Generic; // https://github.com/tukasa0001/TownOfHost/blob/main/Modules/OptionHolder.cs namespace HNSRevamped diff --git a/Modules/LateTask.cs b/Modules/LateTask.cs index 06329f8..e0f905b 100644 --- a/Modules/LateTask.cs +++ b/Modules/LateTask.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Runtime.CompilerServices; diff --git a/Modules/LogHandler.cs b/Modules/LogHandler.cs index 8b04eb1..1246f40 100644 --- a/Modules/LogHandler.cs +++ b/Modules/LogHandler.cs @@ -3,9 +3,6 @@ using System.Diagnostics; using System.IO; using System.Net.Http; using System.Runtime.CompilerServices; -using HarmonyLib; -using System.Linq; -using System.Collections.Generic; using LogLevel = BepInEx.Logging.LogLevel; namespace HNSRevamped; diff --git a/Modules/OptionBackup/OptionBackupData.cs b/Modules/OptionBackup/OptionBackupData.cs index 8c6a2c1..d5f2a7b 100644 --- a/Modules/OptionBackup/OptionBackupData.cs +++ b/Modules/OptionBackup/OptionBackupData.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using AmongUs.GameOptions; // https://github.com/tukasa0001/TownOfHost/blob/main/Modules/OptionBackup/OptionBackupData.cs diff --git a/Modules/RPC.cs b/Modules/RPC.cs index 1149bd6..8d3e287 100644 --- a/Modules/RPC.cs +++ b/Modules/RPC.cs @@ -1,9 +1,7 @@ -using HarmonyLib; -using Hazel; +using Hazel; using InnerNet; using UnityEngine; using System; -using System.Linq; using AmongUs.GameOptions; using Object = UnityEngine.Object; diff --git a/Modules/Utils.cs b/Modules/Utils.cs index d6d85a8..b899edf 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -1,11 +1,10 @@ -using System.Collections.Generic; using System.Data; -using System.Linq; using AmongUs.GameOptions; using Hazel; using UnityEngine; using Il2CppInterop.Runtime.InteropTypes.Arrays; using InnerNet; +using System.Diagnostics; using System.IO; using System.Reflection; using System; @@ -19,6 +18,14 @@ namespace HNSRevamped; public static class Utils { + private static readonly DateTime Epoch = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + private static readonly DateTime StartTime = DateTime.UtcNow; + private static readonly long EpochStartSeconds = (long)(StartTime - Epoch).TotalSeconds; + private static readonly Stopwatch Stopwatch = Stopwatch.StartNew(); + + public static long TimeStamp => EpochStartSeconds + (long)Stopwatch.Elapsed.TotalSeconds; + + public static bool IsLobby => AmongUsClient.Instance.GameState == InnerNetClient.GameStates.Joined; public static bool InGame => AmongUsClient.Instance && AmongUsClient.Instance.GameState == InnerNetClient.GameStates.Started; public static bool isHideNSeek => GameOptionsManager.Instance.CurrentGameOptions.GameMode == GameModes.HideNSeek; @@ -97,4 +104,51 @@ public static class Utils else return optionItem.GetName(); } + + public static string GetRegionName(IRegionInfo region = null) + { + region ??= ServerManager.Instance.CurrentRegion; + + string name = region.Name; + + if (AmongUsClient.Instance.NetworkMode != NetworkModes.OnlineGame) + { + name = "Local Game"; + return name; + } + + if (region.PingServer.EndsWith("among.us", StringComparison.Ordinal)) + { + // Official servers + name = name switch + { + "North America" => "NA", + "Europe" => "EU", + "Asia" => "AS", + _ => name + }; + + return name; + } + + string ip = region.Servers.FirstOrDefault()?.Ip ?? string.Empty; + + if (ip.Contains("aumods.us", StringComparison.Ordinal) || ip.Contains("duikbo.at", StringComparison.Ordinal)) + { + // Modded Servers + if (ip.Contains("au-eu")) + name = "MEU"; + else if (ip.Contains("au-as")) + name = "MAS"; + else + name = "MNA"; + + return name; + } + + if (name.Contains("Niko", StringComparison.OrdinalIgnoreCase)) + name = name.Replace("233(", "-").TrimEnd(')'); + + return name; + } } diff --git a/Patches/ChatControlPatch.cs b/Patches/ChatControlPatch.cs new file mode 100644 index 0000000..7f5ed31 --- /dev/null +++ b/Patches/ChatControlPatch.cs @@ -0,0 +1,23 @@ +using InnerNet; +using System; +using UnityEngine; + +// https://github.com/SuperNewRoles/SuperNewRoles/blob/master/SuperNewRoles/Patches/LobbyBehaviourPatch.cs +namespace HNSRevamped; + +[HarmonyPatch(typeof(ChatController), nameof(ChatController.Update))] +internal static class ChatControllerUpdatePatch +{ + + public static void Postfix(ChatController __instance) + { + if (Main.DarkTheme.Value) + { + __instance.freeChatField.background.color = new Color32(40, 40, 40, byte.MaxValue); + + __instance.quickChatField.background.color = new Color32(40, 40, 40, byte.MaxValue); + __instance.quickChatField.text.color = Color.white; + } + else __instance.freeChatField.textArea.outputText.color = Color.black; + } +} \ No newline at end of file diff --git a/Patches/ClientOptionsPatch.cs b/Patches/ClientOptionsPatch.cs new file mode 100644 index 0000000..a5f5ef6 --- /dev/null +++ b/Patches/ClientOptionsPatch.cs @@ -0,0 +1,79 @@ +using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using UnityEngine; + +namespace HNSRevamped +{ + // https://github.com/tukasa0001/TownOfHost + [HarmonyPatch(typeof(OptionsMenuBehaviour), nameof(OptionsMenuBehaviour.Start))] + public static class OptionsMenuBehaviourStartPatch + { + private static ClientOptionItem GM; // Currently not used yet + private static ClientOptionItem UnlockFPS; + private static ClientOptionItem ShowFPS; + private static ClientOptionItem AutoStart; + private static ClientOptionItem DarkTheme; + private static ClientOptionItem LobbyMusic; + + public static void Postfix(OptionsMenuBehaviour __instance) + { + if (__instance.DisableMouseMovement == null) return; + + if (GM == null || GM.ToggleButton == null) + { + GM = ClientOptionItem.Create("GM", Main.GM, __instance, GMButtonToggle); + + static void GMButtonToggle() + { + if (Main.GM.Value) + HudManager.Instance.ShowPopUp("Hi there! GM hasn't been implemented yet. Sorry for the inconvenience! -MV"); + } + } + + if (UnlockFPS == null || UnlockFPS.ToggleButton == null) + { + UnlockFPS = ClientOptionItem.Create("UnlockFPS", Main.UnlockFps, __instance, UnlockFPSButtonToggle); + + static void UnlockFPSButtonToggle() + { + Application.targetFrameRate = Main.UnlockFps.Value ? 120 : 60; + Logger.SendInGame($"FPS Set To {Application.targetFrameRate}"); + } + } + + if (ShowFPS == null || ShowFPS.ToggleButton == null) + ShowFPS = ClientOptionItem.Create("ShowFPS", Main.ShowFps, __instance); + + if (AutoStart == null || AutoStart.ToggleButton == null) + { + AutoStart = ClientOptionItem.Create("AutoStart", Main.AutoStart, __instance, AutoStartButtonToggle); + + static void AutoStartButtonToggle() + { + if (!Main.AutoStart.Value && GameStartManager.InstanceExists && + GameStartManager.Instance.startState == GameStartManager.StartingStates.Countdown) + { + GameStartManager.Instance.ResetStartState(); + Logger.SendInGame("CancelStartCountDown"); + } + } + } + + if (DarkTheme == null || DarkTheme.ToggleButton == null) + DarkTheme = ClientOptionItem.Create("EnableDarkTheme", Main.DarkTheme, __instance); + + if (LobbyMusic == null || LobbyMusic.ToggleButton == null) + LobbyMusic = ClientOptionItem.Create("LobbyMusic", Main.LobbyMusic, __instance); + } + } + + [HarmonyPatch(typeof(OptionsMenuBehaviour), nameof(OptionsMenuBehaviour.Close))] + public static class OptionsMenuBehaviourClosePatch + { + public static void Postfix() + { + ClientOptionItem.CustomBackground?.gameObject.SetActive(false); + } + } +} \ No newline at end of file diff --git a/Patches/CredentialsPatch.cs b/Patches/CredentialsPatch.cs new file mode 100644 index 0000000..96b9c0e --- /dev/null +++ b/Patches/CredentialsPatch.cs @@ -0,0 +1,160 @@ +using System; +using System.Text; +using TMPro; +using UnityEngine; + +//https://github.com/Gurge44/EndlessHostRoles/blob/main/Patches/CredentialsPatch.cs +namespace HNSRevamped +{ + public enum ErrorCode + { + Main_DictionaryError = 10003 + } + + public class ErrorText + { + public static ErrorText Instance; + public TextMeshPro Text; + + private readonly List _errors = new(); + + public static void Create(TextMeshPro baseText) + { + if (Instance != null) return; + + var text = UnityEngine.Object.Instantiate(baseText); + text.name = "ErrorText"; + + text.enabled = false; + text.text = "-"; + text.color = Color.red; + text.alignment = TextAlignmentOptions.Top; + + Instance = new ErrorText + { + Text = text + }; + } + + public void AddError(ErrorCode code) + { + if (!_errors.Contains(code)) + _errors.Add(code); + + Text.enabled = true; + Text.text = $"Error: {code}"; + } + } + + [HarmonyPatch(typeof(VersionShower), nameof(VersionShower.Start))] + internal static class VersionShowerStartPatch + { + private static void Postfix(VersionShower __instance) + { + Main.CredentialsText = $"Hide And Seek Revamped v0.1.0"; + + ErrorText.Create(__instance.text); + + if (Main.HasArgumentException && ErrorText.Instance != null) + { + ErrorText.Instance.AddError(ErrorCode.Main_DictionaryError); + } + } + } + + [HarmonyPatch(typeof(PingTracker), nameof(PingTracker.Update))] + internal static class PingTrackerUpdatePatch + { + public static PingTracker Instance; + private static readonly StringBuilder Sb = new(); + private static long LastUpdate; + private static readonly List LastFPS = new(); + + public static bool Prefix(PingTracker __instance) + { + FpsSampler.TickFrame(); + + PingTracker instance = Instance ?? __instance; + + if (AmongUsClient.Instance == null) return false; + + if (AmongUsClient.Instance.NetworkMode == NetworkModes.FreePlay) + { + instance.gameObject.SetActive(false); + return false; + } + + if (instance.name != "HNSR_SettingsText") + { + instance.aspectPosition.DistanceFromEdge = !AmongUsClient.Instance.IsGameStarted ? instance.lobbyPos : instance.gamePos; + instance.text.alignment = TextAlignmentOptions.Center; + instance.text.text = Sb.ToString(); + } + + if (Instance == null) Instance = __instance; + + long now = Utils.TimeStamp; + if (now == LastUpdate) return false; + LastUpdate = now; + + Sb.Clear(); + + Sb.Append(Utils.IsLobby ? "\r\n" : ""); + Sb.Append(Main.CredentialsText); + + int ping = AmongUsClient.Instance.Ping; + string color = ping switch + { + < 30 => "#44dfcc", + < 100 => "#7bc690", + < 200 => "#f3920e", + < 400 => "#ff146e", + _ => "#ff4500" + }; + + Sb.Append(Utils.InGame ? " - " : "\r\n"); + Sb.Append($"Ping: {ping}"); + AppendSeparator(); + Sb.Append($"Server: {Utils.GetRegionName()}"); + + if (Main.ShowFps.Value && LastFPS.Count > 0) + { + float fps = LastFPS.Average(); + Color fpscolor = fps switch + { + < 10f => Color.red, + < 25f => Color.yellow, + < 50f => Color.green, + _ => new Color32(0, 165, 255, 255) + }; + + AppendSeparator(); + Sb.Append(Utils.ColorString(fpscolor, Utils.ColorString(Color.cyan, "FPS: ") + (int)fps)); + } + + if (Utils.InGame) Sb.Append("\r\n."); + + return false; + + void AppendSeparator() => Sb.Append(Utils.InGame ? " - " : " - "); + } + + private static class FpsSampler + { + private static int Frames; + private static float Elapsed; + private const float SampleInterval = 0.5f; + + public static void TickFrame() + { + Frames++; + Elapsed += Time.unscaledDeltaTime; + if (Elapsed < SampleInterval) return; + LastFPS.Add(Frames / Elapsed); + if (LastFPS.Count > 10) LastFPS.RemoveAt(0); + Frames = 0; + Elapsed = 0f; + } + } + } +} \ No newline at end of file diff --git a/Patches/GameOptionsMenuPatch.cs b/Patches/GameOptionsMenuPatch.cs index 210b93f..9cd133a 100644 --- a/Patches/GameOptionsMenuPatch.cs +++ b/Patches/GameOptionsMenuPatch.cs @@ -1,6 +1,5 @@ using System; using Il2CppSystem.Collections.Generic; -using HarmonyLib; using UnityEngine; using Object = UnityEngine.Object; @@ -533,4 +532,21 @@ namespace HNSRevamped return false; } } + [HarmonyPatch(typeof(ChatController), nameof(ChatController.Update))] + public static class FixDarkThemeForSearchBar + { + public static FreeChatInputField InputField; + public static void Postfix() + { + if (!GameSettingMenu.Instance) return; + FreeChatInputField field = InputField; + + if (field != null) + { + field.background.color = new Color32(40, 40, 40, byte.MaxValue); + field.textArea.compoText.Color(Color.white); + field.textArea.outputText.color = Color.white; + } + } + } } \ No newline at end of file diff --git a/Patches/GameSettingMenuPatch.cs b/Patches/GameSettingMenuPatch.cs index 6ea9aa1..377b50a 100644 --- a/Patches/GameSettingMenuPatch.cs +++ b/Patches/GameSettingMenuPatch.cs @@ -1,6 +1,4 @@ using System; -using HarmonyLib; -using System.Collections.Generic; using TMPro; using UnityEngine; using Object = UnityEngine.Object; diff --git a/Patches/GameStartManagerPatch.cs b/Patches/GameStartManagerPatch.cs index 9544c47..99e9a4e 100644 --- a/Patches/GameStartManagerPatch.cs +++ b/Patches/GameStartManagerPatch.cs @@ -1,6 +1,4 @@ -using HarmonyLib; - -namespace HNSRevamped; +namespace HNSRevamped; [HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.Update))] public static class GameStartManagerUpdatePatch diff --git a/Patches/JoinAndLeavePatches.cs b/Patches/JoinAndLeavePatches.cs index 5e3e896..48eb6e2 100644 --- a/Patches/JoinAndLeavePatches.cs +++ b/Patches/JoinAndLeavePatches.cs @@ -1,12 +1,9 @@ using AmongUs.Data; -using HarmonyLib; using AmongUs.GameOptions; using InnerNet; using System.Text.RegularExpressions; using TMPro; using UnityEngine; -using System.Linq; - namespace HNSRevamped; diff --git a/Patches/LobbyPatch.cs b/Patches/LobbyPatch.cs new file mode 100644 index 0000000..4d786b1 --- /dev/null +++ b/Patches/LobbyPatch.cs @@ -0,0 +1,28 @@ +using InnerNet; +using System; +using UnityEngine; + +// https://github.com/SuperNewRoles/SuperNewRoles/blob/master/SuperNewRoles/Patches/LobbyBehaviourPatch.cs +namespace HNSRevamped; + +[HarmonyPatch(typeof(LobbyBehaviour), nameof(LobbyBehaviour.Update))] +internal static class LobbyBehaviourUpdatePatch +{ + public static void Postfix(LobbyBehaviour __instance) + { + // ReSharper disable once ConvertToLocalFunction + Func lobbybgm = x => x.Name.Equals("MapTheme"); + ISoundPlayer mapThemeSound = SoundManager.Instance.soundPlayers.Find(lobbybgm); + + if (!Main.LobbyMusic.Value) + { + if (mapThemeSound == null) return; + SoundManager.Instance.StopNamedSound("MapTheme"); + } + else + { + if (mapThemeSound != null) return; + SoundManager.Instance.CrossFadeSound("MapTheme", __instance.MapTheme, 0.5f); + } + } +} \ No newline at end of file diff --git a/Patches/LobbyViewSettingsPatch.cs b/Patches/LobbyViewSettingsPatch.cs index 36402f2..89dfb6f 100644 --- a/Patches/LobbyViewSettingsPatch.cs +++ b/Patches/LobbyViewSettingsPatch.cs @@ -1,8 +1,6 @@ using System; using TMPro; -using HarmonyLib; using UnityEngine; -using System.Collections.Generic; using Object = UnityEngine.Object; diff --git a/Patches/NumberOptionsPatch.cs b/Patches/NumberOptionsPatch.cs index e37f7c8..5e09d9a 100644 --- a/Patches/NumberOptionsPatch.cs +++ b/Patches/NumberOptionsPatch.cs @@ -1,5 +1,4 @@ -using HarmonyLib; -using AmongUs.GameOptions; +using AmongUs.GameOptions; namespace HNSRevamped; diff --git a/Patches/PlayerControlPatches.cs b/Patches/PlayerControlPatches.cs index 529397f..4dcd5dc 100644 --- a/Patches/PlayerControlPatches.cs +++ b/Patches/PlayerControlPatches.cs @@ -1,5 +1,4 @@ using AmongUs.Data; -using HarmonyLib; using AmongUs.GameOptions; using InnerNet;