Decompiled source of BUG Reclamation v1.0.1

BUG_Reclamation.dll

Decompiled a day ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CommonAPI;
using CommonAPI.Systems;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 TrashStation
{
	internal sealed class BurnPanel
	{
		private readonly bool besideWindow;

		private Vector2 size;

		private const int RowHeight = 20;

		private const int Pad = 8;

		private const int Bar = 6;

		private const int Top = 50;

		private static readonly Color Back = new Color(0f, 0.17254902f, 11f / 51f, 0.96f);

		private static readonly Color Shade = new Color(0f, 0f, 0f, 0.3f);

		private static readonly Color Line = new Color(0.654902f, 0.9137255f, 1f, 1f);

		private static readonly Color Word = new Color(1f, 1f, 1f, 0.8f);

		private const float BgRight = 15f;

		private const float BgTop = 30f;

		private const float BgBottom = 13f;

		private const float BgLeft = 15f;

		private RectTransform window;

		private RectTransform button;

		private RectTransform panel;

		private RectTransform content;

		private Font font;

		private Text header;

		private readonly List<Image> icons = new List<Image>();

		private readonly List<Text> names = new List<Text>();

		private readonly List<Text> counts = new List<Text>();

		private readonly List<Text> points = new List<Text>();

		private bool open;

		private long shown = -1L;

		private float nextRefresh;

		private static double Efficiency => Plugin.PowerPerPoint / 100000.0;

		internal BurnPanel(bool besideWindow, Vector2 size)
		{
			//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)
			this.besideWindow = besideWindow;
			this.size = size;
			open = !besideWindow;
		}

		internal void Size(Vector2 value)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (value != size)
			{
				size = value;
				window = null;
			}
		}

		internal void Show(RectTransform owner, Font font, long key, Vector3 topLeft, Vector3 listAt = default(Vector3))
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)window != (Object)(object)owner || (Object)(object)button == (Object)null)
			{
				Build(owner, font);
			}
			if (!((Component)button).gameObject.activeSelf)
			{
				((Component)button).gameObject.SetActive(true);
			}
			((Transform)button).position = topLeft;
			((Component)panel).gameObject.SetActive(open);
			if (open)
			{
				if (key != shown || Time.unscaledTime >= nextRefresh)
				{
					Fill(key);
				}
				if (besideWindow)
				{
					Transform obj = ((Transform)owner).Find("panel-bg");
					RectTransform val = (RectTransform)(((object)((obj is RectTransform) ? obj : null)) ?? ((object)owner));
					Rect rect = val.rect;
					((Transform)panel).position = ((Transform)val).TransformPoint(new Vector3(((Rect)(ref rect)).xMax - 15f, ((Rect)(ref rect)).yMax - 30f, 0f));
					panel.sizeDelta = new Vector2(size.x, ((Rect)(ref rect)).height - 30f - 13f);
				}
				else
				{
					((Transform)panel).position = listAt;
				}
			}
		}

		internal void Hide()
		{
			if ((Object)(object)button != (Object)null && ((Component)button).gameObject.activeSelf)
			{
				((Component)button).gameObject.SetActive(false);
			}
			if ((Object)(object)panel != (Object)null && ((Component)panel).gameObject.activeSelf)
			{
				((Component)panel).gameObject.SetActive(false);
			}
		}

		private void Build(RectTransform owner, Font font)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: 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_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: 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_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: 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_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)button != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)button).gameObject);
			}
			if ((Object)(object)panel != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)panel).gameObject);
			}
			icons.Clear();
			names.Clear();
			counts.Clear();
			points.Clear();
			window = owner;
			this.font = font;
			shown = -1L;
			UnityAction onClick = (UnityAction)delegate
			{
				open = !open;
				shown = -1L;
			};
			button = TextButton((Transform)(object)owner, font, Lang.T("Burned"), onClick);
			Transform val = (besideWindow ? ((Transform)owner).Find("panel-bg") : null);
			panel = Box("trash-burned-list", (Transform)(object)owner, size, ((Object)(object)val != (Object)null) ? Color.clear : (besideWindow ? Back : Shade));
			if ((Object)(object)val != (Object)null)
			{
				RectTransform val2 = (RectTransform)Object.Instantiate<GameObject>(((Component)val).gameObject, (Transform)(object)panel, false).transform;
				((Object)val2).name = "glass";
				for (int num = ((Transform)val2).childCount - 1; num >= 0; num--)
				{
					Transform child = ((Transform)val2).GetChild(num);
					if ((Object)(object)((Component)child).GetComponentInChildren<Text>(true) != (Object)null || (Object)(object)((Component)child).GetComponentInChildren<Button>(true) != (Object)null || (Object)(object)((Component)child).GetComponentInChildren<UIButton>(true) != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)((Component)child).gameObject);
					}
				}
				val2.anchorMin = Vector2.zero;
				val2.anchorMax = Vector2.one;
				val2.pivot = new Vector2(0.5f, 0.5f);
				val2.offsetMin = new Vector2(-15f, -13f);
				val2.offsetMax = new Vector2(15f, 30f);
				((Transform)val2).localScale = new Vector3(-1f, 1f, 1f);
				((Transform)val2).SetAsFirstSibling();
			}
			float num2 = size.x - 16f - 6f - 4f;
			Title(font, "Item", (TextAnchor)3, 32f, 100f);
			Title(font, "Count", (TextAnchor)5, 8f + num2 - 130f, 56f);
			Title(font, besideWindow ? "Energy" : "Points", (TextAnchor)5, 8f + num2 - 70f, 70f);
			header = Label((Transform)(object)panel, font, 14, (TextAnchor)0, Line);
			At(((Graphic)header).rectTransform, 8f, -8f, size.x - 16f, 18f);
			RectTransform component = new GameObject("view", new Type[2]
			{
				typeof(RectTransform),
				typeof(RectMask2D)
			}).GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)panel, false);
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = new Vector2(8f, 8f);
			component.offsetMax = new Vector2(-18f, -50f);
			content = new GameObject("content", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Transform)content).SetParent((Transform)(object)component, false);
			content.anchorMin = new Vector2(0f, 1f);
			content.anchorMax = Vector2.one;
			content.pivot = new Vector2(0f, 1f);
			content.sizeDelta = Vector2.zero;
			RectTransform val3 = Box("bar", (Transform)(object)panel, Vector2.zero, new Color(1f, 1f, 1f, 0.08f));
			val3.anchorMin = new Vector2(1f, 0f);
			val3.anchorMax = Vector2.one;
			val3.pivot = new Vector2(1f, 1f);
			val3.offsetMin = new Vector2(-14f, 8f);
			val3.offsetMax = new Vector2(-8f, -50f);
			RectTransform val4 = Box("handle", (Transform)(object)val3, Vector2.zero, new Color(Line.r, Line.g, Line.b, 0.6f));
			Vector2 offsetMin = (val4.offsetMax = Vector2.zero);
			val4.offsetMin = offsetMin;
			Scrollbar val5 = ((Component)val3).gameObject.AddComponent<Scrollbar>();
			val5.handleRect = val4;
			((Selectable)val5).targetGraphic = (Graphic)(object)((Component)val4).GetComponent<Image>();
			val5.direction = (Direction)2;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)val5).navigation = navigation;
			((Component)panel).gameObject.AddComponent<UIScrollZone>();
			ScrollRect obj = ((Component)panel).gameObject.AddComponent<ScrollRect>();
			obj.viewport = component;
			obj.content = content;
			obj.horizontal = false;
			obj.movementType = (MovementType)2;
			obj.scrollSensitivity = 40f;
			obj.verticalScrollbar = val5;
			obj.verticalScrollbarVisibility = (ScrollbarVisibility)1;
			((Component)panel).gameObject.SetActive(false);
		}

		private void Title(Font font, string english, TextAnchor align, float x, float width)
		{
			//IL_0009: 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)
			Text obj = Label((Transform)(object)panel, font, 12, align, new Color(1f, 1f, 1f, 0.55f));
			obj.text = Lang.T(english);
			At(((Graphic)obj).rectTransform, x, -30f, width, 18f);
		}

		private void AddRow()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			float y = -icons.Count * 20;
			float num = size.x - 16f - 6f - 4f;
			Image component = new GameObject("icon", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<Image>();
			((Component)component).transform.SetParent((Transform)(object)content, false);
			((Graphic)component).raycastTarget = false;
			At(((Graphic)component).rectTransform, 0f, y, 18f, 18f);
			icons.Add(component);
			Text val = Label((Transform)(object)content, font, 13, (TextAnchor)3, Color.white);
			At(((Graphic)val).rectTransform, 24f, y, num - 130f - 20f - 8f, 20f);
			names.Add(val);
			Text val2 = Label((Transform)(object)content, font, 13, (TextAnchor)5, Color.white);
			At(((Graphic)val2).rectTransform, num - 130f, y, 56f, 20f);
			counts.Add(val2);
			Text val3 = Label((Transform)(object)content, font, 13, (TextAnchor)5, Line);
			At(((Graphic)val3).rectTransform, num - 70f, y, 70f, 20f);
			points.Add(val3);
		}

		private void Fill(long key)
		{
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			shown = key;
			nextRefresh = Time.unscaledTime + 0.5f;
			List<KeyValuePair<int, Ledger.Line>> list = Ledger.Read(key);
			long num = 0L;
			long num2 = 0L;
			foreach (KeyValuePair<int, Ledger.Line> item in list)
			{
				num += item.Value.Points;
				num2 += item.Value.Count;
			}
			header.text = ((list.Count == 0) ? Lang.T("Nothing burned yet") : (besideWindow ? Lang.F("Burned: {0} items = {1}", Value.Short(num2), Value.Energy((double)num * Efficiency)) : Lang.F("Burned: {0} items, {1} points", Value.Short(num2), Value.Short(num))));
			while (icons.Count < list.Count)
			{
				AddRow();
			}
			for (int i = 0; i < icons.Count; i++)
			{
				bool flag = i < list.Count;
				((Component)icons[i]).gameObject.SetActive(flag);
				((Component)names[i]).gameObject.SetActive(flag);
				((Component)counts[i]).gameObject.SetActive(flag);
				((Component)points[i]).gameObject.SetActive(flag);
				if (flag)
				{
					ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(list[i].Key);
					icons[i].sprite = ((val != null) ? val.iconSprite : null);
					((Behaviour)icons[i]).enabled = (Object)(object)icons[i].sprite != (Object)null;
					names[i].text = ((val != null) ? ((Proto)val).name : ("#" + list[i].Key));
					counts[i].text = "×" + Value.Short(list[i].Value.Count);
					points[i].text = (besideWindow ? Value.Energy((double)list[i].Value.Points * Efficiency) : Value.Short(list[i].Value.Points));
				}
			}
			content.sizeDelta = new Vector2(0f, (float)(list.Count * 20));
		}

		private static RectTransform TextButton(Transform parent, Font font, string text, UnityAction onClick)
		{
			//IL_0005: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			Text val = Label(parent, font, 15, (TextAnchor)3, Color.white);
			((Object)val).name = "trash-burned-button";
			val.text = text;
			((Graphic)val).raycastTarget = true;
			RectTransform rectTransform = ((Graphic)val).rectTransform;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			rectTransform.anchorMax = val2;
			rectTransform.anchorMin = val2;
			rectTransform.pivot = new Vector2(0f, 1f);
			rectTransform.sizeDelta = new Vector2(val.preferredWidth + 8f, 24f);
			Button obj = ((Component)val).gameObject.AddComponent<Button>();
			((Selectable)obj).targetGraphic = (Graphic)(object)val;
			ColorBlock colors = ((Selectable)obj).colors;
			Color normalColor = (((ColorBlock)(ref colors)).selectedColor = Word);
			((ColorBlock)(ref colors)).normalColor = normalColor;
			((ColorBlock)(ref colors)).highlightedColor = Line;
			((ColorBlock)(ref colors)).pressedColor = new Color(1f, 1f, 1f, 0.55f);
			((ColorBlock)(ref colors)).fadeDuration = 0.08f;
			((Selectable)obj).colors = colors;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)obj).navigation = navigation;
			((UnityEvent)obj.onClick).AddListener(onClick);
			return rectTransform;
		}

		private static RectTransform Box(string name, Transform parent, Vector2 size, Color color)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_002d: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_006f: 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_0082: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent(parent, false);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			val2.anchorMax = val3;
			val2.anchorMin = val3;
			val2.pivot = new Vector2(0f, 1f);
			val2.sizeDelta = size;
			((Graphic)val.GetComponent<Image>()).color = color;
			return val2;
		}

		internal static Text Label(Transform parent, Font font, int size, TextAnchor align, Color color)
		{
			//IL_0025: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			Text component = new GameObject("text", new Type[2]
			{
				typeof(RectTransform),
				typeof(Text)
			}).GetComponent<Text>();
			((Component)component).transform.SetParent(parent, false);
			component.font = font;
			component.fontSize = size;
			component.alignment = align;
			((Graphic)component).color = color;
			((Graphic)component).raycastTarget = false;
			component.horizontalOverflow = (HorizontalWrapMode)1;
			component.verticalOverflow = (VerticalWrapMode)1;
			return component;
		}

		private static void At(RectTransform r, float x, float y, float w, float h)
		{
			//IL_0013: 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_002a: 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)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			r.anchorMax = val;
			r.anchorMin = val;
			r.pivot = new Vector2(0f, 1f);
			r.anchoredPosition = new Vector2(x, y);
			r.sizeDelta = new Vector2(w, h);
		}
	}
	internal static class Icons
	{
		internal static void Apply(ItemProto building, RecipeProto recipe, string file)
		{
			Sprite val = Load(file);
			if ((Object)(object)val == (Object)null)
			{
				throw new FileNotFoundException("no icon", file);
			}
			Traverse.Create((object)building).Field("_iconSprite").SetValue((object)val);
			Traverse.Create((object)recipe).Field("_iconSprite").SetValue((object)val);
		}

		internal static void Apply(TechProto tech, ItemProto like)
		{
			Traverse.Create((object)tech).Field("_iconSprite").SetValue((object)like.iconSprite);
		}

		private static Sprite Load(string path)
		{
			//IL_000e: 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)
			//IL_0020: Expected O, but got Unknown
			//IL_0050: 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)
			if (!File.Exists(path))
			{
				return null;
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true)
			{
				name = Path.GetFileNameWithoutExtension(path)
			};
			if (!ImageConversion.LoadImage(val, File.ReadAllBytes(path)))
			{
				return null;
			}
			((Texture)val).wrapMode = (TextureWrapMode)1;
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}
	}
	public enum Language
	{
		English,
		Chinese,
		Turkish
	}
	public static class Lang
	{
		public static Language Current = Language.English;

		private static readonly Dictionary<string, string[]> texts = new Dictionary<string, string[]>
		{
			["Trash Converter"] = new string[2] { "垃圾转换器", "Çöp Dönüştürücü" },
			["Burns any item that sorters bring, ammunition and buildings included, and turns its points into the Dark Fog item its recipe makes. Every item is worth points by its raw materials, from the simplest to the rarest; the points gather in the converter and each time they reach the recipe's price one item is made. The items it makes are never taken in."] = new string[2] { "焚烧分拣器送入的任何物品(包括弹药和建筑),并将其点数转换为配方所产出的黑雾物品。每种物品按其原材料拥有点数,从最普通到最稀有;点数在转换器中累积,每达到配方价格便产出一个物品。它产出的物品永远不会被接收。", "Sıralayıcıların getirdiği her eşyayı, mermi ve binalar dahil, yakar ve puanını tarifinin ürettiği Kara Sis eşyasına çevirir. Her eşyanın ham maddesine göre, en basitten en nadire, bir puanı vardır; puanlar dönüştürücüde birikir ve tarifin fiyatına her ulaştığında bir eşya üretilir. Ürettiği eşyaları asla kabul etmez." },
			["Incinerator"] = new string[2] { "焚化炉", "Yakma Fırını" },
			["Burns any item that sorters bring, ammunition and buildings included, for power. Fuels burn as they do in a power plant; anything else gives energy by its rarity, little for simple items, and the rarest also burn at a higher power. The items the trash converter makes and ocean liquids are never taken in."] = new string[2] { "焚烧分拣器送入的任何物品(包括弹药和建筑)来发电。燃料按其在发电厂中的方式燃烧;其他物品按稀有度提供能量,普通物品很少,最稀有的物品还以更高的功率燃烧。垃圾转换器产出的物品和海洋液体永远不会被接收。", "Sıralayıcıların getirdiği her eşyayı, mermi ve binalar dahil, enerji için yakar. Yakıtlar bir santraldeki gibi yanar; diğer her şey nadirliğine göre enerji verir, basit eşyalar az, en nadirleri ayrıca daha yüksek güçte yanar. Çöp dönüştürücünün ürettiği eşyaları ve okyanus sıvılarını asla kabul etmez." },
			["Points"] = new string[2] { "点数", "Puan" },
			["Points of burned items, waiting inside a trash converter."] = new string[2] { "被焚烧物品的点数,存放在垃圾转换器中。", "Yakılan eşyaların puanı; bir çöp dönüştürücüde bekler." },
			["Heat"] = new string[2] { "热量", "Isı" },
			["Heat of burned items, waiting inside an incinerator: each is 100 kJ of fuel. Only an incinerator burns it."] = new string[2] { "被焚烧物品的热量,存放在焚化炉中:每份为 100 kJ 燃料。只有焚化炉能燃烧它。", "Yakılan eşyaların ısısı; bir yakma fırınında bekler: her biri 100 kJ yakıttır. Yalnızca yakma fırını yakar." },
			["Reclamation"] = new string[2] { "回收", "Geri Kazanım" },
			["Buildings that burn any item for points: a trash converter that turns them into Dark Fog items, and an incinerator that turns them into power."] = new string[2] { "将任何物品焚烧为点数的建筑:把点数转换为黑雾物品的垃圾转换器,以及把点数转化为电力的焚化炉。", "Her eşyayı puana yakan binalar: puanı Kara Sis eşyalarına çeviren çöp dönüştürücü ve enerjiye çeviren yakma fırını." },
			["Energy"] = new string[2] { "能量", "Enerji" },
			["Trash points: {0} ({1} of power in an incinerator)"] = new string[2] { "垃圾点数:{0}(在焚化炉中发电 {1})", "Çöp puanı: {0} (yakma fırınında {1} elektrik)" },
			["{0} to go"] = new string[2] { "还差 {0}", "{0} kaldı" },
			["Burned"] = new string[2] { "已焚烧", "Yakılanlar" },
			["Item"] = new string[2] { "物品", "Eşya" },
			["Count"] = new string[2] { "数量", "Adet" },
			["This item cannot be burned"] = new string[2] { "该物品无法焚烧", "Bu eşya yakılamaz" },
			["Stock {0} ≈ {1}"] = new string[2] { "库存 {0} ≈ {1}", "Stok {0} ≈ {1}" },
			["{0} s"] = new string[2] { "{0} 秒", "{0} sn" },
			["{0} min"] = new string[2] { "{0} 分", "{0} dk" },
			["{0} h"] = new string[2] { "{0} 时", "{0} sa" },
			["The building is full"] = new string[2] { "建筑已满", "Bina dolu" },
			["Nothing burned yet"] = new string[2] { "尚未焚烧任何物品", "Henüz bir şey yakılmadı" },
			["Burned: {0} items = {1}"] = new string[2] { "已焚烧:{0} 个物品 = {1}", "Yakılan: {0} eşya = {1}" },
			["Burned: {0} items, {1} points"] = new string[2] { "已焚烧:{0} 个物品,{1} 点", "Yakılan: {0} eşya, {1} puan" }
		};

		public static IEnumerable<KeyValuePair<string, string[]>> All => texts;

		public static string T(string english)
		{
			if (Current == Language.English || !texts.TryGetValue(english, out var value))
			{
				return english;
			}
			return value[(Current != Language.Chinese) ? 1u : 0u];
		}

		public static string F(string english, params object[] args)
		{
			return string.Format(CultureInfo.InvariantCulture, T(english), args);
		}
	}
	public static class Ledger
	{
		public sealed class Line
		{
			public long Count;

			public long Points;
		}

		private static readonly ConcurrentDictionary<long, Dictionary<int, Line>> books = new ConcurrentDictionary<long, Dictionary<int, Line>>();

		public static void Add(long building, int item, int count, long each)
		{
			Dictionary<int, Line> orAdd = books.GetOrAdd(building, (long _) => new Dictionary<int, Line>());
			lock (orAdd)
			{
				if (!orAdd.TryGetValue(item, out var value))
				{
					value = (orAdd[item] = new Line());
				}
				value.Count += count;
				value.Points += each * count;
			}
		}

		public static List<KeyValuePair<int, Line>> Read(long building)
		{
			List<KeyValuePair<int, Line>> list = new List<KeyValuePair<int, Line>>();
			if (!books.TryGetValue(building, out var value))
			{
				return list;
			}
			lock (value)
			{
				foreach (KeyValuePair<int, Line> item in value)
				{
					list.Add(new KeyValuePair<int, Line>(item.Key, new Line
					{
						Count = item.Value.Count,
						Points = item.Value.Points
					}));
				}
			}
			list.Sort((KeyValuePair<int, Line> a, KeyValuePair<int, Line> b) => b.Value.Points.CompareTo(a.Value.Points));
			return list;
		}

		public static void Remove(long building)
		{
			books.TryRemove(building, out var _);
		}

		public static void Clear()
		{
			books.Clear();
		}
	}
	internal static class Model
	{
		private const int Grid = 4;

		private const int Swatch = 8;

		private const int Fps = 30;

		private const float FloorShade = 0.55f;

		internal static void Apply(PrefabDesc desc, string file, Material template)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: 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_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: 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_01f7: Expected O, but got Unknown
			using BinaryReader binaryReader = new BinaryReader(File.OpenRead(file));
			if (binaryReader.ReadInt32() != 843928404)
			{
				throw new InvalidDataException(file + " is not a model file");
			}
			int num = binaryReader.ReadInt32();
			int num2 = binaryReader.ReadInt32();
			int num3 = binaryReader.ReadInt32();
			int num4 = binaryReader.ReadInt32();
			int num5 = binaryReader.ReadInt32();
			int num6 = binaryReader.ReadInt32();
			float[] palette = Floats(binaryReader, num6 * 8);
			float[] array = Floats(binaryReader, num * 2);
			int[] array2 = new int[num4];
			for (int i = 0; i < num4; i++)
			{
				array2[i] = binaryReader.ReadInt32();
			}
			float[] sourceArray = Floats(binaryReader, num2 * 9);
			float[] sourceArray2 = Floats(binaryReader, num3 * (num - num2) * 9);
			VertaBuffer val = new VertaBuffer();
			val.Expand((VertType)9, num, num3);
			for (int j = 0; j < num3; j++)
			{
				Array.Copy(sourceArray, 0, val.data, j * num * 9, num2 * 9);
				Array.Copy(sourceArray2, j * (num - num2) * 9, val.data, j * num * 9 + num2 * 9, (num - num2) * 9);
			}
			Vector3[] array3 = (Vector3[])(object)new Vector3[num];
			Vector3[] array4 = (Vector3[])(object)new Vector3[num];
			Vector4[] array5 = (Vector4[])(object)new Vector4[num];
			Vector2[] array6 = (Vector2[])(object)new Vector2[num];
			for (int k = 0; k < num; k++)
			{
				int num7 = k * 9;
				float[] data = val.data;
				array3[k] = new Vector3(data[num7], data[num7 + 1], data[num7 + 2]);
				array4[k] = new Vector3(data[num7 + 3], data[num7 + 4], data[num7 + 5]);
				array5[k] = new Vector4(data[num7 + 6], data[num7 + 7], data[num7 + 8], 1f);
				array6[k] = new Vector2(array[k * 2], array[k * 2 + 1]);
			}
			Mesh val2 = new Mesh
			{
				name = Path.GetFileNameWithoutExtension(file)
			};
			if (num > 65000)
			{
				val2.indexFormat = (IndexFormat)1;
			}
			val2.vertices = array3;
			val2.normals = array4;
			val2.tangents = array5;
			val2.uv = array6;
			val2.subMeshCount = 2;
			int[] array7 = new int[num4 - num5];
			int[] array8 = new int[num5];
			Array.Copy(array2, array7, array7.Length);
			Array.Copy(array2, array7.Length, array8, 0, array8.Length);
			val2.SetTriangles(array7, 0);
			val2.SetTriangles(array8, 1);
			val2.RecalculateBounds();
			Material val3 = Material(template, palette, num6, ((Object)val2).name, Path.ChangeExtension(file, null));
			Material val4 = Floor(template, ((Object)val2).name);
			for (int l = 0; l < desc.lodCount; l++)
			{
				desc.lodMeshes[l] = val2;
				desc.lodMaterials[l] = (Material[])(object)new Material[2] { val3, val4 };
				desc.lodVertas[l] = val;
				Material[][] lodBlueprintMaterials = desc.lodBlueprintMaterials;
				Material[] array9 = ((lodBlueprintMaterials != null) ? lodBlueprintMaterials[l] : null);
				if (array9 != null)
				{
					Material val5 = ((array9.Length != 0) ? array9[0] : null);
					desc.lodBlueprintMaterials[l] = (Material[])(object)new Material[2] { val5, val5 };
				}
				if (desc.lodSubmeshIgnores != null)
				{
					desc.lodSubmeshIgnores[l] = new bool[2];
				}
			}
			desc.anim_prepare_length = 0f;
			desc.anim_working_length = (float)(num3 - 1) / 30f;
		}

		private static float[] Floats(BinaryReader r, int n)
		{
			byte[] array = r.ReadBytes(n * 4);
			if (array.Length != n * 4)
			{
				throw new EndOfStreamException();
			}
			float[] array2 = new float[n];
			Buffer.BlockCopy(array, 0, array2, 0, array.Length);
			return array2;
		}

		private static Material Material(Material template, float[] palette, int swatches, string name, string baked)
		{
			Material val = Swatches(template, palette, swatches, name);
			Texture2D val2 = Png(baked + "_a.png", linear: false);
			Texture2D val3 = Png(baked + "_s.png", linear: true);
			Texture2D val4 = Png(baked + "_e.png", linear: false);
			Texture2D val5 = Png(baked + "_n.png", linear: true);
			if ((Object)(object)val2 != (Object)null && (Object)(object)val3 != (Object)null && (Object)(object)val4 != (Object)null)
			{
				if ((Object)(object)val5 != (Object)null)
				{
					val.SetTexture("_NormalTex", (Texture)(object)val5);
				}
				val.SetTexture("_MainTex", (Texture)(object)val2);
				val.SetTexture("_MS_Tex", (Texture)(object)val3);
				val.SetTexture("_EmissionTex", (Texture)(object)val4);
			}
			return val;
		}

		private static Material Floor(Material template, string name)
		{
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: 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_0126: 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_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Expected O, but got Unknown
			Texture val = null;
			Texture val2 = null;
			BuiltinConfig builtin = Configs.builtin;
			Material[] array = (Material[])(object)((!((Object)(object)builtin != (Object)null)) ? new Material[0] : new Material[2] { builtin.planetReformMatProto0, builtin.planetReformMatProto1 });
			foreach (Material val3 in array)
			{
				if ((Object)(object)val3 == (Object)null)
				{
					continue;
				}
				string[] texturePropertyNames = val3.GetTexturePropertyNames();
				foreach (string text in texturePropertyNames)
				{
					Texture texture = val3.GetTexture(text);
					if (!((Object)(object)texture == (Object)null))
					{
						if (((Object)texture).name == "reform-7-a")
						{
							val = texture;
						}
						else if (((Object)texture).name == "reform-7-n")
						{
							val2 = texture;
						}
					}
				}
			}
			Material val4 = new Material(template)
			{
				name = name + "-floor"
			};
			Color val5 = (((Object)(object)val != (Object)null) ? new Color(0.55f, 0.55f, 0.55f, 1f) : new Color(0.17f, 0.17f, 0.17f, 1f));
			val4.SetTexture("_MainTex", (Texture)(((Object)(object)val != (Object)null) ? ((object)val) : ((object)Solid(Color.white, linear: false, name + "-floor-a"))));
			val4.SetTexture("_NormalTex", (Texture)(((Object)(object)val2 != (Object)null) ? ((object)val2) : ((object)Solid(new Color(1f, 0.5f, 0.5f, 0.5f), linear: true, name + "-floor-n"))));
			val4.SetTexture("_MS_Tex", (Texture)(object)Solid(new Color(0.4f, 1f, 0f, 0.4f), linear: true, name + "-floor-s"));
			val4.SetTexture("_EmissionTex", (Texture)(object)Solid(Color.clear, linear: true, name + "-floor-e"));
			val4.SetColor("_Color", ((Color)(ref val5)).gamma);
			val4.SetColor("_EmissionMask", Color.white);
			val4.SetFloat("_AlbedoMultiplier", 1f);
			val4.SetFloat("_EmissionMultiplier", 0f);
			val4.SetFloat("_AlphaClip", 0f);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Foundation pattern reform-7 not found; the floor is plain");
			}
			return val4;
		}

		private static Texture2D Solid(Color c, bool linear, string name)
		{
			//IL_000e: 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)
			Color[] array = (Color[])(object)new Color[16];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = c;
			}
			return Texture(array, 4, linear, name);
		}

		private static Texture2D Png(string path, bool linear)
		{
			//IL_000f: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			if (!File.Exists(path))
			{
				return null;
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear)
			{
				name = Path.GetFileNameWithoutExtension(path),
				wrapMode = (TextureWrapMode)1,
				anisoLevel = 4
			};
			if (!ImageConversion.LoadImage(val, File.ReadAllBytes(path), false))
			{
				return null;
			}
			val.Apply(true, true);
			return val;
		}

		private static Material Swatches(Material template, float[] palette, int swatches, string name)
		{
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: 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_0148: 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_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: 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_0222: Expected O, but got Unknown
			//IL_00a7: 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)
			//IL_00b6: 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)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			int num = 32;
			Color[] array = (Color[])(object)new Color[num * num];
			Color[] array2 = (Color[])(object)new Color[num * num];
			Color[] array3 = (Color[])(object)new Color[num * num];
			Color val = default(Color);
			Color val2 = default(Color);
			Color val3 = default(Color);
			for (int i = 0; i < swatches && i < 16; i++)
			{
				int num2 = i * 8;
				((Color)(ref val))..ctor(palette[num2], palette[num2 + 1], palette[num2 + 2], 0f);
				((Color)(ref val2))..ctor(palette[num2 + 3], 1f, 0f, palette[num2 + 4]);
				((Color)(ref val3))..ctor(palette[num2 + 5], palette[num2 + 6], palette[num2 + 7], 0f);
				int num3 = i % 4 * 8;
				int num4 = i / 4 * 8;
				for (int j = num4; j < num4 + 8; j++)
				{
					for (int k = num3; k < num3 + 8; k++)
					{
						array[j * num + k] = val;
						array2[j * num + k] = val2;
						array3[j * num + k] = val3;
					}
				}
			}
			Color[] array4 = (Color[])(object)new Color[num * num];
			for (int l = 0; l < array4.Length; l++)
			{
				array4[l] = new Color(1f, 0.5f, 0.5f, 0.5f);
			}
			Material val4 = new Material(template)
			{
				name = name
			};
			val4.SetTexture("_MainTex", (Texture)(object)Texture(array, num, linear: false, name + "-a"));
			val4.SetTexture("_MS_Tex", (Texture)(object)Texture(array2, num, linear: true, name + "-s"));
			val4.SetTexture("_EmissionTex", (Texture)(object)Texture(array3, num, linear: true, name + "-e"));
			val4.SetTexture("_NormalTex", (Texture)(object)Texture(array4, num, linear: true, name + "-n"));
			val4.SetColor("_Color", Color.white);
			val4.SetColor("_EmissionMask", Color.white);
			val4.SetFloat("_AlbedoMultiplier", 1f);
			val4.SetFloat("_EmissionMultiplier", 3f);
			val4.SetFloat("_EmissionJitter", 0f);
			val4.SetFloat("_AlphaClip", 0f);
			return val4;
		}

		private static Texture2D Texture(Color[] pixels, int size, bool linear, string name)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, false, linear)
			{
				name = name,
				filterMode = (FilterMode)0,
				wrapMode = (TextureWrapMode)1
			};
			val.SetPixels(pixels);
			val.Apply(false, true);
			return val;
		}
	}
	internal static class Picker
	{
		private const float Cell = 46f;

		private const float MinWidth = 330f;

		private static Vector2 pickerSize;

		private static Vector2 contentSize;

		private static Vector2 contentPos;

		private static bool saved;

		private static readonly List<GameObject> hidden = new List<GameObject>();

		private static bool ForConverter(UIRecipePicker picker)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			if ((int)Traverse.Create((object)picker).Field<ERecipeType>("filter").Value == 97)
			{
				return true;
			}
			Func<RecipeProto, bool> currentFilter = UIRecipePickerExtension.currentFilter;
			RecipeProto val = ((ProtoSet<RecipeProto>)(object)LDB.recipes).Select(9704);
			if (currentFilter != null && val != null)
			{
				return currentFilter(val);
			}
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIRecipePicker), "_OnOpen")]
		private static void Open(UIRecipePicker __instance)
		{
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			Restore(__instance);
			if (!ForConverter(__instance))
			{
				return;
			}
			Transform obj = ((Component)__instance).transform.Find("content");
			RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			Transform obj2 = ((val != null) ? ((Transform)val).parent : null);
			RectTransform val2 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return;
			}
			Traverse val3 = Traverse.Create((object)__instance);
			RecipeProto[] value = val3.Field<RecipeProto[]>("protoArray").Value;
			uint[] value2 = val3.Field<uint[]>("indexArray").Value;
			Array.Clear(value, 0, value.Length);
			Array.Clear(value2, 0, value2.Length);
			int num = 0;
			foreach (RecipeProto outputRecipe in Plugin.OutputRecipes)
			{
				if (num < value.Length && GameMain.history.RecipeUnlocked(((Proto)outputRecipe).ID))
				{
					value[num] = outputRecipe;
					value2[num] = GameMain.iconSet.recipeIconIndex[((Proto)outputRecipe).ID];
					num++;
				}
			}
			int num2 = Math.Max(1, num);
			Material value3 = val3.Field<Material>("iconMat").Value;
			if (value3 != null)
			{
				value3.SetVector("_Grid", new Vector4((float)num2, 1f, 0.04f, 0.04f));
			}
			saved = true;
			pickerSize = __instance.pickerTrans.sizeDelta;
			contentSize = val.sizeDelta;
			contentPos = val.anchoredPosition;
			float num3 = (((Object)(object)__instance.typeButton1 != (Object)null) ? Math.Max(0f, Top((RectTransform)/*isinst with value type is only supported in some contexts*/, val2) - Top(val, val2)) : 0f);
			UITabButton[] componentsInChildren = ((Component)__instance.pickerTrans).GetComponentsInChildren<UITabButton>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Hide(((Component)componentsInChildren[i]).gameObject);
			}
			UIButton typeButton = __instance.typeButton1;
			Hide((typeButton != null) ? ((Component)typeButton).gameObject : null);
			UIButton typeButton2 = __instance.typeButton2;
			Hide((typeButton2 != null) ? ((Component)typeButton2).gameObject : null);
			val.sizeDelta = new Vector2((float)num2 * 46f, 46f);
			val.anchoredPosition = contentPos + new Vector2(0f, num3);
			__instance.pickerTrans.sizeDelta = new Vector2(Math.Max(330f, pickerSize.x - (contentSize.x - (float)num2 * 46f)), pickerSize.y - num3 - (contentSize.y - 46f));
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIRecipePicker), "_OnClose")]
		private static void Close(UIRecipePicker __instance)
		{
			Restore(__instance);
		}

		private static void Restore(UIRecipePicker picker)
		{
			//IL_005c: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			foreach (GameObject item in hidden)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.SetActive(true);
				}
			}
			hidden.Clear();
			if (saved)
			{
				saved = false;
				picker.pickerTrans.sizeDelta = pickerSize;
				Transform obj = ((Component)picker).transform.Find("content");
				RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
				if (!((Object)(object)val == (Object)null))
				{
					val.sizeDelta = contentSize;
					val.anchoredPosition = contentPos;
				}
			}
		}

		private static void Hide(GameObject go)
		{
			if (!((Object)(object)go == (Object)null) && go.activeSelf)
			{
				go.SetActive(false);
				hidden.Add(go);
			}
		}

		private static float Top(RectTransform rt, RectTransform space)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rt == (Object)null)
			{
				return 0f;
			}
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rt.GetWorldCorners(array);
			return ((Transform)space).InverseTransformPoint(array[1]).y;
		}
	}
	[BepInPlugin("bug.dsp.trashstation", "BUG_Reclamation", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[CommonAPISubmoduleDependency(new string[] { "ProtoRegistry" })]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "bug.dsp.trashstation";

		public const int ConverterItem = 9701;

		public const int IncineratorItem = 9702;

		public const int PointsItem = 9703;

		public const int FirstOutputRecipe = 9704;

		public const int TechId = 1964;

		public const int HeatItem = 9704;

		public const int LegacyModel = 700;

		public const int IncineratorModel = 701;

		public const int ConverterModel = 702;

		public const int AssemblerItem = 2303;

		public const int PlantItem = 2204;

		public const ERecipeType RecipeType = (ERecipeType)97;

		private const int Unplaced = 1;

		public const short FuelMask = 32;

		internal static ManualLogSource Log;

		private static ItemProto converter;

		private static ItemProto incinerator;

		private static ItemProto points;

		private static ItemProto heat;

		private static RecipeProto converterRecipe;

		private static RecipeProto incineratorRecipe;

		private static readonly List<RecipeProto> outputRecipes = new List<RecipeProto>();

		private static ModelProto converterModel;

		private static ModelProto incineratorModel;

		private static bool ready;

		private static string dir;

		internal static int[] Points = new int[0];

		internal static double PowerPerPoint = 100000.0;

		internal static int MaxPointsPerMinute = 5000;

		internal static long UseFuelPerTick;

		internal static long GenEnergyPerTick;

		internal static long[] Heat = new long[0];

		internal static byte[] Levels = new byte[0];

		public const string ConverterDesc = "Burns any item that sorters bring, ammunition and buildings included, and turns its points into the Dark Fog item its recipe makes. Every item is worth points by its raw materials, from the simplest to the rarest; the points gather in the converter and each time they reach the recipe's price one item is made. The items it makes are never taken in.";

		public const string IncineratorDesc = "Burns any item that sorters bring, ammunition and buildings included, for power. Fuels burn as they do in a power plant; anything else gives energy by its rarity, little for simple items, and the rarest also burn at a higher power. The items the trash converter makes and ocean liquids are never taken in.";

		public const string PointsDesc = "Points of burned items, waiting inside a trash converter.";

		public const string HeatDesc = "Heat of burned items, waiting inside an incinerator: each is 100 kJ of fuel. Only an incinerator burns it.";

		internal static IEnumerable<RecipeProto> OutputRecipes => outputRecipes;

		internal static long HeatOf(int item)
		{
			if (item <= 0 || item >= Heat.Length)
			{
				return 0L;
			}
			return Heat[item];
		}

		internal static int LevelOf(int item)
		{
			if (item <= 0 || item >= Levels.Length)
			{
				return 0;
			}
			return Levels[item];
		}

		internal static int PointsOf(int item)
		{
			if (item <= 0 || item >= Points.Length)
			{
				return 0;
			}
			return Points[item];
		}

		internal static bool IsOutputRecipe(int recipeId)
		{
			if (recipeId >= 9704)
			{
				return recipeId < 9704 + Value.Outputs.Length;
			}
			return false;
		}

		private void Awake()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Expected O, but got Unknown
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			Stopwatch stopwatch = Stopwatch.StartNew();
			Log = ((BaseUnityPlugin)this).Logger;
			dir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			Lang.Current = ((BaseUnityPlugin)this).Config.Bind<Language>("General", "Language", Language.English, "Language of the mod's own texts: English, Chinese or Turkish (applies after restarting the game).").Value;
			Trash.ListX = ((BaseUnityPlugin)this).Config.Bind<int>("Converter window", "ListX", 170, new ConfigDescription("Burned list: pixels from the input slot's left edge to the list's left edge.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(60, 400), Array.Empty<object>())).Value;
			Trash.ListUp = ((BaseUnityPlugin)this).Config.Bind<int>("Converter window", "ListUp", 25, new ConfigDescription("Burned list: pixels its top sits above the input slot's top (negative = lower).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-30, 30), Array.Empty<object>())).Value;
			Trash.ListWidth = ((BaseUnityPlugin)this).Config.Bind<int>("Converter window", "ListWidth", 525, new ConfigDescription("Burned list: width in pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(300, 700), Array.Empty<object>())).Value;
			Trash.ListHeight = ((BaseUnityPlugin)this).Config.Bind<int>("Converter window", "ListHeight", 147, new ConfigDescription("Burned list: height in pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(90, 200), Array.Empty<object>())).Value;
			MaxPointsPerMinute = ((BaseUnityPlugin)this).Config.Bind<int>("Incinerator", "MaxPointsPerMinute", 5000, new ConfigDescription("Points an incinerator burns per minute at full load (each is 100 kJ of fuel, 80 kJ of power): 5000 is 6.67 MW. The thermal plant it copies burns 1620 (2.16 MW). Applies to built incinerators too, after restarting the game.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1620, 100000), Array.Empty<object>())).Value;
			Harmony val = new Harmony("bug.dsp.trashstation");
			val.PatchAll(typeof(Plugin));
			val.PatchAll(typeof(Trash));
			val.PatchAll(typeof(Picker));
			using (ProtoRegistry.StartModLoad("bug.dsp.trashstation"))
			{
				converter = ProtoRegistry.RegisterItem(9701, Lang.T("Trash Converter"), Lang.T("Burns any item that sorters bring, ammunition and buildings included, and turns its points into the Dark Fog item its recipe makes. Every item is worth points by its raw materials, from the simplest to the rarest; the points gather in the converter and each time they reach the recipe's price one item is made. The items it makes are never taken in."), "Icons/ItemRecipe/assembler-1", 0, 50, (EItemType)6);
				converterModel = ProtoRegistry.RegisterModel(702, converter, "Entities/Prefabs/assembler-mk-1", (Material[])null, new int[5] { 22, 11, 12, 1, 40 }, 0);
				Ruins(converterModel, 388, 4, 30000);
				Ruins(ProtoRegistry.RegisterModel(700, "Entities/Prefabs/storage-1", (Material[])null, 0), 390, 4, 24000);
				incinerator = ProtoRegistry.RegisterItem(9702, Lang.T("Incinerator"), Lang.T("Burns any item that sorters bring, ammunition and buildings included, for power. Fuels burn as they do in a power plant; anything else gives energy by its rarity, little for simple items, and the rarest also burn at a higher power. The items the trash converter makes and ocean liquids are never taken in."), "Icons/ItemRecipe/fuel-plant", 0, 50, (EItemType)6);
				incineratorModel = ProtoRegistry.RegisterModel(701, incinerator, "Entities/Prefabs/power-generator", (Material[])null, new int[6] { 53, 4, 5, 6, 1, 40 }, 0);
				Ruins(incineratorModel, 388, 1, 27000);
				points = ProtoRegistry.RegisterItem(9703, Lang.T("Points"), Lang.T("Points of burned items, waiting inside a trash converter."), "Icons/ItemRecipe/accumulator-full", 0, 10000000, (EItemType)2);
				heat = ProtoRegistry.RegisterItem(9704, Lang.T("Heat"), Lang.T("Heat of burned items, waiting inside an incinerator: each is 100 kJ of fuel. Only an incinerator burns it."), "Icons/ItemRecipe/accumulator-full", 0, 10000000, (EItemType)2);
				heat.FuelType = 32;
				heat.HeatValue = 100000L;
				converterRecipe = ProtoRegistry.RegisterRecipe(9701, (ERecipeType)4, 180, new int[3] { 2303, 1103, 1301 }, new int[3] { 1, 8, 4 }, new int[1] { 9701 }, new int[1] { 1 }, "", 0, 1, Lang.T("Trash Converter"), "Icons/ItemRecipe/assembler-1");
				incineratorRecipe = ProtoRegistry.RegisterRecipe(9702, (ERecipeType)4, 180, new int[3] { 2204, 1103, 1301 }, new int[3] { 1, 8, 4 }, new int[1] { 9702 }, new int[1] { 1 }, "", 0, 1, Lang.T("Incinerator"), "Icons/ItemRecipe/fuel-plant");
				for (int i = 0; i < Value.Outputs.Length; i++)
				{
					int num = Value.Outputs[i];
					RecipeProto val2 = ProtoRegistry.RegisterRecipe(9704 + i, (ERecipeType)97, 60, new int[1] { 9703 }, new int[1] { Value.Price(num) }, new int[1] { num }, new int[1] { 1 }, "", 0, 1, Lang.T("Trash Converter"), "Icons/ItemRecipe/assembler-1");
					val2.Handcraft = false;
					outputRecipes.Add(val2);
				}
			}
			Log.LogInfo((object)("Registered in " + stopwatch.ElapsedMilliseconds + " ms"));
		}

		private static void Ruins(ModelProto m, int ruin, int symmetry, int hp)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			m.ObjectType = (EObjectType)0;
			m.RuinType = (ERuinType)2;
			m.RuinId = ruin;
			m.RuinCount = 1;
			m.RotSymmetry = symmetry;
			m.HpMax = hp;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
		[HarmonyAfter(new string[] { "me.xiaoye97.plugin.Dyson.LDBTool", "dsp.common-api.CommonAPI", "org.LoShin.GenesisBook", "bug.dsp.oreenrichment", "bug.dsp.deliveryitemchain", "bug.dsp.dronecoverage", "Gnimaerd.DSP.plugin.MoreMegaStructure", "com.ckcz123.DSP_Battle", "org.kremnev8.plugin.RebindBuildBar" })]
		[HarmonyPriority(0)]
		private static void Setup()
		{
			if (ready)
			{
				return;
			}
			ready = true;
			Stopwatch stopwatch = Stopwatch.StartNew();
			try
			{
				Adopt();
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Buildings keep CommonAPI's defaults: " + ex));
			}
			try
			{
				Ingredients(converterRecipe);
				Ingredients(incineratorRecipe);
			}
			catch (Exception ex2)
			{
				Log.LogWarning((object)("Recipe inputs not checked: " + ex2.Message));
			}
			try
			{
				Place();
			}
			catch (Exception ex3)
			{
				Log.LogError((object)("Buildings not placed in the replicator or build bar: " + ex3));
			}
			try
			{
				BuildTech();
			}
			catch (Exception ex4)
			{
				Log.LogError((object)("Research not added, the buildings cannot be unlocked: " + ex4));
			}
			try
			{
				BuildPoints();
			}
			catch (Exception ex5)
			{
				Log.LogError((object)("Item points not computed, nothing is taken in: " + ex5));
				Points = new int[0];
				Heat = new long[0];
			}
			try
			{
				Icons.Apply(converter, converterRecipe, Path.Combine(dir, "converter_icon.png"));
				Icons.Apply(incinerator, incineratorRecipe, Path.Combine(dir, "incinerator_icon.png"));
				TechProto val = ((ProtoSet<TechProto>)(object)LDB.techs).Select(1964);
				if (val != null)
				{
					Icons.Apply(val, converter);
				}
			}
			catch (Exception ex6)
			{
				Log.LogWarning((object)("Buildings keep the copied icons: " + ex6.Message));
			}
			Log.LogInfo((object)("Set up in " + stopwatch.ElapsedMilliseconds + " ms"));
		}

		private static void Adopt()
		{
			//IL_004c: 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)
			Copy(converter, converterModel, 2303);
			Copy(incinerator, incineratorModel, 2204);
			PrefabDesc prefabDesc = converterModel.prefabDesc;
			if (prefabDesc == null || !prefabDesc.isAssembler)
			{
				throw new InvalidOperationException("the copied assembler has no assembler");
			}
			prefabDesc.assemblerRecipeType = (ERecipeType)97;
			if (converter.prefabDesc != null)
			{
				converter.prefabDesc.assemblerRecipeType = (ERecipeType)97;
			}
			PrefabDesc prefabDesc2 = incineratorModel.prefabDesc;
			if (prefabDesc2 == null || !prefabDesc2.isPowerGen)
			{
				throw new InvalidOperationException("the copied thermal plant has no generator");
			}
			prefabDesc2.fuelMask = 32;
			double num = ((prefabDesc2.useFuelPerTick > 0) ? ((double)prefabDesc2.genEnergyPerTick / (double)prefabDesc2.useFuelPerTick) : 0.8);
			UseFuelPerTick = (long)((double)MaxPointsPerMinute * 100000.0 / 3600.0);
			GenEnergyPerTick = (long)((double)UseFuelPerTick * num);
			PowerPerPoint = 100000.0 * num;
			PrefabDesc[] array = (PrefabDesc[])(object)new PrefabDesc[2] { prefabDesc2, incinerator.prefabDesc };
			foreach (PrefabDesc val in array)
			{
				if (val != null)
				{
					val.fuelMask = 32;
					val.useFuelPerTick = UseFuelPerTick;
					val.genEnergyPerTick = GenEnergyPerTick;
				}
			}
			ItemProto.InitFuelNeeds();
			ItemProto obj = ((ProtoSet<ItemProto>)(object)LDB.items).Select(2303);
			object obj2;
			if (obj == null)
			{
				obj2 = null;
			}
			else
			{
				PrefabDesc prefabDesc3 = obj.prefabDesc;
				if (prefabDesc3 == null)
				{
					obj2 = null;
				}
				else
				{
					Material[][] lodMaterials = prefabDesc3.lodMaterials;
					if (lodMaterials == null)
					{
						obj2 = null;
					}
					else
					{
						Material[] obj3 = lodMaterials[0];
						obj2 = ((obj3 != null) ? obj3[0] : null);
					}
				}
			}
			Material template = (Material)obj2;
			Look(prefabDesc, "converter.tsm");
			Look(prefabDesc2, "incinerator.tsm");
			foreach (RecipeProto outputRecipe in outputRecipes)
			{
				ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(outputRecipe.Results[0]);
				if (val2 != null)
				{
					((Proto)outputRecipe).Name = ((Proto)val2).Name;
					((Proto)outputRecipe).name = ((Proto)val2).name;
					outputRecipe.IconPath = val2.IconPath;
					Traverse.Create((object)outputRecipe).Field("_iconSprite").SetValue((object)val2.iconSprite);
				}
			}
			static void Copy(ItemProto mine, ModelProto myModel, int source)
			{
				ItemProto val3 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(source);
				ModelProto val4 = ((val3 != null) ? ((ProtoSet<ModelProto>)(object)LDB.models).Select(val3.ModelIndex) : null);
				if (val3 != null && val4 != null)
				{
					mine.HpMax = val3.HpMax;
					if (val3.DescFields != null)
					{
						mine.DescFields = (int[])val3.DescFields.Clone();
					}
					myModel.HpMax = val4.HpMax;
					myModel.HpUpgrade = val4.HpUpgrade;
					myModel.HpRecover = val4.HpRecover;
				}
			}
			void Look(PrefabDesc desc, string file)
			{
				try
				{
					if ((Object)(object)template != (Object)null)
					{
						Model.Apply(desc, Path.Combine(dir, file), template);
					}
				}
				catch (Exception ex)
				{
					Log.LogWarning((object)("Model " + file + " not used: " + ex.Message));
				}
			}
		}

		private static void Ingredients(RecipeProto recipe)
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Invalid comparison between Unknown and I4
			HashSet<int> hashSet = new HashSet<int>();
			RecipeProto[] dataArray = ((ProtoSet<RecipeProto>)(object)LDB.recipes).dataArray;
			foreach (RecipeProto val in dataArray)
			{
				if (val?.Results != null && val != converterRecipe && val != incineratorRecipe)
				{
					hashSet.UnionWith(val.Results);
				}
			}
			List<int> list = new List<int>();
			for (int j = 0; j < recipe.Items.Length; j++)
			{
				ItemProto val2 = ((ProtoSet<ItemProto>)(object)LDB.items).Select(recipe.Items[j]);
				if (j == 0 || (val2 != null && (hashSet.Contains(((Proto)val2).ID) || (int)val2.Type == 1)))
				{
					list.Add(j);
				}
				else
				{
					Log.LogWarning((object)(((Proto)recipe).name + ": input " + recipe.Items[j] + " is not made in this game, left out"));
				}
			}
			if (list.Count != recipe.Items.Length)
			{
				recipe.Items = list.Select((int num) => recipe.Items[num]).ToArray();
				recipe.ItemCounts = list.Select((int num) => recipe.ItemCounts[num]).ToArray();
			}
		}

		private static void Place()
		{
			Traverse val = Traverse.Create(typeof(UIBuildMenu));
			ItemProto[,] protos = (val.Field<bool>("staticLoaded").Value ? val.Field<ItemProto[,]>("protos").Value : null);
			HashSet<Proto> hashSet = new HashSet<Proto>((IEnumerable<Proto>)outputRecipes)
			{
				(Proto)(object)converter,
				(Proto)(object)incinerator,
				(Proto)(object)converterRecipe,
				(Proto)(object)incineratorRecipe
			};
			HashSet<int> cells = new HashSet<int>();
			ItemProto[] dataArray = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray;
			foreach (ItemProto val2 in dataArray)
			{
				if (val2 != null && !hashSet.Contains((Proto)(object)val2))
				{
					cells.Add(val2.GridIndex);
				}
			}
			RecipeProto[] dataArray2 = ((ProtoSet<RecipeProto>)(object)LDB.recipes).dataArray;
			foreach (RecipeProto val3 in dataArray2)
			{
				if (val3 != null && !hashSet.Contains((Proto)(object)val3))
				{
					cells.Add(val3.GridIndex);
				}
			}
			HashSet<int> keys = new HashSet<int>();
			dataArray = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray;
			foreach (ItemProto val4 in dataArray)
			{
				if (val4 != null && !hashSet.Contains((Proto)(object)val4))
				{
					keys.Add(val4.BuildIndex);
				}
			}
			HashSet<ItemProto> shown = new HashSet<ItemProto>();
			if (protos != null)
			{
				for (int j = 0; j < protos.GetLength(0); j++)
				{
					for (int k = 0; k < protos.GetLength(1); k++)
					{
						if (protos[j, k] != null)
						{
							keys.Add(j * 100 + k);
							shown.Add(protos[j, k]);
						}
					}
				}
			}
			Put(converter, converterRecipe, 2303, new int[1] { Row(2303, 3) });
			Put(incinerator, incineratorRecipe, 2204, new int[2]
			{
				Row(2204, 1),
				converter.BuildIndex / 100
			});
			Log.LogInfo((object)("Trash converter at cell " + converter.GridIndex + " key " + converter.BuildIndex + ", incinerator at cell " + incinerator.GridIndex + " key " + incinerator.BuildIndex));
			void Put(ItemProto item, RecipeProto recipe, int source, params int[] rows)
			{
				item.GridIndex = (recipe.GridIndex = Take(Tab(source)));
				int num = Value.Slot(keys, rows);
				keys.Add(num);
				item.BuildIndex = num;
				if (protos != null && num > 0 && !shown.Contains(item))
				{
					protos[num / 100, num % 100] = item;
				}
			}
			static int Row(int source, int fallback)
			{
				int num = ((ProtoSet<ItemProto>)(object)LDB.items).Select(source)?.BuildIndex ?? 0;
				if (num <= 0)
				{
					return fallback;
				}
				return num / 100;
			}
			static int Tab(int source)
			{
				return Math.Max(1, (((ProtoSet<ItemProto>)(object)LDB.items).Select(source)?.GridIndex ?? 2000) / 1000);
			}
			int Take(int tab)
			{
				int num = Value.Cell(cells, tab);
				cells.Add(num);
				return num;
			}
		}

		private static void BuildPoints()
		{
			List<Value.Recipe> list = (from x in ((ProtoSet<RecipeProto>)(object)LDB.recipes).dataArray
				where x?.Items != null && x.Results != null && x.ItemCounts != null && x.ResultCounts != null && x.Items.Length == x.ItemCounts.Length && x.Results.Length == x.ResultCounts.Length && (int)x.Type != 97
				select new Value.Recipe
				{
					In = x.Items,
					InN = x.ItemCounts,
					Out = x.Results,
					OutN = x.ResultCounts
				}).ToList();
			Dictionary<int, double> dictionary = Value.Costs(list, Value.FixedCosts);
			int[] array = new int[((ProtoSet<ItemProto>)(object)LDB.items).dataArray.Max((ItemProto i) => ((Proto)(i?)).ID ?? 0) + 1];
			long[] array2 = new long[array.Length];
			byte[] array3 = new byte[array.Length];
			double num = PowerPerPoint / 100000.0;
			HashSet<int> hashSet = new HashSet<int> { 1000, 1116 };
			ThemeProto[] dataArray = ((ProtoSet<ThemeProto>)(object)LDB.themes).dataArray;
			foreach (ThemeProto val in dataArray)
			{
				if (val != null && val.WaterItemId > 0)
				{
					hashSet.Add(val.WaterItemId);
				}
			}
			ItemProto[] dataArray2 = ((ProtoSet<ItemProto>)(object)LDB.items).dataArray;
			foreach (ItemProto val2 in dataArray2)
			{
				if (val2 != null && ((Proto)val2).ID != 9703 && ((Proto)val2).ID != 9704 && Array.IndexOf(Value.Outputs, ((Proto)val2).ID) < 0 && !hashSet.Contains(((Proto)val2).ID))
				{
					array[((Proto)val2).ID] = Value.Points(dictionary.TryGetValue(((Proto)val2).ID, out var value) ? value : 0.0, val2.HeatValue);
					bool flag = val2.HeatValue > 0;
					array2[((Proto)val2).ID] = (flag ? val2.HeatValue : Value.Heat(array[((Proto)val2).ID]));
					array3[((Proto)val2).ID] = (byte)((!flag) ? ((uint)Value.Level(array[((Proto)val2).ID])) : 0u);
					val2.description = val2.description + "\n" + Lang.F("Trash points: {0} ({1} of power in an incinerator)", array[((Proto)val2).ID], Value.Energy((double)array2[((Proto)val2).ID] * num)) + ((array3[((Proto)val2).ID] > 0) ? (" +" + array3[((Proto)val2).ID] * 25 + "%") : "");
				}
			}
			array[9703] = 1;
			array2[9704] = 100000L;
			Points = array;
			Heat = array2;
			Levels = array3;
			Log.LogInfo((object)("Points for " + array.Count((int p) => p > 0) + " items, from " + list.Count + " recipes; prices " + string.Join(", ", Value.Outputs.Select((int o) => o + "=" + Value.Price(o)))));
		}

		private static void BuildTech()
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if (((ProtoSet<TechProto>)(object)LDB.techs).Exist(1964))
			{
				throw new InvalidOperationException("tech id " + 1964 + " is taken by another mod");
			}
			Tech.Layout(((ProtoSet<TechProto>)(object)LDB.techs).dataArray, out var x, out var _, out var y);
			TechProto val = Tech.New(1964, Lang.T("Reclamation"), Lang.T("Buildings that burn any item for points: a trash converter that turns them into Dark Fog items, and an incinerator that turns them into power."), "Icons/ItemRecipe/fuel-plant", Tech.Unlocking(2204), new int[2] { 9701, 9702 }, new Vector2(x, y));
			Tech.Insert((TechProto[])(object)new TechProto[1] { val });
			converterRecipe.preTech = (incineratorRecipe.preTech = val);
			foreach (RecipeProto outputRecipe in outputRecipes)
			{
				outputRecipe.preTech = val;
			}
			Log.LogInfo((object)("Tech " + 1964 + " added at x " + x + " y " + y));
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameHistoryData), "RecipeUnlocked")]
		private static void Unlocked(GameHistoryData __instance, int recipeId, ref bool __result)
		{
			if (!__result && (IsOutputRecipe(recipeId) || recipeId == 9701 || recipeId == 9702))
			{
				__result = __instance.TechUnlocked(1964);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static void MadeFrom(RecipeProto __instance, ref string __result)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			if ((int)__instance.Type == 97 && converter != null)
			{
				__result = ((Proto)converter).name;
			}
		}
	}
	internal static class Tech
	{
		internal static TechProto New(int id, string name, string desc, string icon, int gate, int[] unlocks, Vector2 position)
		{
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			int[] items = new int[1] { TechProto.matrixIds[0] };
			int[] itemPoints = new int[1] { 10 };
			long hashNeeded = 36000L;
			bool isLabTech = true;
			TechProto val = ((gate > 0) ? ((ProtoSet<TechProto>)(object)LDB.techs).Select(gate) : null);
			if (val?.Items != null && val.Items.Length != 0 && val.ItemPoints != null && val.ItemPoints.Length == val.Items.Length && val.HashNeeded > 0)
			{
				items = (int[])val.Items.Clone();
				itemPoints = (int[])val.ItemPoints.Clone();
				hashNeeded = val.HashNeeded;
				isLabTech = val.IsLabTech;
			}
			TechProto val2 = new TechProto();
			((Proto)val2).ID = id;
			((Proto)val2).Name = name;
			val2.Desc = desc;
			val2.Conclusion = "";
			val2.Published = true;
			val2.IsLabTech = isLabTech;
			val2.IconPath = icon;
			val2.IconTag = "";
			val2.PreTechs = new int[0];
			val2.PreTechsImplicit = ((gate <= 0) ? new int[0] : new int[1] { gate });
			val2.PreItem = new int[0];
			val2.Items = items;
			val2.ItemPoints = itemPoints;
			val2.HashNeeded = hashNeeded;
			val2.UnlockRecipes = unlocks;
			val2.UnlockFunctions = new int[0];
			val2.UnlockValues = new double[0];
			val2.AddItems = new int[0];
			val2.AddItemCounts = new int[0];
			val2.PropertyOverrideItems = new int[0];
			val2.PropertyItemCounts = new int[0];
			val2.PropertyOverrideItemArray = (IDCNT[])(object)new IDCNT[0];
			val2.Position = position;
			return val2;
		}

		internal static void Insert(TechProto[] techs)
		{
			TechProtoSet techs2 = LDB.techs;
			TechProto[] dataArray = ((ProtoSet<TechProto>)(object)techs2).dataArray;
			((ProtoTable)techs2).Init(dataArray.Length + techs.Length);
			Array.Copy(dataArray, ((ProtoSet<TechProto>)(object)techs2).dataArray, dataArray.Length);
			for (int i = 0; i < techs.Length; i++)
			{
				((ProtoSet<TechProto>)(object)techs2).dataArray[dataArray.Length + i] = techs[i];
			}
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			for (int j = 0; j < ((ProtoSet<TechProto>)(object)techs2).dataArray.Length; j++)
			{
				dictionary[((Proto)((ProtoSet<TechProto>)(object)techs2).dataArray[j]).ID] = j;
			}
			Traverse.Create((object)techs2).Field("dataIndices").SetValue((object)dictionary);
			if (((ProtoSet<TechProto>)(object)techs2).Select(((Proto)techs[0]).ID) != techs[0])
			{
				throw new InvalidOperationException("proto index not rebuilt");
			}
			TechProto[] array = techs;
			for (int k = 0; k < array.Length; k++)
			{
				array[k].Preload();
			}
			array = techs;
			for (int k = 0; k < array.Length; k++)
			{
				array[k].Preload2();
			}
		}

		internal static int Unlocking(int item)
		{
			HashSet<int> hashSet = new HashSet<int>();
			RecipeProto[] dataArray = ((ProtoSet<RecipeProto>)(object)LDB.recipes).dataArray;
			foreach (RecipeProto val in dataArray)
			{
				if (val?.Results != null && Array.IndexOf(val.Results, item) >= 0)
				{
					hashSet.Add(((Proto)val).ID);
				}
			}
			TechProto[] dataArray2 = ((ProtoSet<TechProto>)(object)LDB.techs).dataArray;
			foreach (TechProto val2 in dataArray2)
			{
				if (val2?.UnlockRecipes == null)
				{
					continue;
				}
				int[] unlockRecipes = val2.UnlockRecipes;
				foreach (int item2 in unlockRecipes)
				{
					if (hashSet.Contains(item2))
					{
						return ((Proto)val2).ID;
					}
				}
			}
			return 0;
		}

		public static void Layout(TechProto[] techs, out float x0, out float dx, out float y0)
		{
			//IL_0042: 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_004a: 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_0066: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			float num = float.MaxValue;
			Dictionary<float, float> dictionary = new Dictionary<float, float>();
			SortedSet<float> sortedSet = new SortedSet<float>();
			SortedSet<float> sortedSet2 = new SortedSet<float>();
			foreach (TechProto val in techs)
			{
				if (val != null && val.page == 0 && val.Published)
				{
					Vector2 position = val.Position;
					num = Math.Min(num, position.y);
					sortedSet.Add(position.y);
					sortedSet2.Add(position.x);
					dictionary[position.y] = (dictionary.TryGetValue(position.y, out var value) ? Math.Min(value, position.x) : position.x);
				}
			}
			dx = CommonGap(sortedSet2, 4f);
			float num2 = CommonGap(sortedSet, 4f);
			x0 = Mode(dictionary.Values, 0f);
			y0 = ((num == float.MaxValue) ? 0f : num) - num2;
		}

		private static float CommonGap(SortedSet<float> values, float fallback)
		{
			List<float> list = new List<float>();
			float num = float.NaN;
			foreach (float value in values)
			{
				if (!float.IsNaN(num) && value - num > 0.5f)
				{
					list.Add(value - num);
				}
				num = value;
			}
			return Mode(list, fallback);
		}

		private static float Mode(IEnumerable<float> values, float fallback)
		{
			Dictionary<float, int> dictionary = new Dictionary<float, int>();
			float num = fallback;
			int num2 = 0;
			foreach (float value2 in values)
			{
				dictionary[value2] = ((!dictionary.TryGetValue(value2, out var value)) ? 1 : (value + 1));
				if (dictionary[value2] > num2 || (dictionary[value2] == num2 && value2 < num))
				{
					num2 = dictionary[value2];
					num = value2;
				}
			}
			return num;
		}
	}
	internal static class Trash
	{
		private static readonly ConcurrentDictionary<long, int> lastBurned = new ConcurrentDictionary<long, int>();

		private static Text stockText;

		private const int NumberSize = 16;

		private static Text leftText;

		private static Text countText;

		private static Text gridText;

		private static GameObject hiddenLabel;

		private static bool searched;

		internal static int ListX = 170;

		internal static int ListUp = 25;

		internal static int ListWidth = 525;

		internal static int ListHeight = 147;

		private static readonly BurnPanel converterPanel = new BurnPanel(besideWindow: false, new Vector2((float)ListWidth, (float)ListHeight));

		private static readonly BurnPanel incineratorPanel = new BurnPanel(besideWindow: true, new Vector2(300f, 0f));

		private static readonly ItemBundle filled = new ItemBundle();

		private static bool Taken(int item, bool heat = false)
		{
			if (!heat)
			{
				return Plugin.PointsOf(item) > 0;
			}
			return Plugin.HeatOf(item) > 0;
		}

		private static long Key(PlanetFactory factory, int id, bool generator)
		{
			return ((long)factory.index << 33) | (generator ? 4294967296L : 0) | (uint)id;
		}

		private static bool Converter(PlanetFactory factory, int asmId)
		{
			AssemblerComponent[] array = factory.factorySystem?.assemblerPool;
			if (array == null || asmId <= 0 || asmId >= array.Length || array[asmId].id != asmId)
			{
				return false;
			}
			int[] array2 = array[asmId].recipeExecuteData?.requires;
			if (array2 != null && array2.Length == 1)
			{
				return array2[0] == 9703;
			}
			return false;
		}

		private static bool Incinerator(PlanetFactory factory, int genId)
		{
			PowerGeneratorComponent[] array = factory.powerSystem?.genPool;
			if (array != null && genId > 0 && genId < array.Length && array[genId].id == genId)
			{
				return array[genId].fuelMask == 32;
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static bool InsertByEntity(PlanetFactory __instance, int entityId, int itemId, byte itemCount, ref byte remainInc, ref int __result)
		{
			if (entityId <= 0 || entityId >= __instance.entityPool.Length || __instance.entityPool[entityId].beltId != 0)
			{
				return true;
			}
			int assemblerId = __instance.entityPool[entityId].assemblerId;
			int powerGenId = __instance.entityPool[entityId].powerGenId;
			if (Converter(__instance, assemblerId))
			{
				__result = Feed(__instance, assemblerId, itemId, itemCount, ref remainInc);
			}
			else
			{
				if (!Incinerator(__instance, powerGenId))
				{
					return true;
				}
				__result = Burn(__instance, powerGenId, itemId, itemCount, ref remainInc);
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static bool InsertByTarget(PlanetFactory __instance, uint ioTargetTypedId, int itemId, byte itemCount, ref byte remainInc, ref int __result)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Invalid comparison between Unknown and I4
			EFactoryIOTargetType val = (EFactoryIOTargetType)((int)ioTargetTypedId & -16777216);
			int num = (int)(ioTargetTypedId & 0xFFFFFF);
			if ((int)val == 33554432 && Converter(__instance, num))
			{
				__result = Feed(__instance, num, itemId, itemCount, ref remainInc);
			}
			else
			{
				if ((int)val != 134217728 || !Incinerator(__instance, num))
				{
					return true;
				}
				__result = Burn(__instance, num, itemId, itemCount, ref remainInc);
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static bool PickForConverter(PlanetFactory __instance, uint ioTargetTypedId, int offset, int filter, int[] needs, ref byte stack, ref byte inc, ref int __result)
		{
			if (needs == null || needs.Length == 0 || needs[0] != 9703)
			{
				return true;
			}
			__result = PickAny(__instance, ioTargetTypedId, offset, filter, heat: false, out stack, out inc);
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlanetFactory), "PickFuelForPowerGenFrom")]
		private static bool PickForIncinerator(PlanetFactory __instance, uint pickTargetTypedId, int insertPowerGenId, int offset, int filter, ref byte stack, ref byte inc, ref bool fuelFull, ref int __result)
		{
			if (!Incinerator(__instance, insertPowerGenId))
			{
				return true;
			}
			stack = 1;
			inc = 0;
			fuelFull = __instance.powerSystem.genPool[insertPowerGenId].fuelCount >= 1000;
			__result = ((!fuelFull) ? PickAny(__instance, pickTargetTypedId, offset, filter, heat: true, out stack, out inc) : 0);
			return false;
		}

		private static int PickAny(PlanetFactory f, uint typed, int offset, int filter, bool heat, out byte stack, out byte inc)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Invalid comparison between Unknown and I4
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Invalid comparison between Unknown and I4
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Invalid comparison between Unknown and I4
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Invalid comparison between Unknown and I4
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Invalid comparison between Unknown and I4
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Invalid comparison between Unknown and I4
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Invalid comparison between Unknown and I4
			stack = 1;
			inc = 0;
			if (filter != 0 && !Taken(filter, heat))
			{
				return 0;
			}
			int num = (int)(typed & 0xFFFFFF);
			int num2 = 0;
			if (num <= 0)
			{
				return 0;
			}
			EFactoryIOTargetType val = (EFactoryIOTargetType)((int)typed & -16777216);
			if ((int)val <= 50331648)
			{
				if ((int)val == 16777216)
				{
					CargoTraffic cargoTraffic = f.cargoTraffic;
					if (num >= cargoTraffic.beltPool.Length || cargoTraffic.beltPool[num].id != num)
					{
						return 0;
					}
					CargoPath cargoPath = cargoTraffic.GetCargoPath(cargoTraffic.beltPool[num].segPathId);
					if (cargoPath == null)
					{
						return 0;
					}
					int num3 = ((BeltComponent)(ref cargoTraffic.beltPool[num])).pivotOnPath + offset - 2;
					lock (cargoPath.buffer)
					{
						num2 = OnBelt(cargoPath, num3, 5, filter, heat);
						return (num2 != 0) ? cargoPath.TryPickItem(num3, 5, num2, ref stack, ref inc) : 0;
					}
				}
				if ((int)val != 33554432)
				{
					if ((int)val == 50331648)
					{
						EjectorComponent[] array = f.factorySystem?.ejectorPool;
						if (array != null && num < array.Length && array[num].id == num && array[num].bulletCount > 0 && Wanted(array[num].bulletId, filter, heat))
						{
							num2 = array[num].bulletId;
						}
					}
				}
				else
				{
					AssemblerComponent[] array2 = f.factorySystem?.assemblerPool;
					if (array2 == null || num >= array2.Length || array2[num].id != num)
					{
						return 0;
					}
					int[] array3 = array2[num].recipeExecuteData?.products;
					int[] produced = array2[num].produced;
					int num4 = 0;
					while (array3 != null && produced != null && num4 < array3.Length && num4 < produced.Length && num2 == 0)
					{
						if (produced[num4] > 0 && Wanted(array3[num4], filter, heat))
						{
							num2 = array3[num4];
						}
						num4++;
					}
				}
			}
			else if ((int)val <= 83886080)
			{
				if ((int)val != 67108864)
				{
					if ((int)val == 83886080)
					{
						StorageComponent[] array4 = f.factoryStorage?.storagePool;
						StorageComponent val2 = ((array4 != null && num < array4.Length) ? array4[num] : null);
						StorageComponent val3 = val2?.topStorage;
						while (val3 != null && num2 == 0)
						{
							int num5 = val3.grids.Length - 1;
							while (num5 >= 0 && num2 == 0)
							{
								if (val3.grids[num5].count > 0 && Wanted(val3.grids[num5].itemId, filter, heat))
								{
									num2 = val3.grids[num5].itemId;
								}
								num5--;
							}
							val3 = ((val3 == val2) ? null : val3.previousStorage);
						}
					}
				}
				else
				{
					SiloComponent[] array5 = f.factorySystem?.siloPool;
					if (array5 != null && num < array5.Length && array5[num].id == num && array5[num].bulletCount > 0 && Wanted(array5[num].bulletId, filter, heat))
					{
						num2 = array5[num].bulletId;
					}
				}
			}
			else if ((int)val != 100663296)
			{
				if ((int)val == 117440512)
				{
					LabComponent[] array6 = f.factorySystem?.labPool;
					if (array6 == null || num >= array6.Length || array6[num].id != num)
					{
						return 0;
					}
					int[] array7 = array6[num].recipeExecuteData?.products;
					int[] produced2 = array6[num].produced;
					int num6 = 0;
					while (array7 != null && produced2 != null && num6 < array7.Length && num6 < produced2.Length && num2 == 0)
					{
						if (produced2[num6] > 0 && Wanted(array7[num6], filter, heat))
						{
							num2 = array7[num6];
						}
						num6++;
					}
				}
			}
			else
			{
				StationComponent[] array8 = f.transport?.stationPool;
				StationStore[] array9 = ((array8 == null || num >= array8.Length) ? null : array8[num]?.storage);
				int num7 = 0;
				while (array9 != null && num7 < array9.Length && num2 == 0)
				{
					if (array9[num7].count > 0 && Wanted(array9[num7].itemId, filter, heat))
					{
						num2 = array9[num7].itemId;
					}
					num7++;
				}
			}
			if (num2 != 0)
			{
				return f.PickFrom(typed, offset, num2, (int[])null, ref stack, ref inc);
			}
			return 0;
		}

		private static bool Wanted(int item, int filter, bool heat)
		{
			if (item > 0 && (filter == 0 || item == filter))
			{
				return Taken(item, heat);
			}
			return false;
		}

		private static int OnBelt(CargoPath path, int index, int length, int filter, bool heat)
		{
			byte[] buffer = path.buffer;
			int num = Math.Min(Math.Max(index, 0) + length, path.pathLength);
			for (int i = Math.Max(0, Math.Min(index, path.pathLength - 1)); i < num; i++)
			{
				if (buffer[i] >= 246)
				{
					i += 250 - buffer[i];
					if (i + 4 >= buffer.Length)
					{
						break;
					}
					int num2 = buffer[i + 1] - 1 + (buffer[i + 2] - 1) * 100 + (buffer[i + 3] - 1) * 10000 + (buffer[i + 4] - 1) * 1000000;
					int item = path.cargoContainer.cargoPool[num2].item;
					if (Wanted(item, filter, heat))
					{
						return item;
					}
				}
			}
			return 0;
		}

		private static int Feed(PlanetFactory factory, int asmId, int itemId, byte count, ref byte remainInc)
		{
			int num = Plugin.PointsOf(itemId);
			if (num <= 0 || count == 0)
			{
				return 0;
			}
			ref AssemblerComponent reference = ref factory.factorySystem.assemblerPool[asmId];
			lock (factory.entityMutexs[reference.entityId])
			{
				reference.served[0] = (int)Math.Min(2147483647L, reference.served[0] + (long)num * (long)count);
			}
			remainInc = 0;
			lastBurned[Key(factory, asmId, generator: false)] = itemId;
			Ledger.Add(Key(factory, asmId, generator: false), itemId, count, num);
			Burned(factory, itemId, count);
			return count;
		}

		private static int Burn(PlanetFactory factory, int genId, int itemId, byte count, ref byte remainInc, bool byHand = false)
		{
			long num = Plugin.HeatOf(itemId);
			if (num <= 0 || count == 0)
			{
				return 0;
			}
			ref PowerGeneratorComponent reference = ref factory.powerSystem.genPool[genId];
			lock (factory.entityMutexs[reference.entityId])
			{
				if (!byHand && reference.fuelCount >= 1000)
				{
					return 0;
				}
				if (reference.fuelId == 9703)
				{
					reference.fuelId = 9704;
				}
				if (reference.fuelId != 9704 || reference.fuelCount <= 0)
				{
					reference.fuelId = 9704;
					reference.fuelCount = 0;
					reference.fuelInc = 0;
					reference.fuelHeat = 100000L;
				}
				long num2 = num * count;
				long num3 = reference.fuelCount + num2 / 100000;
				int fuelCount = reference.fuelCount;
				reference.fuelCount = (short)Math.Min(32767L, num3);
				reference.fuelEnergy += (num3 - reference.fuelCount) * 100000 + num2 % 100000;
				reference.fuelInc = (short)Math.Min(32767L, reference.fuelInc + (long)Plugin.LevelOf(itemId) * (long)(reference.fuelCount - fuelCount));
			}
			lastBurned[Key(factory, genId, generator: true)] = itemId;
			Ledger.Add(Key(factory, genId, generator: true), itemId, count, num);
			remainInc = 0;
			Burned(factory, itemId, count);
			return count;
		}

		private static void Burned(PlanetFactory factory, int itemId, int count)
		{
			if (itemId != 9703 && itemId != 9704)
			{
				FactoryProductionStat[] array = GameMain.statistics?.production?.factoryStatPool;
				if (array != null && factory.index < array.Length && array[factory.index] != null)
				{
					Interlocked.Add(ref array[factory.index].consumeRegister[itemId], count);
				}
			}
		}

		private static void Stock(UIPowerGeneratorWindow window, in PowerGeneratorComponent g)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)stockText == (Object)null)
			{
				stockText = Object.Instantiate<Text>(window.fuelText2, ((Component)window.fuelText2).transform.parent.parent);
				((Object)stockText).name = "trash-stock-text";
				stockText.alignment = (TextAnchor)3;
				stockText.horizontalOverflow = (HorizontalWrapMode)1;
				((Graphic)stockText).raycastTarget = false;
				RectTransform rectTransform = ((Graphic)stockText).rectTransform;
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(0.5f, 0.5f);
				rectTransform.anchorMax = val;
				rectTransform.anchorMin = val;
				rectTransform.pivot = new Vector2(0f, 0.5f);
				rectTransform.sizeDelta = new Vector2(180f, 20f);
				rectTransform.anchoredPosition = new Vector2(-40f, -88f);
			}
			if (!((Component)stockText).gameObject.activeSelf)
			{
				((Component)stockText).gameObject.SetActive(true);
			}
			double num = (double)g.fuelCount * 100000.0 + (double)Math.Max(0L, g.fuelEnergy);
			double seconds = ((g.useFuelPerTick > 0) ? (num / ((double)g.useFuelPerTick * 60.0)) : 0.0);
			stockText.text = Lang.F("Stock {0} ≈ {1}", Value.Energy(num * Power(in g) / 100000.0), Span(seconds));
		}

		private static string Span(double seconds)
		{
			if (!(seconds < 100.0))
			{
				if (!(seconds < 6000.0))
				{
					return Lang.F("{0} h", Math.Round(seconds / 3600.0, 1));
				}
				return Lang.F("{0} min", Math.Round(seconds / 60.0, 1));
			}
			return Lang.F("{0} s", Math.Round(seconds));
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIPowerGeneratorWindow), "_OnUpdate")]
		private static void Window(UIPowerGeneratorWindow __instance)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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)
			//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_00e2: 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)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			PlanetFactory factory = __instance.factory;
			int generatorId = __instance.generatorId;
			if (factory == null || !Incinerator(factory, generatorId))
			{
				incineratorPanel.Hide();
				if ((Object)(object)stockText != (Object)null && ((Component)stockText).gameObject.activeSelf)
				{
					((Component)stockText).gameObject.SetActive(false);
				}
				return;
			}
			Stock(__instance, in factory.powerSystem.genPool[generatorId]);
			RectTransform rectTransform = ((Graphic)__instance.fuelIcon2).rectTransform;
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rectTransform.GetWorldCorners(array);
			Vector3 val = (array[2] + array[3]) / 2f;
			incineratorPanel.Show((RectTransform)((Component)__instance).transform, __instance.fuelText2.font, Key(factory, generatorId, generator: true), val + ((Transform)rectTransform).TransformVector(new Vector3(18f, 13f, 0f)));
			if (factory.powerSystem.genPool[generatorId].fuelCount > 0)
			{
				int value;
				ItemProto val2 = (lastBurned.TryGetValue(Key(factory, generatorId, generator: true), out value) ? ((ProtoSet<ItemProto>)(object)LDB.items).Select(value) : null);
				if (val2 != null)
				{
					__instance.fuelIcon2.sprite = val2.iconSprite;
					((Behaviour)__instance.fuelIcon2).enabled = (Object)(object)val2.iconSprite != (Object)null;
					ref PowerGeneratorComponent g = ref factory.powerSystem.genPool[generatorId];
					int num = Plugin.LevelOf(value);
					__instance.fuelText2.text = ((Proto)val2).name + " · " + Value.Energy((double)Plugin.HeatOf(value) * Power(in g) / 100000.0) + ((num > 0) ? (" · +" + num * 25 + "%") : "");
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static void Serving(UIAssemblerWindow __instance, ref AssemblerComponent assembler)
		{
			PlanetFactory factory = __instance.factory;
			UIStorageGrid servingBox = __instance.servingBox;
			if (factory != null && !((Object)(object)servingBox == (Object)null) && Converter(factory, assembler.id) && assembler.served[0] > 0 && lastBurned.TryGetValue(Key(factory, assembler.id, generator: false), out var value) && value > 0 && value < GameMain.iconSet.itemIconIndex.Length)
			{
				Traverse obj = Traverse.Create((object)servingBox);
				uint[] value2 = obj.Field<uint[]>("iconIndexArray").Value;
				ComputeBuffer value3 = obj.Field<ComputeBuffer>("iconIndexBuffer").Value;
				if (value2 != null && value3 != null)
				{
					value2[0] = GameMain.iconSet.itemIconIndex[value] | (value2[0] & 0xFF000000u);
					value3.SetData((Array)value2);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIAssemblerWindow), "_OnUpdate")]
		[HarmonyAfter(new string[] { "dsp.assemblerUI.speedMod" })]
		private static void Numbers(UIAssemblerWindow __instance)
		{
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to