Decompiled source of StackableFood v1.0.1

KinkoCraft.StackableFood.dll

Decompiled 10 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("KinkoCraft.StackableFood")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+1168fb1aac1ffdc31775e7e1153a0fdf38aeab51")]
[assembly: AssemblyProduct("Stackable Food")]
[assembly: AssemblyTitle("KinkoCraft.StackableFood")]
[assembly: AssemblyVersion("1.0.1.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 KinkoCraft.StackableFood
{
	internal static class PluginMeta
	{
		public const string Guid = "KinkoCraft.StackableFood";

		public const string Name = "Stackable Food";

		public const string Version = "1.0.1";

		public const string ItemStackerFixGuid = "com.travv.aleandtale.itemstack99safe";

		public const ushort ItemStackerFixCap = 99;
	}
	[BepInPlugin("KinkoCraft.StackableFood", "Stackable Food", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class StackableFoodPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static ConfigEntry<int> StandaloneMaxStack;

		internal static ConfigEntry<bool> IncludeDrinks;

		private void Awake()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			StandaloneMaxStack = ((BaseUnityPlugin)this).Config.Bind<int>("General", "StandaloneMaxStack", 10, new ConfigDescription("How many food items stack in one inventory slot when ItemStackerFix is NOT installed. With ItemStackerFix installed this is ignored and the cap is 99.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 99), Array.Empty<object>()));
			IncludeDrinks = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "IncludeDrinks", false, "Also make drinks (beer, juice, etc.) stackable, not just plated food.");
			new Harmony("KinkoCraft.StackableFood").PatchAll(typeof(FoodStackPatch));
			Log.LogInfo((object)"Stackable Food v1.0.1 loaded.");
		}
	}
	public class FoodStackPatch
	{
		[HarmonyPatch(typeof(ItemManager), "Awake")]
		[HarmonyPostfix]
		private static void BumpFoodStacks(ItemManager __instance)
		{
			bool flag = Chainloader.PluginInfos.ContainsKey("com.travv.aleandtale.itemstack99safe");
			ushort num = (ushort)(flag ? 99 : ((ushort)StackableFoodPlugin.StandaloneMaxStack.Value));
			bool value = StackableFoodPlugin.IncludeDrinks.Value;
			ItemData[] array = __instance.itemDataHub?.itemData;
			if (array == null)
			{
				StackableFoodPlugin.Log.LogWarning((object)"itemDataHub.itemData was null; no food made stackable.");
				return;
			}
			int num2 = 0;
			ItemData[] array2 = array;
			foreach (ItemData val in array2)
			{
				if (!((Object)(object)val == (Object)null) && IsFood(val, value) && val.maxStack < num && val.maxStack <= 1)
				{
					val.maxStack = num;
					num2++;
				}
			}
			StackableFoodPlugin.Log.LogInfo((object)(string.Format("Stackable Food: cap={0} ({1}), ", num, flag ? "ItemStackerFix detected" : "standalone") + $"includeDrinks={value}, updated {num2} item(s)."));
		}

		private static bool IsFood(ItemData data, bool includeDrinks)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			Type type = data.type;
			if (type - 4 > 1)
			{
				if ((int)type == 6)
				{
					return includeDrinks;
				}
				return false;
			}
			return true;
		}
	}
}