Decompiled source of WindowLayout v0.1.0

plugins/WindowLayout/WindowLayout.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RepoMods.Shared;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("saya")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("WindowLayout")]
[assembly: AssemblyTitle("WindowLayout")]
[assembly: AssemblyVersion("0.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 RepoMods.Shared
{
	internal sealed class RepoConfigLocalization
	{
		private sealed class ChoiceLabels(Translation[]? japanese, Translation[]? english)
		{
			internal Translation[]? Japanese { get; } = japanese;

			internal Translation[]? English { get; } = english;
		}

		[DataContract]
		internal sealed class Catalog
		{
			[DataMember(Name = "sections")]
			public Translation[]? Sections { get; set; }

			[DataMember(Name = "settings")]
			public Setting[] Settings { get; set; } = Array.Empty<Setting>();

			[DataMember(Name = "toggle")]
			public Translation[]? Toggle { get; set; }
		}

		[DataContract]
		internal sealed class Setting
		{
			[DataMember(Name = "section")]
			public string Section { get; set; } = string.Empty;

			[DataMember(Name = "key")]
			public string Key { get; set; } = string.Empty;

			[DataMember(Name = "label")]
			public string? Label { get; set; }

			[DataMember(Name = "choices")]
			public Translation[]? Choices { get; set; }
		}

		[DataContract]
		internal sealed class Translation
		{
			[DataMember(Name = "key")]
			public string Key { get; set; } = string.Empty;

			[DataMember(Name = "label")]
			public string? Label { get; set; }
		}

		internal const string RepoConfigGuid = "nickklmao.repoconfig";

		private const string MenuLibGuid = "nickklmao.menulib";

		private static RepoConfigLocalization? _active;

		private readonly ConfigFile _config;

		private readonly ManualLogSource _log;

		private readonly Harmony _harmony;

		private readonly Catalog? _japanese;

		private readonly Catalog? _english;

		private readonly MethodInfo _createEntries;

		private readonly Func<string, string> _displayName;

		private readonly Func<string?> _localeCode;

		private readonly Type _rowType;

		private readonly Type _labelType;

		private readonly Type _sliderType;

		private readonly Type _toggleType;

		private readonly Dictionary<Type, FieldInfo> _settingLabels;

		private readonly FieldInfo _categoryLabel;

		private readonly FieldInfo _leftToggle;

		private readonly FieldInfo _rightToggle;

		private readonly FieldInfo _sliderValue;

		private readonly FieldInfo _sliderText;

		private readonly FieldInfo _maskedSliderText;

		private readonly PropertyInfo _sliderOptions;

		private readonly MethodInfo _updateSliderText;

		private readonly ConditionalWeakTable<Component, ChoiceLabels> _choices = new ConditionalWeakTable<Component, ChoiceLabels>();

		private bool _failed;

		private RepoConfigLocalization(BaseUnityPlugin plugin, Catalog? japanese, Catalog? english, Assembly repoConfig, Assembly menuLib, Func<string?> localeCode)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			_config = plugin.Config;
			_log = Logger.CreateLogSource(plugin.Info.Metadata.Name + " REPOConfig");
			_harmony = new Harmony(plugin.Info.Metadata.GUID + ".repoconfig-localization");
			_japanese = japanese;
			_english = english;
			_localeCode = localeCode;
			Type type = repoConfig.GetType("REPOConfig.ConfigMenu", throwOnError: true);
			_createEntries = Method(type, "CreateModEntries", MenuType(menuLib, "REPOPopupPage"), typeof(ConfigEntryBase[]));
			_displayName = (Func<string, string>)Method(type, "FixNaming", typeof(string)).CreateDelegate(typeof(Func<string, string>));
			_rowType = MenuType(menuLib, "REPOElement");
			_labelType = MenuType(menuLib, "REPOLabel");
			_sliderType = MenuType(menuLib, "REPOSlider");
			_toggleType = MenuType(menuLib, "REPOToggle");
			Type type2 = MenuType(menuLib, "REPOInputField");
			_settingLabels = new Dictionary<Type, FieldInfo>
			{
				[_sliderType] = Field(_sliderType, "labelTMP"),
				[_toggleType] = Field(_toggleType, "labelTMP"),
				[type2] = Field(type2, "labelTMP")
			};
			_categoryLabel = Field(_labelType, "labelTMP");
			_leftToggle = Field(_toggleType, "leftButtonTMP");
			_rightToggle = Field(_toggleType, "rightButtonTMP");
			_sliderValue = Field(_sliderType, "value");
			_sliderText = Field(_sliderType, "valueTMP");
			_maskedSliderText = Field(_sliderType, "maskedValueTMP");
			_sliderOptions = AccessTools.DeclaredProperty(_sliderType, "stringOptions") ?? throw new MissingMemberException(_sliderType.FullName, "stringOptions");
			_updateSliderText = Method(_sliderType, "UpdateBarText");
		}

		internal static void Start(BaseUnityPlugin plugin, Catalog? english = null)
		{
			if (!Chainloader.PluginInfos.TryGetValue("nickklmao.repoconfig", out var value) || !Chainloader.PluginInfos.TryGetValue("nickklmao.menulib", out var value2))
			{
				return;
			}
			RepoConfigLocalization repoConfigLocalization = null;
			try
			{
				Type type = Type.GetType("UnityEngine.Localization.Settings.LocalizationSettings, Unity.Localization");
				Catalog catalog = (((object)type == null) ? null : ReadJapaneseCatalog(plugin.Info.Location));
				if (catalog != null || english != null)
				{
					repoConfigLocalization = new RepoConfigLocalization(plugin, catalog, english, ((object)value.Instance).GetType().Assembly, ((object)value2.Instance).GetType().Assembly, ((object)type == null) ? ((Func<string>)(() => (string?)null)) : CreateLocaleReader(type));
					repoConfigLocalization._harmony.Patch((MethodBase)repoConfigLocalization._createEntries, (HarmonyMethod)null, Hook("AfterCreateEntries"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					if (HasChoices(catalog) || HasChoices(english))
					{
						repoConfigLocalization._harmony.Patch((MethodBase)repoConfigLocalization._updateSliderText, (HarmonyMethod)null, Hook("AfterUpdateSliderText"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					}
					_active = repoConfigLocalization;
				}
			}
			catch (Exception ex)
			{
				if (repoConfigLocalization != null)
				{
					repoConfigLocalization._harmony.UnpatchSelf();
				}
				(repoConfigLocalization?._log ?? Logger.CreateLogSource(plugin.Info.Metadata.Name + " REPOConfig")).LogWarning((object)("Localization could not start (" + ex.GetType().Name + "); using REPOConfig defaults."));
			}
		}

		private static Catalog? ReadJapaneseCatalog(string pluginPath)
		{
			string path = Path.ChangeExtension(pluginPath, ".repoconfig.ja.json");
			if (!File.Exists(path))
			{
				return null;
			}
			using FileStream stream = File.OpenRead(path);
			object result;
			if (new DataContractJsonSerializer(typeof(Catalog)).ReadObject(stream) is Catalog catalog)
			{
				Setting[] settings = catalog.Settings;
				if (settings != null && settings.Length > 0)
				{
					result = catalog;
					goto IL_004f;
				}
			}
			result = null;
			goto IL_004f;
			IL_004f:
			return (Catalog?)result;
		}

		private static bool HasChoices(Catalog? catalog)
		{
			return catalog?.Settings.Any(delegate(Setting setting)
			{
				Translation[] choices = setting.Choices;
				return choices != null && choices.Length > 0;
			}) ?? false;
		}

		internal static void Stop()
		{
			RepoConfigLocalization? active = _active;
			_active = null;
			if (active != null)
			{
				active._harmony.UnpatchSelf();
			}
		}

		private static Func<string?> CreateLocaleReader(Type settings)
		{
			PropertyInfo selected = settings.GetProperty("SelectedLocale", BindingFlags.Static | BindingFlags.Public) ?? throw new MissingMemberException(settings.FullName, "SelectedLocale");
			PropertyInfo identifier = selected.PropertyType.GetProperty("Identifier") ?? throw new MissingMemberException(selected.PropertyType.FullName, "Identifier");
			PropertyInfo code = identifier.PropertyType.GetProperty("Code") ?? throw new MissingMemberException(identifier.PropertyType.FullName, "Code");
			return delegate
			{
				object value = selected.GetValue(null);
				return (value == null) ? null : (code.GetValue(identifier.GetValue(value)) as string);
			};
		}

		private static void AfterCreateEntries(Component __0, ConfigEntryBase[] __1)
		{
			RepoConfigLocalization active = _active;
			if (active == null || active._failed || __1.Length == 0 || __1[0].ConfigFile != active._config)
			{
				return;
			}
			try
			{
				string a = active._localeCode();
				Catalog catalog = ((string.Equals(a, "ja-JP", StringComparison.OrdinalIgnoreCase) || string.Equals(a, "ja", StringComparison.OrdinalIgnoreCase)) ? active._japanese : null);
				if (catalog != null || active._english != null)
				{
					active.TranslatePage(__0, __1, catalog);
				}
			}
			catch (Exception ex)
			{
				active._failed = true;
				active._log.LogWarning((object)("Localization could not update the menu (" + ex.GetType().Name + ")."));
			}
		}

		private void TranslatePage(Component page, ConfigEntryBase[] entries, Catalog? japanese)
		{
			ILookup<string, IGrouping<string, ConfigEntryBase>> lookup = (from entry in entries
				group entry by entry.Definition.Section).ToLookup<IGrouping<string, ConfigEntryBase>, string>((IGrouping<string, ConfigEntryBase> section) => _displayName(section.Key), StringComparer.Ordinal);
			IGrouping<string, ConfigEntryBase> grouping = null;
			Component[] componentsInChildren = page.GetComponentsInChildren(_rowType, true);
			foreach (Component val in componentsInChildren)
			{
				Type type = ((object)val).GetType();
				if (type == _labelType)
				{
					TMP_Text val2 = ReadText(_categoryLabel, val);
					if (val2 != null)
					{
						grouping = Unique(lookup[val2.text]);
						SetText(val2, FindLabel(japanese?.Sections, grouping?.Key) ?? FindLabel(_english?.Sections, grouping?.Key));
						continue;
					}
				}
				if (grouping == null || !_settingLabels.TryGetValue(type, out FieldInfo value))
				{
					continue;
				}
				TMP_Text label = ReadText(value, val);
				if (label == null)
				{
					continue;
				}
				ConfigEntryBase val3 = Unique(grouping.Where((ConfigEntryBase item) => _displayName(item.Definition.Key) == label.text));
				if (val3 == null)
				{
					continue;
				}
				Setting setting = FindSetting(japanese, val3.Definition);
				Setting setting2 = FindSetting(_english, val3.Definition);
				SetText(label, setting?.Label ?? setting2?.Label);
				if (type == _toggleType)
				{
					Translation[] array = japanese?.Toggle;
					if (array != null)
					{
						TranslateToggle(val, _leftToggle, array);
						TranslateToggle(val, _rightToggle, array);
					}
				}
				if (!(type == _sliderType))
				{
					continue;
				}
				Translation[] array2 = setting?.Choices;
				if (array2 == null || array2.Length <= 0)
				{
					array2 = setting2?.Choices;
					if (array2 == null || array2.Length <= 0)
					{
						continue;
					}
				}
				_choices.Add(val, new ChoiceLabels(setting?.Choices, setting2?.Choices));
				_updateSliderText.Invoke(val, null);
			}
		}

		private static void TranslateToggle(Component row, FieldInfo field, Translation[] toggles)
		{
			TMP_Text val = ReadText(field, row);
			if (val != null)
			{
				SetText(val, FindLabel(toggles, val.text));
			}
		}

		private static Setting? FindSetting(Catalog? catalog, ConfigDefinition definition)
		{
			return catalog?.Settings.FirstOrDefault((Setting item) => item.Section == definition.Section && item.Key == definition.Key);
		}

		private static void AfterUpdateSliderText(Component __instance)
		{
			RepoConfigLocalization active = _active;
			if (active != null && !active._failed && active._choices.TryGetValue(__instance, out ChoiceLabels value) && active._sliderOptions.GetValue(__instance) is string[] array && array.Length > 0)
			{
				int num = Convert.ToInt32((float)active._sliderValue.GetValue(__instance));
				string key = ((num >= 0 && num < array.Length) ? array[num] : array[0]);
				string label = FindLabel(value.Japanese, key) ?? FindLabel(value.English, key);
				SetText(ReadText(active._sliderText, __instance), label);
				SetText(ReadText(active._maskedSliderText, __instance), label);
			}
		}

		private static T? Unique<T>(IEnumerable<T> matches) where T : class
		{
			using IEnumerator<T> enumerator = matches.GetEnumerator();
			if (!enumerator.MoveNext())
			{
				return null;
			}
			T current = enumerator.Current;
			return enumerator.MoveNext() ? null : current;
		}

		private static string? FindLabel(Translation[]? translations, string? key)
		{
			return translations?.FirstOrDefault((Translation translation) => translation.Key == key)?.Label;
		}

		private static TMP_Text? ReadText(FieldInfo field, Component row)
		{
			object? value = field.GetValue(row);
			return (TMP_Text?)((value is TMP_Text) ? value : null);
		}

		private static void SetText(TMP_Text? text, string? label)
		{
			if (text != null && !string.IsNullOrWhiteSpace(label))
			{
				text.text = label;
			}
		}

		private static Type MenuType(Assembly assembly, string name)
		{
			return assembly.GetType("MenuLib.MonoBehaviors." + name, throwOnError: true);
		}

		private static MethodInfo Method(Type type, string name, params Type[] parameters)
		{
			return AccessTools.DeclaredMethod(type, name, parameters, (Type[])null) ?? throw new MissingMethodException(type.FullName, name);
		}

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

		private static HarmonyMethod Hook(string name)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			return new HarmonyMethod(typeof(RepoConfigLocalization), name, (Type[])null);
		}
	}
}
namespace WindowLayout
{
	internal static class Layout
	{
		internal static int Width(string preset, int customWidth)
		{
			return preset switch
			{
				"1280x720" => 1280, 
				"1920x1080" => 1920, 
				"2560x1440" => 2560, 
				"Custom" => (Math.Clamp(customWidth, 320, 7680) + 8) / 16 * 16, 
				_ => 1600, 
			};
		}

		internal static int Center(int start, int end, int size)
		{
			return start + Math.Max(0, (end - start - size) / 2);
		}
	}
	internal sealed class NativeWindow
	{
		private struct Rect
		{
			public int Left;

			public int Top;

			public int Right;

			public int Bottom;

			public int Width => Right - Left;

			public int Height => Bottom - Top;
		}

		private struct MonitorInfo
		{
			public int Size;

			public Rect Bounds;

			public Rect Work;

			public uint Flags;
		}

		private const int Style = -16;

		private const int ResizeStyles = 327680;

		private const uint NoSize = 1u;

		private const uint NoMove = 2u;

		private const uint NoZOrder = 4u;

		private const uint NoActivate = 16u;

		private const uint FrameChanged = 32u;

		private IntPtr locked;

		private int removed;

		internal bool IsLocked => locked != IntPtr.Zero;

		internal bool Apply(int width, int height, bool center, int x, int y)
		{
			IntPtr intPtr = FindGameWindow();
			if (intPtr == IntPtr.Zero || IsIconic(intPtr))
			{
				return false;
			}
			if (IsZoomed(intPtr))
			{
				ShowWindow(intPtr, 9);
			}
			if (intPtr != locked)
			{
				removed = 0;
			}
			int windowLong = GetWindowLong(intPtr, -16);
			if (windowLong == 0)
			{
				return false;
			}
			if ((windowLong & 0x50000) != 0)
			{
				if (SetWindowLong(intPtr, -16, windowLong & -327681) == 0)
				{
					return false;
				}
				removed |= windowLong & 0x50000;
			}
			locked = intPtr;
			if (!SetWindowPos(intPtr, IntPtr.Zero, 0, 0, 0, 0, 55u) || !GetWindowRect(intPtr, out var rect) || !GetClientRect(intPtr, out var rect2))
			{
				return false;
			}
			int num = width + rect.Width - rect2.Width;
			int num2 = height + rect.Height - rect2.Height;
			if (center)
			{
				MonitorInfo info = new MonitorInfo
				{
					Size = Marshal.SizeOf<MonitorInfo>()
				};
				if (!GetMonitorInfo(MonitorFromWindow(intPtr, 2u), ref info))
				{
					return false;
				}
				x = Layout.Center(info.Work.Left, info.Work.Right, num);
				y = Layout.Center(info.Work.Top, info.Work.Bottom, num2);
			}
			if (SetWindowPos(intPtr, IntPtr.Zero, x, y, num, num2, 52u) && GetClientRect(intPtr, out rect2) && rect2.Width == width)
			{
				return rect2.Height == height;
			}
			return false;
		}

		internal void Release()
		{
			if (!IsLocked)
			{
				return;
			}
			if (removed != 0 && FindGameWindow() == locked)
			{
				int windowLong = GetWindowLong(locked, -16);
				if (windowLong == 0 || SetWindowLong(locked, -16, windowLong | removed) == 0 || !SetWindowPos(locked, IntPtr.Zero, 0, 0, 0, 0, 55u))
				{
					return;
				}
			}
			locked = IntPtr.Zero;
			removed = 0;
		}

		private static IntPtr FindGameWindow()
		{
			using Process process = Process.GetCurrentProcess();
			IntPtr intPtr = IntPtr.Zero;
			while ((intPtr = FindWindowEx(IntPtr.Zero, intPtr, "UnityWndClass", null)) != IntPtr.Zero)
			{
				GetWindowThreadProcessId(intPtr, out var owner);
				if (owner == process.Id && IsWindowVisible(intPtr))
				{
					return intPtr;
				}
			}
			return IntPtr.Zero;
		}

		[DllImport("user32.dll", CharSet = CharSet.Unicode)]
		private static extern IntPtr FindWindowEx(IntPtr parent, IntPtr after, string className, string? title);

		[DllImport("user32.dll")]
		private static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint owner);

		[DllImport("user32.dll")]
		private static extern bool IsWindowVisible(IntPtr hwnd);

		[DllImport("user32.dll")]
		private static extern bool IsIconic(IntPtr hwnd);

		[DllImport("user32.dll")]
		private static extern bool IsZoomed(IntPtr hwnd);

		[DllImport("user32.dll")]
		private static extern bool ShowWindow(IntPtr hwnd, int command);

		[DllImport("user32.dll")]
		private static extern int GetWindowLong(IntPtr hwnd, int index);

		[DllImport("user32.dll")]
		private static extern int SetWindowLong(IntPtr hwnd, int index, int value);

		[DllImport("user32.dll")]
		private static extern bool GetWindowRect(IntPtr hwnd, out Rect rect);

		[DllImport("user32.dll")]
		private static extern bool GetClientRect(IntPtr hwnd, out Rect rect);

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

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

		[DllImport("user32.dll")]
		private static extern bool SetWindowPos(IntPtr hwnd, IntPtr insertAfter, int x, int y, int width, int height, uint flags);
	}
	[BepInPlugin("saya.WindowLayout", "Window Layout", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginVersion = "0.1.0";

		private ConfigEntry<bool> active;

		private ConfigEntry<string> preset;

		private ConfigEntry<int> customWidth;

		private ConfigEntry<bool> center;

		private ConfigEntry<int> x;

		private ConfigEntry<int> y;

		private readonly NativeWindow window = new NativeWindow();

		private bool wasWindowed;

		private volatile bool pending = true;

		private int applyFrame;

		private float retryAt;

		private void Awake()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			if ((int)Application.platform != 2)
			{
				((Behaviour)this).enabled = false;
				return;
			}
			active = ((BaseUnityPlugin)this).Config.Bind<bool>("Window", "Enabled", true, "Apply the layout in windowed mode on Windows.");
			preset = ((BaseUnityPlugin)this).Config.Bind<string>("Window", "Size", "1600x900", new ConfigDescription("Client area in pixels.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[5] { "1280x720", "1600x900", "1920x1080", "2560x1440", "Custom" }), Array.Empty<object>()));
			customWidth = ((BaseUnityPlugin)this).Config.Bind<int>("Window", "Custom Width", 1600, new ConfigDescription("Rounded to the nearest multiple of 16.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(320, 7680), Array.Empty<object>()));
			center = ((BaseUnityPlugin)this).Config.Bind<bool>("Window", "Center", true, "Center on the current monitor's work area.");
			x = ((BaseUnityPlugin)this).Config.Bind<int>("Window", "Left", 0, "Left edge in virtual desktop coordinates when Center is off.");
			y = ((BaseUnityPlugin)this).Config.Bind<int>("Window", "Top", 0, "Top edge in virtual desktop coordinates when Center is off.");
			((BaseUnityPlugin)this).Config.SettingChanged += SettingsChanged;
			RepoConfigLocalization.Start((BaseUnityPlugin)(object)this);
		}

		private void SettingsChanged(object sender, SettingChangedEventArgs args)
		{
			pending = true;
		}

		private void LateUpdate()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			bool flag = (int)Screen.fullScreenMode == 3;
			if (!flag || !active.Value)
			{
				if (flag && window.IsLocked)
				{
					window.Release();
				}
				wasWindowed = false;
				return;
			}
			if (!wasWindowed || pending)
			{
				pending = false;
				wasWindowed = true;
				applyFrame = Time.frameCount + 2;
				retryAt = 0f;
			}
			if (applyFrame == 0 || Time.frameCount < applyFrame || Time.unscaledTime < retryAt)
			{
				return;
			}
			int num = Layout.Width(preset.Value, customWidth.Value);
			if (window.Apply(num, num / 16 * 9, center.Value, x.Value, y.Value))
			{
				applyFrame = 0;
				return;
			}
			if (retryAt == 0f)
			{
				((BaseUnityPlugin)this).Logger.LogDebug((object)"Waiting for the game window to accept the layout.");
			}
			retryAt = Time.unscaledTime + 1f;
		}

		private void OnDestroy()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			if (active != null)
			{
				((BaseUnityPlugin)this).Config.SettingChanged -= SettingsChanged;
				if ((int)Screen.fullScreenMode == 3)
				{
					window.Release();
				}
				RepoConfigLocalization.Stop();
			}
		}
	}
}