Decompiled source of PlantIt Continuation v0.2.1

BepInEx/plugins/PlantIt/PlantIt.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("PlantIt")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1+c039f86b9daa07bc614afb512417fe89ee879537")]
[assembly: AssemblyProduct("PlantIt")]
[assembly: AssemblyTitle("PlantIt")]
[assembly: AssemblyVersion("0.2.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 PlantIt
{
	internal static class BuildMenu
	{
		internal static readonly string[] Labels = new string[4] { "Misc.", "Hanging", "No Pot", "Potted" };

		internal static readonly string[] Tokens = new string[4] { "$plantit_misc", "$plantit_hanging", "$plantit_nopot", "$plantit_potted" };

		internal static readonly Dictionary<string, string> Groups = new Dictionary<string, string>(StringComparer.Ordinal);

		internal static bool Contains(Piece piece, string group)
		{
			if (Object.op_Implicit((Object)(object)piece) && Groups.TryGetValue(Utils.GetPrefabName(((Component)piece).gameObject), out var value))
			{
				return value == group;
			}
			return false;
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class AddPlantItGroups
	{
		private static void Postfix(ref UsageTagFlags[] ___m_usageTags, ref string[] ___m_usageTagDisplayNames)
		{
			string[] tokens = BuildMenu.Tokens;
			foreach (string text in tokens)
			{
				if (!___m_usageTagDisplayNames.Contains(text))
				{
					___m_usageTags = ___m_usageTags.Concat((IEnumerable<UsageTagFlags>)(object)new UsageTagFlags[1]).ToArray();
					___m_usageTagDisplayNames = ___m_usageTagDisplayNames.Concat(new string[1] { text }).ToArray();
				}
			}
		}
	}
	[HarmonyPatch(typeof(ByUsagePieceList), "GetTagDisplayName")]
	internal static class PlantItGroupLabels
	{
		private static void Postfix(ref string __result)
		{
			int num = Array.IndexOf(BuildMenu.Tokens, __result);
			if (num >= 0)
			{
				__result = BuildMenu.Labels[num];
			}
		}
	}
	[HarmonyPatch(typeof(ByUsagePieceList), "UpdateAvailableTags")]
	internal static class PlantItAvailableGroups
	{
		private static void Postfix(PieceTable pieceTable, string[] ___m_usageTagDisplayNames, List<int> ___m_availableTags)
		{
			int n;
			for (n = 0; n < BuildMenu.Tokens.Length; n++)
			{
				int num = Array.IndexOf(___m_usageTagDisplayNames, BuildMenu.Tokens[n]);
				if (num < 0)
				{
					continue;
				}
				if (pieceTable.m_availablePieces.Any((Piece p) => BuildMenu.Contains(p, BuildMenu.Labels[n])))
				{
					if (!___m_availableTags.Contains(num))
					{
						___m_availableTags.Add(num);
					}
				}
				else
				{
					___m_availableTags.Remove(num);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ByUsagePieceList), "GetAvailablePiecesWithTag")]
	internal static class PlantItGroupFilter
	{
		private static bool Prefix(int tagId, PieceTable pieceTable, IList<Piece> resultOut, string[] ___m_usageTagDisplayNames)
		{
			if (tagId < 0 || tagId >= ___m_usageTagDisplayNames.Length)
			{
				return true;
			}
			int num = Array.IndexOf(BuildMenu.Tokens, ___m_usageTagDisplayNames[tagId]);
			if (num < 0)
			{
				return true;
			}
			foreach (Piece availablePiece in pieceTable.m_availablePieces)
			{
				if (BuildMenu.Contains(availablePiece, BuildMenu.Labels[num]) || availablePiece.m_repairPiece || availablePiece.m_removePiece)
				{
					resultOut.Add(availablePiece);
				}
			}
			return false;
		}
	}
	internal static class CactusModel
	{
		private static Mesh mesh;

		private static Material[] materials;

		private static Vector3[] bindPositions;

		private static int[] parents;

		private static Sprite icon;

		internal static Sprite Icon()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			if (Materials.Headless)
			{
				return null;
			}
			if (Object.op_Implicit((Object)(object)icon))
			{
				return icon;
			}
			using Stream stream = typeof(CactusModel).Assembly.GetManifestResourceStream("PlantIt.cactus-icon.png");
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val, memoryStream.ToArray()))
			{
				throw new InvalidDataException("Invalid cactus icon");
			}
			icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			return icon;
		}

		private static Vector3 Vector(BinaryReader r)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
		}

		private static void Load()
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Expected O, but got Unknown
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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_01c7: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)mesh))
			{
				return;
			}
			using Stream input = typeof(CactusModel).Assembly.GetManifestResourceStream("PlantIt.cactus.bin");
			using BinaryReader binaryReader = new BinaryReader(input);
			if (binaryReader.ReadInt32() != 1346589745)
			{
				throw new InvalidDataException("Cactus mesh version");
			}
			int num = binaryReader.ReadInt32();
			parents = new int[num];
			bindPositions = (Vector3[])(object)new Vector3[num];
			Matrix4x4[] array = (Matrix4x4[])(object)new Matrix4x4[num];
			for (int i = 0; i < num; i++)
			{
				parents[i] = binaryReader.ReadInt32();
				bindPositions[i] = Vector(binaryReader);
				array[i] = Matrix4x4.Translate(-bindPositions[i]);
			}
			num = binaryReader.ReadInt32();
			materials = (Material[])(object)new Material[num];
			List<int>[] array2 = new List<int>[num];
			for (int j = 0; j < num; j++)
			{
				materials[j] = Materials.ColorMaterial(new Color(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()));
				array2[j] = new List<int>();
			}
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<BoneWeight> list3 = new List<BoneWeight>();
			int num2 = binaryReader.ReadInt32();
			for (int k = 0; k < num2; k++)
			{
				int num3 = binaryReader.ReadInt32();
				int num4 = binaryReader.ReadInt32();
				int num5 = binaryReader.ReadInt32();
				int count = list.Count;
				for (int l = 0; l < num4; l++)
				{
					list.Add(Vector(binaryReader));
					list2.Add(Vector(binaryReader));
					int boneIndex = binaryReader.ReadInt32();
					int boneIndex2 = binaryReader.ReadInt32();
					float num6 = binaryReader.ReadSingle();
					BoneWeight item = default(BoneWeight);
					((BoneWeight)(ref item)).boneIndex0 = boneIndex;
					((BoneWeight)(ref item)).boneIndex1 = boneIndex2;
					((BoneWeight)(ref item)).weight0 = num6;
					((BoneWeight)(ref item)).weight1 = 1f - num6;
					list3.Add(item);
				}
				for (int m = 0; m < num5; m++)
				{
					array2[num3].Add(binaryReader.ReadInt32() + count);
				}
			}
			mesh = new Mesh
			{
				name = "PlantIt original wiggling cactus",
				indexFormat = (IndexFormat)1
			};
			mesh.SetVertices(list);
			mesh.SetNormals(list2);
			mesh.boneWeights = list3.ToArray();
			mesh.bindposes = array;
			mesh.subMeshCount = materials.Length;
			for (int n = 0; n < array2.Length; n++)
			{
				mesh.SetTriangles(array2[n], n);
			}
			mesh.RecalculateBounds();
		}

		internal static void Build(GameObject prefab)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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)
			if (!Materials.Headless)
			{
				Load();
				GameObject val = new GameObject("PlantIt cactus model");
				val.transform.SetParent(prefab.transform, false);
				Transform[] array = (Transform[])(object)new Transform[parents.Length];
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = new GameObject("cactus bone " + i).transform;
					array[i].SetParent((parents[i] < 0) ? val.transform : array[parents[i]], false);
					array[i].localPosition = bindPositions[i] - ((parents[i] < 0) ? Vector3.zero : bindPositions[parents[i]]);
				}
				SkinnedMeshRenderer obj = val.AddComponent<SkinnedMeshRenderer>();
				obj.sharedMesh = mesh;
				((Renderer)obj).sharedMaterials = materials;
				obj.bones = array;
				obj.rootBone = array[0];
				obj.quality = (SkinQuality)2;
				((Renderer)obj).localBounds = new Bounds(new Vector3(0f, 1f, 0f), new Vector3(2.1f, 2.4f, 1.3f));
				obj.updateWhenOffscreen = false;
				val.layer = prefab.layer;
			}
		}
	}
	internal static class CactusMotion
	{
		internal const float EnterRadius = 4f;

		internal const float ExitRadius = 4.5f;

		internal static bool IsNear(float squaredDistance, bool active)
		{
			return squaredDistance <= (active ? 20.25f : 16f);
		}

		internal static float Blend(float current, bool active, float deltaTime)
		{
			float num = (active ? 1f : 0f);
			float num2 = Math.Max(0f, deltaTime) * 2.5f;
			if (!(current < num))
			{
				return Math.Max(num, current - num2);
			}
			return Math.Min(num, current + num2);
		}

		internal static float Angle(int bone, double phase, float amount)
		{
			return bone switch
			{
				1 => amount * 8f * (float)Math.Sin(phase), 
				2 => amount * -12f * (float)Math.Sin(phase - 0.7), 
				3 => amount * 8f * (float)Math.Sin(phase - 1.3), 
				4 => amount * 12f * (float)Math.Sin(phase + 0.6), 
				5 => amount * -12f * (float)Math.Sin(phase + 0.6), 
				_ => 0f, 
			};
		}
	}
	public sealed class CactusWiggle : MonoBehaviour
	{
		private Transform[] bones;

		private ZNetView view;

		private bool near;

		private float amount;

		private float nextScan;

		private void Start()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			if ((int)SystemInfo.graphicsDeviceType == 4)
			{
				((Behaviour)this).enabled = false;
				return;
			}
			view = ((Component)this).GetComponent<ZNetView>();
			SkinnedMeshRenderer componentInChildren = ((Component)this).GetComponentInChildren<SkinnedMeshRenderer>();
			if (!Object.op_Implicit((Object)(object)componentInChildren))
			{
				((Behaviour)this).enabled = false;
			}
			else
			{
				bones = componentInChildren.bones;
			}
		}

		private void Update()
		{
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			if (bones == null || !Object.op_Implicit((Object)(object)view) || !view.IsValid())
			{
				return;
			}
			if (Time.time >= nextScan)
			{
				nextScan = Time.time + 0.25f;
				bool flag = false;
				foreach (Player allPlayer in Player.GetAllPlayers())
				{
					if (Object.op_Implicit((Object)(object)allPlayer) && !((Character)allPlayer).IsDead())
					{
						Vector3 val = ((Component)allPlayer).transform.position - ((Component)this).transform.position;
						if (CactusMotion.IsNear(((Vector3)(ref val)).sqrMagnitude, near))
						{
							flag = true;
							break;
						}
					}
				}
				near = flag;
			}
			if (near || !(amount <= 0f))
			{
				amount = CactusMotion.Blend(amount, near, Time.deltaTime);
				double phase = (Object.op_Implicit((Object)(object)ZNet.instance) ? ZNet.instance.GetTimeSeconds() : ((double)Time.time)) * 3.9269908169872414;
				for (int i = 1; i < bones.Length; i++)
				{
					bones[i].localRotation = Quaternion.Euler(0f, 0f, CactusMotion.Angle(i, phase, amount));
				}
			}
		}

		private void OnDisable()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (bones != null)
			{
				for (int i = 1; i < bones.Length; i++)
				{
					if (Object.op_Implicit((Object)(object)bones[i]))
					{
						bones[i].localRotation = Quaternion.identity;
					}
				}
			}
			amount = 0f;
			near = false;
		}
	}
	internal static class Catalog
	{
		internal static readonly Entry[] Entries = new Entry[109]
		{
			new Entry("plantset4", "custompiece_fancypot", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_fancypotL", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_hangingpot_large", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_hangingpot_small", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_TCpot1", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_TCpot1L", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_TCpot2", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_TCpot2L", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_TCpot3", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_TCpot3L", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_TCpotrectangle", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_TCpotrectangleL", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_TCpotsquare", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_TCpotsquareL", "Misc.", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_vines3", "Hanging", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_vines4", "Hanging", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_vines5", "Hanging", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_vines6", "Hanging", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_vines7", "Hanging", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_vines8", "No Pot", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_vines9", "No Pot", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_vines10", "Hanging", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_vines11", "Hanging", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_vines12", "Hanging", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_vinesvanilla", "Hanging", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_vinesvanillabig", "Hanging", "Wood", 2, recover: true),
			new Entry("plantset4", "custompiece_vinesvanillastretched", "Hanging", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_birdofparadise", "Potted", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_bonsai", "Potted", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_coffeeplant", "Potted", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_fiddleleaf", "Potted", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_littlehouseplant", "Potted", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_orchid", "Potted", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_spikyplant", "Potted", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_umbrellapalm", "Potted", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_barrelcactus", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_cactus1", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_cactus1.2", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_cactus2", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_desertlily", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_desertmarigold", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_evergladespalm", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_hibiscusflower", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_ivorycanepalm", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_ladypalm", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_pricklypear", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantsetfixedcolliders", "custompiece_venusflytrap", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantset2", "custompiece_aeonium", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantset2", "custompiece_aloe", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantset2", "custompiece_bromeliad", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantset2", "custompiece_ivy1", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantset2", "custompiece_ivy1.2", "No Pot", "Wood", 2, recover: true),
			new Entry("custompiece_plantset2", "custompiece_rubberfig", "Potted", "Wood", 2, recover: true),
			new Entry("custompiece_plantset2", "custompiece_tallhouseplant", "Potted", "Wood", 2, recover: true),
			new Entry("custompiece_plantset2", "custompiece_vines1.2", "Hanging", "Wood", 2, recover: true),
			new Entry("custompiece_plantset2", "custompiece_vines1", "Hanging", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_aeoniums", "Potted", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_bamboo", "Potted", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_cattail", "No Pot", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_coolpot", "Potted", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_hangingplant", "Hanging", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_hangingplant1.2", "Hanging", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_kelp", "No Pot", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_kelpbig", "No Pot", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_miscplant1", "Potted", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_miscplant2", "Potted", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_orchid2", "Potted", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_pottedcactus1", "Potted", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_pottedcactus2", "Potted", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_rosevine", "No Pot", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_smallpottedplant", "Potted", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_tallflowerbush", "No Pot", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_vines2", "No Pot", "Wood", 2, recover: true),
			new Entry("plantset3", "custompiece_weirdflowers", "Potted", "Wood", 2, recover: true),
			new Entry("stumpsandlogs", "$custompiece_stump1", "Misc.", "Wood", 2, recover: true),
			new Entry("stumpsandlogs", "$custompiece_stump2", "Misc.", "Wood", 2, recover: true),
			new Entry("stumpsandlogs", "$custompiece_stump3", "Misc.", "Wood", 2, recover: true),
			new Entry("stumpsandlogs", "$custompiece_stump4", "Misc.", "Wood", 2, recover: true),
			new Entry("stumpsandlogs", "$custompiece_stump5", "Misc.", "Wood", 2, recover: true),
			new Entry("stumpsandlogs", "$custompiece_stump6", "Misc.", "Wood", 2, recover: true),
			new Entry("stumpsandlogs", "$custompiece_stump7", "Misc.", "Wood", 2, recover: true),
			new Entry("stumpsandlogs", "$custompiece_log1", "Misc.", "Wood", 5, recover: true),
			new Entry("stumpsandlogs", "$custompiece_log2", "Misc.", "Wood", 5, recover: true),
			new Entry("stumpsandlogs", "$custompiece_log3", "Misc.", "Wood", 5, recover: true),
			new Entry("stumpsandlogs", "$custompiece_log4", "Misc.", "Wood", 5, recover: true),
			new Entry("stumpsandlogs", "$custompiece_log5", "Misc.", "Wood", 5, recover: true),
			new Entry("stumpsandlogs", "$custompiece_stumptable", "Misc.", "Wood", 10, recover: true),
			new Entry("misc", "$custompiece_grassblock_small", "Misc.", "Wood", 2, recover: true),
			new Entry("misc", "$custompiece_grassblock_medium", "Misc.", "Wood", 5, recover: true),
			new Entry("misc", "$custompiece_grassblock_large", "Misc.", "Wood", 10, recover: true),
			new Entry("misc", "$custompiece_dirtblock_small", "Misc.", "Wood", 2, recover: true),
			new Entry("misc", "$custompiece_dirtblock_medium", "Misc.", "Wood", 5, recover: true),
			new Entry("misc", "$custompiece_dirtblock_large", "Misc.", "Wood", 10, recover: true),
			new Entry("misc", "$custompiece_blackpine", "No Pot", "Wood", 10, recover: true),
			new Entry("pottedsucculents", "$custompiece_s1_roundcactuspinkflowers", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s2_tallcactusredflower", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s3_pottedpricklypear", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s4_snakeplant", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s5_aloe", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s6_pachy", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s7_calisunset", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s8_towercactus", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s9_whiteflowers", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s10_fatboi", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s11_cLehmannii", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s12_splitrocks", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s13_roundcactusyellowflowers", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s14_roseaeonium", "Potted", "Wood", 2, recover: true),
			new Entry("pottedsucculents", "$custompiece_s15_euphorbia", "Potted", "Wood", 2, recover: true)
		};
	}
	internal sealed class Entry
	{
		internal readonly string Bundle;

		internal readonly string Prefab;

		internal readonly string Category;

		internal readonly string Item;

		internal readonly int Amount;

		internal readonly bool Recover;

		internal Entry(string bundle, string prefab, string category, string item, int amount, bool recover)
		{
			Bundle = bundle;
			Prefab = prefab;
			Category = category;
			Item = item;
			Amount = amount;
			Recover = recover;
		}
	}
	internal static class Materials
	{
		private static readonly Dictionary<int, Material> converted = new Dictionary<int, Material>();

		private static readonly Dictionary<string, Shader> shaders = new Dictionary<string, Shader>(StringComparer.Ordinal);

		private static Material surface;

		internal static bool Headless => (int)SystemInfo.graphicsDeviceType == 4;

		internal static void Prepare()
		{
			if (Headless)
			{
				return;
			}
			Shader[] array = Resources.FindObjectsOfTypeAll<Shader>();
			foreach (Shader val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && val.isSupported)
				{
					shaders[((Object)val).name] = val;
				}
			}
			surface = PrefabManager.Instance.GetPrefab("piece_chest_wood").GetComponentsInChildren<MeshRenderer>(true).SelectMany((MeshRenderer r) => ((Renderer)r).sharedMaterials)
				.First((Material m) => Object.op_Implicit((Object)(object)m) && Object.op_Implicit((Object)(object)m.shader) && m.shader.isSupported && ((Object)m.shader).name.StartsWith("Custom/"));
		}

		internal static void Apply(GameObject prefab)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_0089: 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_0098: Expected O, but got Unknown
			//IL_00ce: 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_0104: 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)
			if (Headless)
			{
				return;
			}
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				Material[] sharedMaterials = val.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val2 = sharedMaterials[j];
					if (!Object.op_Implicit((Object)(object)val2))
					{
						continue;
					}
					if (!converted.TryGetValue(((Object)val2).GetInstanceID(), out var value))
					{
						string key = (Object.op_Implicit((Object)(object)val2.shader) ? ((Object)val2.shader).name : "");
						if (shaders.TryGetValue(key, out var value2))
						{
							value = new Material(val2)
							{
								shader = value2
							};
						}
						else
						{
							value = new Material(surface);
							if (val2.HasProperty("_MainTex"))
							{
								value.mainTexture = val2.GetTexture("_MainTex");
							}
							value.mainTextureScale = val2.mainTextureScale;
							value.mainTextureOffset = val2.mainTextureOffset;
							value.color = (val2.HasProperty("_Color") ? val2.GetColor("_Color") : Color.white);
							string[] array = new string[2] { "_BumpMap", "_Cutoff" };
							foreach (string text in array)
							{
								if (value.HasProperty(text) && val2.HasProperty(text))
								{
									if (text == "_BumpMap")
									{
										value.SetTexture(text, val2.GetTexture(text));
									}
									else
									{
										value.SetFloat(text, val2.GetFloat(text));
									}
								}
							}
							if (value.HasProperty("_Cull"))
							{
								value.SetFloat("_Cull", 0f);
							}
							if (value.HasProperty("_Cutoff"))
							{
								value.SetFloat("_Cutoff", val2.HasProperty("_Cutoff") ? val2.GetFloat("_Cutoff") : 0.5f);
							}
							value.EnableKeyword("_ALPHATEST_ON");
						}
						((Object)value).name = ((Object)val2).name + " [PlantIt current shader]";
						converted.Add(((Object)val2).GetInstanceID(), value);
					}
					sharedMaterials[j] = value;
				}
				val.sharedMaterials = sharedMaterials;
			}
		}

		internal static Material ColorMaterial(Color color)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(surface)
			{
				name = "PlantIt cactus",
				color = color,
				mainTexture = (Texture)(object)Texture2D.whiteTexture
			};
			val.mainTextureScale = Vector2.one;
			val.mainTextureOffset = Vector2.zero;
			string[] array = new string[3] { "_BumpMap", "_MetallicGlossMap", "_EmissionMap" };
			foreach (string text in array)
			{
				if (val.HasProperty(text))
				{
					val.SetTexture(text, (Texture)null);
				}
			}
			array = new string[5] { "_Glossiness", "_Metallic", "_MetalGloss", "_AddSnow", "_NoiseGlowEnabled" };
			foreach (string text2 in array)
			{
				if (val.HasProperty(text2))
				{
					val.SetFloat(text2, 0f);
				}
			}
			if (val.HasProperty("_MoveableObject"))
			{
				val.SetFloat("_MoveableObject", 1f);
			}
			array = new string[3] { "_EmissionColor", "_EmissiveColor", "_NoiseGlowColor" };
			foreach (string text3 in array)
			{
				if (val.HasProperty(text3))
				{
					val.SetColor(text3, Color.black);
				}
			}
			val.DisableKeyword("_EMISSION");
			val.DisableKeyword("NOISEGLOW");
			return val;
		}
	}
	[BepInPlugin("com.jotunn.PlantIt", "PlantIt — Continuation", "0.2.1")]
	[BepInDependency("com.jotunn.jotunn", "2.30.0")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "com.jotunn.PlantIt";

		public const string Version = "0.2.1";

		internal const string TableName = "_PlantitPieceTable";

		internal const string CactusName = "PlantIt_WigglingCactus";

		private Harmony harmony;

		private bool attempted;

		private Transform templates;

		private readonly Dictionary<string, AssetBundle> bundles = new Dictionary<string, AssetBundle>();

		private void Awake()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			using (Stream stream = ((object)this).GetType().Assembly.GetManifestResourceStream("PlantIt.English.json"))
			{
				using StreamReader streamReader = new StreamReader(stream);
				LocalizationManager.Instance.GetLocalization().AddJsonFile("English", streamReader.ReadToEnd());
			}
			harmony = new Harmony("com.jotunn.PlantIt");
			harmony.PatchAll();
			PrefabManager.OnVanillaPrefabsAvailable += Register;
		}

		private void OnDestroy()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= Register;
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			foreach (AssetBundle value in bundles.Values)
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					value.Unload(false);
				}
			}
		}

		private AssetBundle Bundle(string name)
		{
			if (!bundles.TryGetValue(name, out var value))
			{
				value = AssetUtils.LoadAssetBundleFromResources(name, ((object)this).GetType().Assembly);
				if (!Object.op_Implicit((Object)(object)value))
				{
					throw new InvalidOperationException("Cannot load PlantIt asset bundle: " + name);
				}
				bundles.Add(name, value);
			}
			return value;
		}

		private void Register()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Expected O, but got Unknown
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Expected O, but got Unknown
			if (attempted)
			{
				return;
			}
			attempted = true;
			PrefabManager.OnVanillaPrefabsAvailable -= Register;
			try
			{
				GameObject val = new GameObject("PlantIt inactive templates");
				val.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)val);
				templates = val.transform;
				Materials.Prepare();
				CustomPieceTable val2 = new CustomPieceTable("_PlantitPieceTable", new PieceTableConfig
				{
					UseCategories = false,
					CanRemovePieces = true
				});
				val2.PieceTable.m_hideAdvancedMenu = false;
				if (!PieceManager.Instance.AddPieceTable(val2))
				{
					throw new InvalidOperationException("Cannot register PlantIt shovel menu.");
				}
				RegisterShovel(val2.PieceTable);
				int num = 0;
				Entry[] entries = Catalog.Entries;
				foreach (Entry entry in entries)
				{
					GameObject val3 = Bundle(entry.Bundle).LoadAsset<GameObject>(entry.Prefab);
					if (!Object.op_Implicit((Object)(object)val3))
					{
						throw new InvalidOperationException("Missing original prefab: " + entry.Prefab);
					}
					GameObject val4 = Clone(entry.Prefab, val3);
					Materials.Apply(val4);
					Piece component = val4.GetComponent<Piece>();
					if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)val4.GetComponent<ZNetView>()))
					{
						throw new InvalidOperationException("Incomplete original prefab: " + entry.Prefab);
					}
					component.m_category = (PieceCategory)0;
					PieceConfig val5 = new PieceConfig();
					val5.PieceTable = "_PlantitPieceTable";
					val5.AllowedInDungeons = false;
					val5.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
					{
						new RequirementConfig(entry.Item, entry.Amount, 0, entry.Recover)
					};
					PieceConfig val6 = val5;
					if (!PieceManager.Instance.AddPiece(new CustomPiece(val4, true, val6)))
					{
						throw new InvalidOperationException("Cannot register " + entry.Prefab);
					}
					BuildMenu.Groups.Add(((Object)val4).name, entry.Category);
					num++;
				}
				RegisterCactus();
				((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("PlantIt Continuation {0}: registered {1} original decorations, original shovel and Wiggling Cactus.", "0.2.1", num));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("PlantIt registration failed; do not save an existing PlantIt world until this is resolved. " + ex));
			}
		}

		private GameObject Clone(string name, GameObject source)
		{
			if (!Object.op_Implicit((Object)(object)source))
			{
				throw new InvalidOperationException("Missing template for " + name);
			}
			GameObject obj = Object.Instantiate<GameObject>(source, templates, false);
			((Object)obj).name = name;
			return obj;
		}

		private void RegisterShovel(PieceTable table)
		{
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Expected O, but got Unknown
			GameObject val = Bundle("shovel").LoadAsset<GameObject>("$PlumgaPlantItShovel");
			if (!Object.op_Implicit((Object)(object)val))
			{
				throw new InvalidOperationException("Original PlantIt shovel missing.");
			}
			GameObject val2 = Clone("$PlumgaPlantItShovel", PrefabManager.Instance.GetPrefab("Cultivator"));
			Transform val3 = val2.transform.Find("attach");
			if (Object.op_Implicit((Object)(object)val3))
			{
				Object.DestroyImmediate((Object)(object)((Component)val3).gameObject);
			}
			Transform obj = val.transform.Find("attach");
			if (!Object.op_Implicit((Object)(object)obj))
			{
				throw new InvalidOperationException("Original shovel attach model missing.");
			}
			((Object)Object.Instantiate<GameObject>(((Component)obj).gameObject, val2.transform, false)).name = "attach";
			Materials.Apply(val2);
			SharedData shared = val2.GetComponent<ItemDrop>().m_itemData.m_shared;
			shared.m_name = "$PlumgaPlantItShovel";
			shared.m_description = "$PlumgaPlantItShovelDescrip";
			shared.m_icons = val.GetComponent<ItemDrop>().m_itemData.m_shared.m_icons;
			shared.m_buildPieces = table;
			ItemConfig val4 = new ItemConfig();
			val4.Amount = 1;
			val4.CraftingStation = "piece_workbench";
			val4.RepairStation = "piece_workbench";
			val4.MinStationLevel = 1;
			val4.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
			{
				new RequirementConfig("Wood", 1, 1, true)
			};
			ItemConfig val5 = val4;
			if (!ItemManager.Instance.AddItem(new CustomItem(val2, false, val5)))
			{
				throw new InvalidOperationException("Cannot register original PlantIt shovel.");
			}
		}

		private void RegisterCactus()
		{
			//IL_00b8: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Expected O, but got Unknown
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Expected O, but got Unknown
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Expected O, but got Unknown
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Expected O, but got Unknown
			GameObject val = Clone("PlantIt_WigglingCactus", PrefabManager.Instance.GetPrefab("jute_carpet"));
			Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			MeshFilter[] componentsInChildren2 = val.GetComponentsInChildren<MeshFilter>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			Collider[] componentsInChildren3 = val.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
			}
			LODGroup[] componentsInChildren4 = val.GetComponentsInChildren<LODGroup>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren4[i]);
			}
			CactusModel.Build(val);
			BoxCollider obj = val.AddComponent<BoxCollider>();
			obj.center = new Vector3(0f, 0.31f, 0f);
			obj.size = new Vector3(0.64f, 0.62f, 0.64f);
			CapsuleCollider obj2 = val.AddComponent<CapsuleCollider>();
			obj2.center = new Vector3(0f, 1.19f, 0f);
			obj2.height = 1.22f;
			obj2.radius = 0.23f;
			Piece component = val.GetComponent<Piece>();
			component.m_category = (PieceCategory)0;
			component.m_groundOnly = false;
			component.m_comfort = 0;
			component.m_groundPiece = false;
			component.m_waterPiece = false;
			component.m_noInWater = false;
			WearNTear component2 = val.GetComponent<WearNTear>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.m_noSupportWear = true;
				component2.m_noRoofWear = true;
				Transform val2 = val.transform.Find("PlantIt cactus model");
				component2.m_new = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).gameObject : null);
				component2.m_worn = null;
				component2.m_broken = null;
				component2.m_health = 100f;
			}
			val.AddComponent<CactusWiggle>();
			PieceManager instance = PieceManager.Instance;
			PieceConfig val3 = new PieceConfig();
			val3.Name = "Wiggling Cactus";
			val3.Description = "A cheerful cactus that dances when a Viking comes close.";
			val3.Icon = CactusModel.Icon();
			val3.PieceTable = "_PlantitPieceTable";
			val3.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				new RequirementConfig("Wood", 2, 0, true),
				new RequirementConfig("AncientSeed", 1, 0, true)
			};
			if (!instance.AddPiece(new CustomPiece(val, false, val3)))
			{
				throw new InvalidOperationException("Cannot register Wiggling Cactus.");
			}
			BuildMenu.Groups.Add(((Object)val).name, "Potted");
		}
	}
}