Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CrowdedMod/Components/MeetingHudPagingBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void Update()
{
base.Update();

if (meetingHud.state is MeetingHud.VoteStates.Animating or MeetingHud.VoteStates.Proceeding ||
if (meetingHud.state is MeetingHud.MeetingStates.Animating or MeetingHud.MeetingStates.Proceeding ||
meetingHud.TimerText.text.Contains($" ({PageIndex + 1}/{MaxPageIndex + 1})"))
return;

Expand Down
10 changes: 5 additions & 5 deletions src/CrowdedMod/CrowdedMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>2.10.0</Version>
<Version>2.12.0</Version>
<Authors>CrowdedMods, andry08</Authors>

<LangVersion>latest</LangVersion>
Expand All @@ -11,15 +11,15 @@
</PropertyGroup>
<PropertyGroup>
<GamePlatform Condition="'$(GamePlatform)' == ''">Steam</GamePlatform>
<GameVersion>2024.9.4</GameVersion>
<GameVersion>2026.9.29</GameVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Reactor" Version="2.3.1" />
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.679" />
<PackageReference Include="Reactor" Version="2.4.0-ci.344" />
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.735" />
<PackageReference Include="AmongUs.GameLibs.$(GamePlatform)" Version="$(GameVersion)" PrivateAssets="all" />

<PackageReference Include="BepInEx.AutoPlugin" Version="1.1.0" PrivateAssets="all" />
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.0.1" PrivateAssets="all" />
<PackageReference Include="BepInEx.IL2CPP.MSBuild" Version="2.1.0-rc.1" PrivateAssets="all" />
</ItemGroup>

<Target Name="Copy" AfterTargets="Build" Condition="'$(AmongUs)' != ''">
Expand Down
3 changes: 1 addition & 2 deletions src/CrowdedMod/CrowdedModPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
253 changes: 101 additions & 152 deletions src/CrowdedMod/Patches/CreateGameOptionsPatches.cs
Original file line number Diff line number Diff line change
@@ -1,188 +1,137 @@
using System;
using AmongUs.GameOptions;
using HarmonyLib;
using Reactor.Utilities.Extensions;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Object = UnityEngine.Object;

/// Taken from AleLuduMod https://github.com/townofus-pl/AleLuduMod/blob/main/AleLuduMod/Patches/CreateGameOptionsPatches.cs
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
private static GameOptionButton _minButton = null!;
private static GameOptionButton _maxButton = null!;
private static GameOptionButton _doubleMinusButton = null!;
private static GameOptionButton _doublePlusButton = null!;

[HarmonyPatch(typeof(CreateGameOptions), nameof(CreateGameOptions.Start))]
public static class CreateGameOptions_Start
{
public static void Postfix(CreateOptionsPicker __instance)
public static void Postfix(CreateGameOptions __instance)
{
if (!__instance.IsHost()) return;

// move stuff to make space for -5 and +5 buttons
foreach (Il2CppSystem.Object obj in __instance.capacityOption.transform)
{
var firstButtonRenderer = __instance.MaxPlayerButtons[0];
firstButtonRenderer.GetComponentInChildren<TextMeshPro>().text = "-";
firstButtonRenderer.enabled = false;

var firstButtonButton = firstButtonRenderer.GetComponent<PassiveButton>();
firstButtonButton.OnClick.RemoveAllListeners();
firstButtonButton.OnClick.AddListener((Action)(() =>
{
for (var i = 1; i < 11; i++)
{
var playerButton = __instance.MaxPlayerButtons[i];

var tmp = playerButton.GetComponentInChildren<TextMeshPro>();
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<TextMeshPro>().text = "+";
lastButtonRenderer.enabled = false;

var lastButtonButton = lastButtonRenderer.GetComponent<PassiveButton>();
lastButtonButton.OnClick.RemoveAllListeners();
lastButtonButton.OnClick.AddListener((Action)(() =>
{
for (var i = 1; i < 11; i++)
{
var playerButton = __instance.MaxPlayerButtons[i];

var tmp = playerButton.GetComponentInChildren<TextMeshPro>();
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<PassiveButton>();
var text = playerButton.GetComponentInChildren<TextMeshPro>();

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<TextMeshPro>().text == __instance.GetTargetOptions().MaxPlayers.ToString();
}
var t = obj.Cast<Transform>();
if (!t || t.gameObject.name is "LabelBackground" or "Title Text") continue;
t.localPosition += new Vector3(1, 0, 0);
}

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 = "-";
// create -5 and +5 buttons
_doubleMinusButton = Object.Instantiate(__instance.capacityOption.MinusBtn, __instance.capacityOption.MinusBtn.transform.parent);
var dmText = _doubleMinusButton.GetComponentInChildren<TextMeshPro>();
dmText.text = "-5";
dmText.fontStyle = FontStyles.Normal;
_doubleMinusButton.transform.localPosition -= new Vector3(0.5f, 0, 0);
_doubleMinusButton.OnClick = new Button.ButtonClickedEvent();
_doubleMinusButton.OnClick.AddListener((UnityAction)(() =>
{
__instance.capacityOption.Increment = 5;
__instance.capacityOption.Decrease();
__instance.capacityOption.Increment = 1;
}));

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();
_doublePlusButton = Object.Instantiate(__instance.capacityOption.PlusBtn, __instance.capacityOption.PlusBtn.transform.parent);
var dpText = _doublePlusButton.GetComponentInChildren<TextMeshPro>();
dpText.text = "+5";
dpText.fontStyle = FontStyles.Normal;
_doublePlusButton.transform.localPosition += new Vector3(0.5f, 0, 0);
_doublePlusButton.OnClick = new Button.ButtonClickedEvent();
_doublePlusButton.OnClick.AddListener((UnityAction)(() =>
{
__instance.capacityOption.Increment = 5;
__instance.capacityOption.Increase();
__instance.capacityOption.Increment = 1;
}));

var thirdButton = __instance.ImpostorButtons[2];
thirdButton.SpriteRenderer.enabled = false;
thirdButton.TextMesh.text = "+";
// create min and max buttons
_minButton = Object.Instantiate(__instance.capacityOption.MinusBtn, __instance.capacityOption.MinusBtn.transform.parent);
var minText = _minButton.GetComponentInChildren<TextMeshPro>();
minText.text = "MIN";
minText.fontSize = minText.fontSizeMax = 2;
minText.fontStyle = FontStyles.Normal;
minText.alignment = TextAlignmentOptions.Center;
_minButton.SetInteractable(true);
_minButton.transform.localPosition -= new Vector3(1, 0, 0);
_minButton.OnClick = new Button.ButtonClickedEvent();
_minButton.OnClick.AddListener((UnityAction)(() =>
{
__instance.capacityOption.Increment = int.MaxValue;
__instance.capacityOption.Decrease();
__instance.capacityOption.Increment = 1;
}));

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();
// create max button
_maxButton = Object.Instantiate(__instance.capacityOption.PlusBtn, __instance.capacityOption.PlusBtn.transform.parent);
var maxText = _maxButton.GetComponentInChildren<TextMeshPro>();
maxText.text = "MAX";
maxText.fontSize = maxText.fontSizeMax = 2;
maxText.fontStyle = FontStyles.Normal;
maxText.alignment = TextAlignmentOptions.Center;
_maxButton.SetInteractable(true);
_maxButton.transform.localPosition += new Vector3(1, 0, 0);
_maxButton.OnClick = new Button.ButtonClickedEvent();
_maxButton.OnClick.AddListener((UnityAction)(() =>
{
__instance.capacityOption.Increment = int.MaxValue;
__instance.capacityOption.Increase();
__instance.capacityOption.Increment = 1;
}));

Debug.Log("Finished creating new buttons for player count picker.");
}
}

[HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.UpdateMaxPlayersButtons))]
public static class CreateOptionsPicker_UpdateMaxPlayersButtons
[HarmonyPatch(typeof(CreateGameOptions), nameof(CreateGameOptions.Show))]
public static class CreateGameOptions_Show
{
public static bool Prefix(CreateOptionsPicker __instance, [HarmonyArgument(0)] IGameOptions opts)
public static void Prefix(CreateGameOptions __instance)
{
if (__instance.CrewArea)
{
__instance.CrewArea.SetCrewSize(opts.MaxPlayers, opts.NumImpostors);
}
// set new valid range
var newRange = new IntRange(1, CrowdedModPlugin.MaxPlayers);
var newFloatRange = new FloatRange(1, CrowdedModPlugin.MaxPlayers);

var selectedAsString = opts.MaxPlayers.ToString();
for (var i = 1; i < __instance.MaxPlayerButtons.Count - 1; i++)
{
__instance.MaxPlayerButtons[i].enabled = __instance.MaxPlayerButtons[i].GetComponentInChildren<TextMeshPro>().text == selectedAsString;
}

return false;
__instance.capacitySetting.ValidRange = newRange;
__instance.capacityOption.ValidRange = newFloatRange;
}
}

[HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.UpdateImpostorsButtons))]
public static class CreateOptionsPicker_UpdateImpostorsButtons
[HarmonyPatch(typeof(CreateGameOptions), nameof(CreateGameOptions.ValueChanged))]
public static class CreateGameOptions_ValueChanged
{
public static bool Prefix(CreateOptionsPicker __instance)
public static void Postfix(OptionBehaviour option)
{
var hasMany = __instance.GetTargetOptions().HasManyImpostors();
var numOpt = option.Cast<NumberOption>();
if (!numOpt) return;

_minButton.SetInteractable(true);
_maxButton.SetInteractable(true);
_doubleMinusButton.SetInteractable(true);
_doublePlusButton.SetInteractable(true);

foreach (var button in __instance.ImpostorButtons)
if (Mathf.Approximately(numOpt.Value, numOpt.ValidRange.max))
{
button.SetOptionEnabled(hasMany);
_maxButton.SetInteractable(false);
_doublePlusButton.SetInteractable(false);
}
else if (Mathf.Approximately(numOpt.Value, numOpt.ValidRange.min))
{
_minButton.SetInteractable(false);
_doubleMinusButton.SetInteractable(false);
}

__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;
Debug.Log("Updated button states!");
}
}
}
30 changes: 30 additions & 0 deletions src/CrowdedMod/Patches/GameStartManagerPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using HarmonyLib;

namespace CrowdedMod.Patches;

// Taken from AleLuduMod https://github.com/townofus-pl/AleLuduMod/blob/main/AleLuduMod/Patches/GameStartManagerPatch.cs
internal static class GameStartManagerPatch
{
[HarmonyPatch(typeof(GameStartManager), nameof(GameStartManager.Update))]
public static class GameStartManagerUpdatePatch
{
public static void Postfix(GameStartManager __instance)
{
if (GameData.Instance == null || AmongUsClient.Instance == null || GameManager.Instance == null || GameManager.Instance.LogicOptions == null || __instance.PlayerCounter == null) return;

int playerCount = GameData.Instance.PlayerCount;
int minPlayers = __instance.MinPlayers;

string counterColor = playerCount switch
{
_ when playerCount < minPlayers => "<color=#FF0000FF>",
_ when playerCount == minPlayers => "<color=#FFFF00FF>",
_ => "<color=#00FF00FF>"
};

int maxPlayers = AmongUsClient.Instance.NetworkMode is NetworkModes.LocalGame ? 15 : GameManager.Instance.LogicOptions.MaxPlayers;

__instance.PlayerCounter.text = $"{counterColor}{playerCount}/{maxPlayers}";
}
}
}
Loading