Decompiled source of ConfigurationManager v1.1.16

ConfigurationManager.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ConditionalConfigSync;
using ConfigurationManager.Utilities;
using HarmonyLib;
using Newtonsoft.Json.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Valheim Configuration Manager")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Valheim Configuration Manager")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0bac4d10-1d45-4b13-861c-48bae48536e9")]
[assembly: AssemblyFileVersion("1.1.16")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.16.0")]
[module: UnverifiableCode]
public struct HSLColor
{
	public float h;

	public float s;

	public float l;

	public float a;

	public HSLColor(float h, float s, float l, float a)
	{
		this.h = h;
		this.s = s;
		this.l = l;
		this.a = a;
	}

	public HSLColor(float h, float s, float l)
	{
		this.h = h;
		this.s = s;
		this.l = l;
		a = 1f;
	}

	public HSLColor(Color c)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		HSLColor hSLColor = FromRGBA(c);
		h = hSLColor.h;
		s = hSLColor.s;
		l = hSLColor.l;
		a = hSLColor.a;
	}

	public static HSLColor FromRGBA(Color c)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: 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_0026: 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_0037: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: 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_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: 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)
		float num = c.a;
		float num2 = Mathf.Min(Mathf.Min(c.r, c.g), c.b);
		float num3 = Mathf.Max(Mathf.Max(c.r, c.g), c.b);
		float num4 = (num2 + num3) / 2f;
		float num5;
		float num6;
		if (num2 == num3)
		{
			num5 = 0f;
			num6 = 0f;
		}
		else
		{
			float num7 = num3 - num2;
			num5 = ((num4 <= 0.5f) ? (num7 / (num3 + num2)) : (num7 / (2f - (num3 + num2))));
			num6 = 0f;
			if (c.r == num3)
			{
				num6 = (c.g - c.b) / num7;
			}
			else if (c.g == num3)
			{
				num6 = 2f + (c.b - c.r) / num7;
			}
			else if (c.b == num3)
			{
				num6 = 4f + (c.r - c.g) / num7;
			}
			num6 = Mathf.Repeat(num6 * 60f, 360f);
		}
		return new HSLColor(num6, num5, num4, num);
	}

	public Color ToRGBA()
	{
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		float num = a;
		float num2 = ((l <= 0.5f) ? (l * (1f + s)) : (l + s - l * s));
		float n = 2f * l - num2;
		float num3;
		float num4;
		float num5;
		if (s == 0f)
		{
			num3 = (num4 = (num5 = l));
		}
		else
		{
			num3 = Value(n, num2, h + 120f);
			num4 = Value(n, num2, h);
			num5 = Value(n, num2, h - 120f);
		}
		return new Color(num3, num4, num5, num);
	}

	private static float Value(float n1, float n2, float hue)
	{
		hue = Mathf.Repeat(hue, 360f);
		if (hue < 60f)
		{
			return n1 + (n2 - n1) * hue / 60f;
		}
		if (hue < 180f)
		{
			return n2;
		}
		if (hue < 240f)
		{
			return n1 + (n2 - n1) * (240f - hue) / 60f;
		}
		return n1;
	}

	public static implicit operator HSLColor(Color src)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		return FromRGBA(src);
	}

	public static implicit operator Color(HSLColor src)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		return src.ToRGBA();
	}
}
namespace ConfigurationManager
{
	public class ConfigFilesEditor
	{
		private enum FileEditState
		{
			None,
			CreatingFolder,
			CreatingFile,
			RenamingFile
		}

		private static readonly string _trashBinDirectory = Path.Combine(Paths.CachePath, "ConfigurationManagerTrashBin");

		private static readonly string[] _directories = new string[3]
		{
			Paths.ConfigPath,
			Paths.PluginPath,
			_trashBinDirectory
		};

		private readonly Dictionary<string, bool> _folderStates = new Dictionary<string, bool>();

		private Vector2 _scrollPosition;

		private string _fileContent;

		private Vector2 _textScrollPosition;

		private Rect _windowRect = new Rect(ConfigurationManager._windowPositionTextEditor.Value, ConfigurationManager._windowSizeTextEditor.Value);

		private const int WindowId = -680;

		private const string SearchBoxName = "searchBoxEditor";

		private const int DirectoryOffset = 20;

		private const string TextEditorControlName = "textEditorTextField";

		private bool _focusSearchBox;

		private bool _focusTextArea;

		private string _searchString;

		private string _errorText;

		private string _activeFile;

		private string _activeDirectory;

		private string _newItemName;

		private string _newItemErrorText;

		private FileEditState _fileNameState;

		private bool _isOpen;

		private bool _clearCache;

		private int _directoryDepth;

		private readonly Dictionary<string, string[]> _cachedFileTree = new Dictionary<string, string[]>();

		private readonly Dictionary<string, string[]> _cachedDirectories = new Dictionary<string, string[]>();

		private FileSystemWatcher[] _watchers;

		private string SearchString
		{
			get
			{
				return _searchString;
			}
			set
			{
				if (value == null)
				{
					value = string.Empty;
				}
				_searchString = value;
			}
		}

		public bool IsOpen
		{
			get
			{
				return _isOpen;
			}
			set
			{
				if (_isOpen != (_isOpen = value))
				{
					ClearCache();
				}
			}
		}

		private void SetFileEditState(FileEditState newState)
		{
			_fileNameState = newState;
			_newItemErrorText = string.Empty;
			_newItemName = string.Empty;
		}

		public void OnGUI()
		{
			//IL_001e: 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_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_004a: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_00b8: 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_00d9: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			if (IsOpen)
			{
				((Rect)(ref _windowRect)).size = ConfigurationManager._windowSizeTextEditor.Value;
				((Rect)(ref _windowRect)).position = ConfigurationManager._windowPositionTextEditor.Value;
				Color backgroundColor = GUI.backgroundColor;
				GUI.backgroundColor = ConfigurationManager._windowBackgroundColor.Value;
				_windowRect = GUI.Window(-680, _windowRect, new WindowFunction(DrawWindow), Utility.IsNullOrWhiteSpace(_activeFile) ? ConfigurationManager._windowTitleTextEditor.Value : ("..." + _activeFile.Replace(Path.GetDirectoryName(Paths.BepInExRootPath) ?? string.Empty, "")), ConfigurationManagerStyles.GetWindowStyle());
				if (!UnityInput.Current.GetKeyDown((KeyCode)323) && ((Rect)(ref _windowRect)).position != ConfigurationManager._windowPositionTextEditor.Value)
				{
					SaveCurrentSizeAndPosition();
				}
				GUI.backgroundColor = backgroundColor;
			}
		}

		internal void SaveCurrentSizeAndPosition()
		{
			//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_0064: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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)
			ConfigurationManager._windowSizeTextEditor.Value = new Vector2(Mathf.Clamp(((Rect)(ref _windowRect)).size.x, 1000f / ConfigurationManager.instance.ScaleFactor, ConfigurationManager.instance.ScreenWidth), Mathf.Clamp(((Rect)(ref _windowRect)).size.y, 600f / ConfigurationManager.instance.ScaleFactor, ConfigurationManager.instance.ScreenHeight));
			ConfigurationManager._windowPositionTextEditor.Value = new Vector2(Mathf.Clamp(((Rect)(ref _windowRect)).position.x, 0f, ConfigurationManager.instance.ScreenWidth - ConfigurationManager._windowSize.Value.x / 4f), Mathf.Clamp(((Rect)(ref _windowRect)).position.y, 0f, ConfigurationManager.instance.ScreenHeight - 40f));
			((BaseUnityPlugin)ConfigurationManager.instance).Config.Save();
		}

		private void DrawFilters()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			string value = ConfigurationManager._extensionsTitleTextEditor.Value;
			GUILayout.Label(value, ConfigurationManagerStyles.GetLabelStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(ConfigurationManagerStyles.GetLabelStyle().CalcSize(new GUIContent(value)).x + 2f) });
			ConfigurationManager._editableExtensions.Value = GUILayout.TextField(ConfigurationManager._editableExtensions.Value, ConfigurationManagerStyles.GetTextStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			Color backgroundColor = GUI.backgroundColor;
			if (ConfigurationManager._hideModConfigs.Value)
			{
				GUI.backgroundColor = ConfigurationManager._enabledBackgroundColor.Value;
			}
			ConfigurationManager._hideModConfigs.Value = GUILayout.Toggle(ConfigurationManager._hideModConfigs.Value, new GUIContent(((ConfigEntryBase)ConfigurationManager._hideModConfigs).Definition.Key, ((ConfigEntryBase)ConfigurationManager._hideModConfigs).Description.Description), ConfigurationManagerStyles.GetToggleStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUI.backgroundColor = backgroundColor;
			GUILayout.EndHorizontal();
		}

		private void DrawSearchBox()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(ConfigurationManager._searchTextEditor.Value, ConfigurationManagerStyles.GetLabelStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(ConfigurationManagerStyles.GetLabelStyle().CalcSize(new GUIContent(ConfigurationManager._searchTextEditor.Value)).x + 4f) });
			GUI.SetNextControlName("searchBoxEditor");
			SearchString = GUILayout.TextField(SearchString, ConfigurationManagerStyles.GetTextStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			if (_focusSearchBox)
			{
				GUI.FocusWindow(-680);
				GUI.FocusControl("searchBoxEditor");
				_focusSearchBox = false;
			}
			Color backgroundColor = GUI.backgroundColor;
			GUI.backgroundColor = ConfigurationManager._widgetBackgroundColor.Value;
			if (GUILayout.Button(ConfigurationManager._clearText.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
			{
				SearchString = string.Empty;
			}
			GUI.backgroundColor = backgroundColor;
			GUILayout.EndHorizontal();
		}

		private void DrawContentButtons()
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			bool flag = !Utility.IsNullOrWhiteSpace(_activeFile);
			try
			{
				GUI.enabled = flag && _fileContent != File.ReadAllText(_activeFile);
				if (GUILayout.Button(ConfigurationManager._saveFileTextEditor.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
				{
					File.WriteAllText(_activeFile, _fileContent);
				}
			}
			catch (Exception ex)
			{
				_errorText = ex.Message;
			}
			finally
			{
				GUI.enabled = true;
			}
			GUI.enabled = flag;
			if (GUILayout.Button(ConfigurationManager._validateJsonTextEditor.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
			{
				_errorText = IsValidJSON(_fileContent);
			}
			if (GUILayout.Button(ConfigurationManager._validateYamlTextEditor.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
			{
				_errorText = IsValidYAML(_fileContent);
			}
			GUI.enabled = true;
			GUILayout.Label(_errorText, ConfigurationManagerStyles.GetLabelStyle(isDefaultValue: false), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.Label(ConfigurationManager._richTextFontSize.Value, ConfigurationManagerStyles.GetLabelStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			if (int.TryParse(GUILayout.TextField(StringExtensionMethods.ToFastString(ConfigurationManager._textEditorFontSize.Value), ConfigurationManagerStyles.GetTextStyle((float)ConfigurationManager._textEditorFontSize.Value, (float)(int)((ConfigEntryBase)ConfigurationManager._textEditorFontSize).DefaultValue), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }), out var result))
			{
				ConfigurationManager._textEditorFontSize.Value = result;
			}
			ConfigurationManager._textEditorWordWrap.Value = GUILayout.Toggle(ConfigurationManager._textEditorWordWrap.Value, ConfigurationManager._wordWrapTextEditor.Value, ConfigurationManagerStyles.GetToggleStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			ConfigurationManager._textEditorRichText.Value = GUILayout.Toggle(ConfigurationManager._textEditorRichText.Value, ConfigurationManager._richTextTextEditor.Value, ConfigurationManagerStyles.GetToggleStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			if (GUILayout.Button(ConfigurationManager._closeText.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
			{
				IsOpen = false;
			}
			GUILayout.EndHorizontal();
		}

		private void DrawWindow(int windowID)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: 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_01bc: 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_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			Color backgroundColor = GUI.backgroundColor;
			GUI.backgroundColor = ConfigurationManager._entryBackgroundColor.Value;
			GUILayout.BeginVertical(ConfigurationManagerStyles.GetBackgroundStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxWidth(GetFileListWidth()) });
			DrawFilters();
			DrawSearchBox();
			_scrollPosition = GUILayout.BeginScrollView(_scrollPosition, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(((Rect)(ref _windowRect)).width * 0.3f) });
			_directoryDepth = 0;
			DrawDirectories(_directories);
			GUILayout.EndScrollView();
			DrawDirectoriesMenu();
			GUILayout.EndVertical();
			GUILayout.BeginVertical(ConfigurationManagerStyles.GetBackgroundStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxWidth(((Rect)(ref _windowRect)).width * 0.7f) });
			DrawContentButtons();
			_textScrollPosition = GUILayout.BeginScrollView(_textScrollPosition, Array.Empty<GUILayoutOption>());
			GUI.enabled = File.Exists(_activeFile);
			GUI.SetNextControlName("textEditorTextField");
			_fileContent = GUILayout.TextArea(_fileContent, ConfigurationManagerStyles.GetFileEditorTextArea(), (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.ExpandHeight(true),
				GUILayout.ExpandWidth(true)
			});
			if (_focusTextArea || GUI.GetNameOfFocusedControl() == "textEditorTextField")
			{
				GUI.FocusWindow(-680);
				GUI.FocusControl("textEditorTextField");
				_focusTextArea = false;
			}
			GUI.enabled = true;
			GUILayout.EndScrollView();
			if (ConfigurationManager._showFullName.Value)
			{
				GUILayout.TextField(_activeFile, ConfigurationManagerStyles.GetTextStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			}
			GUILayout.EndVertical();
			GUI.backgroundColor = backgroundColor;
			GUILayout.EndHorizontal();
			GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref _windowRect)).width, 20f));
			if (!SettingFieldDrawer.DrawCurrentDropdown())
			{
				ConfigurationManager.DrawTooltip(_windowRect);
			}
			_windowRect = Utils.ResizeWindow(windowID, _windowRect, out var sizeChanged);
			if (sizeChanged)
			{
				SaveCurrentSizeAndPosition();
			}
		}

		private float GetFileListWidth()
		{
			return ((Rect)(ref _windowRect)).width * 0.3f;
		}

		private void DrawDirectory(string path)
		{
			_directoryDepth++;
			DrawDirectories(GetDirectories(path));
			if (path == _activeDirectory && _fileNameState == FileEditState.CreatingFolder)
			{
				DrawFileNameField();
			}
			DrawFiles(path);
			_directoryDepth--;
		}

		private void DrawDirectories(IEnumerable<string> directories)
		{
			foreach (string directory in directories)
			{
				if ((ConfigurationManager._showTrashBin.Value || !(directory == _trashBinDirectory)) && (ConfigurationManager._showEmptyFolders.Value || DirectoryContainsValidFiles(directory)))
				{
					if (!_folderStates.ContainsKey(directory))
					{
						_folderStates[directory] = false;
					}
					bool num = _folderStates[directory];
					bool flag = (_folderStates[directory] = GUILayout.Toggle(_folderStates[directory], Path.GetFileName(directory), ConfigurationManagerStyles.GetDirectoryStyle(directory == _activeDirectory), Array.Empty<GUILayoutOption>()));
					if (num != flag && _folderStates[directory])
					{
						_activeDirectory = directory;
						SetFileEditState(FileEditState.None);
					}
					if (_folderStates[directory])
					{
						GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
						GUILayout.Space(20f);
						GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
						DrawDirectory(directory);
						GUILayout.EndVertical();
						GUILayout.EndHorizontal();
					}
				}
			}
		}

		private void DrawFileNameField()
		{
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxWidth(GetFileListWidth() - (float)(20 * (_directoryDepth + 1)) - 5f) });
			if (_fileNameState == FileEditState.CreatingFolder || _fileNameState == FileEditState.CreatingFile)
			{
				GUILayout.Label((_fileNameState == FileEditState.CreatingFolder) ? ConfigurationManager._newFolderLabelTextEditor.Value : ConfigurationManager._newFileLabelTextEditor.Value, ConfigurationManagerStyles.GetLabelStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			}
			_newItemName = GUILayout.TextField(_newItemName, ConfigurationManagerStyles.GetFileNameFieldStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			if (GUILayout.Button(ConfigurationManager._newEntryOKButtonTextEditor.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
			{
				if (_fileNameState == FileEditState.CreatingFolder || _fileNameState == FileEditState.CreatingFile)
				{
					CreateNewItem(_newItemName, _fileNameState == FileEditState.CreatingFolder);
				}
				else if (_fileNameState == FileEditState.RenamingFile)
				{
					RenameActiveFile();
				}
			}
			GUILayout.EndHorizontal();
			if (!Utility.IsNullOrWhiteSpace(_newItemErrorText))
			{
				GUILayout.Label(_newItemErrorText, ConfigurationManagerStyles.GetFileNameErrorStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			}
			GUILayout.EndVertical();
		}

		private void RenameActiveFile()
		{
			if (_newItemName == Path.GetFileName(_activeFile))
			{
				SetFileEditState(FileEditState.None);
				return;
			}
			string directoryName = Path.GetDirectoryName(_activeFile);
			if (directoryName == null)
			{
				return;
			}
			string text = Path.Combine(directoryName, _newItemName);
			if (File.Exists(text))
			{
				_newItemErrorText = ConfigurationManager._fileExistsTextEditor.Value;
				return;
			}
			try
			{
				File.Move(_activeFile, text);
				_activeFile = text;
				SetFileEditState(FileEditState.None);
			}
			catch (Exception ex)
			{
				_newItemErrorText = ex.Message;
			}
		}

		private void MoveActiveFileToTrash()
		{
			if (Utility.IsNullOrWhiteSpace(_activeFile))
			{
				return;
			}
			Directory.CreateDirectory(_trashBinDirectory);
			string text = Path.Combine(_trashBinDirectory, Path.GetFileName(_activeFile));
			if (File.Exists(text))
			{
				text = Path.Combine(_trashBinDirectory, $"{Path.GetFileNameWithoutExtension(text)}_{DateTime.Now:yyyyMMdd_HHmmss}{Path.GetExtension(text)}");
			}
			try
			{
				if (_activeFile != null)
				{
					File.Move(_activeFile, text);
				}
				_activeFile = string.Empty;
				_fileContent = string.Empty;
				SetFileEditState(FileEditState.None);
			}
			catch (Exception ex)
			{
				_newItemErrorText = ex.Message;
			}
		}

		public ConfigFilesEditor()
		{
			//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_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)
			InitializeFileWatcher();
		}

		private void InitializeFileWatcher()
		{
			_watchers = new FileSystemWatcher[2]
			{
				new FileSystemWatcher(Paths.ConfigPath),
				new FileSystemWatcher(Paths.PluginPath)
			};
			FileSystemWatcher[] watchers = _watchers;
			foreach (FileSystemWatcher fileSystemWatcher in watchers)
			{
				fileSystemWatcher.IncludeSubdirectories = true;
				fileSystemWatcher.Changed += delegate
				{
					ClearCache();
				};
				fileSystemWatcher.Created += delegate
				{
					ClearCache();
				};
				fileSystemWatcher.Deleted += delegate
				{
					ClearCache();
				};
				fileSystemWatcher.Renamed += delegate
				{
					ClearCache();
				};
			}
		}

		private void ClearCache()
		{
			_clearCache = true;
			FileSystemWatcher[] watchers = _watchers;
			foreach (FileSystemWatcher fileSystemWatcher in watchers)
			{
				fileSystemWatcher.EnableRaisingEvents = IsOpen;
			}
		}

		private string[] GetFiles(string path)
		{
			if (_clearCache)
			{
				_cachedFileTree.Clear();
				_cachedDirectories.Clear();
			}
			_clearCache = false;
			if (_cachedFileTree.TryGetValue(path, out var value))
			{
				return value;
			}
			string[] array = (Directory.Exists(path) ? Directory.GetFiles(path) : Array.Empty<string>());
			_cachedFileTree[path] = array;
			return array;
		}

		private string[] GetDirectories(string path)
		{
			if (_clearCache)
			{
				_cachedFileTree.Clear();
				_cachedDirectories.Clear();
			}
			_clearCache = false;
			if (_cachedDirectories.TryGetValue(path, out var value))
			{
				return value;
			}
			string[] array = (Directory.Exists(path) ? Directory.GetDirectories(path) : Array.Empty<string>());
			_cachedDirectories[path] = array;
			return array;
		}

		private void DrawFiles(string path)
		{
			bool flag = false;
			string[] files = GetFiles(path);
			foreach (string text in files)
			{
				if (IsValidFile(text))
				{
					if (text == _activeFile && _fileNameState == FileEditState.RenamingFile)
					{
						DrawFileNameField();
					}
					else if (GUILayout.Button(Path.GetFileName(text), ConfigurationManagerStyles.GetFileStyle(text == _activeFile), Array.Empty<GUILayoutOption>()))
					{
						LoadFileToEditor(text);
					}
					if (path == _activeDirectory && text == _activeFile && _fileNameState == FileEditState.CreatingFile)
					{
						DrawFileNameField();
						flag = true;
					}
				}
			}
			if (!flag && path == _activeDirectory && _fileNameState == FileEditState.CreatingFile)
			{
				DrawFileNameField();
			}
		}

		private bool IsValidFile(string file)
		{
			string fileName = Path.GetFileName(file);
			if (fileName == "manifest.json")
			{
				return false;
			}
			if (ConfigurationManager._hideModConfigs.Value && Chainloader.PluginInfos.Values.Any((PluginInfo plugin) => plugin.Instance.Config.ConfigFilePath == file))
			{
				return false;
			}
			string extension = Path.GetExtension(file).ToLower();
			if (ConfigurationManager._editableExtensions.Value.Split(',').Select(GetNormalizedExtension).Any((string validExtension) => extension == validExtension))
			{
				return Utility.IsNullOrWhiteSpace(SearchString) || fileName.IndexOf(SearchString, StringComparison.OrdinalIgnoreCase) > -1;
			}
			return false;
		}

		private static string GetNormalizedExtension(string extension)
		{
			if (Utility.IsNullOrWhiteSpace(extension))
			{
				return string.Empty;
			}
			string text = extension.Trim().ToLower();
			return text.StartsWith(".") ? text : ("." + text);
		}

		private bool DirectoryContainsValidFiles(string path)
		{
			return GetFiles(path).Any(IsValidFile) || GetDirectories(path).Any(DirectoryContainsValidFiles);
		}

		private void LoadFileToEditor(string filePath)
		{
			try
			{
				_fileContent = File.ReadAllText(filePath);
				_activeFile = filePath;
				_activeDirectory = Path.GetDirectoryName(filePath);
				_errorText = string.Empty;
				SetFileEditState(FileEditState.None);
				_focusTextArea = true;
			}
			catch (IOException ex)
			{
				ConfigurationManager.LogError("Failed to load file " + filePath + ": " + ex.Message);
				_errorText = "Failed to load file";
				_fileContent = ex.Message;
			}
		}

		private void DrawDirectoriesMenu()
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button(ConfigurationManager._newFolderButtonTextEditor.Value, ConfigurationManagerStyles.GetButtonStyle(), Array.Empty<GUILayoutOption>()))
			{
				SetFileEditState(FileEditState.CreatingFolder);
			}
			if (GUILayout.Button(ConfigurationManager._newFileButtonTextEditor.Value, ConfigurationManagerStyles.GetButtonStyle(), Array.Empty<GUILayoutOption>()))
			{
				SetFileEditState(FileEditState.CreatingFile);
			}
			if (GUILayout.Button(ConfigurationManager._renameFileButtonTextEditor.Value, ConfigurationManagerStyles.GetButtonStyle(), Array.Empty<GUILayoutOption>()))
			{
				SetFileEditState(FileEditState.RenamingFile);
				_newItemName = Path.GetFileName(_activeFile);
			}
			if (GUILayout.Button(new GUIContent(ConfigurationManager._deleteFileButtonTextEditor.Value, ConfigurationManager._deleteFileTooltipTextEditor.Value), ConfigurationManagerStyles.GetButtonStyle(), Array.Empty<GUILayoutOption>()))
			{
				MoveActiveFileToTrash();
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			ConfigurationManager._showEmptyFolders.Value = GUILayout.Toggle(ConfigurationManager._showEmptyFolders.Value, ConfigurationManager._showEmptyTextEditor.Value, ConfigurationManagerStyles.GetToggleStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.FlexibleSpace();
			ConfigurationManager._showFullName.Value = GUILayout.Toggle(ConfigurationManager._showFullName.Value, new GUIContent(ConfigurationManager._showFullNameTextEditor.Value, ConfigurationManager._showFullNameTooltipTextEditor.Value), ConfigurationManagerStyles.GetToggleStyle(), Array.Empty<GUILayoutOption>());
			ConfigurationManager._showTrashBin.Value = GUILayout.Toggle(ConfigurationManager._showTrashBin.Value, ConfigurationManager._showTrashBinTextEditor.Value, ConfigurationManagerStyles.GetToggleStyle(), Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
		}

		private void CreateNewItem(string itemName, bool isFolder)
		{
			if (string.IsNullOrWhiteSpace(itemName) || string.IsNullOrEmpty(_activeDirectory))
			{
				return;
			}
			string text = Path.Combine(_activeDirectory, itemName);
			try
			{
				if (isFolder)
				{
					Directory.CreateDirectory(text);
					ConfigurationManager._showEmptyFolders.Value = true;
					_activeDirectory = text;
					_activeFile = string.Empty;
				}
				else
				{
					File.Create(text).Close();
					LoadFileToEditor(text);
				}
				SetFileEditState(FileEditState.None);
			}
			catch (Exception ex)
			{
				_newItemErrorText = ex.Message;
			}
		}

		public string IsValidJSON(string text)
		{
			if (Utility.IsNullOrWhiteSpace(text))
			{
				return string.Empty;
			}
			try
			{
				JToken.Parse(text);
				return ConfigurationManager._fileIsValidJsonTextEditor.Value;
			}
			catch
			{
				return ConfigurationManager._fileIsNotValidJsonTextEditor.Value;
			}
		}

		public string IsValidYAML(string text)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			if (Utility.IsNullOrWhiteSpace(text))
			{
				return string.Empty;
			}
			try
			{
				IDeserializer val = ((BuilderSkeleton<DeserializerBuilder>)new DeserializerBuilder()).WithNamingConvention(CamelCaseNamingConvention.Instance).Build();
				val.Deserialize<object>(text);
				return ConfigurationManager._fileIsValidYamlTextEditor.Value;
			}
			catch
			{
				return ConfigurationManager._fileIsNotValidYamlTextEditor.Value;
			}
		}
	}
	internal sealed class ConfigSettingEntry : SettingEntryBase
	{
		private sealed class DynamicAttributeSource
		{
			private readonly object source;

			private readonly PropertyInfo readOnlyProperty;

			private readonly FieldInfo readOnlyField;

			private readonly PropertyInfo browsableProperty;

			private readonly FieldInfo browsableField;

			internal Type SourceType { get; }

			internal DynamicAttributeSource(object source, Type sourceType, PropertyInfo readOnlyProperty, FieldInfo readOnlyField, PropertyInfo browsableProperty, FieldInfo browsableField)
			{
				this.source = source;
				SourceType = sourceType;
				this.readOnlyProperty = readOnlyProperty;
				this.readOnlyField = readOnlyField;
				this.browsableProperty = browsableProperty;
				this.browsableField = browsableField;
			}

			internal bool TryGetReadOnly(out bool value)
			{
				return TryGetBoolean(readOnlyProperty, readOnlyField, out value);
			}

			internal bool TryGetBrowsable(out bool value)
			{
				return TryGetBoolean(browsableProperty, browsableField, out value);
			}

			private bool TryGetBoolean(PropertyInfo property, FieldInfo field, out bool value)
			{
				if (((property != null) ? property.GetValue(source, null) : field?.GetValue(source)) is bool flag)
				{
					value = flag;
					return true;
				}
				value = false;
				return false;
			}
		}

		private readonly ConfigSynchronizationInfo synchronizationInfo;

		private readonly List<DynamicAttributeSource> dynamicAttributeSources = new List<DynamicAttributeSource>();

		public ConfigEntryBase Entry { get; }

		public override Type SettingType => Entry.SettingType;

		public ConfigSettingEntry(ConfigEntryBase entry, BaseUnityPlugin owner)
		{
			Entry = entry;
			DispName = entry.Definition.Key;
			base.Category = entry.Definition.Section;
			ConfigDescription description = entry.Description;
			base.Description = ((description != null) ? description.Description : null);
			TypeConverter converter = TomlTypeConverter.GetConverter(entry.SettingType);
			if (converter != null)
			{
				base.ObjToStr = (object o) => converter.ConvertToString(o, entry.SettingType);
				base.StrToObj = (string s) => converter.ConvertToObject(s, entry.SettingType);
			}
			ConfigDescription description2 = entry.Description;
			AcceptableValueBase val = ((description2 != null) ? description2.AcceptableValues : null);
			if (val != null)
			{
				GetAcceptableValues(val);
			}
			base.DefaultValue = entry.DefaultValue;
			ConfigDescription description3 = entry.Description;
			SetFromAttributes((description3 != null) ? description3.Tags : null, owner);
			ConfigDescription description4 = entry.Description;
			InitializeDynamicAttributeSources((description4 != null) ? description4.Tags : null);
			synchronizationInfo = ConfigSynchronizationInfo.Create(entry);
		}

		private void GetAcceptableValues(AcceptableValueBase values)
		{
			Type type = ((object)values).GetType();
			PropertyInfo property = type.GetProperty("AcceptableValues", BindingFlags.Instance | BindingFlags.Public);
			if (property != null)
			{
				base.AcceptableValues = ((IEnumerable)property.GetValue(values, null)).Cast<object>().ToArray();
				return;
			}
			PropertyInfo property2 = type.GetProperty("MinValue", BindingFlags.Instance | BindingFlags.Public);
			PropertyInfo property3 = type.GetProperty("MaxValue", BindingFlags.Instance | BindingFlags.Public);
			if (property2 != null && property3 != null)
			{
				base.AcceptableValueRange = new KeyValuePair<object, object>(property2.GetValue(values, null), property3.GetValue(values, null));
			}
		}

		private void InitializeDynamicAttributeSources(object[] tags)
		{
			if (tags == null)
			{
				return;
			}
			foreach (object obj in tags)
			{
				if (obj == null)
				{
					continue;
				}
				Type type = obj.GetType();
				if (!(type.Name != "ConfigurationManagerAttributes"))
				{
					PropertyInfo property = type.GetProperty("ReadOnly", BindingFlags.Instance | BindingFlags.Public);
					FieldInfo field = type.GetField("ReadOnly", BindingFlags.Instance | BindingFlags.Public);
					PropertyInfo property2 = type.GetProperty("Browsable", BindingFlags.Instance | BindingFlags.Public);
					FieldInfo field2 = type.GetField("Browsable", BindingFlags.Instance | BindingFlags.Public);
					if (property != null || field != null || property2 != null || field2 != null)
					{
						dynamicAttributeSources.Add(new DynamicAttributeSource(obj, type, property, field, property2, field2));
					}
				}
			}
		}

		internal override bool RefreshDynamicAttributes()
		{
			bool? readOnly = base.ReadOnly;
			bool? browsable = base.Browsable;
			foreach (DynamicAttributeSource dynamicAttributeSource in dynamicAttributeSources)
			{
				try
				{
					if (dynamicAttributeSource.TryGetReadOnly(out var value))
					{
						base.ReadOnly = value;
					}
					if (dynamicAttributeSource.TryGetBrowsable(out var value2))
					{
						base.Browsable = value2;
					}
				}
				catch (Exception ex)
				{
					ConfigurationManager.LogInfo("Failed to refresh dynamic attributes from " + dynamicAttributeSource.SourceType.FullName + " - " + ex.Message);
				}
			}
			return readOnly != base.ReadOnly || browsable != base.Browsable;
		}

		public override object Get()
		{
			return Entry.BoxedValue;
		}

		protected override void SetValue(object newVal)
		{
			Entry.BoxedValue = newVal;
		}

		internal ConfigSynchronizationState GetSynchronizationState()
		{
			return synchronizationInfo.GetState();
		}

		internal bool ToggleSynchronizationPolicy()
		{
			return synchronizationInfo.TogglePolicy();
		}

		internal bool ShouldBeHidden()
		{
			return ConfigurationManager.hiddenSettings.Value.Contains(base.PluginInfo.GUID + "=" + Entry.Definition.Section + "=" + Entry.Definition.Key);
		}
	}
	internal enum ConfigSynchronizationProvider
	{
		None,
		Jotunn,
		ServerSync,
		ConditionalConfigSync
	}
	internal readonly struct ConfigSynchronizationState
	{
		internal static readonly ConfigSynchronizationState None = new ConfigSynchronizationState(ConfigSynchronizationProvider.None, isServerControlled: false, isConditional: false, isOverridden: false, canChangePolicy: false, string.Empty);

		internal ConfigSynchronizationProvider Provider { get; }

		internal bool IsServerControlled { get; }

		internal bool IsConditional { get; }

		internal bool IsOverridden { get; }

		internal bool CanChangePolicy { get; }

		internal string Tooltip { get; }

		internal bool IsVisible => IsConditional || IsServerControlled || IsOverridden;

		internal ConfigSynchronizationState(ConfigSynchronizationProvider provider, bool isServerControlled, bool isConditional, bool isOverridden, bool canChangePolicy, string tooltip)
		{
			Provider = provider;
			IsServerControlled = isServerControlled;
			IsConditional = isConditional;
			IsOverridden = isOverridden;
			CanChangePolicy = canChangePolicy;
			Tooltip = tooltip;
		}
	}
	internal abstract class ConfigSynchronizationInfo
	{
		private sealed class NoSynchronizationInfo : ConfigSynchronizationInfo
		{
			internal override ConfigSynchronizationState GetState()
			{
				return ConfigSynchronizationState.None;
			}
		}

		private sealed class ConditionalConfigSynchronizationInfo : ConfigSynchronizationInfo
		{
			private readonly OwnConfigEntryBase entry;

			private ConfigSyncMode lastMode;

			private bool lastDefaultServerControlled;

			private bool lastServerControlled;

			private bool lastOverridden;

			private ConfigSyncPolicyControlState lastPolicyControlState;

			private bool hasCachedState;

			private ConfigSynchronizationState cachedState;

			internal ConditionalConfigSynchronizationInfo(OwnConfigEntryBase entry)
			{
				this.entry = entry;
			}

			internal override ConfigSynchronizationState GetState()
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Invalid comparison between Unknown and I4
				//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_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Invalid comparison between Unknown and I4
				//IL_0051: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01be: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01db: 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_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0124: Unknown result type (might be due to invalid IL or missing references)
				//IL_0126: Unknown result type (might be due to invalid IL or missing references)
				//IL_0128: Unknown result type (might be due to invalid IL or missing references)
				//IL_012a: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_012f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0141: Expected I4, but got Unknown
				bool flag = (int)entry.SyncMode == 1;
				bool isSynchronizationOverridden = entry.IsSynchronizationOverridden;
				bool isServerControlled = entry.IsServerControlled;
				bool serverControlledByDefault = entry.ServerControlledByDefault;
				ConfigSyncPolicyControlState synchronizationPolicyControlState = entry.SynchronizationPolicyControlState;
				bool canChangePolicy = (int)synchronizationPolicyControlState == 1;
				if (hasCachedState && lastMode == entry.SyncMode && lastDefaultServerControlled == serverControlledByDefault && lastServerControlled == isServerControlled && lastOverridden == isSynchronizationOverridden && lastPolicyControlState == synchronizationPolicyControlState)
				{
					return cachedState;
				}
				string text = FormatOwnership(isServerControlled) + " setting\nSynchronization provider: Conditional Config Sync\n" + $"Mode: {entry.SyncMode}";
				if (flag)
				{
					text = text + "\nMod default: " + FormatOwnership(serverControlledByDefault);
					text = ((!isSynchronizationOverridden) ? (text + "\nServer policy: No override; using mod default") : (text + $"\nServer policy override: {entry.EffectiveOverride}"));
					ConfigSyncPolicyControlState val = synchronizationPolicyControlState;
					ConfigSyncPolicyControlState val2 = val;
					text = (val2 - 1) switch
					{
						0 => text + "\nClick to switch policy to " + FormatOwnership(!isServerControlled), 
						2 => text + "\nPolicy control: Requires administrator access", 
						1 => text + "\nPolicy control: Requires a compatible active server session", 
						_ => text + "\nPolicy control: Fixed by the mod", 
					};
				}
				else
				{
					text += "\nPolicy control: Fixed by the mod";
				}
				cachedState = new ConfigSynchronizationState(ConfigSynchronizationProvider.ConditionalConfigSync, isServerControlled, flag, isSynchronizationOverridden, canChangePolicy, text);
				lastMode = entry.SyncMode;
				lastDefaultServerControlled = serverControlledByDefault;
				lastServerControlled = isServerControlled;
				lastOverridden = isSynchronizationOverridden;
				lastPolicyControlState = synchronizationPolicyControlState;
				hasCachedState = true;
				return cachedState;
			}

			internal override bool TogglePolicy()
			{
				return entry.ToggleSynchronizationPolicy();
			}
		}

		private sealed class ReflectedBooleanSynchronizationInfo : ConfigSynchronizationInfo
		{
			private readonly object source;

			private readonly FieldInfo field;

			private readonly PropertyInfo property;

			private readonly ConfigSynchronizationState serverControlledState;

			internal ReflectedBooleanSynchronizationInfo(ConfigSynchronizationProvider provider, object source, FieldInfo field, string providerName)
			{
				this.source = source;
				this.field = field;
				serverControlledState = CreateServerControlledState(provider, providerName);
			}

			internal ReflectedBooleanSynchronizationInfo(ConfigSynchronizationProvider provider, object source, PropertyInfo property, string providerName)
			{
				this.source = source;
				this.property = property;
				serverControlledState = CreateServerControlledState(provider, providerName);
			}

			internal override ConfigSynchronizationState GetState()
			{
				bool flag;
				try
				{
					flag = ((field != null) ? ((bool)field.GetValue(source)) : ((bool)property.GetValue(source)));
				}
				catch
				{
					return ConfigSynchronizationState.None;
				}
				if (!flag)
				{
					return ConfigSynchronizationState.None;
				}
				return serverControlledState;
			}

			private static ConfigSynchronizationState CreateServerControlledState(ConfigSynchronizationProvider provider, string providerName)
			{
				return new ConfigSynchronizationState(provider, isServerControlled: true, isConditional: false, isOverridden: false, canChangePolicy: false, "Server-controlled setting\nSynchronization provider: " + providerName + "\nPolicy control: Fixed by the synchronization provider");
			}
		}

		private const BindingFlags InstanceMembers = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		internal static readonly ConfigSynchronizationInfo None = new NoSynchronizationInfo();

		internal abstract ConfigSynchronizationState GetState();

		internal virtual bool TogglePolicy()
		{
			return false;
		}

		internal static ConfigSynchronizationInfo Create(ConfigEntryBase entry)
		{
			ConfigDescription description = entry.Description;
			object[] array = ((description != null) ? description.Tags : null);
			if (array == null || array.Length == 0)
			{
				return None;
			}
			OwnConfigEntryBase val = array.OfType<OwnConfigEntryBase>().FirstOrDefault((Func<OwnConfigEntryBase, bool>)((OwnConfigEntryBase tag) => tag.BaseConfig == entry));
			if (val != null)
			{
				return new ConditionalConfigSynchronizationInfo(val);
			}
			object[] array2 = array;
			foreach (object obj in array2)
			{
				if (obj != null && TryCreateServerSyncInfo(entry, obj, out var info))
				{
					return info;
				}
			}
			object[] array3 = array;
			foreach (object obj2 in array3)
			{
				if (obj2 != null && TryCreateJotunnInfo(obj2, out var info2))
				{
					return info2;
				}
			}
			return None;
		}

		private static bool TryCreateServerSyncInfo(ConfigEntryBase entry, object tag, out ConfigSynchronizationInfo info)
		{
			info = null;
			Type type = tag.GetType();
			if (!HasBaseType(type, "ServerSync.OwnConfigEntryBase"))
			{
				return false;
			}
			PropertyInfo property = type.GetProperty("BaseConfig", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			FieldInfo field = type.GetField("SynchronizedConfig", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property == null || field?.FieldType != typeof(bool))
			{
				return false;
			}
			try
			{
				if (property.GetValue(tag) != entry)
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			info = new ReflectedBooleanSynchronizationInfo(ConfigSynchronizationProvider.ServerSync, tag, field, "ServerSync");
			return true;
		}

		private static bool TryCreateJotunnInfo(object tag, out ConfigSynchronizationInfo info)
		{
			info = null;
			Type type = tag.GetType();
			if (!string.Equals(type.Assembly.GetName().Name, "Jotunn", StringComparison.Ordinal) || !string.Equals(type.Name, "ConfigurationManagerAttributes", StringComparison.Ordinal))
			{
				return false;
			}
			PropertyInfo property = type.GetProperty("IsAdminOnly", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property?.PropertyType != typeof(bool))
			{
				return false;
			}
			info = new ReflectedBooleanSynchronizationInfo(ConfigSynchronizationProvider.Jotunn, tag, property, "Jotunn");
			return true;
		}

		private static bool HasBaseType(Type type, string fullName)
		{
			Type type2 = type;
			while (type2 != null)
			{
				if (string.Equals(type2.FullName, fullName, StringComparison.Ordinal))
				{
					return true;
				}
				type2 = type2.BaseType;
			}
			return false;
		}

		private static string FormatOwnership(bool isServerControlled)
		{
			return isServerControlled ? "Server-controlled" : "Client-controlled";
		}
	}
	internal class SettingEditWindow
	{
		private sealed class ColorCacheEntry
		{
			public Color Last;

			public Texture2D Tex;
		}

		private Rect _windowRect = new Rect(ConfigurationManager._windowPositionEditSetting.Value, ConfigurationManager._windowSizeEditSetting.Value);

		private const int WindowId = -6800;

		private const string NewItemFieldControlName = "StringListNewItemField";

		private SettingEntryBase setting;

		private static SettingEntryBase _currentKeyboardShortcutToSet;

		private static IEnumerable<KeyCode> _keysToCheck;

		private static readonly Dictionary<SettingEntryBase, ColorCacheEntry> ColorCache = new Dictionary<SettingEntryBase, ColorCacheEntry>();

		private Vector2 _scrollPosition = Vector2.zero;

		private Vector2 _scrollPositionEnum = Vector2.zero;

		private int listIndex = -1;

		private IList listEnum = null;

		private Action drawerFunction;

		private string errorText;

		private object valueToSet;

		private string errorOnSetting;

		private readonly List<string> vectorParts = new List<string>();

		private readonly List<float> vectorFloats = new List<float>();

		private readonly List<float> vectorDefault = new List<float>();

		private string colorAsHEX;

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

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

		private string separator;

		private int editStringView;

		private string newItem;

		private ConfigEntryBase dummyCustomDrawerConfigEntry;

		private static readonly Dictionary<Type, string> typeMappings = new Dictionary<Type, string>
		{
			{
				typeof(int),
				"Integer"
			},
			{
				typeof(float),
				"Float"
			},
			{
				typeof(double),
				"Double"
			},
			{
				typeof(decimal),
				"Decimal"
			},
			{
				typeof(bool),
				"Boolean"
			},
			{
				typeof(string),
				"String"
			},
			{
				typeof(long),
				"Long"
			},
			{
				typeof(short),
				"Short"
			},
			{
				typeof(byte),
				"Byte"
			},
			{
				typeof(sbyte),
				"Signed Byte"
			},
			{
				typeof(uint),
				"Unsigned Integer"
			},
			{
				typeof(ulong),
				"Unsigned Long"
			},
			{
				typeof(ushort),
				"Unsigned Short"
			},
			{
				typeof(char),
				"Character"
			},
			{
				typeof(DateTime),
				"DateTime"
			},
			{
				typeof(TimeSpan),
				"TimeSpan"
			},
			{
				typeof(Guid),
				"GUID"
			},
			{
				typeof(KeyValuePair<, >),
				"Map<Key, Value>"
			},
			{
				typeof(object),
				"Object"
			}
		};

		private readonly Dictionary<Type, bool> _canCovertCache = new Dictionary<Type, bool>();

		public Dictionary<Type, Action> SettingDrawHandlers { get; }

		private bool IsStringList => setting != null && setting.SettingType != null && typeof(IList<string>).IsAssignableFrom(setting.SettingType);

		public bool IsOpen { get; set; }

		public SettingEditWindow()
		{
			//IL_0006: 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_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_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_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)
			SettingDrawHandlers = new Dictionary<Type, Action>
			{
				{
					typeof(bool),
					DrawBoolField
				},
				{
					typeof(KeyboardShortcut),
					DrawKeyboardShortcut
				},
				{
					typeof(KeyCode),
					DrawKeyCode
				},
				{
					typeof(Color),
					DrawColor
				},
				{
					typeof(Vector2),
					DrawVector
				},
				{
					typeof(Vector3),
					DrawVector
				},
				{
					typeof(Vector4),
					DrawVector
				},
				{
					typeof(Quaternion),
					DrawVector
				}
			};
		}

		public void EditSetting(SettingEntryBase setting)
		{
			if (this.setting == setting && IsOpen)
			{
				IsOpen = false;
				return;
			}
			this.setting = setting;
			InitializeWindow();
			IsOpen = true;
		}

		public void OnGUI()
		{
			//IL_0095: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: 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)
			if (!IsOpen)
			{
				return;
			}
			setting.RefreshDynamicAttributes();
			if (setting.Browsable == false)
			{
				IsOpen = false;
				return;
			}
			if (setting.ReadOnly == true)
			{
				valueToSet = setting.Get();
				errorOnSetting = string.Empty;
			}
			((Rect)(ref _windowRect)).size = ConfigurationManager._windowSizeEditSetting.Value;
			((Rect)(ref _windowRect)).position = ConfigurationManager._windowPositionEditSetting.Value;
			Color backgroundColor = GUI.backgroundColor;
			GUI.backgroundColor = ConfigurationManager._windowBackgroundColor.Value;
			_windowRect = GUI.Window(-6800, _windowRect, new WindowFunction(DrawWindow), $"{setting.PluginInfo.Name} {setting.PluginInfo.Version}", ConfigurationManagerStyles.GetWindowStyle());
			if (!UnityInput.Current.GetKeyDown((KeyCode)323) && ((Rect)(ref _windowRect)).position != ConfigurationManager._windowPositionEditSetting.Value)
			{
				SaveCurrentSizeAndPosition();
			}
			GUI.backgroundColor = backgroundColor;
		}

		private void UpdateStringList()
		{
			if (Utility.IsNullOrWhiteSpace(separator))
			{
				separator = ",";
			}
			if (setting.SettingType != typeof(string) && !IsStringList)
			{
				return;
			}
			separatedString.Clear();
			if (IsStringList)
			{
				try
				{
					separatedString.AddRange(valueToSet as IList<string>);
				}
				catch
				{
					separatedString.AddRange(valueToSet.ToString().Split(new string[1] { separator }, StringSplitOptions.None));
				}
			}
			else
			{
				separatedString.AddRange(valueToSet.ToString().Split(new string[1] { separator }, StringSplitOptions.None));
			}
			separatedStringDefault.Clear();
			if (setting.DefaultValue == null)
			{
				return;
			}
			if (IsStringList)
			{
				try
				{
					separatedStringDefault.AddRange((setting.DefaultValue as IList<string>).Select((string s) => s.Trim()));
					return;
				}
				catch
				{
					separatedStringDefault.AddRange(from s in setting.DefaultValue.ToString().Split(new string[1] { separator }, StringSplitOptions.None)
						select s.Trim());
					return;
				}
			}
			separatedStringDefault.AddRange(from s in setting.DefaultValue.ToString().Split(new string[1] { separator }, StringSplitOptions.None)
				select s.Trim());
		}

		private void InitializeWindow()
		{
			//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_00a4: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Expected O, but got Unknown
			listEnum = null;
			listIndex = -1;
			drawerFunction = null;
			valueToSet = ((setting.SettingType == typeof(Color)) ? ((object)Utils.RoundColorToHEX((Color)setting.Get())) : setting.Get());
			errorText = string.Empty;
			errorOnSetting = string.Empty;
			colorAsHEX = ((setting.SettingType == typeof(Color)) ? ("#" + ColorUtility.ToHtmlStringRGBA((Color)valueToSet)) : string.Empty);
			separator = ",";
			separatedString.Clear();
			newItem = string.Empty;
			editStringView = 0;
			_scrollPosition = Vector2.zero;
			_scrollPositionEnum = Vector2.zero;
			dummyCustomDrawerConfigEntry = null;
			if (setting is ConfigSettingEntry configSettingEntry && (setting.CustomDrawer != null || setting.CustomHotkeyDrawer != null))
			{
				Type type = typeof(ConfigEntry<>).MakeGenericType(configSettingEntry.Entry.SettingType);
				ConstructorInfo constructorInfo = AccessTools.Constructor(type, new Type[4]
				{
					typeof(ConfigFile),
					typeof(ConfigDefinition),
					configSettingEntry.Entry.SettingType,
					typeof(ConfigDescription)
				}, false);
				dummyCustomDrawerConfigEntry = (ConfigEntryBase)constructorInfo.Invoke(new object[4]
				{
					configSettingEntry.Entry.ConfigFile,
					configSettingEntry.Entry.Definition,
					configSettingEntry.Entry.DefaultValue,
					configSettingEntry.Entry.Description
				});
				dummyCustomDrawerConfigEntry.BoxedValue = configSettingEntry.Entry.BoxedValue;
			}
			if (setting.AcceptableValueRange.Key != null)
			{
				drawerFunction = DrawRangeField;
			}
			else if (setting.AcceptableValues != null && setting.AcceptableValues.Length != 0 && setting.SettingType.IsInstanceOfType(setting.AcceptableValues.FirstOrDefault((object x) => x != null)))
			{
				SetAcceptableValuesDrawer();
			}
			else if (setting.SettingType.IsEnum && setting.SettingType != typeof(KeyCode))
			{
				listEnum = Enum.GetValues(setting.SettingType);
				if (setting.SettingType.GetCustomAttributes(typeof(FlagsAttribute), inherit: false).Any())
				{
					drawerFunction = DrawFlagsField;
				}
				else
				{
					drawerFunction = DrawEnumListField;
				}
			}
			else
			{
				SettingDrawHandlers.TryGetValue(setting.SettingType, out drawerFunction);
			}
			InitListIndex();
			InitVectorParts();
			UpdateStringList();
		}

		private void InitListIndex()
		{
			listIndex = ((listEnum == null) ? (-1) : listEnum.IndexOf(valueToSet));
		}

		private void InitVectorParts()
		{
			//IL_0050: 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_00a8: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: 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)
			vectorParts.Clear();
			vectorFloats.Clear();
			vectorDefault.Clear();
			if (setting.SettingType == typeof(Vector2))
			{
				FillVectorList<Vector2>(vectorFloats, (Vector2)valueToSet);
				FillVectorList<Vector2>(vectorDefault, (Vector2)setting.DefaultValue);
			}
			else if (setting.SettingType == typeof(Vector3))
			{
				FillVectorList<Vector3>(vectorFloats, (Vector3)valueToSet);
				FillVectorList<Vector3>(vectorDefault, (Vector3)setting.DefaultValue);
			}
			else if (setting.SettingType == typeof(Vector4))
			{
				FillVectorList<Vector4>(vectorFloats, (Vector4)valueToSet);
				FillVectorList<Vector4>(vectorDefault, (Vector4)setting.DefaultValue);
			}
			else if (setting.SettingType == typeof(Quaternion))
			{
				FillVectorList<Quaternion>(vectorFloats, (Quaternion)valueToSet);
				FillVectorList<Quaternion>(vectorDefault, (Quaternion)setting.DefaultValue);
			}
			vectorParts.AddRange(vectorFloats.Select((float f) => f.ToString()));
		}

		private void SetAcceptableValuesDrawer()
		{
			if (setting.SettingType == typeof(KeyCode))
			{
				listEnum = ((setting.AcceptableValues.Length > 1) ? setting.AcceptableValues : Enum.GetValues(setting.SettingType));
				drawerFunction = DrawKeyCode;
			}
			else
			{
				listEnum = setting.AcceptableValues;
				drawerFunction = DrawEnumListField;
			}
		}

		internal void SaveCurrentSizeAndPosition()
		{
			//IL_000c: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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)
			ConfigurationManager._windowSizeEditSetting.Value = new Vector2(Mathf.Clamp(((Rect)(ref _windowRect)).size.x, 200f, ConfigurationManager.instance.ScreenWidth / 2f), Mathf.Clamp(((Rect)(ref _windowRect)).size.y, 200f, ConfigurationManager.instance.ScreenHeight * 0.9f));
			ConfigurationManager._windowPositionEditSetting.Value = new Vector2(Mathf.Clamp(((Rect)(ref _windowRect)).position.x, 0f, ConfigurationManager.instance.ScreenWidth - ConfigurationManager._windowSize.Value.x / 4f), Mathf.Clamp(((Rect)(ref _windowRect)).position.y, 0f, ConfigurationManager.instance.ScreenHeight - 40f));
			((BaseUnityPlugin)ConfigurationManager.instance).Config.Save();
		}

		private void DrawWindow(int windowID)
		{
			//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_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			Color backgroundColor = GUI.backgroundColor;
			GUI.backgroundColor = ConfigurationManager._entryBackgroundColor.Value;
			GUILayout.BeginVertical(ConfigurationManagerStyles.GetSettingWindowBackgroundStyle(), Array.Empty<GUILayoutOption>());
			GUILayout.Space(1f);
			GUILayout.Label("<b>" + setting.Category + "</b>", ConfigurationManagerStyles.GetLabelStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			DrawDelimiterLine();
			GUILayout.Space(1f);
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(false) });
			GUILayout.Label(setting.DispName + " ", ConfigurationManagerStyles.GetLabelStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUILayout.Label("(" + GetTypeRepresentation(setting.SettingType) + ")", ConfigurationManagerStyles.GetLabelStyleInfo(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.EndHorizontal();
			GUILayout.Label(setting.Description, ConfigurationManagerStyles.GetLabelStyle(isDefaultValue: false), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			if (setting.DefaultValue != null)
			{
				GUIStyle labelStyle = ConfigurationManagerStyles.GetLabelStyle();
				GUIContent val = new GUIContent(ConfigurationManager._defaultValueDescriptionEditWindow.Value);
				float num = labelStyle.CalcSize(val).x + 3f;
				GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(false) });
				GUILayout.Label(ConfigurationManager._defaultValueDescriptionEditWindow.Value, labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num) });
				GUILayout.Label(GetValueRepresentation(setting.DefaultValue, setting.SettingType) ?? "", ConfigurationManagerStyles.GetLabelStyleInfo(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
				GUILayout.EndHorizontal();
			}
			DrawDelimiterLine();
			GUILayout.Space(5f);
			bool enabled = GUI.enabled;
			GUI.enabled = enabled && setting.ReadOnly != true;
			DrawSettingValue();
			GUI.enabled = enabled;
			if (!Utility.IsNullOrWhiteSpace(errorOnSetting))
			{
				GUILayout.Label(errorOnSetting, ConfigurationManagerStyles.GetLabelStyle(), Array.Empty<GUILayoutOption>());
			}
			DrawDelimiterLine();
			GUILayout.Space(1f);
			DrawMenuButtons();
			GUILayout.EndVertical();
			GUI.backgroundColor = backgroundColor;
			GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref _windowRect)).width, 20f));
			if (!SettingFieldDrawer.DrawCurrentDropdown())
			{
				ConfigurationManager.DrawTooltip(_windowRect);
			}
			_windowRect = Utils.ResizeWindow(windowID, _windowRect, out var sizeChanged);
			if (sizeChanged)
			{
				SaveCurrentSizeAndPosition();
			}
		}

		private void DrawLabel(string label, string value)
		{
			bool flag = !Utility.IsNullOrWhiteSpace(label) && !Utility.IsNullOrWhiteSpace(value);
			if (flag)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			}
			if (!Utility.IsNullOrWhiteSpace(label))
			{
				GUILayout.Label(Utility.IsNullOrWhiteSpace(value) ? label : (label + ":"), ConfigurationManagerStyles.GetLabelStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			}
			if (!Utility.IsNullOrWhiteSpace(value))
			{
				GUILayout.Label(value, ConfigurationManagerStyles.GetLabelStyleInfo(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			}
			if (flag)
			{
				GUILayout.EndHorizontal();
			}
		}

		private void DrawInfo(string info)
		{
			DrawLabel(null, info);
		}

		private string GetTypeRepresentation(Type type)
		{
			string value;
			if (!type.IsGenericType)
			{
				return typeMappings.TryGetValue(type, out value) ? value : type.Name;
			}
			Type[] genericArguments = type.GetGenericArguments();
			string value2;
			string text = string.Join(", ", genericArguments.Select((Type t) => typeMappings.TryGetValue(t, out value2) ? value2 : t.Name));
			return ZDOHelper.GetValueOrDefaultPiktiv<Type, string>((IDictionary<Type, string>)typeMappings, type, type.Name) + "<" + text + ">";
		}

		private string GetValueRepresentation(object value, Type type)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (type == typeof(Color))
			{
				return "#" + ColorUtility.ToHtmlStringRGBA((Color)value);
			}
			if (type == typeof(bool))
			{
				return ((bool)value) ? ConfigurationManager._enabledText.Value : ConfigurationManager._disabledText.Value;
			}
			return value.ToString();
		}

		private void DrawMenuButtons()
		{
			setting.RefreshDynamicAttributes();
			bool valueOrDefault = setting.ReadOnly == true;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			bool enabled = GUI.enabled;
			GUI.enabled = enabled && !valueOrDefault && !IsValueToSetDefaultValue();
			DrawDefaultButton();
			GUI.enabled = enabled;
			GUILayout.Label(ConfigurationManager._pressEscapeHintEditWindow.Value, ConfigurationManagerStyles.GetLabelStyleInfo(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			enabled = GUI.enabled;
			GUI.enabled = enabled && !valueOrDefault && !ConfigurationManagerStyles.IsEqualConfigValues(setting.SettingType, valueToSet, setting.Get());
			if (GUILayout.Button(ConfigurationManager._applyButtonEditWindow.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
			{
				ApplySettingValue();
			}
			GUI.enabled = enabled;
			if (GUILayout.Button(ConfigurationManager._closeText.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
			{
				IsOpen = false;
			}
			GUILayout.EndHorizontal();
		}

		private void ApplySettingValue()
		{
			if (valueToSet != null)
			{
				try
				{
					setting.Set(valueToSet);
					InitializeWindow();
				}
				catch (Exception ex)
				{
					errorOnSetting = ex.ToString();
				}
			}
		}

		private void DrawSettingValue()
		{
			//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_001b: 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_002a: 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)
			Color backgroundColor = GUI.backgroundColor;
			GUI.backgroundColor = ConfigurationManager._widgetBackgroundColor.Value;
			bool drawStringMenu = false;
			_scrollPosition = GUILayout.BeginScrollView(_scrollPosition, Array.Empty<GUILayoutOption>());
			if (!DrawCustomField() && !DrawKnownDrawer())
			{
				if (errorText.Length > 0)
				{
					GUILayout.Label("Error:\n" + errorText, ConfigurationManagerStyles.GetLabelStyle(), Array.Empty<GUILayoutOption>());
				}
				DrawUnknownField(out drawStringMenu);
			}
			GUILayout.EndScrollView();
			if (drawStringMenu)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label(ConfigurationManager._editAsLabelEditWindow.Value, ConfigurationManagerStyles.GetLabelStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
				if (editStringView != (editStringView = GUILayout.SelectionGrid(editStringView, new string[2]
				{
					ConfigurationManager._editAsTextEditWindow.Value,
					ConfigurationManager._editAsListEditWindow.Value
				}, 2, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) })))
				{
				}
				if (editStringView > 0)
				{
					GUILayout.Label(ConfigurationManager._separatorLabelEditWindow.Value, ConfigurationManagerStyles.GetLabelStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
					if (separator != (separator = GUILayout.TextField(separator, Array.Empty<GUILayoutOption>())))
					{
						UpdateStringList();
					}
					if (GUILayout.Button(ConfigurationManager._trimWhitespaceButtonEditWindow.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
					{
						separatedString = separatedString.Select((string s) => s.Trim()).ToList();
						valueToSet = setting.StrToObj(string.Join(separator, separatedString));
					}
				}
				GUILayout.EndHorizontal();
			}
			GUI.backgroundColor = backgroundColor;
		}

		private static void DrawDelimiterLine()
		{
			//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_0043: Unknown result type (might be due to invalid IL or missing references)
			Color backgroundColor = GUI.backgroundColor;
			GUI.backgroundColor = ConfigurationManager._widgetBackgroundColor.Value;
			GUILayout.Label("", ConfigurationManagerStyles.GetDelimiterLine(), (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.ExpandWidth(true),
				GUILayout.Height(2f)
			});
			GUI.backgroundColor = backgroundColor;
		}

		private bool DrawKnownDrawer()
		{
			if (drawerFunction == null)
			{
				return false;
			}
			try
			{
				drawerFunction();
				return true;
			}
			catch (Exception ex)
			{
				ConfigurationManager.LogWarning(ex);
				errorText = ex.GetType().Name + " - " + ex.Message;
			}
			return false;
		}

		public bool DrawCustomField()
		{
			//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_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			if (SettingFieldDrawer.IsSettingFailedToCustomDraw(setting))
			{
				GUILayout.Label("Error when calling custom drawer function.", Array.Empty<GUILayoutOption>());
				return false;
			}
			Color contentColor = GUI.contentColor;
			bool flag = true;
			int fontSize = GUI.skin.textField.fontSize;
			int fontSize2 = GUI.skin.textArea.fontSize;
			int fontSize3 = GUI.skin.label.fontSize;
			int fontSize4 = GUI.skin.button.fontSize;
			GUI.skin.textArea.fontSize = ConfigurationManagerStyles.fontSize;
			GUI.skin.textField.fontSize = ConfigurationManagerStyles.fontSize;
			GUI.skin.label.fontSize = ConfigurationManagerStyles.fontSize;
			GUI.skin.button.fontSize = ConfigurationManagerStyles.fontSize;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			int rightColumnWidth = ConfigurationManager.instance.RightColumnWidth;
			ConfigurationManager.instance.SetRightColumnWidth(Mathf.RoundToInt(((Rect)(ref _windowRect)).width * 0.9f));
			try
			{
				GUI.contentColor = (IsValueToSetDefaultValue() ? ConfigurationManager._fontColorValueDefault.Value : ConfigurationManager._fontColorValueChanged.Value);
				if (setting.CustomDrawer != null)
				{
					setting.CustomDrawer(dummyCustomDrawerConfigEntry);
				}
				else if (setting.CustomHotkeyDrawer != null)
				{
					bool isCurrentlyAcceptingInput = _currentKeyboardShortcutToSet == setting;
					bool flag2 = isCurrentlyAcceptingInput;
					setting.CustomHotkeyDrawer(dummyCustomDrawerConfigEntry, ref isCurrentlyAcceptingInput);
					if (isCurrentlyAcceptingInput != flag2)
					{
						_currentKeyboardShortcutToSet = (isCurrentlyAcceptingInput ? setting : null);
					}
				}
				else
				{
					flag = false;
				}
			}
			catch (Exception e)
			{
				SettingFieldDrawer.SetSettingFailedToCustomDraw(setting, e);
				flag = false;
			}
			finally
			{
				ConfigurationManager.instance.SetRightColumnWidth(rightColumnWidth);
			}
			GUILayout.EndHorizontal();
			GUI.contentColor = contentColor;
			GUI.skin.textField.fontSize = fontSize;
			GUI.skin.textArea.fontSize = fontSize2;
			GUI.skin.label.fontSize = fontSize3;
			GUI.skin.button.fontSize = fontSize4;
			if (flag && dummyCustomDrawerConfigEntry != null)
			{
				valueToSet = dummyCustomDrawerConfigEntry.BoxedValue;
			}
			return flag;
		}

		private void DrawRangeField()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			object obj = valueToSet;
			float num = (float)Convert.ToDouble(obj, CultureInfo.InvariantCulture);
			float num2 = (float)Convert.ToDouble(setting.AcceptableValueRange.Key, CultureInfo.InvariantCulture);
			float num3 = (float)Convert.ToDouble(setting.AcceptableValueRange.Value, CultureInfo.InvariantCulture);
			float num4 = ConfigurationManagerStyles.GetTextStyle(setting).CalcHeight(new GUIContent(obj.ToString()), 100f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(ConfigurationManager._rangeLabelEditWindow.Value, ConfigurationManagerStyles.GetLabelStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			GUILayout.Label($"{num2} - {num3}", ConfigurationManagerStyles.GetLabelStyleInfo(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(num4) });
			try
			{
				float num5 = DrawCenteredHorizontalSlider(num, num2, num3, num4);
				if ((double)Math.Abs(num5 - num) >= (double)Mathf.Abs(num3 - num2) / Math.Pow(10.0, ConfigurationManager._rangePrecision.Value + 2))
				{
					valueToSet = Convert.ChangeType(Utils.RoundWithPrecision(num5, ConfigurationManager._rangePrecision.Value), setting.SettingType, CultureInfo.InvariantCulture);
				}
				if (setting.ShowRangeAsPercent == true)
				{
					SettingFieldDrawer.DrawCenteredLabel($"{Mathf.Abs(num5 - num2) / Mathf.Abs(num3 - num2):P0}", ConfigurationManagerStyles.GetLabelStyle(setting));
					return;
				}
				string text = obj.ToString().AppendZeroIfFloat(setting.SettingType);
				string text2 = GUILayout.TextField(text, ConfigurationManagerStyles.GetTextStyle(setting), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
				if (text2 != text && Utils.TryParseFloat(text2, out var result))
				{
					float value = Mathf.Clamp(result, num2, num3);
					valueToSet = Convert.ChangeType(Utils.RoundWithPrecision(value, ConfigurationManager._rangePrecision.Value), setting.SettingType);
				}
			}
			finally
			{
				GUILayout.EndHorizontal();
			}
		}

		private static float DrawCenteredHorizontalSlider(float converted, float leftValue, float rightValue, float height)
		{
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(height) });
			GUILayout.Space(height * 0.35f);
			float result = GUILayout.HorizontalSlider(converted, leftValue, rightValue, ConfigurationManagerStyles.GetSliderStyle(), ConfigurationManagerStyles.GetThumbStyle(), (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.ExpandWidth(true),
				GUILayout.Height(height)
			});
			GUILayout.EndVertical();
			return result;
		}

		private void DrawUnknownField(out bool drawStringMenu)
		{
			drawStringMenu = false;
			if (setting.ObjToStr != null && setting.StrToObj != null)
			{
				string text = setting.ObjToStr(valueToSet).AppendZeroIfFloat(setting.SettingType);
				if (setting.SettingType == typeof(string) || IsStringList)
				{
					if (editStringView > 0)
					{
						DrawEditableList();
						valueToSet = setting.StrToObj(string.Join(separator, separatedString));
						GUILayout.FlexibleSpace();
					}
					else
					{
						string text2 = GUILayout.TextArea(text, ConfigurationManagerStyles.GetTextStyle(IsValueToSetDefaultValue()), (GUILayoutOption[])(object)new GUILayoutOption[2]
						{
							GUILayout.ExpandWidth(true),
							GUILayout.ExpandHeight(true)
						}).AppendZeroIfFloat(setting.SettingType);
						if (text2 != text)
						{
							valueToSet = setting.StrToObj(text2);
						}
					}
					drawStringMenu = true;
				}
				else
				{
					string text3 = GUILayout.TextArea(text, ConfigurationManagerStyles.GetTextStyle(IsValueToSetDefaultValue()), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }).AppendZeroIfFloat(setting.SettingType);
					if (text3 != text)
					{
						valueToSet = setting.StrToObj(text3);
					}
				}
				return;
			}
			string text4 = ((valueToSet == null) ? "NULL" : Convert.ToString(valueToSet, CultureInfo.InvariantCulture).AppendZeroIfFloat(setting.SettingType));
			if (CanCovert(text4, setting.SettingType))
			{
				string text5 = GUILayout.TextArea(text4, ConfigurationManagerStyles.GetTextStyle(IsValueToSetDefaultValue()), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }).AppendZeroIfFloat(setting.SettingType);
				if (text5 != text4)
				{
					try
					{
						valueToSet = Convert.ChangeType(text5, setting.SettingType, CultureInfo.InvariantCulture);
					}
					catch
					{
					}
				}
			}
			else
			{
				valueToSet = GUILayout.TextArea(text4, ConfigurationManagerStyles.GetTextStyle(IsValueToSetDefaultValue()), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }).AppendZeroIfFloat(setting.SettingType);
			}
		}

		private void DrawEditableList()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Invalid comparison between Unknown and I4
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Round(ConfigurationManagerStyles.GetButtonStyle().CalcSize(new GUIContent("▲")).x);
			for (int i = 0; i < separatedString.Count; i++)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("✕", ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num) }))
				{
					GUILayout.EndHorizontal();
					separatedString.RemoveAt(i);
					break;
				}
				separatedString[i] = GUILayout.TextArea(separatedString[i], ConfigurationManagerStyles.GetTextStyle(separatedStringDefault.IndexOf(separatedString[i].Trim()) == i), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
				bool enabled = GUI.enabled;
				GUI.enabled = i > 0;
				if (GUILayout.Button("▲", ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num) }))
				{
					SwapElements(i, i - 1);
				}
				GUI.enabled = i < separatedString.Count - 1;
				if (GUILayout.Button("▼", ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num) }))
				{
					SwapElements(i, i + 1);
				}
				GUI.enabled = enabled;
				GUILayout.EndHorizontal();
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUI.SetNextControlName("StringListNewItemField");
			newItem = GUILayout.TextField(newItem, ConfigurationManagerStyles.GetTextStyle(isDefaultValue: false), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
			if (string.IsNullOrEmpty(newItem) && (int)Event.current.type == 7)
			{
				GUI.Label(GUILayoutUtility.GetLastRect(), ConfigurationManager._newValuePlaceholderEditWindow.Value, ConfigurationManagerStyles.GetPlaceholderTextStyle());
			}
			if (GUILayout.Button(ConfigurationManager._addButtonEditWindow.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }) && !string.IsNullOrWhiteSpace(newItem))
			{
				separatedString.Add(newItem);
				newItem = "";
				GUI.FocusControl("StringListNewItemField");
			}
			GUILayout.EndHorizontal();
			void SwapElements(int indexA, int indexB)
			{
				List<string> list = separatedString;
				List<string> list2 = separatedString;
				string value = separatedString[indexB];
				string value2 = separatedString[indexA];
				list[indexA] = value;
				list2[indexB] = value2;
			}
		}

		private bool IsValueToSetDefaultValue()
		{
			return ConfigurationManagerStyles.IsEqualConfigValues(setting.SettingType, valueToSet, setting.DefaultValue);
		}

		private bool CanCovert(string value, Type type)
		{
			if (_canCovertCache.ContainsKey(type))
			{
				return _canCovertCache[type];
			}
			try
			{
				object obj = Convert.ChangeType(value, type);
				_canCovertCache[type] = true;
				return true;
			}
			catch
			{
				_canCovertCache[type] = false;
				return false;
			}
		}

		public static void ClearCache()
		{
			foreach (KeyValuePair<SettingEntryBase, ColorCacheEntry> item in ColorCache)
			{
				Object.Destroy((Object)(object)item.Value.Tex);
			}
			ColorCache.Clear();
		}

		internal void DrawDefaultButton()
		{
			//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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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)
			if (setting.HideDefaultButton)
			{
				return;
			}
			Color backgroundColor = GUI.backgroundColor;
			GUI.backgroundColor = ConfigurationManager._widgetBackgroundColor.Value;
			if (setting.DefaultValue != null)
			{
				if (DrawResetButton())
				{
					if (setting.SettingType == typeof(Color))
					{
						valueToSet = Utils.RoundColorToHEX((Color)setting.DefaultValue);
						colorAsHEX = "#" + ColorUtility.ToHtmlStringRGBA((Color)valueToSet);
					}
					else
					{
						valueToSet = setting.DefaultValue;
					}
					if (dummyCustomDrawerConfigEntry != null)
					{
						dummyCustomDrawerConfigEntry.BoxedValue = setting.DefaultValue;
					}
					InitListIndex();
					InitVectorParts();
					UpdateStringList();
					ClearCache();
				}
			}
			else if (setting.SettingType.IsClass && DrawResetButton())
			{
				valueToSet = null;
				if (dummyCustomDrawerConfigEntry != null)
				{
					dummyCustomDrawerConfigEntry.BoxedValue = null;
				}
				InitListIndex();
				InitVectorParts();
				UpdateStringList();
				ClearCache();
			}
			GUI.backgroundColor = backgroundColor;
			static bool DrawResetButton()
			{
				GUILayout.Space(5f);
				return GUILayout.Button(ConfigurationManager._resetSettingText.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			}
		}

		private void DrawBoolField()
		{
			//IL_0006: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			GUI.backgroundColor = ConfigurationManager._widgetBackgroundColor.Value;
			bool flag = (bool)valueToSet;
			Color backgroundColor = GUI.backgroundColor;
			if (flag)
			{
				GUI.backgroundColor = ConfigurationManager._enabledBackgroundColor.Value;
			}
			bool flag2 = GUILayout.SelectionGrid((!flag) ? 1 : 0, new string[2]
			{
				ConfigurationManager._enabledText.Value,
				ConfigurationManager._disabledText.Value
			}, 2, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }) == 0;
			if (flag2 != flag)
			{
				valueToSet = flag2;
			}
			if (flag)
			{
				GUI.backgroundColor = backgroundColor;
			}
		}

		private void DrawFlagsField()
		{
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			long num = Convert.ToInt64(valueToSet);
			long num2 = Convert.ToInt64(setting.DefaultValue);
			var array = (from Enum x in Enum.GetValues(setting.SettingType)
				select new
				{
					name = x.ToString(),
					val = Convert.ToInt64(x)
				}).ToArray();
			float num3 = ((Rect)(ref _windowRect)).width * 0.8f;
			GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxWidth(num3) });
			int num4 = 0;
			while (num4 < array.Length)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				int num5 = 0;
				for (; num4 < array.Length; num4++)
				{
					var anon = array[num4];
					if (anon.val != 0)
					{
						bool flag = (num & anon.val) == anon.val;
						bool flag2 = (num2 & anon.val) == anon.val;
						GUIStyle buttonStyle = ConfigurationManagerStyles.GetButtonStyle(flag == flag2);
						int num6 = (int)buttonStyle.CalcSize(new GUIContent(anon.name)).x;
						num5 += num6;
						if ((float)num5 > num3)
						{
							break;
						}
						GUI.changed = false;
						if (GUILayout.Button(anon.name, buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
						{
							flag = !flag;
						}
						if (GUI.changed)
						{
							long value = (flag ? (num | anon.val) : (num & ~anon.val));
							valueToSet = Enum.ToObject(setting.SettingType, value);
						}
					}
				}
				GUILayout.EndHorizontal();
			}
			GUI.changed = false;
			GUILayout.EndVertical();
			GUILayout.FlexibleSpace();
		}

		private void DrawEnumListField()
		{
			//IL_0025: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			GUIContent[] array = listEnum.Cast<object>().Select(SettingFieldDrawer.ObjectToGuiContent).ToArray();
			_scrollPositionEnum = GUILayout.BeginScrollView(_scrollPositionEnum, false, false, Array.Empty<GUILayoutOption>());
			try
			{
				listIndex = GUILayout.SelectionGrid(listIndex, array, 1, ConfigurationManagerStyles.GetComboBoxStyle(), Array.Empty<GUILayoutOption>());
				if (listEnum != null && listIndex >= 0 && listIndex < listEnum.Count)
				{
					valueToSet = listEnum[listIndex];
				}
			}
			finally
			{
				GUILayout.EndScrollView();
			}
			GUILayout.FlexibleSpace();
		}

		private void DrawKeyCode()
		{
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if (_currentKeyboardShortcutToSet == setting)
			{
				GUILayout.Label(ConfigurationManager._shortcutKeysText.Value, ConfigurationManagerStyles.GetLabelStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
				GUIUtility.keyboardControl = -1;
				if (_keysToCheck == null)
				{
					_keysToCheck = UnityInput.Current.SupportedKeyCodes.Except((IEnumerable<KeyCode>)(object)new KeyCode[2]
					{
						(KeyCode)323,
						default(KeyCode)
					}).ToArray();
				}
				foreach (KeyCode item in _keysToCheck)
				{
					if (UnityInput.Current.GetKeyUp(item))
					{
						valueToSet = item;
						_currentKeyboardShortcutToSet = null;
						break;
					}
				}
				if (GUILayout.Button(ConfigurationManager._cancelText.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
				{
					_currentKeyboardShortcutToSet = null;
				}
			}
			else
			{
				if (listEnum == null)
				{
					listEnum = Enum.GetValues(setting.SettingType);
				}
				DrawEnumListField();
				if (GUILayout.Button(new GUIContent(ConfigurationManager._shortcutKeyText.Value), ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
				{
					_currentKeyboardShortcutToSet = setting;
				}
			}
		}

		private void DrawKeyboardShortcut()
		{
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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)
			if (_currentKeyboardShortcutToSet == setting)
			{
				GUILayout.Label(ConfigurationManager._shortcutKeysText.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
				GUIUtility.keyboardControl = -1;
				IInputSystem current = UnityInput.Current;
				if (_keysToCheck == null)
				{
					_keysToCheck = current.SupportedKeyCodes.Except((IEnumerable<KeyCode>)(object)new KeyCode[2]
					{
						(KeyCode)323,
						default(KeyCode)
					}).ToArray();
				}
				foreach (KeyCode item in _keysToCheck)
				{
					if (current.GetKeyUp(item))
					{
						valueToSet = (object)new KeyboardShortcut(item, _keysToCheck.Where((Func<KeyCode, bool>)current.GetKey).ToArray());
						_currentKeyboardShortcutToSet = null;
						break;
					}
				}
				if (GUILayout.Button(ConfigurationManager._cancelText.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
				{
					_currentKeyboardShortcutToSet = null;
				}
			}
			else
			{
				if (GUILayout.Button(valueToSet.ToString(), ConfigurationManagerStyles.GetButtonStyle(setting), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }))
				{
					_currentKeyboardShortcutToSet = setting;
				}
				if (GUILayout.Button(ConfigurationManager._clearText.Value, ConfigurationManagerStyles.GetButtonStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) }))
				{
					valueToSet = KeyboardShortcut.Empty;
					_currentKeyboardShortcutToSet = null;
				}
			}
		}

		private void DrawVectorPart(int position)
		{
			if (1 == 0)
			{
			}
			string text = position switch
			{
				0 => "X", 
				1 => "Y", 
				2 => "Z", 
				3 => "W", 
				_ => "", 
			};
			if (1 == 0)
			{
			}
			string text2 = text;
			float result;
			bool isDefaultValue = Utils.TryParseFloat(vectorParts[position], out result) && vectorDefault[position] == result;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(text2 + " ", ConfigurationManagerStyles.GetLabelStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			vectorParts[position] = GUILayout.TextField(vectorParts[position], ConfigurationManagerStyles.GetTextStyle(isDefaultValue), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }).KeepDigitsAndFirstDot();
			GUILayout.EndHorizontal();
		}

		private void DrawVector()
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Expected O, but got Unknown
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < vectorParts.Count; i++)
			{
				DrawVectorPart(i);
			}
			for (int j = 0; j < vectorParts.Count; j++)
			{
				if (Utils.TryParseFloat(vectorParts[j], out var result))
				{
					vectorFloats[j] = result;
				}
			}
			if (setting.SettingType == typeof(Vector2))
			{
				valueToSet = (object)new Vector2(vectorFloats[0], vectorFloats[1]);
			}
			else if (setting.SettingType == typeof(Vector3))
			{
				valueToSet = (object)new Vector3(vectorFloats[0], vectorFloats[1], vectorFloats[2]);
			}
			else if (setting.SettingType == typeof(Vector4))
			{
				valueToSet = (object)new Vector4(vectorFloats[0], vectorFloats[1], vectorFloats[2], vectorFloats[3]);
			}
			else if (setting.SettingType == typeof(Quaternion))
			{
				valueToSet = (object)new Quaternion(vectorFloats[0], vectorFloats[1], vectorFloats[2], vectorFloats[3]);
			}
			GUILayout.FlexibleSpace();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label($"{ConfigurationManager._precisionLabelEditWindow.Value}: {ConfigurationManager._vectorPrecision.Value} ", ConfigurationManagerStyles.GetLabelStyle(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) });
			float height = ConfigurationManagerStyles.GetTextStyle(setting).CalcHeight(new GUIContent(ConfigurationManager._vectorPrecision.Value.ToString()), 100f);
			ConfigurationManager._vectorPrecision.Value = Mathf.RoundToInt(DrawCenteredHorizontalSlider(ConfigurationManager._vectorPrecision.Value, 0f, 5f, height));
			GUILayout.EndHorizontal();
		}

		private void DrawColor()
		{
			//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_0018: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Invalid comparison between Unknown and I4
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00a2: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: 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_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missi