Decompiled source of AutomaticInviter v2.0.0

Mods/AutomaticInviter.dll

Decompiled 9 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using AutomaticInviter;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppRUMBLE.Interactions.InteractionBase;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Social;
using Il2CppRUMBLE.Social.Phone;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppTMPro;
using MelonLoader;
using Microsoft.CodeAnalysis;
using RumbleModdingAPI.RMAPI;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "AutomaticInviter", "2.0.0", "Orangenal", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AutomaticInviter")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+995416f88fd7690bb77205eee13f18b15a1f0cf4")]
[assembly: AssemblyProduct("AutomaticInviter")]
[assembly: AssemblyTitle("AutomaticInviter")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AutomaticInviter
{
	public class Core : MelonMod
	{
		private string[] usernameList;

		private string usernamesPath = "UserData/AutomaticInviter/usernames.txt";

		private string[] IDList;

		private string IDsPath = "UserData/AutomaticInviter/IDs.txt";

		private string[] CodesList;

		private string CodesListPath = "UserData/AutomaticInviter/FriendCodes.txt";

		internal static Instance loggerInstance;

		private bool autoInvite = false;

		private AssetBundle assetBundle = null;

		public static string invokedFind = null;

		private static object inviteListByCodeCoroutine = null;

		internal static object waitingCoroutine = null;

		internal static string currentScene = "Loader";

		private static Dictionary<string, UserData> codeCache = new Dictionary<string, UserData>();

		public override void OnInitializeMelon()
		{
			Actions.onMapInitialized += OnMapInitialised;
			InitFiles();
			loggerInstance = ((MelonBase)this).LoggerInstance;
			assetBundle = AssetBundles.LoadAssetBundleFromStream((MelonMod)(object)this, "AutomaticInviter.autoinvite");
			loggerInstance.Msg("Initialised.");
		}

		public override void OnUpdate()
		{
			if (!Input.GetKeyDown((KeyCode)111))
			{
				return;
			}
			UpdateLists();
			MelonLogger.Msg("Inviting");
			OptionsPage component;
			if (currentScene == "Gym")
			{
				GameObject gameObject = SettingsScreen.GetGameObject();
				component = gameObject.GetComponent<OptionsPage>();
			}
			else
			{
				if (!(currentScene == "Park"))
				{
					return;
				}
				GameObject gameObject2 = SettingsScreen.GetGameObject();
				component = gameObject2.GetComponent<OptionsPage>();
			}
			if (usernameList.Length >= 1)
			{
				InviteListByUsername(usernameList, component);
			}
			if (IDList.Length >= 1)
			{
				InviteListByMasterID(IDList, component);
			}
			if (CodesList.Length >= 1 && inviteListByCodeCoroutine == null)
			{
				inviteListByCodeCoroutine = MelonCoroutines.Start(InviteListByFriendCode(CodesList, component));
			}
			MelonLogger.Msg("okay done");
		}

		private void InitFiles()
		{
			if (!Directory.Exists("UserData"))
			{
				Directory.CreateDirectory("UserData");
			}
			if (!Directory.Exists("UserData/AutomaticInviter"))
			{
				Directory.CreateDirectory("UserData/AutomaticInviter");
			}
			if (!File.Exists(usernamesPath))
			{
				File.WriteAllText(usernamesPath, string.Empty);
			}
			if (!File.Exists(IDsPath))
			{
				File.WriteAllText(IDsPath, string.Empty);
			}
			if (!File.Exists(CodesListPath))
			{
				File.WriteAllText(CodesListPath, string.Empty);
			}
			UpdateLists();
		}

		private void UpdateLists()
		{
			usernameList = Array.Empty<string>();
			IDList = Array.Empty<string>();
			CodesList = Array.Empty<string>();
			usernameList = (File.Exists(usernamesPath) ? File.ReadAllLines(usernamesPath) : Array.Empty<string>());
			IDList = (File.Exists(IDsPath) ? File.ReadAllLines(IDsPath) : Array.Empty<string>());
			CodesList = (File.Exists(CodesListPath) ? File.ReadAllLines(CodesListPath) : Array.Empty<string>());
		}

		public static void InvitePerson(string masterID, string titleID, string username, OptionsPage optionsPage)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			if ((Object)(object)optionsPage == (Object)null)
			{
				loggerInstance.Error("Options page is null!");
				return;
			}
			UserData val = new UserData(masterID, titleID, username, -1);
			optionsPage.Initialize(val);
			optionsPage.inviteButton.onPressed.Invoke();
		}

		public static void InvitePerson(UserData userData, OptionsPage optionsPage)
		{
			if ((Object)(object)optionsPage == (Object)null)
			{
				loggerInstance.Error("Options page is null!");
				return;
			}
			optionsPage.Initialize(userData);
			optionsPage.inviteButton.onPressed.Invoke();
		}

		public static void InvitePersonByFriendCode(string code, FindUser findUser)
		{
			foreach (char c in code)
			{
				findUser.OnNumberPressed((int)char.GetNumericValue(c));
			}
			invokedFind = code;
		}

		private void OnStep(int step)
		{
			autoInvite = step == 1;
		}

		public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
			if (inviteListByCodeCoroutine != null)
			{
				MelonCoroutines.Stop(inviteListByCodeCoroutine);
				inviteListByCodeCoroutine = null;
			}
			if (waitingCoroutine != null)
			{
				MelonCoroutines.Stop(waitingCoroutine);
				waitingCoroutine = null;
			}
			codeCache = new Dictionary<string, UserData>();
		}

		private void OnMapInitialised(string sceneName)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0651: Unknown result type (might be due to invalid IL or missing references)
			//IL_0671: Unknown result type (might be due to invalid IL or missing references)
			//IL_071f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0740: Unknown result type (might be due to invalid IL or missing references)
			currentScene = sceneName;
			if (sceneName == "Gym")
			{
				autoInvite = false;
				GameObject gameObject = HostPanel.GetGameObject();
				GameObject gameObject2 = ((Component)gameObject.transform.GetChild(1)).gameObject;
				GameObject val = Object.Instantiate<GameObject>(gameObject2, gameObject2.transform.parent, true);
				((Object)val).name = "AutoInvite Pilicy";
				Vector3 position = gameObject2.transform.position;
				Quaternion rotation = gameObject2.transform.rotation;
				val.transform.position = position - new Vector3(0f, 0.729f, 0f);
				val.transform.rotation = rotation;
				((TMP_Text)((Component)val.transform.GetChild(1)).GetComponentInChildren<TextMeshPro>()).text = "Auto invite on open?";
				InteractionSlider component = ((Component)val.transform.GetChild(2).GetChild(8)).GetComponent<InteractionSlider>();
				Action<int> val2 = Action<int>.op_Implicit((Action<int>)delegate(int step)
				{
					autoInvite = step == 1;
				});
				UnityAction<int> val3 = DelegateSupport.ConvertDelegate<UnityAction<int>>((Delegate)new Action<int>(OnStep));
				((UnityEvent<int>)(object)((InteractionNumericalBase)component).onStepReached).AddListener(val3);
				GameObject gameObject3 = ((Component)val.transform.GetChild(1).GetChild(1)).gameObject;
				GameObject gameObject4 = ((Component)val.transform.GetChild(1).GetChild(4)).gameObject;
				gameObject3.transform.localScale = new Vector3(0.075f, 0.075f, 0.075f);
				gameObject4.transform.localScale = new Vector3(0.075f, 0.075f, 0.075f);
				Texture2D val4 = assetBundle.LoadAsset<Texture2D>("cross");
				Texture2D val5 = assetBundle.LoadAsset<Texture2D>("checkmark");
				((Renderer)gameObject3.GetComponent<MeshRenderer>()).material.SetTexture("_Texture", (Texture)(object)val4);
				((Renderer)gameObject4.GetComponent<MeshRenderer>()).material.SetTexture("_Texture", (Texture)(object)val5);
				Transform transform = gameObject.transform;
				transform.position += new Vector3(0f, 0.1f, 0f);
				Transform child = gameObject.transform.GetChild(0);
				child.localPosition -= new Vector3(0f, 0.1f, 0f);
				Transform child2 = gameObject2.transform.GetChild(0).GetChild(0);
				child2.localPosition += new Vector3(0.02f, 0f, 0f);
				Transform child3 = gameObject2.transform.GetChild(0).GetChild(0);
				child3.localScale -= new Vector3(0f, 0.01f, 0f);
				for (int num = 1; num < gameObject.transform.GetChild(2).GetChild(0).childCount; num++)
				{
					Transform child4 = gameObject.transform.GetChild(2).GetChild(0).GetChild(num);
					child4.localScale = new Vector3(child4.localScale.x, 0.035f, child4.localScale.z);
				}
				GameObject gameObject5 = SettingsScreen.GetGameObject();
				if ((Object)(object)gameObject5 == (Object)null)
				{
					loggerInstance.Error("Cannot find settings page object!");
					return;
				}
				OptionsPage optionsGym = gameObject5.GetComponent<OptionsPage>();
				if ((Object)(object)optionsGym == (Object)null)
				{
					loggerInstance.Error("Cannot find options page!");
					return;
				}
				GameObject gameObject6 = FloatingButton.GetGameObject();
				GameObject val6 = Object.Instantiate<GameObject>(gameObject6);
				((Object)val6).name = "AutoInvite Button";
				val6.transform.position = new Vector3(8.1477f, 1.321f, 14.2382f);
				val6.transform.rotation = Quaternion.Euler(0f, 197.4544f, 0f);
				((TMP_Text)((Component)val6.transform.GetChild(1)).GetComponent<TextMeshPro>()).text = "AutoInvite";
				Object.Destroy((Object)(object)((Component)val6.transform.GetChild(2)).gameObject);
				GameObject val7 = Create.NewButton();
				((Object)val7).name = "InviteListButton";
				((Component)val7.transform.GetChild(0)).gameObject.GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
				{
					UpdateLists();
					loggerInstance.Msg("Inviting people...");
					if (usernameList.Length >= 1)
					{
						InviteListByUsername(usernameList, optionsGym);
					}
					if (IDList.Length >= 1)
					{
						InviteListByMasterID(IDList, optionsGym);
					}
					if (CodesList.Length >= 1 && inviteListByCodeCoroutine == null)
					{
						inviteListByCodeCoroutine = MelonCoroutines.Start(InviteListByFriendCode(CodesList, optionsGym));
					}
					loggerInstance.Msg("People invited!");
				}));
				val7.transform.SetParent(val6.transform);
				val7.transform.localPosition = new Vector3(0.0326f, 0.0054f, 0.0458f);
				val7.transform.rotation = Quaternion.Euler(0f, 285f, 90f);
			}
			if (sceneName != "Park" || !Players.IsHost())
			{
				return;
			}
			UpdateLists();
			GameObject gameObject7 = SettingsScreen.GetGameObject();
			if ((Object)(object)gameObject7 == (Object)null)
			{
				loggerInstance.Error("Cannot find settings page object!");
				return;
			}
			OptionsPage options = gameObject7.GetComponent<OptionsPage>();
			if ((Object)(object)options == (Object)null)
			{
				loggerInstance.Error("Cannot find options page!");
				return;
			}
			if (autoInvite)
			{
				loggerInstance.Msg("Inviting people...");
				if (usernameList.Length >= 1)
				{
					InviteListByUsername(usernameList, options);
				}
				if (IDList.Length >= 1)
				{
					InviteListByMasterID(IDList, options);
				}
				if (CodesList.Length >= 1 && inviteListByCodeCoroutine == null)
				{
					inviteListByCodeCoroutine = MelonCoroutines.Start(InviteListByFriendCode(CodesList, options));
				}
				loggerInstance.Msg("People invited!");
			}
			GameObject gameObject8 = FloatingButton.GetGameObject();
			GameObject val8 = Object.Instantiate<GameObject>(gameObject8);
			((Object)val8).name = "AutoInvite Button";
			val8.transform.position = new Vector3(-29.2742f, -1.6354f, -7.015f);
			val8.transform.rotation = Quaternion.Euler(0f, 90f, 0f);
			((TMP_Text)((Component)val8.transform.GetChild(1)).GetComponent<TextMeshPro>()).text = "AutoInvite";
			Object.Destroy((Object)(object)((Component)val8.transform.GetChild(2)).gameObject);
			GameObject val9 = Create.NewButton();
			((Object)val9).name = "InviteListButton";
			((Component)val9.transform.GetChild(0)).gameObject.GetComponent<InteractionButton>().onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
			{
				UpdateLists();
				loggerInstance.Msg("Inviting people...");
				if (usernameList.Length >= 1)
				{
					InviteListByUsername(usernameList, options);
				}
				if (IDList.Length >= 1)
				{
					InviteListByMasterID(IDList, options);
				}
				if (CodesList.Length >= 1 && inviteListByCodeCoroutine == null)
				{
					inviteListByCodeCoroutine = MelonCoroutines.Start(InviteListByFriendCode(CodesList, options));
				}
				loggerInstance.Msg("People invited!");
			}));
			val9.transform.SetParent(val8.transform);
			val9.transform.localPosition = new Vector3(0.0326f, 0.0054f, 0.0458f);
			val9.transform.rotation = Quaternion.Euler(0f, 180f, 90f);
		}

		public static void InviteListByUsername(string[] usernames, OptionsPage optionsPage = null)
		{
			if (usernames.Length < 1)
			{
				loggerInstance.Error("Username list is empty!");
				return;
			}
			if ((Object)(object)optionsPage == (Object)null)
			{
				GameObject gameObject;
				if (currentScene == "Gym")
				{
					gameObject = SettingsScreen.GetGameObject();
				}
				else
				{
					if (!(currentScene == "Park"))
					{
						loggerInstance.Error("Users cannot be invited in scene \"" + currentScene + "\"");
						return;
					}
					gameObject = SettingsScreen.GetGameObject();
				}
				if ((Object)(object)gameObject == (Object)null)
				{
					loggerInstance.Error("Cannot find settings page object!");
					return;
				}
				optionsPage = gameObject.GetComponent<OptionsPage>();
				if ((Object)(object)optionsPage == (Object)null)
				{
					loggerInstance.Error("Cannot find options page!");
					return;
				}
			}
			List<GetFriendsResult> confirmedFriends = FriendHandler.ConfirmedFriends;
			foreach (string username in usernames)
			{
				IEnumerable<GetFriendsResult> enumerable = ((IEnumerable<GetFriendsResult>)confirmedFriends.ToArray()).Where((GetFriendsResult val) => ((UserSearchResult)val).PublicName == username || Regex.Replace(((UserSearchResult)val).PublicName, "<#[0-9A-Fa-f]{3,6}>", "") == username);
				if (enumerable.Count() > 1)
				{
					loggerInstance.Warning("Multiple friends found with username \"" + username + ",\" please use their ID instead!");
					continue;
				}
				if (enumerable.Count() == 0)
				{
					loggerInstance.Warning("No friends with username \"" + username + "\"");
					continue;
				}
				foreach (GetFriendsResult friend in enumerable)
				{
					if (((IEnumerable<Player>)Players.GetAllPlayers().ToArray()).Where((Player player) => player.Data.GeneralData.PlayFabMasterId == ((UserSearchResult)friend).PlayFabMasterId).Count() != 0)
					{
						loggerInstance.Msg("Inviting " + ((UserSearchResult)friend).PublicName);
						InvitePerson(((UserSearchResult)friend).PlayFabMasterId, ((UserSearchResult)friend).PlayFabTitleId, ((UserSearchResult)friend).PublicName, optionsPage);
					}
				}
			}
		}

		public static void InviteListByMasterID(string[] IDs, OptionsPage optionsPage = null)
		{
			if (IDs.Length < 1)
			{
				loggerInstance.Error("ID list is empty!");
				return;
			}
			if ((Object)(object)optionsPage == (Object)null)
			{
				GameObject gameObject;
				if (currentScene == "Gym")
				{
					gameObject = SettingsScreen.GetGameObject();
				}
				else
				{
					if (!(currentScene == "Park"))
					{
						loggerInstance.Error("Users cannot be invited in scene \"" + currentScene + "\"");
						return;
					}
					gameObject = SettingsScreen.GetGameObject();
				}
				if ((Object)(object)gameObject == (Object)null)
				{
					loggerInstance.Error("Cannot find settings page object!");
					return;
				}
				optionsPage = gameObject.GetComponent<OptionsPage>();
				if ((Object)(object)optionsPage == (Object)null)
				{
					loggerInstance.Error("Cannot find options page!");
					return;
				}
			}
			List<GetFriendsResult> confirmedFriends = FriendHandler.ConfirmedFriends;
			foreach (string masterID in IDs)
			{
				if (((IEnumerable<Player>)Players.GetAllPlayers().ToArray()).Where((Player player) => player.Data.GeneralData.PlayFabMasterId == masterID).Count() != 0)
				{
					break;
				}
				IEnumerable<GetFriendsResult> source = ((IEnumerable<GetFriendsResult>)confirmedFriends.ToArray()).Where((GetFriendsResult friend) => ((UserSearchResult)friend).PlayFabMasterId == masterID);
				if (source.Count() == 0)
				{
					loggerInstance.Msg("No friends with ID \"" + masterID + "\"");
					UserData val = UserDataManager.FetchUserData(masterID);
					if (val != null)
					{
						loggerInstance.Msg("Inviting ID " + val.playFabMasterId + " - " + val.publicName);
						InvitePerson(val.playFabMasterId, val.playFabTitleId, val.publicName, optionsPage);
					}
					else
					{
						loggerInstance.Warning("Could not find user - " + masterID);
					}
				}
				else
				{
					GetFriendsResult val2 = source.First();
					loggerInstance.Msg("Inviting ID " + ((UserSearchResult)val2).PlayFabMasterId + " - " + ((UserSearchResult)val2).PublicName);
					InvitePerson(((UserSearchResult)val2).PlayFabMasterId, ((UserSearchResult)val2).PlayFabTitleId, ((UserSearchResult)val2).PublicName, optionsPage);
				}
			}
		}

		public static IEnumerator InviteListByFriendCode(string[] codes, OptionsPage optionsPage = null)
		{
			if (codes.Length < 1)
			{
				loggerInstance.Error("Code list is empty!");
				inviteListByCodeCoroutine = null;
				yield break;
			}
			if ((Object)(object)optionsPage == (Object)null)
			{
				GameObject optionsObject;
				if (currentScene == "Gym")
				{
					optionsObject = SettingsScreen.GetGameObject();
				}
				else
				{
					if (!(currentScene == "Park"))
					{
						loggerInstance.Error("Users cannot be invited in scene \"" + currentScene + "\"");
						yield break;
					}
					optionsObject = SettingsScreen.GetGameObject();
				}
				if ((Object)(object)optionsObject == (Object)null)
				{
					loggerInstance.Error("Cannot find settings page object!");
					inviteListByCodeCoroutine = null;
					yield break;
				}
				optionsPage = optionsObject.GetComponent<OptionsPage>();
				if ((Object)(object)optionsPage == (Object)null)
				{
					loggerInstance.Error("Cannot find options page!");
					inviteListByCodeCoroutine = null;
					yield break;
				}
			}
			GameObject friendScreen;
			if (currentScene == "Gym")
			{
				friendScreen = PlayerFinderScreen.GetGameObject();
			}
			else
			{
				if (!(currentScene == "Park"))
				{
					loggerInstance.Error("Users cannot be invited in scene \"" + currentScene + "\"");
					yield break;
				}
				friendScreen = PlayerFinderScreen.GetGameObject();
			}
			FindUser findUser = friendScreen.GetComponent<FindUser>();
			foreach (string code in codes)
			{
				if (codeCache.ContainsKey(code))
				{
					loggerInstance.Msg("Inviting player with friend code " + code);
					UserData userData = codeCache[code];
					if (((IEnumerable<Player>)Players.GetAllPlayers().ToArray()).Where((Player player) => player.Data.GeneralData.PlayFabMasterId == userData.playFabMasterId).Count() == 0)
					{
						InvitePerson(userData, optionsPage);
					}
					inviteListByCodeCoroutine = null;
					yield break;
				}
				loggerInstance.Msg("Finding player with friend code " + code);
				InvitePersonByFriendCode(code, findUser);
				while (invokedFind != null)
				{
					yield return null;
				}
				for (int i2 = 1; i2 <= 8; i2++)
				{
					findUser.OnBackspacePressed();
				}
			}
			inviteListByCodeCoroutine = null;
		}

		internal static IEnumerator WaitForUserData(PlayerTag playerTag, OptionsPage options, string code)
		{
			int count = 0;
			while (playerTag.UserData.publicName == "" && count < 5000)
			{
				count++;
				yield return null;
			}
			if (count == 5000)
			{
				loggerInstance.Warning("Search for user timed out");
			}
			else if (((IEnumerable<Player>)Players.GetAllPlayers().ToArray()).Where((Player player) => player.Data.GeneralData.PlayFabMasterId == playerTag.UserData.playFabMasterId).Count() == 0)
			{
				codeCache.Add(code, playerTag.UserData);
				options.Initialize(playerTag.UserData);
				loggerInstance.Msg("Inviting player with friend code " + code);
				InvitePerson(playerTag.UserData, options);
			}
		}
	}
	[HarmonyPatch(typeof(FindUser), "OnDoneFindingUser")]
	internal class FindUserPatch
	{
		private static void Postfix(ref FindUser __instance)
		{
			if (Core.invokedFind == null)
			{
				return;
			}
			GameObject gameObject;
			if (Core.currentScene == "Gym")
			{
				gameObject = SettingsScreen.GetGameObject();
			}
			else
			{
				if (!(Core.currentScene == "Park"))
				{
					Core.loggerInstance.Error("Users cannot be invited in scene \"" + Core.currentScene + "\"");
					return;
				}
				gameObject = SettingsScreen.GetGameObject();
			}
			if ((Object)(object)gameObject == (Object)null)
			{
				Core.loggerInstance.Error("Cannot find settings page object!");
				return;
			}
			OptionsPage component = gameObject.GetComponent<OptionsPage>();
			if ((Object)(object)component == (Object)null)
			{
				Core.loggerInstance.Error("Cannot find options page!");
				return;
			}
			if (__instance.searchStatusText.text != "No ID match found")
			{
				Core.waitingCoroutine = MelonCoroutines.Start(Core.WaitForUserData(__instance.PlayerTag, component, Core.invokedFind));
			}
			else
			{
				Core.loggerInstance.Warning("No user found with friend code " + Core.invokedFind);
			}
			Core.invokedFind = null;
		}
	}
}