Decompiled source of AutoClogChests v2.0.0

plugins/AutoClogChests/AutoClogChests.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using AutoClogChests.Patches;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
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("AutoClogChests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoClogChests")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("89b7a6ef-fd0a-43c2-b288-3a1f9dfcdc5b")]
[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 AutoClogChests
{
	[BepInPlugin("com.equinox.AutoClogChests", "AutoClogChests", "2.0.0")]
	public class AutoClogChestsPlugin : BaseUnityPlugin
	{
		private const string MyGUID = "com.equinox.AutoClogChests";

		private const string PluginName = "AutoClogChests";

		private const string VersionString = "2.0.0";

		private const string NumEmptySlotsKey = "NumEmptySlots";

		public static ConfigEntry<int> NumEmptySlots;

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

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

		public static bool finishedLoadingBuilds = false;

		public static int resIDToTry = 0;

		public static int limestoneResID = -1;

		public static int ironOreResID = -1;

		private void Awake()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			NumEmptySlots = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NumEmptySlots", 1, new ConfigDescription("Number of empty slots at the start of the chest.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 56), Array.Empty<object>()));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: AutoClogChests, VersionString: 2.0.0 is loading...");
			Harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: AutoClogChests, VersionString: 2.0.0 is loaded.");
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(typeof(ChestDefinitionPatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(SaveStatePatch), (string)null);
		}
	}
}
namespace AutoClogChests.Patches
{
	public class ChestDefinitionPatch
	{
		[HarmonyPatch(typeof(ChestDefinition), "InitInstance")]
		[HarmonyPostfix]
		private static void autoClogChest(ref ChestInstance newInstance)
		{
			if (AutoClogChestsPlugin.NumEmptySlots.Value == 56)
			{
				return;
			}
			if (AutoClogChestsPlugin.limestoneResID == -1)
			{
				findIDs();
			}
			if (AutoClogChestsPlugin.finishedLoadingBuilds)
			{
				int num = default(int);
				for (int i = AutoClogChestsPlugin.NumEmptySlots.Value; i < 55; i++)
				{
					((Inventory)(ref MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<ChestInstance>(ref newInstance, 0))).AddResourcesToSlot(AutoClogChestsPlugin.limestoneResID, i, ref num, 1, true);
				}
				((Inventory)(ref MACHINE_INSTANCE_HELPER_EXTENSIONS.GetInventory<ChestInstance>(ref newInstance, 0))).AddResourcesToSlot(AutoClogChestsPlugin.ironOreResID, 55, ref num, 1, true);
			}
		}

		private static void findIDs()
		{
			if ((Object)(object)GameDefines.instance == (Object)null)
			{
				return;
			}
			foreach (ResourceInfo resource in GameDefines.instance.resources)
			{
				if (resource.displayName == "Limestone")
				{
					AutoClogChestsPlugin.limestoneResID = SaveState.GetIdForResInfo((UniqueIdScriptableObject)(object)resource);
				}
				else if (resource.displayName == "Iron Ore")
				{
					AutoClogChestsPlugin.ironOreResID = SaveState.GetIdForResInfo((UniqueIdScriptableObject)(object)resource);
				}
				if (AutoClogChestsPlugin.limestoneResID != -1 && AutoClogChestsPlugin.ironOreResID != -1)
				{
					break;
				}
			}
		}
	}
	public class SaveStatePatch
	{
		[HarmonyPatch(typeof(SaveState), "GenerateBuildingsOnLoad")]
		[HarmonyPostfix]
		private static void setFinishedLoadingBuildings()
		{
			AutoClogChestsPlugin.finishedLoadingBuilds = true;
		}
	}
}