Decompiled source of UIEnhancements v0.0.5

UIEnhancements.dll

Decompiled 10 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DysonSphereProgram.Modding.UIEnhancements.UI.Builder;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("UIEnhancements")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+cfeda1093856cf9746ab70a9da992993de06e4f1")]
[assembly: AssemblyProduct("UIEnhancements")]
[assembly: AssemblyTitle("UIEnhancements")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	public record IsExternalInit;
}
namespace DysonSphereProgram.Modding.UIEnhancements
{
	public class EditableStationStorageMax : EnhancementBase
	{
		public static List<Text> patchedTexts = new List<Text>();

		public static List<InputField> patchedInputFields = new List<InputField>();

		public static ConfigEntry<int> sliderStep;

		public static ConfigEntry<int> sliderStepPercent;

		protected override string Name => "Editable Station Storage Max";

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIStationWindow), "_OnCreate")]
		public static void PatchStationWindow(ref UIStationWindow __instance)
		{
			for (int i = 0; i < __instance.storageUIs.Length; i++)
			{
				ref UIStationStorage reference = ref __instance.storageUIs[i];
				InputField item = PatchMaxValue(ref reference);
				patchedTexts.Add(reference.maxValueText);
				patchedInputFields.Add(item);
			}
		}

		private static InputField PatchMaxValue(ref UIStationStorage __instance)
		{
			UIStationStorage component = __instance;
			int result;
			DelegateDataBindSource<int, string> binding = new DelegateDataBindSource<int, string>(delegate
			{
				if (!Object.op_Implicit((Object)(object)component))
				{
					return 0;
				}
				if (component.station == null)
				{
					return 0;
				}
				return (component.index < component.station.storage.Length) ? component.station.storage[component.index].max : 0;
			}, delegate(int newMax)
			{
				if (Object.op_Implicit((Object)(object)component) && component.station != null && component.index < component.station.storage.Length && newMax >= 0)
				{
					component.station.storage[component.index].max = newMax;
				}
			}, DataBindTransform.From((int x) => x.ToString(), (string x) => (!int.TryParse(x, out result)) ? (-1) : result));
			TextBoxToInputField.CreateInputFieldFromText(__instance.maxValueText, out var inputFieldContext, delegate(InputFieldContext context)
			{
				context.WithAnchor(Anchor.StretchRight).OfSize(50, -6).Bind(binding);
			});
			((Component)__instance.maxValueText).gameObject.SetActive(false);
			return inputFieldContext.inputField;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIStationStorage), "RefreshValues")]
		public static void PatchStationStorageRefreshValues(ref UIStationStorage __instance)
		{
			if (__instance.station != null && __instance.index < __instance.station.storage.Length)
			{
				ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)__instance.stationWindow.factory.entityPool[__instance.station.entityId].protoId);
				__instance.maxSlider.maxValue = val.prefabDesc.stationMaxItemCount + __instance.GetAdditionStorage();
				__instance.maxSlider.value = __instance.station.storage[__instance.index].max;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIStationStorage), "OnMaxSliderValueChange")]
		public static void InterceptSliderValueChange(ref UIStationStorage __instance, ref float val)
		{
			if (__instance.station != null && __instance.index < __instance.station.storage.Length && (int)val != __instance.station.storage[__instance.index].max && (int)val != (int)__instance.maxSlider.maxValue)
			{
				int num = sliderStep.Value;
				if (sliderStepPercent.Value != 0)
				{
					num = (int)__instance.maxSlider.maxValue * sliderStepPercent.Value / 100;
				}
				val -= (int)val % num;
			}
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(UIStationStorage), "RefreshValues")]
		public static IEnumerable<CodeInstruction> PatchRefreshValues(IEnumerable<CodeInstruction> code, ILGenerator generator)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(code, generator);
			val.SearchForward((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Calls(ci, AccessTools.PropertySetter(typeof(Slider), "value"))));
			int pos = val.Pos;
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdarg(ci, (int?)0)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.LoadsField(ci, AccessTools.Field(typeof(UIStationStorage), "maxSlider"), false)), (string)null)
			});
			int pos2 = val.Pos;
			val.RemoveInstructionsInRange(pos2, pos);
			val.Start();
			val.SearchForward((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Calls(ci, AccessTools.PropertySetter(typeof(Slider), "maxValue"))));
			int pos3 = val.Pos;
			val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.IsLdarg(ci, (int?)0)), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.LoadsField(ci, AccessTools.Field(typeof(UIStationStorage), "maxSlider"), false)), (string)null)
			});
			int pos4 = val.Pos;
			val.RemoveInstructionsInRange(pos4, pos3);
			return val.InstructionEnumeration();
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(UIStationStorage), "OnMaxSliderValueChange")]
		public static IEnumerable<CodeInstruction> PatchMaxSliderValueChange(IEnumerable<CodeInstruction> code, ILGenerator generator)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(code, generator);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)100f, (string)null),
				new CodeMatch((OpCode?)OpCodes.Mul, (object)null, (string)null)
			});
			if (val.IsValid)
			{
				val.SetOperandAndAdvance((object)1f);
			}
			return val.InstructionEnumeration();
		}

		public static void ApplyPatch(Harmony harmony)
		{
			harmony.PatchAll(typeof(EditableStationStorageMax));
			if (Object.op_Implicit((Object)(object)UIRoot.instance) && Object.op_Implicit((Object)(object)UIRoot.instance.uiGame) && ((ManualBehaviour)UIRoot.instance.uiGame).created)
			{
				UIStationWindow __instance = UIRoot.instance.uiGame.stationWindow;
				PatchStationWindow(ref __instance);
			}
		}

		private static void RemovePatch()
		{
			foreach (Text patchedText in patchedTexts)
			{
				((Component)patchedText).gameObject.SetActive(true);
			}
			foreach (InputField patchedInputField in patchedInputFields)
			{
				Object.Destroy((Object)(object)((Component)patchedInputField).gameObject);
			}
			patchedTexts.Clear();
			patchedInputFields.Clear();
		}

		protected override void UseConfig(ConfigFile configFile)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			sliderStep = configFile.Bind<int>(base.ConfigSection, "Slider Step", 100, (ConfigDescription)null);
			sliderStepPercent = configFile.Bind<int>(base.ConfigSection, "Slider Step %", 0, new ConfigDescription("If this is non-zero, the slider step will be a percentage of the maximum", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		}

		protected override void Patch(Harmony _harmony)
		{
			ApplyPatch(_harmony);
		}

		protected override void Unpatch()
		{
			RemovePatch();
		}

		protected override void CreateUI()
		{
		}

		protected override void DestroyUI()
		{
		}
	}
	public abstract class EnhancementBase
	{
		public const string enhancementEnableDisableSection = "# Enable / Disable Enhancements";

		public ConfigEntry<bool> IsEnabled;

		protected abstract string Name { get; }

		protected string ConfigSection => "## " + Name;

		protected abstract void UseConfig(ConfigFile configFile);

		protected abstract void Patch(Harmony _harmony);

		protected abstract void Unpatch();

		protected abstract void CreateUI();

		protected abstract void DestroyUI();

		public void LifecycleUseConfig(ConfigFile configFile)
		{
			IsEnabled = configFile.Bind<bool>("# Enable / Disable Enhancements", Name, false, (ConfigDescription)null);
			UseConfig(configFile);
		}

		public void LifecyclePatch(Harmony _harmony)
		{
			if (!IsEnabled.Value)
			{
				return;
			}
			try
			{
				Patch(_harmony);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)ex);
			}
		}

		public void LifecycleUnpatch()
		{
			if (!IsEnabled.Value)
			{
				return;
			}
			try
			{
				Unpatch();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)ex);
			}
		}

		public void LifecycleCreateUI()
		{
			if (!IsEnabled.Value)
			{
				return;
			}
			try
			{
				CreateUI();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)ex);
			}
		}

		public void LifecycleDestroyUI()
		{
			if (!IsEnabled.Value)
			{
				return;
			}
			try
			{
				DestroyUI();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)ex);
			}
		}
	}
	public class HideGameTimeDisplay : EnhancementBase
	{
		private static GameObject gameTimeDisplay;

		protected override string Name => "Hide Game Time Display";

		protected override void UseConfig(ConfigFile configFile)
		{
		}

		protected override void Patch(Harmony _harmony)
		{
		}

		protected override void Unpatch()
		{
		}

		protected override void CreateUI()
		{
			gameTimeDisplay = ((Component)((Component)UIRoot.instance).GetComponentInChildren<UIFpsStat>(true).timeTextComp).gameObject;
			gameTimeDisplay.SetActive(false);
		}

		protected override void DestroyUI()
		{
			if (Object.op_Implicit((Object)(object)gameTimeDisplay))
			{
				gameTimeDisplay.SetActive(true);
			}
		}
	}
	public class HideRealTimeDisplay : EnhancementBase
	{
		private static GameObject realTimeDisplay;

		protected override string Name => "Hide Real Time Display";

		protected override void UseConfig(ConfigFile configFile)
		{
		}

		protected override void Patch(Harmony _harmony)
		{
		}

		protected override void Unpatch()
		{
		}

		protected override void CreateUI()
		{
			realTimeDisplay = ((Component)((Component)UIRoot.instance).GetComponentInChildren<UIFpsStat>(true).realTimeTextComp).gameObject;
			realTimeDisplay.SetActive(false);
		}

		protected override void DestroyUI()
		{
			if (Object.op_Implicit((Object)(object)realTimeDisplay))
			{
				realTimeDisplay.SetActive(true);
			}
		}
	}
	public class PartialOffscreenWindows : EnhancementBase
	{
		public static ConfigEntry<int> thresholdWidth;

		public static ConfigEntry<int> thresholdHeight;

		private static Vector2 thresholdVector => new Vector2((float)thresholdWidth.Value, (float)thresholdHeight.Value);

		protected override string Name => "Partial Off-screen Windows";

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(UIWindowDrag), "Update")]
		private static IEnumerable<CodeInstruction> PatchUpdate(IEnumerable<CodeInstruction> code, ILGenerator generator)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(code, generator);
			TranspilerHelpers.LocalHelper? minLocal = null;
			TranspilerHelpers.LocalHelper? maxLocal = null;
			val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Calls(ci, AccessTools.Method(typeof(UIRoot), "WorldToScreenPoint", (Type[])null, (Type[])null))), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => ci.StoresLocal(out minLocal)), (string)null)
			});
			if (val.IsInvalid)
			{
				Plugin.Log.LogDebug((object)"Invalid on the first stloc");
			}
			Plugin.Log.LogDebug((object)val.Opcode);
			Plugin.Log.LogDebug((object)val.Pos);
			val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Calls(ci, AccessTools.Method(typeof(UIRoot), "WorldToScreenPoint", (Type[])null, (Type[])null))), (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => ci.StoresLocal(out maxLocal)), (string)null)
			});
			if (val.IsInvalid)
			{
				Plugin.Log.LogDebug((object)"Invalid on the second stloc");
			}
			Plugin.Log.LogDebug((object)val.Opcode);
			Plugin.Log.LogDebug((object)val.Pos);
			val.Advance(1);
			Plugin.Log.LogDebug((object)minLocal);
			Plugin.Log.LogDebug((object)maxLocal);
			val.Insert((CodeInstruction[])(object)new CodeInstruction[3]
			{
				minLocal?.Ldloca(),
				maxLocal?.Ldloca(),
				CodeInstruction.Call(typeof(PartialOffscreenWindows), "AdjustWindowRectParams", (Type[])null, (Type[])null)
			});
			return val.InstructionEnumeration();
		}

		public static void AdjustWindowRectParams(ref Vector2 pos1, ref Vector2 pos2)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			if (pos1.x < pos2.x)
			{
				float x = pos2.x;
				pos2.x = pos1.x + thresholdVector.x;
				pos1.x = x - thresholdVector.x;
			}
			else
			{
				float x2 = pos1.x;
				pos1.x = pos2.x + thresholdVector.x;
				pos2.x = x2 - thresholdVector.x;
			}
			if (pos1.y > pos2.y)
			{
				float y = pos2.y;
				pos2.y = pos1.y - thresholdVector.y;
				pos1.y = y + thresholdVector.y;
			}
			else
			{
				float y2 = pos1.y;
				pos1.y = pos2.y - thresholdVector.y;
				pos2.y = y2 + thresholdVector.y;
			}
		}

		protected override void UseConfig(ConfigFile configFile)
		{
			thresholdWidth = configFile.Bind<int>(base.ConfigSection, "Threshold Width", 100, (ConfigDescription)null);
			thresholdHeight = configFile.Bind<int>(base.ConfigSection, "Threshold Height", 100, (ConfigDescription)null);
		}

		protected override void Patch(Harmony _harmony)
		{
			_harmony.PatchAll(typeof(PartialOffscreenWindows));
		}

		protected override void Unpatch()
		{
		}

		protected override void CreateUI()
		{
		}

		protected override void DestroyUI()
		{
		}
	}
	[BepInPlugin("dev.raptor.dsp.UIEnhancements", "UIEnhancements", "0.0.5")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "dev.raptor.dsp.UIEnhancements";

		public const string NAME = "UIEnhancements";

		public const string VERSION = "0.0.5";

		private Harmony _harmony;

		internal static ManualLogSource Log;

		internal List<EnhancementBase> enhancements = new List<EnhancementBase>();

		private void Awake()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			enhancements.Add(new EditableStationStorageMax());
			enhancements.Add(new UnrestrictedUIScaler());
			enhancements.Add(new PartialOffscreenWindows());
			enhancements.Add(new HideRealTimeDisplay());
			enhancements.Add(new HideGameTimeDisplay());
			enhancements.Add(new SwapNewGameAndContinue());
			_harmony = new Harmony("dev.raptor.dsp.UIEnhancements");
			enhancements.ForEach(delegate(EnhancementBase x)
			{
				x.LifecycleUseConfig(((BaseUnityPlugin)this).Config);
			});
			enhancements.ForEach(delegate(EnhancementBase x)
			{
				x.LifecyclePatch(_harmony);
			});
			UIBuilderPlugin.Create("dev.raptor.dsp.UIEnhancements", OnCreateUI);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"UIEnhancements Awake() called");
		}

		private void OnCreateUI()
		{
			enhancements.ForEach(delegate(EnhancementBase x)
			{
				x.LifecycleCreateUI();
			});
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"UIEnhancements OnDestroy() called");
			enhancements.ForEach(delegate(EnhancementBase x)
			{
				x.LifecycleDestroyUI();
			});
			enhancements.ForEach(delegate(EnhancementBase x)
			{
				x.LifecycleUnpatch();
			});
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			UIBuilderPlugin.Destroy();
			Log = null;
		}
	}
	public class SwapNewGameAndContinue : EnhancementBase
	{
		private float newGameOrigPosY;

		private float continueGameOrigPosY;

		protected override string Name => "Swap New Game and Continue";

		protected override void UseConfig(ConfigFile configFile)
		{
		}

		protected override void Patch(Harmony _harmony)
		{
		}

		protected override void Unpatch()
		{
		}

		protected override void CreateUI()
		{
			UIMainMenu uiMainMenu = UIRoot.instance.uiMainMenu;
			newGameOrigPosY = uiMainMenu.newGameRtPosY;
			continueGameOrigPosY = uiMainMenu.continueRtPosY;
			uiMainMenu.newGameRtPosY = continueGameOrigPosY;
			uiMainMenu.continueRtPosY = newGameOrigPosY;
		}

		protected override void DestroyUI()
		{
			UIMainMenu uiMainMenu = UIRoot.instance.uiMainMenu;
			uiMainMenu.newGameRtPosY = newGameOrigPosY;
			uiMainMenu.continueRtPosY = continueGameOrigPosY;
		}
	}
	public static class TranspilerHelpers
	{
		public readonly record struct LocalHelper(int localIdx)
		{
			public CodeInstruction Ldloc()
			{
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Expected O, but got Unknown
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Expected O, but got Unknown
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Expected O, but got Unknown
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Expected O, but got Unknown
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Expected O, but got Unknown
				int num = localIdx;
				if (num <= 127)
				{
					return (CodeInstruction)(num switch
					{
						0 => (object)new CodeInstruction(OpCodes.Ldloc_0, (object)null), 
						1 => (object)new CodeInstruction(OpCodes.Ldloc_1, (object)null), 
						2 => (object)new CodeInstruction(OpCodes.Ldloc_2, (object)null), 
						3 => (object)new CodeInstruction(OpCodes.Ldloc_3, (object)null), 
						_ => (object)new CodeInstruction(OpCodes.Ldloc_S, (object)(sbyte)localIdx), 
					});
				}
				return new CodeInstruction(OpCodes.Ldloc, (object)localIdx);
			}

			public CodeInstruction Ldloca()
			{
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Expected O, but got Unknown
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Expected O, but got Unknown
				if (localIdx <= 127)
				{
					return new CodeInstruction(OpCodes.Ldloca_S, (object)(sbyte)localIdx);
				}
				return new CodeInstruction(OpCodes.Ldloca, (object)localIdx);
			}

			public CodeInstruction Stloc()
			{
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Expected O, but got Unknown
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Expected O, but got Unknown
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Expected O, but got Unknown
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Expected O, but got Unknown
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Expected O, but got Unknown
				int num = localIdx;
				if (num <= 127)
				{
					return (CodeInstruction)(num switch
					{
						0 => (object)new CodeInstruction(OpCodes.Stloc_0, (object)null), 
						1 => (object)new CodeInstruction(OpCodes.Stloc_1, (object)null), 
						2 => (object)new CodeInstruction(OpCodes.Stloc_2, (object)null), 
						3 => (object)new CodeInstruction(OpCodes.Stloc_3, (object)null), 
						_ => (object)new CodeInstruction(OpCodes.Stloc_S, (object)(sbyte)localIdx), 
					});
				}
				return new CodeInstruction(OpCodes.Stloc, (object)localIdx);
			}
		}

		private static int GetLocalIdxFromOperand(object operand)
		{
			if (operand is LocalBuilder localBuilder)
			{
				return localBuilder.LocalIndex;
			}
			try
			{
				return Convert.ToInt32(operand);
			}
			catch (Exception)
			{
				Plugin.Log.LogError((object)("Failed to convert operand to int: " + operand));
				Plugin.Log.LogDebug((object)("The type of local operand is " + operand.GetType()));
				throw;
			}
		}

		public static bool LoadsLocal(this CodeInstruction code, out LocalHelper? local)
		{
			local = null;
			if (!CodeInstructionExtensions.IsLdloc(code, (LocalBuilder)null))
			{
				return false;
			}
			if (code.opcode == OpCodes.Ldloc_0)
			{
				local = new LocalHelper(0);
			}
			else if (code.opcode == OpCodes.Ldloc_1)
			{
				local = new LocalHelper(1);
			}
			else if (code.opcode == OpCodes.Ldloc_2)
			{
				local = new LocalHelper(2);
			}
			else if (code.opcode == OpCodes.Ldloc_3)
			{
				local = new LocalHelper(3);
			}
			else if (code.opcode == OpCodes.Ldloc_S || code.opcode == OpCodes.Ldloca_S)
			{
				local = new LocalHelper(GetLocalIdxFromOperand(code.operand));
			}
			else if (code.opcode == OpCodes.Ldloc || code.opcode == OpCodes.Ldloca)
			{
				local = new LocalHelper(GetLocalIdxFromOperand(code.operand));
			}
			return true;
		}

		public static bool StoresLocal(this CodeInstruction code, out LocalHelper? local)
		{
			local = null;
			if (!CodeInstructionExtensions.IsStloc(code, (LocalBuilder)null))
			{
				return false;
			}
			if (code.opcode == OpCodes.Stloc_0)
			{
				local = new LocalHelper(0);
			}
			else if (code.opcode == OpCodes.Stloc_1)
			{
				local = new LocalHelper(1);
			}
			else if (code.opcode == OpCodes.Stloc_2)
			{
				local = new LocalHelper(2);
			}
			else if (code.opcode == OpCodes.Stloc_3)
			{
				local = new LocalHelper(3);
			}
			else if (code.opcode == OpCodes.Stloc_S)
			{
				local = new LocalHelper(GetLocalIdxFromOperand(code.operand));
			}
			else if (code.opcode == OpCodes.Stloc)
			{
				local = new LocalHelper(GetLocalIdxFromOperand(code.operand));
			}
			return true;
		}
	}
	public static class TextBoxToInputField
	{
		public static void CreateInputFieldFromText(Text text, Action<InputFieldContext> initializer = null)
		{
			CreateInputFieldFromText(text, out var _, initializer);
		}

		public static void CreateInputFieldFromText(Text text, out InputFieldContext inputFieldContext, Action<InputFieldContext> initializer = null)
		{
			//IL_0013: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Component)text).transform.parent;
			RectTransform component = ((Component)text).GetComponent<RectTransform>();
			ColorBlock defaultColorBlock = ColorBlock.defaultColorBlock;
			((ColorBlock)(ref defaultColorBlock)).normalColor = Color.clear;
			Color white = Color.white;
			((ColorBlock)(ref defaultColorBlock)).highlightedColor = ((Color)(ref white)).AlphaMultiplied(0.1f);
			((ColorBlock)(ref defaultColorBlock)).pressedColor = Color.clear;
			((ColorBlock)(ref defaultColorBlock)).disabledColor = Color.clear;
			ColorBlock value = defaultColorBlock;
			InputFieldContext context = UIBuilderDSL.Create.InputField("input-field").ChildOf(parent).WithPivot(component.pivot)
				.WithMinMaxAnchor(component.anchorMin, component.anchorMax)
				.At(component.anchoredPosition)
				.OfSize(component.sizeDelta)
				.WithVisuals<InputFieldContext, Image>((IProperties<Image>)new ImageProperties());
			ColorBlock? colors = value;
			inputFieldContext = context.WithTransition(null, colors);
			IGraphicContextExtensions.WithColor(IGraphicContextExtensions.WithMaterial(UIBuilderDSL.Select.Text(inputFieldContext.text), ((Graphic)text).material), ((Graphic)text).color).WithFont(text.font).WithFontSize(text.fontSize, text.resizeTextForBestFit ? new int?(text.resizeTextMinSize) : null, text.resizeTextForBestFit ? new int?(text.resizeTextMaxSize) : null)
				.WithAlignment(text.alignment)
				.WithOverflow(text.horizontalOverflow, text.verticalOverflow);
			initializer?.Invoke(inputFieldContext);
		}
	}
	public class UnrestrictedUIScaler : EnhancementBase
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<Resolution, int> <>9__9_0;

			public static Func<Resolution, int> <>9__9_1;

			public static Func<Resolution, int> <>9__9_2;

			public static Func<Resolution, int> <>9__9_3;

			public static Func<int, float> <>9__9_4;

			public static Func<float, int> <>9__9_5;

			public static Action<Image> <>9__9_6;

			public static Func<int, string> <>9__9_7;

			public static Func<string, int> <>9__9_8;

			public static Action<CanvasScaler> <>9__9_12;

			public static Action<float> <>9__9_9;

			public static UnityAction <>9__9_10;

			public static UnityAction <>9__9_11;

			public static UnityAction <>9__9_13;

			internal int <CreateUI>b__9_0(Resolution x)
			{
				return ((Resolution)(ref x)).height;
			}

			internal int <CreateUI>b__9_1(Resolution x)
			{
				return ((Resolution)(ref x)).width;
			}

			internal int <CreateUI>b__9_2(Resolution x)
			{
				return ((Resolution)(ref x)).height;
			}

			internal int <CreateUI>b__9_3(Resolution x)
			{
				return ((Resolution)(ref x)).width;
			}

			internal float <CreateUI>b__9_4(int x)
			{
				return x;
			}

			internal int <CreateUI>b__9_5(float x)
			{
				return (int)x;
			}

			internal void <CreateUI>b__9_6(Image x)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				((Graphic)x).color = new Color(0.13f, 0.18f, 0.2f, 1f);
			}

			internal string <CreateUI>b__9_7(int x)
			{
				return x.ToString();
			}

			internal int <CreateUI>b__9_8(string x)
			{
				if (!int.TryParse(x, out var result))
				{
					return 900;
				}
				return result;
			}

			internal void <CreateUI>b__9_12(CanvasScaler scaler)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				int height = ((Resolution)(ref DSPGame.globalOption.resolution)).height;
				scaler.referenceResolution = new Vector2((float)height, (float)height);
			}

			internal void <CreateUI>b__9_9(float value)
			{
				UICanvasScalerHandler.uiLayoutHeight = (int)value;
			}

			internal void <CreateUI>b__9_10()
			{
				((Component)uiScaleSliderCanvas).gameObject.SetActive(false);
				restoreUiLayoutHeight = null;
			}

			internal void <CreateUI>b__9_11()
			{
				((Component)uiScaleSliderCanvas).gameObject.SetActive(false);
				if (restoreUiLayoutHeight.HasValue)
				{
					UICanvasScalerHandler.uiLayoutHeight = restoreUiLayoutHeight.Value;
					restoreUiLayoutHeight = null;
				}
			}

			internal void <CreateUI>b__9_13()
			{
				restoreUiLayoutHeight = UICanvasScalerHandler.uiLayoutHeight;
				uiScale.Value = restoreUiLayoutHeight.Value;
				((Component)uiScaleSliderCanvas).gameObject.SetActive(true);
			}
		}

		public static ConfigEntry<int> uiScale;

		public static Slider uiScaleSlider;

		public static Canvas uiScaleSliderCanvas;

		public static RectTransform vanillaUiSliderRectTransform;

		public static Button livePreviewButton;

		private static int? restoreUiLayoutHeight;

		protected override string Name => "Unrestricted UI Scaler";

		protected override void UseConfig(ConfigFile configFile)
		{
			uiScale = configFile.Bind<int>(base.ConfigSection, "UI Reference Height", 900, (ConfigDescription)null);
		}

		protected override void Patch(Harmony _harmony)
		{
			_harmony.PatchAll(typeof(UnrestrictedUIScaler));
		}

		protected override void Unpatch()
		{
		}

		protected override void CreateUI()
		{
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0498: Unknown result type (might be due to invalid IL or missing references)
			//IL_049d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: Expected O, but got Unknown
			//IL_0565: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_051b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0520: Unknown result type (might be due to invalid IL or missing references)
			//IL_0526: Expected O, but got Unknown
			//IL_06a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_06be: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_061d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0622: Unknown result type (might be due to invalid IL or missing references)
			//IL_0628: Expected O, but got Unknown
			if ((Object)(object)uiScaleSlider != (Object)null)
			{
				return;
			}
			int num = Screen.resolutions.Min((Resolution x) => ((Resolution)(ref x)).height);
			int num2 = Mathf.Min(Screen.resolutions.Min((Resolution x) => ((Resolution)(ref x)).width), num);
			int num3 = Screen.resolutions.Max((Resolution x) => ((Resolution)(ref x)).height);
			int num4 = Mathf.Max(Screen.resolutions.Max((Resolution x) => ((Resolution)(ref x)).width), num3);
			ConfigEntryDataBindSource<int, float> configEntryDataBindSource = new ConfigEntryDataBindSource<int, float>(uiScale, DataBindTransform.From((int x) => x, (float x) => (int)x));
			Image component;
			UIElementContext parent = UIBuilderDSL.Create.UIElement("slider-handle-container").WithComponent<UIElementContext, Image>(out component, (Action<Image>)delegate(Image x)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				((Graphic)x).color = new Color(0.13f, 0.18f, 0.2f, 1f);
			});
			ColorBlock defaultColorBlock = ColorBlock.defaultColorBlock;
			((ColorBlock)(ref defaultColorBlock)).normalColor = Color.clear;
			Color white = Color.white;
			((ColorBlock)(ref defaultColorBlock)).highlightedColor = ((Color)(ref white)).AlphaMultiplied(0.1f);
			((ColorBlock)(ref defaultColorBlock)).pressedColor = Color.clear;
			((ColorBlock)(ref defaultColorBlock)).disabledColor = Color.clear;
			ColorBlock value2 = defaultColorBlock;
			InputFieldContext context = UIBuilderDSL.Create.InputField("slider-handle-input-field").ChildOf(parent).WithAnchor(Anchor.Center)
				.OfSize(40, 20)
				.WithVisuals<InputFieldContext, Image>((IProperties<Image>)new ImageProperties
				{
					color = Color.white
				});
			ColorBlock? colors = value2;
			int result;
			InputFieldContext parent2 = context.WithTransition(null, colors).Bind(configEntryDataBindSource.WithTransform((int x) => x.ToString(), (string x) => (!int.TryParse(x, out result)) ? 900 : result));
			UIElementContext context2 = UIBuilderDSL.Create.UIElement("bg").ChildOf((UIElementContext)parent2).WithAnchor(Anchor.Stretch)
				.OfSize(0, 0);
			IProperties<Image>[] array = new IProperties<Image>[1];
			ImageProperties obj = new ImageProperties
			{
				raycastTarget = false,
				sprite = UIBuilder.spriteBorder1,
				type = (Type)1
			};
			white = Color.white;
			obj.color = ((Color)(ref white)).AlphaMultiplied(0.6f);
			array[0] = obj;
			context2.WithComponent<UIElementContext, Image>(out Image _, array);
			SliderHandleConfiguration value3 = new SliderHandleConfiguration(80f, 0.6f, component);
			SliderConfiguration configuration = new SliderConfiguration(num2, num4, wholeNumbers: true, (Direction)0, null, null, 6f, value3);
			Canvas overlayCanvas = UIRoot.instance.overlayCanvas;
			Transform parent3 = ((Component)overlayCanvas).transform.parent;
			UIBuilderDSL.Create.UIElement("ui-scale-slider-canvas").ChildOf(parent3).WithComponent<UIElementContext, CanvasScaler>((Action<CanvasScaler>)delegate(CanvasScaler scaler)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				int height = ((Resolution)(ref DSPGame.globalOption.resolution)).height;
				scaler.referenceResolution = new Vector2((float)height, (float)height);
			})
				.WithComponent<UIElementContext, Canvas>(out uiScaleSliderCanvas)
				.WithComponent<UIElementContext, GraphicRaycaster>(out GraphicRaycaster _);
			((Component)uiScaleSliderCanvas).gameObject.SetActive(false);
			uiScaleSliderCanvas.planeDistance = overlayCanvas.planeDistance;
			uiScaleSliderCanvas.renderMode = (RenderMode)0;
			uiScaleSliderCanvas.worldCamera = overlayCanvas.worldCamera;
			SliderContext context3 = UIBuilderDSL.Create.Slider("ui-scale-slider", configuration).ChildOf(((Component)uiScaleSliderCanvas).transform).WithMinMaxAnchor(new Vector2(0.1f, 1f), new Vector2(0.9f, 1f))
				.OfSize(0, 30)
				.At(0, 0)
				.Bind(configEntryDataBindSource);
			colors = UIBuilder.buttonSelectableProperties.colors;
			SliderValueChangedHandler component4;
			SliderContext sliderContext = context3.WithTransition(null, colors).WithComponent<SliderContext, SliderValueChangedHandler>(out component4);
			component4.slider = sliderContext.slider;
			component4.Handler = delegate(float value)
			{
				UICanvasScalerHandler.uiLayoutHeight = (int)value;
			};
			UIElementContext parent4 = UIBuilderDSL.Create.UIElement("btn-container").ChildOf(parent).WithAnchor(Anchor.Bottom)
				.WithPivot(0.5f, 1f)
				.At(0, -20);
			object obj2 = <>c.<>9__9_10;
			if (obj2 == null)
			{
				UnityAction val = delegate
				{
					((Component)uiScaleSliderCanvas).gameObject.SetActive(false);
					restoreUiLayoutHeight = null;
				};
				<>c.<>9__9_10 = val;
				obj2 = (object)val;
			}
			UIBuilderDSL.Create.Button("apply-btn", "Apply", (UnityAction)obj2).ChildOf(parent4).WithAnchor(Anchor.Right)
				.At(-5, 0)
				.OfSize(60, 25)
				.WithVisuals<ButtonContext, Image>((IProperties<Image>)UIBuilder.buttonImgProperties)
				.WithTransition(UIBuilder.buttonSelectableProperties.transition);
			object obj3 = <>c.<>9__9_11;
			if (obj3 == null)
			{
				UnityAction val2 = delegate
				{
					((Component)uiScaleSliderCanvas).gameObject.SetActive(false);
					if (restoreUiLayoutHeight.HasValue)
					{
						UICanvasScalerHandler.uiLayoutHeight = restoreUiLayoutHeight.Value;
						restoreUiLayoutHeight = null;
					}
				};
				<>c.<>9__9_11 = val2;
				obj3 = (object)val2;
			}
			ButtonContext context4 = UIBuilderDSL.Create.Button("cancel-btn", "Cancel", (UnityAction)obj3).ChildOf(parent4).WithAnchor(Anchor.Left)
				.At(5, 0)
				.OfSize(60, 25)
				.WithVisuals<ButtonContext, Image>((IProperties<Image>)GraphicPropertiesBuilder.WithColor(UIBuilder.buttonImgProperties, new Color(1f, 0.3f, 0.37f, 0.8471f)));
			Transition? transition = UIBuilder.buttonSelectableProperties.transition;
			colors = null;
			context4.WithTransition(transition, colors);
			uiScaleSlider = sliderContext.slider;
			vanillaUiSliderRectTransform = ((Component)UIRoot.instance.optionWindow.uiLayoutHeightComp).GetComponent<RectTransform>();
			Color white2 = Color.white;
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.4887f, 0.6525f, 0.7453f, 0.4886f);
			Color highlightedColor = default(Color);
			((Color)(ref highlightedColor))..ctor(0.4887f, 0.6525f, 0.7453f, 0.7255f);
			object obj4 = <>c.<>9__9_13;
			if (obj4 == null)
			{
				UnityAction val4 = delegate
				{
					restoreUiLayoutHeight = UICanvasScalerHandler.uiLayoutHeight;
					uiScale.Value = restoreUiLayoutHeight.Value;
					((Component)uiScaleSliderCanvas).gameObject.SetActive(true);
				};
				<>c.<>9__9_13 = val4;
				obj4 = (object)val4;
			}
			ButtonContext context5 = UIBuilderDSL.Create.Button("ui-scaler-activate-button", "Enable Live Preview", (UnityAction)obj4).ChildOf(((Transform)vanillaUiSliderRectTransform).parent).WithAnchor(Anchor.Left)
				.At(250, 0)
				.WithLayoutSize(120f, 30f)
				.WithContentSizeFitter((FitMode)2, (FitMode)2)
				.WithFontSize(14)
				.WithVisuals<ButtonContext, Image>((IProperties<Image>)new ImageProperties
				{
					color = white2
				});
			defaultColorBlock = ColorBlock.defaultColorBlock;
			((ColorBlock)(ref defaultColorBlock)).normalColor = val3;
			((ColorBlock)(ref defaultColorBlock)).pressedColor = val3;
			((ColorBlock)(ref defaultColorBlock)).disabledColor = val3;
			((ColorBlock)(ref defaultColorBlock)).highlightedColor = highlightedColor;
			colors = defaultColorBlock;
			ButtonContext buttonContext = context5.WithTransition(null, colors);
			buttonContext.text.resizeTextForBestFit = false;
			livePreviewButton = buttonContext.button;
			((Component)vanillaUiSliderRectTransform).gameObject.SetActive(false);
		}

		protected override void DestroyUI()
		{
			if ((Object)(object)uiScaleSlider != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)uiScaleSlider).gameObject);
				uiScaleSlider = null;
			}
			if ((Object)(object)uiScaleSliderCanvas != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)uiScaleSliderCanvas).gameObject);
				uiScaleSliderCanvas = null;
			}
			if ((Object)(object)vanillaUiSliderRectTransform != (Object)null)
			{
				((Component)vanillaUiSliderRectTransform).gameObject.SetActive(true);
				vanillaUiSliderRectTransform = null;
			}
			if ((Object)(object)livePreviewButton != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)livePreviewButton).gameObject);
				livePreviewButton = null;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameOption), "Apply")]
		public static void ApplyUIScaleAgain()
		{
			if (restoreUiLayoutHeight.HasValue)
			{
				UICanvasScalerHandler.uiLayoutHeight = restoreUiLayoutHeight.Value;
			}
			else
			{
				UICanvasScalerHandler.uiLayoutHeight = uiScale.Value;
			}
		}
	}
}
namespace DysonSphereProgram.Modding.UIEnhancements.UI.Builder
{
	public abstract class DataBindController<T> : MonoBehaviour
	{
		public IDataBindSource<T> Binding;

		protected bool ChangedFromUI;

		private void LateUpdate()
		{
			if (ChangedFromUI)
			{
				UIToBinding();
				ChangedFromUI = false;
			}
			else
			{
				BindingToUI();
			}
		}

		protected abstract void BindingToUI();

		protected abstract void UIToBinding();
	}
	public class DataBindSlider : DataBindController<float>
	{
		private Slider slider;

		private void Start()
		{
			slider = ((Component)this).GetComponent<Slider>();
			((UnityEvent<float>)(object)slider.onValueChanged).AddListener((UnityAction<float>)ValueChangedHandler);
		}

		private void ValueChangedHandler(float _)
		{
			ChangedFromUI = true;
		}

		protected override void BindingToUI()
		{
			slider.value = Binding.Value;
		}

		protected override void UIToBinding()
		{
			Binding.Value = slider.value;
		}
	}
	public class DataBindToggleBool : DataBindController<bool>
	{
		private Toggle toggle;

		private void Start()
		{
			toggle = ((Component)this).GetComponent<Toggle>();
			((UnityEvent<bool>)(object)toggle.onValueChanged).AddListener((UnityAction<bool>)ValueChangedHandler);
		}

		private void ValueChangedHandler(bool _)
		{
			ChangedFromUI = true;
		}

		protected override void BindingToUI()
		{
			toggle.isOn = Binding.Value;
		}

		protected override void UIToBinding()
		{
			Binding.Value = toggle.isOn;
		}
	}
	public class DataBindToggleEnum : DataBindController<Enum>
	{
		private Toggle toggle;

		public Enum linkedValue;

		private void Start()
		{
			toggle = ((Component)this).GetComponent<Toggle>();
			((UnityEvent<bool>)(object)toggle.onValueChanged).AddListener((UnityAction<bool>)ValueChangedHandler);
		}

		private void ValueChangedHandler(bool _)
		{
			ChangedFromUI = true;
		}

		protected override void BindingToUI()
		{
			toggle.isOn = Binding.Value.Equals(linkedValue);
		}

		protected override void UIToBinding()
		{
			if (toggle.isOn)
			{
				Binding.Value = linkedValue;
			}
		}
	}
	public class DataBindInputField : DataBindController<string>
	{
		private InputField inputField;

		private bool uiDirty;

		private void Start()
		{
			inputField = ((Component)this).GetComponent<InputField>();
			((UnityEvent<string>)(object)inputField.onValueChanged).AddListener((UnityAction<string>)ValueChangedHandler);
			((UnityEvent<string>)(object)inputField.onEndEdit).AddListener((UnityAction<string>)SubmitHandler);
		}

		private void ValueChangedHandler(string value)
		{
			if (value != Binding.Value)
			{
				uiDirty = true;
			}
		}

		private void SubmitHandler(string _)
		{
			ChangedFromUI = true;
		}

		protected override void BindingToUI()
		{
			if (!uiDirty)
			{
				inputField.text = Binding.Value;
			}
		}

		protected override void UIToBinding()
		{
			Binding.Value = inputField.text;
			uiDirty = false;
		}
	}
	public interface IOneWayDataBindSource
	{
		object Value { get; }
	}
	public interface IOneWayDataBindSource<out TVisual>
	{
		TVisual Value { get; }
	}
	public interface IDataBindSource<TVisual>
	{
		TVisual Value { get; set; }
	}
	public class DataBindTransform<TLogical, TVisual>
	{
		public readonly Func<TLogical, TVisual> LogicalToVisualTransform;

		public readonly Func<TVisual, TLogical> VisualToLogicalTransform;

		public DataBindTransform(Func<TLogical, TVisual> forward, Func<TVisual, TLogical> reverse)
		{
			LogicalToVisualTransform = forward;
			VisualToLogicalTransform = reverse;
		}
	}
	public static class DataBindTransform
	{
		public static DataBindTransform<TLogical, TVisual> From<TLogical, TVisual>(Func<TLogical, TVisual> forward, Func<TVisual, TLogical> reverse)
		{
			return new DataBindTransform<TLogical, TVisual>(forward, reverse);
		}

		public static DataBindTransform<T, T> Identity<T>()
		{
			return From((T x) => x, (T x) => x);
		}
	}
	public abstract class DataBindSourceBase<TLogical, TVisual> : IDataBindSource<TVisual>, IOneWayDataBindSource<TVisual>, IOneWayDataBindSource
	{
		protected readonly DataBindTransform<TLogical, TVisual> transform;

		object IOneWayDataBindSource.Value => Value;

		public virtual TVisual Value
		{
			get
			{
				return transform.LogicalToVisualTransform(Get());
			}
			set
			{
				Set(transform.VisualToLogicalTransform(value));
			}
		}

		protected DataBindSourceBase(DataBindTransform<TLogical, TVisual> transform)
		{
			this.transform = transform;
		}

		protected abstract TLogical Get();

		protected abstract void Set(TLogical value);

		public DataBindSourceBase<TLogical, UVisual> WithTransform<UVisual>(Func<TLogical, UVisual> forward, Func<UVisual, TLogical> reverse)
		{
			return WithTransform(DataBindTransform.From(forward, reverse));
		}

		public abstract DataBindSourceBase<TLogical, UVisual> WithTransform<UVisual>(DataBindTransform<TLogical, UVisual> newTransform);
	}
	public class ConfigEntryDataBindSource<TLogical, TVisual> : DataBindSourceBase<TLogical, TVisual>
	{
		private readonly ConfigEntry<TLogical> entry;

		public ConfigEntryDataBindSource(ConfigEntry<TLogical> entry, DataBindTransform<TLogical, TVisual> transform)
			: base(transform)
		{
			this.entry = entry;
		}

		protected override TLogical Get()
		{
			return entry.Value;
		}

		protected override void Set(TLogical value)
		{
			entry.Value = value;
		}

		public override DataBindSourceBase<TLogical, UVisual> WithTransform<UVisual>(DataBindTransform<TLogical, UVisual> newTransform)
		{
			return new ConfigEntryDataBindSource<TLogical, UVisual>(entry, newTransform);
		}
	}
	public class ConfigEntryDataBindSource<T> : ConfigEntryDataBindSource<T, T>
	{
		public static implicit operator ConfigEntryDataBindSource<T>(ConfigEntry<T> entry)
		{
			return new ConfigEntryDataBindSource<T>(entry);
		}

		public ConfigEntryDataBindSource(ConfigEntry<T> entry)
			: base(entry, DataBindTransform.Identity<T>())
		{
		}
	}
	public class MemberDataBindSource<U, TLogical, TVisual> : DataBindSourceBase<TLogical, TVisual>
	{
		private readonly U obj;

		private readonly Func<U, TLogical> getter;

		private readonly Action<U, TLogical> setter;

		public MemberDataBindSource(U obj, Func<U, TLogical> getter, Action<U, TLogical> setter, DataBindTransform<TLogical, TVisual> transform)
			: base(transform)
		{
			this.obj = obj;
			this.getter = getter;
			this.setter = setter;
		}

		protected override TLogical Get()
		{
			return getter(obj);
		}

		protected override void Set(TLogical value)
		{
			setter(obj, value);
		}

		public override DataBindSourceBase<TLogical, UVisual> WithTransform<UVisual>(DataBindTransform<TLogical, UVisual> newTransform)
		{
			return new MemberDataBindSource<U, TLogical, UVisual>(obj, getter, setter, newTransform);
		}
	}
	public class MemberDataBindSource<U, T> : MemberDataBindSource<U, T, T>
	{
		public MemberDataBindSource(U obj, Func<U, T> getter, Action<U, T> setter)
			: base(obj, getter, setter, DataBindTransform.Identity<T>())
		{
		}
	}
	public class DelegateDataBindSource<TLogical, TVisual> : DataBindSourceBase<TLogical, TVisual>
	{
		private readonly Func<TLogical> getter;

		private readonly Action<TLogical> setter;

		public DelegateDataBindSource(Func<TLogical> getter, Action<TLogical> setter, DataBindTransform<TLogical, TVisual> transform)
			: base(transform)
		{
			this.getter = getter;
			this.setter = setter;
		}

		protected override TLogical Get()
		{
			return getter();
		}

		protected override void Set(TLogical value)
		{
			setter(value);
		}

		public override DataBindSourceBase<TLogical, UVisual> WithTransform<UVisual>(DataBindTransform<TLogical, UVisual> newTransform)
		{
			return new DelegateDataBindSource<TLogical, UVisual>(getter, setter, newTransform);
		}
	}
	public class DelegateDataBindSource<T> : DelegateDataBindSource<T, T>
	{
		public DelegateDataBindSource(Func<T> getter, Action<T> setter)
			: base(getter, setter, DataBindTransform.Identity<T>())
		{
		}
	}
	public class UIModWindowBase : ManualBehaviour, IInitializeFromContext<UIBuilderDSL.FancyWindowContext>, IInitializeFromContext<UIBuilderDSL.PlainWindowContext>, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
	{
		private bool toCaptureScroll;

		private bool focusPointEnter;

		public void InitializeFromContext(UIBuilderDSL.FancyWindowContext context)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			InitializeFromContext((UIBuilderDSL.WindowContext<UIBuilderDSL.FancyWindowContext>)context.WithCloseButton(new UnityAction(base._Close)));
		}

		public void InitializeFromContext(UIBuilderDSL.PlainWindowContext context)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			InitializeFromContext((UIBuilderDSL.WindowContext<UIBuilderDSL.PlainWindowContext>)context.WithCloseButton(new UnityAction(base._Close)));
		}

		private void InitializeFromContext<T>(UIBuilderDSL.WindowContext<T> context) where T : UIBuilderDSL.WindowContext<T>
		{
			toCaptureScroll = context.scrollCapture;
			((ManualBehaviour)this)._Create();
			((ManualBehaviour)this)._Init((object)null);
			((ManualBehaviour)this)._Open();
		}

		public override void _OnClose()
		{
			if (toCaptureScroll)
			{
				UIBuilder.inScrollView.Remove(this);
			}
			((ManualBehaviour)this)._OnClose();
		}

		public void OnPointerEnter(PointerEventData eventData)
		{
			if (toCaptureScroll)
			{
				UIBuilder.inScrollView.Add(this);
			}
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			if (toCaptureScroll)
			{
				UIBuilder.inScrollView.Remove(this);
			}
		}

		private void OnApplicationFocus(bool focus)
		{
			if (!toCaptureScroll)
			{
				return;
			}
			if (!focus)
			{
				focusPointEnter = UIBuilder.inScrollView.Contains(this);
				UIBuilder.inScrollView.Remove(this);
			}
			if (focus)
			{
				if (focusPointEnter)
				{
					UIBuilder.inScrollView.Add(this);
				}
				else
				{
					UIBuilder.inScrollView.Remove(this);
				}
			}
		}
	}
	public class UIWindowResize : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
	{
		public EventTrigger resizeTrigger;

		public RectTransform resizeTrans;

		public int resizeThreshold = 4;

		public Vector2 minSize;

		private bool mouseDown;

		private bool mouseOver;

		private Vector2 resizeMouseBegin;

		private Vector2 resizeSizeDeltaBegin;

		private Vector2 resizeSizeDeltaWanted;

		public bool pointerIn;

		public bool resizing { get; private set; }

		private void OnEnable()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_0072: 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_00a5: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			Entry val = new Entry();
			val.eventID = (EventTriggerType)2;
			((UnityEvent<BaseEventData>)(object)val.callback).AddListener((UnityAction<BaseEventData>)OnPointerDown);
			resizeTrigger.triggers.Add(val);
			Entry val2 = new Entry();
			val2.eventID = (EventTriggerType)3;
			((UnityEvent<BaseEventData>)(object)val2.callback).AddListener((UnityAction<BaseEventData>)OnPointerUp);
			resizeTrigger.triggers.Add(val2);
			Entry val3 = new Entry();
			val3.eventID = (EventTriggerType)0;
			((UnityEvent<BaseEventData>)(object)val3.callback).AddListener((UnityAction<BaseEventData>)OnPointerEnterResizeArea);
			resizeTrigger.triggers.Add(val3);
			Entry val4 = new Entry();
			val4.eventID = (EventTriggerType)1;
			((UnityEvent<BaseEventData>)(object)val4.callback).AddListener((UnityAction<BaseEventData>)OnPointerExitResizeArea);
			resizeTrigger.triggers.Add(val4);
			if ((Object)(object)resizeTrans == (Object)null)
			{
				ref RectTransform reference = ref resizeTrans;
				Transform transform = ((Component)this).transform;
				reference = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			}
			VFAudio.Create("common-popup-3", (Transform)null, Vector3.zero, true, 2, -1, -1L);
		}

		private void OnDisable()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			resizeTrigger.triggers.Clear();
			mouseDown = false;
			resizeMouseBegin = Vector2.zero;
			resizeSizeDeltaBegin = Vector2.zero;
			if (resizing)
			{
				resizeTrans.sizeDelta = new Vector2(Mathf.Round(resizeSizeDeltaWanted.x), Mathf.Round(resizeSizeDeltaWanted.y));
			}
			pointerIn = false;
		}

		private void OnApplicationFocus(bool focus)
		{
			if (!focus)
			{
				pointerIn = false;
			}
		}

		private void OnPointerDown(BaseEventData eventData)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			mouseDown = true;
			UIRoot.ScreenPointIntoRect(Input.mousePosition, resizeTrans, ref resizeMouseBegin);
			resizeSizeDeltaBegin = resizeTrans.sizeDelta;
			resizeSizeDeltaWanted = resizeTrans.sizeDelta;
			UICursor.SetCursor((ECursor)2);
		}

		private void OnPointerUp(BaseEventData eventData)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			mouseDown = false;
			resizeMouseBegin = Vector2.zero;
			resizeSizeDeltaBegin = Vector2.zero;
		}

		private void OnPointerEnterResizeArea(BaseEventData eventData)
		{
			mouseOver = true;
		}

		private void OnPointerExitResizeArea(BaseEventData eventData)
		{
			mouseOver = false;
		}

		private void BringToFront()
		{
			int childCount = ((Component)this).transform.parent.childCount;
			if (((Component)this).transform.GetSiblingIndex() < childCount - 1)
			{
				((Component)this).transform.SetAsLastSibling();
			}
		}

		private void Update()
		{
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			if (mouseDown)
			{
				if (!Input.GetMouseButton(0) && !Input.GetMouseButton(1))
				{
					mouseDown = false;
				}
				Vector2 val = default(Vector2);
				UIRoot.ScreenPointIntoRect(Input.mousePosition, resizeTrans, ref val);
				Vector2 val2 = val - resizeMouseBegin;
				if (Mathf.Abs(val2.x) + Mathf.Abs(val2.y) > (float)resizeThreshold)
				{
					resizing = true;
					resizeSizeDeltaWanted = resizeSizeDeltaBegin + new Vector2(val2.x, 0f - val2.y);
					resizeTrans.sizeDelta = new Vector2(Mathf.Round(Mathf.Max(resizeSizeDeltaWanted.x, minSize.x)), Mathf.Round(Mathf.Max(resizeSizeDeltaWanted.y, minSize.y)));
				}
				UICursor.SetCursor((ECursor)2);
			}
			else
			{
				resizing = false;
				resizeMouseBegin = Vector2.zero;
				resizeSizeDeltaBegin = Vector2.zero;
				if (mouseOver)
				{
					UICursor.SetCursor((ECursor)3);
				}
			}
			if (pointerIn && (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)))
			{
				BringToFront();
			}
		}

		public void OnPointerEnter(PointerEventData eventData)
		{
			pointerIn = true;
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			pointerIn = false;
		}
	}
	public abstract class ValueChangeHandler<T> : MonoBehaviour
	{
		public Action<T> Handler;

		protected T prevValue;

		protected abstract T CurrentValue { get; }

		private void OnEnable()
		{
			Handler?.Invoke(CurrentValue);
		}

		private void LateUpdate()
		{
			T currentValue;
			T val = (currentValue = CurrentValue);
			if (!val.Equals(prevValue))
			{
				Handler?.Invoke(currentValue);
				prevValue = currentValue;
			}
		}
	}
	public class DataBindValueChangeHandler : ValueChangeHandler<object>
	{
		public IOneWayDataBindSource Binding;

		protected override object CurrentValue => Binding.Value;
	}
	public abstract class DataBindValueChangeHandler<T> : ValueChangeHandler<T>
	{
		public IOneWayDataBindSource<T> Binding;

		protected override T CurrentValue => Binding.Value;
	}
	public class DataBindValueChangedHandlerBool : DataBindValueChangeHandler<bool>
	{
	}
	public class DataBindValueChangedHandlerInt : DataBindValueChangeHandler<int>
	{
	}
	public class DataBindValueChangedHandlerLong : DataBindValueChangeHandler<long>
	{
	}
	public class DataBindValueChangedHandlerFloat : DataBindValueChangeHandler<float>
	{
	}
	public class DataBindValueChangedHandlerDouble : DataBindValueChangeHandler<double>
	{
	}
	public class ToggleValueChangedHandler : ValueChangeHandler<bool>
	{
		public Toggle toggle;

		protected override bool CurrentValue => toggle.isOn;

		private void Start()
		{
			if (!Object.op_Implicit((Object)(object)toggle))
			{
				toggle = ((Component)this).GetComponent<Toggle>();
			}
		}
	}
	public class SliderValueChangedHandler : ValueChangeHandler<float>
	{
		public Slider slider;

		protected override float CurrentValue => slider.value;

		private void Start()
		{
			if (!Object.op_Implicit((Object)(object)slider))
			{
				slider = ((Component)this).GetComponent<Slider>();
			}
		}
	}
	public interface IProperties<T> where T : Component
	{
		void Apply(T component);
	}
	public abstract record GraphicProperties : IProperties<Graphic>
	{
		public Material material { get; init; }

		public Color color { get; init; } = Color.white;


		public bool raycastTarget { get; init; } = true;


		public void Apply(Graphic component)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)material != (Object)null)
			{
				component.material = material;
			}
			component.color = color;
			component.raycastTarget = raycastTarget;
		}

		[CompilerGenerated]
		protected virtual bool PrintMembers(StringBuilder builder)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			RuntimeHelpers.EnsureSufficientExecutionStack();
			builder.Append("material = ");
			builder.Append(material);
			builder.Append(", color = ");
			Color val = color;
			builder.Append(((object)(Color)(ref val)).ToString());
			builder.Append(", raycastTarget = ");
			builder.Append(raycastTarget.ToString());
			return true;
		}
	}
	public abstract record MaskableGraphicProperties : GraphicProperties, IProperties<MaskableGraphic>
	{
		public bool maskable { get; init; } = true;


		public void Apply(MaskableGraphic component)
		{
			base.Apply((Graphic)(object)component);
			component.maskable = maskable;
		}
	}
	public record RawImageProperties : MaskableGraphicProperties, IProperties<RawImage>
	{
		public Texture texture { get; init; }

		public Rect uvRect { get; init; } = new Rect(0f, 0f, 1f, 1f);


		public void Apply(RawImage component)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			base.Apply((MaskableGraphic)(object)component);
			if ((Object)(object)texture != (Object)null)
			{
				component.texture = texture;
			}
			component.uvRect = uvRect;
		}

		[CompilerGenerated]
		protected override bool PrintMembers(StringBuilder builder)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (base.PrintMembers(builder))
			{
				builder.Append(", ");
			}
			builder.Append("texture = ");
			builder.Append(texture);
			builder.Append(", uvRect = ");
			Rect val = uvRect;
			builder.Append(((object)(Rect)(ref val)).ToString());
			return true;
		}
	}
	public record ImageProperties : MaskableGraphicProperties, IProperties<Image>
	{
		public Sprite sprite { get; init; }

		public Sprite overrideSprite { get; init; }

		public Type type { get; init; }

		public bool preserveAspect { get; init; }

		public bool fillCenter { get; init; } = true;


		public FillMethod fillMethod { get; init; } = (FillMethod)4;


		public bool fillClockwise { get; init; } = true;


		public int fillOrigin { get; init; }

		public float alphaHitTestMinimumThreshold { get; init; }

		public bool useSpriteMesh { get; init; }

		public void Apply(Image component)
		{
			//IL_003d: 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)
			base.Apply((MaskableGraphic)(object)component);
			if ((Object)(object)sprite != (Object)null)
			{
				component.sprite = sprite;
			}
			if ((Object)(object)overrideSprite != (Object)null)
			{
				component.overrideSprite = overrideSprite;
			}
			component.type = type;
			component.preserveAspect = preserveAspect;
			component.fillCenter = fillCenter;
			component.fillMethod = fillMethod;
			component.fillClockwise = fillClockwise;
			component.fillOrigin = fillOrigin;
			component.alphaHitTestMinimumThreshold = alphaHitTestMinimumThreshold;
			component.useSpriteMesh = useSpriteMesh;
		}

		[CompilerGenerated]
		protected override bool PrintMembers(StringBuilder builder)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			if (base.PrintMembers(builder))
			{
				builder.Append(", ");
			}
			builder.Append("sprite = ");
			builder.Append(sprite);
			builder.Append(", overrideSprite = ");
			builder.Append(overrideSprite);
			builder.Append(", type = ");
			Type val = type;
			builder.Append(((object)(Type)(ref val)).ToString());
			builder.Append(", preserveAspect = ");
			builder.Append(preserveAspect.ToString());
			builder.Append(", fillCenter = ");
			builder.Append(fillCenter.ToString());
			builder.Append(", fillMethod = ");
			FillMethod val2 = fillMethod;
			builder.Append(((object)(FillMethod)(ref val2)).ToString());
			builder.Append(", fillClockwise = ");
			builder.Append(fillClockwise.ToString());
			builder.Append(", fillOrigin = ");
			builder.Append(fillOrigin.ToString());
			builder.Append(", alphaHitTestMinimumThreshold = ");
			builder.Append(alphaHitTestMinimumThreshold.ToString());
			builder.Append(", useSpriteMesh = ");
			builder.Append(useSpriteMesh.ToString());
			return true;
		}
	}
	public static class GraphicPropertiesBuilder
	{
		public static readonly ImageProperties ImagePropertiesDefault = new ImageProperties();

		public static readonly TranslucentImageProperties TranslucentImagePropertiesDefault = new TranslucentImageProperties();

		public static T WithRaycast<T>(this T record, bool raycastTarget) where T : GraphicProperties
		{
			T obj = (T)record.<Clone>$();
			obj.raycastTarget = raycastTarget;
			return obj;
		}

		public static T WithColor<T>(this T record, Color color) where T : GraphicProperties
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			T obj = (T)record.<Clone>$();
			obj.color = color;
			return obj;
		}

		public static T WithMaterial<T>(this T record, Material material) where T : GraphicProperties
		{
			T obj = (T)record.<Clone>$();
			obj.material = material;
			return obj;
		}

		public static T WithSprite<T>(this T record, Sprite sprite, Sprite overrideSprite = null, Type? type = null) where T : ImageProperties
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			T obj = (T)record.<Clone>$();
			obj.sprite = sprite;
			obj.overrideSprite = (Object.op_Implicit((Object)(object)overrideSprite) ? overrideSprite : record.overrideSprite);
			obj.type = (type.HasValue ? type.Value : record.type);
			return obj;
		}

		public static T WithSlicedSprite<T>(this T record, Sprite sprite, Sprite overrideSprite = null) where T : ImageProperties
		{
			return record.WithSprite(sprite, overrideSprite, (Type)1);
		}
	}
	public record TranslucentImageProperties : ImageProperties, IProperties<TranslucentImage>
	{
		public TranslucentImageSource source { get; init; }

		public float vibrancy { get; init; } = 1f;


		public float brightness { get; init; }

		public float flatten { get; init; } = 0.1f;


		public bool updating { get; init; } = true;


		public bool lateUpdating { get; init; } = true;


		public float spriteBlending { get; init; } = 0.65f;


		public void Apply(TranslucentImage component)
		{
			base.Apply((Image)(object)component);
			component.vibrancy = vibrancy;
			component.brightness = brightness;
			component.flatten = flatten;
			component.updating = updating;
			component.lateUpdating = lateUpdating;
			component.spriteBlending = spriteBlending;
		}
	}
	public record TextProperties : MaskableGraphicProperties, IProperties<Text>
	{
		public Font font { get; init; }

		public bool supportRichText { get; init; } = true;


		public bool resizeTextForBestFit { get; init; }

		public int resizeTextMinSize { get; init; } = 14;


		public int resizeTextMaxSize { get; init; } = 40;


		public TextAnchor alignment { get; init; }

		public bool alignByGeometry { get; init; }

		public int fontSize { get; init; } = 14;


		public HorizontalWrapMode horizontalOverflow { get; init; }

		public VerticalWrapMode verticalOverflow { get; init; }

		public float lineSpacing { get; init; } = 1f;


		public FontStyle fontStyle { get; init; }

		public void Apply(Text component)
		{
			//IL_0053: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			base.Apply((MaskableGraphic)(object)component);
			if ((Object)(object)font != (Object)null)
			{
				component.font = font;
			}
			component.supportRichText = supportRichText;
			component.resizeTextForBestFit = resizeTextForBestFit;
			component.resizeTextMinSize = resizeTextMinSize;
			component.resizeTextMaxSize = resizeTextMaxSize;
			component.alignment = alignment;
			component.alignByGeometry = alignByGeometry;
			component.fontSize = fontSize;
			component.horizontalOverflow = horizontalOverflow;
			component.verticalOverflow = verticalOverflow;
			component.lineSpacing = lineSpacing;
			component.fontStyle = fontStyle;
		}

		[CompilerGenerated]
		protected override bool PrintMembers(StringBuilder builder)
		{
			//IL_00d8: 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_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: 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_01c9: Unknown result type (might be due to invalid IL or missing references)
			if (base.PrintMembers(builder))
			{
				builder.Append(", ");
			}
			builder.Append("font = ");
			builder.Append(font);
			builder.Append(", supportRichText = ");
			builder.Append(supportRichText.ToString());
			builder.Append(", resizeTextForBestFit = ");
			builder.Append(resizeTextForBestFit.ToString());
			builder.Append(", resizeTextMinSize = ");
			builder.Append(resizeTextMinSize.ToString());
			builder.Append(", resizeTextMaxSize = ");
			builder.Append(resizeTextMaxSize.ToString());
			builder.Append(", alignment = ");
			TextAnchor val = alignment;
			builder.Append(((object)(TextAnchor)(ref val)).ToString());
			builder.Append(", alignByGeometry = ");
			builder.Append(alignByGeometry.ToString());
			builder.Append(", fontSize = ");
			builder.Append(fontSize.ToString());
			builder.Append(", horizontalOverflow = ");
			HorizontalWrapMode val2 = horizontalOverflow;
			builder.Append(((object)(HorizontalWrapMode)(ref val2)).ToString());
			builder.Append(", verticalOverflow = ");
			VerticalWrapMode val3 = verticalOverflow;
			builder.Append(((object)(VerticalWrapMode)(ref val3)).ToString());
			builder.Append(", lineSpacing = ");
			builder.Append(lineSpacing.ToString());
			builder.Append(", fontStyle = ");
			FontStyle val4 = fontStyle;
			builder.Append(((object)(FontStyle)(ref val4)).ToString());
			return true;
		}
	}
	public record SelectableProperties : IProperties<Selectable>
	{
		public Transition? transition { get; init; }

		public ColorBlock? colors { get; init; }

		public SpriteState? spriteState { get; init; }

		public void Apply(Selectable component)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if (transition.HasValue)
			{
				component.transition = transition.Value;
			}
			if (colors.HasValue)
			{
				component.colors = colors.Value;
			}
			if (spriteState.HasValue)
			{
				component.spriteState = spriteState.Value;
			}
		}
	}
	public record ScrollRectProperties : IProperties<ScrollRect>
	{
		public MovementType movementType { get; init; } = (MovementType)1;


		public float elasticity { get; init; } = 0.1f;


		public bool inertia { get; init; } = true;


		public float decelerationRate { get; init; } = 0.135f;


		public float scrollSensitivity { get; init; } = 1f;


		public float horizontalScrollbarSpacing { get; init; }

		public float verticalScrollbarSpacing { get; init; }

		public void Apply(ScrollRect component)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			component.movementType = movementType;
			component.elasticity = elasticity;
			component.inertia = inertia;
			component.decelerationRate = decelerationRate;
			component.scrollSensitivity = scrollSensitivity;
			component.horizontalScrollbarSpacing = horizontalScrollbarSpacing;
			component.verticalScrollbarSpacing = verticalScrollbarSpacing;
		}

		[CompilerGenerated]
		protected virtual bool PrintMembers(StringBuilder builder)
		{
			//IL_0013: 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)
			RuntimeHelpers.EnsureSufficientExecutionStack();
			builder.Append("movementType = ");
			MovementType val = movementType;
			builder.Append(((object)(MovementType)(ref val)).ToString());
			builder.Append(", elasticity = ");
			builder.Append(elasticity.ToString());
			builder.Append(", inertia = ");
			builder.Append(inertia.ToString());
			builder.Append(", decelerationRate = ");
			builder.Append(decelerationRate.ToString());
			builder.Append(", scrollSensitivity = ");
			builder.Append(scrollSensitivity.ToString());
			builder.Append(", horizontalScrollbarSpacing = ");
			builder.Append(horizontalScrollbarSpacing.ToString());
			builder.Append(", verticalScrollbarSpacing = ");
			builder.Append(verticalScrollbarSpacing.ToString());
			return true;
		}
	}
	public static class UIBuilderPlugin
	{
		private static Harmony _harmony;

		public static ManualLogSource Log;

		private static string GUID;

		public static void Create(string requestingModGUID, Action onReadyCallback)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			GUID = requestingModGUID + "-UIBuilder";
			Log = Logger.CreateLogSource(GUID);
			_harmony = new Harmony(GUID);
			_harmony.PatchAll(typeof(UIBuilder));
			UIBuilder.QueueReadyCallback(onReadyCallback);
			UIRoot instance = UIRoot.instance;
			bool? obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				UIGame uiGame = instance.uiGame;
				obj = ((uiGame != null) ? new bool?(((ManualBehaviour)uiGame).created) : null);
			}
			bool? flag = obj;
			if (flag.GetValueOrDefault())
			{
				UIBuilder.Create();
			}
			Log.LogInfo((object)(GUID + " Create() called"));
		}

		public static void Destroy()
		{
			UIBuilder.Destroy();
			Log.LogInfo((object)(GUID + " Destroy() called"));
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Log = null;
		}
	}
	public enum AnchorHorizontal
	{
		Left,
		Middle,
		Right,
		Stretch
	}
	public enum AnchorVertical
	{
		Top,
		Middle,
		Bottom,
		Stretch
	}
	public record Anchor(AnchorVertical vertical, AnchorHorizontal horizontal)
	{
		public static Anchor TopLeft = new Anchor(AnchorVertical.Top, AnchorHorizontal.Left);

		public static Anchor Top = new Anchor(AnchorVertical.Top, AnchorHorizontal.Middle);

		public static Anchor TopRight = new Anchor(AnchorVertical.Top, AnchorHorizontal.Right);

		public static Anchor Left = new Anchor(AnchorVertical.Middle, AnchorHorizontal.Left);

		public static Anchor Center = new Anchor(AnchorVertical.Middle, AnchorHorizontal.Middle);

		public static Anchor Right = new Anchor(AnchorVertical.Middle, AnchorHorizontal.Right);

		public static Anchor BottomLeft = new Anchor(AnchorVertical.Bottom, AnchorHorizontal.Left);

		public static Anchor Bottom = new Anchor(AnchorVertical.Bottom, AnchorHorizontal.Middle);

		public static Anchor BottomRight = new Anchor(AnchorVertical.Bottom, AnchorHorizontal.Right);

		public static Anchor Stretch = new Anchor(AnchorVertical.Stretch, AnchorHorizontal.Stretch);

		public static Anchor TopStretch = new Anchor(AnchorVertical.Top, AnchorHorizontal.Stretch);

		public static Anchor CenterStretch = new Anchor(AnchorVertical.Middle, AnchorHorizontal.Stretch);

		public static Anchor BottomStretch = new Anchor(AnchorVertical.Bottom, AnchorHorizontal.Stretch);

		public static Anchor StretchLeft = new Anchor(AnchorVertical.Stretch, AnchorHorizontal.Left);

		public static Anchor StretchCenter = new Anchor(AnchorVertical.Stretch, AnchorHorizontal.Middle);

		public static Anchor StretchRight = new Anchor(AnchorVertical.Stretch, AnchorHorizontal.Right);

		public (Vector2, Vector2) ToMinMaxAnchors()
		{
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			var (num, num2) = horizontal switch
			{
				AnchorHorizontal.Left => (0f, 0f), 
				AnchorHorizontal.Right => (1f, 1f), 
				AnchorHorizontal.Middle => (0.5f, 0.5f), 
				AnchorHorizontal.Stretch => (0f, 1f), 
				_ => throw new NotImplementedException(), 
			};
			var (num3, num4) = vertical switch
			{
				AnchorVertical.Bottom => (0f, 0f), 
				AnchorVertical.Top => (1f, 1f), 
				AnchorVertical.Middle => (0.5f, 0.5f), 
				AnchorVertical.Stretch => (0f, 1f), 
				_ => throw new NotImplementedException(), 
			};
			return (new Vector2(num, num3), new Vector2(num2, num4));
		}

		[CompilerGenerated]
		protected Anchor(Anchor original)
		{
			vertical = original.vertical;
			horizontal = original.horizontal;
		}
	}
	public interface IButtonSelectableContext : ISelectableContext
	{
		Button button { get; }
	}
	public record ButtonContext(Button button, Text text) : UIElementContext(((Component)button).gameObject), IButtonSelectableContext, ISelectableContext, ITextContext, IGraphicContext, ISelectableVisuals
	{
		public Graphic visuals { get; set; }

		Text ITextContext.text => text;

		Graphic IGraphicContext.graphic => (Graphic)(object)text;

		Button IButtonSelectableContext.button => button;

		Selectable ISelectableContext.selectable => (Selectable)(object)button;
	}
	public static class ButtonContextExtensions
	{
		public static ButtonContext Select(Button button, Text text = null, Graphic visuals = null)
		{
			return new ButtonContext(button, text)
			{
				visuals = visuals
			};
		}

		public static ButtonContext Create(GameObject buttonObj, GameObject textObj)
		{
			Button orCreateComponent = buttonObj.GetOrCreateComponent<Button>();
			Text orCreateComponent2 = textObj.GetOrCreateComponent<Text>();
			return Select(orCreateComponent, orCreateComponent2);
		}

		public static ButtonContext Create(GameObject buttonObj)
		{
			return Select(buttonObj.GetOrCreateComponent<Button>());
		}

		public static ButtonContext Create(GameObject buttonObj, string buttonText)
		{
			return Create(buttonObj.GetOrCreateComponent<Button>(), buttonText);
		}

		public static ButtonContext Create(Button button, string buttonText)
		{
			TextContext context = UIBuilderDSL.Create.Text("text");
			VerticalWrapMode? vertical = (VerticalWrapMode)0;
			TextContext textContext = context.WithOverflow(null, vertical).WithFont(UIBuilder.fontSAIRASB).WithFontSize(16)
				.WithLocalizer(buttonText)
				.ChildOf(((Component)button).gameObject)
				.WithAnchor(Anchor.Stretch)
				.At(0, 0);
			return Select(button, textContext.text);
		}
	}
	public static class IButtonContextExtensions
	{
		public static T AddClickListener<T>(this T Context, UnityAction onClickCallback) where T : IButtonSelectableContext
		{
			if (onClickCallback != null)
			{
				((UnityEvent)Context.button.onClick).AddListener(onClickCallback);
			}
			return Context;
		}

		public static T RemoveClickListener<T>(this T Context, UnityAction onClickCallback) where T : IButtonSelectableContext
		{
			if (onClickCallback != null)
			{
				((UnityEvent)Context.button.onClick).RemoveListener(onClickCallback);
			}
			return Context;
		}

		public static T ClearClickListeners<T>(this T Context) where T : IButtonSelectableContext
		{
			((UnityEventBase)Context.button.onClick).RemoveAllListeners();
			return Context;
		}

		public static T SetClickListener<T>(this T Context, UnityAction onClickCallback) where T : IButtonSelectableContext
		{
			return Context.ClearClickListeners().AddClickListener(onClickCallback);
		}
	}
	public static class UIBuilderDSL
	{
		public record ComboBoxContext : UIElementContext
		{
			public ComboBoxContext Context => this;

			public ComboBoxContext(GameObject uiElement)
				: base(uiElement)
			{
			}
		}

		public record FancyWindowContext : WindowContext<FancyWindowContext>
		{
			public override FancyWindowContext Context => this;

			protected override TranslucentImageProperties panelBgCloneImgProperties => UIBuilder.fancyWindowPanelBgProperties;

			protected override ImageProperties panelBgBorderCloneImgProperties => UIBuilder.fancyWindowPanelBgBorderProperties;

			protected override ImageProperties panelBgDragTriggerCloneImgProperties => UIBuilder.fancyWindowPanelBgDragTriggerProperties;

			protected override ImageProperties shadowCloneImgProperties => UIBuilder.fancyWindowShadowImgProperties;

			public FancyWindowContext(GameObject uiElement)
				: base(uiElement)
			{
			}

			internal FancyWindowContext WithButtonBox(bool withSortBtn)
			{
				WithPanelBg();
				if ((Object)(object)base.panelBg.SelectChild("btn-box") != (Object)null)
				{
					return Context;
				}
				TranslucentImage component;
				UIElementContext parent = UIElementExtensions.WithComponent<UIElementContext, TranslucentImage>(Create.UIElement("btn-box"), out component, new IProperties<TranslucentImage>[1] { UIBuilder.fancyWindowPanelBgBtnBoxProperties }).ChildOf(base.panelBg).WithAnchor(Anchor.TopRight)
					.WithPivot(0.5f, 0.5f)
					.OfSize(withSortBtn ? 60 : 40, 24)
					.At(withSortBtn ? (-60) : (-50), -30);
				UIElementExtensions.WithComponent<UIElementContext, Image>(Create.UIElement("btn-border"), out Image _, new IProperties<Image>[1] { UIBuilder.fancyWindowPanelBgBtnBoxBorderProperties }).ChildOf(parent).WithAnchor(Anchor.Stretch);
				return Context;
			}

			public FancyWindowContext WithCloseButton(UnityAction closeCallback)
			{
				using (base.DeactivatedScope)
				{
					WithButtonBox(withSortBtn: false);
					GameObject val = base.panelBg.SelectChild("btn-box");
					if ((Object)(object)val.SelectChild("close-btn") != (Object)null)
					{
						return Context;
					}
					Image component;
					UIElementContext uIElementContext = UIElementExtensions.WithComponent<UIElementContext, Image>(Create.UIElement("close-btn"), out component, new IProperties<Image>[1] { UIBuilder.fancyWindowPanelBgBtnBoxHexBtnProperties }).ChildOf(val).WithPivot(0.5f, 0.5f)
						.OfSize(38, 23);
					UIElementExtensions.WithComponent<UIElementContext, Image>(Create.UIElement("x"), out Image component2, new IProperties<Image>[1] { UIBuilder.fancyWindowPanelBgBtnBoxCloseBtnXProperties }).ChildOf(uIElementContext).WithPivot(0.5f, 0.5f)
						.OfSize(10, 10);
					UIElementExtensions.WithComponent<UIElementContext, Image>(Create.UIElement("col"), out Image _, new IProperties<Image>[1] { UIBuilder.fancyWindowPanelBgBtnBoxCloseBtnColProperties }).ChildOf(uIElementContext).WithPivot(0.5f, 0.5f)
						.OfSize(25, 19);
					uIElementContext.WithComponent<UIElementContext, Button>(out Button _, (Action<Button>)delegate(Button b)
					{
						((UnityEvent)b.onClick).AddListener(closeCallback);
					}).WithTransitions(UIBuilder.fancyWindowPanelBgBtnBoxCloseBtnTransition.CloneWithTarget((Graphic)(object)component), UIBuilder.fancyWindowPanelBgBtnBoxCloseBtnXTransition.CloneWithTarget((Graphic)(object)component2));
					return Context;
				}
			}

			public FancyWindowContext WithCloseAndSortButton(UnityAction closeCallback, UnityAction sortCallback)
			{
				WithButtonBox(withSortBtn: true);
				GameObject val = base.panelBg.SelectChild("btn-box");
				if ((Object)(object)val.SelectChild("close-btn") != (Object)null)
				{
					return Context;
				}
				Image component;
				UIElementContext uIElementContext = UIElementExtensions.WithComponent<UIElementContext, Image>(Create.UIElement("close-btn"), out component, new IProperties<Image>[1] { UIBuilder.fancyWindowPanelBgBtnBoxHexBtnRProperties }).ChildOf(val).WithPivot(0.5f, 0.5f)
					.OfSize(30, 24)
					.At(15, 0);
				Image component2;
				UIElementContext uIElementContext2 = UIElementExtensions.WithComponent<UIElementContext, Image>(Create.UIElement("sort-btn"), out component2, new IProperties<Image>[1] { UIBuilder.fancyWindowPanelBgBtnBoxHexBtnLProperties }).ChildOf(val).WithPivot(0.5f, 0.5f)
					.OfSize(30, 24)
					.At(-15, 0);
				UIElementExtensions.WithComponent<UIElementContext, Image>(Create.UIElement("x"), out Image component3, new IProperties<Image>[1] { UIBuilder.fancyWindowPanelBgBtnBoxCloseBtnXProperties }).ChildOf(uIElementContext).WithPivot(0.5f, 0.5f)
					.OfSize(10, 10)
					.At(-3, 0);
				UIElementExtensions.WithComponent<UIElementContext, Image>(Create.UIElement("col"), out Image component4, new IProperties<Image>[1] { UIBuilder.fancyWindowPanelBgBtnBoxCloseBtnColProperties }).ChildOf(uIElementContext).WithPivot(0.5f, 0.5f)
					.OfSize(25, 19)
					.At(-2, 0);
				UIElementExtensions.WithComponent<UIElementContext, Image>(Create.UIElement("x"), out Image component5, new IProperties<Image>[1] { UIBuilder.fancyWindowPanelBgBtnBoxSortBtnXProperties }).ChildOf(uIElementContext2).WithPivot(0.5f, 0.5f)
					.OfSize(10, 10)
					.At(3, 0);
				UIElementExtensions.WithComponent<UIElementContext, Image>(Create.UIElement("col"), out component4, new IProperties<Image>[1] { UIBuilder.fancyWindowPanelBgBtnBoxSortBtnColProperties }).ChildOf(uIElementContext2).WithPivot(0.5f, 0.5f)
					.OfSize(25, 19)
					.At(2, 0);
				uIElementContext.WithComponent<UIElementContext, Button>(out Button component6, (Action<Button>)delegate(Button b)
				{
					((UnityEvent)b.onClick).AddListener(closeCallback);
				}).WithTransitions(UIBuilder.fancyWindowPanelBgBtnBoxCloseBtnTransition.CloneWithTarget((Graphic)(object)component), UIBuilder.fancyWindowPanelBgBtnBoxCloseBtnXTransition.CloneWithTarget((Graphic)(object)component3));
				uIElementContext2.WithComponent<UIElementContext, Button>(out component6, (Action<Button>)delegate(Button b)
				{
					((UnityEvent)b.onClick).AddListener(sortCallback);
				}).WithTransitions(UIBuilder.fancyWindowPanelBgBtnBoxSortBtnTransition.CloneWithTarget((Graphic)(object)component2), UIBuilder.fancyWindowPanelBgBtnBoxSortBtnXTransition.CloneWithTarget((Graphic)(object)component5));
				return Context;
			}

			public override FancyWindowContext WithBorder()
			{
				WithPanelBg();
				UIElementExtensions.WithComponent<UIElementContext, Image>(Create.UIElement("border"), out Image _, new IProperties<Image>[1] { panelBgBorderCloneImgProperties }).ChildOf(base.panelBg).WithAnchor(Anchor.Stretch)
					.OfSize(0, 0);
				return Context;
			}

			public override FancyWindowContext WithTitle(string title)
			{
				WithPanelBg();
				Create.Text("title-text").ChildOf(base.panelBg).WithAnchor(Anchor.TopLeft)
					.At(40, -20)
					.WithLocalizer(title)
					.WithFont(UIBuilder.fontSAIRAB)
					.WithFontSize(18)
					.WithAlignment((TextAnchor)3)
					.OfSize(158, 36)
					.WithOverflow((HorizontalWrapMode)0, (VerticalWrapMode)0);
				return Context;
			}

			[CompilerGenerated]
			public new void Deconstruct(out GameObject uiElement)
			{
				uiElement = base.uiElement;
			}
		}

		public record PlainWindowContext : WindowContext<PlainWindowContext>
		{
			public override PlainWindowContext Context => this;

			protected override TranslucentImageProperties panelBgCloneImgProperties => UIBuilder.plainWindowPanelBgProperties;

			protected override ImageProperties panelBgBorderCloneImgProperties => UIBuilder.plainWindowPanelBgBorderProperties;

			protected override ImageProperties panelBgDragTriggerCloneImgProperties => UIBuilder.plainWindowPanelBgDragTriggerProperties;

			protected override ImageProperties shadowCloneImgProperties => UIBuilder.plainWindowShadowImgProperties;

			public PlainWindowContext(GameObject uiElement)
				: base(uiElement)
			{
			}

			public override PlainWindowContext WithShadow()
			{
				base.WithShadow();
				new UIElementContext(base.uiElement.SelectChild("shadow")).OfSize(44, 44);
				return Context;
			}

			public PlainWindowContext WithCloseButton(UnityAction closeCallback)
			{
				WithPanelBg();
				if ((Object)(object)base.panelBg.SelectChild("x") != (Object)null)
				{
					return Context;
				}
				_ = UIElementExtensions.WithComponent<UIElementContext, Image>(Create.UIElement("x"), out Image component, new IProperties<Image>[1] { UIBuilder.plainWindowPanelBgXProperties }).WithComponent<UIElementContext, Button>(out Button _, (Action<Button>)delegate(Button b)
				{
					((UnityEvent)b.onClick).AddListener(closeCallback);
				}).WithTransitions(UIBuilder.plainWindowPanelBgXTransition.CloneWithTarget((Graphic)(object)component))
					.ChildOf(base.panelBg)
					.WithAnchor(Anchor.TopRight)
					.OfSize(21, 21)
					.At(-13, -13)
					.uiElement;
				return Context;
			}

			public override PlainWindowContext WithBorder()
			{
				WithPanelBg();
				UIElementExtensions.WithComponent<UIElementContext, Image>(Create.UIElement("border"), out Image _, new IProperties<Image>[1] { panelBgBorderCloneImgProperties }).ChildOf(base.panelBg).WithAnchor(Anchor.Stretch)
					.OfSize(6, 6);
				return Context;
			}

			public override PlainWindowContext WithTitle(string title)
			{
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				WithPanelBg();
				TextContext context = IGraphicContextExtensions.WithMaterial(Create.Text("title-text").ChildOf(base.panelBg).WithAnchor(Anchor.TopLeft)
					.At(15, -24)
					.WithLocalizer(title)
					.WithFont(UIBuilder.fontSAIRAB)
					.WithFontSize(18)
					.WithAlignment((TextAnchor)3), UIBuilder.materialWidgetTextAlpha5x);
				Color white = Color.white;
				IGraphicContextExtensions.WithColor(context, ((Color)(ref white)).AlphaMultiplied(0.6f)).WithContentSizeFitter((FitMode)2);
				return Context;
			}

			[CompilerGenerated]
			public new void Deconstruct(out GameObject uiElement)
			{
				uiElement = base.uiElement;
			}
		}

		[StructLayout(LayoutKind.Sequential, Size = 1)]
		public struct SelectContext
		{
			public readonly UIElementContext UIElement(RectTransform transform)
			{
				return UIElementExtensions.Select(((Component)transform).gameObject);
			}

			public readonly UIElementContext UIElement(GameObject obj)
			{
				return UIElementExtensions.Select(obj);
			}

			public readonly PlainWindowContext PlainWindow(GameObject obj)
			{
				return new PlainWindowContext(obj);
			}

			public readonly FancyWindowContext FancyWindow(GameObject obj)
			{
				return new FancyWindowContext(obj);
			}

			public readonly ScrollViewContext ScrollView(ScrollRect scrollRect)
			{
				return ScrollViewContextExtensions.Select(scrollRect);
			}

			public readonly ButtonContext Button(Button button, Text text = null, Graphic visuals = null)
			{
				return ButtonContextExtensions.Select(button, text, visuals);
			}

			public readonly ToggleContext Toggle(Toggle toggle, Image image = null)
			{
				return ToggleContextExtensions.Select(toggle, image);
			}

			public readonly ToggleButtonContext ToggleButton(Toggle toggle, Text text = null, Graphic visuals = null)
			{
				return ToggleButtonContextExtensions.Select(toggle, text, visuals);
			}

			public readonly TextContext Text(Text text)
			{
				return TextContextExtensions.Select(text);
			}

			public readonly SliderContext Slider(Slider slider, Image fill, Image handle = null)
			{
				return SliderContextExtensions.Select(slider, fill, handle);
			}

			public readonly InputFieldContext InputField(InputField inputField, Text text = null)
			{
				return InputFieldContextExtensions.Select(inputField, text);
			}

			public readonly ComboBoxContext ComboBox(GameObject obj)
			{
				return new ComboBoxContext(obj);
			}

			public readonly HorizontalLayoutGroupContext HorizontalLayoutGroup(GameObject obj)
			{
				return new HorizontalLayoutGroupContext(obj);
			}

			public readonly VerticalLayoutGroupContext VerticalLayoutGroup(GameObject obj)
			{
				return new VerticalLayoutGroupContext(obj);
			}

			public readonly GridLayoutGroupContext GridLayoutGroup(GameObject obj)
			{
				return new GridLayoutGroupContext(obj);
			}
		}

		[StructLayout(LayoutKind.Sequential, Size = 1)]
		public struct CreateContext
		{
			public readonly UIElementContext UIElement(string name)
			{
				return UIElementExtensions.Create(name);
			}

			public readonly PlainWindowContext PlainWindow(string name)
			{
				return Select.PlainWindow(UIElement(name).uiElement).WithBorder().WithShadow()
					.WithDragProperties()
					.WithResizeProperties();
			}

			public readonly FancyWindowContext FancyWindow(string name)
			{
				return Select.FancyWindow(UIElement(name).uiElement).WithBorder().WithShadow()
					.WithDragProperties()
					.WithResizeProperties();
			}

			public readonly ScrollViewContext ScrollView(string name, ScrollViewConfiguration configuration)
			{
				return ScrollViewContextExtensions.Create(UIElement(name).uiElement, configuration);
			}

			public readonly ButtonContext Button(string name, string buttonText, UnityAction onClickCallback = null)
			{
				return ButtonContextExtensions.Create(UIElement(name).uiElement, buttonText).AddClickListener(onClickCallback);
			}

			public readonly ToggleContext Toggle(string name)
			{
				return ToggleContextExtensions.Create(UIElement(name).uiElement);
			}

			public readonly ToggleButtonContext ToggleButton(string name, string buttonText)
			{
				return ToggleButtonContextExtensions.Create(UIElement(name).uiElement, buttonText);
			}

			public readonly TextContext Text(string name)
			{
				return TextContextExtensions.Create(UIElement(name).uiElement);
			}

			public readonly SliderContext Slider(string name, SliderConfiguration configuration)
			{
				return SliderContextExtensions.Create(UIElement(name).uiElement, configuration);
			}

			public readonly InputFieldContext InputField(string name)
			{
				return InputFieldContextExtensions.Create(UIElement(name).uiElement);
			}

			public readonly ComboBoxContext ComboBox(string name)
			{
				UIComboBox val = Object.Instantiate<UIComboBox>(UIBuilder.comboBoxComponent, (Transform)null, false);
				return Select.ComboBox(((Component)val).gameObject);
			}

			public readonly HorizontalLayoutGroupContext HorizontalLayoutGroup(string name)
			{
				return Select.HorizontalLayoutGroup(UIElement(name).uiElement);
			}

			public readonly VerticalLayoutGroupContext VerticalLayoutGroup(string name)
			{
				return Select.VerticalLayoutGroup(UIElement(name).uiElement);
			}

			public readonly GridLayoutGroupContext GridLayoutGroup(string name)
			{
				return Select.GridLayoutGroup(UIElement(name).uiElement);
			}
		}

		public abstract record WindowContext<T> : UIElementContext where T : WindowContext<T>
		{
			public bool scrollCapture { get; set; }

			public GameObject panelBg { get; protected set; }

			protected abstract TranslucentImageProperties panelBgCloneImgProperties { get; }

			protected abstract ImageProperties panelBgBorderCloneImgProperties { get; }

			protected abstract ImageProperties panelBgDragTriggerCloneImgProperties { get; }

			protected abstract ImageProperties shadowCloneImgProperties { get; }

			public abstract T Context { get; }

			protected WindowContext(GameObject uiElement)
				: base(uiElement)
			{
			}

			public T WithScrollCapture()
			{
				scrollCapture = true;
				return Context;
			}

			internal T WithPanelBg()
			{
				if ((Object)(object)panelBg != (Object)null)
				{
					return Context;
				}
				panelBg = UIElementExtensions.WithComponent<UIElementContext, TranslucentImage>(Create.UIElement("panel-bg"), out TranslucentImage _, new IProperties<TranslucentImage>[1] { panelBgCloneImgProperties }).ChildOf(base.uiElement).WithAnchor(Anchor.Stretch)
					.uiElement;
				return Context;
			}

			internal T WithDragSuppor