Decompiled source of WeHaveTheMeats v1.0.0

WeHaveTheMeats/WeHaveTheMeats.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[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 WeHaveTheMeats
{
	[BepInPlugin("local.wehavethemeats", "WeHaveTheMeats", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal const string TargetPrefab = "food_smelter";

		internal const string SourcePrefab = "piece_cookingstation_iron";

		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("local.wehavethemeats").PatchAll();
		}
	}
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	[HarmonyPriority(0)]
	internal static class ZNetScene_Awake_Patch
	{
		private static void Postfix(ZNetScene __instance)
		{
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Expected O, but got Unknown
			List<GameObject> list = new List<GameObject>(__instance.m_prefabs);
			Dictionary<int, GameObject> value = Traverse.Create((object)__instance).Field("m_namedPrefabs").GetValue<Dictionary<int, GameObject>>();
			if (value != null)
			{
				foreach (GameObject value2 in value.Values)
				{
					if ((Object)(object)value2 != (Object)null && !list.Contains(value2))
					{
						list.Add(value2);
					}
				}
			}
			GameObject val = ((IEnumerable<GameObject>)list).FirstOrDefault((Func<GameObject, bool>)((GameObject g) => (Object)(object)g != (Object)null && ((Object)g).name == "piece_cookingstation_iron"));
			CookingStation val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<CookingStation>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				Debug.LogWarning((object)"[WeHaveTheMeats] 'piece_cookingstation_iron' not found. Nothing patched.");
				return;
			}
			GameObject val3 = ((IEnumerable<GameObject>)list).FirstOrDefault((Func<GameObject, bool>)((GameObject g) => (Object)(object)g != (Object)null && ((Object)g).name == "food_smelter"));
			Smelter val4 = (((Object)(object)val3 != (Object)null) ? val3.GetComponent<Smelter>() : null);
			if ((Object)(object)val4 == (Object)null)
			{
				Debug.LogWarning((object)"[WeHaveTheMeats] 'food_smelter' not found. Nothing patched.");
				return;
			}
			int num = 0;
			foreach (ItemConversion conv in val2.m_conversion)
			{
				if (!((Object)(object)conv.m_from == (Object)null) && !((Object)(object)conv.m_to == (Object)null) && !val4.m_conversion.Any((ItemConversion c) => (Object)(object)c.m_from != (Object)null && ((Object)c.m_from).name == ((Object)conv.m_from).name))
				{
					val4.m_conversion.Add(new ItemConversion
					{
						m_from = conv.m_from,
						m_to = conv.m_to
					});
					num++;
				}
			}
			Debug.Log((object)string.Format("[WeHaveTheMeats] Added {0} recipe(s) to '{1}'.", num, "food_smelter"));
		}
	}
}