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
24 changes: 23 additions & 1 deletion Reactor/Patches/Miscellaneous/CustomServersPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ namespace Reactor.Patches.Miscellaneous;

internal static class CustomServersPatch
{
// A code lookup can point to an official game while a custom region is selected.
// Keep only the target IP from an official response so later lookups replace stale state.
private static string? _officialFindGameIp;

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

private static bool IsOfficialFindGameTarget()
{
return _officialFindGameIp is { Length: > 0 } targetIp &&
string.Equals(AmongUsClient.Instance.networkAddress, targetIp, StringComparison.Ordinal);
}

[HarmonyPatch]
public static class DisableAuthServerPatch
{
Expand All @@ -30,7 +40,7 @@ public static IEnumerable<MethodBase> TargetMethods() =>

public static bool Prefix(ref bool __result)
{
if (IsCurrentServerOfficial())
if (IsCurrentServerOfficial() || IsOfficialFindGameTarget())
{
return true;
}
Expand All @@ -40,6 +50,18 @@ public static bool Prefix(ref bool __result)
}
}

[HarmonyPatch(typeof(EnterCodeManager), nameof(EnterCodeManager.FindGameResult))]
public static class CacheFindGameTargetPatch
{
[HarmonyPostfix]
public static void Postfix([HarmonyArgument(0)] HttpMatchmakerManager.FindGameByCodeResponse response)
{
_officialFindGameIp = response != null && IsCurrentServerOfficial()
? response.Game?.IPString
: null;
}
}

[HarmonyPatch]
public static class EnableUdpPatch
{
Expand Down