Skip to content
Open
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
33 changes: 32 additions & 1 deletion Reactor/Patches/Miscellaneous/CustomServersPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace Reactor.Patches.Miscellaneous;
[HarmonyPatch]
internal static class CustomServersPatch
{
private static StringNames? _lastFindGameRegion;
private static string? _lastFindGameIp;

private static bool IsCurrentServerOfficial()
{
const string Domain = "among.us";
Expand All @@ -16,17 +19,45 @@ private static bool IsCurrentServerOfficial()
regionInfo.Servers.All(serverInfo => serverInfo.Ip.EndsWith(Domain, StringComparison.Ordinal));
}

private static bool IsCurrentServerOfficialByStringNames(StringNames name)
{
return name is StringNames.ServerNA or StringNames.ServerEU or StringNames.ServerAS;
}

private static bool IsCurrentServerOfficialByFindGameInfo()
{
return _lastFindGameRegion is { } region && IsCurrentServerOfficialByStringNames(region)
&& AmongUsClient.Instance.networkAddress == _lastFindGameIp;
}

[HarmonyPatch(typeof(EnterCodeManager), nameof(EnterCodeManager.FindGameResult))]
[HarmonyPostfix]
public static void CacheRegionAndIpOnFindGame(
EnterCodeManager __instance,
[HarmonyArgument(0)] HttpMatchmakerManager.FindGameByCodeResponse response)
{
if (response == null)
{
return;
}

_lastFindGameRegion = response.Region;
_lastFindGameIp = response.Game?.IPString;
}

[HarmonyPatch(typeof(AuthManager._CoConnect_d__4), nameof(AuthManager._CoConnect_d__4.MoveNext))]
[HarmonyPatch(typeof(AuthManager._CoWaitForNonce_d__6), nameof(AuthManager._CoWaitForNonce_d__6.MoveNext))]
[HarmonyPrefix]
public static bool DisableAuthServer(ref bool __result)
{
if (IsCurrentServerOfficial())
if (IsCurrentServerOfficial() || IsCurrentServerOfficialByFindGameInfo())
{
// Info("Exchanging nonce since target server is official.");
return true;
}

__result = false;
// Info("Skipped nonce since target server is custom");
return false;
}

Expand Down