Decompiled source of MorePlanters v1.1.0

plugins/MorePlanters/MorePlanters.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EquinoxsModUtils;
using HarmonyLib;
using MorePlanters.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MorePlanters")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MorePlanters")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e0f66e42-86ec-4117-9cbd-82c72f89b2ee")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MorePlanters
{
	[BepInPlugin("com.equinox.MorePlanters", "MorePlanters", "1.0.1")]
	public class MorePlantersPlugin : BaseUnityPlugin
	{
		private const string MyGUID = "com.equinox.MorePlanters";

		private const string PluginName = "MorePlanters";

		private const string VersionString = "1.0.1";

		private static readonly Harmony Harmony = new Harmony("com.equinox.MorePlanters");

		public static ManualLogSource Log = new ManualLogSource("MorePlanters");

		public const string planterMk2Name = "Planter MKII";

		public const string planterMk3Name = "Planter MKIII";

		public static SchematicsRecipeData planterMk2Recipe;

		public static SchematicsRecipeData planterMk3Recipe;

		public static GameObject planterMk2Prefab;

		public static GameObject planterMk3Prefab;

		public static ConfigEntry<bool> doublePlants;

		public static ConfigEntry<float> slot1XOffset;

		public static ConfigEntry<float> slot2XOffset;

		public static ConfigEntry<float> slot3XOffset;

		public static ConfigEntry<float> slot4XOffset;

		public static ConfigEntry<float> yOffset;

		private static string dataFolder => Application.persistentDataPath + "/MorePlanters";

		private void Awake()
		{
			//IL_0054: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_00ed: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: MorePlanters, VersionString: 1.0.1 is loading...");
			Harmony.PatchAll();
			CreateConfigEntries();
			ApplyPatches();
			LoadPrefabs();
			PlanterMk3GUI.buttonUncheckedTexture = ModUtils.LoadTexture2DFromFile("MorePlanters.Assets.Images.CheckboxUnTicked.png", false, (Assembly)null);
			PlanterMk3GUI.buttonCheckedTexture = ModUtils.LoadTexture2DFromFile("MorePlanters.Assets.Images.CheckboxTicked.png", false, (Assembly)null);
			ModUtils.AddNewUnlock(new NewUnlockDetails
			{
				category = (TechCategory)1,
				coreTypeNeeded = (CoreType)2,
				coreCountNeeded = 100,
				description = "Produces two plants per seed at 2x speed",
				displayName = "Planter MKII",
				numScansNeeded = 0,
				requiredTier = (ResearchTier)1,
				treePosition = 0,
				sprite = ModUtils.LoadSpriteFromFile("MorePlanters.Assets.Images.Planter Mk2.png", false)
			}, false);
			ModUtils.AddNewUnlock(new NewUnlockDetails
			{
				category = (TechCategory)1,
				coreTypeNeeded = (CoreType)2,
				coreCountNeeded = 250,
				description = "Houses an integrated Thresher and has the capability to self-seed",
				displayName = "Planter MKIII",
				numScansNeeded = 0,
				requiredTier = (ResearchTier)1,
				treePosition = 0,
				sprite = ModUtils.LoadSpriteFromFile("MorePlanters.Assets.Images.Planter Mk3.png", false)
			}, false);
			ModUtils.GameDefinesLoaded += OnGameDefinesLoaded;
			ModUtils.SaveStateLoaded += OnSaveStateLoaded;
			ModUtils.TechTreeStateLoaded += OnTechTreeLoaded;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: MorePlanters, VersionString: 1.0.1 is loaded.");
			Log = ((BaseUnityPlugin)this).Logger;
		}

		private void OnGUI()
		{
			if (PlanterMk3GUI.shouldShowGUI)
			{
				PlanterMk3GUI.DrawGUI();
			}
		}

		private void OnGameDefinesLoaded(object sender, EventArgs e)
		{
			ResourceInfo resourceInfoByName = ModUtils.GetResourceInfoByName("Planter MKII", false);
			resourceInfoByName.unlock = ModUtils.GetUnlockByName("Planter MKII", false);
			ResourceInfo resourceInfoByName2 = ModUtils.GetResourceInfoByName("Planter MKIII", false);
			resourceInfoByName2.unlock = ModUtils.GetUnlockByName("Planter MKIII", false);
		}

		private void OnSaveStateLoaded(object sender, EventArgs e)
		{
			LoadData(SaveState.instance.metadata.worldName);
		}

		private void OnTechTreeLoaded(object sender, EventArgs e)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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)
			Unlock unlockByName = ModUtils.GetUnlockByName("Atlantum Ingot", false);
			Unlock unlockByName2 = ModUtils.GetUnlockByName("Thresher MKII", false);
			Unlock unlockByName3 = ModUtils.GetUnlockByName("Assembler MKII", false);
			Unlock unlockByName4 = ModUtils.GetUnlockByName("Planter MKII", false);
			unlockByName4.requiredTier = unlockByName.requiredTier;
			unlockByName4.treePosition = unlockByName3.treePosition;
			unlockByName4.unlockedRecipes.Add(planterMk2Recipe);
			Unlock unlockByName5 = ModUtils.GetUnlockByName("Planter MKIII", false);
			unlockByName5.requiredTier = unlockByName2.requiredTier;
			unlockByName5.treePosition = unlockByName3.treePosition;
			unlockByName5.unlockedRecipes.Add(planterMk3Recipe);
			Unlock unlockByName6 = ModUtils.GetUnlockByName("Planter", false);
			unlockByName6.unlockedRecipes.Remove(planterMk2Recipe);
			unlockByName6.unlockedRecipes.Remove(planterMk3Recipe);
		}

		public static void SaveData(string worldName)
		{
			Directory.CreateDirectory(dataFolder);
			string path = dataFolder + "/" + worldName + ".txt";
			List<string> list = new List<string>();
			foreach (PlanterExtension value in PlanterMk3GUI.planterExtensions.Values)
			{
				list.Add(value.Serialise());
			}
			File.WriteAllLines(path, list);
		}

		public static void LoadData(string worldName)
		{
			string path = dataFolder + "/" + worldName + ".txt";
			if (!File.Exists(path))
			{
				Log.LogWarning((object)("Save file not found for world '" + worldName + "'"));
				return;
			}
			string[] array = File.ReadAllLines(path);
			string[] array2 = array;
			foreach (string input in array2)
			{
				PlanterExtension planterExtension = PlanterExtension.Deserialise(input);
				PlanterMk3GUI.planterExtensions.Add(planterExtension.instanceId, planterExtension);
			}
		}

		private void CreateConfigEntries()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Expected O, but got Unknown
			doublePlants = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Double Plants", true, new ConfigDescription("Whether the Planter MKII should produce two plants per seed. Disable if not using a mod to void excess", (AcceptableValueBase)null, Array.Empty<object>()));
			slot1XOffset = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Slot 1 X Offset", -295f, new ConfigDescription("Controls the horizontal offset of the filter GUI for the first plant slot", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-5000f, 5000f), Array.Empty<object>()));
			slot2XOffset = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Slot 2 X Offset", -145f, new ConfigDescription("Controls the horizontal offset of the filter GUI for the second plant slot", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-5000f, 5000f), Array.Empty<object>()));
			slot3XOffset = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Slot 3 X Offset", 10f, new ConfigDescription("Controls the horizontal offset of the filter GUI for the third plant slot", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-5000f, 5000f), Array.Empty<object>()));
			slot4XOffset = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Slot 4 X Offset", 160f, new ConfigDescription("Controls the horizontal offset of the filter GUI for the fourth plant slot", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-5000f, 5000f), Array.Empty<object>()));
			yOffset = ((BaseUnityPlugin)this).Config.Bind<float>("General", "GUI Y Offset", -300f, new ConfigDescription("Controls the vertical offset of the filter GUI", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-5000f, 5000f), Array.Empty<object>()));
		}

		private void ApplyPatches()
		{
			Harmony.CreateAndPatchAll(typeof(GameDefinesPatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(PlanterDefinitionPatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(PlanterInstancePatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(PlanterUIPatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(SaveStatePatch), (string)null);
		}

		private void LoadPrefabs()
		{
			AssetBundle val = LoadAssetBundle("caspuinox");
			planterMk2Prefab = val.LoadAsset<GameObject>("assets/gpui_plantermk2.prefab");
			planterMk3Prefab = val.LoadAsset<GameObject>("assets/gpui_plantermk3.prefab");
			Transform obj = planterMk3Prefab.transform.Find("r_spin");
			if (obj != null)
			{
				((Component)obj).gameObject.AddComponent<IndependentRotation>();
			}
			Transform obj2 = planterMk3Prefab.transform.Find("f_spin");
			if (obj2 != null)
			{
				((Component)obj2).gameObject.AddComponent<IndependentRotation>();
			}
		}

		private static AssetBundle LoadAssetBundle(string filename)
		{
			Assembly callingAssembly = Assembly.GetCallingAssembly();
			return AssetBundle.LoadFromStream(callingAssembly.GetManifestResourceStream("MorePlanters.Assets." + filename));
		}
	}
	public class IndependentRotation : MonoBehaviour
	{
		public Vector3 rotationAxis = Vector3.left;

		public float rotationSpeed = 90f;

		public void SetRotationSettings(Vector3 axis, float speed)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			rotationAxis = axis;
			rotationSpeed = speed;
		}

		private void Update()
		{
			//IL_0008: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.Rotate(rotationAxis * rotationSpeed * Time.deltaTime, (Space)1);
		}
	}
	public static class PlanterMk3GUI
	{
		public static bool shouldShowGUI = false;

		public static PlanterInstance currentPlanter;

		public static bool[,] buttonStates = new bool[4, 3];

		public static Dictionary<uint, PlanterExtension> planterExtensions = new Dictionary<uint, PlanterExtension>();

		public static Texture2D buttonUncheckedTexture;

		public static Texture2D buttonCheckedTexture;

		public static float slot1XOffset => MorePlantersPlugin.slot1XOffset.Value;

		public static float slot2XOffset => MorePlantersPlugin.slot2XOffset.Value;

		public static float slot3XOffset => MorePlantersPlugin.slot3XOffset.Value;

		public static float slot4XOffset => MorePlantersPlugin.slot4XOffset.Value;

		public static float yOffset => MorePlantersPlugin.yOffset.Value;

		public static void DrawGUI()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Invalid comparison between Unknown and I4
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Invalid comparison between Unknown and I4
			uint instanceId = currentPlanter.commonInfo.instanceId;
			if (!planterExtensions.ContainsKey(instanceId))
			{
				planterExtensions.Add(instanceId, new PlanterExtension(instanceId));
				for (int i = 0; i < 4; i++)
				{
					buttonStates[i, 0] = true;
					buttonStates[i, 1] = false;
					buttonStates[i, 2] = false;
					if ((int)currentPlanter.plantSlots[i].state != 0)
					{
						ResourceInfo resInfoFromId = SaveState.GetResInfoFromId(currentPlanter.plantSlots[i].plantId);
						string text = ((resInfoFromId.displayName == "Kindlevine") ? "Kindlevine Stems" : "Shiverthorn Buds");
						switch (i)
						{
						case 0:
							planterExtensions[instanceId].slot1Output = ModUtils.GetResourceInfoByName(text, false);
							break;
						case 1:
							planterExtensions[instanceId].slot2Output = ModUtils.GetResourceInfoByName(text, false);
							break;
						case 2:
							planterExtensions[instanceId].slot3Output = ModUtils.GetResourceInfoByName(text, false);
							break;
						case 3:
							planterExtensions[instanceId].slot4Output = ModUtils.GetResourceInfoByName(text, false);
							break;
						}
					}
				}
				planterExtensions[instanceId].buttonStates = buttonStates;
			}
			else
			{
				buttonStates = planterExtensions[instanceId].buttonStates;
			}
			for (int j = 0; j < currentPlanter.plantSlots.Length; j++)
			{
				if ((int)currentPlanter.plantSlots[j].state != 0)
				{
					DrawOptionsForPlantSlot(j);
				}
			}
		}

		private static void DrawOptionsForPlantSlot(int slot)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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)
			//IL_004f: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_00d9: 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_00ed: Expected O, but got Unknown
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: 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)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Expected O, but got Unknown
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: 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_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			ResourceInfo resInfoFromId = SaveState.GetResInfoFromId(currentPlanter.plantSlots[slot].plantId);
			float num = (float)(Screen.width / 2) + GetOffsetForSlot(slot);
			float num2 = (float)(Screen.height / 2) + yOffset;
			GUIStyle val = new GUIStyle
			{
				padding = new RectOffset(5, 5, 0, 0)
			};
			val.normal.background = buttonUncheckedTexture;
			val.hover.background = buttonUncheckedTexture;
			val.active.background = buttonUncheckedTexture;
			val.focused.background = buttonUncheckedTexture;
			val.onNormal.background = buttonUncheckedTexture;
			val.onHover.background = buttonUncheckedTexture;
			val.onActive.background = buttonUncheckedTexture;
			val.onFocused.background = buttonUncheckedTexture;
			GUIStyle val2 = val;
			GUIStyle val3 = new GUIStyle
			{
				padding = new RectOffset(5, 5, 0, 0)
			};
			val3.normal.background = buttonCheckedTexture;
			val3.hover.background = buttonCheckedTexture;
			val3.active.background = buttonCheckedTexture;
			val3.focused.background = buttonCheckedTexture;
			val3.onNormal.background = buttonCheckedTexture;
			val3.onHover.background = buttonCheckedTexture;
			val3.onActive.background = buttonCheckedTexture;
			val3.onFocused.background = buttonCheckedTexture;
			GUIStyle val4 = val3;
			if (resInfoFromId.displayName == "Kindlevine")
			{
				if (GUI.Button(new Rect(num, num2, 40f, 40f), (Texture)(object)ModUtils.GetImageForResource("Kindlevine Stems", false), buttonStates[slot, 0] ? val4 : val2))
				{
					HandleButtonClick(slot, 0, "Kindlevine Stems");
				}
				if (GUI.Button(new Rect(num + 45f, num2, 40f, 40f), (Texture)(object)ModUtils.GetImageForResource("Kindlevine Extract", false), buttonStates[slot, 1] ? val4 : val2))
				{
					HandleButtonClick(slot, 1, "Kindlevine Extract");
				}
				if (GUI.Button(new Rect(num + 90f, num2, 40f, 40f), (Texture)(object)ModUtils.GetImageForResource("Plantmatter Fiber", false), buttonStates[slot, 2] ? val4 : val2))
				{
					HandleButtonClick(slot, 2, "Plantmatter Fiber");
				}
			}
			else if (resInfoFromId.displayName == "Shiverthorn")
			{
				if (GUI.Button(new Rect(num, num2, 40f, 40f), (Texture)(object)ModUtils.GetImageForResource("Shiverthorn Buds", false), buttonStates[slot, 0] ? val4 : val2))
				{
					HandleButtonClick(slot, 0, "Shiverthorn Buds");
				}
				if (GUI.Button(new Rect(num + 45f, num2, 40f, 40f), (Texture)(object)ModUtils.GetImageForResource("Shiverthorn Extract", false), buttonStates[slot, 1] ? val4 : val2))
				{
					HandleButtonClick(slot, 1, "Shiverthorn Extract");
				}
				if (GUI.Button(new Rect(num + 90f, num2, 40f, 40f), (Texture)(object)ModUtils.GetImageForResource("Plantmatter", false), buttonStates[slot, 2] ? val4 : val2))
				{
					HandleButtonClick(slot, 2, "Plantmatter");
				}
			}
		}

		private static float GetOffsetForSlot(int slot)
		{
			return slot switch
			{
				0 => slot1XOffset, 
				1 => slot2XOffset, 
				2 => slot3XOffset, 
				3 => slot4XOffset, 
				_ => 0f, 
			};
		}

		private static void HandleButtonClick(int plantSlot, int buttonIndex, string outputName)
		{
			for (int i = 0; i < 3; i++)
			{
				buttonStates[plantSlot, i] = false;
			}
			buttonStates[plantSlot, buttonIndex] = true;
			uint instanceId = currentPlanter.commonInfo.instanceId;
			planterExtensions[instanceId].buttonStates = buttonStates;
			switch (plantSlot)
			{
			case 0:
				planterExtensions[instanceId].slot1Output = ModUtils.GetResourceInfoByName(outputName, false);
				break;
			case 1:
				planterExtensions[instanceId].slot2Output = ModUtils.GetResourceInfoByName(outputName, false);
				break;
			case 2:
				planterExtensions[instanceId].slot3Output = ModUtils.GetResourceInfoByName(outputName, false);
				break;
			case 3:
				planterExtensions[instanceId].slot4Output = ModUtils.GetResourceInfoByName(outputName, false);
				break;
			}
		}
	}
	public class PlanterExtension
	{
		public uint instanceId;

		public bool[,] buttonStates;

		public ResourceInfo slot1Output;

		public ResourceInfo slot2Output;

		public ResourceInfo slot3Output;

		public ResourceInfo slot4Output;

		public List<ResourceStack> queuedOutputs = new List<ResourceStack>();

		public string Serialise()
		{
			//IL_0137: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			string text = $"{instanceId}|";
			for (int i = 0; i < 4; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					text += (buttonStates[i, j] ? "1" : "0");
				}
			}
			string text2 = (((Object)(object)slot1Output == (Object)null) ? "null" : slot1Output.displayName);
			string text3 = (((Object)(object)slot2Output == (Object)null) ? "null" : slot2Output.displayName);
			string text4 = (((Object)(object)slot3Output == (Object)null) ? "null" : slot3Output.displayName);
			string text5 = (((Object)(object)slot4Output == (Object)null) ? "null" : slot4Output.displayName);
			text = text + "|" + text2;
			text = text + "|" + text3;
			text = text + "|" + text4;
			text = text + "|" + text5;
			foreach (ResourceStack queuedOutput in queuedOutputs)
			{
				ResourceStack current = queuedOutput;
				text += $"|{((UniqueIdScriptableObject)((ResourceStack)(ref current)).info).uniqueId},{current.count}";
			}
			return text;
		}

		public static PlanterExtension Deserialise(string input)
		{
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			PlanterExtension planterExtension = new PlanterExtension(0u);
			List<string> list = input.Split(new char[1] { '|' }).ToList();
			planterExtension.instanceId = uint.Parse(list[0]);
			list.RemoveAt(0);
			for (int i = 0; i < 4; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					int index = i * 3 + j;
					planterExtension.buttonStates[i, j] = list[0][index] == '1';
				}
			}
			list.RemoveAt(0);
			if (list[0] != "null")
			{
				planterExtension.slot1Output = ModUtils.GetResourceInfoByName(list[0], false);
			}
			list.RemoveAt(0);
			if (list[0] != "null")
			{
				planterExtension.slot2Output = ModUtils.GetResourceInfoByName(list[0], false);
			}
			list.RemoveAt(0);
			if (list[0] != "null")
			{
				planterExtension.slot3Output = ModUtils.GetResourceInfoByName(list[0], false);
			}
			list.RemoveAt(0);
			if (list[0] != "null")
			{
				planterExtension.slot4Output = ModUtils.GetResourceInfoByName(list[0], false);
			}
			list.RemoveAt(0);
			foreach (string item in list)
			{
				int num = int.Parse(item.Split(new char[1] { ',' })[0]);
				int num2 = int.Parse(item.Split(new char[1] { ',' })[1]);
				planterExtension.queuedOutputs.Add(ResourceStack.CreateSimpleStack(num, num2));
			}
			return planterExtension;
		}

		public PlanterExtension(uint id)
		{
			instanceId = id;
			buttonStates = new bool[4, 3];
		}
	}
}
namespace MorePlanters.Patches
{
	internal class GameDefinesPatch
	{
		private static bool hasAdded;

		private static PlanterDefinition planterMk1Definition;

		private static PlanterDefinition planterMk2Definition;

		private static PlanterDefinition planterMk3Definition;

		[HarmonyPatch(typeof(GameDefines), "GetMaxResId")]
		[HarmonyPrefix]
		private static void AddNewPlantersToGame()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			if (!hasAdded)
			{
				hasAdded = true;
				planterMk1Definition = (PlanterDefinition)ModUtils.GetResourceInfoByNameUnsafe("Planter", false);
				AddPlanterMk2();
				AddRecipeForPlanterMk2();
				AddPlanterMk3();
				AddRecipeForPlanterMk3();
				ModUtils.SetPrivateStaticField<GameDefines>("_topResId", GameDefines.instance, (object)(-1));
			}
		}

		private static void AddPlanterMk2()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			planterMk2Definition = (PlanterDefinition)ScriptableObject.CreateInstance(typeof(PlanterDefinition));
			ModUtils.CloneObject<PlanterDefinition>(planterMk1Definition, ref planterMk2Definition);
			((ResourceInfo)planterMk2Definition).description = "Produces two plants per seed at 2x speed";
			((ResourceInfo)planterMk2Definition).rawName = "Planter MKII";
			((ResourceInfo)planterMk2Definition).rawSprite = ModUtils.LoadSpriteFromFile("MorePlanters.Assets.Images.Planter Mk2.png", false);
			((UniqueIdScriptableObject)planterMk2Definition).uniqueId = ModUtils.GetNewResourceID(false);
			((BuilderInfo)planterMk2Definition).kWPowerConsumption = 250;
			((BuilderInfo)planterMk2Definition).machineTier = 2;
			GameDefines.instance.resources.Add((ResourceInfo)(object)planterMk2Definition);
			GameDefines.instance.buildableResources.Add((BuilderInfo)(object)planterMk2Definition);
			ResourceNames.SafeResources.Add("Planter MKII");
		}

		private static void AddRecipeForPlanterMk2()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			NewRecipeDetails val = new NewRecipeDetails
			{
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				duration = 10,
				ingredients = new List<RecipeResourceInfo>
				{
					new RecipeResourceInfo("Planter", 1),
					new RecipeResourceInfo("Atlantum Ingot", 10),
					new RecipeResourceInfo("Wall Light (1x1)", 4)
				},
				outputs = new List<RecipeResourceInfo>
				{
					new RecipeResourceInfo("Planter MKII", 1)
				},
				sortPriority = 4
			};
			MorePlantersPlugin.planterMk2Recipe = val.ConvertToRecipe();
			((Object)MorePlantersPlugin.planterMk2Recipe).name = "Planter MKII";
			((UniqueIdScriptableObject)MorePlantersPlugin.planterMk2Recipe).uniqueId = ModUtils.GetNewRecipeID(true);
			MorePlantersPlugin.planterMk2Recipe.unlock = ((ResourceInfo)planterMk1Definition).unlock;
			GameDefines.instance.schematicsRecipeEntries.Add(MorePlantersPlugin.planterMk2Recipe);
		}

		private static void AddPlanterMk3()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			planterMk3Definition = (PlanterDefinition)ScriptableObject.CreateInstance(typeof(PlanterDefinition));
			ModUtils.CloneObject<PlanterDefinition>(planterMk1Definition, ref planterMk3Definition);
			((ResourceInfo)planterMk3Definition).description = "Houses an integrated Thresher and has the capability to self-seed";
			((ResourceInfo)planterMk3Definition).rawName = "Planter MKIII";
			((ResourceInfo)planterMk3Definition).rawSprite = ModUtils.LoadSpriteFromFile("MorePlanters.Assets.Images.Planter Mk3.png", false);
			((UniqueIdScriptableObject)planterMk3Definition).uniqueId = ModUtils.GetNewResourceID(false);
			((BuilderInfo)planterMk3Definition).kWPowerConsumption = 500;
			((BuilderInfo)planterMk3Definition).machineTier = 3;
			GameDefines.instance.resources.Add((ResourceInfo)(object)planterMk3Definition);
			GameDefines.instance.buildableResources.Add((BuilderInfo)(object)planterMk3Definition);
			ResourceNames.SafeResources.Add("Planter MKIII");
		}

		private static void AddRecipeForPlanterMk3()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			NewRecipeDetails val = new NewRecipeDetails
			{
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				duration = 10,
				ingredients = new List<RecipeResourceInfo>
				{
					new RecipeResourceInfo("Planter MKII", 1),
					new RecipeResourceInfo("Thresher MKII", 1),
					new RecipeResourceInfo("Biobrick", 50)
				},
				outputs = new List<RecipeResourceInfo>
				{
					new RecipeResourceInfo("Planter MKIII", 1)
				},
				sortPriority = 5
			};
			MorePlantersPlugin.planterMk3Recipe = val.ConvertToRecipe();
			((Object)MorePlantersPlugin.planterMk3Recipe).name = "Planter MKIII";
			((UniqueIdScriptableObject)MorePlantersPlugin.planterMk3Recipe).uniqueId = ModUtils.GetNewRecipeID(true);
			MorePlantersPlugin.planterMk3Recipe.unlock = ((ResourceInfo)planterMk1Definition).unlock;
			GameDefines.instance.schematicsRecipeEntries.Add(MorePlantersPlugin.planterMk3Recipe);
		}
	}
	internal class PlanterDefinitionPatch
	{
		private static Dictionary<Vector3, GameObject> myVisualsMap = new Dictionary<Vector3, GameObject>();

		[HarmonyPatch(typeof(MachineDefinition<PlanterInstance, PlanterDefinition>), "OnBuild")]
		[HarmonyPostfix]
		private static void AddVisuals(PlanterDefinition __instance, MachineInstanceRef<PlanterInstance> instRef)
		{
			//IL_004f: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			switch (((ResourceInfo)__instance).displayName)
			{
			case "Planter MKII":
				val = MorePlantersPlugin.planterMk2Prefab;
				break;
			case "Planter MKIII":
				val = MorePlantersPlugin.planterMk3Prefab;
				break;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val, ((GridInfo)(ref instRef.gridInfo)).BottomCenter, Quaternion.Euler(0f, (float)(instRef.gridInfo.yawRot + 90), 0f));
			val2.transform.localScale = new Vector3(1.01f, 1.01f, 1.01f);
			myVisualsMap.Add(((GridInfo)(ref instRef.gridInfo)).BottomCenter, val2);
		}

		[HarmonyPatch(typeof(MachineDefinition<PlanterInstance, PlanterDefinition>), "OnDeconstruct")]
		[HarmonyPostfix]
		private static void RemoveVisuals(PlanterDefinition __instance, ref PlanterInstance erasedInstance)
		{
			//IL_000c: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			if (myVisualsMap.ContainsKey(((GridInfo)(ref erasedInstance.gridInfo)).BottomCenter))
			{
				Object.Destroy((Object)(object)myVisualsMap[((GridInfo)(ref erasedInstance.gridInfo)).BottomCenter]);
				myVisualsMap.Remove(((GridInfo)(ref erasedInstance.gridInfo)).BottomCenter);
			}
		}
	}
	internal class PlanterInstancePatch
	{
		[HarmonyPatch(typeof(PlanterInstance), "SimUpdate")]
		[HarmonyPrefix]
		private static void ApplySpeedBoost(PlanterInstance __instance)
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			if (((ResourceInfo)((PlanterInstance)(ref __instance)).myDef).displayName == "Planter")
			{
				return;
			}
			for (int i = 0; i < __instance.plantSlots.Count(); i++)
			{
				if (__instance.plantSlots[i].growthProgress > __instance.plantSlots[i].totalGrowthDuration)
				{
					__instance.plantSlots[i].growthProgress = __instance.plantSlots[i].totalGrowthDuration;
				}
				int plantId = __instance.plantSlots[i].plantId;
				if (plantId == -1)
				{
					break;
				}
				ResourceInfo resInfoFromId = SaveState.GetResInfoFromId(plantId);
				if (__instance.plantSlots[i].totalGrowthDuration == 120f)
				{
					__instance.plantSlots[i].totalGrowthDuration = 60f;
				}
			}
		}

		[HarmonyPatch(typeof(PlanterInstance), "TakeAvailableRes")]
		[HarmonyPrefix]
		private static bool DoublePlantsForInserterTake(PlanterInstance __instance, ref bool __result, out ResourceStack stack, int filterType, int maxCount)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Invalid comparison between Unknown and I4
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: 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)
			stack = ResourceStack.CreateEmptyStack();
			if (((ResourceInfo)((PlanterInstance)(ref __instance)).myDef).displayName == "Planter")
			{
				return true;
			}
			if (((ResourceInfo)((PlanterInstance)(ref __instance)).myDef).displayName == "Planter MKIII")
			{
				HandleTakeAvailableResForMk3(__instance, ref __result, out stack);
				return false;
			}
			if (!MorePlantersPlugin.doublePlants.Value)
			{
				return true;
			}
			int num = 0;
			for (int i = 0; i < __instance.plantSlots.Length; i++)
			{
				ref PlantSlot reference = ref __instance.plantSlots[i];
				if ((int)reference.state == 2 && (filterType < 0 || reference.plantId == filterType) && num < maxCount)
				{
					num += 2;
					filterType = reference.plantId;
					if (((ResourceInfo)((PlanterInstance)(ref __instance)).myDef).displayName == "Planter MKII")
					{
						((PlantSlot)(ref reference)).MakeEmpty();
						((Inventory)(ref ((PlanterInstance)(ref __instance)).GetOutputInventory())).RemoveResourcesFromSlot(i, (SlotTransferMode)3);
					}
					else
					{
						reference.growthProgress = 0f;
						reference.state = (PlantState)1;
					}
				}
			}
			if (num > 0)
			{
				stack = ResourceStack.CreateSimpleStack(filterType, num);
			}
			__result = num > 0;
			return false;
		}

		[HarmonyPatch(typeof(PlanterInstance), "TakeAll")]
		[HarmonyPrefix]
		private static bool DoublePlantsForTakeAll(PlanterInstance __instance, ref List<ResourceStack> __result, bool actuallyTake)
		{
			//IL_003e: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Invalid comparison between Unknown and I4
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			if (((ResourceInfo)((PlanterInstance)(ref __instance)).myDef).displayName == "Planter")
			{
				return true;
			}
			if (((ResourceInfo)((PlanterInstance)(ref __instance)).myDef).displayName == "Planter MKIII")
			{
				__result = HandleTakeAllForMk3(__instance, actuallyTake);
				return false;
			}
			List<ResourceStack> list = new List<ResourceStack>();
			for (int i = 0; i < __instance.plantSlots.Length; i++)
			{
				ref PlantSlot reference = ref __instance.plantSlots[i];
				if ((int)reference.state == 2)
				{
					list.Add(ResourceStack.CreateSimpleStack(reference.plantId, 2));
					if (actuallyTake)
					{
						((PlantSlot)(ref reference)).MakeEmpty();
						((Inventory)(ref ((PlanterInstance)(ref __instance)).GetOutputInventory())).RemoveResourcesFromSlot(i, (SlotTransferMode)3);
					}
				}
			}
			__result = list;
			return false;
		}

		private static void HandleTakeAvailableResForMk3(PlanterInstance __instance, ref bool __result, out ResourceStack stack)
		{
			//IL_00c0: 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)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: 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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//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_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < __instance.plantSlots.Length; i++)
			{
				if ((int)__instance.plantSlots[i].state != 2)
				{
					continue;
				}
				int resIDForSlot = GetResIDForSlot(__instance.commonInfo.instanceId, i);
				if (resIDForSlot != -1)
				{
					int countForResID = GetCountForResID(resIDForSlot);
					if (PlanterMk3GUI.planterExtensions.ContainsKey(__instance.commonInfo.instanceId))
					{
						PlanterMk3GUI.planterExtensions[__instance.commonInfo.instanceId].queuedOutputs.Add(ResourceStack.CreateSimpleStack(resIDForSlot, countForResID));
						__instance.plantSlots[i].growthProgress = 0f;
						__instance.plantSlots[i].state = (PlantState)1;
					}
				}
			}
			if (!PlanterMk3GUI.planterExtensions.ContainsKey(__instance.commonInfo.instanceId))
			{
				__result = false;
				stack = ResourceStack.CreateEmptyStack();
			}
			else if (PlanterMk3GUI.planterExtensions[__instance.commonInfo.instanceId].queuedOutputs.Count > 0)
			{
				stack = FHG_Utils.First<ResourceStack>(PlanterMk3GUI.planterExtensions[__instance.commonInfo.instanceId].queuedOutputs);
				PlanterMk3GUI.planterExtensions[__instance.commonInfo.instanceId].queuedOutputs.RemoveAt(0);
				__result = true;
			}
			else
			{
				__result = false;
				stack = ResourceStack.CreateEmptyStack();
			}
		}

		private static List<ResourceStack> HandleTakeAllForMk3(PlanterInstance __instance, bool actuallyTake)
		{
			//IL_008f: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			List<ResourceStack> list = new List<ResourceStack>();
			for (int i = 0; i < __instance.plantSlots.Length; i++)
			{
				ref PlantSlot reference = ref __instance.plantSlots[i];
				if ((int)reference.state == 2)
				{
					int num = GetResIDForSlot(__instance.commonInfo.instanceId, i);
					if (num == -1)
					{
						num = reference.plantId;
					}
					int countForResID = GetCountForResID(num);
					list.Add(ResourceStack.CreateSimpleStack(num, countForResID));
					if (actuallyTake)
					{
						((PlantSlot)(ref reference)).MakeEmpty();
						((Inventory)(ref ((PlanterInstance)(ref __instance)).GetOutputInventory())).RemoveResourcesFromSlot(i, (SlotTransferMode)3);
					}
				}
			}
			return list;
		}

		private static int GetResIDForSlot(uint id, int slot)
		{
			if (!PlanterMk3GUI.planterExtensions.ContainsKey(id))
			{
				return -1;
			}
			switch (slot)
			{
			case 0:
				if ((Object)(object)PlanterMk3GUI.planterExtensions[id].slot1Output != (Object)null)
				{
					return ((UniqueIdScriptableObject)PlanterMk3GUI.planterExtensions[id].slot1Output).uniqueId;
				}
				return -1;
			case 1:
				if ((Object)(object)PlanterMk3GUI.planterExtensions[id].slot2Output != (Object)null)
				{
					return ((UniqueIdScriptableObject)PlanterMk3GUI.planterExtensions[id].slot2Output).uniqueId;
				}
				return -1;
			case 2:
				if ((Object)(object)PlanterMk3GUI.planterExtensions[id].slot3Output != (Object)null)
				{
					return ((UniqueIdScriptableObject)PlanterMk3GUI.planterExtensions[id].slot3Output).uniqueId;
				}
				return -1;
			case 3:
				if ((Object)(object)PlanterMk3GUI.planterExtensions[id].slot4Output != (Object)null)
				{
					return ((UniqueIdScriptableObject)PlanterMk3GUI.planterExtensions[id].slot4Output).uniqueId;
				}
				return -1;
			default:
				return -1;
			}
		}

		private static int GetCountForResID(int resID)
		{
			ResourceInfo resInfoFromId = SaveState.GetResInfoFromId(resID);
			return resInfoFromId.displayName switch
			{
				"Kindlevine Stems" => 6, 
				"Kindlevine Extract" => 18, 
				"Plantmatter Fiber" => 18, 
				"Shiverthorn Buds" => 6, 
				"Shiverthorn Extract" => 18, 
				"Plantmatter" => 18, 
				_ => 2, 
			};
		}
	}
	public class PlanterUIPatch
	{
		[HarmonyPatch(typeof(PlanterUI), "OnOpen")]
		[HarmonyPostfix]
		private static void ShowPlanterMk3GUI(PlanterUI __instance)
		{
			//IL_000c: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			PlanterInstance val = ((MachineInstanceRef<PlanterInstance>)ModUtils.GetPrivateField<PlanterUI>("_myMachineRef", __instance)).Get();
			if (((ResourceInfo)((PlanterInstance)(ref val)).myDef).displayName == "Planter MKIII")
			{
				Debug.Log((object)$"Opened Mk3 Planter: {val.commonInfo.instanceId}");
				PlanterMk3GUI.currentPlanter = val;
				PlanterMk3GUI.buttonStates = new bool[4, 3];
				PlanterMk3GUI.shouldShowGUI = true;
			}
		}

		[HarmonyPatch(typeof(PlanterUI), "OnClose")]
		[HarmonyPostfix]
		private static void HidePlantMk3GUI()
		{
			PlanterMk3GUI.shouldShowGUI = false;
			Debug.Log((object)"Hid Planter Mk3 GUI");
		}
	}
	internal class SaveStatePatch
	{
		[HarmonyPatch(typeof(SaveState), "SaveToFile")]
		[HarmonyPostfix]
		private static void SavePlanterExtensions()
		{
			MorePlantersPlugin.SaveData(SaveState.instance.metadata.worldName);
		}
	}
}