Decompiled source of PocketCalc v1.3.1

PocketCalc.dll

Decompiled 2 hours ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[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 PocketCalc
{
	public static class Expr
	{
		public const string DivideByZero = "Cannot divide by zero";

		public const string Invalid = "Invalid expression";

		public const string TooBig = "Result too large";

		public static string Eval(string s, out double value)
		{
			value = 0.0;
			double num = 0.0;
			double num2 = 1.0;
			char c = '+';
			char c2 = '*';
			int i = 0;
			while (true)
			{
				bool flag = false;
				for (; i < s.Length && (s[i] == '+' || s[i] == '-'); i++)
				{
					flag ^= s[i] == '-';
				}
				int num3 = i;
				for (; i < s.Length && (char.IsDigit(s[i]) || s[i] == '.'); i++)
				{
				}
				if (i < s.Length && s[i] == 'E')
				{
					i++;
					if (i < s.Length && (s[i] == '+' || s[i] == '-'))
					{
						i++;
					}
					for (; i < s.Length && char.IsDigit(s[i]); i++)
					{
					}
				}
				if (!double.TryParse(s.Substring(num3, i - num3), NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
				{
					return "Invalid expression";
				}
				if (flag)
				{
					result = 0.0 - result;
				}
				if (c2 == '*')
				{
					num2 *= result;
				}
				else
				{
					if (result == 0.0)
					{
						return "Cannot divide by zero";
					}
					num2 /= result;
				}
				if (i == s.Length)
				{
					break;
				}
				char c3 = s[i++];
				switch (c3)
				{
				case '*':
				case '/':
					c2 = c3;
					break;
				case '+':
				case '-':
					num += ((c == '+') ? num2 : (0.0 - num2));
					c = c3;
					num2 = 1.0;
					c2 = '*';
					break;
				default:
					return "Invalid expression";
				}
			}
			value = num + ((c == '+') ? num2 : (0.0 - num2));
			if (!double.IsNaN(value) && !double.IsInfinity(value))
			{
				return null;
			}
			return "Result too large";
		}

		public static string Format(double v)
		{
			if (v != 0.0)
			{
				return v.ToString("G15", CultureInfo.InvariantCulture);
			}
			return "0";
		}
	}
	public class Calculator
	{
		private const int MaxLength = 60;

		private double? answer;

		private string typed = "";

		private string last = "";

		public string Error { get; private set; }

		public string Shown => (answer.HasValue ? Expr.Format(answer.Value) : "") + typed;

		public string Top => Error ?? last;

		public void Press(char c)
		{
			if (c >= '0' && c <= '9')
			{
				StartNumber();
				if (typed.Length < 60)
				{
					typed += c;
				}
				return;
			}
			switch (c)
			{
			case ',':
			case '.':
				Decimal();
				break;
			case '*':
			case '+':
			case '-':
			case '/':
				Operator(c);
				break;
			case '=':
				Enter();
				break;
			case '\b':
				Error = null;
				if (typed.Length > 0)
				{
					typed = typed.Substring(0, typed.Length - 1);
					break;
				}
				answer = null;
				last = "";
				break;
			}
		}

		private void StartNumber()
		{
			Error = null;
			if (typed.Length == 0)
			{
				answer = null;
			}
		}

		private void Decimal()
		{
			StartNumber();
			int num = typed.LastIndexOfAny(new char[4] { '+', '-', '*', '/' }) + 1;
			if (typed.IndexOf('.', num) < 0 && typed.Length < 60)
			{
				typed += ((num == typed.Length) ? "0." : ".");
			}
		}

		private void Operator(char c)
		{
			Error = null;
			char c2 = ((typed.Length > 0) ? typed[typed.Length - 1] : '\0');
			if (c == '-' && (c2 == '*' || c2 == '/'))
			{
				typed += c;
				return;
			}
			typed = typed.TrimEnd('+', '-', '*', '/');
			if ((Shown.Length != 0 || c == '-') && typed.Length < 60)
			{
				typed += c;
			}
		}

		public void Enter()
		{
			string text = typed.TrimEnd('+', '-', '*', '/');
			if (text.Length == 0)
			{
				typed = "";
				return;
			}
			string s = (answer.HasValue ? answer.Value.ToString("R", CultureInfo.InvariantCulture) : "") + text;
			Error = Expr.Eval(s, out var value);
			if (Error == null)
			{
				last = (answer.HasValue ? Expr.Format(answer.Value) : "") + text + " =";
				answer = value;
				typed = "";
			}
		}

		public void Clear()
		{
			answer = null;
			typed = (last = "");
			Error = null;
		}
	}
	[BepInPlugin("bug.dsp.pocketcalc", "PocketCalc", "1.3.1")]
	public class Plugin : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__38_0;

			public static UnityAction <>9__38_1;

			public static UnityAction <>9__38_2;

			public static UnityAction <>9__38_3;

			public static UnityAction <>9__38_4;

			internal void <Build>b__38_0()
			{
				win.SetActive(false);
			}

			internal void <Build>b__38_1()
			{
				calc.Press('\b');
			}

			internal void <Build>b__38_2()
			{
				calc.Press('/');
			}

			internal void <Build>b__38_3()
			{
				calc.Press('0');
			}

			internal void <Build>b__38_4()
			{
				calc.Press('.');
			}
		}

		private const int ShownChars = 30;

		private const float Width = 304f;

		private const float Height = 372f;

		private const float Left = 20f;

		private const float Key = 60f;

		private const float KeyStep = 68f;

		private const float RowHeight = 38f;

		private const float RowStep = 46f;

		private const float FirstRow = -130f;

		private static readonly string[] DigitRows = new string[3] { "789*", "456-", "123+" };

		private static readonly Color Ink = Color32.op_Implicit(new Color32((byte)232, (byte)246, (byte)252, byte.MaxValue));

		private static readonly Color Soft = Color32.op_Implicit(new Color32((byte)176, (byte)208, (byte)220, byte.MaxValue));

		private static readonly Color Accent = Color32.op_Implicit(new Color32((byte)253, (byte)150, (byte)94, byte.MaxValue));

		private static readonly Color AccentInk = Color32.op_Implicit(new Color32((byte)28, (byte)14, (byte)6, byte.MaxValue));

		private static readonly Color Scrim = Color32.op_Implicit(new Color32((byte)4, (byte)22, (byte)30, (byte)168));

		private static readonly Color Well = Color32.op_Implicit(new Color32((byte)0, (byte)10, (byte)16, (byte)120));

		private static readonly Color Line = Color32.op_Implicit(new Color32((byte)167, (byte)233, byte.MaxValue, (byte)40));

		private static readonly Color[] Glass = (Color[])(object)new Color[4]
		{
			Color32.op_Implicit(new Color32((byte)167, (byte)233, byte.MaxValue, (byte)56)),
			Color32.op_Implicit(new Color32((byte)167, (byte)233, byte.MaxValue, (byte)92)),
			Color32.op_Implicit(new Color32((byte)167, (byte)233, byte.MaxValue, (byte)32)),
			Ink
		};

		private static readonly Color[] Operator = (Color[])(object)new Color[4]
		{
			Color32.op_Implicit(new Color32((byte)167, (byte)233, byte.MaxValue, (byte)104)),
			Color32.op_Implicit(new Color32((byte)167, (byte)233, byte.MaxValue, (byte)140)),
			Color32.op_Implicit(new Color32((byte)167, (byte)233, byte.MaxValue, (byte)72)),
			Ink
		};

		private static readonly Color[] Equals_ = (Color[])(object)new Color[4]
		{
			Accent,
			Color32.op_Implicit(new Color32(byte.MaxValue, (byte)174, (byte)128, byte.MaxValue)),
			Color32.op_Implicit(new Color32((byte)226, (byte)128, (byte)76, byte.MaxValue)),
			AccentInk
		};

		private static readonly Color[] ClearKey = (Color[])(object)new Color[4]
		{
			Color32.op_Implicit(new Color32((byte)253, (byte)110, (byte)80, (byte)70)),
			Color32.op_Implicit(new Color32((byte)253, (byte)110, (byte)80, (byte)108)),
			Color32.op_Implicit(new Color32((byte)253, (byte)110, (byte)80, (byte)46)),
			Color32.op_Implicit(new Color32(byte.MaxValue, (byte)222, (byte)210, byte.MaxValue))
		};

		public static bool Blocking;

		public static bool PassThrough;

		public static bool OtherFieldFocused;

		private static ConfigEntry<KeyboardShortcut> hotkey;

		private static readonly Calculator calc = new Calculator();

		private static KeyCode waitRelease;

		private static GameObject win;

		private static Text topText;

		private static Text mainText;

		private static bool Open
		{
			get
			{
				if ((Object)(object)win != (Object)null)
				{
					return win.activeInHierarchy;
				}
				return false;
			}
		}

		public static bool IsBlocked(KeyCode key)
		{
			//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_000e: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			if ((int)key < 323)
			{
				if ((int)key >= 303)
				{
					return (int)key > 313;
				}
				return true;
			}
			return false;
		}

		private void Awake()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			hotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "Hotkey", new KeyboardShortcut((KeyCode)99, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Opens and closes the calculator.");
			new Harmony("bug.dsp.pocketcalc").PatchAll(typeof(Patches));
		}

		private static void Close(KeyCode pressed)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			win.SetActive(false);
			waitRelease = pressed;
		}

		private void Update()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Invalid comparison between Unknown and I4
			//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_009c: Unknown result type (might be due to invalid IL or missing references)
			if (!GameMain.isRunning || DSPGame.IsMenuDemo || GameMain.isPaused || !((ManualBehaviour)UIRoot.instance.uiGame).active)
			{
				if ((Object)(object)win != (Object)null)
				{
					win.SetActive(false);
				}
				Blocking = false;
				waitRelease = (KeyCode)0;
				return;
			}
			PassThrough = true;
			if ((int)waitRelease != 0 && !Input.GetKey(waitRelease))
			{
				waitRelease = (KeyCode)0;
			}
			if (!OtherFieldFocused)
			{
				KeyboardShortcut value = hotkey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					if (Open)
					{
						value = hotkey.Value;
						Close(((KeyboardShortcut)(ref value)).MainKey);
					}
					else
					{
						if ((Object)(object)win == (Object)null)
						{
							Build();
						}
						win.SetActive(true);
						win.transform.SetAsLastSibling();
					}
				}
				else if (Open)
				{
					if (Input.GetKeyDown((KeyCode)27))
					{
						Close((KeyCode)27);
					}
					else if (Input.GetKeyDown((KeyCode)13) || Input.GetKeyDown((KeyCode)271))
					{
						calc.Enter();
					}
					else if (Input.GetKeyDown((KeyCode)127))
					{
						calc.Clear();
					}
					else
					{
						string inputString = Input.inputString;
						foreach (char c in inputString)
						{
							calc.Press(c);
						}
					}
				}
			}
			PassThrough = false;
			Blocking = Open || (int)waitRelease > 0;
			if (Open)
			{
				ShowState();
			}
		}

		private static string Tail(string s)
		{
			if (s.Length <= 30)
			{
				return s;
			}
			return "…" + s.Substring(s.Length - 30);
		}

		private static void ShowState()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			topText.text = Tail(calc.Top);
			((Graphic)topText).color = ((calc.Error != null) ? Color32.op_Implicit(new Color32(byte.MaxValue, (byte)150, (byte)130, byte.MaxValue)) : Soft);
			mainText.text = ((calc.Shown.Length == 0) ? "0" : Tail(calc.Shown));
			mainText.fontSize = ((mainText.text.Length <= 14) ? 28 : ((mainText.text.Length <= 20) ? 20 : 16));
		}

		private static void Build()
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Expected O, but got Unknown
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: 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_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: 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_02b2: 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_02d8: Expected O, but got Unknown
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: 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_0324: Expected O, but got Unknown
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Expected O, but got Unknown
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_048d: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: Expected O, but got Unknown
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04db: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0506: Unknown result type (might be due to invalid IL or missing references)
			//IL_0510: Expected O, but got Unknown
			//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Expected O, but got Unknown
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Expected O, but got Unknown
			Transform transform = ((Component)UIRoot.instance.uiGame.generatorWindow).transform;
			GameObject gameObject = ((Component)transform.Find("ray-receiver/switch-button-1")).gameObject;
			Text component = ((Component)transform.Find("power-network-desc/desc-group/label-1")).GetComponent<Text>();
			Text component2 = ((Component)transform.Find("power-network-desc/desc-group/value-1")).GetComponent<Text>();
			win = Object.Instantiate<GameObject>(((Component)transform).gameObject, transform.parent, false);
			((Object)win).name = "Calculator";
			Object.DestroyImmediate((Object)(object)win.GetComponent<UIPowerGeneratorWindow>());
			foreach (Transform item in win.transform)
			{
				Transform val = item;
				if (((Object)val).name != "panel-bg")
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
			Object.Destroy((Object)(object)((Component)win.transform.Find("panel-bg/btn-box/menu-wnd-btn")).gameObject);
			StripLocalizers(win);
			Backdrop(win.transform.Find("panel-bg"));
			Button component3 = ((Component)win.transform.Find("panel-bg/btn-box/close-wnd-btn")).GetComponent<Button>();
			component3.onClick = new ButtonClickedEvent();
			ButtonClickedEvent onClick = component3.onClick;
			object obj = <>c.<>9__38_0;
			if (obj == null)
			{
				UnityAction val2 = delegate
				{
					win.SetActive(false);
				};
				<>c.<>9__38_0 = val2;
				obj = (object)val2;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			Text component4 = ((Component)win.transform.Find("panel-bg/title-text")).GetComponent<Text>();
			component4.text = "Calculator";
			((Graphic)component4).rectTransform.sizeDelta = new Vector2(200f, ((Graphic)component4).rectTransform.sizeDelta.y);
			RectTransform val3 = (RectTransform)win.transform;
			val3.anchoredPosition = new Vector2(400f, 250f);
			val3.sizeDelta = new Vector2(304f, 372f);
			Card((Transform)(object)val3, new Vector2(20f, -50f), new Vector2(264f, 68f), Well);
			topText = NewText(component, (Transform)(object)val3, new Vector2(30f, -54f), new Vector2(244f, 18f));
			topText.fontSize = 13;
			mainText = NewText(component2, (Transform)(object)val3, new Vector2(30f, -74f), new Vector2(244f, 38f));
			((Graphic)mainText).color = Ink;
			float num = 128f;
			NewButton(gameObject, (Transform)(object)val3, new Vector2(20f, -130f), new Vector2(num, 38f), "Clear (Del)", 14, ClearKey, new UnityAction(calc.Clear));
			Vector2 pos = new Vector2(156f, -130f);
			Vector2 size = new Vector2(60f, 38f);
			Color[] glass = Glass;
			object obj2 = <>c.<>9__38_1;
			if (obj2 == null)
			{
				UnityAction val4 = delegate
				{
					calc.Press('\b');
				};
				<>c.<>9__38_1 = val4;
				obj2 = (object)val4;
			}
			NewButton(gameObject, (Transform)(object)val3, pos, size, "Back", 14, glass, (UnityAction)obj2);
			Vector2 pos2 = new Vector2(224f, -130f);
			Vector2 size2 = new Vector2(60f, 38f);
			Color[] palette = Operator;
			object obj3 = <>c.<>9__38_2;
			if (obj3 == null)
			{
				UnityAction val5 = delegate
				{
					calc.Press('/');
				};
				<>c.<>9__38_2 = val5;
				obj3 = (object)val5;
			}
			NewButton(gameObject, (Transform)(object)val3, pos2, size2, "/", 20, palette, (UnityAction)obj3);
			for (int num2 = 0; num2 < DigitRows.Length; num2++)
			{
				for (int num3 = 0; num3 < 4; num3++)
				{
					char key = DigitRows[num2][num3];
					NewButton(gameObject, (Transform)(object)val3, new Vector2(20f + (float)num3 * 68f, -130f - (float)(num2 + 1) * 46f), new Vector2(60f, 38f), key.ToString(), 20, (num3 == 3) ? Operator : Glass, (UnityAction)delegate
					{
						calc.Press(key);
					});
				}
			}
			float num4 = -314f;
			Vector2 pos3 = new Vector2(20f, num4);
			Vector2 size3 = new Vector2(num, 38f);
			Color[] glass2 = Glass;
			object obj4 = <>c.<>9__38_3;
			if (obj4 == null)
			{
				UnityAction val6 = delegate
				{
					calc.Press('0');
				};
				<>c.<>9__38_3 = val6;
				obj4 = (object)val6;
			}
			NewButton(gameObject, (Transform)(object)val3, pos3, size3, "0", 20, glass2, (UnityAction)obj4);
			Vector2 pos4 = new Vector2(156f, num4);
			Vector2 size4 = new Vector2(60f, 38f);
			Color[] glass3 = Glass;
			object obj5 = <>c.<>9__38_4;
			if (obj5 == null)
			{
				UnityAction val7 = delegate
				{
					calc.Press('.');
				};
				<>c.<>9__38_4 = val7;
				obj5 = (object)val7;
			}
			NewButton(gameObject, (Transform)(object)val3, pos4, size4, ".", 20, glass3, (UnityAction)obj5);
			NewButton(gameObject, (Transform)(object)val3, new Vector2(224f, num4), new Vector2(60f, 38f), "=", 22, Equals_, new UnityAction(calc.Enter));
			win.SetActive(false);
		}

		private static Text NewText(Text tpl, Transform parent, Vector2 pos, Vector2 size)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			Text obj = Object.Instantiate<Text>(tpl, parent, false);
			StripLocalizers(((Component)obj).gameObject);
			Place(((Graphic)obj).rectTransform, pos, size);
			((Graphic)obj).material = null;
			obj.alignment = (TextAnchor)5;
			obj.horizontalOverflow = (HorizontalWrapMode)1;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		private static void NewButton(GameObject tpl, Transform parent, Vector2 pos, Vector2 size, string label, int fontSize, Color[] palette, UnityAction onClick)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			GameObject obj = Object.Instantiate<GameObject>(tpl, parent, false);
			StripLocalizers(obj);
			obj.SetActive(true);
			Place((RectTransform)obj.transform, pos, size);
			obj.GetComponentInChildren<Text>().text = label;
			Button component = obj.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			((UnityEvent)component.onClick).AddListener(onClick);
			UIButton component2 = obj.GetComponent<UIButton>();
			component2.tips.tipTitle = "";
			component2.tips.tipText = "";
			Style(obj, palette, fontSize);
		}

		private static void Style(GameObject go, Color[] palette, int fontSize)
		{
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_005d: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			Text componentInChildren = go.GetComponentInChildren<Text>();
			Transition[] transitions = go.GetComponent<UIButton>().transitions;
			foreach (Transition val in transitions)
			{
				if (!((Object)(object)val.target == (Object)null))
				{
					bool flag = val.target is Text;
					val.normalColor = (val.disabledColor = (flag ? palette[3] : palette[0]));
					val.mouseoverColor = (flag ? palette[3] : palette[1]);
					val.pressedColor = (flag ? palette[3] : palette[2]);
					val.highlightColorOverride = (flag ? AccentInk : Accent);
					val.alphaOnly = false;
					val.mouseoverSize = (val.pressedSize = (val.highlightSizeMultiplier = 1f));
				}
			}
			go.GetComponent<UIButton>().highlighted = false;
			((Selectable)go.GetComponent<Button>()).transition = (Transition)0;
			Image component = go.GetComponent<Image>();
			((Graphic)component).material = null;
			((Graphic)component).color = palette[0];
			((Graphic)componentInChildren).color = palette[3];
			componentInChildren.fontSize = fontSize;
			componentInChildren.alignment = (TextAnchor)4;
			RectTransform rectTransform = ((Graphic)componentInChildren).rectTransform;
			rectTransform.anchorMin = Vector2.zero;
			rectTransform.anchorMax = Vector2.one;
			rectTransform.pivot = new Vector2(0.5f, 0.5f);
			Vector2 anchoredPosition = (rectTransform.sizeDelta = Vector2.zero);
			rectTransform.anchoredPosition = anchoredPosition;
		}

		private static void Backdrop(Transform panel)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			Image component = ((Component)panel).GetComponent<Image>();
			Image component2 = new GameObject("scrim", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<Image>();
			((Component)component2).transform.SetParent(panel, false);
			((Component)component2).transform.SetAsFirstSibling();
			((Graphic)component2).rectTransform.anchorMin = Vector2.zero;
			((Graphic)component2).rectTransform.anchorMax = Vector2.one;
			RectTransform rectTransform = ((Graphic)component2).rectTransform;
			Vector2 anchoredPosition = (((Graphic)component2).rectTransform.sizeDelta = Vector2.zero);
			rectTransform.anchoredPosition = anchoredPosition;
			component2.sprite = component.sprite;
			component2.type = component.type;
			((Graphic)component2).color = Scrim;
			((Graphic)component2).raycastTarget = false;
		}

		private static Image Card(Transform parent, Vector2 pos, Vector2 size, Color color)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			Image component = new GameObject("card", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<Image>();
			((Component)component).transform.SetParent(parent, false);
			Place(((Graphic)component).rectTransform, pos, size);
			((Graphic)component).color = color;
			((Graphic)component).raycastTarget = false;
			return component;
		}

		private static void Place(RectTransform rt, Vector2 pos, Vector2 size)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			rt.pivot = val;
			Vector2 anchorMin = (rt.anchorMax = val);
			rt.anchorMin = anchorMin;
			rt.anchoredPosition = pos;
			rt.sizeDelta = size;
			((Transform)rt).localScale = Vector3.one;
		}

		private static void StripLocalizers(GameObject go)
		{
			Localizer[] componentsInChildren = go.GetComponentsInChildren<Localizer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
		}
	}
	public static class Patches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(VFInput), "UpdateGameStates")]
		private static void BlockGame()
		{
			if ((Object)(object)UIRoot.instance == (Object)null)
			{
				return;
			}
			Plugin.OtherFieldFocused = VFInput.inputing;
			if (Plugin.Blocking)
			{
				VFInput.inputing = true;
				if (!Plugin.OtherFieldFocused && (Object)(object)EventSystem.current.currentSelectedGameObject != (Object)null)
				{
					EventSystem.current.SetSelectedGameObject((GameObject)null);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Input), "GetKey", new Type[] { typeof(KeyCode) })]
		[HarmonyPatch(typeof(Input), "GetKeyDown", new Type[] { typeof(KeyCode) })]
		[HarmonyPatch(typeof(Input), "GetKeyUp", new Type[] { typeof(KeyCode) })]
		private static bool FilterKey(KeyCode key, ref bool __result)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Blocking || Plugin.PassThrough || !Plugin.IsBlocked(key))
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
}