Decompiled source of iGPU Savior v1.7.3

BepInEx/plugins/iGPU.Savior.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Bulbul;
using HarmonyLib;
using ModShared;
using NestopiSystem.DIContainers;
using PotatoOptimization.Configuration;
using PotatoOptimization.Core;
using PotatoOptimization.Features;
using PotatoOptimization.Patches;
using PotatoOptimization.UI;
using PotatoOptimization.Utilities;
using R3;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("iGPU Savior")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("iGPU Savior")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6a7f588e-da7a-4976-afed-31e2529c1039")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ModShared
{
	public class ModSettingsManager : MonoBehaviour
	{
		private abstract class SettingItemDef
		{
			public string Label;
		}

		private class ToggleDef : SettingItemDef
		{
			public bool DefaultValue;

			public Action<bool> OnValueChanged;
		}

		private class DropdownDef : SettingItemDef
		{
			public List<string> Options;

			public int DefaultIndex;

			public Action<int> OnValueChanged;
		}

		private class InputFieldDef : SettingItemDef
		{
			public string DefaultValue;

			public Action<string> OnValueChanged;
		}

		private class ModData
		{
			public string Name;

			public string Version;

			public List<SettingItemDef> Items = new List<SettingItemDef>();
		}

		[CompilerGenerated]
		private sealed class <>c__DisplayClass30_0
		{
			public DropdownDef def;
		}

		[CompilerGenerated]
		private sealed class <>c__DisplayClass30_1
		{
			public int idx;

			public <>c__DisplayClass30_0 CS$<>8__locals1;

			internal void <CreateDropdownSequence>b__0()
			{
				CS$<>8__locals1.def.OnValueChanged?.Invoke(idx);
			}
		}

		[CompilerGenerated]
		private sealed class <BuildSequence>d__27 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public ModSettingsManager <>4__this;

			private List<ModData>.Enumerator <>7__wrap1;

			private List<SettingItemDef>.Enumerator <>7__wrap2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <BuildSequence>d__27(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if ((uint)(num - -4) <= 1u || num == 2)
				{
					try
					{
						if (num == -4 || num == 2)
						{
							try
							{
							}
							finally
							{
								<>m__Finally2();
							}
						}
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>7__wrap1 = default(List<ModData>.Enumerator);
				<>7__wrap2 = default(List<SettingItemDef>.Enumerator);
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					int num = <>1__state;
					ModSettingsManager modSettingsManager = <>4__this;
					Transform contentParent;
					Transform contentParent2;
					switch (num)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						modSettingsManager._isBuildingUI = true;
						foreach (Transform item in modSettingsManager._contentParent)
						{
							Object.Destroy((Object)(object)((Component)item).gameObject);
						}
						<>2__current = null;
						<>1__state = 1;
						return true;
					case 1:
						<>1__state = -1;
						<>7__wrap1 = modSettingsManager._registeredMods.GetEnumerator();
						<>1__state = -3;
						goto IL_02a5;
					case 2:
						{
							<>1__state = -4;
							goto IL_027d;
						}
						IL_02a5:
						if (<>7__wrap1.MoveNext())
						{
							ModData current = <>7__wrap1.Current;
							if (current.Name != "General Settings" || !string.IsNullOrEmpty(current.Version))
							{
								modSettingsManager.CreateSectionHeader(current.Name, current.Version);
								if (current.Name == "iGPU Savior")
								{
									modSettingsManager.AdjustHeaderPosition(current.Name);
								}
							}
							<>7__wrap2 = current.Items.GetEnumerator();
							<>1__state = -4;
							goto IL_027d;
						}
						<>m__Finally1();
						<>7__wrap1 = default(List<ModData>.Enumerator);
						modSettingsManager.AdjustScrollViewPosition();
						contentParent = modSettingsManager._contentParent;
						LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)(object)((contentParent is RectTransform) ? contentParent : null));
						modSettingsManager._isBuildingUI = false;
						contentParent2 = modSettingsManager._contentParent;
						LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)(object)((contentParent2 is RectTransform) ? contentParent2 : null));
						modSettingsManager._isBuildingUI = false;
						return false;
						IL_027d:
						while (<>7__wrap2.MoveNext())
						{
							SettingItemDef current2 = <>7__wrap2.Current;
							if (current2 is ToggleDef toggleDef)
							{
								GameObject val = ModToggleCloner.CreateToggle(modSettingsManager._settingUIRoot, toggleDef.Label, toggleDef.DefaultValue, toggleDef.OnValueChanged);
								if ((Object)(object)val != (Object)null)
								{
									val.transform.SetParent(modSettingsManager._contentParent, false);
									modSettingsManager.EnforceLayout(val);
									val.SetActive(true);
								}
								continue;
							}
							if (current2 is DropdownDef def)
							{
								<>2__current = modSettingsManager.CreateDropdownSequence(def);
								<>1__state = 2;
								return true;
							}
							if (!(current2 is InputFieldDef inputFieldDef))
							{
								continue;
							}
							Transform val2 = modSettingsManager._settingUIRoot.Find("Graphics/ScrollView/Viewport/Content");
							if ((Object)(object)val2 == (Object)null)
							{
								PotatoPlugin.Log.LogError((object)"[Manager] Graphics Content not found!");
								continue;
							}
							GameObject val3 = ModInputFieldCloner.CreateInputField(val2, inputFieldDef.Label, inputFieldDef.DefaultValue, inputFieldDef.OnValueChanged);
							if ((Object)(object)val3 != (Object)null)
							{
								val3.transform.SetParent(modSettingsManager._contentParent, false);
								modSettingsManager.EnforceLayout(val3);
								val3.SetActive(true);
							}
							else
							{
								PotatoPlugin.Log.LogWarning((object)("[Manager] Failed to create input field: " + inputFieldDef.Label));
							}
						}
						<>m__Finally2();
						<>7__wrap2 = default(List<SettingItemDef>.Enumerator);
						modSettingsManager.CreateDivider();
						goto IL_02a5;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				((IDisposable)<>7__wrap1).Dispose();
			}

			private void <>m__Finally2()
			{
				<>1__state = -3;
				((IDisposable)<>7__wrap2).Dispose();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <CreateDropdownSequence>d__30 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public DropdownDef def;

			public ModSettingsManager <>4__this;

			private <>c__DisplayClass30_0 <>8__1;

			private GameObject <pulldownClone>5__2;

			private Transform <content>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <CreateDropdownSequence>d__30(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>8__1 = null;
				<pulldownClone>5__2 = null;
				<content>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0310: Unknown result type (might be due to invalid IL or missing references)
				//IL_031a: Expected O, but got Unknown
				int num = <>1__state;
				ModSettingsManager modSettingsManager = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
				{
					<>1__state = -1;
					<>8__1 = new <>c__DisplayClass30_0();
					<>8__1.def = def;
					<pulldownClone>5__2 = ModPulldownCloner.CloneAndClearPulldown(modSettingsManager._settingUIRoot);
					if ((Object)(object)<pulldownClone>5__2 == (Object)null)
					{
						return false;
					}
					string[] array = new string[3] { "TitleText", "Title/Text", "Text" };
					foreach (string text in array)
					{
						Transform val = <pulldownClone>5__2.transform.Find(text);
						if (!((Object)(object)val != (Object)null))
						{
							continue;
						}
						TMP_Text component = ((Component)val).GetComponent<TMP_Text>();
						if (Object.op_Implicit((Object)(object)component))
						{
							component.text = <>8__1.def.Label;
							ModLocalizer component2 = ((Component)val).GetComponent<ModLocalizer>();
							if ((Object)(object)component2 != (Object)null)
							{
								component2.Key = <>8__1.def.Label;
							}
							break;
						}
					}
					GameObject selectButtonTemplate = ModPulldownCloner.GetSelectButtonTemplate(modSettingsManager._settingUIRoot);
					for (int j = 0; j < <>8__1.def.Options.Count; j++)
					{
						<>c__DisplayClass30_1 CS$<>8__locals0 = new <>c__DisplayClass30_1
						{
							CS$<>8__locals1 = <>8__1,
							idx = j
						};
						ModPulldownCloner.AddOption(<pulldownClone>5__2, selectButtonTemplate, CS$<>8__locals0.CS$<>8__locals1.def.Options[j], delegate
						{
							CS$<>8__locals0.CS$<>8__locals1.def.OnValueChanged?.Invoke(CS$<>8__locals0.idx);
						});
					}
					if (<>8__1.def.DefaultIndex >= 0 && <>8__1.def.DefaultIndex < <>8__1.def.Options.Count)
					{
						modSettingsManager.UpdatePulldownSelectedText(<pulldownClone>5__2, <>8__1.def.Options[<>8__1.def.DefaultIndex]);
					}
					Object.Destroy((Object)(object)selectButtonTemplate);
					<pulldownClone>5__2.transform.SetParent(modSettingsManager._contentParent, false);
					modSettingsManager.EnforceLayout(<pulldownClone>5__2);
					<pulldownClone>5__2.SetActive(true);
					<content>5__3 = <pulldownClone>5__2.transform.Find("PulldownList/Pulldown/CurrentSelectText (TMP)/Content");
					Transform obj2 = <content>5__3;
					LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)(object)((obj2 is RectTransform) ? obj2 : null));
					Canvas.ForceUpdateCanvases();
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				case 1:
				{
					<>1__state = -1;
					Transform obj3 = <content>5__3;
					LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)(object)((obj3 is RectTransform) ? obj3 : null));
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				case 2:
				{
					<>1__state = -1;
					Transform obj = <content>5__3;
					float num2 = ((RectTransform)((obj is RectTransform) ? obj : null)).sizeDelta.y;
					if (num2 < 40f)
					{
						num2 = (float)<>8__1.def.Options.Count * 40f;
					}
					Transform originalPath = modSettingsManager._settingUIRoot.Find("Graphics/ScrollView/Viewport/Content/GraphicQualityPulldownList");
					ModPulldownCloner.EnsurePulldownListUI(<pulldownClone>5__2, originalPath, <content>5__3, num2);
					<>2__current = (object)new WaitForSeconds(0.05f);
					<>1__state = 3;
					return true;
				}
				case 3:
					<>1__state = -1;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private List<ModData> _registeredMods = new List<ModData>();

		private ModData _currentRegisteringMod;

		private Transform _contentParent;

		private Transform _settingUIRoot;

		private bool _isBuildingUI;

		private const float LABEL_WIDTH = 380f;

		public static ModSettingsManager Instance { get; private set; }

		public bool IsInitialized { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
				IsInitialized = true;
				Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			}
			else if ((Object)(object)Instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		public void RegisterMod(string modName, string modVersion)
		{
			ModData modData = _registeredMods.Find((ModData m) => m.Name == modName);
			if (modData != null)
			{
				_currentRegisteringMod = modData;
				return;
			}
			ModData modData2 = new ModData
			{
				Name = modName,
				Version = modVersion
			};
			_registeredMods.Add(modData2);
			_currentRegisteringMod = modData2;
			PotatoPlugin.Log.LogInfo((object)("[ModManager] Mod 注册: " + modName));
		}

		public void RegisterTranslation(string key, string en, string ja, string zh)
		{
			ModTranslationManager.Add(key, en, ja, zh);
		}

		private void EnsureCurrentMod()
		{
			if (_currentRegisteringMod == null)
			{
				RegisterMod("General Settings", "");
			}
		}

		public void AddToggle(string labelOrKey, bool defaultValue, Action<bool> onValueChanged)
		{
			EnsureCurrentMod();
			_currentRegisteringMod.Items.Add(new ToggleDef
			{
				Label = labelOrKey,
				DefaultValue = defaultValue,
				OnValueChanged = onValueChanged
			});
		}

		public void AddDropdown(string labelOrKey, List<string> options, int defaultIndex, Action<int> onValueChanged)
		{
			EnsureCurrentMod();
			_currentRegisteringMod.Items.Add(new DropdownDef
			{
				Label = labelOrKey,
				Options = options,
				DefaultIndex = defaultIndex,
				OnValueChanged = onValueChanged
			});
		}

		public void AddInputField(string labelText, string defaultValue, Action<string> onValueChanged)
		{
			EnsureCurrentMod();
			_currentRegisteringMod.Items.Add(new InputFieldDef
			{
				Label = labelText,
				DefaultValue = defaultValue,
				OnValueChanged = onValueChanged
			});
		}

		public void RebuildUI(Transform contentParent, Transform settingUIRoot)
		{
			if (!_isBuildingUI)
			{
				_contentParent = contentParent;
				_settingUIRoot = settingUIRoot;
				((MonoBehaviour)this).StartCoroutine(BuildSequence());
			}
		}

		[IteratorStateMachine(typeof(<BuildSequence>d__27))]
		private IEnumerator BuildSequence()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <BuildSequence>d__27(0)
			{
				<>4__this = this
			};
		}

		private void AdjustScrollViewPosition()
		{
			PotatoPlugin.Log.LogInfo((object)"[UI] AdjustScrollViewPosition called - doing nothing (Legacy code disabled)");
		}

		private void AdjustHeaderPosition(string modName)
		{
		}

		[IteratorStateMachine(typeof(<CreateDropdownSequence>d__30))]
		private IEnumerator CreateDropdownSequence(DropdownDef def)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CreateDropdownSequence>d__30(0)
			{
				<>4__this = this,
				def = def
			};
		}

		private void EnforceLayout(GameObject obj)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = obj.GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				component.anchorMin = new Vector2(0f, 1f);
				component.anchorMax = new Vector2(0f, 1f);
				component.pivot = new Vector2(0.5f, 1f);
				component.anchoredPosition = Vector2.zero;
				obj.transform.localPosition = Vector3.zero;
				obj.transform.localScale = Vector3.one;
				obj.transform.localRotation = Quaternion.identity;
			}
			TMP_Text[] componentsInChildren = obj.GetComponentsInChildren<TMP_Text>(true);
			foreach (TMP_Text val in componentsInChildren)
			{
				if (((Object)val).name.Contains("Title") || ((Object)val).name.Contains("Label") || ((Object)val).name == "Text")
				{
					LayoutElement val2 = ((Component)val).GetComponent<LayoutElement>();
					if ((Object)(object)val2 == (Object)null)
					{
						val2 = ((Component)val).gameObject.AddComponent<LayoutElement>();
					}
					val2.minWidth = 380f;
					val2.preferredWidth = 380f;
					val2.flexibleWidth = 0f;
					val.alignment = (TextAlignmentOptions)4097;
					break;
				}
			}
			LayoutElement val3 = obj.GetComponent<LayoutElement>();
			if ((Object)(object)val3 == (Object)null)
			{
				val3 = obj.AddComponent<LayoutElement>();
			}
			if (val3.minHeight < 10f)
			{
				val3.minHeight = 60f;
			}
			if (val3.preferredHeight < 10f)
			{
				val3.preferredHeight = 60f;
			}
		}

		private void CreateSectionHeader(string name, string version)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Header_" + name);
			val.transform.SetParent(_contentParent, false);
			val.AddComponent<RectTransform>().sizeDelta = new Vector2(0f, 55f);
			LayoutElement obj = val.AddComponent<LayoutElement>();
			obj.minHeight = 55f;
			obj.preferredHeight = 55f;
			obj.flexibleWidth = 1f;
			TextMeshProUGUI obj2 = val.AddComponent<TextMeshProUGUI>();
			string text = (string.IsNullOrEmpty(version) ? "" : (" <size=18><color=#888888>v" + version + "</color></size>"));
			((TMP_Text)obj2).text = "<size=24><b>" + name + "</b></size>" + text;
			((TMP_Text)obj2).alignment = (TextAlignmentOptions)1025;
			((Graphic)obj2).color = Color.white;
		}

		private void CreateDivider()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Divider");
			val.transform.SetParent(_contentParent, false);
			LayoutElement obj = val.AddComponent<LayoutElement>();
			obj.minHeight = 20f;
			obj.preferredHeight = 20f;
		}

		private void UpdatePulldownSelectedText(GameObject clone, string text)
		{
			string[] array = new string[2] { "PulldownList/Pulldown/CurrentSelectText (TMP)", "CurrentSelectText (TMP)" };
			foreach (string text2 in array)
			{
				Transform val = clone.transform.Find(text2);
				if (!((Object)(object)val != (Object)null))
				{
					continue;
				}
				TMP_Text component = ((Component)val).GetComponent<TMP_Text>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.text = text;
					ModLocalizer modLocalizer = ((Component)val).gameObject.GetComponent<ModLocalizer>();
					if ((Object)(object)modLocalizer == (Object)null)
					{
						modLocalizer = ((Component)val).gameObject.AddComponent<ModLocalizer>();
					}
					modLocalizer.Key = text;
					break;
				}
			}
		}
	}
}
namespace PotatoOptimization.UI
{
	public class ModPulldownCloner
	{
		private static Type GetPulldownUIType()
		{
			return TypeHelper.GetPulldownUIType();
		}

		public static GameObject CloneAndClearPulldown(Transform settingUITransform)
		{
			try
			{
				if ((Object)(object)settingUITransform == (Object)null)
				{
					PotatoPlugin.Log.LogError((object)"settingUITransform is null");
					return null;
				}
				Transform val = settingUITransform.Find("Graphics/ScrollView/Viewport/Content/GraphicQualityPulldownList");
				if ((Object)(object)val == (Object)null)
				{
					PotatoPlugin.Log.LogError((object)"GraphicQualityPulldownList not found");
					return null;
				}
				GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject);
				((Object)val2).name = "ModPulldownList";
				val2.SetActive(false);
				ModUIHelper.RemoveLocalizers(val2);
				string[] array = new string[3] { "TitleText", "Title/Text", "Text" };
				foreach (string text in array)
				{
					Transform val3 = val2.transform.Find(text);
					if ((Object)(object)val3 != (Object)null)
					{
						((Component)val3).gameObject.AddComponent<ModLocalizer>();
						break;
					}
				}
				array = new string[2] { "PulldownList/Pulldown/CurrentSelectText (TMP)", "CurrentSelectText (TMP)" };
				foreach (string text2 in array)
				{
					Transform val4 = val2.transform.Find(text2);
					if ((Object)(object)val4 != (Object)null)
					{
						((Component)val4).gameObject.AddComponent<ModLocalizer>();
						break;
					}
				}
				Transform val5 = val2.transform.Find("PulldownList/Pulldown/CurrentSelectText (TMP)/Content");
				if ((Object)(object)val5 == (Object)null)
				{
					PotatoPlugin.Log.LogError((object)"Cloned pulldown's Content container not found");
					Object.Destroy((Object)(object)val2);
					return null;
				}
				for (int num = val5.childCount - 1; num >= 0; num--)
				{
					Object.Destroy((Object)(object)((Component)val5.GetChild(num)).gameObject);
				}
				((Component)val5).gameObject.SetActive(true);
				PotatoPlugin.Log.LogInfo((object)"Content initialized (always active, clipped by parent)");
				Transform val6 = val2.transform.Find("PulldownList/PulldownButton");
				if ((Object)(object)val6 != (Object)null)
				{
					if ((Object)(object)((Component)val6).GetComponent<Button>() == (Object)null)
					{
						PotatoPlugin.Log.LogError((object)"PulldownButton has no Button component");
					}
				}
				else
				{
					PotatoPlugin.Log.LogError((object)"PulldownButton not found");
				}
				PotatoPlugin.Log.LogInfo((object)("Successfully cloned pulldown: " + ((Object)val2).name));
				return val2;
			}
			catch (Exception arg)
			{
				PotatoPlugin.Log.LogError((object)$"Failed to clone pulldown: {arg}");
				return null;
			}
		}

		public static GameObject GetSelectButtonTemplate(Transform settingUITransform)
		{
			try
			{
				if ((Object)(object)settingUITransform == (Object)null)
				{
					PotatoPlugin.Log.LogError((object)"settingUITransform is null");
					return null;
				}
				Transform val = settingUITransform.Find("Graphics/ScrollView/Viewport/Content/GraphicQualityPulldownList/PulldownList/Pulldown/CurrentSelectText (TMP)/Content");
				val = ((!((Object)(object)val != (Object)null) || val.childCount <= 0) ? null : val.GetChild(0));
				if ((Object)(object)val == (Object)null)
				{
					PotatoPlugin.Log.LogError((object)"Original SelectButton template not found");
					return null;
				}
				GameObject obj = Object.Instantiate<GameObject>(((Component)val).gameObject);
				((Object)obj).name = "SelectButtonTemplate";
				obj.SetActive(false);
				ModUIHelper.RemoveLocalizers(obj);
				return obj;
			}
			catch (Exception arg)
			{
				PotatoPlugin.Log.LogError((object)$"Failed to get SelectButton template: {arg}");
				return null;
			}
		}

		public static void AddOption(GameObject pulldownClone, GameObject buttonTemplate, string optionText, Action onClick)
		{
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Expected O, but got Unknown
			try
			{
				Transform val = pulldownClone.transform.Find("PulldownList/Pulldown/CurrentSelectText (TMP)/Content");
				if ((Object)(object)val == (Object)null)
				{
					val = pulldownClone.transform.Find("PulldownList/Pulldown/CurrentSelectText (TMP)/ScrollView/Viewport/Content");
					if ((Object)(object)val == (Object)null)
					{
						RectTransform[] componentsInChildren = pulldownClone.GetComponentsInChildren<RectTransform>(true);
						foreach (RectTransform val2 in componentsInChildren)
						{
							if (((Object)val2).name == "Content")
							{
								val = (Transform)(object)val2;
								break;
							}
						}
					}
					if ((Object)(object)val == (Object)null)
					{
						PotatoPlugin.Log.LogError((object)"Content container not found");
						return;
					}
				}
				GameObject val3 = Object.Instantiate<GameObject>(buttonTemplate, val);
				((Object)val3).name = "SelectButton_" + optionText;
				val3.SetActive(true);
				TMP_Text componentInChildren = val3.GetComponentInChildren<TMP_Text>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.text = optionText;
					((Component)componentInChildren).gameObject.AddComponent<ModLocalizer>().Key = optionText;
				}
				Image[] componentsInChildren2 = val3.GetComponentsInChildren<Image>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					((Graphic)componentsInChildren2[i]).raycastTarget = true;
				}
				Button component = val3.GetComponent<Button>();
				if (!((Object)(object)component != (Object)null))
				{
					return;
				}
				((UnityEventBase)component.onClick).RemoveAllListeners();
				((UnityEvent)component.onClick).AddListener((UnityAction)delegate
				{
					//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_00eb: Unknown result type (might be due to invalid IL or missing references)
					PotatoPlugin.Log.LogInfo((object)("Option clicked: " + optionText));
					try
					{
						Type pulldownUIType = GetPulldownUIType();
						if (pulldownUIType != null)
						{
							Component val4 = pulldownClone.GetComponent(pulldownUIType);
							if ((Object)(object)val4 == (Object)null)
							{
								val4 = pulldownClone.GetComponentInChildren(pulldownUIType);
							}
							if ((Object)(object)val4 != (Object)null)
							{
								LanguageSupplier val5 = ProjectLifetimeScope.Resolve<LanguageSupplier>();
								GameLanguageType lang = (GameLanguageType)((val5 == null) ? 2 : ((int)val5.Language.CurrentValue));
								string[] array = new string[2] { "PulldownList/Pulldown/CurrentSelectText (TMP)", "CurrentSelectText (TMP)" };
								foreach (string text in array)
								{
									Transform val6 = pulldownClone.transform.Find(text);
									if ((Object)(object)val6 != (Object)null)
									{
										ModLocalizer component3 = ((Component)val6).GetComponent<ModLocalizer>();
										if ((Object)(object)component3 != (Object)null)
										{
											component3.Key = optionText;
										}
										break;
									}
								}
								string text2 = ModTranslationManager.Get(optionText, lang);
								if (string.IsNullOrEmpty(text2))
								{
									text2 = optionText;
								}
								MethodInfo method = pulldownUIType.GetMethod("ChangeSelectContentText", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
								if (method != null)
								{
									method.Invoke(val4, new object[1] { text2 });
									PotatoPlugin.Log.LogInfo((object)("Updated selected text to: " + text2));
								}
								MethodInfo method2 = pulldownUIType.GetMethod("ClosePullDown", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
								if (method2 != null)
								{
									method2.Invoke(val4, new object[1] { false });
									PotatoPlugin.Log.LogInfo((object)"Dropdown closed via ClosePullDown()");
								}
							}
						}
					}
					catch (Exception ex)
					{
						PotatoPlugin.Log.LogWarning((object)("Failed to update dropdown: " + ex.Message));
					}
					onClick?.Invoke();
				});
				if (!((Selectable)component).interactable)
				{
					((Selectable)component).interactable = true;
				}
				if ((Object)(object)((Selectable)component).targetGraphic == (Object)null)
				{
					Image component2 = val3.GetComponent<Image>();
					if ((Object)(object)component2 != (Object)null)
					{
						((Selectable)component).targetGraphic = (Graphic)(object)component2;
					}
				}
			}
			catch (Exception arg)
			{
				PotatoPlugin.Log.LogError((object)$"Failed to add option: {arg}");
			}
		}

		public static void MountPulldown(GameObject pulldownClone, string parentPath)
		{
			try
			{
				GameObject val = GameObject.Find("UI_FacilitySetting");
				if (!((Object)(object)val == (Object)null))
				{
					Transform val2 = val.transform.Find(parentPath);
					if (!((Object)(object)val2 == (Object)null))
					{
						pulldownClone.transform.SetParent(val2, false);
						pulldownClone.SetActive(true);
					}
				}
			}
			catch (Exception arg)
			{
				PotatoPlugin.Log.LogError((object)$"Failed to mount pulldown: {arg}");
			}
		}

		public static void EnsurePulldownListUI(GameObject clone, Transform originalPath, Transform content, float manualContentHeight = -1f)
		{
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Expected O, but got Unknown
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Expected O, but got Unknown
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Type pulldownUIType = GetPulldownUIType();
				if (pulldownUIType == null)
				{
					PotatoPlugin.Log.LogError((object)"PulldownListUI type not found");
					return;
				}
				Transform val = clone.transform.Find("PulldownList");
				Transform val2 = clone.transform.Find("PulldownList/Pulldown");
				Transform obj = clone.transform.Find("PulldownList/PulldownButton");
				Transform val3 = clone.transform.Find("PulldownList/Pulldown/CurrentSelectText (TMP)");
				GameObject val4 = (((Object)(object)val != (Object)null) ? ((Component)val).gameObject : clone);
				Component pulldownUI = val4.GetComponent(pulldownUIType);
				if ((Object)(object)pulldownUI == (Object)null)
				{
					pulldownUI = val4.AddComponent(pulldownUIType);
				}
				Button val5 = ((obj != null) ? ((Component)obj).GetComponent<Button>() : null);
				TMP_Text val6 = ((val3 != null) ? ((Component)val3).GetComponent<TMP_Text>() : null);
				RectTransform val7 = ((val2 != null) ? ((Component)val2).GetComponent<RectTransform>() : null);
				RectTransform value2 = ((obj != null) ? ((Component)obj).GetComponent<RectTransform>() : null);
				RectTransform val8 = ((content != null) ? ((Component)content).GetComponent<RectTransform>() : null);
				if ((Object)(object)val5 == (Object)null || (Object)(object)val6 == (Object)null || (Object)(object)val7 == (Object)null)
				{
					return;
				}
				int childCount = content.childCount;
				float num = 40f;
				Rect rect;
				if (childCount > 0)
				{
					RectTransform component = ((Component)content.GetChild(0)).GetComponent<RectTransform>();
					if ((Object)(object)component != (Object)null)
					{
						rect = component.rect;
						if (((Rect)(ref rect)).height > 10f)
						{
							rect = component.rect;
							num = ((Rect)(ref rect)).height;
						}
					}
				}
				float num2 = (float)childCount * num;
				float num3 = 6f * num;
				bool num4 = num2 > num3;
				float num5 = (num4 ? num3 : num2);
				rect = val7.rect;
				float num6 = ((Rect)(ref rect)).height + num5 + 10f;
				if (num4)
				{
					VerticalLayoutGroup component2 = ((Component)content).GetComponent<VerticalLayoutGroup>();
					if ((Object)(object)component2 != (Object)null)
					{
						((HorizontalOrVerticalLayoutGroup)component2).childControlWidth = true;
						((HorizontalOrVerticalLayoutGroup)component2).childForceExpandWidth = true;
					}
					if (((Object)content.parent).name != "Viewport")
					{
						GameObject val9 = new GameObject("ScrollView", new Type[1] { typeof(RectTransform) });
						val9.transform.SetParent(content.parent, false);
						RectTransform component3 = val9.GetComponent<RectTransform>();
						component3.anchorMin = Vector2.zero;
						component3.anchorMax = new Vector2(1f, 0f);
						component3.pivot = new Vector2(0.5f, 1f);
						component3.sizeDelta = new Vector2(0f, num5);
						component3.anchoredPosition = Vector2.zero;
						ScrollRect val10 = val9.AddComponent<ScrollRect>();
						val10.horizontal = false;
						val10.vertical = true;
						val10.scrollSensitivity = 20f;
						val10.movementType = (MovementType)2;
						GameObject val11 = new GameObject("Viewport", new Type[2]
						{
							typeof(RectTransform),
							typeof(RectMask2D)
						});
						val11.transform.SetParent(val9.transform, false);
						RectTransform component4 = val11.GetComponent<RectTransform>();
						component4.anchorMin = Vector2.zero;
						component4.anchorMax = Vector2.one;
						component4.sizeDelta = Vector2.zero;
						content.SetParent(val11.transform, true);
						val10.viewport = component4;
						val10.content = val8;
						val8.anchorMin = new Vector2(0f, 1f);
						val8.anchorMax = new Vector2(1f, 1f);
						val8.pivot = new Vector2(0.5f, 1f);
						val8.anchoredPosition = Vector2.zero;
						val8.sizeDelta = new Vector2(0f, num2);
						ContentSizeFitter val12 = ((Component)content).GetComponent<ContentSizeFitter>();
						if ((Object)(object)val12 == (Object)null)
						{
							val12 = ((Component)content).gameObject.AddComponent<ContentSizeFitter>();
						}
						val12.verticalFit = (FitMode)2;
					}
				}
				else if ((Object)(object)val8 != (Object)null)
				{
					val8.anchorMin = Vector2.zero;
					val8.anchorMax = new Vector2(1f, 0f);
					val8.pivot = new Vector2(0.5f, 1f);
					val8.sizeDelta = new Vector2(0f, num2);
					val8.anchoredPosition = Vector2.zero;
				}
				Canvas val13 = clone.GetComponent<Canvas>();
				if ((Object)(object)val13 == (Object)null)
				{
					val13 = clone.AddComponent<Canvas>();
					val13.overrideSorting = false;
					val13.sortingOrder = 0;
					if ((Object)(object)clone.GetComponent<GraphicRaycaster>() == (Object)null)
					{
						clone.AddComponent<GraphicRaycaster>();
					}
					PotatoPlugin.Log.LogInfo((object)"✅ Canvas added to ROOT object (ModPulldownList)");
				}
				if ((Object)(object)val2 != (Object)null)
				{
					Canvas component5 = ((Component)val2).GetComponent<Canvas>();
					if ((Object)(object)component5 != (Object)null)
					{
						Object.Destroy((Object)(object)component5);
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					Canvas component6 = ((Component)val).GetComponent<Canvas>();
					if ((Object)(object)component6 != (Object)null)
					{
						Object.Destroy((Object)(object)component6);
					}
				}
				PulldownLayerController pulldownLayerController = clone.GetComponent<PulldownLayerController>();
				if ((Object)(object)pulldownLayerController == (Object)null)
				{
					pulldownLayerController = clone.AddComponent<PulldownLayerController>();
				}
				pulldownLayerController.Initialize(pulldownUI, val13);
				SetField("_currentSelectContentText", val6);
				SetField("_pullDownParentRect", val7);
				SetField("_openPullDownSizeDeltaY", num6);
				SetField("_pullDownOpenCloseSeconds", 0.3f);
				SetField("_pullDownOpenButton", val5);
				SetField("_pullDownButtonRect", value2);
				SetField("_isOpen", false);
				pulldownUIType.GetMethod("Setup")?.Invoke(pulldownUI, null);
				void SetField(string fieldName, object value)
				{
					if (value != null)
					{
						pulldownUIType.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(pulldownUI, value);
					}
				}
			}
			catch (Exception arg)
			{
				PotatoPlugin.Log.LogError((object)$"Failed to configure PulldownListUI: {arg}");
			}
		}
	}
	public class PulldownLayerController : MonoBehaviour
	{
		private Component pulldownUI;

		private Canvas targetCanvas;

		private FieldInfo isOpenField;

		private bool lastIsOpen;

		private bool isInitialized;

		public void Initialize(Component pulldownUIComponent, Canvas canvas)
		{
			pulldownUI = pulldownUIComponent;
			targetCanvas = canvas;
			if ((Object)(object)pulldownUI != (Object)null)
			{
				isOpenField = ((object)pulldownUI).GetType().GetField("_isOpen", BindingFlags.Instance | BindingFlags.NonPublic);
				isInitialized = true;
				UpdateSortingOrder(isOpen: false);
				PotatoPlugin.Log.LogInfo((object)"PulldownLayerController initialized successfully");
			}
		}

		private void Update()
		{
			if (!isInitialized || (Object)(object)pulldownUI == (Object)null || (Object)(object)targetCanvas == (Object)null || isOpenField == null)
			{
				return;
			}
			try
			{
				bool flag = (bool)isOpenField.GetValue(pulldownUI);
				if (flag != lastIsOpen)
				{
					UpdateSortingOrder(flag);
					lastIsOpen = flag;
				}
			}
			catch
			{
			}
		}

		private void UpdateSortingOrder(bool isOpen)
		{
			if (!((Object)(object)targetCanvas == (Object)null))
			{
				if (isOpen)
				{
					targetCanvas.overrideSorting = true;
					targetCanvas.sortingOrder = 30000;
				}
				else
				{
					targetCanvas.overrideSorting = false;
					targetCanvas.sortingOrder = 0;
				}
			}
		}
	}
	public static class ModUIHelper
	{
		public static void RemoveLocalizers(GameObject obj)
		{
			if (!((Object)(object)obj == (Object)null))
			{
				TextLocalizationBehaviour component = obj.GetComponent<TextLocalizationBehaviour>();
				if ((Object)(object)component != (Object)null)
				{
					Object.Destroy((Object)(object)component);
					PotatoPlugin.Log.LogInfo((object)("[UI Fix] Removed localization 'spy' from " + ((Object)obj).name));
				}
				TextLocalizationBehaviour[] componentsInChildren = obj.GetComponentsInChildren<TextLocalizationBehaviour>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Object.Destroy((Object)(object)componentsInChildren[i]);
				}
			}
		}
	}
	[HarmonyPatch(typeof(SettingUI), "Setup")]
	public class ModSettingsIntegration
	{
		private static GameObject modContentParent;

		private static InteractableUI modInteractableUI;

		private static SettingUI cachedSettingUI;

		private static Canvas _rootCanvas;

		private static List<GameObject> modDropdowns = new List<GameObject>();

		private static void Postfix(SettingUI __instance)
		{
			try
			{
				cachedSettingUI = __instance;
				_rootCanvas = ((Component)__instance).GetComponentInParent<Canvas>() ?? Object.FindObjectOfType<Canvas>();
				CreateModSettingsTab(__instance);
				HookIntoTabButtons(__instance);
				GameObject obj = modContentParent;
				if (obj != null)
				{
					obj.SetActive(false);
				}
			}
			catch (Exception ex)
			{
				PotatoPlugin.Log.LogError((object)("MOD integration failed: " + ex.Message + "\n" + ex.StackTrace));
			}
		}

		private static void CreateModSettingsTab(SettingUI settingUI)
		{
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Expected O, but got Unknown
			try
			{
				object? value = AccessTools.Field(typeof(SettingUI), "_creditsInteractableUI").GetValue(settingUI);
				InteractableUI val = (InteractableUI)((value is InteractableUI) ? value : null);
				object? value2 = AccessTools.Field(typeof(SettingUI), "_creditsParent").GetValue(settingUI);
				GameObject val2 = (GameObject)((value2 is GameObject) ? value2 : null);
				if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
				{
					return;
				}
				GameObject modTabButton = Object.Instantiate<GameObject>(((Component)val).gameObject);
				((Object)modTabButton).name = "ModSettingsTabButton";
				modTabButton.transform.SetParent(((Component)val).transform.parent, false);
				modTabButton.transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex() + 1);
				modContentParent = Object.Instantiate<GameObject>(val2);
				((Object)modContentParent).name = "ModSettingsContent";
				modContentParent.transform.SetParent(val2.transform.parent, false);
				modContentParent.SetActive(false);
				ScrollRect componentInChildren = modContentParent.GetComponentInChildren<ScrollRect>();
				if ((Object)(object)componentInChildren == (Object)null)
				{
					return;
				}
				RectTransform content = componentInChildren.content;
				foreach (Transform item in (Transform)content)
				{
					Object.Destroy((Object)(object)((Component)item).gameObject);
				}
				ConfigureContentLayout(((Component)content).gameObject);
				ModSettingsManager modSettingsManager = ModSettingsManager.Instance;
				if ((Object)(object)modSettingsManager == (Object)null)
				{
					GameObject val3 = new GameObject("ModSettingsManager");
					Object.DontDestroyOnLoad((Object)val3);
					modSettingsManager = val3.AddComponent<ModSettingsManager>();
				}
				ModUICoroutineRunner.Instance.RunDelayed(0.3f, delegate
				{
					UpdateModButtonText(modTabButton);
					UpdateModContentText(modContentParent);
					AdjustTabBarLayout(modTabButton.transform.parent);
				});
				modInteractableUI = modTabButton.GetComponent<InteractableUI>();
				InteractableUI obj = modInteractableUI;
				if (obj != null)
				{
					obj.Setup();
				}
				Button component = modTabButton.GetComponent<Button>();
				if (component != null)
				{
					((UnityEvent)component.onClick).AddListener((UnityAction)delegate
					{
						SwitchToModTab(settingUI);
					});
				}
				ModUIHelper.RemoveLocalizers(modTabButton);
				TMP_Text componentInChildren2 = modTabButton.GetComponentInChildren<TMP_Text>(true);
				if ((Object)(object)componentInChildren2 != (Object)null)
				{
					((Component)componentInChildren2).gameObject.AddComponent<ModLocalizer>().Key = "MOD_SETTINGS_TITLE";
				}
				else
				{
					_ = (Object)(object)modTabButton.GetComponentInChildren<Text>(true) != (Object)null;
				}
				LayoutElement val4 = modTabButton.GetComponent<LayoutElement>();
				if ((Object)(object)val4 == (Object)null)
				{
					val4 = modTabButton.AddComponent<LayoutElement>();
				}
				val4.flexibleWidth = 0f;
				val4.minWidth = 80f;
				val4.preferredWidth = 120f;
				RegisterCurrentMod(modSettingsManager);
			}
			catch (Exception ex)
			{
				PotatoPlugin.Log.LogError((object)("CreateModSettingsTab failed: " + ex.Message));
			}
		}

		private static void ConfigureContentLayout(GameObject content)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = content.GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				component.anchorMin = new Vector2(0f, 1f);
				component.anchorMax = new Vector2(1f, 1f);
				component.pivot = new Vector2(0.5f, 1f);
				component.anchoredPosition = Vector2.zero;
				component.sizeDelta = new Vector2(0f, 0f);
				((Transform)component).localScale = Vector3.one;
			}
			VerticalLayoutGroup obj = content.GetComponent<VerticalLayoutGroup>() ?? content.AddComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 16f;
			((LayoutGroup)obj).padding = new RectOffset(10, 40, 20, 20);
			((LayoutGroup)obj).childAlignment = (TextAnchor)0;
			((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true;
			ContentSizeFitter obj2 = content.GetComponent<ContentSizeFitter>() ?? content.AddComponent<ContentSizeFitter>();
			obj2.verticalFit = (FitMode)2;
			obj2.horizontalFit = (FitMode)0;
			ScrollRect componentInParent = content.GetComponentInParent<ScrollRect>();
			if (!((Object)(object)componentInParent != (Object)null))
			{
				return;
			}
			GameObject gameObject = ((Component)((Component)componentInParent).transform.parent).gameObject;
			VerticalLayoutGroup component2 = gameObject.GetComponent<VerticalLayoutGroup>();
			if ((Object)(object)component2 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component2);
			}
			HorizontalLayoutGroup component3 = gameObject.GetComponent<HorizontalLayoutGroup>();
			if ((Object)(object)component3 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component3);
			}
			RectTransform component4 = ((Component)componentInParent).GetComponent<RectTransform>();
			component4.anchorMin = Vector2.zero;
			component4.anchorMax = Vector2.one;
			component4.pivot = new Vector2(0.5f, 0.5f);
			component4.offsetMin = new Vector2(50f, 50f);
			component4.offsetMax = new Vector2(-50f, -150f);
			PotatoPlugin.Log.LogInfo((object)"[UI Fix] Constrained ScrollView window: Top=-150, Bottom=50");
			if ((Object)(object)componentInParent.viewport != (Object)null)
			{
				componentInParent.viewport.anchorMin = Vector2.zero;
				componentInParent.viewport.anchorMax = Vector2.one;
				componentInParent.viewport.sizeDelta = Vector2.zero;
				componentInParent.viewport.anchoredPosition = Vector2.zero;
				if ((Object)(object)((Component)componentInParent.viewport).GetComponent<RectMask2D>() == (Object)null)
				{
					((Component)componentInParent.viewport).gameObject.AddComponent<RectMask2D>();
				}
			}
		}

		private static void FixScrollViewLayout(ScrollRect scrollRect)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)scrollRect == (Object)null)
				{
					return;
				}
				GameObject gameObject = ((Component)scrollRect).gameObject;
				GameObject gameObject2 = ((Component)gameObject.transform.parent).gameObject;
				PotatoPlugin.Log.LogInfo((object)("[UI Nuclear Fix] Applying fix to " + ((Object)gameObject).name + " inside " + ((Object)gameObject2).name));
				VerticalLayoutGroup component = gameObject2.GetComponent<VerticalLayoutGroup>();
				if ((Object)(object)component != (Object)null)
				{
					PotatoPlugin.Log.LogInfo((object)"  - Destroying VerticalLayoutGroup on Root");
					Object.DestroyImmediate((Object)(object)component);
				}
				HorizontalLayoutGroup component2 = gameObject2.GetComponent<HorizontalLayoutGroup>();
				if ((Object)(object)component2 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)component2);
				}
				RectTransform component3 = ((Component)scrollRect).GetComponent<RectTransform>();
				component3.anchorMin = Vector2.zero;
				component3.anchorMax = Vector2.one;
				component3.pivot = new Vector2(0.5f, 0.5f);
				component3.offsetMin = new Vector2(40f, 50f);
				component3.offsetMax = new Vector2(-40f, -130f);
				PotatoPlugin.Log.LogInfo((object)$"  - ScrollView Margins Applied: Min={component3.offsetMin}, Max={component3.offsetMax}");
				if ((Object)(object)scrollRect.viewport != (Object)null)
				{
					Mask component4 = ((Component)scrollRect.viewport).GetComponent<Mask>();
					Image component5 = ((Component)scrollRect.viewport).GetComponent<Image>();
					if ((Object)(object)component4 != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)component4);
					}
					if ((Object)(object)component5 != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)component5);
					}
					if ((Object)(object)((Component)scrollRect.viewport).GetComponent<RectMask2D>() == (Object)null)
					{
						((Component)scrollRect.viewport).gameObject.AddComponent<RectMask2D>();
					}
					RectTransform component6 = ((Component)scrollRect.viewport).GetComponent<RectTransform>();
					component6.anchorMin = Vector2.zero;
					component6.anchorMax = Vector2.one;
					component6.sizeDelta = Vector2.zero;
					component6.anchoredPosition = Vector2.zero;
				}
			}
			catch (Exception ex)
			{
				PotatoPlugin.Log.LogError((object)("[UI Nuclear Fix] Failed: " + ex.Message));
			}
		}

		private static void RegisterCurrentMod(ModSettingsManager manager)
		{
			ModUICoroutineRunner.Instance.RunDelayed(0.5f, delegate
			{
				//IL_0216: Unknown result type (might be due to invalid IL or missing references)
				//IL_025a: Unknown result type (might be due to invalid IL or missing references)
				//IL_029e: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)modContentParent == (Object)null) && !((Object)(object)cachedSettingUI == (Object)null))
				{
					manager.RegisterMod("iGPU Savior", "1.7.3");
					manager.AddToggle("SETTING_MIRROR_AUTO", PotatoPlugin.Config.CfgEnableMirror.Value, delegate(bool val)
					{
						PotatoPlugin.Config.CfgEnableMirror.Value = val;
						Object.FindObjectOfType<PotatoController>()?.SetMirrorState(val);
					});
					manager.AddToggle("SETTING_PORTRAIT_AUTO", PotatoPlugin.Config.CfgEnablePortraitMode.Value, delegate(bool val)
					{
						PotatoPlugin.Config.CfgEnablePortraitMode.Value = val;
						PotatoPlugin.Log.LogInfo((object)$"竖屏优化自启动已设置为: {val}");
					});
					manager.AddDropdown("SETTING_MINI_SCALE", new List<string> { "1/3", "1/4", "1/5" }, (int)(PotatoPlugin.Config.CfgWindowScale.Value - 3), delegate(int index)
					{
						PotatoPlugin.Config.CfgWindowScale.Value = (WindowScaleRatio)(index + 3);
					});
					manager.AddDropdown("SETTING_DRAG_MODE", new List<string> { "DRAG_MODE_CTRL", "DRAG_MODE_ALT", "DRAG_MODE_RIGHT" }, (int)PotatoPlugin.Config.CfgDragMode.Value, delegate(int index)
					{
						PotatoPlugin.Config.CfgDragMode.Value = (DragMode)index;
					});
					List<string> options = new List<string>
					{
						"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10",
						"F11", "F12"
					};
					manager.AddDropdown("SETTING_KEY_POTATO", options, GetKeyIndex(PotatoPlugin.Config.KeyPotatoMode.Value), delegate(int i)
					{
						//IL_000b: Unknown result type (might be due to invalid IL or missing references)
						PotatoPlugin.Config.KeyPotatoMode.Value = GetKey(i);
					});
					manager.AddDropdown("SETTING_KEY_PIP", options, GetKeyIndex(PotatoPlugin.Config.KeyPiPMode.Value), delegate(int i)
					{
						//IL_000b: Unknown result type (might be due to invalid IL or missing references)
						PotatoPlugin.Config.KeyPiPMode.Value = GetKey(i);
					});
					manager.AddDropdown("SETTING_KEY_MIRROR", options, GetKeyIndex(PotatoPlugin.Config.KeyCameraMirror.Value), delegate(int i)
					{
						//IL_000b: Unknown result type (might be due to invalid IL or missing references)
						PotatoPlugin.Config.KeyCameraMirror.Value = GetKey(i);
					});
					ModSettingsManager modSettingsManager = manager;
					KeyCode value = PotatoPlugin.Config.KeyPortraitMode.Value;
					modSettingsManager.AddInputField("SETTING_KEY_PORTRAIT", ((object)(KeyCode)(ref value)).ToString(), delegate(string val)
					{
						//IL_0015: Unknown result type (might be due to invalid IL or missing references)
						//IL_001a: Unknown result type (might be due to invalid IL or missing references)
						//IL_0025: 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)
						try
						{
							KeyCode val2 = (KeyCode)Enum.Parse(typeof(KeyCode), val.ToUpper());
							PotatoPlugin.Config.KeyPortraitMode.Value = val2;
							PotatoPlugin.Log.LogInfo((object)$"Portrait key updated to: {val2}");
						}
						catch
						{
							PotatoPlugin.Log.LogWarning((object)("Invalid KeyCode: '" + val + "', ignored"));
						}
					});
					ScrollRect componentInChildren = modContentParent.GetComponentInChildren<ScrollRect>();
					if ((Object)(object)componentInChildren != (Object)null)
					{
						manager.RebuildUI((Transform)(object)componentInChildren.content, ((Component)cachedSettingUI).transform);
						ModUICoroutineRunner.Instance.RunDelayed(1f, delegate
						{
							if ((Object)(object)modContentParent != (Object)null)
							{
								DebugUIHierarchy(modContentParent.transform);
							}
						});
					}
				}
			});
			static KeyCode GetKey(int i)
			{
				return (KeyCode)(282 + i);
			}
			static int GetKeyIndex(KeyCode key)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected I4, but got Unknown
				int num = key - 282;
				if (num < 0 || num >= 12)
				{
					return 0;
				}
				return num;
			}
		}

		public static void DebugUIHierarchy(Transform root)
		{
			PotatoPlugin.Log.LogWarning((object)("[UI DEBUG] Inspecting Hierarchy for: " + ((Object)root).name));
			InspectRecursive(root, 0);
		}

		private static void InspectRecursive(Transform t, int depth)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			foreach (Transform item in t)
			{
				InspectRecursive(item, depth + 1);
			}
		}

		private static Transform GetGraphicsContentTransform()
		{
			if (!((Object)(object)cachedSettingUI != (Object)null))
			{
				return null;
			}
			return ((Component)cachedSettingUI).transform.Find("Graphics/ScrollView/Viewport/Content");
		}

		private static void UpdateModButtonText(GameObject modTabButton)
		{
			TextMeshProUGUI[] componentsInChildren = modTabButton.GetComponentsInChildren<TextMeshProUGUI>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((TMP_Text)componentsInChildren[i]).text = "MOD";
			}
		}

		private static void UpdateModContentText(GameObject modContentParent)
		{
			Transform val = modContentParent.transform.Find("Title");
			if ((Object)(object)val != (Object)null)
			{
				TextMeshProUGUI component = ((Component)val).GetComponent<TextMeshProUGUI>();
				if ((Object)(object)component != (Object)null)
				{
					((TMP_Text)component).text = "MOD";
				}
			}
			TextMeshProUGUI[] componentsInChildren = modContentParent.GetComponentsInChildren<TextMeshProUGUI>(true);
			foreach (TextMeshProUGUI val2 in componentsInChildren)
			{
				if (((TMP_Text)val2).text.Contains("Credits"))
				{
					((TMP_Text)val2).text = "MOD Settings";
				}
			}
		}

		private static void AdjustTabBarLayout(Transform tabBarParent)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			HorizontalLayoutGroup component = ((Component)tabBarParent).GetComponent<HorizontalLayoutGroup>();
			if ((Object)(object)component != (Object)null)
			{
				PotatoPlugin.Log.LogInfo((object)"[UI Fix] Reverting HorizontalLayoutGroup changes.");
				((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)component).spacing = 0f;
				if (((LayoutGroup)component).padding != null)
				{
					((LayoutGroup)component).padding.left = 0;
					((LayoutGroup)component).padding.right = 0;
				}
			}
			RectTransform component2 = ((Component)tabBarParent).GetComponent<RectTransform>();
			if ((Object)(object)component2 != (Object)null)
			{
				Vector2 anchoredPosition = component2.anchoredPosition;
				component2.anchoredPosition = new Vector2(anchoredPosition.x - 90f, anchoredPosition.y);
			}
		}

		private static void ConfigureGhostButton(GameObject modBtn)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			LayoutElement val = modBtn.GetComponent<LayoutElement>();
			if ((Object)(object)val == (Object)null)
			{
				val = modBtn.AddComponent<LayoutElement>();
			}
			val.ignoreLayout = true;
			RectTransform component = modBtn.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(1f, 0f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(0f, 0.5f);
			component.anchoredPosition = new Vector2(0f, 0f);
			component.sizeDelta = new Vector2(140f, 0f);
			TextMeshProUGUI componentInChildren = modBtn.GetComponentInChildren<TextMeshProUGUI>();
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				((TMP_Text)componentInChildren).enableWordWrapping = false;
			}
		}

		private static void HookIntoTabButtons(SettingUI settingUI)
		{
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			string[] array = new string[4] { "_generalInteractableUI", "_graphicInteractableUI", "_audioInteractableUI", "_creditsInteractableUI" };
			string[] array2 = new string[4] { "_generalParent", "_graphicParent", "_audioParent", "_creditsParent" };
			for (int i = 0; i < array.Length; i++)
			{
				object? value = AccessTools.Field(typeof(SettingUI), array[i]).GetValue(settingUI);
				InteractableUI val = (InteractableUI)((value is InteractableUI) ? value : null);
				object? value2 = AccessTools.Field(typeof(SettingUI), array2[i]).GetValue(settingUI);
				GameObject val2 = (GameObject)((value2 is GameObject) ? value2 : null);
				if (!((Object)(object)val != (Object)null))
				{
					continue;
				}
				InteractableUI capturedBtn = val;
				GameObject capturedParent = val2;
				Button component = ((Component)val).GetComponent<Button>();
				if (component == null)
				{
					continue;
				}
				((UnityEvent)component.onClick).AddListener((UnityAction)delegate
				{
					GameObject obj = modContentParent;
					if (obj != null)
					{
						obj.SetActive(false);
					}
					InteractableUI obj2 = modInteractableUI;
					if (obj2 != null)
					{
						obj2.DeactivateUseUI(false);
					}
					if (Object.op_Implicit((Object)(object)capturedParent))
					{
						capturedParent.SetActive(true);
						capturedBtn.ActivateUseUI(false);
					}
				});
			}
		}

		private static void SwitchToModTab(SettingUI settingUI)
		{
			string[] array = new string[4] { "_generalParent", "_graphicParent", "_audioParent", "_creditsParent" };
			foreach (string text in array)
			{
				object? value = AccessTools.Field(typeof(SettingUI), text).GetValue(settingUI);
				object? obj = ((value is GameObject) ? value : null);
				if (obj != null)
				{
					((GameObject)obj).SetActive(false);
				}
			}
			array = new string[4] { "_generalInteractableUI", "_graphicInteractableUI", "_audioInteractableUI", "_creditsInteractableUI" };
			foreach (string text2 in array)
			{
				object? value2 = AccessTools.Field(typeof(SettingUI), text2).GetValue(settingUI);
				object? obj2 = ((value2 is InteractableUI) ? value2 : null);
				if (obj2 != null)
				{
					((InteractableUI)obj2).DeactivateUseUI(false);
				}
			}
			OnOpenModTab();
			InteractableUI obj3 = modInteractableUI;
			if (obj3 != null)
			{
				obj3.ActivateUseUI(false);
			}
			GameObject obj4 = modContentParent;
			if (obj4 != null)
			{
				obj4.SetActive(true);
			}
			GameObject obj5 = modContentParent;
			ScrollRect val = ((obj5 != null) ? obj5.GetComponentInChildren<ScrollRect>() : null);
			if ((Object)(object)val != (Object)null)
			{
				LayoutRebuilder.ForceRebuildLayoutImmediate(modContentParent.GetComponent<RectTransform>());
				val.verticalNormalizedPosition = 1f;
			}
		}

		private static void OnOpenModTab()
		{
			PlayClickSound();
			foreach (GameObject modDropdown in modDropdowns)
			{
				if (!((Object)(object)modDropdown == (Object)null))
				{
					Component val = modDropdown.GetComponent("PulldownListUI") ?? modDropdown.GetComponentInChildren(Type.GetType("Bulbul.PulldownListUI, Assembly-CSharp"));
					((object)val)?.GetType().GetMethod("ClosePullDown")?.Invoke(val, new object[1] { true });
				}
			}
		}

		private static void PlayClickSound()
		{
			if (!((Object)(object)cachedSettingUI == (Object)null))
			{
				object value = AccessTools.Field(typeof(SettingUI), "_systemSeService").GetValue(cachedSettingUI);
				value?.GetType().GetMethod("PlayClick")?.Invoke(value, null);
			}
		}
	}
	public class ModUICoroutineRunner : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <DelayedAction>d__4 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public float seconds;

			public Action action;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DelayedAction>d__4(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(seconds);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					action?.Invoke();
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static ModUICoroutineRunner _instance;

		public static ModUICoroutineRunner Instance
		{
			get
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Expected O, but got Unknown
				if ((Object)(object)_instance == (Object)null)
				{
					GameObject val = new GameObject("ModUI_CoroutineRunner");
					Object.DontDestroyOnLoad((Object)val);
					_instance = val.AddComponent<ModUICoroutineRunner>();
				}
				return _instance;
			}
		}

		public void RunDelayed(float seconds, Action action)
		{
			((MonoBehaviour)this).StartCoroutine(DelayedAction(seconds, action));
		}

		[IteratorStateMachine(typeof(<DelayedAction>d__4))]
		private IEnumerator DelayedAction(float seconds, Action action)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayedAction>d__4(0)
			{
				seconds = seconds,
				action = action
			};
		}
	}
	[HarmonyPatch(typeof(SettingUI), "Activate")]
	public class ModSettingsActivateHandler
	{
		private static void Postfix(SettingUI __instance)
		{
			try
			{
				object? value = AccessTools.Field(typeof(ModSettingsIntegration), "modContentParent").GetValue(null);
				GameObject val = (GameObject)((value is GameObject) ? value : null);
				object? value2 = AccessTools.Field(typeof(ModSettingsIntegration), "modInteractableUI").GetValue(null);
				object? obj = ((value2 is InteractableUI) ? value2 : null);
				if (val != null)
				{
					val.SetActive(false);
				}
				if (obj != null)
				{
					((InteractableUI)obj).DeactivateUseUI(false);
				}
				object? value3 = AccessTools.Field(typeof(SettingUI), "_generalInteractableUI").GetValue(__instance);
				InteractableUI val2 = (InteractableUI)((value3 is InteractableUI) ? value3 : null);
				object? value4 = AccessTools.Field(typeof(SettingUI), "_generalParent").GetValue(__instance);
				object? obj2 = ((value4 is GameObject) ? value4 : null);
				if (val2 != null)
				{
					val2.ActivateUseUI(false);
				}
				if (obj2 != null)
				{
					((GameObject)obj2).SetActive(true);
				}
				string[] array = new string[3] { "_graphicParent", "_audioParent", "_creditsParent" };
				foreach (string text in array)
				{
					object? value5 = AccessTools.Field(typeof(SettingUI), text).GetValue(__instance);
					object? obj3 = ((value5 is GameObject) ? value5 : null);
					if (obj3 != null)
					{
						((GameObject)obj3).SetActive(false);
					}
				}
			}
			catch
			{
			}
		}
	}
	public class ModToggleCloner
	{
		public static GameObject CreateToggle(Transform settingRoot, string labelText, bool initialValue, Action<bool> onValueChanged)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Expected O, but got Unknown
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Expected O, but got Unknown
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			Button btnOn;
			Button btnOff;
			try
			{
				if ((Object)(object)settingRoot == (Object)null)
				{
					return null;
				}
				Transform val = settingRoot.Find("MusicAudio/ScrollView/Viewport/Content");
				if ((Object)(object)val == (Object)null)
				{
					PotatoPlugin.Log.LogError((object)"Audio tab content not found");
					return null;
				}
				Transform val2 = null;
				foreach (Transform item in val)
				{
					Transform val3 = item;
					if (((Object)val3).name.Contains("Pomodoro") && ((Object)val3).name.Contains("OnOff"))
					{
						val2 = val3;
						break;
					}
				}
				if ((Object)(object)val2 == (Object)null)
				{
					PotatoPlugin.Log.LogError((object)"Original Pomodoro Row not found! Cannot clone style.");
					return null;
				}
				PotatoPlugin.Log.LogInfo((object)("Found template row: " + ((Object)val2).name));
				GameObject val4 = Object.Instantiate<GameObject>(((Component)val2).gameObject);
				((Object)val4).name = "ModToggle_" + labelText;
				val4.SetActive(true);
				RemoveLocalizers(val4);
				val4.AddComponent<ModLocalizer>().Key = labelText;
				TMP_Text[] componentsInChildren = val4.GetComponentsInChildren<TMP_Text>(true);
				bool flag = false;
				if (componentsInChildren.Length != 0)
				{
					componentsInChildren.OrderBy((TMP_Text t) => t.transform.position.x).ToArray()[0].text = labelText;
					flag = true;
				}
				if (!flag)
				{
					Transform val5 = val4.transform.Find("Title");
					if ((Object)(object)val5 != (Object)null && (Object)(object)((Component)val5).GetComponent<TMP_Text>() != (Object)null)
					{
						((Component)val5).GetComponent<TMP_Text>().text = labelText;
					}
				}
				Button[] componentsInChildren2 = val4.GetComponentsInChildren<Button>(true);
				if (componentsInChildren2.Length < 2)
				{
					PotatoPlugin.Log.LogError((object)"Cloned row has less than 2 buttons!");
					return val4;
				}
				Array.Sort(componentsInChildren2, (Button a, Button b) => ((Component)a).transform.position.x.CompareTo(((Component)b).transform.position.x));
				btnOn = componentsInChildren2[0];
				btnOff = componentsInChildren2[1];
				SetButtonText(btnOn, "ON");
				SetButtonText(btnOff, "OFF");
				((UnityEventBase)btnOn.onClick).RemoveAllListeners();
				((UnityEventBase)btnOff.onClick).RemoveAllListeners();
				((UnityEvent)btnOn.onClick).AddListener((UnityAction)delegate
				{
					if (((Selectable)btnOn).interactable)
					{
						UpdateState(state: true);
						onValueChanged?.Invoke(obj: true);
						PlayClickSound(settingRoot);
					}
				});
				((UnityEvent)btnOff.onClick).AddListener((UnityAction)delegate
				{
					if (((Selectable)btnOff).interactable)
					{
						UpdateState(state: false);
						onValueChanged?.Invoke(obj: false);
						PlayClickSound(settingRoot);
					}
				});
				UpdateState(initialValue);
				Transform parent = ((Component)btnOn).transform.parent;
				HorizontalLayoutGroup component = val4.GetComponent<HorizontalLayoutGroup>();
				if ((Object)(object)component != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)component);
				}
				if ((Object)(object)parent != (Object)null)
				{
					RectTransform component2 = ((Component)parent).GetComponent<RectTransform>();
					if ((Object)(object)component2 != (Object)null)
					{
						Vector2 anchorMin = component2.anchorMin;
						Vector2 anchorMax = component2.anchorMax;
						component2.anchorMin = new Vector2(anchorMin.x, 0.5f);
						component2.anchorMax = new Vector2(anchorMax.x, 0.5f);
						component2.pivot = new Vector2(component2.pivot.x, 0.5f);
						component2.anchoredPosition = Vector2.op_Implicit(new Vector3(197.5f, 0f, 0f));
					}
				}
				return val4;
			}
			catch (Exception arg)
			{
				PotatoPlugin.Log.LogError((object)$"CreateToggle failed: {arg}");
				return null;
			}
			void UpdateState(bool state)
			{
				((Selectable)btnOn).interactable = !state;
				((Selectable)btnOff).interactable = state;
				InteractableUI component3 = ((Component)btnOn).GetComponent<InteractableUI>();
				InteractableUI component4 = ((Component)btnOff).GetComponent<InteractableUI>();
				if (state)
				{
					if (component3 != null)
					{
						component3.ActivateUseUI(false);
					}
					if (component4 != null)
					{
						component4.DeactivateUseUI(false);
					}
				}
				else
				{
					if (component3 != null)
					{
						component3.DeactivateUseUI(false);
					}
					if (component4 != null)
					{
						component4.ActivateUseUI(false);
					}
				}
			}
		}

		private static void SetButtonText(Button btn, string text)
		{
			TMP_Text componentInChildren = ((Component)btn).GetComponentInChildren<TMP_Text>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.text = text;
			}
		}

		private static void PlayClickSound(Transform root)
		{
		}

		private static void RemoveLocalizers(GameObject obj)
		{
			TextLocalizationBehaviour component = obj.GetComponent<TextLocalizationBehaviour>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
				PotatoPlugin.Log.LogInfo((object)("[UI Fix] Removed localization 'spy' from " + ((Object)obj).name));
			}
			TextLocalizationBehaviour[] componentsInChildren = obj.GetComponentsInChildren<TextLocalizationBehaviour>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren[i]);
			}
		}
	}
	public class ModInputFieldCloner
	{
		public static GameObject CreateInputField(Transform modContent, string labelText, string initialValue, Action<string> onValueChanged)
		{
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)modContent == (Object)null)
				{
					return null;
				}
				Transform val2 = modContent.Find("FrameRate");
				if ((Object)(object)val2 == (Object)null)
				{
					PotatoPlugin.Log.LogWarning((object)"[Input] Template 'FrameRate' not found!");
					return null;
				}
				GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject);
				((Object)val3).name = labelText.Replace(" ", "").Replace("(", "").Replace(")", "");
				val3.SetActive(false);
				Transform val4 = val3.transform.Find("DeactiveFrameRate");
				if ((Object)(object)val4 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)((Component)val4).gameObject);
				}
				Transform val5 = val3.transform.Find("TitleText");
				if ((Object)(object)val5 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)((Component)val5).gameObject);
				}
				MonoBehaviour[] componentsInChildren = val3.GetComponentsInChildren<MonoBehaviour>(true);
				foreach (MonoBehaviour val6 in componentsInChildren)
				{
					if (!((Object)(object)val6 == (Object)null))
					{
						Type type = ((object)val6).GetType();
						string text = type.Namespace ?? "";
						if (!text.StartsWith("UnityEngine.UI") && !text.Contains("TMPro") && !(type == typeof(LayoutElement)) && !(type == typeof(CanvasGroup)) && !(type == typeof(CanvasRenderer)))
						{
							Object.DestroyImmediate((Object)(object)val6);
						}
					}
				}
				Transform val7 = val3.transform.Find("ActiveFrameRate");
				if ((Object)(object)val7 != (Object)null)
				{
					((Object)val7).name = "InputField";
					GameObject gameObject = ((Component)val7).gameObject;
					HorizontalLayoutGroup component = gameObject.GetComponent<HorizontalLayoutGroup>();
					if ((Object)(object)component != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)component);
					}
					VerticalLayoutGroup component2 = gameObject.GetComponent<VerticalLayoutGroup>();
					if ((Object)(object)component2 != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)component2);
					}
					ContentSizeFitter component3 = gameObject.GetComponent<ContentSizeFitter>();
					if ((Object)(object)component3 != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)component3);
					}
					RectTransform component4 = ((Component)val7).GetComponent<RectTransform>();
					if ((Object)(object)component4 != (Object)null)
					{
						component4.anchorMin = new Vector2(0.5f, 0.5f);
						component4.anchorMax = new Vector2(0.5f, 0.5f);
						component4.pivot = new Vector2(0.5f, 0.5f);
						component4.anchoredPosition = Vector2.zero;
						component4.sizeDelta = new Vector2(1260f, 50f);
					}
					Transform obj = val7.Find("TitleText");
					TMP_Text val8 = ((obj != null) ? ((Component)obj).GetComponent<TMP_Text>() : null);
					if ((Object)(object)val8 == (Object)null)
					{
						val8 = ((Component)val7).GetComponentInChildren<TMP_Text>();
					}
					if ((Object)(object)val8 != (Object)null)
					{
						val8.text = labelText;
						ModLocalizer modLocalizer = ((Component)val8).gameObject.GetComponent<ModLocalizer>();
						if ((Object)(object)modLocalizer == (Object)null)
						{
							modLocalizer = ((Component)val8).gameObject.AddComponent<ModLocalizer>();
						}
						modLocalizer.Key = labelText;
						val8.alignment = (TextAlignmentOptions)4097;
						RectTransform component5 = ((Component)val8).GetComponent<RectTransform>();
						if ((Object)(object)component5 != (Object)null)
						{
							component5.anchorMin = new Vector2(0.5f, 0.5f);
							component5.anchorMax = new Vector2(0.5f, 0.5f);
							component5.pivot = new Vector2(0f, 0.5f);
							component5.anchoredPosition = new Vector2(-306f, 40f);
							component5.sizeDelta = new Vector2(400f, 50f);
						}
					}
					Transform val9 = val7.Find("WorkTimeInputField (TMP)");
					if ((Object)(object)val9 == (Object)null)
					{
						TMP_InputField componentInChildren = ((Component)val7).GetComponentInChildren<TMP_InputField>();
						if ((Object)(object)componentInChildren != (Object)null)
						{
							val9 = ((Component)componentInChildren).transform;
						}
					}
					if ((Object)(object)val9 != (Object)null)
					{
						((Object)val9).name = "TMP_InputField";
						RectTransform component6 = ((Component)val9).GetComponent<RectTransform>();
						if ((Object)(object)component6 != (Object)null)
						{
							component6.anchorMin = new Vector2(0.5f, 0.5f);
							component6.anchorMax = new Vector2(0.5f, 0.5f);
							component6.pivot = new Vector2(0f, 0.5f);
							component6.anchoredPosition = new Vector2(40f, 40f);
							component6.sizeDelta = new Vector2(405f, 40f);
						}
					}
					TMP_InputField componentInChildren2 = ((Component)val7).GetComponentInChildren<TMP_InputField>();
					if ((Object)(object)componentInChildren2 != (Object)null)
					{
						componentInChildren2.contentType = (ContentType)0;
						componentInChildren2.lineType = (LineType)0;
						componentInChildren2.characterValidation = (CharacterValidation)0;
						componentInChildren2.characterLimit = 0;
						componentInChildren2.text = initialValue;
						((UnityEventBase)componentInChildren2.onValueChanged).RemoveAllListeners();
						((UnityEventBase)componentInChildren2.onEndEdit).RemoveAllListeners();
						((UnityEventBase)componentInChildren2.onSubmit).RemoveAllListeners();
						((UnityEventBase)componentInChildren2.onSelect).RemoveAllListeners();
						((UnityEventBase)componentInChildren2.onDeselect).RemoveAllListeners();
						((UnityEvent<string>)(object)componentInChildren2.onEndEdit).AddListener((UnityAction<string>)delegate(string val)
						{
							onValueChanged?.Invoke(val);
						});
					}
				}
				LayoutElement val10 = val3.GetComponent<LayoutElement>();
				if ((Object)(object)val10 == (Object)null)
				{
					val10 = val3.AddComponent<LayoutElement>();
				}
				val10.minHeight = 50f;
				val10.preferredHeight = 50f;
				val10.flexibleHeight = 0f;
				return val3;
			}
			catch (Exception arg)
			{
				PotatoPlugin.Log.LogError((object)$"[Input] CreateInputField failed: {arg}");
				return null;
			}
		}
	}
	public class ModLocalizer : MonoBehaviour
	{
		private string _key;

		private TMP_Text _textComp;

		private IDisposable _subscription;

		private GameLanguageType _currentLang = (GameLanguageType)2;

		private FontSupplier _fontSupplier;

		public string Key
		{
			get
			{
				return _key;
			}
			set
			{
				if (_key != value)
				{
					_key = value;
					Refresh();
				}
			}
		}

		private void OnEnable()
		{
			if ((Object)(object)_textComp != (Object)null && !string.IsNullOrEmpty(_key))
			{
				Refresh();
			}
		}

		private void Start()
		{
			_textComp = ((Component)this).GetComponent<TMP_Text>();
			if ((Object)(object)_textComp == (Object)null)
			{
				_textComp = ((Component)this).GetComponentInChildren<TMP_Text>();
			}
			if ((Object)(object)_textComp == (Object)null)
			{
				return;
			}
			try
			{
				LanguageSupplier val = ProjectLifetimeScope.Resolve<LanguageSupplier>();
				_fontSupplier = ProjectLifetimeScope.Resolve<FontSupplier>();
				if (val != null)
				{
					_subscription = ObservableSubscribeExtensions.Subscribe<GameLanguageType>((Observable<GameLanguageType>)(object)val.Language, (Action<GameLanguageType>)delegate(GameLanguageType lang)
					{
						//IL_0001: Unknown result type (might be due to invalid IL or missing references)
						//IL_0002: Unknown result type (might be due to invalid IL or missing references)
						_currentLang = lang;
						Refresh();
					});
				}
			}
			catch (Exception arg)
			{
				PotatoPlugin.Log.LogError((object)$"[ModLocalizer] Error in Start: {arg}");
			}
		}

		public void Refresh()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_textComp == (Object)null)
			{
				return;
			}
			string text = ModTranslationManager.Get(Key, _currentLang);
			if (!string.IsNullOrEmpty(text))
			{
				_textComp.text = text;
			}
			if ((Object)(object)_fontSupplier != (Object)null)
			{
				TMP_FontAsset fontAsset = _fontSupplier.GetFontAsset(_currentLang);
				if ((Object)(object)fontAsset != (Object)null)
				{
					_textComp.font = fontAsset;
				}
			}
		}

		private void OnDestroy()
		{
			_subscription?.Dispose();
		}
	}
	public static class ModTranslationManager
	{
		private static Dictionary<string, Dictionary<GameLanguageType, string>> _translations;

		static ModTranslationManager()
		{
			_translations = new Dictionary<string, Dictionary<GameLanguageType, string>>();
			InitializeTranslations();
		}

		public static void Add(string key, string en, string ja, string zh)
		{
			Dictionary<GameLanguageType, string> value = new Dictionary<GameLanguageType, string>
			{
				{
					(GameLanguageType)2,
					en
				},
				{
					(GameLanguageType)1,
					ja
				},
				{
					(GameLanguageType)3,
					zh
				},
				{
					(GameLanguageType)4,
					zh
				}
			};
			_translations[key] = value;
		}

		private static void InitializeTranslations()
		{
			Add("MOD_SETTINGS_TITLE", "MOD Settings", "MOD設定", "MOD 设置");
			Add("SETTING_MIRROR_AUTO", "Mirror Auto-Start", "ミラー自動起動", "镜像自启动");
			Add("SETTING_PORTRAIT_AUTO", "Portrait Auto-Start", "縦画面自動起動", "竖屏优化自启动");
			Add("SETTING_MINI_SCALE", "Mini Window Scale", "小窓スケール", "小窗缩放");
			Add("SETTING_DRAG_MODE", "Drag Mode", "ドラッグモード", "小窗拖动模式");
			Add("SETTING_KEY_POTATO", "Potato Mode Key", "ポテトモードキー", "土豆模式快捷键");
			Add("SETTING_KEY_PIP", "PiP Mode Key", "PiPモードキー", "小窗模式快捷键");
			Add("SETTING_KEY_MIRROR", "Mirror Key", "ミラーキー", "镜像模式快捷键");
			Add("SETTING_KEY_PORTRAIT", "Portrait Key", "縦画面キー", "竖屏优化快捷键");
			Add("DRAG_MODE_CTRL", "Ctrl + Left Click", "Ctrl + 左クリック", "Ctrl + 左键");
			Add("DRAG_MODE_ALT", "Alt + Left Click", "Alt + 左クリック", "Alt + 左键");
			Add("DRAG_MODE_RIGHT", "Right Key Hold", "右クリックホールド", "右键按住");
		}

		public static string Get(string key, GameLanguageType lang)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(key))
			{
				return "";
			}
			if (_translations.TryGetValue(key, out var value))
			{
				if (value.TryGetValue(lang, out var value2))
				{
					return value2;
				}
				if (value.TryGetValue((GameLanguageType)2, out var value3))
				{
					return value3;
				}
				return "[" + key + "]";
			}
			return key;
		}
	}
}
namespace PotatoOptimization.Patches
{
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public class InputMousePositionPatch
	{
		public static bool IsInputMirrored { get; set; }

		private static void Postfix(ref Vector3 __result)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			if (IsInputMirrored && !IsPointerOverUI(__result))
			{
				__result = new Vector3((float)Screen.width - __result.x, __result.y, __result.z);
			}
		}

		private static bool IsPointerOverUI(Vector3 mousePosition)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)EventSystem.current != (Object)null)
			{
				PointerEventData val = new PointerEventData(EventSystem.current)
				{
					position = new Vector2(mousePosition.x, mousePosition.y)
				};
				List<RaycastResult> list = new List<RaycastResult>();
				EventSystem.current.RaycastAll(val, list);
				foreach (RaycastResult item in list)
				{
					RaycastResult current = item;
					if ((Object)(object)((RaycastResult)(ref current)).gameObject != (Object)null && ((Object)((RaycastResult)(ref current)).gameObject).name != "MirrorDisplay" && (Object)(object)((RaycastResult)(ref current)).gameObject.GetComponentInParent<Canvas>() != (Object)null && ((Object)((RaycastResult)(ref current)).gameObject.GetComponentInParent<Canvas>()).name != "MirrorCanvas")
					{
						return true;
					}
				}
			}
			return false;
		}
	}
}
namespace PotatoOptimization.Utilities
{
	public static class WindowManager
	{
		public struct POINT
		{
			public int X;

			public int Y;
		}

		public struct RECT
		{
			public int Left;

			public int Top;

			public int Right;

			public int Bottom;
		}

		private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);

		private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);

		[DllImport("user32.dll")]
		private static extern IntPtr GetActiveWindow();

		[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
		private static extern int SetWindowLong32(IntPtr hWnd, int nIndex, int dwNewLong);

		[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
		private static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

		[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
		private static extern int GetWindowLong32(IntPtr hWnd, int nIndex);

		[DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")]
		private static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);

		[DllImport("user32.dll")]
		private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);

		[DllImport("user32.dll")]
		private static extern bool ReleaseCapture();

		[DllImport("user32.dll")]
		private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

		[DllImport("user32.dll")]
		[return: MarshalAs(UnmanagedType.Bool)]
		private static extern bool GetCursorPos(out POINT lpPoint);

		[DllImport("user32.dll")]
		[return: MarshalAs(UnmanagedType.Bool)]
		private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);

		public static IntPtr GetCurrentWindowHandle()
		{
			return GetActiveWindow();
		}

		public static IntPtr SetWindowStyle(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
		{
			if (IntPtr.Size == 8)
			{
				return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
			}
			return new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32()));
		}

		public static IntPtr GetWindowStyle(IntPtr hWnd, int nIndex)
		{
			if (IntPtr.Size == 8)
			{
				return GetWindowLongPtr64(hWnd, nIndex);
			}
			return new IntPtr(GetWindowLong32(hWnd, nIndex));
		}

		public static void RemoveWindowBorder(IntPtr hWnd)
		{
			long num = GetWindowStyle(hWnd, -16).ToInt64();
			num &= -13369345;
			SetWindowStyle(hWnd, -16, new IntPtr(num));
			SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, 99u);
		}

		public static void RestoreWindowStyle(IntPtr hWnd, IntPtr originalStyle)
		{
			SetWindowStyle(hWnd, -16, originalStyle);
			SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, 99u);
		}

		public static bool MoveWindow(IntPtr hWnd, int x, int y)
		{
			return SetWindowPos(hWnd, IntPtr.Zero, x, y, 0, 0, 5u);
		}

		public static void StartSystemDrag()
		{
			try
			{
				ReleaseCapture();
				SendMessage(GetActiveWindow(), 161, 2, 0);
			}
			catch (Exception ex)
			{
				PotatoPlugin.Log.LogError((object)("拖动窗口失败: " + ex.Message));
			}
		}

		public static bool GetCursorScreenPosition(out POINT point)
		{
			return GetCursorPos(out point);
		}

		public static bool GetWindowBounds(IntPtr hWnd, out RECT rect)
		{
			return GetWindowRect(hWnd, out rect);
		}
	}
	public static class TypeHelper
	{
		private static readonly Dictionary<string, Type> _typeCache = new Dictionary<string, Type>();

		public static Type GetPulldownUIType()
		{
			if (_typeCache.TryGetValue("PulldownUI", out var value))
			{
				return value;
			}
			Type type = Type.GetType("Bulbul.PulldownListUI, Assembly-CSharp") ?? Type.GetType("PulldownListUI, Assembly-CSharp") ?? Type.GetType("PulldownListUI");
			if (type != null)
			{
				_typeCache["PulldownUI"] = type;
			}
			return type;
		}

		public static Type GetSettingUIType()
		{
			if (_typeCache.TryGetValue("SettingUI", out var value))
			{
				return value;
			}
			Type type = Type.GetType("Bulbul.SettingUI, Assembly-CSharp") ?? Type.GetType("SettingUI, Assembly-CSharp") ?? Type.GetType("SettingUI");
			if (type != null)
			{
				_typeCache["SettingUI"] = type;
			}
			return type;
		}

		public static void ClearCache()
		{
			_typeCache.Clear();
		}

		public static Type FindType(string typeName, params string[] assemblyNames)
		{
			if (_typeCache.TryGetValue(typeName, out var value))
			{
				return value;
			}
			Type type = null;
			foreach (string text in assemblyNames)
			{
				type = Type.GetType(typeName + ", " + text);
				if (type != null)
				{
					break;
				}
			}
			if (type == null)
			{
				type = Type.GetType(typeName);
			}
			if (type != null)
			{
				_typeCache[typeName] = type;
			}
			return type;
		}
	}
}
namespace PotatoOptimization.Features
{
	public class RenderQualityManager
	{
		private bool _isPotatoMode;

		private float _lastRunTime;

		public bool IsPotatoMode => _isPotatoMode;

		public void TogglePotatoMode()
		{
			_isPotatoMode = !_isPotatoMode;
			if (_isPotatoMode)
			{
				ApplyPotatoMode(showLog: true);
				PotatoPlugin.Log.LogWarning((object)">>> 土豆模式: ON <<<");
			}
			else
			{
				RestoreQuality();
				PotatoPlugin.Log.LogWarning((object)">>> 土豆模式: OFF <<<");
			}
		}

		public void UpdatePotatoMode()
		{
			if (_isPotatoMode && Time.realtimeSinceStartup - _lastRunTime > 3f)
			{
				ApplyPotatoMode(showLog: false);
				_lastRunTime = Time.realtimeSinceStartup;
			}
		}

		private void ApplyPotatoMode(bool showLog)
		{
			try
			{
				Application.targetFrameRate = 15;
				QualitySettings.vSyncCount = 0;
				RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline;
				if ((Object)(object)currentRenderPipeline != (Object)null)
				{
					Type type = ((object)currentRenderPipeline).GetType();
					SetProperty(type, currentRenderPipeline, "renderScale", 0.4f);
					SetProperty(type, currentRenderPipeline, "shadowDistance", 0f);
					SetProperty(type, currentRenderPipeline, "msaaSampleCount", 1);
				}
				MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>();
				if (array == null)
				{
					return;
				}
				MonoBehaviour[] array2 = array;
				foreach (MonoBehaviour val in array2)
				{
					if ((Object)(object)val != (Object)null && ((Behaviour)val).enabled && ((object)val).GetType().Name.Contains("Volume"))
					{
						((Behaviour)val).enabled = false;
					}
				}
			}
			catch (Exception ex)
			{
				if (showLog)
				{
					PotatoPlugin.Log.LogError((object)("应用土豆模式失败: " + ex.Message));
				}
			}
		}

		private void RestoreQuality()
		{
			try
			{
				Application.targetFrameRate = 60;
				RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline;
				if ((Object)(object)currentRenderPipeline != (Object)null)
				{
					SetProperty(((object)currentRenderPipeline).GetType(), currentRenderPipeline, "renderScale", 1f);
					SetProperty(((object)currentRenderPipeline).GetType(), currentRenderPipeline, "shadowDistance", 50f);
				}
			}
			catch (Exception ex)
			{
				PotatoPlugin.Log.LogError((object)("恢复画质失败: " + ex.Message));
			}
		}

		private void SetProperty(Type type, object obj, string propName, object value)
		{
			try
			{
				PropertyInfo property = type.GetProperty(propName);
				if (property != null && property.CanWrite)
				{
					property.SetValue(obj, value, null);
				}
			}
			catch (Exception ex)
			{
				PotatoPlugin.Log.LogWarning((object)("设置属性失败 [" + propName + "]: " + ex.Message));
			}
		}
	}
	public class AudioManager
	{
		private AudioChannelSwapper _swapper;

		public void EnableChannelSwap()
		{
			try
			{
				AudioListener val = Object.FindObjectOfType<AudioListener>();
				if ((Object)(object)val == (Object)null)
				{
					PotatoPlugin.Log.LogWarning((object)"未找到 AudioListener,跳过音频镜像");
					return;
				}
				_swapper = ((Component)val).gameObject.GetComponent<AudioChannelSwapper>();
				if ((Object)(object)_swapper == (Object)null)
				{
					_swapper = ((Component)val).gameObject.AddComponent<AudioChannelSwapper>();
					PotatoPlugin.Log.LogInfo((object)"已创建音频声道交换组件");
				}
				else if (((Behaviour)_swapper).enabled)
				{
					PotatoPlugin.Log.LogWarning((object)"音频声道交换组件已启用,跳过重复添加");
					return;
				}
				((Behaviour)_swapper).enabled = true;
				PotatoPlugin.Log.LogInfo((object)"已启用音频声道交换 (左右互换)");
			}
			catch (Exception ex)
			{
				PotatoPlugin.Log.LogError((object)("启用音频镜像失败: " + ex.Message));
			}
		}

		public void DisableChannelSwap()
		{
			if ((Object)(object)_swapper != (Object)null)
			{
				Object.Destroy((Object)(object)_swapper);
				_swapper = null;
				PotatoPlugin.Log.LogInfo((object)"已销毁音频声道交换组件");
			}
		}
	}
	public class AudioChannelSwapper : MonoBehaviour
	{
		private void OnAudioFilterRead(float[] data, int channels)
		{
			if (data == null || data.Length == 0 || channels != 2)
			{
				return;
			}
			if (data.Length % 2 != 0)
			{
				PotatoPlugin.Log.LogWarning((object)$"音频数据长度异常: {data.Length} (应为偶数)");
				return;
			}
			for (int i = 0; i < data.Length; i += 2)
			{
				float num = data[i];
				data[i] = data[i + 1];
				data[i + 1] = num;
			}
		}
	}
	public class CameraMirrorManager
	{
		private readonly AudioManager _audioManager;

		private bool _isMirrored;

		private RenderTexture _mirrorRenderTexture;

		private GameObject _mirrorCanvas;

		private RawImage _mirrorRawImage;

		private Material _mirrorFlipMaterial;

		private int _lastScreenWidth;

		private int _lastScreenHeight;

		public bool IsMirrored => _isMirrored;

		public CameraMirrorManager(AudioManager audioManager)
		{
			_audioManager = audioManager;
			_lastScreenWidth = Screen.width;
			_lastScreenHeight = Screen.height;
			PotatoPlugin.Log.LogInfo((object)$"[镜像管理器] 初始化: 屏幕分辨率 {Screen.width}x{Screen.height}");
		}

		public void Toggle()
		{
			SetMirrorState(!_isMirrored);
		}

		public void SetMirrorState(bool enabled)
		{
			_isMirrored = enabled;
			ApplyMirrorMode();
		}

		public void CheckResolutionChange()
		{
			if (_isMirrored && (Screen.width != _lastScreenWidth || Screen.height != _lastScreenHeight))
			{
				PotatoPlugin.Log.LogInfo((object)$"检测到分辨率变化: {_lastScreenWidth}x{_lastScreenHeight} -> {Screen.width}x{Screen.height}");
				_lastScreenWidth = Screen.width;
				_lastScreenHeight = Screen.height;
				RecreateRenderTexture();
			}
		}

		public void Cleanup()
		{
			if (_isMirrored)
			{
				DisableMirrorMode();
			}
		}

		private void ApplyMirrorMode()
		{
			if (_isMirrored)
			{
				EnableMirrorMode();
			}
			else
			{
				DisableMirrorMode();
			}
		}

		private void EnableMirrorMode()
		{
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				PotatoPlugin.Log.LogWarning((object)">>> 未找到主摄像机,跳过镜像 <<<");
				return