Decompiled source of HungryThreshers v1.0.1

plugins/HungryThreshers/HungryThreshers.dll

Decompiled 4 months ago
using System;
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 EquinoxsModUtils;
using HarmonyLib;
using HungryThreshers.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HungryThreshers")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HungryThreshers")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dc08a998-3c31-44f0-9a0c-894be6f1913c")]
[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 HungryThreshers
{
	[BepInPlugin("com.equinox.HungryThreshers", "HungryThreshers", "1.0.1")]
	public class HungryThreshersPlugin : BaseUnityPlugin
	{
		private const string MyGUID = "com.equinox.HungryThreshers";

		private const string PluginName = "HungryThreshers";

		private const string VersionString = "1.0.1";

		private const string PauseIfBothFullKey = "PauseIfBothFull";

		public static ConfigEntry<bool> PauseIfBothFull;

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

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

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: HungryThreshers, VersionString: 1.0.1 is loading...");
			PauseIfBothFull = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PauseIfBothFull", false, new ConfigDescription("When enabled, threshers will not void items if all outputs are full", (AcceptableValueBase)null, Array.Empty<object>()));
			Harmony.PatchAll();
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.PatchAll(typeof(ThresherInstancePatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: HungryThreshers, VersionString: 1.0.1 is loaded.");
		}
	}
}
namespace HungryThreshers.Patches
{
	public class ThresherInstancePatch
	{
		[HarmonyPatch(typeof(ThresherInstance), "UpdateCrafting")]
		[HarmonyPrefix]
		private static void clearOutputsForCrafting(ThresherInstance __instance)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_0036: 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_0057: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			Inventory inputInventory = ((ThresherInstance)(ref __instance)).GetInputInventory();
			if (((ResourceStack)(ref inputInventory.myStacks[0])).isEmpty)
			{
				return;
			}
			Inventory outputInventory = ((ThresherInstance)(ref __instance)).GetOutputInventory();
			SchematicsRecipeData val = ModUtils.TryFindThresherRecipe(inputInventory.myStacks[0].id, false);
			bool flag = true;
			for (int i = 0; i < val.outputTypes.Length; i++)
			{
				if (!IsSlotFull(__instance, i))
				{
					flag = false;
				}
			}
			if (flag && HungryThreshersPlugin.PauseIfBothFull.Value)
			{
				return;
			}
			for (int j = 0; j < outputInventory.myStacks.Count(); j++)
			{
				if (IsSlotFull(__instance, j))
				{
					((Inventory)(ref outputInventory)).RemoveResourcesFromSlot(j, val.outputQuantities[j]);
				}
			}
		}

		private static bool IsSlotFull(ThresherInstance __instance, int index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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)
			//IL_001b: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			Inventory inputInventory = ((ThresherInstance)(ref __instance)).GetInputInventory();
			Inventory outputInventory = ((ThresherInstance)(ref __instance)).GetOutputInventory();
			SchematicsRecipeData val = ModUtils.TryFindThresherRecipe(inputInventory.myStacks[0].id, false);
			if (((ResourceStack)(ref outputInventory.myStacks[index])).isEmpty)
			{
				return false;
			}
			int num = val.outputQuantities[index];
			int num2 = outputInventory.myStacks[index].maxStack - num;
			return outputInventory.myStacks[index].count >= num2;
		}
	}
}