Decompiled source of SettingMenuFix v1.0.0

BepInEx/plugins/SettingMenuFix/SettingMenuFix.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.PostProcessing;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SettingMenuFix
{
	internal sealed class CigarDoses
	{
		private readonly FieldInfo doses;

		private readonly FieldInfo channels;

		private readonly FieldInfo type;

		private readonly FieldInfo charge;

		private readonly object black;

		internal readonly MethodInfo ComposeMethod;

		internal CigarDoses(Assembly assembly)
		{
			Type type = assembly.GetType("TobaccoPotAndCigar.Smoking.CigarEffectService", throwOnError: true);
			Type nestedType = type.GetNestedType("DoseGroup", BindingFlags.NonPublic);
			Type nestedType2 = type.GetNestedType("DoseChannel", BindingFlags.NonPublic);
			if (nestedType == null || nestedType2 == null)
			{
				throw new InvalidOperationException("Cigar dose types changed.");
			}
			doses = Required(type, "Doses");
			channels = Required(nestedType, "Channels");
			this.type = Required(nestedType2, "Type");
			charge = Required(nestedType2, "Charge");
			if (charge.FieldType != typeof(float) || !this.type.FieldType.IsEnum || !typeof(IDictionary).IsAssignableFrom(doses.FieldType) || !typeof(IList).IsAssignableFrom(channels.FieldType))
			{
				throw new InvalidOperationException("Cigar dose field types changed.");
			}
			black = Enum.Parse(this.type.FieldType, "Black");
			ComposeMethod = AccessTools.Method(type, "TickAndCompose", new Type[2]
			{
				typeof(PlayerTobacco),
				typeof(float)
			}, (Type[])null);
			if (ComposeMethod == null)
			{
				throw new MissingMethodException(type.FullName, "TickAndCompose");
			}
		}

		private static FieldInfo Required(Type owner, string name)
		{
			return AccessTools.Field(owner, name) ?? throw new MissingFieldException(owner.FullName, name);
		}

		internal float ReadBlack()
		{
			float num = 0f;
			foreach (DictionaryEntry item in (IDictionary)doses.GetValue(null))
			{
				foreach (object item2 in (IList)channels.GetValue(item.Value))
				{
					if (black.Equals(type.GetValue(item2)))
					{
						float num2 = (float)charge.GetValue(item2);
						if (num2 > 0f)
						{
							num += num2;
						}
					}
				}
			}
			return num;
		}
	}
	internal sealed class ContrastState
	{
		private bool owns;

		private float baseline;

		private float output;

		internal static float Strength(float pipe, float cigar)
		{
			return Math.Min(1f, (Positive(pipe) + Positive(cigar)) / 100f);
		}

		internal static float ContrastStrength(float pipe, float cigar)
		{
			return (Positive(pipe) + Positive(cigar)) / 100f;
		}

		private static float Positive(float value)
		{
			if (!float.IsNaN(value))
			{
				return Math.Max(0f, value);
			}
			return 0f;
		}

		internal float Apply(float current, bool bloom, float pipe, float cigar)
		{
			if (!owns || current != output)
			{
				baseline = current;
			}
			output = (bloom ? baseline : (baseline * (1f + ContrastStrength(pipe, cigar))));
			owns = true;
			return output;
		}

		internal float Release(float current)
		{
			float result = ((owns && current == output) ? baseline : current);
			owns = false;
			return result;
		}
	}
	internal struct DisplayMode : IEquatable<DisplayMode>
	{
		internal readonly int Width;

		internal readonly int Height;

		internal readonly int Hertz;

		internal readonly int VanillaIndex;

		internal readonly uint Numerator;

		internal readonly uint Denominator;

		internal double ExactHertz
		{
			get
			{
				if (Denominator != 0)
				{
					return (double)Numerator / (double)Denominator;
				}
				return 0.0;
			}
		}

		internal string SizeText
		{
			get
			{
				int width = Width;
				string text = width.ToString();
				width = Height;
				return text + " x " + width;
			}
		}

		internal string RateText
		{
			get
			{
				if (Hertz > 0)
				{
					string text;
					if (!(Math.Abs(ExactHertz - (double)Hertz) < 0.01))
					{
						text = ExactHertz.ToString("0.###", CultureInfo.InvariantCulture);
					}
					else
					{
						int hertz = Hertz;
						text = hertz.ToString(CultureInfo.InvariantCulture);
					}
					return text + " Hz";
				}
				return "automatic";
			}
		}

		internal DisplayMode(int width, int height, int hertz, int vanillaIndex = -1)
			: this(width, height, (uint)Math.Max(0, hertz), 1u, hertz, vanillaIndex)
		{
		}

		internal DisplayMode(int width, int height, uint numerator, uint denominator, int requestHertz, int vanillaIndex = -1)
		{
			Width = width;
			Height = height;
			Hertz = requestHertz;
			VanillaIndex = vanillaIndex;
			uint num = numerator;
			uint num2 = ((denominator == 0) ? 1u : denominator);
			while (num2 != 0)
			{
				uint num3 = num % num2;
				num = num2;
				num2 = num3;
			}
			uint num4 = Math.Max(1u, num);
			Numerator = numerator / num4;
			Denominator = ((denominator == 0) ? 1 : denominator) / num4;
		}

		internal DisplayMode WithSize(int width, int height)
		{
			return new DisplayMode(width, height, Numerator, Denominator, Hertz);
		}

		public bool Equals(DisplayMode other)
		{
			if (Width == other.Width && Height == other.Height && Numerator == other.Numerator)
			{
				return Denominator == other.Denominator;
			}
			return false;
		}

		public override bool Equals(object obj)
		{
			if (obj is DisplayMode)
			{
				return Equals((DisplayMode)obj);
			}
			return false;
		}

		public override int GetHashCode()
		{
			return (int)((((uint)(((Width * 397) ^ Height) * 397) ^ Numerator) * 397) ^ Denominator);
		}

		internal bool SameSize(DisplayMode other)
		{
			if (Width == other.Width)
			{
				return Height == other.Height;
			}
			return false;
		}

		public override string ToString()
		{
			return SizeText + " (" + RateText + ")";
		}
	}
	internal sealed class DisplayCatalog
	{
		internal readonly List<DisplayMode> Modes = new List<DisplayMode>();

		internal readonly List<DisplayMode> Sizes = new List<DisplayMode>();

		internal DisplayCatalog(IEnumerable<DisplayMode> modes, DisplayMode current)
		{
			HashSet<DisplayMode> hashSet = new HashSet<DisplayMode>();
			foreach (DisplayMode mode in modes)
			{
				if (mode.Width > 0 && mode.Height > 0 && mode.Hertz >= 0 && hashSet.Add(mode))
				{
					Modes.Add(mode);
				}
			}
			if (Modes.Count == 0)
			{
				Modes.Add(new DisplayMode(Math.Max(1, current.Width), Math.Max(1, current.Height), Math.Max(0, current.Hertz)));
			}
			Modes.Sort(delegate(DisplayMode a, DisplayMode b)
			{
				int num = ((long)a.Width * (long)a.Height).CompareTo((long)b.Width * (long)b.Height);
				if (num == 0)
				{
					int width = a.Width;
					num = width.CompareTo(b.Width);
				}
				if (num == 0)
				{
					int width = a.Height;
					num = width.CompareTo(b.Height);
				}
				return (num != 0) ? num : a.ExactHertz.CompareTo(b.ExactHertz);
			});
			foreach (DisplayMode mode2 in Modes)
			{
				if (Sizes.Count == 0 || !Sizes[Sizes.Count - 1].SameSize(mode2))
				{
					Sizes.Add(mode2);
				}
			}
		}

		internal List<DisplayMode> Rates(DisplayMode size)
		{
			return Modes.FindAll((DisplayMode m) => m.SameSize(size));
		}

		internal DisplayMode Resolve(DisplayMode wanted)
		{
			DisplayMode result = Modes[0];
			long num = long.MaxValue;
			double num2 = double.MaxValue;
			foreach (DisplayMode mode in Modes)
			{
				long num3 = Math.Abs((long)mode.Width - (long)wanted.Width) + Math.Abs((long)mode.Height - (long)wanted.Height);
				double num4 = Math.Abs(mode.ExactHertz - wanted.ExactHertz);
				if (num3 < num || (num3 == num && num4 < num2))
				{
					result = mode;
					num = num3;
					num2 = num4;
				}
			}
			return result;
		}
	}
	internal sealed class ListViewport
	{
		internal const int Capacity = 8;

		internal int Count { get; private set; }

		internal int Offset { get; private set; }

		internal int VisibleCount => Math.Min(8, Count - Offset);

		internal int MaxOffset => Math.Max(0, Count - 8);

		internal string Range
		{
			get
			{
				if (Count != 0)
				{
					return Offset + 1 + "-" + (Offset + VisibleCount) + " / " + Count;
				}
				return "0 / 0";
			}
		}

		internal void Open(int count, int selected)
		{
			Count = Math.Max(0, count);
			Offset = Math.Max(0, Math.Min(MaxOffset, selected - 4));
		}

		internal void Scroll(int rows)
		{
			Offset = (int)Math.Max(0L, Math.Min(MaxOffset, (long)Offset + (long)rows));
		}
	}
	internal sealed class DisplaySettings
	{
		internal const string WidthKey = "DogEggz.SettingMenuFix.Width";

		internal const string HeightKey = "DogEggz.SettingMenuFix.Height";

		internal const string RateKey = "DogEggz.SettingMenuFix.RefreshRate";

		internal const string NumeratorKey = "DogEggz.SettingMenuFix.RefreshNumerator";

		internal const string DenominatorKey = "DogEggz.SettingMenuFix.RefreshDenominator";

		private bool loaded;

		private int syncedIndex;

		private int applyFrame;

		private float confirmAt;

		private string device;

		private bool reportedNativeFailure;

		internal DisplayCatalog Catalog { get; private set; }

		internal DisplayMode Selected { get; private set; }

		internal bool Applying { get; private set; }

		internal string WindowLabel
		{
			get
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Invalid comparison between Unknown and I4
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				if (!Applying)
				{
					if ((int)Settings.fullscreenMode != 3)
					{
						if ((int)Settings.fullscreenMode != 0)
						{
							return "borderless window";
						}
						return "fullscreen";
					}
					return "windowed";
				}
				return "applying...";
			}
		}

		internal void RefreshCatalog()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Invalid comparison between Unknown and I4
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Invalid comparison between Unknown and I4
			Resolution currentResolution = Screen.currentResolution;
			DisplayMode displayMode = new DisplayMode(Screen.width, Screen.height, ((Resolution)(ref currentResolution)).refreshRate);
			Resolution[] resolutions = Screen.resolutions;
			List<DisplayMode> list = new List<DisplayMode>(resolutions.Length);
			for (int i = 0; i < resolutions.Length; i++)
			{
				list.Add(new DisplayMode(((Resolution)(ref resolutions[i])).width, ((Resolution)(ref resolutions[i])).height, ((Resolution)(ref resolutions[i])).refreshRate, i));
			}
			List<DisplayMode> modes = list;
			if ((int)Application.platform == 2 || (int)Application.platform == 7)
			{
				try
				{
					device = WindowsDisplayModes.DisplayName();
					List<DisplayMode> list2 = WindowsDisplayModes.Read(device, list);
					if (list2.Count > 0)
					{
						modes = list2;
					}
					if (WindowsDisplayModes.TryCurrent(device, out var current))
					{
						displayMode = new DisplayMode(Screen.width, Screen.height, current.Hertz);
					}
				}
				catch (Exception ex)
				{
					if (!reportedNativeFailure)
					{
						ManualLogSource log = Plugin.Log;
						if (log != null)
						{
							log.LogWarning((object)("Windows refresh-rate enumeration unavailable; using Unity modes: " + ex.Message));
						}
						reportedNativeFailure = true;
					}
				}
			}
			Catalog = new DisplayCatalog(modes, displayMode);
			if (!loaded)
			{
				Selected = displayMode;
				if (PlayerPrefs.HasKey("DogEggz.SettingMenuFix.Width") && PlayerPrefs.HasKey("DogEggz.SettingMenuFix.Height") && PlayerPrefs.HasKey("DogEggz.SettingMenuFix.RefreshRate"))
				{
					int num = PlayerPrefs.GetInt("DogEggz.SettingMenuFix.RefreshNumerator", 0);
					int num2 = PlayerPrefs.GetInt("DogEggz.SettingMenuFix.RefreshDenominator", 0);
					Selected = ((num > 0 && num2 > 0) ? new DisplayMode(PlayerPrefs.GetInt("DogEggz.SettingMenuFix.Width"), PlayerPrefs.GetInt("DogEggz.SettingMenuFix.Height"), (uint)num, (uint)num2, PlayerPrefs.GetInt("DogEggz.SettingMenuFix.RefreshRate")) : new DisplayMode(PlayerPrefs.GetInt("DogEggz.SettingMenuFix.Width"), PlayerPrefs.GetInt("DogEggz.SettingMenuFix.Height"), PlayerPrefs.GetInt("DogEggz.SettingMenuFix.RefreshRate")));
				}
				else if (Settings.resolution >= 0 && Settings.resolution < list.Count)
				{
					Selected = list[Settings.resolution];
				}
				loaded = true;
			}
			Selected = Catalog.Resolve(Selected);
			SynchronizeIndex();
		}

		internal void ApplyVanillaRequest()
		{
			if (loaded && Settings.resolution != syncedIndex)
			{
				Resolution[] resolutions = Screen.resolutions;
				int resolution = Settings.resolution;
				if (resolution >= 0 && resolution < resolutions.Length)
				{
					Selected = new DisplayMode(((Resolution)(ref resolutions[resolution])).width, ((Resolution)(ref resolutions[resolution])).height, ((Resolution)(ref resolutions[resolution])).refreshRate, resolution);
				}
			}
			RefreshCatalog();
			Apply();
		}

		internal void Select(DisplayMode choice)
		{
			RefreshCatalog();
			Selected = Catalog.Resolve(choice);
			Apply();
		}

		private void Apply()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected I4, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Settings.fullscreenMode != 3 && (int)Settings.fullscreenMode != 0 && (int)Settings.fullscreenMode != 1)
			{
				Settings.fullscreenMode = (FullScreenMode)1;
			}
			SynchronizeIndex();
			PlayerPrefs.SetInt("DogEggz.SettingMenuFix.Width", Selected.Width);
			PlayerPrefs.SetInt("DogEggz.SettingMenuFix.Height", Selected.Height);
			PlayerPrefs.SetInt("DogEggz.SettingMenuFix.RefreshRate", Selected.Hertz);
			PlayerPrefs.SetInt("DogEggz.SettingMenuFix.RefreshNumerator", (int)Selected.Numerator);
			PlayerPrefs.SetInt("DogEggz.SettingMenuFix.RefreshDenominator", (int)Selected.Denominator);
			PlayerPrefs.SetInt("fullscreenMode", (int)Settings.fullscreenMode);
			PlayerPrefs.Save();
			Screen.SetResolution(Selected.Width, Selected.Height, Settings.fullscreenMode, Selected.Hertz);
			Applying = true;
			applyFrame = Time.frameCount;
			confirmAt = Time.unscaledTime + 0.5f;
			NativeSettingsMenu.RefreshAll();
		}

		private void SynchronizeIndex()
		{
			Settings.resolution = Math.Max(0, Selected.VanillaIndex);
			syncedIndex = Settings.resolution;
			if (Selected.VanillaIndex >= 0)
			{
				PlayerPrefs.SetInt("resolution", syncedIndex);
			}
		}

		internal unsafe void Tick()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0172: Expected I4, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			if (!Applying || Time.frameCount <= applyFrame + 1 || Time.unscaledTime < confirmAt)
			{
				return;
			}
			Applying = false;
			FullScreenMode fullScreenMode = Screen.fullScreenMode;
			if (fullScreenMode != Settings.fullscreenMode)
			{
				Plugin.Log.LogWarning((object)("Requested window mode " + ((object)Unsafe.As<FullScreenMode, FullScreenMode>(ref Settings.fullscreenMode)/*cast due to .constrained prefix*/).ToString() + "; Unity reports " + ((object)(*(FullScreenMode*)(&fullScreenMode))/*cast due to .constrained prefix*/).ToString() + "."));
			}
			Settings.fullscreenMode = fullScreenMode;
			if ((int)fullScreenMode == 0 && device != null)
			{
				try
				{
					if (WindowsDisplayModes.TryCurrent(device, out var current) && current.Hertz != Selected.Hertz)
					{
						ManualLogSource log = Plugin.Log;
						if (log != null)
						{
							string[] obj = new string[7]
							{
								"Requested ",
								Selected.ToString(),
								" using ",
								null,
								null,
								null,
								null
							};
							int hertz = Selected.Hertz;
							obj[3] = hertz.ToString();
							obj[4] = " Hz; Windows reports ";
							DisplayMode displayMode = current;
							obj[5] = displayMode.ToString();
							obj[6] = ".";
							log.LogWarning((object)string.Concat(obj));
						}
					}
				}
				catch (Exception ex)
				{
					ManualLogSource log2 = Plugin.Log;
					if (log2 != null)
					{
						log2.LogWarning((object)("Could not verify refresh rate: " + ex.Message));
					}
				}
			}
			PlayerPrefs.SetInt("fullscreenMode", (int)fullScreenMode);
			PlayerPrefs.Save();
			NativeSettingsMenu.RefreshAll();
		}

		internal void CycleWindowMode()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Settings.fullscreenMode = (FullScreenMode)(((int)Settings.fullscreenMode != 3) ? (((int)Settings.fullscreenMode == 0) ? 1 : 3) : 0);
			RefreshCatalog();
			Apply();
		}
	}
	internal static class MenuPreferences
	{
		internal static bool ConsumeLegacy(ConfigFile config)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			bool saveOnConfigSet = config.SaveOnConfigSet;
			config.SaveOnConfigSet = false;
			try
			{
				bool value = config.Bind<bool>("Graphics", "Bloom", true, (ConfigDescription)null).Value;
				config.Bind<int>("Temporary tuning", "Maximum black tobacco contrast (%)", 5, (ConfigDescription)null);
				config.Remove(new ConfigDefinition("Graphics", "Bloom"));
				config.Remove(new ConfigDefinition("Temporary tuning", "Maximum black tobacco contrast (%)"));
				config.Save();
				return value;
			}
			finally
			{
				config.SaveOnConfigSet = saveOnConfigSet;
			}
		}
	}
	internal sealed class NativeSettingsMenu : MonoBehaviour
	{
		private static readonly List<NativeSettingsMenu> Menus = new List<NativeSettingsMenu>();

		private readonly List<GameObject> created = new List<GameObject>();

		private readonly Dictionary<GameObject, bool> stockListChildren = new Dictionary<GameObject, bool>();

		private readonly Dictionary<GameObject, bool> hiddenWhileOpen = new Dictionary<GameObject, bool>();

		private readonly Dictionary<Transform, Vector3> moved = new Dictionary<Transform, Vector3>();

		private readonly ListViewport viewport = new ListViewport();

		private readonly NativeMenuButton[] rows = new NativeMenuButton[8];

		private ResolutionsUI list;

		private TextMesh labels;

		private TextMesh resolutionText;

		private TextMesh rateText;

		private TextMesh bloomText;

		private TextMesh rangeText;

		private GPButtonWindowMode window;

		private string originalLabels;

		private NativeMenuButton previous;

		private NativeMenuButton next;

		private List<DisplayMode> choices;

		private bool rates;

		private bool ready;

		private bool open;

		private bool cleaning;

		private GameObject[] originalButtons;

		private Renderer originalBackdrop;

		private bool originalBackdropEnabled;

		private Transform backdrop;

		private Bounds backdropMeshBounds;

		private NativeMenuButton close;

		internal static bool TryAttach(ResolutionsUI list)
		{
			if ((Object)(object)Plugin.Instance == (Object)null || (Object)(object)list == (Object)null)
			{
				return false;
			}
			NativeSettingsMenu componentInParent = ((Component)list).GetComponentInParent<NativeSettingsMenu>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				return componentInParent.ready;
			}
			Transform parent = ((Component)list).transform.parent;
			TextMesh val = ((IEnumerable<TextMesh>)((Component)parent).GetComponentsInChildren<TextMesh>(true)).FirstOrDefault((Func<TextMesh, bool>)((TextMesh t) => t.text.Contains("DISPLAY\n") && t.text.Contains("GRAPHICS\n\n")));
			GPButtonSettingsCheckbo val2 = ((IEnumerable<GPButtonSettingsCheckbo>)((Component)parent).GetComponentsInChildren<GPButtonSettingsCheckbo>(true)).FirstOrDefault((Func<GPButtonSettingsCheckbo, bool>)((GPButtonSettingsCheckbo b) => b.setting == "ambientOcclusion"));
			GPButtonResolutionUI val3 = ((IEnumerable<GPButtonResolutionUI>)((Component)parent).GetComponentsInChildren<GPButtonResolutionUI>(true)).FirstOrDefault((Func<GPButtonResolutionUI, bool>)((GPButtonResolutionUI b) => b.openList && (Object)(object)b.list == (Object)(object)((Component)list).gameObject));
			GPButtonWindowMode componentInChildren = ((Component)parent).GetComponentInChildren<GPButtonWindowMode>(true);
			GPButtonTargetFramerate componentInChildren2 = ((Component)parent).GetComponentInChildren<GPButtonTargetFramerate>(true);
			GPButtonSettingsCheckbo val4 = ((IEnumerable<GPButtonSettingsCheckbo>)((Component)parent).GetComponentsInChildren<GPButtonSettingsCheckbo>(true)).FirstOrDefault((Func<GPButtonSettingsCheckbo, bool>)((GPButtonSettingsCheckbo b) => b.setting == "vsync"));
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren2 == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)list.buttonPrefab == (Object)null || !val.text.Contains("screen resolution\nwindow mode\ntarget framerate\nenable v-sync\n\n\n"))
			{
				Plugin.Log.LogWarning((object)"Native graphics sheet does not match Sailwind 0.38.1; retaining its original controls.");
				return false;
			}
			NativeSettingsMenu nativeSettingsMenu = ((Component)parent).gameObject.AddComponent<NativeSettingsMenu>();
			try
			{
				nativeSettingsMenu.Initialize(list, val, val2, val3, componentInChildren, componentInChildren2, val4);
				Menus.Add(nativeSettingsMenu);
				Plugin.Log.LogInfo((object)"Attached native settings sheet: Bloom, resolution and refresh-rate selectors (8 rows).");
				return true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Native settings UI initialization failed: " + ex));
				nativeSettingsMenu.Restore();
				Object.Destroy((Object)(object)nativeSettingsMenu);
				return false;
			}
		}

		private void Initialize(ResolutionsUI source, TextMesh text, GPButtonSettingsCheckbo checkbox, GPButtonResolutionUI opener, GPButtonWindowMode windowButton, GPButtonTargetFramerate target, GPButtonSettingsCheckbo vsync)
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: 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_019c: Expected O, but got Unknown
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_051b: Unknown result type (might be due to invalid IL or missing references)
			//IL_052c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0536: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Expected O, but got Unknown
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			list = source;
			labels = text;
			window = windowButton;
			originalLabels = text.text;
			originalButtons = list.buttons;
			resolutionText = ((Component)opener).GetComponentInChildren<TextMesh>(true);
			labels.text = labels.text.Replace("screen resolution\nwindow mode\ntarget framerate\nenable v-sync\n\n\n", "screen resolution\nrefresh rate\nwindow mode\ntarget framerate\nenable v-sync\n\n").Replace("GRAPHICS\n\n", "GRAPHICS\nBloom\n");
			MoveDown(((Component)window).transform);
			MoveDown(((Component)target).transform);
			MoveDown(((Component)vsync).transform);
			NativeMenuButton nativeMenuButton = CopyButton(((Component)opener).gameObject, ((Component)opener).transform.parent, "refresh rate", delegate
			{
				Open(refreshRates: true);
			});
			((Component)nativeMenuButton).transform.localPosition = ((Component)opener).transform.localPosition + Vector3.down * 0.02f;
			rateText = nativeMenuButton.Text;
			NativeMenuButton nativeMenuButton2 = CopyButton(((Component)checkbox).gameObject, ((Component)this).transform, "Bloom", delegate
			{
				Plugin.Instance.SetBloom(!Plugin.Instance.Bloom);
				Plugin.Instance.RefreshEffectsNow();
			});
			Vector3 localPosition = ((Component)checkbox).transform.localPosition;
			localPosition.y = 0f;
			((Component)nativeMenuButton2).transform.localPosition = localPosition;
			bloomText = nativeMenuButton2.Text;
			((Component)list).gameObject.SetActive(false);
			foreach (Transform item in ((Component)list).transform)
			{
				Transform val = item;
				stockListChildren[((Component)val).gameObject] = ((Component)val).gameObject.activeSelf;
				((Component)val).gameObject.SetActive(false);
			}
			originalBackdrop = ((Component)list).GetComponent<Renderer>();
			if ((Object)(object)originalBackdrop != (Object)null)
			{
				originalBackdropEnabled = originalBackdrop.enabled;
			}
			MeshFilter component = ((Component)list).GetComponent<MeshFilter>();
			if ((Object)(object)originalBackdrop != (Object)null && (Object)(object)component != (Object)null && (Object)(object)component.sharedMesh != (Object)null)
			{
				GameObject val2 = new GameObject("DogEggz.SettingMenuFix.selector parchment");
				created.Add(val2);
				val2.layer = ((Component)list).gameObject.layer;
				backdrop = val2.transform;
				backdrop.SetParent(((Component)list).transform, false);
				val2.AddComponent<MeshFilter>().sharedMesh = component.sharedMesh;
				((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterials = originalBackdrop.sharedMaterials;
				backdropMeshBounds = component.sharedMesh.bounds;
				originalBackdrop.enabled = false;
			}
			for (int num = 0; num < rows.Length; num++)
			{
				int slot = num;
				rows[num] = CopyButton(list.buttonPrefab, ((Component)list).transform, "display choice " + num, delegate
				{
					Choose(slot);
				});
				((Component)rows[num]).transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
				((Component)rows[num]).transform.localPosition = list.firstButtonLocalPos + Vector3.down * (0.05f * (float)num);
			}
			close = CopyButton(list.buttonPrefab, ((Component)list).transform, "close choices", Close);
			PlaceSmall(close, 0.08f, 0.235f, "close");
			previous = CopyButton(list.buttonPrefab, ((Component)list).transform, "previous choices", delegate
			{
				Scroll(-8);
			});
			PlaceSmall(previous, 0.08f, -0.245f, "prev");
			next = CopyButton(list.buttonPrefab, ((Component)list).transform, "next choices", delegate
			{
				Scroll(8);
			});
			PlaceSmall(next, -0.14f, -0.245f, "next");
			GameObject val3 = Object.Instantiate<GameObject>(((Component)rows[0].Text).gameObject, ((Component)list).transform, false);
			created.Add(val3);
			((Object)val3).name = "visible range";
			val3.transform.localPosition = new Vector3(-0.03f, -0.315f, 0.018f);
			val3.transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
			val3.transform.localScale = Vector3.one * 0.0038f;
			rangeText = val3.GetComponent<TextMesh>();
			rangeText.anchor = (TextAnchor)4;
			rangeText.alignment = (TextAlignment)1;
			((Component)list).gameObject.AddComponent<NativeViewportLifecycle>().Menu = this;
			list.buttons = (GameObject[])(object)new GameObject[0];
			ready = true;
			Plugin.Instance.Display.RefreshCatalog();
			RefreshLabels();
			Physics.SyncTransforms();
		}

		private void MoveDown(Transform item)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			moved[item] = item.localPosition;
			item.localPosition += Vector3.down * 0.02f;
		}

		private NativeMenuButton CopyButton(GameObject template, Transform parent, string name, Action click)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("DogEggz.SettingMenuFix." + name);
			created.Add(val);
			val.SetActive(false);
			val.layer = template.layer;
			val.transform.SetParent(parent, false);
			val.transform.localPosition = template.transform.localPosition;
			val.transform.localRotation = template.transform.localRotation;
			val.transform.localScale = template.transform.localScale;
			val.AddComponent<MeshFilter>().sharedMesh = template.GetComponent<MeshFilter>().sharedMesh;
			((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterials = template.GetComponent<Renderer>().sharedMaterials;
			BoxCollider obj = val.AddComponent<BoxCollider>();
			BoxCollider component = template.GetComponent<BoxCollider>();
			obj.center = component.center;
			obj.size = component.size;
			((Collider)obj).isTrigger = ((Collider)component).isTrigger;
			TextMesh component2 = Object.Instantiate<GameObject>(((Component)template.GetComponentInChildren<TextMesh>(true)).gameObject, val.transform, false).GetComponent<TextMesh>();
			NativeMenuButton nativeMenuButton = val.AddComponent<NativeMenuButton>();
			nativeMenuButton.Text = component2;
			nativeMenuButton.Activate = click;
			val.SetActive(true);
			return nativeMenuButton;
		}

		private static void PlaceSmall(NativeMenuButton button, float x, float y, string text)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			((Component)button).transform.localPosition = new Vector3(x, y, 0.017f);
			((Component)button).transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
			Vector3 localScale = ((Component)button).transform.localScale;
			localScale.x *= 0.48f;
			((Component)button).transform.localScale = localScale;
			Vector3 localScale2 = ((Component)button.Text).transform.localScale;
			localScale2.x /= 0.48f;
			((Component)button.Text).transform.localScale = localScale2;
			button.Text.text = text;
		}

		internal void Open(bool refreshRates)
		{
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			if (!ready || (Object)(object)Plugin.Instance == (Object)null)
			{
				return;
			}
			rates = refreshRates;
			Plugin.Instance.Display.RefreshCatalog();
			DisplaySettings display = Plugin.Instance.Display;
			choices = (rates ? display.Catalog.Rates(display.Selected) : display.Catalog.Sizes);
			int selected = choices.FindIndex((DisplayMode m) => (!rates) ? m.SameSize(display.Selected) : m.Equals(display.Selected));
			viewport.Open(choices.Count, selected);
			if (!open)
			{
				foreach (Transform item in ((Component)this).transform)
				{
					Transform val = item;
					if ((Object)(object)val != (Object)(object)((Component)list).transform && ((Object)val).name != "bg")
					{
						hiddenWhileOpen[((Component)val).gameObject] = ((Component)val).gameObject.activeSelf;
						((Component)val).gameObject.SetActive(false);
					}
				}
			}
			open = true;
			((Component)list).gameObject.SetActive(true);
			RenderRows();
		}

		internal void Close()
		{
			if (!open)
			{
				return;
			}
			open = false;
			foreach (KeyValuePair<GameObject, bool> item in hiddenWhileOpen)
			{
				if ((Object)(object)item.Key != (Object)null)
				{
					item.Key.SetActive(item.Value);
				}
			}
			hiddenWhileOpen.Clear();
			if ((Object)(object)list != (Object)null)
			{
				((Component)list).gameObject.SetActive(false);
			}
			RefreshLabels();
			Physics.SyncTransforms();
		}

		internal void ListEnabled()
		{
			if (ready && !open)
			{
				Open(rates);
			}
		}

		internal void ListDisabled()
		{
			if (ready && open)
			{
				Close();
			}
		}

		private void Choose(int slot)
		{
			int num = viewport.Offset + slot;
			if (open && slot >= 0 && slot < viewport.VisibleCount && num < choices.Count)
			{
				DisplayMode choice = choices[num];
				if (!rates)
				{
					choice = Plugin.Instance.Display.Selected.WithSize(choice.Width, choice.Height);
				}
				Plugin.Instance.Display.Select(choice);
				Close();
			}
		}

		internal void Scroll(int amount)
		{
			if (open)
			{
				int offset = viewport.Offset;
				viewport.Scroll(amount);
				if (offset != viewport.Offset)
				{
					RenderRows();
				}
			}
		}

		internal void ReadInput()
		{
			if (open)
			{
				float axis = Input.GetAxis("Mouse ScrollWheel");
				if (axis != 0f)
				{
					Scroll((!(axis > 0f)) ? 1 : (-1));
				}
				if (Input.GetKeyDown((KeyCode)280))
				{
					Scroll(-8);
				}
				if (Input.GetKeyDown((KeyCode)281))
				{
					Scroll(8);
				}
				if (Input.GetKeyDown((KeyCode)278))
				{
					Scroll(-viewport.Count);
				}
				if (Input.GetKeyDown((KeyCode)279))
				{
					Scroll(viewport.Count);
				}
			}
		}

		private void RenderRows()
		{
			DisplayMode selected = Plugin.Instance.Display.Selected;
			for (int i = 0; i < rows.Length; i++)
			{
				bool flag = i < viewport.VisibleCount;
				((Component)rows[i]).gameObject.SetActive(flag);
				if (flag)
				{
					DisplayMode displayMode = choices[viewport.Offset + i];
					bool flag2 = (rates ? displayMode.Equals(selected) : displayMode.SameSize(selected));
					rows[i].Text.text = (flag2 ? "> " : "") + (rates ? displayMode.RateText : displayMode.SizeText);
					rows[i].SetSelected(flag2);
				}
			}
			previous.SetAvailable(viewport.Offset > 0);
			next.SetAvailable(viewport.Offset < viewport.MaxOffset);
			rangeText.text = (rates ? "refresh rate" : "resolution") + "  " + viewport.Range;
			FitBackdrop();
			Physics.SyncTransforms();
		}

		private void FitBackdrop()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: 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_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			float num = list.firstButtonLocalPos.y - 0.05f * (float)Math.Max(0, viewport.VisibleCount - 1);
			Vector3 localPosition = ((Component)previous).transform.localPosition;
			localPosition.y = num - 0.065f;
			((Component)previous).transform.localPosition = localPosition;
			localPosition.x = ((Component)next).transform.localPosition.x;
			((Component)next).transform.localPosition = localPosition;
			localPosition = ((Component)rangeText).transform.localPosition;
			localPosition.y = num - 0.135f;
			((Component)rangeText).transform.localPosition = localPosition;
			if ((Object)(object)backdrop == (Object)null)
			{
				return;
			}
			Bounds val = default(Bounds);
			((Bounds)(ref val))..ctor(((Component)close).transform.localPosition, Vector3.zero);
			Renderer[] componentsInChildren = ((Component)list).GetComponentsInChildren<Renderer>();
			foreach (Renderer val2 in componentsInChildren)
			{
				if ((Object)(object)val2 == (Object)(object)originalBackdrop || (Object)(object)((Component)val2).transform == (Object)(object)backdrop || !val2.enabled)
				{
					continue;
				}
				MeshFilter component = ((Component)val2).GetComponent<MeshFilter>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.sharedMesh != (Object)null)
				{
					Bounds bounds = component.sharedMesh.bounds;
					for (int j = 0; j < 8; j++)
					{
						Vector3 val3 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))));
						((Bounds)(ref val)).Encapsulate(((Component)list).transform.InverseTransformPoint(((Component)val2).transform.TransformPoint(val3)));
					}
				}
				else
				{
					Bounds bounds2 = val2.bounds;
					for (int k = 0; k < 8; k++)
					{
						Vector3 val4 = ((Bounds)(ref bounds2)).center + Vector3.Scale(((Bounds)(ref bounds2)).extents, new Vector3((float)(((k & 1) != 0) ? 1 : (-1)), (float)(((k & 2) != 0) ? 1 : (-1)), (float)(((k & 4) != 0) ? 1 : (-1))));
						((Bounds)(ref val)).Encapsulate(((Component)list).transform.InverseTransformPoint(val4));
					}
				}
			}
			Vector3 val5 = default(Vector3);
			((Vector3)(ref val5))..ctor(Mathf.Max(((Bounds)(ref backdropMeshBounds)).size.x, ((Bounds)(ref val)).size.x / 0.78f), ((Bounds)(ref val)).size.y / 0.8f, ((Bounds)(ref backdropMeshBounds)).size.z);
			Vector3 val6 = default(Vector3);
			((Vector3)(ref val6))..ctor(val5.x / ((Bounds)(ref backdropMeshBounds)).size.x, val5.y / ((Bounds)(ref backdropMeshBounds)).size.y, 1f);
			backdrop.localScale = val6;
			backdrop.localPosition = new Vector3(((Bounds)(ref val)).center.x - ((Bounds)(ref backdropMeshBounds)).center.x * val6.x, ((Bounds)(ref val)).center.y - ((Bounds)(ref backdropMeshBounds)).center.y * val6.y, 0f);
		}

		internal void RefreshLabels()
		{
			if (ready && !((Object)(object)Plugin.Instance == (Object)null))
			{
				DisplaySettings display = Plugin.Instance.Display;
				resolutionText.text = display.Selected.SizeText;
				rateText.text = display.Selected.RateText;
				bloomText.text = (Plugin.Instance.Bloom ? "X" : "");
				window.text.text = display.WindowLabel;
			}
		}

		internal static void RefreshAll()
		{
			foreach (NativeSettingsMenu menu in Menus)
			{
				if ((Object)(object)menu != (Object)null)
				{
					menu.RefreshLabels();
				}
			}
		}

		internal static void RemoveAll()
		{
			NativeSettingsMenu[] array = Menus.ToArray();
			foreach (NativeSettingsMenu nativeSettingsMenu in array)
			{
				if ((Object)(object)nativeSettingsMenu != (Object)null)
				{
					nativeSettingsMenu.Restore();
					Object.Destroy((Object)(object)nativeSettingsMenu);
				}
			}
			Menus.Clear();
		}

		private void Restore()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			if (cleaning)
			{
				return;
			}
			cleaning = true;
			Close();
			ready = false;
			if ((Object)(object)originalBackdrop != (Object)null)
			{
				originalBackdrop.enabled = originalBackdropEnabled;
			}
			if ((Object)(object)labels != (Object)null && originalLabels != null)
			{
				labels.text = originalLabels;
			}
			foreach (KeyValuePair<Transform, Vector3> item in moved)
			{
				if ((Object)(object)item.Key != (Object)null)
				{
					item.Key.localPosition = item.Value;
				}
			}
			foreach (KeyValuePair<GameObject, bool> stockListChild in stockListChildren)
			{
				if ((Object)(object)stockListChild.Key != (Object)null)
				{
					stockListChild.Key.SetActive(stockListChild.Value);
				}
			}
			foreach (GameObject item2 in created)
			{
				if ((Object)(object)item2 != (Object)null)
				{
					item2.SetActive(false);
					Object.Destroy((Object)(object)item2);
				}
			}
			if ((Object)(object)list != (Object)null)
			{
				NativeViewportLifecycle component = ((Component)list).GetComponent<NativeViewportLifecycle>();
				if ((Object)(object)component != (Object)null)
				{
					component.Menu = null;
					Object.Destroy((Object)(object)component);
				}
				list.buttons = originalButtons;
				if (list.buttons == null || list.buttons.Length == 0)
				{
					list.CreateButtons();
				}
			}
			Physics.SyncTransforms();
		}

		private void OnDestroy()
		{
			Menus.Remove(this);
		}
	}
	internal sealed class NativeMenuButton : GoPointerButton
	{
		internal TextMesh Text;

		internal Action Activate;

		public override void OnActivate()
		{
			if (((Behaviour)this).isActiveAndEnabled && !base.unclickable)
			{
				Activate?.Invoke();
			}
		}

		internal void SetSelected(bool selected)
		{
			base.overrideEnableOutline = selected;
		}

		internal void SetAvailable(bool available)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			base.unclickable = !available;
			((Collider)((Component)this).GetComponent<BoxCollider>()).enabled = available;
			Text.color = (available ? new Color(0.06f, 0.06f, 0.04f, 1f) : new Color(0.4f, 0.4f, 0.35f, 1f));
		}
	}
	internal sealed class NativeViewportLifecycle : MonoBehaviour
	{
		internal NativeSettingsMenu Menu;

		private void OnEnable()
		{
			Menu?.ListEnabled();
		}

		private void OnDisable()
		{
			Menu?.ListDisabled();
		}
	}
	[HarmonyPatch(typeof(ResolutionsUI), "CreateButtons")]
	internal static class CreateRowsPatch
	{
		private static bool Prefix(ResolutionsUI __instance)
		{
			return !NativeSettingsMenu.TryAttach(__instance);
		}
	}
	[HarmonyPatch(typeof(ResolutionsUI), "Update")]
	internal static class ScrollInputPatch
	{
		private static bool Prefix(ResolutionsUI __instance)
		{
			NativeSettingsMenu componentInParent = ((Component)__instance).GetComponentInParent<NativeSettingsMenu>();
			if ((Object)(object)componentInParent == (Object)null)
			{
				return true;
			}
			componentInParent.ReadInput();
			return false;
		}
	}
	[HarmonyPatch(typeof(ResolutionsUI), "Scroll")]
	internal static class ScrollRowsPatch
	{
		private static bool Prefix(ResolutionsUI __instance, float amount)
		{
			NativeSettingsMenu componentInParent = ((Component)__instance).GetComponentInParent<NativeSettingsMenu>();
			if ((Object)(object)componentInParent == (Object)null)
			{
				return true;
			}
			if (amount != 0f)
			{
				componentInParent.Scroll((amount > 0f) ? 1 : (-1));
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(GPButtonResolutionUI), "OnActivate")]
	internal static class OpenListPatch
	{
		private static bool Prefix(GPButtonResolutionUI __instance)
		{
			if ((Object)(object)__instance.list == (Object)null)
			{
				return true;
			}
			NativeSettingsMenu componentInParent = __instance.list.GetComponentInParent<NativeSettingsMenu>();
			if ((Object)(object)componentInParent == (Object)null)
			{
				return true;
			}
			if (__instance.openList)
			{
				componentInParent.Open(refreshRates: false);
			}
			else
			{
				componentInParent.Close();
			}
			return false;
		}
	}
	internal sealed class PipeVisualCharge
	{
		private bool active;

		internal float Charge { get; private set; }

		internal void Reset()
		{
			active = false;
			Charge = 0f;
		}

		internal void Sync(bool bloom, float vanilla)
		{
			if (bloom)
			{
				Reset();
			}
			else if (!active)
			{
				Charge = Math.Max(0f, vanilla);
				active = true;
			}
		}

		internal void Tick(float seconds)
		{
			if (active)
			{
				Charge = Math.Max(0f, Charge - Math.Max(0f, seconds) * 0.5f);
			}
		}

		internal void Inhale(float seconds)
		{
			if (active)
			{
				Charge += Math.Max(0f, seconds) * 2f;
			}
		}
	}
	[BepInPlugin("DogEggz.SettingMenuFix", "Setting Menu Fix", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInIncompatibility("DogEggz.BlackTobaccoContrast")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "DogEggz.SettingMenuFix";

		public const string Name = "Setting Menu Fix";

		public const string Version = "1.0.0";

		internal const string CigarGuid = "DogEggz.Cigar";

		internal const string NoBloomGuid = "com.app24.nobloom";

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		internal readonly PipeVisualCharge PipeVisual = new PipeVisualCharge();

		private PlayerTobacco visualOwner;

		internal readonly DisplaySettings Display = new DisplaySettings();

		private readonly ContrastState contrast = new ContrastState();

		private readonly List<HarmonyMethod> suspendedNoBloom = new List<HarmonyMethod>();

		private Harmony harmony;

		private CigarDoses cigars;

		private PostProcessingProfile profile;

		private const string BloomKey = "DogEggz.SettingMenuFix.Bloom";

		private bool quitting;

		internal bool Bloom { get; private set; }

		private void Awake()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			bool flag = MenuPreferences.ConsumeLegacy(((BaseUnityPlugin)this).Config);
			Bloom = PlayerPrefs.GetInt("DogEggz.SettingMenuFix.Bloom", flag ? 1 : 0) != 0;
			PlayerPrefs.SetInt("DogEggz.SettingMenuFix.Bloom", Bloom ? 1 : 0);
			PlayerPrefs.Save();
			harmony = new Harmony("DogEggz.SettingMenuFix");
			try
			{
				if (Chainloader.PluginInfos.TryGetValue("DogEggz.Cigar", out var value))
				{
					cigars = new CigarDoses(((object)value.Instance).GetType().Assembly);
				}
				harmony.PatchAll(typeof(Plugin).Assembly);
				if (cigars != null)
				{
					harmony.Patch((MethodBase)cigars.ComposeMethod, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "AfterCigarComposition", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				SuspendNoBloom();
				SceneManager.sceneLoaded += SceneLoaded;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Setting Menu Fix 1.0.0 loaded. GUID: DogEggz.SettingMenuFix");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Setting Menu Fix initialization failed: " + ex));
				Cleanup();
				((Behaviour)this).enabled = false;
			}
		}

		private void Start()
		{
			AttachMenus();
		}

		private void SceneLoaded(Scene scene, LoadSceneMode mode)
		{
			AttachMenus();
		}

		private static void AttachMenus()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			ResolutionsUI[] array = Resources.FindObjectsOfTypeAll<ResolutionsUI>();
			foreach (ResolutionsUI val in array)
			{
				Scene scene = ((Component)val).gameObject.scene;
				if (((Scene)(ref scene)).IsValid())
				{
					NativeSettingsMenu.TryAttach(val);
				}
			}
		}

		internal void SetBloom(bool enabled)
		{
			Bloom = enabled;
			PlayerPrefs.SetInt("DogEggz.SettingMenuFix.Bloom", enabled ? 1 : 0);
			PlayerPrefs.Save();
			RefreshEffectsNow();
		}

		internal void ResetVisual()
		{
			PipeVisual.Reset();
			visualOwner = null;
		}

		internal void PrepareVisual(PlayerTobacco tobacco)
		{
			if ((Object)(object)tobacco == (Object)null)
			{
				ResetVisual();
				return;
			}
			if ((Object)(object)visualOwner != (Object)(object)tobacco)
			{
				PipeVisual.Reset();
				visualOwner = tobacco;
			}
			PipeVisual.Sync(Bloom, tobacco.black);
		}

		internal void RefreshEffectsNow()
		{
			ApplyEffects(PlayerTobacco.instance, includeCigars: true);
			NativeSettingsMenu.RefreshAll();
		}

		private void Update()
		{
			Display.Tick();
		}

		internal void ApplyEffects(PlayerTobacco tobacco, bool includeCigars)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			PrepareVisual(tobacco);
			if ((Object)(object)tobacco == (Object)null || (Object)(object)tobacco.postProcessing == (Object)null)
			{
				ReleaseContrast();
				return;
			}
			if ((Object)(object)profile != (Object)(object)tobacco.postProcessing)
			{
				ReleaseContrast();
				profile = tobacco.postProcessing;
			}
			float cigar = ((includeCigars && cigars != null) ? cigars.ReadBlack() : 0f);
			Settings settings = profile.colorGrading.settings;
			settings.basic.contrast = contrast.Apply(settings.basic.contrast, Bloom, PipeVisual.Charge, cigar);
			profile.colorGrading.settings = settings;
		}

		private static void AfterCigarComposition(PlayerTobacco __0)
		{
			Instance?.ApplyEffects(__0, includeCigars: true);
		}

		private void ReleaseContrast()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)profile != (Object)null)
			{
				Settings settings = profile.colorGrading.settings;
				settings.basic.contrast = contrast.Release(settings.basic.contrast);
				profile.colorGrading.settings = settings;
			}
			else
			{
				contrast.Release(0f);
			}
			profile = null;
		}

		private void SuspendNoBloom()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_0081: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.PropertyGetter(typeof(BloomComponent), "active");
			Patches patchInfo = Harmony.GetPatchInfo((MethodBase)methodInfo);
			if (patchInfo == null)
			{
				return;
			}
			foreach (Patch prefix in patchInfo.Prefixes)
			{
				if (prefix.owner == "com.app24.nobloom")
				{
					suspendedNoBloom.Add(new HarmonyMethod(prefix.PatchMethod)
					{
						priority = prefix.priority,
						before = prefix.before,
						after = prefix.after
					});
				}
			}
			if (suspendedNoBloom.Count > 0)
			{
				harmony.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)1, "com.app24.nobloom");
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Suspended No Bloom's bloom prefix while the Bloom setting is managed.");
			}
		}

		private void OnApplicationQuit()
		{
			quitting = true;
		}

		private void OnDestroy()
		{
			Cleanup();
		}

		private void Cleanup()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			SceneManager.sceneLoaded -= SceneLoaded;
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			ReleaseContrast();
			if (!quitting)
			{
				NativeSettingsMenu.RemoveAll();
			}
			foreach (HarmonyMethod item in suspendedNoBloom)
			{
				new Harmony("com.app24.nobloom").Patch((MethodBase)AccessTools.PropertyGetter(typeof(BloomComponent), "active"), item, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			suspendedNoBloom.Clear();
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerTobacco), "Update")]
	internal static class TobaccoBasePatch
	{
		[HarmonyPrefix]
		private static void Prefix(PlayerTobacco __instance)
		{
			Plugin.Instance?.PrepareVisual(__instance);
			Plugin.Instance?.PipeVisual.Tick(Time.deltaTime);
		}

		[HarmonyPostfix]
		[HarmonyBefore(new string[] { "DogEggz.Cigar" })]
		private static void Postfix(PlayerTobacco __instance)
		{
			Plugin.Instance?.ApplyEffects(__instance, includeCigars: false);
		}
	}
	[HarmonyPatch(typeof(PlayerTobacco), "Smoke")]
	internal static class PipeSmokePatch
	{
		private static void Prefix(PlayerTobacco __instance, int tobaccoType)
		{
			if (tobaccoType == 3)
			{
				Plugin.Instance?.PrepareVisual(__instance);
			}
		}

		private static void Postfix(PlayerTobacco __instance, int tobaccoType, bool __runOriginal)
		{
			if (tobaccoType == 3 && __runOriginal && !((Object)(object)Plugin.Instance == (Object)null))
			{
				Plugin.Instance.PipeVisual.Inhale(Time.deltaTime);
				Plugin.Instance.ApplyEffects(__instance, includeCigars: true);
			}
		}
	}
	[HarmonyPatch(typeof(SaveLoadManager), "LoadNeeds")]
	internal static class TobaccoLoadedPatch
	{
		private static void Postfix()
		{
			Plugin.Instance?.ResetVisual();
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class BloomPassPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ref bool __result)
		{
			if ((Object)(object)Plugin.Instance != (Object)null && !Plugin.Instance.Bloom)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(Settings), "ApplyCurrentResolution")]
	internal static class ApplyResolutionPatch
	{
		private static bool Prefix()
		{
			if ((Object)(object)Plugin.Instance == (Object)null)
			{
				return true;
			}
			Plugin.Instance.Display.ApplyVanillaRequest();
			return false;
		}
	}
	[HarmonyPatch(typeof(SettingsLoader), "Awake")]
	internal static class SettingsLoadedPatch
	{
		private static void Postfix(SettingsLoader __instance)
		{
			GPButtonSettingsCheckbo[] checkboxes = __instance.checkboxes;
			foreach (GPButtonSettingsCheckbo val in checkboxes)
			{
				if ((Object)(object)val != (Object)null && val.setting == "ambientOcclusion")
				{
					ResolutionsUI[] componentsInChildren = ((Component)((Component)val).transform.parent).GetComponentsInChildren<ResolutionsUI>(true);
					for (int j = 0; j < componentsInChildren.Length; j++)
					{
						NativeSettingsMenu.TryAttach(componentsInChildren[j]);
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(MouseButtonPointer), "DoRaycast")]
	internal static class PointerSyncPatch
	{
		private static void Prefix()
		{
			if (GameState.inCursorMenu && !Physics.autoSyncTransforms)
			{
				Physics.SyncTransforms();
			}
		}
	}
	[HarmonyPatch(typeof(GPButtonWindowMode), "OnActivate")]
	internal static class WindowModePatch
	{
		private static bool Prefix(GPButtonWindowMode __instance)
		{
			if ((Object)(object)Plugin.Instance == (Object)null || (Object)(object)((Component)__instance).GetComponentInParent<NativeSettingsMenu>() == (Object)null)
			{
				return true;
			}
			Plugin.Instance.Display.CycleWindowMode();
			return false;
		}
	}
	internal static class WindowsDisplayModes
	{
		private struct DxgiMode
		{
			internal uint Width;

			internal uint Height;

			internal uint Numerator;

			internal uint Denominator;

			internal uint Format;

			internal uint ScanlineOrder;

			internal uint Scaling;
		}

		[StructLayout(LayoutKind.Explicit, Size = 220)]
		private struct DeviceMode
		{
			[FieldOffset(68)]
			internal ushort Size;

			[FieldOffset(168)]
			internal uint Bits;

			[FieldOffset(172)]
			internal uint Width;

			[FieldOffset(176)]
			internal uint Height;

			[FieldOffset(180)]
			internal uint Flags;

			[FieldOffset(184)]
			internal uint Hertz;
		}

		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
		private struct MonitorInfo
		{
			internal uint Size;

			internal int Left;

			internal int Top;

			internal int Right;

			internal int Bottom;

			internal int WorkLeft;

			internal int WorkTop;

			internal int WorkRight;

			internal int WorkBottom;

			internal uint Flags;

			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
			internal string Device;
		}

		[UnmanagedFunctionPointer(CallingConvention.StdCall)]
		private delegate int Enumerate(IntPtr self, uint index, out IntPtr result);

		[UnmanagedFunctionPointer(CallingConvention.StdCall)]
		private delegate int GetDescription(IntPtr self, IntPtr result);

		[UnmanagedFunctionPointer(CallingConvention.StdCall)]
		private delegate int GetModes(IntPtr self, uint format, uint flags, ref uint count, IntPtr modes);

		[DllImport("dxgi.dll")]
		private static extern int CreateDXGIFactory(ref Guid id, out IntPtr factory);

		[DllImport("user32.dll", CharSet = CharSet.Unicode)]
		private static extern bool EnumDisplaySettings(string device, int index, ref DeviceMode mode);

		[DllImport("user32.dll")]
		private static extern IntPtr MonitorFromWindow(IntPtr window, uint flags);

		[DllImport("user32.dll", CharSet = CharSet.Unicode)]
		private static extern bool GetMonitorInfo(IntPtr monitor, ref MonitorInfo info);

		private static T Method<T>(IntPtr obj, int slot)
		{
			return (T)(object)Marshal.GetDelegateForFunctionPointer(Marshal.ReadIntPtr(Marshal.ReadIntPtr(obj), slot * IntPtr.Size), typeof(T));
		}

		private static void Check(int hr)
		{
			if (hr < 0)
			{
				Marshal.ThrowExceptionForHR(hr);
			}
		}

		internal static string DisplayName()
		{
			using Process process = Process.GetCurrentProcess();
			IntPtr monitor = MonitorFromWindow(process.MainWindowHandle, 1u);
			MonitorInfo info = new MonitorInfo
			{
				Size = (uint)Marshal.SizeOf(typeof(MonitorInfo))
			};
			return GetMonitorInfo(monitor, ref info) ? info.Device : null;
		}

		internal static bool TryCurrent(string device, out DisplayMode current)
		{
			DeviceMode mode = new DeviceMode
			{
				Size = 220
			};
			bool result = EnumDisplaySettings(device, -1, ref mode);
			current = new DisplayMode((int)mode.Width, (int)mode.Height, (int)mode.Hertz);
			return result;
		}

		internal static List<DisplayMode> Read(string device, IList<DisplayMode> vanilla)
		{
			List<DisplayMode> precise = ReadDxgi(device);
			List<DisplayMode> list = new List<DisplayMode>();
			int num = 0;
			while (true)
			{
				DeviceMode mode = new DeviceMode
				{
					Size = 220
				};
				if (!EnumDisplaySettings(device, num, ref mode))
				{
					break;
				}
				if (mode.Bits == 32 && (mode.Flags & 2) == 0 && mode.Hertz > 1)
				{
					list.Add(new DisplayMode((int)mode.Width, (int)mode.Height, (int)mode.Hertz));
				}
				num++;
			}
			return Merge(precise, list, vanilla);
		}

		internal static List<DisplayMode> Merge(IList<DisplayMode> precise, IList<DisplayMode> requests, IList<DisplayMode> vanilla)
		{
			List<DisplayMode> list = new List<DisplayMode>();
			foreach (DisplayMode request in requests)
			{
				int num = -1;
				double num2 = double.MaxValue;
				for (int i = 0; i < precise.Count; i++)
				{
					if (precise[i].SameSize(request))
					{
						double num3 = Math.Abs(precise[i].ExactHertz - (double)request.Hertz);
						if (num3 < num2)
						{
							num = i;
							num2 = num3;
						}
					}
				}
				if (num < 0 || num2 >= 1.0)
				{
					continue;
				}
				DisplayMode candidate = precise[num];
				int vanillaIndex = -1;
				double num4 = double.MaxValue;
				foreach (DisplayMode item in vanilla)
				{
					if (item.SameSize(candidate))
					{
						double num5 = Math.Abs(item.ExactHertz - Math.Floor(candidate.ExactHertz));
						if (num5 < num4)
						{
							vanillaIndex = item.VanillaIndex;
							num4 = num5;
						}
					}
				}
				candidate = new DisplayMode(candidate.Width, candidate.Height, candidate.Numerator, candidate.Denominator, request.Hertz, vanillaIndex);
				int num6 = list.FindIndex((DisplayMode m) => m.Equals(candidate));
				if (num6 < 0)
				{
					list.Add(candidate);
				}
				else if (Math.Abs((double)list[num6].Hertz - candidate.ExactHertz) > num2)
				{
					list[num6] = candidate;
				}
			}
			return list;
		}

		private static List<DisplayMode> ReadDxgi(string device)
		{
			List<DisplayMode> list = new List<DisplayMode>();
			Guid id = new Guid("7b7166ec-21c7-44ae-b21a-c9ae321ae369");
			Check(CreateDXGIFactory(ref id, out var factory));
			try
			{
				Enumerate enumerate = Method<Enumerate>(factory, 7);
				uint num = 0u;
				while (true)
				{
					int num2 = enumerate(factory, num, out var result);
					if (num2 == -2005270526)
					{
						break;
					}
					Check(num2);
					try
					{
						Enumerate enumerate2 = Method<Enumerate>(result, 7);
						uint num3 = 0u;
						while (true)
						{
							num2 = enumerate2(result, num3, out var result2);
							if (num2 == -2005270526)
							{
								break;
							}
							Check(num2);
							try
							{
								IntPtr intPtr = Marshal.AllocHGlobal(96);
								string a;
								try
								{
									Check(Method<GetDescription>(result2, 7)(result2, intPtr));
									a = Marshal.PtrToStringUni(intPtr);
								}
								finally
								{
									Marshal.FreeHGlobal(intPtr);
								}
								if (string.Equals(a, device, StringComparison.OrdinalIgnoreCase))
								{
									GetModes getModes = Method<GetModes>(result2, 8);
									uint count = 0u;
									Check(getModes(result2, 28u, 2u, ref count, IntPtr.Zero));
									if (count != 0)
									{
										IntPtr intPtr2 = Marshal.AllocHGlobal(checked((int)count * 28));
										try
										{
											Check(getModes(result2, 28u, 2u, ref count, intPtr2));
											for (int i = 0; i < count; i++)
											{
												DxgiMode dxgiMode = (DxgiMode)Marshal.PtrToStructure(IntPtr.Add(intPtr2, i * 28), typeof(DxgiMode));
												if (dxgiMode.Denominator != 0 && dxgiMode.Numerator != 0)
												{
													list.Add(new DisplayMode((int)dxgiMode.Width, (int)dxgiMode.Height, dxgiMode.Numerator, dxgiMode.Denominator, (int)(dxgiMode.Numerator / dxgiMode.Denominator)));
												}
											}
										}
										finally
										{
											Marshal.FreeHGlobal(intPtr2);
										}
									}
								}
							}
							finally
							{
								Marshal.Release(result2);
							}
							num3++;
						}
					}
					finally
					{
						Marshal.Release(result);
					}
					num++;
				}
				return list;
			}
			finally
			{
				Marshal.Release(factory);
			}
		}
	}
}