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/CrowdedMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>
<PropertyGroup>
<GamePlatform Condition="'$(GamePlatform)' == ''">Steam</GamePlatform>
<GameVersion>2024.9.4</GameVersion>
<GameVersion>2025.4.15</GameVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Reactor" Version="2.3.1" />
Expand Down
10 changes: 9 additions & 1 deletion src/CrowdedMod/CrowdedModPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using Reactor.Networking;
using Reactor.Networking.Attributes;
using Reactor.Utilities;
using System;
using System.Linq;
using UnityEngine.SceneManagement;

namespace CrowdedMod;

Expand All @@ -29,7 +31,13 @@ public override void Load()

Harmony.PatchAll();

RemoveVanillaServer();
SceneManager.add_sceneLoaded((Action<Scene, LoadSceneMode>)((scene, _) =>
{
if (scene.name == "MainMenu")
{
RemoveVanillaServer();
}
}));
}

public static void RemoveVanillaServer()
Expand Down
41 changes: 21 additions & 20 deletions src/CrowdedMod/Patches/GenericPatches.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using AmongUs.GameOptions;
using AmongUs.Data;
using CrowdedMod.Net;
using HarmonyLib;
using Hazel;
Expand Down Expand Up @@ -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<IGameOptions>(), maxExpectedPlayers);
}

[HarmonyPatch(typeof(NormalGameOptionsV09), nameof(NormalGameOptionsV09.AreInvalid))]
public static class InvalidNormalOptionsPatches
{
public static bool Prefix(NormalGameOptionsV09 __instance, [HarmonyArgument(0)] int maxExpectedPlayers)
=> IsOptionValid(__instance.Cast<IGameOptions>(), 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
{
Expand Down Expand Up @@ -235,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<IntGameSetting>();
if (intOption != null && option.Title == StringNames.GameNumImpostors)
{
intOption.ValidRange = new IntRange(1, CrowdedModPlugin.MaxImpostors);
return;
Expand All @@ -244,13 +254,4 @@ public static void Postfix(GameManager __instance)
}
}
}

[HarmonyPatch(typeof(MainMenuManager), nameof(MainMenuManager.Start))]
public static class RemoveVanillaServerPatch
{
public static void Postfix()
{
CrowdedModPlugin.RemoveVanillaServer();
}
}
}
Loading