Decompiled source of Botanerranean v1.0.0

Botanerranean.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using EquinoxsModUtils;
using EquinoxsModUtils.Additions;
using HarmonyLib;
using PropStreaming;
using ReikaKalseki.DIANEXCAL;
using UnityEngine;

[assembly: TargetFramework(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace ReikaKalseki.Botanerranean;

[BepInPlugin("ReikaKalseki.Botanerranean", "Botanerranean", "1.0.0")]
public class BotanerraneanMod : BaseUnityPlugin
{
	public static BotanerraneanMod instance;

	private static CoreBoostTech planterCoreTech;

	private static CoreBoostTech seedYieldCoreTech;

	internal static CustomTech[] seedYieldBoostTechs;

	private static CustomTech t3PlanterTech;

	private static CustomTech seedPlantmatterTech;

	private static CustomTech seedCarbonTech;

	private static CustomMachine<PlanterInstance, PlanterDefinition> t3Planter;

	private static ResourceInfo t2Planter;

	private static CustomRecipe kindlevineSeedBlasting;

	private static CustomRecipe shiverthornSeedBlasting;

	private static CustomRecipe kindlevineSeedSmelting;

	private static CustomRecipe shiverthornSeedSmelting;

	private static SeedYieldTech.TechLevel[] techLevels;

	public static SchematicsRecipeData planter2Recipe;

	public static SchematicsRecipeData planter3Recipe;

	public static readonly Assembly modDLL = Assembly.GetExecutingAssembly();

	public static readonly Config<BTConfig.ConfigEntries> config = new Config<BTConfig.ConfigEntries>(modDLL);

	private static readonly Dictionary<string, NewRecipeDetails> seedRecipes = new Dictionary<string, NewRecipeDetails>();

	public static float globalPlanterSpeedFactor = 1f;

	public BotanerraneanMod()
	{
		instance = this;
		TTUtil.log("Constructed BT mod object", (Assembly)null, 0);
	}

	public void Awake()
	{
		//IL_003a: 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_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Expected O, but got Unknown
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: 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_01ce: Expected O, but got Unknown
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Expected O, but got Unknown
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Expected O, but got Unknown
		//IL_033b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		//IL_037c: Expected O, but got Unknown
		TTUtil.log("Begin Initializing Botanerranean", (Assembly)null, 0);
		try
		{
			config.load(false);
			techLevels = new SeedYieldTech.TechLevel[3]
			{
				new SeedYieldTech.TechLevel(1, (CoreType)0, 150, config.getInt(BTConfig.ConfigEntries.SEED1EFFECT), TTUtil.getTierAtStation((ProductionTerminal)1, 1), (TechColumns)20),
				new SeedYieldTech.TechLevel(2, (CoreType)2, 80, config.getInt(BTConfig.ConfigEntries.SEED2EFFECT), TTUtil.getTierAtStation((ProductionTerminal)1, 5), (TechColumns)20),
				new SeedYieldTech.TechLevel(3, (CoreType)2, 160, config.getInt(BTConfig.ConfigEntries.SEED3EFFECT), TTUtil.getTierAtStation((ProductionTerminal)2, 1), (TechColumns)100)
			};
			Harmony val = new Harmony("Botanerranean");
			Harmony.DEBUG = true;
			FileLog.logPath = Path.Combine(Path.GetDirectoryName(modDLL.Location), "harmony-log_" + Path.GetFileName(Assembly.GetExecutingAssembly().Location) + ".txt");
			FileLog.Log("Ran mod register, started harmony (harmony log)");
			TTUtil.log("Ran mod register, started harmony", (Assembly)null, 0);
			try
			{
				val.PatchAll(modDLL);
			}
			catch (Exception ex)
			{
				FileLog.Log("Caught exception when running patchers!");
				FileLog.Log(ex.Message);
				FileLog.Log(ex.StackTrace);
				FileLog.Log(ex.ToString());
			}
			t3Planter = new CustomMachine<PlanterInstance, PlanterDefinition>("Planter MKIII", "Grows plants at quadruple the speed of the MK1 planter [this desc should be replaced].", "PlanterT3", "Planter MKII", "Planter MKII");
			((NewRecipeDetails)t3Planter.addRecipe(1)).ingredients = new List<RecipeResourceInfo>
			{
				new RecipeResourceInfo
				{
					name = "Planter MKII",
					quantity = 1
				}
			};
			t3PlanterTech = t3Planter.createUnlock((TechCategory)1, (CoreType)3, 100);
			t3Planter.register();
			planterCoreTech = new CoreBoostTech(config.getInt(BTConfig.ConfigEntries.PLANTERCOREEFFECT), (CoreType)2, 100, (string)null);
			planterCoreTech.setText("Planter", "speed of all Planters");
			((CustomTech)planterCoreTech).setPosition(TTUtil.getTierAtStation((ProductionTerminal)3, 6), (TechColumns)60);
			((CustomTech)planterCoreTech).setSprite("Planter", true);
			((CustomTech)planterCoreTech).register();
			seedYieldBoostTechs = (CustomTech[])(object)new CustomTech[techLevels.Length];
			for (int i = 0; i < seedYieldBoostTechs.Length; i++)
			{
				seedYieldBoostTechs[i] = (CustomTech)(object)new SeedYieldTech(techLevels[i]);
				seedYieldBoostTechs[i].register();
			}
			seedYieldCoreTech = new CoreBoostTech(config.getInt(BTConfig.ConfigEntries.SEEDCOREEFFECT), (CoreType)1, 100, "Core Boost (Threshing)");
			seedYieldCoreTech.setText("Threshing Seed Yield", "seed yield from threshing");
			((CustomTech)seedYieldCoreTech).setPosition(TTUtil.getTierAtStation((ProductionTerminal)3, 6), (TechColumns)100);
			((CustomTech)seedYieldCoreTech).setSprite("Kindlevine Seed", true);
			((CustomTech)seedYieldCoreTech).register();
			kindlevineSeedSmelting = makeSeedToPlantmatterAndCarbon("Kindlevine Seed", 1.5f);
			shiverthornSeedSmelting = makeSeedToPlantmatterAndCarbon("Shiverthorn Seed", 0.5f);
			kindlevineSeedBlasting = (CustomRecipe)(object)new SeedBlastingRecipe(kindlevineSeedSmelting);
			shiverthornSeedBlasting = (CustomRecipe)(object)new SeedBlastingRecipe(shiverthornSeedSmelting);
			kindlevineSeedBlasting.register();
			shiverthornSeedBlasting.register();
			seedPlantmatterTech = new CustomTech((TechCategory)1, "Seed Recycling I", "Reusing surplus seeds.", (CoreType)0, 50);
			seedPlantmatterTech.setPosition(TTUtil.getTierAtStation((ProductionTerminal)1, 4), (TechColumns)40);
			seedPlantmatterTech.setSprite("SeedPlantmatter", false);
			seedPlantmatterTech.register();
			seedCarbonTech = new CustomTech((TechCategory)1, "Seed Recycling II", "A more lucrative use for surplus seeds.", (CoreType)2, 20);
			seedCarbonTech.setSprite("SeedToCarbon", false);
			seedCarbonTech.finalFixes = delegate
			{
				//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_004d: Unknown result type (might be due to invalid IL or missing references)
				TTUtil.log("Adjusting " + ((NewUnlockDetails)seedCarbonTech).displayName, (Assembly)null, 0);
				Unlock unlock = TTUtil.getUnlock("Carbon Powder", true);
				Unlock unlock2 = seedCarbonTech.unlock;
				unlock2.treePosition = unlock.treePosition;
				unlock2.requiredTier = TTUtil.getTierAfter(unlock.requiredTier, 1);
				unlock2.dependency1 = unlock;
				unlock2.dependency2 = seedPlantmatterTech.unlock;
				unlock2.dependencies = new List<Unlock> { unlock2.dependency1, unlock2.dependency2 };
			};
			seedCarbonTech.setRecipes((CustomRecipe[])(object)new CustomRecipe[4] { kindlevineSeedSmelting, shiverthornSeedSmelting, kindlevineSeedBlasting, shiverthornSeedBlasting });
			seedCarbonTech.register();
			DIMod.onDefinesLoadedFirstTime += onDefinesLoaded;
			DIMod.onTechsLoadedFirstTime += onTechsLoaded;
			DIMod.onRecipesLoaded += onRecipesLoaded;
		}
		catch (Exception ex2)
		{
			TTUtil.log("Failed to load Botanerranean: " + ex2, (Assembly)null, 0);
		}
		TTUtil.log("Finished Initializing Botanerranean", (Assembly)null, 0);
	}

	private static void onDefinesLoaded()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: 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)
		//IL_005b: 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)
		//IL_0078: 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_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		TTUtil.log("Copying PlanterMKII data to MKIII", (Assembly)null, 0);
		Unlock unlock = TTUtil.getUnlock("Planter MKII", true);
		Unlock unlock2 = TTUtil.getUnlock("Planter MKIII", true);
		unlock2.requiredTier = unlock.requiredTier;
		unlock2.treePosition = unlock.treePosition;
		unlock2.coresNeeded.Clear();
		unlock2.coresNeeded.Add(new RequiredCores
		{
			type = (CoreType)1,
			number = unlock.coresNeeded[0].number
		});
		unlock2.dependencies = new List<Unlock>(unlock.dependencies);
		unlock2.dependencies.Add(unlock);
		unlock2.dependency1 = unlock.dependency1;
		unlock2.dependency2 = unlock.dependency2;
		unlock2.numScansNeeded = 0;
		TTUtil.log("Moving PlanterMKII tech", (Assembly)null, 0);
		Unlock unlock3 = TTUtil.getUnlock("Thresher MKII", true);
		unlock.requiredTier = TTUtil.getTierAtStation((ProductionTerminal)1, 2);
		unlock.treePosition = TTUtil.getUnlock("Assembler MKII", true).treePosition;
		unlock.coresNeeded.Clear();
		unlock.coresNeeded.Add(new RequiredCores
		{
			type = (CoreType)2,
			number = 50
		});
		unlock.dependencies = new List<Unlock> { unlock3 };
		unlock.dependency1 = unlock3.dependency1;
		unlock.dependency2 = unlock3.dependency2;
		t2Planter = Resources.GetResourceInfoByName("Planter MKII", false);
		((NewResourceDetails)t3Planter.item).description = t2Planter.description.Replace("rapid", "extremely fast");
		DIExtensions.setDescription(unlock2, ((NewResourceDetails)t3Planter.item).description);
	}

	private static void onRecipesLoaded()
	{
		planter2Recipe = TTUtil.getRecipesByOutput("Planter MKII")[0];
		planter3Recipe = TTUtil.getRecipesByOutput(t3Planter.name)[0];
		planter3Recipe.ingTypes = (ResourceInfo[])(object)new ResourceInfo[planter2Recipe.ingTypes.Length];
		for (int i = 0; i < planter3Recipe.ingTypes.Length; i++)
		{
			planter3Recipe.ingTypes[i] = planter2Recipe.ingTypes[i];
			if (((UniqueIdScriptableObject)planter3Recipe.ingTypes[i]).uniqueId == Resources.GetResourceIDByName("Planter", false))
			{
				planter3Recipe.ingTypes[i] = Resources.GetResourceInfoByName("Planter MKII", false);
			}
		}
		planter3Recipe.ingQuantities = new int[planter2Recipe.ingQuantities.Length];
		planter3Recipe.duration = planter2Recipe.duration * 4f;
		Array.Copy(planter2Recipe.ingQuantities, planter3Recipe.ingQuantities, planter3Recipe.ingQuantities.Length);
		TTUtil.compileRecipe(planter3Recipe);
		TTUtil.setIngredients(planter2Recipe, new object[6] { "Planter", 2, "Steel Frame", 1, "Advanced Circuit", 15 });
	}

	private static void onTechsLoaded()
	{
		TTUtil.setUnlockRecipes("Planter MKII", (SchematicsRecipeData[])(object)new SchematicsRecipeData[1] { planter2Recipe });
		TTUtil.setUnlockRecipes(t3Planter.name, (SchematicsRecipeData[])(object)new SchematicsRecipeData[1] { planter3Recipe });
		seedPlantmatterTech.setRecipes(TTUtil.getRecipes((Predicate<SchematicsRecipeData>)isSeedRecycling).ToArray());
	}

	private static bool isSeedRecycling(SchematicsRecipeData rec)
	{
		if ((Object)(object)rec == (Object)null)
		{
			return false;
		}
		if (rec.ingTypes == null || (Object)(object)rec.ingTypes[0] == (Object)null || rec.outputTypes == null || (Object)(object)rec.outputTypes[0] == (Object)null)
		{
			TTUtil.log("Invalid recipe " + DIExtensions.toDebugString(rec), (Assembly)null, 0);
			return false;
		}
		return rec.ingTypes.Length == 1 && TTUtil.isSeed(rec.ingTypes[0]) && rec.outputTypes.Length == 1 && ((UniqueIdScriptableObject)rec.outputTypes[0]).uniqueId == Resources.GetResourceIDByName("Plantmatter", false);
	}

	private static CustomRecipe makeSeedToPlantmatterAndCarbon(string name, float relativeValue = 1f)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected O, but got Unknown
		//IL_00d9: 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_010b: 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)
		CustomRecipe val = new CustomRecipe(name + "_To_Plantmatter", (CraftingMethod)0);
		((NewRecipeDetails)val).duration = 2f;
		((NewRecipeDetails)val).unlockName = "";
		((NewRecipeDetails)val).ingredients = new List<RecipeResourceInfo>
		{
			new RecipeResourceInfo
			{
				name = name,
				quantity = 1
			}
		};
		((NewRecipeDetails)val).outputs = new List<RecipeResourceInfo>
		{
			new RecipeResourceInfo
			{
				name = "Plantmatter",
				quantity = DIExtensions.multiplyBy(6, (double)(relativeValue * config.getFloat(BTConfig.ConfigEntries.SEEDPLANTMATTERRATIO1)))
			}
		};
		val.register();
		CustomRecipe val2 = new CustomRecipe(name + "_To_Carbon", (CraftingMethod)2);
		((NewRecipeDetails)val2).duration = 15f;
		((NewRecipeDetails)val2).unlockName = "";
		((NewRecipeDetails)val2).ingredients = new List<RecipeResourceInfo>
		{
			new RecipeResourceInfo
			{
				name = name,
				quantity = 10
			}
		};
		((NewRecipeDetails)val2).outputs = new List<RecipeResourceInfo>
		{
			new RecipeResourceInfo
			{
				name = "Carbon Powder",
				quantity = FHG_Utils.FloorToInt(10f * relativeValue * config.getFloat(BTConfig.ConfigEntries.SEEDPLANTMATTERRATIO2))
			}
		};
		val2.register();
		return val2;
	}

	public static bool tickPlantSlot(ref PlantSlot slot, float increment, ref PlanterInstance owner)
	{
		return ((PlantSlot)(ref slot)).UpdateGrowth(increment * getPlanterSpeed(ref owner));
	}

	public static float getPlanterGrowthTimeForUI(float val, ref PlanterInstance pi)
	{
		return val / getPlanterSpeed(ref pi);
	}

	private static float getPlanterSpeed(ref PlanterInstance pi)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		float num = globalPlanterSpeedFactor;
		num *= 1f + planterCoreTech.currentEffect;
		if (t3Planter != null && t3Planter.isThisMachine((IMachineInstance<PlanterInstance, PlanterDefinition>)(object)pi))
		{
			num *= 4f;
		}
		return num;
	}

	public static void initializePlanterSettings(PlanterDefinition def)
	{
		if (t3Planter.isThisMachine((MachineDefinition<PlanterInstance, PlanterDefinition>)(object)def))
		{
			((BuilderInfo)def).runtimePowerSettings.kWPowerConsumption = ((BuilderInfo)def).runtimePowerSettings.kWPowerConsumption * 75 / 35;
			TTUtil.log("Set " + DIExtensions.toDebugString<PlanterInstance, PlanterDefinition>((MachineDefinition<PlanterInstance, PlanterDefinition>)(object)def) + " power cost to " + ((RuntimePowerSettings)(ref ((BuilderInfo)def).runtimePowerSettings)).GetPowerConsumption(), (Assembly)null, 0);
		}
		else if (((ResourceInfo)def).displayName.EndsWith("MKII", StringComparison.InvariantCultureIgnoreCase))
		{
			((BuilderInfo)def).runtimePowerSettings.kWPowerConsumption = ((BuilderInfo)def).runtimePowerSettings.kWPowerConsumption * 5 / 7;
			TTUtil.log("Set " + DIExtensions.toDebugString<PlanterInstance, PlanterDefinition>((MachineDefinition<PlanterInstance, PlanterDefinition>)(object)def) + " power cost to " + ((RuntimePowerSettings)(ref ((BuilderInfo)def).runtimePowerSettings)).GetPowerConsumption(), (Assembly)null, 0);
		}
		else if (((ResourceInfo)def).displayName == "Planter")
		{
			((BuilderInfo)def).runtimePowerSettings.kWPowerConsumption = DIExtensions.multiplyBy(((BuilderInfo)def).runtimePowerSettings.kWPowerConsumption, 0.4);
			TTUtil.log("Set " + DIExtensions.toDebugString<PlanterInstance, PlanterDefinition>((MachineDefinition<PlanterInstance, PlanterDefinition>)(object)def) + " power cost to " + ((RuntimePowerSettings)(ref ((BuilderInfo)def).runtimePowerSettings)).GetPowerConsumption(), (Assembly)null, 0);
		}
	}

	public static void initializeThresherSettings(ThresherDefinition def)
	{
		if (((ResourceInfo)def).displayName == "Thresher")
		{
			((BuilderInfo)def).runtimePowerSettings.kWPowerConsumption = DIExtensions.multiplyBy(((BuilderInfo)def).runtimePowerSettings.kWPowerConsumption, 0.375);
			TTUtil.log("Set " + DIExtensions.toDebugString<ThresherInstance, ThresherDefinition>((MachineDefinition<ThresherInstance, ThresherDefinition>)(object)def) + " power cost to " + ((RuntimePowerSettings)(ref ((BuilderInfo)def).runtimePowerSettings)).GetPowerConsumption(), (Assembly)null, 0);
		}
		else if (((ResourceInfo)def).displayName.EndsWith("MKII", StringComparison.InvariantCultureIgnoreCase))
		{
			((BuilderInfo)def).runtimePowerSettings.kWPowerConsumption = DIExtensions.multiplyBy(((BuilderInfo)def).runtimePowerSettings.kWPowerConsumption, 0.625);
			TTUtil.log("Set " + DIExtensions.toDebugString<ThresherInstance, ThresherDefinition>((MachineDefinition<ThresherInstance, ThresherDefinition>)(object)def) + " power cost to " + ((RuntimePowerSettings)(ref ((BuilderInfo)def).runtimePowerSettings)).GetPowerConsumption(), (Assembly)null, 0);
		}
	}

	internal static SeedYieldTech.TechLevel getHighestSeedTechLevelUnlocked()
	{
		for (int num = seedYieldBoostTechs.Length - 1; num >= 0; num--)
		{
			if (seedYieldBoostTechs[num].isUnlocked)
			{
				return techLevels[num];
			}
		}
		return null;
	}

	public static int getThresherItemYield(int amt, int index, ref ThresherInstance machine)
	{
		SchematicsRecipeData curSchematic = machine.curSchematic;
		if (amt == 1 && TTUtil.isSeed(curSchematic.outputTypes[index]))
		{
			BTConfig.ConfigEntries configEntries = (((Object)machine._myDef).name.EndsWith("_2", StringComparison.InvariantCultureIgnoreCase) ? BTConfig.ConfigEntries.THRESHER2BONUSBASE : BTConfig.ConfigEntries.THRESHER1BONUSBASE);
			float @float = config.getFloat(configEntries);
			@float += seedYieldCoreTech.currentEffect;
			SeedYieldTech.TechLevel highestSeedTechLevelUnlocked = getHighestSeedTechLevelUnlocked();
			if (highestSeedTechLevelUnlocked != null)
			{
				@float += (float)highestSeedTechLevelUnlocked.yieldBoost;
			}
			if (Random.Range(0f, 1f) < @float)
			{
				amt++;
			}
		}
		return amt;
	}

	public static void restoreAllFlora()
	{
		SaveState.instance.voxeland.destroyedProps.RemoveAll((InstanceLookup inst) => false);
	}

	public static void onProdTerminalResourceUpdate(ref ResourceRequirementData[] arr, GatedDoorConfiguration cfg)
	{
		if ((Object)(object)cfg == (Object)null)
		{
			return;
		}
		TTUtil.log("onProdTerminalResourceUpdate for " + ((Object)cfg).name, (Assembly)null, 0);
		if (cfg.reqTypes == null)
		{
			TTUtil.log("Null reqs!!", (Assembly)null, 0);
			return;
		}
		for (int i = 0; i < cfg.reqTypes.Length; i++)
		{
			ResourceInfo val = cfg.reqTypes[i];
			TTUtil.log("Checking " + DIExtensions.toDebugString(val), (Assembly)null, 0);
			bool flag = false;
			if ((Object)(object)val != (Object)null && ((UniqueIdScriptableObject)val).uniqueId == ((UniqueIdScriptableObject)t2Planter).uniqueId)
			{
				CustomItem item = t3Planter.item;
				if (item == null)
				{
					throw new Exception("No such item to add to production terminal to replace '" + DIExtensions.toDebugString(val) + "'!");
				}
				if ((Object)(object)item.item.rawSprite == (Object)null)
				{
					throw new Exception("Item " + DIExtensions.toDebugString(item.item) + " not valid for production terminal, has no sprite!");
				}
				cfg.reqTypes[i] = item.item;
				TTUtil.log("Replaced planter 2 with 3 in PT " + ((Object)cfg).name, (Assembly)null, 0);
				flag = true;
				break;
			}
		}
		TTUtil.log("Finished replacing production terminal resources " + DIExtensions.toDebugString<string>(cfg.reqTypes.Select((ResourceInfo res) => DIExtensions.toDebugString(res))) + " => " + DIExtensions.toDebugString<string>(arr.Select((ResourceRequirementData res) => DIExtensions.toDebugString(res.resType))), (Assembly)null, 0);
	}
}
public class BTConfig
{
	public enum ConfigEntries
	{
		[ConfigEntry("Seed Yield I Effect", typeof(int), 5f, 1f, 10f, float.NaN)]
		SEED1EFFECT,
		[ConfigEntry("Seed Yield II Effect", typeof(int), 10f, 5f, 50f, float.NaN)]
		SEED2EFFECT,
		[ConfigEntry("Seed Yield III Effect", typeof(int), 25f, 10f, 100f, float.NaN)]
		SEED3EFFECT,
		[ConfigEntry("Planter Core Boost Effect", typeof(int), 5f, 1f, 50f, float.NaN)]
		PLANTERCOREEFFECT,
		[ConfigEntry("Seed Yield Core Boost Effect", typeof(int), 5f, 1f, 50f, float.NaN)]
		SEEDCOREEFFECT,
		[ConfigEntry("Seed Recycling I Yield Scalar", typeof(float), 1f, 0f, 5f, float.NaN)]
		SEEDPLANTMATTERRATIO1,
		[ConfigEntry("Seed Recycling II Yield Scalar", typeof(float), 1f, 0f, 5f, float.NaN)]
		SEEDPLANTMATTERRATIO2,
		[ConfigEntry("Thresher I Base Extra Seed Yield Chance", typeof(float), 1f, 0f, 5f, float.NaN)]
		THRESHER1BONUSBASE,
		[ConfigEntry("Thresher II Base Extra Seed Yield Chance", typeof(float), 2.5f, 0f, 10f, float.NaN)]
		THRESHER2BONUSBASE
	}
}
public static class Patches
{
	[HarmonyPatch(typeof(PlanterInstance))]
	[HarmonyPatch("SimUpdate")]
	public static class PlanterSpeedHook
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			try
			{
				int methodCallByName = InstructionHandlers.getMethodCallByName(list, 0, 0, "PlanterInstance+PlantSlot", "UpdateGrowth");
				list[methodCallByName] = InstructionHandlers.createMethodCall("ReikaKalseki.Botanerranean.BotanerraneanMod", "tickPlantSlot", false, new Type[3]
				{
					typeof(PlantSlot).MakeByRefType(),
					typeof(float),
					typeof(PlanterInstance).MakeByRefType()
				});
				list.Insert(methodCallByName, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
				FileLog.Log("Done patch " + MethodBase.GetCurrentMethod().DeclaringType);
			}
			catch (Exception ex)
			{
				FileLog.Log(string.Concat("Caught exception when running patch ", MethodBase.GetCurrentMethod().DeclaringType, "!"));
				FileLog.Log(ex.Message);
				FileLog.Log(ex.StackTrace);
				FileLog.Log(ex.ToString());
			}
			return list.AsEnumerable();
		}
	}

	[HarmonyPatch("UpdateSlots")]
	[HarmonyPatch(typeof(PlanterInspectorItem))]
	public static class PlanterSpeedUIHook
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			try
			{
				int instruction = InstructionHandlers.getInstruction(list, 0, 0, OpCodes.Ldfld, new object[2] { "PlanterInstance+PlantSlot", "totalGrowthDuration" });
				list.InsertRange(instruction + 1, new List<CodeInstruction>
				{
					new CodeInstruction(OpCodes.Ldarg_1, (object)null),
					InstructionHandlers.createMethodCall("ReikaKalseki.Botanerranean.BotanerraneanMod", "getPlanterGrowthTimeForUI", false, new Type[2]
					{
						typeof(float),
						typeof(PlanterInstance).MakeByRefType()
					})
				});
				FileLog.Log("Done patch " + MethodBase.GetCurrentMethod().DeclaringType);
			}
			catch (Exception ex)
			{
				FileLog.Log(string.Concat("Caught exception when running patch ", MethodBase.GetCurrentMethod().DeclaringType, "!"));
				FileLog.Log(ex.Message);
				FileLog.Log(ex.StackTrace);
				FileLog.Log(ex.ToString());
			}
			return list.AsEnumerable();
		}
	}

	[HarmonyPatch(typeof(PlanterDefinition))]
	[HarmonyPatch("InitOverrideSettings")]
	public static class PlanterPowerHook
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			try
			{
				InstructionHandlers.patchEveryReturnPre(list, (CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					InstructionHandlers.createMethodCall("ReikaKalseki.Botanerranean.BotanerraneanMod", "initializePlanterSettings", false, new Type[1] { typeof(PlanterDefinition) })
				});
				FileLog.Log("Done patch " + MethodBase.GetCurrentMethod().DeclaringType);
			}
			catch (Exception ex)
			{
				FileLog.Log(string.Concat("Caught exception when running patch ", MethodBase.GetCurrentMethod().DeclaringType, "!"));
				FileLog.Log(ex.Message);
				FileLog.Log(ex.StackTrace);
				FileLog.Log(ex.ToString());
			}
			return list.AsEnumerable();
		}
	}

	[HarmonyPatch(typeof(ThresherDefinition))]
	[HarmonyPatch("InitOverrideSettings")]
	public static class ThresherPowerHook
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			try
			{
				InstructionHandlers.patchEveryReturnPre(list, (CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					InstructionHandlers.createMethodCall("ReikaKalseki.Botanerranean.BotanerraneanMod", "initializeThresherSettings", false, new Type[1] { typeof(ThresherDefinition) })
				});
				FileLog.Log("Done patch " + MethodBase.GetCurrentMethod().DeclaringType);
			}
			catch (Exception ex)
			{
				FileLog.Log(string.Concat("Caught exception when running patch ", MethodBase.GetCurrentMethod().DeclaringType, "!"));
				FileLog.Log(ex.Message);
				FileLog.Log(ex.StackTrace);
				FileLog.Log(ex.ToString());
			}
			return list.AsEnumerable();
		}
	}

	[HarmonyPatch(typeof(ThresherInstance))]
	[HarmonyPatch("UpdateCrafting")]
	public static class ThresherSeedYield
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			try
			{
				int instruction = InstructionHandlers.getInstruction(list, 0, 0, OpCodes.Ldfld, new object[2] { "SchematicsRecipeData", "outputQuantities" });
				instruction = InstructionHandlers.getFirstOpcode(list, instruction, OpCodes.Stloc_3);
				list.InsertRange(instruction, new List<CodeInstruction>
				{
					new CodeInstruction(OpCodes.Ldloc_1, (object)null),
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					InstructionHandlers.createMethodCall("ReikaKalseki.Botanerranean.BotanerraneanMod", "getThresherItemYield", false, new Type[3]
					{
						typeof(int),
						typeof(int),
						typeof(ThresherInstance).MakeByRefType()
					})
				});
				FileLog.Log("Done patch " + MethodBase.GetCurrentMethod().DeclaringType);
			}
			catch (Exception ex)
			{
				FileLog.Log(string.Concat("Caught exception when running patch ", MethodBase.GetCurrentMethod().DeclaringType, "!"));
				FileLog.Log(ex.Message);
				FileLog.Log(ex.StackTrace);
				FileLog.Log(ex.ToString());
			}
			return list.AsEnumerable();
		}
	}
}
public class SeedBlastingRecipe : CustomRecipe
{
	private static readonly float BLASTING_EFFICIENCY_FACTOR;

	private static readonly Dictionary<string, SeedBlastingRecipe> recipeItems;

	private static int carbonPowderID;

	private static int carbonPowderBrickID;

	private static float powderPerBrick;

	public readonly CustomRecipe basicRecipe;

	public string sourceItem => ((NewRecipeDetails)basicRecipe).ingredients[0].name;

	static SeedBlastingRecipe()
	{
		BLASTING_EFFICIENCY_FACTOR = 3.5f;
		recipeItems = new Dictionary<string, SeedBlastingRecipe>();
		DIMod.onDefinesLoadedFirstTime += delegate
		{
			carbonPowderID = Resources.GetResourceIDByName("Carbon Powder", false);
			carbonPowderBrickID = Resources.GetResourceIDByName("Carbon Powder Brick", false);
		};
		DIMod.onRecipesLoaded += delegate
		{
			SchematicsRecipeData recipe = TTUtil.getRecipe((Predicate<SchematicsRecipeData>)isPowderToBrick);
			powderPerBrick = (float)DIExtensions.getCost(recipe, carbonPowderID) / (4f * (float)DIExtensions.getYield(recipe, carbonPowderBrickID));
			TTUtil.log("Computed powder per brick ratio of " + powderPerBrick.ToString("0.00"), (Assembly)null, 0);
		};
	}

	private static bool isPowderToBrick(SchematicsRecipeData rec)
	{
		return rec.ingTypes.Length == 1 && ((UniqueIdScriptableObject)rec.ingTypes[0]).uniqueId == carbonPowderID && rec.outputTypes.Length == 1 && ((UniqueIdScriptableObject)rec.outputTypes[0]).uniqueId == carbonPowderBrickID;
	}

	internal SeedBlastingRecipe(CustomRecipe smeltingReference)
		: base(((NewRecipeDetails)smeltingReference).GUID + "_to_brick", (CraftingMethod)4)
	{
		//IL_0044: 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_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		basicRecipe = smeltingReference;
		recipeItems[((NewRecipeDetails)basicRecipe).GUID] = this;
		((NewRecipeDetails)this).ingredients = new List<RecipeResourceInfo>
		{
			new RecipeResourceInfo
			{
				name = sourceItem,
				quantity = 1
			}
		};
		((NewRecipeDetails)this).outputs = new List<RecipeResourceInfo>
		{
			new RecipeResourceInfo
			{
				name = "Carbon Powder Brick",
				quantity = 1
			}
		};
		Action finalFixes = delegate
		{
			((CustomRecipe)this).recipe.ingQuantities[0] = computeCost(basicRecipe);
			((CustomRecipe)this).recipe.runtimeIngQuantities[0] = ((CustomRecipe)this).recipe.ingQuantities[0];
			TTUtil.log("Computed seed cost of " + ((CustomRecipe)this).recipe.ingQuantities[0] + " for " + DIExtensions.toDebugString(((CustomRecipe)this).recipe), (Assembly)null, 0);
			if (((CustomRecipe)this).recipe.ingQuantities[0] > Resources.GetResourceInfoByName(sourceItem, false).maxStackCount)
			{
				TTUtil.log("Over max stack size!", (Assembly)null, 0);
			}
		};
		base.finalFixes = finalFixes;
	}

	private static int computeCost(CustomRecipe from)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		float num = (float)((NewRecipeDetails)from).ingredients[0].quantity / (float)((NewRecipeDetails)from).outputs[0].quantity;
		return MathUtil.roundUpToX(FHG_Utils.CeilToInt(num * powderPerBrick / BLASTING_EFFICIENCY_FACTOR), 5);
	}
}
public class SeedYieldTech : CustomTech
{
	internal class TechLevel
	{
		public readonly int level;

		public readonly ResearchTier ptTier;

		public readonly TechColumns column;

		public readonly CoreType coreType;

		public readonly int coreCount;

		public readonly int yieldBoost;

		public string description => "Increases seed yield from threshing by " + yieldBoost + "%.";

		internal TechLevel(int l, CoreType c, int cc, int f, ResearchTier tt, TechColumns col = 20)
		{
			//IL_0010: 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_0026: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			level = l;
			coreType = c;
			coreCount = cc;
			yieldBoost = f;
			ptTier = tt;
			column = col;
		}

		public override string ToString()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			return $"[TechLevel Level={level}, CoreType={coreType}, CoreCount={coreCount}, Yield+={yieldBoost}]";
		}
	}

	private static readonly Dictionary<int, SeedYieldTech> levels = new Dictionary<int, SeedYieldTech>();

	internal SeedYieldTech(TechLevel t)
		: base((TechCategory)1, "Seed Yield " + RomanNumeral.getRomanNumeral(t.level), t.description, t.coreType, t.coreCount)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		levels[t.level] = this;
		((CustomTech)this).setPosition(t.ptTier, t.column);
		((CustomTech)this).setSprite("Kindlevine Seed", true);
		if (t.level > 1)
		{
			((CustomTech)this).setDependencies((CustomTech)(object)levels[t.level - 1], (CustomTech)null);
		}
	}
}