Decompiled source of TalentTree v3.0.0

TalentTree.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Data.SqlTypes;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Numerics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using Balance;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Core;
using Core.Builds;
using HarmonyLib;
using Integration;
using JetBrains.Annotations;
using LocalizationManager;
using M2Core.Assets;
using M2Core.Commands;
using M2Core.Config;
using M2Core.Content;
using M2Core.Patching;
using M2Core.UI;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Linq.JsonPath;
using Newtonsoft.Json.Schema;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Utilities;
using Patches;
using ServerSync;
using SkillsReworked.Api;
using SkillsReworked.Systems.Prestige;
using SkillsReworked.Systems.Progression;
using SkillsReworked.Systems.Rebirth;
using SkillsReworked.Systems.Rewards;
using SoftReferenceableAssets;
using TMPro;
using TalentTree;
using Talents;
using Talents.Berserker;
using Talents.Berserker.Effects;
using Talents.Berserker.Patches;
using Talents.Bulwark;
using Talents.Bulwark.Effects;
using Talents.Cultist;
using Talents.Cultist.Effects;
using Talents.Cultist.Patches;
using Talents.Hunter;
using Talents.Hunter.Effects;
using Talents.Shared;
using Talents.Valkyrie;
using Talents.Warcaller;
using Talents.Warcaller.Effects;
using Talents.Warcaller.Patches;
using Talents.Warrior;
using Talents.Warrior.Effects;
using Talents.Warrior.Patches;
using UI;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Experimental.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.U2D;
using UnityEngine.UI;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: <3c8b908b-b4e1-4d94-ab62-aa2dfa33b2d6>IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: <3c8b908b-b4e1-4d94-ab62-aa2dfa33b2d6>IgnoresAccessChecksTo("assembly_utils")]
[assembly: <3c8b908b-b4e1-4d94-ab62-aa2dfa33b2d6>IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("TalentTree")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b04e14e07886ac8c3beb80a329db9fdb6a65c919")]
[assembly: AssemblyProduct("TalentTree")]
[assembly: AssemblyTitle("TalentTree")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[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 UI
{
	internal static class TalentWindowFooterBuilder
	{
		internal sealed class Result
		{
			public Button ApplyButton;

			public Text ApplyBtnLabel;

			public Button ResetButton;

			public Text ResetBtnLabel;
		}

		public static Result Build(Transform panel, TalentUiLayout layout)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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)
			Result result = new Result();
			var (val, applyButton, applyBtnLabel) = UiFactory.CreateButtonBottomCenter(panel, "ApplyButton", TalentLocalization.T("tt_ui_apply"), layout.ApplyButtonOffset, layout.ApplyButtonSize);
			val.SetActive(false);
			result.ApplyButton = applyButton;
			result.ApplyBtnLabel = applyBtnLabel;
			var (val2, resetButton, resetBtnLabel) = UiFactory.CreateButtonBottomCenter(panel, "ResetButton", TalentLocalization.T("tt_ui_reset_draft"), layout.ResetButtonOffset, layout.ResetButtonSize);
			val2.SetActive(false);
			result.ResetButton = resetButton;
			result.ResetBtnLabel = resetBtnLabel;
			return result;
		}
	}
	internal static class TalentWindowHeaderBuilder
	{
		internal sealed class Result
		{
			public Text TitleText;

			public Text PointsText;

			public Button CloseButton;

			public Button StatsButton;

			public Text StatsBtnLabel;

			public Button BuildsButton;

			public Text BuildsBtnLabel;
		}

		public static Result Build(Transform panel, TalentUiLayout layout)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			Result result = new Result();
			var (val, val2) = UiFactory.CreateTextTopCenter(panel, "Title", TalentLocalization.T("tt_ui_talents_title"), layout.TitleOffset, layout.TitleSize, UiTheme.Fonts.Norse, layout.TitleFontSize, UiTheme.Colors.Orange, outline: true, Color.black);
			val2.alignment = (TextAnchor)4;
			result.TitleText = val2;
			Button item = UiFactory.CreateButtonTopRight(panel, "CloseButton", "X", layout.CloseButtonOffset, layout.CloseButtonSize).button;
			result.CloseButton = item;
			Text item2 = UiFactory.CreateNumberToken(panel, "Points", UiFactory.Presets.TopLeft, layout.PointsTokenOffset, layout.PointsTokenSize, UiTheme.Colors.Orange, UiTheme.Fonts.Body, layout.PointsTokenFontSize, Color.white).number;
			item2.text = "0";
			result.PointsText = item2;
			(GameObject go, Button button, Text label) tuple2 = UiFactory.CreateButtonTopLeft(panel, "StatsButton", TalentLocalization.T("tt_ui_stats"), layout.StatsButtonOffset, layout.StatsButtonSize);
			Button item3 = tuple2.button;
			Text item4 = tuple2.label;
			result.StatsButton = item3;
			result.StatsBtnLabel = item4;
			(GameObject go, Button button, Text label) tuple3 = UiFactory.CreateButtonTopLeft(panel, "BuildsButton", TalentLocalization.T("tt_ui_builds"), layout.BuildsButtonOffset, layout.BuildsButtonSize);
			Button item5 = tuple3.button;
			Text item6 = tuple3.label;
			result.BuildsButton = item5;
			result.BuildsBtnLabel = item6;
			return result;
		}
	}
	internal static class TalentWindowSearchBuilder
	{
		internal sealed class Result
		{
			public InputField SearchInput;

			public RectTransform SearchInputRt;

			public GameObject SearchDropdown;

			public RectTransform SearchDropdownRt;
		}

		public static Result Build(Transform panel, TalentUiLayout layout, TalentUiTheme theme)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0065: 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_0098: 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_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: 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_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Expected O, but got Unknown
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Expected O, but got Unknown
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Expected O, but got Unknown
			Result result = new Result();
			GameObject val = new GameObject("SearchBox", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(InputField)
			});
			val.transform.SetParent(panel, false);
			result.SearchInputRt = (RectTransform)val.transform;
			UiFactory.SetTopRight(result.SearchInputRt, layout.SearchOffset, layout.SearchSize);
			Image component = val.GetComponent<Image>();
			component.sprite = UiSprites.Get("text_field");
			component.type = (Type)1;
			((Graphic)component).color = theme.SearchBoxBackground;
			((Graphic)component).raycastTarget = true;
			result.SearchInput = val.GetComponent<InputField>();
			result.SearchInput.lineType = (LineType)0;
			result.SearchInput.characterLimit = layout.SearchCharacterLimit;
			RectTransform val2 = UiFactory.CreateRect("Text", val.transform);
			UiFactory.SetRectStretch(val2, new Vector2(layout.SearchTextPaddingX, layout.SearchTextPaddingY), new Vector2(0f - layout.SearchTextPaddingX, 0f - layout.SearchTextPaddingY));
			Text val3 = ((Component)val2).gameObject.AddComponent<Text>();
			val3.text = "";
			val3.font = UiTheme.Fonts.Body;
			val3.fontSize = layout.SearchFontSize;
			((Graphic)val3).color = Color.white;
			val3.alignment = (TextAnchor)3;
			val3.supportRichText = false;
			result.SearchInput.textComponent = val3;
			RectTransform val4 = UiFactory.CreateRect("Placeholder", val.transform);
			UiFactory.SetRectStretch(val4, val2.offsetMin, val2.offsetMax);
			Text val5 = ((Component)val4).gameObject.AddComponent<Text>();
			val5.text = TalentLocalization.T("tt_ui_search_placeholder");
			val5.font = UiTheme.Fonts.Body;
			val5.fontSize = layout.SearchFontSize;
			((Graphic)val5).color = theme.SearchPlaceholderColor;
			val5.alignment = (TextAnchor)3;
			((Graphic)val5).raycastTarget = false;
			result.SearchInput.placeholder = (Graphic)(object)val5;
			result.SearchDropdown = new GameObject("SearchDropdown", new Type[4]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(VerticalLayoutGroup),
				typeof(ContentSizeFitter)
			});
			result.SearchDropdown.transform.SetParent(panel, false);
			result.SearchDropdownRt = (RectTransform)result.SearchDropdown.transform;
			UiFactory.SetTopRight(result.SearchDropdownRt, new Vector2(result.SearchInputRt.anchoredPosition.x, result.SearchInputRt.anchoredPosition.y - result.SearchInputRt.sizeDelta.y - layout.SearchDropdownGap), new Vector2(result.SearchInputRt.sizeDelta.x, layout.SearchDropdownInitialHeight));
			Image component2 = result.SearchDropdown.GetComponent<Image>();
			component2.sprite = UiSprites.Get("text_field");
			component2.type = (Type)1;
			((Graphic)component2).color = theme.SearchDropdownBackground;
			((Graphic)component2).raycastTarget = true;
			VerticalLayoutGroup component3 = result.SearchDropdown.GetComponent<VerticalLayoutGroup>();
			((LayoutGroup)component3).padding = new RectOffset(layout.SearchDropdownPadding, layout.SearchDropdownPadding, layout.SearchDropdownPadding, layout.SearchDropdownPadding);
			((HorizontalOrVerticalLayoutGroup)component3).spacing = layout.SearchDropdownSpacing;
			((HorizontalOrVerticalLayoutGroup)component3).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)component3).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)component3).childForceExpandWidth = true;
			((LayoutGroup)component3).childAlignment = (TextAnchor)0;
			ContentSizeFitter component4 = result.SearchDropdown.GetComponent<ContentSizeFitter>();
			component4.horizontalFit = (FitMode)0;
			component4.verticalFit = (FitMode)2;
			result.SearchDropdown.SetActive(false);
			return result;
		}
	}
	internal static class TalentWindowTreeAreaBuilder
	{
		internal sealed class Result
		{
			public ScrollRect ScrollRect;

			public RectTransform ViewportRt;

			public RectTransform ContentRt;

			public RectTransform WorldRt;

			public RectTransform PathsRootRt;

			public RectTransform NodesRootRt;

			public MouseWheelZoomToCursor Zoom;

			public TreeViewportClip Clip;

			public TreePointer Pointer;
		}

		public static Result Build(Transform panel, TalentUiLayout layout, TalentUiTheme theme)
		{
			//IL_001d: 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_003f: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			Result result = new Result();
			RectTransform val = UiFactory.CreateRect("TalentTree_Area", panel);
			float treeFrameInset = layout.TreeFrameInset;
			UiFactory.SetRectStretch(val, new Vector2(treeFrameInset, treeFrameInset), new Vector2(0f - treeFrameInset, 0f - treeFrameInset));
			RectTransform val2 = UiFactory.CreateRect("Backdrop", (Transform)(object)val);
			UiFactory.SetRectStretch(val2, layout.TreeContentInsetMin - new Vector2(treeFrameInset, treeFrameInset), layout.TreeContentInsetMax + new Vector2(treeFrameInset, treeFrameInset));
			Image val3 = ((Component)val2).gameObject.AddComponent<Image>();
			val3.sprite = UiSprites.Get("Background");
			((Graphic)val3).color = theme.TreeBackground;
			((Graphic)val3).raycastTarget = false;
			result.ViewportRt = UiFactory.CreateRect("Viewport", (Transform)(object)val);
			UiFactory.SetRectStretch(result.ViewportRt, Vector2.zero, Vector2.zero);
			result.Clip = ((Component)result.ViewportRt).gameObject.AddComponent<TreeViewportClip>();
			result.Clip.Init(layout.TreeEdgeSoftness);
			((Component)result.ViewportRt).gameObject.AddComponent<RaycastSurface>();
			result.Pointer = ((Component)result.ViewportRt).gameObject.AddComponent<TreePointer>();
			result.ContentRt = UiFactory.CreateRect("Content", (Transform)(object)result.ViewportRt);
			UiFactory.SetCenter(result.ContentRt, Vector2.zero, layout.ContentSize);
			((Transform)result.ContentRt).localScale = Vector3.one;
			((Component)result.ContentRt).gameObject.AddComponent<Canvas>();
			result.WorldRt = UiFactory.CreateRect("World", (Transform)(object)result.ContentRt);
			UiFactory.SetCenter(result.WorldRt, Vector2.zero, result.ContentRt.sizeDelta);
			result.PathsRootRt = UiFactory.CreateRect("PathsRoot", (Transform)(object)result.WorldRt);
			result.NodesRootRt = UiFactory.CreateRect("NodesRoot", (Transform)(object)result.WorldRt);
			UiFactory.SetRectStretch(result.PathsRootRt, Vector2.zero, Vector2.zero);
			UiFactory.SetRectStretch(result.NodesRootRt, Vector2.zero, Vector2.zero);
			((Component)result.PathsRootRt).transform.SetAsFirstSibling();
			((Component)result.NodesRootRt).transform.SetAsLastSibling();
			result.ScrollRect = ((Component)val).gameObject.AddComponent<ScrollRect>();
			result.ScrollRect.viewport = result.ViewportRt;
			result.ScrollRect.content = result.ContentRt;
			result.ScrollRect.horizontal = true;
			result.ScrollRect.vertical = true;
			result.ScrollRect.movementType = (MovementType)2;
			result.ScrollRect.inertia = true;
			result.ScrollRect.scrollSensitivity = 0f;
			result.Zoom = ((Component)result.ViewportRt).gameObject.AddComponent<MouseWheelZoomToCursor>();
			result.Zoom.Initialize(result.ViewportRt, result.ContentRt, result.ScrollRect, layout);
			return result;
		}
	}
	internal enum BuildsListLevel
	{
		List,
		Buttons
	}
	internal sealed class BuildsListNavigation
	{
		public const int SaveCell = 0;

		public const int PasteCell = 1;

		public const int TopCells = 2;

		public const int Plan = 0;

		public const int CopyCode = 1;

		public const int Rename = 2;

		public const int Delete = 3;

		public const int ButtonCount = 4;

		public const int ButtonColumns = 2;

		public BuildsListLevel Level { get; private set; } = BuildsListLevel.List;

		public int BuildCount { get; private set; }

		public int Build { get; private set; } = -1;

		public int TopCell { get; private set; } = 0;

		public int Button { get; private set; } = 0;

		public bool OnTopRow => Build < 0;

		public bool InButtons => Level == BuildsListLevel.Buttons;

		public void Reset(int builds, int build)
		{
			BuildCount = Math.Max(0, builds);
			Build = ((BuildCount > 0 && build >= 0) ? Math.Min(build, BuildCount - 1) : (-1));
			ToList();
		}

		public void Follow(int builds, int build)
		{
			BuildCount = Math.Max(0, builds);
			if (OnTopRow)
			{
				return;
			}
			if (build >= 0 && build < BuildCount)
			{
				Build = build;
				return;
			}
			ToList();
			if (BuildCount > 0)
			{
				Build = Math.Min(Build, BuildCount - 1);
				return;
			}
			Build = -1;
			TopCell = 0;
		}

		public bool Step(int dx, int dy)
		{
			dx = Math.Sign(dx);
			dy = Math.Sign(dy);
			if (InButtons)
			{
				return StepInBlock(dx, dy);
			}
			if (dy != 0)
			{
				return StepVertically(dy);
			}
			if (dx == 0 || !OnTopRow)
			{
				return false;
			}
			int num = Math.Max(0, Math.Min(1, TopCell + dx));
			if (num == TopCell)
			{
				return false;
			}
			TopCell = num;
			return true;
		}

		public bool SelectBuild(int build)
		{
			if (BuildCount == 0)
			{
				return false;
			}
			int num = Math.Max(0, Math.Min(BuildCount - 1, build));
			bool result = num != Build || InButtons;
			Build = num;
			ToList();
			return result;
		}

		public bool Enter()
		{
			if (InButtons || OnTopRow)
			{
				return false;
			}
			Level = BuildsListLevel.Buttons;
			Button = 0;
			return true;
		}

		public bool Back()
		{
			if (!InButtons)
			{
				return false;
			}
			ToList();
			return true;
		}

		private bool StepVertically(int dy)
		{
			if (OnTopRow)
			{
				if (dy < 0 || BuildCount == 0)
				{
					return false;
				}
				Build = 0;
				return true;
			}
			int num = Build + dy;
			if (num >= BuildCount)
			{
				return false;
			}
			Build = num;
			return true;
		}

		private bool StepInBlock(int dx, int dy)
		{
			int num = 2;
			int num2 = Math.Max(0, Math.Min(1, Button % 2 + dx));
			int num3 = Math.Max(0, Math.Min(num - 1, Button / 2 + dy));
			int num4 = num3 * 2 + num2;
			if (num4 == Button)
			{
				return false;
			}
			Button = num4;
			return true;
		}

		private void ToList()
		{
			Level = BuildsListLevel.List;
			Button = 0;
		}
	}
	internal sealed class BuildsRenameFlow
	{
		private sealed class NameRequest : TextReceiver
		{
			private readonly BuildsRenameFlow _flow;

			public readonly SavedBuild Build;

			public NameRequest(BuildsRenameFlow flow, SavedBuild build)
			{
				_flow = flow;
				Build = build;
			}

			public string GetText()
			{
				return Build.Name ?? "";
			}

			public void SetText(string text)
			{
				_flow.OnNameEntered(this, text);
			}
		}

		private readonly BuildLibrary _library;

		private Transform _home;

		private InputField _field;

		private SavedBuild _typing;

		private Graphic[] _covered;

		private int _escapedFrame = -1;

		private NameRequest _request;

		private UiMenuStyle _menuStyle;

		public bool IsTyping => _typing != null;

		public InputField Field => _field;

		public BuildsRenameFlow(BuildLibrary library)
		{
			_library = library;
		}

		public void Build(Transform home, TalentUiLayout layout)
		{
			//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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			_home = home;
			TalentUiTheme talentUiTheme = TalentUiTheme.Default;
			_menuStyle = new UiMenuStyle
			{
				Background = UiSprites.Get("text_field"),
				BackgroundColor = talentUiTheme.HoverTooltipBackground,
				HighlightColor = talentUiTheme.SuggestionSelected,
				DisabledTextColor = talentUiTheme.StatsZeroTextColor,
				FontSize = layout.StatsPanelRowFontSize,
				RowHeight = layout.StatsPanelRowHeight,
				PaddingY = layout.BuildsPanelRowPaddingX,
				PaddingX = 2f * layout.BuildsPanelRowPaddingX
			};
			_field = UiInput.Create(home, UiPlacement.Stretch(), null, (ContentType)0, UiInput.DefaultText.WithSize(layout.StatsPanelRowFontSize).WithAlignment((TextAnchor)3));
			((Object)((Component)_field).gameObject).name = "Builds_RenameField";
			float num = Mathf.Max(0f, (layout.StatsPanelRowHeight - layout.BuildsPanelRenameTextHeight) * 0.5f);
			Graphic[] array = (Graphic[])(object)new Graphic[2]
			{
				(Graphic)_field.textComponent,
				_field.placeholder
			};
			foreach (Graphic val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					RectTransform rectTransform = val.rectTransform;
					rectTransform.anchorMin = Vector2.zero;
					rectTransform.anchorMax = Vector2.one;
					rectTransform.offsetMin = new Vector2(layout.BuildsPanelRenameTextPaddingX, num);
					rectTransform.offsetMax = new Vector2(0f - layout.BuildsPanelRenameTextPaddingX, 0f - num);
				}
			}
			_field.lineType = (LineType)0;
			_field.characterLimit = 40;
			((UnityEvent<string>)(object)_field.onEndEdit).AddListener((UnityAction<string>)OnFieldEnded);
			((Component)_field).gameObject.SetActive(false);
		}

		public void StartTyping(SavedBuild build, RectTransform row, params Graphic[] covered)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			End();
			CancelRequest();
			if (build != null && !((Object)(object)row == (Object)null) && !((Object)(object)_field == (Object)null))
			{
				_typing = build;
				_covered = covered;
				SetCovered(shown: false);
				((Component)_field).transform.SetParent((Transform)(object)row, false);
				UiPlacement.Stretch().ApplyTo((RectTransform)((Component)_field).transform);
				((Component)_field).gameObject.SetActive(true);
				_field.text = build.Name;
				Graphic placeholder = _field.placeholder;
				Text val = (Text)(object)((placeholder is Text) ? placeholder : null);
				if (val != null)
				{
					val.text = build.Name;
				}
				((Selectable)_field).Select();
				_field.ActivateInputField();
			}
		}

		public bool Cancel()
		{
			if (_typing != null)
			{
				End();
				return true;
			}
			return _escapedFrame == Time.frameCount;
		}

		public void End()
		{
			if (_typing == null)
			{
				return;
			}
			_typing = null;
			SetCovered(shown: true);
			_covered = null;
			if (!((Object)(object)_field == (Object)null))
			{
				if (_field.isFocused)
				{
					_field.DeactivateInputField();
				}
				((Component)_field).transform.SetParent(_home, false);
				((Component)_field).gameObject.SetActive(false);
			}
		}

		private void OnFieldEnded(string text)
		{
			SavedBuild typing = _typing;
			if (typing != null)
			{
				bool wasCanceled = _field.wasCanceled;
				if (wasCanceled)
				{
					_escapedFrame = Time.frameCount;
				}
				End();
				if (!wasCanceled)
				{
					Give(typing, text);
				}
			}
		}

		private void SetCovered(bool shown)
		{
			if (_covered == null)
			{
				return;
			}
			Graphic[] covered = _covered;
			foreach (Graphic val in covered)
			{
				if ((Object)(object)val != (Object)null)
				{
					((Behaviour)val).enabled = shown;
				}
			}
		}

		public void OpenNameMenu(SavedBuild build, ResolvedBuild resolved, int maxKeystones, RectTransform anchor, Action typeInField)
		{
			if (build == null || (Object)(object)anchor == (Object)null)
			{
				return;
			}
			List<UiMenuItem> list = new List<UiMenuItem>();
			foreach (string item in BuildNameService.RenameChoices(resolved, _library, build, maxKeystones))
			{
				string name = item;
				list.Add(new UiMenuItem(name, delegate
				{
					Pick(build, name);
				}));
			}
			list.Add(new UiMenuItem(TalentLocalization.T("tt_ui_builds_type_name"), delegate
			{
				if (!RequestTyped(build))
				{
					typeInField?.Invoke();
				}
			}));
			UiContextMenu.Open(list, anchor, _menuStyle);
		}

		public void CloseNameMenu()
		{
			UiContextMenu.Close();
		}

		private void Pick(SavedBuild build, string name)
		{
			if (!string.IsNullOrEmpty(name))
			{
				_library.Rename(build, BuildNameService.Unique(name, _library, build));
			}
		}

		private bool RequestTyped(SavedBuild build)
		{
			CancelRequest();
			if (build == null)
			{
				return false;
			}
			NameRequest nameRequest = new NameRequest(this, build);
			if (!ValheimTextDialog.Request((TextReceiver)(object)nameRequest, TalentLocalization.T("tt_ui_builds_rename"), 40))
			{
				return false;
			}
			_request = nameRequest;
			return true;
		}

		public void CancelRequest()
		{
			if (_request != null)
			{
				ValheimTextDialog.Cancel((TextReceiver)(object)_request);
				_request = null;
			}
		}

		private void OnNameEntered(NameRequest request, string text)
		{
			if (request == _request)
			{
				_request = null;
				Give(request.Build, text);
			}
		}

		private void Give(SavedBuild build, string text)
		{
			string text2 = BuildShareText.CleanName(text);
			if (text2.Length > 0 && text2 != build.Name)
			{
				_library.Rename(build, text2);
			}
		}
	}
	public readonly struct IndexedNode
	{
		public readonly string Id;

		public readonly int SectorOrder;

		public readonly float Ring;

		public readonly float Angle;

		public readonly IReadOnlyList<string> StatIds;

		public readonly bool Locked;

		public readonly bool AffectsOthers;

		public IndexedNode(string id, int sectorOrder, float ring, float angle, IReadOnlyList<string> statIds, bool locked, bool affectsOthers)
		{
			Id = id;
			SectorOrder = sectorOrder;
			Ring = ring;
			Angle = angle;
			StatIds = statIds ?? Array.Empty<string>();
			Locked = locked;
			AffectsOthers = affectsOthers;
		}
	}
	public static class ListWindow
	{
		public static int Scroll(int offset, int steps, int itemCount, int rowCount)
		{
			return Math.Max(0, Math.Min(offset + steps, itemCount - rowCount));
		}
	}
	public sealed class StatSearchIndex
	{
		private static readonly IReadOnlyList<string> None = Array.Empty<string>();

		private readonly Dictionary<string, List<string>> _nodesByStat = new Dictionary<string, List<string>>();

		private readonly Dictionary<string, int> _order = new Dictionary<string, int>();

		private List<string> _nearbyPlayers = new List<string>();

		private readonly List<(string StatId, string Name)> _names = new List<(string, string)>();

		public void Rebuild(IEnumerable<IndexedNode> nodes, Func<string, string> statName, ISet<string> searchableStats)
		{
			_nodesByStat.Clear();
			_order.Clear();
			_nearbyPlayers = new List<string>();
			_names.Clear();
			List<IndexedNode> list = new List<IndexedNode>();
			foreach (IndexedNode node in nodes)
			{
				if (!node.Locked)
				{
					list.Add(node);
				}
			}
			list.Sort(delegate(IndexedNode a, IndexedNode b)
			{
				int sectorOrder = a.SectorOrder;
				int num = sectorOrder.CompareTo(b.SectorOrder);
				if (num == 0)
				{
					float ring = a.Ring;
					num = ring.CompareTo(b.Ring);
				}
				if (num == 0)
				{
					float ring = a.Angle;
					num = ring.CompareTo(b.Angle);
				}
				return (num != 0) ? num : string.CompareOrdinal(a.Id, b.Id);
			});
			foreach (IndexedNode item in list)
			{
				_order[item.Id] = _order.Count;
				if (item.AffectsOthers)
				{
					_nearbyPlayers.Add(item.Id);
				}
				foreach (string statId in item.StatIds)
				{
					if (!_nodesByStat.TryGetValue(statId, out var value))
					{
						value = (_nodesByStat[statId] = new List<string>());
					}
					if (value.Count == 0 || value[value.Count - 1] != item.Id)
					{
						value.Add(item.Id);
					}
				}
			}
			foreach (string key in _nodesByStat.Keys)
			{
				if (searchableStats.Contains(key))
				{
					_names.Add((key, statName(key) ?? key));
				}
			}
			_names.Sort(((string StatId, string Name) a, (string StatId, string Name) b) => string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase));
		}

		public IReadOnlyList<string> NodesFor(string statId)
		{
			IReadOnlyList<string> result;
			if (statId == null || !_nodesByStat.TryGetValue(statId, out var value))
			{
				result = None;
			}
			else
			{
				IReadOnlyList<string> readOnlyList = value;
				result = readOnlyList;
			}
			return result;
		}

		public IReadOnlyList<string> NodesForNearbyPlayers()
		{
			return _nearbyPlayers;
		}

		public IReadOnlyList<string> MatchStats(string query)
		{
			if (string.IsNullOrWhiteSpace(query))
			{
				return None;
			}
			string text = query.Trim();
			List<(string, int)> list = new List<(string, int)>();
			foreach (var name in _names)
			{
				string item = name.StatId;
				string item2 = name.Name;
				int num = MatchRank(item2, text);
				if (num >= 0)
				{
					list.Add((item, num));
				}
			}
			Dictionary<string, int> order = new Dictionary<string, int>();
			for (int i = 0; i < list.Count; i++)
			{
				order[list[i].Item1] = i;
			}
			list.Sort(((string StatId, int Rank) a, (string StatId, int Rank) b) => (a.Rank != b.Rank) ? a.Rank.CompareTo(b.Rank) : order[a.StatId].CompareTo(order[b.StatId]));
			List<string> list2 = new List<string>(list.Count);
			foreach (var item3 in list)
			{
				list2.Add(item3.Item1);
			}
			return list2;
		}

		public static int MatchRank(string name, string text)
		{
			if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(text))
			{
				return -1;
			}
			int num = name.IndexOf(text, StringComparison.OrdinalIgnoreCase);
			if (num < 0)
			{
				return -1;
			}
			if (num == 0)
			{
				return 0;
			}
			while (num > 0)
			{
				if (!char.IsLetterOrDigit(name[num - 1]))
				{
					return 1;
				}
				num = ((num + 1 < name.Length) ? name.IndexOf(text, num + 1, StringComparison.OrdinalIgnoreCase) : (-1));
			}
			return 2;
		}

		public IReadOnlyList<string> AllStats()
		{
			List<string> list = new List<string>(_names.Count);
			foreach (var name in _names)
			{
				string item = name.StatId;
				list.Add(item);
			}
			return list;
		}

		public IReadOnlyList<string> NodesForAll(IEnumerable<string> statIds, IEnumerable<string> alsoNodes = null)
		{
			HashSet<string> hashSet = new HashSet<string>();
			List<string> list = new List<string>();
			foreach (string statId in statIds)
			{
				foreach (string item in NodesFor(statId))
				{
					if (hashSet.Add(item))
					{
						list.Add(item);
					}
				}
			}
			if (alsoNodes != null)
			{
				foreach (string alsoNode in alsoNodes)
				{
					if (alsoNode != null && _order.ContainsKey(alsoNode) && hashSet.Add(alsoNode))
					{
						list.Add(alsoNode);
					}
				}
			}
			list.Sort((string a, string b) => _order[a].CompareTo(_order[b]));
			return list;
		}
	}
	internal sealed class TalentSearchController
	{
		private sealed class SearchItem
		{
			public string Id;

			public string Name;

			public string IdLower;

			public string NameLower;

			public string HaystackLower;
		}

		private struct SearchMatch
		{
			public SearchItem Item;

			public int Score;
		}

		private enum ItemKind
		{
			Header,
			Talent,
			Stat,
			AllWith,
			NearbyPlayers
		}

		private struct ListItem
		{
			public ItemKind Kind;

			public int Group;

			public string Label;

			public string Count;

			public string TalentId;

			public string StatId;

			public bool Selectable => Kind != ItemKind.Header;
		}

		private sealed class SuggestionEntry
		{
			public GameObject Go;

			public Button Button;

			public Image Background;

			public Text Label;

			public Text Count;
		}

		private sealed class SuggestionPointerDownCatcher : MonoBehaviour, IPointerDownHandler, IEventSystemHandler
		{
			public TalentSearchController Owner;

			public int Index;

			public void OnPointerDown(PointerEventData eventData)
			{
				Owner._suppressEndEditOnce = true;
				Owner.SelectByRow(Index);
			}
		}

		private sealed class DropdownScrollCatcher : MonoBehaviour, IScrollHandler, IEventSystemHandler
		{
			public TalentSearchController Owner;

			public void OnScroll(PointerEventData eventData)
			{
				//IL_0002: 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)
				if (eventData.scrollDelta.y > 0f)
				{
					Owner.ScrollBy(-1);
				}
				else if (eventData.scrollDelta.y < 0f)
				{
					Owner.ScrollBy(1);
				}
			}
		}

		public enum SearchChoiceKind
		{
			Talent,
			Stat,
			AllWith,
			NearbyPlayers,
			Typed
		}

		public readonly struct SearchChoice
		{
			public readonly SearchChoiceKind Kind;

			public readonly string StatId;

			public readonly string Query;

			public SearchChoice(SearchChoiceKind kind, string statId, string query)
			{
				Kind = kind;
				StatId = statId;
				Query = query;
			}
		}

		private const int DefaultIndexCapacity = 256;

		private const int DefaultMatchBufferCapacity = 256;

		private const int DefaultSuggestionsCapacity = 16;

		private const int ScorePrefixNameBase = 1000;

		private const int ScoreContainsNameBase = 800;

		private const int ScorePrefixIdBase = 600;

		private const int ScoreContainsIdBase = 400;

		private const int ScoreContainsHaystackBase = 200;

		private const int GroupTalents = 0;

		private const int GroupStats = 1;

		private readonly TalentUiTheme _theme;

		private readonly TalentUiLayout _layout;

		private readonly List<SearchItem> _index = new List<SearchItem>(256);

		private readonly List<SearchMatch> _matchBuffer = new List<SearchMatch>(256);

		private readonly List<SuggestionEntry> _suggestions = new List<SuggestionEntry>(16);

		private Text _more;

		private readonly StatSearchIndex _stats = new StatSearchIndex();

		private readonly HashSet<string> _searchableStats = new HashSet<string>();

		private readonly InputField _input;

		private readonly RectTransform _inputRt;

		private readonly GameObject _dropdown;

		private readonly RectTransform _dropdownRt;

		private bool _suppressSearchEvents;

		private bool _suppressEndEditOnce;

		private bool _selecting;

		private bool _pendingHide;

		private readonly List<ListItem> _items = new List<ListItem>(256);

		private int _offset;

		private int _selected = -1;

		private IReadOnlyList<string> _matchedStats = Array.Empty<string>();

		private bool _browsing;

		private Func<TalentDefinition, string> _displayName;

		private float _markTypedAt = -1f;

		private string _query;

		public bool IsDropdownVisible => (Object)(object)_dropdown != (Object)null && _dropdown.activeSelf;

		private int RowCount => Mathf.Min(_layout.SearchMaxSuggestions, _items.Count);

		public event Action<SearchChoice, IReadOnlyList<string>> Chosen;

		public event Action Emptied;

		public TalentSearchController(InputField input, RectTransform inputRt, GameObject dropdown, RectTransform dropdownRt, TalentUiTheme theme = null, TalentUiLayout layout = null)
		{
			_input = input;
			_inputRt = inputRt;
			_dropdown = dropdown;
			_dropdownRt = dropdownRt;
			_theme = theme ?? TalentUiTheme.Default;
			_layout = layout ?? TalentUiLayout.Default;
			if ((Object)(object)_dropdown != (Object)null)
			{
				_dropdown.AddComponent<DropdownScrollCatcher>().Owner = this;
			}
		}

		private void ScrollBy(int steps)
		{
			int num = ListWindow.Scroll(_offset, steps, _items.Count, RowCount);
			if (num != _offset)
			{
				_offset = num;
				ShowRows();
			}
		}

		public void Bind(Func<TalentDefinition, string> displayName)
		{
			_displayName = displayName;
			((UnityEventBase)_input.onValueChanged).RemoveAllListeners();
			((UnityEventBase)_input.onEndEdit).RemoveAllListeners();
			((UnityEvent<string>)(object)_input.onValueChanged).AddListener((UnityAction<string>)OnSearchChanged);
			((UnityEvent<string>)(object)_input.onEndEdit).AddListener((UnityAction<string>)OnSearchEndEdit);
		}

		public void RebuildIndex(IEnumerable<TalentDefinition> defs)
		{
			_index.Clear();
			List<IndexedNode> list = new List<IndexedNode>(1024);
			foreach (TalentDefinition def in defs)
			{
				if (def != null)
				{
					bool flag = SectorRegistry.IsLocked(def.SectorId);
					list.Add(ToIndexedNode(def, flag));
					if (def.Tier == NodeTier.Keystone && !flag)
					{
						string text = def.Id ?? "";
						string text2 = ((_displayName != null) ? _displayName(def) : (def.NameKey ?? text));
						string text3 = text.ToLowerInvariant();
						string text4 = (text2 ?? "").ToLowerInvariant();
						_index.Add(new SearchItem
						{
							Id = text,
							Name = text2,
							IdLower = text3,
							NameLower = text4,
							HaystackLower = text3 + " " + text4
						});
					}
				}
			}
			_searchableStats.Clear();
			foreach (StatDef stat in StatCatalog.Stats)
			{
				if (stat.Searchable)
				{
					_searchableStats.Add(stat.Id);
				}
			}
			_stats.Rebuild(list, TalentStatLabels.StatName, _searchableStats);
		}

		private static IndexedNode ToIndexedNode(TalentDefinition def, bool locked)
		{
			List<string> list = new List<string>(2);
			bool flag = false;
			ITalentEffect[] effects = def.Effects;
			foreach (ITalentEffect talentEffect in effects)
			{
				if (!(talentEffect is IStatProgressionProvider statProgressionProvider))
				{
					continue;
				}
				foreach (StatRow item in StatCatalog.RowsFor(statProgressionProvider.CacheKey))
				{
					list.Add(item.StatId);
					flag |= item.AffectsOthers;
				}
			}
			SectorDefinition sectorDefinition = SectorRegistry.Get(def.SectorId);
			return new IndexedNode(def.Id, sectorDefinition?.Order ?? 0, def.PosRing, def.PosOffset, list, locked, flag);
		}

		public void Clear()
		{
			_suppressSearchEvents = true;
			try
			{
				_input.text = "";
			}
			finally
			{
				_suppressSearchEvents = false;
			}
			_markTypedAt = -1f;
			HideDropdown();
		}

		public void Focus()
		{
			if (!((Object)(object)_input == (Object)null))
			{
				((Selectable)_input).Select();
				_input.ActivateInputField();
				if (!string.IsNullOrWhiteSpace(_input.text))
				{
					UpdateSuggestions(_input.text);
				}
			}
		}

		public void HideDropdown()
		{
			_pendingHide = false;
			if ((Object)(object)_dropdown != (Object)null)
			{
				_dropdown.SetActive(false);
			}
			_selected = -1;
			_browsing = false;
		}

		public void TickGamepad()
		{
			if ((Object)(object)_input == (Object)null || (Object)(object)_dropdown == (Object)null)
			{
				return;
			}
			if (!_browsing)
			{
				if (ZInput.GetButtonDown("JoyLStick"))
				{
					OpenBrowse();
				}
			}
			else if (ZInput.GetButtonDown("JoyDPadDown") || ZInput.GetButtonDown("JoyLStickDown"))
			{
				Move(1, rumble: true);
			}
			else if (ZInput.GetButtonDown("JoyDPadUp") || ZInput.GetButtonDown("JoyLStickUp"))
			{
				Move(-1, rumble: true);
			}
			else if (ZInput.GetButtonDown("JoyTabRight"))
			{
				SwitchGroup(1);
			}
			else if (ZInput.GetButtonDown("JoyTabLeft"))
			{
				SwitchGroup(-1);
			}
			else if (ZInput.GetButtonDown("JoyButtonA"))
			{
				ZInput.ResetButtonStatus("JoyButtonA");
				TrySelectCurrent();
			}
		}

		private void OpenBrowse()
		{
			List<SearchItem> list = new List<SearchItem>(_index);
			list.Sort((SearchItem a, SearchItem b) => string.Compare(a.Name, b.Name, StringComparison.CurrentCultureIgnoreCase));
			_items.Clear();
			AddTalentGroup(list);
			_matchedStats = _stats.AllStats();
			AddStatGroup(_matchedStats, withAllWith: false, null, nearbyPlayers: true);
			if (_items.Count != 0)
			{
				_browsing = true;
				ShowList();
			}
		}

		private void SwitchGroup(int direction)
		{
			if (_selected < 0)
			{
				return;
			}
			int num = _items[_selected].Group + direction;
			for (int i = 0; i < _items.Count; i++)
			{
				if (_items[i].Group == num && _items[i].Selectable)
				{
					Select(i);
					if ((Object)(object)GamepadRumble.instance != (Object)null)
					{
						GamepadRumble.instance.PlayGlobalSelectVibration();
					}
					break;
				}
			}
		}

		private void AlignDropdown()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_dropdownRt == (Object)null) && !((Object)(object)_inputRt == (Object)null))
			{
				_dropdownRt.anchoredPosition = new Vector2(_inputRt.anchoredPosition.x, _inputRt.anchoredPosition.y - _inputRt.sizeDelta.y - _layout.SearchDropdownGap);
			}
		}

		public void Tick()
		{
			if ((Object)(object)_input == (Object)null || (Object)(object)_dropdown == (Object)null)
			{
				return;
			}
			if (_markTypedAt >= 0f && Time.unscaledTime >= _markTypedAt)
			{
				_markTypedAt = -1f;
				MarkTyped();
			}
			if (_pendingHide)
			{
				_pendingHide = false;
				if (!_selecting)
				{
					HideDropdown();
				}
			}
			else if (_dropdown.activeSelf && _input.isFocused)
			{
				if (ZInput.GetKeyDown((KeyCode)274, true))
				{
					Move(1, rumble: false);
				}
				else if (ZInput.GetKeyDown((KeyCode)273, true))
				{
					Move(-1, rumble: false);
				}
				else if (IsSubmitKeyDown())
				{
					TrySelectCurrent();
				}
			}
		}

		private void OnSearchEndEdit(string value)
		{
			if (!_selecting)
			{
				if (_suppressEndEditOnce)
				{
					_suppressEndEditOnce = false;
				}
				else if (!IsSubmitKeyDown() || !TrySelectCurrent())
				{
					_pendingHide = true;
				}
			}
		}

		private void OnSearchChanged(string raw)
		{
			if (!_suppressSearchEvents && !_selecting)
			{
				if (string.IsNullOrWhiteSpace(raw))
				{
					_markTypedAt = -1f;
					HideDropdown();
					this.Emptied?.Invoke();
				}
				else
				{
					UpdateSuggestions(raw);
					_markTypedAt = Time.unscaledTime + _layout.SearchMarkTypedDelay;
				}
			}
		}

		private void MarkTyped()
		{
			string text = (_input.text ?? string.Empty).Trim();
			if (text.Length == 0)
			{
				return;
			}
			string value = text.ToLowerInvariant();
			List<string> list = new List<string>();
			foreach (SearchItem item in _index)
			{
				if (item.NameLower.Contains(value))
				{
					list.Add(item.Id);
				}
			}
			if (TalentLocalization.T("tt_ui_search_nearby_players").IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0)
			{
				list.AddRange(_stats.NodesForNearbyPlayers());
			}
			this.Chosen?.Invoke(new SearchChoice(SearchChoiceKind.Typed, null, text), _stats.NodesForAll(_stats.MatchStats(text), list));
		}

		private void UpdateSuggestions(string raw)
		{
			string text = raw.Trim();
			string text2 = text.ToLowerInvariant();
			if (text2.Length == 0)
			{
				HideDropdown();
				return;
			}
			_matchBuffer.Clear();
			for (int i = 0; i < _index.Count; i++)
			{
				SearchItem item = _index[i];
				int num = ScoreMatch(item, text2);
				if (num > 0)
				{
					_matchBuffer.Add(new SearchMatch
					{
						Item = item,
						Score = num
					});
				}
			}
			_matchBuffer.Sort((SearchMatch a, SearchMatch b) => b.Score.CompareTo(a.Score));
			List<SearchItem> list = new List<SearchItem>(_matchBuffer.Count);
			foreach (SearchMatch item2 in _matchBuffer)
			{
				list.Add(item2.Item);
			}
			_items.Clear();
			AddTalentGroup(list);
			_query = text;
			_matchedStats = _stats.MatchStats(text);
			bool nearbyPlayers = TalentLocalization.T("tt_ui_search_nearby_players").IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0;
			AddStatGroup(_matchedStats, withAllWith: true, text, nearbyPlayers);
			if (_items.Count == 0)
			{
				HideDropdown();
				return;
			}
			_browsing = false;
			ShowList();
		}

		private void AddTalentGroup(List<SearchItem> talents)
		{
			if (talents.Count == 0)
			{
				return;
			}
			_items.Add(new ListItem
			{
				Kind = ItemKind.Header,
				Group = 0,
				Label = TalentLocalization.T("tt_ui_search_group_talents")
			});
			foreach (SearchItem talent in talents)
			{
				_items.Add(new ListItem
				{
					Kind = ItemKind.Talent,
					Group = 0,
					Label = talent.Name,
					TalentId = talent.Id
				});
			}
		}

		private void AddStatGroup(IReadOnlyList<string> stats, bool withAllWith, string query, bool nearbyPlayers)
		{
			int num = (nearbyPlayers ? _stats.NodesForNearbyPlayers().Count : 0);
			if (stats.Count == 0 && num == 0)
			{
				return;
			}
			_items.Add(new ListItem
			{
				Kind = ItemKind.Header,
				Group = 1,
				Label = TalentLocalization.T("tt_ui_search_group_stats")
			});
			if (withAllWith && stats.Count > 1)
			{
				_items.Add(new ListItem
				{
					Kind = ItemKind.AllWith,
					Group = 1,
					Label = StatFormat.Apply(TalentLocalization.T("tt_ui_search_all_with"), query),
					Count = _stats.NodesForAll(stats).Count.ToString()
				});
			}
			foreach (string stat in stats)
			{
				_items.Add(new ListItem
				{
					Kind = ItemKind.Stat,
					Group = 1,
					Label = TalentStatLabels.StatName(stat),
					StatId = stat,
					Count = _stats.NodesFor(stat).Count.ToString()
				});
			}
			if (num > 0)
			{
				_items.Add(new ListItem
				{
					Kind = ItemKind.NearbyPlayers,
					Group = 1,
					Label = TalentLocalization.T("tt_ui_search_nearby_players"),
					Count = num.ToString()
				});
			}
		}

		private void ShowList()
		{
			_offset = 0;
			_selected = NextSelectable(-1, 1);
			ShowRows();
			FitDropdownWidth();
			AlignDropdown();
			_dropdown.SetActive(true);
		}

		private void FitDropdownWidth()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			if (_suggestions.Count == 0 || (Object)(object)_dropdownRt == (Object)null || (Object)(object)_inputRt == (Object)null)
			{
				return;
			}
			Text label = _suggestions[0].Label;
			TextGenerationSettings generationSettings = label.GetGenerationSettings(Vector2.zero);
			float num = 0f;
			foreach (ListItem item in _items)
			{
				generationSettings.fontSize = ((item.Kind == ItemKind.Header) ? _layout.SearchGroupHeaderFontSize : _layout.SuggestionFontSize);
				float num2 = label.cachedTextGeneratorForLayout.GetPreferredWidth(item.Label ?? string.Empty, generationSettings) / label.pixelsPerUnit;
				num = Mathf.Max(num, num2);
			}
			float num3 = num + _layout.SuggestionLabelPaddingX * 2f + _layout.SuggestionCountWidth + (float)_layout.SearchDropdownPadding * 2f;
			_dropdownRt.sizeDelta = new Vector2(Mathf.Max(_inputRt.sizeDelta.x, Mathf.Ceil(num3)), _dropdownRt.sizeDelta.y);
		}

		private int ScoreMatch(SearchItem item, string q)
		{
			if (item.NameLower.StartsWith(q))
			{
				return 1000 - item.NameLower.Length;
			}
			if (item.NameLower.Contains(q))
			{
				return 800 - item.NameLower.Length;
			}
			if (item.IdLower.StartsWith(q))
			{
				return 600 - item.IdLower.Length;
			}
			if (item.IdLower.Contains(q))
			{
				return 400 - item.IdLower.Length;
			}
			if (item.HaystackLower.Contains(q))
			{
				return 200 - item.HaystackLower.Length;
			}
			return 0;
		}

		private int NextSelectable(int from, int direction)
		{
			for (int i = from + direction; i >= 0 && i < _items.Count; i += direction)
			{
				if (_items[i].Selectable)
				{
					return i;
				}
			}
			return -1;
		}

		private void Move(int direction, bool rumble)
		{
			int num = NextSelectable(_selected, direction);
			if (num >= 0)
			{
				Select(num);
				if (rumble && (Object)(object)GamepadRumble.instance != (Object)null)
				{
					GamepadRumble.instance.PlayGlobalSelectVibration();
				}
			}
		}

		private void Select(int index)
		{
			_selected = index;
			int rowCount = RowCount;
			int num = ((index > 0 && !_items[index - 1].Selectable) ? (index - 1) : index);
			if (num < _offset)
			{
				_offset = num;
			}
			else if (index >= _offset + rowCount)
			{
				_offset = index - rowCount + 1;
			}
			_offset = Mathf.Clamp(_offset, 0, Mathf.Max(0, _items.Count - rowCount));
			ShowRows();
		}

		private void ShowRows()
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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)
			int rowCount = RowCount;
			EnsureSuggestionEntries(rowCount);
			ShowMore(_items.Count - (_offset + rowCount));
			for (int i = 0; i < _suggestions.Count; i++)
			{
				SuggestionEntry suggestionEntry = _suggestions[i];
				bool flag = i < rowCount;
				suggestionEntry.Go.SetActive(flag);
				if (flag)
				{
					ListItem listItem = _items[_offset + i];
					bool flag2 = listItem.Kind == ItemKind.Header;
					suggestionEntry.Label.text = ((flag2 || _browsing) ? listItem.Label : WithMatch(listItem.Label, _query));
					suggestionEntry.Label.fontSize = (flag2 ? _layout.SearchGroupHeaderFontSize : _layout.SuggestionFontSize);
					((Graphic)suggestionEntry.Label).color = (flag2 ? UiTheme.Colors.Orange : Color.white);
					suggestionEntry.Count.text = listItem.Count ?? string.Empty;
					((Graphic)suggestionEntry.Background).raycastTarget = !flag2;
					((Graphic)suggestionEntry.Background).color = (flag2 ? Color.clear : ((_offset + i == _selected) ? _theme.SuggestionSelected : _theme.SuggestionNormal));
				}
			}
		}

		private static string WithMatch(string label, string query)
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(label) || string.IsNullOrEmpty(query) || label.IndexOf('<') >= 0)
			{
				return label;
			}
			string text = query.Trim();
			int num = -1;
			for (int num2 = label.IndexOf(text, StringComparison.OrdinalIgnoreCase); num2 >= 0; num2 = ((num2 + 1 < label.Length) ? label.IndexOf(text, num2 + 1, StringComparison.OrdinalIgnoreCase) : (-1)))
			{
				if (num < 0)
				{
					num = num2;
				}
				if (num2 == 0 || !char.IsLetterOrDigit(label[num2 - 1]))
				{
					num = num2;
					break;
				}
			}
			if (num < 0)
			{
				return label;
			}
			string text2 = ColorUtility.ToHtmlStringRGB(UiTheme.Colors.Yellow);
			return label.Substring(0, num) + "<color=#" + text2 + ">" + label.Substring(num, text.Length) + "</color>" + label.Substring(num + text.Length);
		}

		private void EnsureSuggestionEntries(int count)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: 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_018b: 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_01b5: Unknown result type (might be due to invalid IL or missing references)
			while (_suggestions.Count < count)
			{
				int count2 = _suggestions.Count;
				GameObject val = new GameObject($"Row_{count2}", new Type[3]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(LayoutElement)
				});
				val.transform.SetParent(_dropdown.transform, false);
				RectTransform val2 = (RectTransform)val.transform;
				val2.sizeDelta = new Vector2(0f, _layout.SuggestionRowHeight);
				LayoutElement component = val.GetComponent<LayoutElement>();
				component.minHeight = _layout.SuggestionRowHeight;
				component.preferredHeight = _layout.SuggestionRowHeight;
				component.flexibleHeight = 0f;
				Image component2 = val.GetComponent<Image>();
				((Graphic)component2).color = _theme.SuggestionNormal;
				((Graphic)component2).raycastTarget = true;
				Button val3 = val.AddComponent<Button>();
				((Selectable)val3).transition = (Transition)0;
				SuggestionPointerDownCatcher suggestionPointerDownCatcher = val.AddComponent<SuggestionPointerDownCatcher>();
				suggestionPointerDownCatcher.Owner = this;
				suggestionPointerDownCatcher.Index = count2;
				Text val4 = MakeRowText(val.transform, "Label", (TextAnchor)3, new Vector2(_layout.SuggestionLabelPaddingX, 0f), new Vector2(0f - _layout.SuggestionLabelPaddingX - _layout.SuggestionCountWidth, 0f));
				val4.supportRichText = true;
				Text val5 = MakeRowText(val.transform, "Count", (TextAnchor)5, new Vector2(_layout.SuggestionLabelPaddingX, 0f), new Vector2(0f - _layout.SuggestionLabelPaddingX, 0f));
				((Graphic)val5).color = _theme.StatsZeroTextColor;
				_suggestions.Add(new SuggestionEntry
				{
					Go = val,
					Button = val3,
					Background = component2,
					Label = val4,
					Count = val5
				});
			}
		}

		private void ShowMore(int below)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_more == (Object)null)
			{
				GameObject val = new GameObject("More", new Type[2]
				{
					typeof(RectTransform),
					typeof(LayoutElement)
				});
				val.transform.SetParent(_dropdown.transform, false);
				LayoutElement component = val.GetComponent<LayoutElement>();
				float minHeight = (component.preferredHeight = _layout.SearchMoreHeight);
				component.minHeight = minHeight;
				_more = MakeRowText(val.transform, "Text", (TextAnchor)4, Vector2.zero, Vector2.zero);
				_more.fontSize = _layout.SearchGroupHeaderFontSize;
				((Graphic)_more).color = _theme.StatsZeroTextColor;
			}
			GameObject gameObject = ((Component)((Component)_more).transform.parent).gameObject;
			bool flag = below > 0;
			if (flag)
			{
				_more.text = StatFormat.Apply(TalentLocalization.T("tt_ui_search_more"), below.ToString());
				gameObject.transform.SetAsLastSibling();
			}
			if (gameObject.activeSelf != flag)
			{
				gameObject.SetActive(flag);
			}
		}

		private Text MakeRowText(Transform row, string name, TextAnchor alignment, Vector2 offsetMin, Vector2 offsetMax)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_003c: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_007d: 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)
			GameObject val = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(Text)
			});
			val.transform.SetParent(row, false);
			UiFactory.SetRectStretch((RectTransform)val.transform, offsetMin, offsetMax);
			Text component = val.GetComponent<Text>();
			component.text = "";
			component.font = UiTheme.Fonts.Body;
			component.fontSize = _layout.SuggestionFontSize;
			((Graphic)component).color = Color.white;
			component.alignment = alignment;
			component.supportRichText = false;
			((Graphic)component).raycastTarget = false;
			return component;
		}

		private void SelectByRow(int row)
		{
			int num = _offset + row;
			if (row >= 0 && row < RowCount && num < _items.Count && _items[num].Selectable)
			{
				_selected = num;
				ShowRows();
				TrySelectCurrent();
			}
		}

		private bool TrySelectCurrent()
		{
			if (_selected < 0 || _selected >= _items.Count)
			{
				return false;
			}
			ListItem listItem = _items[_selected];
			if (!listItem.Selectable)
			{
				return false;
			}
			_markTypedAt = -1f;
			_selecting = true;
			try
			{
				HideDropdown();
				_input.DeactivateInputField();
				switch (listItem.Kind)
				{
				case ItemKind.Talent:
					this.Chosen?.Invoke(new SearchChoice(SearchChoiceKind.Talent, null, null), new string[1] { listItem.TalentId });
					break;
				case ItemKind.Stat:
					this.Chosen?.Invoke(new SearchChoice(SearchChoiceKind.Stat, listItem.StatId, null), _stats.NodesFor(listItem.StatId));
					break;
				case ItemKind.AllWith:
					this.Chosen?.Invoke(new SearchChoice(SearchChoiceKind.AllWith, null, _query), _stats.NodesForAll(_matchedStats));
					break;
				case ItemKind.NearbyPlayers:
					this.Chosen?.Invoke(new SearchChoice(SearchChoiceKind.NearbyPlayers, null, null), _stats.NodesForNearbyPlayers());
					break;
				}
			}
			finally
			{
				_selecting = false;
			}
			return true;
		}

		private static bool IsSubmitKeyDown()
		{
			return ZInput.GetKeyDown((KeyCode)13, true) || ZInput.GetKeyDown((KeyCode)271, true);
		}
	}
	internal static class TalentTreeLayoutCoordinator
	{
		public static float TreeBaseSize { get; private set; }

		public static float AutoFitZoom { get; private set; }

		public static float MinZoom { get; private set; } = TalentUiLayout.Default.MinZoom;

		private static TalentUiLayout Layout => TalentUiLayout.Default;

		private static Vector2 ComputeContentSize(float vpW, float vpH)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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)
			float num = Mathf.Max(vpW, vpH);
			float num2 = Layout.ScrollExtraPadding * (vpW / num);
			float num3 = Layout.ScrollExtraPadding * (vpH / num);
			float num4 = TreeBaseSize + 2f * num2;
			float num5 = TreeBaseSize + 2f * num3;
			float num6 = Mathf.Max(0.01f, Layout.StartZoom);
			float num7 = (vpW - vpH) / num6;
			float num8 = ((num7 > 0f) ? (num4 + num7) : num4);
			float num9 = ((num7 > 0f) ? num5 : (num5 - num7));
			return new Vector2(num8, num9);
		}

		public static RadialLayout.LayoutResult ApplyRadialLayout(TalentTreeView tree)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			string[] orderedIds = SectorRegistry.GetOrderedIds();
			RadialLayout.LayoutResult layoutResult = RadialLayout.ComputePositionsNoOverlap(TalentRegistry.All, orderedIds, RadialLayoutParams.FromLayout(Layout));
			foreach (KeyValuePair<string, Vector2> position in layoutResult.Positions)
			{
				tree.SetNodePosition(position.Key, position.Value);
			}
			return layoutResult;
		}

		public static void ResizeWorldToFit(float maxRadius, TalentWindowView view, SectorLabelTracker labels)
		{
			//IL_0051: 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_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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: 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)
			TreeBaseSize = Mathf.Max(Layout.MinWorldSize, maxRadius * 2f + Layout.WorldPadding);
			float num = TreeBaseSize;
			float num2 = TreeBaseSize;
			Rect rect;
			if ((Object)(object)view?.ViewportRt != (Object)null)
			{
				rect = view.ViewportRt.rect;
				float width = ((Rect)(ref rect)).width;
				rect = view.ViewportRt.rect;
				float height = ((Rect)(ref rect)).height;
				if (width > 0f && height > 0f)
				{
					Vector2 val = ComputeContentSize(width, height);
					num = val.x;
					num2 = val.y;
				}
			}
			if ((Object)(object)view?.ContentRt != (Object)null)
			{
				view.ContentRt.sizeDelta = new Vector2(num, num2);
			}
			if ((Object)(object)view?.WorldRt != (Object)null)
			{
				view.WorldRt.sizeDelta = new Vector2(num, num2);
			}
			if ((Object)(object)view?.ScrollRect != (Object)null)
			{
				view.ScrollRect.normalizedPosition = new Vector2(0.5f, 0.5f);
			}
			AutoFitZoom = Layout.StartZoom;
			MinZoom = Layout.MinZoom;
			if ((Object)(object)view?.ViewportRt != (Object)null && TreeBaseSize > 0f)
			{
				rect = view.ViewportRt.rect;
				float width2 = ((Rect)(ref rect)).width;
				rect = view.ViewportRt.rect;
				float height2 = ((Rect)(ref rect)).height;
				if (width2 > 0f && height2 > 0f)
				{
					UpdateZoomLimits(width2, height2, labels);
				}
			}
		}

		public static SectorLabelTracker InitSectorLabelTracker(TalentWindowView view, RadialLayout.LayoutResult layoutResult, IReadOnlyDictionary<string, RectTransform> nodeRects, SectorLabelTracker existing)
		{
			if ((Object)(object)existing != (Object)null)
			{
				existing.Cleanup();
				Object.Destroy((Object)(object)existing);
			}
			if (view == null || (Object)(object)view.ViewportRt == (Object)null || (Object)(object)view.WorldRt == (Object)null)
			{
				return null;
			}
			Transform parent = ((Transform)view.ViewportRt).parent;
			GameObject val = (((Object)(object)parent != (Object)null) ? ((Component)parent).gameObject : ((Component)view.ViewportRt).gameObject);
			SectorLabelTracker sectorLabelTracker = val.AddComponent<SectorLabelTracker>();
			sectorLabelTracker.Initialize(view.WorldRt, view.ViewportRt, layoutResult.SectorMidAngles, layoutResult.Positions, nodeRects, Layout, TalentUiTheme.Default);
			return sectorLabelTracker;
		}

		public static void RecalculateForViewport(TalentWindowView view, SectorLabelTracker labels)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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)
			if ((Object)(object)view?.ViewportRt == (Object)null || (Object)(object)view?.ContentRt == (Object)null || TreeBaseSize <= 0f)
			{
				return;
			}
			Rect rect = view.ViewportRt.rect;
			float width = ((Rect)(ref rect)).width;
			rect = view.ViewportRt.rect;
			float height = ((Rect)(ref rect)).height;
			if (!(width <= 0f) && !(height <= 0f))
			{
				Vector2 sizeDelta = ComputeContentSize(width, height);
				view.ContentRt.sizeDelta = sizeDelta;
				if ((Object)(object)view.WorldRt != (Object)null)
				{
					view.WorldRt.sizeDelta = sizeDelta;
				}
				UpdateZoomLimits(width, height, labels);
			}
		}

		private static void UpdateZoomLimits(float vpW, float vpH, SectorLabelTracker labels)
		{
			//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_000d: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			Vector4 treeContentInsets = Layout.TreeContentInsets;
			float num = vpW - treeContentInsets.x - treeContentInsets.z;
			float num2 = vpH - treeContentInsets.y - treeContentInsets.w;
			float num3 = Mathf.Min(num, num2) / TreeBaseSize;
			if ((Object)(object)labels != (Object)null)
			{
				num3 = Mathf.Min(num3, labels.FitZoom(num, num2));
			}
			num3 = Mathf.Max(num3, Layout.ZoomFloor);
			MinZoom = Mathf.Min(Layout.MinZoom, num3);
			AutoFitZoom = Mathf.Clamp(num3, Layout.MinZoom, Layout.MaxZoom);
		}
	}
	public static class TalentWindow
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Action <0>__Tick;

			public static Action <1>__LateTick;

			public static Action<bool> <2>__Back;

			public static UnityAction <3>__Toggle;

			public static UnityAction <4>__ToggleStats;

			public static UnityAction <5>__ToggleBuilds;

			public static UnityAction <6>__OnApplyClicked;

			public static UnityAction <7>__OnResetDraftClicked;

			public static Action <8>__OnLocalizationUpdated;

			public static Action <9>__HidePreview;

			public static Action<string, bool> <10>__ShowHoverPreview;

			public static Action<string> <11>__CenterOnNode;

			public static Action <12>__Refresh;

			public static Action<IReadOnlyCollection<string>> <13>__OnDraftApplied;

			public static Action <14>__EndMarkOfClosedTalent;

			public static Action <15>__RefreshTree;

			public static Action<ResolvedBuild> <16>__ShowBuildPreview;

			public static Action <17>__HideBuildPreview;

			public static Action<ResolvedBuild> <18>__OnBuildApplyRequested;

			public static Action<string, bool> <19>__SetBuildsKeys;

			public static Func<TalentDefinition, string> <20>__GetTalentDisplayName;

			public static Action<TalentSearchController.SearchChoice, IReadOnlyList<string>> <21>__ShowSearchMark;

			public static Action <22>__HideSearchMark;

			public static Func<string, Vector2?> <23>__GetCenterTarget;
		}

		private static TalentWindowView _view;

		private static TalentTreeView _tree;

		private static TalentNodeHalos _halos;

		private static TalentNodeMarks _marks;

		private static TalentTreePathView _paths;

		private static LearnRevealState _reveal;

		private static TalentTreeState _treeState;

		private static TalentHoverTooltip _hoverTooltip;

		private static StatsPanelView _statsPanel;

		private static BuildsPanelView _buildsPanel;

		private static TalentConfirmDialog _confirmDialog;

		private static ApplyWaveEffect _wave;

		private static TalentSearchController _search;

		private static SectorLabelTracker _sectorTracker;

		private static IReadOnlyDictionary<string, RectTransform> _nodeRects;

		private static TalentWindowHoverController _hover;

		private static TalentWindowSelectionController _selection;

		private static TalentWindowGamepadController _gamepad;

		private const int WindowGroupPriority = 5;

		private static GameObject _gamepadGroup;

		private static GameObject _searchHint;

		private static UIGamePad _tooltipPad;

		private static UIGamePad _applyPad;

		private static bool _gamepadBound;

		private static bool _gamepadWasActive;

		private static GameObject _selectedBeforeOpen;

		private static int _reselectAtFrame;

		private static bool _statsOpen;

		private static GameObject _updaterHost;

		private static UpdateLoopRunner _loop;

		private static LateUpdateLoopRunner _lateLoop;

		private static bool _pendingBuild;

		private static bool _pendingOpen;

		private static bool _loggedGuiNotReady;

		private static readonly object WindowOwner = new object();

		private static bool _wasOnTop;

		private static readonly List<string> _route = new List<string>();

		private static bool _routeShown;

		private static ResolvedBuild _buildPreview;

		private static IReadOnlyList<string> _markNodes;

		private static string _markOpened;

		private static TalentUiLayout Layout => TalentUiLayout.Default;

		private static TalentUiTheme Theme => TalentUiTheme.Default;

		public static bool IsOpen => (Object)(object)_view?.Root != (Object)null && _view.Root.activeSelf;

		internal static bool IsBuildsPanelOpen => IsOpen && _buildsPanel != null && _buildsPanel.IsVisible;

		public static void EnsureBuilt()
		{
			EnsureUpdateLoop();
			if (_view != null && (Object)(object)_view.Root == (Object)null)
			{
				_view = null;
			}
			if ((Object)(object)UiRoot.Front == (Object)null)
			{
				_pendingBuild = true;
				return;
			}
			if (_view != null && (Object)(object)_view.Root != (Object)null && (Object)(object)_view.Root.transform.parent != (Object)(object)UiRoot.Front)
			{
				Object.Destroy((Object)(object)_view.Root);
				_view = null;
			}
			if (_view != null)
			{
				return;
			}
			try
			{
				BuildUI();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Failed building Talent window UI: {arg}");
				_view = null;
			}
		}

		private static void EnsureUpdateLoop()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			if (!((Object)(object)_loop != (Object)null))
			{
				_updaterHost = new GameObject("TalentTree_UpdateLoop");
				Object.DontDestroyOnLoad((Object)(object)_updaterHost);
				_loop = _updaterHost.AddComponent<UpdateLoopRunner>();
				_loop.Tick = Tick;
				_lateLoop = _updaterHost.AddComponent<LateUpdateLoopRunner>();
				_lateLoop.Tick = LateTick;
			}
		}

		public static void Toggle()
		{
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			EnsureBuilt();
			if ((Object)(object)_view?.Root == (Object)null)
			{
				_pendingBuild = true;
				_pendingOpen = true;
				if (!_loggedGuiNotReady)
				{
					Plugin.Log.LogWarning((object)"Talent window UI is not ready yet (Custom GUI is rebuilding). It will open automatically once available.");
					_loggedGuiNotReady = true;
				}
				return;
			}
			_loggedGuiNotReady = false;
			bool flag = !_view.Root.activeSelf;
			if (!flag)
			{
				_buildsPanel?.SetVisible(visible: false);
				if ((Object)(object)_wave != (Object)null)
				{
					_wave.Stop(redraw: false);
				}
			}
			_view.Root.SetActive(flag);
			if (flag)
			{
				UiInputBlock.Push(WindowOwner);
				UiWindowStack.Open(WindowOwner, (RectTransform)_view.Root.transform, Back);
			}
			else
			{
				UiInputBlock.Pop(WindowOwner);
				UiWindowStack.Close(WindowOwner);
			}
			if (flag)
			{
				OnOpened();
			}
			else
			{
				OnClosed();
			}
		}

		private static void BuildUI()
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//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_00e9: Expected O, but got Unknown
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			//IL_016a: 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_0175: Expected O, but got Unknown
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Expected O, but got Unknown
			_view = TalentWindowView.Build();
			_view.ApplyLocalization();
			_gamepadGroup = ((Component)UiFactory.CreateRect("GamepadGroup", _view.Root.transform)).gameObject;
			_gamepadGroup.AddComponent<UIGroupHandler>().m_groupPriority = 5;
			_gamepadGroup.SetActive(false);
			_gamepadBound = false;
			_tooltipPad = null;
			_applyPad = null;
			if ((Object)(object)_view.CloseButton != (Object)null)
			{
				ButtonClickedEvent onClick = _view.CloseButton.onClick;
				object obj = <>O.<3>__Toggle;
				if (obj == null)
				{
					UnityAction val = Toggle;
					<>O.<3>__Toggle = val;
					obj = (object)val;
				}
				((UnityEvent)onClick).AddListener((UnityAction)obj);
			}
			if ((Object)(object)_view.StatsButton != (Object)null)
			{
				ButtonClickedEvent onClick2 = _view.StatsButton.onClick;
				object obj2 = <>O.<4>__ToggleStats;
				if (obj2 == null)
				{
					UnityAction val2 = ToggleStats;
					<>O.<4>__ToggleStats = val2;
					obj2 = (object)val2;
				}
				((UnityEvent)onClick2).AddListener((UnityAction)obj2);
			}
			if ((Object)(object)_view.BuildsButton != (Object)null)
			{
				ButtonClickedEvent onClick3 = _view.BuildsButton.onClick;
				object obj3 = <>O.<5>__ToggleBuilds;
				if (obj3 == null)
				{
					UnityAction val3 = ToggleBuilds;
					<>O.<5>__ToggleBuilds = val3;
					obj3 = (object)val3;
				}
				((UnityEvent)onClick3).AddListener((UnityAction)obj3);
			}
			if ((Object)(object)_view.ApplyButton != (Object)null)
			{
				ButtonClickedEvent onClick4 = _view.ApplyButton.onClick;
				object obj4 = <>O.<6>__OnApplyClicked;
				if (obj4 == null)
				{
					UnityAction val4 = OnApplyClicked;
					<>O.<6>__OnApplyClicked = val4;
					obj4 = (object)val4;
				}
				((UnityEvent)onClick4).AddListener((UnityAction)obj4);
			}
			if ((Object)(object)_view.ResetButton != (Object)null)
			{
				ButtonClickedEvent onClick5 = _view.ResetButton.onClick;
				object obj5 = <>O.<7>__OnResetDraftClicked;
				if (obj5 == null)
				{
					UnityAction val5 = OnResetDraftClicked;
					<>O.<7>__OnResetDraftClicked = val5;
					obj5 = (object)val5;
				}
				((UnityEvent)onClick5).AddListener((UnityAction)obj5);
			}
			TalentLocalization.LocalizationUpdated -= OnLocalizationUpdated;
			TalentLocalization.LocalizationUpdated += OnLocalizationUpdated;
			_hover = new TalentWindowHoverController(Layout, () => _selection != null && _selection.Pinned, delegate(string id)
			{
				ShowHoverPreview(id);
			}, HidePreview);
			_selection = new TalentWindowSelectionController(_hover, ShowHoverPreview, HidePreview, CenterOnNode, Refresh, OnDraftApplied);
			_selection.Changed += EndMarkOfClosedTalent;
			_reveal = new LearnRevealState();
			_treeState = new TalentTreeState(_reveal);
			_halos = new TalentNodeHalos(Layout, Theme);
			_marks = new TalentNodeMarks(Layout);
			_tree = new TalentTreeView(Layout, Theme, _marks);
			_tree.Build(_view.NodesRootRt, TalentRegistry.All);
			if ((Object)(object)_view.TreePointer != (Object)null)
			{
				_view.TreePointer.Init(_tree.NodeAt);
				_view.TreePointer.NodeClicked += _selection.OnNodeClicked;
				_view.TreePointer.NodeEnter += _hover.OnNodeHoverEnter;
				_view.TreePointer.NodeExit += _hover.OnNodeHoverExit;
				_view.TreePointer.EmptyClicked += _selection.OnPanelClicked;
			}
			RadialLayout.LayoutResult layoutResult = TalentTreeLayoutCoordinator.ApplyRadialLayout(_tree);
			_nodeRects = _tree.NodeRects;
			TalentTreeLayoutCoordinator.ResizeWorldToFit(layoutResult.MaxRadius, _view, null);
			_sectorTracker = TalentTreeLayoutCoordinator.InitSectorLabelTracker(_view, layoutResult, _nodeRects, _sectorTracker);
			_halos.Build(_view.PathsRootRt, TalentRegistry.All, _nodeRects);
			_paths = new TalentTreePathView(_view.PathsRootRt, Layout, Theme);
			_paths.Build(TalentRegistry.All, _nodeRects);
			_marks.Build(_view.PathsRootRt, _nodeRects);
			_wave = ((Component)_view.NodesRootRt).gameObject.AddComponent<ApplyWaveEffect>();
			_wave.Init(_tree, _paths, _reveal, RefreshTree, Layout, Theme, _view.PathsRootRt);
			if ((Object)(object)_view.TreeClip != (Object)null)
			{
				_view.TreeClip.Invalidate();
			}
			_statsPanel = new StatsPanelView();
			_statsPanel.Build(_view.PanelRect, Layout);
			_statsPanel.ApplyLocalization();
			_statsPanel.SetVisible(visible: false);
			BuildLibrary buildLibrary = new BuildLibrary(BuildLibraryLocation.FilePath);
			buildLibrary.Load();
			_buildsPanel = new BuildsPanelView();
			_buildsPanel.Build(_view.PanelRect, Layout, buildLibrary);
			_buildsPanel.PreviewRequested += ShowBuildPreview;
			_buildsPanel.PreviewHidden += HideBuildPreview;
			_buildsPanel.ApplyRequested += OnBuildApplyRequested;
			_buildsPanel.ConfirmRequested += delegate(string message, Action onConfirm)
			{
				_confirmDialog?.Show(message, onConfirm);
			};
			_buildsPanel.KeysChanged += TalentKeyHintsView.SetBuildsKeys;
			_hoverTooltip = new TalentHoverTooltip();
			_hoverTooltip.Build(_view.PanelRect);
			_view.TreeClip?.AlsoClip(_hoverTooltip.Root.transform);
			_hoverTooltip.SelectRequested += _selection.StageById;
			_hoverTooltip.SelectAllRequested += _selection.StageAllById;
			_hoverTooltip.DeselectRequested += _selection.UnstageById;
			_hoverTooltip.Hide();
			_confirmDialog = new TalentConfirmDialog();
			_confirmDialog.Build(_view.PanelRect);
			if ((Object)(object)_view.PanelClickCatcher != (Object)null)
			{
				_view.PanelClickCatcher.Clicked += _selection.OnPanelClicked;
			}
			_search = new TalentSearchController(_view.SearchInput, _view.SearchInputRt, _view.SearchDropdown, _view.SearchDropdownRt, Theme, Layout);
			_search.Bind(GetTalentDisplayName);
			_search.Chosen += ShowSearchMark;
			_search.Emptied += HideSearchMark;
			_search.RebuildIndex(TalentRegistry.All);
			_gamepad = new TalentWindowGamepadController(_view, _nodeRects, _selection, GetCenterTarget, () => (_confirmDialog != null && _confirmDialog.IsVisible) || (_search != null && _search.IsDropdownVisible) || ValheimTextDialog.IsOpen, () => _buildsPanel != null && _buildsPanel.IsVisible);
			_gamepad.SearchMarks = () => _markNodes;
			ApplyZOrder();
		}

		private static void BindGamepad()
		{
			if (!_gamepadBound && !((Object)(object)InventoryGui.instance == (Object)null))
			{
				_gamepadBound = true;
				List<GameObject> list = new List<GameObject>();
				if ((Object)(object)_confirmDialog?.Root != (Object)null)
				{
					list.Add(_confirmDialog.Root);
				}
				if ((Object)(object)_view.SearchDropdown != (Object)null)
				{
					list.Add(_view.SearchDropdown);
				}
				if ((Object)(object)ValheimTextDialog.Panel != (Object)null)
				{
					list.Add(ValheimTextDialog.Panel);
				}
				GamepadHints.Bind(_view.CloseButton, null, "JoyButtonB", (KeyCode)0);
				BlockBy(GamepadHints.Bind(_view.StatsButton, "JoyRStick", null, (KeyCode)0), list);
				BlockBy(GamepadHints.Bind(_view.BuildsButton, "JoyStart", null, (KeyCode)0), list);
				_applyPad = GamepadHints.Bind(_view.ApplyButton, "JoyButtonX", null, (KeyCode)0);
				BlockBy(_applyPad, list);
				BlockBy(GamepadHints.Bind(_view.ResetButton, "JoyBack", null, (KeyCode)0), list);
				_tooltipPad = _hoverTooltip?.BindGamepad();
				BlockBy(_tooltipPad, list);
				_confirmDialog?.BindGamepad();
				_searchHint = GamepadHints.CreateHint((Transform)(object)_view.SearchInputRt, "JoyLStick");
			}
		}

		private static void Back(bool fromController)
		{
			if (ValheimTextDialog.OpenLately)
			{
				return;
			}
			if (_confirmDialog != null && _confirmDialog.IsVisible)
			{
				_confirmDialog.Hide();
			}
			else if (_search != null && _search.IsDropdownVisible)
			{
				_search.HideDropdown();
			}
			else if ((_buildsPanel == null || !_buildsPanel.CancelRename()) && (!fromController || _buildsPanel == null || !_buildsPanel.Back()))
			{
				if (!fromController && _selection != null && _selection.Pinned)
				{
					_selection.CloseAndUnpin();
				}
				else if (_markNodes != null)
				{
					HideSearchMark();
				}
				else if (_buildsPanel != null && _buildsPanel.IsVisible)
				{
					_buildsPanel.SetVisible(visible: false);
				}
				else if (IsOpen)
				{
					Toggle();
				}
			}
		}

		private static void SetGamepadButtonsActive(bool active)
		{
			if (!((Object)(object)_view?.Root == (Object)null))
			{
				UIGamePad[] componentsInChildren = _view.Root.GetComponentsInChildren<UIGamePad>(true);
				foreach (UIGamePad pad in componentsInChildren)
				{
					SetPadAwake(pad, active);
				}
			}
		}

		private static void SetPadAwake(UIGamePad pad, bool awake)
		{
			if (!((Object)(object)pad == (Object)null))
			{
				if (((Behaviour)pad).enabled != awake)
				{
					((Behaviour)pad).enabled = awake;
				}
				if (!awake && (Object)(object)pad.m_hint != (Object)null && pad.m_hint.activeSelf)
				{
					pad.m_hint.SetActive(false);
				}
			}
		}

		private static void BlockBy(UIGamePad pad, List<GameObject> blockers)
		{
			if ((Object)(object)pad != (Object)null)
			{
				pad.m_blockingElements = blockers;
			}
		}

		private static void OnLocalizationUpdated()
		{
			if (!((Object)(object)_view?.Root == (Object)null))
			{
				_view.ApplyLocalization();
				_statsPanel?.ApplyLocalization();
				_buildsPanel?.ApplyLocalization();
				if ((Object)(object)_sectorTracker != (Object)null)
				{
					_sectorTracker.RefreshLabelText();
				}
				_hoverTooltip?.ApplyLocalization();
				_confirmDialog?.ApplyLocalization();
				TalentKeyHintsView.Invalidate();
				_search?.RebuildIndex(TalentRegistry.All);
				if (IsOpen)
				{
					Refresh();
				}
			}
		}

		private static void ApplyZOrder()
		{
			RectTransform searchInputRt = _view.SearchInputRt;
			if (searchInputRt != null)
			{
				((Transform)searchInputRt).SetAsLastSibling();
			}
			RectTransform searchDropdownRt = _view.SearchDropdownRt;
			if (searchDropdownRt != null)
			{
				((Transform)searchDropdownRt).SetAsLastSibling();
			}
			StatsPanelView statsPanel = _statsPanel;
			if (statsPanel != null)
			{
				GameObject root = statsPanel.Root;
				if (root != null)
				{
					root.transform.SetAsLastSibling();
				}
			}
			BuildsPanelView buildsPanel = _buildsPanel;
			if (buildsPanel != null)
			{
				GameObject root2 = buildsPanel.Root;
				if (root2 != null)
				{
					root2.transform.SetAsLastSibling();
				}
			}
			TalentHoverTooltip hoverTooltip = _hoverTooltip;
			if (hoverTooltip != null)
			{
				GameObject root3 = hoverTooltip.Root;
				if (root3 != null)
				{
					root3.transform.SetAsLastSibling();
				}
			}
			TalentConfirmDialog confirmDialog = _confirmDialog;
			if (confirmDialog != null)
			{
				GameObject root4 = confirmDialog.Root;
				if (root4 != null)
				{
					root4.transform.SetAsLastSibling();
				}
			}
		}

		private static void OnOpened()
		{
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			TalentPointsNotice.MarkSeen(Player.m_localPlayer);
			BindGamepad();
			EventSystem current = EventSystem.current;
			if ((Object)(object)current != (Object)null)
			{
				_selectedBeforeOpen = current.currentSelectedGameObject;
				current.SetSelectedGameObject((GameObject)null);
			}
			if (ZInput.instance != null)
			{
				ZInput.ResetButtonStatus("JoyButtonA");
			}
			_selection?.ResetOnOpen();
			_hover?.Reset();
			_gamepad?.Reset();
			_gamepadWasActive = ZInput.IsGamepadActive();
			_statsOpen = false;
			HidePreview();
			_statsPanel?.SetVisible(visible: false);
			_buildsPanel?.SetVisible(visible: false);
			_confirmDialog?.Hide();
			HideBuildPreview();
			HideSearchMark();
			UpdateDraftButtonsInteractable();
			TalentTreeLayoutCoordinator.RecalculateForViewport(_view, _sectorTracker);
			if ((Object)(object)_view.Zoom != (Object)null)
			{
				_view.Zoom.Initialize(_view.ViewportRt, _view.ContentRt, _view.ScrollRect, TalentTreeLayoutCoordinator.MinZoom, Layout.MaxZoom, Layout.ZoomFactorPerStep, Layout.MouseWheelDeadzone);
				_view.Zoom.SetScale(TalentTreeLayoutCoordinator.AutoFitZoom);
			}
			if ((Object)(object)_view.ScrollRect != (Object)null)
			{
				_view.ScrollRect.StopMovement();
				_view.ScrollRect.normalizedPosition = new Vector2(0.5f, 0.5f);
				RectTransform contentRt = _view.ContentRt;
				contentRt.anchoredPosition += Layout.TreeContentCentre;
			}
			_search?.Clear();
			_search?.RebuildIndex(TalentRegistry.All);
			Refresh();
		}

		private static void OnClosed()
		{
			HideSearchMark();
			_reselectAtFrame = Time.frameCount + 2;
		}

		private static void RestoreInventorySelection()
		{
			GameObject selectedBeforeOpen = _selectedBeforeOpen;
			_selectedBeforeOpen = null;
			EventSystem current = EventSystem.current;
			if ((Object)(object)current != (Object)null && (Object)(object)selectedBeforeOpen != (Object)null && selectedBeforeOpen.activeInHierarchy && InventoryGui.IsVisible())
			{
				current.SetSelectedGameObject(selectedBeforeOpen);
			}
		}

		private static void Tick()
		{
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			ValheimTextDialog.Tick();
			if ((Object)(object)_selectedBeforeOpen != (Object)null && !IsOpen && Time.frameCount >= _reselectAtFrame)
			{
				RestoreInventorySelection();
			}
			if (_pendingBuild || _pendingOpen)
			{
				if (_view != null && (Object)(object)_view.Root == (Object)null)
				{
					_view = null;
				}
				if ((Object)(object)UiRoot.Front != (Object)null)
				{
					EnsureBuilt();
					_pendingBuild = false;
					_loggedGuiNotReady = false;
					if (_pendingOpen && (Object)(object)_view?.Root != (Object)null)
					{
						_pendingOpen = false;
						if (!_view.Root.activeSelf)
						{
							_view.Root.SetActive(true);
							UiInputBlock.Push(WindowOwner);
							UiWindowStack.Open(WindowOwner, (RectTransform)_view.Root.transform, Back);
							OnOpened();
						}
					}
				}
			}
			if (IsOpen)
			{
				bool flag = UiWindowStack.IsTop(WindowOwner);
				if (flag != _wasOnTop)
				{
					_wasOnTop = flag;
					SetGamepadButtonsActive(flag);
				}
				_search?.Tick();
				_hoverTooltip?.Tick();
				if (flag)
				{
					TickShortcuts();
				}
				bool flag2 = (_confirmDialog != null && _confirmDialog.IsVisible) || ValheimTextDialog.IsOpen;
				bool flag3 = _buildsPanel != null && _buildsPanel.IsVisible;
				bool flag4 = ZInput.IsExclusiveGamepadActive() && !ZInput.IsTouchActive();
				bool flag5 = flag4 && !flag2 && flag;
				if (flag5 && !flag3)
				{
					_search?.TickGamepad();
				}
				if (flag5 && (_search == null || !_search.IsDropdownVisible))
				{
					_buildsPanel?.TickGamepad();
				}
				if (!flag2 && flag)
				{
					_buildsPanel?.Tick();
				}
				SetPadAwake(_tooltipPad, flag && !flag3);
				SetPadAwake(_applyPad, flag && !flag3);
				bool flag6 = flag4 && flag && !flag3;
				if ((Object)(object)_searchHint != (Object)null && _searchHint.activeSelf != flag6)
				{
					_searchHint.SetActive(flag6);
				}
				if (flag)
				{
					_gamepad?.Tick();
				}
				bool flag7 = ZInput.IsGamepadActive();
				bool flag8 = flag7 && flag;
				if ((Object)(object)_gamepadGroup != (Object)null && _gamepadGroup.activeSelf != flag8)
				{
					_gamepadGroup.SetActive(flag8);
				}
				if (flag7)
				{
					ClearSelection();
				}
				if (flag7 != _gamepadWasActive)
				{
					_gamepadWasActive = flag7;
					Refresh();
				}
				_hover?.Tick();
			}
		}

		private static void LateTick()
		{
			if (IsOpen && _hoverTooltip != null && _nodeRects != null && _selection != null && _hover != null)
			{
				string text = (_selection.Pinned ? _selection.SelectedId : _hover.CandidateId);
				if (!string.IsNullOrEmpty(text) && _nodeRects.TryGetValue(text, out var value))
				{
					_hoverTooltip.UpdatePosition(value);
				}
			}
		}

		private static void ClearSelection()
		{
			EventSystem current = EventSystem.current;
			GameObject val = (((Object)(object)current != (Object)null) ? current.currentSelectedGameObject : null);
			if ((Object)(object)val != (Object)null && val.transform.IsChildOf(_view.Root.transform))
			{
				current.SetSelectedGameObject((GameObject)null);
			}
		}

		private static void HidePreview()
		{
			_hoverTooltip?.Hide();
			_tree?.ClearAllHighlights();
			_route.Clear();
			ShowRoute(null, show: false);
		}

		private static void ShowHoverPreview(string id, bool pinned = false)
		{
			if (!((Object)(object)Player.m_localPlayer == (Object)null) && TalentRegistry.TryGet(id, out var def))
			{
				TalentRuntime talentRuntime = TalentRuntimeService.Get(Player.m_localPlayer);
				int value = 0;
				int value2 = 0;
				talentRuntime?.State.Ranks.TryGetValue(id, out value);
				talentRuntime?.DraftRanks.TryGetValue(id, out value2);
				bool flag = talentRuntime != null && TalentWindowSelectionController.CanUnlock(talentRuntime, def);
				if (!pinned || flag || _buildPreview != null || !TalentRouteService.TryFind(Player.m_localPlayer, talentRuntime, id, _route, out var _))
				{
					_route.Clear();
				}
				_tree.ClearAllHighlights();
				ShowRoute(talentRuntime, _route.Count > 0);
				_tree.SetHighlighted(id, on: true, Layout.SelectedNodeScale);
				if (_nodeRects != null && _nodeRects.TryGetValue(id, out var value3))
				{
					_hoverTooltip?.ShowFor(def, value3, value, value2, flag, CanTakeFirstStep(talentRuntime), pinned);
					_view.TreeClip?.InvalidateAlso();
				}
			}
		}

		private static bool CanTakeFirstStep(TalentRuntime rt)
		{
			if (rt == null)
			{
				return false;
			}
			foreach (string item in _route)
			{
				if (rt.GetEffectiveRank(item) > 0)
				{
					continue;
				}
				TalentDefinition def;
				return TalentRegistry.TryGet(item, out def) && TalentWindowSelectionController.CanUnlock(rt, def);
			}
			return false;
		}

		private static void ShowRoute(TalentRuntime rt, bool show)
		{
			if (show)
			{
				foreach (string item in _route)
				{
					if (rt.GetEffectiveRank(item) == 0)
					{
						_tree.SetOnRoute(item);
					}
				}
			}
			else if (!_routeShown)
			{
				return;
			}
			_routeShown = show;
			_paths?.SetRoute(show ? _route : null);
		}

		public static void ShowBuildPreview(ResolvedBuild build)
		{
			if (build == null)
			{
				HideBuildPreview();
			}
			else if (IsOpen && _tree != null && _paths != null)
			{
				_buildPreview = build;
				TalentRuntime rt = (((Object)(object)Player.m_localPlayer != (Object)null) ? TalentRuntimeService.Get(Player.m_localPlayer) : null);
				_tree.SetBuildPreview(build.Ranks, build.NotFitting);
				_paths.SetBuildPreview(build.Ranks.Keys);
				_route.Clear();
				ShowRoute(rt, show: false);
				Refresh();
			}
		}

		public static void HideBuildPreview()
		{
			HideBuildPreview(refresh: true);
		}

		private static void HideBuildPreview(bool refresh)
		{
			if (_buildPreview != null)
			{
				_buildPreview = null;
				_tree?.ClearBuildPreview();
				_paths?.ClearBuildPreview();
				if (refresh && IsOpen)
				{
					Refresh();
				}
			}
		}

		private static void ShowSearchMark(TalentSearchController.SearchChoice choice, IReadOnlyList<string> nodeIds)
		{
			if (!IsOpen || _tree == null || _paths == null)
			{
				return;
			}
			if (nodeIds == null || nodeIds.Count == 0)
			{
				HideSearchMark();
				return;
			}
			_markOpened = null;
			_markNodes = nodeIds;
			_tree.SetSearchMark(nodeIds);
			_paths.SetSearchFocus(on: true);
			_halos.SetSearchFocus(on: true);
			TalentKeyHintsView.SetNextMatch(on: true);
			Refresh();
			if (choice.Kind != TalentSearchController.SearchChoiceKind.Typed && nodeIds.Count == 1)
			{
				_search?.Clear();
				_selection.SelectTalent(nodeIds[0]);
				_markOpened = nodeIds[0];
				EndMarkOfClosedTalent();
			}
		}

		private static void EndMarkOfClosedTalent()
		{
			if (_markOpened != null && _selection != null && (!_selection.Pinned || !(_selection.SelectedId == _markOpened)))
			{
				HideSearchMark();
			}
		}

		private static void HideSearchMark()
		{
			HideSearchMark(refresh: true);
		}

		private static void HideSearchMark(bool refresh)
		{
			_markOpened = null;
			if (_markNodes != null)
			{
				_markNodes = null;
				_tree?.ClearSearchMark();
				_paths?.SetSearchFocus(on: false);
				_halos?.SetSearchFocus(on: false);
				TalentKeyHintsView.SetNextMatch(on: false);
				if (refresh && IsOpen)
				{
					Refresh();
				}
			}
		}

		private static void CenterOnNode(string id)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			Vector2? centerTarget = GetCenterTarget(id);
			if (centerTarget.HasValue)
			{
				_view.ContentRt.anchoredPosition = centerTarget.Value;
				if ((Object)(object)_view.ScrollRect != (Object)null)
				{
					_view.ScrollRect.velocity = Vector2.zero;
				}
			}
		}

		private static Vector2? GetCenterTarget(string id)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: 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)
			if (_view == null || (Object)(object)_view.ContentRt == (Object)null || (Object)(object)_view.ViewportRt == (Object)null || _nodeRects == null)
			{
				return null;
			}
			if (!_nodeRects.TryGetValue(id, out var value) || (Object)(object)value == (Object)null)
			{
				return null;
			}
			float x = ((Transform)_view.ContentRt).localScale.x;
			Vector2 val = -value.anchoredPosition * x + Layout.TreeContentCentre;
			float num = _view.ContentRt.sizeDelta.x * x;
			float num2 = _view.ContentRt.sizeDelta.y * x;
			Rect rect = _view.ViewportRt.rect;
			float width = ((Rect)(ref rect)).width;
			rect = _view.ViewportRt.rect;
			float height = ((Rect)(ref rect)).height;
			float num3 = Mathf.Max(0f, (num - width) * 0.5f);
			float num4 = Mathf.Max(0f, (num2 - height) * 0.5f);
			val.x = Mathf.Clamp(val.x, 0f - num3, num3);
			val.y = Mathf.Clamp(val.y, 0f - num4, num4);
			return val;
		}

		private static void OnApplyClicked()
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			int pendingCost = TalentDraftService.GetPendingCost(Player.m_localPlayer);
			if (pendingCost > 0)
			{
				int num = TalentPointBudgetService.GetAvailablePoints(Player.m_localPlayer) + pendingCost;
				_confirmDialog?.Show(TalentLocalization.Format("tt_ui_apply_confirm_text", pendingCost, num), delegate
				{
					_selection?.ApplyDraft();
				});
			}
		}

		private static v