Decompiled source of MorePlantmatter v1.0.3

plugins/MorePlantmatter/MorePlantmatter.dll

Decompiled 2 months ago
using System;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MorePlantmatter.Patches;
using PropStreaming;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MorePlantmatter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MorePlantmatter")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a1da3b87-b759-4ad2-93ef-ff98347ad5bc")]
[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 MorePlantmatter
{
	[BepInPlugin("com.equinox.MorePlantmatter", "MorePlantmatter", "1.0.0")]
	public class MorePlantmatterPlugin : BaseUnityPlugin
	{
		private const string MyGUID = "com.equinox.MorePlantmatter";

		private const string PluginName = "MorePlantmatter";

		private const string VersionString = "1.0.0";

		private const string multiplierKey = "Multiplier";

		public static ConfigEntry<int> multiplier;

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

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

		private void Awake()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			multiplier = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Multiplier", 2, new ConfigDescription("Multiplier for amount of plantmatter gained when harvesting plants", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>()));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: MorePlantmatter, VersionString: 1.0.0 is loading...");
			Harmony.PatchAll();
			Harmony.CreateAndPatchAll(typeof(HitDestructibleActionPatch), (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: MorePlantmatter, VersionString: 1.0.0 is loaded.");
			Log = ((BaseUnityPlugin)this).Logger;
		}

		private void Update()
		{
		}
	}
}
namespace MorePlantmatter.Patches
{
	internal class HitDestructibleActionPatch
	{
		private static DateTime lastCall = DateTime.Now;

		private static int multiplier => MorePlantmatterPlugin.multiplier.Value;

		[HarmonyPatch(typeof(HitDestructibleAction), "GetPlayerInventoryChanges")]
		[HarmonyPrefix]
		private static void AddMorePlantmatter(HitDestructibleAction __instance)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if ((DateTime.Now - lastCall).TotalMilliseconds < 100.0)
			{
				return;
			}
			lastCall = DateTime.Now;
			InstanceLookup[] propLookups = __instance.info.propLookups;
			DestructibleData val2 = default(DestructibleData);
			for (int i = 0; i < propLookups.Length; i++)
			{
				InstanceLookup val = propLookups[i];
				if (!PropManager.instance.GetDestructibleData(ref val, ref val2) || !val2.WouldBeDestroyed(val, __instance.info.hitStrength))
				{
					break;
				}
				foreach (DestructibleReward reward in val2.rewards)
				{
					if (reward == null || reward.resource.displayName != "Plantmatter")
					{
						continue;
					}
					for (int j = 0; j < multiplier - 1; j++)
					{
						int idForResInfo = SaveState.GetIdForResInfo((UniqueIdScriptableObject)(object)reward.resource);
						if (!((InventoryWrapper)Player.instance.inventory).CanAddResources(idForResInfo, reward.quantity, (List<NetworkInventorySlot>)null))
						{
							break;
						}
						((InventoryWrapper)Player.instance.inventory).AddResources(idForResInfo, reward.quantity);
					}
				}
			}
		}
	}
}