Decompiled source of Mod Settings v1.0.0

ModSettings.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Epic.OnlineServices.Lobby;
using Microsoft.CodeAnalysis;
using Mirror;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ModSettings
{
	internal static class HostSync
	{
		private const string Prefix = "com.pigpooteamelf.";

		private const string CountKey = "JOLF_CFG_N";

		private const string PartKey = "JOLF_CFG_";

		private const int PartSize = 900;

		private static string lastPublished;

		private static string lastLobbyId;

		private static string lastApplied;

		private static readonly Dictionary<ConfigEntryBase, object> originals = new Dictionary<ConfigEntryBase, object>();

		internal static bool IsGuest
		{
			get
			{
				if (NetworkClient.active)
				{
					return !NetworkServer.active;
				}
				return false;
			}
		}

		private static BEosLobby Lobby
		{
			get
			{
				try
				{
					BEosLobby currentLobby = BEosLobbyManager.CurrentLobby;
					return (currentLobby != null && currentLobby.IsValid()) ? currentLobby : null;
				}
				catch
				{
					return null;
				}
			}
		}

		internal static bool IsManaged(string pluginGuid, ConfigEntryBase e)
		{
			if (pluginGuid.StartsWith("com.pigpooteamelf.") && pluginGuid != "com.pigpooteamelf.modsettings")
			{
				ConfigDescription description = e.Description;
				return ((description == null) ? ((bool?)null) : description.Tags?.Any((object t) => t as string == "Personal")) != true;
			}
			return false;
		}

		private static IEnumerable<(string id, ConfigEntryBase entry)> Managed()
		{
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				BaseUnityPlugin instance = value.Instance;
				ConfigFile val = ((instance != null) ? instance.Config : null);
				if (val == null)
				{
					continue;
				}
				string guid = value.Metadata.GUID;
				foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in val)
				{
					if (IsManaged(guid, item.Value))
					{
						yield return (id: guid.Substring("com.pigpooteamelf.".Length) + "/" + item.Key.Section + "/" + item.Key.Key, entry: item.Value);
					}
				}
			}
		}

		internal static void Tick()
		{
			try
			{
				if (NetworkServer.active)
				{
					RestoreOwn();
					Publish();
				}
				else if (IsGuest)
				{
					Receive();
				}
				else
				{
					RestoreOwn();
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Settings sync: " + ex.Message));
			}
		}

		private static void Publish()
		{
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Expected O, but got Unknown
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Expected O, but got Unknown
			BEosLobby lobby = Lobby;
			if (lobby == null || !lobby.IsCurrentUserOwner())
			{
				return;
			}
			StringBuilder stringBuilder = new StringBuilder();
			foreach (var (value, val) in Managed().OrderBy<(string, ConfigEntryBase), string>(((string id, ConfigEntryBase entry) m) => m.id, StringComparer.Ordinal))
			{
				stringBuilder.Append(value).Append('=').Append(TomlTypeConverter.ConvertToString(val.BoxedValue, val.SettingType).Replace("\n", " "))
					.Append('\n');
			}
			string text = stringBuilder.ToString();
			if (!(text == lastPublished) || !(lobby.Id == lastLobbyId))
			{
				int num = Math.Max(1, (text.Length + 900 - 1) / 900);
				for (int num2 = 0; num2 < num; num2++)
				{
					string text2 = text.Substring(num2 * 900, Math.Min(900, text.Length - num2 * 900));
					lobby.SetLobbyAttribute(new BEosAttribute("JOLF_CFG_" + num2, text2, (LobbyAttributeVisibility)0));
				}
				lobby.SetLobbyAttribute(new BEosAttribute("JOLF_CFG_N", (long)num, (LobbyAttributeVisibility)0));
				lastPublished = text;
				lastLobbyId = lobby.Id;
				Plugin.Log.LogInfo((object)$"Shared {text.Count((char c) => c == '\n')} mod settings with the lobby ({num} part(s)).");
			}
		}

		private static void Receive()
		{
			BEosLobby lobby = Lobby;
			if (((lobby != null) ? lobby.Attributes : null) == null || !lobby.Attributes.TryGetValue("JOLF_CFG_N", out var value) || value == null)
			{
				return;
			}
			long longValue = value.LongValue;
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < longValue; i++)
			{
				if (!lobby.Attributes.TryGetValue("JOLF_CFG_" + i, out var value2) || value2 == null)
				{
					return;
				}
				stringBuilder.Append(value2.StringValue);
			}
			string text = stringBuilder.ToString();
			if (text == lastApplied)
			{
				return;
			}
			lastApplied = text;
			Dictionary<string, ConfigEntryBase> dictionary = Managed().ToDictionary(((string id, ConfigEntryBase entry) m) => m.id, ((string id, ConfigEntryBase entry) m) => m.entry);
			int num = 0;
			string[] array = text.Split('\n');
			foreach (string text2 in array)
			{
				int num3 = text2.IndexOf('=');
				if (num3 > 0 && dictionary.TryGetValue(text2.Substring(0, num3), out var value3))
				{
					object obj;
					try
					{
						obj = TomlTypeConverter.ConvertToValue(text2.Substring(num3 + 1), value3.SettingType);
					}
					catch
					{
						continue;
					}
					if (!originals.ContainsKey(value3))
					{
						originals[value3] = value3.BoxedValue;
					}
					value3.ConfigFile.SaveOnConfigSet = false;
					if (!object.Equals(value3.BoxedValue, obj))
					{
						value3.BoxedValue = obj;
					}
					num++;
				}
			}
			Plugin.Log.LogInfo((object)$"Using the host's settings ({num} of them).");
		}

		private static void RestoreOwn()
		{
			lastApplied = null;
			if (originals.Count == 0)
			{
				return;
			}
			foreach (KeyValuePair<ConfigEntryBase, object> original in originals)
			{
				original.Key.ConfigFile.SaveOnConfigSet = false;
				if (!object.Equals(original.Key.BoxedValue, original.Value))
				{
					original.Key.BoxedValue = original.Value;
				}
			}
			foreach (ConfigFile item in originals.Keys.Select((ConfigEntryBase e) => e.ConfigFile).Distinct())
			{
				item.SaveOnConfigSet = true;
			}
			originals.Clear();
			Plugin.Log.LogInfo((object)"Back to your own settings.");
		}
	}
	[BepInPlugin("com.pigpooteamelf.modsettings", "Mod Settings", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private ConfigEntry<KeyCode> openKey;

		private ConfigEntry<float> uiScale;

		private bool open;

		private Rect window;

		private Vector2 scroll;

		private string search = "";

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

		private ConfigEntryBase waitingForKey;

		private readonly Dictionary<ConfigEntryBase, string> textEdits = new Dictionary<ConfigEntryBase, string>();

		private GUIStyle header;

		private GUIStyle small;

		private GUIStyle wrap;

		private bool stylesMade;

		private bool disabledGameInput;

		private CursorLockMode prevLock;

		private bool prevVisible;

		private float nextSync;

		private void Awake()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			openKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Window", "OpenKey", (KeyCode)282, "Key that opens and closes this settings window.");
			uiScale = ((BaseUnityPlugin)this).Config.Bind<float>("Window", "Size", 1f, new ConfigDescription("Size of the settings window's text and controls.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.6f, 2f), Array.Empty<object>()));
			Log.LogInfo((object)$"Mod Settings ready: press {openKey.Value}.");
		}

		private void Update()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime >= nextSync)
			{
				nextSync = Time.unscaledTime + 1f;
				HostSync.Tick();
			}
			Keyboard current = Keyboard.current;
			if (current != null && waitingForKey == null && Pressed(current, openKey.Value))
			{
				SetOpen(!open);
			}
			if (open && current != null && ((ButtonControl)current.escapeKey).wasPressedThisFrame && waitingForKey == null)
			{
				SetOpen(value: false);
			}
		}

		private void LateUpdate()
		{
			if (open)
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
		}

		private void SetOpen(bool value)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			if (open == value)
			{
				return;
			}
			open = value;
			waitingForKey = null;
			textEdits.Clear();
			if (open)
			{
				prevLock = Cursor.lockState;
				prevVisible = Cursor.visible;
				disabledGameInput = SetGameInput(on: false);
				return;
			}
			if (disabledGameInput)
			{
				SetGameInput(on: true);
			}
			disabledGameInput = false;
			Cursor.lockState = prevLock;
			Cursor.visible = prevVisible;
		}

		private static bool SetGameInput(bool on)
		{
			try
			{
				if (on)
				{
					InputManager.DisableMode((InputMode)4096);
				}
				else
				{
					InputManager.EnableMode((InputMode)4096);
				}
				return true;
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Couldn't switch game input: " + ex.Message));
				return false;
			}
		}

		internal unsafe static bool Pressed(Keyboard kb, KeyCode code)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			string text = ((object)(*(KeyCode*)(&code))/*cast due to .constrained prefix*/).ToString();
			if (text.StartsWith("Alpha"))
			{
				text = "Digit" + text.Substring(5);
			}
			else if (text.StartsWith("Keypad"))
			{
				text = "Numpad" + text.Substring(6);
			}
			if (!Enum.TryParse<Key>(text, ignoreCase: true, out Key result) || (int)result == 0)
			{
				return false;
			}
			KeyControl val = kb[result];
			if (val != null)
			{
				return ((ButtonControl)val).wasPressedThisFrame;
			}
			return false;
		}

		private void MakeStyles()
		{
			//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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			if (!stylesMade)
			{
				stylesMade = true;
				header = new GUIStyle(GUI.skin.button)
				{
					alignment = (TextAnchor)3,
					fontStyle = (FontStyle)1,
					fontSize = 16
				};
				small = new GUIStyle(GUI.skin.label)
				{
					fontSize = 11,
					wordWrap = true
				};
				small.normal.textColor = new Color(0.75f, 0.75f, 0.75f);
				wrap = new GUIStyle(GUI.skin.label)
				{
					wordWrap = true
				};
			}
		}

		private void OnGUI()
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Expected O, but got Unknown
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Invalid comparison between Unknown and I4
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (!open)
			{
				return;
			}
			MakeStyles();
			if (waitingForKey != null && (int)Event.current.type == 4 && (int)Event.current.keyCode != 0)
			{
				if ((int)Event.current.keyCode != 27)
				{
					waitingForKey.BoxedValue = Event.current.keyCode;
				}
				waitingForKey = null;
				Event.current.Use();
			}
			float num = Mathf.Clamp(uiScale.Value, 0.6f, 2f) * Mathf.Max(0.75f, (float)Screen.height / 1080f);
			GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
			float num2 = (float)Screen.width / num;
			float num3 = (float)Screen.height / num;
			if (((Rect)(ref window)).width == 0f)
			{
				window = new Rect(num2 * 0.5f - 320f, num3 * 0.08f, 640f, num3 * 0.84f);
			}
			((Rect)(ref window)).width = Mathf.Min(640f, num2 - 20f);
			((Rect)(ref window)).height = Mathf.Min(((Rect)(ref window)).height, num3 - 20f);
			((Rect)(ref window)).x = Mathf.Clamp(((Rect)(ref window)).x, 0f, num2 - ((Rect)(ref window)).width);
			((Rect)(ref window)).y = Mathf.Clamp(((Rect)(ref window)).y, 0f, num3 - 40f);
			GUI.backgroundColor = new Color(0.1f, 0.1f, 0.12f, 1f);
			window = GUI.Window(24301, window, new WindowFunction(DrawWindow), "Mod Settings");
			GUI.backgroundColor = Color.white;
		}

		private void DrawWindow(int id)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Expected O, but got Unknown
			GUI.backgroundColor = Color.white;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Search", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
			search = GUILayout.TextField(search ?? "", Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Close", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
			{
				SetOpen(value: false);
			}
			GUILayout.EndHorizontal();
			if (HostSync.IsGuest)
			{
				GUILayout.Label("You're in someone else's game: the host controls these settings.", wrap, Array.Empty<GUILayoutOption>());
			}
			GUILayout.Label($"Changes save straight away. Some only take effect on the next hole or after a restart (it says so where it matters). {openKey.Value} or Esc to close.", small, Array.Empty<GUILayoutOption>());
			scroll = GUILayout.BeginScrollView(scroll, Array.Empty<GUILayoutOption>());
			foreach (PluginInfo item in Chainloader.PluginInfos.Values.OrderBy<PluginInfo, string>((PluginInfo p) => p.Metadata.Name, StringComparer.OrdinalIgnoreCase))
			{
				BaseUnityPlugin instance = item.Instance;
				ConfigFile val = ((instance != null) ? instance.Config : null);
				if (val == null || val.Count == 0)
				{
					continue;
				}
				List<ConfigEntryBase> list = ((IEnumerable<KeyValuePair<ConfigDefinition, ConfigEntryBase>>)val).Select((KeyValuePair<ConfigDefinition, ConfigEntryBase> kv) => kv.Value).Where(Matches).ToList();
				if (list.Count == 0)
				{
					continue;
				}
				string gUID = item.Metadata.GUID;
				int num;
				object obj;
				if (!expanded.Contains(gUID))
				{
					num = ((search.Length > 0) ? 1 : 0);
					if (num == 0)
					{
						obj = "►  ";
						goto IL_01c3;
					}
				}
				else
				{
					num = 1;
				}
				obj = "▼  ";
				goto IL_01c3;
				IL_01c3:
				if (GUILayout.Button((string?)obj + item.Metadata.Name + $"   ({list.Count})", header, Array.Empty<GUILayoutOption>()) && !expanded.Remove(gUID))
				{
					expanded.Add(gUID);
				}
				if (num == 0)
				{
					continue;
				}
				GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
				foreach (IGrouping<string, ConfigEntryBase> item2 in from e in list
					group e by e.Definition.Section)
				{
					GUILayout.Label(item2.Key, new GUIStyle(GUI.skin.label)
					{
						fontStyle = (FontStyle)1
					}, Array.Empty<GUILayoutOption>());
					foreach (ConfigEntryBase item3 in item2)
					{
						DrawEntry(item3, item.Metadata.GUID);
					}
					GUILayout.Space(6f);
				}
				GUILayout.EndVertical();
				GUILayout.Space(4f);
			}
			GUILayout.EndScrollView();
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 22f));
		}

		private bool Matches(ConfigEntryBase e)
		{
			if (string.IsNullOrEmpty(search))
			{
				return true;
			}
			if (e.Definition.Key.IndexOf(search, StringComparison.OrdinalIgnoreCase) < 0 && e.Definition.Section.IndexOf(search, StringComparison.OrdinalIgnoreCase) < 0)
			{
				ConfigDescription description = e.Description;
				return (((description != null) ? description.Description : null) ?? "").IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return true;
		}

		private static string Nice(string key)
		{
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < key.Length; i++)
			{
				char c = key[i];
				if (i > 0 && char.IsUpper(c) && !char.IsUpper(key[i - 1]))
				{
					stringBuilder.Append(' ');
					stringBuilder.Append(char.ToLowerInvariant(c));
				}
				else
				{
					stringBuilder.Append(c);
				}
			}
			return stringBuilder.ToString();
		}

		private void DrawEntry(ConfigEntryBase e, string pluginGuid)
		{
			//IL_059f: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a5: Invalid comparison between Unknown and I4
			//IL_05ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b3: Invalid comparison between Unknown and I4
			//IL_05ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c4: Invalid comparison between Unknown and I4
			Type settingType = e.SettingType;
			ConfigDescription description = e.Description;
			AcceptableValueBase val = ((description != null) ? description.AcceptableValues : null);
			string text = Nice(e.Definition.Key);
			bool flag = HostSync.IsManaged(pluginGuid, e) && HostSync.IsGuest;
			if (flag)
			{
				text += "  (set by the host)";
			}
			bool enabled = GUI.enabled;
			GUI.enabled = enabled && !flag;
			try
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (settingType == typeof(bool))
				{
					bool flag2 = (bool)e.BoxedValue;
					bool flag3 = GUILayout.Toggle(flag2, "  " + text, Array.Empty<GUILayoutOption>());
					if (flag3 != flag2)
					{
						e.BoxedValue = flag3;
					}
					GUILayout.FlexibleSpace();
				}
				else if ((settingType == typeof(float) || settingType == typeof(double)) && val != null && ((object)val).GetType().Name.StartsWith("AcceptableValueRange"))
				{
					float num = Convert.ToSingle(((object)val).GetType().GetProperty("MinValue").GetValue(val));
					float num2 = Convert.ToSingle(((object)val).GetType().GetProperty("MaxValue").GetValue(val));
					float num3 = Convert.ToSingle(e.BoxedValue);
					GUILayout.Label(text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(190f) });
					float num4 = GUILayout.HorizontalSlider(num3, num, num2, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(180f) });
					GUILayout.Label(FormatNumber(num4, num2 - num), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
					if (Mathf.Abs(num4 - num3) > 1E-06f)
					{
						e.BoxedValue = ((settingType == typeof(double)) ? ((object)(double)Round(num4, num2 - num)) : ((object)Round(num4, num2 - num)));
					}
				}
				else if (settingType == typeof(int) && val != null && ((object)val).GetType().Name.StartsWith("AcceptableValueRange"))
				{
					int num5 = (int)((object)val).GetType().GetProperty("MinValue").GetValue(val);
					int num6 = (int)((object)val).GetType().GetProperty("MaxValue").GetValue(val);
					int num7 = (int)e.BoxedValue;
					GUILayout.Label(text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(190f) });
					int num8 = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)num7, (float)num5, (float)num6, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(180f) }));
					GUILayout.Label(num8.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) });
					if (num8 != num7)
					{
						e.BoxedValue = num8;
					}
				}
				else if (settingType == typeof(KeyCode))
				{
					GUILayout.Label(text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(190f) });
					if (GUILayout.Button((waitingForKey == e) ? "Press a key... (Esc = cancel)" : e.BoxedValue.ToString(), Array.Empty<GUILayoutOption>()))
					{
						waitingForKey = e;
					}
				}
				else if (settingType.IsEnum)
				{
					GUILayout.Label(text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(190f) });
					string[] names = Enum.GetNames(settingType);
					if (names.Length <= 4)
					{
						int num9 = Array.IndexOf<string>(names, e.BoxedValue.ToString());
						int num10 = GUILayout.Toolbar(num9, names.Select(Nice).ToArray(), Array.Empty<GUILayoutOption>());
						if (num10 != num9)
						{
							e.BoxedValue = Enum.Parse(settingType, names[num10]);
						}
					}
					else if (GUILayout.Button(Nice(e.BoxedValue.ToString()) + "   (click to change)", Array.Empty<GUILayoutOption>()))
					{
						int num11 = Array.IndexOf<string>(names, e.BoxedValue.ToString());
						e.BoxedValue = Enum.Parse(settingType, names[(num11 + 1) % names.Length]);
					}
				}
				else if (settingType == typeof(string) && val != null && ((object)val).GetType().Name.StartsWith("AcceptableValueList"))
				{
					GUILayout.Label(text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(190f) });
					string[] array = ((IEnumerable<string>)((object)val).GetType().GetProperty("AcceptableValues").GetValue(val)).ToArray();
					int num12 = Array.IndexOf(array, (string)e.BoxedValue);
					int num13 = GUILayout.Toolbar(Mathf.Max(0, num12), array, Array.Empty<GUILayoutOption>());
					if (num13 != num12)
					{
						e.BoxedValue = array[num13];
					}
				}
				else
				{
					GUILayout.Label(text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(190f) });
					if (!textEdits.TryGetValue(e, out var value))
					{
						value = TomlTypeConverter.ConvertToString(e.BoxedValue, settingType);
					}
					string text2 = "cfg_" + e.Definition.Section + "_" + e.Definition.Key;
					GUI.SetNextControlName(text2);
					string text3 = GUILayout.TextField(value, Array.Empty<GUILayoutOption>());
					if (text3 != value)
					{
						textEdits[e] = text3;
					}
					bool flag4 = GUI.GetNameOfFocusedControl() == text2;
					bool flag5 = (int)Event.current.type == 4 && ((int)Event.current.keyCode == 13 || (int)Event.current.keyCode == 271);
					if (textEdits.ContainsKey(e) && (!flag4 || (flag4 && flag5)))
					{
						try
						{
							e.BoxedValue = TomlTypeConverter.ConvertToValue(textEdits[e], settingType);
						}
						catch
						{
							Log.LogWarning((object)("'" + textEdits[e] + "' isn't a valid value for " + e.Definition.Key));
						}
						textEdits.Remove(e);
						if (flag5)
						{
							GUI.FocusControl((string)null);
						}
					}
					if (GUILayout.Button("Reset", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(55f) }))
					{
						e.BoxedValue = e.DefaultValue;
						textEdits.Remove(e);
					}
				}
				GUILayout.EndHorizontal();
			}
			catch (Exception ex)
			{
				GUILayout.EndHorizontal();
				GUILayout.Label(text + ": can't show this setting (" + ex.GetType().Name + ")", small, Array.Empty<GUILayoutOption>());
			}
			GUI.enabled = enabled;
			ConfigDescription description2 = e.Description;
			string text4 = ((description2 != null) ? description2.Description : null);
			if (flag)
			{
				text4 = (string.IsNullOrEmpty(text4) ? "" : (text4 + " ")) + "You're using the host's value; your own comes back when you leave.";
			}
			if (!string.IsNullOrEmpty(text4))
			{
				GUILayout.Label(text4, small, Array.Empty<GUILayoutOption>());
			}
			GUILayout.Space(3f);
		}

		private static float Round(float v, float span)
		{
			if (!(span >= 100f))
			{
				if (!(span >= 10f))
				{
					return Mathf.Round(v * 100f) / 100f;
				}
				return Mathf.Round(v * 10f) / 10f;
			}
			return Mathf.Round(v);
		}

		private static string FormatNumber(float v, float span)
		{
			if (!(span >= 100f))
			{
				if (!(span >= 10f))
				{
					return v.ToString("0.00");
				}
				return v.ToString("0.0");
			}
			return v.ToString("0");
		}
	}
}