Decompiled source of TavernFoodPriorities v1.7.0

TavernFoodPriorities.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SuperFantasyKingdom;
using SuperFantasyKingdom.Tavern;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("TavernFoodPriorities")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.7.0.0")]
[assembly: AssemblyInformationalVersion("1.7.0+cb8adb3947351a168918f60493dad4d2236b72f0")]
[assembly: AssemblyProduct("Tavern Food Priorities")]
[assembly: AssemblyTitle("TavernFoodPriorities")]
[assembly: AssemblyVersion("1.7.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 TavernFoodPriorities
{
	[BepInPlugin("ownly.tavernfoodpriorities", "Tavern Food Priorities", "1.7.0")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID).PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Tavern Food Priorities loaded: units eat the cheapest food first");
		}
	}
	[HarmonyPatch(typeof(TavernFoodManager), "FindBestFood")]
	internal static class Patch_FindLowestFood
	{
		private const int MeatToCookFallback = 6;

		private static readonly ResourceType[] eatOrderConserveFish;

		private static readonly ResourceType[] eatOrderSpendFish;

		private static bool Prefix(TavernFoodManager __instance, ref ResourceType __result)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected I4, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Invalid comparison between Unknown and I4
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Invalid comparison between Unknown and I4
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			List<ResourceAmount> value = Traverse.Create((object)__instance).Field("m_Inventory").GetValue<List<ResourceAmount>>();
			ResourceType val = (ResourceType)0;
			int num = int.MaxValue;
			if (value != null)
			{
				int num2 = 0;
				foreach (ResourceAmount item in value)
				{
					if ((int)item.type == 34 || (int)item.type == 33 || (int)item.type == 11)
					{
						num2 += item.amount;
					}
				}
				int num3 = (((Object)(object)TavernSaveManager.Instance != (Object)null) ? TavernSaveManager.Instance.GetMeatToCook() : 6);
				ResourceType[] array = ((Traverse.Create((object)__instance).Field("m_CookFish").GetValue<bool>() && num2 < num3) ? eatOrderConserveFish : eatOrderSpendFish);
				foreach (ResourceAmount item2 in value)
				{
					if (item2.amount > 0)
					{
						int num4 = Array.IndexOf(array, item2.type);
						if (num4 >= 0 && num4 < num)
						{
							num = num4;
							val = item2.type;
						}
					}
				}
			}
			__result = (ResourceType)(int)val;
			return false;
		}

		static Patch_FindLowestFood()
		{
			ResourceType[] array = new ResourceType[6];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			eatOrderConserveFish = (ResourceType[])(object)array;
			ResourceType[] array2 = new ResourceType[6];
			RuntimeHelpers.InitializeArray(array2, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			eatOrderSpendFish = (ResourceType[])(object)array2;
		}
	}
}