Decompiled source of GlitnirMenu v1.2.2

GlitnirMenu.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("GlitnirMenu")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GlitnirMenu")]
[assembly: AssemblyTitle("GlitnirMenu")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace GlitnirMenu
{
	internal static class CameraManager
	{
		private static Vector3 _defaultCharPos;

		private static Vector3 _defaultCredPos;

		private static Vector3 _defaultGamePos;

		private static Vector3 _defaultMainPos;

		private static Vector3 _defaultStartPos;

		private static Vector3 _defaultSavesPos;

		private static Vector3 _defaultCharRot;

		private static Vector3 _defaultCredRot;

		private static Vector3 _defaultGameRot;

		private static Vector3 _defaultMainRot;

		private static Vector3 _defaultStartRot;

		private static Vector3 _defaultSavesRot;

		private static readonly Vector3 PresetCharPos = new Vector3(-206.2f, 39.34f, 162.26f);

		private static readonly Vector3 PresetCharRot = new Vector3(19.6f, -211f, 0f);

		private static readonly Vector3 PresetCredPos = new Vector3(-205.3f, 34.29f, 132.06f);

		private static readonly Vector3 PresetCredRot = new Vector3(19.6f, -211f, 0f);

		private static readonly Vector3 PresetMainPos = new Vector3(-208.54f, 32.2f, 131.38f);

		private static readonly Vector3 PresetMainRot = new Vector3(0.72f, -211f, 0f);

		private static readonly Vector3 PresetGamePos = new Vector3(-204.55f, 38f, 158.8f);

		private static readonly Vector3 PresetGameRot = new Vector3(-181.447f, -48.532f, -180f);

		private static readonly Vector3 PresetSavesPos = new Vector3(-208.45f, 45.76f, 131.23f);

		private static readonly Vector3 PresetSavesRot = new Vector3(0.72f, -211f, 131.23f);

		private static readonly Vector3 PresetPlayerPos = new Vector3(-204.51f, 36.5f, 157.53f);

		internal static void GatherDefaults(FejdStartup startup)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			_defaultCharPos = startup.m_cameraMarkerCharacter.position;
			_defaultCredPos = startup.m_cameraMarkerCredits.position;
			_defaultGamePos = startup.m_cameraMarkerGame.position;
			_defaultMainPos = startup.m_cameraMarkerMain.position;
			_defaultStartPos = startup.m_cameraMarkerStart.position;
			_defaultSavesPos = startup.m_cameraMarkerSaves.position;
			Quaternion rotation = startup.m_cameraMarkerCharacter.rotation;
			_defaultCharRot = ((Quaternion)(ref rotation)).eulerAngles;
			rotation = startup.m_cameraMarkerCredits.rotation;
			_defaultCredRot = ((Quaternion)(ref rotation)).eulerAngles;
			rotation = startup.m_cameraMarkerGame.rotation;
			_defaultGameRot = ((Quaternion)(ref rotation)).eulerAngles;
			rotation = startup.m_cameraMarkerMain.rotation;
			_defaultMainRot = ((Quaternion)(ref rotation)).eulerAngles;
			rotation = startup.m_cameraMarkerStart.rotation;
			_defaultStartRot = ((Quaternion)(ref rotation)).eulerAngles;
			rotation = startup.m_cameraMarkerSaves.rotation;
			_defaultSavesRot = ((Quaternion)(ref rotation)).eulerAngles;
		}

		internal static void ApplyConfigValues()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)FejdStartup.instance == (Object)null))
			{
				FejdStartup instance = FejdStartup.instance;
				instance.m_cameraMarkerCharacter.position = GlitnirMenuPlugin.CharacterCameraMarker_Position.Value;
				instance.m_cameraMarkerCredits.position = GlitnirMenuPlugin.CreditsCameraMarker_Position.Value;
				instance.m_cameraMarkerGame.position = GlitnirMenuPlugin.GameCameraMarker_Position.Value;
				instance.m_cameraMarkerMain.position = GlitnirMenuPlugin.MainCameraMarker_Position.Value;
				instance.m_cameraMarkerStart.position = GlitnirMenuPlugin.StartCameraMarker_Position.Value;
				instance.m_cameraMarkerSaves.position = GlitnirMenuPlugin.SavesCameraMarker_Position.Value;
				instance.m_cameraMarkerCharacter.rotation = Quaternion.Euler(GlitnirMenuPlugin.CharacterCameraMarker_Rotation.Value);
				instance.m_cameraMarkerCredits.rotation = Quaternion.Euler(GlitnirMenuPlugin.CreditsCameraMarker_Rotation.Value);
				instance.m_cameraMarkerGame.rotation = Quaternion.Euler(GlitnirMenuPlugin.GameCameraMarker_Rotation.Value);
				instance.m_cameraMarkerMain.rotation = Quaternion.Euler(GlitnirMenuPlugin.MainCameraMarker_Rotation.Value);
				instance.m_cameraMarkerStart.rotation = Quaternion.Euler(GlitnirMenuPlugin.StartCameraMarker_Rotation.Value);
				instance.m_cameraMarkerSaves.rotation = Quaternion.Euler(GlitnirMenuPlugin.SavesCameraMarker_Rotation.Value);
			}
		}

		internal static void ApplyPlayerValues()
		{
			//IL_001d: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)FejdStartup.instance == (Object)null))
			{
				FejdStartup.instance.m_characterPreviewPoint.position = GlitnirMenuPlugin.MPlayerPosition.Value;
				FejdStartup.instance.m_characterPreviewPoint.rotation = Quaternion.Euler(GlitnirMenuPlugin.MPlayerRotation.Value);
			}
		}

		internal static void ApplyAndSync()
		{
			bool flag = GlitnirMenuPlugin.UsePreset.Value == GlitnirMenuPlugin.Toggle.On;
			bool flag2 = GlitnirMenuPlugin.UseVanilla.Value == GlitnirMenuPlugin.Toggle.On;
			if (flag && !flag2)
			{
				ApplyPreset();
			}
			else if (flag2 && !flag)
			{
				ApplyVanilla();
			}
			ApplyConfigValues();
			ApplyPlayerValues();
		}

		internal static void ApplyPreset()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_0032: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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)
			GlitnirMenuPlugin.CharacterCameraMarker_Position.Value = PresetCharPos;
			GlitnirMenuPlugin.CreditsCameraMarker_Position.Value = PresetCredPos;
			GlitnirMenuPlugin.GameCameraMarker_Position.Value = PresetGamePos;
			GlitnirMenuPlugin.MainCameraMarker_Position.Value = PresetMainPos;
			GlitnirMenuPlugin.StartCameraMarker_Position.Value = PresetMainPos;
			GlitnirMenuPlugin.SavesCameraMarker_Position.Value = PresetSavesPos;
			GlitnirMenuPlugin.CharacterCameraMarker_Rotation.Value = PresetCharRot;
			GlitnirMenuPlugin.CreditsCameraMarker_Rotation.Value = PresetCredRot;
			GlitnirMenuPlugin.GameCameraMarker_Rotation.Value = PresetGameRot;
			GlitnirMenuPlugin.MainCameraMarker_Rotation.Value = PresetMainRot;
			GlitnirMenuPlugin.StartCameraMarker_Rotation.Value = PresetMainRot;
			GlitnirMenuPlugin.SavesCameraMarker_Rotation.Value = PresetSavesRot;
			GlitnirMenuPlugin.MPlayerPosition.Value = PresetPlayerPos;
		}

		internal static void ApplyVanilla()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_0032: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			GlitnirMenuPlugin.CharacterCameraMarker_Position.Value = _defaultCharPos;
			GlitnirMenuPlugin.CreditsCameraMarker_Position.Value = _defaultCredPos;
			GlitnirMenuPlugin.GameCameraMarker_Position.Value = _defaultGamePos;
			GlitnirMenuPlugin.MainCameraMarker_Position.Value = _defaultMainPos;
			GlitnirMenuPlugin.StartCameraMarker_Position.Value = _defaultStartPos;
			GlitnirMenuPlugin.SavesCameraMarker_Position.Value = _defaultSavesPos;
			GlitnirMenuPlugin.CharacterCameraMarker_Rotation.Value = _defaultCharRot;
			GlitnirMenuPlugin.CreditsCameraMarker_Rotation.Value = _defaultCredRot;
			GlitnirMenuPlugin.GameCameraMarker_Rotation.Value = _defaultGameRot;
			GlitnirMenuPlugin.MainCameraMarker_Rotation.Value = _defaultMainRot;
			GlitnirMenuPlugin.StartCameraMarker_Rotation.Value = _defaultStartRot;
			GlitnirMenuPlugin.SavesCameraMarker_Rotation.Value = _defaultSavesRot;
		}

		internal static bool HandleCameraLock(FejdStartup instance)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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 (GlitnirMenuPlugin.CameraLockEnabled.Value != GlitnirMenuPlugin.Toggle.On)
			{
				return true;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "start")
			{
				return true;
			}
			Camera val = Camera.main ?? ((Camera.allCameras.Length != 0) ? Camera.allCameras[0] : null);
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			Transform cameraMarkerCharacter = instance.m_cameraMarkerCharacter;
			if ((Object)(object)cameraMarkerCharacter == (Object)null)
			{
				return true;
			}
			Vector3 val2 = cameraMarkerCharacter.position + GlitnirMenuPlugin.CameraLockOffset.Value;
			Quaternion rotation = cameraMarkerCharacter.rotation;
			float value = GlitnirMenuPlugin.CameraLockBackOffset.Value;
			if (!Mathf.Approximately(value, 0f))
			{
				val2 -= cameraMarkerCharacter.forward * value;
			}
			float value2 = GlitnirMenuPlugin.CameraLockSmoothing.Value;
			if (value2 > 0f)
			{
				((Component)val).transform.position = Vector3.Lerp(((Component)val).transform.position, val2, Time.deltaTime / value2);
				((Component)val).transform.rotation = Quaternion.Slerp(((Component)val).transform.rotation, rotation, Time.deltaTime / value2);
			}
			else
			{
				((Component)val).transform.position = val2;
				((Component)val).transform.rotation = rotation;
			}
			return GlitnirMenuPlugin.CameraLockAllScreens.Value != GlitnirMenuPlugin.Toggle.On;
		}
	}
	internal static class DiscordPanel
	{
		private static GameObject _panel;

		private static Image _logoImage;

		private static Texture2D _logoTexture;

		private static Sprite _logoSprite;

		internal static void BuildOrRefresh(FejdStartup fejd)
		{
			if (!((Object)(object)fejd == (Object)null))
			{
				if (GlitnirMenuPlugin.DiscordPanelEnabled.Value != GlitnirMenuPlugin.Toggle.On)
				{
					Destroy();
				}
				else if ((Object)(object)_panel != (Object)null)
				{
					Refresh(fejd);
				}
				else
				{
					Build(fejd);
				}
			}
		}

		internal static void Rebuild(FejdStartup fejd)
		{
			Destroy();
			BuildOrRefresh(fejd);
		}

		internal static void Refresh(FejdStartup fejd)
		{
			if (!((Object)(object)_panel == (Object)null))
			{
				bool active = (Object)(object)fejd != (Object)null && (Object)(object)fejd.m_mainMenu != (Object)null && fejd.m_mainMenu.activeInHierarchy;
				_panel.SetActive(active);
			}
		}

		internal static void Destroy()
		{
			if ((Object)(object)_panel != (Object)null)
			{
				Object.Destroy((Object)(object)_panel);
				_panel = null;
			}
			if ((Object)(object)_logoSprite != (Object)null)
			{
				Object.Destroy((Object)(object)_logoSprite);
				_logoSprite = null;
			}
			if ((Object)(object)_logoTexture != (Object)null)
			{
				Object.Destroy((Object)(object)_logoTexture);
				_logoTexture = null;
			}
			_logoImage = null;
		}

		private static void Build(FejdStartup fejd)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0055: 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)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Expected O, but got Unknown
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Canvas val = Object.FindFirstObjectByType<Canvas>();
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				_panel = new GameObject("GlitnirDiscordPanel");
				_panel.transform.SetParent(((Component)val).transform, false);
				RectTransform val2 = _panel.AddComponent<RectTransform>();
				val2.anchorMin = new Vector2(1f, 0f);
				val2.anchorMax = new Vector2(1f, 0f);
				val2.pivot = new Vector2(1f, 0f);
				val2.anchoredPosition = new Vector2(GlitnirMenuPlugin.DiscordPosX.Value, GlitnirMenuPlugin.DiscordPosY.Value);
				val2.sizeDelta = new Vector2(GlitnirMenuPlugin.DiscordLogoWidth.Value + 20f, GlitnirMenuPlugin.DiscordLogoHeight.Value + 20f);
				GameObject val3 = new GameObject("DiscordLogo");
				val3.transform.SetParent(_panel.transform, false);
				RectTransform val4 = val3.AddComponent<RectTransform>();
				val4.anchorMin = Vector2.zero;
				val4.anchorMax = Vector2.one;
				val4.offsetMin = Vector2.zero;
				val4.offsetMax = Vector2.zero;
				_logoImage = val3.AddComponent<Image>();
				_logoImage.preserveAspect = true;
				((Graphic)_logoImage).color = Color.white;
				LoadLogoSprite();
				string url = GlitnirMenuPlugin.DiscordInviteUrl.Value;
				if (!string.IsNullOrWhiteSpace(url))
				{
					Button val5 = val3.AddComponent<Button>();
					((UnityEvent)val5.onClick).AddListener((UnityAction)delegate
					{
						Application.OpenURL(url);
					});
					ColorBlock colors = ((Selectable)val5).colors;
					((ColorBlock)(ref colors)).normalColor = Color.white;
					((ColorBlock)(ref colors)).highlightedColor = new Color(0.8f, 0.8f, 0.8f, 1f);
					((ColorBlock)(ref colors)).pressedColor = new Color(0.6f, 0.6f, 0.6f, 1f);
					((Selectable)val5).colors = colors;
					((Selectable)val5).targetGraphic = (Graphic)(object)_logoImage;
				}
				Refresh(fejd);
				GlitnirMenuPlugin.Log.LogInfo((object)"[DiscordPanel] Painel do Discord criado.");
			}
			catch (Exception ex)
			{
				GlitnirMenuPlugin.Log.LogError((object)("[DiscordPanel] Erro ao criar painel: " + ex.Message));
			}
		}

		private static void LoadLogoSprite()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(GlitnirMenuPlugin.AssetRoot, "discord", "discord_logo.png");
			if (!File.Exists(path))
			{
				return;
			}
			try
			{
				if ((Object)(object)_logoSprite != (Object)null)
				{
					Object.Destroy((Object)(object)_logoSprite);
					_logoSprite = null;
				}
				if ((Object)(object)_logoTexture != (Object)null)
				{
					Object.Destroy((Object)(object)_logoTexture);
					_logoTexture = null;
				}
				_logoTexture = new Texture2D(2, 2);
				ImageConversion.LoadImage(_logoTexture, File.ReadAllBytes(path));
				_logoSprite = Sprite.Create(_logoTexture, new Rect(0f, 0f, (float)((Texture)_logoTexture).width, (float)((Texture)_logoTexture).height), new Vector2(0.5f, 0.5f), 100f);
				if ((Object)(object)_logoImage != (Object)null)
				{
					_logoImage.sprite = _logoSprite;
				}
			}
			catch (Exception ex)
			{
				GlitnirMenuPlugin.Log.LogWarning((object)("[DiscordPanel] Erro ao carregar logo: " + ex.Message));
			}
		}
	}
	[BepInPlugin("Padilha.GlitnirMenu", "GlitnirMenu", "1.2.0")]
	public class GlitnirMenuPlugin : BaseUnityPlugin
	{
		public enum Toggle
		{
			On = 1,
			Off = 0
		}

		private const string ModGUID = "Padilha.GlitnirMenu";

		public static readonly string AssetRoot;

		public static readonly string LoadingArtFolder;

		public static readonly string TeleportArtFolder;

		private static readonly string ConfigFileFullPath;

		private readonly Harmony _harmony = new Harmony("Padilha.GlitnirMenu");

		private FileSystemWatcher _cfgWatcher;

		private FileSystemWatcher _pngWatcher;

		private EventHandler _reloadLogoHandler;

		private EventHandler _rebuildDiscordHandler;

		private EventHandler _onCamChangeHandler;

		private EventHandler _onPlayerChangeHandler;

		internal static TMP_FontAsset CapturedMenuFont;

		private static readonly Dictionary<string, string[]> _artFilesCache;

		private static ConfigEntry<Toggle> _modEnabled;

		private static ConfigEntry<string> _mainLogoFile;

		public static ConfigEntry<float> MainLogoWidth;

		public static ConfigEntry<float> MainLogoHeight;

		public static ConfigEntry<float> MainLogoOffsetY;

		public static ConfigEntry<Toggle> LogoPulseEnabled;

		public static ConfigEntry<float> LogoPulseSpeed;

		public static ConfigEntry<float> LogoPulseMin;

		public static ConfigEntry<float> LogoPulseMax;

		public static ConfigEntry<string> DiscordInviteUrl;

		public static ConfigEntry<Toggle> DiscordPanelEnabled;

		public static ConfigEntry<float> DiscordLogoWidth;

		public static ConfigEntry<float> DiscordLogoHeight;

		public static ConfigEntry<float> DiscordPosX;

		public static ConfigEntry<float> DiscordPosY;

		public static ConfigEntry<Toggle> DiscordPulseEnabled;

		public static ConfigEntry<float> DiscordPulseSpeed;

		public static ConfigEntry<float> DiscordPulseMin;

		public static ConfigEntry<float> DiscordPulseMax;

		public static ConfigEntry<Toggle> LoadingScreenEnabled;

		public static ConfigEntry<Toggle> SlideshowEnabled;

		public static ConfigEntry<float> SlideshowInterval;

		public static ConfigEntry<Toggle> TeleportScreenEnabled;

		public static ConfigEntry<Toggle> HideChangelog;

		public static ConfigEntry<Toggle> HideMerchStore;

		public static ConfigEntry<Toggle> HideModdedWarning;

		public static ConfigEntry<string> WelcomePanelTitle;

		public static ConfigEntry<string> WelcomePanelMessage;

		public static ConfigEntry<int> WelcomeServerMaxPlayers;

		public static ConfigEntry<string> WelcomeServerIP;

		public static ConfigEntry<int> WelcomeServerQueryPort;

		public static ConfigEntry<Toggle> WelcomePanelEnabled;

		public static ConfigEntry<float> WelcomePanelWidth;

		public static ConfigEntry<float> WelcomePanelHeight;

		public static ConfigEntry<float> WelcomePanelPosX;

		public static ConfigEntry<float> WelcomePanelPosY;

		public static ConfigEntry<Toggle> UsePreset;

		public static ConfigEntry<Toggle> UseVanilla;

		public static ConfigEntry<Vector3> CharacterCameraMarker_Position;

		public static ConfigEntry<Vector3> CreditsCameraMarker_Position;

		public static ConfigEntry<Vector3> GameCameraMarker_Position;

		public static ConfigEntry<Vector3> MainCameraMarker_Position;

		public static ConfigEntry<Vector3> StartCameraMarker_Position;

		public static ConfigEntry<Vector3> SavesCameraMarker_Position;

		public static ConfigEntry<Vector3> CharacterCameraMarker_Rotation;

		public static ConfigEntry<Vector3> CreditsCameraMarker_Rotation;

		public static ConfigEntry<Vector3> GameCameraMarker_Rotation;

		public static ConfigEntry<Vector3> MainCameraMarker_Rotation;

		public static ConfigEntry<Vector3> StartCameraMarker_Rotation;

		public static ConfigEntry<Vector3> SavesCameraMarker_Rotation;

		public static ConfigEntry<Vector3> MPlayerPosition;

		public static ConfigEntry<Vector3> MPlayerRotation;

		public static ConfigEntry<Toggle> CameraLockEnabled;

		public static ConfigEntry<Toggle> CameraLockAllScreens;

		public static ConfigEntry<Vector3> CameraLockOffset;

		public static ConfigEntry<float> CameraLockBackOffset;

		public static ConfigEntry<float> CameraLockSmoothing;

		public static ConfigEntry<Toggle> DeersEnabled;

		public static ConfigEntry<string> Criatura1PrefabName;

		public static ConfigEntry<float> Criatura1AlturaOffset;

		public static ConfigEntry<string> Criatura2PrefabName;

		public static ConfigEntry<float> Criatura2AlturaOffset;

		public static GlitnirMenuPlugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		public static string MainLogoFile => _mainLogoFile.Value;

		public void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			EnsureFolders();
			RegisterConfigs(new ConfigFile(ConfigFileFullPath, true));
			TransformHelper.Init();
			WelcomePanel.ResetPollingFlag();
			WelcomePanel.ResetSeparatorCache();
			WelcomePanel.ResetPlayerCount();
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			ZNetViewAwakeGuard.Init(_harmony);
			SetupWatchers();
		}

		private void OnDestroy()
		{
			try
			{
				_harmony.UnpatchSelf();
			}
			catch
			{
			}
			LoadingOverlay.Destroy();
			DiscordPanel.Destroy();
			WelcomePanel.Destroy();
			MenuCreatures.DestroyAll();
			LogoManager.Unload();
			WelcomePanel.ResetSeparatorCache();
			WelcomePanel.ResetPlayerCount();
			TransformHelper.ClearCache();
			if (_reloadLogoHandler != null)
			{
				_mainLogoFile.SettingChanged -= _reloadLogoHandler;
				_modEnabled.SettingChanged -= _reloadLogoHandler;
				MainLogoWidth.SettingChanged -= _reloadLogoHandler;
				MainLogoHeight.SettingChanged -= _reloadLogoHandler;
				MainLogoOffsetY.SettingChanged -= _reloadLogoHandler;
			}
			if (_rebuildDiscordHandler != null)
			{
				DiscordLogoWidth.SettingChanged -= _rebuildDiscordHandler;
				DiscordLogoHeight.SettingChanged -= _rebuildDiscordHandler;
				DiscordPanelEnabled.SettingChanged -= _rebuildDiscordHandler;
				DiscordPosX.SettingChanged -= _rebuildDiscordHandler;
				DiscordPosY.SettingChanged -= _rebuildDiscordHandler;
			}
			if (_onCamChangeHandler != null)
			{
				CharacterCameraMarker_Position.SettingChanged -= _onCamChangeHandler;
				CreditsCameraMarker_Position.SettingChanged -= _onCamChangeHandler;
				GameCameraMarker_Position.SettingChanged -= _onCamChangeHandler;
				MainCameraMarker_Position.SettingChanged -= _onCamChangeHandler;
				StartCameraMarker_Position.SettingChanged -= _onCamChangeHandler;
				SavesCameraMarker_Position.SettingChanged -= _onCamChangeHandler;
				CharacterCameraMarker_Rotation.SettingChanged -= _onCamChangeHandler;
				CreditsCameraMarker_Rotation.SettingChanged -= _onCamChangeHandler;
				GameCameraMarker_Rotation.SettingChanged -= _onCamChangeHandler;
				MainCameraMarker_Rotation.SettingChanged -= _onCamChangeHandler;
				StartCameraMarker_Rotation.SettingChanged -= _onCamChangeHandler;
				SavesCameraMarker_Rotation.SettingChanged -= _onCamChangeHandler;
			}
			if (_onPlayerChangeHandler != null)
			{
				MPlayerPosition.SettingChanged -= _onPlayerChangeHandler;
				MPlayerRotation.SettingChanged -= _onPlayerChangeHandler;
			}
			if (_cfgWatcher != null)
			{
				_cfgWatcher.EnableRaisingEvents = false;
				_cfgWatcher.Dispose();
				_cfgWatcher = null;
			}
			if (_pngWatcher != null)
			{
				_pngWatcher.EnableRaisingEvents = false;
				_pngWatcher.Dispose();
				_pngWatcher = null;
			}
		}

		private void RegisterConfigs(ConfigFile cfg)
		{
			//IL_05e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0615: Unknown result type (might be due to invalid IL or missing references)
			//IL_0644: Unknown result type (might be due to invalid IL or missing references)
			//IL_0673: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0700: Unknown result type (might be due to invalid IL or missing references)
			//IL_072f: Unknown result type (might be due to invalid IL or missing references)
			//IL_075e: Unknown result type (might be due to invalid IL or missing references)
			//IL_078d: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_07eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_092e: Unknown result type (might be due to invalid IL or missing references)
			//IL_09cb: Unknown result type (might be due to invalid IL or missing references)
			_modEnabled = C<Toggle>("01 - Geral", "Mod Ativado", Toggle.On, "Ativa ou desativa o GlitnirMenu.");
			_mainLogoFile = C<string>("02 - Logo", "Logo Principal", "GlitnirMenu_Logo.png", "Nome do arquivo PNG da logo. Coloque em BepInEx/config/GlitnirMenu/images/menu/");
			MainLogoWidth = C<float>("02 - Logo", "Logo Largura", 700f, "Largura em pixels da logo. 0 = tamanho original.");
			MainLogoHeight = C<float>("02 - Logo", "Logo Altura", 700f, "Altura em pixels da logo. 0 = tamanho original.");
			MainLogoOffsetY = C<float>("02 - Logo", "Logo Posicao Y", 550f, "Desloca a logo verticalmente. Positivo = sobe.");
			LogoPulseEnabled = C<Toggle>("02 - Logo", "Pulsar Ativado", Toggle.On, "Anima a logo com um pulso suave.");
			LogoPulseSpeed = C<float>("02 - Logo", "Pulsar Velocidade", 1.2f, "Velocidade do pulso.");
			LogoPulseMin = C<float>("02 - Logo", "Pulsar Escala Min", 0.95f, "Escala mínima do pulso.");
			LogoPulseMax = C<float>("02 - Logo", "Pulsar Escala Max", 1.05f, "Escala máxima do pulso.");
			_reloadLogoHandler = delegate
			{
				LogoManager.ForceReload(_mainLogoFile.Value);
			};
			_mainLogoFile.SettingChanged += _reloadLogoHandler;
			_modEnabled.SettingChanged += _reloadLogoHandler;
			MainLogoWidth.SettingChanged += _reloadLogoHandler;
			MainLogoHeight.SettingChanged += _reloadLogoHandler;
			MainLogoOffsetY.SettingChanged += _reloadLogoHandler;
			DiscordPanelEnabled = C<Toggle>("04 - Discord", "Painel Ativado", Toggle.On, "Mostra o painel do Discord no menu principal.");
			DiscordInviteUrl = C<string>("04 - Discord", "Link do Servidor", "", "Link de convite do Discord (https://discord.gg/...). Deixe vazio para desativar o botão.");
			DiscordLogoWidth = C<float>("04 - Discord", "Logo Largura", 400f, "Largura em pixels da imagem do Discord no menu.");
			DiscordLogoHeight = C<float>("04 - Discord", "Logo Altura", 200f, "Altura em pixels. | IMAGEM: coloque em BepInEx/config/GlitnirMenu/images/discord/discord_logo.png (nome obrigatorio: discord_logo.png)");
			DiscordPosX = C<float>("04 - Discord", "Posicao X", 50f, "Posição horizontal.");
			DiscordPosY = C<float>("04 - Discord", "Posicao Y", 50f, "Posição vertical.");
			DiscordPulseEnabled = C<Toggle>("04 - Discord", "Pulsar Ativado", Toggle.On, "Anima a logo do Discord com um pulso suave.");
			DiscordPulseSpeed = C<float>("04 - Discord", "Pulsar Velocidade", 0.8f, "Velocidade do pulso.");
			DiscordPulseMin = C<float>("04 - Discord", "Pulsar Escala Min", 0.93f, "Escala mínima.");
			DiscordPulseMax = C<float>("04 - Discord", "Pulsar Escala Max", 1.07f, "Escala máxima.");
			_rebuildDiscordHandler = delegate
			{
				if ((Object)(object)FejdStartup.instance != (Object)null)
				{
					DiscordPanel.Rebuild(FejdStartup.instance);
				}
			};
			DiscordLogoWidth.SettingChanged += _rebuildDiscordHandler;
			DiscordLogoHeight.SettingChanged += _rebuildDiscordHandler;
			DiscordPanelEnabled.SettingChanged += _rebuildDiscordHandler;
			DiscordPosX.SettingChanged += _rebuildDiscordHandler;
			DiscordPosY.SettingChanged += _rebuildDiscordHandler;
			LoadingScreenEnabled = C<Toggle>("03 - Loading Screen", "Ativado", Toggle.On, "Exibe imagem personalizada durante carregamento.");
			TeleportScreenEnabled = C<Toggle>("03 - Loading Screen", "Tela de Teleporte", Toggle.On, "Exibe imagem personalizada durante teleporte.");
			SlideshowEnabled = C<Toggle>("03 - Loading Screen", "Slideshow Ativado", Toggle.On, "Troca as imagens automaticamente.");
			SlideshowInterval = C<float>("03 - Loading Screen", "Slideshow Intervalo", 4f, "Segundos entre cada troca de imagem.");
			HideChangelog = C<Toggle>("05 - Esconder", "Esconder Changelog", Toggle.On, "Esconde o painel de notas de atualização.");
			HideMerchStore = C<Toggle>("05 - Esconder", "Esconder Merch Store", Toggle.On, "Esconde o link da loja oficial.");
			HideModdedWarning = C<Toggle>("05 - Esconder", "Esconder Aviso de Mod", Toggle.On, "Esconde o aviso de versão modificada.");
			WelcomePanelTitle = C<string>("11 - Painel Boas-vindas", "Titulo", "⚔ GLITNIR FANTASY ⚔", "Título exibido no painel.");
			WelcomePanelMessage = C<string>("11 - Painel Boas-vindas", "Mensagem", "O eco das trombetas de guerra ressoa e os corvos de Odin trazem a notícia: sua jornada em Valheim começou! Você acaba de atracar em Glitnir, um reino moldado pelo aço, pela magia e pela glória. Aqui, não somos apenas sobreviventes; somos construtores de impérios, caçadores de feras lendárias e irmãos de armas. Seja você um mestre construtor que ergue fortalezas impenetráveis, um guerreiro implacável pronto para encarar os piores perigos dos biomas mais sombrios, ou um alquimista focado em poções e estratégias avançadas, o seu lugar é aqui", "Mensagem de boas-vindas.");
			WelcomeServerMaxPlayers = C<int>("11 - Painel Boas-vindas", "Max Players", 100, "Capacidade máxima do servidor.");
			WelcomeServerIP = C<string>("11 - Painel Boas-vindas", "Servidor IP", "177.54.147.114", "IP do servidor Valheim.");
			WelcomeServerQueryPort = C<int>("11 - Painel Boas-vindas", "Servidor Porta Query", 24445, "Porta de query Steam (porta do jogo + 1).");
			WelcomePanelEnabled = C<Toggle>("11 - Painel Boas-vindas", "Ativado", Toggle.On, "Ativa o painel de boas-vindas.");
			WelcomePanelWidth = C<float>("11 - Painel Boas-vindas", "Largura", 320f, "Largura do painel em pixels.");
			WelcomePanelHeight = C<float>("11 - Painel Boas-vindas", "Altura", 500f, "Altura do painel em pixels.");
			WelcomePanelPosX = C<float>("11 - Painel Boas-vindas", "Posicao X", 5f, "Posição horizontal do painel.");
			WelcomePanelPosY = C<float>("11 - Painel Boas-vindas", "Posicao Y", 130f, "Posição vertical do painel.");
			UsePreset = C<Toggle>("06 - Presets", "Usar Preset", Toggle.On, "Usa as posições de câmera do preset Glitnir.");
			UseVanilla = C<Toggle>("06 - Presets", "Usar Vanilla", Toggle.Off, "Usa as posições de câmera originais do Valheim.");
			UsePreset.SettingChanged += delegate
			{
				if (UsePreset.Value == Toggle.On)
				{
					UseVanilla.Value = Toggle.Off;
				}
				CameraManager.ApplyAndSync();
			};
			UseVanilla.SettingChanged += delegate
			{
				if (UseVanilla.Value == Toggle.On)
				{
					UsePreset.Value = Toggle.Off;
				}
				CameraManager.ApplyAndSync();
			};
			CharacterCameraMarker_Position = C<Vector3>("07 - Câmeras Posição", "Character", new Vector3(-161.89f, 55.97f, 230.13f), "");
			CreditsCameraMarker_Position = C<Vector3>("07 - Câmeras Posição", "Credits", new Vector3(-156.86f, 78.89f, 225.68f), "");
			GameCameraMarker_Position = C<Vector3>("07 - Câmeras Posição", "Game", new Vector3(-157.85f, 56.59f, 229.93f), "");
			MainCameraMarker_Position = C<Vector3>("07 - Câmeras Posição", "Main", new Vector3(-142.53f, 59f, 227.72f), "");
			StartCameraMarker_Position = C<Vector3>("07 - Câmeras Posição", "Start", new Vector3(-137.63f, 54.78f, 227.44f), "");
			SavesCameraMarker_Position = C<Vector3>("07 - Câmeras Posição", "Saves", new Vector3(-163.02f, 60.34f, 228.74f), "");
			CharacterCameraMarker_Rotation = C<Vector3>("08 - Câmeras Rotação", "Character", new Vector3(13.79f, -84.748f, 0f), "");
			CreditsCameraMarker_Rotation = C<Vector3>("08 - Câmeras Rotação", "Credits", new Vector3(-2.197f, -48.48f, 0f), "");
			GameCameraMarker_Rotation = C<Vector3>("08 - Câmeras Rotação", "Game", new Vector3(-187.257f, 77.72f, 180f), "");
			MainCameraMarker_Rotation = C<Vector3>("08 - Câmeras Rotação", "Main", new Vector3(1.241f, -84.232f, 0f), "");
			StartCameraMarker_Rotation = C<Vector3>("08 - Câmeras Rotação", "Start", new Vector3(41.028f, -84.232f, 0f), "");
			SavesCameraMarker_Rotation = C<Vector3>("08 - Câmeras Rotação", "Saves", new Vector3(185.79f, 81.743f, -180f), "");
			_onCamChangeHandler = delegate
			{
				CameraManager.ApplyConfigValues();
			};
			CharacterCameraMarker_Position.SettingChanged += _onCamChangeHandler;
			CreditsCameraMarker_Position.SettingChanged += _onCamChangeHandler;
			GameCameraMarker_Position.SettingChanged += _onCamChangeHandler;
			MainCameraMarker_Position.SettingChanged += _onCamChangeHandler;
			StartCameraMarker_Position.SettingChanged += _onCamChangeHandler;
			SavesCameraMarker_Position.SettingChanged += _onCamChangeHandler;
			CharacterCameraMarker_Rotation.SettingChanged += _onCamChangeHandler;
			CreditsCameraMarker_Rotation.SettingChanged += _onCamChangeHandler;
			GameCameraMarker_Rotation.SettingChanged += _onCamChangeHandler;
			MainCameraMarker_Rotation.SettingChanged += _onCamChangeHandler;
			StartCameraMarker_Rotation.SettingChanged += _onCamChangeHandler;
			SavesCameraMarker_Rotation.SettingChanged += _onCamChangeHandler;
			MPlayerPosition = C<Vector3>("09 - Player", "Posição", new Vector3(-204.51f, 36.5f, 157.53f), "");
			MPlayerRotation = C<Vector3>("09 - Player", "Rotação", new Vector3(13.79f, -84.748f, 0f), "");
			_onPlayerChangeHandler = delegate
			{
				CameraManager.ApplyPlayerValues();
			};
			MPlayerPosition.SettingChanged += _onPlayerChangeHandler;
			MPlayerRotation.SettingChanged += _onPlayerChangeHandler;
			CameraLockEnabled = C<Toggle>("12 - Camera Lock", "Ativado", Toggle.Off, "Trava a câmera no marker Character.");
			CameraLockAllScreens = C<Toggle>("12 - Camera Lock", "Travar em Todas as Telas", Toggle.On, "Se On, trava em todas as telas.");
			CameraLockOffset = C<Vector3>("12 - Camera Lock", "Offset", Vector3.zero, "Offset adicional sobre o marker.");
			CameraLockBackOffset = C<float>("12 - Camera Lock", "Recuo", 0f, "Recua a câmera no eixo de visão.");
			CameraLockSmoothing = C<float>("12 - Camera Lock", "Suavizacao", 0f, "Suavização do lock. 0 = instantâneo.");
			DeersEnabled = C<Toggle>("13 - Cervos", "Ativado", Toggle.On, "Spawna criaturas no menu principal.");
			Criatura1PrefabName = C<string>("13 - Cervos", "Criatura 1 Prefab", "Deer", "Nome do prefab da Criatura 1. Ex: Deer, Boar, Wolf, Neck, Blob...");
			Criatura1AlturaOffset = C<float>("13 - Cervos", "Criatura 1 Altura", 0.3f, "Offset de altura da Criatura 1.");
			Criatura2PrefabName = C<string>("13 - Cervos", "Criatura 2 Prefab", "Eikthyr", "Nome do prefab da Criatura 2. Ex: Eikthyr, Troll, BlobElite, Skeleton...");
			Criatura2AlturaOffset = C<float>("13 - Cervos", "Criatura 2 Altura", 1f, "Offset de altura da Criatura 2.");
			ConfigEntry<T> C<T>(string s, string k, T d, string desc)
			{
				return cfg.Bind<T>(s, k, d, desc);
			}
		}

		private void SetupWatchers()
		{
			_cfgWatcher = new FileSystemWatcher(Path.GetDirectoryName(ConfigFileFullPath), "GlitnirMenu.cfg");
			_cfgWatcher.IncludeSubdirectories = false;
			_cfgWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			_cfgWatcher.EnableRaisingEvents = true;
			_pngWatcher = new FileSystemWatcher(AssetRoot, "*.png");
			_pngWatcher.Changed += delegate
			{
				LogoManager.ForceReload(_mainLogoFile.Value);
				InvalidateArtCache();
			};
			_pngWatcher.Created += delegate
			{
				LogoManager.ForceReload(_mainLogoFile.Value);
				InvalidateArtCache();
			};
			_pngWatcher.Renamed += delegate
			{
				LogoManager.ForceReload(_mainLogoFile.Value);
				InvalidateArtCache();
			};
			_pngWatcher.IncludeSubdirectories = true;
			_pngWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			_pngWatcher.EnableRaisingEvents = true;
		}

		internal static bool IsStartScene()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			return ((Scene)(ref activeScene)).name == "start";
		}

		internal static TMP_FontAsset GetMenuFont()
		{
			if ((Object)(object)CapturedMenuFont != (Object)null)
			{
				return CapturedMenuFont;
			}
			TextMeshProUGUI val = Object.FindFirstObjectByType<TextMeshProUGUI>();
			if ((Object)(object)((val != null) ? ((TMP_Text)val).font : null) != (Object)null)
			{
				return ((TMP_Text)val).font;
			}
			TMP_FontAsset val2 = Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
			TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			if (array == null || array.Length == 0)
			{
				return null;
			}
			return array[0];
		}

		internal static void HideClutter(FejdStartup fejd)
		{
			if ((Object)(object)fejd == (Object)null)
			{
				return;
			}
			bool flag = HideChangelog.Value == Toggle.On;
			bool flag2 = HideMerchStore.Value == Toggle.On;
			bool flag3 = HideModdedWarning.Value == Toggle.On;
			if (!flag && !flag2 && !flag3)
			{
				return;
			}
			Transform[] componentsInChildren = ((Component)fejd).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				GameObject gameObject = ((Component)val).gameObject;
				string text = (((Object)gameObject).name ?? "").ToLowerInvariant();
				if (flag)
				{
					switch (text)
					{
					case "canvas changelog":
					case "changelog":
					case "patchlogscroll":
					case "topic":
						gameObject.SetActive(false);
						continue;
					}
				}
				if (flag2 && (text.Contains("merch") || text == "valheim.shop"))
				{
					gameObject.SetActive(false);
					continue;
				}
				if (flag3 && text == "modded_text")
				{
					gameObject.SetActive(false);
					continue;
				}
				string goText = GetGoText(gameObject);
				if (!string.IsNullOrEmpty(goText))
				{
					goText = goText.ToLowerInvariant();
					if (flag && (goText.Contains("patch note") || goText.Contains("notas de atualiza")))
					{
						gameObject.SetActive(false);
					}
					else if (flag2 && (goText.Contains("valheim.shop") || goText.Contains("merch")))
					{
						gameObject.SetActive(false);
					}
					else if (flag3 && (goText.Contains("modded version") || goText.Contains("versão modificada") || goText.Contains("módosított")))
					{
						gameObject.SetActive(false);
					}
				}
			}
		}

		internal static void InvalidateArtCache()
		{
			_artFilesCache.Clear();
		}

		internal static string GetRandomArtPath(string folder)
		{
			if (!Directory.Exists(folder))
			{
				return null;
			}
			if (!_artFilesCache.TryGetValue(folder, out var value))
			{
				value = (from f in Directory.GetFiles(folder)
					where f.EndsWith(".png", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase)
					select f).ToArray();
				_artFilesCache[folder] = value;
			}
			if (value.Length != 0)
			{
				return value[Random.Range(0, value.Length)];
			}
			return null;
		}

		private static string GetGoText(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 component2.text.Trim();
			}
			return "";
		}

		private static void EnsureFolders()
		{
			Directory.CreateDirectory(AssetRoot);
			Directory.CreateDirectory(LoadingArtFolder);
			Directory.CreateDirectory(TeleportArtFolder);
			Directory.CreateDirectory(Path.Combine(AssetRoot, "discord"));
			Directory.CreateDirectory(Path.Combine(AssetRoot, "menu"));
		}

		static GlitnirMenuPlugin()
		{
			_artFilesCache = new Dictionary<string, string[]>();
			string path = Path.Combine(Paths.ConfigPath, "GlitnirMenu");
			ConfigFileFullPath = Path.Combine(path, "GlitnirMenu.cfg");
			AssetRoot = Path.Combine(path, "images");
			LoadingArtFolder = Path.Combine(AssetRoot, "loading");
			TeleportArtFolder = Path.Combine(AssetRoot, "teleport");
		}
	}
	internal class CanvasCoroutineRunner : MonoBehaviour
	{
	}
	internal static class ZNetViewAwakeGuard
	{
		private static Harmony _harmony;

		private static MethodInfo _targetMethod;

		private static HarmonyMethod _prefixMethod;

		private static bool _isPatched;

		internal static void Init(Harmony harmony)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0065: 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)
			_harmony = harmony;
			_targetMethod = AccessTools.Method(typeof(ZNetView), "Awake", (Type[])null, (Type[])null);
			_prefixMethod = new HarmonyMethod(typeof(ZNetViewAwakeGuard).GetMethod("Prefix", BindingFlags.Static | BindingFlags.NonPublic));
			SceneManager.activeSceneChanged += delegate(Scene _, Scene next)
			{
				Sync(((Scene)(ref next)).name);
			};
			Scene activeScene = SceneManager.GetActiveScene();
			Sync(((Scene)(ref activeScene)).name);
		}

		private static void Sync(string name)
		{
			if (name == "start")
			{
				Apply();
			}
			else
			{
				Remove();
			}
		}

		private static void Apply()
		{
			if (!_isPatched)
			{
				_harmony.Patch((MethodBase)_targetMethod, _prefixMethod, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_isPatched = true;
			}
		}

		private static void Remove()
		{
			if (_isPatched)
			{
				_harmony.Unpatch((MethodBase)_targetMethod, (HarmonyPatchType)1, _harmony.Id);
				_isPatched = false;
			}
		}

		private static bool Prefix()
		{
			return false;
		}
	}
	internal static class LoadingOverlay
	{
		internal static bool DeathRespawnHappened;

		private static Image _wolfFillImage;

		private static TextMeshProUGUI _progressTMP;

		private static Text _progressLegacy;

		private static float _progressValue;

		private static RawImage _rawImage;

		private static CanvasGroup _group;

		private static CanvasCoroutineRunner _runner;

		private static Texture2D _texture;

		private static Hud _cachedHud;

		private static Transform _cachedLoadingGuiTransform;

		private const float TeleportTimeoutSeconds = 8f;

		private static float _teleportSafetyTimer = 0f;

		private static readonly (float t, string msg)[] LoadingMessages = new(float, string)[11]
		{
			(0f, "Acendendo as forjas de Glitnir..."),
			(0.1f, "Invocando os corvos de Odin..."),
			(0.2f, "Navegando pelos mares de Midgard..."),
			(0.3f, "Despertando os espíritos ancestrais..."),
			(0.4f, "Forjando os laços entre os reinos..."),
			(0.5f, "Preparando os nove reinos..."),
			(0.6f, "Convocando os guerreiros vikings..."),
			(0.7f, "Erguendo as muralhas de Glitnir..."),
			(0.8f, "Abrindo os portões sagrados..."),
			(0.9f, "Valhalla está quase pronto..."),
			(0.99f, "Os portões de Glitnir se abrem!")
		};

		private static readonly (float t, string msg)[] TeleportMessages = new(float, string)[4]
		{
			(0f, "Atravessando o portal..."),
			(0.3f, "Viajando entre os reinos..."),
			(0.6f, "Chegando ao destino..."),
			(0.9f, "Aterrissando em segurança...")
		};

		private static bool _hiding = false;

		internal static GameObject Root { get; private set; }

		internal static float TargetProgress { get; private set; }

		internal static bool IsActive => (Object)(object)Root != (Object)null;

		internal static bool IsTeleport
		{
			get
			{
				if ((Object)(object)Root != (Object)null)
				{
					return ((Object)Root).name == "GlitnirMenu_TeleportOverlay";
				}
				return false;
			}
		}

		internal static bool IsDeath
		{
			get
			{
				if ((Object)(object)Root != (Object)null)
				{
					return ((Object)Root).name == "GlitnirMenu_DeathOverlay";
				}
				return false;
			}
		}

		internal static bool IsLoading
		{
			get
			{
				if ((Object)(object)Root != (Object)null)
				{
					return ((Object)Root).name == "GlitnirMenu_LoadingOverlay";
				}
				return false;
			}
		}

		internal static void KeepTeleportAlive()
		{
			_teleportSafetyTimer = 0f;
		}

		internal static void ShowLoading()
		{
			if (GlitnirMenuPlugin.LoadingScreenEnabled.Value == GlitnirMenuPlugin.Toggle.On)
			{
				TargetProgress = 0f;
				_progressValue = 0f;
				Create("GlitnirMenu_LoadingOverlay", GlitnirMenuPlugin.LoadingArtFolder, SimulateLoadingProgress, hideVanilla: true);
			}
		}

		internal static void ShowDeath()
		{
			if (GlitnirMenuPlugin.LoadingScreenEnabled.Value == GlitnirMenuPlugin.Toggle.On)
			{
				DeathRespawnHappened = false;
				Create("GlitnirMenu_DeathOverlay", GlitnirMenuPlugin.LoadingArtFolder, SimulateDeathProgress);
			}
		}

		internal static void ShowTeleport()
		{
			try
			{
				if (GlitnirMenuPlugin.TeleportScreenEnabled.Value == GlitnirMenuPlugin.Toggle.On)
				{
					TargetProgress = 0f;
					_progressValue = 0f;
					Create("GlitnirMenu_TeleportOverlay", GlitnirMenuPlugin.TeleportArtFolder, SimulateTeleportProgress, hideVanilla: true);
				}
			}
			catch (Exception ex)
			{
				GlitnirMenuPlugin.Log.LogWarning((object)("[LoadingOverlay] Erro no teleport overlay: " + ex.Message));
			}
		}

		internal static void Hide()
		{
			if (!((Object)(object)Root == (Object)null) && !_hiding)
			{
				if ((Object)(object)_runner != (Object)null)
				{
					_hiding = true;
					((MonoBehaviour)_runner).StartCoroutine(FadeAndDestroy(0.5f));
				}
				else
				{
					Destroy();
					RestoreVanillaLoadingGui();
				}
			}
		}

		internal static void SetCheckpoint(float target, string label)
		{
			if (!(target <= TargetProgress))
			{
				TargetProgress = target;
				GlitnirMenuPlugin.Log.LogInfo((object)$"[GlitnirMenu] Checkpoint: {label} ({Mathf.RoundToInt(target * 100f)}%)");
			}
		}

		internal static void HideVanillaGui(Hud hud)
		{
			try
			{
				Transform val = TransformHelper.FindChild(((Component)hud).transform, "LoadingGUI");
				if (!((Object)(object)val == (Object)null))
				{
					CanvasGroup val2 = ((Component)val).gameObject.GetComponent<CanvasGroup>() ?? ((Component)val).gameObject.AddComponent<CanvasGroup>();
					val2.alpha = 0f;
					val2.blocksRaycasts = false;
				}
			}
			catch (Exception ex)
			{
				GlitnirMenuPlugin.Log.LogWarning((object)("[LoadingOverlay] HideVanillaGui: " + ex.Message));
			}
		}

		internal static void Destroy()
		{
			if ((Object)(object)Root != (Object)null)
			{
				Object.Destroy((Object)(object)Root);
				Root = null;
			}
			if ((Object)(object)_texture != (Object)null)
			{
				Object.Destroy((Object)(object)_texture);
				_texture = null;
			}
			_rawImage = null;
			_group = null;
			_runner = null;
			_wolfFillImage = null;
			_progressTMP = null;
			_progressLegacy = null;
			_progressValue = 0f;
			TargetProgress = 0f;
			_hiding = false;
		}

		private static bool Create(string rootName, string artFolder, Func<IEnumerator> progressRoutine, bool hideVanilla = false)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			string randomArtPath = GlitnirMenuPlugin.GetRandomArtPath(artFolder);
			if (string.IsNullOrEmpty(randomArtPath))
			{
				return false;
			}
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, File.ReadAllBytes(randomArtPath));
			if (((Texture)val).width <= 2)
			{
				Object.Destroy((Object)(object)val);
				return false;
			}
			Destroy();
			_texture = val;
			Root = new GameObject(rootName);
			Object.DontDestroyOnLoad((Object)(object)Root);
			Canvas val2 = Root.AddComponent<Canvas>();
			val2.renderMode = (RenderMode)0;
			val2.sortingOrder = 9999;
			Root.AddComponent<CanvasScaler>().uiScaleMode = (ScaleMode)1;
			Root.AddComponent<GraphicRaycaster>();
			((Graphic)AddFullRect("BG", Root.transform).AddComponent<Image>()).color = Color.black;
			GameObject val3 = AddFullRect("Art", Root.transform);
			_rawImage = val3.AddComponent<RawImage>();
			_rawImage.texture = (Texture)(object)val;
			_rawImage.uvRect = CalcUvRect(val);
			_group = val3.AddComponent<CanvasGroup>();
			_group.alpha = 0f;
			_runner = Root.AddComponent<CanvasCoroutineRunner>();
			((MonoBehaviour)_runner).StartCoroutine(FadeOverlay(0f, 1f, 0.5f));
			((MonoBehaviour)_runner).StartCoroutine(progressRoutine());
			if (hideVanilla)
			{
				((MonoBehaviour)_runner).StartCoroutine(HideVanillaLoadingGuiCoroutine());
			}
			ConfigEntry<GlitnirMenuPlugin.Toggle> slideshowEnabled = GlitnirMenuPlugin.SlideshowEnabled;
			if (slideshowEnabled != null && slideshowEnabled.Value == GlitnirMenuPlugin.Toggle.On)
			{
				((MonoBehaviour)_runner).StartCoroutine(SlideshowCoroutine(artFolder));
			}
			AddProgressBar();
			GlitnirMenuPlugin.Log.LogInfo((object)("[GlitnirMenu] Overlay '" + rootName + "' exibido: " + randomArtPath));
			return true;
		}

		private static IEnumerator SimulateLoadingProgress()
		{
			TargetProgress = 0.05f;
			while ((Object)(object)Root != (Object)null && (Object)(object)Player.m_localPlayer == (Object)null)
			{
				_progressValue = Mathf.MoveTowards(_progressValue, TargetProgress, Time.unscaledDeltaTime * 0.04f);
				UpdateProgressBar();
				yield return null;
			}
			TargetProgress = 1f;
			while ((Object)(object)Root != (Object)null && _progressValue < 1f)
			{
				_progressValue = Mathf.MoveTowards(_progressValue, 1f, Time.unscaledDeltaTime * 0.5f);
				UpdateProgressBar();
				yield return null;
			}
			UpdateProgressBar();
		}

		private static IEnumerator SimulateTeleportProgress()
		{
			TargetProgress = 0.1f;
			_teleportSafetyTimer = 0f;
			while ((Object)(object)Root != (Object)null && TargetProgress < 1f)
			{
				_teleportSafetyTimer += Time.unscaledDeltaTime;
				if (_teleportSafetyTimer >= 8f)
				{
					GlitnirMenuPlugin.Log.LogWarning((object)("[LoadingOverlay] Timeout: nenhum sinal de progresso do teleporte por " + $"{8f:F0}s (travado em {Mathf.RoundToInt(TargetProgress * 100f)}%) — forçando fechamento do overlay."));
					TargetProgress = 1f;
					break;
				}
				_progressValue = Mathf.MoveTowards(_progressValue, TargetProgress, Time.unscaledDeltaTime * 0.04f);
				UpdateProgressBar();
				yield return null;
			}
			while ((Object)(object)Root != (Object)null && _progressValue < 1f)
			{
				_progressValue = Mathf.MoveTowards(_progressValue, 1f, Time.unscaledDeltaTime * 0.5f);
				UpdateProgressBar();
				yield return null;
			}
			UpdateProgressBar();
			if ((Object)(object)Root != (Object)null && IsTeleport)
			{
				yield return (object)new WaitForSecondsRealtime(0.4f);
				if ((Object)(object)Root != (Object)null && IsTeleport)
				{
					Hide();
				}
			}
		}

		private static IEnumerator SimulateDeathProgress()
		{
			TargetProgress = 0.05f;
			while ((Object)(object)Root != (Object)null && !DeathRespawnHappened)
			{
				_progressValue = Mathf.MoveTowards(_progressValue, TargetProgress, Time.unscaledDeltaTime * 0.04f);
				UpdateProgressBar();
				yield return null;
			}
			TargetProgress = 1f;
			while ((Object)(object)Root != (Object)null && _progressValue < 1f)
			{
				_progressValue = Mathf.MoveTowards(_progressValue, 1f, Time.unscaledDeltaTime * 0.5f);
				UpdateProgressBar();
				yield return null;
			}
			UpdateProgressBar();
		}

		private static IEnumerator SlideshowCoroutine(string folder)
		{
			SlideshowState state = new SlideshowState();
			BeginPreload(folder, state);
			while ((Object)(object)Root != (Object)null)
			{
				float interval = GlitnirMenuPlugin.SlideshowInterval?.Value ?? 4f;
				float elapsed = 0f;
				while (elapsed < interval || !state.Loaded)
				{
					if ((Object)(object)Root == (Object)null)
					{
						yield break;
					}
					elapsed += Time.unscaledDeltaTime;
					yield return null;
				}
				if ((Object)(object)Root == (Object)null)
				{
					break;
				}
				ConfigEntry<GlitnirMenuPlugin.Toggle> slideshowEnabled = GlitnirMenuPlugin.SlideshowEnabled;
				if (slideshowEnabled == null || slideshowEnabled.Value != GlitnirMenuPlugin.Toggle.On)
				{
					break;
				}
				byte[] bytes = state.Bytes;
				state = new SlideshowState();
				BeginPreload(folder, state);
				if (bytes == null)
				{
					continue;
				}
				Texture2D tex = new Texture2D(2, 2);
				ImageConversion.LoadImage(tex, bytes);
				if (((Texture)tex).width <= 2)
				{
					Object.Destroy((Object)(object)tex);
					continue;
				}
				if ((Object)(object)_group != (Object)null)
				{
					float t = 0f;
					while (t < 0.4f && (Object)(object)_group != (Object)null)
					{
						_group.alpha = Mathf.Lerp(1f, 0f, t / 0.4f);
						t += Time.unscaledDeltaTime;
						yield return null;
					}
					if ((Object)(object)_group != (Object)null)
					{
						_group.alpha = 0f;
					}
				}
				if ((Object)(object)_rawImage != (Object)null)
				{
					if ((Object)(object)_texture != (Object)null)
					{
						Object.Destroy((Object)(object)_texture);
					}
					_texture = tex;
					_rawImage.texture = (Texture)(object)tex;
					_rawImage.uvRect = CalcUvRect(tex);
				}
				if ((Object)(object)_group != (Object)null)
				{
					float t = 0f;
					while (t < 0.4f && (Object)(object)_group != (Object)null)
					{
						_group.alpha = Mathf.Lerp(0f, 1f, t / 0.4f);
						t += Time.unscaledDeltaTime;
						yield return null;
					}
					if ((Object)(object)_group != (Object)null)
					{
						_group.alpha = 1f;
					}
				}
			}
		}

		private static void BeginPreload(string folder, SlideshowState state)
		{
			string path = GlitnirMenuPlugin.GetRandomArtPath(folder);
			if (string.IsNullOrEmpty(path))
			{
				state.Loaded = true;
				return;
			}
			ThreadPool.QueueUserWorkItem(delegate
			{
				try
				{
					state.Bytes = File.ReadAllBytes(path);
				}
				catch
				{
				}
				Thread.MemoryBarrier();
				state.Loaded = true;
			});
		}

		private static void AddProgressBar()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Expected O, but got Unknown
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: 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_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Expected O, but got Unknown
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)GlitnirMenuPlugin.CapturedMenuFont == (Object)null)
				{
					GlitnirMenuPlugin.CapturedMenuFont = GlitnirMenuPlugin.GetMenuFont();
				}
				GameObject val = new GameObject("WolfBarContainer");
				val.transform.SetParent(Root.transform, false);
				RectTransform val2 = val.AddComponent<RectTransform>();
				val2.anchorMin = new Vector2(0.5f, 0f);
				val2.anchorMax = new Vector2(0.5f, 0f);
				val2.pivot = new Vector2(0.5f, 0f);
				val2.anchoredPosition = new Vector2(0f, -15f);
				val2.sizeDelta = new Vector2(480f, 45f);
				GameObject val3 = new GameObject("WolfBar");
				val3.transform.SetParent(val.transform, false);
				Image val4 = val3.AddComponent<Image>();
				val4.sprite = MakeSprite(WolfBarAssets.WolfBarFull);
				val4.preserveAspect = false;
				RectTransform component = val3.GetComponent<RectTransform>();
				component.anchorMin = Vector2.zero;
				component.anchorMax = Vector2.one;
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				GameObject val5 = new GameObject("Fill");
				val5.transform.SetParent(val.transform, false);
				_wolfFillImage = val5.AddComponent<Image>();
				_wolfFillImage.sprite = MakeSprite(WolfBarAssets.FillBar);
				_wolfFillImage.type = (Type)3;
				_wolfFillImage.fillMethod = (FillMethod)0;
				_wolfFillImage.fillOrigin = 0;
				_wolfFillImage.fillAmount = 0f;
				_wolfFillImage.preserveAspect = false;
				RectTransform component2 = val5.GetComponent<RectTransform>();
				component2.anchorMin = new Vector2(0.007f, 0.056f);
				component2.anchorMax = new Vector2(0.993f, 0.969f);
				component2.offsetMin = Vector2.zero;
				component2.offsetMax = Vector2.zero;
				GameObject val6 = new GameObject("ProgressText");
				val6.transform.SetParent(val.transform, false);
				RectTransform val7 = val6.AddComponent<RectTransform>();
				val7.anchorMin = new Vector2(0.058f, 0.72f);
				val7.anchorMax = new Vector2(0.938f, 1.1f);
				val7.pivot = new Vector2(0.5f, 0.5f);
				val7.anchoredPosition = Vector2.zero;
				val7.sizeDelta = Vector2.zero;
				if ((Object)(object)GlitnirMenuPlugin.CapturedMenuFont != (Object)null)
				{
					TextMeshProUGUI val8 = val6.AddComponent<TextMeshProUGUI>();
					((TMP_Text)val8).text = "Acendendo as forjas de Glitnir...  0%";
					((TMP_Text)val8).font = GlitnirMenuPlugin.CapturedMenuFont;
					((TMP_Text)val8).fontSize = 14.4f;
					((TMP_Text)val8).fontStyle = (FontStyles)0;
					((TMP_Text)val8).alignment = (TextAlignmentOptions)514;
					((Graphic)val8).color = new Color(0.95f, 0.93f, 0.88f, 1f);
					Material val9 = new Material(((TMP_Text)val8).fontSharedMaterial);
					val9.EnableKeyword("UNDERLAY_ON");
					val9.SetColor("_UnderlayColor", new Color(0f, 0f, 0f, 0.95f));
					val9.SetFloat("_UnderlayOffsetX", 2f);
					val9.SetFloat("_UnderlayOffsetY", -2f);
					val9.SetFloat("_UnderlaySoftness", 0.2f);
					((TMP_Text)val8).fontMaterial = val9;
					((TMP_Text)val8).textWrappingMode = (TextWrappingModes)0;
					_progressTMP = val8;
					_progressLegacy = null;
				}
				else
				{
					Text val10 = val6.AddComponent<Text>();
					val10.text = "Acendendo as forjas de Glitnir...  0%";
					val10.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
					val10.fontSize = 13;
					val10.fontStyle = (FontStyle)0;
					val10.alignment = (TextAnchor)4;
					((Graphic)val10).color = new Color(0.95f, 0.93f, 0.88f, 1f);
					Shadow val11 = val6.AddComponent<Shadow>();
					val11.effectColor = new Color(0f, 0f, 0f, 0.85f);
					val11.effectDistance = new Vector2(1.5f, -1.5f);
					_progressLegacy = val10;
					_progressTMP = null;
				}
				_progressValue = 0f;
			}
			catch (Exception ex)
			{
				GlitnirMenuPlugin.Log.LogWarning((object)("[LoadingOverlay] AddProgressBar: " + ex.Message));
			}
		}

		private static void UpdateProgressBar()
		{
			try
			{
				_progressValue = Mathf.Clamp01(_progressValue);
				if ((Object)(object)_wolfFillImage != (Object)null)
				{
					_wolfFillImage.fillAmount = _progressValue;
				}
				int num = Mathf.RoundToInt(_progressValue * 100f);
				string text = $"{GetThematicMessage(_progressValue)}  {num}%";
				if ((Object)(object)_progressTMP != (Object)null)
				{
					((TMP_Text)_progressTMP).text = text;
				}
				if ((Object)(object)_progressLegacy != (Object)null)
				{
					_progressLegacy.text = text;
				}
			}
			catch
			{
			}
		}

		private static string GetThematicMessage(float progress)
		{
			(float, string)[] array = (IsTeleport ? TeleportMessages : LoadingMessages);
			string result = array[0].Item2;
			(float, string)[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				var (num, text) = array2[i];
				if (!(progress >= num))
				{
					break;
				}
				result = text;
			}
			return result;
		}

		private static IEnumerator FadeOverlay(float from, float to, float dur)
		{
			float t = 0f;
			while (t < dur)
			{
				if ((Object)(object)_group == (Object)null)
				{
					yield break;
				}
				_group.alpha = Mathf.Lerp(from, to, t / dur);
				t += Time.unscaledDeltaTime;
				yield return null;
			}
			if ((Object)(object)_group != (Object)null)
			{
				_group.alpha = to;
			}
		}

		private static IEnumerator FadeAndDestroy(float dur)
		{
			float t = 0f;
			while (t < dur && (Object)(object)_group != (Object)null)
			{
				_group.alpha = Mathf.Lerp(1f, 0f, t / dur);
				t += Time.unscaledDeltaTime;
				yield return null;
			}
			GameObject root = Root;
			Texture2D texture = _texture;
			Root = null;
			_rawImage = null;
			_group = null;
			_runner = null;
			_texture = null;
			_hiding = false;
			RestoreVanillaLoadingGui();
			if ((Object)(object)root != (Object)null)
			{
				Object.Destroy((Object)(object)root);
			}
			if ((Object)(object)texture != (Object)null)
			{
				Object.Destroy((Object)(object)texture);
			}
			GlitnirMenuPlugin.Log.LogInfo((object)"[GlitnirMenu] Overlay removido.");
		}

		private static IEnumerator HideVanillaLoadingGuiCoroutine()
		{
			_cachedHud = null;
			_cachedLoadingGuiTransform = null;
			while ((Object)(object)Root != (Object)null)
			{
				if ((Object)(object)Hud.instance != (Object)null)
				{
					if ((Object)(object)_cachedLoadingGuiTransform == (Object)null || (Object)(object)_cachedHud != (Object)(object)Hud.instance)
					{
						_cachedHud = Hud.instance;
						_cachedLoadingGuiTransform = TransformHelper.FindChild(((Component)Hud.instance).transform, "LoadingGUI");
					}
					if ((Object)(object)_cachedLoadingGuiTransform != (Object)null)
					{
						CanvasGroup val = ((Component)_cachedLoadingGuiTransform).gameObject.GetComponent<CanvasGroup>() ?? ((Component)_cachedLoadingGuiTransform).gameObject.AddComponent<CanvasGroup>();
						val.alpha = 0f;
						val.blocksRaycasts = false;
					}
				}
				yield return (object)new WaitForSecondsRealtime(0.1f);
			}
			_cachedHud = null;
			_cachedLoadingGuiTransform = null;
		}

		private static void RestoreVanillaLoadingGui()
		{
			try
			{
				if ((Object)(object)Hud.instance == (Object)null)
				{
					return;
				}
				Transform val = TransformHelper.FindChild(((Component)Hud.instance).transform, "LoadingGUI");
				if (!((Object)(object)val == (Object)null))
				{
					CanvasGroup component = ((Component)val).gameObject.GetComponent<CanvasGroup>();
					if ((Object)(object)component != (Object)null)
					{
						component.alpha = 1f;
						component.blocksRaycasts = true;
					}
				}
			}
			catch
			{
			}
		}

		private static GameObject AddFullRect(string name, Transform parent)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001c: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			val2.offsetMin = Vector2.zero;
			val2.offsetMax = Vector2.zero;
			return val;
		}

		private static Rect CalcUvRect(Texture2D tex)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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)
			float num = (float)Screen.width / (float)Screen.height;
			float num2 = (float)((Texture)tex).width / (float)((Texture)tex).height;
			if (Mathf.Approximately(num, num2))
			{
				return new Rect(0f, 0f, 1f, 1f);
			}
			if (num2 > num)
			{
				float num3 = num / num2;
				return new Rect((1f - num3) / 2f, 0f, num3, 1f);
			}
			float num4 = num2 / num;
			return new Rect(0f, (1f - num4) / 2f, 1f, num4);
		}

		private static Sprite MakeSprite(Texture2D tex)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)tex == (Object)null)
			{
				return null;
			}
			return Sprite.Create(tex, new Rect(0f, 0f, (float)((Texture)tex).width, (float)((Texture)tex).height), new Vector2(0.5f, 0.5f), 100f);
		}
	}
	internal static class LogoManager
	{
		private static Sprite _sprite;

		private static Texture2D _texture;

		private static string _loadedFile;

		internal static void TryReload(string filename)
		{
			if (GlitnirMenuPlugin.IsStartScene())
			{
				if ((Object)(object)_sprite == (Object)null || _loadedFile != filename)
				{
					Load(filename);
				}
				Apply();
			}
		}

		internal static void ForceReload(string filename)
		{
			Unload();
			TryReload(filename);
		}

		internal static void Unload()
		{
			if ((Object)(object)_sprite != (Object)null)
			{
				Object.Destroy((Object)(object)_sprite);
				_sprite = null;
			}
			if ((Object)(object)_texture != (Object)null)
			{
				Object.Destroy((Object)(object)_texture);
				_texture = null;
			}
			_loadedFile = null;
		}

		private static void Load(string filename)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_sprite != (Object)null)
			{
				Object.Destroy((Object)(object)_sprite);
				_sprite = null;
			}
			if ((Object)(object)_texture != (Object)null)
			{
				Object.Destroy((Object)(object)_texture);
				_texture = null;
			}
			_texture = LoadTexture(filename);
			if (!((Object)(object)_texture == (Object)null))
			{
				_sprite = Sprite.Create(_texture, new Rect(0f, 0f, (float)((Texture)_texture).width, (float)((Texture)_texture).height), Vector2.zero);
				_loadedFile = filename;
			}
		}

		private static Texture2D LoadTexture(string filename)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			try
			{
				string path = Path.Combine(GlitnirMenuPlugin.AssetRoot, "menu");
				if (!Directory.Exists(path))
				{
					GlitnirMenuPlugin.Log.LogWarning((object)"[LogoManager] Pasta menu/ não encontrada.");
					return null;
				}
				List<string> list = Directory.GetFiles(path, "*.png", SearchOption.AllDirectories).OrderBy(Path.GetFileName).ToList();
				string text = list.Find((string f) => Path.GetFileName(f) == filename);
				if (text == null)
				{
					GlitnirMenuPlugin.Log.LogWarning((object)("[LogoManager] Imagem não encontrada: " + filename));
					return null;
				}
				Texture2D val = new Texture2D(2, 2);
				ImageConversion.LoadImage(val, File.ReadAllBytes(text));
				return val;
			}
			catch (Exception ex)
			{
				GlitnirMenuPlugin.Log.LogWarning((object)("[LogoManager] Erro ao carregar " + filename + ": " + ex.Message));
				return null;
			}
		}

		private static void Apply()
		{
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_sprite == (Object)null || (Object)(object)FejdStartup.instance == (Object)null)
			{
				return;
			}
			try
			{
				Transform val = TransformHelper.FindChild(FejdStartup.instance.m_mainMenu.transform, "Logo");
				if ((Object)(object)val == (Object)null)
				{
					GlitnirMenuPlugin.Log.LogError((object)"[LogoManager] Transform 'Logo' não encontrado.");
					return;
				}
				Transform val2 = TransformHelper.FindChild(val, "LOGO");
				if ((Object)(object)val2 != (Object)null)
				{
					Image component = ((Component)val2).GetComponent<Image>();
					if ((Object)(object)component == (Object)null)
					{
						GlitnirMenuPlugin.Log.LogWarning((object)"[LogoManager] Componente Image não encontrado em LOGO.");
					}
					else
					{
						component.sprite = _sprite;
						RectTransform component2 = ((Component)val2).GetComponent<RectTransform>();
						if ((Object)(object)component2 != (Object)null)
						{
							float value = GlitnirMenuPlugin.MainLogoWidth.Value;
							float value2 = GlitnirMenuPlugin.MainLogoHeight.Value;
							component2.anchorMin = new Vector2(0.5f, 0.5f);
							component2.anchorMax = new Vector2(0.5f, 0.5f);
							if (value > 0f || value2 > 0f)
							{
								component2.sizeDelta = new Vector2((value > 0f) ? value : component2.sizeDelta.x, (value2 > 0f) ? value2 : component2.sizeDelta.y);
							}
							component2.anchoredPosition = new Vector2(component2.anchoredPosition.x, GlitnirMenuPlugin.MainLogoOffsetY.Value);
						}
					}
				}
				string[] logoChildrenToDisable = ValheimUINames.LogoChildrenToDisable;
				foreach (string name in logoChildrenToDisable)
				{
					Transform obj = TransformHelper.FindChild(val, name);
					if (obj != null)
					{
						((Component)obj).gameObject.SetActive(false);
					}
				}
				GlitnirMenuPlugin.Log.LogInfo((object)"[LogoManager] Logo aplicada.");
			}
			catch (Exception ex)
			{
				GlitnirMenuPlugin.Log.LogError((object)("[LogoManager] Erro ao aplicar logo: " + ex.Message));
			}
		}
	}
	internal static class MenuCreatures
	{
		private static readonly GameObject[] _instances = (GameObject[])(object)new GameObject[3];

		private static GameObject _cachedPrefab1;

		private static GameObject _cachedPrefab2;

		private static GameObject _cachedCookingPrefab;

		private static string _cachedName1;

		private static string _cachedName2;

		private static bool _updatingAnimator;

		internal static Animator PlayerAnimator { get; private set; }

		internal static IEnumerator SpawnCoroutine(FejdStartup fejd)
		{
			ConfigEntry<GlitnirMenuPlugin.Toggle> deersEnabled = GlitnirMenuPlugin.DeersEnabled;
			if (deersEnabled != null && deersEnabled.Value == GlitnirMenuPlugin.Toggle.On)
			{
				yield return null;
				yield return null;
				DestroyAll();
				string prefabName = GlitnirMenuPlugin.Criatura1PrefabName?.Value ?? "Deer";
				string prefabName2 = GlitnirMenuPlugin.Criatura2PrefabName?.Value ?? "Eikthyr";
				GameObject prefab = GetPrefab(ref _cachedPrefab1, ref _cachedName1, prefabName);
				GameObject prefab2 = GetPrefab(ref _cachedPrefab2, ref _cachedName2, prefabName2);
				GameObject cookingPrefab = GetCookingPrefab();
				Transform characterPreviewPoint = fejd.m_characterPreviewPoint;
				if (!((Object)(object)characterPreviewPoint == (Object)null))
				{
					Vector3 position = characterPreviewPoint.position;
					Vector3 forward = characterPreviewPoint.forward;
					Vector3 right = characterPreviewPoint.right;
					Vector3 pos = position + right * 5f - forward * 1.5f + Vector3.up * (GlitnirMenuPlugin.Criatura1AlturaOffset?.Value ?? 0f);
					Quaternion rotation = characterPreviewPoint.rotation;
					SpawnCreature(prefab, prefabName, 0, pos, ((Quaternion)(ref rotation)).eulerAngles.y + 300f);
					Vector3 pos2 = position - right * 5f - forward * 6f + Vector3.up * (GlitnirMenuPlugin.Criatura2AlturaOffset?.Value ?? 0f);
					rotation = characterPreviewPoint.rotation;
					SpawnCreature(prefab2, prefabName2, 1, pos2, ((Quaternion)(ref rotation)).eulerAngles.y + 390f);
					SpawnCookingStation(cookingPrefab, new Vector3(-165.35f, 54.56f, 229.09f));
				}
			}
		}

		internal static void DestroyAll()
		{
			for (int i = 0; i < _instances.Length; i++)
			{
				if ((Object)(object)_instances[i] != (Object)null)
				{
					Object.Destroy((Object)(object)_instances[i]);
					_instances[i] = null;
				}
			}
		}

		internal static IEnumerator SitPlayer(FejdStartup fejd)
		{
			yield return (object)new WaitForSecondsRealtime(3f);
			Animator val = FindPlayerAnimator();
			if ((Object)(object)val == (Object)null)
			{
				GlitnirMenuPlugin.Log.LogWarning((object)"[MenuCreatures] Animator do personagem não encontrado.");
				yield break;
			}
			PlayerAnimator = val;
			val.SetBool("emote_sit", true);
		}

		internal static IEnumerator AtualizarEsentar()
		{
			if (_updatingAnimator)
			{
				yield break;
			}
			_updatingAnimator = true;
			try
			{
				yield return (object)new WaitForSecondsRealtime(0.5f);
				Animator val = FindPlayerAnimator();
				if ((Object)(object)val == (Object)null)
				{
					GlitnirMenuPlugin.Log.LogWarning((object)"[MenuCreatures] AtualizarEsentar: Animator não encontrado.");
					yield break;
				}
				PlayerAnimator = val;
				val.SetBool("emote_sit", true);
			}
			finally
			{
				_updatingAnimator = false;
			}
		}

		internal static void StandPlayer()
		{
			Animator playerAnimator = PlayerAnimator;
			if (playerAnimator != null)
			{
				playerAnimator.SetBool("emote_sit", false);
			}
		}

		private static void SpawnCreature(GameObject prefab, string prefabName, int slot, Vector3 pos, float rotY)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)prefab == (Object)null)
			{
				GlitnirMenuPlugin.Log.LogWarning((object)("[MenuCreatures] Prefab '" + prefabName + "' não encontrado."));
				return;
			}
			try
			{
				GameObject val = Object.Instantiate<GameObject>(prefab, pos, Quaternion.Euler(0f, rotY, 0f));
				Animator componentInChildren = val.GetComponentInChildren<Animator>();
				MonoBehaviour[] componentsInChildren = val.GetComponentsInChildren<MonoBehaviour>(true);
				foreach (MonoBehaviour val2 in componentsInChildren)
				{
					if (((object)val2).GetType() != typeof(Animator))
					{
						((Behaviour)val2).enabled = false;
					}
				}
				if ((Object)(object)componentInChildren != (Object)null)
				{
					((Behaviour)componentInChildren).enabled = true;
				}
				SetupRigidbody(val.GetComponentInChildren<Rigidbody>());
				val.transform.position = pos;
				_instances[slot] = val;
			}
			catch (Exception ex)
			{
				GlitnirMenuPlugin.Log.LogWarning((object)("[MenuCreatures] Erro ao spawnar '" + prefabName + "': " + ex.Message));
			}
		}

		private static void SpawnCookingStation(GameObject prefab, Vector3 pos)
		{
			//IL_001b: 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)
			if ((Object)(object)prefab == (Object)null)
			{
				GlitnirMenuPlugin.Log.LogWarning((object)"[MenuCreatures] Prefab 'piece_cookingstation' não encontrado.");
				return;
			}
			try
			{
				GameObject val = Object.Instantiate<GameObject>(prefab, pos, Quaternion.Euler(0f, 60f, 0f));
				ZSyncTransform[] componentsInChildren = val.GetComponentsInChildren<ZSyncTransform>(true);
				foreach (ZSyncTransform val2 in componentsInChildren)
				{
					((Behaviour)val2).enabled = false;
				}
				SetupRigidbody(val.GetComponentInChildren<Rigidbody>());
				_instances[2] = val;
			}
			catch (Exception ex)
			{
				GlitnirMenuPlugin.Log.LogWarning((object)("[MenuCreatures] Erro ao spawnar cooking station: " + ex.Message));
			}
		}

		private static void SetupRigidbody(Rigidbody rb)
		{
			//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)
			if (!((Object)(object)rb == (Object)null))
			{
				rb.linearVelocity = Vector3.zero;
				rb.angularVelocity = Vector3.zero;
				rb.isKinematic = true;
			}
		}

		private static GameObject GetPrefab(ref GameObject cache, ref string cachedName, string prefabName)
		{
			if (cachedName != prefabName)
			{
				cache = null;
				cachedName = prefabName;
			}
			if ((Object)(object)cache != (Object)null)
			{
				return cache;
			}
			if ((Object)(object)ZNetScene.instance != (Object)null)
			{
				cache = ZNetScene.instance.GetPrefab(prefabName);
			}
			if ((Object)(object)cache == (Object)null)
			{
				cache = Resources.Load<GameObject>(prefabName);
			}
			if ((Object)(object)cache == (Object)null)
			{
				GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
				foreach (GameObject val in array)
				{
					if (((Object)val).name == prefabName)
					{
						cache = val;
						break;
					}
				}
			}
			return cache;
		}

		private static GameObject GetCookingPrefab()
		{
			if ((Object)(object)_cachedCookingPrefab != (Object)null)
			{
				return _cachedCookingPrefab;
			}
			if ((Object)(object)ZNetScene.instance != (Object)null)
			{
				_cachedCookingPrefab = ZNetScene.instance.GetPrefab("piece_cookingstation");
			}
			if ((Object)(object)_cachedCookingPrefab == (Object)null)
			{
				_cachedCookingPrefab = Resources.Load<GameObject>("piece_cookingstation");
			}
			if ((Object)(object)_cachedCookingPrefab == (Object)null)
			{
				GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
				foreach (GameObject val in array)
				{
					if (((Object)val).name == "piece_cookingstation")
					{
						_cachedCookingPrefab = val;
						break;
					}
				}
			}
			return _cachedCookingPrefab;
		}

		private static Animator FindPlayerAnimator()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			VisEquipment val = Object.FindFirstObjectByType<VisEquipment>();
			if ((Object)(object)val != (Object)null)
			{
				Animator componentInChildren = ((Component)val).GetComponentInChildren<Animator>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					return componentInChildren;
				}
			}
			Animator[] array = Object.FindObjectsByType<Animator>((FindObjectsSortMode)0);
			foreach (Animator val2 in array)
			{
				Scene scene = ((Component)val2).gameObject.scene;
				if (((Scene)(ref scene)).name == "start" && (Object)(object)val2.avatar != (Object)null && val2.avatar.isHuman)
				{
					return val2;
				}
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "SetupGui")]
	internal static class Patch_SetupGui
	{
		private static float _lastSetupTime = -999f;

		private const float _setupCooldown = 1.5f;

		private static bool _logoAnimating = false;

		private static bool _discordAnimating = false;

		private static void Postfix(FejdStartup __instance)
		{
			WolfBarAssets.Load();
			CameraManager.GatherDefaults(__instance);
			LogoManager.TryReload(GlitnirMenuPlugin.MainLogoFile);
			DiscordPanel.BuildOrRefresh(__instance);
			WelcomePanel.BuildOrRefresh(__instance);
			((MonoBehaviour)GlitnirMenuPlugin.Instance).StartCoroutine(CaptureMenuFontAndRebuild(__instance));
			((MonoBehaviour)GlitnirMenuPlugin.Instance).StartCoroutine(HideClutterDelayed(__instance));
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (!(realtimeSinceStartup - _lastSetupTime < 1.5f))
			{
				_lastSetupTime = realtimeSinceStartup;
				((MonoBehaviour)GlitnirMenuPlugin.Instance).StartCoroutine(MenuCreatures.SpawnCoroutine(__instance));
				((MonoBehaviour)GlitnirMenuPlugin.Instance).StartCoroutine(MenuCreatures.SitPlayer(__instance));
				if (!_logoAnimating)
				{
					((MonoBehaviour)GlitnirMenuPlugin.Instance).StartCoroutine(AnimateMenuLogo());
				}
				if (!_discordAnimating)
				{
					((MonoBehaviour)GlitnirMenuPlugin.Instance).StartCoroutine(AnimateDiscordLogo());
				}
			}
		}

		private static IEnumerator CaptureMenuFontAndRebuild(FejdStartup fejd)
		{
			if ((Object)(object)GlitnirMenuPlugin.CapturedMenuFont != (Object)null)
			{
				yield break;
			}
			float waited = 0f;
			while ((Object)(object)GlitnirMenuPlugin.CapturedMenuFont == (Object)null && waited < 5f)
			{
				yield return (object)new WaitForSecondsRealtime(0.1f);
				waited += 0.1f;
				GlitnirMenuPlugin.CapturedMenuFont = GlitnirMenuPlugin.GetMenuFont();
			}
			if ((Object)(object)GlitnirMenuPlugin.CapturedMenuFont == (Object)null)
			{
				GlitnirMenuPlugin.Log.LogWarning((object)"[GlitnirMenu] Fonte TMP não encontrada — painéis usando Arial como fallback.");
				yield break;
			}
			GlitnirMenuPlugin.Log.LogInfo((object)("[GlitnirMenu] Fonte TMP capturada (" + ((Object)GlitnirMenuPlugin.CapturedMenuFont).name + "), reconstruindo welcome panel."));
			if (GlitnirMenuPlugin.IsStartScene() && !((Object)(object)fejd == (Object)null))
			{
				WelcomePanel.Destroy();
				WelcomePanel.BuildOrRefresh(fejd);
			}
		}

		private static IEnumerator HideClutterDelayed(FejdStartup fejd)
		{
			yield return (object)new WaitForSecondsRealtime(0.5f);
			GlitnirMenuPlugin.HideClutter(fejd);
		}

		private static IEnumerator AnimateMenuLogo()
		{
			_logoAnimating = true;
			try
			{
				ConfigEntry<GlitnirMenuPlugin.Toggle> logoPulseEnabled = GlitnirMenuPlugin.LogoPulseEnabled;
				if (logoPulseEnabled == null || logoPulseEnabled.Value != GlitnirMenuPlugin.Toggle.On)
				{
					yield break;
				}
				yield return (object)new WaitForSecondsRealtime(0.6f);
				if ((Object)(object)FejdStartup.instance == (Object)null)
				{
					yield break;
				}
				Transform val = TransformHelper.FindChild(FejdStartup.instance.m_mainMenu.transform, "Logo");
				if ((Object)(object)val == (Object)null)
				{
					yield break;
				}
				Transform val2 = TransformHelper.FindChild(val, "LOGO");
				if ((Object)(object)val2 == (Object)null)
				{
					yield break;
				}
				RectTransform rt = ((Component)val2).GetComponent<RectTransform>();
				if (!((Object)(object)rt == (Object)null))
				{
					Vector3 baseScale = ((Transform)rt).localScale;
					float t = 0f;
					while (GlitnirMenuPlugin.IsStartScene() && (Object)(object)rt != (Object)null)
					{
						float num = GlitnirMenuPlugin.LogoPulseSpeed?.Value ?? 1.2f;
						float num2 = GlitnirMenuPlugin.LogoPulseMin?.Value ?? 0.95f;
						float num3 = GlitnirMenuPlugin.LogoPulseMax?.Value ?? 1.05f;
						t += Time.deltaTime * num;
						((Transform)rt).localScale = baseScale * Mathf.Lerp(num2, num3, (Mathf.Sin(t) + 1f) * 0.5f);
						yield return null;
					}
					if ((Object)(object)rt != (Object)null)
					{
						((Transform)rt).localScale = baseScale;
					}
				}
			}
			finally
			{
				_logoAnimating = false;
			}
		}

		private static IEnumerator AnimateDiscordLogo()
		{
			_discordAnimating = true;
			try
			{
				ConfigEntry<GlitnirMenuPlugin.Toggle> discordPulseEnabled = GlitnirMenuPlugin.DiscordPulseEnabled;
				if (discordPulseEnabled == null || discordPulseEnabled.Value != GlitnirMenuPlugin.Toggle.On)
				{
					yield break;
				}
				yield return (object)new WaitForSecondsRealtime(0.8f);
				GameObject panel = null;
				float waited = 0f;
				while (waited < 5f)
				{
					panel = GameObject.Find("GlitnirDiscordPanel");
					if ((Object)(object)panel != (Object)null)
					{
						break;
					}
					waited += Time.deltaTime;
					yield return null;
				}
				if ((Object)(object)panel == (Object)null)
				{
					yield break;
				}
				RectTransform rt = panel.GetComponent<RectTransform>();
				if (!((Object)(object)rt == (Object)null))
				{
					Vector3 baseScale = ((Transform)rt).localScale;
					float t = 0f;
					while (GlitnirMenuPlugin.IsStartScene() && (Object)(object)panel != (Object)null)
					{
						float num = GlitnirMenuPlugin.DiscordPulseSpeed?.Value ?? 0.8f;
						float num2 = GlitnirMenuPlugin.DiscordPulseMin?.Value ?? 0.93f;
						float num3 = GlitnirMenuPlugin.DiscordPulseMax?.Value ?? 1.07f;
						t += Time.deltaTime * num;
						((Transform)rt).localScale = baseScale * Mathf.Lerp(num2, num3, (Mathf.Sin(t) + 1f) * 0.5f);
						yield return null;
					}
					if ((Object)(object)rt != (Object)null)
					{
						((Transform)rt).localScale = baseScale;
					}
				}
			}
			finally
			{
				_discordAnimating = false;
			}
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "UpdateCamera")]
	internal static class Patch_UpdateCamera
	{
		private static int _frameSkip;

		private static bool _lastMenuActive;

		private static bool Prefix(FejdStartup __instance)
		{
			_frameSkip++;
			if (_frameSkip >= 10)
			{
				_frameSkip = 0;
				bool flag = (Object)(object)__instance.m_mainMenu != (Object)null && __instance.m_mainMenu.activeInHierarchy;
				if (flag != _lastMenuActive)
				{
					_lastMenuActive = flag;
					DiscordPanel.Refresh(__instance);
					WelcomePanel.Refresh(__instance);
				}
			}
			return CameraManager.HandleCameraLock(__instance);
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "OnStartGame")]
	internal static class Patch_OnStartGame
	{
		private static void Prefix()
		{
			MenuCreatures.StandPlayer();
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "OnSelelectCharacterBack")]
	internal static class Patch_OnSelelectCharacterBack
	{
		private static void Postfix()
		{
			((MonoBehaviour)GlitnirMenuPlugin.Instance).StartCoroutine(MenuCreatures.AtualizarEsentar());
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "OnNewCharacterCancel")]
	internal static class Patch_OnNewCharacterCancel
	{
		private static void Postfix()
		{
			((MonoBehaviour)GlitnirMenuPlugin.Instance).StartCoroutine(MenuCreatures.AtualizarEsentar());
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "OnNewCharacterDone")]
	internal static class Patch_OnNewCharacterDone
	{
		private static void Postfix()
		{
			((MonoBehaviour)GlitnirMenuPlugin.Instance).StartCoroutine(MenuCreatures.AtualizarEsentar());
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "OnServerListTab")]
	internal static class Patch_OnServerListTab
	{
		private static void Postfix(FejdStartup __instance)
		{
			TryCaptureGlitnirPlayers.Execute(__instance);
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "SetServerToJoin")]
	internal static class Patch_SetServerToJoin
	{
		private static void Postfix(object[] __args)
		{
			try
			{
				if (__args == null || __args.Length == 0)
				{
					return;
				}
				object obj = __args[0];
				if (obj == null)
				{
					return;
				}
				string text = "";
				int online = 0;
				FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					try
					{
						object value = fieldInfo.GetValue(obj);
						string text2 = fieldInfo.Name.ToLower();
						if (text2.Contains("name") && value is string text3)
						{
							text = text3;
						}
						if ((text2.Contains("player") || text2.Contains("count") || text2.Contains("num")) && value is int num)
						{
							online = num;
						}
					}
					catch
					{
					}
				}
				if (text.ToLowerInvariant().Contains("glitnir"))
				{
					WelcomePanel.SetOnline(online);
				}
			}
			catch (Exception ex)
			{
				GlitnirMenuPlugin.Log.LogWarning((object)("[GlitnirMenu] SetServerToJoin patch: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(Game), "Awake")]
	internal static class Patch_GameAwake
	{
		private static void Postfix()
		{
			LoadingOverlay.ShowLoading();
		}
	}
	[HarmonyPatch(typeof(Player), "TeleportTo")]
	internal static class Patch_PlayerTeleportTo
	{
		private static void Postfix(bool __result)
		{
			if (__result)
			{
				LoadingOverlay.ShowTeleport();
				LoadingOverlay.SetCheckpoint(0.3f, "Teleporte iniciado");
				Patch_PlayerUpdateTeleport.NotifyTeleportStarted();
			}
		}
	}
	[HarmonyPatch(typeof(Player), "UpdateTeleport")]
	internal static class Patch_PlayerUpdateTeleport
	{
		private const float MinInstantTeleportTime = 0.3f;

		private static bool _wasTeleporting = false;

		private static float _startTime = -1f;

		private static bool _resolvedInstant = false;

		private static MethodInfo _isAreaReadyMethod;

		private static bool _isAreaReadyLookupDone = false;

		internal static void NotifyTeleportStarted()
		{
			_wasTeleporting = false;
			_resolvedInstant = false;
			_startTime = Time.unscaledTime;
		}

		private static void Postfix(Player __instance)
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			if (!LoadingOverlay.IsTeleport)
			{
				_wasTeleporting = false;
				_startTime = -1f;
			}
			else if (((Character)__instance).IsTeleporting())
			{
				_wasTeleporting = true;
				LoadingOverlay.KeepTeleportAlive();
				LoadingOverlay.SetCheckpoint(0.6f, "Teleportando...");
			}
			else if (_wasTeleporting)
			{
				_wasTeleporting = false;
				_startTime = -1f;
				LoadingOverlay.SetCheckpoint(1f, "Teleporte concluído");
				LoadingOverlay.Hide();
			}
			else
			{
				if (_resolvedInstant || _startTime < 0f)
				{
					return;
				}
				float num = Time.unscaledTime - _startTime;
				if (!(num < 0.3f))
				{
					if (IsAreaReady(((Component)__instance).transform.position))
					{
						_resolvedInstant = true;
						_startTime = -1f;
						GlitnirMenuPlugin.Log.LogInfo((object)$"[GlitnirMenu] Teleporte sem animação detectado — área pronta após {num:F2}s, concluindo overlay.");
						LoadingOverlay.SetCheckpoint(1f, "Teleporte concluído");
						LoadingOverlay.Hide();
					}
					else
					{
						LoadingOverlay.KeepTeleportAlive();
					}
				}
			}
		}

		private static bool IsAreaReady(Vector3 pos)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)ZNetScene.instance == (Object)null)
				{
					return true;
				}
				if (!_isAreaReadyLookupDone)
				{
					_isAreaReadyLookupDone = true;
					_isAreaReadyMethod = typeof(ZNetScene).GetMethod("IsAreaReady", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(Vector3) }, null);
				}
				if (_isAreaReadyMethod == null)
				{
					return true;
				}
				return (bool)_isAreaReadyMethod.Invoke(ZNetScene.instance, new object[1] { pos });
			}
			catch (Exception ex)
			{
				GlitnirMenuPlugin.Log.LogWarning((object)("[GlitnirMenu] IsAreaReady falhou: " + ex.Message));
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "OnDeath")]
	internal static class Patch_PlayerOnDeath
	{
		private static void Prefix(Player __instance)
		{
			if (GlitnirMenuPlugin.LoadingScreenEnabled.Value == GlitnirMenuPlugin.Toggle.On && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				LoadingOverlay.DeathRespawnHappened = false;
				((MonoBehaviour)GlitnirMenuPlugin.Instance).StartCoroutine(ShowDeathAfterDelay());
			}
		}

		private static IEnumerator ShowDeathAfterDelay()
		{
			yield return (object)new WaitForSecondsRealtime(1.5f);