Decompiled source of RootsAndRemedies v1.0.0

RootAndRemedies.dll

Decompiled 15 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using ImmersiveTrader;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using RootsAndRemedies.Foods.Quests;
using RootsAndRemedies.Foods.StoneBeasts;
using RootsAndRemedies.Foods.Wyrm;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RootAndRemedies")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.12.1.0")]
[assembly: AssemblyInformationalVersion("0.12.1")]
[assembly: AssemblyProduct("RootAndRemedies")]
[assembly: AssemblyTitle("RootAndRemedies")]
[assembly: AssemblyVersion("0.12.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RootsAndRemedies.Foods
{
	internal static class AdminGate
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static CoroutineHandler <0>__OnServer;

			public static CoroutineHandler <1>__OnClient;
		}

		private static CustomRPC rpc;

		private static bool? answer;

		private static float answered = -1000f;

		private static float asked = -1000f;

		private static ZNet owner;

		internal static void Init()
		{
			//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_0025: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			NetworkManager instance = NetworkManager.Instance;
			object obj = <>O.<0>__OnServer;
			if (obj == null)
			{
				CoroutineHandler val = OnServer;
				<>O.<0>__OnServer = val;
				obj = (object)val;
			}
			object obj2 = <>O.<1>__OnClient;
			if (obj2 == null)
			{
				CoroutineHandler val2 = OnClient;
				<>O.<1>__OnClient = val2;
				obj2 = (object)val2;
			}
			rpc = instance.AddRPC("RnR_AdminCheck", (CoroutineHandler)obj, (CoroutineHandler)obj2);
		}

		private static string Digits(string text)
		{
			text = (text ?? "").Trim();
			int length = text.Length;
			int num = length;
			while (num > 0 && char.IsDigit(text[num - 1]))
			{
				num--;
			}
			return text.Substring(num, length - num);
		}

		private static IEnumerable<string> Files()
		{
			string text = null;
			try
			{
				text = Utils.GetSaveDataPath((FileSource)2);
			}
			catch (Exception)
			{
			}
			if (!string.IsNullOrEmpty(text))
			{
				yield return Path.Combine(text, "admin.txt");
			}
			yield return Path.Combine(Paths.ConfigPath, "admin.txt");
		}

		private static HashSet<string> Ids()
		{
			HashSet<string> hashSet = new HashSet<string>();
			foreach (string item in Files())
			{
				try
				{
					if (!File.Exists(item))
					{
						continue;
					}
					string[] array = File.ReadAllLines(item);
					for (int i = 0; i < array.Length; i++)
					{
						string text = array[i].Trim();
						if (text.Length != 0 && !text.StartsWith("#"))
						{
							string text2 = Digits(text);
							if (text2.Length > 0)
							{
								hashSet.Add(text2);
							}
						}
					}
				}
				catch (Exception ex)
				{
					Plugin.Instance.LoggerGarden("admin.txt could not be read: " + ex.Message);
				}
			}
			return hashSet;
		}

		private static IEnumerator OnServer(long sender, ZPackage pkg)
		{
			ZNet instance = ZNet.instance;
			ZNetPeer val = ((instance != null) ? instance.GetPeer(sender) : null);
			bool flag = val != null && val.m_socket != null && Ids().Contains(Digits(val.m_socket.GetHostName()));
			ZPackage val2 = new ZPackage();
			val2.Write(flag);
			rpc.SendPackage(sender, val2);
			yield break;
		}

		private static IEnumerator OnClient(long sender, ZPackage pkg)
		{
			answer = pkg.ReadBool();
			answered = Time.time;
			yield break;
		}

		internal static bool Allowed(Terminal terminal)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			if ((Object)(object)ZNet.instance == (Object)null)
			{
				terminal.AddString("Enter a world first.");
				return false;
			}
			if ((Object)(object)owner != (Object)(object)ZNet.instance)
			{
				owner = ZNet.instance;
				answer = null;
			}
			if (ZNet.instance.IsServer())
			{
				return true;
			}
			if (answer == true && Time.time - answered < 60f)
			{
				return true;
			}
			if (Time.time - asked > 3f && ZNet.instance.GetServerPeer() != null)
			{
				asked = Time.time;
				rpc.SendPackage(ZNet.instance.GetServerPeer().m_uid, new ZPackage());
			}
			terminal.AddString((answer == false && Time.time - answered < 60f) ? "Only admins listed in admin.txt may use the rnr commands." : "Checking the admin list... try again in a second.");
			return false;
		}
	}
	public sealed class RnrPickTuning : MonoBehaviour
	{
		public string Kind;

		private void Awake()
		{
			Pickable component = ((Component)this).GetComponent<Pickable>();
			Plugin instance = Plugin.Instance;
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)instance))
			{
				switch (Kind)
				{
				case "flower":
					component.m_amount = instance.FlowersPerPick.Value;
					component.m_respawnTimeMinutes = instance.FlowerRegrowMinutes.Value;
					break;
				case "oyster":
					component.m_respawnTimeMinutes = instance.OysterRegrowMinutes.Value;
					break;
				case "rosemary":
					component.m_respawnTimeMinutes = instance.RosemaryRegrowMinutes.Value;
					break;
				}
			}
		}
	}
	internal static class FoodCatalog
	{
		internal static readonly FoodDefinition[] All = new FoodDefinition[49]
		{
			new FoodDefinition("F01", "Smoked Boar Jerky", "BoarJerky", "RNR_F01_SmokedBoarJerky", "attack stamina", "Attack stamina cost −1%"),
			new FoodDefinition("F02", "Smoked Minced Meat Sauce", "MinceMeatSauce", "RNR_F02_SmokedMincedMeatSauce", "attack stamina", "Attack stamina cost −1%"),
			new FoodDefinition("F03", "Dried Queen's Jam", "QueensJam", "RNR_F03_DriedQueensJam", "run stamina", "Run stamina cost −1%"),
			new FoodDefinition("F04", "Dried Carrot Soup", "CarrotSoup", "RNR_F04_DriedCarrotSoup", "jump stamina", "Jump stamina cost −1%"),
			new FoodDefinition("F05", "Smoked Deer Stew", "DeerStew", "RNR_F05_SmokedDeerStew", "block stamina", "Block stamina cost −1%"),
			new FoodDefinition("F06", "Dried Muckshake", "ShocklateSmoothie", "RNR_F06_DriedMuckshake", "jump stamina", "Jump stamina cost −1%"),
			new FoodDefinition("F07", "Smoked Turnip Stew", "TurnipStew", "RNR_F07_SmokedTurnipStew", "block stamina", "Block stamina cost −1%"),
			new FoodDefinition("F08", "Smoked Sausages", "Sausages", "RNR_F08_SmokedSausages", "attack stamina", "Attack stamina cost −1%"),
			new FoodDefinition("F09", "Smoked Black Soup", "BlackSoup", "RNR_F09_SmokedBlackSoup", "block stamina", "Block stamina cost −1%"),
			new FoodDefinition("F13", "Smoked Serpent Stew", "SerpentStew", "RNR_F13_SmokedSerpentStew", "block stamina", "Block stamina cost −1%"),
			new FoodDefinition("F15", "Smoked Wolf Jerky", "WolfJerky", "RNR_F15_SmokedWolfJerky", "run stamina", "Run stamina cost −1%"),
			new FoodDefinition("F16", "Smoked Wolf Skewer", "WolfMeatSkewer", "RNR_F16_SmokedWolfMeatSkewer", "attack stamina", "Attack stamina cost −1%"),
			new FoodDefinition("F17", "Smoked Eyescream", "Eyescream", "RNR_F17_SmokedEyescream", "eitr cost", "Eitr cost when casting −1%"),
			new FoodDefinition("F19", "Smoked Fish Wraps", "FishWraps", "RNR_F19_SmokedFishWraps", "run stamina", "Run stamina cost −1%"),
			new FoodDefinition("F20", "Smoked Lox Meat Pie", "LoxPie", "RNR_F20_SmokedLoxPie", "block stamina", "Block stamina cost −1%"),
			new FoodDefinition("F21", "Smoked Blood Pudding", "BloodPudding", "RNR_F21_SmokedBloodPudding", "jump stamina", "Jump stamina cost −1%"),
			new FoodDefinition("F23", "Smoked Meat Platter", "MeatPlatter", "RNR_F23_SmokedMeatPlatter", "attack stamina", "Attack stamina cost −1%"),
			new FoodDefinition("F24", "Smoked Honey-Glazed Chicken", "HoneyGlazedChicken", "RNR_F24_SmokedHoneyGlazedChicken", "dodge stamina", "Dodge stamina cost −1%"),
			new FoodDefinition("F25", "Smoked Misthare Supreme", "MisthareSupreme", "RNR_F25_SmokedMisthareSupreme", "dodge stamina", "Dodge stamina cost −1%"),
			new FoodDefinition("F26", "Dried Salad", "Salad", "RNR_F26_DriedSalad", "run stamina", "Run stamina cost −1%"),
			new FoodDefinition("F27", "Smoked Mushroom Omelette", "MushroomOmelette", "RNR_F27_SmokedMushroomOmelette", "jump stamina", "Jump stamina cost −1%"),
			new FoodDefinition("F28", "Smoked Fish 'n' Bread", "FishAndBread", "RNR_F28_SmokedFishAndBread", "run stamina", "Run stamina cost −1%"),
			new FoodDefinition("F29", "Smoked Stuffed Mushroom", "MagicallyStuffedShroom", "RNR_F29_SmokedStuffedMushroom", "eitr cost", "Eitr cost when casting −1%"),
			new FoodDefinition("F30", "Dried Yggdrasil Porridge", "YggdrasilPorridge", "RNR_F30_DriedYggdrasilPorridge", "eitr cost", "Eitr cost when casting −1%"),
			new FoodDefinition("F31", "Smoked Seeker Aspic", "SeekerAspic", "RNR_F31_SmokedSeekerAspic", "eitr cost", "Eitr cost when casting −1%"),
			new FoodDefinition("F33", "Smoked Fiery Svinstew", "FierySvinstew", "RNR_F33_SmokedFierySvinstew", "block stamina", "Block stamina cost −1%"),
			new FoodDefinition("F34", "Smoked Mashed Meat", "MashedMeat", "RNR_F34_SmokedMashedMeat", "attack stamina", "Attack stamina cost −1%"),
			new FoodDefinition("F35", "Smoked Piquant Pie", "PiquantPie", "RNR_F35_SmokedPiquantPie", "dodge stamina", "Dodge stamina cost −1%"),
			new FoodDefinition("F36", "Dried Spicy Marmalade", "SpicyMarmalade", "RNR_F36_DriedSpicyMarmalade", "run stamina", "Run stamina cost −1%"),
			new FoodDefinition("F37", "Dried Scorching Medley", "ScorchingMedley", "RNR_F37_DriedScorchingMedley", "jump stamina", "Jump stamina cost −1%"),
			new FoodDefinition("F38", "Smoked Roasted Crust Pie", "RoastedCrustPie", "RNR_F38_SmokedRoastedCrustPie", "jump stamina", "Jump stamina cost −1%"),
			new FoodDefinition("F39", "Dried Sizzling Berry Broth", "SizzlingBerryBroth", "RNR_F39_DriedSizzlingBerryBroth", "eitr cost", "Eitr cost when casting −1%"),
			new FoodDefinition("F40", "Dried Sparkling Shroomshake", "SparklingShroomshake", "RNR_F40_DriedSparklingShroomshake", "eitr cost", "Eitr cost when casting −1%"),
			new FoodDefinition("F41", "Dried Marinated Greens", "MarinatedGreens", "RNR_F41_DriedMarinatedGreens", "dodge stamina", "Dodge stamina cost −1%"),
			new FoodDefinition("F43", "Smoked Seal Blubber", "CookedSealBlubber", "RNR_F43_SmokedCookedSealBlubber", "block stamina", "Block stamina cost −1%"),
			new FoodDefinition("F44", "Smoked Moose Meat", "CookedMooseMeat", "RNR_F44_SmokedCookedMooseMeat", "attack stamina", "Attack stamina cost −1%"),
			new FoodDefinition("F45", "Dried Kale Chips", "KaleChips", "RNR_F45_DriedKaleChips", "jump stamina", "Jump stamina cost −1%"),
			new FoodDefinition("F46", "Dried Baked Poteitr", "BakedPoteitr", "RNR_F46_DriedBakedPoteitr", "stamina regeneration", "Stamina regeneration +1%"),
			new FoodDefinition("F47", "Dried Oat Milk", "OatMilk", "RNR_F47_DriedOatMilk", "stamina regeneration", "Stamina regeneration +1%"),
			new FoodDefinition("F48", "Dried Lingonberry Juice", "Lingondricka", "RNR_F48_DriedLingondricka", "run stamina", "Run stamina cost −1%"),
			new FoodDefinition("F49", "Twice-Smoked Moose Meat", "SmokedMooseMeat", "RNR_F49_SmokedSmokedMooseMeat", "attack stamina", "Attack stamina cost −1%"),
			new FoodDefinition("F50", "Twice-Smoked Fish", "SmokedFish", "RNR_F50_SmokedSmokedFish", "dodge stamina", "Dodge stamina cost −1%"),
			new FoodDefinition("F51", "Smoked Meatballs and Poteitr", "MeatballsMashedPoteitr", "RNR_F51_SmokedMeatballsMashedPoteitr", "block stamina", "Block stamina cost −1%"),
			new FoodDefinition("F52", "Smoked Meat in Bread", "MooseKebab", "RNR_F52_SmokedMooseKebab", "run stamina", "Run stamina cost −1%"),
			new FoodDefinition("F53", "Smoked Fish Soup", "FishSoup", "RNR_F53_SmokedFishSoup", "dodge stamina", "Dodge stamina cost −1%"),
			new FoodDefinition("F54", "Smoked Seal Meat Soup", "SealSoup", "RNR_F54_SmokedSealSoup", "block stamina", "Block stamina cost −1%"),
			new FoodDefinition("F55", "Dried Oatmeal", "OatmealLingonberryJam", "RNR_F55_DriedOatmealLingonberryJam", "stamina regeneration", "Stamina regeneration +1%"),
			new FoodDefinition("F56", "Smoked Pancakes", "Pancakes", "RNR_F56_SmokedPancakes", "eitr cost", "Eitr cost when casting −1%"),
			new FoodDefinition("F57", "Smoked Oven Pancake", "OvenPancake", "RNR_F57_SmokedOvenPancake", "jump stamina", "Jump stamina cost −1%")
		};
	}
	internal sealed class FoodDefinition
	{
		internal readonly string Id;

		internal readonly string Name;

		internal readonly string Source;

		internal readonly string Prefab;

		internal readonly string Effect;

		internal readonly string Attribute;

		internal readonly int Tier;

		internal readonly FoodDefinition Base;

		internal float BaseDuration;

		internal string BaseName;

		internal bool Smoked => Base.Name.StartsWith("Smoked");

		internal FoodDefinition(string id, string name, string source, string prefab, string effect, string attribute)
		{
			Id = id;
			Name = name;
			Source = source;
			Prefab = prefab;
			Effect = effect;
			Attribute = attribute;
			Tier = 1;
			Base = this;
		}

		private FoodDefinition(FoodDefinition b, int tier)
		{
			Id = b.Id;
			Name = b.Name + " [" + FoodRules.TierLabel(tier) + "]";
			Source = b.Source;
			Prefab = b.Prefab + "_T" + tier;
			Effect = b.Effect;
			Attribute = b.Attribute;
			Tier = tier;
			Base = b;
		}

		internal FoodDefinition WithTier(int tier)
		{
			if (tier > 1)
			{
				return new FoodDefinition(Base, tier);
			}
			return Base;
		}
	}
	internal static class FoodRules
	{
		internal static float ExtraSeconds(int tier)
		{
			return (float)(4 + Math.Max(1, Math.Min(3, tier))) * 60f;
		}

		internal static float Percent(int tier)
		{
			if (tier > 1)
			{
				return 0.02f;
			}
			return 0.01f;
		}

		internal static int HealthTick(int tier)
		{
			return Math.Max(1, Math.Min(3, tier));
		}

		internal static string TierLabel(int tier)
		{
			if (tier > 1)
			{
				if (tier != 2)
				{
					return "Best";
				}
				return "Fine";
			}
			return "Poor";
		}

		internal static float Percent(IEnumerable<KeyValuePair<string, int>> sourceTiers)
		{
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			foreach (KeyValuePair<string, int> sourceTier in sourceTiers)
			{
				if (!dictionary.TryGetValue(sourceTier.Key, out var value) || sourceTier.Value > value)
				{
					dictionary[sourceTier.Key] = sourceTier.Value;
				}
			}
			return dictionary.Values.OrderByDescending((int t) => t).Take(3).Sum((int t) => Percent(t));
		}

		internal static float Reduce(float current, float basis, float percent)
		{
			return Math.Max(0f, current - basis * Math.Max(0f, percent));
		}

		internal static float Multiplier(float percent, bool increase = false)
		{
			return 1f + (increase ? 1f : (-1f)) * Math.Max(0f, percent);
		}

		internal static string Attribute(string attribute, int tier)
		{
			return Regex.Replace(attribute, "1%", Math.Round(Percent(tier) * 100f) + "%");
		}

		internal static string Tooltip(string text, string duration, string attribute, int tier = 1)
		{
			string mark = "<color=#FF0000>+" + (4 + Math.Max(1, Math.Min(3, tier))) + "min</color>";
			if (text.Contains(mark))
			{
				return text;
			}
			return Regex.Replace(text, "(\\$item_food_duration:\\s*<color=orange>)[^<]*(</color>)", (Match m) => m.Groups[1].Value + duration + m.Groups[2].Value + " " + mark + "\n<color=#FF0000>" + Attribute(attribute, tier) + "</color>");
		}
	}
	internal sealed class FoodCommandRequest
	{
		internal bool Valid;

		internal string Action;

		internal string Id;

		internal int Amount = 1;

		internal int Tier = 1;

		internal static FoodCommandRequest Parse(string[] args)
		{
			FoodCommandRequest result = new FoodCommandRequest();
			if (args.Length == 0)
			{
				return result;
			}
			result.Action = args[0].ToLowerInvariant();
			if (result.Action == "list" || result.Action == "status")
			{
				result.Valid = args.Length == 1;
				return result;
			}
			if (result.Action != "spawn")
			{
				return result;
			}
			int num = 1;
			if (num < args.Length && args[num].Equals("food", StringComparison.OrdinalIgnoreCase))
			{
				num++;
			}
			if (num < args.Length && args[num].StartsWith("F", StringComparison.OrdinalIgnoreCase))
			{
				result.Id = args[num++].ToUpperInvariant();
				if (!FoodCatalog.All.Any((FoodDefinition d) => d.Id == result.Id))
				{
					return result;
				}
			}
			if (num < args.Length && (!int.TryParse(args[num++], out result.Amount) || result.Amount < 1 || result.Amount > 20))
			{
				return result;
			}
			if (num < args.Length && (!int.TryParse(args[num++], out result.Tier) || result.Tier < 1 || result.Tier > 3))
			{
				return result;
			}
			result.Valid = num == args.Length;
			return result;
		}
	}
	internal static class GardenObjects
	{
		internal static readonly Dictionary<string, GameObject> Items = new Dictionary<string, GameObject>();

		internal static int Pieces;

		internal static readonly string[] Ids = new string[12]
		{
			"MosquitoNet", "RosemaryRoot", "LiveFlytrap", "OysterMushroom", "OysterMycelium", "Clay", "Fly", "RosemaryLeaves", "Kaolin", "FishBile",
			"SunflowerOil", "PressCrank"
		};

		internal static readonly string[] Names = new string[12]
		{
			"Mosquito Net", "Rosemary Root", "Live Flytrap", "Oyster Mushroom", "Oyster Mushroom Mycelium", "Clay", "Fly", "Rosemary Sprigs", "Kaolin", "Fish Bile",
			"Sunflower Oil", "Press Crank"
		};

		internal static readonly string[] Descriptions = new string[12]
		{
			"A knotted rope net, the heart of a mosquito trap. Carry it to a stand of fine wood.", "A tangle of fragrant rosemary roots with soil still clinging to them. Plant three in a planter.", "A carnivorous plant with a hungry grip. It even bites fingers!", "A pale, silvery oyster mushroom with a mild, earthy smell. A gentle remedy for weary bodies.", "A mushroom with fine white threads at the base. Press it into a log to start a new colony.", "Sticky grey clay. Shape it, fire it and it keeps its form for good.", "A fat, buzzing fly caught in a flytrap. Its wings still twitch. Potion makers will pay for these.", "Fresh sprigs of rosemary. Sharp, resinous and good for the lungs.", "Soft, snow-white china clay boiled out of ordinary stone. Pure enough to fire into porcelain.", "A bitter green bile scraped from fish. Brewers stir it into potions that fight poison.",
			"Golden oil pressed from sunflower seeds. Smooth, mild and perfect for mellowing a potion.", "A heavy wooden bar for turning the screw of a press. Without it a screw press is just a pile of timber."
		};

		internal static void Register(Action<string> error)
		{
			for (int i = 0; i < Ids.Length; i++)
			{
				try
				{
					Item(i);
				}
				catch (Exception ex)
				{
					error("Garden item " + Ids[i] + ": " + ex);
				}
			}
			for (int j = 0; j < 8; j++)
			{
				try
				{
					Piece(j);
				}
				catch (Exception ex2)
				{
					error("Garden piece " + j + ": " + ex2);
				}
			}
			try
			{
				Potions.Register(error);
			}
			catch (Exception ex3)
			{
				error("Improved potions: " + ex3);
			}
			Plugin.Instance.LoggerGarden("R&R garden pieces: " + Pieces + "/8; items " + Items.Count + "/" + Ids.Length);
		}

		private static Sprite Icon(string name, Sprite fallback)
		{
			//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: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("RNR.Garden." + name + ".png");
			if (stream == null)
			{
				throw new Exception("Missing icon " + name);
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, array);
			((Texture)val).filterMode = (FilterMode)0;
			return IconSizing.Fit(val, fallback, 0.94f);
		}

		private static void Item(int i)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//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_009a: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Expected O, but got Unknown
			GameObject prefab = PrefabManager.Instance.GetPrefab("Carrot");
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("RNR_" + Ids[i], prefab);
			SharedData val2 = new SharedData();
			FieldInfo[] fields = typeof(SharedData).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				fieldInfo.SetValue(val2, fieldInfo.GetValue(prefab.GetComponent<ItemDrop>().m_itemData.m_shared));
			}
			val.GetComponent<ItemDrop>().m_itemData = new ItemData
			{
				m_shared = val2,
				m_dropPrefab = val
			};
			val2.m_name = Names[i];
			val2.m_description = Descriptions[i];
			val2.m_itemType = (ItemType)1;
			val2.m_food = 0f;
			val2.m_foodStamina = 0f;
			val2.m_foodEitr = 0f;
			val2.m_foodBurnTime = 0f;
			val2.m_buildPieces = null;
			val2.m_appendToolTip = null;
			val2.m_maxStackSize = 50;
			val2.m_weight = 0.1f;
			val2.m_icons = (Sprite[])(object)new Sprite[1] { Icon(Ids[i], val2.m_icons[0]) };
			PlantModels.HideOriginal(val);
			GardenVisual.Item(val, i);
			if (!ItemManager.Instance.AddItem(new CustomItem(val, false)))
			{
				throw new Exception("Registration rejected");
			}
			Items.Add(Ids[i], val);
		}

		private static RequirementConfig Req(string id, int amount)
		{
			//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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			return new RequirementConfig
			{
				Item = id,
				Amount = amount,
				Recover = true
			};
		}

		private static void Free(Piece piece)
		{
			piece.m_groundOnly = false;
			piece.m_groundPiece = false;
			piece.m_notOnWood = false;
			piece.m_notOnFloor = false;
			piece.m_notOnTiltingSurface = false;
			piece.m_cultivatedGroundOnly = false;
			piece.m_spaceRequirement = 0f;
			piece.m_noClipping = false;
		}

		private static void PiecePan()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//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_00c6: 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_00dc: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("RNR_SaltPan", "piece_oven");
			Free(val.GetComponent<Piece>());
			GardenVisual.Piece(val, 6);
			Processing.Configure(val, smoke: false, "Clay Salt Pan", pan: true);
			GameObject val2 = new GameObject("snap");
			val2.transform.SetParent(val.transform, false);
			val2.tag = "snappoint";
			Sprite icon = Icon("SaltPan", PrefabManager.Instance.GetPrefab("Stone").GetComponent<ItemDrop>().m_itemData.m_shared.m_icons[0]);
			RequirementConfig[] requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				Req("Stone", 20),
				Req("RNR_Clay", 1)
			};
			if (!PieceManager.Instance.AddPiece(new CustomPiece(val, true, new PieceConfig
			{
				Name = "Clay Salt Pan",
				Description = "Boils stone down to Kaolin. Put stones in from the top and burn any wood below. Four stones make one Kaolin, which drops in front of the pan.",
				PieceTable = "Hammer",
				Category = "R&R",
				Icon = icon,
				Requirements = requirements
			})))
			{
				throw new Exception("Piece registration rejected");
			}
			Pieces++;
		}

		private static void PiecePress()
		{
			//IL_00c7: 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)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_010b: Expected O, but got Unknown
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("RNR_ScrewPress", "cauldron_ext5_mortarandpestle");
			PlantModels.HideOriginal(val);
			GardenVisual.Piece(val, 7);
			CraftingStation component = PrefabManager.Instance.GetPrefab("piece_preptable").GetComponent<CraftingStation>();
			val.GetComponent<StationExtension>().m_craftingStation = component;
			val.GetComponent<Piece>().m_craftingStation = component;
			Sprite icon = Icon("ScrewPress", PrefabManager.Instance.GetPrefab("Stone").GetComponent<ItemDrop>().m_itemData.m_shared.m_icons[0]);
			RequirementConfig[] requirements = (RequirementConfig[])(object)new RequirementConfig[4]
			{
				Req("FineWood", 10),
				Req("BronzeNails", 5),
				Req("Stone", 5),
				Req("RNR_PressCrank", 1)
			};
			if (!PieceManager.Instance.AddPiece(new CustomPiece(val, true, new PieceConfig
			{
				Name = "Screw Press",
				Description = "An addition to the Food Preparation Table. Unlocks pressing Sunflower Oil from Sunflower Heads and Fish Bile from fish and serpent meat.",
				PieceTable = "Hammer",
				Category = "R&R",
				Icon = icon,
				Requirements = requirements
			})))
			{
				throw new Exception("Piece registration rejected");
			}
			Pieces++;
			Recipes();
		}

		private static void Recipes()
		{
			Add("RNR_Recipe_SunflowerOil", "RNR_SunflowerOil", 1, "RNR_SunflowerHead", 1);
			string[] array = new string[12]
			{
				"Fish1", "Fish2", "Fish3", "Fish4_cave", "Fish5", "Fish6", "Fish7", "Fish8", "Fish9", "Fish10",
				"Fish11", "Fish12"
			};
			foreach (string text in array)
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab(text);
				string text2 = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_name : text);
				string text3 = Localization.instance.Localize(text2);
				int amount = Potions.BileYield(text3);
				Plugin.Instance.LoggerGarden("R&R fish bile: " + text + " (" + text3 + ") -> " + amount);
				Add("RNR_Recipe_FishBile_" + text, "RNR_FishBile", amount, text, 1);
			}
			array = new string[2] { "SerpentMeat", "BoneMawSerpentMeat" };
			foreach (string text4 in array)
			{
				Add("RNR_Recipe_FishBile_" + text4, "RNR_FishBile", 5, text4, 1);
			}
			static void Add(string name, string item, int amount2, string material, int count)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Expected O, but got Unknown
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Expected O, but got Unknown
				try
				{
					RecipeConfig val = new RecipeConfig();
					val.Name = name;
					val.Item = item;
					val.Amount = amount2;
					val.CraftingStation = "piece_preptable";
					val.MinStationLevel = 2;
					val.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
					{
						new RequirementConfig
						{
							Item = material,
							Amount = count
						}
					};
					RecipeConfig val2 = val;
					if (!ItemManager.Instance.AddRecipe(new CustomRecipe(val2)))
					{
						Plugin.Instance.LoggerGarden("R&R recipe rejected: " + name);
					}
				}
				catch (Exception ex)
				{
					Plugin.Instance.LoggerGarden("R&R recipe " + name + ": " + ex.Message);
				}
			}
		}

		private static void PieceOven(int i)
		{
			//IL_00e9: 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_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: 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_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Expected O, but got Unknown
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Expected O, but got Unknown
			bool flag = i == 5;
			string[] array = new string[6] { "MosquitoTrap", "RosemaryPlanter", "FlytrapPlanter", "OysterWall", "DryingRack", "Smokehouse" };
			string[] array2 = new string[6] { "Mosquito Trap", "Rosemary Planter", "Potted Flytrap", "Oyster Mushroom Wall Planter", "Wicker Drying Rack", "Clay Smokehouse" };
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("RNR_" + array[i], "piece_oven");
			Piece component = val.GetComponent<Piece>();
			component.m_groundOnly = false;
			component.m_groundPiece = false;
			component.m_notOnWood = false;
			component.m_notOnFloor = false;
			component.m_notOnTiltingSurface = false;
			component.m_cultivatedGroundOnly = false;
			component.m_spaceRequirement = 0f;
			component.m_noClipping = false;
			GardenVisual.Piece(val, i);
			Processing.Configure(val, flag, array2[i]);
			GameObject val2 = new GameObject("snap");
			val2.transform.SetParent(val.transform, false);
			val2.tag = "snappoint";
			RequirementConfig[] requirements = (RequirementConfig[])(object)((!flag) ? new RequirementConfig[4]
			{
				Req("Wood", 20),
				Req("RoundLog", 5),
				Req("Stone", 5),
				Req("RNR_Clay", 1)
			} : new RequirementConfig[4]
			{
				Req("Stone", 20),
				Req("Wood", 5),
				Req("RoundLog", 10),
				Req("RNR_Clay", 1)
			});
			Sprite icon = Icon(array[i], PrefabManager.Instance.GetPrefab("Stone").GetComponent<ItemDrop>().m_itemData.m_shared.m_icons[0]);
			string description = (flag ? "Smokes food over a wood fire. Load up to 12 foods; one is finished every 12 game hours and uses 4 wood. The wood you burn sets the quality of the food." : "Dries food over a wood fire. Load up to 12 foods; one is finished every 12 game hours and uses 4 wood. The wood you burn sets the quality of the food.");
			if (!PieceManager.Instance.AddPiece(new CustomPiece(val, true, new PieceConfig
			{
				Name = array2[i],
				Description = description,
				PieceTable = "Hammer",
				Category = "R&R",
				Icon = icon,
				Requirements = requirements
			})))
			{
				throw new Exception("Piece registration rejected");
			}
			Pieces++;
		}

		private static void Piece(int i)
		{
			//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_01b2: Unknown result type (might be due to invalid IL or missing references)
			//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_01da: 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_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Expected O, but got Unknown
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_049d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a7: Expected O, but got Unknown
			//IL_05bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0541: Unknown result type (might be due to invalid IL or missing references)
			//IL_054b: Expected O, but got Unknown
			//IL_060e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0619: Unknown result type (might be due to invalid IL or missing references)
			//IL_0624: Unknown result type (might be due to invalid IL or missing references)
			//IL_062c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0639: Expected O, but got Unknown
			//IL_0634: Unknown result type (might be due to invalid IL or missing references)
			//IL_063e: Expected O, but got Unknown
			switch (i)
			{
			case 4:
			case 5:
				PieceOven(i);
				return;
			case 6:
				PiecePan();
				return;
			case 7:
				PiecePress();
				return;
			}
			string[] array = new string[6] { "MosquitoTrap", "RosemaryPlanter", "FlytrapPlanter", "OysterWall", "DryingRack", "Smokehouse" };
			string[] array2 = new string[6] { "Mosquito Trap", "Rosemary Planter", "Potted Flytrap", "Oyster Mushroom Wall Planter", "Wicker Drying Rack", "Clay Smokehouse" };
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("RNR_" + array[i], "piece_beehive");
			PlantModels.HideOriginal(val);
			StripHiveEffects(val, i == 1 || i == 2 || i == 5);
			Beehive component = val.GetComponent<Beehive>();
			Piece component2 = val.GetComponent<Piece>();
			component2.m_groundOnly = false;
			component2.m_groundPiece = false;
			component2.m_notOnWood = false;
			component2.m_notOnFloor = false;
			component2.m_notOnTiltingSurface = false;
			component2.m_cultivatedGroundOnly = false;
			component2.m_spaceRequirement = 0f;
			component2.m_noClipping = false;
			Collider[] componentsInChildren = val.GetComponentsInChildren<Collider>(true);
			for (int j = 0; j < componentsInChildren.Length; j++)
			{
				componentsInChildren[j].enabled = false;
			}
			Vector3 val2 = (Vector3)(i switch
			{
				4 => new Vector3(1.65f, 1.9f, 1.45f), 
				3 => new Vector3(1.04f, 2f, 0.86f), 
				2 => new Vector3(0.9f, 1.25f, 0.9f), 
				1 => new Vector3(2f, 0.9f, 1f), 
				0 => new Vector3(1f, 2.5f, 1f), 
				_ => new Vector3(1.5f, 2f, 1.7f), 
			});
			if (i < 4)
			{
				BoxCollider obj = val.AddComponent<BoxCollider>();
				obj.size = val2;
				obj.center = new Vector3(0f, val2.y / 2f, 0f);
			}
			GameObject[] array3 = GardenVisual.Piece(val, i);
			GameObject val3 = new GameObject("snap");
			val3.transform.SetParent(val.transform, false);
			val3.tag = "snappoint";
			RequirementConfig[] requirements = i switch
			{
				4 => (RequirementConfig[])(object)new RequirementConfig[3]
				{
					Req("Wood", 30),
					Req("FineWood", 10),
					Req("Resin", 10)
				}, 
				3 => (RequirementConfig[])(object)new RequirementConfig[1] { Req("RNR_OysterMycelium", 1) }, 
				2 => (RequirementConfig[])(object)new RequirementConfig[2]
				{
					Req("Stone", 3),
					Req("RNR_LiveFlytrap", 1)
				}, 
				1 => (RequirementConfig[])(object)new RequirementConfig[2]
				{
					Req("Stone", 3),
					Req("RNR_RosemaryRoot", 1)
				}, 
				0 => (RequirementConfig[])(object)new RequirementConfig[2]
				{
					Req("RNR_MosquitoNet", 1),
					Req("FineWood", 4)
				}, 
				_ => (RequirementConfig[])(object)new RequirementConfig[3]
				{
					Req("Stone", 30),
					Req("RNR_Clay", 20),
					Req("Wood", 20)
				}, 
			};
			if (i == 0 || i == 2)
			{
				RnrInsectProducer rnrInsectProducer = val.AddComponent<RnrInsectProducer>();
				rnrInsectProducer.Flies = i == 2;
				rnrInsectProducer.Radius = Math.Max(0.1f, ((i == 2) ? Plugin.Instance.FlytrapSpacing : Plugin.Instance.MosquitoSpacing).Value);
				GameObject val4 = ((i == 0) ? PrefabManager.Instance.GetPrefab("Needle") : Items["Fly"]);
				component.m_name = array2[i];
				component.m_honeyItem = val4.GetComponent<ItemDrop>();
				component.m_secPerUnit = 1200f;
				component.m_maxHoney = 4;
				component.m_effectOnlyInDaylight = false;
				component.m_maxCover = 0f;
				component.m_biome = (Biome)(-1);
				component.m_extractText = "Collect";
				component.m_checkText = "Check";
				component.m_happyText = "";
				component.m_sleepText = "";
				component.m_areaText = "";
				component.m_freespaceText = "";
				component.m_beeEffect = new GameObject("Insects disabled");
				component.m_beeEffect.transform.SetParent(val.transform, false);
				component.m_spawnPoint = new GameObject("Output").transform;
				component.m_spawnPoint.SetParent(val.transform, false);
				component.m_spawnPoint.localPosition = new Vector3(0f, 0.5f, 0.8f);
				component.m_spawnEffect = new EffectList();
			}
			else
			{
				Object.DestroyImmediate((Object)(object)component);
				Pickable obj2 = val.AddComponent<Pickable>();
				obj2.m_itemPrefab = Items[(i == 1) ? "RosemaryLeaves" : "OysterMushroom"];
				obj2.m_amount = 3;
				obj2.m_overrideName = array2[i];
				obj2.m_respawnTimeMinutes = ((i == 3) ? Plugin.Instance.OysterRegrowMinutes.Value : Plugin.Instance.RosemaryRegrowMinutes.Value);
				obj2.m_hideWhenPicked = array3[1];
				obj2.m_defaultPicked = true;
				obj2.m_defaultEnabled = true;
				obj2.m_respawnTimeInitMin = 0f;
				obj2.m_respawnTimeInitMax = 0f;
				obj2.m_extraDrops = new DropTable();
				obj2.m_hoverOffset = 0.7f;
				val.AddComponent<RnrPickTuning>().Kind = ((i == 3) ? "oyster" : "rosemary");
				RnrGardenStages rnrGardenStages = val.AddComponent<RnrGardenStages>();
				rnrGardenStages.Trimmed = array3[0];
				rnrGardenStages.Grown = array3[1];
			}
			Sprite icon = Icon(array[i], PrefabManager.Instance.GetPrefab("Stone").GetComponent<ItemDrop>().m_itemData.m_shared.m_icons[0]);
			if (!PieceManager.Instance.AddPiece(new CustomPiece(val, true, new PieceConfig
			{
				Name = array2[i],
				Description = i switch
				{
					3 => "Gives 3 oyster mushrooms every hour.", 
					5 => "Smokes food over a wood fire. Load up to 12 foods; one is finished every 12 game hours. The wood you burn sets the quality.", 
					4 => "Dries food over a wood fire. Load up to 12 foods; one is finished every 12 game hours. The wood you burn sets the quality.", 
					2 => "Produces 1 Fly every 20 minutes, day and night. Flies do not fly in the rain. Keep planters at least 3 m apart.", 
					0 => "Produces 1 Needle every 20 minutes, day and night. Mosquitoes do not fly in the rain. Keep traps at least 3 m apart.", 
					_ => "Gives 3 rosemary leaves every 2 hours.", 
				},
				PieceTable = "Hammer",
				Category = "R&R",
				Icon = icon,
				Requirements = requirements
			})))
			{
				throw new Exception("Piece registration rejected");
			}
			Pieces++;
		}

		private static void StripHiveEffects(GameObject obj, bool stone)
		{
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Expected O, but got Unknown
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Expected O, but got Unknown
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Expected O, but got Unknown
			Transform[] componentsInChildren = obj.GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val) && (Object)(object)val != (Object)(object)obj.transform && ((Object)val).name == "BeeEffect")
				{
					Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
				}
			}
			ZSFX[] componentsInChildren2 = obj.GetComponentsInChildren<ZSFX>(true);
			foreach (ZSFX val2 in componentsInChildren2)
			{
				if (Object.op_Implicit((Object)(object)val2))
				{
					Object.DestroyImmediate((Object)(object)((Component)val2).gameObject);
				}
			}
			Component[] componentsInChildren3 = obj.GetComponentsInChildren<Component>(true);
			foreach (Component val3 in componentsInChildren3)
			{
				if (Object.op_Implicit((Object)(object)val3))
				{
					string name = ((object)val3).GetType().Name;
					if (name == "AudioSource")
					{
						Object.DestroyImmediate((Object)(object)val3);
					}
					else if (name == "ParticleSystem" && (Object)(object)val3.gameObject != (Object)(object)obj)
					{
						Object.DestroyImmediate((Object)(object)val3.gameObject);
					}
				}
			}
			Beehive component = obj.GetComponent<Beehive>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.m_spawnEffect = new EffectList();
			}
			WearNTear component2 = obj.GetComponent<WearNTear>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab(stone ? "stone_wall_1x1" : "wood_beam");
				WearNTear val4 = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponent<WearNTear>() : null);
				if (Object.op_Implicit((Object)(object)val4))
				{
					component2.m_hitEffect = val4.m_hitEffect;
					component2.m_destroyedEffect = val4.m_destroyedEffect;
					component2.m_switchEffect = val4.m_switchEffect;
				}
				else
				{
					component2.m_hitEffect = new EffectList();
					component2.m_destroyedEffect = new EffectList();
					component2.m_switchEffect = new EffectList();
				}
			}
		}

		internal static void Status(Terminal t)
		{
			t.AddString("R&R garden: " + Pieces + "/8 pieces; " + Items.Count + "/" + Ids.Length + " items");
		}

		internal static bool Command(string[] a, Terminal t)
		{
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: 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)
			if (a.Length == 2 && a[0] == "garden" && a[1] == "nearby")
			{
				RnrInsectProducer.Nearby(t);
				return true;
			}
			if (a.Length == 1 && a[0] == "garden")
			{
				Status(t);
				foreach (KeyValuePair<string, GameObject> item in Items)
				{
					t.AddString("RNR_" + item.Key);
				}
				return true;
			}
			if (a.Length < 2 || a[0] != "spawn" || a[1] != "garden")
			{
				return false;
			}
			int result = 1;
			if (a.Length > 3 || (a.Length == 3 && (!int.TryParse(a[2], out result) || result < 1 || result > 50)))
			{
				t.AddString("rnr spawn garden [1–50]");
				return true;
			}
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer) || !Object.op_Implicit((Object)(object)ZNetScene.instance))
			{
				t.AddString("Enter a world first.");
				return true;
			}
			int num = 0;
			foreach (KeyValuePair<string, GameObject> item2 in Items)
			{
				GameObject prefab = ZNetScene.instance.GetPrefab("RNR_" + item2.Key);
				if (Object.op_Implicit((Object)(object)prefab))
				{
					Object.Instantiate<GameObject>(prefab, ((Component)localPlayer).transform.position + ((Component)localPlayer).transform.forward * 2f + ((Component)localPlayer).transform.right * ((float)num++ * 0.4f - 1.4f) + Vector3.up, Quaternion.identity).GetComponent<ItemDrop>().SetStack(result);
				}
			}
			Status(t);
			return true;
		}
	}
	public sealed class RnrGardenStages : MonoBehaviour
	{
		public GameObject Trimmed;

		public GameObject Grown;

		private void Update()
		{
			if (Object.op_Implicit((Object)(object)Trimmed) && Object.op_Implicit((Object)(object)Grown))
			{
				Trimmed.SetActive(!Grown.activeSelf);
			}
		}
	}
	public sealed class RnrInsectProducer : MonoBehaviour
	{
		public bool Flies;

		public float Radius = 3f;

		internal bool ClockReady;

		internal bool WasAllowed;

		private static readonly HashSet<RnrInsectProducer> Active = new HashSet<RnrInsectProducer>();

		private void OnEnable()
		{
			Active.Add(this);
			ClockReady = false;
		}

		private void OnDisable()
		{
			Active.Remove(this);
			ClockReady = false;
		}

		internal static void Nearby(Terminal terminal)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer))
			{
				terminal.AddString("Enter a world first.");
				return;
			}
			int num = 0;
			foreach (RnrInsectProducer item in Active)
			{
				if (!Object.op_Implicit((Object)(object)item))
				{
					continue;
				}
				Vector3 val = ((Component)item).transform.position - ((Component)localPlayer).transform.position;
				if (!(((Vector3)(ref val)).sqrMagnitude > 400f))
				{
					ZNetView component = ((Component)item).GetComponent<ZNetView>();
					if (Object.op_Implicit((Object)(object)component) && component.IsValid())
					{
						ZDO zDO = component.GetZDO();
						terminal.AddString((item.Flies ? "Potted Flytrap" : "Mosquito Trap") + ": " + zDO.GetInt(ZDOVars.s_level, 0) + "/4; " + item.Progress() + "; " + (item.Blocked() ?? "Working") + "; " + (component.IsOwner() ? "owner" : "remote owner"));
						num++;
					}
				}
			}
			if (num == 0)
			{
				terminal.AddString("No traps within 20 m.");
			}
		}

		internal string Progress()
		{
			ZNetView component = ((Component)this).GetComponent<ZNetView>();
			if (!Object.op_Implicit((Object)(object)component) || !component.IsValid())
			{
				return "Waiting for world";
			}
			ZDO zDO = component.GetZDO();
			if (zDO.GetInt(ZDOVars.s_level, 0) >= 4)
			{
				return "Storage full";
			}
			float num = Mathf.Clamp(zDO.GetFloat(ZDOVars.s_product, 0f), 0f, 1200f);
			int num2 = Mathf.CeilToInt(1200f - num);
			return "Next " + (Flies ? "Fly" : "Needle") + ": " + Mathf.FloorToInt(num * 100f / 1200f) + "% (" + (num2 / 60).ToString("00") + ":" + (num2 % 60).ToString("00") + " active time left)";
		}

		public string Blocked()
		{
			//IL_009a: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			if (EnvMan.IsWet())
			{
				if (!Flies)
				{
					return "Mosquitoes do not fly in the rain.";
				}
				return "Flies do not fly in the rain.";
			}
			float num = Math.Max(0.1f, (Flies ? Plugin.Instance.FlytrapSpacing : Plugin.Instance.MosquitoSpacing).Value);
			foreach (RnrInsectProducer item in Active)
			{
				if (!Object.op_Implicit((Object)(object)item) || (Object)(object)item == (Object)(object)this || item.Flies != Flies)
				{
					continue;
				}
				ZNetView component = ((Component)item).GetComponent<ZNetView>();
				if (Object.op_Implicit((Object)(object)component) && component.IsValid())
				{
					Vector3 val = ((Component)item).transform.position - ((Component)this).transform.position;
					if (((Vector3)(ref val)).sqrMagnitude < num * num)
					{
						return Flies ? "Flytrap planters are too close together." : "Mosquito traps are too close together.";
					}
				}
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(Beehive), "UpdateBees")]
	internal static class GardenProductionPatch
	{
		private static bool Prefix(Beehive __instance)
		{
			RnrInsectProducer component = ((Component)__instance).GetComponent<RnrInsectProducer>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return true;
			}
			ZNetView component2 = ((Component)__instance).GetComponent<ZNetView>();
			if (!Object.op_Implicit((Object)(object)component2) || !component2.IsValid())
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)__instance.m_beeEffect))
			{
				__instance.m_beeEffect.SetActive(false);
			}
			if (!component2.IsOwner())
			{
				component.ClockReady = false;
				return false;
			}
			ZDO zDO = component2.GetZDO();
			long ticks = ZNet.instance.GetTime().Ticks;
			long num = zDO.GetLong(ZDOVars.s_lastTime, ticks);
			zDO.Set(ZDOVars.s_lastTime, ticks);
			int num2 = zDO.GetInt(ZDOVars.s_level, 0);
			bool flag = component.Blocked() == null;
			double totalSeconds = TimeSpan.FromTicks(ticks - num).TotalSeconds;
			int result;
			float num3 = GardenRules.Tick(zDO.GetFloat(ZDOVars.s_product, 0f), totalSeconds, component.ClockReady, component.WasAllowed, flag, num2, __instance.m_maxHoney, out result);
			component.ClockReady = true;
			component.WasAllowed = flag;
			if (result != num2)
			{
				zDO.Set(ZDOVars.s_level, result, false);
			}
			zDO.Set(ZDOVars.s_product, num3);
			return false;
		}
	}
	[HarmonyPatch(typeof(Beehive), "GetHoverText")]
	internal static class GardenHoverPatch
	{
		private static bool Prefix(Beehive __instance, ref string __result)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<RnrInsectProducer>()))
			{
				return true;
			}
			if (!PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, false, false))
			{
				__result = __instance.m_name;
				return false;
			}
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			int num = ((Object.op_Implicit((Object)(object)component) && component.IsValid()) ? component.GetZDO().GetInt(ZDOVars.s_level, 0) : 0);
			__result = Localization.instance.Localize(__instance.m_name + ((num > 0) ? "\n[<color=yellow><b>$KEY_Use</b></color>] Collect" : ""));
			return false;
		}
	}
	[HarmonyPatch(typeof(Beehive), "Interact")]
	internal static class GardenInteractPatch
	{
		private static bool Prefix(Beehive __instance, Humanoid character, bool repeat, ref bool __result)
		{
			if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<RnrInsectProducer>()) || repeat)
			{
				return true;
			}
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			if (!Object.op_Implicit((Object)(object)component) || !component.IsValid() || component.GetZDO().GetInt(ZDOVars.s_level, 0) > 0)
			{
				return true;
			}
			__result = true;
			return false;
		}
	}
	internal static class GardenRules
	{
		internal const float SecondsPerUnit = 1200f;

		internal static float Tick(float progress, double elapsed, bool clockReady, bool wasAllowed, bool allowed, int level, int capacity, out int result)
		{
			return Advance(progress, clockReady ? elapsed : 0.0, allowed && wasAllowed, level, capacity, out result);
		}

		internal static float Advance(float progress, double elapsed, bool allowed, int level, int capacity, out int result)
		{
			result = level;
			if (level >= capacity)
			{
				return 0f;
			}
			if (float.IsNaN(progress) || float.IsInfinity(progress) || progress < 0f)
			{
				progress = 0f;
			}
			if (!allowed || double.IsNaN(elapsed) || double.IsInfinity(elapsed) || elapsed <= 0.0)
			{
				return progress;
			}
			double num = Math.Min((double)progress + elapsed, (double)(capacity - level) * 1200.0);
			int num2 = (int)(num / 1200.0);
			result = level + num2;
			if (result < capacity)
			{
				return (float)(num - (double)((float)num2 * 1200f));
			}
			return 0f;
		}
	}
	internal static class GardenVisual
	{
		private sealed class Model
		{
			public Mesh Mesh;

			public string[] Keys;
		}

		private static readonly Dictionary<string, Model> Models = new Dictionary<string, Model>();

		private static readonly Dictionary<string, Material> Materials = new Dictionary<string, Material>();

		private static readonly Dictionary<string, Texture2D> Textures = new Dictionary<string, Texture2D>();

		private static byte[] Resource(string name)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("RNR.GardenGeometry." + name);
			if (stream == null)
			{
				throw new Exception("Missing garden resource: " + name);
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		private static Model Load(string name)
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Expected O, but got Unknown
			if (Models.TryGetValue(name, out var value))
			{
				return value;
			}
			using GZipStream input = new GZipStream(new MemoryStream(Resource(name + ".mesh.gz")), CompressionMode.Decompress);
			using BinaryReader binaryReader = new BinaryReader(input);
			if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "RNR2")
			{
				throw new Exception("Unsupported garden mesh format: " + name);
			}
			int num = binaryReader.ReadInt32();
			int num2 = binaryReader.ReadInt32();
			Vector3[] array = (Vector3[])(object)new Vector3[num];
			Vector3[] array2 = (Vector3[])(object)new Vector3[num];
			Vector2[] array3 = (Vector2[])(object)new Vector2[num];
			Color[] array4 = (Color[])(object)new Color[num];
			for (int i = 0; i < num; i++)
			{
				array[i] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			for (int j = 0; j < num; j++)
			{
				array2[j] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			for (int k = 0; k < num; k++)
			{
				array3[k] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
				array4[k] = Color.white;
			}
			Mesh val = new Mesh
			{
				name = "RNR garden " + name
			};
			if (num > 65000)
			{
				val.indexFormat = (IndexFormat)1;
			}
			val.vertices = array;
			val.normals = array2;
			val.uv = array3;
			val.colors = array4;
			val.subMeshCount = num2;
			string[] array5 = new string[num2];
			for (int l = 0; l < num2; l++)
			{
				array5[l] = Encoding.UTF8.GetString(binaryReader.ReadBytes(binaryReader.ReadInt32()));
				int[] array6 = new int[binaryReader.ReadInt32()];
				for (int m = 0; m < array6.Length; m++)
				{
					array6[m] = binaryReader.ReadInt32();
				}
				val.SetTriangles(array6, l);
			}
			val.RecalculateBounds();
			if (num > 0)
			{
				val.RecalculateTangents();
			}
			Model model = new Model
			{
				Mesh = val,
				Keys = array5
			};
			Models.Add(name, model);
			return model;
		}

		private static Material Vanilla(string prefab, string material)
		{
			GameObject prefab2 = PrefabManager.Instance.GetPrefab(prefab);
			if (!Object.op_Implicit((Object)(object)prefab2))
			{
				throw new Exception("Vanilla prefab missing: " + prefab);
			}
			Renderer[] componentsInChildren = prefab2.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Material[] sharedMaterials = componentsInChildren[i].sharedMaterials;
				foreach (Material val in sharedMaterials)
				{
					if (Object.op_Implicit((Object)(object)val) && ((Object)val).name.Replace(" (Instance)", "") == material)
					{
						return val;
					}
				}
			}
			throw new Exception("Vanilla material missing: " + prefab + "/" + material);
		}

		private static Texture2D Texture(string name, bool linear = false, bool smooth = false)
		{
			//IL_0016: 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_002d: Expected O, but got Unknown
			if (Textures.TryGetValue(name, out var value))
			{
				return value;
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear)
			{
				name = "RNR " + name
			};
			if (!ImageConversion.LoadImage(val, Resource("tex_" + name + ".png")))
			{
				throw new Exception("Garden texture failed to load: " + name);
			}
			((Texture)val).filterMode = (FilterMode)(smooth ? 1 : 0);
			((Texture)val).wrapMode = (TextureWrapMode)(smooth ? 1 : 0);
			((Texture)val).anisoLevel = ((!smooth) ? 1 : 4);
			Textures.Add(name, val);
			return val;
		}

		private static Material Retexture(Material template, string name, Texture texture, bool keepNormal)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_0028: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(template)
			{
				name = name
			};
			if (Object.op_Implicit((Object)(object)texture))
			{
				val.SetTexture("_MainTex", texture);
			}
			val.SetTextureScale("_MainTex", Vector2.one);
			val.SetTextureOffset("_MainTex", Vector2.zero);
			string[] array;
			if (!keepNormal)
			{
				array = new string[3] { "_BumpMap", "_MetallicGlossMap", "_EmissionMap" };
				foreach (string text in array)
				{
					if (val.HasProperty(text))
					{
						val.SetTexture(text, (Texture)null);
					}
				}
				array = new string[3] { "_NORMALMAP", "_METALLICGLOSSMAP", "_EMISSION" };
				foreach (string text2 in array)
				{
					val.DisableKeyword(text2);
				}
			}
			array = new string[2] { "_Color", "_BaseColor" };
			foreach (string text3 in array)
			{
				if (val.HasProperty(text3))
				{
					val.SetColor(text3, Color.white);
				}
			}
			return val;
		}

		private static Material Material(string key)
		{
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: 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_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Expected O, but got Unknown
			if (Materials.TryGetValue(key, out var value))
			{
				return value;
			}
			Material val;
			switch (key)
			{
			case "stone":
				val = Vanilla("stone_wall_2x1", "stone_mat");
				break;
			case "wood":
				val = Retexture(Vanilla("wood_pole", "woodpole"), "RNR garden wood", null, keepNormal: true);
				break;
			case "straw":
				val = Vanilla("wood_roof", "straw_roof");
				break;
			case "straw_a":
				val = Vanilla("wood_roof", "straw_roof_alpha");
				break;
			case "dark":
				val = Vanilla("darkwood_beam", "DarkWood_mat");
				break;
			case "g:glow":
				val = new Material(Shader.Find("Sprites/Default"))
				{
					name = "RNR garden glow",
					color = new Color(1f, 0.2f, 0.05f, 0.85f)
				};
				break;
			case "log":
				val = Vanilla("wood_pole_log", "logwall");
				break;
			default:
			{
				string text = key.Substring(2);
				if (key.StartsWith("c:"))
				{
					val = Retexture(Vanilla("stone_wall_2x1", "stone_mat"), "RNR garden " + text, (Texture)(object)Texture(text), keepNormal: false);
				}
				else if (key.StartsWith("a:") || key.StartsWith("v:"))
				{
					val = Retexture(Vanilla("BlueberryBush", "Bush01"), "RNR garden " + text, (Texture)(object)Texture(text), keepNormal: false);
					string[] array = new string[2] { "_SwayDistance", "_RippleDistance" };
					foreach (string text2 in array)
					{
						if (val.HasProperty(text2))
						{
							val.SetFloat(text2, 0f);
						}
					}
					if (val.HasProperty("_Cutoff"))
					{
						val.SetFloat("_Cutoff", 0.5f);
					}
				}
				else
				{
					if (!key.StartsWith("b:"))
					{
						throw new Exception("Unknown garden material key: " + key);
					}
					val = Retexture(Vanilla("stone_wall_2x1", "stone_mat"), "RNR garden " + text, (Texture)(object)Texture(text + "_color"), keepNormal: false);
				}
				break;
			}
			}
			Materials.Add(key, val);
			return val;
		}

		private static GameObject Attach(GameObject parent, string name)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			Model model = Load(name);
			GameObject val = new GameObject(name);
			val.layer = parent.layer;
			val.transform.SetParent(parent.transform, false);
			if (model.Keys.Length == 0)
			{
				return val;
			}
			val.AddComponent<MeshFilter>().sharedMesh = model.Mesh;
			Material[] array = (Material[])(object)new Material[model.Keys.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Material(model.Keys[i]);
			}
			((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterials = array;
			return val;
		}

		internal static GameObject[] Piece(GameObject parent, int i)
		{
			Attach(parent, "P" + i);
			if (i != 1 && i != 3)
			{
				return (GameObject[])(object)new GameObject[2];
			}
			GameObject val = Attach(parent, "P" + i + "_trim");
			GameObject val2 = Attach(parent, "P" + i + "_grown");
			val.SetActive(false);
			return (GameObject[])(object)new GameObject[2] { val, val2 };
		}

		internal static void Item(GameObject parent, int i)
		{
			Attach(parent, "I" + i);
		}

		internal static GameObject Extra(GameObject parent, string name, bool active = false)
		{
			GameObject obj = Attach(parent, name);
			obj.SetActive(active);
			return obj;
		}
	}
	internal static class IconMatte
	{
		internal static byte[] Clean(byte[] rgba, int width, int height)
		{
			if (width < 1 || height < 1 || rgba.Length != width * height * 4)
			{
				throw new ArgumentException("Invalid RGBA image");
			}
			byte[] array = (byte[])rgba.Clone();
			for (int i = 0; i < array.Length; i += 4)
			{
				if (array[i + 3] < 128)
				{
					array[i] = 36;
					array[i + 1] = 27;
					array[i + 2] = 21;
					array[i + 3] = 0;
				}
			}
			byte[] array2 = (byte[])array.Clone();
			for (int j = 0; j < height; j++)
			{
				for (int k = 0; k < width; k++)
				{
					int num = (j * width + k) * 4;
					if (array2[num + 3] == 0)
					{
						continue;
					}
					bool flag = false;
					for (int l = -1; l <= 1; l++)
					{
						for (int m = -1; m <= 1; m++)
						{
							int num2 = k + m;
							int num3 = j + l;
							if (num2 < 0 || num3 < 0 || num2 >= width || num3 >= height || array2[(num3 * width + num2) * 4 + 3] == 0)
							{
								flag = true;
							}
						}
					}
					if (flag)
					{
						int num4 = Math.Min(array2[num], Math.Min(array2[num + 1], array2[num + 2]));
						int num5 = Math.Max(array2[num], Math.Max(array2[num + 1], array2[num + 2]));
						if (num4 >= 130 && num5 - num4 <= 65)
						{
							array[num] = 48;
							array[num + 1] = 35;
							array[num + 2] = 26;
						}
						else if (array2[num + 3] < 240)
						{
							array[num] = (byte)Math.Min((int)array[num], 64);
							array[num + 1] = (byte)Math.Min((int)array[num + 1], 48);
							array[num + 2] = (byte)Math.Min((int)array[num + 2], 36);
						}
					}
				}
			}
			return array;
		}
	}
	internal static class IconSizing
	{
		internal static bool NoGpu => (int)SystemInfo.graphicsDeviceType == 4;

		internal static Sprite Fit(Texture2D input, Sprite original, float fill = 0f)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0078: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			//IL_0114: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Expected O, but got Unknown
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Expected O, but got Unknown
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			Clean(input);
			if (!Object.op_Implicit((Object)(object)original) || NoGpu)
			{
				return Sprite.Create(input, new Rect(0f, 0f, (float)((Texture)input).width, (float)((Texture)input).height), new Vector2(0.5f, 0.5f));
			}
			Rect rect = original.rect;
			int num = Mathf.RoundToInt(((Rect)(ref rect)).width);
			rect = original.rect;
			int num2 = Mathf.RoundToInt(((Rect)(ref rect)).height);
			Rect textureRect = original.textureRect;
			RenderTexture temporary = RenderTexture.GetTemporary(num, num2, 0, (RenderTextureFormat)0);
			RenderTexture active = RenderTexture.active;
			Texture2D val = null;
			try
			{
				Graphics.Blit((Texture)(object)original.texture, temporary, new Vector2(((Rect)(ref textureRect)).width / (float)((Texture)original.texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)original.texture).height), new Vector2(((Rect)(ref textureRect)).x / (float)((Texture)original.texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)original.texture).height));
				RenderTexture.active = temporary;
				val = new Texture2D(num, num2, (TextureFormat)4, false);
				val.ReadPixels(new Rect(0f, 0f, (float)num, (float)num2), 0, 0);
				val.Apply();
				RectInt val2 = Bounds(val);
				RectInt val3 = Bounds(input);
				if (fill > 0f)
				{
					int num3 = Mathf.RoundToInt((float)num * fill);
					int num4 = Mathf.RoundToInt((float)num2 * fill);
					((RectInt)(ref val2))..ctor((num - num3) / 2, (num2 - num4) / 2, num3, num4);
				}
				float num5 = Mathf.Min((float)((RectInt)(ref val2)).width / (float)((RectInt)(ref val3)).width, (float)((RectInt)(ref val2)).height / (float)((RectInt)(ref val3)).height);
				int num6 = Mathf.Max(1, Mathf.RoundToInt((float)((RectInt)(ref val3)).width * num5));
				int num7 = Mathf.Max(1, Mathf.RoundToInt((float)((RectInt)(ref val3)).height * num5));
				int num8 = ((RectInt)(ref val2)).x + (((RectInt)(ref val2)).width - num6) / 2;
				int num9 = ((RectInt)(ref val2)).y + (((RectInt)(ref val2)).height - num7) / 2;
				Color32[] array = (Color32[])(object)new Color32[num * num2];
				Color32[] pixels = input.GetPixels32();
				for (int i = 0; i < num7; i++)
				{
					for (int j = 0; j < num6; j++)
					{
						int num10 = num8 + j;
						int num11 = num9 + i;
						if (num10 < 0 || num11 < 0 || num10 >= num || num11 >= num2)
						{
							continue;
						}
						int num12 = ((RectInt)(ref val3)).x + j * ((RectInt)(ref val3)).width / num6;
						int num13 = Mathf.Max(num12 + 1, ((RectInt)(ref val3)).x + (j + 1) * ((RectInt)(ref val3)).width / num6);
						int num14 = ((RectInt)(ref val3)).y + i * ((RectInt)(ref val3)).height / num7;
						int num15 = Mathf.Max(num14 + 1, ((RectInt)(ref val3)).y + (i + 1) * ((RectInt)(ref val3)).height / num7);
						float num16 = 0f;
						float num17 = 0f;
						float num18 = 0f;
						float num19 = 0f;
						int num20 = 0;
						for (int k = num14; k < num15 && k < ((Texture)input).height; k++)
						{
							for (int l = num12; l < num13 && l < ((Texture)input).width; l++)
							{
								Color32 val4 = pixels[k * ((Texture)input).width + l];
								num16 += (float)(val4.r * val4.a);
								num17 += (float)(val4.g * val4.a);
								num18 += (float)(val4.b * val4.a);
								num19 += (float)(int)val4.a;
								num20++;
							}
						}
						if (num19 > 0f)
						{
							array[num11 * num + num10] = new Color32((byte)(num16 / num19), (byte)(num17 / num19), (byte)(num18 / num19), (byte)(num19 / (float)num20));
						}
					}
				}
				Texture2D val5 = new Texture2D(num, num2, (TextureFormat)4, false);
				val5.SetPixels32(array);
				Clean(val5);
				val5.Apply();
				((Texture)val5).filterMode = (FilterMode)0;
				((Texture)val5).wrapMode = (TextureWrapMode)1;
				Rect val6 = new Rect(0f, 0f, (float)num, (float)num2);
				float x = original.pivot.x;
				rect = original.rect;
				float num21 = x / ((Rect)(ref rect)).width;
				float y = original.pivot.y;
				rect = original.rect;
				return Sprite.Create(val5, val6, new Vector2(num21, y / ((Rect)(ref rect)).height), original.pixelsPerUnit);
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
				if (Object.op_Implicit((Object)(object)val))
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}

		private static void Clean(Texture2D texture)
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			Color32[] pixels = texture.GetPixels32();
			byte[] array = new byte[pixels.Length * 4];
			for (int i = 0; i < pixels.Length; i++)
			{
				array[i * 4] = pixels[i].r;
				array[i * 4 + 1] = pixels[i].g;
				array[i * 4 + 2] = pixels[i].b;
				array[i * 4 + 3] = pixels[i].a;
			}
			array = IconMatte.Clean(array, ((Texture)texture).width, ((Texture)texture).height);
			for (int j = 0; j < pixels.Length; j++)
			{
				pixels[j] = new Color32(array[j * 4], array[j * 4 + 1], array[j * 4 + 2], array[j * 4 + 3]);
			}
			texture.SetPixels32(pixels);
			texture.Apply();
		}

		private static RectInt Bounds(Texture2D texture)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			Color32[] pixels = texture.GetPixels32();
			int num = ((Texture)texture).width;
			int num2 = -1;
			int num3 = ((Texture)texture).height;
			int num4 = -1;
			for (int i = 0; i < ((Texture)texture).height; i++)
			{
				for (int j = 0; j < ((Texture)texture).width; j++)
				{
					if (pixels[i * ((Texture)texture).width + j].a > 16)
					{
						num = Mathf.Min(num, j);
						num2 = Mathf.Max(num2, j);
						num3 = Mathf.Min(num3, i);
						num4 = Mathf.Max(num4, i);
					}
				}
			}
			if (num2 >= num)
			{
				return new RectInt(num, num3, num2 - num + 1, num4 - num3 + 1);
			}
			return new RectInt(0, 0, ((Texture)texture).width, ((Texture)texture).height);
		}
	}
	internal sealed class PlantItem
	{
		internal readonly string Id;

		internal readonly string Name;

		internal readonly int Model;

		internal readonly bool Seed;

		internal string Prefab => "RNR_" + Id;

		internal PlantItem(string id, string name, int model, bool seed)
		{
			Id = id;
			Name = name;
			Model = model;
			Seed = seed;
		}
	}
	internal static class PlantCatalog
	{
		internal static readonly PlantItem[] Items = new PlantItem[6]
		{
			new PlantItem("SunflowerSeeds", "Sunflower Seeds", 7, seed: true),
			new PlantItem("SunflowerHead", "Sunflower Head", 3, seed: false),
			new PlantItem("MugwortSeeds", "Mugwort Seeds", 15, seed: true),
			new PlantItem("Mugwort", "Mugwort Sprigs", 11, seed: false),
			new PlantItem("FoxgloveFlowers", "Foxglove Flowers", 19, seed: false),
			new PlantItem("LavenderFlowers", "Lavender Flowers", 27, seed: false)
		};

		internal static readonly string[] PlantNames = new string[8] { "Sunflower — flower crop", "Sunflower — seed crop", "Mugwort — herb crop", "Mugwort — seed crop", "Foxglove Bush", "Foxglove Bush", "Lavender Bush", "Lavender Bush" };

		internal static readonly float[] Heights = new float[8] { 2.3f, 2.3f, 0.85f, 0.85f, 2f, 2f, 1.2f, 1.2f };

		internal static readonly int[] Rows = new int[6] { 0, 1, 2, 3, 4, 6 };

		internal const float FlowerRespawnMinutes = 300f;

		internal static string Description(string id)
		{
			return id switch
			{
				"SunflowerHead" => "A heavy golden head, full of oily seeds. Press it for sunflower oil.", 
				"Mugwort" => "Grey-green sprigs of mugwort. Bitter smelling, and loved by dreamers and brewers.", 
				"FoxgloveFlowers" => "Tall, speckled bells of foxglove. Beautiful, powerful and not to be eaten raw.", 
				"LavenderFlowers" => "Soft purple lavender, dried until it rustles. Calms the mind and sweetens a brew.", 
				_ => "A useful plant.", 
			};
		}

		internal static bool Bush(int row)
		{
			return row >= 4;
		}

		internal static int Input(int row)
		{
			if (row >= 4)
			{
				if (row >= 6)
				{
					return 5;
				}
				return 4;
			}
			return row;
		}

		internal static int Output(int row)
		{
			if (row >= 4)
			{
				return Input(row);
			}
			return row ^ 1;
		}

		internal static int Cost(int row)
		{
			if (!Bush(row))
			{
				return 1;
			}
			return 3;
		}

		internal static float Radius(int row)
		{
			if (row >= 2)
			{
				if (!Bush(row))
				{
					return 0.35f;
				}
				return 0.75f;
			}
			return 0.28f;
		}

		internal static float ColliderRadius(int row)
		{
			if (!Bush(row))
			{
				return Radius(row);
			}
			return 0.42f;
		}

		internal static float GrowSeconds(int row)
		{
			if (!Bush(row))
			{
				return 2400f;
			}
			return 4500f;
		}

		internal static int Yield(int row)
		{
			if (row % 2 != 0)
			{
				return 3;
			}
			return 1;
		}

		internal static string CropPrefab(int row)
		{
			return row switch
			{
				3 => "RNR_MugwortSeedPlant", 
				2 => "RNR_MugwortPlant", 
				_ => "RNR_Crop" + row, 
			};
		}
	}
	internal static class PlantModels
	{
		private static readonly Dictionary<int, Mesh> Meshes = new Dictionary<int, Mesh>();

		private static Material material;

		internal static byte[] Resource(string name)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("RNR.Plants." + name);
			if (stream == null)
			{
				throw new Exception("Missing plant resource " + name);
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		private static Mesh Model(int index)
		{
			//IL_00a4: 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)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Expected O, but got Unknown
			if (Meshes.TryGetValue(index, out var value))
			{
				return value;
			}
			using GZipStream input = new GZipStream(new MemoryStream(Resource(((index >= 100) ? "F" : "P") + (index % 100).ToString("00") + ".mesh.gz")), CompressionMode.Decompress);
			using BinaryReader binaryReader = new BinaryReader(input);
			int num = binaryReader.ReadInt32();
			int num2 = binaryReader.ReadInt32();
			Vector3[] array = (Vector3[])(object)new Vector3[num];
			Vector3[] array2 = (Vector3[])(object)new Vector3[num];
			Vector2[] array3 = (Vector2[])(object)new Vector2[num];
			int[] array4 = new int[num2];
			for (int i = 0; i < num; i++)
			{
				array[i] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			for (int j = 0; j < num; j++)
			{
				array2[j] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			for (int k = 0; k < num; k++)
			{
				array3[k] = new Vector2(binaryReader.ReadSingle(), 1f - binaryReader.ReadSingle());
			}
			for (int l = 0; l < num2; l++)
			{
				array4[l] = binaryReader.ReadInt32();
			}
			Color[] array5 = (Color[])(object)new Color[num];
			for (int m = 0; m < num; m++)
			{
				array5[m] = Color.white;
			}
			Mesh val = new Mesh
			{
				name = "RNR plant model " + index,
				indexFormat = (IndexFormat)1
			};
			val.vertices = array;
			val.normals = array2;
			val.colors = array5;
			val.uv = array3;
			val.triangles = array4;
			val.RecalculateBounds();
			Meshes[index] = val;
			return val;
		}

		internal static GameObject Visual(GameObject parent, int index, float height, bool unhealthy = false, float depth = 1f)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)material))
			{
				material = CreateMaterial(parent);
			}
			GameObject val = new GameObject("RNR Visual " + index);
			val.layer = parent.layer;
			val.transform.SetParent(parent.transform, false);
			Mesh val2 = Model(index);
			Mesh val3 = null;
			string text = "F" + index.ToString("00") + ".mesh.gz";
			if (Assembly.GetExecutingAssembly().GetManifestResourceInfo("RNR.Plants." + text) != null)
			{
				val3 = Model(100 + index);
			}
			Bounds bounds = val2.bounds;
			Vector3 size = ((Bounds)(ref bounds)).size;
			float num = ((height > 0f) ? (height / Math.Max(0.001f, Math.Max(size.x, Math.Max(size.y, size.z)))) : 1f);
			val.transform.localScale = new Vector3(num, num, num);
			Material val4 = material;
			if (unhealthy)
			{
				val4 = new Material(material);
				if (val4.HasProperty("_Color"))
				{
					val4.SetColor("_Color", new Color(0.5f, 0.35f, 0.2f));
				}
			}
			Attach(val, val2, val4, "Foliage");
			if (Object.op_Implicit((Object)(object)val3))
			{
				Attach(val, val3, val4, "Flowers");
			}
			if (index % 4 != 3)
			{
				val.AddComponent<RnrPlantWind>();
			}
			return val;
		}

		private static void Attach(GameObject root, Mesh mesh, Material selected, string name)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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)
			GameObject val = new GameObject(name)
			{
				layer = root.layer
			};
			val.transform.SetParent(root.transform, false);
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = selected;
		}

		private static Material CreateMaterial(GameObject parent)
		{
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Expected O, but got Unknown
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Expected O, but got Unknown
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			Material val = null;
			string text = null;
			string[] array = new string[4] { "Pickable_Carrot", "sapling_carrot", "BlueberryBush", "wood_floor" };
			foreach (string text2 in array)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					break;
				}
				GameObject prefab = PrefabManager.Instance.GetPrefab(text2);
				if (!Object.op_Implicit((Object)(object)prefab))
				{
					continue;
				}
				Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					Material[] sharedMaterials = componentsInChildren[j].sharedMaterials;
					foreach (Material val2 in sharedMaterials)
					{
						if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val2.shader) || (text2 != "wood_floor" && ((Object)val2.shader).name != "Custom/Vegetation"))
						{
							continue;
						}
						string[] array2 = new string[3] { "_MainTex", "_BaseMap", "_BaseColorMap" };
						foreach (string text3 in array2)
						{
							if (val2.HasProperty(text3))
							{
								val = val2;
								text = text3;
								break;
							}
						}
						if (Object.op_Implicit((Object)(object)val))
						{
							break;
						}
					}
					if (Object.op_Implicit((Object)(object)val))
					{
						break;
					}
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				throw new Exception("No loaded native crop material with a base texture on " + ((Object)parent).name);
			}
			Texture2D val3 = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val3, Resource("atlas.png")))
			{
				throw new Exception("Plant atlas failed");
			}
			((Texture)val3).filterMode = (FilterMode)0;
			((Texture)val3).wrapMode = (TextureWrapMode)1;
			Material val4 = new Material(val)
			{
				name = "RNR plants"
			};
			val4.SetTexture(text, (Texture)(object)val3);
			val4.SetTextureScale(text, Vector2.one);
			val4.SetTextureOffset(text, Vector2.zero);
			array = new string[2] { "_Color", "_BaseColor" };
			foreach (string text4 in array)
			{
				if (val4.HasProperty(text4))
				{
					val4.SetColor(text4, Color.white);
				}
			}
			array = new string[6] { "_BumpMap", "_MetallicGlossMap", "_OcclusionMap", "_EmissionMap", "_SkinBumpMap", "_MossTex" };
			foreach (string text5 in array)
			{
				if (val4.HasProperty(text5))
				{
					val4.SetTexture(text5, (Texture)null);
				}
			}
			if (val4.HasProperty("_EmissionColor"))
			{
				val4.SetColor("_EmissionColor", Color.black);
			}
			array = new string[3] { "_NORMALMAP", "_METALLICGLOSSMAP", "_EMISSION" };
			foreach (string text6 in array)
			{
				val4.DisableKeyword(text6);
			}
			array = new string[4] { "_Metallic", "_Glossiness", "_Smoothness", "_BumpScale" };
			foreach (string text7 in array)
			{
				if (val4.HasProperty(text7))
				{
					val4.SetFloat(text7, 0f);
				}
			}
			array = new string[3] { "_SwayDistance", "_RippleDistance", "_Cull" };
			foreach (string text8 in array)
			{
				if (val4.HasProperty(text8))
				{
					val4.SetFloat(text8, 0f);
				}
			}
			if (val4.HasProperty("_Cutoff"))
			{
				val4.SetFloat("_Cutoff", 0.5f);
			}
			if (val4.HasProperty("_TwoSidedNormals"))
			{
				val4.SetFloat("_TwoSidedNormals", 1f);
			}
			return val4;
		}

		internal static Sprite Icon(int index, Sprite original)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, Resource("P" + index.ToString("00") + ".png"));
			Sprite obj = IconSizing.Fit(val, original, 0.94f);
			if ((Object)(object)obj.texture != (Object)(object)val)
			{
				Object.Destroy((Object)(object)val);
			}
			return obj;
		}

		internal static void HideOriginal(GameObject obj)
		{
			LODGroup[] componentsInChildren = obj.GetComponentsInChildren<LODGroup>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			Renderer[] componentsInChildren2 = obj.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				componentsInChildren2[i].enabled = false;
			}
		}
	}
	public sealed class RnrPlantWind : MonoBehaviour
	{
		private sealed class MovingMesh
		{
			internal Mesh Mesh;

			internal Vector3[] Rest;

			internal Vector3[] Moving;

			internal bool Flowers;

			internal float Top;
		}

		private readonly List<MovingMesh> moving = new List<MovingMesh>();

		private float next;

		private float phase;

		private void Start()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_00b5: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			phase = ((Component)this).transform.position.x * 0.73f + ((Component)this).transform.position.z * 0.91f;
			MeshFilter[] componentsInChildren = ((Component)this).GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val in componentsInChildren)
			{
				Mesh val2 = Object.Instantiate<Mesh>(val.sharedMesh);
				val2.MarkDynamic();
				val.sharedMesh = val2;
				List<MovingMesh> list = moving;
				MovingMesh obj = new MovingMesh
				{
					Mesh = val2,
					Rest = val2.vertices,
					Moving = (Vector3[])(object)new Vector3[val2.vertexCount],
					Flowers = (((Object)((Component)val).gameObject).name == "Flowers")
				};
				Bounds bounds = val2.bounds;
				obj.Top = Mathf.Max(0.1f, ((Bounds)(ref bounds)).max.y);
				list.Add(obj);
				val2.bounds = new Bounds(new Vector3(0f, 1.25f, 0f), new Vector3(4f, 3.5f, 4f));
			}
		}

		private void Update()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00ca: 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)
			//IL_00d1: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: 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_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < next)
			{
				return;
			}
			next = Time.time + 0.05f;
			Vector3 val = (Object.op_Implicit((Object)(object)EnvMan.instance) ? EnvMan.instance.GetWindForce() : Vector3.zero);
			Vector3 val2 = ((Component)this).transform.InverseTransformDirection(val);
			val2.y = 0f;
			float num = 0.65f + 0.35f * Mathf.Sin(Time.time * 1.1f + phase);
			foreach (MovingMesh item in moving)
			{
				if (item.Flowers || item.Top > 1.5f)
				{
					Vector3 val3 = ((((Vector3)(ref val2)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref val2)).normalized : Vector3.right);
					Vector3 val4 = Vector3.Cross(Vector3.up, val3);
					float num2 = Mathf.Max(((Vector3)(ref val2)).magnitude, 0.3f);
					float num3 = (item.Flowers ? 0.12f : 0.11f);
					float num4 = (item.Flowers ? 2f : 0.6f);
					for (int i = 0; i < item.Rest.Length; i++)
					{
						Vector3 val5 = item.Rest[i];
						float num5 = Mathf.Clamp01(val5.y / item.Top);
						num5 *= num5;
						float num6 = phase + val5.x * num4 + val5.z * num4;
						Vector3 val6 = val3 * (num2 * (0.55f + 0.45f * Mathf.Sin(Time.time * 1.7f + num6))) + val4 * (0.3f * Mathf.Sin(Time.time * 1.1f + num6 * 1.3f));
						item.Moving[i] = val5 + val6 * (num3 * item.Top * num5);
					}
					item.Mesh.vertices = item.Moving;
				}
				else
				{
					for (int j = 0; j < item.Rest.Length; j++)
					{
						Vector3 val7 = item.Rest[j];
						float num7 = Mathf.Clamp01(val7.y);
						num7 *= num7;
						Vector3 val8 = val2 * (0.1f * num7 * num * (0.75f + 0.25f * Mathf.Sin(Time.time * 2.3f + phase + val7.y * 2f)));
						item.Moving[j] = val7 + val8;
					}
					item.Mesh.vertices = item.Moving;
				}
			}
		}

		private void OnDestroy()
		{
			foreach (MovingMesh item in moving)
			{
				if (Object.op_Implicit((Object)(object)item.Mesh))
				{
					Object.Destroy((Object)(object)item.Mesh);
				}
			}
		}
	}
	public sealed class RnrPlantVisuals : MonoBehaviour
	{
		public GameObject Young;

		public GameObject YoungUnhealthy;

		public GameObject Middle;

		public GameObject MiddleUnhealthy;
	}
	internal static class Plants
	{
		internal static readonly Dictionary<string, GameObject> Items = new Dictionary<string, GameObject>();

		internal static int Pieces;

		internal static void Register(Action<string> error)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Expected O, but got Unknown
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Expected O, but got Unknown
			PlantItem[] items = PlantCatalog.Items;
			foreach (PlantItem plantItem in items)
			{
				try
				{
					GameObject prefab = PrefabManager.Instance.GetPrefab(plantItem.Seed ? "CarrotSeeds" : "Carrot");
					if (!Object.op_Implicit((Object)(object)prefab))
					{
						throw new Exception("Missing native crop item");
					}
					GameObject val = PrefabManager.Instance.CreateClonedPrefab(plantItem.Prefab, prefab);
					ItemDrop component = val.GetComponent<ItemDrop>();
					SharedData val2 = new SharedData();
					FieldInfo[] fields = typeof(SharedData).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (FieldInfo fieldInfo in fields)
					{
						fieldInfo.SetValue(val2, fieldInfo.GetValue(prefab.GetComponent<ItemDrop>().m_itemData.m_shared));
					}
					component.m_itemData = new ItemData();
					component.m_itemData.m_shared = val2;
					component.m_itemData.m_dropPrefab = val;
					val2.m_name = plantItem.Name;
					val2.m_description = (plantItem.Seed ? ("Plant to grow " + plantItem.Name.Replace(" Seeds", "") + ".") : PlantCatalog.Description(plantItem.Id));
					val2.m_itemType = (ItemType)1;
					val2.m_food = 0f;
					val2.m_foodStamina = 0f;
					val2.m_foodEitr = 0f;
					val2.m_foodBurnTime = 0f;
					val2.m_maxStackSize = (plantItem.Seed ? 100 : 50);
					val2.m_weight = 0.1f;
					val2.m_buildPieces = null;
					val2.m_appendToolTip = null;
					val2.m_icons = (Sprite[])(object)new Sprite[1] { PlantModels.Icon(plantItem.Model, val2.m_icons.FirstOrDefault()) };
					PlantModels.HideOriginal(val);
					PlantModels.Visual(val, plantItem.Model, plantItem.Seed ? 0.38f : 0.6f).transform.localPosition = new Vector3(0f, 0.02f, 0f);
					if (!ItemManager.Instance.AddItem(new CustomItem(val, false)))
					{
						throw new Exception("Item registration failed");
					}
					Items.Add(plantItem.Prefab, val);
				}
				catch (Exception ex)
				{
					error(plantItem.Id + ": " + ex);
				}
			}
			int[] rows = PlantCatalog.Rows;
			for (int i = 0; i < rows.Length; i++)
			{
				int row = ro