Decompiled source of EasyBlasting v1.0.0

plugins/EasyBlasting/EasyBlasting.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 EasyBlasting.Patches;
using EquinoxsModUtils;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("EasyBlasting")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EasyBlasting")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("31148f8c-87ff-4d28-afbc-73cfa7544084")]
[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 EasyBlasting
{
	[BepInPlugin("com.equinox.EasyBlasting", "EasyBlasting", "1.0.0")]
	public class EasyBlastingPlugin : BaseUnityPlugin
	{
		private const string MyGUID = "com.equinox.EasyBlasting";

		private const string PluginName = "EasyBlasting";

		private const string VersionString = "1.0.0";

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

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

		public static ConfigEntry<bool> EasyBlastMiners;

		public static ConfigEntry<bool> EasyBlastSmelters;

		public static ConfigEntry<bool> PauseProcessing;

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: EasyBlasting, VersionString: 1.0.0 is loading...");
			Harmony.PatchAll();
			ApplyPatches();
			CreateConfigEntries();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: EasyBlasting, VersionString: 1.0.0 is loaded.");
			Log = ((BaseUnityPlugin)this).Logger;
		}

		private void Update()
		{
		}

		private void ApplyPatches()
		{
			Harmony.CreateAndPatchAll(typeof(BlastSmelterInstancePatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(DrillInstancePatch), (string)null);
		}

		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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			EasyBlastMiners = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Easy Blast Miners", true, new ConfigDescription("When true, miners will not waste mining charges", (AcceptableValueBase)null, Array.Empty<object>()));
			EasyBlastSmelters = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Easy Blast Smelters", true, new ConfigDescription("When true, blast smelters will only consume 1 charge per cycle", (AcceptableValueBase)null, Array.Empty<object>()));
			PauseProcessing = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Pause Processing", true, new ConfigDescription("When true, blast machines will stop processing when their output is full", (AcceptableValueBase)null, Array.Empty<object>()));
		}
	}
}
namespace EasyBlasting.Patches
{
	internal class BlastSmelterInstancePatch
	{
		[HarmonyPatch(typeof(BlastSmelterInstance), "ConsumeFuel")]
		[HarmonyPrefix]
		private static bool ConsumeOneCharge(BlastSmelterInstance __instance, ref bool __result)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			if (!EasyBlastingPlugin.EasyBlastSmelters.Value)
			{
				return true;
			}
			if (EasyBlastingPlugin.PauseProcessing.Value)
			{
				ref Inventory outputInventory = ref ((BlastSmelterInstance)(ref __instance)).GetOutputInventory();
				if (!((Inventory)(ref outputInventory)).isEmpty && ((ResourceStack)(ref outputInventory.myStacks[0])).isFull)
				{
					__result = false;
					return false;
				}
			}
			ref Inventory fuelInventory = ref ((BlastSmelterInstance)(ref __instance)).GetFuelInventory();
			if (((Inventory)(ref fuelInventory)).isEmpty)
			{
				return true;
			}
			((Inventory)(ref fuelInventory)).RemoveResourcesFromSlot(0, 1);
			__result = true;
			return false;
		}
	}
	internal class DrillInstancePatch
	{
		internal static int blast2 = -1;

		internal static int blast3 = -1;

		internal static int blast4 = -1;

		internal static int blast5 = -1;

		[HarmonyPatch(typeof(DrillInstance), "ConsumeExplosives")]
		[HarmonyPrefix]
		private static bool ConsumeMinExplosives(DrillInstance __instance, out int explosivesConsumed, ref bool __result)
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			explosivesConsumed = 0;
			if (!EasyBlastingPlugin.EasyBlastMiners.Value)
			{
				return true;
			}
			if (blast2 == -1)
			{
				GetBlastUnlockIds();
			}
			List<int> list = new List<int> { 1 };
			if (TechTreeState.instance.IsUnlockActive(blast2))
			{
				list.Add(3);
			}
			if (TechTreeState.instance.IsUnlockActive(blast3))
			{
				list.Add(5);
			}
			if (TechTreeState.instance.IsUnlockActive(blast4))
			{
				list.Add(10);
			}
			if (TechTreeState.instance.IsUnlockActive(blast5))
			{
				list.Add(15);
			}
			ref Inventory fuelInventory = ref ((DrillInstance)(ref __instance)).GetFuelInventory();
			int numCharges = fuelInventory.myStacks[0].count;
			((Inventory)(ref fuelInventory)).RemoveResourcesFromSlot(0, explosivesConsumed = list.Where((int amount) => amount <= numCharges).Max());
			__result = true;
			return false;
		}

		[HarmonyPatch(typeof(DrillInstance), "ExplosivesReady")]
		[HarmonyPrefix]
		private static bool ReplaceExplosivesReady(ref DrillInstance __instance, ref bool __result)
		{
			if (((ResourceStack)(ref ((DrillInstance)(ref __instance)).GetOutputInventory().myStacks[0])).isEmpty)
			{
				return true;
			}
			ResourceInfo info = ((ResourceStack)(ref ((DrillInstance)(ref __instance)).GetOutputInventory().myStacks[0])).info;
			int maxStack = ((DrillInstance)(ref __instance)).GetOutputInventory().myStacks[0].maxStack;
			int resourceCount = ((Inventory)(ref ((DrillInstance)(ref __instance)).GetOutputInventory())).GetResourceCount(((UniqueIdScriptableObject)info).uniqueId, false);
			if (resourceCount == maxStack)
			{
				__result = false;
				return false;
			}
			return true;
		}

		private static void GetBlastUnlockIds()
		{
			blast2 = ((UniqueIdScriptableObject)Unlocks.GetUnlockByName("BDR-MultiBlast II", false)).uniqueId;
			blast3 = ((UniqueIdScriptableObject)Unlocks.GetUnlockByName("BDR-MultiBlast III", false)).uniqueId;
			blast4 = ((UniqueIdScriptableObject)Unlocks.GetUnlockByName("BDR-MultiBlast IV", false)).uniqueId;
			blast5 = ((UniqueIdScriptableObject)Unlocks.GetUnlockByName("BDR-MultiBlast V", false)).uniqueId;
		}
	}
}