Decompiled source of BlastSmelterPause v1.1.0

plugins/BlastSmelterPause/BlastSmelterPause.dll

Decompiled 2 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using BlastSmelterPause.Patches;
using HarmonyLib;
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("BlastSmelterPause")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BlastSmelterPause")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1bb49965-b042-45e9-9c20-fa4d013774c6")]
[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 BlastSmelterPause
{
	[BepInPlugin("com.equinox.BlastSmelterPause", "BlastSmelterPause", "1.1.0")]
	public class BlastSmelterPausePlugin : BaseUnityPlugin
	{
		private const string MyGUID = "com.equinox.BlastSmelterPause";

		private const string PluginName = "BlastSmelterPause";

		private const string VersionString = "1.1.0";

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

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

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: BlastSmelterPause, VersionString: 1.1.0 is loading...");
			Harmony.PatchAll();
			Harmony.CreateAndPatchAll(typeof(BlastSmelterInstancePatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(DrillInstancePatch), (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: BlastSmelterPause, VersionString: 1.1.0 is loaded.");
			Log = ((BaseUnityPlugin)this).Logger;
		}
	}
}
namespace BlastSmelterPause.Patches
{
	internal class BlastSmelterInstancePatch
	{
		[HarmonyPatch(typeof(BlastSmelterInstance), "UpdateCrafting")]
		[HarmonyPrefix]
		private static bool ReplaceUpdateCrafting(ref BlastSmelterInstance __instance, float dt)
		{
			//IL_007b: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Invalid comparison between Unknown and I4
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Invalid comparison between Unknown and I4
			__instance.cooldown -= dt / ((BlastSmelterInstance)(ref __instance)).myDef.runtimeSettings.cooldown;
			ref Inventory outputInventory = ref ((BlastSmelterInstance)(ref __instance)).GetOutputInventory();
			ref Inventory inputInventory = ref ((BlastSmelterInstance)(ref __instance)).GetInputInventory();
			if ((Object)(object)__instance.targetRecipe != (Object)null && ((Inventory)(ref outputInventory)).GetResourceCount(((UniqueIdScriptableObject)__instance.targetRecipe.outputTypes[0]).uniqueId, false) == __instance.targetRecipe.outputTypes[0].maxStackCount)
			{
				return false;
			}
			MethodInfo method = ((object)__instance).GetType().GetMethod("HasResourcesToCraft", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method2 = ((object)__instance).GetType().GetMethod("RefreshHasFuel", BindingFlags.Instance | BindingFlags.NonPublic);
			method2.Invoke(__instance, new object[0]);
			MethodInfo method3 = ((object)__instance).GetType().GetMethod("ConsumeFuel", BindingFlags.Instance | BindingFlags.NonPublic);
			if ((Object)(object)__instance.targetRecipe != (Object)null && TechTreeState.instance.IsRecipeKnown(__instance.targetRecipe) && __instance.cooldown <= 0f && (bool)method.Invoke(__instance, new object[0]) && (bool)method3.Invoke(__instance, new object[0]))
			{
				__instance.cooldown = 0f;
				method2.Invoke(__instance, new object[0]);
				if ((Object)(object)__instance.targetRecipe != (Object)null && (int)__instance.targetRecipe.craftingMethod == 4)
				{
					__instance.lastOutputAmount = 0;
					__instance.lastOutputResource = ((UniqueIdScriptableObject)__instance.targetRecipe.outputTypes[0]).uniqueId;
					int num = GameState.instance.blastSmelterIterations;
					int num2 = __instance.targetRecipe.outputTypes[0].maxStackCount - ((Inventory)(ref outputInventory)).GetResourceCount(__instance.lastOutputResource, false);
					if (num > num2)
					{
						num = num2 / __instance.targetRecipe.outputQuantities[0];
					}
					for (int i = 0; i < num; i++)
					{
						if (!(bool)method.Invoke(__instance, new object[0]))
						{
							continue;
						}
						MethodInfo method4 = ((object)__instance).GetType().GetMethod("TakeResourcesToCraft", BindingFlags.Instance | BindingFlags.NonPublic);
						method4.Invoke(__instance, new object[1] { false });
						for (int j = 0; j < __instance.targetRecipe.outputQuantities.Length && j < __instance.targetRecipe.outputTypes.Length; j++)
						{
							if (((Inventory)(ref outputInventory)).CanAddResources(((UniqueIdScriptableObject)__instance.targetRecipe.outputTypes[j]).uniqueId, __instance.targetRecipe.outputQuantities[j], (List<NetworkInventorySlot>)null))
							{
								((Inventory)(ref outputInventory)).AddResources(__instance.targetRecipe.outputTypes[j], __instance.targetRecipe.outputQuantities[j], true);
								__instance.lastOutputAmount += __instance.targetRecipe.outputQuantities[j];
							}
							if ((int)__instance.commonInfo.protectionStatus == 0)
							{
								PlayerQuestSystem.instance.OnSmelterCraft(__instance.targetRecipe.outputTypes[j], __instance.targetRecipe.outputQuantities[j]);
							}
						}
					}
				}
				__instance.cooldown = 1f;
				__instance.queuedBlastAnim = true;
			}
			if (((Inventory)(ref inputInventory)).isEmpty && ((Inventory)(ref outputInventory)).isEmpty)
			{
				__instance.targetRecipe = null;
			}
			return false;
		}
	}
	internal class DrillInstancePatch
	{
		[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;
		}
	}
}