diff --git a/src/CrowdedMod/CrowdedMod.csproj b/src/CrowdedMod/CrowdedMod.csproj index 2789976..ca93385 100644 --- a/src/CrowdedMod/CrowdedMod.csproj +++ b/src/CrowdedMod/CrowdedMod.csproj @@ -2,7 +2,7 @@ net6.0 - 2.10.0 + 2.11.0 CrowdedMods, andry08 latest @@ -11,15 +11,15 @@ Steam - 2024.9.4 + 2025.9.9 - - + + - + diff --git a/src/CrowdedMod/CrowdedModPlugin.cs b/src/CrowdedMod/CrowdedModPlugin.cs index 7a18fb2..1af56be 100644 --- a/src/CrowdedMod/CrowdedModPlugin.cs +++ b/src/CrowdedMod/CrowdedModPlugin.cs @@ -12,11 +12,10 @@ namespace CrowdedMod; [BepInAutoPlugin("xyz.crowdedmods.crowdedmod")] [BepInProcess("Among Us.exe")] [BepInDependency(ReactorPlugin.Id)] -[ReactorModFlags(ModFlags.RequireOnAllClients)] [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 = 255; // allegedly. should stick to 127 tho public const int MaxImpostors = MaxPlayers / 2; public static bool ForceDisableFreeColor { get; set; } = false; diff --git a/src/CrowdedMod/Patches/CreateGameOptionsPatches.cs b/src/CrowdedMod/Patches/CreateGameOptionsPatches.cs deleted file mode 100644 index a7bb22b..0000000 --- a/src/CrowdedMod/Patches/CreateGameOptionsPatches.cs +++ /dev/null @@ -1,188 +0,0 @@ -using System; -using AmongUs.GameOptions; -using HarmonyLib; -using Reactor.Utilities.Extensions; -using TMPro; -using UnityEngine; - -namespace CrowdedMod.Patches; - -internal static class CreateGameOptionsPatches -{ - private static bool HasManyImpostors(this IGameOptions options) => - options.GameMode is GameModes.Normal or GameModes.NormalFools; - - private static bool IsHost(this CreateOptionsPicker picker) => picker.mode == SettingsMode.Host; - - [HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.Awake))] - public static class CreateOptionsPicker_Awake - { - public static void Postfix(CreateOptionsPicker __instance) - { - if (!__instance.IsHost()) return; - - { - var firstButtonRenderer = __instance.MaxPlayerButtons[0]; - firstButtonRenderer.GetComponentInChildren().text = "-"; - firstButtonRenderer.enabled = false; - - var firstButtonButton = firstButtonRenderer.GetComponent(); - firstButtonButton.OnClick.RemoveAllListeners(); - firstButtonButton.OnClick.AddListener((Action)(() => - { - for (var i = 1; i < 11; i++) - { - var playerButton = __instance.MaxPlayerButtons[i]; - - var tmp = playerButton.GetComponentInChildren(); - var newValue = Mathf.Max(byte.Parse(tmp.text) - 10, byte.Parse(playerButton.name) - 2); - tmp.text = newValue.ToString(); - } - - __instance.UpdateMaxPlayersButtons(__instance.GetTargetOptions()); - })); - firstButtonRenderer.Destroy(); - - var lastButtonRenderer = __instance.MaxPlayerButtons[^1]; - lastButtonRenderer.GetComponentInChildren().text = "+"; - lastButtonRenderer.enabled = false; - - var lastButtonButton = lastButtonRenderer.GetComponent(); - lastButtonButton.OnClick.RemoveAllListeners(); - lastButtonButton.OnClick.AddListener((Action)(() => - { - for (var i = 1; i < 11; i++) - { - var playerButton = __instance.MaxPlayerButtons[i]; - - var tmp = playerButton.GetComponentInChildren(); - var newValue = Mathf.Min(byte.Parse(tmp.text) + 10, - CrowdedModPlugin.MaxPlayers - 14 + byte.Parse(playerButton.name)); - tmp.text = newValue.ToString(); - } - - __instance.UpdateMaxPlayersButtons(__instance.GetTargetOptions()); - })); - lastButtonRenderer.Destroy(); - - for (var i = 1; i < 11; i++) - { - var playerButton = __instance.MaxPlayerButtons[i].GetComponent(); - var text = playerButton.GetComponentInChildren(); - - playerButton.OnClick.RemoveAllListeners(); - playerButton.OnClick.AddListener((Action)(() => - { - var maxPlayers = byte.Parse(text.text); - var maxImp = Mathf.Min(__instance.GetTargetOptions().NumImpostors, maxPlayers / 2); - __instance.GetTargetOptions().SetInt(Int32OptionNames.NumImpostors, maxImp); - __instance.ImpostorButtons[1].TextMesh.text = maxImp.ToString(); - __instance.SetMaxPlayersButtons(maxPlayers); - })); - } - - foreach (var button in __instance.MaxPlayerButtons) - { - button.enabled = button.GetComponentInChildren().text == __instance.GetTargetOptions().MaxPlayers.ToString(); - } - } - - var secondButton = __instance.ImpostorButtons[1]; - secondButton.SpriteRenderer.enabled = false; - secondButton.transform.FindChild("ConsoleHighlight").gameObject.Destroy(); - secondButton.PassiveButton.OnClick.RemoveAllListeners(); - secondButton.BoxCollider.size = new Vector2(0f, 0f); - - var secondButtonText = secondButton.TextMesh; - secondButtonText.text = __instance.GetTargetOptions().NumImpostors.ToString(); - - var firstButton = __instance.ImpostorButtons[0]; - firstButton.SpriteRenderer.enabled = false; - firstButton.TextMesh.text = "-"; - - var firstPassiveButton = firstButton.PassiveButton; - firstPassiveButton.OnClick.RemoveAllListeners(); - firstPassiveButton.OnClick.AddListener((Action)(() => { - var newVal = Mathf.Clamp( - byte.Parse(secondButtonText.text) - 1, - 1, - __instance.GetTargetOptions().MaxPlayers / 2 - ); - __instance.SetImpostorButtons(newVal); - secondButtonText.text = newVal.ToString(); - })); - - var thirdButton = __instance.ImpostorButtons[2]; - thirdButton.SpriteRenderer.enabled = false; - thirdButton.TextMesh.text = "+"; - - var thirdPassiveButton = thirdButton.PassiveButton; - thirdPassiveButton.OnClick.RemoveAllListeners(); - thirdPassiveButton.OnClick.AddListener((Action)(() => { - var newVal = Mathf.Clamp( - byte.Parse(secondButtonText.text) + 1, - 1, - __instance.GetTargetOptions().MaxPlayers / 2 - ); - __instance.SetImpostorButtons(newVal); - secondButtonText.text = newVal.ToString(); - })); - } - } - - [HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.UpdateMaxPlayersButtons))] - public static class CreateOptionsPicker_UpdateMaxPlayersButtons - { - public static bool Prefix(CreateOptionsPicker __instance, [HarmonyArgument(0)] IGameOptions opts) - { - if (__instance.CrewArea) - { - __instance.CrewArea.SetCrewSize(opts.MaxPlayers, opts.NumImpostors); - } - - var selectedAsString = opts.MaxPlayers.ToString(); - for (var i = 1; i < __instance.MaxPlayerButtons.Count - 1; i++) - { - __instance.MaxPlayerButtons[i].enabled = __instance.MaxPlayerButtons[i].GetComponentInChildren().text == selectedAsString; - } - - return false; - } - } - - [HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.UpdateImpostorsButtons))] - public static class CreateOptionsPicker_UpdateImpostorsButtons - { - public static bool Prefix(CreateOptionsPicker __instance) - { - var hasMany = __instance.GetTargetOptions().HasManyImpostors(); - - foreach (var button in __instance.ImpostorButtons) - { - button.SetOptionEnabled(hasMany); - } - - __instance.ImpostorText.color = hasMany ? Color.white : Palette.DisabledGrey; - - return false; - } - } - - [HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.Refresh))] - public static class CreateOptionsPicker_Refresh - { - public static bool Prefix(CreateOptionsPicker __instance) - { - var options = __instance.GetTargetOptions(); - - __instance.UpdateImpostorsButtons(options.NumImpostors); - __instance.UpdateMaxPlayersButtons(options); - __instance.UpdateLanguageButton((uint)options.Keywords); - __instance.MapMenu.UpdateMapButtons(options.MapId); - var modeName = GameModesHelpers.ModeToName[GameOptionsManager.Instance.CurrentGameOptions.GameMode]; - __instance.GameModeText.text = TranslationController.Instance.GetString(modeName); - - return false; - } - } -} \ No newline at end of file diff --git a/src/CrowdedMod/Patches/GenericPatches.cs b/src/CrowdedMod/Patches/GenericPatches.cs index 4a8802e..4cc30a9 100644 --- a/src/CrowdedMod/Patches/GenericPatches.cs +++ b/src/CrowdedMod/Patches/GenericPatches.cs @@ -73,10 +73,10 @@ 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))] + [HarmonyPatch(typeof(LegacyGameOptions), nameof(LegacyGameOptions.AreInvalid))] public static class InvalidOptionsPatches { - public static bool Prefix(GameOptionsData __instance, [HarmonyArgument(0)] int maxExpectedPlayers) + public static bool Prefix(LegacyGameOptions __instance, [HarmonyArgument(0)] int maxExpectedPlayers) { return __instance.MaxPlayers > maxExpectedPlayers || __instance.NumImpostors < 1 || @@ -112,6 +112,15 @@ public static void Prefix(GameStartManager __instance) } } + [HarmonyPostfix] + [HarmonyPatch(typeof(CreateGameOptions), nameof(CreateGameOptions.Show))] + public static void CreateGameOptionsShowPostfix(CreateGameOptions __instance) { + var numberOption = __instance.gameObject.GetComponentInChildren(true); + if (numberOption != null) { + numberOption.ValidRange.max = CrowdedModPlugin.MaxPlayers; + } + } + public static void Postfix(GameStartManager __instance) { if (string.IsNullOrEmpty(fixDummyCounterColor) ||