Decompiled source of SupplyDrop v1.0.0

SupplyDrop.dll

Decompiled a day 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 SupplyDrop
{
	public static class Amount
	{
		public const int Max = 999999999;

		public static int Parse(string text)
		{
			if (!int.TryParse(text, NumberStyles.None, CultureInfo.InvariantCulture, out var result) || result <= 0)
			{
				return 0;
			}
			return Math.Min(result, 999999999);
		}

		public static string Format(long n)
		{
			return n.ToString("N0", CultureInfo.InvariantCulture);
		}
	}
	[BepInPlugin("bug.dsp.supplydrop", "SupplyDrop", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__Hide;

			public static UnityAction <1>__Pick;

			public static UnityAction <2>__Give;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__37_0;

			internal void <Build>b__37_0()
			{
				if (selected == null)
				{
					Status("Choose an item first.", error: true);
				}
				else
				{
					amountField.text = Math.Max(1, selected.StackSize).ToString(CultureInfo.InvariantCulture);
				}
			}

			internal void <.cctor>b__46_0(ItemProto p)
			{
				if (p != null)
				{
					Select(p);
				}
			}
		}

		private const int SandId = 1099;

		private const float Width = 340f;

		private const float Height = 292f;

		private const float Left = 20f;

		private const float Inner = 300f;

		private static readonly int[] Presets = new int[4] { 1, 10, 100, 1000 };

		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 Bad = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)150, (byte)130, byte.MaxValue));

		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[] Give_ = (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 ConfigEntry<KeyboardShortcut> hotkey;

		private static GameObject win;

		private static RectTransform root;

		private static Image icon;

		private static Text nameText;

		private static Text infoText;

		private static Text statusText;

		private static InputField amountField;

		private static ItemProto selected;

		private static readonly Action<ItemProto> OnPicked = delegate(ItemProto p)
		{
			if (p != null)
			{
				Select(p);
			}
		};

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

		private void Awake()
		{
			//IL_0028: 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)
			hotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "Hotkey", new KeyboardShortcut((KeyCode)103, (KeyCode[])(object)new KeyCode[2]
			{
				(KeyCode)306,
				(KeyCode)304
			}), "Opens and closes the SupplyDrop window.");
			new Harmony("bug.dsp.supplydrop").PatchAll(typeof(Patches));
		}

		private void Update()
		{
			//IL_0086: 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)
			if (!GameMain.isRunning || DSPGame.IsMenuDemo || GameMain.isPaused || !((ManualBehaviour)UIRoot.instance.uiGame).active)
			{
				if (Open)
				{
					Hide();
				}
				return;
			}
			GameObject val = (((Object)(object)EventSystem.current == (Object)null) ? null : EventSystem.current.currentSelectedGameObject);
			if ((Object)(object)val != (Object)null && (Object)(object)val.GetComponent<InputField>() != (Object)null)
			{
				InputField obj = amountField;
				if ((Object)(object)val != (Object)(object)((obj != null) ? ((Component)obj).gameObject : null))
				{
					goto IL_00a8;
				}
			}
			KeyboardShortcut value = hotkey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				if (Open)
				{
					Hide();
				}
				else
				{
					Show();
				}
			}
			goto IL_00a8;
			IL_00a8:
			if (Open)
			{
				ShowState();
			}
		}

		private static void Show()
		{
			if ((Object)(object)win == (Object)null)
			{
				Build();
			}
			win.SetActive(true);
			win.transform.SetAsLastSibling();
			statusText.text = "";
			if (selected == null)
			{
				Pick();
			}
		}

		public static void Hide()
		{
			win.SetActive(false);
			if (UIItemPicker.isOpened && UIRoot.instance.uiGame.itemPicker.onReturn == OnPicked)
			{
				UIItemPicker.Close();
			}
		}

		private static void Pick()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_00b3: 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)
			if (!UIItemPicker.isOpened)
			{
				UIItemPicker.showAll = false;
				UIItemPicker.Popup(root.anchoredPosition, OnPicked);
				if (UIItemPicker.isOpened)
				{
					RectTransform pickerTrans = UIRoot.instance.uiGame.itemPicker.pickerTrans;
					Vector3[] array = (Vector3[])(object)new Vector3[4];
					Vector3[] array2 = (Vector3[])(object)new Vector3[4];
					pickerTrans.GetWorldCorners(array);
					root.GetWorldCorners(array2);
					float num = 10f * ((Transform)root).lossyScale.x;
					((Transform)pickerTrans).position = ((Transform)pickerTrans).position + new Vector3(array2[1].x - num - array[2].x, array2[1].y - array[1].y, 0f);
				}
			}
		}

		private static void Select(ItemProto proto)
		{
			selected = proto;
			icon.sprite = proto.iconSprite;
			((Behaviour)icon).enabled = true;
			nameText.text = ((Proto)proto).name;
			statusText.text = "";
		}

		private static void ShowState()
		{
			infoText.text = ((selected == null) ? "Click the slot to choose an item" : ("In inventory: " + Amount.Format(Count(((Proto)selected).ID))));
		}

		private static long Count(int id)
		{
			if (id != 1099)
			{
				return GameMain.mainPlayer.package.GetItemCount(id);
			}
			return GameMain.mainPlayer.sandCount;
		}

		private static void Status(string text, bool error)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			statusText.text = text;
			((Graphic)statusText).color = (error ? Bad : Soft);
		}

		private static void Give()
		{
			if (selected == null)
			{
				Status("Choose an item first.", error: true);
				return;
			}
			int num = Amount.Parse(amountField.text);
			if (num == 0)
			{
				Status("Enter an amount of 1 or more.", error: true);
				return;
			}
			if (!GameMain.history.ItemUnlocked(((Proto)selected).ID))
			{
				Status(((Proto)selected).name + " is not unlocked yet.", error: true);
				return;
			}
			Player mainPlayer = GameMain.mainPlayer;
			int num2;
			if (((Proto)selected).ID == 1099)
			{
				mainPlayer.SetSandCount(mainPlayer.sandCount + num, (ESandSource)3);
				num2 = num;
			}
			else
			{
				int num3 = default(int);
				num2 = mainPlayer.package.AddItemStacked(((Proto)selected).ID, num, 0, ref num3);
				if (num2 > 0)
				{
					mainPlayer.NotifyPackageAddItem(((Proto)selected).ID, num2, 0);
					UIItemup.Up(((Proto)selected).ID, num2);
				}
			}
			if (num2 == num)
			{
				Status("Added " + Amount.Format(num2) + " × " + ((Proto)selected).name + ".", error: false);
			}
			else if (num2 == 0)
			{
				Status("Inventory is full.", error: true);
			}
			else
			{
				Status("Inventory full: added " + Amount.Format(num2) + " of " + Amount.Format(num) + ".", error: true);
			}
		}

		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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Expected O, but got Unknown
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Expected O, but got Unknown
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: 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_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Expected O, but got Unknown
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Expected O, but got Unknown
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fc: Expected O, but got Unknown
			//IL_052a: 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_057c: Unknown result type (might be due to invalid IL or missing references)
			//IL_058b: Unknown result type (might be due to invalid IL or missing references)
			//IL_055b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_0566: Expected O, but got Unknown
			//IL_05cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b7: 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 = "SupplyDrop";
			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);
				}
			}
			RectTransform val2 = (RectTransform)win.transform.Find("panel-bg/btn-box");
			Object.DestroyImmediate((Object)(object)((Component)((Transform)val2).Find("menu-wnd-btn")).gameObject);
			val2.sizeDelta = new Vector2(32f, val2.sizeDelta.y);
			val2.anchoredPosition += new Vector2(16f, 0f);
			((RectTransform)((Transform)val2).Find("close-wnd-btn")).anchoredPosition = Vector2.zero;
			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 = <>O.<0>__Hide;
			if (obj == null)
			{
				UnityAction val3 = Hide;
				<>O.<0>__Hide = val3;
				obj = (object)val3;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			Text component4 = ((Component)win.transform.Find("panel-bg/title-text")).GetComponent<Text>();
			component4.text = "Supply Drop";
			((Graphic)component4).rectTransform.sizeDelta = new Vector2(200f, ((Graphic)component4).rectTransform.sizeDelta.y);
			root = (RectTransform)win.transform;
			root.anchoredPosition = new Vector2(440f, 280f);
			root.sizeDelta = new Vector2(340f, 292f);
			RectTransform parent = root;
			Vector2 pos = new Vector2(20f, -50f);
			Vector2 size = new Vector2(64f, 64f);
			Color[] glass = Glass;
			object obj2 = <>O.<1>__Pick;
			if (obj2 == null)
			{
				UnityAction val4 = Pick;
				<>O.<1>__Pick = val4;
				obj2 = (object)val4;
			}
			GameObject val5 = NewButton(gameObject, (Transform)(object)parent, pos, size, "", 14, glass, (UnityAction)obj2);
			icon = new GameObject("icon", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<Image>();
			((Component)icon).transform.SetParent(val5.transform, false);
			RectTransform rectTransform = ((Graphic)icon).rectTransform;
			RectTransform rectTransform2 = ((Graphic)icon).rectTransform;
			RectTransform rectTransform3 = ((Graphic)icon).rectTransform;
			Vector2 val6 = default(Vector2);
			((Vector2)(ref val6))..ctor(0.5f, 0.5f);
			rectTransform3.pivot = val6;
			Vector2 anchorMin = (rectTransform2.anchorMax = val6);
			rectTransform.anchorMin = anchorMin;
			((Graphic)icon).rectTransform.sizeDelta = new Vector2(52f, 52f);
			((Graphic)icon).raycastTarget = false;
			((Behaviour)icon).enabled = false;
			nameText = NewText(component2, (Transform)(object)root, new Vector2(96f, -56f), new Vector2(224f, 24f), (TextAnchor)3);
			((Graphic)nameText).color = Ink;
			nameText.text = "No item";
			infoText = NewText(component, (Transform)(object)root, new Vector2(96f, -84f), new Vector2(224f, 20f), (TextAnchor)3);
			((Graphic)infoText).color = Soft;
			Text obj3 = NewText(component, (Transform)(object)root, new Vector2(20f, -128f), new Vector2(76f, 32f), (TextAnchor)3);
			obj3.text = "Amount";
			((Graphic)obj3).color = Soft;
			amountField = NewField(component2, (Transform)(object)root, new Vector2(96f, -128f), new Vector2(224f, 32f));
			float num = 306f / (float)(Presets.Length + 1);
			float num2 = num - 6f;
			for (int i = 0; i < Presets.Length; i++)
			{
				int n = Presets[i];
				NewButton(gameObject, (Transform)(object)root, new Vector2(20f + (float)i * num, -170f), new Vector2(num2, 32f), Amount.Format(n), 15, Glass, (UnityAction)delegate
				{
					amountField.text = n.ToString(CultureInfo.InvariantCulture);
				});
			}
			RectTransform parent2 = root;
			Vector2 pos2 = new Vector2(20f + (float)Presets.Length * num, -170f);
			Vector2 size2 = new Vector2(num2, 32f);
			Color[] glass2 = Glass;
			object obj4 = <>c.<>9__37_0;
			if (obj4 == null)
			{
				UnityAction val8 = delegate
				{
					if (selected == null)
					{
						Status("Choose an item first.", error: true);
					}
					else
					{
						amountField.text = Math.Max(1, selected.StackSize).ToString(CultureInfo.InvariantCulture);
					}
				};
				<>c.<>9__37_0 = val8;
				obj4 = (object)val8;
			}
			NewButton(gameObject, (Transform)(object)parent2, pos2, size2, "Stack", 14, glass2, (UnityAction)obj4);
			RectTransform parent3 = root;
			Vector2 pos3 = new Vector2(20f, -214f);
			Vector2 size3 = new Vector2(300f, 38f);
			Color[] give_ = Give_;
			object obj5 = <>O.<2>__Give;
			if (obj5 == null)
			{
				UnityAction val9 = Give;
				<>O.<2>__Give = val9;
				obj5 = (object)val9;
			}
			NewButton(gameObject, (Transform)(object)parent3, pos3, size3, "Add to inventory", 16, give_, (UnityAction)obj5);
			statusText = NewText(component, (Transform)(object)root, new Vector2(20f, -258f), new Vector2(300f, 20f), (TextAnchor)3);
			win.SetActive(false);
		}

		private static Text NewText(Text tpl, Transform parent, Vector2 pos, Vector2 size, TextAnchor alignment)
		{
			//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)
			//IL_0028: 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 = alignment;
			obj.horizontalOverflow = (HorizontalWrapMode)1;
			((Graphic)obj).raycastTarget = false;
			obj.text = "";
			return obj;
		}

		private static InputField NewField(Text tpl, Transform parent, Vector2 pos, Vector2 size)
		{
			//IL_0025: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			Image component = new GameObject("amount", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<Image>();
			((Component)component).transform.SetParent(parent, false);
			Place(((Graphic)component).rectTransform, pos, size);
			((Graphic)component).color = Well;
			Text val = NewText(tpl, ((Component)component).transform, new Vector2(10f, 0f), new Vector2(size.x - 20f, size.y), (TextAnchor)3);
			val.horizontalOverflow = (HorizontalWrapMode)0;
			val.supportRichText = false;
			((Graphic)val).color = Ink;
			InputField obj = ((Component)component).gameObject.AddComponent<InputField>();
			obj.textComponent = val;
			((Selectable)obj).targetGraphic = (Graphic)(object)component;
			obj.contentType = (ContentType)2;
			obj.characterLimit = 9;
			obj.caretColor = Ink;
			obj.selectionColor = Color32.op_Implicit(new Color32((byte)253, (byte)150, (byte)94, (byte)110));
			obj.text = "1";
			return obj;
		}

		private static GameObject 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);
			return obj;
		}

		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 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 Escape()
		{
			if (VFInput.escape && Plugin.Open && !UIItemPicker.isOpened)
			{
				VFInput.escape = false;
				Plugin.Hide();
			}
		}
	}
}