Fix server menu, game list order by player count, and loading

This commit is contained in:
D1GQ committed 2025-03-29 03:33:03 -05:00
1 parent 00c7cb29c4
commit c02eaaefe3
5 files changed
+126 -3

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
namespace BetterAmongUs.Managers;
internal class CustomLoadingBarManager
{
internal static AmongUsLoadingBar? LoadingBar => DestroyableSingleton<LoadingBarManager>.Instance?.loadingBar;
internal static void ToggleLoadingBar(bool on)
{
DestroyableSingleton<LoadingBarManager>.Instance.loadingBar.gameObject.SetActive(on);
}
internal static void SetLoadingPercent(float percent, string loadText)
{
var loadingBar = DestroyableSingleton<LoadingBarManager>.Instance.loadingBar;
loadingBar.SetLoadingPercent(percent, StringNames.None);
loadingBar.loadingText.SetText(loadText);
}
}
+50 -1
View File
@@ -1,10 +1,12 @@
using BetterAmongUs.Helpers;
using BepInEx.Unity.IL2CPP.Utils;
using BetterAmongUs.Helpers;
using BetterAmongUs.Items;
using BetterAmongUs.Managers;
using BetterAmongUs.Modules;
using HarmonyLib;
using Hazel;
using InnerNet;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
@@ -126,7 +128,54 @@ internal class ClientPatch
}
}, 0.6f, shouldLog: false);
}
[HarmonyPatch(nameof(AmongUsClient.CoStartGame))]
[HarmonyPostfix]
internal static void CoStartGame_Postfix(AmongUsClient __instance)
{
__instance.StartCoroutine(CoLoading());
}
private static IEnumerator CoLoading()
{
CustomLoadingBarManager.ToggleLoadingBar(true);
try
{
while (Main.AllPlayerControls.Count > 0 && Main.AllPlayerControls.Any(pc => !pc.roleAssigned))
{
if (!GameState.IsInGame)
{
yield break;
}
int totalPlayers = Main.AllPlayerControls.Count;
if (totalPlayers == 0) yield break;
int playersWithRoles = Main.AllPlayerControls.Count(pc => pc.roleAssigned);
float progress = (float)playersWithRoles / totalPlayers;
int percent = Mathf.RoundToInt(progress * 100f);
string loadingText = (GameState.IsHost && playersWithRoles > 0)
? "Assigning Roles"
: "Loading";
CustomLoadingBarManager.SetLoadingPercent(progress, loadingText);
yield return null;
}
CustomLoadingBarManager.SetLoadingPercent(100f, "Complete");
yield return new WaitForSeconds(0.5f);
}
finally
{
CustomLoadingBarManager.ToggleLoadingBar(false);
}
}
}
[HarmonyPatch(typeof(InnerNetClient))]
internal class InnerNetClientPatch
{
+18 -1
View File
@@ -64,8 +64,25 @@ internal class FindAGameManagerPatch
[HarmonyPatch(nameof(FindAGameManager.HandleList))]
[HarmonyPostfix]
internal static void HandleList_Postfix(FindAGameManager __instance)
internal static void HandleList_Postfix(FindAGameManager __instance, HttpMatchmakerManager.FindGamesListFilteredResponse response)
{
GameListing[] games = response.Games.ToArray();
games = [.. games.OrderByDescending(game => game.PlayerCount).ThenBy(game => game.TrueHostName)];
int gameNum = 0;
int count = 0;
while (count < __instance.gameContainers.Length && count < games.Count())
{
if (games[count].Options != null)
{
__instance.gameContainers[gameNum].gameObject.SetActive(true);
__instance.gameContainers[gameNum].SetGameListing(games[count]);
__instance.gameContainers[gameNum].SetupGameInfo();
gameNum++;
}
count++;
}
foreach (var container in __instance.gameContainers)
{
Transform child = container.transform.Find("Container");
+21
View File
@@ -0,0 +1,21 @@
using HarmonyLib;
namespace BetterAmongUs.Patches;
[HarmonyPatch(typeof(LoadingBarManager))]
internal class LoadingBarManagerPatch
{
[HarmonyPatch(nameof(LoadingBarManager.SetLoadingPercent))]
[HarmonyPrefix]
private static bool SetLoadingPercent_Prefix()
{
return false;
}
[HarmonyPatch(nameof(LoadingBarManager.ToggleLoadingBar))]
[HarmonyPrefix]
private static bool ToggleLoadingBart_Prefix()
{
return false;
}
}
+19 -1
View File
@@ -1,12 +1,30 @@
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace BetterAmongUs.Patches;
[HarmonyPatch]
internal class ServerDropdownPatch
{
[HarmonyPatch(typeof(FindAGameManager))]
[HarmonyPatch(nameof(FindAGameManager.Start))]
[HarmonyPrefix]
internal static void Start_Prefix(FindAGameManager __instance)
{
var aspectPosition = __instance.serverDropdown.transform.parent.GetComponent<AspectPosition>();
if (aspectPosition != null)
{
aspectPosition.Alignment = AspectPosition.EdgeAlignments.Top;
aspectPosition.anchorPoint = Vector3.zero;
aspectPosition.DistanceFromEdge = new Vector3(-1.2f, 0.3f, 0f);
aspectPosition.AdjustPosition();
}
__instance.modeText.transform.localPosition -= new Vector3(0.4f, 0f, 0f);
}
[HarmonyPatch(typeof(ServerDropdown))]
[HarmonyPatch(nameof(ServerDropdown.FillServerOptions))]
[HarmonyPrefix]
@@ -16,7 +34,7 @@ internal class ServerDropdownPatch
int num = 0;
int column = 0;
const int maxPerColumn = 6;
int maxPerColumn = SceneManager.GetActiveScene().name == "FindAGame" ? 10 : 6;
const float columnWidth = 3.5f;
const float buttonSpacing = 0.5f;