BepInEx/plugins/smolMods.Core.dll

Decompiled 14 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Mirror;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("smolMods.Core")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a3231e664cf7d257a8601fb862a89ade69b41d83")]
[assembly: AssemblyProduct("smolMods.Core")]
[assembly: AssemblyTitle("smolMods.Core")]
[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 SmolMods.Core
{
	internal static class CharacterPreview
	{
		private class Entry
		{
			public GameObject root;

			public Image head;

			public Image tuft;

			public Image chest;

			public Image handL;

			public Image handR;

			public Image body;

			public Image footL;

			public Image footR;

			public Image armL;

			public Image armR;

			public Image legL;

			public Image legR;

			public TextMeshProUGUI mood;
		}

		private static readonly List<Entry> Entries = new List<Entry>();

		private static Sprite _circle;

		private static float _nextTick;

		private static readonly Color FallbackHead = new Color(0.18f, 0.62f, 0.39f);

		private static readonly Color FallbackTorso = new Color(0.94f, 0.23f, 0.16f);

		private static readonly Color FallbackLegs = new Color(0.165f, 0.165f, 0.18f);

		private static readonly Color EyeInk = new Color(1f, 0.98f, 0.92f);

		private static readonly Color MoodInkColor = new Color(0.13f, 0.11f, 0.09f);

		private static Sprite _arc;

		internal static void BuildPanel(ModPanelContext ctx)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: 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_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: 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_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Expected O, but got Unknown
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0490: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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)
			//IL_00a1: 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_050d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0514: Expected O, but got Unknown
			try
			{
				Entry entry = new Entry();
				GameObject val = (entry.root = new GameObject("ModsCharacterPreview"));
				val.transform.SetParent(ctx.NoteGo.transform.parent, false);
				RectTransform component = ctx.NoteGo.GetComponent<RectTransform>();
				RectTransform val2 = val.AddComponent<RectTransform>();
				Vector2 val3 = ctx.NextSlot(new Vector2(340f, 340f), -110f);
				if ((Object)(object)component != (Object)null)
				{
					val2.anchorMin = component.anchorMin;
					val2.anchorMax = component.anchorMax;
					val2.pivot = component.pivot;
					val2.anchoredPosition = component.anchoredPosition + val3;
				}
				val2.sizeDelta = new Vector2(340f, 340f);
				entry.legL = AddArc(val, "leg_l", new Vector2(-24f, -107f), new Vector2(76f, 48f), 90f, FallbackLegs);
				entry.legR = AddArc(val, "leg_r", new Vector2(24f, -107f), new Vector2(76f, 48f), -90f, FallbackLegs);
				entry.body = AddPart(val, "body", new Vector2(0f, -35f), new Vector2(116f, 116f), FallbackLegs, circle: true);
				entry.footL = AddPart(val, "foot_l", new Vector2(-31f, -138f), new Vector2(41f, 15f), FallbackLegs, circle: true);
				entry.footR = AddPart(val, "foot_r", new Vector2(31f, -138f), new Vector2(41f, 15f), FallbackLegs, circle: true);
				((Transform)((Graphic)entry.footL).rectTransform).localEulerAngles = new Vector3(0f, 0f, 10f);
				((Transform)((Graphic)entry.footR).rectTransform).localEulerAngles = new Vector3(0f, 0f, -10f);
				entry.armL = AddArc(val, "arm_l", new Vector2(-62f, 30f), new Vector2(120f, 60f), 15f, FallbackTorso);
				entry.armR = AddArc(val, "arm_r", new Vector2(62f, 30f), new Vector2(120f, 60f), -15f, FallbackTorso);
				entry.chest = AddPart(val, "chest", new Vector2(0f, 40f), new Vector2(64f, 64f), FallbackTorso, circle: true);
				entry.handL = AddPart(val, "hand_l", new Vector2(-96f, 25f), new Vector2(32f, 32f), FallbackTorso, circle: true);
				entry.handR = AddPart(val, "hand_r", new Vector2(96f, 25f), new Vector2(32f, 32f), FallbackTorso, circle: true);
				entry.tuft = AddPart(val, "tuft", new Vector2(-38f, 140f), new Vector2(42f, 20f), FallbackHead, circle: true);
				((Transform)((Graphic)entry.tuft).rectTransform).localEulerAngles = new Vector3(0f, 0f, -40f);
				entry.head = AddPart(val, "head", new Vector2(0f, 100f), new Vector2(88f, 88f), FallbackHead, circle: true);
				AddPart(val, "eye", new Vector2(0f, 102f), new Vector2(58f, 58f), EyeInk, circle: true);
				GameObject val4 = new GameObject("mood");
				val4.transform.SetParent(val.transform, false);
				RectTransform obj = val4.AddComponent<RectTransform>();
				obj.anchoredPosition = new Vector2(0f, 102f);
				obj.sizeDelta = new Vector2(70f, 50f);
				entry.mood = val4.AddComponent<TextMeshProUGUI>();
				((TMP_Text)entry.mood).alignment = (TextAlignmentOptions)514;
				((TMP_Text)entry.mood).enableWordWrapping = false;
				((TMP_Text)entry.mood).overflowMode = (TextOverflowModes)0;
				((Graphic)entry.mood).raycastTarget = false;
				((TMP_Text)entry.mood).fontSize = 40f;
				((Graphic)entry.mood).color = MoodInkColor;
				((TMP_Text)entry.mood).text = "";
				if ((Object)(object)ModSettingsApi.MenuGlyphFont != (Object)null)
				{
					((TMP_Text)entry.mood).font = ModSettingsApi.MenuGlyphFont;
				}
				ModSettingsApi.RegisterColorRoot(val.transform);
				ctx.RegisterPanel(val);
				Entries.Add(entry);
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					log.LogInfo((object)"Character preview created");
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = ModSettingsApi.Log;
				if (log2 != null)
				{
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val5 = new BepInExWarningLogInterpolatedStringHandler(35, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Character preview creation failed: ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(ex.Message);
					}
					log2.LogWarning(val5);
				}
			}
		}

		private static Image AddArc(GameObject root, string name, Vector2 pos, Vector2 size, float rotZ, Color color)
		{
			//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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(root.transform, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.anchoredPosition = pos;
			obj.sizeDelta = size;
			((Transform)obj).localEulerAngles = new Vector3(0f, 0f, rotZ);
			Image obj2 = val.AddComponent<Image>();
			((Graphic)obj2).raycastTarget = false;
			obj2.sprite = ArcSprite();
			((Graphic)obj2).color = color;
			return obj2;
		}

		private static Sprite ArcSprite()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_arc != (Object)null)
			{
				return _arc;
			}
			Texture2D val = new Texture2D(96, 96, (TextureFormat)5, false);
			((Object)val).hideFlags = (HideFlags)61;
			float num = 47.5f;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(num + 32f * Mathf.Cos((float)Math.PI / 6f), num + 32f * Mathf.Sin((float)Math.PI / 6f));
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(num + 32f * Mathf.Cos(2.6179938f), num + 32f * Mathf.Sin(2.6179938f));
			Vector2 val4 = default(Vector2);
			for (int i = 0; i < 96; i++)
			{
				for (int j = 0; j < 96; j++)
				{
					float num2 = (float)j - num;
					float num3 = (float)i - num;
					float num4 = Mathf.Atan2(num3, num2);
					float num6;
					if (num4 >= (float)Math.PI / 6f && num4 <= 2.6179938f)
					{
						float num5 = Mathf.Sqrt(num2 * num2 + num3 * num3);
						num6 = Mathf.Clamp01(5.5f - Mathf.Abs(num5 - 32f) + 0.5f);
					}
					else
					{
						((Vector2)(ref val4))..ctor((float)j, (float)i);
						float num7 = Mathf.Min(Vector2.Distance(val4, val2), Vector2.Distance(val4, val3));
						num6 = Mathf.Clamp01(5.5f - num7 + 0.5f);
					}
					val.SetPixel(j, i, new Color(1f, 1f, 1f, num6));
				}
			}
			val.Apply();
			_arc = Sprite.Create(val, new Rect(0f, 0f, 96f, 96f), new Vector2(0.5f, 0.5f));
			((Object)_arc).hideFlags = (HideFlags)61;
			return _arc;
		}

		private static Image AddPart(GameObject root, string name, Vector2 pos, Vector2 size, Color color, bool circle)
		{
			//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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(root.transform, false);
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.anchoredPosition = pos;
			obj.sizeDelta = size;
			Image val2 = val.AddComponent<Image>();
			((Graphic)val2).raycastTarget = false;
			if (circle)
			{
				val2.sprite = CircleSprite();
			}
			((Graphic)val2).color = color;
			return val2;
		}

		private static Sprite CircleSprite()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_circle != (Object)null)
			{
				return _circle;
			}
			Texture2D val = new Texture2D(96, 96, (TextureFormat)5, false);
			((Object)val).hideFlags = (HideFlags)61;
			float num = 46.5f;
			float num2 = 47.5f;
			for (int i = 0; i < 96; i++)
			{
				for (int j = 0; j < 96; j++)
				{
					float num3 = Mathf.Sqrt(((float)j - num2) * ((float)j - num2) + ((float)i - num2) * ((float)i - num2));
					float num4 = Mathf.Clamp01(num - num3 + 0.5f);
					val.SetPixel(j, i, new Color(1f, 1f, 1f, num4));
				}
			}
			val.Apply();
			_circle = Sprite.Create(val, new Rect(0f, 0f, 96f, 96f), new Vector2(0.5f, 0.5f));
			((Object)_circle).hideFlags = (HideFlags)61;
			return _circle;
		}

		internal static void Tick()
		{
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Expected O, but got Unknown
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < _nextTick)
			{
				return;
			}
			_nextTick = Time.unscaledTime + 0.25f;
			try
			{
				bool flag = false;
				for (int num = Entries.Count - 1; num >= 0; num--)
				{
					if ((Object)(object)Entries[num].root == (Object)null)
					{
						Entries.RemoveAt(num);
					}
					else if (Entries[num].root.activeInHierarchy)
					{
						flag = true;
					}
				}
				if (!flag)
				{
					return;
				}
				int head;
				int torso;
				int legs;
				bool inWalk = PlayerPalette.TryGetActualLook(out head, out torso, out legs);
				PreviewLook previewLook = ((ModSettingsApi.PreviewLookProvider != null) ? ModSettingsApi.PreviewLookProvider() : new PreviewLook
				{
					Head = -1,
					Torso = -1,
					Legs = -1
				});
				Color c = PartColor(inWalk, head, previewLook.Head, FallbackHead);
				Color c2 = PartColor(inWalk, torso, previewLook.Torso, FallbackTorso);
				Color c3 = PartColor(inWalk, legs, previewLook.Legs, FallbackLegs);
				string text = "";
				if (ModSettingsApi.PreviewGlyphProvider != null)
				{
					try
					{
						text = ModSettingsApi.PreviewGlyphProvider() ?? "";
					}
					catch
					{
						text = "";
					}
				}
				foreach (Entry entry in Entries)
				{
					if (!((Object)(object)entry.root == (Object)null) && entry.root.activeInHierarchy)
					{
						Tint(entry.head, c);
						Tint(entry.tuft, c);
						Tint(entry.chest, c2);
						Tint(entry.handL, c2);
						Tint(entry.handR, c2);
						Tint(entry.armL, c2);
						Tint(entry.armR, c2);
						Tint(entry.body, c3);
						Tint(entry.footL, c3);
						Tint(entry.footR, c3);
						Tint(entry.legL, c3);
						Tint(entry.legR, c3);
						if ((Object)(object)entry.mood != (Object)null && ((TMP_Text)entry.mood).text != text)
						{
							((TMP_Text)entry.mood).text = text;
						}
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					bool flag2 = default(bool);
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(31, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Character preview tick failed: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val);
				}
			}
		}

		private static void Tint(Image img, Color c)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)img != (Object)null && ((Graphic)img).color != c)
			{
				((Graphic)img).color = c;
			}
		}

		private static Color PartColor(bool inWalk, int actualId, int rowValue, Color fallback)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			Color? val = (inWalk ? PlayerPalette.PaletteDisplayColor(actualId) : ((Color?)null));
			if (!val.HasValue)
			{
				val = PlayerPalette.PaletteDisplayColor(rowValue);
			}
			return val ?? fallback;
		}
	}
	public static class HudTintApi
	{
		public static readonly Color DefaultDarkIcon = new Color(0.13f, 0.13f, 0.15f);

		private static readonly Dictionary<int, (Graphic g, Color c)> HudGraphics = new Dictionary<int, (Graphic, Color)>();

		private static readonly Dictionary<int, (Renderer r, string prop, Color c)> HudRenderers = new Dictionary<int, (Renderer, string, Color)>();

		private static readonly Dictionary<int, (SpriteRenderer r, Color c)> HudSprites = new Dictionary<int, (SpriteRenderer, Color)>();

		private static string _activeId;

		private static Func<Color?> _activeTint;

		private static Action _activePreempted;

		private static bool _arbitrating;

		private static readonly Dictionary<int, bool> StaticHudVerdict = new Dictionary<int, bool>();

		private static float _nextTick;

		private static readonly string[] ColorPropsFallback = new string[3] { "_BaseColor", "_Color", "_TintColor" };

		private static readonly Dictionary<int, string[]> ShaderColorProps = new Dictionary<int, string[]>();

		private static MaterialPropertyBlock _mpb;

		public static void Claim(string claimantId, Func<Color?> tint, Action onPreempted)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			if (string.IsNullOrEmpty(claimantId) || _arbitrating)
			{
				return;
			}
			try
			{
				_arbitrating = true;
				if (_activeId != null && _activeId != claimantId)
				{
					Action activePreempted = _activePreempted;
					try
					{
						activePreempted?.Invoke();
					}
					catch (Exception ex)
					{
						ManualLogSource log = ModSettingsApi.Log;
						if (log != null)
						{
							bool flag = default(bool);
							BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(28, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral("HUD preempt handler failed: ");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
							}
							log.LogWarning(val);
						}
					}
				}
				_activeId = claimantId;
				_activeTint = tint;
				_activePreempted = onPreempted;
				RestoreHud();
				ApplyHud();
			}
			finally
			{
				_arbitrating = false;
			}
		}

		public static void Release(string claimantId)
		{
			if (_activeId != null && !(_activeId != claimantId))
			{
				_activeId = null;
				_activeTint = null;
				_activePreempted = null;
				RestoreHud();
			}
		}

		public static bool IsClaimed(string claimantId)
		{
			return _activeId == claimantId;
		}

		public static bool IsHudOwned(Graphic g)
		{
			if ((Object)(object)g == (Object)null)
			{
				return false;
			}
			int instanceID = ((Object)g).GetInstanceID();
			if (HudGraphics.ContainsKey(instanceID))
			{
				return true;
			}
			if (StaticHudVerdict.TryGetValue(instanceID, out var value))
			{
				return value;
			}
			value = false;
			try
			{
				Transform val = ((Component)g).transform;
				while ((Object)(object)val != (Object)null)
				{
					string name = ((Object)val).name;
					if (!string.IsNullOrEmpty(name))
					{
						if ((Object)(object)((Component)val).GetComponent<SettingsRow>() != (Object)null || (Object)(object)((Component)val).GetComponent<SettingsMenu>() != (Object)null)
						{
							break;
						}
						name = name.ToLowerInvariant();
						if (name.Contains("crosshair") || name.Contains("armhud") || name.Contains("reticle"))
						{
							value = true;
							break;
						}
					}
					val = val.parent;
				}
			}
			catch
			{
			}
			StaticHudVerdict[instanceID] = value;
			return value;
		}

		internal static void Tick()
		{
			if (_activeId == null || Time.unscaledTime < _nextTick)
			{
				return;
			}
			_nextTick = Time.unscaledTime + 0.2f;
			try
			{
				ApplyHud();
			}
			catch
			{
			}
		}

		private static Color CurrentTint()
		{
			//IL_002a: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			if (_activeTint != null)
			{
				try
				{
					Color? val = _activeTint();
					if (val.HasValue)
					{
						return val.Value;
					}
				}
				catch
				{
				}
			}
			return DefaultDarkIcon;
		}

		private static IEnumerable<Transform> CrosshairRoots()
		{
			Crosshair ch;
			try
			{
				ch = Crosshair.instance;
			}
			catch
			{
				ch = null;
			}
			if (ch != null)
			{
				if ((Object)(object)ch.crosshairNormal != (Object)null)
				{
					yield return ch.crosshairNormal;
				}
				if ((Object)(object)ch.crosshairHolding != (Object)null)
				{
					yield return ch.crosshairHolding;
				}
				if ((Object)(object)ch.crosshairWindup != (Object)null)
				{
					yield return (Transform)(object)ch.crosshairWindup;
				}
				if ((Object)(object)ch.wings != (Object)null)
				{
					yield return ch.wings;
				}
			}
		}

		private static ArmHud SafeArmHud(bool hudLikely)
		{
			if (!hudLikely)
			{
				return null;
			}
			try
			{
				return ArmHud.instance;
			}
			catch
			{
				return null;
			}
		}

		private static IEnumerable<Transform> EnumerateHudRoots()
		{
			bool hudLikely = false;
			foreach (Transform item in CrosshairRoots())
			{
				hudLikely = true;
				yield return item;
			}
			PlayerCharacter val = PlayerPalette.FindLocalPlayer();
			if ((Object)(object)val != (Object)null && val.highlighter != null && (Object)(object)val.highlighter.inWorldCrosshair != (Object)null)
			{
				yield return val.highlighter.inWorldCrosshair;
			}
			ArmHud arm = SafeArmHud(hudLikely);
			if (arm == null)
			{
				yield break;
			}
			foreach (Image item2 in ArmHudImages(arm))
			{
				if ((Object)(object)item2 != (Object)null)
				{
					yield return ((Component)item2).transform;
				}
			}
			if ((Object)(object)arm.backpackEmpty != (Object)null)
			{
				yield return arm.backpackEmpty;
			}
			if ((Object)(object)arm.backpackFull != (Object)null)
			{
				yield return arm.backpackFull;
			}
			if ((Object)(object)arm.holsterEmpty != (Object)null)
			{
				yield return arm.holsterEmpty;
			}
			if ((Object)(object)arm.holsterFull != (Object)null)
			{
				yield return arm.holsterFull;
			}
		}

		private static IEnumerable<Image> ArmHudImages(ArmHud arm)
		{
			if (arm != null)
			{
				SingleArmHud[] array = (SingleArmHud[])(object)new SingleArmHud[2] { arm.armHudLeft, arm.armHudRight };
				foreach (SingleArmHud side in array)
				{
					yield return side.waving;
					yield return side.wavingLocked;
					yield return side.wavingLockRing;
					yield return side.airplane;
					yield return side.airplaneLocked;
					yield return side.airplaneLockRing;
				}
			}
		}

		private static string[] ColorPropsFor(Material mat)
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)mat == (Object)null || (Object)(object)mat.shader == (Object)null)
			{
				return Array.Empty<string>();
			}
			int instanceID = ((Object)mat.shader).GetInstanceID();
			if (ShaderColorProps.TryGetValue(instanceID, out var value))
			{
				return value;
			}
			List<string> list = new List<string>();
			List<string> list2 = new List<string>();
			bool flag = default(bool);
			ManualLogSource log;
			try
			{
				int propertyCount = mat.shader.GetPropertyCount();
				for (int i = 0; i < propertyCount; i++)
				{
					if ((int)mat.shader.GetPropertyType(i) != 0)
					{
						continue;
					}
					string propertyName = mat.shader.GetPropertyName(i);
					if (!string.IsNullOrEmpty(propertyName))
					{
						if (propertyName.ToLowerInvariant().Contains("emiss"))
						{
							list2.Add(propertyName);
						}
						else
						{
							list.Add(propertyName);
						}
					}
				}
			}
			catch (Exception ex)
			{
				log = ModSettingsApi.Log;
				if (log != null)
				{
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(36, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Shader property scan failed for '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)mat.shader).name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val);
				}
			}
			if (list.Count == 0)
			{
				string[] colorPropsFallback = ColorPropsFallback;
				foreach (string text in colorPropsFallback)
				{
					if (mat.HasProperty(text))
					{
						list.Add(text);
					}
				}
			}
			if (list.Count == 0 && list2.Count > 0)
			{
				list.AddRange(list2);
			}
			string[] array = list.ToArray();
			ShaderColorProps[instanceID] = array;
			log = ModSettingsApi.Log;
			if (log != null)
			{
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(34, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[HUD] shader '");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)mat.shader).name);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' color properties: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>((array.Length != 0) ? string.Join(", ", array) : "(none)");
				}
				log.LogInfo(val2);
			}
			return array;
		}

		internal static void ApplyHud()
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			if (_activeId == null)
			{
				return;
			}
			try
			{
				Color val = CurrentTint();
				foreach (Transform item in EnumerateHudRoots())
				{
					TintSubtree(item, val);
				}
				Color val2 = default(Color);
				foreach (Graphic previewGraphic in ModSettingsApi.PreviewGraphics)
				{
					if (!((Object)(object)previewGraphic == (Object)null))
					{
						int instanceID = ((Object)previewGraphic).GetInstanceID();
						if (!HudGraphics.ContainsKey(instanceID))
						{
							HudGraphics[instanceID] = (previewGraphic, previewGraphic.color);
						}
						((Color)(ref val2))..ctor(val.r, val.g, val.b, HudGraphics[instanceID].c.a);
						if (previewGraphic.color != val2)
						{
							previewGraphic.color = val2;
						}
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(17, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("ApplyHud failed: ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val3);
				}
			}
		}

		private static void TintSubtree(Transform root, Color tint)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: 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_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Expected O, but got Unknown
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			Color val2 = default(Color);
			foreach (Graphic componentsInChild in ((Component)root).GetComponentsInChildren<Graphic>(true))
			{
				int instanceID = ((Object)componentsInChild).GetInstanceID();
				Color val;
				if (HudGraphics.TryGetValue(instanceID, out (Graphic, Color) value))
				{
					val = value.Item2;
				}
				else
				{
					val = componentsInChild.color;
					HudGraphics[instanceID] = (componentsInChild, val);
				}
				((Color)(ref val2))..ctor(tint.r, tint.g, tint.b, val.a);
				if (componentsInChild.color != val2)
				{
					componentsInChild.color = val2;
				}
			}
			Color val4 = default(Color);
			Color val6 = default(Color);
			foreach (Renderer componentsInChild2 in ((Component)root).GetComponentsInChildren<Renderer>(true))
			{
				try
				{
					SpriteRenderer val3 = ((Il2CppObjectBase)componentsInChild2).TryCast<SpriteRenderer>();
					if ((Object)(object)val3 != (Object)null)
					{
						int instanceID2 = ((Object)componentsInChild2).GetInstanceID();
						if (!HudSprites.ContainsKey(instanceID2))
						{
							HudSprites[instanceID2] = (val3, val3.color);
						}
						((Color)(ref val4))..ctor(tint.r, tint.g, tint.b, HudSprites[instanceID2].c.a);
						if (val3.color != val4)
						{
							val3.color = val4;
						}
					}
					Material material = componentsInChild2.material;
					if ((Object)(object)material == (Object)null)
					{
						continue;
					}
					string[] array = ColorPropsFor(material);
					if (array.Length == 0)
					{
						continue;
					}
					string text = array[0];
					int instanceID3 = ((Object)componentsInChild2).GetInstanceID();
					Color val5;
					if (HudRenderers.TryGetValue(instanceID3, out (Renderer, string, Color) value2))
					{
						val5 = value2.Item3;
					}
					else
					{
						val5 = material.GetColor(text);
						HudRenderers[instanceID3] = (componentsInChild2, text, val5);
					}
					((Color)(ref val6))..ctor(tint.r, tint.g, tint.b, val5.a);
					if (material.GetColor(text) != val6)
					{
						string[] array2 = array;
						foreach (string text2 in array2)
						{
							material.SetColor(text2, val6);
						}
					}
					if (_mpb == null)
					{
						_mpb = new MaterialPropertyBlock();
					}
					componentsInChild2.GetPropertyBlock(_mpb);
					if (_mpb.GetColor(text) != val6)
					{
						string[] array2 = array;
						foreach (string text3 in array2)
						{
							_mpb.SetColor(text3, val6);
						}
						componentsInChild2.SetPropertyBlock(_mpb);
					}
				}
				catch
				{
				}
			}
		}

		private static void RestoreHud()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			foreach (var value in HudGraphics.Values)
			{
				try
				{
					if ((Object)(object)value.g != (Object)null)
					{
						value.g.color = value.c;
					}
				}
				catch
				{
				}
			}
			foreach (var value2 in HudRenderers.Values)
			{
				try
				{
					if (!((Object)(object)value2.r == (Object)null) && !((Object)(object)value2.r.material == (Object)null))
					{
						string[] array = ColorPropsFor(value2.r.material);
						string[] array2 = array;
						foreach (string text in array2)
						{
							value2.r.material.SetColor(text, value2.c);
						}
						if (_mpb == null)
						{
							_mpb = new MaterialPropertyBlock();
						}
						value2.r.GetPropertyBlock(_mpb);
						array2 = array;
						foreach (string text2 in array2)
						{
							_mpb.SetColor(text2, value2.c);
						}
						value2.r.SetPropertyBlock(_mpb);
					}
				}
				catch
				{
				}
			}
			foreach (var value3 in HudSprites.Values)
			{
				try
				{
					if ((Object)(object)value3.r != (Object)null)
					{
						value3.r.color = value3.c;
					}
				}
				catch
				{
				}
			}
			HudGraphics.Clear();
			HudRenderers.Clear();
			HudSprites.Clear();
		}
	}
	[HarmonyPatch]
	internal static class MenuInjector
	{
		private static readonly HashSet<int> InjectedInstances = new HashSet<int>();

		private static readonly List<SettingsRow> CreatedRows = new List<SettingsRow>();

		private static readonly Dictionary<int, Color> BaseLabelColors = new Dictionary<int, Color>();

		private static readonly HashSet<int> OpenSettingsMenus = new HashSet<int>();

		private static int _reapplyFramesLeft;

		private static readonly List<(GameObject button, SettingsMenu menu, SettingsCatagory cat)> ModsButtons = new List<(GameObject, SettingsMenu, SettingsCatagory)>();

		private const string ModsNoteBase = "Big Walk has no anti-cheat, and these mods\ndon't change how the game plays. ♥";

		private static readonly List<(GameObject note, SettingsCatagory cat, SettingsMenu menu)> ModsNotes = new List<(GameObject, SettingsCatagory, SettingsMenu)>();

		private static readonly List<(GameObject root, SettingsCatagory cat)> CategoryPanels = new List<(GameObject, SettingsCatagory)>();

		private const float RowHeightBudget = 860f;

		private const float MinRowHeight = 58f;

		private const float MaxRowHeight = 96f;

		private static string _vanillaLeftGlyph;

		private static string _vanillaRightGlyph;

		internal static bool AnySettingsMenuOpen => OpenSettingsMenus.Count > 0;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SettingsWardrobe), "GetHangerBySettingsType")]
		private static bool GetHanger_Prefix(SettingsType settingsType, ref ISettingsHanger __result)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected I4, but got Unknown
			if (!RowRegistry.IsModRow(settingsType))
			{
				return true;
			}
			if (RowRegistry.TryGet((int)settingsType, out var def))
			{
				__result = ((Il2CppObjectBase)def.GetOrCreateHanger()).Cast<ISettingsHanger>();
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SettingsHelper), "GetArrayLabelValue")]
		private static bool GetArrayLabel_Prefix(SettingsType settingsType, int value, ref DisplayType displayType, ref string __result)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected I4, but got Unknown
			if (!RowRegistry.IsModRow(settingsType))
			{
				return true;
			}
			if (RowRegistry.TryGet((int)settingsType, out var def))
			{
				displayType = (DisplayType)1;
				__result = ((def.LabelFor != null) ? def.LabelFor(value) : value.ToString());
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SettingsRow), "Refresh")]
		private static bool RowRefresh_Prefix(SettingsRow __instance)
		{
			//IL_0001: 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_001e: Expected I4, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			try
			{
				if (!RowRegistry.IsModRow(__instance.settingsType))
				{
					return true;
				}
				if (!RowRegistry.TryGet((int)__instance.settingsType, out var def))
				{
					return true;
				}
				if (def.Kind != ModRowKind.Slider)
				{
					return true;
				}
				SyncSliderRow(__instance, def);
				return false;
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(27, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Row refresh prefix failed: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val);
				}
				return true;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SettingsRow), "Refresh")]
		private static void RowRefresh_Postfix(SettingsRow __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected I4, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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)
			try
			{
				if (!RowRegistry.IsModRow(__instance.settingsType) || !RowRegistry.TryGet((int)__instance.settingsType, out var def) || def.Kind == ModRowKind.Slider)
				{
					return;
				}
				if (def.UseDiscrete)
				{
					SyncDiscreteRow(__instance, def);
					return;
				}
				ShowArrows(__instance);
				SetArrowGlyphs(__instance);
				if (def.LabelColorFor == null || (Object)(object)__instance.arrayLabel == (Object)null)
				{
					return;
				}
				TMP_Text val = __instance.arrayLabel.textElement ?? ((Component)__instance.arrayLabel).GetComponent<TMP_Text>();
				if (!((Object)(object)val == (Object)null))
				{
					int instanceID = ((Object)val).GetInstanceID();
					if (!BaseLabelColors.ContainsKey(instanceID))
					{
						BaseLabelColors[instanceID] = ((Graphic)val).color;
					}
					((Graphic)val).color = (Color)(((??)def.LabelColorFor(def.Value)) ?? BaseLabelColors[instanceID]);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(28, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Row refresh postfix failed: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val2);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SettingsMenu), "OnDisable")]
		private static void SettingsMenuOnDisable_Postfix(SettingsMenu __instance)
		{
			try
			{
				OpenSettingsMenus.Remove(((Object)__instance).GetInstanceID());
			}
			catch
			{
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SettingsMenu), "OnEnable")]
		private static void SettingsMenuOnEnable_Postfix(SettingsMenu __instance)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			try
			{
				OpenSettingsMenus.Add(((Object)__instance).GetInstanceID());
				if (RowRegistry.RowOrder.Count != 0)
				{
					if (InjectedInstances.Add(((Object)__instance).GetInstanceID()))
					{
						Inject(__instance);
					}
					NotifyMenuOpened();
					HarvestVanillaArrowGlyphs(__instance);
					RefreshModRows();
					RequestRowReapply();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(33, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("sMods category injection failed: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
					}
					log.LogError(val);
				}
			}
		}

		private static void NotifyMenuOpened()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			bool flag = default(bool);
			foreach (Action item in RowRegistry.MenuOpened)
			{
				try
				{
					item();
				}
				catch (Exception ex)
				{
					ManualLogSource log = ModSettingsApi.Log;
					if (log != null)
					{
						BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(29, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("OnMenuOpened handler failed: ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
						}
						log.LogWarning(val);
					}
				}
			}
		}

		internal static void RefreshModRowsPublic()
		{
			RefreshModRows();
		}

		internal static void RequestRowReapply()
		{
			_reapplyFramesLeft = 6;
		}

		internal static void TickRowReapply()
		{
			if (_reapplyFramesLeft <= 0)
			{
				return;
			}
			_reapplyFramesLeft--;
			try
			{
				RefreshModRows();
			}
			catch
			{
			}
		}

		internal static void HandleSelectionChanged(GameObject selected)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			bool flag = default(bool);
			for (int num = ModsButtons.Count - 1; num >= 0; num--)
			{
				(GameObject, SettingsMenu, SettingsCatagory) tuple = ModsButtons[num];
				if ((Object)(object)tuple.Item1 == (Object)null || (Object)(object)tuple.Item2 == (Object)null || (Object)(object)tuple.Item3 == (Object)null)
				{
					ModsButtons.RemoveAt(num);
				}
				else if (((Object)tuple.Item1).GetInstanceID() == ((Object)selected).GetInstanceID())
				{
					try
					{
						tuple.Item2.PressCatagoryButton(tuple.Item3);
						break;
					}
					catch (Exception ex)
					{
						ManualLogSource log = ModSettingsApi.Log;
						if (log != null)
						{
							BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(33, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Selecting sMods category failed: ");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
							}
							log.LogWarning(val);
						}
						break;
					}
				}
			}
		}

		internal static void RegisterCategoryPanel(GameObject root, SettingsCatagory cat)
		{
			root.SetActive(false);
			CategoryPanels.Add((root, cat));
		}

		private static string ComposeNoteText()
		{
			List<(int, string)> list = new List<(int, string)>();
			foreach (var noteLine in RowRegistry.NoteLines)
			{
				int item = noteLine.order;
				Func<string> item2 = noteLine.line;
				string text = null;
				try
				{
					text = item2();
				}
				catch
				{
				}
				if (!string.IsNullOrEmpty(text))
				{
					list.Add((item, text));
				}
			}
			list.Sort(((int order, string text) a, (int order, string text) b) => a.order.CompareTo(b.order));
			StringBuilder stringBuilder = new StringBuilder();
			foreach (var item4 in list)
			{
				string item3 = item4.Item2;
				stringBuilder.Append(item3).Append('\n');
			}
			stringBuilder.Append("Big Walk has no anti-cheat, and these mods\ndon't change how the game plays. ♥");
			return stringBuilder.ToString();
		}

		private static void CreateModsNote(SettingsMenu menu, SettingsCatagory modsCat)
		{
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Expected O, but got Unknown
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			bool flag = default(bool);
			try
			{
				VersionDisplay componentInChildren = ((Component)menu).GetComponentInChildren<VersionDisplay>(true);
				if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren.textField == (Object)null)
				{
					ManualLogSource log = ModSettingsApi.Log;
					if (log != null)
					{
						log.LogWarning((object)"VersionDisplay not found; skipping sMods note");
					}
					return;
				}
				GameObject gameObject = ((Component)componentInChildren).gameObject;
				GameObject val = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
				((Object)val).name = "ModsNote";
				VersionDisplay component = val.GetComponent<VersionDisplay>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
				}
				foreach (LocalizedText componentsInChild in val.GetComponentsInChildren<LocalizedText>(true))
				{
					Object.Destroy((Object)(object)componentsInChild);
				}
				RectTransform component2 = gameObject.GetComponent<RectTransform>();
				RectTransform component3 = val.GetComponent<RectTransform>();
				if ((Object)(object)component2 != (Object)null && (Object)(object)component3 != (Object)null)
				{
					component3.anchoredPosition = component2.anchoredPosition + new Vector2(0f, -125f);
					component3.sizeDelta = new Vector2(Mathf.Max(component2.sizeDelta.x, 420f), 170f);
				}
				TMP_Text val2 = val.GetComponent<TMP_Text>() ?? val.GetComponentInChildren<TMP_Text>(true);
				if ((Object)(object)val2 != (Object)null)
				{
					val2.text = ComposeNoteText();
					val2.richText = true;
					val2.enableWordWrapping = true;
					val2.alignment = (TextAlignmentOptions)260;
					val2.overflowMode = (TextOverflowModes)0;
				}
				val.SetActive(false);
				ModsNotes.Add((val, modsCat, menu));
				if ((Object)(object)ModSettingsApi.MenuGlyphFont == (Object)null)
				{
					ModSettingsApi.MenuGlyphFont = FindRowLabelFont(menu);
				}
				ModPanelContext obj = new ModPanelContext(val, modsCat, menu);
				List<(int, Action<ModPanelContext>)> list = new List<(int, Action<ModPanelContext>)>(RowRegistry.PanelProviders);
				list.Sort(((int order, Action<ModPanelContext> build) a, (int order, Action<ModPanelContext> build) b) => a.order.CompareTo(b.order));
				foreach (var (num, action) in list)
				{
					try
					{
						action(obj);
					}
					catch (Exception ex)
					{
						ManualLogSource log2 = ModSettingsApi.Log;
						if (log2 != null)
						{
							BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(32, 2, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Panel provider (order ");
								((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(num);
								((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(") failed: ");
								((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
							}
							log2.LogWarning(val3);
						}
					}
				}
				ManualLogSource log3 = ModSettingsApi.Log;
				if (log3 != null)
				{
					log3.LogInfo((object)"sMods note created under the settings heading");
				}
			}
			catch (Exception ex2)
			{
				ManualLogSource log2 = ModSettingsApi.Log;
				if (log2 != null)
				{
					BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(28, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Creating sMods note failed: ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex2.Message);
					}
					log2.LogWarning(val3);
				}
			}
		}

		private static TMP_FontAsset FindRowLabelFont(SettingsMenu menu)
		{
			try
			{
				if ((Object)(object)menu == (Object)null)
				{
					return null;
				}
				Il2CppArrayBase<SettingsRow> componentsInChildren = ((Component)menu).GetComponentsInChildren<SettingsRow>(true);
				if (componentsInChildren == null)
				{
					return null;
				}
				foreach (SettingsRow item in componentsInChildren)
				{
					if (!((Object)(object)item == (Object)null) && !((Object)(object)item.arrayLabel == (Object)null))
					{
						TMP_Text val = ((Component)item.arrayLabel).GetComponent<TMP_Text>();
						if ((Object)(object)val == (Object)null)
						{
							val = ((Component)item.arrayLabel).GetComponentInChildren<TMP_Text>(true);
						}
						if ((Object)(object)val != (Object)null && (Object)(object)val.font != (Object)null)
						{
							return val.font;
						}
					}
				}
			}
			catch
			{
			}
			return null;
		}

		internal static void UpdateModsNote(SettingsCatagory activeCatagory)
		{
			for (int num = ModsNotes.Count - 1; num >= 0; num--)
			{
				(GameObject, SettingsCatagory, SettingsMenu) tuple = ModsNotes[num];
				if ((Object)(object)tuple.Item1 == (Object)null || (Object)(object)tuple.Item2 == (Object)null)
				{
					ModsNotes.RemoveAt(num);
				}
				else
				{
					try
					{
						bool flag = (Object)(object)activeCatagory != (Object)null && ((Object)activeCatagory).GetInstanceID() == ((Object)tuple.Item2).GetInstanceID();
						if (flag)
						{
							TMP_Text val = tuple.Item1.GetComponent<TMP_Text>() ?? tuple.Item1.GetComponentInChildren<TMP_Text>(true);
							if ((Object)(object)val != (Object)null)
							{
								string text = ComposeNoteText();
								if (val.text != text)
								{
									val.text = text;
								}
							}
						}
						if (tuple.Item1.activeSelf != flag)
						{
							tuple.Item1.SetActive(flag);
						}
					}
					catch
					{
					}
				}
			}
			for (int num2 = CategoryPanels.Count - 1; num2 >= 0; num2--)
			{
				var (val2, val3) = CategoryPanels[num2];
				if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
				{
					CategoryPanels.RemoveAt(num2);
				}
				else
				{
					try
					{
						bool flag2 = (Object)(object)activeCatagory != (Object)null && ((Object)activeCatagory).GetInstanceID() == ((Object)val3).GetInstanceID();
						if (val2.activeSelf != flag2)
						{
							val2.SetActive(flag2);
						}
					}
					catch
					{
					}
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SettingsMenu), "SwapToCatagory")]
		private static void SwapToCatagory_Postfix(SettingsCatagory newCatagory)
		{
			UpdateModsNote(newCatagory);
			foreach (var modsNote in ModsNotes)
			{
				if (!((Object)(object)modsNote.cat == (Object)null) && !((Object)(object)newCatagory == (Object)null) && ((Object)modsNote.cat).GetInstanceID() == ((Object)newCatagory).GetInstanceID())
				{
					if ((Object)(object)modsNote.menu != (Object)null)
					{
						HarvestVanillaArrowGlyphs(modsNote.menu);
					}
					RefreshModRows();
					RequestRowReapply();
				}
			}
		}

		private static bool IsDiscreteLabel(SettingsRow row, LocalizedText lt)
		{
			try
			{
				TMP_Text[] array = (TMP_Text[])(object)new TMP_Text[3] { row.label0, row.label1, row.label2 };
				foreach (TMP_Text val in array)
				{
					if (!((Object)(object)val == (Object)null))
					{
						if ((Object)(object)lt.textElement != (Object)null && ((Object)lt.textElement).GetInstanceID() == ((Object)val).GetInstanceID())
						{
							return true;
						}
						if (((Object)((Component)lt).gameObject).GetInstanceID() == ((Object)((Component)val).gameObject).GetInstanceID())
						{
							return true;
						}
					}
				}
			}
			catch
			{
			}
			return false;
		}

		private static void ShowArrows(SettingsRow row)
		{
			try
			{
				ShowArrow(row.leftButton);
				ShowArrow(row.rightButton);
			}
			catch
			{
			}
		}

		private static void ShowArrow(Button button)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_010b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)button == (Object)null)
			{
				return;
			}
			((Component)button).gameObject.SetActive(true);
			foreach (CanvasGroup componentsInChild in ((Component)button).GetComponentsInChildren<CanvasGroup>(true))
			{
				componentsInChild.alpha = 1f;
			}
			foreach (Graphic componentsInChild2 in ((Component)button).GetComponentsInChildren<Graphic>(true))
			{
				Color color = componentsInChild2.color;
				if ((Object)(object)((Il2CppObjectBase)componentsInChild2).TryCast<TMP_Text>() != (Object)null)
				{
					if (color.a < 0.99f)
					{
						componentsInChild2.color = new Color(color.r, color.g, color.b, 1f);
					}
					continue;
				}
				Image val = ((Il2CppObjectBase)componentsInChild2).TryCast<Image>();
				if ((Object)(object)val != (Object)null && (Object)(object)val.sprite == (Object)null)
				{
					if (!((Object)componentsInChild2).name.ToLowerInvariant().Contains("highlight") && color.a > 0.001f)
					{
						componentsInChild2.color = new Color(color.r, color.g, color.b, 0f);
					}
				}
				else if (color.a < 0.99f)
				{
					componentsInChild2.color = new Color(color.r, color.g, color.b, 1f);
				}
			}
		}

		private static void RefreshModRows()
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected I4, but got Unknown
			CreatedRows.RemoveAll((SettingsRow r) => (Object)(object)r == (Object)null);
			bool flag = default(bool);
			foreach (SettingsRow createdRow in CreatedRows)
			{
				try
				{
					if (RowRegistry.TryGet((int)createdRow.settingsType, out var def) && def.Kind == ModRowKind.Slider)
					{
						SyncSliderRow(createdRow, def);
					}
					else
					{
						createdRow.Refresh();
					}
				}
				catch (Exception ex)
				{
					ManualLogSource log = ModSettingsApi.Log;
					if (log != null)
					{
						BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(27, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Row refresh failed for '");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)createdRow).name);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
						}
						log.LogWarning(val);
					}
				}
			}
		}

		private static void ConfigureSliderRow(SettingsRow row, ModRowDef def)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			Slider slider = row.slider;
			if ((Object)(object)slider == (Object)null)
			{
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(36, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Slider template has no slider for '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(def.Title);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
					}
					log.LogWarning(val);
				}
				return;
			}
			slider.minValue = def.SliderMin;
			slider.maxValue = def.SliderMax;
			slider.wholeNumbers = true;
			slider.onValueChanged = new SliderEvent();
			((UnityEvent<float>)(object)slider.onValueChanged).AddListener(UnityAction<float>.op_Implicit((Action<float>)delegate(float f)
			{
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Expected O, but got Unknown
				//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ec: Expected O, but got Unknown
				bool flag2 = default(bool);
				try
				{
					int num = Mathf.RoundToInt(f / 5f) * 5;
					num = Mathf.Clamp(num, def.SliderMin, def.SliderMax);
					SettingsHanger orCreateHanger = def.GetOrCreateHanger();
					if (orCreateHanger.value != num)
					{
						orCreateHanger.value = num;
						orCreateHanger.Save();
						try
						{
							def.OnApply?.Invoke(num);
						}
						catch (Exception ex)
						{
							ManualLogSource log2 = ModSettingsApi.Log;
							if (log2 != null)
							{
								BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(17, 2, ref flag2);
								if (flag2)
								{
									((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[");
									((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(def.Title);
									((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("] apply failed: ");
									((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
								}
								log2.LogError(val2);
							}
						}
						UpdateSliderLabel(row, def);
					}
				}
				catch (Exception ex2)
				{
					ManualLogSource log2 = ModSettingsApi.Log;
					if (log2 != null)
					{
						BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(22, 1, ref flag2);
						if (flag2)
						{
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Slider change failed: ");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex2.Message);
						}
						log2.LogWarning(val3);
					}
				}
			}));
			SyncSliderRow(row, def);
		}

		private static void SyncSliderRow(SettingsRow row, ModRowDef def)
		{
			if (!((Object)(object)row.slider == (Object)null))
			{
				row.slider.SetValueWithoutNotify((float)def.Value);
				UpdateSliderLabel(row, def);
			}
		}

		private static void UpdateSliderLabel(SettingsRow row, ModRowDef def)
		{
			if (!((Object)(object)row.sliderLabel == (Object)null))
			{
				string text = ((def.LabelFor != null) ? def.LabelFor(def.Value) : def.Value.ToString());
				SetLiteral(row.sliderLabel, text);
			}
		}

		private static void CompressRowLayout(Transform rowParent, List<SettingsRow> rows)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				int count = rows.Count;
				VerticalLayoutGroup component = ((Component)rowParent).GetComponent<VerticalLayoutGroup>();
				float num = Mathf.Clamp(860f / (float)Mathf.Max(count, 1), 58f, 96f);
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(31, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Row height target: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(num, "F0");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("px for ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(count);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" rows");
					}
					log.LogInfo(val);
				}
				if ((Object)(object)component != (Object)null)
				{
					((HorizontalOrVerticalLayoutGroup)component).childControlHeight = true;
					((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight = false;
					((LayoutGroup)component).childAlignment = (TextAnchor)1;
				}
				foreach (SettingsRow row in rows)
				{
					if (!((Object)(object)row == (Object)null))
					{
						LayoutElement obj = ((Component)row).GetComponent<LayoutElement>() ?? ((Component)row).gameObject.AddComponent<LayoutElement>();
						obj.minHeight = num;
						obj.preferredHeight = num;
						obj.flexibleHeight = 0f;
						RectTransform component2 = ((Component)row).GetComponent<RectTransform>();
						if ((Object)(object)component2 != (Object)null)
						{
							component2.SetSizeWithCurrentAnchors((Axis)1, num);
						}
					}
				}
				if ((Object)(object)component != (Object)null)
				{
					((LayoutGroup)component).SetLayoutVertical();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(26, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CompressRowLayout failed: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val2);
				}
			}
		}

		private static SettingsRow FindArrayTemplate(SettingsMenu menu)
		{
			SettingsCatagory[] array = (SettingsCatagory[])(object)new SettingsCatagory[4] { menu.catagoryGraphics, menu.catagoryAudio, menu.catagoryGeneral, menu.catagoryControls };
			foreach (SettingsCatagory val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				foreach (SettingsRow componentsInChild in ((Component)val).GetComponentsInChildren<SettingsRow>(true))
				{
					if ((Object)(object)componentsInChild.leftButton != (Object)null && (Object)(object)componentsInChild.rightButton != (Object)null && (Object)(object)componentsInChild.arrayLabel != (Object)null && (Object)(object)componentsInChild.slider == (Object)null)
					{
						return componentsInChild;
					}
				}
			}
			return null;
		}

		private static SettingsRow FindDiscreteTemplate(SettingsMenu menu)
		{
			SettingsCatagory[] array = (SettingsCatagory[])(object)new SettingsCatagory[4] { menu.catagoryGraphics, menu.catagoryGeneral, menu.catagoryControls, menu.catagoryAudio };
			foreach (SettingsCatagory val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				foreach (SettingsRow componentsInChild in ((Component)val).GetComponentsInChildren<SettingsRow>(true))
				{
					if ((Object)(object)componentsInChild.label0 != (Object)null && (Object)(object)componentsInChild.label1 != (Object)null && (Object)(object)componentsInChild.slider == (Object)null && (Object)(object)componentsInChild.leftButton == (Object)null)
					{
						return componentsInChild;
					}
				}
			}
			return null;
		}

		private static void SyncDiscreteRow(SettingsRow row, ModRowDef def)
		{
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				List<TMP_Text> list = new List<TMP_Text>();
				TMP_Text[] array = (TMP_Text[])(object)new TMP_Text[3] { row.label0, row.label1, row.label2 };
				foreach (TMP_Text val in array)
				{
					if ((Object)(object)val != (Object)null)
					{
						list.Add(val);
					}
				}
				list.Sort(delegate(TMP_Text a, TMP_Text b)
				{
					//IL_001f: 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)
					RectTransform component = ((Component)a).GetComponent<RectTransform>();
					RectTransform component2 = ((Component)b).GetComponent<RectTransform>();
					float num2 = (((Object)(object)component != (Object)null) ? component.anchoredPosition.x : 0f);
					float value = (((Object)(object)component2 != (Object)null) ? component2.anchoredPosition.x : 0f);
					return num2.CompareTo(value);
				});
				int[] possibleValues = def.PossibleValues;
				for (int num = 0; num < list.Count; num++)
				{
					TMP_Text val2 = list[num];
					if (!((Object)(object)val2 == (Object)null))
					{
						if (possibleValues == null || num >= possibleValues.Length)
						{
							((Component)val2).gameObject.SetActive(false);
							continue;
						}
						((Component)val2).gameObject.SetActive(true);
						val2.text = ((def.LabelFor != null) ? def.LabelFor(possibleValues[num]) : possibleValues[num].ToString());
						bool flag = def.Value == possibleValues[num];
						val2.fontStyle = (FontStyles)(flag ? (val2.fontStyle | 4) : (val2.fontStyle & -5));
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					bool flag2 = default(bool);
					BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(33, 2, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Discrete row sync failed for '");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(def.Title);
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("': ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val3);
				}
			}
		}

		private static void HarvestVanillaArrowGlyphs(SettingsMenu menu)
		{
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Expected O, but got Unknown
			if (!string.IsNullOrEmpty(_vanillaLeftGlyph) && !string.IsNullOrEmpty(_vanillaRightGlyph))
			{
				return;
			}
			bool flag = default(bool);
			try
			{
				SettingsCatagory[] array = (SettingsCatagory[])(object)new SettingsCatagory[4] { menu.catagoryGeneral, menu.catagoryGraphics, menu.catagoryAudio, menu.catagoryControls };
				foreach (SettingsCatagory val in array)
				{
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					foreach (SettingsRow componentsInChild in ((Component)val).GetComponentsInChildren<SettingsRow>(true))
					{
						if ((Object)(object)componentsInChild.leftButton == (Object)null || (Object)(object)componentsInChild.rightButton == (Object)null || RowRegistry.IsModRow(componentsInChild.settingsType))
						{
							continue;
						}
						TMP_Text val2 = FirstText(componentsInChild.leftButton);
						TMP_Text val3 = FirstText(componentsInChild.rightButton);
						if (!((Object)(object)val2 != (Object)null) || !((Object)(object)val3 != (Object)null) || string.IsNullOrEmpty(val2.text) || string.IsNullOrEmpty(val3.text) || !(val2.text != "<") || !(val3.text != ">"))
						{
							continue;
						}
						_vanillaLeftGlyph = val2.text;
						_vanillaRightGlyph = val3.text;
						ManualLogSource log = ModSettingsApi.Log;
						if (log != null)
						{
							BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(41, 3, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Arrow glyphs harvested from '");
								((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(((Object)componentsInChild).name);
								((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("': L='");
								((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(_vanillaLeftGlyph);
								((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("' R='");
								((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(_vanillaRightGlyph);
								((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("'");
							}
							log.LogInfo(val4);
						}
						return;
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					BepInExWarningLogInterpolatedStringHandler val5 = new BepInExWarningLogInterpolatedStringHandler(28, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Arrow glyph harvest failed: ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val5);
				}
			}
		}

		private static TMP_Text FirstText(Button button)
		{
			foreach (Graphic componentsInChild in ((Component)button).GetComponentsInChildren<Graphic>(true))
			{
				TMP_Text val = ((Il2CppObjectBase)componentsInChild).TryCast<TMP_Text>();
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		private static void SetArrowGlyphs(SettingsRow row)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			try
			{
				TMP_FontAsset val = (((Object)(object)row.arrayLabel != (Object)null && (Object)(object)row.arrayLabel.textElement != (Object)null) ? row.arrayLabel.textElement.font : null);
				bool flag = !string.IsNullOrEmpty(_vanillaLeftGlyph) && !string.IsNullOrEmpty(_vanillaRightGlyph);
				ApplyGlyph(row.leftButton, flag ? _vanillaLeftGlyph : "<", flag ? null : val);
				ApplyGlyph(row.rightButton, flag ? _vanillaRightGlyph : ">", flag ? null : val);
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					bool flag2 = default(bool);
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(27, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Arrow glyph assign failed: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val2);
				}
			}
		}

		private static void ApplyGlyph(Button button, string glyph, TMP_FontAsset overrideFont)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)button == (Object)null)
			{
				return;
			}
			TMP_Text val = FirstText(button);
			if (!((Object)(object)val == (Object)null))
			{
				if ((Object)(object)overrideFont != (Object)null)
				{
					val.font = overrideFont;
				}
				if (val.text != glyph)
				{
					val.text = glyph;
				}
				Color color = ((Graphic)val).color;
				if (color.a < 0.99f)
				{
					((Graphic)val).color = new Color(color.r, color.g, color.b, 1f);
				}
			}
		}

		private static SettingsRow FindSliderTemplate(SettingsMenu menu)
		{
			SettingsCatagory[] array = (SettingsCatagory[])(object)new SettingsCatagory[4] { menu.catagoryAudio, menu.catagoryGraphics, menu.catagoryGeneral, menu.catagoryControls };
			foreach (SettingsCatagory val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				foreach (SettingsRow componentsInChild in ((Component)val).GetComponentsInChildren<SettingsRow>(true))
				{
					if ((Object)(object)componentsInChild.slider != (Object)null && (Object)(object)componentsInChild.leftButton == (Object)null)
					{
						return componentsInChild;
					}
				}
			}
			return null;
		}

		private static void Inject(SettingsMenu menu)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_06c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cf: Expected O, but got Unknown
			//IL_071c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0726: Expected O, but got Unknown
			//IL_07a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ac: Expected O, but got Unknown
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Expected O, but got Unknown
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Expected O, but got Unknown
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e3: Expected O, but got Unknown
			//IL_064c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0651: Unknown result type (might be due to invalid IL or missing references)
			//IL_0653: Unknown result type (might be due to invalid IL or missing references)
			//IL_0669: Unknown result type (might be due to invalid IL or missing references)
			//IL_0670: Expected O, but got Unknown
			//IL_0623: Unknown result type (might be due to invalid IL or missing references)
			//IL_062a: Unknown result type (might be due to invalid IL or missing references)
			//IL_062f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0634: Unknown result type (might be due to invalid IL or missing references)
			//IL_0684: Unknown result type (might be due to invalid IL or missing references)
			//IL_069c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0644: Unknown result type (might be due to invalid IL or missing references)
			//IL_0646: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource log = ModSettingsApi.Log;
			ManualLogSource val = log;
			bool flag = default(bool);
			if (val != null)
			{
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(57, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Injecting sMods category into SettingsMenu '");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)((Component)menu).gameObject).name);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' (mainMenu=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<bool>(menu.isInMainMenu);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(")");
				}
				val.LogInfo(val2);
			}
			RowRegistry.Injected = true;
			SettingsCatagory catagoryGeneral = menu.catagoryGeneral;
			SettingsCatagory catagoryControls = menu.catagoryControls;
			SettingsCatagory catagoryRebind = menu.catagoryRebind;
			if ((Object)(object)catagoryGeneral == (Object)null || (Object)(object)catagoryRebind == (Object)null)
			{
				if (log != null)
				{
					log.LogError((object)"catagoryGeneral/catagoryRebind missing; aborting injection");
				}
				return;
			}
			GameObject val3 = Object.Instantiate<GameObject>(((Component)catagoryGeneral).gameObject, ((Component)catagoryGeneral).transform.parent);
			((Object)val3).name = "CatagoryMods";
			val3.SetActive(false);
			SettingsCatagory modsCat = val3.GetComponent<SettingsCatagory>();
			Il2CppArrayBase<SettingsRow> componentsInChildren = val3.GetComponentsInChildren<SettingsRow>(true);
			if (componentsInChildren == null || componentsInChildren.Length == 0)
			{
				if (log != null)
				{
					log.LogError((object)"No SettingsRow children found in cloned category; aborting");
				}
				Object.Destroy((Object)(object)val3);
				return;
			}
			SettingsRow val4 = null;
			SettingsRow val5 = null;
			foreach (SettingsRow item in componentsInChildren)
			{
				if ((Object)(object)val4 == (Object)null && (Object)(object)item.leftButton != (Object)null && (Object)(object)item.rightButton != (Object)null && (Object)(object)item.arrayLabel != (Object)null)
				{
					val4 = item;
				}
				if ((Object)(object)val5 == (Object)null && (Object)(object)item.boringButton != (Object)null)
				{
					val5 = item;
				}
			}
			SettingsRow val6 = FindArrayTemplate(menu) ?? val4;
			SettingsRow val7 = FindSliderTemplate(menu);
			val = log;
			if (val != null)
			{
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(34, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Templates: array=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)(object)val6 != (Object)null) ? ((Object)val6).name : "NONE");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", slider=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)(object)val7 != (Object)null) ? ((Object)val7).name : "NONE");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", reset=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)(object)val5 != (Object)null) ? ((Object)val5).name : "NONE");
				}
				val.LogInfo(val2);
			}
			if ((Object)(object)val6 == (Object)null || (Object)(object)val4 == (Object)null)
			{
				if (log != null)
				{
					log.LogError((object)"No array row template found; aborting");
				}
				Object.Destroy((Object)(object)val3);
				return;
			}
			Transform parent = ((Component)val4).transform.parent;
			int siblingIndex = ((Component)val4).transform.GetSiblingIndex();
			List<SettingsRow> list = new List<SettingsRow>();
			SettingsRow val8 = FindDiscreteTemplate(menu);
			val = log;
			if (val != null)
			{
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(19, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Discrete template: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)(object)val8 != (Object)null) ? ((Object)val8).name : "NONE");
				}
				val.LogInfo(val2);
			}
			foreach (ModRowDef item2 in RowRegistry.Ordered())
			{
				SettingsRow val9 = ((item2.Kind == ModRowKind.Slider && (Object)(object)val7 != (Object)null) ? val7 : ((!item2.UseDiscrete || !((Object)(object)val8 != (Object)null)) ? val6 : val8));
				GameObject obj = Object.Instantiate<GameObject>(((Component)val9).gameObject, parent);
				((Object)obj).name = $"ModRow_{item2.SettingsTypeId}";
				obj.transform.SetSiblingIndex(siblingIndex + list.Count);
				SettingsRow component = obj.GetComponent<SettingsRow>();
				component.settingsType = (SettingsType)item2.SettingsTypeId;
				component.saveSelf = true;
				component.wrap = true;
				if (item2.UseDiscrete && (Object)(object)val8 != (Object)null)
				{
					SyncDiscreteRow(component, item2);
				}
				else if (item2.Kind != ModRowKind.Slider)
				{
					ShowArrows(component);
					SetArrowGlyphs(component);
				}
				RetitleRow(component, item2.Title);
				if (item2.Kind == ModRowKind.Slider)
				{
					ConfigureSliderRow(component, item2);
				}
				list.Add(component);
				CreatedRows.Add(component);
			}
			foreach (SettingsRow item3 in componentsInChildren)
			{
				if ((Object)(object)item3 == (Object)null)
				{
					continue;
				}
				if ((Object)(object)val5 != (Object)null && ((Object)item3).GetInstanceID() == ((Object)val5).GetInstanceID())
				{
					((Component)val5).transform.SetAsLastSibling();
					if ((Object)(object)val5.boringButton != (Object)null)
					{
						val5.boringButton.onClick = new ButtonClickedEvent();
						((UnityEvent)val5.boringButton.onClick).AddListener(UnityAction.op_Implicit((Action)ResetAllModRows));
					}
				}
				else
				{
					Object.Destroy((Object)(object)((Component)item3).gameObject);
				}
			}
			List<SettingsRow> list2 = new List<SettingsRow>(list);
			if ((Object)(object)val5 != (Object)null)
			{
				list2.Add(val5);
			}
			modsCat.rows = new Il2CppReferenceArray<SettingsRow>(list2.ToArray());
			CompressRowLayout(parent, list2);
			Selectable catagoryButton = catagoryRebind.catagoryButton;
			if ((Object)(object)catagoryButton == (Object)null)
			{
				if (log != null)
				{
					log.LogError((object)"Rebinding category button missing; aborting button creation");
				}
				return;
			}
			GameObject val10 = Object.Instantiate<GameObject>(((Component)catagoryButton).gameObject, ((Component)catagoryButton).transform.parent);
			((Object)val10).name = "ButtonMods";
			val10.transform.SetSiblingIndex(((Component)catagoryButton).transform.GetSiblingIndex() + 1);
			try
			{
				RectTransform component2 = ((Component)catagoryButton).GetComponent<RectTransform>();
				RectTransform component3 = val10.GetComponent<RectTransform>();
				Vector2 val11 = default(Vector2);
				((Vector2)(ref val11))..ctor(0f, -70f);
				if ((Object)(object)catagoryControls != (Object)null && (Object)(object)catagoryControls.catagoryButton != (Object)null)
				{
					RectTransform component4 = ((Component)catagoryControls.catagoryButton).GetComponent<RectTransform>();
					Vector2 val12 = component2.anchoredPosition - component4.anchoredPosition;
					if (((Vector2)(ref val12)).sqrMagnitude > 0.01f)
					{
						val11 = val12;
					}
				}
				component3.anchoredPosition = component2.anchoredPosition + val11;
				val = log;
				if (val != null)
				{
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(31, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("sMods button placed at ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Vector2>(component3.anchoredPosition);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (step ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Vector2>(val11);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(")");
					}
					val.LogInfo(val2);
				}
			}
			catch (Exception ex)
			{
				val = log;
				if (val != null)
				{
					BepInExWarningLogInterpolatedStringHandler val13 = new BepInExWarningLogInterpolatedStringHandler(27, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val13).AppendLiteral("Button positioning failed: ");
						((BepInExLogInterpolatedStringHandler)val13).AppendFormatted<string>(ex.Message);
					}
					val.LogWarning(val13);
				}
			}
			RelabelTexts(val10, "sMods");
			Button component5 = val10.GetComponent<Button>();
			modsCat.catagoryButton = (Selectable)(object)component5;
			component5.onClick = new ButtonClickedEvent();
			((UnityEvent)component5.onClick).AddListener(UnityAction.op_Implicit((Action)delegate
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Expected O, but got Unknown
				try
				{
					menu.PressCatagoryButton(modsCat);
				}
				catch (Exception ex2)
				{
					ManualLogSource log2 = ModSettingsApi.Log;
					if (log2 != null)
					{
						bool flag2 = default(bool);
						BepInExErrorLogInterpolatedStringHandler val14 = new BepInExErrorLogInterpolatedStringHandler(28, 1, ref flag2);
						if (flag2)
						{
							((BepInExLogInterpolatedStringHandler)val14).AppendLiteral("PressCatagoryButton failed: ");
							((BepInExLogInterpolatedStringHandler)val14).AppendFormatted<Exception>(ex2);
						}
						log2.LogError(val14);
					}
				}
			}));
			if (menu.buttonList != null)
			{
				menu.buttonList.Add(component5);
			}
			ModsButtons.Add((val10, menu, modsCat));
			CreateModsNote(menu, modsCat);
			FixNavigation(catagoryButton, (Selectable)(object)component5);
			val = log;
			if (val != null)
			{
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(36, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("sMods category injected with ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(list.Count);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" row(s)");
				}
				val.LogInfo(val2);
			}
		}

		private static void RetitleRow(SettingsRow row, string title)
		{
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Expected O, but got Unknown
			bool flag = false;
			int num = (((Object)(object)row.arrayLabel != (Object)null) ? ((Object)row.arrayLabel).GetInstanceID() : 0);
			int num2 = (((Object)(object)row.sliderLabel != (Object)null) ? ((Object)row.sliderLabel).GetInstanceID() : 0);
			int num3 = (((Object)(object)row.title != (Object)null) ? ((Object)row.title).GetInstanceID() : 0);
			foreach (LocalizedText componentsInChild in ((Component)row).GetComponentsInChildren<LocalizedText>(true))
			{
				if (((Object)componentsInChild).GetInstanceID() != num && ((Object)componentsInChild).GetInstanceID() != num2 && !((Object)(object)((Component)componentsInChild).GetComponentInParent<Button>() != (Object)null) && !IsDiscreteLabel(row, componentsInChild))
				{
					if (((Object)componentsInChild).GetInstanceID() == num3 || ((Object)componentsInChild).name == "Title" || (componentsInChild.key != null && componentsInChild.key.StartsWith("SETTINGS_")))
					{
						SetLiteral(componentsInChild, title);
						flag = true;
					}
					else
					{
						SetLiteral(componentsInChild, "");
					}
				}
			}
			if (flag)
			{
				return;
			}
			ManualLogSource log = ModSettingsApi.Log;
			if (log != null)
			{
				bool flag2 = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(33, 1, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("No title element found for row '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)row).name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
				}
				log.LogWarning(val);
			}
		}

		private static void RelabelTexts(GameObject go, string text)
		{
			bool flag = false;
			foreach (LocalizedText componentsInChild in go.GetComponentsInChildren<LocalizedText>(true))
			{
				SetLiteral(componentsInChild, text);
				flag = true;
			}
			if (!flag)
			{
				TMP_Text componentInChildren = go.GetComponentInChildren<TMP_Text>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.text = text;
				}
			}
		}

		private static void SetLiteral(LocalizedText lt, string text)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			try
			{
				lt.displayType = (DisplayType)1;
				lt.rawValue = text;
				if ((Object)(object)lt.textElement != (Object)null)
				{
					lt.textElement.text = text;
					return;
				}
				TMP_Text component = ((Component)lt).GetComponent<TMP_Text>();
				if ((Object)(object)component != (Object)null)
				{
					component.text = text;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(25, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("SetLiteral failed on '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)lt).name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val);
				}
			}
		}

		private static void FixNavigation(Selectable above, Selectable inserted)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			try
			{
				Navigation navigation = above.navigation;
				Selectable selectOnDown = navigation.selectOnDown;
				Navigation navigation2 = inserted.navigation;
				navigation2.selectOnUp = above;
				navigation2.selectOnDown = selectOnDown;
				inserted.navigation = navigation2;
				navigation.selectOnDown = inserted;
				above.navigation = navigation;
				if ((Object)(object)selectOnDown != (Object)null)
				{
					Navigation navigation3 = selectOnDown.navigation;
					navigation3.selectOnUp = inserted;
					selectOnDown.navigation = navigation3;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsApi.Log;
				if (log != null)
				{
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(25, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Navigation fixup failed: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val);
				}
			}
		}

		private static void ResetAllModRows()
		{
			foreach (ModRowDef item in RowRegistry.Ordered())
			{
				SettingsHanger orCreateHanger = item.GetOrCreateHanger();
				orCreateHanger.ResetToDefault();
				orCreateHanger.Save();
			}
			RefreshModRows();
			ManualLogSource log = ModSettingsApi.Log;
			if (log != null)
			{
				log.LogInfo((object)"Mod settings reset to defaults");
			}
		}
	}
	public class ModBootstrapper : MonoBehaviour
	{
		private float _applyAt = -1f;

		private bool _done;

		private static readonly HashSet<int> _appliedIds = new HashSet<int>();

		private static readonly Dictionary<int, int> _lastSeen = new Dictionary<int, int>();

		private static float _flushAt = -1f;

		private static float _nextPersistScan;

		private static float _nextLookPoll;

		private static (int h, int t, int l) _lastLook = (h: int.MinValue, t: 0, l: 0);

		public ModBootstrapper(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Update()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			if (_done)
			{
				bool flag = default(bool);
				foreach (Action ticker in RowRegistry.Tickers)
				{
					try
					{
						ticker();
					}
					catch (Exception ex)
					{
						ManualLogSource log = ModSettingsApi.Log;
						if (log != null)
						{
							BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(15, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Ticker failed: ");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
							}
							log.LogWarning(val);
						}
					}
				}
				HudTintApi.Tick();
				TickLookPoll();
				TickPersist();
				ApplyLateRegistrations();
			}
			else if (_applyAt < 0f)
			{
				_applyAt = Time.unscaledTime + 2f;
				PreloadSavedValues();
			}
			else if (!(Time.unscaledTime < _applyAt))
			{
				_done = true;
				ApplyAllSaved();
			}
		}

		private static void PreloadSavedValues()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			int num = 0;
			bool flag = default(bool);
			ManualLogSource log;
			foreach (ModRowDef item in RowRegistry.Ordered())
			{
				try
				{
					item.GetOrCreateHanger();
					num++;
				}
				catch (Exception ex)
				{
					log = ModSettingsApi.Log;