Decompiled source of AdvancedMachines v2.4.2

AdvancedMachines.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EquinoxsModUtils;
using EquinoxsModUtils.Additions;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TechtonicaFramework.TechTree;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("AdvancedMachines")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f49145fbf9f44c78c3aba4e59c2566758d964b82")]
[assembly: AssemblyProduct("AdvancedMachines")]
[assembly: AssemblyTitle("AdvancedMachines")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 AdvancedMachines
{
	[BepInPlugin("com.certifired.AdvancedMachines", "AdvancedMachines", "2.4.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class AdvancedMachinesPlugin : BaseUnityPlugin
	{
		private const string MyGUID = "com.certifired.AdvancedMachines";

		private const string PluginName = "AdvancedMachines";

		private const string VersionString = "2.4.2";

		private static readonly Harmony Harmony = new Harmony("com.certifired.AdvancedMachines");

		public static ManualLogSource Log;

		public const string SmelterMk4Name = "Smelter MKIV";

		public const string SmelterMk5Name = "Smelter MKV";

		public const string AssemblerMk3Name = "Assembler MKIII";

		public const string AssemblerMk4Name = "Assembler MKIV";

		public const string DrillMk3Name = "Mining Drill MKIII";

		public const string DrillMk4Name = "Mining Drill MKIV";

		public const string ThresherMk3Name = "Thresher MKIII";

		public const string ThresherMk4Name = "Thresher MKIV";

		public const string ThresherMk5Name = "Thresher MKV";

		public const string PlanterMk4Name = "Planter MKIV";

		public const string PlanterMk5Name = "Planter MKV";

		public static ConfigEntry<bool> EnableHiddenVariants;

		public static ConfigEntry<bool> EnableTier4Machines;

		public static ConfigEntry<bool> EnableTier5Machines;

		private const float Tier4SpeedMult = 2f;

		private const float Tier5SpeedMult = 3f;

		private const float Tier4PowerMult = 1.5f;

		private const float Tier5PowerMult = 2f;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"PluginName: AdvancedMachines, VersionString: 2.4.2 is loading...");
			EnableHiddenVariants = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Hidden Variants", true, "Unlock all hidden machine variants");
			EnableTier4Machines = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Tier 4 Machines", true, "Add Tier 4 (MK IV) versions of machines");
			EnableTier5Machines = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Tier 5 Machines", true, "Add Tier 5 (MK V) versions of machines");
			Harmony.PatchAll();
			if (EnableTier4Machines.Value)
			{
				RegisterTier4Machines();
			}
			if (EnableTier5Machines.Value)
			{
				RegisterTier5Machines();
			}
			Events.GameDefinesLoaded += OnGameDefinesLoaded;
			Events.TechTreeStateLoaded += OnTechTreeStateLoaded;
			Log.LogInfo((object)"PluginName: AdvancedMachines, VersionString: 2.4.2 is loaded.");
		}

		private void RegisterTier4Machines()
		{
			//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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0073: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: 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_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: 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_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: 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_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: 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_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Expected O, but got Unknown
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: 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_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Expected O, but got Unknown
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: 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_03b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Expected O, but got Unknown
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0482: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0506: Unknown result type (might be due to invalid IL or missing references)
			//IL_0511: Unknown result type (might be due to invalid IL or missing references)
			//IL_0519: Unknown result type (might be due to invalid IL or missing references)
			//IL_0521: Unknown result type (might be due to invalid IL or missing references)
			//IL_052c: Unknown result type (might be due to invalid IL or missing references)
			//IL_053d: Expected O, but got Unknown
			//IL_0550: Unknown result type (might be due to invalid IL or missing references)
			//IL_0563: Unknown result type (might be due to invalid IL or missing references)
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			RegisterUnlock("Smelter MKIV", (TechCategory)1, (CoreType)3, 500, "Advanced smelter with 2x processing speed.", (ResearchTier)16384);
			SmelterDefinition val = ScriptableObject.CreateInstance<SmelterDefinition>();
			val.craftingEfficiency = 2f;
			val.usesFuel = true;
			val.fuelConsumptionRate = 0.5f;
			EMUAdditions.AddNewMachine<SmelterInstance, SmelterDefinition>((MachineDefinition<SmelterInstance, SmelterDefinition>)(object)val, new NewResourceDetails
			{
				name = "Smelter MKIV",
				description = $"High-performance smelter with {2f}x processing speed. Requires more power but processes ores faster.",
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				headerTitle = "Modded",
				maxStackCount = 50,
				sortPriority = 100,
				unlockName = "Smelter MKIV",
				parentName = "Smelter MKIII"
			}, false);
			RegisterRecipe("Smelter MKIV", new List<RecipeResourceInfo>
			{
				new RecipeResourceInfo("Smelter MKIII", 2),
				new RecipeResourceInfo("Steel Frame", 10),
				new RecipeResourceInfo("Processor Unit", 5),
				new RecipeResourceInfo("Cooling System", 5)
			});
			RegisterUnlock("Assembler MKIII", (TechCategory)1, (CoreType)3, 500, "Advanced assembler with 2x crafting speed.", (ResearchTier)1024);
			AssemblerDefinition val2 = ScriptableObject.CreateInstance<AssemblerDefinition>();
			EMUAdditions.AddNewMachine<AssemblerInstance, AssemblerDefinition>((MachineDefinition<AssemblerInstance, AssemblerDefinition>)(object)val2, new NewResourceDetails
			{
				name = "Assembler MKIII",
				description = $"High-performance assembler with {2f}x crafting speed.",
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				headerTitle = "Modded",
				maxStackCount = 50,
				sortPriority = 100,
				unlockName = "Assembler MKIII",
				parentName = "Assembler MKII"
			}, false);
			RegisterRecipe("Assembler MKIII", new List<RecipeResourceInfo>
			{
				new RecipeResourceInfo("Assembler MKII", 2),
				new RecipeResourceInfo("Steel Frame", 10),
				new RecipeResourceInfo("Processor Unit", 5),
				new RecipeResourceInfo("Shiverthorn Coolant", 5)
			});
			RegisterUnlock("Mining Drill MKIII", (TechCategory)1, (CoreType)3, 500, "Advanced mining drill with 2x dig speed.", (ResearchTier)1024);
			DrillDefinition val3 = ScriptableObject.CreateInstance<DrillDefinition>();
			EMUAdditions.AddNewMachine<DrillInstance, DrillDefinition>((MachineDefinition<DrillInstance, DrillDefinition>)(object)val3, new NewResourceDetails
			{
				name = "Mining Drill MKIII",
				description = $"High-performance mining drill with {2f}x dig speed.",
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				headerTitle = "Modded",
				maxStackCount = 50,
				sortPriority = 100,
				unlockName = "Mining Drill MKIII",
				parentName = "Mining Drill MKII"
			}, false);
			RegisterRecipe("Mining Drill MKIII", new List<RecipeResourceInfo>
			{
				new RecipeResourceInfo("Mining Drill MKII", 2),
				new RecipeResourceInfo("Steel Frame", 10),
				new RecipeResourceInfo("Mechanical Components", 10),
				new RecipeResourceInfo("Shiverthorn Coolant", 5)
			});
			RegisterUnlock("Thresher MKIII", (TechCategory)1, (CoreType)3, 300, "Improved thresher with 1.5x processing speed.", (ResearchTier)1024);
			ThresherDefinition val4 = ScriptableObject.CreateInstance<ThresherDefinition>();
			EMUAdditions.AddNewMachine<ThresherInstance, ThresherDefinition>((MachineDefinition<ThresherInstance, ThresherDefinition>)(object)val4, new NewResourceDetails
			{
				name = "Thresher MKIII",
				description = "Improved thresher with 1.5x processing speed.",
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				headerTitle = "Modded",
				maxStackCount = 50,
				sortPriority = 99,
				unlockName = "Thresher MKIII",
				parentName = "Thresher"
			}, false);
			RegisterRecipe("Thresher MKIII", new List<RecipeResourceInfo>
			{
				new RecipeResourceInfo("Thresher", 2),
				new RecipeResourceInfo("Steel Frame", 5),
				new RecipeResourceInfo("Mechanical Components", 3),
				new RecipeResourceInfo("Processor Unit", 2)
			});
			RegisterUnlock("Thresher MKIV", (TechCategory)1, (CoreType)3, 500, "Advanced thresher with 2x processing speed.", (ResearchTier)16384);
			ThresherDefinition val5 = ScriptableObject.CreateInstance<ThresherDefinition>();
			EMUAdditions.AddNewMachine<ThresherInstance, ThresherDefinition>((MachineDefinition<ThresherInstance, ThresherDefinition>)(object)val5, new NewResourceDetails
			{
				name = "Thresher MKIV",
				description = $"High-performance thresher with {2f}x processing speed.",
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				headerTitle = "Modded",
				maxStackCount = 50,
				sortPriority = 100,
				unlockName = "Thresher MKIV",
				parentName = "Thresher MKIII"
			}, false);
			RegisterRecipe("Thresher MKIV", new List<RecipeResourceInfo>
			{
				new RecipeResourceInfo("Thresher MKIII", 2),
				new RecipeResourceInfo("Steel Frame", 10),
				new RecipeResourceInfo("Mechanical Components", 5),
				new RecipeResourceInfo("Processor Unit", 3)
			});
			RegisterUnlock("Planter MKIV", (TechCategory)1, (CoreType)3, 500, "Advanced planter with 2.5x growth speed.", (ResearchTier)16384);
			PlanterDefinition val6 = ScriptableObject.CreateInstance<PlanterDefinition>();
			EMUAdditions.AddNewMachine<PlanterInstance, PlanterDefinition>((MachineDefinition<PlanterInstance, PlanterDefinition>)(object)val6, new NewResourceDetails
			{
				name = "Planter MKIV",
				description = "High-performance planter with 2.5x growth speed. Extends MorePlanters' Planter MKIII.",
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				headerTitle = "Modded",
				maxStackCount = 50,
				sortPriority = 100,
				unlockName = "Planter MKIV",
				parentName = "Planter"
			}, false);
			RegisterRecipe("Planter MKIV", new List<RecipeResourceInfo>
			{
				new RecipeResourceInfo("Planter MKIII", 2),
				new RecipeResourceInfo("Steel Frame", 10),
				new RecipeResourceInfo("Mechanical Components", 10),
				new RecipeResourceInfo("Shiverthorn Coolant", 5)
			});
			Log.LogInfo((object)"Registered Tier 4 machines");
		}

		private void RegisterTier5Machines()
		{
			//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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0073: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: 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_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Expected O, but got Unknown
			//IL_01b4: 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_01da: 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_0222: 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_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Expected O, but got Unknown
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: 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)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Expected O, but got Unknown
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: 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_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_042c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_0463: Expected O, but got Unknown
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			RegisterUnlock("Smelter MKV", (TechCategory)1, (CoreType)1, 1000, "Ultimate smelter with 3x processing speed.", (ResearchTier)262144);
			SmelterDefinition val = ScriptableObject.CreateInstance<SmelterDefinition>();
			val.craftingEfficiency = 3f;
			val.usesFuel = true;
			val.fuelConsumptionRate = 0.75f;
			EMUAdditions.AddNewMachine<SmelterInstance, SmelterDefinition>((MachineDefinition<SmelterInstance, SmelterDefinition>)(object)val, new NewResourceDetails
			{
				name = "Smelter MKV",
				description = $"Ultimate smelter with {3f}x processing speed. Peak performance for large-scale operations.",
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				headerTitle = "Modded",
				maxStackCount = 50,
				sortPriority = 101,
				unlockName = "Smelter MKV",
				parentName = "Smelter MKIII"
			}, false);
			RegisterRecipe("Smelter MKV", new List<RecipeResourceInfo>
			{
				new RecipeResourceInfo("Smelter MKIV", 2),
				new RecipeResourceInfo("Atlantum Mixture Brick", 10),
				new RecipeResourceInfo("Processor Unit", 10),
				new RecipeResourceInfo("Shiverthorn Coolant", 10)
			});
			RegisterUnlock("Assembler MKIV", (TechCategory)1, (CoreType)1, 1000, "Ultimate assembler with 3x crafting speed.", (ResearchTier)16384);
			AssemblerDefinition val2 = ScriptableObject.CreateInstance<AssemblerDefinition>();
			EMUAdditions.AddNewMachine<AssemblerInstance, AssemblerDefinition>((MachineDefinition<AssemblerInstance, AssemblerDefinition>)(object)val2, new NewResourceDetails
			{
				name = "Assembler MKIV",
				description = $"Ultimate assembler with {3f}x crafting speed.",
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				headerTitle = "Modded",
				maxStackCount = 50,
				sortPriority = 101,
				unlockName = "Assembler MKIV",
				parentName = "Assembler MKII"
			}, false);
			RegisterRecipe("Assembler MKIV", new List<RecipeResourceInfo>
			{
				new RecipeResourceInfo("Assembler MKIII", 2),
				new RecipeResourceInfo("Atlantum Mixture Brick", 10),
				new RecipeResourceInfo("Processor Unit", 10),
				new RecipeResourceInfo("Shiverthorn Coolant", 10)
			});
			RegisterUnlock("Mining Drill MKIV", (TechCategory)1, (CoreType)1, 1000, "Ultimate mining drill with 3x dig speed.", (ResearchTier)16384);
			DrillDefinition val3 = ScriptableObject.CreateInstance<DrillDefinition>();
			EMUAdditions.AddNewMachine<DrillInstance, DrillDefinition>((MachineDefinition<DrillInstance, DrillDefinition>)(object)val3, new NewResourceDetails
			{
				name = "Mining Drill MKIV",
				description = $"Ultimate mining drill with {3f}x dig speed.",
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				headerTitle = "Modded",
				maxStackCount = 50,
				sortPriority = 101,
				unlockName = "Mining Drill MKIV",
				parentName = "Mining Drill MKII"
			}, false);
			RegisterRecipe("Mining Drill MKIV", new List<RecipeResourceInfo>
			{
				new RecipeResourceInfo("Mining Drill MKIII", 2),
				new RecipeResourceInfo("Atlantum Mixture Brick", 10),
				new RecipeResourceInfo("Mechanical Components", 20),
				new RecipeResourceInfo("Shiverthorn Coolant", 10)
			});
			RegisterUnlock("Thresher MKV", (TechCategory)1, (CoreType)1, 1000, "Ultimate thresher with 3x processing speed.", (ResearchTier)262144);
			ThresherDefinition val4 = ScriptableObject.CreateInstance<ThresherDefinition>();
			EMUAdditions.AddNewMachine<ThresherInstance, ThresherDefinition>((MachineDefinition<ThresherInstance, ThresherDefinition>)(object)val4, new NewResourceDetails
			{
				name = "Thresher MKV",
				description = $"Ultimate thresher with {3f}x processing speed.",
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				headerTitle = "Modded",
				maxStackCount = 50,
				sortPriority = 101,
				unlockName = "Thresher MKV",
				parentName = "Thresher MKIII"
			}, false);
			RegisterRecipe("Thresher MKV", new List<RecipeResourceInfo>
			{
				new RecipeResourceInfo("Thresher MKIV", 2),
				new RecipeResourceInfo("Atlantum Mixture Brick", 10),
				new RecipeResourceInfo("Mechanical Components", 10),
				new RecipeResourceInfo("Processor Unit", 5)
			});
			RegisterUnlock("Planter MKV", (TechCategory)1, (CoreType)1, 1000, "Ultimate planter with 4x growth speed.", (ResearchTier)262144);
			PlanterDefinition val5 = ScriptableObject.CreateInstance<PlanterDefinition>();
			EMUAdditions.AddNewMachine<PlanterInstance, PlanterDefinition>((MachineDefinition<PlanterInstance, PlanterDefinition>)(object)val5, new NewResourceDetails
			{
				name = "Planter MKV",
				description = "Ultimate planter with 4x growth speed. Peak agricultural performance.",
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				headerTitle = "Modded",
				maxStackCount = 50,
				sortPriority = 101,
				unlockName = "Planter MKV",
				parentName = "Planter"
			}, false);
			RegisterRecipe("Planter MKV", new List<RecipeResourceInfo>
			{
				new RecipeResourceInfo("Planter MKIV", 2),
				new RecipeResourceInfo("Atlantum Mixture Brick", 10),
				new RecipeResourceInfo("Kindlevine Extract", 50),
				new RecipeResourceInfo("Shiverthorn Coolant", 10)
			});
			Log.LogInfo((object)"Registered Tier 5 machines");
		}

		private void RegisterUnlock(string name, TechCategory category, CoreType coreType, int coreCount, string description, ResearchTier tier)
		{
			//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_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0018: 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_0028: 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_0030: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			EMUAdditions.AddNewUnlock(new NewUnlockDetails
			{
				category = ModdedTabModule.ModdedCategory,
				coreTypeNeeded = coreType,
				coreCountNeeded = coreCount,
				description = description,
				displayName = name,
				requiredTier = tier,
				treePosition = 50
			}, false);
		}

		private void RegisterRecipe(string outputName, List<RecipeResourceInfo> ingredients)
		{
			//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_0011: 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_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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			EMUAdditions.AddNewRecipe(new NewRecipeDetails
			{
				GUID = "com.certifired.AdvancedMachines",
				craftingMethod = (CraftingMethod)0,
				craftTierRequired = 0,
				duration = 15f,
				unlockName = outputName,
				ingredients = ingredients,
				outputs = new List<RecipeResourceInfo>
				{
					new RecipeResourceInfo(outputName, 1)
				},
				sortPriority = 100
			}, false);
		}

		private void OnGameDefinesLoaded()
		{
			LinkUnlockToResource("Smelter MKIV");
			LinkUnlockToResource("Smelter MKV");
			LinkUnlockToResource("Assembler MKIII");
			LinkUnlockToResource("Assembler MKIV");
			LinkUnlockToResource("Mining Drill MKIII");
			LinkUnlockToResource("Mining Drill MKIV");
			LinkUnlockToResource("Thresher MKIII");
			LinkUnlockToResource("Thresher MKIV");
			LinkUnlockToResource("Thresher MKV");
			LinkUnlockToResource("Planter MKIV");
			LinkUnlockToResource("Planter MKV");
			ConfigureMachine("Smelter MKIV", 3, 2f, 225);
			ConfigureMachine("Smelter MKV", 4, 3f, 300);
			ConfigureMachine("Assembler MKIII", 2, 2f, 300);
			ConfigureMachine("Assembler MKIV", 3, 3f, 400);
			ConfigureMachine("Mining Drill MKIII", 2, 2f, 150);
			ConfigureMachine("Mining Drill MKIV", 3, 3f, 200);
			ConfigureMachine("Thresher MKIII", 2, 1.5f, 120);
			ConfigureMachine("Thresher MKIV", 3, 2f, 120);
			ConfigureMachine("Thresher MKV", 4, 3f, 160);
			ConfigureMachine("Planter MKIV", 3, 2.5f, 90);
			ConfigureMachine("Planter MKV", 4, 4f, 120);
		}

		private void LinkUnlockToResource(string name)
		{
			try
			{
				ResourceInfo resourceInfoByName = Resources.GetResourceInfoByName(name, false);
				if ((Object)(object)resourceInfoByName != (Object)null)
				{
					resourceInfoByName.unlock = Unlocks.GetUnlockByName(name, false);
				}
			}
			catch
			{
			}
		}

		private void ConfigureMachine(string name, int tier, float speedMult, int powerKW)
		{
			try
			{
				ResourceInfo resourceInfoByName = Resources.GetResourceInfoByName(name, false);
				if ((Object)(object)resourceInfoByName == (Object)null)
				{
					return;
				}
				BuilderInfo val = (BuilderInfo)(object)((resourceInfoByName is BuilderInfo) ? resourceInfoByName : null);
				if (val != null)
				{
					val.machineTier = tier;
				}
				FieldInfo field = ((object)resourceInfoByName).GetType().GetField("runtimePowerSettings");
				if (field != null)
				{
					object value = field.GetValue(resourceInfoByName);
					if (value != null)
					{
						FieldInfo field2 = value.GetType().GetField("kWPowerConsumption");
						if (field2 != null)
						{
							field2.SetValue(value, powerKW);
							field.SetValue(resourceInfoByName, value);
						}
					}
				}
				Log.LogInfo((object)$"Configured {name}: tier={tier}, speedMult={speedMult}, power={powerKW}kW");
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Failed to configure " + name + ": " + ex.Message));
			}
		}

		private void OnTechTreeStateLoaded()
		{
			ConfigureUnlock("Assembler MKIII", "Assembler", (ResearchTier)1024, 10);
			ConfigureUnlock("Mining Drill MKIII", "Mining Drill", (ResearchTier)1024, 30);
			ConfigureUnlock("Thresher MKIII", "Thresher", (ResearchTier)1024, 50);
			ConfigureUnlock("Smelter MKIV", "Smelter", (ResearchTier)16384, 10);
			ConfigureUnlock("Assembler MKIV", "Assembler", (ResearchTier)16384, 30);
			ConfigureUnlock("Mining Drill MKIV", "Mining Drill", (ResearchTier)16384, 50);
			ConfigureUnlock("Thresher MKIV", "Thresher", (ResearchTier)16384, 70);
			ConfigureUnlock("Planter MKIV", "Planter", (ResearchTier)16384, 90);
			ConfigureUnlock("Smelter MKV", "Smelter", (ResearchTier)262144, 10);
			ConfigureUnlock("Thresher MKV", "Thresher", (ResearchTier)262144, 30);
			ConfigureUnlock("Planter MKV", "Planter", (ResearchTier)262144, 50);
			Log.LogInfo((object)"Configured unlock tiers and sprites");
		}

		private void ConfigureUnlock(string unlockName, string spriteSourceName, ResearchTier tier, int position)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Unlock unlockByName = Unlocks.GetUnlockByName(unlockName, false);
				if ((Object)(object)unlockByName == (Object)null)
				{
					Log.LogWarning((object)("Could not find unlock: " + unlockName));
					return;
				}
				unlockByName.requiredTier = tier;
				unlockByName.treePosition = position;
				Sprite val = null;
				ResourceInfo resourceInfoByName = Resources.GetResourceInfoByName(spriteSourceName, false);
				if ((Object)(object)resourceInfoByName != (Object)null && (Object)(object)resourceInfoByName.sprite != (Object)null)
				{
					val = resourceInfoByName.sprite;
				}
				else
				{
					Unlock unlockByName2 = Unlocks.GetUnlockByName(spriteSourceName, false);
					if ((Object)(object)unlockByName2 != (Object)null && (Object)(object)unlockByName2.sprite != (Object)null)
					{
						val = unlockByName2.sprite;
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					unlockByName.sprite = val;
				}
				Log.LogInfo((object)string.Format("Configured {0}: tier={1}, pos={2}, sprite={3}", unlockName, tier, position, ((Object)(object)unlockByName.sprite != (Object)null) ? "SET" : "NULL"));
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Failed to configure unlock " + unlockName + ": " + ex.Message));
			}
		}

		private string GetBaseMachineName(string machineName)
		{
			if (machineName.Contains("Smelter"))
			{
				return "Smelter";
			}
			if (machineName.Contains("Assembler"))
			{
				return "Assembler";
			}
			if (machineName.Contains("Mining Drill") || machineName.Contains("Drill"))
			{
				return "Mining Drill";
			}
			if (machineName.Contains("Thresher"))
			{
				return "Thresher";
			}
			if (machineName.Contains("Planter"))
			{
				return "Planter";
			}
			return null;
		}
	}
	[HarmonyPatch]
	internal static class ForceTierPatches
	{
		private static readonly Dictionary<string, ResearchTier> ForcedTiers = new Dictionary<string, ResearchTier>
		{
			{
				"Assembler MKIII",
				(ResearchTier)1024
			},
			{
				"Mining Drill MKIII",
				(ResearchTier)1024
			},
			{
				"Thresher MKIII",
				(ResearchTier)1024
			},
			{
				"Smelter MKIV",
				(ResearchTier)16384
			},
			{
				"Assembler MKIV",
				(ResearchTier)16384
			},
			{
				"Mining Drill MKIV",
				(ResearchTier)16384
			},
			{
				"Thresher MKIV",
				(ResearchTier)16384
			},
			{
				"Planter MKIV",
				(ResearchTier)16384
			},
			{
				"Smelter MKV",
				(ResearchTier)262144
			},
			{
				"Thresher MKV",
				(ResearchTier)262144
			},
			{
				"Planter MKV",
				(ResearchTier)262144
			}
		};

		[HarmonyPatch(typeof(TechTreeState), "IsUnlockActive")]
		[HarmonyPrefix]
		private static void ForceUnlockTier(int unlockId)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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)
			if (unlockId < 0 || TechTreeState.instance == null)
			{
				return;
			}
			UnlockState[] unlockStates = TechTreeState.instance.unlockStates;
			if (unlockId < unlockStates.Length)
			{
				Unlock unlockRef = unlockStates[unlockId].unlockRef;
				if ((Object)(object)unlockRef != (Object)null && !string.IsNullOrEmpty(unlockRef.displayName) && ForcedTiers.TryGetValue(unlockRef.displayName, out var value) && unlockRef.requiredTier != value)
				{
					unlockRef.requiredTier = value;
				}
			}
		}

		[HarmonyPatch(typeof(TechTreeState), "Init")]
		[HarmonyPostfix]
		private static void ForceAllTiersAfterInit()
		{
			ForceAllTiers("Init");
		}

		[HarmonyPatch(typeof(TechTreeState), "ReadSaveState")]
		[HarmonyPostfix]
		private static void ForceAllTiersAfterSaveLoad()
		{
			ForceAllTiers("ReadSaveState");
		}

		public static void ForceAllTiers(string source)
		{
			//IL_0077: 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_008b: 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)
			if (GameDefines.instance?.unlocks == null)
			{
				return;
			}
			bool flag = false;
			foreach (Unlock unlock in GameDefines.instance.unlocks)
			{
				if ((Object)(object)unlock != (Object)null && !string.IsNullOrEmpty(unlock.displayName) && ForcedTiers.TryGetValue(unlock.displayName, out var value) && unlock.requiredTier != value)
				{
					unlock.requiredTier = value;
					flag = true;
				}
			}
			if (flag && source != null)
			{
				AdvancedMachinesPlugin.Log.LogInfo((object)("Forced MKIII/MKIV/MKV unlocks to correct tiers (" + source + ")"));
			}
		}
	}
	[HarmonyPatch]
	internal static class ToolbarFixPatches
	{
		[HarmonyPatch(typeof(ToolbarSlotUI), "Refresh")]
		[HarmonyFinalizer]
		private static Exception CatchRefreshErrors(Exception __exception)
		{
			if (__exception != null)
			{
				AdvancedMachinesPlugin.Log.LogWarning((object)("Toolbar slot refresh error (caught): " + __exception.Message));
				return null;
			}
			return null;
		}

		[HarmonyPatch(typeof(PlayerToolbar), "RefreshToolbars")]
		[HarmonyFinalizer]
		private static Exception CatchToolbarRefreshErrors(Exception __exception)
		{
			if (__exception != null)
			{
				AdvancedMachinesPlugin.Log.LogWarning((object)("Toolbar refresh error (caught): " + __exception.Message));
				return null;
			}
			return null;
		}

		[HarmonyPatch(typeof(PlayerToolbar), "LoadToolbarData")]
		[HarmonyFinalizer]
		private static Exception CatchToolbarLoadErrors(Exception __exception)
		{
			if (__exception != null)
			{
				AdvancedMachinesPlugin.Log.LogWarning((object)("Toolbar load error (caught): " + __exception.Message));
				return null;
			}
			return null;
		}
	}
	[HarmonyPatch]
	internal static class HiddenVariantsPatches
	{
		[HarmonyPatch(typeof(BuilderInfo), "IsVariantAvailable")]
		[HarmonyPrefix]
		private static bool IsVariantAvailablePrefix(ref bool __result, BuilderInfo __instance, int index)
		{
			if (!AdvancedMachinesPlugin.EnableHiddenVariants.Value)
			{
				return true;
			}
			if (__instance.variationData != null && index >= 0 && index < __instance.variationData.Length)
			{
				__result = true;
				return false;
			}
			__result = false;
			return false;
		}

		[HarmonyPatch(typeof(TechTreeState), "IsVariantAvailable")]
		[HarmonyPrefix]
		private static bool TechTreeIsVariantAvailablePrefix(ref bool __result, BuilderInfo info, int variationIndex)
		{
			if (!AdvancedMachinesPlugin.EnableHiddenVariants.Value)
			{
				return true;
			}
			if ((Object)(object)info != (Object)null && info.variationData != null && variationIndex >= 0 && variationIndex < info.variationData.Length)
			{
				__result = true;
				return false;
			}
			__result = false;
			return false;
		}
	}
}