Decompiled source of YggdrasilSeeds v1.0.2

plugins\YggdrasilSeeds.dll

Decompiled 2 hours 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.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("YggdrasilSeeds")]
[assembly: AssemblyDescription("Adds harvestable Yggdrasil seeds that can be planted with a cultivator.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Detromental")]
[assembly: AssemblyProduct("YggdrasilSeeds")]
[assembly: AssemblyCopyright("Copyright © Detromental 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
namespace YggdrasilSeeds;

internal class RandomYggdrasilShootVisual : MonoBehaviour
{
	private static List<GameObject> cleanShootTemplates;

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

	private static readonly int VisualIndexHash = StringExtensionMethods.GetStableHashCode("YggdrasilShootVisualIndex");

	private void Awake()
	{
		Plant component = ((Component)this).GetComponent<Plant>();
		Transform val = ((Component)this).transform.Find("YggdrasilShootVisual");
		Transform val2 = ((Component)this).transform.Find("YggdrasilShootUnhealthyVisual");
		if ((Object)(object)component != (Object)null && (Object)(object)val != (Object)null)
		{
			component.m_healthy = ((Component)val).gameObject;
			component.m_unhealthy = (((Object)(object)val2 != (Object)null) ? ((Component)val2).gameObject : ((Component)val).gameObject);
		}
	}

	private void Start()
	{
		EnsureTemplatesBuilt();
		if (cleanShootTemplates == null || cleanShootTemplates.Count == 0)
		{
			return;
		}
		ZNetView component = ((Component)this).GetComponent<ZNetView>();
		if ((Object)(object)component == (Object)null || !component.IsValid())
		{
			return;
		}
		ZDO zDO = component.GetZDO();
		int num = zDO.GetInt(VisualIndexHash, -1);
		if (num < 0 || num >= cleanShootTemplates.Count)
		{
			num = Random.Range(0, cleanShootTemplates.Count);
			if (component.IsOwner())
			{
				zDO.Set(VisualIndexHash, num, false);
			}
		}
		if (num != 0 || !((Object)(object)((Component)this).transform.Find("YggdrasilShootVisual") != (Object)null))
		{
			ApplyCleanTemplate(((Component)this).transform, cleanShootTemplates[num]);
		}
	}

	internal static void EnsureTemplatesBuilt()
	{
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		if (cleanShootTemplates != null && cleanShootTemplates.Count > 0)
		{
			return;
		}
		cleanShootTemplates = new List<GameObject>();
		List<GameObject> list = new List<GameObject>();
		string[] smallShootVisualPrefabs = YggdrasilSeeds.SmallShootVisualPrefabs;
		foreach (string text in smallShootVisualPrefabs)
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab(text);
			if ((Object)(object)prefab != (Object)null && (Object)(object)prefab.GetComponentInChildren<MeshRenderer>(true) != (Object)null && !list.Contains(prefab))
			{
				list.Add(prefab);
			}
		}
		if (list.Count == 0)
		{
			smallShootVisualPrefabs = new string[5] { "Beech_Sapling", "sapling_beech", "Fir_Sapling", "Pine_Sapling", "Birch_Sapling" };
			foreach (string text2 in smallShootVisualPrefabs)
			{
				GameObject prefab2 = PrefabManager.Instance.GetPrefab(text2);
				if ((Object)(object)prefab2 != (Object)null && (Object)(object)prefab2.GetComponentInChildren<MeshRenderer>(true) != (Object)null && !list.Contains(prefab2))
				{
					list.Add(prefab2);
				}
			}
		}
		foreach (GameObject item in list)
		{
			bool activeSelf = item.activeSelf;
			item.SetActive(false);
			GameObject val = Object.Instantiate<GameObject>(item);
			item.SetActive(activeSelf);
			((Object)val).name = ((Object)item).name + "_CleanVisualTemplate";
			Object.DontDestroyOnLoad((Object)(object)val);
			Collider[] componentsInChildren = val.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			Destructible[] componentsInChildren2 = val.GetComponentsInChildren<Destructible>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			TreeBase[] componentsInChildren3 = val.GetComponentsInChildren<TreeBase>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
			}
			ZNetView[] componentsInChildren4 = val.GetComponentsInChildren<ZNetView>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren4[i]);
			}
			LodFadeInOut[] componentsInChildren5 = val.GetComponentsInChildren<LodFadeInOut>(true);
			for (int i = 0; i < componentsInChildren5.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren5[i]);
			}
			LODGroup[] componentsInChildren6 = val.GetComponentsInChildren<LODGroup>(true);
			for (int i = 0; i < componentsInChildren6.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren6[i]);
			}
			Plant[] componentsInChildren7 = val.GetComponentsInChildren<Plant>(true);
			for (int i = 0; i < componentsInChildren7.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren7[i]);
			}
			Piece[] componentsInChildren8 = val.GetComponentsInChildren<Piece>(true);
			for (int i = 0; i < componentsInChildren8.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren8[i]);
			}
			Transform[] componentsInChildren9 = val.GetComponentsInChildren<Transform>(true);
			foreach (Transform val2 in componentsInChildren9)
			{
				((Component)val2).gameObject.SetActive(true);
				if ((Object)(object)val2 != (Object)(object)val.transform && val2.localPosition.y > 2f)
				{
					val2.localPosition = new Vector3(val2.localPosition.x, 0f, val2.localPosition.z);
				}
			}
			val.SetActive(false);
			cleanShootTemplates.Add(val);
		}
	}

	internal static void ApplyInitialVisual(Transform prefabRoot)
	{
		EnsureTemplatesBuilt();
		if (cleanShootTemplates != null && cleanShootTemplates.Count > 0)
		{
			ApplyCleanTemplate(prefabRoot, cleanShootTemplates[0]);
		}
	}

	private static void ApplyCleanTemplate(Transform root, GameObject cleanTemplate)
	{
		if (!((Object)(object)root == (Object)null) && !((Object)(object)cleanTemplate == (Object)null))
		{
			Plant component = ((Component)root).GetComponent<Plant>();
			if ((Object)(object)component != (Object)null)
			{
				component.m_healthy = null;
				component.m_unhealthy = null;
			}
			RemoveOldChild(root, "YggdrasilShootVisual");
			RemoveOldChild(root, "YggdrasilShootUnhealthyVisual");
			GameObject healthy = InstantiateVisualInstance(root, cleanTemplate, "YggdrasilShootVisual", 1f, applyWiltedTint: false);
			GameObject val = InstantiateVisualInstance(root, cleanTemplate, "YggdrasilShootUnhealthyVisual", 0.65f, applyWiltedTint: true);
			val.SetActive(false);
			if ((Object)(object)component != (Object)null)
			{
				component.m_healthy = healthy;
				component.m_unhealthy = val;
			}
		}
	}

	private static void RemoveOldChild(Transform root, string childName)
	{
		Transform val = root.Find(childName);
		if ((Object)(object)val != (Object)null)
		{
			((Component)val).gameObject.SetActive(false);
			Object.Destroy((Object)(object)((Component)val).gameObject);
		}
	}

	private static Material GetSharedWiltedMaterial(Material original)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)original == (Object)null)
		{
			return null;
		}
		if (!wiltedMaterialCache.TryGetValue(original, out var value) || (Object)(object)value == (Object)null)
		{
			value = new Material(original);
			value.color = new Color(0.65f, 0.52f, 0.25f, 1f);
			wiltedMaterialCache[original] = value;
		}
		return value;
	}

	private static GameObject InstantiateVisualInstance(Transform root, GameObject cleanTemplate, string objName, float scaleMultiplier, bool applyWiltedTint)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: 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)
		GameObject val = Object.Instantiate<GameObject>(cleanTemplate, root);
		((Object)val).name = objName;
		val.transform.localPosition = Vector3.zero;
		val.transform.localRotation = Quaternion.identity;
		val.transform.localScale = Vector3.one * scaleMultiplier;
		MeshRenderer[] componentsInChildren = val.GetComponentsInChildren<MeshRenderer>(true);
		foreach (MeshRenderer val2 in componentsInChildren)
		{
			((Renderer)val2).enabled = true;
			if (applyWiltedTint && (Object)(object)((Renderer)val2).sharedMaterial != (Object)null)
			{
				((Renderer)val2).sharedMaterial = GetSharedWiltedMaterial(((Renderer)val2).sharedMaterial);
			}
		}
		val.SetActive(true);
		return val;
	}
}
[BepInPlugin("Detromental.YggdrasilSeeds", "YggdrasilSeeds", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class YggdrasilSeeds : BaseUnityPlugin
{
	public const string PluginGUID = "Detromental.YggdrasilSeeds";

	public const string PluginName = "YggdrasilSeeds";

	public const string PluginVersion = "1.0.2";

	private ConfigEntry<float> seedDropChancePercent;

	private ConfigEntry<int> minSeedsDropped;

	private ConfigEntry<int> maxSeedsDropped;

	private ConfigEntry<float> growTimeSeconds;

	private ConfigEntry<float> growRadius;

	internal static readonly string[] SmallShootVisualPrefabs = new string[3] { "YggaShoot_small1", "YggaShoot_small2", "YggaShoot_small3" };

	private static readonly string[] FullGrownYggdrasilTrees = new string[3] { "YggaShoot1", "YggaShoot2", "YggaShoot3" };

	private GameObject seedPrefab;

	private GameObject saplingPrefab;

	private bool treeDropsRegistered;

	private void Awake()
	{
		CreateConfigs();
		AddLocalizations();
		PrefabManager.OnVanillaPrefabsAvailable += RegisterCustomSeedAndSapling;
		PrefabManager.OnPrefabsRegistered += ConfigureYggdrasilTreeDrops;
	}

	private void CreateConfigs()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Expected O, but got Unknown
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Expected O, but got Unknown
		seedDropChancePercent = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Drops", "SeedDropChancePercent", 35f, new ConfigDescription("Percentage chance (0 to 100) for a felled Yggdrasil tree to drop Yggdrasil seeds on initial chop.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
		minSeedsDropped = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Drops", "MinSeedsDropped", 1, new ConfigDescription("Minimum number of Yggdrasil seeds dropped when a seed drop occurs.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50), Array.Empty<object>()));
		maxSeedsDropped = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Drops", "MaxSeedsDropped", 2, new ConfigDescription("Maximum number of Yggdrasil seeds dropped when a seed drop occurs.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50), Array.Empty<object>()));
		growTimeSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Growth", "GrowTimeSeconds", 4000f, new ConfigDescription("Time in seconds for a planted Yggdrasil shoot to grow into a full Yggdrasil tree.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 86400f), Array.Empty<object>()));
		growRadius = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Growth", "GrowRadius", 5.5f, new ConfigDescription("Clearance radius in meters around the sapling so wide Yggdrasil canopies do not block neighboring shoots (also controls PlantEasily grid spacing).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 15f), Array.Empty<object>()));
	}

	private void AddLocalizations()
	{
		CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
		string text = "English";
		localization.AddTranslation(ref text, new Dictionary<string, string>
		{
			{ "item_yggdrasil_seed", "Yggdrasil seed" },
			{ "item_yggdrasil_seed_desc", "A radiant seed fallen from the World Tree, pulsing with ancient vitality. Plant it with a cultivator." },
			{ "piece_yggdrasil_sapling", "Yggdrasil shoot" },
			{ "piece_yggdrasil_sapling_desc", "A young sprout of Yggdrasil that will grow into a towering tree in any biome." }
		});
	}

	private Sprite LoadEmbeddedSeedSprite()
	{
		try
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string r) => r.EndsWith("yggdrasil_seed.png", StringComparison.OrdinalIgnoreCase));
			if (!string.IsNullOrEmpty(text))
			{
				using Stream stream = executingAssembly.GetManifestResourceStream(text);
				if (stream != null)
				{
					string text2 = Path.Combine(Path.GetTempPath(), "yggdrasil_seed_icon.png");
					using (FileStream destination = File.Create(text2))
					{
						stream.CopyTo(destination);
					}
					Sprite val = AssetUtils.LoadSpriteFromFile(text2);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
			}
		}
		catch (Exception ex)
		{
			Logger.LogWarning((object)("Failed loading custom seed icon, using fallback: " + ex.Message));
		}
		GameObject prefab = PrefabManager.Instance.GetPrefab("BeechSeeds");
		if (prefab == null)
		{
			return null;
		}
		ItemDrop component = prefab.GetComponent<ItemDrop>();
		if (component == null)
		{
			return null;
		}
		ItemData itemData = component.m_itemData;
		if (itemData == null)
		{
			return null;
		}
		return itemData.GetIcon();
	}

	private void CustomizeSeedGroundModel(GameObject itemPrefab)
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Expected O, but got Unknown
		//IL_0084: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: 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)
		//IL_01fc: 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_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Expected O, but got Unknown
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Expected O, but got Unknown
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		Material val = null;
		MeshRenderer[] componentsInChildren = itemPrefab.GetComponentsInChildren<MeshRenderer>(true);
		foreach (MeshRenderer val2 in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null && (Object)(object)((Renderer)val2).sharedMaterial != (Object)null)
			{
				val = ((Renderer)val2).sharedMaterial;
			}
			((Component)val2).gameObject.SetActive(false);
		}
		GameObject val3 = new GameObject("YggdrasilSeedPodVisual");
		val3.transform.SetParent(itemPrefab.transform, false);
		val3.transform.localPosition = new Vector3(0f, 0.08f, 0f);
		val3.transform.localRotation = Quaternion.Euler(82f, 0f, 15f);
		GameObject val4 = CreateSeedPart(val3.transform, "SeedCore", Vector3.zero, Vector3.zero, new Vector3(0.11f, 0.21f, 0.11f), 0.55f);
		MeshRenderer component = val4.GetComponent<MeshRenderer>();
		if ((Object)(object)component != (Object)null && (Object)(object)val != (Object)null)
		{
			Material val5 = new Material(val);
			val5.color = Color.white;
			if (val5.HasProperty("_EmissionColor"))
			{
				val5.EnableKeyword("_EMISSION");
				val5.SetColor("_EmissionColor", new Color(0.55f, 0.48f, 0.35f, 1f));
			}
			((Renderer)component).sharedMaterial = val5;
			val4.AddComponent<SwirlingSeedMist>();
		}
		Texture2D mainTexture = CreateBarkTexture();
		Material val6 = null;
		if ((Object)(object)val != (Object)null)
		{
			val6 = new Material(val);
			val6.mainTexture = (Texture)(object)mainTexture;
			val6.color = new Color(0.75f, 0.58f, 0.44f, 1f);
			if (val6.HasProperty("_EmissionColor"))
			{
				val6.DisableKeyword("_EMISSION");
				val6.SetColor("_EmissionColor", Color.black);
			}
		}
		GameObject val7 = CreateSeedPart(val3.transform, "BarkHuskLeft", new Vector3(-0.028f, 0f, -0.008f), new Vector3(0f, 0f, 12f), new Vector3(0.095f, 0.24f, 0.125f), 0.52f);
		GameObject val8 = CreateSeedPart(val3.transform, "BarkHuskRight", new Vector3(0.028f, 0f, -0.008f), new Vector3(0f, 0f, -12f), new Vector3(0.095f, 0.24f, 0.125f), 0.52f);
		if ((Object)(object)val6 != (Object)null)
		{
			((Renderer)val7.GetComponent<MeshRenderer>()).sharedMaterial = val6;
			((Renderer)val8.GetComponent<MeshRenderer>()).sharedMaterial = val6;
		}
	}

	private GameObject CreateSeedPart(Transform parent, string partName, Vector3 localPos, Vector3 localEuler, Vector3 localScale, float tipTaper)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: 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)
		GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
		((Object)val).name = partName;
		val.transform.SetParent(parent, false);
		val.transform.localPosition = localPos;
		val.transform.localRotation = Quaternion.Euler(localEuler);
		val.transform.localScale = localScale;
		Collider component = val.GetComponent<Collider>();
		if ((Object)(object)component != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)component);
		}
		MeshFilter component2 = val.GetComponent<MeshFilter>();
		if ((Object)(object)component2 != (Object)null && (Object)(object)component2.sharedMesh != (Object)null)
		{
			Mesh val2 = Object.Instantiate<Mesh>(component2.sharedMesh);
			Vector3[] vertices = val2.vertices;
			for (int i = 0; i < vertices.Length; i++)
			{
				float y = vertices[i].y;
				float num = ((y > 0f) ? Mathf.Lerp(1f, tipTaper, y * 2f) : Mathf.Lerp(1f, 0.85f, (0f - y) * 2f));
				vertices[i].x *= num;
				vertices[i].z *= num;
			}
			val2.vertices = vertices;
			val2.RecalculateNormals();
			val2.RecalculateBounds();
			component2.sharedMesh = val2;
		}
		return val;
	}

	private Texture2D CreateBarkTexture()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false);
		for (int i = 0; i < 32; i++)
		{
			for (int j = 0; j < 32; j++)
			{
				float num = Mathf.Sin((float)j * 0.95f + Mathf.Sin((float)i * 0.35f) * 1.6f) * 0.5f + 0.5f;
				Color val2 = Color.Lerp(new Color(0.32f, 0.21f, 0.13f), new Color(0.58f, 0.4f, 0.26f), num);
				val.SetPixel(j, i, val2);
			}
		}
		val.Apply();
		return val;
	}

	private List<GameObject> FindFullGrownYggdrasilTrees()
	{
		List<GameObject> list = new List<GameObject>();
		string[] fullGrownYggdrasilTrees = FullGrownYggdrasilTrees;
		foreach (string text in fullGrownYggdrasilTrees)
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab(text);
			if ((Object)(object)prefab != (Object)null && !list.Contains(prefab))
			{
				list.Add(prefab);
			}
		}
		return list;
	}

	private void RegisterCustomSeedAndSapling()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Expected O, but got Unknown
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Expected O, but got Unknown
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0287: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Expected O, but got Unknown
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Expected O, but got Unknown
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Expected O, but got Unknown
		try
		{
			Sprite val = LoadEmbeddedSeedSprite();
			ItemConfig val2 = new ItemConfig();
			val2.Name = "$item_yggdrasil_seed";
			val2.Description = "$item_yggdrasil_seed_desc";
			val2.Icons = (Sprite[])((!((Object)(object)val != (Object)null)) ? ((Array)Array.Empty<Sprite>()) : ((Array)new Sprite[1] { val }));
			val2.StackSize = 100;
			val2.Weight = 0.1f;
			ItemConfig val3 = val2;
			CustomItem val4 = new CustomItem("YggdrasilSeed", "BeechSeeds", val3);
			seedPrefab = val4.ItemPrefab;
			CustomizeSeedGroundModel(seedPrefab);
			ItemManager.Instance.AddItem(val4);
			saplingPrefab = PrefabManager.Instance.CreateClonedPrefab("sapling_yggdrasil", "Beech_Sapling");
			foreach (Transform item in saplingPrefab.transform)
			{
				((Component)item).gameObject.SetActive(false);
			}
			Piece val5 = saplingPrefab.GetComponent<Piece>();
			if ((Object)(object)val5 == (Object)null)
			{
				val5 = saplingPrefab.AddComponent<Piece>();
			}
			val5.m_name = "$piece_yggdrasil_sapling";
			val5.m_description = "$piece_yggdrasil_sapling_desc";
			val5.m_icon = val;
			val5.m_groundOnly = true;
			val5.m_groundPiece = true;
			val5.m_cultivatedGroundOnly = false;
			val5.m_canBeRemoved = true;
			Plant val6 = saplingPrefab.GetComponent<Plant>();
			if ((Object)(object)val6 == (Object)null)
			{
				val6 = saplingPrefab.AddComponent<Plant>();
			}
			val6.m_name = "$piece_yggdrasil_sapling";
			val6.m_biome = (Biome)895;
			val6.m_growTime = growTimeSeconds.Value;
			val6.m_growTimeMax = growTimeSeconds.Value;
			val6.m_growRadius = growRadius.Value;
			val6.m_needCultivatedGround = false;
			val6.m_destroyIfCantGrow = false;
			val6.m_minScale = 0.85f;
			val6.m_maxScale = 1.15f;
			List<GameObject> list = FindFullGrownYggdrasilTrees();
			if (list.Count > 0)
			{
				val6.m_grownPrefabs = list.ToArray();
				Logger.LogInfo((object)string.Format("Pre-assigned grown Yggdrasil trees ({0}): [{1}]", list.Count, string.Join(", ", list.Select((GameObject t) => ((Object)t).name))));
			}
			RandomYggdrasilShootVisual.ApplyInitialVisual(saplingPrefab.transform);
			if ((Object)(object)saplingPrefab.GetComponent<RandomYggdrasilShootVisual>() == (Object)null)
			{
				saplingPrefab.AddComponent<RandomYggdrasilShootVisual>();
			}
			PieceConfig val7 = new PieceConfig();
			val7.Name = "$piece_yggdrasil_sapling";
			val7.Description = "$piece_yggdrasil_sapling_desc";
			val7.PieceTable = "Cultivator";
			val7.Category = "Misc";
			val7.AllowedInDungeons = false;
			val7.Icon = val;
			val7.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
			{
				new RequirementConfig
				{
					Item = "YggdrasilSeed",
					Amount = 1,
					Recover = true
				}
			};
			PieceConfig val8 = val7;
			PieceManager.Instance.AddPiece(new CustomPiece(saplingPrefab, false, val8));
			Logger.LogInfo((object)"Successfully registered YggdrasilSeed and sapling_yggdrasil!");
		}
		catch (Exception arg)
		{
			Logger.LogError((object)$"Error registering Yggdrasil seed/sapling: {arg}");
		}
		finally
		{
			PrefabManager.OnVanillaPrefabsAvailable -= RegisterCustomSeedAndSapling;
		}
	}

	private void ConfigureYggdrasilTreeDrops()
	{
		if (treeDropsRegistered || (Object)(object)seedPrefab == (Object)null)
		{
			return;
		}
		float dropWeight = Mathf.Clamp01(seedDropChancePercent.Value / 100f);
		int num = Mathf.Max(1, minSeedsDropped.Value);
		int maxDrop = Mathf.Max(num, maxSeedsDropped.Value);
		List<GameObject> list = FindFullGrownYggdrasilTrees();
		foreach (GameObject item in list)
		{
			TreeBase component = item.GetComponent<TreeBase>();
			if ((Object)(object)component != (Object)null && component.m_dropWhenDestroyed != null)
			{
				component.m_dropWhenDestroyed.m_dropChance = 1f;
				component.m_dropWhenDestroyed.m_oneOfEach = true;
				AddSeedToDropTable(component.m_dropWhenDestroyed, dropWeight, num, maxDrop);
			}
		}
		if ((Object)(object)saplingPrefab != (Object)null)
		{
			Plant component2 = saplingPrefab.GetComponent<Plant>();
			if ((Object)(object)component2 != (Object)null && (component2.m_grownPrefabs == null || component2.m_grownPrefabs.Length == 0) && list.Count > 0)
			{
				component2.m_grownPrefabs = list.ToArray();
			}
		}
		treeDropsRegistered = true;
		PrefabManager.OnPrefabsRegistered -= ConfigureYggdrasilTreeDrops;
	}

	private void AddSeedToDropTable(DropTable dropTable, float dropWeight, int minDrop, int maxDrop)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		if (dropTable != null && !((Object)(object)seedPrefab == (Object)null) && !(dropWeight <= 0f) && !dropTable.m_drops.Any((DropData d) => (Object)(object)d.m_item == (Object)(object)seedPrefab))
		{
			dropTable.m_drops.Add(new DropData
			{
				m_item = seedPrefab,
				m_stackMin = minDrop,
				m_stackMax = maxDrop,
				m_weight = dropWeight,
				m_dontScale = false
			});
		}
	}
}
internal class SwirlingSeedMist : MonoBehaviour
{
	private static Texture2D sharedSwirlTex;

	private static Color[] pixelBuffer;

	private static float lastUpdateTime = -1f;

	private const float UpdateInterval = 0.066f;

	private static readonly Color GoldHeart = new Color(1f, 0.78f, 0.18f);

	private static readonly Color WarmAmber = new Color(0.92f, 0.62f, 0.25f);

	private static readonly Color BrightTeal = new Color(0.32f, 0.88f, 0.78f);

	private static readonly Color DeepTeal = new Color(0.08f, 0.42f, 0.44f);

	private MeshRenderer cachedRenderer;

	private void Start()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		if ((Object)(object)sharedSwirlTex == (Object)null)
		{
			sharedSwirlTex = new Texture2D(32, 32, (TextureFormat)4, false);
			pixelBuffer = (Color[])(object)new Color[1024];
			UpdateSwirlTexture(0f);
		}
		cachedRenderer = ((Component)this).GetComponent<MeshRenderer>();
		if ((Object)(object)cachedRenderer != (Object)null && (Object)(object)((Renderer)cachedRenderer).sharedMaterial != (Object)null)
		{
			((Renderer)cachedRenderer).sharedMaterial.mainTexture = (Texture)(object)sharedSwirlTex;
			if (((Renderer)cachedRenderer).sharedMaterial.HasProperty("_EmissionMap"))
			{
				((Renderer)cachedRenderer).sharedMaterial.SetTexture("_EmissionMap", (Texture)(object)sharedSwirlTex);
			}
		}
	}

	private void Update()
	{
		if (!((Object)(object)sharedSwirlTex == (Object)null) && !((Object)(object)cachedRenderer == (Object)null) && ((Renderer)cachedRenderer).isVisible)
		{
			float time = Time.time;
			if (!(time - lastUpdateTime < 0.066f))
			{
				lastUpdateTime = time;
				UpdateSwirlTexture(time * 2.2f);
			}
		}
	}

	private static void UpdateSwirlTexture(float t)
	{
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_015c: 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_0170: 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_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < 32; i++)
		{
			float num = (float)i / 31f;
			for (int j = 0; j < 32; j++)
			{
				float num2 = (float)j / 31f;
				float num3 = ((Mathf.Abs(num2 - 0.75f) < Mathf.Abs(num2 - 0.25f)) ? ((num2 - 0.75f) * 8.5f) : ((num2 - 0.25f) * 8.5f));
				float num4 = (num - 0.5f) * 2.8f;
				float num5 = Mathf.Atan2(num4, num3);
				float num6 = Mathf.Sqrt(num3 * num3 + num4 * num4);
				float num7 = Mathf.Sin(num5 * 2f + num6 * 8f - t) * 0.5f + 0.5f;
				float num8 = Mathf.Cos(num * 18f - t * 1.4f + Mathf.Sin(num2 * 22f + t * 0.8f) * 1.5f) * 0.5f + 0.5f;
				float num9 = num7 * 0.65f + num8 * 0.35f;
				Color val = Color.Lerp(DeepTeal, BrightTeal, num9);
				float num10 = num6 + (num9 - 0.5f) * 0.18f;
				Color val2 = ((num10 < 0.22f) ? Color.Lerp(GoldHeart, WarmAmber, num10 / 0.22f) : ((num10 < 0.38f) ? Color.Lerp(WarmAmber, val, (num10 - 0.22f) / 0.16f) : val));
				pixelBuffer[i * 32 + j] = val2;
			}
		}
		sharedSwirlTex.SetPixels(pixelBuffer);
		sharedSwirlTex.Apply(false);
	}
}