Skip to content

Commit b53ece5

Browse files
automatic lobby join
1 parent f30c141 commit b53ece5

1 file changed

Lines changed: 60 additions & 1 deletion

File tree

AuthFix/AuthPlugin.cs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using AmongUs.Data;
22
using BepInEx;
33
using BepInEx.Unity.IL2CPP;
4+
using BepInEx.Unity.IL2CPP.Utils.Collections;
45
using Epic.OnlineServices;
56
using Epic.OnlineServices.Connect;
67
using HarmonyLib;
@@ -32,6 +33,8 @@ public partial class AuthPlugin : BasePlugin
3233

3334
public override void Load()
3435
{
36+
var coroutines = AddComponent<Coroutines>();
37+
3538
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), Id);
3639
ServerManager.DefaultRegions = new Il2CppReferenceArray<IRegionInfo>([]);
3740

@@ -58,10 +61,64 @@ public override void Load()
5861
adsButton.GetComponent<PassiveButton>().enabled = false;
5962
adsButton.SetActive(false);
6063
}
64+
65+
coroutines.StartCoroutine(WaitForLogin().WrapToIl2Cpp());
6166
}
6267
}));
6368
}
6469

70+
public System.Collections.IEnumerator WaitForLogin()
71+
{
72+
if (string.IsNullOrEmpty(get_lobby()))
73+
{
74+
yield break;
75+
}
76+
77+
while (EOSManager.Instance == null)
78+
{
79+
yield return null;
80+
}
81+
82+
var eos = EOSManager.Instance;
83+
84+
while (string.IsNullOrEmpty(eos.FriendCode))
85+
{
86+
yield return null;
87+
}
88+
while (!StoreManager.Instance.FinishedInitializationFlow)
89+
{
90+
yield return null;
91+
}
92+
93+
var parts = get_lobby().Split(["\r\n", "\n"], StringSplitOptions.None);
94+
95+
if (parts.Length < 2)
96+
{
97+
yield break;
98+
}
99+
100+
string region = parts[0];
101+
string code = parts[1];
102+
103+
var regionCandidates = new[]
104+
{
105+
region,
106+
$"https://{region}",
107+
$"http://{region}"
108+
};
109+
110+
var selectedRegion = ServerManager.Instance.AvailableRegions.FirstOrDefault(r =>
111+
r.Servers.Any(s => regionCandidates.Contains(s.Ip, StringComparer.OrdinalIgnoreCase)) ||
112+
regionCandidates.Contains(r.PingServer, StringComparer.OrdinalIgnoreCase)
113+
);
114+
115+
if (selectedRegion != null)
116+
{
117+
ServerManager.Instance.SetRegion(selectedRegion);
118+
AmongUsClient.Instance.StartCoroutine(AmongUsClient.Instance.CoFindGameInfoFromCodeAndJoin(GameCode.GameNameToInt(code)));
119+
}
120+
}
121+
65122
public static GameObject FindInactiveByName(string name)
66123
{
67124
Scene activeScene = SceneManager.GetActiveScene();
@@ -217,4 +274,6 @@ public static bool Prefix()
217274
return false;
218275
}
219276
}
220-
}
277+
}
278+
279+
public class Coroutines : MonoBehaviour { }

0 commit comments

Comments
 (0)