From 44f63d6042a4a87f9687aab34be5f09fdccec12a Mon Sep 17 00:00:00 2001 From: Ape <155788660+ApeMV@users.noreply.github.com> Date: Tue, 17 Feb 2026 16:50:07 +0100 Subject: [PATCH] Command, GM, NumberOption fixes + Faster loading --- Modules/CustomOptionsHolder.cs | 10 +-- Modules/FixedUpdate.cs | 25 +++--- Patches/ChatPatches.cs | 144 +++++++++++++++------------------ Patches/ClientOptionsPatch.cs | 23 ++++++ Patches/DevicePatches.cs | 2 + Patches/IntroPatch.cs | 23 +++++- Patches/NumberOptionsPatch.cs | 23 +++++- Patches/OnGameStartedPatch.cs | 14 ---- 8 files changed, 148 insertions(+), 116 deletions(-) diff --git a/Modules/CustomOptionsHolder.cs b/Modules/CustomOptionsHolder.cs index b85e848..a1fee37 100644 --- a/Modules/CustomOptionsHolder.cs +++ b/Modules/CustomOptionsHolder.cs @@ -38,11 +38,11 @@ namespace AmongUsRevamped taskOptionsLoad = Task.Run(Load); } - [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start)), HarmonyPostfix] - public static void WaitOptionsLoad() - { - taskOptionsLoad.Wait(); - } + //[HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start)), HarmonyPostfix] + //public static void WaitOptionsLoad() + //{ + //taskOptionsLoad.Wait(); + //} public const int PresetId = 0; diff --git a/Modules/FixedUpdate.cs b/Modules/FixedUpdate.cs index 265c0fe..2d7bef2 100644 --- a/Modules/FixedUpdate.cs +++ b/Modules/FixedUpdate.cs @@ -94,22 +94,19 @@ class FixedUpdateInGamePatch Main.NormalOptions.KillCooldown = 25f; } - if (AmongUsClient.Instance.AmHost) + if (__instance.Data.PlayerLevel != 0 && __instance.Data.PlayerLevel < Options.KickLowLevelPlayer.GetInt() && __instance.Data.ClientId != AmongUsClient.Instance.HostId) { - if (__instance.Data.PlayerLevel != 0 && __instance.Data.PlayerLevel < Options.KickLowLevelPlayer.GetInt() && __instance.Data.ClientId != AmongUsClient.Instance.HostId) + if (!Options.TempBanLowLevelPlayer.GetBool()) { - if (!Options.TempBanLowLevelPlayer.GetBool()) - { - AmongUsClient.Instance.KickPlayer(__instance.Data.ClientId, false); - Logger.Info($" {__instance.Data.PlayerName} was kicked for being under level {Options.KickLowLevelPlayer.GetInt()}", "KickLowLevelPlayer"); - Logger.SendInGame($" {__instance.Data.PlayerName} was kicked for being under level {Options.KickLowLevelPlayer.GetInt()}"); - } - else - { - AmongUsClient.Instance.KickPlayer(__instance.Data.ClientId, true); - Logger.Info($" {__instance.Data.PlayerName} was banned for being under level {Options.KickLowLevelPlayer.GetInt()} ", "BanLowLevelPlayer"); - Logger.SendInGame($" {__instance.Data.PlayerName} was banned for being under level {Options.KickLowLevelPlayer.GetInt()}"); - } + AmongUsClient.Instance.KickPlayer(__instance.Data.ClientId, false); + Logger.Info($" {__instance.Data.PlayerName} was kicked for being under level {Options.KickLowLevelPlayer.GetInt()}", "KickLowLevelPlayer"); + Logger.SendInGame($" {__instance.Data.PlayerName} was kicked for being under level {Options.KickLowLevelPlayer.GetInt()}"); + } + else + { + AmongUsClient.Instance.KickPlayer(__instance.Data.ClientId, true); + Logger.Info($" {__instance.Data.PlayerName} was banned for being under level {Options.KickLowLevelPlayer.GetInt()} ", "BanLowLevelPlayer"); + Logger.SendInGame($" {__instance.Data.PlayerName} was banned for being under level {Options.KickLowLevelPlayer.GetInt()}"); } } diff --git a/Patches/ChatPatches.cs b/Patches/ChatPatches.cs index dad3409..356f5a6 100644 --- a/Patches/ChatPatches.cs +++ b/Patches/ChatPatches.cs @@ -312,6 +312,71 @@ public static class RPCHandlerPatch } } + bool col1 = text.StartsWith("/col ") || text.StartsWith("/cor "); + bool col2 = text.StartsWith("/color "); + bool col3 = text.StartsWith("/colour "); + + if ((col1 || col2 || col3) && !Utils.InGame) + { + string argCol = text.Substring(col1 ? 5 : col2 ? 7 : col3 ? 8 : 0).Trim(); + + if (Utils.TryGetColorId(argCol, out byte colId)) + { + if (Options.ColorCommandLevel.GetValue() == 0 && Utils.IsPlayerModerator(__instance.Data.FriendCode) || Options.ColorCommandLevel.GetValue() == 1) + { + if (colId > 17 && !Options.AllowFortegreen.GetBool()) return; + __instance.RpcSetColor(colId); + } + } + } + + // Banning works by name and color. Commands are separated incase someone has a color as their name + bool isKick = text.StartsWith("/kick "); + bool isBan = text.StartsWith("/ban "); + + bool isColorKick = text.StartsWith("/ckick "); + bool isColorBan = text.StartsWith("/cban "); + + bool banLog = isBan || isColorBan; + + if (isKick || isBan || isColorKick || isColorBan) + { + if (Utils.IsPlayerModerator(__instance.Data.FriendCode)) + { + string arg = text.Substring(isKick ? 6 : isBan ? 5 : isColorKick ? 7 : isColorBan ? 6 : 0).Trim(); + + PlayerControl target = null; + + foreach (PlayerControl p in PlayerControl.AllPlayerControls) + { + if (p.Data == null || p == PlayerControl.LocalPlayer || Utils.IsPlayerModerator(p.Data.FriendCode)) continue; + + if ((isKick || isBan) && p.Data.PlayerName.Equals(arg, StringComparison.OrdinalIgnoreCase)) + { + target = p; + break; + } + + if ((isColorKick || isColorBan) && Utils.TryGetColorId(arg, out byte colorId)) + { + if (p.Data.DefaultOutfit.ColorId == colorId) + { + target = p; + break; + } + } + } + + if (target != null) + { + AmongUsClient.Instance.KickPlayer(target.Data.ClientId, isBan || isColorBan); + Logger.Info($" {__instance.Data.PlayerName} {(banLog ? "banned" : "kicked")} {target.Data.PlayerName}", "Kick&BanCommand"); + } + } + } + + if (CustomRoleManagement.HandlingRoleMessages || OnGameJoinedPatch.WaitingForChat) return; + if (text == "/h" || text == "/help" || text == "/cmd" || text == "/commands") { if (!Utils.IsPlayerModerator(__instance.Data.FriendCode) || !Options.ModeratorCanUseCommand.GetBool()) return; @@ -379,87 +444,8 @@ public static class RPCHandlerPatch } } - - bool col1 = text.StartsWith("/col ") || text.StartsWith("/cor "); - bool col2 = text.StartsWith("/color "); - bool col3 = text.StartsWith("/colour "); - - if ((col1 || col2 || col3) && !Utils.InGame) - { - string argCol = text.Substring(col1 ? 5 : col2 ? 7 : col3 ? 8 : 0).Trim(); - - if (Utils.TryGetColorId(argCol, out byte colId)) - { - if (Options.ColorCommandLevel.GetValue() == 0 && Utils.IsPlayerModerator(__instance.Data.FriendCode) || Options.ColorCommandLevel.GetValue() == 1) - { - if (colId > 17 && !Options.AllowFortegreen.GetBool()) return; - __instance.RpcSetColor(colId); - } - } - } - else - { - - if (!Utils.IsPlayerModerator(__instance.Data.FriendCode)) return; - // Banning works by name and color. Commands are separated incase someone has a color as their name - bool isKick = text.StartsWith("/kick "); - bool isBan = text.StartsWith("/ban "); - - bool isColorKick = text.StartsWith("/ckick "); - bool isColorBan = text.StartsWith("/cban "); - - bool banLog = isBan || isColorBan; - - if (!isKick && !isBan && !isColorKick && !isColorBan) return; - - if (Utils.IsPlayerModerator(__instance.Data.FriendCode)) - { - string arg = text.Substring(isKick ? 6 : isBan ? 5 : isColorKick ? 7 : isColorBan ? 6 : 0).Trim(); - - PlayerControl target = null; - - foreach (PlayerControl p in PlayerControl.AllPlayerControls) - { - if (p.Data == null || p == PlayerControl.LocalPlayer || Utils.IsPlayerModerator(p.Data.FriendCode)) continue; - - if ((isKick || isBan) && p.Data.PlayerName.Equals(arg, StringComparison.OrdinalIgnoreCase)) - { - target = p; - break; - } - - if ((isColorKick || isColorBan) && Utils.TryGetColorId(arg, out byte colorId)) - { - if (p.Data.DefaultOutfit.ColorId == colorId) - { - target = p; - break; - } - } - } - - if (target != null) - { - AmongUsClient.Instance.KickPlayer(target.Data.ClientId, isBan || isColorBan); - Logger.Info($" {__instance.Data.PlayerName} {(banLog ? "banned" : "kicked")} {target.Data.PlayerName}", "Kick&BanCommand"); - } - } - } break; } } } -} - -[HarmonyPatch(typeof(HudManager), nameof(HudManager.Update))] -public static class HudManager_Update -{ - public static void Postfix(HudManager __instance) - { - if (Main.GM.Value) - { - __instance.Chat.gameObject.SetActive(true); - __instance.MapButton.gameObject.SetActive(true); - } - } } \ No newline at end of file diff --git a/Patches/ClientOptionsPatch.cs b/Patches/ClientOptionsPatch.cs index 9c94dfc..fd0a648 100644 --- a/Patches/ClientOptionsPatch.cs +++ b/Patches/ClientOptionsPatch.cs @@ -76,4 +76,27 @@ namespace AmongUsRevamped ClientOptionItem.CustomBackground?.gameObject.SetActive(false); } } + + [HarmonyPatch(typeof(SplashManager), nameof(SplashManager.Update))] + internal class SplashLogoAnimatorPatch + { + public static void Prefix(SplashManager __instance) + { + __instance.sceneChanger.AllowFinishLoadingScene(); + __instance.startedSceneLoad = true; + } + } + + [HarmonyPatch(typeof(HudManager), nameof(HudManager.Update))] + public static class HudManager_Update + { + public static void Postfix(HudManager __instance) + { + if (Main.GM.Value) + { + __instance.Chat.gameObject.SetActive(true); + __instance.MapButton.gameObject.SetActive(true); + } + } + } } \ No newline at end of file diff --git a/Patches/DevicePatches.cs b/Patches/DevicePatches.cs index 897396b..6ae332e 100644 --- a/Patches/DevicePatches.cs +++ b/Patches/DevicePatches.cs @@ -58,6 +58,8 @@ internal static class DisableDevice foreach (PlayerControl pc in Main.AllPlayerControls) { + if (pc.Data.IsDead || Main.GM.Value && pc == PlayerControl.LocalPlayer) return; + try { var doComms = false; diff --git a/Patches/IntroPatch.cs b/Patches/IntroPatch.cs index 062a9fd..2e576ce 100644 --- a/Patches/IntroPatch.cs +++ b/Patches/IntroPatch.cs @@ -1,4 +1,5 @@ -using Hazel; +using AmongUs.GameOptions; +using Hazel; using InnerNet; using System; using UnityEngine; @@ -25,6 +26,12 @@ internal static class CoShowIntroPatch { "Mayor", Translator.Get("Mayor")} }); + if (Main.GM.Value) + { + PlayerControl.LocalPlayer.RpcSetRole(AmongUs.GameOptions.RoleTypes.CrewmateGhost, false); + PlayerControl.LocalPlayer.myTasks.Clear(); + } + if (!Utils.isHideNSeek) return; foreach (var p in PlayerControl.AllPlayerControls) @@ -35,4 +42,18 @@ internal static class CoShowIntroPatch } } } +} + +[HarmonyPatch(typeof(IntroCutscene), nameof(IntroCutscene.BeginCrewmate))] +class BeginCrewmatePatch +{ + public static void Postfix(IntroCutscene __instance) + { + if (!AmongUsClient.Instance.AmHost) return; + + if (Main.GM.Value) + { + __instance.TeamTitle.text = "Game Master"; + } + } } \ No newline at end of file diff --git a/Patches/NumberOptionsPatch.cs b/Patches/NumberOptionsPatch.cs index 6766931..2b79abf 100644 --- a/Patches/NumberOptionsPatch.cs +++ b/Patches/NumberOptionsPatch.cs @@ -17,11 +17,19 @@ public static class NumberOption_Increase if (Utils.isHideNSeek || Utils.IsLobby && !Utils.isHideNSeek && __instance.Title != StringNames.GameNumImpostors && __instance.Title != StringNames.GamePlayerSpeed) { - - if (__instance.Value + increment > __instance.ValidRange.max) + if (__instance.Value <= __instance.ValidRange.min) { return true; } + + if (__instance.Value + increment > __instance.ValidRange.max) + { + __instance.Value = __instance.ValidRange.max; + __instance.UpdateValue(); + __instance.OnValueChanged.Invoke(__instance); + return false; + } + else { __instance.Value += increment; @@ -47,10 +55,19 @@ public static class NumberOption_Decrease if (Utils.isHideNSeek || Utils.IsLobby && !Utils.isHideNSeek && __instance.Title != StringNames.GameNumImpostors && __instance.Title != StringNames.GamePlayerSpeed) { - if (__instance.Value - increment < __instance.ValidRange.min) + if (__instance.Value >= __instance.ValidRange.max) { return true; } + + if (__instance.Value - increment < __instance.ValidRange.min) + { + __instance.Value = __instance.ValidRange.min; + __instance.UpdateValue(); + __instance.OnValueChanged.Invoke(__instance); + return false; + } + else { __instance.Value -= increment; diff --git a/Patches/OnGameStartedPatch.cs b/Patches/OnGameStartedPatch.cs index 128da2a..4f48bea 100644 --- a/Patches/OnGameStartedPatch.cs +++ b/Patches/OnGameStartedPatch.cs @@ -16,20 +16,6 @@ internal class CoStartGamePatch NormalGameEndChecker.imps.Clear(); NormalGameEndChecker.LastWinReason = ""; - if (Main.GM.Value) - { - if (Options.Gamemode.GetValue() == 3) - { - PlayerControl.LocalPlayer.CoSetRole(AmongUs.GameOptions.RoleTypes.CrewmateGhost, false); - } - else - { - PlayerControl.LocalPlayer.RpcSetRole(AmongUs.GameOptions.RoleTypes.CrewmateGhost, false); - } - - PlayerControl.LocalPlayer.myTasks.Clear(); - } - if (Options.Gamemode.GetValue() == 3 && !Utils.isHideNSeek) { foreach (var p in PlayerControl.AllPlayerControls)