Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

100 player lobby (Ported from crowded) #831

Draft
wants to merge 7 commits into
base: 100PlayerLobbySupport
Choose a base branch
from
Draft
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
15 changes: 1 addition & 14 deletions Modules/OptionHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,7 @@ public static void WaitOptionsLoad_Postfix()
Main.Preset4.Value, Main.Preset5.Value
];

// Custom Game Mode
public static OptionItem GameMode;
public static CustomGameMode CurrentGameMode
=> GameMode.GetInt() switch
{
1 => CustomGameMode.FFA,
2 => CustomGameMode.HidenSeekTOHE, // HidenSeekTOHE must be after other game modes
_ => CustomGameMode.Standard
};
public static CustomGameMode CurrentGameMode = CustomGameMode.Standard;

public static readonly string[] gameModes =
[
Expand Down Expand Up @@ -606,11 +598,6 @@ public static void Load()
.SetColor(new Color32(255, 235, 4, byte.MaxValue))
.SetHeader(true);

// Game Mode
GameMode = StringOptionItem.Create(60000, "GameMode", gameModes, 0, TabGroup.GameSettings, false)
.SetHeader(true);


#region Roles/Add-ons Settings
CustomRoleCounts = [];
CustomGhostRoleCounts = [];
Expand Down
4 changes: 2 additions & 2 deletions Modules/OptionShower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static string GetText()
GameOptionsManager.Instance.CurrentGameOptions.ToHudString(GameData.Instance ? GameData.Instance.PlayerCount : 10) + "\n\n"
];

// Mod Settings
sb.Append($"{Options.GameMode.GetName()}: {Options.GameMode.GetString()}\n\n");
// Mod Settings (todo)
//sb.Append($"{Options.CurrentGameMode.ToString()}: {Options.GameMode.GetString()}\n\n");
if (Options.HideGameSettings.GetBool() && !AmongUsClient.Instance.AmHost)
{
sb.Append($"<color=#ff0000>{GetString("Message.HideGameSettings")}</color>");
Expand Down
156 changes: 156 additions & 0 deletions Patches/CreateGameOptionsPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
using System;
using AmongUs.GameOptions;
using TMPro;
using UnityEngine;

namespace TOHE.Patches;
// The following code comes from Crowded https://github.com/CrowdedMods/CrowdedMod/blob/master/src/CrowdedMod/Patches/CreateGameOptionsPatches.cs
internal static class CreateGameOptionsPatches
{
[HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.Awake))]
public static class CreateOptionsPicker_Awake
{
public static void Postfix(CreateOptionsPicker __instance)
{
if (__instance.mode != SettingsMode.Host) return;

{
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,
Main.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 secondButton = __instance.ImpostorButtons[1];
secondButton.SpriteRenderer.enabled = false;
//secondButton.transform.FindChild("ConsoleHighlight").gameObject.Destroy();
//secondButton.PassiveButton.Destroy();
//secondButton.BoxCollider.Destroy();

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<TextMeshPro>().text == selectedAsString;
}

return false;
}
}

[HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.UpdateImpostorsButtons))]
public static class CreateOptionsPicker_UpdateImpostorsButtons
{
public static bool Prefix()
{
return false;
}
}
}
25 changes: 6 additions & 19 deletions Patches/GameOptionsMenuPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ public static void Postfix(GameSettingMenu __instance)
__instance.Tabs.SetActive(true);
}
}
[HarmonyPatch(typeof(GameSettingMenu), nameof(GameSettingMenu.Close))]
class GameSettingMenuClosePatch
{
public static void Postfix()
{
// if custom game mode is HideNSeekTOHE in normal game, set standart
if (GameStates.IsNormalGame && Options.CurrentGameMode == CustomGameMode.HidenSeekTOHE)
{
// Select standart custom game mode
Options.GameMode.SetValue(0);
}
}
}
[HarmonyPatch(typeof(GameSettingMenu), nameof(GameSettingMenu.InitializeOptions))]
public static class GameSettingMenuInitializeOptionsPatch
{
Expand Down Expand Up @@ -72,7 +59,7 @@ public static void Postfix(GameOptionsMenu __instance)
if (Options.CurrentGameMode == CustomGameMode.HidenSeekTOHE)
{
// Select standart custom game mode for normal game
Options.GameMode.SetValue(0);
Options.CurrentGameMode = CustomGameMode.Standard;
}

template = Object.FindObjectOfType<StringOption>();
Expand Down Expand Up @@ -113,7 +100,7 @@ public static void Postfix(GameOptionsMenu __instance)
else if (GameStates.IsHideNSeek)
{
// Select custom game mode for Hide & Seek
Options.GameMode.SetValue(2);
Options.CurrentGameMode = CustomGameMode.HidenSeekTOHE;

gameSettingMenu = Object.FindObjectOfType<GameSettingMenu>();
if (gameSettingMenu == null) return;
Expand Down Expand Up @@ -521,12 +508,12 @@ public static bool Prefix(StringOption __instance)
if (GameStates.IsHideNSeek)
{
// Set Hide & Seek game mode
Options.GameMode.SetValue(2);
Options.CurrentGameMode = CustomGameMode.HidenSeekTOHE;
}
else if (Options.CurrentGameMode == CustomGameMode.HidenSeekTOHE)
{
// Set standart game mode
Options.GameMode.SetValue(0);
Options.CurrentGameMode = CustomGameMode.Standard;
}
}
return false;
Expand Down Expand Up @@ -564,12 +551,12 @@ public static bool Prefix(StringOption __instance)
if (GameStates.IsHideNSeek)
{
// Set Hide & Seek game mode
Options.GameMode.SetValue(2);
Options.CurrentGameMode = CustomGameMode.HidenSeekTOHE;
}
else if (Options.CurrentGameMode == CustomGameMode.HidenSeekTOHE)
{
// Set standart game mode
Options.GameMode.SetValue(0);
Options.CurrentGameMode = CustomGameMode.Standard;
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using UnityEngine;
using AmongUs.GameOptions;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using UnityEngine;

namespace TOHE.Patches;

Expand Down Expand Up @@ -54,7 +56,7 @@ public static void Postfix(CreateOptionsPicker __instance)
if (__instance.mode == SettingsMode.Host)
{
mapPickerMenu.transform.localPosition = new Vector3(mapPickerMenu.transform.localPosition.x, 0.85f, mapPickerMenu.transform.localPosition.z);

mapPickerTransform.localScale = new Vector3(0.86f, 0.85f, 1f);
mapPickerTransform.transform.localPosition = new Vector3(mapPickerTransform.transform.localPosition.x + 0.05f, mapPickerTransform.transform.localPosition.y + 0.03f, mapPickerTransform.transform.localPosition.z);
}
Expand All @@ -79,4 +81,68 @@ private static void SwapIconOrButtomsPositions(Component one, Component two)
Vector3 vector3 = position2;
transform2.position = vector3;
}
}

//Thanks: https://github.com/TheOtherRolesAU/TheOtherRoles/blob/8c55511599d73ba2c166491f7d6d4351d04f7ce8/TheOtherRoles/Patches/CreateOptionsPickerPatch.cs#L10
[HarmonyPatch(typeof(GameModeMenu))]
class GameModeMenuPatch
{
[HarmonyPatch(typeof(GameModeMenu), nameof(GameModeMenu.OnEnable))]
public static bool Prefix(GameModeMenu __instance)
{
uint gameMode = (uint)__instance.Parent.GetTargetOptions().GameMode;
float num = (Mathf.CeilToInt(3f / 10f) / 2f - 0.5f) * -2.5f;
__instance.controllerSelectable.Clear();
int num2 = 0;
__instance.ButtonPool.poolSize = 3;
for (int i = 0; i <= 3; i++)
{
GameModes entry = (GameModes)i;
if (entry != GameModes.None)
{
ChatLanguageButton chatLanguageButton = __instance.ButtonPool.Get<ChatLanguageButton>();
chatLanguageButton.transform.localPosition = new Vector3(num + (float)(num2 / 10) * 2.5f, 2f - (float)(num2 % 10) * 0.5f, 0f);
if (i <= 2)
chatLanguageButton.Text.text = DestroyableSingleton<TranslationController>.Instance.GetString(GameModesHelpers.ModeToName[entry], new Il2CppReferenceArray<Il2CppSystem.Object>(0));
else
{
chatLanguageButton.Text.text = i == 3 ? "FFA" : "Unknown";
}
chatLanguageButton.Button.OnClick.RemoveAllListeners();
chatLanguageButton.Button.OnClick.AddListener((System.Action)delegate {
__instance.ChooseOption(entry);
});

bool isCurrentMode = i <= 2 && Options.CurrentGameMode == CustomGameMode.Standard ? (long)entry == (long)((ulong)gameMode) : (i == 3 && Options.CurrentGameMode == CustomGameMode.FFA || i == 4 && Options.CurrentGameMode == CustomGameMode.HidenSeekTOHE);
chatLanguageButton.SetSelected(isCurrentMode);
__instance.controllerSelectable.Add(chatLanguageButton.Button);
if (isCurrentMode)
{
__instance.defaultButtonSelected = chatLanguageButton.Button;
}
num2++;
}
}
ControllerManager.Instance.OpenOverlayMenu(__instance.name, __instance.BackButton, __instance.defaultButtonSelected, __instance.controllerSelectable, false);
return false;
}

[HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.SetGameMode))]
public static bool Prefix(CreateOptionsPicker __instance, ref GameModes mode)
{
if (mode <= GameModes.HideNSeek)
{
Options.CurrentGameMode = CustomGameMode.Standard;
return true;
}

__instance.SetGameMode(GameModes.Normal);
int gm = (int)mode - 1;
if (gm == (int)CustomGameMode.FFA)
{
__instance.GameModeText.text = "FFA";
Options.CurrentGameMode = CustomGameMode.FFA;
}
return false;
}
}
4 changes: 2 additions & 2 deletions Patches/PlayerJoinAndLeftPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void Postfix(AmongUsClient __instance)
if (Options.CurrentGameMode == CustomGameMode.HidenSeekTOHE)
{
// Select standart
Options.GameMode.SetValue(0);
Options.CurrentGameMode = CustomGameMode.Standard;
}
break;

Expand All @@ -79,7 +79,7 @@ public static void Postfix(AmongUsClient __instance)
if (Options.CurrentGameMode is CustomGameMode.Standard or CustomGameMode.FFA)
{
// Select HideNSeekTOHE
Options.GameMode.SetValue(2);
Options.CurrentGameMode = CustomGameMode.HidenSeekTOHE;
}
break;

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
### :star: [Mini.RegionInstall](https://github.com/miniduikboot/Mini.RegionInstall)
>
> - Using Mini.RegionInstall to add modded server regions
### :star: [CrowdedMod](https://github.com/CrowdedMods/CrowdedMod)
>
> - Provided feature: 100 players lobby

---

Expand Down
5 changes: 4 additions & 1 deletion main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class Main : BasePlugin
public static bool ExceptionMessageIsShown = false;
public static bool AlreadyShowMsgBox = false;
public static string credentialsText;
public const int MaxPlayers = 127;
public const int MaxImpostors = 127 / 2;
public Coroutines coroutines;
public static NormalGameOptionsV07 NormalOptions => GameOptionsManager.Instance.currentNormalGameOptions;
public static HideNSeekGameOptionsV07 HideNSeekOptions => GameOptionsManager.Instance.currentHideNSeekGameOptions;
Expand Down Expand Up @@ -414,7 +416,8 @@ public static void ExportCustomRoleColors()
public override void Load()
{
Instance = this;

NormalGameOptionsV07.RecommendedImpostors = NormalGameOptionsV07.MaxImpostors = Enumerable.Repeat(127, 127).ToArray();
NormalGameOptionsV07.MinPlayers = Enumerable.Repeat(4, 127).ToArray();
//Client Options
HideName = Config.Bind("Client Options", "Hide Game Code Name", "TOHE");
HideColor = Config.Bind("Client Options", "Hide Game Code Color", $"{ModColor}");
Expand Down