Decompiled source of InfiniteFoundations v1.0.0

InfiniteFoundations.dll

Decompiled 11 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
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("InfiniteFoundations")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("InfiniteFoundations")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("72aea663-afe3-4c45-b54f-914d98de6b82")]
[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 InfiniteFoundations;

[BepInPlugin("com.tinysquid.infinitefoundations", "infinitefoundations", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	private class PatchSandCount
	{
		private static void Postfix(ref long __result)
		{
			__result = 999999L;
		}
	}

	[HarmonyPatch(typeof(StorageComponent), "GetItemCount", new Type[] { typeof(int) })]
	private class PatchFoundationCount
	{
		private static void Postfix(int itemId, ref int __result)
		{
			if (itemId == foundationItemId.Value)
			{
				__result = 9999;
			}
		}
	}

	public const string PLUGIN_GUID = "com.tinysquid.infinitefoundations";

	public const string PLUGIN_NAME = "infinitefoundations";

	public const string PLUGIN_VERSION = "1.0.0";

	private static Harmony harmony;

	private ConfigEntry<bool> shouldOverrideSoil;

	private ConfigEntry<bool> shouldOverrideFoundations;

	private static ConfigEntry<int> foundationItemId;

	public void Awake()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		LoadConfig();
		harmony = new Harmony("com.tinysquid.infinitefoundations");
		ApplyPatches();
	}

	public void OnDestroy()
	{
		RevertPatches();
	}

	public void LoadConfig()
	{
		shouldOverrideSoil = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "shouldOverrideSoil", true, "toggle for infinite soil");
		shouldOverrideFoundations = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "shouldOverrideFoundations", true, "toggle for infinite foundations");
		foundationItemId = ((BaseUnityPlugin)this).Config.Bind<int>("Other", "foundationItemId", 1131, "exposed item id for foundations if the game ever changes it for any reason. See https://dsp-wiki.com/Modding:Items_IDs");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded configuration values.");
	}

	public void ApplyPatches()
	{
		try
		{
			if (shouldOverrideSoil.Value)
			{
				harmony.PatchAll(typeof(PatchSandCount));
			}
			if (shouldOverrideFoundations.Value)
			{
				harmony.PatchAll(typeof(PatchFoundationCount));
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Patches applied!");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Patch failed with exception: " + ex.ToString()));
		}
	}

	public void RevertPatches()
	{
		harmony.UnpatchSelf();
	}
}