Decompiled source of MMOHeimMainMenu v1.0.4

MMOHeimMainMenu.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("MMOHeimMainMenu")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Custom main menu assets, loading art rotation, and Discord link for MMOHeim.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MMOHeimMainMenu")]
[assembly: AssemblyTitle("MMOHeimMainMenu")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 MMOHeimMainMenu
{
	internal static class LoadingScreens
	{
		internal struct LoadingTargetResult
		{
			internal bool IsValid;

			internal bool IsRaw;

			internal Image? Image;

			internal RawImage? RawImage;

			internal int Score;

			internal string Path;

			internal string ObjectName;
		}

		[CompilerGenerated]
		private sealed class <ForceKeepCoroutine>d__17 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public LoadingTargetResult result;

			public Sprite sprite;

			private float <deadline>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ForceKeepCoroutine>d__17(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<deadline>5__2 = Time.realtimeSinceStartup + 2400f;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (Time.realtimeSinceStartup < <deadline>5__2 && !MMOHeimMainMenuPlugin.TryGetLocalPlayerPresentPlain() && (Object)(object)MMOHeimMainMenuPlugin.Instance != (Object)null)
				{
					ApplyLoadingTargetResult(result, sprite);
					<>2__current = (object)new WaitForSecondsRealtime(2f);
					<>1__state = 1;
					return true;
				}
				_forceCoroutine = null;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <LoadingFadeCoroutine>d__20 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public LoadingTargetResult result;

			private float <elapsed>5__2;

			private float <startAlpha>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <LoadingFadeCoroutine>d__20(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<elapsed>5__2 = 0f;
					<startAlpha>5__3 = 1f;
					if (result.IsRaw && (Object)(object)result.RawImage != (Object)null)
					{
						<startAlpha>5__3 = ((Graphic)result.RawImage).canvasRenderer.GetAlpha();
					}
					else if ((Object)(object)result.Image != (Object)null)
					{
						<startAlpha>5__3 = ((Graphic)result.Image).canvasRenderer.GetAlpha();
					}
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (<elapsed>5__2 < 0.6f)
				{
					<elapsed>5__2 += Time.unscaledDeltaTime;
					float num = Mathf.Clamp01(<elapsed>5__2 / 0.6f);
					float a = Mathf.Lerp(<startAlpha>5__3, 0f, num);
					TryApplyAlpha(result, a);
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				ClearLoadingTarget(result);
				LoadingArtSessionActive = false;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <WaitForConnectedWorldLoadAndReplaceCoroutine>d__13 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private float <deadlineSearch>5__2;

			private string <chosenLoadingArtPath>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitForConnectedWorldLoadAndReplaceCoroutine>d__13(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 2u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<chosenLoadingArtPath>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Expected O, but got Unknown
				//IL_00be: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c8: Expected O, but got Unknown
				//IL_0131: Unknown result type (might be due to invalid IL or missing references)
				//IL_013b: Expected O, but got Unknown
				bool result;
				try
				{
					switch (<>1__state)
					{
					default:
						result = false;
						goto end_IL_0000;
					case 0:
						<>1__state = -1;
						if (WatcherRunning)
						{
							result = false;
						}
						else
						{
							WatcherRunning = true;
							<>1__state = -3;
							<>2__current = (object)new WaitForSecondsRealtime(0f);
							<>1__state = 1;
							result = true;
						}
						goto end_IL_0000;
					case 1:
						<>1__state = -3;
						<deadlineSearch>5__2 = Time.realtimeSinceStartup + 2400f;
						<chosenLoadingArtPath>5__3 = null;
						break;
					case 2:
						<>1__state = -3;
						break;
					case 3:
						<>1__state = -3;
						break;
					}
					if (Time.realtimeSinceStartup < <deadlineSearch>5__2 && !MMOHeimMainMenuPlugin.TryGetLocalPlayerPresentPlain())
					{
						if (<chosenLoadingArtPath>5__3 == null)
						{
							<chosenLoadingArtPath>5__3 = MMOHeimMainMenuPlugin.GetRandomLoadingArtPath();
						}
						string text = <chosenLoadingArtPath>5__3;
						if (string.IsNullOrEmpty(text) || !File.Exists(text))
						{
							<>2__current = (object)new WaitForSecondsRealtime(0.5f);
							<>1__state = 2;
							result = true;
						}
						else
						{
							Sprite val = SpriteFromFile(text);
							if (!((Object)(object)val != (Object)null))
							{
								goto IL_012b;
							}
							LoadingTargetResult loadingTargetResult = FindBestConnectedWorldLoadingTarget();
							if (!loadingTargetResult.IsValid || !ApplyLoadingTargetResult(loadingTargetResult, val))
							{
								Object.Destroy((Object)(object)val);
								goto IL_012b;
							}
							LoadingTargetResult result2 = loadingTargetResult;
							LoadingArtSessionActive = true;
							StartForceKeep(loadingTargetResult, val);
							StartCleanup(result2);
							result = false;
							<>m__Finally1();
						}
					}
					else
					{
						<chosenLoadingArtPath>5__3 = null;
						<>m__Finally1();
						result = false;
					}
					goto end_IL_0000;
					IL_012b:
					<>2__current = (object)new WaitForSecondsRealtime(0.5f);
					<>1__state = 3;
					result = true;
					end_IL_0000:;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				WatcherRunning = false;
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <WaitUntilWorldThenClear>d__15 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public LoadingTargetResult result;

			private float <deadline>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <WaitUntilWorldThenClear>d__15(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<deadline>5__2 = Time.realtimeSinceStartup + 2400f;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (!MMOHeimMainMenuPlugin.TryGetLocalPlayerPresentPlain() && Time.realtimeSinceStartup < <deadline>5__2)
				{
					MMOHeimMainMenuPlugin.IsWorldFullyLoaded();
					<>2__current = (object)new WaitForSecondsRealtime(0.5f);
					<>1__state = 1;
					return true;
				}
				MMOHeimMainMenuPlugin.IsWorldFullyLoaded();
				FadeOutAndClearLoadingTarget(result);
				_cleanupCoroutine = null;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private const float PostSceneDelaySeconds = 0f;

		private const float SearchIntervalSeconds = 0.5f;

		private const float MaxLoadWaitSeconds = 2400f;

		private const float MaintainArtIntervalSeconds = 2f;

		private const int MinimumValidScore = 300;

		private const float LoadingFadeOutSeconds = 0.6f;

		private static Coroutine? _cleanupCoroutine;

		private static Coroutine? _forceCoroutine;

		internal static volatile bool WatcherRunning;

		internal static volatile bool LoadingArtSessionActive;

		internal static void ResetForMainMenu()
		{
			LoadingArtSessionActive = false;
		}

		internal static void TryStartLoadingScreenWatcher()
		{
			if (MMOHeimMainMenuPlugin.EnableCustomLoadingScreens && !((Object)(object)MMOHeimMainMenuPlugin.Instance == (Object)null) && !WatcherRunning && !LoadingArtSessionActive)
			{
				((MonoBehaviour)MMOHeimMainMenuPlugin.Instance).StartCoroutine(WaitForConnectedWorldLoadAndReplaceCoroutine());
			}
		}

		[IteratorStateMachine(typeof(<WaitForConnectedWorldLoadAndReplaceCoroutine>d__13))]
		internal static IEnumerator WaitForConnectedWorldLoadAndReplaceCoroutine()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForConnectedWorldLoadAndReplaceCoroutine>d__13(0);
		}

		private static void StartCleanup(LoadingTargetResult result)
		{
			if (!((Object)(object)MMOHeimMainMenuPlugin.Instance == (Object)null) && result.IsValid)
			{
				if (_cleanupCoroutine != null)
				{
					((MonoBehaviour)MMOHeimMainMenuPlugin.Instance).StopCoroutine(_cleanupCoroutine);
					_cleanupCoroutine = null;
				}
				_cleanupCoroutine = ((MonoBehaviour)MMOHeimMainMenuPlugin.Instance).StartCoroutine(WaitUntilWorldThenClear(result));
			}
		}

		[IteratorStateMachine(typeof(<WaitUntilWorldThenClear>d__15))]
		private static IEnumerator WaitUntilWorldThenClear(LoadingTargetResult result)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitUntilWorldThenClear>d__15(0)
			{
				result = result
			};
		}

		private static void StartForceKeep(LoadingTargetResult result, Sprite sprite)
		{
			if (!((Object)(object)MMOHeimMainMenuPlugin.Instance == (Object)null) && result.IsValid && !((Object)(object)sprite == (Object)null))
			{
				if (_forceCoroutine != null)
				{
					((MonoBehaviour)MMOHeimMainMenuPlugin.Instance).StopCoroutine(_forceCoroutine);
					_forceCoroutine = null;
				}
				_forceCoroutine = ((MonoBehaviour)MMOHeimMainMenuPlugin.Instance).StartCoroutine(ForceKeepCoroutine(result, sprite));
			}
		}

		[IteratorStateMachine(typeof(<ForceKeepCoroutine>d__17))]
		private static IEnumerator ForceKeepCoroutine(LoadingTargetResult result, Sprite sprite)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ForceKeepCoroutine>d__17(0)
			{
				result = result,
				sprite = sprite
			};
		}

		private static Sprite? SpriteFromFile(string absolutePath)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				byte[] data = File.ReadAllBytes(absolutePath);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!TextureDecode.LoadImage(val, data, markNonReadable: false))
				{
					Object.Destroy((Object)(object)val);
					return null;
				}
				val.Apply(true, false);
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			}
			catch
			{
				return null;
			}
		}

		private static void FadeOutAndClearLoadingTarget(LoadingTargetResult result)
		{
			if (!result.IsValid || (Object)(object)MMOHeimMainMenuPlugin.Instance == (Object)null)
			{
				ClearLoadingTarget(result);
				LoadingArtSessionActive = false;
				return;
			}
			if (_cleanupCoroutine != null)
			{
				((MonoBehaviour)MMOHeimMainMenuPlugin.Instance).StopCoroutine(_cleanupCoroutine);
				_cleanupCoroutine = null;
			}
			IEnumerator enumerator = LoadingFadeCoroutine(result);
			((MonoBehaviour)MMOHeimMainMenuPlugin.Instance).StartCoroutine(enumerator);
		}

		[IteratorStateMachine(typeof(<LoadingFadeCoroutine>d__20))]
		private static IEnumerator LoadingFadeCoroutine(LoadingTargetResult result)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadingFadeCoroutine>d__20(0)
			{
				result = result
			};
		}

		private static void TryApplyAlpha(LoadingTargetResult result, float a)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (result.IsValid)
			{
				Color color = default(Color);
				((Color)(ref color))..ctor(1f, 1f, 1f, Mathf.Clamp01(a));
				if (result.IsRaw && (Object)(object)result.RawImage != (Object)null)
				{
					((Graphic)result.RawImage).color = color;
					((Graphic)result.RawImage).SetAllDirty();
				}
				else if (!result.IsRaw && (Object)(object)result.Image != (Object)null)
				{
					((Graphic)result.Image).color = color;
					((Graphic)result.Image).SetAllDirty();
				}
			}
		}

		internal static LoadingTargetResult FindBestConnectedWorldLoadingTarget()
		{
			LoadingTargetResult loadingTargetResult = default(LoadingTargetResult);
			loadingTargetResult.IsValid = false;
			loadingTargetResult.IsRaw = false;
			loadingTargetResult.Image = null;
			loadingTargetResult.RawImage = null;
			loadingTargetResult.Score = int.MinValue;
			loadingTargetResult.Path = string.Empty;
			loadingTargetResult.ObjectName = string.Empty;
			LoadingTargetResult result = loadingTargetResult;
			Image[] array = Resources.FindObjectsOfTypeAll<Image>();
			foreach (Image val in array)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null)
				{
					int num = CalculateConnectedWorldLoadingImageScore(val);
					if (num > result.Score)
					{
						result.IsValid = num >= 300;
						result.IsRaw = false;
						result.Image = val;
						result.RawImage = null;
						result.Score = num;
						result.Path = GetHierarchyPath(((Component)val).transform);
						result.ObjectName = ((Object)((Component)val).gameObject).name;
					}
				}
			}
			RawImage[] array2 = Resources.FindObjectsOfTypeAll<RawImage>();
			foreach (RawImage val2 in array2)
			{
				if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).gameObject != (Object)null)
				{
					int num2 = CalculateConnectedWorldLoadingRawImageScore(val2);
					if (num2 > result.Score)
					{
						result.IsValid = num2 >= 300;
						result.IsRaw = true;
						result.Image = null;
						result.RawImage = val2;
						result.Score = num2;
						result.Path = GetHierarchyPath(((Component)val2).transform);
						result.ObjectName = ((Object)((Component)val2).gameObject).name;
					}
				}
			}
			return result;
		}

		private static bool ApplyLoadingTargetResult(LoadingTargetResult result, Sprite customSprite)
		{
			if (!result.IsValid || (Object)(object)customSprite == (Object)null)
			{
				return false;
			}
			if (result.IsRaw)
			{
				if ((Object)(object)result.RawImage == (Object)null)
				{
					return false;
				}
				ApplyLoadingRawImage(result.RawImage, customSprite);
			}
			else
			{
				if ((Object)(object)result.Image == (Object)null)
				{
					return false;
				}
				ApplyLoadingImage(result.Image, customSprite);
			}
			return true;
		}

		private static void ApplyLoadingImage(Image target, Sprite customSprite)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			target.sprite = customSprite;
			target.overrideSprite = customSprite;
			((Behaviour)target).enabled = true;
			target.preserveAspect = false;
			target.type = (Type)0;
			((Graphic)target).material = null;
			((Graphic)target).color = Color.white;
			StretchToFullscreen(((Graphic)target).rectTransform);
			((Graphic)target).SetAllDirty();
		}

		private static void ApplyLoadingRawImage(RawImage target, Sprite customSprite)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			target.texture = (Texture)(object)customSprite.texture;
			((Behaviour)target).enabled = true;
			((Graphic)target).material = null;
			((Graphic)target).color = Color.white;
			StretchToFullscreen(((Graphic)target).rectTransform);
			((Graphic)target).SetAllDirty();
		}

		private static void ClearLoadingTarget(LoadingTargetResult result)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			if (result.IsValid)
			{
				if (result.IsRaw && (Object)(object)result.RawImage != (Object)null && (Object)(object)((Component)result.RawImage).gameObject != (Object)null)
				{
					result.RawImage.texture = null;
					((Graphic)result.RawImage).color = new Color(1f, 1f, 1f, 0f);
					((Behaviour)result.RawImage).enabled = false;
					((Graphic)result.RawImage).SetAllDirty();
				}
				else if (!result.IsRaw && (Object)(object)result.Image != (Object)null && (Object)(object)((Component)result.Image).gameObject != (Object)null)
				{
					result.Image.sprite = null;
					result.Image.overrideSprite = null;
					((Graphic)result.Image).color = new Color(1f, 1f, 1f, 0f);
					((Behaviour)result.Image).enabled = false;
					((Graphic)result.Image).SetAllDirty();
				}
			}
		}

		private static bool Approximately(float a, float b)
		{
			return Mathf.Abs(a - b) <= 0.001f;
		}

		internal static bool IsFullscreenLike(RectTransform rt)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rt == (Object)null)
			{
				return false;
			}
			bool num = Approximately(rt.anchorMin.x, 0f) && Approximately(rt.anchorMin.y, 0f) && Approximately(rt.anchorMax.x, 1f) && Approximately(rt.anchorMax.y, 1f);
			bool flag = Approximately(rt.offsetMin.x, 0f) && Approximately(rt.offsetMin.y, 0f) && Approximately(rt.offsetMax.x, 0f) && Approximately(rt.offsetMax.y, 0f);
			return num && flag;
		}

		internal static string GetHierarchyPath(Transform transform)
		{
			if ((Object)(object)transform == (Object)null)
			{
				return "<null>";
			}
			List<string> list = new List<string>();
			Transform val = transform;
			while ((Object)(object)val != (Object)null)
			{
				list.Insert(0, ((Object)val).name);
				val = val.parent;
			}
			return string.Join("/", list.ToArray());
		}

		internal static int CalculateConnectedWorldLoadingImageScore(Image img)
		{
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_0458: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((img != null) ? ((Component)img).gameObject : null) == (Object)null)
			{
				return int.MinValue;
			}
			string text = ((Object)((Component)img).gameObject).name ?? string.Empty;
			text = text.ToLowerInvariant();
			string text2 = GetHierarchyPath(((Component)img).transform).ToLowerInvariant();
			string text3 = (((Object)(object)img.sprite != (Object)null) ? (((Object)img.sprite).name ?? string.Empty).ToLowerInvariant() : string.Empty);
			if (!text2.Contains("loadinggui"))
			{
				return int.MinValue;
			}
			if (text2.Contains("popupblockingbackground") || text2.Contains("unifiedpopup") || text2.Contains("achievementpopup") || text2.Contains("achievementui") || text2.Contains("editguild") || text2.Contains("createguild") || text2.Contains("searchguild") || text2.Contains("guildmanagementui") || text2.Contains("applicationsui") || text2.Contains("noguild") || text2.Contains("discord") || text2.Contains("_console(clone)") || text2.Contains("/_console") || text2.Contains("logoutput") || text2.Contains("serveroptions") || text2.Contains("connectionfailed") || text2.Contains("managesavesmenu") || text2.Contains("removecharacterdialog") || text2.Contains("pleasewait"))
			{
				return int.MinValue;
			}
			if (!text.Contains("crosshair") && !text.Contains("healthicon") && !text.Contains("foodicon") && !text.Contains("windicon") && !text.Contains("mounticon") && !text.Contains("player_marker") && !text.Contains("ship_marker") && !text.Contains("wind_marker"))
			{
				switch (text)
				{
				case "backgroundback":
				case "buttonclose":
				case "button":
				case "border":
				case "bkg":
				case "bar":
				case "darken":
				case "handle":
				case "separator":
					break;
				default:
				{
					if (text2.Contains("/enemyhud/") || text2.Contains("/inventory_screen/") || text2.Contains("/statuseffects/") || text2.Contains("/keyhints/") || text2.Contains("/buildhud/") || text2.Contains("/shiphud/controls/") || text2.Contains("/crosshair/") || text2.Contains("/guardianpower/"))
					{
						return int.MinValue;
					}
					int num = 0;
					if (text == "screen")
					{
						num += 5000;
					}
					if (text2.EndsWith("/hud/screen"))
					{
						num += 5000;
					}
					if (text2.Contains("/hud/screen"))
					{
						num += 3000;
					}
					if (text2.Contains("loadinggui"))
					{
						num += 300;
					}
					if (text2.Contains("pixelfix"))
					{
						num += 40;
					}
					if (text2.Contains("/hud/"))
					{
						num += 150;
					}
					if (text2.Contains("/ingamegui/"))
					{
						num += 50;
					}
					if (text == "background")
					{
						num += 180;
					}
					if (text.Contains("background"))
					{
						num += 120;
					}
					if (text3.Contains("background"))
					{
						num += 60;
					}
					if (text.Contains("image"))
					{
						num += 20;
					}
					if (((Behaviour)img).enabled)
					{
						num += 20;
					}
					if (((Component)img).gameObject.activeInHierarchy)
					{
						num += 60;
					}
					if ((Object)(object)((Graphic)img).canvasRenderer != (Object)null && ((Graphic)img).canvasRenderer.GetAlpha() > 0.01f)
					{
						num += 40;
					}
					RectTransform rectTransform = ((Graphic)img).rectTransform;
					if ((Object)(object)rectTransform != (Object)null)
					{
						Rect rect = rectTransform.rect;
						float num2 = Mathf.Abs(((Rect)(ref rect)).width);
						rect = rectTransform.rect;
						float num3 = Mathf.Abs(((Rect)(ref rect)).height);
						float num4 = num2 * num3;
						if (num4 < 200000f)
						{
							return int.MinValue;
						}
						if (num4 > 300000f)
						{
							num += 60;
						}
						if (num4 > 500000f)
						{
							num += 120;
						}
						if (num4 > 1000000f)
						{
							num += 220;
						}
						if (num4 > 1800000f)
						{
							num += 320;
						}
						if (num2 >= (float)Screen.width * 0.7f)
						{
							num += 80;
						}
						if (num3 >= (float)Screen.height * 0.7f)
						{
							num += 80;
						}
						if (num2 >= (float)Screen.width * 0.9f)
						{
							num += 100;
						}
						if (num3 >= (float)Screen.height * 0.9f)
						{
							num += 100;
						}
						if (IsFullscreenLike(rectTransform))
						{
							num += 400;
						}
					}
					return num;
				}
				}
			}
			return int.MinValue;
		}

		internal static int CalculateConnectedWorldLoadingRawImageScore(RawImage raw)
		{
			//IL_02c7: 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_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((raw != null) ? ((Component)raw).gameObject : null) == (Object)null)
			{
				return int.MinValue;
			}
			string text = (((Object)((Component)raw).gameObject).name ?? string.Empty).ToLowerInvariant();
			string text2 = GetHierarchyPath(((Component)raw).transform).ToLowerInvariant();
			if (!text2.Contains("loadinggui"))
			{
				return int.MinValue;
			}
			if (text2.Contains("popupblockingbackground") || text2.Contains("unifiedpopup") || text2.Contains("achievementpopup") || text2.Contains("achievementui") || text2.Contains("editguild") || text2.Contains("createguild") || text2.Contains("searchguild") || text2.Contains("guildmanagementui") || text2.Contains("applicationsui") || text2.Contains("noguild") || text2.Contains("discord") || text2.Contains("_console(clone)") || text2.Contains("/_console") || text2.Contains("logoutput") || text2.Contains("serveroptions") || text2.Contains("connectionfailed") || text2.Contains("managesavesmenu") || text2.Contains("removecharacterdialog") || text2.Contains("pleasewait"))
			{
				return int.MinValue;
			}
			if (text2.Contains("/enemyhud/") || text2.Contains("/inventory_screen/") || text2.Contains("/statuseffects/") || text2.Contains("/keyhints/") || text2.Contains("/buildhud/") || text2.Contains("/shiphud/controls/") || text2.Contains("/crosshair/") || text2.Contains("/guardianpower/"))
			{
				return int.MinValue;
			}
			int num = 0;
			if (text == "screen")
			{
				num += 5000;
			}
			if (text2.EndsWith("/hud/screen"))
			{
				num += 5000;
			}
			if (text2.Contains("/hud/screen"))
			{
				num += 3000;
			}
			if (text2.Contains("loadinggui"))
			{
				num += 300;
			}
			if (text2.Contains("pixelfix"))
			{
				num += 40;
			}
			if (text2.Contains("/hud/"))
			{
				num += 150;
			}
			if (text == "background")
			{
				num += 180;
			}
			if (text.Contains("background"))
			{
				num += 120;
			}
			if (text.Contains("image"))
			{
				num += 20;
			}
			if (((Behaviour)raw).enabled)
			{
				num += 20;
			}
			if (((Component)raw).gameObject.activeInHierarchy)
			{
				num += 60;
			}
			RectTransform rectTransform = ((Graphic)raw).rectTransform;
			if ((Object)(object)rectTransform != (Object)null)
			{
				Rect rect = rectTransform.rect;
				float num2 = Mathf.Abs(((Rect)(ref rect)).width);
				rect = rectTransform.rect;
				float num3 = Mathf.Abs(((Rect)(ref rect)).height);
				float num4 = num2 * num3;
				if (num4 < 200000f)
				{
					return int.MinValue;
				}
				if (num4 > 300000f)
				{
					num += 60;
				}
				if (num4 > 500000f)
				{
					num += 120;
				}
				if (num4 > 1000000f)
				{
					num += 220;
				}
				if (num4 > 1800000f)
				{
					num += 320;
				}
				if (num2 >= (float)Screen.width * 0.7f)
				{
					num += 80;
				}
				if (num3 >= (float)Screen.height * 0.7f)
				{
					num += 80;
				}
				if (num2 >= (float)Screen.width * 0.9f)
				{
					num += 100;
				}
				if (num3 >= (float)Screen.height * 0.9f)
				{
					num += 100;
				}
				if (IsFullscreenLike(rectTransform))
				{
					num += 400;
				}
			}
			return num;
		}

		internal static void StretchToFullscreen(RectTransform rt)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)rt == (Object)null))
			{
				rt.anchorMin = Vector2.zero;
				rt.anchorMax = Vector2.one;
				rt.pivot = new Vector2(0.5f, 0.5f);
				rt.offsetMin = Vector2.zero;
				rt.offsetMax = Vector2.zero;
				rt.anchoredPosition = Vector2.zero;
				((Transform)rt).localScale = Vector3.one;
				((Transform)rt).localRotation = Quaternion.identity;
			}
		}
	}
	internal static class Hu
	{
		internal const string StartGameLower = "játék indítása";

		internal const string SettingsLower = "beállitások";

		internal const string PatchNotesTitleLower = "frissítési napló";

		internal const string ModdedMarkerLower = "módosított";
	}
	[BepInPlugin("rdmods.mmheim.mainmenu", "MMOHeim Main Menu", "1.0.0")]
	public sealed class MMOHeimMainMenuPlugin : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__61_0;

			internal void <CreateDiscordPanel>b__61_0()
			{
				Application.OpenURL("https://discord.gg/yX9tv3FXY6");
				LogInfo("Discord opened.");
			}
		}

		[CompilerGenerated]
		private sealed class <FadeMusic>d__68 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public float seconds;

			private MMOHeimMainMenuPlugin <plug>5__2;

			private AudioSource <src>5__3;

			private float <v0>5__4;

			private float <t>5__5;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <FadeMusic>d__68(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<plug>5__2 = null;
				<src>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<plug>5__2 = Instance;
					if ((Object)(object)<plug>5__2?._menuMusicSource == (Object)null)
					{
						StopMenuMusic();
						return false;
					}
					<src>5__3 = <plug>5__2._menuMusicSource;
					<v0>5__4 = <src>5__3.volume;
					<t>5__5 = 0f;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (<t>5__5 < seconds && (Object)(object)<src>5__3 != (Object)null)
				{
					<t>5__5 += Time.unscaledDeltaTime;
					<src>5__3.volume = Mathf.Lerp(<v0>5__4, 0f, Mathf.Clamp01(<t>5__5 / seconds));
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				if ((Object)(object)<plug>5__2 != (Object)null)
				{
					<plug>5__2._menuMusicFadeCoroutine = null;
				}
				StopMenuMusic();
				LogInfo("Menu music stopped after fade.");
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <HideUnwantedMainMenuUiDelayed>d__48 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private int <i>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <HideUnwantedMainMenuUiDelayed>d__48(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<i>5__2 = 0;
					break;
				case 1:
					<>1__state = -1;
					<i>5__2++;
					break;
				}
				if (<i>5__2 < 8)
				{
					HideMenuClutterOnce();
					<>2__current = (object)new WaitForSecondsRealtime(0.5f);
					<>1__state = 1;
					return true;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <LoadAndPlayMusic>d__64 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private UnityWebRequest <req>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <LoadAndPlayMusic>d__64(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 2)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<req>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				bool result;
				try
				{
					switch (<>1__state)
					{
					default:
						result = false;
						break;
					case 0:
						<>1__state = -1;
						<>2__current = (object)new WaitForSecondsRealtime(0.1f);
						<>1__state = 1;
						result = true;
						break;
					case 1:
					{
						<>1__state = -1;
						string musicPath = GetMusicPath();
						if (!File.Exists(musicPath))
						{
							LogWarn("mainmenu.ogg missing: " + musicPath);
							result = false;
							break;
						}
						string absoluteUri = new Uri(Path.GetFullPath(musicPath)).AbsoluteUri;
						<req>5__2 = UnityWebRequestMultimedia.GetAudioClip(absoluteUri, (AudioType)14);
						<>1__state = -3;
						<>2__current = <req>5__2.SendWebRequest();
						<>1__state = 2;
						result = true;
						break;
					}
					case 2:
					{
						<>1__state = -3;
						AudioClip content = DownloadHandlerAudioClip.GetContent(<req>5__2);
						if ((Object)(object)content == (Object)null || (Object)(object)Instance == (Object)null)
						{
							LogWarn("Music failed: " + <req>5__2.error);
							result = false;
						}
						else
						{
							EnsureMenuMusicAudio(Instance);
							AudioSource menuMusicSource = Instance._menuMusicSource;
							menuMusicSource.clip = content;
							menuMusicSource.loop = true;
							menuMusicSource.volume = 0.55f;
							if (!menuMusicSource.isPlaying)
							{
								menuMusicSource.Play();
							}
							LogInfo("Menu music playing.");
							if ((Object)(object)Instance != (Object)null)
							{
								Instance._menuMusicStartCoroutine = null;
							}
							result = false;
						}
						<>m__Finally1();
						break;
					}
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<req>5__2 != null)
				{
					((IDisposable)<req>5__2).Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <LoadDiscordLogoDelayed>d__62 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public MMOHeimMainMenuPlugin <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <LoadDiscordLogoDelayed>d__62(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d3: Expected O, but got Unknown
				int num = <>1__state;
				MMOHeimMainMenuPlugin mMOHeimMainMenuPlugin = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					if ((Object)(object)_discordLogoImage == (Object)null)
					{
						return false;
					}
					string discordLogoPath = GetDiscordLogoPath();
					if (!File.Exists(discordLogoPath))
					{
						return false;
					}
					Sprite val = LoadSpriteFromDisk(discordLogoPath);
					if ((Object)(object)val != (Object)null && (Object)(object)_discordLogoImage != (Object)null)
					{
						_discordLogoImage.sprite = val;
						_discordLogoImage.overrideSprite = val;
						_discordLogoImage.type = (Type)0;
						((Graphic)_discordLogoImage).color = Color.white;
						((Graphic)_discordLogoImage).material = null;
						foreach (Transform item in ((Component)_discordLogoImage).transform)
						{
							Transform val2 = item;
							if (((Object)val2).name == "DiscordGlyph")
							{
								((Component)val2).gameObject.SetActive(false);
							}
						}
					}
					mMOHeimMainMenuPlugin._discordLogoCoroutine = null;
					return false;
				}
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <MuteVanillaMenuMusicLoop>d__45 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public float seconds;

			private float <end>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <MuteVanillaMenuMusicLoop>d__45(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<end>5__2 = Time.realtimeSinceStartup + seconds;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (Time.realtimeSinceStartup < <end>5__2 && (Object)(object)Instance != (Object)null)
				{
					MuteVanillaMenuMusicNow();
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <ReplaceLogoDelayed>d__52 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private int <attempt>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ReplaceLogoDelayed>d__52(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Expected O, but got Unknown
				//IL_0124: Unknown result type (might be due to invalid IL or missing references)
				//IL_012e: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSecondsRealtime(0.75f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<attempt>5__2 = 0;
					break;
				case 2:
					<>1__state = -1;
					goto IL_013e;
				case 3:
					{
						<>1__state = -1;
						goto IL_013e;
					}
					IL_013e:
					<attempt>5__2++;
					break;
				}
				if (<attempt>5__2 < 6)
				{
					FejdStartup val = Object.FindFirstObjectByType<FejdStartup>();
					if ((Object)(object)val == (Object)null || !File.Exists(GetLogoPath()))
					{
						<>2__current = (object)new WaitForSecondsRealtime(0.75f);
						<>1__state = 2;
						return true;
					}
					Image val2 = null;
					int num = int.MinValue;
					Image[] componentsInChildren = ((Component)val).GetComponentsInChildren<Image>(true);
					foreach (Image val3 in componentsInChildren)
					{
						if (!((Object)(object)val3 == (Object)null))
						{
							int num2 = ScoreLogo(val3);
							if (num2 > num)
							{
								num = num2;
								val2 = val3;
							}
						}
					}
					if ((Object)(object)val2 != (Object)null && num >= 50)
					{
						Sprite val4 = LoadSpriteFromDisk(GetLogoPath());
						if ((Object)(object)val4 != (Object)null)
						{
							ApplyLogo(val2, val4);
							LogInfo($"Logo applied (score {num}).");
							return false;
						}
					}
					<>2__current = (object)new WaitForSecondsRealtime(0.75f);
					<>1__state = 3;
					return true;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public const string ModGuid = "rdmods.mmheim.mainmenu";

		public const string ModName = "MMOHeim Main Menu";

		public const string AssetFolderName = "MMOheimMainMenu";

		public const string LoadingArtFolderName = "LoadingArt";

		public const int LoadingArtMaxSlot = 12;

		public const string DiscordInviteUrl = "https://discord.gg/yX9tv3FXY6";

		public const string DiscordTitleText = "Need help? Join Discord!";

		public const string DiscordButtonText = "Click here to join Discord!";

		internal static bool MenuMusicFadeCommittedForSession;

		internal static readonly bool EnableCustomLoadingScreens = true;

		private ConfigEntry<bool>? _enableLogging;

		private Harmony? _harmony;

		private GameObject? _menuMusicGo;

		private AudioSource? _menuMusicSource;

		private Coroutine? _menuMusicFadeCoroutine;

		private Coroutine? _menuMusicStartCoroutine;

		private static GameObject? _discordPanel;

		private Coroutine? _discordLogoCoroutine;

		private static Image? _discordLogoImage;

		private static readonly HashSet<string> NeverHide = new HashSet<string>(StringComparer.Ordinal) { "startgui", "worldpanel", "startgame", "topleft", "topright", "menu", "joinpanel", "panel", "tooltips" };

		internal static MMOHeimMainMenuPlugin? Instance { get; private set; }

		internal static ConfigEntry<bool>? ModEnabled { get; private set; }

		internal static ManualLogSource? ModLog { get; private set; }

		private void Awake()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			Instance = this;
			ModLog = ((BaseUnityPlugin)this).Logger;
			MenuMusicFadeCommittedForSession = false;
			ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Turn this mod on or off.");
			_enableLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableLogging", false, "Write informational logs from MMOHeim Main Menu.");
			((BaseUnityPlugin)this).Config.Save();
			if (!ModEnabled.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"MMOHeim Main Menu is disabled in config.");
				return;
			}
			EnsureAssetDirectories();
			_harmony = new Harmony("rdmods.mmheim.mainmenu");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)("MMOHeim Main Menu loaded. Asset root: " + GetAssetRootPath()));
		}

		private void OnDestroy()
		{
			if (_discordLogoCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(_discordLogoCoroutine);
				_discordLogoCoroutine = null;
			}
			if (_menuMusicFadeCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(_menuMusicFadeCoroutine);
				_menuMusicFadeCoroutine = null;
			}
			if (_menuMusicStartCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(_menuMusicStartCoroutine);
				_menuMusicStartCoroutine = null;
			}
			StopMenuMusic();
			Harmony? harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			_harmony = null;
			Instance = null;
		}

		internal static bool TryGetLocalPlayerPresentPlain()
		{
			try
			{
				return (Object)(object)Player.m_localPlayer != (Object)null;
			}
			catch
			{
				return false;
			}
		}

		internal static void CommitMenuMusicFadeForWorldEntry(string trigger)
		{
			if (ModEnabled != null && ModEnabled.Value && !MenuMusicFadeCommittedForSession)
			{
				MenuMusicFadeCommittedForSession = true;
				LogInfo("Stopping menu music (" + trigger + ").");
				FadeOutAndStopMenuMusic();
			}
		}

		internal static bool IsWorldFullyLoaded()
		{
			bool num = TryGetLocalPlayerPresentPlain();
			if (num && !MenuMusicFadeCommittedForSession)
			{
				CommitMenuMusicFadeForWorldEntry("local player in world");
			}
			return num;
		}

		internal static void LogInfo(string message)
		{
			if (Instance?._enableLogging != null && Instance._enableLogging.Value)
			{
				ManualLogSource? modLog = ModLog;
				if (modLog != null)
				{
					modLog.LogInfo((object)message);
				}
			}
		}

		internal static void LogWarn(string message)
		{
			ManualLogSource? modLog = ModLog;
			if (modLog != null)
			{
				modLog.LogWarning((object)message);
			}
		}

		internal static string GetAssetRootPath()
		{
			return Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Instance).Info.Location), "MMOheimMainMenu");
		}

		internal static string GetLoadingArtFolder()
		{
			return Path.Combine(GetAssetRootPath(), "LoadingArt");
		}

		internal static string GetLogoPath()
		{
			return Path.Combine(GetAssetRootPath(), "logo.png");
		}

		internal static string GetDiscordLogoPath()
		{
			return Path.Combine(GetAssetRootPath(), "discordlogo.png");
		}

		internal static string GetMusicPath()
		{
			return Path.Combine(GetAssetRootPath(), "mainmenu.ogg");
		}

		internal static string? GetRandomLoadingArtPath()
		{
			string loadingArtFolder = GetLoadingArtFolder();
			if (!Directory.Exists(loadingArtFolder))
			{
				return null;
			}
			string result = null;
			int num = 0;
			for (int i = 1; i <= 12; i++)
			{
				string text = Path.Combine(loadingArtFolder, $"art{i}.png");
				if (File.Exists(text))
				{
					num++;
					if (num == 1 || Random.Range(0, num) == 0)
					{
						result = text;
					}
				}
			}
			return result;
		}

		private void EnsureAssetDirectories()
		{
			try
			{
				Directory.CreateDirectory(GetAssetRootPath());
				Directory.CreateDirectory(GetLoadingArtFolder());
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not create asset folders: " + ex.Message));
			}
		}

		[IteratorStateMachine(typeof(<MuteVanillaMenuMusicLoop>d__45))]
		internal static IEnumerator MuteVanillaMenuMusicLoop(float seconds)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <MuteVanillaMenuMusicLoop>d__45(0)
			{
				seconds = seconds
			};
		}

		private static void MuteVanillaMenuMusicNow()
		{
			try
			{
				if (!(Resources.FindObjectsOfTypeAll(typeof(AudioSource)) is AudioSource[] array))
				{
					return;
				}
				AudioSource[] array2 = array;
				foreach (AudioSource val in array2)
				{
					if (!((Object)(object)((val != null) ? ((Component)val).gameObject : null) == (Object)null) && !((Object)(object)val == (Object)(object)Instance?._menuMusicSource))
					{
						string text = ((Object)((Component)val).gameObject).name.ToLowerInvariant();
						string text2 = (((Object)(object)val.clip != (Object)null) ? ((Object)val.clip).name.ToLowerInvariant() : string.Empty);
						string text3 = LoadingScreens.GetHierarchyPath(((Component)val).transform).ToLowerInvariant();
						if ((text3.Contains("fejd") || text3.Contains("menu") || text3.Contains("main") || text.Contains("music") || text.Contains("audio") || text2.Contains("menu") || text2.Contains("theme") || text2.Contains("music")) && (val.isPlaying || !(val.volume <= 0.001f)))
						{
							val.volume = 0f;
							val.Stop();
						}
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? modLog = ModLog;
				if (modLog != null)
				{
					modLog.LogError((object)ex);
				}
			}
		}

		[IteratorStateMachine(typeof(<HideUnwantedMainMenuUiDelayed>d__48))]
		internal static IEnumerator HideUnwantedMainMenuUiDelayed()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <HideUnwantedMainMenuUiDelayed>d__48(0);
		}

		private static void HideMenuClutterOnce()
		{
			FejdStartup val = Object.FindFirstObjectByType<FejdStartup>();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Transform[] componentsInChildren = ((Component)val).GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				GameObject gameObject = ((Component)componentsInChildren[i]).gameObject;
				string text = (((Object)gameObject).name ?? string.Empty).ToLowerInvariant();
				if (!NeverHide.Contains(text))
				{
					string lowerOwn = GetOwnText(gameObject).ToLowerInvariant();
					if (ShouldHideUi(text, lowerOwn))
					{
						gameObject.SetActive(false);
					}
				}
			}
		}

		private static bool ShouldHideUi(string lowerName, string lowerOwn)
		{
			bool flag;
			switch (lowerName)
			{
			case "canvas changelog":
			case "changelog":
			case "topic":
			case "patchlogscroll":
				flag = true;
				break;
			default:
				flag = false;
				break;
			}
			if (flag || lowerOwn == "frissítési napló")
			{
				return true;
			}
			if (lowerName.Contains("merch") || lowerName == "valheim.shop" || lowerName == "url" || lowerOwn == "valheim.shop")
			{
				return true;
			}
			if (lowerName == "modded_text" || lowerOwn.Contains("currently playing a modded version") || lowerOwn.Contains("modded version") || lowerOwn.Contains("módosított"))
			{
				return true;
			}
			return false;
		}

		private static string GetOwnText(GameObject go)
		{
			TextMeshProUGUI component = go.GetComponent<TextMeshProUGUI>();
			if ((Object)(object)component != (Object)null && !string.IsNullOrWhiteSpace(((TMP_Text)component).text))
			{
				return ((TMP_Text)component).text.Trim();
			}
			Text component2 = go.GetComponent<Text>();
			if (!((Object)(object)component2 != (Object)null) || string.IsNullOrWhiteSpace(component2.text))
			{
				return string.Empty;
			}
			return component2.text.Trim();
		}

		[IteratorStateMachine(typeof(<ReplaceLogoDelayed>d__52))]
		internal static IEnumerator ReplaceLogoDelayed()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ReplaceLogoDelayed>d__52(0);
		}

		private static int ScoreLogo(Image img)
		{
			//IL_00a6: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			string text = (((Object)((Component)img).gameObject).name ?? "").ToLowerInvariant();
			string text2 = (((Object)(object)img.sprite != (Object)null) ? ((Object)img.sprite).name.ToLowerInvariant() : "");
			int num = 0;
			if (text.Contains("logo"))
			{
				num += 100;
			}
			if (text.Contains("valheim"))
			{
				num += 80;
			}
			if (text2.Contains("logo"))
			{
				num += 50;
			}
			if (((Component)img).gameObject.activeInHierarchy)
			{
				num += 15;
			}
			if (((Behaviour)img).enabled)
			{
				num += 10;
			}
			RectTransform rectTransform = ((Graphic)img).rectTransform;
			if ((Object)(object)rectTransform != (Object)null)
			{
				Rect rect = rectTransform.rect;
				float width = ((Rect)(ref rect)).width;
				rect = rectTransform.rect;
				if (Mathf.Abs(width * ((Rect)(ref rect)).height) > 10000f)
				{
					num += 10;
				}
				if (((Transform)rectTransform).position.y > (float)Screen.height * 0.45f)
				{
					num += 10;
				}
			}
			return num;
		}

		private static Sprite? LoadSpriteFromDisk(string path)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				byte[] data = File.ReadAllBytes(path);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!TextureDecode.LoadImage(val, data, markNonReadable: false))
				{
					Object.Destroy((Object)(object)val);
					return null;
				}
				val.Apply(true, false);
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
			}
			catch (Exception ex)
			{
				LogWarn("logo load: " + ex.Message);
				return null;
			}
		}

		private static void ApplyLogo(Image target, Sprite sp)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			target.sprite = sp;
			target.overrideSprite = sp;
			((Behaviour)target).enabled = true;
			target.preserveAspect = true;
			target.type = (Type)0;
			((Graphic)target).material = null;
			((Graphic)target).color = Color.white;
			if ((Object)(object)((Graphic)target).rectTransform != (Object)null)
			{
				RectTransform rectTransform = ((Graphic)target).rectTransform;
				Rect rect = sp.rect;
				float width = ((Rect)(ref rect)).width;
				rect = sp.rect;
				rectTransform.sizeDelta = new Vector2(width, ((Rect)(ref rect)).height);
				((Transform)((Graphic)target).rectTransform).localScale = Vector3.one;
			}
		}

		internal static TextMeshProUGUI? FindBestMenuTmpText(FejdStartup startup)
		{
			if ((Object)(object)startup == (Object)null)
			{
				return null;
			}
			TextMeshProUGUI result = null;
			int num = int.MinValue;
			TextMeshProUGUI[] componentsInChildren = ((Component)startup).GetComponentsInChildren<TextMeshProUGUI>(true);
			foreach (TextMeshProUGUI val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null))
				{
					string text = (((TMP_Text)val).text ?? "").ToLowerInvariant();
					string text2 = (((Object)((Component)val).gameObject).name ?? "").ToLowerInvariant();
					int num2 = 0;
					if (text.Contains("start game") || text.Contains("játék indítása"))
					{
						num2 += 300;
					}
					if (text.Contains("beállitások") || text.Contains("settings"))
					{
						num2 += 220;
					}
					if (text2.Contains("text"))
					{
						num2 += 20;
					}
					if (((TMP_Text)val).fontSize >= 20f)
					{
						num2 += 15;
					}
					if (num2 > num)
					{
						num = num2;
						result = val;
					}
				}
			}
			return result;
		}

		internal static Button? FindBestVisibleMainMenuButton(FejdStartup startup)
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)startup == (Object)null)
			{
				return null;
			}
			Button result = null;
			int num = int.MinValue;
			Button[] componentsInChildren = ((Component)startup).GetComponentsInChildren<Button>(true);
			foreach (Button val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy)
				{
					continue;
				}
				string text = GetButtonText(((Component)val).gameObject).ToLowerInvariant();
				string text2 = (((Object)((Component)val).gameObject).name ?? "").ToLowerInvariant();
				int num2 = 0;
				if (text.Contains("start game") || text.Contains("játék indítása"))
				{
					num2 += 300;
				}
				if (text.Contains("start") || text2.Contains("start"))
				{
					num2 += 150;
				}
				if (text.Contains("play"))
				{
					num2 += 120;
				}
				RectTransform component = ((Component)val).GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					Rect rect = component.rect;
					float width = ((Rect)(ref rect)).width;
					rect = component.rect;
					if (Mathf.Abs(width * ((Rect)(ref rect)).height) > 5000f)
					{
						num2 += 10;
					}
				}
				if (num2 > num)
				{
					num = num2;
					result = val;
				}
			}
			return result;
		}

		private static string GetButtonText(GameObject go)
		{
			TextMeshProUGUI[] componentsInChildren = go.GetComponentsInChildren<TextMeshProUGUI>(true);
			foreach (TextMeshProUGUI val in componentsInChildren)
			{
				if (!string.IsNullOrWhiteSpace(((TMP_Text)val).text))
				{
					return ((TMP_Text)val).text;
				}
			}
			Text[] componentsInChildren2 = go.GetComponentsInChildren<Text>(true);
			foreach (Text val2 in componentsInChildren2)
			{
				if (!string.IsNullOrWhiteSpace(val2.text))
				{
					return val2.text;
				}
			}
			return "";
		}

		internal static void SetButtonText(GameObject go, string txt)
		{
			TextMeshProUGUI[] componentsInChildren = go.GetComponentsInChildren<TextMeshProUGUI>(true);
			foreach (TextMeshProUGUI obj in componentsInChildren)
			{
				((TMP_Text)obj).richText = false;
				((TMP_Text)obj).text = txt;
			}
			Text[] componentsInChildren2 = go.GetComponentsInChildren<Text>(true);
			foreach (Text obj2 in componentsInChildren2)
			{
				obj2.supportRichText = false;
				obj2.text = txt;
			}
		}

		private static void NormalizeRectForLayoutGroup(RectTransform rt)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			((Transform)rt).localScale = Vector3.one;
			rt.anchorMin = new Vector2(0f, 0f);
			rt.anchorMax = new Vector2(1f, 1f);
			rt.pivot = new Vector2(0.5f, 0.5f);
			rt.anchoredPosition = Vector2.zero;
			rt.offsetMin = Vector2.zero;
			rt.offsetMax = Vector2.zero;
		}

		internal static void CreateDiscordPanel()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Expected O, but got Unknown
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Expected O, but got Unknown
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Expected O, but got Unknown
			try
			{
				if ((Object)(object)_discordPanel != (Object)null)
				{
					_discordPanel.SetActive(true);
					return;
				}
				FejdStartup val = Object.FindFirstObjectByType<FejdStartup>();
				Canvas val2 = Object.FindFirstObjectByType<Canvas>();
				if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)Instance == (Object)null)
				{
					return;
				}
				_discordPanel = new GameObject("MMOHeimDiscordPanel");
				_discordPanel.transform.SetParent(((Component)val2).transform, false);
				RectTransform obj = _discordPanel.AddComponent<RectTransform>();
				obj.anchorMin = new Vector2(1f, 0f);
				obj.anchorMax = new Vector2(1f, 0f);
				obj.pivot = new Vector2(1f, 0f);
				obj.anchoredPosition = new Vector2(-36f, 105f);
				obj.sizeDelta = new Vector2(328f, 360f);
				VerticalLayoutGroup obj2 = _discordPanel.AddComponent<VerticalLayoutGroup>();
				((LayoutGroup)obj2).childAlignment = (TextAnchor)4;
				((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = false;
				((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)obj2).spacing = 16f;
				_discordPanel.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
				TextMeshProUGUI val3 = FindBestMenuTmpText(val);
				GameObject val4 = new GameObject("DiscordTitle", new Type[1] { typeof(RectTransform) });
				val4.transform.SetParent(_discordPanel.transform, false);
				NormalizeRectForLayoutGroup(val4.GetComponent<RectTransform>());
				LayoutElement obj3 = val4.AddComponent<LayoutElement>();
				obj3.flexibleWidth = 1f;
				obj3.preferredWidth = 300f;
				obj3.preferredHeight = 90f;
				TextMeshProUGUI val5 = val4.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val5).richText = false;
				((TMP_Text)val5).text = "Need help? Join Discord!";
				((TMP_Text)val5).horizontalAlignment = (HorizontalAlignmentOptions)2;
				((TMP_Text)val5).verticalAlignment = (VerticalAlignmentOptions)512;
				((TMP_Text)val5).textWrappingMode = (TextWrappingModes)1;
				((TMP_Text)val5).overflowMode = (TextOverflowModes)0;
				((TMP_Text)val5).margin = Vector4.zero;
				((TMP_Text)val5).enableAutoSizing = false;
				((Graphic)val5).raycastTarget = false;
				if ((Object)(object)val3 != (Object)null)
				{
					((TMP_Text)val5).font = ((TMP_Text)val3).font;
					((TMP_Text)val5).fontSharedMaterial = ((TMP_Text)val3).fontSharedMaterial;
					((TMP_Text)val5).fontSize = Mathf.Clamp(((TMP_Text)val3).fontSize - 1f, 16f, 28f);
					((Graphic)val5).color = ((Graphic)val3).color;
				}
				else
				{
					((TMP_Text)val5).fontSize = 22f;
					((Graphic)val5).color = new Color(0.93f, 0.79f, 0.42f);
				}
				GameObject val6 = new GameObject("DiscordLogo");
				val6.transform.SetParent(_discordPanel.transform, false);
				LayoutElement obj4 = val6.AddComponent<LayoutElement>();
				obj4.preferredHeight = 150f;
				obj4.preferredWidth = 300f;
				_discordLogoImage = val6.AddComponent<Image>();
				_discordLogoImage.type = (Type)0;
				((Graphic)_discordLogoImage).color = Color.white;
				((Graphic)_discordLogoImage).material = null;
				_discordLogoImage.preserveAspect = true;
				((Graphic)_discordLogoImage).raycastTarget = false;
				GameObject val7 = new GameObject("DiscordGlyph");
				val7.transform.SetParent(val6.transform, false);
				RectTransform obj5 = val7.AddComponent<RectTransform>();
				obj5.anchorMin = Vector2.zero;
				obj5.anchorMax = Vector2.one;
				Vector2 offsetMin = (obj5.offsetMax = Vector2.zero);
				obj5.offsetMin = offsetMin;
				Text obj6 = val7.AddComponent<Text>();
				obj6.text = "DIS";
				obj6.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
				obj6.fontSize = 24;
				obj6.fontStyle = (FontStyle)1;
				obj6.alignment = (TextAnchor)4;
				((Graphic)obj6).color = Color.white;
				Button val8 = FindBestVisibleMainMenuButton(val);
				if ((Object)(object)val8 != (Object)null)
				{
					GameObject val9 = Object.Instantiate<GameObject>(((Component)val8).gameObject, _discordPanel.transform, false);
					LayoutElement obj7 = val9.GetComponent<LayoutElement>() ?? val9.AddComponent<LayoutElement>();
					obj7.preferredWidth = 300f;
					obj7.preferredHeight = 46f;
					Button component = val9.GetComponent<Button>();
					if ((Object)(object)component != (Object)null)
					{
						component.onClick = new ButtonClickedEvent();
						ButtonClickedEvent onClick = component.onClick;
						object obj8 = <>c.<>9__61_0;
						if (obj8 == null)
						{
							UnityAction val10 = delegate
							{
								Application.OpenURL("https://discord.gg/yX9tv3FXY6");
								LogInfo("Discord opened.");
							};
							<>c.<>9__61_0 = val10;
							obj8 = (object)val10;
						}
						((UnityEvent)onClick).AddListener((UnityAction)obj8);
						SetButtonText(val9, "Click here to join Discord!");
					}
				}
				Instance._discordLogoCoroutine = ((MonoBehaviour)Instance).StartCoroutine(Instance.LoadDiscordLogoDelayed());
				LogInfo("Discord panel ready.");
			}
			catch (Exception ex)
			{
				ManualLogSource? modLog = ModLog;
				if (modLog != null)
				{
					modLog.LogError((object)("Discord panel failed: " + ex));
				}
			}
		}

		[IteratorStateMachine(typeof(<LoadDiscordLogoDelayed>d__62))]
		private IEnumerator LoadDiscordLogoDelayed()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadDiscordLogoDelayed>d__62(0)
			{
				<>4__this = this
			};
		}

		internal static void StartMenuMusic()
		{
			if (!((Object)(object)Instance == (Object)null))
			{
				if (Instance._menuMusicStartCoroutine != null)
				{
					((MonoBehaviour)Instance).StopCoroutine(Instance._menuMusicStartCoroutine);
					Instance._menuMusicStartCoroutine = null;
				}
				Instance._menuMusicStartCoroutine = ((MonoBehaviour)Instance).StartCoroutine(LoadAndPlayMusic());
			}
		}

		[IteratorStateMachine(typeof(<LoadAndPlayMusic>d__64))]
		private static IEnumerator LoadAndPlayMusic()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadAndPlayMusic>d__64(0);
		}

		private static void EnsureMenuMusicAudio(MMOHeimMainMenuPlugin plug)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			if (!((Object)(object)plug._menuMusicSource != (Object)null) || !((Object)(object)plug._menuMusicGo != (Object)null))
			{
				plug._menuMusicGo = new GameObject("MMOHeimMenuMusicAudio");
				Object.DontDestroyOnLoad((Object)(object)plug._menuMusicGo);
				plug._menuMusicSource = plug._menuMusicGo.AddComponent<AudioSource>();
				plug._menuMusicSource.playOnAwake = false;
				plug._menuMusicSource.loop = true;
				plug._menuMusicSource.spatialBlend = 0f;
			}
		}

		internal static void StopMenuMusic()
		{
			MMOHeimMainMenuPlugin instance = Instance;
			if ((Object)(object)instance?._menuMusicSource != (Object)null)
			{
				instance._menuMusicSource.Stop();
				instance._menuMusicSource.clip = null;
			}
			if ((Object)(object)instance?._menuMusicGo != (Object)null)
			{
				Object.Destroy((Object)(object)instance._menuMusicGo);
				instance._menuMusicGo = null;
				instance._menuMusicSource = null;
			}
		}

		internal static void FadeOutAndStopMenuMusic()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				StopMenuMusic();
				return;
			}
			if ((Object)(object)Instance._menuMusicSource == (Object)null || (Object)(object)Instance._menuMusicGo == (Object)null)
			{
				StopMenuMusic();
				return;
			}
			if (Instance._menuMusicFadeCoroutine != null)
			{
				((MonoBehaviour)Instance).StopCoroutine(Instance._menuMusicFadeCoroutine);
				Instance._menuMusicFadeCoroutine = null;
			}
			Instance._menuMusicFadeCoroutine = ((MonoBehaviour)Instance).StartCoroutine(FadeMusic(2.25f));
		}

		[IteratorStateMachine(typeof(<FadeMusic>d__68))]
		private static IEnumerator FadeMusic(float seconds)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <FadeMusic>d__68(0)
			{
				seconds = seconds
			};
		}
	}
	internal static class TextureDecode
	{
		private static bool _triedResolve;

		private static MethodInfo? _loadImageThree;

		private static MethodInfo? _loadImageTwo;

		internal static bool LoadImage(Texture2D tex, byte[] data, bool markNonReadable)
		{
			EnsureResolved();
			if (_loadImageThree != null)
			{
				return (bool)_loadImageThree.Invoke(null, new object[3] { tex, data, markNonReadable });
			}
			if (_loadImageTwo != null)
			{
				return (bool)_loadImageTwo.Invoke(null, new object[2] { tex, data });
			}
			return false;
		}

		private static void EnsureResolved()
		{
			if (_triedResolve)
			{
				return;
			}
			_triedResolve = true;
			Type type = null;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				if (!(assembly.GetName().Name != "UnityEngine.ImageConversionModule"))
				{
					type = assembly.GetType("UnityEngine.ImageConversion");
					break;
				}
			}
			if (!(type == null))
			{
				_loadImageThree = type.GetMethod("LoadImage", BindingFlags.Static | BindingFlags.Public, null, new Type[3]
				{
					typeof(Texture2D),
					typeof(byte[]),
					typeof(bool)
				}, null);
				if (_loadImageThree == null)
				{
					_loadImageTwo = type.GetMethod("LoadImage", BindingFlags.Static | BindingFlags.Public, null, new Type[2]
					{
						typeof(Texture2D),
						typeof(byte[])
					}, null);
				}
			}
		}
	}
}
namespace MMOHeimMainMenu.Patches
{
	[HarmonyPatch(typeof(FejdStartup), "Start")]
	public static class FejdStartup_Start_Postfix
	{
		private static void Postfix(FejdStartup __instance)
		{
			if (MMOHeimMainMenuPlugin.ModEnabled != null && MMOHeimMainMenuPlugin.ModEnabled.Value)
			{
				if ((Object)(object)__instance == (Object)null)
				{
					MMOHeimMainMenuPlugin.LogWarn("FejdStartup.Start: instance null.");
					return;
				}
				MMOHeimMainMenuPlugin.MenuMusicFadeCommittedForSession = false;
				LoadingScreens.ResetForMainMenu();
				MMOHeimMainMenuPlugin.LogInfo("FejdStartup.Start: menu opened.");
				((MonoBehaviour)__instance).StartCoroutine(MMOHeimMainMenuPlugin.ReplaceLogoDelayed());
				((MonoBehaviour)__instance).StartCoroutine(MMOHeimMainMenuPlugin.HideUnwantedMainMenuUiDelayed());
				MMOHeimMainMenuPlugin.CreateDiscordPanel();
				((MonoBehaviour)__instance).StartCoroutine(MMOHeimMainMenuPlugin.MuteVanillaMenuMusicLoop(6f));
				MMOHeimMainMenuPlugin.StartMenuMusic();
			}
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "OnWorldStart")]
	public static class FejdStartup_OnWorldStart_Postfix
	{
		private static void Postfix()
		{
			if (MMOHeimMainMenuPlugin.ModEnabled != null && MMOHeimMainMenuPlugin.ModEnabled.Value)
			{
				MMOHeimMainMenuPlugin.LogInfo("FejdStartup.OnWorldStart.");
				LoadingScreens.TryStartLoadingScreenWatcher();
			}
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "OnJoinStart")]
	public static class FejdStartup_OnJoinStart_Postfix
	{
		private static void Postfix()
		{
			if (MMOHeimMainMenuPlugin.ModEnabled != null && MMOHeimMainMenuPlugin.ModEnabled.Value)
			{
				MMOHeimMainMenuPlugin.LogInfo("FejdStartup.OnJoinStart.");
				MMOHeimMainMenuPlugin.CommitMenuMusicFadeForWorldEntry("FejdStartup.OnJoinStart");
				LoadingScreens.TryStartLoadingScreenWatcher();
			}
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "OnCharacterStart")]
	public static class FejdStartup_OnCharacterStart_Postfix
	{
		private static void Postfix()
		{
			if (MMOHeimMainMenuPlugin.ModEnabled != null && MMOHeimMainMenuPlugin.ModEnabled.Value)
			{
				MMOHeimMainMenuPlugin.LogInfo("FejdStartup.OnCharacterStart.");
				LoadingScreens.TryStartLoadingScreenWatcher();
			}
		}
	}
	[HarmonyPatch(typeof(Valkyrie), "Awake")]
	public static class Valkyrie_Awake_Postfix
	{
		private static void Postfix()
		{
			if (MMOHeimMainMenuPlugin.ModEnabled != null && MMOHeimMainMenuPlugin.ModEnabled.Value)
			{
				MMOHeimMainMenuPlugin.CommitMenuMusicFadeForWorldEntry("Valkyrie.Awake (setting up valkyrie)");
			}
		}
	}
}