Decompiled source of Valharvest v3.3.0

plugins/Valharvest.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using SimpleJson;
using UnityEngine;
using UnityEngine.Serialization;
using Valharvest.Configurations;
using Valharvest.Scripts;
using Valharvest.WorldGen;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Valharvest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Valharvest")]
[assembly: AssemblyCopyright("Copyright Frenvius 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("3.3.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("3.3.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
public class CustomBeehive : MonoBehaviour, Hoverable, Interactable
{
	public string m_name = "";

	public GameObject m_hideWhenPicked;

	public Transform m_spawnPoint;

	public float m_secPerUnit = 800f;

	public int m_maxHoney = 3;

	public ItemDrop m_honeyItem;

	public EffectList m_spawnEffect = new EffectList();

	private ZNetView m_nview;

	private void Awake()
	{
		m_nview = ((Component)this).GetComponent<ZNetView>();
		if (m_nview.GetZDO() != null)
		{
			HidePrefab();
			if (m_nview.IsOwner() && m_nview.GetZDO().GetLong("lastTime", 0L) == 0L)
			{
				m_nview.GetZDO().Set("lastTime", ZNet.instance.GetTime().Ticks);
			}
			m_nview.Register("Extract", (Action<long>)RPC_Extract);
			((MonoBehaviour)this).InvokeRepeating("UpdateBees", 0f, 10f);
			((MonoBehaviour)this).InvokeRepeating("HidePrefab", 0f, 5f);
		}
	}

	private void HidePrefab()
	{
		if (Object.op_Implicit((Object)(object)m_hideWhenPicked))
		{
			int honeyLevel = GetHoneyLevel();
			m_hideWhenPicked.SetActive(honeyLevel > 0);
		}
	}

	public string GetHoverText()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, false, false))
		{
			return Localization.instance.Localize(m_name + "\n$piece_noaccess");
		}
		int honeyLevel = GetHoneyLevel();
		if (honeyLevel > 0)
		{
			return Localization.instance.Localize(m_name + " ( " + m_honeyItem.m_itemData.m_shared.m_name + " x " + honeyLevel + " )\n[<color=yellow><b>$KEY_Use</b></color>] $water_well_extract");
		}
		return Localization.instance.Localize(m_name + " ( $piece_container_empty )\n[<color=yellow><b>$KEY_Use</b></color>] $water_well_check");
	}

	public string GetHoverName()
	{
		return m_name;
	}

	public bool Interact(Humanoid character, bool repeat, bool alt)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		if (repeat)
		{
			return false;
		}
		if (!PrivateArea.CheckAccess(((Component)this).transform.position, 0f, true, false))
		{
			return true;
		}
		if (GetHoneyLevel() > 0)
		{
			Extract();
		}
		else
		{
			((Character)character).Message((MessageType)2, "$water_well_use", 0, (Sprite)null);
		}
		return true;
	}

	public bool UseItem(Humanoid user, ItemData item)
	{
		return false;
	}

	private void Extract()
	{
		m_nview.InvokeRPC("Extract", Array.Empty<object>());
	}

	private void RPC_Extract(long caller)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		int honeyLevel = GetHoneyLevel();
		if (honeyLevel > 0)
		{
			if (Object.op_Implicit((Object)(object)m_hideWhenPicked))
			{
				m_hideWhenPicked.SetActive(false);
			}
			m_spawnEffect.Create(m_spawnPoint.position, Quaternion.identity, (Transform)null, 1f, -1);
			for (int i = 0; i < honeyLevel; i++)
			{
				Vector2 val = Random.insideUnitCircle * 0.5f;
				Vector3 val2 = m_spawnPoint.position + new Vector3(val.x, 0.25f * (float)i, val.y);
				Object.Instantiate<ItemDrop>(m_honeyItem, val2, Quaternion.identity);
			}
			ResetLevel();
		}
	}

	private float GetTimeSinceLastUpdate()
	{
		DateTime dateTime = new DateTime(m_nview.GetZDO().GetLong("lastTime", ZNet.instance.GetTime().Ticks));
		DateTime time = ZNet.instance.GetTime();
		TimeSpan timeSpan = time - dateTime;
		m_nview.GetZDO().Set("lastTime", time.Ticks);
		double num = timeSpan.TotalSeconds;
		if (num < 0.0)
		{
			num = 0.0;
		}
		return (float)num;
	}

	private void ResetLevel()
	{
		m_nview.GetZDO().Set("level", 0);
	}

	private void IncreseLevel(int i)
	{
		int honeyLevel = GetHoneyLevel();
		honeyLevel += i;
		honeyLevel = Mathf.Clamp(honeyLevel, 0, m_maxHoney);
		m_nview.GetZDO().Set("level", honeyLevel);
	}

	private int GetHoneyLevel()
	{
		return m_nview.GetZDO().GetInt("level", 0);
	}

	private void UpdateBees()
	{
		if (GetHoneyLevel() > 0 && Object.op_Implicit((Object)(object)m_hideWhenPicked))
		{
			m_hideWhenPicked.SetActive(true);
		}
		if (m_nview.IsOwner())
		{
			float timeSinceLastUpdate = GetTimeSinceLastUpdate();
			float @float = m_nview.GetZDO().GetFloat("product", 0f);
			@float += timeSinceLastUpdate;
			if (@float > m_secPerUnit)
			{
				int i = (int)(@float / m_secPerUnit);
				IncreseLevel(i);
				@float = 0f;
			}
			m_nview.GetZDO().Set("product", @float);
		}
	}
}
namespace Valharvest
{
	public static class BoneAppetitCompat
	{
		private static bool? _isInstalled;

		public static bool IsInstalled
		{
			get
			{
				if (!_isInstalled.HasValue)
				{
					_isInstalled = Chainloader.PluginInfos.ContainsKey("com.rockerkitten.boneappetit");
					Logger.LogInfo((object)("BoneAppetit detection: " + (_isInstalled.Value ? "INSTALLED" : "NOT FOUND")));
				}
				return _isInstalled.Value;
			}
		}

		public static string GetEggItem()
		{
			if (!IsInstalled)
			{
				return "vh_egg";
			}
			return "rk_egg";
		}

		public static string GetPorkItem()
		{
			if (!IsInstalled)
			{
				return "RawMeat";
			}
			return "rk_pork";
		}

		public static string GetCookingStation(string stationName, bool useBAStations = true)
		{
			if (IsInstalled && useBAStations)
			{
				return stationName;
			}
			switch (stationName)
			{
			case "rk_prep":
				if (Valharvest.Configurations.Valharvest.UseVanillaPrepTable.Value)
				{
					return "piece_preptable";
				}
				return "piece_prep_table";
			case "rk_griddle":
			case "rk_grill":
				return "piece_cooking_pot";
			default:
				return stationName;
			}
		}

		public static void RemapIngredients(RequirementConfig[] requirements)
		{
			if (IsInstalled || requirements == null)
			{
				return;
			}
			for (int i = 0; i < requirements.Length; i++)
			{
				if (requirements[i].Item == "rk_egg")
				{
					requirements[i].Item = "vh_egg";
				}
				else if (requirements[i].Item == "rk_pork")
				{
					requirements[i].Item = "RawMeat";
				}
			}
		}
	}
	public static class Utils
	{
		private const string Name = "name";

		private const string Food = "food";

		private const string Weight = "weight";

		private const string Variants = "variants";

		private const string FoodRegen = "foodRegen";

		private const string FoodStamina = "foodStamina";

		private const string Description = "description";

		private const string MaxStackSize = "maxStackSize";

		private const string FoodBurnTime = "foodBurnTime";

		private const string ConsumeStatusEffect = "consumeStatusEffect";

		public static readonly int MainTex = Shader.PropertyToID("_MainTex");

		public static readonly int Color = Shader.PropertyToID("_Color");

		private static readonly int Cull = Shader.PropertyToID("_Cull");

		private static readonly int Cutoff = Shader.PropertyToID("_Cutoff");

		private static readonly int Height = Shader.PropertyToID("_Height");

		private static readonly int AddSnow = Shader.PropertyToID("_AddSnow");

		private static readonly int AddRain = Shader.PropertyToID("_AddRain");

		private static readonly int CamCull = Shader.PropertyToID("_CamCull");

		private static readonly int Metallic = Shader.PropertyToID("_Metallic");

		private static readonly int SwaySpeed = Shader.PropertyToID("_SwaySpeed");

		private static readonly int MossNormal = Shader.PropertyToID("_MossNormal");

		private static readonly int Glossiness = Shader.PropertyToID("_Glossiness");

		private static readonly int RippleSpeed = Shader.PropertyToID("_RippleSpeed");

		private static readonly int SwayDistance = Shader.PropertyToID("_SwayDistance");

		private static readonly int PushDistance = Shader.PropertyToID("_PushDistance");

		private static readonly int MossTransition = Shader.PropertyToID("_MossTransition");

		private static readonly int RippleDistance = Shader.PropertyToID("_RippleDistance");

		private static readonly int FadeDistanceMin = Shader.PropertyToID("_FadeDistanceMin");

		private static readonly int FadeDistanceMax = Shader.PropertyToID("_FadeDistanceMax");

		private static readonly int RippleDeadzoneMin = Shader.PropertyToID("_RippleDeadzoneMin");

		private static readonly int RippleDeadzoneMax = Shader.PropertyToID("_RippleDeadzoneMax");

		public static void ConfigureMaterial(Material material, Shader shader, JsonObject content, Dictionary<Type, int> typeDict, Dictionary<string, int> getMatItem)
		{
			material.shader = shader;
			foreach (KeyValuePair<string, object> item in content)
			{
				if (!(item.Key == "shader"))
				{
					SetMaterialConfigItems(typeDict, item, material, getMatItem);
				}
			}
		}

		private static void SetMaterialConfigItems(Dictionary<Type, int> typeDict, KeyValuePair<string, object> materialItem, Material material, Dictionary<string, int> getMatItem)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			switch (typeDict[materialItem.Value.GetType()])
			{
			case 0:
				material.SetFloat(getMatItem[materialItem.Key], float.Parse(materialItem.Value.ToString()));
				break;
			case 1:
			{
				Color val = default(Color);
				ColorUtility.TryParseHtmlString(materialItem.Value.ToString(), ref val);
				material.SetColor(Color, val);
				break;
			}
			case 2:
				material.SetFloat(getMatItem[materialItem.Key], float.Parse(materialItem.Value.ToString()));
				break;
			}
		}

		public static Dictionary<Type, int> GetTypeDict()
		{
			return new Dictionary<Type, int>
			{
				{
					typeof(long),
					0
				},
				{
					typeof(string),
					1
				},
				{
					typeof(double),
					2
				}
			};
		}

		public static Dictionary<string, int> GetMatItem()
		{
			return new Dictionary<string, int>
			{
				{ "glossiness", Glossiness },
				{ "cutoff", Cutoff },
				{ "mossNormal", MossNormal },
				{ "mossTransition", MossTransition },
				{ "addSnow", AddSnow },
				{ "addRain", AddRain },
				{ "height", Height },
				{ "swaySpeed", SwaySpeed },
				{ "metallic", Metallic },
				{ "swayDistance", SwayDistance },
				{ "rippleSpeed", RippleSpeed },
				{ "rippleDistance", RippleDistance },
				{ "rippleDeadzoneMin", RippleDeadzoneMin },
				{ "rippleDeadzoneMax", RippleDeadzoneMax },
				{ "pushDistance", PushDistance },
				{ "camCull", CamCull },
				{ "cull", Cull },
				{ "color", Color },
				{ "fadeDistanceMin", FadeDistanceMin },
				{ "fadeDistanceMax", FadeDistanceMax }
			};
		}

		public static void ChangeItemDrop(CustomItem item, string configObject)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BoneAppetitBalance.resources");
			if (stream != null)
			{
				JsonObject content = SimpleJson.DeserializeObject<JsonObject>(SimpleJson.DeserializeObject<JsonObject>(new StreamReader(stream).ReadToEnd())[configObject].ToString());
				SharedData shared = item.ItemDrop.m_itemData.m_shared;
				SetItemDropFromContent(content, shared);
			}
		}

		public static void LoadNewFood()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("newFoodsConfig.resources");
			if (stream == null)
			{
				return;
			}
			foreach (KeyValuePair<string, object> item in SimpleJson.DeserializeObject<JsonObject>(new StreamReader(stream).ReadToEnd()))
			{
				string key = item.Key;
				JsonObject val = SimpleJson.DeserializeObject<JsonObject>(item.Value.ToString());
				RequirementConfig[] requirements = SimpleJson.DeserializeObject<RequirementConfig[]>(val["requirements"].ToString());
				BoneAppetitCompat.RemapIngredients(requirements);
				CustomItem val2 = null;
				try
				{
					val2 = new CustomItem(Main.modAssets.LoadAsset<GameObject>(key), true, new ItemConfig
					{
						Name = val["name"].ToString(),
						Enabled = true,
						Requirements = requirements,
						CraftingStation = GetCookingStation(val),
						Amount = Convert.ToInt32(val["amount"].ToString())
					});
					ChangeFoodDrop(val2, key);
				}
				catch (Exception ex)
				{
					Logger.LogError((object)("Error while loading " + key + ": " + ex.Message));
				}
				finally
				{
					ItemManager.Instance.AddItem(val2);
				}
			}
			PrefabManager.OnVanillaPrefabsAvailable -= LoadNewFood;
		}

		private static string GetCookingStation(JsonObject foodObject)
		{
			return BoneAppetitCompat.GetCookingStation(foodObject["craftingStation"].ToString(), Valharvest.Configurations.Valharvest.UseBoneAppetitCookingStations.Value);
		}

		public static void LoadBalancedFood()
		{
			if (!BoneAppetitCompat.IsInstalled)
			{
				ItemManager.OnItemsRegisteredFejd -= LoadBalancedFood;
				return;
			}
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BoneAppetitBalance.resources");
			if (stream == null)
			{
				return;
			}
			foreach (KeyValuePair<string, object> item in SimpleJson.DeserializeObject<JsonObject>(new StreamReader(stream).ReadToEnd()))
			{
				string key = item.Key;
				JsonObject val = SimpleJson.DeserializeObject<JsonObject>(item.Value.ToString());
				RequirementConfig[] requirements = SimpleJson.DeserializeObject<RequirementConfig[]>(val["requirements"].ToString());
				BoneAppetitCompat.RemapIngredients(requirements);
				RegisterFood(key, key, Convert.ToInt32(val["amount"].ToString()), GetCookingStation(val), requirements);
			}
			ItemManager.OnItemsRegisteredFejd -= LoadBalancedFood;
		}

		private static void ChangeFoodDrop(CustomItem item, string configObject)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("newFoodsConfig.resources");
			if (stream != null)
			{
				JsonObject content = SimpleJson.DeserializeObject<JsonObject>(SimpleJson.DeserializeObject<JsonObject>(new StreamReader(stream).ReadToEnd())[configObject].ToString());
				SharedData shared = item.ItemDrop.m_itemData.m_shared;
				SetItemDropFromContent(content, shared);
			}
		}

		private static void SetItemDropFromContent(JsonObject content, SharedData itemDrop)
		{
			if (content["name"] != null)
			{
				itemDrop.m_name = content["name"].ToString();
			}
			if (content["description"] != null)
			{
				itemDrop.m_description = content["description"].ToString();
			}
			if (content["weight"] != null)
			{
				itemDrop.m_weight = float.Parse(content["weight"].ToString());
			}
			if (content["maxStackSize"] != null)
			{
				itemDrop.m_maxStackSize = int.Parse(content["maxStackSize"].ToString());
			}
			if (content["variants"] != null)
			{
				itemDrop.m_variants = int.Parse(content["variants"].ToString());
			}
			if (content["food"] != null)
			{
				itemDrop.m_food = float.Parse(content["food"].ToString());
			}
			if (content["foodStamina"] != null)
			{
				itemDrop.m_foodStamina = float.Parse(content["foodStamina"].ToString());
			}
			if (content["foodBurnTime"] != null)
			{
				itemDrop.m_foodBurnTime = float.Parse(content["foodBurnTime"].ToString()) * 60f;
			}
			if (content["foodRegen"] != null)
			{
				itemDrop.m_foodRegen = float.Parse(content["foodRegen"].ToString());
			}
			if (content["consumeStatusEffect"] != null)
			{
				StatusEffect consumeStatusEffect = Main.modAssets.LoadAsset<StatusEffect>(content["consumeStatusEffect"].ToString());
				itemDrop.m_consumeStatusEffect = consumeStatusEffect;
			}
		}

		private static void RegisterFood(string name, string prefab, int amount, string craftingStation, RequirementConfig[] requirements)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0048: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			CustomItem item = ItemManager.Instance.GetItem(prefab);
			ItemManager.Instance.RemoveRecipe("Recipe_" + prefab);
			try
			{
				CustomRecipe val = new CustomRecipe(new RecipeConfig
				{
					Item = prefab,
					Amount = amount,
					CraftingStation = craftingStation,
					Requirements = requirements
				});
				ChangeItemDrop(item, prefab);
				ItemManager.Instance.AddRecipe(val);
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Error while loading " + name + ": " + ex.Message));
			}
		}

		public static string ReadEmbeddedFile(string embeddedName)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedName);
			if (stream == null)
			{
				return null;
			}
			return new StreamReader(stream).ReadToEnd();
		}
	}
	[BepInPlugin("com.frenvius.Valharvest", "Valharvest", "3.3.0")]
	[BepInDependency("com.jotunn.jotunn", "2.7.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class Main : BaseUnityPlugin
	{
		public const string ModGuid = "com.frenvius.Valharvest";

		public const string ModName = "Valharvest";

		public const string Version = "3.3.0";

		public static AssetBundle modAssets;

		public static EffectList loxMilkSfx;

		public static EffectList boneMealVfx;

		public static Texture2D newEggTexture;

		public static Texture2D pizzaPlateTexture;

		public static Sprite newEggSprite;

		public static Sprite pizzaSprite;

		public static bool IsFarmingModInstalled;

		public static KeyboardShortcut MassPlantShortcut;

		public GameObject greydwarfFab;

		public GameObject trollFab;

		public GameObject goblinFab;

		public GameObject draugrFab;

		public GameObject greydwarfBruteFab;

		public GameObject draugrEliteFab;

		public GameObject seagullFab;

		private Harmony _h;

		public void Awake()
		{
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			CreateConfigValues();
			AssetLoad();
			Loaders.LoadItems();
			Loaders.LoadPieces();
			PrefabManager.OnVanillaPrefabsAvailable += Utils.LoadNewFood;
			PrefabManager.OnVanillaPrefabsAvailable += LoadSounds;
			PrefabManager.OnVanillaPrefabsAvailable += PlantUtils.AddCustomPlantsPrefab;
			if (BoneAppetitCompat.IsInstalled)
			{
				ItemManager.OnItemsRegisteredFejd += Utils.LoadBalancedFood;
				ItemManager.OnItemsRegisteredFejd += LoadBalance;
			}
			ItemManager.OnItemsRegisteredFejd += Loaders.LoadCookingStations;
			PrefabManager.OnVanillaPrefabsAvailable += Plants.AddCustomPlants;
			PrefabManager.OnVanillaPrefabsAvailable += CustomDrops;
			PrefabManager.OnVanillaPrefabsAvailable += CheckIfFarmingModInstalled;
			PrefabManager.OnVanillaPrefabsAvailable += HandlePrefabComponent.ZNetViewAwakePatch;
			PrefabManager.OnPrefabsRegistered += HandlePrefabComponent.PrepTableSmokePatch;
			PrefabManager.OnPrefabsRegistered += HandlePrefabComponent.FoodCrateEffectsPatch;
			PrefabManager.OnPrefabsRegistered += CustomFeed;
			PrefabManager.OnPrefabsRegistered += PrepTableRecipeCopier.CopyVanillaPrepTableRecipes;
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new ExportItemsCommand());
			if (Valharvest.Configurations.Valharvest.DropEnabled.Value)
			{
				PrefabManager.OnVanillaPrefabsAvailable += NewDrops;
			}
			_h = new Harmony("mod.valharvest");
			_h.PatchAll();
		}

		private void OnDestroy()
		{
			Logger.LogInfo((object)"Valharvest: OnDestroy");
			_h.UnpatchSelf();
		}

		private static void CheckIfFarmingModInstalled()
		{
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			Chainloader.Start();
			using (IEnumerator<KeyValuePair<string, PluginInfo>> enumerator = Chainloader.PluginInfos.Where((KeyValuePair<string, PluginInfo> plugin) => plugin.Value.Metadata.GUID == "org.bepinex.plugins.farming").GetEnumerator())
			{
				if (enumerator.MoveNext())
				{
					_ = enumerator.Current;
					IsFarmingModInstalled = true;
				}
			}
			if (IsFarmingModInstalled)
			{
				ConfigFile config = Chainloader.PluginInfos["org.bepinex.plugins.farming"].Instance.Config;
				foreach (ConfigDefinition key in config.Keys)
				{
					if (((object)key).ToString().Contains("Toggle Mass Plant"))
					{
						ConfigEntryBase val = config[key];
						KeyCode val2 = (KeyCode)Enum.Parse(typeof(KeyCode), val.BoxedValue.ToString());
						MassPlantShortcut = new KeyboardShortcut(val2, Array.Empty<KeyCode>());
					}
				}
			}
			PrefabManager.OnVanillaPrefabsAvailable -= CheckIfFarmingModInstalled;
		}

		public void CreateConfigValues()
		{
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			new Valharvest.Configurations.Valharvest(((BaseUnityPlugin)this).Config);
		}

		public void LoadBalance()
		{
			if (!BoneAppetitCompat.IsInstalled)
			{
				ItemManager.OnItemsRegistered -= LoadBalance;
				return;
			}
			try
			{
				BoneAppetitBalance.SeagullEgg();
				BoneAppetitBalance.Kabob();
				BoneAppetitBalance.Pizza();
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Error while running OnItemsRegistered: " + ex.Message));
			}
			finally
			{
				Logger.LogInfo((object)"Load Complete.");
				ItemManager.OnItemsRegistered -= LoadBalance;
			}
		}

		public void AssetLoad()
		{
			modAssets = AssetUtils.LoadAssetBundleFromResources("valharvest", Assembly.GetExecutingAssembly());
			newEggTexture = modAssets.LoadAsset<Texture2D>("egg");
			newEggSprite = modAssets.LoadAsset<Sprite>("eggsprite");
			pizzaPlateTexture = modAssets.LoadAsset<Texture2D>("pizza_plate");
			pizzaSprite = modAssets.LoadAsset<Sprite>("pizzaSprite");
			Logger.LogInfo((object)"Preparing the plants...");
		}

		public void LoadSounds()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			GameObject val = modAssets.LoadAsset<GameObject>("sfx_pours_milk");
			PrefabManager.Instance.AddPrefab(new CustomPrefab(val, true));
			GameObject val2 = modAssets.LoadAsset<GameObject>("sfx_lox_pet_milk");
			PrefabManager.Instance.AddPrefab(new CustomPrefab(val2, true));
			GameObject val3 = modAssets.LoadAsset<GameObject>("sfx_lox_pet");
			PrefabManager.Instance.AddPrefab(new CustomPrefab(val3, true));
			GameObject val4 = modAssets.LoadAsset<GameObject>("vfx_bone_meal");
			PrefabManager.Instance.AddPrefab(new CustomPrefab(val4, true));
			EffectList val5 = new EffectList();
			val5.m_effectPrefabs = (EffectData[])(object)new EffectData[2]
			{
				new EffectData
				{
					m_prefab = val2,
					m_enabled = true
				},
				new EffectData
				{
					m_prefab = val,
					m_enabled = true
				}
			};
			loxMilkSfx = val5;
			val5 = new EffectList();
			val5.m_effectPrefabs = (EffectData[])(object)new EffectData[1]
			{
				new EffectData
				{
					m_prefab = val4,
					m_enabled = true
				}
			};
			boneMealVfx = val5;
			PrefabManager.OnVanillaPrefabsAvailable -= LoadSounds;
			CookingConversionConfig val6 = new CookingConversionConfig
			{
				FromItem = "apple",
				ToItem = "baked_apple",
				CookTime = 5f,
				Station = "piece_cookingstation"
			};
			ItemManager.Instance.AddItemConversion(new CustomItemConversion((ConversionConfig)(object)val6));
		}

		public void NewDrops()
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Expected O, but got Unknown
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Expected O, but got Unknown
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Expected O, but got Unknown
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Expected O, but got Unknown
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Expected O, but got Unknown
			greydwarfFab = PrefabManager.Instance.GetPrefab("Greydwarf");
			trollFab = PrefabManager.Instance.GetPrefab("Troll");
			goblinFab = PrefabManager.Instance.GetPrefab("Goblin");
			draugrFab = PrefabManager.Instance.GetPrefab("Draugr");
			greydwarfBruteFab = PrefabManager.Instance.GetPrefab("Greydwarf_Elite");
			draugrEliteFab = PrefabManager.Instance.GetPrefab("Draugr_Elite");
			GameObject prefab = PrefabManager.Instance.GetPrefab("pepper");
			GameObject prefab2 = PrefabManager.Instance.GetPrefab("tomato");
			GameObject prefab3 = PrefabManager.Instance.GetPrefab("garlic");
			GameObject prefab4 = PrefabManager.Instance.GetPrefab("rice");
			GameObject prefab5 = PrefabManager.Instance.GetPrefab("potato");
			GameObject prefab6 = PrefabManager.Instance.GetPrefab("pumpkin");
			greydwarfFab.GetComponent<CharacterDrop>().m_drops.Add(new Drop
			{
				m_prefab = prefab,
				m_amountMin = 1,
				m_amountMax = 2,
				m_chance = 0.4f,
				m_levelMultiplier = true,
				m_onePerPlayer = false
			});
			trollFab.GetComponent<CharacterDrop>().m_drops.Add(new Drop
			{
				m_prefab = prefab3,
				m_amountMin = 1,
				m_amountMax = 3,
				m_chance = 0.4f,
				m_levelMultiplier = true,
				m_onePerPlayer = false
			});
			goblinFab.GetComponent<CharacterDrop>().m_drops.Add(new Drop
			{
				m_prefab = prefab4,
				m_amountMin = 1,
				m_amountMax = 1,
				m_chance = 0.4f,
				m_levelMultiplier = true,
				m_onePerPlayer = false
			});
			draugrFab.GetComponent<CharacterDrop>().m_drops.Add(new Drop
			{
				m_prefab = prefab2,
				m_amountMin = 1,
				m_amountMax = 1,
				m_chance = 0.4f,
				m_levelMultiplier = true,
				m_onePerPlayer = false
			});
			greydwarfBruteFab.GetComponent<CharacterDrop>().m_drops.Add(new Drop
			{
				m_prefab = prefab5,
				m_amountMin = 1,
				m_amountMax = 1,
				m_chance = 0.4f,
				m_levelMultiplier = true,
				m_onePerPlayer = false
			});
			draugrEliteFab.GetComponent<CharacterDrop>().m_drops.Add(new Drop
			{
				m_prefab = prefab6,
				m_amountMin = 1,
				m_amountMax = 1,
				m_chance = 0.4f,
				m_levelMultiplier = true,
				m_onePerPlayer = false
			});
			PrefabManager.OnVanillaPrefabsAvailable -= NewDrops;
		}

		public void CustomDrops()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			if (!BoneAppetitCompat.IsInstalled)
			{
				try
				{
					GameObject prefab = PrefabManager.Instance.GetPrefab("Seagal");
					if ((Object)(object)prefab != (Object)null)
					{
						GameObject prefab2 = PrefabManager.Instance.GetPrefab(BoneAppetitCompat.GetEggItem());
						if ((Object)(object)prefab2 != (Object)null)
						{
							DropOnDestroyed component = prefab.GetComponent<DropOnDestroyed>();
							if ((Object)(object)component != (Object)null)
							{
								component.m_dropWhenDestroyed.m_drops.Add(new DropData
								{
									m_item = prefab2,
									m_stackMin = 1,
									m_stackMax = 2,
									m_weight = 0.75f
								});
								Logger.LogInfo((object)"Added vh_egg drop to seagulls (BoneAppetit not installed)");
							}
						}
					}
				}
				catch (Exception ex)
				{
					Logger.LogWarning((object)("Failed to add egg drops to seagulls: " + ex.Message));
				}
			}
			PrefabManager.OnVanillaPrefabsAvailable -= CustomDrops;
		}

		public void AddConsumableItemsToCreature(string[] items, string creature)
		{
			MonsterAI component = PrefabManager.Instance.GetPrefab(creature).GetComponent<MonsterAI>();
			foreach (string text in items)
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab(text);
				component.m_consumeItems.Add(prefab.GetComponent<ItemDrop>());
			}
		}

		public void CustomFeed()
		{
			string[] items = new string[3] { "apple", "tomato", "potato" };
			AddConsumableItemsToCreature(items, "Boar");
			string[] items2 = new string[1] { BoneAppetitCompat.GetPorkItem() };
			AddConsumableItemsToCreature(items2, "Wolf");
			PrefabManager.OnVanillaPrefabsAvailable -= CustomFeed;
		}
	}
}
namespace Valharvest.WorldGen
{
	public static class Plants
	{
		private const string Min = "min";

		private const string Max = "max";

		private const string Biome = "biome";

		private const string InForest = "inForest";

		private const string BiomeArea = "biomeArea";

		private const string GroupRadius = "groupRadius";

		private const string GroupSizeMin = "groupSizeMin";

		private const string GroupSizeMax = "groupSizeMax";

		private const string MinAltitude = "minAltitude";

		private const string MaxAltitude = "maxAltitude";

		private const string ForestThresholdMin = "forestThresholdMin";

		private const string ForestThresholdMax = "forestThresholdMax";

		private const Biome Swamp = 2;

		private const Biome Plains = 16;

		private const Biome Meadows = 1;

		private const Biome Mountain = 4;

		private const Biome Mistlands = 512;

		private const Biome BlackForest = 8;

		private const BiomeArea Edge = 1;

		private const BiomeArea Median = 2;

		private const BiomeArea Everything = 3;

		public static void AddCustomPlants()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			string text = Utils.ReadEmbeddedFile("plantsLocations.resources");
			if (text == null)
			{
				return;
			}
			foreach (KeyValuePair<string, object> item in SimpleJson.DeserializeObject<JsonObject>(text))
			{
				GameObject val = PrefabManager.Instance.CreateClonedPrefab(item.Key + "_wild", item.Key);
				JsonObject content = SimpleJson.DeserializeObject<JsonObject>(item.Value.ToString());
				try
				{
					ZoneManager.Instance.AddCustomVegetation(new CustomVegetation(val, true, GetVegetationConfig(content)));
				}
				catch (Exception ex)
				{
					Logger.LogError((object)("Error while loading " + item.Key + ": " + ex.Message));
				}
				finally
				{
					PrefabManager.OnVanillaPrefabsAvailable -= AddCustomPlants;
				}
			}
		}

		private static VegetationConfig GetVegetationConfig(JsonObject content)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			VegetationConfig val = new VegetationConfig();
			Dictionary<string, Biome> biome = GetBiome();
			Dictionary<string, BiomeArea> biomeArea = GetBiomeArea();
			if (content["min"] != null)
			{
				val.Min = float.Parse(content["min"].ToString());
			}
			if (content["max"] != null)
			{
				val.Max = float.Parse(content["max"].ToString());
			}
			if (content["groupSizeMin"] != null)
			{
				val.GroupSizeMin = int.Parse(content["groupSizeMin"].ToString());
			}
			if (content["groupSizeMax"] != null)
			{
				val.GroupSizeMax = int.Parse(content["groupSizeMax"].ToString());
			}
			if (content["groupRadius"] != null)
			{
				val.GroupRadius = float.Parse(content["groupRadius"].ToString());
			}
			if (content["minAltitude"] != null)
			{
				val.MinAltitude = float.Parse(content["minAltitude"].ToString());
			}
			if (content["maxAltitude"] != null)
			{
				val.MaxAltitude = float.Parse(content["maxAltitude"].ToString());
			}
			if (content["biome"] != null)
			{
				val.Biome = biome[content["biome"].ToString()];
			}
			if (content["biomeArea"] != null)
			{
				val.BiomeArea = biomeArea[content["biomeArea"].ToString()];
			}
			if (content["inForest"] != null)
			{
				val.InForest = Convert.ToBoolean(content["inForest"].ToString());
			}
			if (content["forestThresholdMin"] != null)
			{
				val.ForestThresholdMin = float.Parse(content["forestThresholdMin"].ToString());
			}
			if (content["forestThresholdMax"] != null)
			{
				val.ForestThresholdMax = float.Parse(content["forestThresholdMax"].ToString());
			}
			return val;
		}

		private static Dictionary<string, Biome> GetBiome()
		{
			return new Dictionary<string, Biome>
			{
				{
					"swamp",
					(Biome)2
				},
				{
					"plains",
					(Biome)16
				},
				{
					"meadows",
					(Biome)1
				},
				{
					"mountain",
					(Biome)4
				},
				{
					"mistlands",
					(Biome)512
				},
				{
					"black_forest",
					(Biome)8
				}
			};
		}

		private static Dictionary<string, BiomeArea> GetBiomeArea()
		{
			return new Dictionary<string, BiomeArea>
			{
				{
					"edge",
					(BiomeArea)1
				},
				{
					"median",
					(BiomeArea)2
				},
				{
					"everything",
					(BiomeArea)3
				}
			};
		}
	}
	public static class PlantUtils
	{
		public static void AddCustomPlantsPrefab()
		{
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			string text = Utils.ReadEmbeddedFile("plants.resources");
			if (text == null)
			{
				return;
			}
			foreach (KeyValuePair<string, object> item in SimpleJson.DeserializeObject<JsonObject>(text))
			{
				Dictionary<string, AssetBundle> assetBundle = Loaders.GetAssetBundle();
				JsonObject val = SimpleJson.DeserializeObject<JsonObject>(item.Value.ToString());
				string key = val["assetBundle"].ToString();
				object obj = val["dropConfig"];
				object obj2 = val["respawnConfig"];
				Dictionary<string, ConfigEntry<int>> dropConfigs = Valharvest.Configurations.Valharvest.GetDropConfigs();
				Dictionary<string, ConfigEntry<int>> respawnTimeConfigs = Valharvest.Configurations.Valharvest.GetRespawnTimeConfigs();
				GameObject val2 = assetBundle[key].LoadAsset<GameObject>(item.Key);
				LoadPlantMaterials(val2, val);
				try
				{
					if (obj != null)
					{
						ConfigEntry<int> val3 = dropConfigs[obj.ToString()];
						val2.GetComponent<Pickable>().m_amount = val3.Value;
					}
					if (obj2 != null)
					{
						ConfigEntry<int> val4 = respawnTimeConfigs[obj2.ToString()];
						val2.GetComponent<Pickable>().m_respawnTimeMinutes = val4.Value * 60;
					}
					if (val["crafting"] != null)
					{
						CustomPiece val5 = Loaders.CreatePieceRecipe(val2, val);
						PieceManager.Instance.AddPiece(val5);
					}
					else
					{
						PrefabManager.Instance.AddPrefab(new CustomPrefab(val2, true));
					}
				}
				catch (Exception ex)
				{
					Logger.LogError((object)("Error while loading " + item.Key + ": " + ex.Message));
				}
				finally
				{
					PrefabManager.OnVanillaPrefabsAvailable -= AddCustomPlantsPrefab;
				}
			}
		}

		private static void LoadPlantMaterials(GameObject plantPrefab, JsonObject plantObject)
		{
			JsonObject val = SimpleJson.DeserializeObject<JsonObject>(plantObject["materials"].ToString());
			foreach (Renderer renderer in ShaderHelper.GetRenderers(plantPrefab))
			{
				Material[] sharedMaterials = renderer.sharedMaterials;
				foreach (Material val2 in sharedMaterials)
				{
					if (!((Object)(object)val2 == (Object)null))
					{
						string name = ((Object)val2).name;
						if (val.ContainsKey(name) && !string.IsNullOrEmpty(val[name].ToString()))
						{
							Dictionary<Type, int> typeDict = Utils.GetTypeDict();
							Dictionary<string, int> matItem = Utils.GetMatItem();
							JsonObject val3 = SimpleJson.DeserializeObject<JsonObject>(val[name].ToString());
							Shader prefab = Cache.GetPrefab<Shader>(val3["shader"].ToString());
							Texture mainTexture = val2.mainTexture;
							Utils.ConfigureMaterial(val2, prefab, val3, typeDict, matItem);
							val2.SetTexture(Utils.MainTex, mainTexture);
						}
					}
				}
			}
		}
	}
}
namespace Valharvest.Scripts
{
	public static class BoneAppetitBalance
	{
		public static void SeagullEgg()
		{
			try
			{
				foreach (Material item in from rend in ShaderHelper.GetRenderers(PrefabManager.Instance.GetPrefab("rk_egg"))
					from mat in rend.materials
					where mat.HasProperty("_MainTex")
					select mat)
				{
					item.SetTexture(Utils.MainTex, (Texture)(object)Main.newEggTexture);
				}
				ItemDrop itemDrop = ItemManager.Instance.GetItem("rk_egg").ItemDrop;
				itemDrop.m_itemData.m_shared.m_description = "A small egg.";
				itemDrop.m_itemData.m_shared.m_icons[0] = Main.newEggSprite;
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Error while loading SeagullEgg: " + ex.Message));
			}
			finally
			{
				Logger.LogInfo((object)"SeagullEgg Loaded.");
			}
		}

		public static void Kabob()
		{
			CustomItem item = ItemManager.Instance.GetItem("rk_kabob");
			if (Valharvest.Configurations.Valharvest.KabobName.Value)
			{
				item.ItemDrop.m_itemData.m_shared.m_name = "Kebab";
			}
		}

		public static void Pizza()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			CustomItem item = ItemManager.Instance.GetItem("rk_pizza");
			Color val = default(Color);
			Color val2 = default(Color);
			foreach (Renderer renderer in ShaderHelper.GetRenderers(PrefabManager.Instance.GetPrefab("rk_pizza")))
			{
				string name = ((Object)renderer).name;
				if (!(name == "pizza"))
				{
					if (name == "Tarelka001")
					{
						Material[] materials = renderer.materials;
						foreach (Material obj in materials)
						{
							ColorUtility.TryParseHtmlString("#855B41", ref val);
							obj.SetTexture(Utils.MainTex, (Texture)(object)Main.pizzaPlateTexture);
							obj.SetColor(Utils.Color, val);
						}
					}
				}
				else
				{
					Material[] materials = renderer.materials;
					foreach (Material obj2 in materials)
					{
						ColorUtility.TryParseHtmlString("#FFFFFF", ref val2);
						obj2.SetColor(Utils.Color, val2);
					}
				}
			}
			item.ItemDrop.m_itemData.m_shared.m_icons[0] = Main.pizzaSprite;
		}
	}
	[HarmonyPatch]
	public static class BoneAppetitNotice
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static PopupButtonCallback <0>__OnOk;
		}

		[CompilerGenerated]
		private sealed class <ShowWhenAvailable>d__4 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private float <elapsed>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ShowWhenAvailable>d__4(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Expected O, but got Unknown
				//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cc: Expected O, but got Unknown
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<elapsed>5__2 = 0f;
					goto IL_0061;
				case 1:
					<>1__state = -1;
					<elapsed>5__2 += 0.2f;
					goto IL_0061;
				case 2:
					{
						<>1__state = -1;
						break;
					}
					IL_0061:
					if (!UnifiedPopup.IsAvailable() && <elapsed>5__2 < 10f)
					{
						<>2__current = (object)new WaitForSeconds(0.2f);
						<>1__state = 1;
						return true;
					}
					if (!UnifiedPopup.IsAvailable())
					{
						return false;
					}
					break;
				}
				if (UnifiedPopup.IsVisible())
				{
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				object obj = <>O.<0>__OnOk;
				if (obj == null)
				{
					PopupButtonCallback val = OnOk;
					<>O.<0>__OnOk = val;
					obj = (object)val;
				}
				UnifiedPopup.Push((PopupBase)new WarningPopup("$valharvest_ba_notice_title", "$valharvest_ba_notice_body", (PopupButtonCallback)obj, true));
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private const float MaxWaitSeconds = 10f;

		private const float PollInterval = 0.2f;

		private static bool _shownThisSession;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(FejdStartup), "Awake")]
		public static void FejdStartupAwakePostfix(FejdStartup __instance)
		{
			if (!_shownThisSession && BoneAppetitCompat.IsInstalled && !Valharvest.Configurations.Valharvest.UseBoneAppetitCookingStations.Value && !Valharvest.Configurations.Valharvest.BoneAppetitNoticeShown.Value)
			{
				_shownThisSession = true;
				((MonoBehaviour)__instance).StartCoroutine(ShowWhenAvailable());
			}
		}

		[IteratorStateMachine(typeof(<ShowWhenAvailable>d__4))]
		private static IEnumerator ShowWhenAvailable()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ShowWhenAvailable>d__4(0);
		}

		private static void OnOk()
		{
			Valharvest.Configurations.Valharvest.BoneAppetitNoticeShown.Value = true;
			UnifiedPopup.Pop();
		}
	}
	public static class ConsumableItemExtractor
	{
		private static HashSet<string> GetValharvestPrefabNames()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			HashSet<string> hashSet = new HashSet<string>();
			try
			{
				foreach (string key in ((JsonObject)SimpleJson.DeserializeObject(Utils.ReadEmbeddedFile("items.resources"))).Keys)
				{
					hashSet.Add(key);
				}
			}
			catch
			{
			}
			try
			{
				foreach (string key2 in ((JsonObject)SimpleJson.DeserializeObject(Utils.ReadEmbeddedFile("newFoodsConfig.resources"))).Keys)
				{
					hashSet.Add(key2);
				}
			}
			catch
			{
			}
			try
			{
				foreach (string key3 in ((JsonObject)SimpleJson.DeserializeObject(Utils.ReadEmbeddedFile("plants.resources"))).Keys)
				{
					hashSet.Add(key3);
				}
			}
			catch
			{
			}
			return hashSet;
		}

		public static void GenerateConsumableItemList()
		{
			Logger.LogInfo((object)"Starting item extraction...");
			if (!Object.op_Implicit((Object)(object)ObjectDB.instance))
			{
				Logger.LogError((object)"ObjectDB not available. Make sure you're in-game.");
				return;
			}
			JsonArray val = ExtractAllItems();
			File.WriteAllText("itemdrops.json", ((object)val).ToString());
			Logger.LogInfo((object)$"Wrote itemdrops.json with {((List<object>)(object)val).Count} items");
			JsonArray val2 = ExtractAllRecipes();
			File.WriteAllText("recipes.json", ((object)val2).ToString());
			Logger.LogInfo((object)$"Wrote recipes.json with {((List<object>)(object)val2).Count} recipes");
			Logger.LogInfo((object)"Item extraction complete!");
		}

		private static JsonArray ExtractAllItems()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_004c: 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: 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_00db: Expected O, but got Unknown
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected O, but got Unknown
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Expected I4, but got Unknown
			//IL_0661: Unknown result type (might be due to invalid IL or missing references)
			//IL_0679: Unknown result type (might be due to invalid IL or missing references)
			JsonArray val = new JsonArray();
			HashSet<string> hashSet = new HashSet<string>();
			HashSet<string> valharvestPrefabNames = GetValharvestPrefabNames();
			string text = "icons";
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			int num = 0;
			foreach (ItemType value in Enum.GetValues(typeof(ItemType)))
			{
				foreach (ItemDrop allItem in ObjectDB.instance.GetAllItems(value, ""))
				{
					if ((Object)(object)allItem == (Object)null || allItem.m_itemData == null || allItem.m_itemData.m_shared == null)
					{
						continue;
					}
					string name = ((Object)((Component)allItem).gameObject).name;
					if (hashSet.Contains(name) || valharvestPrefabNames.Contains(name))
					{
						continue;
					}
					hashSet.Add(name);
					JsonObject val3 = new JsonObject();
					SharedData shared = allItem.m_itemData.m_shared;
					val3.Add("var_name", (object)(shared.m_name ?? ""));
					val3.Add("raw_name", (object)Localization.instance.Localize(shared.m_name ?? ""));
					val3.Add("true_name", (object)name);
					JsonObject val4 = new JsonObject();
					val4.Add("raw_name", (object)Localization.instance.Localize(shared.m_name ?? ""));
					val4.Add("var_name", (object)(shared.m_name ?? ""));
					val4.Add("item_type_name", (object)((object)(ItemType)(ref shared.m_itemType)).ToString());
					val4.Add("item_type", (object)(int)shared.m_itemType);
					val4.Add("description", (object)Localization.instance.Localize(shared.m_description ?? ""));
					val4.Add("prefab_name", (object)name);
					val4.Add("food", (object)shared.m_food);
					val4.Add("food_burn_time", (object)shared.m_foodBurnTime);
					val4.Add("food_regen", (object)shared.m_foodRegen);
					val4.Add("food_stamina", (object)shared.m_foodStamina);
					val4.Add("armor", (object)shared.m_armor);
					val4.Add("armor_per_level", (object)shared.m_armorPerLevel);
					val4.Add("attack_force", (object)shared.m_attackForce);
					val4.Add("backstab_bonus", (object)shared.m_backstabBonus);
					val4.Add("block_power", (object)shared.m_blockPower);
					val4.Add("block_power_per_level", (object)shared.m_blockPowerPerLevel);
					val4.Add("deflection_force", (object)shared.m_deflectionForce);
					val4.Add("deflection_force_per_level", (object)shared.m_deflectionForcePerLevel);
					val4.Add("ai_attack_interval", (object)shared.m_aiAttackInterval);
					val4.Add("ai_attack_max_angle", (object)shared.m_aiAttackMaxAngle);
					val4.Add("ai_attack_range", (object)shared.m_aiAttackRange);
					val4.Add("ai_attack_range_min", (object)shared.m_aiAttackRangeMin);
					val4.Add("ai_prioritized", (object)shared.m_aiPrioritized);
					val4.Add("ai_target_type", (object)((object)(AiTarget)(ref shared.m_aiTargetType)).ToString());
					val4.Add("ai_when_flying", (object)shared.m_aiWhenFlying);
					val4.Add("ai_when_swiming", (object)shared.m_aiWhenSwiming);
					val4.Add("ai_when_walking", (object)shared.m_aiWhenWalking);
					val4.Add("animation_state", (object)((object)(AnimationState)(ref shared.m_animationState)).ToString());
					val4.Add("blockable", (object)shared.m_blockable);
					val4.Add("can_be_reparied", (object)shared.m_canBeReparied);
					val4.Add("destroy_broken", (object)shared.m_destroyBroken);
					val4.Add("dodgeable", (object)shared.m_dodgeable);
					val4.Add("durability_drain", (object)shared.m_durabilityDrain);
					val4.Add("durability_per_level", (object)shared.m_durabilityPerLevel);
					val4.Add("equip_duration", (object)shared.m_equipDuration);
					val4.Add("helmet_hide_hair", (object)((object)(HelmetHairType)(ref shared.m_helmetHideHair)).ToString());
					val4.Add("max_durability", (object)shared.m_maxDurability);
					val4.Add("max_quality", (object)shared.m_maxQuality);
					val4.Add("max_stack_size", (object)shared.m_maxStackSize);
					val4.Add("movement_modifier", (object)shared.m_movementModifier);
					val4.Add("quest_item", (object)shared.m_questItem);
					val4.Add("set_size", (object)shared.m_setSize);
					val4.Add("teleportable", (object)shared.m_teleportable);
					val4.Add("timed_block_bonus", (object)shared.m_timedBlockBonus);
					val4.Add("tool_tier", (object)shared.m_toolTier);
					val4.Add("use_durability", (object)shared.m_useDurability);
					val4.Add("use_durability_drain", (object)shared.m_useDurabilityDrain);
					val4.Add("value", (object)shared.m_value);
					val4.Add("variants", (object)shared.m_variants);
					val4.Add("weight", (object)shared.m_weight);
					val4.Add("ammo_type", (object)(shared.m_ammoType ?? ""));
					val4.Add("skill_type", (object)((object)(SkillType)(ref shared.m_skillType)).ToString());
					val4.Add("damages", (object)ExtractDamageData(shared.m_damages));
					val4.Add("damages_per_level", (object)ExtractDamageDataWithPrefix(shared.m_damagesPerLevel));
					val4.Add("status_effects", (object)ExtractStatusEffects(shared));
					val4.Add("set_name", (object)(shared.m_setName ?? ""));
					val4.Add("set_status_effect", (object)(((Object)(object)shared.m_setStatusEffect != (Object)null) ? ((Object)shared.m_setStatusEffect).name : ""));
					val4.Add("food_eitr", (object)shared.m_foodEitr);
					if (shared.m_icons != null && shared.m_icons.Length != 0 && (Object)(object)shared.m_icons[0] != (Object)null)
					{
						val4.Add("icon", (object)(name + ".png"));
						if (ExportItemIcon(shared, name, text))
						{
							num++;
						}
					}
					val3.Add("shared_data", (object)val4);
					((List<object>)(object)val).Add((object)val3);
				}
			}
			Logger.LogInfo((object)$"Exported {num} icons to {text}/");
			return val;
		}

		private static JsonArray ExtractAllRecipes()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Expected O, but got Unknown
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Expected O, but got Unknown
			JsonArray val = new JsonArray();
			HashSet<string> valharvestPrefabNames = GetValharvestPrefabNames();
			if (ObjectDB.instance.m_recipes == null)
			{
				return val;
			}
			foreach (Recipe recipe in ObjectDB.instance.m_recipes)
			{
				if ((Object)(object)recipe == (Object)null || (Object)(object)recipe.m_item == (Object)null)
				{
					continue;
				}
				string name = ((Object)((Component)recipe.m_item).gameObject).name;
				if (valharvestPrefabNames.Contains(name))
				{
					continue;
				}
				JsonObject val2 = new JsonObject();
				SharedData shared = recipe.m_item.m_itemData.m_shared;
				val2.Add("raw_name", (object)Localization.instance.Localize(shared.m_name ?? ""));
				val2.Add("var_name", (object)(shared.m_name ?? ""));
				val2.Add("true_name", (object)(((Object)recipe).name ?? ""));
				val2.Add("enabled", (object)recipe.m_enabled);
				val2.Add("min_station_level", (object)recipe.m_minStationLevel);
				val2.Add("amount", (object)recipe.m_amount);
				if ((Object)(object)recipe.m_craftingStation != (Object)null)
				{
					val2.Add("raw_crafting_station_name", (object)Localization.instance.Localize(recipe.m_craftingStation.m_name ?? ""));
					val2.Add("true_crafting_station_name", (object)(((Object)recipe.m_craftingStation).name ?? ""));
				}
				else
				{
					val2.Add("raw_crafting_station_name", (object)"");
					val2.Add("true_crafting_station_name", (object)"");
				}
				JsonArray val3 = new JsonArray();
				if (recipe.m_resources != null)
				{
					Requirement[] resources = recipe.m_resources;
					foreach (Requirement val4 in resources)
					{
						if (val4 != null && !((Object)(object)val4.m_resItem == (Object)null))
						{
							JsonObject val5 = new JsonObject();
							SharedData shared2 = val4.m_resItem.m_itemData.m_shared;
							val5.Add("amount", (object)val4.m_amount);
							val5.Add("amount_per_level", (object)val4.m_amountPerLevel);
							val5.Add("raw_name", (object)Localization.instance.Localize(shared2.m_name ?? ""));
							val5.Add("var_name", (object)(shared2.m_name ?? ""));
							val5.Add("true_name", (object)(((Object)((Component)val4.m_resItem).gameObject).name ?? ""));
							val5.Add("recover", (object)val4.m_recover);
							((List<object>)(object)val3).Add((object)val5);
						}
					}
				}
				val2.Add("requirements", (object)val3);
				((List<object>)(object)val).Add((object)val2);
			}
			return val;
		}

		private static JsonObject ExtractDamageData(DamageTypes damages)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			JsonObject val = new JsonObject();
			val.Add("damage", (object)damages.m_damage);
			val.Add("blunt", (object)damages.m_blunt);
			val.Add("slash", (object)damages.m_slash);
			val.Add("pierce", (object)damages.m_pierce);
			val.Add("chop", (object)damages.m_chop);
			val.Add("pickaxe", (object)damages.m_pickaxe);
			val.Add("fire", (object)damages.m_fire);
			val.Add("frost", (object)damages.m_frost);
			val.Add("lightning", (object)damages.m_lightning);
			val.Add("poison", (object)damages.m_poison);
			val.Add("spirit", (object)damages.m_spirit);
			return val;
		}

		private static JsonObject ExtractDamageDataWithPrefix(DamageTypes damages)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			JsonObject val = new JsonObject();
			val.Add("m_damage", (object)damages.m_damage);
			val.Add("m_blunt", (object)damages.m_blunt);
			val.Add("m_slash", (object)damages.m_slash);
			val.Add("m_pierce", (object)damages.m_pierce);
			val.Add("m_chop", (object)damages.m_chop);
			val.Add("m_pickaxe", (object)damages.m_pickaxe);
			val.Add("m_fire", (object)damages.m_fire);
			val.Add("m_frost", (object)damages.m_frost);
			val.Add("m_lightning", (object)damages.m_lightning);
			val.Add("m_poison", (object)damages.m_poison);
			val.Add("m_spirit", (object)damages.m_spirit);
			return val;
		}

		private static JsonArray ExtractStatusEffects(SharedData shared)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			JsonArray val = new JsonArray();
			if ((Object)(object)shared.m_attackStatusEffect != (Object)null)
			{
				((List<object>)(object)val).Add((object)((Object)shared.m_attackStatusEffect).name);
			}
			if ((Object)(object)shared.m_consumeStatusEffect != (Object)null)
			{
				((List<object>)(object)val).Add((object)((Object)shared.m_consumeStatusEffect).name);
			}
			if ((Object)(object)shared.m_equipStatusEffect != (Object)null)
			{
				((List<object>)(object)val).Add((object)((Object)shared.m_equipStatusEffect).name);
			}
			if ((Object)(object)shared.m_setStatusEffect != (Object)null)
			{
				((List<object>)(object)val).Add((object)((Object)shared.m_setStatusEffect).name);
			}
			return val;
		}

		private static bool ExportItemIcon(SharedData shared, string prefabName, string outputDir)
		{
			if (shared.m_icons == null || shared.m_icons.Length == 0)
			{
				return false;
			}
			Sprite val = shared.m_icons[0];
			if ((Object)(object)val == (Object)null || (Object)(object)val.texture == (Object)null)
			{
				return false;
			}
			try
			{
				Texture2D val2 = MakeTextureReadable(val);
				if ((Object)(object)val2 == (Object)null)
				{
					return false;
				}
				byte[] bytes = ImageConversion.EncodeToPNG(val2);
				File.WriteAllBytes(Path.Combine(outputDir, prefabName + ".png"), bytes);
				Object.Destroy((Object)(object)val2);
				return true;
			}
			catch (Exception ex)
			{
				Logger.LogWarning((object)("Failed to export icon for " + prefabName + ": " + ex.Message));
				return false;
			}
		}

		private static Texture2D MakeTextureReadable(Sprite sprite)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			Texture2D texture = sprite.texture;
			Rect textureRect = sprite.textureRect;
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)texture).width, ((Texture)texture).height, 0, (RenderTextureFormat)0);
			Graphics.Blit((Texture)(object)texture, temporary);
			RenderTexture active = RenderTexture.active;
			RenderTexture.active = temporary;
			int num = Mathf.FloorToInt(((Rect)(ref textureRect)).x);
			int num2 = Mathf.FloorToInt(((Rect)(ref textureRect)).y);
			int num3 = Mathf.FloorToInt(((Rect)(ref textureRect)).width);
			int num4 = Mathf.FloorToInt(((Rect)(ref textureRect)).height);
			Texture2D val = new Texture2D(num3, num4, (TextureFormat)5, false);
			val.ReadPixels(new Rect((float)num, (float)num2, (float)num3, (float)num4), 0, 0);
			val.Apply();
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			return val;
		}
	}
	public class ExportItemsCommand : ConsoleCommand
	{
		public override string Name => "exportitems";

		public override string Help => "Exports all game items to itemdrops.json and recipes to recipes.json in the Valheim directory";

		public override void Run(string[] args)
		{
			Logger.LogInfo((object)"Running exportitems command...");
			ConsumableItemExtractor.GenerateConsumableItemList();
		}
	}
	public class CultivatedGround : Heightmap
	{
		private void Awake()
		{
		}

		private void Update()
		{
		}

		private void OnEnable()
		{
			Regenerate();
		}

		private void Regenerate()
		{
			Generate();
		}

		private void Generate()
		{
			Initialize();
		}

		public void Initialize()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			int num = base.m_width + 1;
			int num2 = num * num;
			if (base.m_heights.Count != num2)
			{
				base.m_heights.Clear();
				for (int i = 0; i < num2; i++)
				{
					base.m_heights.Add(0f);
				}
				base.m_paintMask = new Texture2D(base.m_width, base.m_width)
				{
					wrapMode = (TextureWrapMode)1
				};
			}
		}
	}
	[HarmonyPatch]
	public static class DeepFireCheckPatch
	{
		[HarmonyPatch(typeof(CraftingStation), "CheckFire")]
		private static class CheckFirePatch
		{
			private static bool Prefix(CraftingStation __instance, ref bool ___m_haveFire)
			{
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				if (!IsTarget((Object)(object)__instance))
				{
					return true;
				}
				GameObject haveFireObject = __instance.m_haveFireObject;
				Collider val = (((Object)(object)haveFireObject != (Object)null) ? haveFireObject.GetComponent<Collider>() : null);
				bool flag;
				if ((Object)(object)val != (Object)null)
				{
					flag = HasBurningInVolume(val);
				}
				else
				{
					Vector3 val2 = (((Object)(object)haveFireObject != (Object)null) ? haveFireObject.transform.position : ((Component)__instance).transform.position);
					float num = ((Valharvest.Configurations.Valharvest.CookingPotFireCheckRadius != null) ? Valharvest.Configurations.Valharvest.CookingPotFireCheckRadius.Value : 0.5f);
					flag = (Object)(object)EffectArea.IsPointInsideArea(val2, (Type)8, num) != (Object)null;
				}
				___m_haveFire = flag;
				if ((Object)(object)haveFireObject != (Object)null)
				{
					haveFireObject.SetActive(flag);
				}
				return false;
			}
		}

		private static int _characterTriggerMask;

		private static readonly Collider[] _hits = (Collider[])(object)new Collider[32];

		private static int CharacterTriggerMask
		{
			get
			{
				if (_characterTriggerMask == 0)
				{
					_characterTriggerMask = LayerMask.GetMask(new string[1] { "character_trigger" });
				}
				return _characterTriggerMask;
			}
		}

		private static bool IsTarget(Object instance)
		{
			if (instance != (Object)null && instance.name != null)
			{
				return instance.name.StartsWith("piece_cooking_pot");
			}
			return false;
		}

		private static bool HasBurningInVolume(Collider volume)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)volume).transform;
			Vector3 lossyScale = transform.lossyScale;
			int num = 0;
			BoxCollider val = (BoxCollider)(object)((volume is BoxCollider) ? volume : null);
			if (val != null)
			{
				Vector3 val2 = transform.TransformPoint(val.center);
				Vector3 val3 = default(Vector3);
				((Vector3)(ref val3))..ctor(Mathf.Abs(val.size.x * lossyScale.x) * 0.5f, Mathf.Abs(val.size.y * lossyScale.y) * 0.5f, Mathf.Abs(val.size.z * lossyScale.z) * 0.5f);
				num = Physics.OverlapBoxNonAlloc(val2, val3, _hits, transform.rotation, CharacterTriggerMask, (QueryTriggerInteraction)2);
			}
			else
			{
				SphereCollider val4 = (SphereCollider)(object)((volume is SphereCollider) ? volume : null);
				if (val4 != null)
				{
					Vector3 val5 = transform.TransformPoint(val4.center);
					float num2 = val4.radius * Mathf.Max(new float[3]
					{
						Mathf.Abs(lossyScale.x),
						Mathf.Abs(lossyScale.y),
						Mathf.Abs(lossyScale.z)
					});
					num = Physics.OverlapSphereNonAlloc(val5, num2, _hits, CharacterTriggerMask, (QueryTriggerInteraction)2);
				}
				else
				{
					CapsuleCollider val6 = (CapsuleCollider)(object)((volume is CapsuleCollider) ? volume : null);
					if (val6 != null)
					{
						Bounds bounds = ((Collider)val6).bounds;
						num = Physics.OverlapBoxNonAlloc(((Bounds)(ref bounds)).center, ((Bounds)(ref bounds)).extents, _hits, Quaternion.identity, CharacterTriggerMask, (QueryTriggerInteraction)2);
					}
					else
					{
						Bounds bounds2 = volume.bounds;
						num = Physics.OverlapBoxNonAlloc(((Bounds)(ref bounds2)).center, ((Bounds)(ref bounds2)).extents, _hits, Quaternion.identity, CharacterTriggerMask, (QueryTriggerInteraction)2);
					}
				}
			}
			for (int i = 0; i < num; i++)
			{
				EffectArea component = ((Component)_hits[i]).GetComponent<EffectArea>();
				if ((Object)(object)component != (Object)null && (component.m_type & 8) != 0)
				{
					return true;
				}
			}
			return false;
		}
	}
	[HarmonyPatch]
	public class EggAndFeatherDrop
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(TreeBase), "SpawnLog")]
		public static void TreeBaseSpawnLog_Patch(TreeBase __instance)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			string name = ((Object)__instance.m_logPrefab).name;
			if (((IList)new string[6] { "PineTree_log", "PineTree_logOLD", "FirTree_log", "beech_log", "Birch_log", "Oak_log" }).Contains((object?)name) && Random.value < 0.15f)
			{
				GameObject prefab = ZNetScene.instance.GetPrefab("Feathers");
				GameObject prefab2 = ZNetScene.instance.GetPrefab(BoneAppetitCompat.GetEggItem());
				int num = Random.Range(1, 8);
				int num2 = Random.Range(1, 3);
				for (int i = 0; i < num; i++)
				{
					Object.Instantiate<GameObject>(prefab, ((Component)__instance).transform.position, Quaternion.identity);
				}
				for (int j = 0; j < num2; j++)
				{
					Object.Instantiate<GameObject>(prefab2, ((Component)__instance).transform.position, Quaternion.identity);
				}
			}
		}
	}
	public class FixPlantHealth : SlowUpdate
	{
		private const float GrowRadiusOverride = 0.4f;

		private const Biome BiomeOverride = 895;

		public override void Awake()
		{
			((SlowUpdate)this).Awake();
		}

		public override void SUpdate(float currentTime, Vector2i referenceZone)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			Plant component = ((Component)this).GetComponent<Plant>();
			Vector3 position = ((Component)this).transform.position;
			if (IsPlantValid(component, currentTime) && RaisedBed.CheckIfItemBellowIsCultivatedGround(position))
			{
				ApplyPlantOverrides(component);
			}
		}

		private bool IsPlantValid(Plant plant, float currentTime)
		{
			if (plant.m_nview.IsValid())
			{
				return currentTime <= plant.m_updateTime;
			}
			return false;
		}

		private void ApplyPlantOverrides(Plant plant)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			plant.m_tolerateHeat = true;
			plant.m_tolerateCold = true;
			plant.m_biome = (Biome)895;
			plant.m_growRadius = 0.4f;
		}
	}
	public class FoodCrate : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <GroundOnceDeferred>d__14 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public FoodCrate <>4__this;

			private ZDO <zdo>5__2;

			private int <mask>5__3;

			private int <pass>5__4;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <GroundOnceDeferred>d__14(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<zdo>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0119: Unknown result type (might be due to invalid IL or missing references)
				//IL_011e: 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_0120: Unknown result type (might be due to invalid IL or missing references)
				//IL_012a: Unknown result type (might be due to invalid IL or missing references)
				//IL_012f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0134: Unknown result type (might be due to invalid IL or missing references)
				//IL_017f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0184: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				FoodCrate foodCrate = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 3;
					return true;
				case 3:
					<>1__state = -1;
					if ((Object)(object)foodCrate._nview == (Object)null || !foodCrate._nview.IsValid() || !foodCrate._nview.IsOwner())
					{
						return false;
					}
					<zdo>5__2 = foodCrate._nview.GetZDO();
					if (<zdo>5__2.GetBool("vh_grounded", false))
					{
						return false;
					}
					<mask>5__3 = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "terrain", "vehicle" });
					<pass>5__4 = 0;
					break;
				case 4:
					<>1__state = -1;
					<pass>5__4++;
					break;
				}
				if (<pass>5__4 < 24)
				{
					Vector3 position = ((Component)foodCrate).transform.position;
					RaycastHit[] array = Physics.RaycastAll(position + Vector3.up * 0.1f, Vector3.down, 50f, <mask>5__3);
					Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
					float num2 = float.NaN;
					RaycastHit[] array2 = array;
					for (int i = 0; i < array2.Length; i++)
					{
						RaycastHit val = array2[i];
						if (!((Object)(object)((Component)((RaycastHit)(ref val)).collider).transform.root == (Object)(object)((Component)foodCrate).transform))
						{
							num2 = ((RaycastHit)(ref val)).point.y;
							break;
						}
					}
					if (!float.IsNaN(num2) && position.y - num2 > 0.05f)
					{
						position.y = num2;
						((Component)foodCrate).transform.position = position;
						<zdo>5__2.SetPosition(position);
					}
					<>2__current = null;
					<>1__state = 4;
					return true;
				}
				<zdo>5__2.Set("vh_grounded", true);
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public const string VH_PILE_ITEM_KEY = "vh_pile_item";

		public const string VH_MIGRATED_KEY = "vh_migrated";

		private const string VH_GROUNDED_KEY = "vh_grounded";

		private const string RPC_REFRESH = "VH_RefreshPile";

		private const string MAT_PREFIX = "Pile";

		private const float GroundSnapEpsilon = 0.05f;

		private const int GroundSettlePasses = 24;

		private static Dictionary<string, Material> _materialCache;

		private Container _container;

		private ZNetView _nview;

		private GameObject[] _piles;

		private void Awake()
		{
			_container = ((Component)this).GetComponent<Container>();
			_nview = ((Component)this).GetComponent<ZNetView>();
			Transform val = ((Component)this).transform.Find("model");
			if ((Object)(object)val != (Object)null)
			{
				GameObject[] array = new GameObject[4];
				Transform obj = val.Find("pile_1_25");
				array[0] = ((obj != null) ? ((Component)obj).gameObject : null);
				Transform obj2 = val.Find("pile_2_50");
				array[1] = ((obj2 != null) ? ((Component)obj2).gameObject : null);
				Transform obj3 = val.Find("pile_3_75");
				array[2] = ((obj3 != null) ? ((Component)obj3).gameObject : null);
				Transform obj4 = val.Find("pile_4_100");
				array[3] = ((obj4 != null) ? ((Component)obj4).gameObject : null);
				_piles = (GameObject[])(object)array;
			}
			ZNetView nview = _nview;
			if (nview != null)
			{
				nview.Register("VH_RefreshPile", (Action<long>)delegate
				{
					RefreshVisual();
				});
			}
		}

		private void Start()
		{
			if (_container?.m_inventory != null)
			{
				Inventory inventory = _container.m_inventory;
				inventory.m_onChanged = (Action)Delegate.Combine(inventory.m_onChanged, new Action(OnInventoryChanged));
			}
			((MonoBehaviour)this).StartCoroutine(GroundOnceDeferred());
			RefreshVisual();
		}

		private void OnDestroy()
		{
			if (_container?.m_inventory != null)
			{
				Inventory inventory = _container.m_inventory;
				inventory.m_onChanged = (Action)Delegate.Remove(inventory.m_onChanged, new Action(OnInventoryChanged));
			}
		}

		[IteratorStateMachine(typeof(<GroundOnceDeferred>d__14))]
		private IEnumerator GroundOnceDeferred()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GroundOnceDeferred>d__14(0)
			{
				<>4__this = this
			};
		}

		private void OnInventoryChanged()
		{
			if ((Object)(object)_nview == (Object)null || !_nview.IsValid() || !_nview.IsOwner())
			{
				return;
			}
			List<ItemData> allItems = _container.m_inventory.GetAllItems();
			ZDO zDO = _nview.GetZDO();
			string @string = zDO.GetString("vh_pile_item", "");
			if (allItems.Count == 0)
			{
				if (!string.IsNullOrEmpty(@string))
				{
					zDO.Set("vh_pile_item", "");
				}
			}
			else if (string.IsNullOrEmpty(@string))
			{
				string text = ResolvePrefabName(allItems[0]);
				if (!string.IsNullOrEmpty(text))
				{
					zDO.Set("vh_pile_item", text);
				}
			}
			_nview.InvokeRPC(ZNetView.Everybody, "VH_RefreshPile", Array.Empty<object>());
		}

		private void RefreshVisual()
		{
			if (_piles == null || _container?.m_inventory == null)
			{
				return;
			}
			for (int i = 0; i < _piles.Length; i++)
			{
				if ((Object)(object)_piles[i] != (Object)null)
				{
					_piles[i].SetActive(false);
				}
			}
			int count = _container.m_inventory.GetAllItems().Count;
			if (count == 0)
			{
				return;
			}
			int num = _container.m_inventory.GetWidth() * _container.m_inventory.GetHeight();
			float num2 = ((num > 0) ? ((float)count / (float)num) : 0f);
			int num3 = ((!(num2 <= 0.25f)) ? ((num2 <= 0.5f) ? 1 : ((num2 <= 0.75f) ? 2 : 3)) : 0);
			GameObject val = _piles[num3];
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			val.SetActive(true);
			Material pileMaterial = GetPileMaterial(((Object)(object)_nview != (Object)null && _nview.IsValid()) ? _nview.GetZDO().GetString("vh_pile_item", "") : "");
			if (!((Object)(object)pileMaterial == (Object)null))
			{
				Renderer component = val.GetComponent<Renderer>();
				if ((Object)(object)component != (Object)null)
				{
					component.sharedMaterial = pileMaterial;
				}
			}
		}

		private static string ResolvePrefabName(ItemData item)
		{
			if ((Object)(object)item?.m_dropPrefab != (Object)null)
			{
				return ((Object)item.m_dropPrefab).name;
			}
			string text = item?.m_shared?.m_name;
			if (!string.IsNullOrEmpty(text) && text.StartsWith("$") && text.EndsWith("_name"))
			{
				return text.Substring(1, text.Length - "$_name".Length + 1);
			}
			return null;
		}

		private static Material GetPileMaterial(string itemPrefabName)
		{
			if (string.IsNullOrEmpty(itemPrefabName))
			{
				return null;
			}
			if (_materialCache == null)
			{
				BuildCache();
			}
			string key = "Pile" + char.ToUpper(itemPrefabName[0]) + itemPrefabName.Substring(1);
			_materialCache.TryGetValue(key, out var value);
			return value;
		}

		private static void BuildCache()
		{
			_materialCache = new Dictionary<string, Material>(StringComparer.OrdinalIgnoreCase);
			if ((Object)(object)Main.modAssets == (Object)null)
			{
				Logger.LogWarning((object)"[FoodCrate] modAssets is null; can't build pile material cache");
				return;
			}
			Material[] array = Main.modAssets.LoadAllAssets<Material>();
			foreach (Material val in array)
			{
				if (!((Object)(object)val == (Object)null) && ((Object)val).name.StartsWith("Pile"))
				{
					string key = ((Object)val).name.Split(new char[1] { '_' })[0];
					_materialCache[key] = val;
				}
			}
			Logger.LogInfo((object)$"[FoodCrate] Cached {_materialCache.Count} pile materials");
		}
	}
	[HarmonyPatch]
	public static class HandlePrefabComponent
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(MonsterAI), "Awake")]
		public static void MonsterAIAwakePatch(MonsterAI __instance)
		{
			if (((Object)((Component)__instance).gameObject).name.Contains("Lox"))
			{
				((Component)__instance).gameObject.AddComponent<MilkLox>();
			}
		}

		public static void ZNetViewAwakePatch()
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			GameObject prefab = PrefabManager.Instance.GetPrefab("water_well");
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				return;
			}
			Transform val = prefab.gameObject.transform.Find("water");
			Transform val2 = prefab.gameObject.transform.Find("spawnpoint");
			if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null)
			{
				CustomBeehive customBeehive = prefab.gameObject.AddComponent<CustomBeehive>();
				customBeehive.m_hideWhenPicked = ((Component)val).gameObject;
				customBeehive.m_spawnPoint = val2;
				customBeehive.m_honeyItem = PrefabManager.Instance.GetPrefab("water_bucket").GetComponent<ItemDrop>();
				EffectList val3 = new EffectList();
				if (val3.m_effectPrefabs.Length == 0)
				{
					val3.m_effectPrefabs = (EffectData[])(object)new EffectData[1];
				}
				val3.m_effectPrefabs[0] = new EffectData
				{
					m_prefab = PrefabManager.Instance.GetPrefab("sfx_ship_waterimpact"),
					m_enabled = true
				};
				customBeehive.m_spawnEffect = val3;
			}
		}

		public static void PrepTableSmokePatch()
		{
			if (Valharvest.Configurations.Valharvest.PrepTableSmokeEnabled.Value)
			{
				return;
			}
			GameObject prefab = PrefabManager.Instance.GetPrefab("piece_prep_table");
			if (!((Object)(object)prefab == (Object)null))
			{
				Transform val = prefab.transform.Find("connectionEffectPoint/prep/SmokeSpawner");
				if ((Object)(object)val != (Object)null)
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
		}

		public static void FoodCrateEffectsPatch()
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab("vh_piece_food_crate");
			if (!((Object)(object)prefab == (Object)null))
			{
				GameObject prefab2 = PrefabManager.Instance.GetPrefab("vfx_Place_wood_pole");
				GameObject prefab3 = PrefabManager.Instance.GetPrefab("sfx_build_hammer_wood");
				GameObject prefab4 = PrefabManager.Instance.GetPrefab("vfx_SawDust");
				GameObject prefab5 = PrefabManager.Instance.GetPrefab("sfx_wood_hit");
				GameObject prefab6 = PrefabManager.Instance.GetPrefab("vfx_SawDust");
				GameObject prefab7 = PrefabManager.Instance.GetPrefab("sfx_wood_destroyed");
				Piece component = prefab.GetComponent<Piece>();
				if ((Object)(object)component != (Object)null)
				{
					component.m_placeEffect = BuildEffectList(prefab2, prefab3);
				}
				WearNTear component2 = prefab.GetComponent<WearNTear>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.m_hitEffect = BuildEffectList(prefab4, prefab5);
					component2.m_destroyedEffect = BuildEffectList(prefab6, prefab7);
				}
			}
		}

		private static EffectList BuildEffectList(params GameObject[] effects)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			List<EffectData> list = new List<EffectData>();
			foreach (GameObject val in effects)
			{
				if (!((Object)(object)val == (Object)null))
				{
					list.Add(new EffectData
					{
						m_prefab = val,
						m_enabled = true
					});
				}
			}
			return new EffectList
			{
				m_effectPrefabs = list.ToArray()
			};
		}
	}
	public class InteractFertilizer : MonoBehaviour, Interactable
	{
		private ZNetView _nview;

		private void Awake()
		{
			_nview = ((Component)this).gameObject.GetComponent<ZNetView>();
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			return false;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory();
			Plant component = ((Component)this).gameObject.GetComponent<Plant>();
			if (!SetPlantTime(component, item))
			{
				return false;
			}
			inventory.RemoveOneItem(item);
			GrowPlant(component);
			return true;
		}

		private bool SetPlantTime(Plant plant, ItemData item)
		{
			bool num = ((Object)item.m_dropPrefab).name == "bonemeal";
			bool flag = ((Object)item.m_dropPrefab).name == "water_bucket";
			double num2 = plant.m_growTime;
			int num3 = (num ? 5 : 2);
			if (!num && !flag)
			{
				return false;
			}
			long @long = _nview.GetZDO().GetLong("plantTime", ZNet.instance.GetTime().Ticks);
			long num4 = (long)(num2 * 10000000.0 / (double)num3);
			long num5 = @long - num4;
			if (num5 < 0)
			{
				num5 = 0L;
			}
			_nview.GetZDO().Set("plantTime", num5);
			SendPlantEffect(plant);
			return true;
		}

		private static void SendPlantEffect(Plant plant)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			float num = Random.Range((float)((double)plant.m_minScale * 0.5), (float)((double)plant.m_maxScale * 0.5));
			Quaternion val = Quaternion.Euler(0f, Random.Range(0f, 360f), 0f);
			Main.boneMealVfx.Create(((Component)plant).transform.position, val, (Transform)null, num, -1);
		}

		public void GrowPlant(Plant plant)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Invalid comparison between Unknown and I4
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Invalid comparison between Unknown and I4
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Invalid comparison between Unknown and I4
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Invalid comparison between Unknown and I4
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Invalid comparison between Unknown and I4
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Invalid comparison between Unknown and I4
			if (plant.m_nview.IsValid())
			{
				plant.m_updateTime = Time.time;
				double num = plant.TimeSincePlanted();
				float growTime = plant.GetGrowTime();
				if (Object.op_Implicit((Object)(object)plant.m_healthyGrown))
				{
					bool flag = num > (double)growTime * 0.5;
					plant.m_healthy.SetActive(!flag && (int)plant.m_status == 0);
					plant.m_unhealthy.SetActive(!flag && (int)plant.m_status > 0);
					plant.m_healthyGrown.SetActive(flag && (int)plant.m_status == 0);
					plant.m_unhealthyGrown.SetActive(flag && (int)plant.m_status > 0);
				}
				else
				{
					plant.m_healthy.SetActive((int)plant.m_status == 0);
					plant.m_unhealthy.SetActive((int)plant.m_status > 0);
				}
				if (plant.m_nview.IsOwner() && !(num <= (double)growTime))
				{
					plant.Grow();
				}
			}
		}
	}
	public class LegacyBoxMigrator : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <MigrateDeferred>d__4 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public LegacyBoxMigrator <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <MigrateDeferred>d__4(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				LegacyBoxMigrator legacyBoxMigrator = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					if ((Object)(object)legacyBoxMigrator._nview == (Object)null || !legacyBoxMigrator._nview.IsValid() || !legacyBoxMigrator._nview.IsOwner())
					{
						return false;
					}
					string prefabName = Utils.GetPrefabName(((Component)legacyBoxMigrator).gameObject);
					if (!BoxToItem.TryGetValue(prefabName, out var value))
					{
						return false;
					}
					if ((Object)(object)ZNetScene.instance == (Object)null || (Object)(object)ObjectDB.instance == (Object)null)
					{
						return false;
					}
					GameObject prefab = ZNetScene.instance.GetPrefab("vh_piece_food_crate");
					if ((Object)(object)prefab == (Object)null)
					{
						Logger.LogWarning((object)("[LegacyBoxMigrator] vh_piece_food_crate not found; skipping " + prefabName));
						return false;
					}
					Quaternion val = Quaternion.Euler(0f, ((Component)legacyBoxMigrator).transform.eulerAngles.y, 0f);
					GameObject val2 = Object.Instantiate<GameObject>(prefab, ((Component)legacyBoxMigrator).transform.position, val);
					Container component = val2.GetComponent<Container>();
					GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(value);
					if ((Object)(object)component != (Object)null && (Object)(object)itemPrefab != (Object)null)
					{
						ItemDrop component2 = itemPrefab.GetComponent<ItemDrop>();
						int num2 = ((!((Object)(object)component2 != (Object)null)) ? 1 : component2.m_itemData.m_quality);
						component.GetInventory().AddItem(value, 50, num2, 0, 0L, "", false);
						component.Save();
						ZNetView component3 = val2.GetComponent<ZNetView>();
						ZDO val3 = ((component3 != null) ? component3.GetZDO() : null);
						if (val3 != null)
						{
							val3.Set("vh_pile_item", value);
							val3.Set("vh_migrated", true);
						}
						Logger.LogInfo((object)$"[LegacyBoxMigrator] {prefabName} -> vh_piece_food_crate ({value} x{50})");
					}
					else
					{
						Logger.LogWarning((object)("[LegacyBoxMigrator] " + prefabName + ": missing Container or item prefab '" + value + "'"));
					}
					Piece component4 = val2.GetComponent<Piece>();
					if ((Object)(object)component4 != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null)
					{
						component4.SetCreator(Player.m_localPlayer.GetPlayerID());
					}
					ZNetScene.instance.Destroy(((Component)legacyBoxMigrator).gameObject);
					return false;
				}
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in Move