Decompiled source of ValheimNotice v1.0.0

ValheimNotice.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Networking;
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: AssemblyVersion("0.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 ValheimNotice
{
	[BepInPlugin("morgnar.valheimnotice", "ValheimNotice", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "morgnar.valheimnotice";

		public const string NAME = "ValheimNotice";

		public const string VERSION = "1.0.0";

		public const string ImageFileName = "welcome.png";

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		internal static ConfigFile Cfg;

		internal static ConfigEntry<bool> Enabled;

		private Harmony _harmony;

		internal static string ModConfigDir => Path.Combine(Paths.ConfigPath, "ValheimNotice");

		internal static string ImagePath => Path.Combine(ModConfigDir, "welcome.png");

		private void Awake()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Directory.CreateDirectory(ModConfigDir);
			Cfg = new ConfigFile(Path.Combine(ModConfigDir, "ValheimNotice.cfg"), true);
			Enabled = Cfg.Bind<bool>("Geral", "Ativado", true, "Liga/desliga a tela de boas-vindas.");
			_harmony = new Harmony("morgnar.valheimnotice");
			_harmony.PatchAll();
			if (Enabled.Value)
			{
				((MonoBehaviour)this).StartCoroutine(WelcomeScreen.PreloadTexture());
			}
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class WelcomeScreen
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__Confirm;

			public static UnityAction <1>__ToggleDontShow;
		}

		private static GameObject _root;

		private static Texture2D _texture;

		private static bool _loading;

		private static Game _shownForGame;

		private static Coroutine _waitRoutine;

		private static Font _font;

		internal static readonly Color BorderColor = new Color(0.78f, 0.58f, 0.28f, 1f);

		internal static readonly Color BorderHover = new Color(1f, 0.8f, 0.45f, 1f);

		internal static readonly Color FillColor = new Color(0.1f, 0.07f, 0.05f, 0.95f);

		internal static readonly Color FillHover = new Color(0.22f, 0.14f, 0.07f, 0.97f);

		internal static readonly Color TextColor = new Color(0.94f, 0.78f, 0.47f, 1f);

		internal static readonly Color TextHover = new Color(1f, 0.93f, 0.72f, 1f);

		internal static readonly Color DontShowColor = new Color(0.92f, 0.86f, 0.74f, 1f);

		internal static readonly Color DontShowHover = new Color(1f, 0.85f, 0.5f, 1f);

		private static readonly MethodInfo PlayerInIntro = AccessTools.Method(typeof(Player), "InIntro", (Type[])null, (Type[])null);

		private static readonly MethodInfo TextViewerIsShowingIntro = AccessTools.Method(typeof(TextViewer), "IsShowingIntro", (Type[])null, (Type[])null);

		private static readonly string[] StripComponents = new string[4] { "Localize", "UIGamePad", "UIInputHint", "UITooltip" };

		private static bool _dontShowChecked;

		private static GameObject _clickSfx;

		private static Image _checkMark;

		private const float ToggleBoxW = 300f;

		private const float ToggleBoxH = 30f;

		public static int ClosedFrame = -1;

		public static bool IsOpen => (Object)(object)_root != (Object)null;

		public static IEnumerator PreloadTexture()
		{
			if ((Object)(object)_texture != (Object)null || _loading)
			{
				yield break;
			}
			string path = Plugin.ImagePath;
			if (!File.Exists(path))
			{
				Plugin.Log.LogWarning((object)("Imagem não encontrada: " + path));
				yield break;
			}
			_loading = true;
			string absoluteUri = new Uri(path).AbsoluteUri;
			UnityWebRequest req = UnityWebRequestTexture.GetTexture(absoluteUri, true);
			try
			{
				yield return req.SendWebRequest();
				if ((int)req.result != 1)
				{
					Plugin.Log.LogWarning((object)("Falha ao carregar imagem: " + path + " (" + req.error + ")"));
				}
				else
				{
					Texture2D content = DownloadHandlerTexture.GetContent(req);
					if ((Object)(object)content != (Object)null)
					{
						((Object)content).name = "ValheimNotice";
						((Texture)content).filterMode = (FilterMode)1;
						((Texture)content).wrapMode = (TextureWrapMode)1;
						_texture = content;
					}
				}
			}
			finally
			{
				((IDisposable)req)?.Dispose();
			}
			_loading = false;
		}

		public static void TryShow()
		{
			if (Plugin.Enabled.Value && !IsOpen && !((Object)(object)Game.instance == (Object)null) && !((Object)(object)_shownForGame == (Object)(object)Game.instance))
			{
				_shownForGame = Game.instance;
				if (_waitRoutine != null)
				{
					((MonoBehaviour)Plugin.Instance).StopCoroutine(_waitRoutine);
				}
				_waitRoutine = ((MonoBehaviour)Plugin.Instance).StartCoroutine(WaitAndShow());
			}
		}

		private static IEnumerator WaitAndShow()
		{
			if ((Object)(object)_texture == (Object)null)
			{
				if (!_loading)
				{
					((MonoBehaviour)Plugin.Instance).StartCoroutine(PreloadTexture());
				}
				while (_loading)
				{
					yield return null;
				}
				if ((Object)(object)_texture == (Object)null)
				{
					yield break;
				}
			}
			float freeTime = 0f;
			while (freeTime < 1f)
			{
				if ((Object)(object)Game.instance == (Object)null)
				{
					yield break;
				}
				freeTime = ((!IsBusy()) ? (freeTime + Time.unscaledDeltaTime) : 0f);
				yield return null;
			}
			Build();
			_waitRoutine = null;
		}

		private static bool IsBusy()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return true;
			}
			if (((Character)localPlayer).IsTeleporting())
			{
				return true;
			}
			if (Invoke(PlayerInIntro, localPlayer))
			{
				return true;
			}
			if ((Object)(object)TextViewer.instance != (Object)null && Invoke(TextViewerIsShowingIntro, TextViewer.instance))
			{
				return true;
			}
			return false;
		}

		private static bool Invoke(MethodInfo method, object target)
		{
			if (method == null)
			{
				return false;
			}
			try
			{
				return (bool)method.Invoke(target, null);
			}
			catch
			{
				return false;
			}
		}

		private static Font GetFont()
		{
			if ((Object)(object)_font != (Object)null)
			{
				return _font;
			}
			try
			{
				Font[] array = Resources.FindObjectsOfTypeAll<Font>();
				foreach (Font val in array)
				{
					if (!((Object)(object)val == (Object)null))
					{
						string text = ((Object)val).name.ToLowerInvariant();
						if (text.Contains("averia") && text.Contains("bold"))
						{
							_font = val;
							break;
						}
						if ((Object)(object)_font == (Object)null && text.Contains("averia"))
						{
							_font = val;
						}
					}
				}
			}
			catch
			{
			}
			if ((Object)(object)_font == (Object)null)
			{
				try
				{
					_font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
				}
				catch
				{
				}
			}
			if ((Object)(object)_font == (Object)null)
			{
				try
				{
					_font = Resources.GetBuiltinResource<Font>("Arial.ttf");
				}
				catch
				{
				}
			}
			return _font;
		}

		private static void Build()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_005b: 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_0146: 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_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_texture == (Object)null) && !IsOpen)
			{
				_root = new GameObject("ValheimNotice");
				Canvas obj = _root.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 30000;
				CanvasScaler obj2 = _root.AddComponent<CanvasScaler>();
				obj2.uiScaleMode = (ScaleMode)1;
				obj2.referenceResolution = new Vector2(1920f, 1080f);
				obj2.matchWidthOrHeight = 0.5f;
				_root.AddComponent<GraphicRaycaster>();
				_root.AddComponent<WelcomeScreenBehaviour>();
				GameObject obj3 = CreateChild("Background", _root.transform);
				((Graphic)obj3.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.75f);
				Stretch(obj3.GetComponent<RectTransform>());
				float num = 774f;
				float num2 = Mathf.Min(1536f / (float)((Texture)_texture).width, num / (float)((Texture)_texture).height);
				float num3 = (float)((Texture)_texture).width * num2;
				float num4 = (float)((Texture)_texture).height * num2;
				float num5 = 45f;
				GameObject obj4 = CreateChild("Image", _root.transform);
				RawImage obj5 = obj4.AddComponent<RawImage>();
				obj5.texture = (Texture)(object)_texture;
				((Graphic)obj5).raycastTarget = false;
				Center(obj4.GetComponent<RectTransform>(), new Vector2(num3, num4), new Vector2(0f, num5));
				float num6 = num5 - num4 / 2f - 40f;
				Vector2 pos = default(Vector2);
				((Vector2)(ref pos))..ctor(0f, num6);
				if (!CreateVanillaButton(_root.transform, pos))
				{
					CreateCustomButton(_root.transform, pos);
				}
				_dontShowChecked = false;
				CreateDontShowToggle(_root.transform, (0f - num3) / 2f, num5 - num4 / 2f - 22f);
				ForceCursor();
			}
		}

		private static bool CreateVanillaButton(Transform parent, Vector2 pos)
		{
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Expected O, but got Unknown
			GameObject val = null;
			try
			{
				Menu instance = Menu.instance;
				Button val2 = null;
				if ((Object)(object)instance != (Object)null)
				{
					object? obj = AccessTools.Field(typeof(Menu), "m_continueButton")?.GetValue(instance);
					val2 = (Button)((obj is Button) ? obj : null);
				}
				if ((Object)(object)val2 == (Object)null)
				{
					return false;
				}
				val = Object.Instantiate<GameObject>(((Component)val2).gameObject, parent, false);
				((Object)val).name = "Button";
				val.SetActive(true);
				Component[] componentsInChildren = val.GetComponentsInChildren<Component>(true);
				foreach (Component val3 in componentsInChildren)
				{
					if ((Object)(object)val3 == (Object)null)
					{
						continue;
					}
					string name = ((object)val3).GetType().Name;
					string[] stripComponents = StripComponents;
					foreach (string text in stripComponents)
					{
						if (name == text)
						{
							Behaviour val4 = (Behaviour)(object)((val3 is Behaviour) ? val3 : null);
							if (val4 != null)
							{
								val4.enabled = false;
							}
							Object.Destroy((Object)(object)val3);
							break;
						}
					}
				}
				LayoutElement component = val.GetComponent<LayoutElement>();
				if ((Object)(object)component != (Object)null)
				{
					component.ignoreLayout = true;
				}
				RectTransform component2 = val.GetComponent<RectTransform>();
				Center(component2, new Vector2(320f, 56f), pos);
				((Transform)component2).localScale = Vector3.one;
				Button component3 = val.GetComponent<Button>();
				component3.onClick = new ButtonClickedEvent();
				ButtonClickedEvent onClick = component3.onClick;
				object obj2 = <>O.<0>__Confirm;
				if (obj2 == null)
				{
					UnityAction val5 = Confirm;
					<>O.<0>__Confirm = val5;
					obj2 = (object)val5;
				}
				((UnityEvent)onClick).AddListener((UnityAction)obj2);
				((Selectable)component3).interactable = true;
				TMP_Text componentInChildren = val.GetComponentInChildren<TMP_Text>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.text = "ENTENDI";
				}
				else
				{
					Text componentInChildren2 = val.GetComponentInChildren<Text>(true);
					if ((Object)(object)componentInChildren2 != (Object)null)
					{
						componentInChildren2.text = "ENTENDI";
					}
				}
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Não deu pra clonar o botão vanilla, usando o estilizado: " + ex.Message));
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				return false;
			}
		}

		private static void CreateCustomButton(Transform parent, Vector2 pos)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00fd: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Expected O, but got Unknown
			GameObject val = CreateChild("Button", parent);
			Center(val.GetComponent<RectTransform>(), new Vector2(320f, 58f), pos);
			Image val2 = val.AddComponent<Image>();
			((Graphic)val2).color = BorderColor;
			GameObject val3 = CreateChild("Fill", val.transform);
			Image val4 = val3.AddComponent<Image>();
			((Graphic)val4).color = FillColor;
			((Graphic)val4).raycastTarget = false;
			RectTransform component = val3.GetComponent<RectTransform>();
			Stretch(component);
			component.offsetMin = new Vector2(3f, 3f);
			component.offsetMax = new Vector2(-3f, -3f);
			GameObject val5 = CreateChild("InnerLine", val3.transform);
			Image obj = val5.AddComponent<Image>();
			((Graphic)obj).color = new Color(BorderColor.r, BorderColor.g, BorderColor.b, 0.45f);
			((Graphic)obj).raycastTarget = false;
			RectTransform component2 = val5.GetComponent<RectTransform>();
			Stretch(component2);
			component2.offsetMin = new Vector2(4f, 4f);
			component2.offsetMax = new Vector2(-4f, -4f);
			GameObject obj2 = CreateChild("InnerFill", val5.transform);
			Image val6 = obj2.AddComponent<Image>();
			((Graphic)val6).color = FillColor;
			((Graphic)val6).raycastTarget = false;
			RectTransform component3 = obj2.GetComponent<RectTransform>();
			Stretch(component3);
			component3.offsetMin = new Vector2(1f, 1f);
			component3.offsetMax = new Vector2(-1f, -1f);
			GameObject obj3 = CreateChild("Text", val.transform);
			Text val7 = obj3.AddComponent<Text>();
			val7.text = "ENTENDI";
			val7.font = GetFont();
			val7.fontSize = 28;
			val7.fontStyle = (FontStyle)1;
			val7.alignment = (TextAnchor)4;
			((Graphic)val7).color = TextColor;
			((Graphic)val7).raycastTarget = false;
			Shadow obj4 = obj3.AddComponent<Shadow>();
			obj4.effectColor = new Color(0f, 0f, 0f, 0.8f);
			obj4.effectDistance = new Vector2(2f, -2f);
			Stretch(obj3.GetComponent<RectTransform>());
			Button obj5 = val.AddComponent<Button>();
			((Selectable)obj5).targetGraphic = (Graphic)(object)val2;
			((Selectable)obj5).transition = (Transition)0;
			ButtonClickedEvent onClick = obj5.onClick;
			object obj6 = <>O.<0>__Confirm;
			if (obj6 == null)
			{
				UnityAction val8 = Confirm;
				<>O.<0>__Confirm = val8;
				obj6 = (object)val8;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj6);
			WelcomeButtonHover welcomeButtonHover = val.AddComponent<WelcomeButtonHover>();
			welcomeButtonHover.Fill = val4;
			welcomeButtonHover.InnerFill = val6;
			welcomeButtonHover.Border = val2;
			welcomeButtonHover.Label = val7;
		}

		private static void CreateDontShowToggle(Transform parent, float leftEdgeX, float y)
		{
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: 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_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Expected O, but got Unknown
			TMP_FontAsset val = null;
			try
			{
				if ((Object)(object)Menu.instance != (Object)null)
				{
					object? obj = AccessTools.Field(typeof(Menu), "m_continueButton")?.GetValue(Menu.instance);
					Button val2 = (Button)((obj is Button) ? obj : null);
					TMP_Text val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponentInChildren<TMP_Text>(true) : null);
					if ((Object)(object)val3 != (Object)null)
					{
						val = val3.font;
					}
					_clickSfx = null;
					if ((Object)(object)val2 != (Object)null)
					{
						MonoBehaviour[] components = ((Component)val2).GetComponents<MonoBehaviour>();
						foreach (MonoBehaviour val4 in components)
						{
							if (!((Object)(object)val4 == (Object)null) && !(((object)val4).GetType().Name != "ButtonSfx"))
							{
								object? obj2 = AccessTools.Field(((object)val4).GetType(), "m_sfxPrefab")?.GetValue(val4);
								_clickSfx = (GameObject)((obj2 is GameObject) ? obj2 : null);
								break;
							}
						}
					}
				}
			}
			catch
			{
			}
			GameObject val5 = CreateChild("DontShowAgain", parent);
			Center(val5.GetComponent<RectTransform>(), new Vector2(300f, 30f), new Vector2(leftEdgeX + 150f, y));
			Image val6 = val5.AddComponent<Image>();
			((Graphic)val6).color = new Color(0f, 0f, 0f, 0f);
			GameObject val7 = CreateChild("Checkbox", val5.transform);
			RectTransform component = val7.GetComponent<RectTransform>();
			Vector2 val8 = default(Vector2);
			((Vector2)(ref val8))..ctor(0f, 0.5f);
			component.anchorMax = val8;
			component.anchorMin = val8;
			component.pivot = new Vector2(0f, 0.5f);
			component.sizeDelta = new Vector2(22f, 22f);
			component.anchoredPosition = new Vector2(4f, 0f);
			Image val9 = val7.AddComponent<Image>();
			((Graphic)val9).color = BorderColor;
			((Graphic)val9).raycastTarget = false;
			GameObject obj4 = CreateChild("Inner", val7.transform);
			Image obj5 = obj4.AddComponent<Image>();
			((Graphic)obj5).color = new Color(0.05f, 0.035f, 0.02f, 0.9f);
			((Graphic)obj5).raycastTarget = false;
			RectTransform component2 = obj4.GetComponent<RectTransform>();
			Stretch(component2);
			component2.offsetMin = new Vector2(2f, 2f);
			component2.offsetMax = new Vector2(-2f, -2f);
			GameObject obj6 = CreateChild("Check", val7.transform);
			_checkMark = obj6.AddComponent<Image>();
			((Graphic)_checkMark).color = TextColor;
			((Graphic)_checkMark).raycastTarget = false;
			RectTransform component3 = obj6.GetComponent<RectTransform>();
			Stretch(component3);
			component3.offsetMin = new Vector2(5f, 5f);
			component3.offsetMax = new Vector2(-5f, -5f);
			((Behaviour)_checkMark).enabled = false;
			GameObject val10 = CreateChild("Label", val5.transform);
			RectTransform component4 = val10.GetComponent<RectTransform>();
			Stretch(component4);
			component4.offsetMin = new Vector2(36f, 0f);
			component4.offsetMax = Vector2.zero;
			Graphic label;
			if ((Object)(object)val != (Object)null)
			{
				TextMeshProUGUI obj7 = val10.AddComponent<TextMeshProUGUI>();
				((TMP_Text)obj7).font = val;
				((TMP_Text)obj7).text = "Não mostrar novamente";
				((TMP_Text)obj7).fontSize = 20f;
				((TMP_Text)obj7).alignment = (TextAlignmentOptions)4097;
				((Graphic)obj7).color = DontShowColor;
				((TMP_Text)obj7).textWrappingMode = (TextWrappingModes)0;
				((Graphic)obj7).raycastTarget = false;
				label = (Graphic)(object)obj7;
			}
			else
			{
				Text obj8 = val10.AddComponent<Text>();
				obj8.font = GetFont();
				obj8.text = "Não mostrar novamente";
				obj8.fontSize = 20;
				obj8.alignment = (TextAnchor)3;
				((Graphic)obj8).color = DontShowColor;
				((Graphic)obj8).raycastTarget = false;
				label = (Graphic)(object)obj8;
			}
			Shadow obj9 = val10.AddComponent<Shadow>();
			obj9.effectColor = new Color(0f, 0f, 0f, 0.9f);
			obj9.effectDistance = new Vector2(1.5f, -1.5f);
			Button obj10 = val5.AddComponent<Button>();
			((Selectable)obj10).targetGraphic = (Graphic)(object)val6;
			((Selectable)obj10).transition = (Transition)0;
			ButtonClickedEvent onClick = obj10.onClick;
			object obj11 = <>O.<1>__ToggleDontShow;
			if (obj11 == null)
			{
				UnityAction val11 = ToggleDontShow;
				<>O.<1>__ToggleDontShow = val11;
				obj11 = (object)val11;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj11);
			WelcomeLinkHover welcomeLinkHover = val5.AddComponent<WelcomeLinkHover>();
			welcomeLinkHover.Label = label;
			welcomeLinkHover.Box = (Graphic)(object)val9;
		}

		private static void ToggleDontShow()
		{
			_dontShowChecked = !_dontShowChecked;
			if ((Object)(object)_clickSfx != (Object)null)
			{
				try
				{
					Object.Instantiate<GameObject>(_clickSfx);
				}
				catch
				{
				}
			}
			if ((Object)(object)_checkMark != (Object)null)
			{
				((Behaviour)_checkMark).enabled = _dontShowChecked;
			}
		}

		public static void Confirm()
		{
			if (_dontShowChecked)
			{
				try
				{
					Plugin.Enabled.Value = false;
					Plugin.Cfg.Save();
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Falha ao salvar config: " + ex.Message));
				}
			}
			Close();
		}

		public static void Close()
		{
			if (!((Object)(object)_root == (Object)null))
			{
				Object.Destroy((Object)(object)_root);
				_root = null;
				ClosedFrame = Time.frameCount;
			}
		}

		public static void ForceCursor()
		{
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}

		private static GameObject CreateChild(string name, Transform parent)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			return val;
		}

		private static void Stretch(RectTransform rt)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			rt.anchorMin = Vector2.zero;
			rt.anchorMax = Vector2.one;
			rt.offsetMin = Vector2.zero;
			rt.offsetMax = Vector2.zero;
		}

		private static void Center(RectTransform rt, Vector2 size, Vector2 pos)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0.5f);
			rt.anchorMax = val;
			rt.anchorMin = val;
			rt.pivot = new Vector2(0.5f, 0.5f);
			rt.sizeDelta = size;
			rt.anchoredPosition = pos;
		}
	}
	internal class WelcomeButtonHover : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler
	{
		public Image Fill;

		public Image InnerFill;

		public Image Border;

		public Text Label;

		private bool _hover;

		private float _targetScale = 1f;

		public void OnPointerEnter(PointerEventData e)
		{
			_hover = true;
			Apply();
			_targetScale = 1.05f;
		}

		public void OnPointerExit(PointerEventData e)
		{
			_hover = false;
			Apply();
			_targetScale = 1f;
		}

		public void OnPointerDown(PointerEventData e)
		{
			_targetScale = 0.97f;
		}

		public void OnPointerUp(PointerEventData e)
		{
			_targetScale = (_hover ? 1.05f : 1f);
		}

		private void Apply()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_0028: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			Color color = (_hover ? WelcomeScreen.FillHover : WelcomeScreen.FillColor);
			if (Object.op_Implicit((Object)(object)Fill))
			{
				((Graphic)Fill).color = color;
			}
			if (Object.op_Implicit((Object)(object)InnerFill))
			{
				((Graphic)InnerFill).color = color;
			}
			if (Object.op_Implicit((Object)(object)Border))
			{
				((Graphic)Border).color = (_hover ? WelcomeScreen.BorderHover : WelcomeScreen.BorderColor);
			}
			if (Object.op_Implicit((Object)(object)Label))
			{
				((Graphic)Label).color = (_hover ? WelcomeScreen.TextHover : WelcomeScreen.TextColor);
			}
		}

		private void Update()
		{
			//IL_0006: 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)
			float num = Mathf.Lerp(((Component)this).transform.localScale.x, _targetScale, Time.unscaledDeltaTime * 14f);
			((Component)this).transform.localScale = new Vector3(num, num, 1f);
		}
	}
	internal class WelcomeLinkHover : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
	{
		public Graphic Label;

		public Graphic Box;

		public void OnPointerEnter(PointerEventData e)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Label))
			{
				Label.color = WelcomeScreen.DontShowHover;
			}
			if (Object.op_Implicit((Object)(object)Box))
			{
				Box.color = WelcomeScreen.BorderHover;
			}
		}

		public void OnPointerExit(PointerEventData e)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Label))
			{
				Label.color = WelcomeScreen.DontShowColor;
			}
			if (Object.op_Implicit((Object)(object)Box))
			{
				Box.color = WelcomeScreen.BorderColor;
			}
		}
	}
	internal class WelcomeScreenBehaviour : MonoBehaviour
	{
		private void Update()
		{
			if (Input.GetKeyDown((KeyCode)13) || Input.GetKeyDown((KeyCode)271))
			{
				WelcomeScreen.Confirm();
			}
			else
			{
				WelcomeScreen.ForceCursor();
			}
		}

		private void LateUpdate()
		{
			WelcomeScreen.ForceCursor();
		}
	}
	[HarmonyPatch(typeof(Player), "OnSpawned")]
	internal static class Player_OnSpawned_Patch
	{
		private static void Postfix(Player __instance)
		{
			if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer)
			{
				WelcomeScreen.TryShow();
			}
		}
	}
	[HarmonyPatch]
	internal static class GameCamera_UpdateMouseCapture_Patch
	{
		private static MethodBase _target;

		private static bool Prepare()
		{
			_target = AccessTools.Method(typeof(GameCamera), "UpdateMouseCapture", (Type[])null, (Type[])null);
			return _target != null;
		}

		private static MethodBase TargetMethod()
		{
			return _target;
		}

		private static void Postfix()
		{
			if (WelcomeScreen.IsOpen)
			{
				WelcomeScreen.ForceCursor();
			}
		}
	}
	[HarmonyPatch]
	internal static class Player_TakeInput_Patch
	{
		private static MethodBase _target;

		private static bool Prepare()
		{
			_target = AccessTools.Method(typeof(Player), "TakeInput", (Type[])null, (Type[])null);
			return _target != null;
		}

		private static MethodBase TargetMethod()
		{
			return _target;
		}

		private static void Postfix(ref bool __result)
		{
			if (WelcomeScreen.IsOpen)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch]
	internal static class Chat_Update_Patch
	{
		private static MethodBase _target;

		private static bool Prepare()
		{
			_target = AccessTools.Method(typeof(Chat), "Update", (Type[])null, (Type[])null);
			return _target != null;
		}

		private static MethodBase TargetMethod()
		{
			return _target;
		}

		private static bool Prefix()
		{
			if (!WelcomeScreen.IsOpen)
			{
				return Time.frameCount != WelcomeScreen.ClosedFrame;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Menu), "IsVisible")]
	internal static class Menu_IsVisible_Patch
	{
		private static void Postfix(ref bool __result)
		{
			if (WelcomeScreen.IsOpen)
			{
				__result = true;
			}
		}
	}
}