Decompiled source of HiveAndNestCapacity v1.0.0

HiveAndNestCapacity.dll

Decompiled 6 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("HiveAndNestCapacity")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HiveAndNestCapacity")]
[assembly: AssemblyTitle("HiveAndNestCapacity")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HiveAndNestCapacity
{
	[BepInPlugin("com.hiveandnestcapacity", "HiveAndNestCapacity", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.hiveandnestcapacity";

		public const string PluginName = "HiveAndNestCapacity";

		public const string PluginVersion = "1.0.0";

		internal static ConfigEntry<int> BeehiveMax;

		internal static ConfigEntry<int> BirdNestMax;

		internal static ConfigEntry<bool> StackDrops;

		private void Awake()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			};
			BeehiveMax = ((BaseUnityPlugin)this).Config.Bind<int>("General", "BeehiveMaxHoney", 4, new ConfigDescription("How much honey a beehive can hold before it stops making more. The game's own is 4.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), new object[1] { val }));
			BirdNestMax = ((BaseUnityPlugin)this).Config.Bind<int>("General", "BirdNestMaxItems", 4, new ConfigDescription("How many items a bird nest can hold before it stops making more. The game's own is 4.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), new object[1] { val }));
			StackDrops = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "StackDrops", true, new ConfigDescription("When you empty a hive or nest, drop the items as stacks instead of one by one (a full hive of 100 would otherwise be 100 separate items on the ground).", (AcceptableValueBase)null, new object[1] { val }));
			new Harmony("com.hiveandnestcapacity").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"HiveAndNestCapacity 1.0.0 loaded");
		}

		internal static int MaxFor(Beehive hive)
		{
			string text = hive.m_name ?? "";
			if (text.Contains("birdnest"))
			{
				return BirdNestMax.Value;
			}
			if (text.Contains("beehive"))
			{
				return BeehiveMax.Value;
			}
			return -1;
		}

		internal static void Apply(Beehive hive)
		{
			int num = MaxFor(hive);
			if (num > 0)
			{
				hive.m_maxHoney = num;
			}
		}
	}
	[HarmonyPatch(typeof(Beehive), "Awake")]
	internal static class Beehive_Awake_Patch
	{
		private static void Postfix(Beehive __instance)
		{
			Plugin.Apply(__instance);
		}
	}
	[HarmonyPatch(typeof(Beehive), "UpdateBees")]
	internal static class Beehive_UpdateBees_Patch
	{
		private static void Prefix(Beehive __instance)
		{
			Plugin.Apply(__instance);
		}
	}
	[HarmonyPatch(typeof(Beehive), "RPC_Extract")]
	internal static class Beehive_RPC_Extract_Patch
	{
		private static readonly FieldRef<Beehive, ZNetView> NView = AccessTools.FieldRefAccess<Beehive, ZNetView>("m_nview");

		private static bool Prefix(Beehive __instance)
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.StackDrops.Value)
			{
				return true;
			}
			ZNetView val = NView.Invoke(__instance);
			if ((Object)(object)val == (Object)null || !val.IsValid() || (Object)(object)__instance.m_honeyItem == (Object)null)
			{
				return true;
			}
			int num = val.GetZDO().GetInt(ZDOVars.s_level, 0);
			if (num <= 0)
			{
				return false;
			}
			ItemData itemData = __instance.m_honeyItem.m_itemData;
			int num2 = num * Game.instance.ScaleDrops(itemData, 1);
			int num3 = Mathf.Max(1, itemData.m_shared.m_maxStackSize);
			__instance.m_spawnEffect.Create(__instance.m_spawnPoint.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
			int num4 = 0;
			while (num2 > 0)
			{
				int num5 = Mathf.Min(num2, num3);
				num2 -= num5;
				Vector2 val2 = Random.insideUnitCircle * 0.5f;
				Vector3 val3 = __instance.m_spawnPoint.position + new Vector3(val2.x, 0.25f * (float)num4++, val2.y);
				ItemDrop component = ((Component)Object.Instantiate<ItemDrop>(__instance.m_honeyItem, val3, Quaternion.identity)).GetComponent<ItemDrop>();
				if (component != null)
				{
					component.SetStack(num5);
				}
			}
			val.GetZDO().Set(ZDOVars.s_level, 0, false);
			return false;
		}
	}
}