Decompiled source of ModSettings v0.1.0

plugins/ModSettings.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UIElements;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ModSettings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+43876164f5310a58e1357617819a08ae43df33a5")]
[assembly: AssemblyProduct("ModSettings")]
[assembly: AssemblyTitle("ModSettings")]
[assembly: AssemblyVersion("0.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ModSettings
{
	internal static class KeyRebindEditor
	{
		private static readonly KeyCode[] ModifierKeys;

		private static Button _listening;

		private static int _cancelledFrame;

		public static bool ConsumesEscape
		{
			get
			{
				if (_listening == null)
				{
					return Time.frameCount - _cancelledFrame <= 1;
				}
				return true;
			}
		}

		public static void CancelListening()
		{
			if (_listening != null)
			{
				Button listening = _listening;
				_listening = null;
				_cancelledFrame = Time.frameCount;
				VisualElement parent = ((VisualElement)listening).parent;
				(((parent != null) ? parent.userData : null) as Action)?.Invoke();
			}
		}

		public unsafe static SettingEditor Create(ConfigEntryBase entry, Action<object> set)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			VisualElement val = new VisualElement();
			Button button = new Button();
			Theme.StyleButton(button, outlined: false);
			val.Add((VisualElement)(object)button);
			Action refresh = delegate
			{
				//IL_0019: 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_0027: Unknown result type (might be due to invalid IL or missing references)
				if (_listening != button)
				{
					KeyboardShortcut val2 = (KeyboardShortcut)entry.BoxedValue;
					((TextElement)button).text = (((int)((KeyboardShortcut)(ref val2)).MainKey == 0) ? "Not bound" : ((object)(*(KeyboardShortcut*)(&val2))/*cast due to .constrained prefix*/).ToString());
				}
			};
			val.userData = refresh;
			button.clicked += delegate
			{
				if (_listening != button)
				{
					CancelListening();
					_listening = button;
					((TextElement)button).text = "Press a key...";
					((Focusable)button).Focus();
				}
			};
			((CallbackEventHandler)button).RegisterCallback<KeyDownEvent>((EventCallback<KeyDownEvent>)delegate(KeyDownEvent e)
			{
				//IL_000e: 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: Invalid comparison between Unknown and I4
				//IL_0032: 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_004e: Invalid comparison between Unknown and I4
				//IL_005f: 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_0057: Invalid comparison between Unknown and I4
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				if (_listening == button && (int)((KeyboardEventBase<KeyDownEvent>)(object)e).keyCode != 0)
				{
					((EventBase)e).StopPropagation();
					if ((int)((KeyboardEventBase<KeyDownEvent>)(object)e).keyCode == 27)
					{
						CancelListening();
					}
					else if (Array.IndexOf(ModifierKeys, ((KeyboardEventBase<KeyDownEvent>)(object)e).keyCode) < 0)
					{
						_listening = null;
						if ((int)((KeyboardEventBase<KeyDownEvent>)(object)e).keyCode == 127 || (int)((KeyboardEventBase<KeyDownEvent>)(object)e).keyCode == 8)
						{
							set(KeyboardShortcut.Empty);
						}
						else
						{
							set((object)new KeyboardShortcut(((KeyboardEventBase<KeyDownEvent>)(object)e).keyCode, HeldModifiers(e)));
						}
						refresh();
					}
				}
			}, (TrickleDown)1);
			((CallbackEventHandler)button).RegisterCallback<FocusOutEvent>((EventCallback<FocusOutEvent>)delegate
			{
				if (_listening == button)
				{
					CancelListening();
				}
			}, (TrickleDown)0);
			return new SettingEditor
			{
				Control = val,
				Refresh = refresh
			};
		}

		private static KeyCode[] HeldModifiers(KeyDownEvent e)
		{
			List<KeyCode> list = new List<KeyCode>();
			if (((KeyboardEventBase<KeyDownEvent>)(object)e).ctrlKey)
			{
				list.Add((KeyCode)306);
			}
			if (((KeyboardEventBase<KeyDownEvent>)(object)e).shiftKey)
			{
				list.Add((KeyCode)304);
			}
			if (((KeyboardEventBase<KeyDownEvent>)(object)e).altKey)
			{
				list.Add((KeyCode)308);
			}
			if (((KeyboardEventBase<KeyDownEvent>)(object)e).commandKey)
			{
				list.Add((KeyCode)310);
			}
			return list.ToArray();
		}

		static KeyRebindEditor()
		{
			KeyCode[] array = new KeyCode[8];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			ModifierKeys = (KeyCode[])(object)array;
			_cancelledFrame = -1;
		}
	}
	internal sealed class ModSettingsPanel
	{
		private readonly VisualElement _overlay;

		private readonly ScrollView _modList;

		private readonly ScrollView _content;

		private readonly TextField _search;

		private readonly Toggle _showAdvanced;

		private readonly Label _restartNotice;

		private readonly Button _closeButton;

		private readonly List<Action> _refreshers = new List<Action>();

		private List<ModInfo> _mods = new List<ModInfo>();

		private ModInfo _selected;

		public VisualElement Root => _overlay;

		public bool IsOpen { get; private set; }

		public event Action CloseRequested;

		public ModSettingsPanel(IEnumerable<StyleSheet> styleSheets)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_004b: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Expected O, but got Unknown
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: 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: Expected O, but got Unknown
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Expected O, but got Unknown
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Expected O, but got Unknown
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Expected O, but got Unknown
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0507: Expected O, but got Unknown
			//IL_0517: Unknown result type (might be due to invalid IL or missing references)
			_overlay = new VisualElement
			{
				name = "ModSettingsOverlay"
			};
			foreach (StyleSheet styleSheet in styleSheets)
			{
				VisualElementStyleSheetSet styleSheets2 = _overlay.styleSheets;
				((VisualElementStyleSheetSet)(ref styleSheets2)).Add(styleSheet);
			}
			IStyle style = _overlay.style;
			style.position = StyleEnum<Position>.op_Implicit((Position)1);
			style.left = (style.right = (style.top = (style.bottom = StyleLength.op_Implicit(0f))));
			style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
			style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)1);
			style.backgroundColor = StyleColor.op_Implicit(new Color(0f, 0f, 0f, 0.7f));
			style.color = StyleColor.op_Implicit(Theme.Text);
			style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1);
			VisualElement val4 = new VisualElement
			{
				name = "ModSettingsWindow"
			};
			IStyle style2 = val4.style;
			style2.width = StyleLength.op_Implicit(Length.Percent(80f));
			style2.height = StyleLength.op_Implicit(Length.Percent(82f));
			style2.maxWidth = StyleLength.op_Implicit(1400f);
			style2.backgroundColor = StyleColor.op_Implicit(Theme.Window);
			Theme.SetBorder(val4, 3f, Theme.WindowBorder, 0f);
			Theme.SetPadding(val4, 20f, 24f);
			_overlay.Add(val4);
			VisualElement val5 = Row();
			val5.style.marginBottom = StyleLength.op_Implicit(16f);
			Label val6 = new Label("MOD SETTINGS");
			((VisualElement)val6).style.fontSize = StyleLength.op_Implicit(34f);
			((VisualElement)val6).style.unityFontStyleAndWeight = StyleEnum<FontStyle>.op_Implicit((FontStyle)1);
			((VisualElement)val6).style.color = StyleColor.op_Implicit(Theme.Text);
			((VisualElement)val6).style.textShadow = StyleTextShadow.op_Implicit(new TextShadow
			{
				offset = new Vector2(2f, 2f),
				color = Color.black
			});
			((VisualElement)val6).style.flexGrow = StyleFloat.op_Implicit(1f);
			val5.Add((VisualElement)(object)val6);
			_search = new TextField
			{
				name = "ModSettingsSearch"
			};
			((VisualElement)_search).style.width = StyleLength.op_Implicit(300f);
			INotifyValueChangedExtensions.RegisterValueChangedCallback<string>((INotifyValueChanged<string>)(object)_search, (EventCallback<ChangeEvent<string>>)delegate
			{
				Rebuild(keepSelection: true);
			});
			val5.Add(Captioned("Search", (VisualElement)(object)_search));
			_showAdvanced = new Toggle
			{
				name = "ModSettingsShowAdvanced"
			};
			INotifyValueChangedExtensions.RegisterValueChangedCallback<bool>((INotifyValueChanged<bool>)(object)_showAdvanced, (EventCallback<ChangeEvent<bool>>)delegate
			{
				Rebuild(keepSelection: true);
			});
			val5.Add(Captioned("Advanced", (VisualElement)(object)_showAdvanced));
			_closeButton = new Button((Action)delegate
			{
				this.CloseRequested?.Invoke();
			})
			{
				text = "Back"
			};
			((VisualElement)_closeButton).style.marginLeft = StyleLength.op_Implicit(20f);
			((VisualElement)_closeButton).style.minWidth = StyleLength.op_Implicit(110f);
			Theme.StyleButton(_closeButton);
			val5.Add((VisualElement)(object)_closeButton);
			Theme.StyleControls(val5);
			val4.Add(val5);
			_restartNotice = new Label("Some changes take effect after restarting the game.");
			((VisualElement)_restartNotice).style.color = StyleColor.op_Implicit(Theme.Gold);
			((VisualElement)_restartNotice).style.marginBottom = StyleLength.op_Implicit(10f);
			((VisualElement)_restartNotice).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1);
			val4.Add((VisualElement)(object)_restartNotice);
			VisualElement val7 = Row();
			val7.style.flexGrow = StyleFloat.op_Implicit(1f);
			val7.style.flexShrink = StyleFloat.op_Implicit(1f);
			val7.style.alignItems = StyleEnum<Align>.op_Implicit((Align)4);
			val4.Add(val7);
			_modList = new ScrollView((ScrollViewMode)0)
			{
				name = "ModSettingsModList"
			};
			((VisualElement)_modList).style.width = StyleLength.op_Implicit(260f);
			((VisualElement)_modList).style.flexShrink = StyleFloat.op_Implicit(0f);
			((VisualElement)_modList).style.marginRight = StyleLength.op_Implicit(20f);
			((VisualElement)_modList).style.paddingRight = StyleLength.op_Implicit(16f);
			((VisualElement)_modList).style.borderRightWidth = StyleFloat.op_Implicit(2f);
			((VisualElement)_modList).style.borderRightColor = StyleColor.op_Implicit(Theme.Line);
			Theme.StyleControls((VisualElement)(object)_modList);
			val7.Add((VisualElement)(object)_modList);
			_content = new ScrollView((ScrollViewMode)0)
			{
				name = "ModSettingsContent"
			};
			((VisualElement)_content).style.flexGrow = StyleFloat.op_Implicit(1f);
			Theme.StyleControls((VisualElement)(object)_content);
			val7.Add((VisualElement)(object)_content);
			_overlay.schedule.Execute((Action)ConfigWriter.Flush).Every(1000L);
		}

		public void Open()
		{
			//IL_002d: 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)
			_mods = SettingsRegistry.Collect();
			((BaseField<string>)(object)_search).SetValueWithoutNotify("");
			((VisualElement)_restartNotice).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1);
			_selected = null;
			Rebuild(keepSelection: false);
			_overlay.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)0);
			_overlay.BringToFront();
			IsOpen = true;
			Button focus = _closeButton;
			((VisualElement)focus).schedule.Execute((Action)delegate
			{
				((Focusable)focus).Focus();
			}).ExecuteLater(0L);
		}

		public void Close()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (IsOpen)
			{
				KeyRebindEditor.CancelListening();
				IsOpen = false;
				_overlay.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1);
				ConfigWriter.Flush();
			}
		}

		private bool IsVisible(SettingInfo setting)
		{
			if (setting.Advanced && !((BaseField<bool>)(object)_showAdvanced).value)
			{
				return false;
			}
			string text = ((BaseField<string>)(object)_search).value?.Trim();
			if (!string.IsNullOrEmpty(text))
			{
				return setting.Matches(text);
			}
			return true;
		}

		private void Rebuild(bool keepSelection)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Expected O, but got Unknown
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Expected O, but got Unknown
			//IL_0290: 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_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			List<ModInfo> list = _mods.Where((ModInfo m) => m.Settings.Any(IsVisible)).ToList();
			if (!keepSelection || !list.Contains(_selected))
			{
				_selected = list.FirstOrDefault();
			}
			((VisualElement)_modList).Clear();
			foreach (ModInfo item in list)
			{
				ModInfo target = item;
				Button val = new Button((Action)delegate
				{
					_selected = target;
					Rebuild(keepSelection: true);
				})
				{
					text = item.Name
				};
				Theme.StyleButton(val, item == _selected);
				((VisualElement)val).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)3);
				IStyle style = ((VisualElement)val).style;
				StyleLength marginLeft = (((VisualElement)val).style.marginRight = StyleLength.op_Implicit(0f));
				style.marginLeft = marginLeft;
				((VisualElement)val).style.marginBottom = StyleLength.op_Implicit(8f);
				IStyle style2 = ((VisualElement)val).style;
				marginLeft = (((VisualElement)val).style.paddingBottom = StyleLength.op_Implicit(10f));
				style2.paddingTop = marginLeft;
				((VisualElement)_modList).Add((VisualElement)(object)val);
			}
			((VisualElement)_content).Clear();
			_refreshers.Clear();
			if (_selected == null)
			{
				((VisualElement)_content).Add((VisualElement)(object)Muted((_mods.Count == 0) ? "No mods with settings are loaded." : "No settings match the search."));
				return;
			}
			Label val4 = new Label(_selected.Name);
			((VisualElement)val4).style.fontSize = StyleLength.op_Implicit(26f);
			((VisualElement)val4).style.unityFontStyleAndWeight = StyleEnum<FontStyle>.op_Implicit((FontStyle)1);
			((VisualElement)val4).style.color = StyleColor.op_Implicit(Theme.Text);
			((VisualElement)_content).Add((VisualElement)(object)val4);
			Label val5 = Muted("v" + _selected.Version + "  ·  " + _selected.Guid);
			((VisualElement)val5).style.marginBottom = StyleLength.op_Implicit(6f);
			((VisualElement)_content).Add((VisualElement)(object)val5);
			string text = null;
			foreach (SettingInfo item2 in _selected.Settings.Where(IsVisible))
			{
				if (item2.Section != text)
				{
					text = item2.Section;
					Label val6 = new Label(text.ToUpperInvariant());
					((VisualElement)val6).style.fontSize = StyleLength.op_Implicit(18f);
					((VisualElement)val6).style.unityFontStyleAndWeight = StyleEnum<FontStyle>.op_Implicit((FontStyle)1);
					((VisualElement)val6).style.color = StyleColor.op_Implicit(Theme.Gold);
					((VisualElement)val6).style.marginTop = StyleLength.op_Implicit(18f);
					((VisualElement)val6).style.marginBottom = StyleLength.op_Implicit(6f);
					((VisualElement)val6).style.paddingBottom = StyleLength.op_Implicit(4f);
					((VisualElement)val6).style.borderBottomWidth = StyleFloat.op_Implicit(2f);
					((VisualElement)val6).style.borderBottomColor = StyleColor.op_Implicit(Theme.Line);
					((VisualElement)_content).Add((VisualElement)(object)val6);
				}
				((VisualElement)_content).Add(CreateRow(item2));
			}
			Theme.StyleControls(((VisualElement)_content).contentContainer);
			RefreshAll();
		}

		private VisualElement CreateRow(SettingInfo setting)
		{
			//IL_001f: 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)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_006e: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Expected O, but got Unknown
			//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_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Expected O, but got Unknown
			//IL_030f: 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_0273: Unknown result type (might be due to invalid IL or missing references)
			VisualElement obj = Row();
			obj.style.backgroundColor = StyleColor.op_Implicit(Theme.Surface);
			obj.style.marginBottom = StyleLength.op_Implicit(6f);
			Theme.SetPadding(obj, 10f, 14f);
			Theme.SetBorder(obj, 0f, Color.clear, 4f);
			VisualElement val = new VisualElement();
			val.style.width = StyleLength.op_Implicit(Length.Percent(42f));
			val.style.flexShrink = StyleFloat.op_Implicit(0f);
			val.style.paddingRight = StyleLength.op_Implicit(16f);
			Label val2 = new Label(setting.Name);
			((VisualElement)val2).style.unityFontStyleAndWeight = StyleEnum<FontStyle>.op_Implicit((FontStyle)1);
			((VisualElement)val2).style.fontSize = StyleLength.op_Implicit(16f);
			((VisualElement)val2).style.color = StyleColor.op_Implicit(Theme.Text);
			((VisualElement)val2).style.whiteSpace = StyleEnum<WhiteSpace>.op_Implicit((WhiteSpace)0);
			val.Add((VisualElement)(object)val2);
			List<string> list = new List<string>();
			if (setting.RestartRequired)
			{
				list.Add("Restart required");
			}
			if (setting.Advanced)
			{
				list.Add("Advanced");
			}
			if (setting.ReadOnly)
			{
				list.Add("Read only");
			}
			if (list.Count > 0)
			{
				Label val3 = new Label(string.Join("  ·  ", list));
				((VisualElement)val3).style.color = StyleColor.op_Implicit(Theme.Gold);
				((VisualElement)val3).style.fontSize = StyleLength.op_Implicit(12f);
				val.Add((VisualElement)(object)val3);
			}
			if (!string.IsNullOrEmpty(setting.Description))
			{
				Label val4 = Muted(setting.Description);
				((VisualElement)val4).style.fontSize = StyleLength.op_Implicit(13f);
				((VisualElement)val4).style.marginTop = StyleLength.op_Implicit(4f);
				val.Add((VisualElement)(object)val4);
			}
			obj.Add(val);
			SettingEditor editor = SettingEditors.Create(setting, delegate
			{
				OnChanged(setting);
			});
			VisualElement val5 = Row();
			val5.style.flexGrow = StyleFloat.op_Implicit(1f);
			if (!(editor.Control is Toggle))
			{
				editor.Control.style.flexGrow = StyleFloat.op_Implicit(1f);
			}
			editor.Control.SetEnabled(!setting.ReadOnly);
			val5.Add(editor.Control);
			obj.Add(val5);
			ConfigEntryBase entry = setting.Entry;
			Button reset = new Button((Action)delegate
			{
				ConfigWriter.Set(entry, entry.DefaultValue);
				OnChanged(setting);
			})
			{
				text = "Reset",
				tooltip = "Reset to default"
			};
			Theme.StyleButton(reset, outlined: false);
			((VisualElement)reset).style.marginLeft = StyleLength.op_Implicit(12f);
			((VisualElement)reset).style.width = StyleLength.op_Implicit(84f);
			obj.Add((VisualElement)(object)reset);
			_refreshers.Add(delegate
			{
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				editor.Refresh();
				bool flag = entry.GetSerializedValue() == TomlTypeConverter.ConvertToString(entry.DefaultValue, entry.SettingType);
				((VisualElement)reset).style.visibility = StyleEnum<Visibility>.op_Implicit((Visibility)((flag || setting.HideDefaultButton || setting.ReadOnly) ? 1 : 0));
			});
			return obj;
		}

		private void OnChanged(SettingInfo setting)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (setting.RestartRequired)
			{
				((VisualElement)_restartNotice).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)0);
			}
			RefreshAll();
		}

		private void RefreshAll()
		{
			foreach (Action refresher in _refreshers)
			{
				refresher();
			}
		}

		private static VisualElement Row()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			VisualElement val = new VisualElement();
			val.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)2);
			val.style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
			return val;
		}

		private static VisualElement Captioned(string caption, VisualElement control)
		{
			//IL_0010: 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)
			VisualElement obj = Row();
			obj.style.marginLeft = StyleLength.op_Implicit(20f);
			Label val = Muted(caption);
			((VisualElement)val).style.marginRight = StyleLength.op_Implicit(8f);
			obj.Add((VisualElement)(object)val);
			obj.Add(control);
			return obj;
		}

		private static Label Muted(string text)
		{
			//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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			Label val = new Label(text);
			((VisualElement)val).style.color = StyleColor.op_Implicit(Theme.Muted);
			((VisualElement)val).style.whiteSpace = StyleEnum<WhiteSpace>.op_Implicit((WhiteSpace)0);
			return val;
		}
	}
	[BepInPlugin("com.darkharasho.stonewards.modsettings", "ModSettings", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.darkharasho.stonewards.modsettings";

		public const string PluginName = "ModSettings";

		public const string PluginVersion = "0.1.0";

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("com.darkharasho.stonewards.modsettings");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"ModSettings 0.1.0 loaded");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal sealed class SettingEditor
	{
		public VisualElement Control;

		public Action Refresh;
	}
	internal static class SettingEditors
	{
		private static readonly Type[] IntegerTypes = new Type[8]
		{
			typeof(int),
			typeof(long),
			typeof(short),
			typeof(byte),
			typeof(sbyte),
			typeof(uint),
			typeof(ushort),
			typeof(ulong)
		};

		private static readonly Type[] RealTypes = new Type[3]
		{
			typeof(float),
			typeof(double),
			typeof(decimal)
		};

		public static SettingEditor Create(SettingInfo setting, Action changed)
		{
			ConfigEntryBase entry = setting.Entry;
			Type settingType = entry.SettingType;
			ConfigDescription description = entry.Description;
			AcceptableValueBase val = ((description != null) ? description.AcceptableValues : null);
			Action<object> set = delegate(object value3)
			{
				ConfigWriter.Set(entry, value3);
				changed();
			};
			if (settingType == typeof(bool))
			{
				return CreateToggle(entry, set);
			}
			if (settingType == typeof(KeyboardShortcut))
			{
				return KeyRebindEditor.Create(entry, set);
			}
			if (val != null && ((object)val).GetType().IsGenericType && ((object)val).GetType().GetGenericTypeDefinition() == typeof(AcceptableValueList<>))
			{
				return CreateDropdown(entry, ((Array)((object)val).GetType().GetProperty("AcceptableValues").GetValue(val)).Cast<object>(), set);
			}
			if (settingType.IsEnum && !settingType.IsDefined(typeof(FlagsAttribute), inherit: false))
			{
				return CreateDropdown(entry, Enum.GetValues(settingType).Cast<object>(), set);
			}
			if (val != null && ((object)val).GetType().IsGenericType && ((object)val).GetType().GetGenericTypeDefinition() == typeof(AcceptableValueRange<>))
			{
				object value = ((object)val).GetType().GetProperty("MinValue").GetValue(val);
				object value2 = ((object)val).GetType().GetProperty("MaxValue").GetValue(val);
				if (IntegerTypes.Contains(settingType))
				{
					return CreateSliderInt(entry, value, value2, set);
				}
				if (RealTypes.Contains(settingType))
				{
					return CreateSlider(entry, value, value2, set);
				}
			}
			return CreateTextField(entry, set);
		}

		private static SettingEditor CreateToggle(ConfigEntryBase entry, Action<object> set)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			Toggle toggle = new Toggle();
			INotifyValueChangedExtensions.RegisterValueChangedCallback<bool>((INotifyValueChanged<bool>)(object)toggle, (EventCallback<ChangeEvent<bool>>)delegate(ChangeEvent<bool> e)
			{
				set(e.newValue);
			});
			return new SettingEditor
			{
				Control = (VisualElement)(object)toggle,
				Refresh = delegate
				{
					((BaseField<bool>)(object)toggle).SetValueWithoutNotify((bool)entry.BoxedValue);
				}
			};
		}

		private static SettingEditor CreateDropdown(ConfigEntryBase entry, IEnumerable<object> values, Action<object> set)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			List<object> options = values.ToList();
			List<string> labels = options.Select((object v) => Label(v, entry.SettingType)).ToList();
			DropdownField dropdown = new DropdownField(labels, 0, (Func<string, string>)null, (Func<string, string>)null);
			Theme.StyleDropdownMenusWhenOpened(dropdown);
			INotifyValueChangedExtensions.RegisterValueChangedCallback<string>((INotifyValueChanged<string>)(object)dropdown, (EventCallback<ChangeEvent<string>>)delegate(ChangeEvent<string> e)
			{
				int num = labels.IndexOf(e.newValue);
				if (num >= 0)
				{
					set(options[num]);
				}
			});
			return new SettingEditor
			{
				Control = (VisualElement)(object)dropdown,
				Refresh = delegate
				{
					string text = Label(entry.BoxedValue, entry.SettingType);
					if (!labels.Contains(text))
					{
						((BasePopupField<string, string>)(object)dropdown).choices = labels.Concat(new string[1] { text }).ToList();
					}
					((BaseField<string>)(object)dropdown).SetValueWithoutNotify(text);
				}
			};
		}

		private static string Label(object value, Type type)
		{
			if (type.IsEnum)
			{
				return SettingsRegistry.Humanize(value.ToString());
			}
			return TomlTypeConverter.ConvertToString(value, type);
		}

		private static SettingEditor CreateSliderInt(ConfigEntryBase entry, object min, object max, Action<object> set)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_0049: Expected O, but got Unknown
			Type type = entry.SettingType;
			SliderInt val = new SliderInt(ToInt(min), ToInt(max), (SliderDirection)0, 0f);
			((BaseSlider<int>)val).showInputField = true;
			SliderInt slider = val;
			INotifyValueChangedExtensions.RegisterValueChangedCallback<int>((INotifyValueChanged<int>)(object)slider, (EventCallback<ChangeEvent<int>>)delegate(ChangeEvent<int> e)
			{
				set(Convert.ChangeType(e.newValue, type));
			});
			return new SettingEditor
			{
				Control = (VisualElement)(object)slider,
				Refresh = delegate
				{
					((BaseField<int>)(object)slider).SetValueWithoutNotify(ToInt(entry.BoxedValue));
				}
			};
		}

		private static SettingEditor CreateSlider(ConfigEntryBase entry, object min, object max, Action<object> set)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0061: Expected O, but got Unknown
			Type type = entry.SettingType;
			float low = Convert.ToSingle(min);
			float high = Convert.ToSingle(max);
			Slider val = new Slider(low, high, (SliderDirection)0, 0f);
			((BaseSlider<float>)val).showInputField = true;
			Slider slider = val;
			float step = Mathf.Pow(10f, Mathf.Floor(Mathf.Log10(Mathf.Max(high - low, 1E-06f))) - 2f);
			INotifyValueChangedExtensions.RegisterValueChangedCallback<float>((INotifyValueChanged<float>)(object)slider, (EventCallback<ChangeEvent<float>>)delegate(ChangeEvent<float> e)
			{
				float num = Mathf.Clamp(Mathf.Round(e.newValue / step) * step, low, high);
				((BaseField<float>)(object)slider).SetValueWithoutNotify(num);
				set(Convert.ChangeType(num, type));
			});
			return new SettingEditor
			{
				Control = (VisualElement)(object)slider,
				Refresh = delegate
				{
					((BaseField<float>)(object)slider).SetValueWithoutNotify(Convert.ToSingle(entry.BoxedValue));
				}
			};
		}

		private static int ToInt(object value)
		{
			double val = Convert.ToDouble(value);
			return (int)Math.Max(-2147483648.0, Math.Min(2147483647.0, val));
		}

		private static SettingEditor CreateTextField(ConfigEntryBase entry, Action<object> set)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			TextField val = new TextField();
			((TextInputBaseField<string>)val).isDelayed = true;
			TextField field = val;
			Action refresh = delegate
			{
				((BaseField<string>)(object)field).SetValueWithoutNotify(entry.GetSerializedValue());
			};
			INotifyValueChangedExtensions.RegisterValueChangedCallback<string>((INotifyValueChanged<string>)(object)field, (EventCallback<ChangeEvent<string>>)delegate(ChangeEvent<string> e)
			{
				object obj;
				try
				{
					obj = ((entry.SettingType == typeof(string)) ? e.newValue : TomlTypeConverter.ConvertToValue(e.newValue, entry.SettingType));
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)$"'{e.newValue}' is not a valid value for {entry.Definition}: {ex.Message}");
					refresh();
					return;
				}
				set(obj);
			});
			return new SettingEditor
			{
				Control = (VisualElement)(object)field,
				Refresh = refresh
			};
		}
	}
	internal static class ConfigWriter
	{
		private static readonly HashSet<ConfigFile> Dirty = new HashSet<ConfigFile>();

		public static void Set(ConfigEntryBase entry, object value)
		{
			ConfigFile configFile = entry.ConfigFile;
			bool saveOnConfigSet = configFile.SaveOnConfigSet;
			try
			{
				configFile.SaveOnConfigSet = false;
				entry.BoxedValue = value;
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Could not set {entry.Definition} to '{value}': {arg}");
			}
			finally
			{
				configFile.SaveOnConfigSet = saveOnConfigSet;
			}
			if (saveOnConfigSet)
			{
				Dirty.Add(configFile);
			}
		}

		public static void Flush()
		{
			foreach (ConfigFile item in Dirty)
			{
				try
				{
					item.Save();
				}
				catch (Exception arg)
				{
					Plugin.Log.LogError((object)$"Could not save {item.ConfigFilePath}: {arg}");
				}
			}
			Dirty.Clear();
		}
	}
	internal sealed class ModInfo
	{
		public string Guid;

		public string Name;

		public string Version;

		public List<SettingInfo> Settings = new List<SettingInfo>();
	}
	internal sealed class SettingInfo
	{
		public ModInfo Mod;

		public ConfigEntryBase Entry;

		public string Section;

		public string Name;

		public string Description;

		public int Order;

		public bool ReadOnly;

		public bool Advanced;

		public bool RestartRequired;

		public bool HideDefaultButton;

		public bool Matches(string search)
		{
			if (!Contains(Name, search) && !Contains(Section, search) && !Contains(Entry.Definition.Key, search) && !Contains(Description, search))
			{
				return Contains(Mod.Name, search);
			}
			return true;
		}

		private static bool Contains(string text, string search)
		{
			if (text != null)
			{
				return text.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return false;
		}
	}
	internal static class SettingsRegistry
	{
		private const BindingFlags AnyField = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		public static List<ModInfo> Collect()
		{
			List<ModInfo> list = new List<ModInfo>();
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				if ((Object)(object)value.Instance == (Object)null)
				{
					continue;
				}
				ModInfo modInfo = new ModInfo
				{
					Guid = value.Metadata.GUID,
					Name = value.Metadata.Name,
					Version = value.Metadata.Version.ToString()
				};
				foreach (ConfigFile item in ConfigFiles(value.Instance))
				{
					foreach (ConfigEntryBase value2 in ((IDictionary<ConfigDefinition, ConfigEntryBase>)item).Values)
					{
						SettingInfo settingInfo = Describe(modInfo, value2);
						if (settingInfo != null)
						{
							modInfo.Settings.Add(settingInfo);
						}
					}
				}
				if (modInfo.Settings.Count != 0)
				{
					modInfo.Settings = modInfo.Settings.OrderBy<SettingInfo, string>((SettingInfo s) => s.Section, StringComparer.OrdinalIgnoreCase).ThenByDescending((SettingInfo s) => s.Order).ThenBy<SettingInfo, string>((SettingInfo s) => s.Name, StringComparer.OrdinalIgnoreCase)
						.ToList();
					list.Add(modInfo);
				}
			}
			return list.OrderBy<ModInfo, string>((ModInfo m) => m.Name, StringComparer.OrdinalIgnoreCase).ToList();
		}

		private static IEnumerable<ConfigFile> ConfigFiles(BaseUnityPlugin plugin)
		{
			HashSet<ConfigFile> seen = new HashSet<ConfigFile> { plugin.Config };
			yield return plugin.Config;
			Type type = ((object)plugin).GetType();
			while (type != null && type != typeof(BaseUnityPlugin))
			{
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					if (!(fieldInfo.FieldType != typeof(ConfigFile)))
					{
						BaseUnityPlugin obj = (fieldInfo.IsStatic ? null : plugin);
						object? value = fieldInfo.GetValue(obj);
						ConfigFile val = (ConfigFile)((value is ConfigFile) ? value : null);
						if (val != null && seen.Add(val))
						{
							yield return val;
						}
					}
				}
				type = type.BaseType;
			}
		}

		private static SettingInfo Describe(ModInfo mod, ConfigEntryBase entry)
		{
			SettingInfo obj = new SettingInfo
			{
				Mod = mod,
				Entry = entry,
				Section = entry.Definition.Section,
				Name = Humanize(entry.Definition.Key)
			};
			ConfigDescription description = entry.Description;
			obj.Description = ((description != null) ? description.Description : null);
			SettingInfo settingInfo = obj;
			ConfigDescription description2 = entry.Description;
			object[] array = ((description2 != null) ? description2.Tags : null);
			if (array == null)
			{
				return settingInfo;
			}
			object[] array2 = array;
			foreach (object obj2 in array2)
			{
				if (obj2 != null)
				{
					if (Read<bool?>(obj2, "Browsable") == false)
					{
						return null;
					}
					settingInfo.Section = Read<string>(obj2, "Category") ?? settingInfo.Section;
					settingInfo.Name = Read<string>(obj2, "DispName") ?? settingInfo.Name;
					settingInfo.Description = Read<string>(obj2, "Description") ?? settingInfo.Description;
					settingInfo.Order = Read<int?>(obj2, "Order") ?? settingInfo.Order;
					settingInfo.ReadOnly |= Read<bool?>(obj2, "ReadOnly") == true;
					settingInfo.Advanced |= Read<bool?>(obj2, "IsAdvanced") == true;
					settingInfo.RestartRequired |= Read<bool?>(obj2, "RestartRequired") == true;
					settingInfo.HideDefaultButton |= Read<bool?>(obj2, "HideDefaultButton") == true;
				}
			}
			return settingInfo;
		}

		private static T Read<T>(object tag, string name)
		{
			Type type = tag.GetType();
			FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public);
			object value;
			if (field != null)
			{
				value = field.GetValue(tag);
			}
			else
			{
				PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public);
				if (property == null || !property.CanRead)
				{
					return default(T);
				}
				value = property.GetValue(tag);
			}
			if (value is T)
			{
				return (T)value;
			}
			return default(T);
		}

		internal static string Humanize(string key)
		{
			if (string.IsNullOrEmpty(key) || key.Contains(" "))
			{
				return key;
			}
			List<char> list = new List<char>(key.Length + 8);
			for (int i = 0; i < key.Length; i++)
			{
				char c = key[i];
				if (c == '_')
				{
					list.Add(' ');
					continue;
				}
				if (i > 0 && char.IsUpper(c) && key[i - 1] != '_' && (char.IsLower(key[i - 1]) || (i + 1 < key.Length && char.IsLower(key[i + 1]) && char.IsUpper(key[i - 1]))))
				{
					list.Add(' ');
				}
				list.Add(c);
			}
			return new string(list.ToArray());
		}
	}
	internal static class Theme
	{
		public static readonly Color Window = Rgb(23, 23, 23);

		public static readonly Color WindowBorder = Rgb(185, 185, 185);

		public static readonly Color Surface = Rgb(34, 36, 41);

		public static readonly Color Control = Rgb(55, 59, 69);

		public static readonly Color ControlHover = Rgb(70, 75, 87);

		public static readonly Color Field = Rgb(20, 21, 24);

		public static readonly Color Line = Rgb(85, 90, 100);

		public static readonly Color Gold = Rgb(240, 200, 94);

		public static readonly Color Text = Rgb(242, 242, 242);

		public static readonly Color Muted = Rgb(169, 174, 183);

		private static readonly TextShadow Shadow = new TextShadow
		{
			offset = new Vector2(2f, 2f),
			color = new Color(0f, 0f, 0f, 0.8f)
		};

		public static void StyleButton(Button button, bool outlined = true)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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)
			IStyle style = ((VisualElement)button).style;
			style.color = StyleColor.op_Implicit(Text);
			style.textShadow = StyleTextShadow.op_Implicit(Shadow);
			style.unityFontStyleAndWeight = StyleEnum<FontStyle>.op_Implicit((FontStyle)1);
			SetPadding((VisualElement)(object)button, 6f, 14f);
			SetBorder((VisualElement)(object)button, 2f, outlined ? Gold : Line, 4f);
			SetHover((VisualElement)(object)button, Control, ControlHover);
		}

		public static void StyleControls(VisualElement root)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_006a: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: 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_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			UQueryExtensions.Query(root, (string)null, "unity-base-field__label").ForEach<StyleColor>((Func<VisualElement, StyleColor>)((VisualElement e) => e.style.color = StyleColor.op_Implicit(Muted)));
			UQueryExtensions.Query(root, (string)null, "unity-base-text-field__input").ForEach((Action<VisualElement>)delegate(VisualElement e)
			{
				//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_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: 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)
				e.style.backgroundColor = StyleColor.op_Implicit(Field);
				e.style.color = StyleColor.op_Implicit(Text);
				SetBorder(e, 1f, Line, 3f);
				UQueryExtensions.Query<VisualElement>(e, (string)null, (string)null).ForEach<StyleColor>((Func<VisualElement, StyleColor>)((VisualElement child) => child.style.color = StyleColor.op_Implicit(Text)));
			});
			UQueryExtensions.Query<Toggle>(root, (string)null, (string)null).ForEach<StyleColor>((Func<Toggle, StyleColor>)((Toggle t) => ((VisualElement)t).style.backgroundColor = StyleColor.op_Implicit(Color.clear)));
			UQueryExtensions.Query(root, (string)null, "unity-toggle__input").ForEach<StyleColor>((Func<VisualElement, StyleColor>)((VisualElement e) => e.style.backgroundColor = StyleColor.op_Implicit(Color.clear)));
			UQueryExtensions.Query(root, (string)null, "unity-toggle__checkmark").ForEach((Action<VisualElement>)delegate(VisualElement e)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: 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_0029: 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_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_0053: Unknown result type (might be due to invalid IL or missing references)
				IStyle style = e.style;
				StyleLength width = (e.style.height = StyleLength.op_Implicit(22f));
				style.width = width;
				e.style.backgroundColor = StyleColor.op_Implicit(Field);
				e.style.unityBackgroundImageTintColor = StyleColor.op_Implicit(Gold);
				SetBorder(e, 2f, Gold, 3f);
			});
			UQueryExtensions.Query(root, (string)null, "unity-base-popup-field__input").ForEach((Action<VisualElement>)delegate(VisualElement e)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				SetBorder(e, 1f, Line, 3f);
				SetHover(e, Control, ControlHover);
				SetPadding(e, 4f, 10f);
			});
			UQueryExtensions.Query(root, (string)null, "unity-base-popup-field__text").ForEach<StyleColor>((Func<VisualElement, StyleColor>)((VisualElement e) => e.style.color = StyleColor.op_Implicit(Text)));
			UQueryExtensions.Query(root, (string)null, "unity-base-popup-field__arrow").ForEach<StyleColor>((Func<VisualElement, StyleColor>)((VisualElement e) => e.style.unityBackgroundImageTintColor = StyleColor.op_Implicit(Text)));
			UQueryExtensions.Query(root, (string)null, "unity-base-slider__tracker").ForEach((Action<VisualElement>)delegate(VisualElement e)
			{
				//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_001b: Unknown result type (might be due to invalid IL or missing references)
				e.style.backgroundColor = StyleColor.op_Implicit(Field);
				SetBorder(e, 1f, Line, 2f);
			});
			UQueryExtensions.Query(root, (string)null, "unity-base-slider__dragger").ForEach((Action<VisualElement>)delegate(VisualElement e)
			{
				//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_001b: Unknown result type (might be due to invalid IL or missing references)
				e.style.backgroundColor = StyleColor.op_Implicit(Gold);
				SetBorder(e, 0f, Color.clear, 2f);
			});
			UQueryExtensions.Query(root, (string)null, "unity-base-slider__dragger-border").ForEach((Action<VisualElement>)delegate(VisualElement e)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				SetBorder(e, 0f, Color.clear, 0f);
			});
			UQueryExtensions.Query(root, (string)null, "unity-scroller").ForEach((Action<VisualElement>)delegate(VisualElement e)
			{
				//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_001b: Unknown result type (might be due to invalid IL or missing references)
				e.style.backgroundColor = StyleColor.op_Implicit(Color.clear);
				SetBorder(e, 0f, Color.clear, 0f);
			});
			UQueryExtensions.Query(root, (string)null, "unity-scroller__low-button").ForEach<StyleEnum<DisplayStyle>>((Func<VisualElement, StyleEnum<DisplayStyle>>)((VisualElement e) => e.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1)));
			UQueryExtensions.Query(root, (string)null, "unity-scroller__high-button").ForEach<StyleEnum<DisplayStyle>>((Func<VisualElement, StyleEnum<DisplayStyle>>)((VisualElement e) => e.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1)));
			UQueryExtensions.Query(root, (string)null, "unity-scroller").ForEach((Action<VisualElement>)delegate(VisualElement scroller)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: 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)
				UQueryExtensions.Query(scroller, (string)null, "unity-base-slider__tracker").ForEach((Action<VisualElement>)delegate(VisualElement e)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					SetBorder(e, 0f, Color.clear, 3f);
				});
				UQueryExtensions.Query(scroller, (string)null, "unity-base-slider__dragger").ForEach<StyleColor>((Func<VisualElement, StyleColor>)((VisualElement e) => e.style.backgroundColor = StyleColor.op_Implicit(Line)));
			});
		}

		public static void StyleDropdownMenusWhenOpened(DropdownField dropdown)
		{
			EventCallback<EventBase> styleLater = delegate
			{
				((VisualElement)dropdown).schedule.Execute((Action)delegate
				{
					//IL_0023: Unknown result type (might be due to invalid IL or missing references)
					//IL_0028: Unknown result type (might be due to invalid IL or missing references)
					//IL_0056: Unknown result type (might be due to invalid IL or missing references)
					//IL_005b: Unknown result type (might be due to invalid IL or missing references)
					//IL_008a: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
					//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
					//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
					//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
					IPanel panel = ((VisualElement)dropdown).panel;
					VisualElement val = ((panel != null) ? panel.visualTree : null);
					if (val != null)
					{
						UQueryExtensions.Query(val, (string)null, "unity-base-dropdown__container-outer").ForEach((Action<VisualElement>)delegate(VisualElement e)
						{
							//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_001b: Unknown result type (might be due to invalid IL or missing references)
							e.style.backgroundColor = StyleColor.op_Implicit(Surface);
							SetBorder(e, 1f, Gold, 3f);
						});
						UQueryExtensions.Query(val, (string)null, "unity-base-dropdown__container-inner").ForEach<StyleColor>((Func<VisualElement, StyleColor>)((VisualElement e) => e.style.backgroundColor = StyleColor.op_Implicit(Surface)));
						UQueryExtensions.Query(val, (string)null, "unity-base-dropdown__item").ForEach((Action<VisualElement>)delegate(VisualElement e)
						{
							//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)
							SetHover(e, Surface, ControlHover);
						});
						UQueryExtensions.Query(val, (string)null, "unity-base-dropdown__label").ForEach<StyleColor>((Func<VisualElement, StyleColor>)((VisualElement e) => e.style.color = StyleColor.op_Implicit(Text)));
						UQueryExtensions.Query(val, (string)null, "unity-base-dropdown__checkmark").ForEach<StyleColor>((Func<VisualElement, StyleColor>)((VisualElement e) => e.style.unityBackgroundImageTintColor = StyleColor.op_Implicit(Gold)));
					}
				}).ExecuteLater(0L);
			};
			((CallbackEventHandler)dropdown).RegisterCallback<PointerDownEvent>((EventCallback<PointerDownEvent>)delegate(PointerDownEvent e)
			{
				styleLater.Invoke((EventBase)(object)e);
			}, (TrickleDown)1);
			((CallbackEventHandler)dropdown).RegisterCallback<NavigationSubmitEvent>((EventCallback<NavigationSubmitEvent>)delegate(NavigationSubmitEvent e)
			{
				styleLater.Invoke((EventBase)(object)e);
			}, (TrickleDown)1);
		}

		public static void SetHover(VisualElement element, Color normal, Color hover)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			bool hovered = false;
			bool focused = false;
			Action update = delegate
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				element.style.backgroundColor = StyleColor.op_Implicit((hovered || focused) ? hover : normal);
			};
			((CallbackEventHandler)element).RegisterCallback<PointerEnterEvent>((EventCallback<PointerEnterEvent>)delegate
			{
				hovered = true;
				update();
			}, (TrickleDown)0);
			((CallbackEventHandler)element).RegisterCallback<PointerLeaveEvent>((EventCallback<PointerLeaveEvent>)delegate
			{
				hovered = false;
				update();
			}, (TrickleDown)0);
			((CallbackEventHandler)element).RegisterCallback<FocusInEvent>((EventCallback<FocusInEvent>)delegate
			{
				focused = true;
				update();
			}, (TrickleDown)0);
			((CallbackEventHandler)element).RegisterCallback<FocusOutEvent>((EventCallback<FocusOutEvent>)delegate
			{
				focused = false;
				update();
			}, (TrickleDown)0);
			update();
		}

		public static void SetPadding(VisualElement element, float vertical, float horizontal)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			IStyle style = element.style;
			StyleLength paddingTop = (style.paddingBottom = StyleLength.op_Implicit(vertical));
			style.paddingTop = paddingTop;
			paddingTop = (style.paddingRight = StyleLength.op_Implicit(horizontal));
			style.paddingLeft = paddingTop;
		}

		public static void SetBorder(VisualElement element, float width, Color color, float radius)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0038: 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_0042: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			IStyle style = element.style;
			StyleFloat val = (style.borderRightWidth = StyleFloat.op_Implicit(width));
			StyleFloat val3 = (style.borderLeftWidth = val);
			StyleFloat borderTopWidth = (style.borderBottomWidth = val3);
			style.borderTopWidth = borderTopWidth;
			StyleColor val6 = (style.borderRightColor = StyleColor.op_Implicit(color));
			StyleColor val8 = (style.borderLeftColor = val6);
			StyleColor borderTopColor = (style.borderBottomColor = val8);
			style.borderTopColor = borderTopColor;
			StyleLength val11 = (style.borderBottomRightRadius = StyleLength.op_Implicit(radius));
			StyleLength val13 = (style.borderBottomLeftRadius = val11);
			StyleLength borderTopLeftRadius = (style.borderTopRightRadius = val13);
			style.borderTopLeftRadius = borderTopLeftRadius;
		}

		private static Color Rgb(int r, int g, int b)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			return new Color((float)r / 255f, (float)g / 255f, (float)b / 255f);
		}
	}
}
namespace ModSettings.Patches
{
	internal static class GameUi
	{
		public static Button CloneButton(Button source, string text)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_006c: 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)
			//IL_007a: Expected O, but got Unknown
			Button val = new Button
			{
				name = "ModSettingsButton"
			};
			foreach (string @class in ((VisualElement)source).GetClasses())
			{
				((VisualElement)val).AddToClassList(@class);
			}
			CopyInlineStyle(((VisualElement)source).style, ((VisualElement)val).style);
			Label val2 = UQueryExtensions.Q<Label>((VisualElement)(object)source, (string)null, (string)null);
			if (string.IsNullOrEmpty(((TextElement)source).text) && val2 != null)
			{
				Label val3 = new Label(text)
				{
					pickingMode = (PickingMode)1
				};
				foreach (string class2 in ((VisualElement)val2).GetClasses())
				{
					((VisualElement)val3).AddToClassList(class2);
				}
				CopyInlineStyle(((VisualElement)val2).style, ((VisualElement)val3).style);
				((VisualElement)val).Add((VisualElement)(object)val3);
			}
			else
			{
				((TextElement)val).text = text;
			}
			return val;
		}

		private static void CopyInlineStyle(IStyle from, IStyle to)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0032: 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_004a: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			to.backgroundColor = from.backgroundColor;
			to.backgroundImage = from.backgroundImage;
			to.unityBackgroundImageTintColor = from.unityBackgroundImageTintColor;
			to.unitySliceLeft = from.unitySliceLeft;
			to.unitySliceRight = from.unitySliceRight;
			to.unitySliceTop = from.unitySliceTop;
			to.unitySliceBottom = from.unitySliceBottom;
			to.unitySliceScale = from.unitySliceScale;
			to.borderTopWidth = from.borderTopWidth;
			to.borderBottomWidth = from.borderBottomWidth;
			to.borderLeftWidth = from.borderLeftWidth;
			to.borderRightWidth = from.borderRightWidth;
			to.borderTopColor = from.borderTopColor;
			to.borderBottomColor = from.borderBottomColor;
			to.borderLeftColor = from.borderLeftColor;
			to.borderRightColor = from.borderRightColor;
			to.borderTopLeftRadius = from.borderTopLeftRadius;
			to.borderTopRightRadius = from.borderTopRightRadius;
			to.borderBottomLeftRadius = from.borderBottomLeftRadius;
			to.borderBottomRightRadius = from.borderBottomRightRadius;
			to.color = from.color;
			to.fontSize = from.fontSize;
			to.unityFont = from.unityFont;
			to.unityFontDefinition = from.unityFontDefinition;
			to.unityFontStyleAndWeight = from.unityFontStyleAndWeight;
			to.unityTextAlign = from.unityTextAlign;
			to.unityTextOutlineColor = from.unityTextOutlineColor;
			to.unityTextOutlineWidth = from.unityTextOutlineWidth;
			to.textShadow = from.textShadow;
			to.letterSpacing = from.letterSpacing;
			to.paddingTop = from.paddingTop;
			to.paddingBottom = from.paddingBottom;
			to.paddingLeft = from.paddingLeft;
			to.paddingRight = from.paddingRight;
		}

		public static List<StyleSheet> StyleSheetsOf(VisualElement element)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			List<StyleSheet> list = new List<StyleSheet>();
			int num = 0;
			while (true)
			{
				int num2 = num;
				int num3;
				VisualElementStyleSheetSet styleSheets;
				if (element == null)
				{
					num3 = 0;
				}
				else
				{
					styleSheets = element.styleSheets;
					num3 = ((VisualElementStyleSheetSet)(ref styleSheets)).count;
				}
				if (num2 >= num3)
				{
					break;
				}
				styleSheets = element.styleSheets;
				list.Add(((VisualElementStyleSheetSet)(ref styleSheets))[num]);
				num++;
			}
			return list;
		}

		public static void GrowAncestorsToFit(VisualElement element, VisualElement stopAt)
		{
			VisualElement parent = element.parent;
			while (parent != null && parent != stopAt)
			{
				VisualElement target = parent;
				((CallbackEventHandler)target).RegisterCallback<GeometryChangedEvent>((EventCallback<GeometryChangedEvent>)delegate
				{
					GrowToFit(target);
				}, (TrickleDown)0);
				parent = parent.parent;
			}
		}

		private static void GrowToFit(VisualElement element)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			//IL_0044: 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_0063: 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_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_00f6: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			float num = float.MaxValue;
			float num2 = float.MinValue;
			Rect layout;
			foreach (VisualElement item in element.Children())
			{
				IResolvedStyle resolvedStyle = item.resolvedStyle;
				if ((int)resolvedStyle.display != 1 && (int)resolvedStyle.position != 1)
				{
					float num3 = num;
					layout = item.layout;
					num = Mathf.Min(num3, ((Rect)(ref layout)).yMin - resolvedStyle.marginTop);
					float num4 = num2;
					layout = item.layout;
					num2 = Mathf.Max(num4, ((Rect)(ref layout)).yMax + resolvedStyle.marginBottom);
				}
			}
			if (!(num2 < num))
			{
				IResolvedStyle resolvedStyle2 = element.resolvedStyle;
				float num5 = num2;
				layout = element.layout;
				float num6 = Mathf.Max(0f, num5 - (((Rect)(ref layout)).height - resolvedStyle2.paddingBottom - resolvedStyle2.borderBottomWidth)) + Mathf.Max(0f, resolvedStyle2.borderTopWidth + resolvedStyle2.paddingTop - num);
				if (!(num6 < 0.5f))
				{
					element.style.maxHeight = StyleLength.op_Implicit((StyleKeyword)3);
					IStyle style = element.style;
					layout = element.layout;
					style.height = StyleLength.op_Implicit(((Rect)(ref layout)).height + num6);
				}
			}
		}
	}
	internal static class MainMenuIntegration
	{
		private sealed class SlotPlacer
		{
			private readonly VisualElement _button;

			private readonly VisualElement _container;

			private readonly VisualElement _roadmap;

			private readonly VisualElement _patchNote;

			private readonly VisualElement _discord;

			private Vector2 _offset;

			public SlotPlacer(VisualElement button, VisualElement container, VisualElement roadmap, VisualElement patchNote, VisualElement discord)
			{
				_button = button;
				_container = container;
				_roadmap = roadmap;
				_patchNote = patchNote;
				_discord = discord;
				VisualElement[] array = (VisualElement[])(object)new VisualElement[4] { container, roadmap, patchNote, discord };
				for (int i = 0; i < array.Length; i++)
				{
					((CallbackEventHandler)array[i]).RegisterCallback<GeometryChangedEvent>((EventCallback<GeometryChangedEvent>)delegate
					{
						Place();
					}, (TrickleDown)0);
				}
				((CallbackEventHandler)button).RegisterCallback<GeometryChangedEvent>((EventCallback<GeometryChangedEvent>)delegate
				{
					Correct();
				}, (TrickleDown)0);
			}

			private Rect Target()
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
				Rect val = VisualElementExtensions.WorldToLocal(_container, _roadmap.worldBound);
				Rect val2 = VisualElementExtensions.WorldToLocal(_container, _patchNote.worldBound);
				Rect val3 = VisualElementExtensions.WorldToLocal(_container, _discord.worldBound);
				float num = ((Rect)(ref val3)).xMin - ((Rect)(ref val)).xMax;
				float num2 = ((Rect)(ref val2)).xMin - num - ((Rect)(ref val)).xMin;
				if (num < 0f || num2 < ((Rect)(ref val)).width * 0.5f)
				{
					num2 = ((Rect)(ref val)).width;
				}
				return new Rect(((Rect)(ref val)).xMin, ((Rect)(ref val2)).yMin, num2, ((Rect)(ref val2)).height);
			}

			private void Place()
			{
				//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_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: Unknown result type (might be due to invalid IL or missing references)
				Rect layout = _roadmap.layout;
				if (!(((Rect)(ref layout)).width <= 0f))
				{
					layout = _patchNote.layout;
					if (!(((Rect)(ref layout)).width <= 0f))
					{
						Rect val = Target();
						IStyle style = _button.style;
						style.left = StyleLength.op_Implicit(((Rect)(ref val)).x - _offset.x);
						style.top = StyleLength.op_Implicit(((Rect)(ref val)).y - _offset.y);
						style.width = StyleLength.op_Implicit(((Rect)(ref val)).width);
						style.height = StyleLength.op_Implicit(((Rect)(ref val)).height);
					}
				}
			}

			private void Correct()
			{
				//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_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_0031: 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_003a: 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_0042: 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_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: 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_0069: Unknown result type (might be due to invalid IL or missing references)
				Rect val = _roadmap.layout;
				if (!(((Rect)(ref val)).width <= 0f))
				{
					val = VisualElementExtensions.WorldToLocal(_container, _button.worldBound);
					Vector2 position = ((Rect)(ref val)).position;
					val = Target();
					Vector2 val2 = position - ((Rect)(ref val)).position;
					if (!(((Vector2)(ref val2)).sqrMagnitude < 0.25f))
					{
						_offset += val2;
						Place();
					}
				}
			}
		}

		private static readonly FieldRef<MainMenu, SettingsScreen> SettingsScreenRef = AccessTools.FieldRefAccess<MainMenu, SettingsScreen>("settingsScreen");

		private static readonly FieldRef<MainMenu, MainMenuScreen> MainMenuScreenRef = AccessTools.FieldRefAccess<MainMenu, MainMenuScreen>("mainMenuScreen");

		private static readonly FieldRef<BaseUIScreen, List<VisualElement>> NavigableElements = AccessTools.FieldRefAccess<BaseUIScreen, List<VisualElement>>("navigableElements");

		private static MainMenu _menu;

		private static Button _modsButton;

		private static ModSettingsPanel _panel;

		public static void Attach(MainMenu menu)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			UIDocument component = ((Component)menu).GetComponent<UIDocument>();
			VisualElement val = ((component != null) ? component.rootVisualElement : null);
			VisualElement val2 = ((val != null) ? UQueryExtensions.Q<VisualElement>(val, "MainMenuScreen", (string)null) : null);
			Button val3 = ((val2 != null) ? UQueryExtensions.Q<Button>(val2, "MainMenu_Roadmap_Btn", (string)null) : null);
			Button val4 = ((val2 != null) ? UQueryExtensions.Q<Button>(val2, "MainMenu_PatchNote_Btn", (string)null) : null);
			Button val5 = ((val2 != null) ? UQueryExtensions.Q<Button>(val2, "MainMenu_Discord_Btn", (string)null) : null);
			if (val3 == null || val4 == null || val5 == null)
			{
				Plugin.Log.LogWarning((object)"Main menu layout not recognised; the Mod Settings button was not added");
				return;
			}
			_menu = menu;
			_modsButton = GameUi.CloneButton(val3, "MOD SETTINGS");
			_modsButton.clicked += Open;
			IStyle style = ((VisualElement)_modsButton).style;
			style.position = StyleEnum<Position>.op_Implicit((Position)1);
			StyleLength val6 = (style.marginBottom = StyleLength.op_Implicit(0f));
			StyleLength val8 = (style.marginTop = val6);
			StyleLength marginLeft = (style.marginRight = val8);
			style.marginLeft = marginLeft;
			val2.Add((VisualElement)(object)_modsButton);
			MainMenuScreen val11 = MainMenuScreenRef.Invoke(menu);
			if (val11 != null)
			{
				NavigableElements.Invoke((BaseUIScreen)(object)val11).Add((VisualElement)(object)_modsButton);
			}
			new SlotPlacer((VisualElement)(object)_modsButton, val2, (VisualElement)(object)val3, (VisualElement)(object)val4, (VisualElement)(object)val5);
			ModSettingsPanel panel = _panel;
			if (panel != null)
			{
				panel.Root.RemoveFromHierarchy();
			}
			SettingsScreen obj = SettingsScreenRef.Invoke(menu);
			_panel = new ModSettingsPanel(GameUi.StyleSheetsOf((obj != null) ? obj.SettingsScreenElement : null));
			_panel.CloseRequested += Close;
			val.Add(_panel.Root);
		}

		private static void Open()
		{
			if (!((Object)(object)_menu == (Object)null) && _panel != null && !_panel.IsOpen)
			{
				AudioManager instance = AudioManager.Instance;
				if (instance != null)
				{
					instance.PlayUIButton();
				}
				MainMenuScreen obj = MainMenuScreenRef.Invoke(_menu);
				if (obj != null)
				{
					obj.SetNavigable(false);
				}
				_panel.Open();
				if ((Object)(object)InputManager.Instance != (Object)null)
				{
					InputManager.Instance.OnMainMenuReturn += OnReturn;
				}
			}
		}

		private static void OnReturn()
		{
			if (KeyRebindEditor.ConsumesEscape)
			{
				KeyRebindEditor.CancelListening();
			}
			else
			{
				Close();
			}
		}

		private static void Close()
		{
			if (_panel == null || !_panel.IsOpen)
			{
				return;
			}
			if ((Object)(object)InputManager.Instance != (Object)null)
			{
				InputManager.Instance.OnMainMenuReturn -= OnReturn;
			}
			AudioManager instance = AudioManager.Instance;
			if (instance != null)
			{
				instance.PlayUIButton();
			}
			_panel.Close();
			if ((Object)(object)_menu != (Object)null)
			{
				_menu.RestoreMainMenuNavigation();
			}
			Button button = _modsButton;
			Button obj = button;
			if (obj != null)
			{
				((VisualElement)obj).schedule.Execute((Action)delegate
				{
					((Focusable)button).Focus();
				}).ExecuteLater(0L);
			}
		}

		public static void Detach(MainMenu menu)
		{
			if ((Object)(object)menu != (Object)(object)_menu)
			{
				return;
			}
			if (_panel != null && _panel.IsOpen)
			{
				if ((Object)(object)InputManager.Instance != (Object)null)
				{
					InputManager.Instance.OnMainMenuReturn -= OnReturn;
				}
				_panel.Close();
			}
			_menu = null;
			_panel = null;
			_modsButton = null;
		}
	}
	[HarmonyPatch(typeof(MainMenu), "Start")]
	internal static class MainMenuStartPatch
	{
		private static void Postfix(MainMenu __instance)
		{
			try
			{
				MainMenuIntegration.Attach(__instance);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Could not add the Mod Settings button to the main menu: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(MainMenu), "OnDestroy")]
	internal static class MainMenuDestroyPatch
	{
		private static void Prefix(MainMenu __instance)
		{
			MainMenuIntegration.Detach(__instance);
		}
	}
	internal static class PauseMenuIntegration
	{
		private static readonly FieldRef<UIPauseMenu, Button> SettingsButton = AccessTools.FieldRefAccess<UIPauseMenu, Button>("settingsButton");

		private static readonly FieldRef<UIPauseMenu, SettingsScreen> SettingsScreenRef = AccessTools.FieldRefAccess<UIPauseMenu, SettingsScreen>("settingsScreen");

		private static readonly FieldRef<BaseMenu, List<VisualElement>> NavigableElements = AccessTools.FieldRefAccess<BaseMenu, List<VisualElement>>("navigableElements");

		private static readonly Action<BaseMenu, bool> SetNavigable = AccessTools.MethodDelegate<Action<BaseMenu, bool>>(AccessTools.Method(typeof(BaseMenu), "SetNavigable", (Type[])null, (Type[])null), (object)null, true);

		private static UIPauseMenu _menu;

		private static Button _modsButton;

		public static ModSettingsPanel Panel { get; private set; }

		public static void Attach(UIPauseMenu menu)
		{
			Button val = SettingsButton.Invoke(menu);
			UIDocument component = ((Component)menu).GetComponent<UIDocument>();
			VisualElement val2 = ((component != null) ? component.rootVisualElement : null);
			if (((val != null) ? ((VisualElement)val).parent : null) == null || val2 == null)
			{
				Plugin.Log.LogWarning((object)"Pause menu layout not recognised; the Mods button was not added");
				return;
			}
			_menu = menu;
			_modsButton = GameUi.CloneButton(val, "Mods");
			_modsButton.clicked += Open;
			VisualElement parent = ((VisualElement)val).parent;
			parent.Insert(parent.IndexOf((VisualElement)(object)val) + 1, (VisualElement)(object)_modsButton);
			NavigableElements.Invoke((BaseMenu)(object)menu).Add((VisualElement)(object)_modsButton);
			GameUi.GrowAncestorsToFit((VisualElement)(object)_modsButton, val2);
			ModSettingsPanel panel = Panel;
			if (panel != null)
			{
				panel.Root.RemoveFromHierarchy();
			}
			SettingsScreen obj = SettingsScreenRef.Invoke(menu);
			Panel = new ModSettingsPanel(GameUi.StyleSheetsOf((obj != null) ? obj.SettingsScreenElement : null));
			Panel.CloseRequested += Close;
			val2.Add(Panel.Root);
		}

		public static bool HandleBack()
		{
			if (KeyRebindEditor.ConsumesEscape)
			{
				KeyRebindEditor.CancelListening();
				return true;
			}
			if (Panel == null || !Panel.IsOpen)
			{
				return false;
			}
			Close();
			return true;
		}

		public static void ForceClose()
		{
			if (Panel != null && Panel.IsOpen)
			{
				Panel.Close();
				if ((Object)(object)_menu != (Object)null)
				{
					SetNavigable((BaseMenu)(object)_menu, arg2: true);
				}
			}
		}

		private static void Open()
		{
			if (!((Object)(object)_menu == (Object)null) && Panel != null)
			{
				AudioManager instance = AudioManager.Instance;
				if (instance != null)
				{
					instance.PlayUIButton();
				}
				SetNavigable((BaseMenu)(object)_menu, arg2: false);
				Panel.Open();
			}
		}

		private static void Close()
		{
			AudioManager instance = AudioManager.Instance;
			if (instance != null)
			{
				instance.PlayUIButton();
			}
			ForceClose();
			Button button = _modsButton;
			Button obj = button;
			if (obj != null)
			{
				((VisualElement)obj).schedule.Execute((Action)delegate
				{
					((Focusable)button).Focus();
				}).ExecuteLater(0L);
			}
		}
	}
	[HarmonyPatch(typeof(UIPauseMenu), "Init")]
	internal static class PauseMenuInitPatch
	{
		private static void Postfix(UIPauseMenu __instance)
		{
			try
			{
				PauseMenuIntegration.Attach(__instance);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Could not add the Mods button to the pause menu: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(UIPauseMenu), "OnPauseExitButton")]
	internal static class PauseMenuBackPatch
	{
		private static bool Prefix()
		{
			return !PauseMenuIntegration.HandleBack();
		}
	}
	[HarmonyPatch(typeof(UIPauseMenu), "PauseShow")]
	internal static class PauseMenuHidePatch
	{
		private static void Postfix(bool _Show)
		{
			if (!_Show)
			{
				PauseMenuIntegration.ForceClose();
			}
		}
	}
}