Decompiled source of SeedCrafting v1.0.1

SeedCrafting.dll

Decompiled 17 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
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: 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 SeedCrafting
{
	[BepInPlugin("com.michal.valheim.seedcrafting", "Seed Crafting", "1.0.1")]
	public class SeedCraftingPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static class ObjectDB_Awake_Patch
		{
			private static void Postfix(ObjectDB __instance)
			{
				if (!_recipesAdded && !((Object)(object)__instance == (Object)null) && __instance.m_items != null && __instance.m_items.Count != 0)
				{
					_recipesAdded = true;
					AddSeedRecipes(__instance);
				}
			}
		}

		public const string PluginGUID = "com.michal.valheim.seedcrafting";

		public const string PluginName = "Seed Crafting";

		public const string PluginVersion = "1.0.1";

		private static readonly (string CropItem, string SeedItem, int SeedAmount)[] Recipes = new(string, string, int)[5]
		{
			("Carrot", "CarrotSeeds", 2),
			("Turnip", "TurnipSeeds", 2),
			("Onion", "OnionSeeds", 2),
			("Kale", "KaleSeeds", 2),
			("Poteitr", "PoteitrSeeds", 2)
		};

		private const string CraftingStationPrefab = "piece_workbench";

		internal static ManualLogSource Log;

		private static bool _recipesAdded;

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Game.isModded = true;
			new Harmony("com.michal.valheim.seedcrafting").PatchAll(typeof(SeedCraftingPlugin).Assembly);
		}

		private static void AddSeedRecipes(ObjectDB objectDB)
		{
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Expected O, but got Unknown
			CraftingStation val = null;
			GameObject val2 = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("piece_workbench") : null);
			if ((Object)(object)val2 != (Object)null)
			{
				val = val2.GetComponent<CraftingStation>();
			}
			if ((Object)(object)val == (Object)null)
			{
				Log.LogWarning((object)"Nie znaleziono crafting station 'piece_workbench' - przepisy beda bez wymaganej stacji.");
			}
			(string, string, int)[] recipes = Recipes;
			for (int i = 0; i < recipes.Length; i++)
			{
				(string, string, int) tuple = recipes[i];
				string item = tuple.Item1;
				string item2 = tuple.Item2;
				int item3 = tuple.Item3;
				GameObject itemPrefab = objectDB.GetItemPrefab(item);
				GameObject itemPrefab2 = objectDB.GetItemPrefab(item2);
				if ((Object)(object)itemPrefab == (Object)null)
				{
					Log.LogWarning((object)("Pomijam recipe " + item + "->" + item2 + ": brak prefabu warzywa '" + item + "' w ObjectDB."));
					continue;
				}
				if ((Object)(object)itemPrefab2 == (Object)null)
				{
					Log.LogWarning((object)("Pomijam recipe " + item + "->" + item2 + ": brak prefabu nasiona '" + item2 + "' w ObjectDB."));
					continue;
				}
				ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
				ItemDrop component2 = itemPrefab2.GetComponent<ItemDrop>();
				if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null)
				{
					Log.LogWarning((object)("Pomijam recipe " + item + "->" + item2 + ": brak komponentu ItemDrop na prefabie."));
					continue;
				}
				Recipe val3 = ScriptableObject.CreateInstance<Recipe>();
				((Object)val3).name = "Recipe_SeedCrafting_" + item;
				val3.m_item = component2;
				val3.m_amount = item3;
				val3.m_enabled = true;
				val3.m_craftingStation = val;
				val3.m_minStationLevel = 1;
				val3.m_resources = (Requirement[])(object)new Requirement[1]
				{
					new Requirement
					{
						m_resItem = component,
						m_amount = 1,
						m_amountPerLevel = 0
					}
				};
				objectDB.m_recipes.Add(val3);
				Log.LogInfo((object)$"Dodano recipe: 1x {item} -> {item3}x {item2}");
			}
		}
	}
}