Decompiled source of Dragon Egg Stacks v1.0.0

plugins/DragonEggStacks.dll

Decompiled 13 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.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 OctoberJemini.DragonEggStacks
{
	[BepInPlugin("OctoberJemini.DragonEggStacks", "Dragon Egg Stacks", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static class DBAwake
		{
			[HarmonyPostfix]
			[HarmonyPriority(0)]
			[HarmonyAfter(new string[] { "net.mtnewton.itemstacks" })]
			private static void Postfix(ObjectDB __instance)
			{
				ApplyDB(__instance);
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
		private static class DBCopy
		{
			[HarmonyPostfix]
			[HarmonyPriority(0)]
			[HarmonyAfter(new string[] { "net.mtnewton.itemstacks" })]
			private static void Postfix(ObjectDB __instance)
			{
				ApplyDB(__instance);
			}
		}

		[HarmonyPatch(typeof(ItemDrop), "Awake")]
		private static class DropAwake
		{
			[HarmonyPostfix]
			[HarmonyPriority(0)]
			private static void Postfix(ItemDrop __instance)
			{
				Apply(__instance);
			}
		}

		public const string Guid = "OctoberJemini.DragonEggStacks";

		private static ConfigEntry<int> size;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			size = ((BaseUnityPlugin)this).Config.Bind<int>("Stacking", "StackSize", 50, new ConfigDescription("Maximum dragon eggs per stack. Applies only to dragon eggs.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 1000), Array.Empty<object>()));
			harmony = new Harmony("OctoberJemini.DragonEggStacks");
			harmony.PatchAll(typeof(Plugin).Assembly);
			Type type = AccessTools.TypeByName("ItemStacks.ItemStacksPlugin");
			if (type != null)
			{
				MethodInfo methodInfo = AccessTools.Method(type, "ModifyItemStackSizeAndWeight", (Type[])null, (Type[])null);
				if (methodInfo != null)
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "AfterItemStacks", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Dragon eggs stack to " + size.Value + "; weight and teleport rules unchanged."));
		}

		private static void Apply(ItemDrop item)
		{
			if (Object.op_Implicit((Object)(object)item) && item.m_itemData != null && item.m_itemData.m_shared != null && item.m_itemData.m_shared.m_name == "$item_dragonegg")
			{
				item.m_itemData.m_shared.m_maxStackSize = size.Value;
			}
		}

		private static void ApplyDB(ObjectDB db)
		{
			if (!Object.op_Implicit((Object)(object)db) || db.m_items == null)
			{
				return;
			}
			foreach (GameObject item in db.m_items)
			{
				if (Object.op_Implicit((Object)(object)item))
				{
					Apply(item.GetComponent<ItemDrop>());
				}
			}
		}

		private static void AfterItemStacks(ObjectDB __0)
		{
			ApplyDB(__0);
		}

		private void OnDestroy()
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}