Decompiled source of Native Settings UI Lib v1.0.0

Yap_NativeSettingsUI.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using YAPYAP;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Yap_NativeSettingsUI")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("YapYap Native Settings UI Library MOD")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Yap_NativeSettingsUI")]
[assembly: AssemblyTitle("Yap_NativeSettingsUI")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Yap_NativeSettingsUI
{
	[BepInPlugin("com.yapyap.nativesettingsui", "Yap Native Settings UI", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <InjectWhenReady>d__8 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public bool isInGame;

			public Plugin <>4__this;

			private UISettings <uiSettings>5__1;

			private MenuController <menuController>5__2;

			private int <i>5__3;

			private GameController <gameController>5__4;

			private int <i>5__5;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<uiSettings>5__1 = null;
				<menuController>5__2 = null;
				<gameController>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<uiSettings>5__1 = null;
					if (!isInGame)
					{
						<menuController>5__2 = null;
						<i>5__3 = 0;
						goto IL_009d;
					}
					<gameController>5__4 = null;
					<i>5__5 = 0;
					goto IL_013a;
				case 1:
					<>1__state = -1;
					<i>5__3++;
					goto IL_009d;
				case 2:
					{
						<>1__state = -1;
						<i>5__5++;
						goto IL_013a;
					}
					IL_009d:
					if (<i>5__3 < 60)
					{
						<menuController>5__2 = Object.FindFirstObjectByType<MenuController>();
						if (!((Object)(object)<menuController>5__2 != (Object)null))
						{
							<>2__current = null;
							<>1__state = 1;
							return true;
						}
					}
					if ((Object)(object)<menuController>5__2 == (Object)null)
					{
						return false;
					}
					<uiSettings>5__1 = NativeSettingsUI.TryGetUiSettings((Component)(object)<menuController>5__2);
					<menuController>5__2 = null;
					break;
					IL_013a:
					if (<i>5__5 < 60)
					{
						<gameController>5__4 = Object.FindFirstObjectByType<GameController>();
						if (!((Object)(object)<gameController>5__4 != (Object)null))
						{
							<>2__current = null;
							<>1__state = 2;
							return true;
						}
					}
					if ((Object)(object)<gameController>5__4 == (Object)null)
					{
						return false;
					}
					<uiSettings>5__1 = NativeSettingsUI.TryGetUiSettings((Component)(object)<gameController>5__4);
					<gameController>5__4 = null;
					break;
				}
				if ((Object)(object)<uiSettings>5__1 == (Object)null)
				{
					return false;
				}
				NativeSettingsUI.Inject(<uiSettings>5__1, isInGame);
				return false;
			}

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

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

		internal static ManualLogSource Log;

		private static Plugin instance;

		private SystemLanguage lastLanguage;

		private int languagePollCountdown;

		private void Awake()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			NativeSettingsUI.InternalInitialize(this);
			SceneManager.sceneLoaded += OnSceneLoaded;
			OnSceneLoaded(SceneManager.GetActiveScene(), (LoadSceneMode)0);
		}

		private void Update()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			if (languagePollCountdown > 0)
			{
				languagePollCountdown--;
				return;
			}
			languagePollCountdown = 10;
			SystemLanguage currentLanguage = NativeSettingsUI.GetCurrentLanguage();
			if (currentLanguage != lastLanguage)
			{
				lastLanguage = currentLanguage;
				NativeSettingsUI.NotifyLanguageChanged(currentLanguage);
			}
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			((MonoBehaviour)this).StartCoroutine(InjectWhenReady(isInGame: false));
			((MonoBehaviour)this).StartCoroutine(InjectWhenReady(isInGame: true));
		}

		[IteratorStateMachine(typeof(<InjectWhenReady>d__8))]
		private IEnumerator InjectWhenReady(bool isInGame)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <InjectWhenReady>d__8(0)
			{
				<>4__this = this,
				isInGame = isInGame
			};
		}
	}
	public readonly struct LocalText
	{
		public readonly string Key;

		public readonly string Chinese;

		public readonly string English;

		public LocalText(string key, string chinese, string english)
		{
			Key = key;
			Chinese = chinese;
			English = english;
		}
	}
	public sealed class UiRef<T> where T : Object
	{
		public T Value { get; private set; }

		public bool IsReady => (Object)(object)Value != (Object)null;

		public event Action<T> Ready;

		internal void SetValue(T value)
		{
			if (!((Object)(object)value == (Object)null))
			{
				Value = value;
				this.Ready?.Invoke(value);
			}
		}
	}
	public sealed class SettingsTab
	{
		internal readonly string Guid;

		internal readonly LocalText Title;

		internal readonly bool ShowInGame;

		private readonly List<IControlDefinition> controls = new List<IControlDefinition>();

		internal SettingsTab(string guid, LocalText title, bool showInGame)
		{
			Guid = guid ?? string.Empty;
			Title = title;
			ShowInGame = showInGame;
		}

		public UiRef<Button> CreateButton(string id, LocalText text, Action onClick, bool showInGame = true, Vector2? preferredSize = null, Vector2? anchoredPositionOffset = null)
		{
			UiRef<Button> uiRef = new UiRef<Button>();
			controls.Add(new ButtonDefinition(id, text, onClick, showInGame, preferredSize, anchoredPositionOffset, uiRef));
			NativeSettingsUI.TryBuildTabIntoExistingContexts(this);
			return uiRef;
		}

		public UiRef<TMP_Text> CreateLabel(string id, LocalText text, bool showInGame = true, Vector2? preferredSize = null, Vector2? anchoredPositionOffset = null)
		{
			UiRef<TMP_Text> uiRef = new UiRef<TMP_Text>();
			controls.Add(new LabelDefinition(id, text, showInGame, preferredSize, anchoredPositionOffset, uiRef));
			NativeSettingsUI.TryBuildTabIntoExistingContexts(this);
			return uiRef;
		}

		public UiRef<UISettingToggle> CreateToggle(string id, string settingKey, LocalText title, bool initialValue, Action<bool> onChanged, bool showInGame = true, Vector2? preferredSize = null, Vector2? anchoredPositionOffset = null)
		{
			UiRef<UISettingToggle> uiRef = new UiRef<UISettingToggle>();
			controls.Add(new ToggleDefinition(id, settingKey, title, initialValue, onChanged, showInGame, preferredSize, anchoredPositionOffset, uiRef));
			NativeSettingsUI.TryBuildTabIntoExistingContexts(this);
			return uiRef;
		}

		public UiRef<UISettingDropdownString> CreateDropdownString(string id, string settingKey, LocalText title, IList<string> options, string initialValue, Action<string> onChanged, bool showInGame = true, Vector2? preferredSize = null, Vector2? anchoredPositionOffset = null)
		{
			UiRef<UISettingDropdownString> uiRef = new UiRef<UISettingDropdownString>();
			controls.Add(new DropdownStringDefinition(id, settingKey, title, options, initialValue, onChanged, showInGame, preferredSize, anchoredPositionOffset, uiRef));
			NativeSettingsUI.TryBuildTabIntoExistingContexts(this);
			return uiRef;
		}

		public UiRef<UICustomSlider> CreateSliderInt(string id, string settingKey, LocalText title, int minValue, int maxValue, int initialValue, Action<int> onChanged, bool showInGame = true, Vector2? preferredSize = null, Vector2? anchoredPositionOffset = null)
		{
			UiRef<UICustomSlider> uiRef = new UiRef<UICustomSlider>();
			controls.Add(new SliderDefinition(id, settingKey, title, minValue, maxValue, initialValue, onChanged, showInGame, preferredSize, anchoredPositionOffset, uiRef));
			NativeSettingsUI.TryBuildTabIntoExistingContexts(this);
			return uiRef;
		}

		public UiRef<TMP_InputField> CreateInputString(string id, string settingKey, LocalText title, string initialValue, Action<string> onChanged, bool showInGame = true, Vector2? preferredSize = null, Vector2? anchoredPositionOffset = null)
		{
			UiRef<TMP_InputField> uiRef = new UiRef<TMP_InputField>();
			controls.Add(new InputStringDefinition(id, settingKey, title, initialValue, onChanged, showInGame, preferredSize, anchoredPositionOffset, uiRef));
			NativeSettingsUI.TryBuildTabIntoExistingContexts(this);
			return uiRef;
		}

		internal IReadOnlyList<IControlDefinition> GetControls()
		{
			return controls;
		}
	}
	public static class NativeSettingsUI
	{
		private sealed class UiSettingsContext
		{
			public readonly UISettings UiSettings;

			public readonly Transform ContentRoot;

			public readonly bool IsInGame;

			public UiSettingsContext(UISettings uiSettings, Transform contentRoot, bool isInGame)
			{
				UiSettings = uiSettings;
				ContentRoot = contentRoot;
				IsInGame = isInGame;
			}
		}

		private static Plugin plugin;

		private static readonly List<SettingsTab> tabs = new List<SettingsTab>();

		private static readonly List<UiSettingsContext> contexts = new List<UiSettingsContext>();

		internal static SystemLanguage CurrentLanguage { get; private set; } = Application.systemLanguage;


		internal static event Action<SystemLanguage> LanguageChanged;

		public static void BindText(TMP_Text tmp, LocalText text)
		{
			if (!((Object)(object)tmp == (Object)null))
			{
				LocalTextBinder.Bind(tmp, text);
			}
		}

		public static void UnbindText(TMP_Text tmp)
		{
			if (!((Object)(object)tmp == (Object)null))
			{
				LocalTextBinder component = ((Component)tmp).GetComponent<LocalTextBinder>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
			}
		}

		public static SettingsTab RegisterTab(string guid, LocalText title, bool showInGame)
		{
			if (string.IsNullOrWhiteSpace(guid))
			{
				guid = Guid.NewGuid().ToString("N");
			}
			for (int i = 0; i < tabs.Count; i++)
			{
				if (string.Equals(tabs[i].Guid, guid, StringComparison.Ordinal))
				{
					return tabs[i];
				}
			}
			SettingsTab settingsTab = new SettingsTab(guid, title, showInGame);
			tabs.Add(settingsTab);
			TryBuildTabIntoExistingContexts(settingsTab);
			return settingsTab;
		}

		internal static void InternalInitialize(Plugin hostPlugin)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			plugin = hostPlugin;
			CurrentLanguage = GetCurrentLanguage();
			NotifyLanguageChanged(CurrentLanguage);
		}

		internal static SystemLanguage GetCurrentLanguage()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			SystemLanguage result = Application.systemLanguage;
			LocalisationManager val = default(LocalisationManager);
			if (Service.Get<LocalisationManager>(ref val) && (Object)(object)val != (Object)null)
			{
				Translator val2 = val.CurrentTranslator ?? val.DefaultTranslator;
				if (val2 != null)
				{
					result = val2.Language;
				}
			}
			return result;
		}

		internal static void NotifyLanguageChanged(SystemLanguage language)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			CurrentLanguage = language;
			NativeSettingsUI.LanguageChanged?.Invoke(language);
		}

		internal static UISettings TryGetUiSettings(Component controller)
		{
			if ((Object)(object)controller == (Object)null)
			{
				return null;
			}
			FieldInfo field = ((object)controller).GetType().GetField("_uiSettings", BindingFlags.Instance | BindingFlags.NonPublic);
			UISettings val = (UISettings)((field != null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val == (Object)null)
			{
				val = controller.GetComponentInChildren<UISettings>(true);
			}
			return val;
		}

		internal static void Inject(UISettings uiSettings, bool isInGame)
		{
			if ((Object)(object)uiSettings == (Object)null)
			{
				return;
			}
			Transform val = ((Component)uiSettings).transform.Find("Window/Content");
			if (!((Object)(object)val == (Object)null) && TryAddContext(uiSettings, val, isInGame))
			{
				for (int i = 0; i < tabs.Count; i++)
				{
					TryBuildTab(uiSettings, val, isInGame, tabs[i]);
				}
			}
		}

		private static bool TryAddContext(UISettings uiSettings, Transform content, bool isInGame)
		{
			for (int i = 0; i < contexts.Count; i++)
			{
				UiSettingsContext uiSettingsContext = contexts[i];
				if ((Object)(object)uiSettingsContext.UiSettings == (Object)(object)uiSettings && uiSettingsContext.IsInGame == isInGame)
				{
					return false;
				}
			}
			contexts.Add(new UiSettingsContext(uiSettings, content, isInGame));
			return true;
		}

		internal static void TryBuildTabIntoExistingContexts(SettingsTab tab)
		{
			if (tab == null)
			{
				return;
			}
			for (int num = contexts.Count - 1; num >= 0; num--)
			{
				UiSettingsContext uiSettingsContext = contexts[num];
				if ((Object)(object)uiSettingsContext.UiSettings == (Object)null || (Object)(object)uiSettingsContext.ContentRoot == (Object)null)
				{
					contexts.RemoveAt(num);
				}
				else
				{
					TryBuildTab(uiSettingsContext.UiSettings, uiSettingsContext.ContentRoot, uiSettingsContext.IsInGame, tab);
				}
			}
		}

		private static void TryBuildTab(UISettings uiSettings, Transform content, bool isInGame, SettingsTab tab)
		{
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)uiSettings == (Object)null || (Object)(object)content == (Object)null || tab == null || (isInGame && !tab.ShowInGame))
			{
				return;
			}
			if (!Templates.TryResolve(content, out var templates))
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogWarning((object)"NativeSettingsUI: UI templates not found; cannot build settings tab.");
				}
				return;
			}
			Transform val = content.Find("Tabs");
			Transform val2 = content.Find("SettingsSection");
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null))
			{
				string tabName = "Tab_" + tab.Guid;
				string sectionName = "Sec_" + tab.Guid;
				Transform val3 = EnsureTab(val, templates.TabTemplate, tabName);
				RectTransform val4 = EnsureSection(val2, templates.SectionTemplate, sectionName);
				if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val4 == (Object)null))
				{
					ApplyTitle(((Component)val3).gameObject, tab.Title, templates.Language);
					EnsureControls((Transform)(object)val4, templates, isInGame, tab);
					EnsureSectionBinding(content, val3, (Transform)(object)val4);
				}
			}
		}

		private static Transform EnsureTab(Transform tabsRoot, Transform template, string tabName)
		{
			Transform val = tabsRoot.Find(tabName);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			if ((Object)(object)template == (Object)null)
			{
				return null;
			}
			Transform transform = Object.Instantiate<GameObject>(((Component)template).gameObject, tabsRoot).transform;
			((Object)transform).name = tabName;
			transform.SetAsLastSibling();
			return transform;
		}

		private static RectTransform EnsureSection(Transform sectionsRoot, RectTransform template, string sectionName)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			Transform obj = sectionsRoot.Find(sectionName);
			RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			if ((Object)(object)val != (Object)null)
			{
				EnsureSectionHasPlaceholder(val);
				CopyLayoutComponents(template, val);
				return val;
			}
			GameObject val2 = new GameObject(sectionName, new Type[1] { typeof(RectTransform) });
			RectTransform component = val2.GetComponent<RectTransform>();
			if ((Object)(object)template != (Object)null)
			{
				component.anchorMin = template.anchorMin;
				component.anchorMax = template.anchorMax;
				component.pivot = template.pivot;
				component.sizeDelta = template.sizeDelta;
				((Transform)component).localPosition = ((Transform)template).localPosition;
				((Transform)component).localRotation = ((Transform)template).localRotation;
				((Transform)component).localScale = ((Transform)template).localScale;
				CopyLayoutComponents(template, component);
			}
			((Transform)component).SetParent(sectionsRoot, false);
			val2.SetActive((Object)(object)template != (Object)null && ((Component)template).gameObject.activeSelf);
			EnsureSectionHasPlaceholder(component);
			return component;
		}

		private static void EnsureSectionHasPlaceholder(RectTransform rect)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			if (!((Object)(object)rect == (Object)null) && ((Transform)rect).childCount <= 0)
			{
				GameObject val = new GameObject("Placeholder", new Type[1] { typeof(RectTransform) });
				RectTransform component = val.GetComponent<RectTransform>();
				((Transform)component).SetParent((Transform)(object)rect, false);
			}
		}

		private static void CopyLayoutComponents(RectTransform from, RectTransform to)
		{
			if ((Object)(object)from == (Object)null || (Object)(object)to == (Object)null)
			{
				return;
			}
			Component[] components = ((Component)from).GetComponents<Component>();
			Component[] array = components;
			foreach (Component val in array)
			{
				if (val is RectTransform || ((object)val).GetType().Name == "CanvasRenderer")
				{
					continue;
				}
				Type type = ((object)val).GetType();
				if (!typeof(LayoutGroup).IsAssignableFrom(type) && type != typeof(ContentSizeFitter))
				{
					continue;
				}
				Component obj = ((Component)to).GetComponent(type) ?? ((Component)to).gameObject.AddComponent(type);
				FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				FieldInfo[] array2 = fields;
				foreach (FieldInfo fieldInfo in array2)
				{
					if (!fieldInfo.IsInitOnly)
					{
						fieldInfo.SetValue(obj, fieldInfo.GetValue(val));
					}
				}
			}
		}

		private static void EnsureControls(Transform section, Templates templates, bool isInGame, SettingsTab tab)
		{
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)section == (Object)null)
			{
				return;
			}
			Transform val = section.Find("Placeholder");
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
			IReadOnlyList<IControlDefinition> controls = tab.GetControls();
			bool flag = false;
			for (int i = 0; i < controls.Count; i++)
			{
				IControlDefinition controlDefinition = controls[i];
				if (controlDefinition != null && controlDefinition.PreferredSize.HasValue)
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				for (int j = 0; j < controls.Count; j++)
				{
					IControlDefinition controlDefinition2 = controls[j];
					if (controlDefinition2 != null && (!isInGame || controlDefinition2.ShowInGame))
					{
						controlDefinition2.Build(section, section, templates);
					}
				}
				return;
			}
			SectionLayout.DisableConflictingLayouts(section);
			Canvas.ForceUpdateCanvases();
			int num = ((templates.ContentInsetLeft > 0) ? templates.ContentInsetLeft : templates.GridPaddingLeft);
			int num2 = ((templates.ContentInsetRight > 0) ? templates.ContentInsetRight : templates.GridPaddingRight);
			float num3 = templates.GridCellSize.x * 2f + templates.GridSpacing.x;
			Transform obj = section;
			RectTransform val2 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			if ((Object)(object)val2 != (Object)null)
			{
				val2.anchorMin = new Vector2(0f, val2.anchorMin.y);
				val2.anchorMax = new Vector2(1f, val2.anchorMax.y);
				val2.pivot = new Vector2(templates.SectionPivotX, val2.pivot.y);
				val2.offsetMin = new Vector2(templates.SectionOffsetMinX, val2.offsetMin.y);
				val2.offsetMax = new Vector2(templates.SectionOffsetMaxX, val2.offsetMax.y);
				val2.sizeDelta = new Vector2(0f, val2.sizeDelta.y);
				Canvas.ForceUpdateCanvases();
				Rect rect = val2.rect;
				float width = ((Rect)(ref rect)).width;
				if (width > 0.01f)
				{
					num3 = width;
				}
				Transform parent = ((Transform)val2).parent;
				RectTransform val3 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				if ((Object)(object)val3 != (Object)null)
				{
					rect = val3.rect;
					float width2 = ((Rect)(ref rect)).width;
					if (width2 > num3 + 0.01f)
					{
						num3 = width2;
					}
				}
			}
			float availableContentWidth = num3 - (float)num - (float)num2;
			if (availableContentWidth < templates.GridCellSize.x)
			{
				availableContentWidth = templates.GridCellSize.x * 2f + templates.GridSpacing.x;
			}
			float computedColumnWidth = (availableContentWidth - templates.GridSpacing.x) * 0.5f;
			if (computedColumnWidth < 1f)
			{
				computedColumnWidth = templates.GridCellSize.x;
			}
			int rowIndex = 0;
			float y = -templates.GridPaddingTop;
			bool hasOpenTwoColumnRow = false;
			Transform openRow = null;
			Transform openLeft = null;
			Transform openRight = null;
			float openRowHeight = templates.GridCellSize.y;
			bool openLeftUsed = false;
			bool openRightUsed = false;
			Queue<IControlDefinition> deferredFullRows = new Queue<IControlDefinition>();
			for (int k = 0; k < controls.Count; k++)
			{
				IControlDefinition controlDefinition3 = controls[k];
				if (controlDefinition3 == null || (isInGame && !controlDefinition3.ShowInGame))
				{
					continue;
				}
				float num4 = GetDesiredHeight(controlDefinition3);
				bool flag2 = IsFullRow(controlDefinition3);
				if (flag2 && !hasOpenTwoColumnRow)
				{
					Transform parent2 = SectionLayout.EnsureFullRow(section, rowIndex++, templates, availableContentWidth, num4, y);
					y -= num4 + templates.GridSpacing.y;
					controlDefinition3.Build(section, parent2, templates);
					continue;
				}
				EnsureOpenRow(num4);
				if (!openLeftUsed)
				{
					controlDefinition3.Build(section, openLeft, templates);
					openLeftUsed = true;
				}
				else if (!openRightUsed)
				{
					if (flag2)
					{
						deferredFullRows.Enqueue(controlDefinition3);
						continue;
					}
					controlDefinition3.Build(section, openRight, templates);
					openRightUsed = true;
					CloseOpenRow();
					FlushDeferredFullRows();
				}
			}
			if (hasOpenTwoColumnRow)
			{
				CloseOpenRow();
			}
			FlushDeferredFullRows();
			SectionLayout.DisableExtraRows(section, rowIndex);
			void CloseOpenRow()
			{
				hasOpenTwoColumnRow = false;
				openRow = null;
				openLeft = null;
				openRight = null;
				openRowHeight = templates.GridCellSize.y;
				openLeftUsed = false;
				openRightUsed = false;
			}
			void EnsureOpenRow(float requiredHeight)
			{
				if (!hasOpenTwoColumnRow)
				{
					openRowHeight = Mathf.Max(templates.GridCellSize.y, requiredHeight);
					SectionLayout.RowSlots rowSlots = SectionLayout.EnsureTwoColumnRow(section, rowIndex++, templates, computedColumnWidth, openRowHeight, y);
					openRow = rowSlots.Row;
					openLeft = rowSlots.Left;
					openRight = rowSlots.Right;
					y -= openRowHeight + templates.GridSpacing.y;
					hasOpenTwoColumnRow = true;
					openLeftUsed = false;
					openRightUsed = false;
				}
				else
				{
					float num5 = Mathf.Max(openRowHeight, requiredHeight);
					if (num5 > openRowHeight + 0.01f)
					{
						openRowHeight = num5;
						SectionLayout.SetRowHeight(openRow, openRowHeight);
						SectionLayout.SetSlotHeight(openLeft, openRowHeight);
						SectionLayout.SetSlotHeight(openRight, openRowHeight);
					}
				}
			}
			void FlushDeferredFullRows()
			{
				while (deferredFullRows.Count > 0)
				{
					IControlDefinition controlDefinition4 = deferredFullRows.Dequeue();
					if (controlDefinition4 != null)
					{
						float desiredHeight = GetDesiredHeight(controlDefinition4);
						Transform parent3 = SectionLayout.EnsureFullRow(section, rowIndex++, templates, availableContentWidth, desiredHeight, y);
						y -= desiredHeight + templates.GridSpacing.y;
						controlDefinition4.Build(section, parent3, templates);
					}
				}
			}
			float GetDesiredHeight(IControlDefinition def)
			{
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				if (def == null || !def.PreferredSize.HasValue)
				{
					return templates.GridCellSize.y;
				}
				float y2 = def.PreferredSize.Value.y;
				if (y2 <= 0f)
				{
					return templates.GridCellSize.y;
				}
				return y2;
			}
			bool IsFullRow(IControlDefinition def)
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				if (def == null || !def.PreferredSize.HasValue)
				{
					return false;
				}
				return def.PreferredSize.Value.x > computedColumnWidth + 0.01f;
			}
		}

		private static void EnsureSectionBinding(Transform content, Transform tab, Transform section)
		{
			UISettings componentInParent = ((Component)content).GetComponentInParent<UISettings>();
			if ((Object)(object)componentInParent == (Object)null)
			{
				return;
			}
			FieldInfo field = typeof(UISettings).GetField("sections", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				return;
			}
			object value = field.GetValue(componentInParent);
			if (!(value is IList list))
			{
				return;
			}
			Type nestedType = typeof(UISettings).GetNestedType("SettingsSection", BindingFlags.Public);
			if (nestedType == null)
			{
				return;
			}
			FieldInfo field2 = nestedType.GetField("SectionObj", BindingFlags.Instance | BindingFlags.Public);
			FieldInfo field3 = nestedType.GetField("TabButton", BindingFlags.Instance | BindingFlags.Public);
			FieldInfo field4 = nestedType.GetField("Indictor", BindingFlags.Instance | BindingFlags.Public);
			if (field2 == null || field3 == null || field4 == null)
			{
				return;
			}
			foreach (object item in list)
			{
				object? value2 = field2.GetValue(item);
				GameObject val = (GameObject)((value2 is GameObject) ? value2 : null);
				if ((Object)(object)val == (Object)(object)((Component)section).gameObject)
				{
					return;
				}
			}
			object obj = Activator.CreateInstance(nestedType);
			field2.SetValue(obj, ((Component)section).gameObject);
			Button component = ((Component)tab).GetComponent<Button>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			field3.SetValue(obj, component);
			UIFader componentInChildren = ((Component)tab).GetComponentInChildren<UIFader>(true);
			field4.SetValue(obj, componentInChildren);
			if (list.IsFixedSize)
			{
				if (!(value is Array array))
				{
					return;
				}
				int length = array.Length;
				Array array2 = Array.CreateInstance(nestedType, length + 1);
				for (int i = 0; i < length; i++)
				{
					array2.SetValue(array.GetValue(i), i);
				}
				array2.SetValue(obj, length);
				field.SetValue(componentInParent, array2);
			}
			else
			{
				list.Add(obj);
			}
			typeof(UISettings).GetMethod("InitSections", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(componentInParent, null);
		}

		private static void ApplyTitle(GameObject root, LocalText title, SystemLanguage language)
		{
			if (!((Object)(object)root == (Object)null))
			{
				LocalisedTMP componentInChildren = root.GetComponentInChildren<LocalisedTMP>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					Object.Destroy((Object)(object)componentInChildren);
				}
				TMP_Text componentInChildren2 = root.GetComponentInChildren<TMP_Text>(true);
				if (!((Object)(object)componentInChildren2 == (Object)null))
				{
					LocalTextBinder.Bind(componentInChildren2, title);
				}
			}
		}
	}
	internal sealed class LocalTextBinder : MonoBehaviour
	{
		private TMP_Text tmp;

		private string zh;

		private string en;

		internal static void Bind(TMP_Text tmp, LocalText text)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)tmp == (Object)null))
			{
				LocalTextBinder localTextBinder = ((Component)tmp).GetComponent<LocalTextBinder>();
				if ((Object)(object)localTextBinder == (Object)null)
				{
					localTextBinder = ((Component)tmp).gameObject.AddComponent<LocalTextBinder>();
				}
				localTextBinder.tmp = tmp;
				localTextBinder.zh = text.Chinese;
				localTextBinder.en = text.English;
				localTextBinder.Apply(NativeSettingsUI.CurrentLanguage);
			}
		}

		private void OnEnable()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			NativeSettingsUI.LanguageChanged += OnLanguageChanged;
			Apply(NativeSettingsUI.CurrentLanguage);
		}

		private void OnDisable()
		{
			NativeSettingsUI.LanguageChanged -= OnLanguageChanged;
		}

		private void OnLanguageChanged(SystemLanguage language)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			Apply(language);
		}

		private void Apply(SystemLanguage language)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Invalid comparison between Unknown and I4
			if ((Object)(object)tmp == (Object)null)
			{
				tmp = ((Component)this).GetComponent<TMP_Text>();
				if ((Object)(object)tmp == (Object)null)
				{
					return;
				}
			}
			if ((int)language == 6 || (int)language == 40 || (int)language == 41)
			{
				tmp.text = ((!string.IsNullOrEmpty(zh)) ? zh : (en ?? string.Empty));
			}
			else
			{
				tmp.text = ((!string.IsNullOrEmpty(en)) ? en : (zh ?? string.Empty));
			}
		}
	}
	internal static class LocalTextUtil
	{
		internal static string Resolve(LocalText text, SystemLanguage language)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			if ((int)language == 6 || (int)language == 40 || (int)language == 41)
			{
				if (!string.IsNullOrEmpty(text.Chinese))
				{
					return text.Chinese;
				}
				return text.English ?? string.Empty;
			}
			if (!string.IsNullOrEmpty(text.English))
			{
				return text.English;
			}
			return text.Chinese ?? string.Empty;
		}

		internal static void ApplyTo(GameObject root, LocalText text, SystemLanguage language)
		{
			if (!((Object)(object)root == (Object)null))
			{
				LocalisedTMP component = root.GetComponent<LocalisedTMP>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
				TMP_Text component2 = root.GetComponent<TMP_Text>();
				if ((Object)(object)component2 != (Object)null)
				{
					LocalTextBinder.Bind(component2, text);
				}
			}
		}
	}
	internal readonly struct Templates
	{
		public readonly RectTransform SectionTemplate;

		public readonly Transform TabTemplate;

		public readonly Transform SliderTemplate;

		public readonly Transform ToggleTemplate;

		public readonly Transform DropdownTemplate;

		public readonly Transform ButtonTemplate;

		public readonly Transform LabelTemplate;

		public readonly SystemLanguage Language;

		public readonly Vector2 GridCellSize;

		public readonly Vector2 GridSpacing;

		public readonly int GridPaddingLeft;

		public readonly int GridPaddingRight;

		public readonly int GridPaddingTop;

		public readonly int GridPaddingBottom;

		public readonly Constraint GridConstraint;

		public readonly int GridConstraintCount;

		public readonly float SectionOffsetMinX;

		public readonly float SectionOffsetMaxX;

		public readonly float SectionPivotX;

		public readonly int ContentInsetLeft;

		public readonly int ContentInsetRight;

		private Templates(RectTransform sectionTemplate, Transform tabTemplate, Transform sliderTemplate, Transform toggleTemplate, Transform dropdownTemplate, Transform buttonTemplate, Transform labelTemplate, SystemLanguage language, Vector2 gridCellSize, Vector2 gridSpacing, int gridPaddingLeft, int gridPaddingRight, int gridPaddingTop, int gridPaddingBottom, Constraint gridConstraint, int gridConstraintCount, float sectionOffsetMinX, float sectionOffsetMaxX, float sectionPivotX, int contentInsetLeft, int contentInsetRight)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			SectionTemplate = sectionTemplate;
			TabTemplate = tabTemplate;
			SliderTemplate = sliderTemplate;
			ToggleTemplate = toggleTemplate;
			DropdownTemplate = dropdownTemplate;
			ButtonTemplate = buttonTemplate;
			LabelTemplate = labelTemplate;
			Language = language;
			GridCellSize = gridCellSize;
			GridSpacing = gridSpacing;
			GridPaddingLeft = gridPaddingLeft;
			GridPaddingRight = gridPaddingRight;
			GridPaddingTop = gridPaddingTop;
			GridPaddingBottom = gridPaddingBottom;
			GridConstraint = gridConstraint;
			GridConstraintCount = gridConstraintCount;
			SectionOffsetMinX = sectionOffsetMinX;
			SectionOffsetMaxX = sectionOffsetMaxX;
			SectionPivotX = sectionPivotX;
			ContentInsetLeft = contentInsetLeft;
			ContentInsetRight = contentInsetRight;
		}

		public static bool TryResolve(Transform content, out Templates templates)
		{
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0431: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: 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_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			templates = default(Templates);
			if ((Object)(object)content == (Object)null)
			{
				return false;
			}
			Transform val = content.Find("Tabs");
			Transform val2 = content.Find("SettingsSection");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return false;
			}
			Transform val3 = val.Find("Tab_General");
			if ((Object)(object)val3 == (Object)null && val.childCount > 0)
			{
				val3 = val.GetChild(0);
			}
			Transform obj = val2.Find("Sec_Audio");
			RectTransform val4 = (RectTransform)(((object)((obj is RectTransform) ? obj : null)) ?? ((object)/*isinst with value type is only supported in some contexts*/));
			if ((Object)(object)val4 == (Object)null && val2.childCount > 0)
			{
				Transform child = val2.GetChild(0);
				val4 = (RectTransform)(object)((child is RectTransform) ? child : null);
			}
			Transform val5 = content.Find("SettingsSection/Sec_Audio");
			Transform val6 = (((Object)(object)val5 != (Object)null) ? val5.Find("MasterVolume") : null);
			Transform val7 = (((Object)(object)val5 != (Object)null) ? val5.Find("Microphone") : null);
			Transform val8 = (((Object)(object)val5 != (Object)null) ? val5.Find("PushToTalk") : null);
			Transform root = content.root;
			Transform val9 = null;
			if ((Object)(object)root != (Object)null)
			{
				val9 = root.Find("UISettings/Window/Content/ButtonContainer/Close");
				if ((Object)(object)val9 == (Object)null)
				{
					val9 = root.Find("Canvas_Menu/UISettings/Window/Content/ButtonContainer/Close");
				}
			}
			Transform val10 = null;
			if ((Object)(object)val6 != (Object)null)
			{
				val10 = val6.Find("Title");
				if ((Object)(object)val10 == (Object)null)
				{
					TMP_Text componentInChildren = ((Component)val6).GetComponentInChildren<TMP_Text>(true);
					if ((Object)(object)componentInChildren != (Object)null)
					{
						val10 = componentInChildren.transform;
					}
				}
			}
			SystemLanguage systemLanguage = Application.systemLanguage;
			systemLanguage = NativeSettingsUI.GetCurrentLanguage();
			if ((Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)val6 == (Object)null || (Object)(object)val7 == (Object)null || (Object)(object)val8 == (Object)null || (Object)(object)val9 == (Object)null || (Object)(object)val10 == (Object)null)
			{
				return false;
			}
			float x = val4.offsetMin.x;
			float x2 = val4.offsetMax.x;
			float x3 = val4.pivot.x;
			Vector2 cellSize = default(Vector2);
			((Vector2)(ref cellSize))..ctor(300f, 60f);
			Vector2 spacing = default(Vector2);
			((Vector2)(ref spacing))..ctor(10f, 10f);
			int num = 0;
			int num2 = 0;
			int gridPaddingTop = 0;
			int gridPaddingBottom = 0;
			Constraint gridConstraint = (Constraint)1;
			int gridConstraintCount = 2;
			GridLayoutGroup component = ((Component)val4).GetComponent<GridLayoutGroup>();
			if ((Object)(object)component != (Object)null)
			{
				cellSize = component.cellSize;
				spacing = component.spacing;
				if (((LayoutGroup)component).padding != null)
				{
					num = ((LayoutGroup)component).padding.left;
					num2 = ((LayoutGroup)component).padding.right;
					gridPaddingTop = ((LayoutGroup)component).padding.top;
					gridPaddingBottom = ((LayoutGroup)component).padding.bottom;
				}
				gridConstraint = component.constraint;
				gridConstraintCount = component.constraintCount;
			}
			int num3 = num;
			int num4 = num2;
			try
			{
				RectTransform val11 = (RectTransform)(object)((val6 is RectTransform) ? val6 : null);
				if ((Object)(object)val4 != (Object)null && (Object)(object)val11 != (Object)null)
				{
					Vector3[] array = (Vector3[])(object)new Vector3[4];
					Vector3[] array2 = (Vector3[])(object)new Vector3[4];
					val4.GetWorldCorners(array);
					val11.GetWorldCorners(array2);
					float x4 = ((Transform)val4).InverseTransformPoint(array[0]).x;
					float x5 = ((Transform)val4).InverseTransformPoint(array[2]).x;
					float x6 = ((Transform)val4).InverseTransformPoint(array2[0]).x;
					float x7 = ((Transform)val4).InverseTransformPoint(array2[2]).x;
					int num5 = Mathf.Max(0, Mathf.RoundToInt(x6 - x4));
					int num6 = Mathf.Max(0, Mathf.RoundToInt(x5 - x7));
					if (num5 > 0)
					{
						num3 = num5;
					}
					if (num6 > 0)
					{
						num4 = num6;
					}
				}
			}
			catch
			{
			}
			num3 = Mathf.Max(num3, 30);
			num4 = Mathf.Max(num4, 30);
			templates = new Templates(val4, val3, val6, val8, val7, val9, val10, systemLanguage, cellSize, spacing, num, num2, gridPaddingTop, gridPaddingBottom, gridConstraint, gridConstraintCount, x, x2, x3, num3, num4);
			return true;
		}
	}
	internal interface IControlDefinition
	{
		string Id { get; }

		bool ShowInGame { get; }

		Vector2? PreferredSize { get; }

		void Build(Transform sectionRoot, Transform parent, Templates templates);
	}
	internal static class SectionLayout
	{
		internal readonly struct RowSlots
		{
			public readonly Transform Row;

			public readonly Transform Left;

			public readonly Transform Right;

			public RowSlots(Transform row, Transform left, Transform right)
			{
				Row = row;
				Left = left;
				Right = right;
			}
		}

		private const string RowPrefix = "NSUI_Row_";

		private const string TwoLeftSlotName = "NSUI_Slot_Left";

		private const string TwoRightSlotName = "NSUI_Slot_Right";

		private const string FullSlotName = "NSUI_Slot_Full";

		internal static void DisableConflictingLayouts(Transform section)
		{
			if (!((Object)(object)section == (Object)null))
			{
				LayoutGroup[] components = ((Component)section).GetComponents<LayoutGroup>();
				for (int i = 0; i < components.Length; i++)
				{
					((Behaviour)components[i]).enabled = false;
				}
			}
		}

		internal static RowSlots EnsureTwoColumnRow(Transform section, int rowIndex, Templates templates, float columnWidth, float rowHeight, float y)
		{
			RectTransform val = EnsureRowBase(section, rowIndex, rowHeight, y);
			Transform val2 = ((Transform)val).Find("NSUI_Slot_Full");
			if ((Object)(object)val2 != (Object)null)
			{
				((Component)val2).gameObject.SetActive(false);
			}
			Transform left = EnsureSlot(val, "NSUI_Slot_Left", columnWidth, rowHeight);
			Transform right = EnsureSlot(val, "NSUI_Slot_Right", columnWidth, rowHeight);
			EnsureRowSlotLayout(val, templates);
			return new RowSlots((Transform)(object)val, left, right);
		}

		internal static Transform EnsureFullRow(Transform section, int rowIndex, Templates templates, float fullRowWidth, float rowHeight, float y)
		{
			RectTransform val = EnsureRowBase(section, rowIndex, rowHeight, y);
			Transform val2 = ((Transform)val).Find("NSUI_Slot_Left");
			if ((Object)(object)val2 != (Object)null)
			{
				((Component)val2).gameObject.SetActive(false);
			}
			Transform val3 = ((Transform)val).Find("NSUI_Slot_Right");
			if ((Object)(object)val3 != (Object)null)
			{
				((Component)val3).gameObject.SetActive(false);
			}
			Transform result = EnsureSlot(val, "NSUI_Slot_Full", fullRowWidth, rowHeight);
			EnsureRowSingleSlotLayout(val, templates);
			return result;
		}

		internal static void SetRowHeight(Transform row, float rowHeight)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)row == (Object)null))
			{
				RectTransform val = (RectTransform)(object)((row is RectTransform) ? row : null);
				if ((Object)(object)val != (Object)null)
				{
					val.sizeDelta = new Vector2(val.sizeDelta.x, rowHeight);
				}
				LayoutElement component = ((Component)row).GetComponent<LayoutElement>();
				if ((Object)(object)component != (Object)null)
				{
					component.preferredHeight = rowHeight;
					component.minHeight = rowHeight;
				}
			}
		}

		internal static void SetSlotHeight(Transform slot, float rowHeight)
		{
			if (!((Object)(object)slot == (Object)null))
			{
				LayoutElement component = ((Component)slot).GetComponent<LayoutElement>();
				if ((Object)(object)component != (Object)null)
				{
					component.preferredHeight = rowHeight;
					component.minHeight = rowHeight;
				}
			}
		}

		private static RectTransform EnsureRowBase(Transform section, int rowIndex, float rowHeight, float y)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_00b7: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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)
			string text = "NSUI_Row_" + rowIndex;
			Transform obj = section.Find(text);
			RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			RectTransform val2;
			if ((Object)(object)val != (Object)null)
			{
				val2 = val;
				((Component)val2).gameObject.SetActive(true);
			}
			else
			{
				GameObject val3 = new GameObject(text, new Type[1] { typeof(RectTransform) });
				val2 = val3.GetComponent<RectTransform>();
				((Transform)val2).SetParent(section, false);
			}
			LayoutElement val4 = ((Component)val2).GetComponent<LayoutElement>();
			if ((Object)(object)val4 == (Object)null)
			{
				val4 = ((Component)val2).gameObject.AddComponent<LayoutElement>();
			}
			val4.preferredHeight = rowHeight;
			val4.minHeight = rowHeight;
			val4.flexibleHeight = 0f;
			val2.anchorMin = new Vector2(0f, 1f);
			val2.anchorMax = new Vector2(1f, 1f);
			val2.pivot = new Vector2(0.5f, 1f);
			val2.anchoredPosition = new Vector2(0f, y);
			val2.sizeDelta = new Vector2(0f, rowHeight);
			return val2;
		}

		private static Transform EnsureSlot(RectTransform row, string name, float width, float height)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			Transform obj = ((Transform)row).Find(name);
			RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			RectTransform val2;
			if ((Object)(object)val != (Object)null)
			{
				val2 = val;
				((Component)val2).gameObject.SetActive(true);
			}
			else
			{
				GameObject val3 = new GameObject(name, new Type[1] { typeof(RectTransform) });
				val2 = val3.GetComponent<RectTransform>();
				((Transform)val2).SetParent((Transform)(object)row, false);
			}
			LayoutElement val4 = ((Component)val2).GetComponent<LayoutElement>();
			if ((Object)(object)val4 == (Object)null)
			{
				val4 = ((Component)val2).gameObject.AddComponent<LayoutElement>();
			}
			val4.preferredWidth = width;
			val4.minWidth = width;
			val4.flexibleWidth = 0f;
			val4.preferredHeight = height;
			val4.minHeight = height;
			val4.flexibleHeight = 0f;
			HorizontalLayoutGroup val5 = ((Component)val2).GetComponent<HorizontalLayoutGroup>();
			if ((Object)(object)val5 == (Object)null)
			{
				val5 = ((Component)val2).gameObject.AddComponent<HorizontalLayoutGroup>();
			}
			((HorizontalOrVerticalLayoutGroup)val5).spacing = 0f;
			((LayoutGroup)val5).padding = new RectOffset(0, 0, 0, 0);
			((LayoutGroup)val5).childAlignment = (TextAnchor)3;
			((HorizontalOrVerticalLayoutGroup)val5).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)val5).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)val5).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)val5).childForceExpandHeight = false;
			return (Transform)(object)val2;
		}

		private static void EnsureRowSlotLayout(RectTransform row, Templates templates)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			HorizontalLayoutGroup val = ((Component)row).GetComponent<HorizontalLayoutGroup>();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)row).gameObject.AddComponent<HorizontalLayoutGroup>();
			}
			((HorizontalOrVerticalLayoutGroup)val).spacing = templates.GridSpacing.x;
			int num = ((templates.ContentInsetLeft > 0) ? templates.ContentInsetLeft : templates.GridPaddingLeft);
			int num2 = ((templates.ContentInsetRight > 0) ? templates.ContentInsetRight : templates.GridPaddingRight);
			((LayoutGroup)val).padding = new RectOffset(num, num2, 0, 0);
			((LayoutGroup)val).childAlignment = (TextAnchor)0;
			((HorizontalOrVerticalLayoutGroup)val).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)val).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)val).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)val).childForceExpandHeight = false;
		}

		private static void EnsureRowSingleSlotLayout(RectTransform row, Templates templates)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			HorizontalLayoutGroup val = ((Component)row).GetComponent<HorizontalLayoutGroup>();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)row).gameObject.AddComponent<HorizontalLayoutGroup>();
			}
			((HorizontalOrVerticalLayoutGroup)val).spacing = 0f;
			int num = ((templates.ContentInsetLeft > 0) ? templates.ContentInsetLeft : templates.GridPaddingLeft);
			int num2 = ((templates.ContentInsetRight > 0) ? templates.ContentInsetRight : templates.GridPaddingRight);
			((LayoutGroup)val).padding = new RectOffset(num, num2, 0, 0);
			((LayoutGroup)val).childAlignment = (TextAnchor)3;
			((HorizontalOrVerticalLayoutGroup)val).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)val).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)val).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)val).childForceExpandHeight = false;
		}

		internal static void DisableExtraRows(Transform section, int usedRowCount)
		{
			for (int i = usedRowCount; i < usedRowCount + 50; i++)
			{
				Transform val = section.Find("NSUI_Row_" + i);
				if ((Object)(object)val == (Object)null)
				{
					break;
				}
				((Component)val).gameObject.SetActive(false);
			}
		}
	}
	internal static class ControlUtil
	{
		internal static Transform FindFirstByName(Transform root, string name)
		{
			if ((Object)(object)root == (Object)null || string.IsNullOrEmpty(name))
			{
				return null;
			}
			if (string.Equals(((Object)root).name, name, StringComparison.Ordinal))
			{
				return root;
			}
			Queue<Transform> queue = new Queue<Transform>();
			queue.Enqueue(root);
			while (queue.Count > 0)
			{
				Transform val = queue.Dequeue();
				for (int i = 0; i < val.childCount; i++)
				{
					Transform child = val.GetChild(i);
					if (string.Equals(((Object)child).name, name, StringComparison.Ordinal))
					{
						return child;
					}
					queue.Enqueue(child);
				}
			}
			return null;
		}

		internal static void ApplyPreferredSize(GameObject root, Vector2? preferredSize)
		{
			//IL_003c: 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)
			if (!((Object)(object)root == (Object)null) && preferredSize.HasValue)
			{
				LayoutElement val = root.GetComponent<LayoutElement>();
				if ((Object)(object)val == (Object)null)
				{
					val = root.AddComponent<LayoutElement>();
				}
				val.preferredWidth = preferredSize.Value.x;
				val.preferredHeight = preferredSize.Value.y;
				val.flexibleWidth = 0f;
				val.flexibleHeight = 0f;
			}
		}

		internal static void ApplyAnchoredPositionOffset(GameObject root, Vector2? offset)
		{
			//IL_003a: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)root == (Object)null) && offset.HasValue)
			{
				Transform transform = root.transform;
				RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				if (!((Object)(object)val == (Object)null))
				{
					val.anchoredPosition += offset.Value;
				}
			}
		}

		internal static void ApplyTitle(Transform controlRoot, LocalText title, SystemLanguage language)
		{
			if ((Object)(object)controlRoot == (Object)null)
			{
				return;
			}
			Transform val = controlRoot.Find("Title");
			if (!((Object)(object)val == (Object)null))
			{
				LocalisedTMP component = ((Component)val).GetComponent<LocalisedTMP>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
				TMP_Text componentInChildren = ((Component)val).GetComponentInChildren<TMP_Text>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					LocalTextBinder.Bind(componentInChildren, title);
				}
			}
		}
	}
	internal sealed class ButtonDefinition : IControlDefinition
	{
		private readonly string id;

		private readonly LocalText text;

		private readonly Action onClick;

		private readonly Vector2? preferredSize;

		private readonly Vector2? anchoredPositionOffset;

		private readonly UiRef<Button> uiRef;

		public string Id => id;

		public bool ShowInGame { get; }

		public Vector2? PreferredSize => preferredSize;

		public ButtonDefinition(string id, LocalText text, Action onClick, bool showInGame, Vector2? preferredSize, Vector2? anchoredPositionOffset, UiRef<Button> uiRef)
		{
			this.id = (string.IsNullOrWhiteSpace(id) ? ("Button_" + Guid.NewGuid().ToString("N")) : id);
			this.text = text;
			this.onClick = onClick;
			this.preferredSize = preferredSize;
			this.anchoredPositionOffset = anchoredPositionOffset;
			this.uiRef = uiRef;
			ShowInGame = showInGame;
		}

		public void Build(Transform sectionRoot, Transform parent, Templates templates)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			Transform val = ControlUtil.FindFirstByName(sectionRoot, id);
			Transform val2;
			if ((Object)(object)val != (Object)null)
			{
				val2 = val;
				if ((Object)(object)val2.parent != (Object)(object)parent)
				{
					val2.SetParent(parent, false);
				}
			}
			else
			{
				val2 = Object.Instantiate<GameObject>(((Component)templates.ButtonTemplate).gameObject, parent).transform;
				((Object)val2).name = id;
				val2.localScale = Vector3.one;
			}
			Button component = ((Component)val2).GetComponent<Button>();
			if ((Object)(object)component != (Object)null)
			{
				component.onClick = new ButtonClickedEvent();
				if (onClick != null)
				{
					((UnityEvent)component.onClick).AddListener((UnityAction)delegate
					{
						onClick();
					});
				}
				uiRef?.SetValue(component);
			}
			Transform val3 = val2.Find("Text");
			if ((Object)(object)val3 != (Object)null)
			{
				LocalisedTMP component2 = ((Component)val3).GetComponent<LocalisedTMP>();
				if ((Object)(object)component2 != (Object)null)
				{
					Object.Destroy((Object)(object)component2);
				}
				TMP_Text componentInChildren = ((Component)val3).GetComponentInChildren<TMP_Text>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					LocalTextBinder.Bind(componentInChildren, text);
				}
			}
			ControlUtil.ApplyPreferredSize(((Component)val2).gameObject, preferredSize);
			ControlUtil.ApplyAnchoredPositionOffset(((Component)val2).gameObject, anchoredPositionOffset);
		}
	}
	internal sealed class LabelDefinition : IControlDefinition
	{
		private readonly string id;

		private readonly LocalText text;

		private readonly Vector2? preferredSize;

		private readonly Vector2? anchoredPositionOffset;

		private readonly UiRef<TMP_Text> uiRef;

		public string Id => id;

		public bool ShowInGame { get; }

		public Vector2? PreferredSize => preferredSize;

		public LabelDefinition(string id, LocalText text, bool showInGame, Vector2? preferredSize, Vector2? anchoredPositionOffset, UiRef<TMP_Text> uiRef)
		{
			this.id = (string.IsNullOrWhiteSpace(id) ? ("Label_" + Guid.NewGuid().ToString("N")) : id);
			this.text = text;
			this.preferredSize = preferredSize;
			this.anchoredPositionOffset = anchoredPositionOffset;
			this.uiRef = uiRef;
			ShowInGame = showInGame;
		}

		public void Build(Transform sectionRoot, Transform parent, Templates templates)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ControlUtil.FindFirstByName(sectionRoot, id);
			Transform val2;
			if ((Object)(object)val != (Object)null)
			{
				val2 = val;
				if ((Object)(object)val2.parent != (Object)(object)parent)
				{
					val2.SetParent(parent, false);
				}
			}
			else
			{
				val2 = Object.Instantiate<GameObject>(((Component)templates.LabelTemplate).gameObject, parent).transform;
				((Object)val2).name = id;
				val2.localScale = Vector3.one;
			}
			LocalisedTMP component = ((Component)val2).GetComponent<LocalisedTMP>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			TMP_Text componentInChildren = ((Component)val2).GetComponentInChildren<TMP_Text>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				LocalTextBinder.Bind(componentInChildren, text);
				uiRef?.SetValue(componentInChildren);
			}
			ControlUtil.ApplyPreferredSize(((Component)val2).gameObject, preferredSize);
			ControlUtil.ApplyAnchoredPositionOffset(((Component)val2).gameObject, anchoredPositionOffset);
		}
	}
	internal sealed class InputStringDefinition : IControlDefinition
	{
		private readonly string id;

		private readonly string settingKey;

		private readonly LocalText title;

		private readonly string initialValue;

		private readonly Action<string> onChanged;

		private readonly Vector2? preferredSize;

		private readonly Vector2? anchoredPositionOffset;

		private readonly UiRef<TMP_InputField> uiRef;

		public string Id => id;

		public bool ShowInGame { get; }

		public Vector2? PreferredSize => preferredSize;

		public InputStringDefinition(string id, string settingKey, LocalText title, string initialValue, Action<string> onChanged, bool showInGame, Vector2? preferredSize, Vector2? anchoredPositionOffset, UiRef<TMP_InputField> uiRef)
		{
			this.id = (string.IsNullOrWhiteSpace(id) ? ("Input_" + Guid.NewGuid().ToString("N")) : id);
			this.settingKey = settingKey ?? string.Empty;
			this.title = title;
			this.initialValue = initialValue ?? string.Empty;
			this.onChanged = onChanged;
			this.preferredSize = preferredSize;
			this.anchoredPositionOffset = anchoredPositionOffset;
			this.uiRef = uiRef;
			ShowInGame = showInGame;
		}

		public void Build(Transform sectionRoot, Transform parent, Templates templates)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ControlUtil.FindFirstByName(sectionRoot, id);
			Transform val2;
			if ((Object)(object)val != (Object)null)
			{
				val2 = val;
				if ((Object)(object)val2.parent != (Object)(object)parent)
				{
					val2.SetParent(parent, false);
				}
			}
			else
			{
				val2 = Object.Instantiate<GameObject>(((Component)templates.SliderTemplate).gameObject, parent).transform;
				((Object)val2).name = id;
				val2.localScale = Vector3.one;
			}
			ControlUtil.ApplyTitle(val2, title, templates.Language);
			UICustomSlider component = ((Component)val2).GetComponent<UICustomSlider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			Transform val3 = ControlUtil.FindFirstByName(val2, "Slider");
			if ((Object)(object)val3 != (Object)null)
			{
				((Component)val3).gameObject.SetActive(true);
				Transform val4 = val3.Find("Value");
				if ((Object)(object)val4 != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)val4).gameObject);
				}
				Transform val5 = val3.Find("Fill Area");
				if ((Object)(object)val5 != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)val5).gameObject);
				}
				Transform val6 = val3.Find("Handle");
				if ((Object)(object)val6 != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)val6).gameObject);
				}
				((Object)val3).name = "Input";
			}
			Transform val7 = ControlUtil.FindFirstByName(val2, "InputField");
			TMP_InputField val8 = (((Object)(object)val7 != (Object)null) ? ((Component)val7).GetComponent<TMP_InputField>() : null);
			if ((Object)(object)val8 == (Object)null)
			{
				val8 = ((Component)val2).GetComponentInChildren<TMP_InputField>(true);
			}
			if ((Object)(object)val8 != (Object)null)
			{
				((Component)val8).gameObject.SetActive(true);
				((Behaviour)val8).enabled = true;
				string @string = initialValue;
				if (!string.IsNullOrEmpty(settingKey))
				{
					@string = PlayerPrefs.GetString(settingKey, initialValue);
				}
				((UnityEventBase)val8.onValueChanged).RemoveAllListeners();
				((UnityEventBase)val8.onEndEdit).RemoveAllListeners();
				val8.SetTextWithoutNotify(@string);
				((UnityEvent<string>)(object)val8.onEndEdit).AddListener((UnityAction<string>)delegate(string v)
				{
					if (!string.IsNullOrEmpty(settingKey))
					{
						PlayerPrefs.SetString(settingKey, v);
					}
					onChanged?.Invoke(v);
				});
				uiRef?.SetValue(val8);
			}
			ControlUtil.ApplyPreferredSize(((Component)val2).gameObject, preferredSize);
			ControlUtil.ApplyAnchoredPositionOffset(((Component)val2).gameObject, anchoredPositionOffset);
		}
	}
	internal sealed class ToggleDefinition : IControlDefinition
	{
		private readonly string id;

		private readonly string settingKey;

		private readonly LocalText title;

		private readonly bool initialValue;

		private readonly Action<bool> onChanged;

		private readonly Vector2? preferredSize;

		private readonly Vector2? anchoredPositionOffset;

		private readonly UiRef<UISettingToggle> uiRef;

		public string Id => id;

		public bool ShowInGame { get; }

		public Vector2? PreferredSize => preferredSize;

		public ToggleDefinition(string id, string settingKey, LocalText title, bool initialValue, Action<bool> onChanged, bool showInGame, Vector2? preferredSize, Vector2? anchoredPositionOffset, UiRef<UISettingToggle> uiRef)
		{
			this.id = (string.IsNullOrWhiteSpace(id) ? ("Toggle_" + Guid.NewGuid().ToString("N")) : id);
			this.settingKey = settingKey ?? string.Empty;
			this.title = title;
			this.initialValue = initialValue;
			this.onChanged = onChanged;
			this.preferredSize = preferredSize;
			this.anchoredPositionOffset = anchoredPositionOffset;
			this.uiRef = uiRef;
			ShowInGame = showInGame;
		}

		public void Build(Transform sectionRoot, Transform parent, Templates templates)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ControlUtil.FindFirstByName(sectionRoot, id);
			Transform val2;
			if ((Object)(object)val != (Object)null)
			{
				val2 = val;
				if ((Object)(object)val2.parent != (Object)(object)parent)
				{
					val2.SetParent(parent, false);
				}
			}
			else
			{
				val2 = Object.Instantiate<GameObject>(((Component)templates.ToggleTemplate).gameObject, parent).transform;
				((Object)val2).name = id;
				val2.localScale = Vector3.one;
			}
			ControlUtil.ApplyTitle(val2, title, templates.Language);
			UISettingToggle componentInChildren = ((Component)val2).GetComponentInChildren<UISettingToggle>(true);
			if ((Object)(object)componentInChildren == (Object)null)
			{
				return;
			}
			((UISettingElement<bool>)(object)componentInChildren).SetSettingKey(settingKey);
			ReflectionUtil.SetPrivateField(componentInChildren, "defaultValue", initialValue);
			((UISettingElement<bool>)(object)componentInChildren).SetValueNoNotify(initialValue);
			if (onChanged != null)
			{
				((UISettingElement<bool>)(object)componentInChildren).OnSettingChanged.AddListener((UnityAction<bool>)delegate(bool value)
				{
					onChanged(value);
				});
			}
			uiRef?.SetValue(componentInChildren);
			ControlUtil.ApplyPreferredSize(((Component)val2).gameObject, preferredSize);
			ControlUtil.ApplyAnchoredPositionOffset(((Component)val2).gameObject, anchoredPositionOffset);
		}
	}
	internal sealed class DropdownStringDefinition : IControlDefinition
	{
		private readonly string id;

		private readonly string settingKey;

		private readonly LocalText title;

		private readonly IList<string> options;

		private readonly string initialValue;

		private readonly Action<string> onChanged;

		private readonly Vector2? preferredSize;

		private readonly Vector2? anchoredPositionOffset;

		private readonly UiRef<UISettingDropdownString> uiRef;

		public string Id => id;

		public bool ShowInGame { get; }

		public Vector2? PreferredSize => preferredSize;

		public DropdownStringDefinition(string id, string settingKey, LocalText title, IList<string> options, string initialValue, Action<string> onChanged, bool showInGame, Vector2? preferredSize, Vector2? anchoredPositionOffset, UiRef<UISettingDropdownString> uiRef)
		{
			this.id = (string.IsNullOrWhiteSpace(id) ? ("Dropdown_" + Guid.NewGuid().ToString("N")) : id);
			this.settingKey = settingKey ?? string.Empty;
			this.title = title;
			this.options = options ?? Array.Empty<string>();
			this.initialValue = initialValue ?? string.Empty;
			this.onChanged = onChanged;
			this.preferredSize = preferredSize;
			this.anchoredPositionOffset = anchoredPositionOffset;
			this.uiRef = uiRef;
			ShowInGame = showInGame;
		}

		public void Build(Transform sectionRoot, Transform parent, Templates templates)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ControlUtil.FindFirstByName(sectionRoot, id);
			Transform val2;
			if ((Object)(object)val != (Object)null)
			{
				val2 = val;
				if ((Object)(object)val2.parent != (Object)(object)parent)
				{
					val2.SetParent(parent, false);
				}
			}
			else
			{
				val2 = Object.Instantiate<GameObject>(((Component)templates.DropdownTemplate).gameObject, parent).transform;
				((Object)val2).name = id;
				val2.localScale = Vector3.one;
			}
			ControlUtil.ApplyTitle(val2, title, templates.Language);
			UISettingDropdownString componentInChildren = ((Component)val2).GetComponentInChildren<UISettingDropdownString>(true);
			if ((Object)(object)componentInChildren == (Object)null)
			{
				return;
			}
			((UISettingElement<string>)(object)componentInChildren).SetSettingKey(settingKey);
			ReflectionUtil.SetPrivateField(componentInChildren, "defaultValue", initialValue);
			((UISettingElement<string>)(object)componentInChildren).SetValueNoNotify(initialValue);
			componentInChildren.PopulateOptions(new List<string>(options));
			if (onChanged != null)
			{
				((UISettingElement<string>)(object)componentInChildren).OnSettingChanged.AddListener((UnityAction<string>)delegate(string value)
				{
					onChanged(value);
				});
			}
			uiRef?.SetValue(componentInChildren);
			ControlUtil.ApplyPreferredSize(((Component)val2).gameObject, preferredSize);
			ControlUtil.ApplyAnchoredPositionOffset(((Component)val2).gameObject, anchoredPositionOffset);
		}
	}
	internal sealed class SliderDefinition : IControlDefinition
	{
		private readonly string id;

		private readonly string settingKey;

		private readonly LocalText title;

		private readonly int minValue;

		private readonly int maxValue;

		private readonly int initialValue;

		private readonly Action<int> onChanged;

		private readonly Vector2? preferredSize;

		private readonly Vector2? anchoredPositionOffset;

		private readonly UiRef<UICustomSlider> uiRef;

		public string Id => id;

		public bool ShowInGame { get; }

		public Vector2? PreferredSize => preferredSize;

		public SliderDefinition(string id, string settingKey, LocalText title, int minValue, int maxValue, int initialValue, Action<int> onChanged, bool showInGame, Vector2? preferredSize, Vector2? anchoredPositionOffset, UiRef<UICustomSlider> uiRef)
		{
			this.id = (string.IsNullOrWhiteSpace(id) ? ("Slider_" + Guid.NewGuid().ToString("N")) : id);
			this.settingKey = settingKey ?? string.Empty;
			this.title = title;
			this.minValue = minValue;
			this.maxValue = maxValue;
			this.initialValue = initialValue;
			this.onChanged = onChanged;
			this.preferredSize = preferredSize;
			this.anchoredPositionOffset = anchoredPositionOffset;
			this.uiRef = uiRef;
			ShowInGame = showInGame;
		}

		public void Build(Transform sectionRoot, Transform parent, Templates templates)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ControlUtil.FindFirstByName(sectionRoot, id);
			Transform val2;
			if ((Object)(object)val != (Object)null)
			{
				val2 = val;
				if ((Object)(object)val2.parent != (Object)(object)parent)
				{
					val2.SetParent(parent, false);
				}
			}
			else
			{
				val2 = Object.Instantiate<GameObject>(((Component)templates.SliderTemplate).gameObject, parent).transform;
				((Object)val2).name = id;
				val2.localScale = Vector3.one;
			}
			ControlUtil.ApplyTitle(val2, title, templates.Language);
			UICustomSlider componentInChildren = ((Component)val2).GetComponentInChildren<UICustomSlider>(true);
			if ((Object)(object)componentInChildren == (Object)null)
			{
				return;
			}
			((UISettingElement<int>)(object)componentInChildren).SetSettingKey(settingKey);
			ReflectionUtil.SetPrivateField(componentInChildren, "minValue", minValue);
			ReflectionUtil.SetPrivateField(componentInChildren, "maxValue", maxValue);
			int num = Mathf.Clamp(initialValue, minValue, maxValue);
			ReflectionUtil.SetPrivateField(componentInChildren, "defaultValue", num);
			((UISettingElement<int>)(object)componentInChildren).SetValueNoNotify(num);
			((UISettingElement<int>)(object)componentInChildren).DisplayValue(num);
			if (onChanged != null)
			{
				((UISettingElement<int>)(object)componentInChildren).OnSettingChanged.AddListener((UnityAction<int>)delegate(int value)
				{
					onChanged(value);
				});
			}
			uiRef?.SetValue(componentInChildren);
			ControlUtil.ApplyPreferredSize(((Component)val2).gameObject, preferredSize);
			ControlUtil.ApplyAnchoredPositionOffset(((Component)val2).gameObject, anchoredPositionOffset);
		}
	}
	internal static class ReflectionUtil
	{
		internal static void SetPrivateField(object target, string fieldName, object value)
		{
			if (target != null && !string.IsNullOrEmpty(fieldName))
			{
				FieldInfo field = target.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
				if (!(field == null))
				{
					field.SetValue(target, value);
				}
			}
		}
	}
}