From 671acac2a507972094f1350e115903290fbc464c Mon Sep 17 00:00:00 2001 From: yukieiji Date: Thu, 19 Jun 2025 23:53:38 +0900 Subject: [PATCH 1/7] fix: AU v20250415 --- src/CrowdedMod/CrowdedMod.csproj | 2 +- src/CrowdedMod/Patches/GenericPatches.cs | 29 ++++++++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/CrowdedMod/CrowdedMod.csproj b/src/CrowdedMod/CrowdedMod.csproj index 2789976..6db50e0 100644 --- a/src/CrowdedMod/CrowdedMod.csproj +++ b/src/CrowdedMod/CrowdedMod.csproj @@ -11,7 +11,7 @@ Steam - 2024.9.4 + 2025.4.15 diff --git a/src/CrowdedMod/Patches/GenericPatches.cs b/src/CrowdedMod/Patches/GenericPatches.cs index 4a8802e..bdf7024 100644 --- a/src/CrowdedMod/Patches/GenericPatches.cs +++ b/src/CrowdedMod/Patches/GenericPatches.cs @@ -1,5 +1,6 @@ using System.Linq; using AmongUs.GameOptions; +using AmongUs.Data; using CrowdedMod.Net; using HarmonyLib; using Hazel; @@ -73,19 +74,27 @@ public static bool Prefix(PlayerTab __instance) // I did not find a use of this method, but still patching for future updates // maxExpectedPlayers is unknown, looks like server code tbh - [HarmonyPatch(typeof(GameOptionsData), nameof(GameOptionsData.AreInvalid))] - public static class InvalidOptionsPatches + [HarmonyPatch(typeof(HideNSeekGameOptionsV09), nameof(HideNSeekGameOptionsV09.AreInvalid))] + public static class InvalidHnSOptionsPatches { - public static bool Prefix(GameOptionsData __instance, [HarmonyArgument(0)] int maxExpectedPlayers) - { - return __instance.MaxPlayers > maxExpectedPlayers || - __instance.NumImpostors < 1 || - __instance.NumImpostors + 1 > maxExpectedPlayers / 2 || - __instance.KillDistance is < 0 or > 2 || - __instance.PlayerSpeedMod is <= 0f or > 3f; - } + public static bool Prefix(HideNSeekGameOptionsV09 __instance, [HarmonyArgument(0)] int maxExpectedPlayers) + => IsOptionValid(__instance.Cast(), maxExpectedPlayers); + } + + [HarmonyPatch(typeof(NormalGameOptionsV09), nameof(NormalGameOptionsV09.AreInvalid))] + public static class InvalidNormalOptionsPatches + { + public static bool Prefix(NormalGameOptionsV09 __instance, [HarmonyArgument(0)] int maxExpectedPlayers) + => IsOptionValid(__instance.Cast(), maxExpectedPlayers); } + private static bool IsOptionValid(IGameOptions option, int maxExpectedPlayers) + => option.MaxPlayers > maxExpectedPlayers || + option.NumImpostors < 1 || + option.NumImpostors + 1 > maxExpectedPlayers / 2 || + option.GetInt(Int32OptionNames.KillDistance) is < 0 or > 2 || + option.GetFloat(FloatOptionNames.PlayerSpeedMod) is <= 0f or > 3f; + [HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.Update))] public static class GameStartManagerUpdatePatch { From 5a239b389767450df150b60d775dd6309c5fb856 Mon Sep 17 00:00:00 2001 From: yukieiji Date: Fri, 20 Jun 2025 00:09:55 +0900 Subject: [PATCH 2/7] fix: patch not work --- src/CrowdedMod/CrowdedModPlugin.cs | 10 +++++++++- src/CrowdedMod/Patches/GenericPatches.cs | 9 --------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/CrowdedMod/CrowdedModPlugin.cs b/src/CrowdedMod/CrowdedModPlugin.cs index 7a18fb2..215a531 100644 --- a/src/CrowdedMod/CrowdedModPlugin.cs +++ b/src/CrowdedMod/CrowdedModPlugin.cs @@ -5,7 +5,9 @@ using Reactor.Networking; using Reactor.Networking.Attributes; using Reactor.Utilities; +using System; using System.Linq; +using UnityEngine.SceneManagement; namespace CrowdedMod; @@ -29,7 +31,13 @@ public override void Load() Harmony.PatchAll(); - RemoveVanillaServer(); + SceneManager.add_sceneLoaded((Action)((scene, _) => + { + if (scene.name == "MainMenu") + { + RemoveVanillaServer(); + } + })); } public static void RemoveVanillaServer() diff --git a/src/CrowdedMod/Patches/GenericPatches.cs b/src/CrowdedMod/Patches/GenericPatches.cs index bdf7024..6ab82d9 100644 --- a/src/CrowdedMod/Patches/GenericPatches.cs +++ b/src/CrowdedMod/Patches/GenericPatches.cs @@ -253,13 +253,4 @@ public static void Postfix(GameManager __instance) } } } - - [HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start))] - public static class RemoveVanillaServerPatch - { - public static void Postfix() - { - CrowdedModPlugin.RemoveVanillaServer(); - } - } } \ No newline at end of file From ac0518c4e8a12da6b7ab127ab63c514f39b22153 Mon Sep 17 00:00:00 2001 From: yukieiji Date: Fri, 20 Jun 2025 00:10:59 +0900 Subject: [PATCH 3/7] fix:unity null error --- src/CrowdedMod/Patches/GenericPatches.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CrowdedMod/Patches/GenericPatches.cs b/src/CrowdedMod/Patches/GenericPatches.cs index 6ab82d9..f0bcef1 100644 --- a/src/CrowdedMod/Patches/GenericPatches.cs +++ b/src/CrowdedMod/Patches/GenericPatches.cs @@ -244,7 +244,8 @@ public static void Postfix(GameManager __instance) { foreach (var option in category.AllGameSettings) { - if (option is IntGameSetting intOption && option.Title == StringNames.GameNumImpostors) + var intOption = option.TryCast(); + if (intOption != null && option.Title == StringNames.GameNumImpostors) { intOption.ValidRange = new IntRange(1, CrowdedModPlugin.MaxImpostors); return; From df0fcde44f21491d6950b4c836e5fb5196237985 Mon Sep 17 00:00:00 2001 From: yukieiji <40425798+yukieiji@users.noreply.github.com> Date: Mon, 15 Sep 2025 20:27:52 +0900 Subject: [PATCH 4/7] fix: pathes --- src/CrowdedMod/Patches/GenericPatches.cs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/CrowdedMod/Patches/GenericPatches.cs b/src/CrowdedMod/Patches/GenericPatches.cs index f0bcef1..b3fd40b 100644 --- a/src/CrowdedMod/Patches/GenericPatches.cs +++ b/src/CrowdedMod/Patches/GenericPatches.cs @@ -74,17 +74,17 @@ public static bool Prefix(PlayerTab __instance) // I did not find a use of this method, but still patching for future updates // maxExpectedPlayers is unknown, looks like server code tbh - [HarmonyPatch(typeof(HideNSeekGameOptionsV09), nameof(HideNSeekGameOptionsV09.AreInvalid))] + [HarmonyPatch(typeof(HideNSeekGameOptionsV10), nameof(HideNSeekGameOptionsV10.AreInvalid))] public static class InvalidHnSOptionsPatches { - public static bool Prefix(HideNSeekGameOptionsV09 __instance, [HarmonyArgument(0)] int maxExpectedPlayers) + public static bool Prefix(HideNSeekGameOptionsV10 __instance, [HarmonyArgument(0)] int maxExpectedPlayers) => IsOptionValid(__instance.Cast(), maxExpectedPlayers); } - [HarmonyPatch(typeof(NormalGameOptionsV09), nameof(NormalGameOptionsV09.AreInvalid))] + [HarmonyPatch(typeof(NormalGameOptionsV10), nameof(NormalGameOptionsV10.AreInvalid))] public static class InvalidNormalOptionsPatches { - public static bool Prefix(NormalGameOptionsV09 __instance, [HarmonyArgument(0)] int maxExpectedPlayers) + public static bool Prefix(NormalGameOptionsV10 __instance, [HarmonyArgument(0)] int maxExpectedPlayers) => IsOptionValid(__instance.Cast(), maxExpectedPlayers); } @@ -156,7 +156,6 @@ public static bool Prefix(InnerNetServer __instance, [HarmonyArgument(0)] InnerN { client.LimboState = LimboStates.NotLimbo; } - var writer = MessageWriter.Get(SendOption.Reliable); try { @@ -179,6 +178,19 @@ public static bool Prefix(InnerNetServer __instance, [HarmonyArgument(0)] InnerN } } + [HarmonyPatch(typeof(CreateGameOptions), nameof(CreateGameOptions.Show))] + public static class CreateGameOptionsShowPatch + { + public static void Postfix(CreateGameOptions __instance) + { + var numberOption = __instance.gameObject.GetComponentInChildren(true); + if (numberOption != null) + { + numberOption.ValidRange.max = CrowdedModPlugin.MaxPlayers; + } + } + } + private static void TryAdjustOptionsRecommendations(GameOptionsManager manager) { const int MaxPlayers = CrowdedModPlugin.MaxPlayers; From 060aa562efc3c037d66b9c524a0213c415a6260a Mon Sep 17 00:00:00 2001 From: yukieiji <40425798+yukieiji@users.noreply.github.com> Date: Mon, 15 Sep 2025 20:31:02 +0900 Subject: [PATCH 5/7] update : versions --- src/CrowdedMod/CrowdedMod.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CrowdedMod/CrowdedMod.csproj b/src/CrowdedMod/CrowdedMod.csproj index 6db50e0..881faf4 100644 --- a/src/CrowdedMod/CrowdedMod.csproj +++ b/src/CrowdedMod/CrowdedMod.csproj @@ -11,7 +11,7 @@ Steam - 2025.4.15 + 2025.9.9 From 0607c9fc81f7403207a4cebd8ed3e1849af0124c Mon Sep 17 00:00:00 2001 From: yukieiji <40425798+yukieiji@users.noreply.github.com> Date: Mon, 15 Sep 2025 20:31:15 +0900 Subject: [PATCH 6/7] change : max player --- src/CrowdedMod/CrowdedModPlugin.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CrowdedMod/CrowdedModPlugin.cs b/src/CrowdedMod/CrowdedModPlugin.cs index 215a531..b7b937a 100644 --- a/src/CrowdedMod/CrowdedModPlugin.cs +++ b/src/CrowdedMod/CrowdedModPlugin.cs @@ -18,7 +18,7 @@ namespace CrowdedMod; [BepInDependency("gg.reactor.debugger", BepInDependency.DependencyFlags.SoftDependency)] public partial class CrowdedModPlugin : BasePlugin { - public const int MaxPlayers = 254; // allegedly. should stick to 127 tho + public const int MaxPlayers = 250; // allegedly. should stick to 127 tho public const int MaxImpostors = MaxPlayers / 2; public static bool ForceDisableFreeColor { get; set; } = false; From 572d41657fb8ae12456d5fa495e8da1b9cec69ba Mon Sep 17 00:00:00 2001 From: yukieiji <40425798+yukieiji@users.noreply.github.com> Date: Mon, 15 Sep 2025 23:11:45 +0900 Subject: [PATCH 7/7] change : option value mod patch priority to last --- src/CrowdedMod/Patches/GenericPatches.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CrowdedMod/Patches/GenericPatches.cs b/src/CrowdedMod/Patches/GenericPatches.cs index b3fd40b..ec90602 100644 --- a/src/CrowdedMod/Patches/GenericPatches.cs +++ b/src/CrowdedMod/Patches/GenericPatches.cs @@ -181,6 +181,7 @@ public static bool Prefix(InnerNetServer __instance, [HarmonyArgument(0)] InnerN [HarmonyPatch(typeof(CreateGameOptions), nameof(CreateGameOptions.Show))] public static class CreateGameOptionsShowPatch { + [HarmonyPostfix, HarmonyPriority(Priority.Last)] public static void Postfix(CreateGameOptions __instance) { var numberOption = __instance.gameObject.GetComponentInChildren(true); @@ -250,6 +251,7 @@ public static void Postfix(GameOptionsManager __instance) [HarmonyPatch(typeof(GameManager), nameof(GameManager.Awake))] public static class GameManager_Awake { + [HarmonyPostfix, HarmonyPriority(Priority.Last)] public static void Postfix(GameManager __instance) { foreach (var category in __instance.GameSettingsList.AllCategories)