Decompiled source of LateRepo v1.6.3

plugins/LateRepo.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using LateRepo.Patches;
using Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LateRepo")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.6.3.0")]
[assembly: AssemblyInformationalVersion("1.6.3+f367845d76642f2045fb9e2a745c99e0baedddb2")]
[assembly: AssemblyProduct("LateRepo")]
[assembly: AssemblyTitle("LateRepo")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.6.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 LateRepo
{
	[BepInPlugin("chaos.holz.laterepo", "LateRepo", "1.6.3")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "chaos.holz.laterepo";

		public const string ModName = "LateRepo";

		public const string ModVersion = "1.6.3";

		private static Harmony _harmony = new Harmony("LateRepo");

		internal static readonly ManualLogSource logger = Logger.CreateLogSource("LateRepo");

		public static ConfigEntry<bool> JoinButton;

		public static ConfigEntry<bool> JoinShop;

		private static ConfigEntry<bool> splashScreen;

		private static ConfigEntry<bool> moonPhase;

		public static ConfigEntry<bool> PlayGamePopup;

		public static ConfigEntry<bool> StartGamePopup;

		public static ConfigEntry<bool> LoadSavePopup;

		private static ConfigEntry<bool> PickRegion;

		public static ConfigEntry<bool> PasswordSkip;

		public static ConfigEntry<string> PasswordSet;

		private void Awake()
		{
			logger.LogInfo((object)"[LateRepo] Initialisiere Patches …");
			JoinButton = ((BaseUnityPlugin)this).Config.Bind<bool>("Late Join", "Invite Button", true, "If true, a button appears in the Escape menu that opens the Steam overlay for inviting players.");
			JoinShop = ((BaseUnityPlugin)this).Config.Bind<bool>("Late Join", "Late Join Shop", true, "If it’s true, players can late join in the shop.");
			PickRegion = ((BaseUnityPlugin)this).Config.Bind<bool>("Lobby Settings", "Auto Region", true, "If true, it automatically picks the best region, so it doesn’t ask you to choose a region anymore.");
			PasswordSkip = ((BaseUnityPlugin)this).Config.Bind<bool>("Lobby Settings", "Passwort Skip", true, "If true, it automatically bypasses the password input screen.");
			PasswordSet = ((BaseUnityPlugin)this).Config.Bind<string>("Lobby Settings", "SetPasswort", "", "Enter the password you want for your private lobby. If it’s empty, no password will be set. This only works if Password Skip is true.");
			splashScreen = ((BaseUnityPlugin)this).Config.Bind<bool>("Popup", "Splash Screen", true, "If true, the splash screen at the beginning is skipped.");
			moonPhase = ((BaseUnityPlugin)this).Config.Bind<bool>("Popup", "Moon Phase Change", true, "If true,");
			PlayGamePopup = ((BaseUnityPlugin)this).Config.Bind<bool>("Popup", "Play Game Popup", true, "If true, the pop-ups for “Host a Game?” and “Warning: Playing with random players” are automatically accepted when you click PUBLIC or PRIVATE GAME, so they don’t appear anymore.");
			LoadSavePopup = ((BaseUnityPlugin)this).Config.Bind<bool>("Popup", "Load Save Popup", false, "If true, the pop-up for “Load Save?” is automatically accepted when you click LOAD SAVE, so it doesn’t appear anymore.");
			StartGamePopup = ((BaseUnityPlugin)this).Config.Bind<bool>("Popup", "Start Game Popup", true, "If true, the pop-up for “Start Game” is automatically accepted when you click START GAME, so it doesn’t appear anymore.");
			LateJoinPatch.InitializeHooks();
			PatchAllStuff();
			logger.LogInfo((object)"[LateRepo] erfolgreich geladen!");
		}

		private void PatchAllStuff()
		{
			if (splashScreen.Value)
			{
				_harmony.PatchAll(typeof(LevelGeneratorPatch));
			}
			if (PickRegion.Value)
			{
				_harmony.PatchAll(typeof(MenuPageRegionPatch));
			}
			if (StartGamePopup.Value || PlayGamePopup.Value || LoadSavePopup.Value)
			{
				_harmony.PatchAll(typeof(PopUpPatch));
			}
			if (PasswordSkip.Value || !string.IsNullOrEmpty(PasswordSet.Value))
			{
				_harmony.PatchAll(typeof(MenuPagePasswordPatch));
			}
			_harmony.PatchAll(typeof(PlayerNameCheckerUpdatePatch));
			_harmony.PatchAll(typeof(MenuPageEscPatch));
			if (moonPhase.Value)
			{
				_harmony.PatchAll(typeof(MoonUIPatch));
			}
		}
	}
}
namespace LateRepo.Patches
{
	[HarmonyPatch(typeof(MenuPageRegions))]
	internal static class MenuPageRegionPatch
	{
		[HarmonyPatch(typeof(MenuPageRegions), "Start")]
		[HarmonyPrefix]
		private static void MenuPageRegionStartPatch(MenuPageRegions __instance)
		{
			__instance.PickRegion("");
		}

		[HarmonyPatch(typeof(MenuPagePublicGameChoice), "ExitPage")]
		[HarmonyPrefix]
		private static bool PublicExitPagePatch()
		{
			MenuManager.instance.PageCloseAll();
			MenuManager.instance.PageOpen((MenuPageIndex)0, false);
			return false;
		}
	}
	[HarmonyPatch(typeof(MenuManager))]
	internal static class PopUpPatch
	{
		public static bool isPublicGame;

		[HarmonyPatch(typeof(MenuManager), "PagePopUpTwoOptions")]
		[HarmonyPrefix]
		private static bool PagePopUpTwoOptionsPatch(MenuButtonPopUp menuButtonPopUp, string popUpHeader, Color popUpHeaderColor, string popUpText, string option1Text, string option2Text, bool richText)
		{
			if (IsPrivateGamePopup(popUpHeader, popUpText))
			{
				isPublicGame = false;
			}
			else if (IsPublicGamePopup(popUpHeader, popUpText))
			{
				isPublicGame = true;
			}
			if (Plugin.PlayGamePopup.Value)
			{
				if (IsPrivateGamePopup(popUpHeader, popUpText))
				{
					UnityEvent option1Event = menuButtonPopUp.option1Event;
					if (option1Event != null)
					{
						option1Event.Invoke();
					}
					return false;
				}
				if (IsPublicGamePopup(popUpHeader, popUpText))
				{
					UnityEvent option1Event2 = menuButtonPopUp.option1Event;
					if (option1Event2 != null)
					{
						option1Event2.Invoke();
					}
					return false;
				}
			}
			if (Plugin.StartGamePopup.Value && IsStartGamePopup(popUpHeader, popUpText))
			{
				UnityEvent option1Event3 = menuButtonPopUp.option1Event;
				if (option1Event3 != null)
				{
					option1Event3.Invoke();
				}
				return false;
			}
			if (Plugin.LoadSavePopup.Value && IsLoadSavePopup(popUpHeader, popUpText))
			{
				UnityEvent option1Event4 = menuButtonPopUp.option1Event;
				if (option1Event4 != null)
				{
					option1Event4.Invoke();
				}
				return false;
			}
			return true;
		}

		private static bool IsPrivateGamePopup(string header, string body)
		{
			header = header.ToLower();
			body = body.ToLower();
			if (!header.Contains("host") && !body.Contains("best computer"))
			{
				return body.Contains("are you this friend");
			}
			return true;
		}

		private static bool IsPublicGamePopup(string header, string body)
		{
			header = header.ToLower();
			body = body.ToLower();
			if (!header.Contains("warning") && !body.Contains("random players"))
			{
				return body.Contains("mean people");
			}
			return true;
		}

		private static bool IsStartGamePopup(string header, string body)
		{
			header = header.ToLower();
			body = body.ToLower();
			if (!header.Contains("start") && !body.Contains("everyone ready"))
			{
				return body.Contains("once the game");
			}
			return true;
		}

		private static bool IsLoadSavePopup(string header, string body)
		{
			header = header.ToLower();
			body = body.ToLower();
			if (!header.Contains("load"))
			{
				return body.Contains("load this save");
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MenuPagePassword))]
	internal static class MenuPagePasswordPatch
	{
		private static bool passwordAlreadySet;

		[HarmonyPatch(typeof(MenuPagePassword), "Update")]
		[HarmonyPrefix]
		private static void PasswordSkipPatch(MenuPagePassword __instance)
		{
			if (!Plugin.PasswordSkip.Value)
			{
				return;
			}
			if (!string.IsNullOrEmpty(Plugin.PasswordSet.Value))
			{
				if (string.IsNullOrEmpty(Plugin.PasswordSet.Value) || passwordAlreadySet)
				{
					return;
				}
				string text = Plugin.PasswordSet.Value.ToUpper().Replace("\n", "").Replace("\r", "")
					.Replace(" ", "");
				AccessTools.Field(typeof(MenuPagePassword), "password").SetValue(__instance, text);
				passwordAlreadySet = true;
				Plugin.logger.LogInfo((object)("[LateRepo] Automatisches Passwort gesetzt: " + text));
			}
			__instance.ConfirmButton();
		}

		[HarmonyPatch(typeof(MenuPagePassword), "Start")]
		[HarmonyPrefix]
		private static void PasswortStartPatch()
		{
			passwordAlreadySet = false;
		}
	}
	[HarmonyPatch(typeof(MoonUI))]
	internal static class MoonUIPatch
	{
		[HarmonyPatch(typeof(MoonUI), "Check")]
		[HarmonyPostfix]
		private static void MoonUICheckPatch(MoonUI __instance)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			if ((int)(State)AccessTools.Field(typeof(MoonUI), "state").GetValue(__instance) > 0)
			{
				AccessTools.Field(typeof(MoonUI), "skip").SetValue(__instance, true);
				__instance.SetState((State)0);
			}
		}
	}
	[HarmonyPatch(typeof(LevelGenerator))]
	internal static class LevelGeneratorPatch
	{
		[HarmonyPatch(typeof(LevelGenerator), "Start")]
		[HarmonyPrefix]
		private static void LevelGeneratorStartPatch()
		{
			if (SemiFunc.IsSplashScreen() && Object.op_Implicit((Object)(object)RunManager.instance) && Object.op_Implicit((Object)(object)DataDirector.instance) && DataDirector.instance.SettingValueFetch((Setting)58) == 1)
			{
				RunManager.instance.levelCurrent = RunManager.instance.levelMainMenu;
			}
		}
	}
	internal static class LateJoinPatch
	{
		private static readonly FieldInfo removeFilterFieldInfo = AccessTools.Field(typeof(PhotonNetwork), "removeFilter");

		private static readonly FieldInfo keyByteSevenFieldInfo = AccessTools.Field(typeof(PhotonNetwork), "keyByteSeven");

		private static readonly FieldInfo serverCleanOptionsFieldInfo = AccessTools.Field(typeof(PhotonNetwork), "ServerCleanOptions");

		private static readonly MethodInfo raiseEventInternalMethodInfo = AccessTools.Method(typeof(PhotonNetwork), "RaiseEventInternal", (Type[])null, (Type[])null);

		private static Hook changeLevelHook;

		private static Hook spawnHook;

		private static Hook levelGenHook;

		private static Hook startHook;

		public static bool canJoin;

		public static void InitializeHooks()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			changeLevelHook = new Hook((MethodBase)AccessTools.Method(typeof(RunManager), "ChangeLevel", (Type[])null, (Type[])null), typeof(LateJoinPatch).GetMethod("ChangeLevelHook"));
			spawnHook = new Hook((MethodBase)AccessTools.Method(typeof(PlayerAvatar), "Spawn", (Type[])null, (Type[])null), typeof(LateJoinPatch).GetMethod("SpawnHook"));
			levelGenHook = new Hook((MethodBase)AccessTools.Method(typeof(LevelGenerator), "Start", (Type[])null, (Type[])null), typeof(LateJoinPatch).GetMethod("LevelGeneratorHook"));
			startHook = new Hook((MethodBase)AccessTools.Method(typeof(PlayerAvatar), "Start", (Type[])null, (Type[])null), typeof(LateJoinPatch).GetMethod("PlayerAvatarStartHook"));
		}

		public static void ChangeLevelHook(Action<RunManager, bool, bool, ChangeLevelType> orig, RunManager self, bool _completedLevel, bool _levelFailed, ChangeLevelType _changeLevelType)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if (_levelFailed || !PhotonNetwork.IsMasterClient)
			{
				orig(self, _completedLevel, _levelFailed, _changeLevelType);
				return;
			}
			object value = AccessTools.Field(typeof(RunManager), "runManagerPUN").GetValue(self);
			object? value2 = AccessTools.Field(typeof(RunManagerPUN), "photonView").GetValue(value);
			PhotonNetwork.RemoveBufferedRPCs(((PhotonView)((value2 is PhotonView) ? value2 : null)).ViewID, (string)null, (int[])null);
			PhotonView[] array = Object.FindObjectsOfType<PhotonView>();
			foreach (PhotonView val in array)
			{
				Scene scene = ((Component)val).gameObject.scene;
				if (((Scene)(ref scene)).buildIndex != -1)
				{
					ClearPhotonCache(val);
				}
			}
			orig(self, _completedLevel, arg3: false, _changeLevelType);
			canJoin = SemiFunc.RunIsLobbyMenu() || SemiFunc.RunIsLobby() || (SemiFunc.RunIsShop() && Plugin.JoinShop.Value);
			if (canJoin)
			{
				SteamManager.instance.UnlockLobby(true);
				PhotonNetwork.CurrentRoom.IsOpen = true;
				Plugin.logger.LogInfo((object)"[LateRepo] Lobbystatus geändert: offen");
				if (PopUpPatch.isPublicGame)
				{
					Plugin.logger.LogInfo((object)"Public");
					PhotonNetwork.CurrentRoom.IsVisible = true;
					GameManager.instance.SetConnectRandom(true);
				}
			}
			else
			{
				SteamManager.instance.LockLobby();
				PhotonNetwork.CurrentRoom.IsOpen = false;
				if (PopUpPatch.isPublicGame)
				{
					PhotonNetwork.CurrentRoom.IsVisible = false;
					GameManager.instance.SetConnectRandom(false);
					Plugin.logger.LogInfo((object)"nicht Public");
				}
			}
		}

		public static void SpawnHook(Action<PlayerAvatar, Vector3, Quaternion> orig, PlayerAvatar self, Vector3 position, Quaternion rotation)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (!(bool)AccessTools.Field(typeof(PlayerAvatar), "spawned").GetValue(self))
			{
				orig(self, position, rotation);
			}
		}

		public static void LevelGeneratorHook(Action<LevelGenerator> orig, LevelGenerator self)
		{
			if (PhotonNetwork.IsMasterClient && SemiFunc.RunIsLobby())
			{
				PhotonNetwork.RemoveBufferedRPCs(self.PhotonView.ViewID, (string)null, (int[])null);
			}
			orig(self);
		}

		public static void PlayerAvatarStartHook(Action<PlayerAvatar> orig, PlayerAvatar self)
		{
			orig(self);
			if (PhotonNetwork.IsMasterClient && !SemiFunc.RunIsLobby())
			{
				self.photonView.RPC("LoadingLevelAnimationCompletedRPC", (RpcTarget)3, Array.Empty<object>());
			}
		}

		private static void ClearPhotonCache(PhotonView photonView)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				object? value = removeFilterFieldInfo.GetValue(null);
				Hashtable val = (Hashtable)((value is Hashtable) ? value : null);
				object value2 = keyByteSevenFieldInfo.GetValue(null);
				object? value3 = serverCleanOptionsFieldInfo.GetValue(null);
				RaiseEventOptions val2 = (RaiseEventOptions)((value3 is RaiseEventOptions) ? value3 : null);
				val[value2] = photonView.InstantiationId;
				val2.CachingOption = (EventCaching)6;
				raiseEventInternalMethodInfo.Invoke(null, new object[4]
				{
					(byte)202,
					val,
					val2,
					SendOptions.SendReliable
				});
			}
			catch (Exception ex)
			{
				Plugin.logger.LogError((object)("[LateRepo] ClearPhotonCache Fehler: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(MenuPageEsc))]
	internal static class MenuPageEscPatch
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__0_0;

			internal void <MenuPageStartPatch>b__0_0()
			{
				if ((Object)(object)SteamManager.instance != (Object)null)
				{
					SteamManager.instance.OpenSteamOverlayToInvite();
				}
				else
				{
					Plugin.logger.LogWarning((object)"[LateRepo] SteamManager.instance ist null.");
				}
			}
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void MenuPageStartPatch(MenuPageEsc __instance)
		{
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.JoinButton.Value || !LateJoinPatch.canJoin || (Object)(object)__instance == (Object)null)
			{
				return;
			}
			MenuButton val = FindButtonByLabel(((Component)__instance).transform, "MAIN MENU");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.logger.LogWarning((object)"[LateRepo] MAIN MENU Button nicht gefunden.");
				return;
			}
			Transform parent = ((Component)val).transform.parent;
			if ((Object)(object)parent == (Object)null || (Object)(object)FindButtonByLabel(parent, "INVITE") != (Object)null)
			{
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, parent);
			MenuButtonPopUp component = val2.GetComponent<MenuButtonPopUp>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			TextMeshProUGUI componentInChildren = val2.GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				((TMP_Text)componentInChildren).text = "INVITE";
				ButtonToTMPText(val2, componentInChildren);
			}
			MenuButton component2 = val2.GetComponent<MenuButton>();
			if (component2 != null)
			{
				component2.buttonTextString = "INVITE";
			}
			Button component3 = val2.GetComponent<Button>();
			if ((Object)(object)component3 != (Object)null)
			{
				((UnityEventBase)component3.onClick).RemoveAllListeners();
				ButtonClickedEvent onClick = component3.onClick;
				object obj = <>c.<>9__0_0;
				if (obj == null)
				{
					UnityAction val3 = delegate
					{
						if ((Object)(object)SteamManager.instance != (Object)null)
						{
							SteamManager.instance.OpenSteamOverlayToInvite();
						}
						else
						{
							Plugin.logger.LogWarning((object)"[LateRepo] SteamManager.instance ist null.");
						}
					};
					<>c.<>9__0_0 = val3;
					obj = (object)val3;
				}
				((UnityEvent)onClick).AddListener((UnityAction)obj);
			}
			val2.transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex() + 1);
			VerticalLayoutGroup component4 = ((Component)parent).GetComponent<VerticalLayoutGroup>();
			HorizontalLayoutGroup component5 = ((Component)parent).GetComponent<HorizontalLayoutGroup>();
			if ((Object)(object)component4 == (Object)null && (Object)(object)component5 == (Object)null)
			{
				RectTransform component6 = ((Component)val).GetComponent<RectTransform>();
				RectTransform component7 = val2.GetComponent<RectTransform>();
				if ((Object)(object)component6 != (Object)null && (Object)(object)component7 != (Object)null)
				{
					float num = 4f;
					Rect rect = component6.rect;
					float num2 = ((Rect)(ref rect)).height + num;
					component7.anchoredPosition = component6.anchoredPosition + new Vector2(0f, 0f - num2);
					LayoutRebuilder.ForceRebuildLayoutImmediate(component7);
				}
			}
		}

		private static void ButtonToTMPText(GameObject buttonGO, TextMeshProUGUI tmp, float padX = 2f, float padY = 2f)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)buttonGO == (Object)null || (Object)(object)tmp == (Object)null)
			{
				return;
			}
			((TMP_Text)tmp).ForceMeshUpdate(false, false);
			Vector2 preferredValues = ((TMP_Text)tmp).GetPreferredValues(((TMP_Text)tmp).text);
			RectTransform component = buttonGO.GetComponent<RectTransform>();
			if (!((Object)(object)component == (Object)null))
			{
				float num = preferredValues.x + padX;
				float num2 = Mathf.Max(component.sizeDelta.y, preferredValues.y + padY);
				component.SetSizeWithCurrentAnchors((Axis)0, num);
				component.SetSizeWithCurrentAnchors((Axis)1, num2);
				RectTransform component2 = ((Component)tmp).GetComponent<RectTransform>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.anchorMin = new Vector2(0f, 0f);
					component2.anchorMax = new Vector2(1f, 1f);
					component2.offsetMin = Vector2.zero;
					component2.offsetMax = Vector2.zero;
				}
				LayoutElement component3 = buttonGO.GetComponent<LayoutElement>();
				if ((Object)(object)component3 != (Object)null)
				{
					component3.preferredWidth = num;
					component3.preferredHeight = num2;
				}
				LayoutRebuilder.ForceRebuildLayoutImmediate(component);
			}
		}

		private static MenuButton FindButtonByLabel(Transform root, string label)
		{
			MenuButton[] componentsInChildren = ((Component)root).GetComponentsInChildren<MenuButton>(true);
			foreach (MenuButton val in componentsInChildren)
			{
				TextMeshProUGUI componentInChildren = ((Component)val).GetComponentInChildren<TextMeshProUGUI>(true);
				if ((Object)(object)componentInChildren != (Object)null && string.Equals(((TMP_Text)componentInChildren).text?.Trim(), label, StringComparison.OrdinalIgnoreCase))
				{
					return val;
				}
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(PlayerNameChecker))]
	internal class PlayerNameCheckerUpdatePatch
	{
		public static class PlayerNamePatch
		{
			[HarmonyPatch(typeof(PlayerNameChecker), "Update")]
			[HarmonyPrefix]
			private static bool SafeUpdate(PlayerNameChecker __instance)
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return false;
				}
				Type type = ((object)__instance).GetType();
				FieldInfo field = type.GetField("target", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				FieldInfo field2 = type.GetField("label", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				object? obj = field?.GetValue(__instance);
				object obj2 = field2?.GetValue(__instance);
				if (obj == null || obj2 == null)
				{
					return false;
				}
				return true;
			}
		}
	}
}