Decompiled source of UnicornsCustomSeeds v1.1.2

UnicornsCustomSeeds_IL2Cpp_1.1.2.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2Cpp;
using Il2CppFishNet;
using Il2CppFishNet.Connection;
using Il2CppFluffyUnderware.DevTools.Extensions;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.AvatarFramework.Equipping;
using Il2CppScheduleOne.Core.Items.Framework;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Dialogue;
using Il2CppScheduleOne.Economy;
using Il2CppScheduleOne.EntityFramework;
using Il2CppScheduleOne.Equipping;
using Il2CppScheduleOne.Growing;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Management;
using Il2CppScheduleOne.Messaging;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.NPCs.CharacterClasses;
using Il2CppScheduleOne.NPCs.Relation;
using Il2CppScheduleOne.ObjectScripts;
using Il2CppScheduleOne.Persistence;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.PlayerTasks;
using Il2CppScheduleOne.Product;
using Il2CppScheduleOne.Product.Packaging;
using Il2CppScheduleOne.Quests;
using Il2CppScheduleOne.StationFramework;
using Il2CppScheduleOne.Storage;
using Il2CppScheduleOne.UI.MainMenu;
using Il2CppScheduleOne.UI.Phone;
using Il2CppScheduleOne.UI.Phone.Delivery;
using Il2CppScheduleOne.UI.Phone.Messages;
using Il2CppScheduleOne.UI.Phone.ProductManagerApp;
using Il2CppScheduleOne.UI.Shop;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using S1API.Quests;
using S1API.Saveables;
using UnicornsCustomSeeds;
using UnicornsCustomSeeds.Managers;
using UnicornsCustomSeeds.Patches;
using UnicornsCustomSeeds.SeedQuests;
using UnicornsCustomSeeds.Seeds;
using UnicornsCustomSeeds.TemplateUtils;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "Unicorns Custom Seeds", "1.1.2", "OverweightUnicorn", null)]
[assembly: MelonColor(255, 191, 0, 255)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("UnicornsCustomSeeds_IL2Cpp_1.1.2")]
[assembly: AssemblyConfiguration("IL2CPP")]
[assembly: AssemblyFileVersion("1.1.2")]
[assembly: AssemblyInformationalVersion("1.0.0+fa9d831ee061a32a32b6003c2f58a81608632142")]
[assembly: AssemblyProduct("UnicornsCustomSeeds_IL2Cpp_1.1.2")]
[assembly: AssemblyTitle("UnicornsCustomSeeds_IL2Cpp_1.1.2")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.0")]
[module: UnverifiableCode]
[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 UnicornsCustomSeeds
{
	public static class BuildInfo
	{
		public const string Name = "Unicorns Custom Seeds";

		public const string Description = "Your good buddy Unicorn can help you synthesize seeds";

		public const string Author = "OverweightUnicorn";

		public const string Company = "UnicornsCanMod";

		public const string Version = "1.1.2";

		public const string DownloadLink = null;
	}
	public class Core : MelonMod
	{
		public override void OnInitializeMelon()
		{
			AssetBundleUtils.Initialize(this);
		}

		public override void OnLateInitializeMelon()
		{
			StashManager.InitializeConfig();
			SeedVisualsManager.LoadSeedMaterial();
			Singleton<LoadManager>.Instance.onLoadComplete.AddListener(UnityAction.op_Implicit((Action)InitMod));
			Singleton<SaveManager>.Instance.onSaveComplete.AddListener(UnityAction.op_Implicit((Action)SaveData));
		}

		public void SaveData()
		{
			try
			{
				string loadedGameFolderPath = Singleton<LoadManager>.Instance.LoadedGameFolderPath;
				if (string.IsNullOrEmpty(loadedGameFolderPath) || !Directory.Exists(loadedGameFolderPath))
				{
					return;
				}
				List<UnicornSeedData> list = new List<UnicornSeedData>();
				list.AddRange(CustomSeedsManager.DiscoveredSeeds.Values);
				list.AddRange(CustomShroomsManager.DiscoveredShrooms.Values);
				list.AddRange(CustomCocaSeedsManager.DiscoveredCocaSeeds.Values);
				string contents = JsonConvert.SerializeObject((object)list, (Formatting)1);
				File.WriteAllText(Path.Combine(loadedGameFolderPath, "DiscoveredCustomSeeds.json"), contents);
				List<ActiveCookingEntry> list2 = new List<ActiveCookingEntry>();
				foreach (KeyValuePair<string, string> item in ActiveCookingRegistry.GuidToMixId)
				{
					list2.Add(new ActiveCookingEntry
					{
						stationGuid = item.Key,
						mixId = item.Value
					});
				}
				string contents2 = JsonConvert.SerializeObject((object)list2, (Formatting)1);
				File.WriteAllText(Path.Combine(loadedGameFolderPath, "UnicornsActiveCooking.json"), contents2);
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
		}

		public void InitMod()
		{
			CustomSeedsManager.Initialize();
			CustomShroomsManager.Initialize();
			CustomCocaSeedsManager.Initialize();
			StashManager.GetAlbertsStash();
			if (CustomSeedsManager.letsMigrate)
			{
				if (CustomSeedsManager.DiscoveredSeeds.Count > 0 || CustomShroomsManager.DiscoveredShrooms.Count > 0 || CustomCocaSeedsManager.DiscoveredCocaSeeds.Count > 0)
				{
					SaveData();
				}
				else
				{
					Utility.Error("Core: migration was flagged but nothing loaded — skipping the save so the existing file isn't overwritten with an empty list.");
				}
				Utility.Success($"Successfully migrated {CustomSeedsManager.DiscoveredSeeds.Count} seed(s)");
				CustomSeedsManager.letsMigrate = false;
			}
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			SeedDefinition item = Registry.GetItem<SeedDefinition>("ogkushseed");
			if (CustomSeedsManager.factory == null && (Object)(object)item != (Object)null)
			{
				CustomSeedsManager.factory = new SeedFactory(item);
			}
			SporeSyringeDefinition item2 = Registry.GetItem<SporeSyringeDefinition>("sporesyringe");
			if (CustomShroomsManager.factory == null && (Object)(object)item2 != (Object)null)
			{
				CustomShroomsManager.factory = new SyringeFactory(item2);
			}
			Dictionary<int, ItemRegister> itemDictionary = Singleton<Registry>.Instance.ItemDictionary;
			SeedDefinition item3 = Registry.GetItem<SeedDefinition>("cocaseed");
			QualityItemDefinition item4 = Registry.GetItem<QualityItemDefinition>("cocaleaf");
			QualityItemDefinition item5 = Registry.GetItem<QualityItemDefinition>("cocainebase");
			if (CustomCocaSeedsManager.factory == null && (Object)(object)item3 != (Object)null && (Object)(object)item4 != (Object)null && (Object)(object)item5 != (Object)null)
			{
				CustomCocaSeedsManager.factory = new CocaFactory(item3, item4, item5);
			}
			else if (CustomCocaSeedsManager.factory == null)
			{
				Utility.Error($"Core: CocaFactory init failed — cocaseed={(Object)(object)item3 != (Object)null}, cocaleaf={(Object)(object)item4 != (Object)null}, cocainebase={(Object)(object)item5 != (Object)null}");
			}
			StashManager.GetAlbertsStash();
			if (sceneName.ToLower() != "main")
			{
				CustomSeedsManager.ClearAll();
				CustomShroomsManager.ClearAll();
				CustomCocaSeedsManager.ClearAll();
				ActiveCookingRegistry.Clear();
				ProductManagerAppPatches.ClearPendingIndicators();
				StashManager.ClearCaches();
			}
			else if ((Object)(object)SeedVisualsManager.seedIcon == (Object)null || (Object)(object)SeedVisualsManager.baseSeedSprite == (Object)null)
			{
				SeedVisualsManager.LoadSeedMaterial();
			}
		}
	}
}
namespace UnicornsCustomSeeds.TemplateUtils
{
	public static class AssetBundleUtils
	{
		private static Core mod;

		private static MelonAssembly melonAssembly;

		private static Dictionary<string, Il2CppAssetBundle> assetBundles = new Dictionary<string, Il2CppAssetBundle>();

		private static string DataFolderName = "UnicornsCanBundle";

		private static string ModFolderName = "UnicornsCustomSeeds";

		private static string GetBundleCachePath(string bundleFileName)
		{
			string text = Path.Combine(MelonEnvironment.UserDataDirectory, DataFolderName, ModFolderName);
			Directory.CreateDirectory(text);
			return Path.Combine(text, bundleFileName + "_1.1.2");
		}

		private static byte[] ReadEmbeddedBundleBytes(string bundleFileName)
		{
			string text = typeof(Core).Namespace + ".Assets." + bundleFileName;
			using Stream stream = melonAssembly.Assembly.GetManifestResourceStream(text);
			if (stream == null)
			{
				MelonLogger.Error($"AssetBundle resource '{text}' not found. Check EmbeddedResource entry for '{bundleFileName}'.");
				return null;
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			byte[] array = memoryStream.ToArray();
			if (array.Length == 0)
			{
				MelonLogger.Error("AssetBundle '" + bundleFileName + "' is empty.");
				return null;
			}
			return array;
		}

		public static bool EnsureBundleCached(string bundleFileName)
		{
			string bundleCachePath = GetBundleCachePath(bundleFileName);
			if (File.Exists(bundleCachePath))
			{
				return true;
			}
			byte[] array = ReadEmbeddedBundleBytes(bundleFileName);
			if (array == null)
			{
				return false;
			}
			try
			{
				File.WriteAllBytes(bundleCachePath, array);
				MelonLogger.Msg($"Cached AssetBundle '{bundleFileName}' to '{bundleCachePath}'.");
				return true;
			}
			catch (Exception value)
			{
				MelonLogger.Error($"Failed writing AssetBundle cache '{bundleFileName}': {value}");
				return false;
			}
		}

		private static Il2CppAssetBundle LoadBundleFromFile(string bundleFileName)
		{
			string bundleCachePath = GetBundleCachePath(bundleFileName);
			try
			{
				Il2CppAssetBundle val = Il2CppAssetBundleManager.LoadFromFile(bundleCachePath);
				if (val == null)
				{
					MelonLogger.Error($"LoadFromFile returned null for bundle '{bundleFileName}' at '{bundleCachePath}'.");
				}
				return val;
			}
			catch (Exception value)
			{
				MelonLogger.Error($"LoadFromFile failed for bundle '{bundleFileName}' at '{bundleCachePath}': {value}");
				return null;
			}
		}

		public static void Initialize(Core coreMod)
		{
			mod = coreMod;
			melonAssembly = ((MelonBase)mod).MelonAssembly;
		}

		public static Il2CppAssetBundle LoadAssetBundle(string bundleFileName)
		{
			if (assetBundles.TryGetValue(bundleFileName, out var value) && value != null)
			{
				return value;
			}
			try
			{
				string bundleCachePath = GetBundleCachePath(bundleFileName);
				Il2CppAssetBundle val;
				if (File.Exists(bundleCachePath))
				{
					val = LoadBundleFromFile(bundleFileName);
				}
				else
				{
					byte[] array = ReadEmbeddedBundleBytes(bundleFileName);
					if (array == null)
					{
						((MelonBase)mod).Unregister("Failed to read required AssetBundle '" + bundleFileName + "' from embedded resources.", false);
						return null;
					}
					try
					{
						Il2CppAssetBundle val2 = Il2CppAssetBundleManager.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(array));
						if (val2 == null)
						{
							((MelonBase)mod).Unregister("Failed to validate required AssetBundle '" + bundleFileName + "' from memory.", false);
							return null;
						}
						try
						{
							File.WriteAllBytes(bundleCachePath, array);
							MelonLogger.Msg($"Cached AssetBundle '{bundleFileName}' to '{bundleCachePath}'.");
						}
						catch (Exception value2)
						{
							try
							{
								val2.Unload(false);
							}
							catch
							{
							}
							((MelonBase)mod).Unregister($"Failed writing required AssetBundle '{bundleFileName}' to cache: {value2}", false);
							return null;
						}
						try
						{
							val2.Unload(false);
						}
						catch (Exception ex)
						{
							MelonLogger.Warning("Failed to unload memory validation bundle '" + bundleFileName + "': " + ex.Message);
						}
						val = LoadBundleFromFile(bundleFileName);
					}
					catch (Exception value3)
					{
						((MelonBase)mod).Unregister($"Failed to validate required AssetBundle '{bundleFileName}' from memory: {value3}", false);
						return null;
					}
				}
				if (val == null)
				{
					((MelonBase)mod).Unregister("Failed to load required AssetBundle '" + bundleFileName + "'.", false);
					return null;
				}
				assetBundles[bundleFileName] = val;
				return val;
			}
			catch (Exception value4)
			{
				((MelonBase)mod).Unregister($"Failed to load required AssetBundle '{bundleFileName}': {value4}", false);
				return null;
			}
		}

		public static void ClearCache()
		{
			assetBundles.Clear();
		}

		public static Il2CppAssetBundle GetLoadedAssetBundle(string bundleName)
		{
			if (assetBundles.ContainsKey(bundleName))
			{
				return assetBundles[bundleName];
			}
			MelonLogger.Warning("Asset bundle '" + bundleName + "' is not loaded.");
			return null;
		}

		public static T LoadAssetFromBundle<T>(string assetName, string bundleName) where T : Object
		{
			Il2CppAssetBundle loadedAssetBundle = GetLoadedAssetBundle(bundleName);
			if (loadedAssetBundle == null)
			{
				MelonLogger.Error("Couldn't find loaded bundle '" + bundleName + "'.");
				return default(T);
			}
			T val = default(T);
			try
			{
				val = loadedAssetBundle.LoadAsset<T>(assetName);
			}
			catch (Exception value)
			{
				MelonLogger.Error($"Failed loading asset '{assetName}' from bundle '{bundleName}'. The bundle may be invalid or have a zero internal pointer. {value}");
				return default(T);
			}
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Error($"Asset '{assetName}' not found in bundle '{bundleName}'.");
				return default(T);
			}
			return val;
		}

		public static Texture2D LoadTextureContaining(string bundleName, params string[] contains)
		{
			Il2CppAssetBundle loadedAssetBundle = GetLoadedAssetBundle(bundleName);
			if (loadedAssetBundle == null)
			{
				return null;
			}
			Il2CppStringArray allAssetNames = loadedAssetBundle.GetAllAssetNames();
			for (int i = 0; i < ((Il2CppArrayBase<string>)(object)allAssetNames).Length; i++)
			{
				string text = ((Il2CppArrayBase<string>)(object)allAssetNames)[i].ToLowerInvariant();
				bool flag = true;
				for (int j = 0; j < contains.Length; j++)
				{
					if (!text.Contains(contains[j].ToLowerInvariant()))
					{
						flag = false;
						break;
					}
				}
				if (!flag)
				{
					continue;
				}
				try
				{
					Texture2D val = loadedAssetBundle.LoadAsset<Texture2D>(((Il2CppArrayBase<string>)(object)allAssetNames)[i]);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Warning($"Failed loading texture '{((Il2CppArrayBase<string>)(object)allAssetNames)[i]}' from bundle '{bundleName}': {ex.Message}");
				}
			}
			return null;
		}
	}
	public static class Utility
	{
		public static void PrintException(Exception e)
		{
			MelonLogger.Msg(ConsoleColor.Red, e.GetType().FullName);
			MelonLogger.Msg(ConsoleColor.DarkRed, e.Message);
			if (!string.IsNullOrWhiteSpace(e.StackTrace))
			{
				MelonLogger.Msg(ConsoleColor.DarkRed, "StackTrace:");
				string[] array = e.StackTrace.Split('\n');
				foreach (string text in array)
				{
					MelonLogger.Msg(ConsoleColor.DarkRed, "    " + text.Trim());
				}
			}
			if (e.InnerException != null)
			{
				MelonLogger.Msg(ConsoleColor.DarkRed, "  -- Inner Exception --");
				PrintException(e.InnerException);
			}
		}

		public static void Error(string msg)
		{
			MelonLogger.Msg(ConsoleColor.Red, msg);
		}

		public static void Log(string msg)
		{
			MelonLogger.Msg(ConsoleColor.DarkMagenta, msg);
		}

		public static void Success(string msg)
		{
			MelonLogger.Msg(ConsoleColor.Green, msg);
		}
	}
}
namespace UnicornsCustomSeeds.Seeds
{
	public class CocaFactory
	{
		public static readonly Dictionary<string, string> CustomLeafIdToBaseId = new Dictionary<string, string>();

		public static readonly Dictionary<string, string> CustomBaseIdToMixId = new Dictionary<string, string>();

		private Transform rootGameObject;

		private SeedDefinition baseSeedDefinition;

		private CocaPlant baseCocaPlantPrefab;

		private PlantHarvestable baseHarvestable;

		private FunctionalSeed baseFunctionalSeedPrefab;

		private Equippable_Seed baseEquippableSeedPrefab;

		private AvatarEquippable baseAvatarEquippablePrefab;

		private StoredItem baseStoredItem;

		private QualityItemDefinition baseCocaLeafDefinition;

		private QualityItemDefinition baseCocaineBaseDefinition;

		public CocaFactory(SeedDefinition baseSeed, QualityItemDefinition baseCocaLeaf, QualityItemDefinition baseCocaineBase)
		{
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			baseSeedDefinition = baseSeed;
			baseCocaLeafDefinition = baseCocaLeaf;
			baseCocaineBaseDefinition = baseCocaineBase;
			baseCocaPlantPrefab = ((Il2CppObjectBase)baseSeed.PlantPrefab).TryCast<CocaPlant>();
			if ((Object)(object)baseCocaPlantPrefab == (Object)null)
			{
				Utility.Error("CocaFactory: Failed to cast PlantPrefab to CocaPlant.");
			}
			CocaPlant obj = baseCocaPlantPrefab;
			baseHarvestable = ((obj != null) ? obj.Harvestable : null);
			baseFunctionalSeedPrefab = baseSeed.FunctionSeedPrefab;
			baseStoredItem = ((StorableItemDefinition)baseSeed).StoredItem;
			baseEquippableSeedPrefab = ((Il2CppObjectBase)((ItemDefinition)baseSeed).Equippable).TryCast<Equippable_Seed>();
			if ((Object)(object)baseEquippableSeedPrefab == (Object)null)
			{
				Utility.Error("CocaFactory: Failed to cast Equippable to Equippable_Seed.");
			}
			Equippable_Seed obj2 = baseEquippableSeedPrefab;
			baseAvatarEquippablePrefab = ((obj2 != null) ? ((Equippable_Viewmodel)obj2).AvatarEquippable : null);
			GameObject val = new GameObject(((BaseItemDefinition)baseSeedDefinition).ID + "_CustomCocaSeeds");
			val.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val);
			rootGameObject = val.transform;
		}

		public void DeleteChildren()
		{
			TransformExt.DeleteChildren(rootGameObject, true, false);
			CustomLeafIdToBaseId.Clear();
			CustomBaseIdToMixId.Clear();
		}

		public SeedDefinition CreateCocaSeedDefinition(ProductDefinition cocaineDef)
		{
			if ((Object)(object)baseSeedDefinition == (Object)null)
			{
				throw new InvalidOperationException("Base seed definition not initialized.");
			}
			QualityItemDefinition val = CloneCustomCocaineBase(cocaineDef);
			QualityItemDefinition val2 = CloneCustomCocaLeaf(val, cocaineDef);
			CocaPlant plantPrefab = CloneCocaPlant(val2);
			SeedDefinition val3 = Object.Instantiate<SeedDefinition>(baseSeedDefinition);
			((BaseItemDefinition)val3).ID = ((BaseItemDefinition)cocaineDef).ID + "_customcocaseed";
			((Object)val3).name = ((BaseItemDefinition)val3).ID;
			((BaseItemDefinition)val3).Name = ((Object)cocaineDef).name + " Coca Seed";
			((BaseItemDefinition)val3).Description = "A custom coca seed that produces " + ((Object)cocaineDef).name + ".";
			((BaseItemDefinition)val3).Icon = ((BaseItemDefinition)baseSeedDefinition).Icon;
			val3.PlantPrefab = (Plant)(object)plantPrefab;
			val3.PlantPrefab.SeedDefinition = val3;
			val3.FunctionSeedPrefab = CloneFunctionalSeedPrefab(((BaseItemDefinition)val3).ID);
			((Object)val3.FunctionSeedPrefab).name = ((BaseItemDefinition)cocaineDef).ID + "CocaSeed_Functional";
			((ItemDefinition)val3).Equippable = (Equippable)(object)CloneEquippableSeedPrefab(val3);
			((StorableItemDefinition)val3).StoredItem = CloneStoredItem(((BaseItemDefinition)val3).ID);
			Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val2);
			Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val);
			Utility.Log($"CocaFactory: {((BaseItemDefinition)val3).ID} ? leaf:{((BaseItemDefinition)val2).ID} ? base:{((BaseItemDefinition)val).ID} ? mix:{((BaseItemDefinition)cocaineDef).ID}");
			return val3;
		}

		private QualityItemDefinition CloneCustomCocaineBase(ProductDefinition cocaineDef)
		{
			QualityItemDefinition val = Object.Instantiate<QualityItemDefinition>(baseCocaineBaseDefinition);
			((BaseItemDefinition)val).ID = ((BaseItemDefinition)cocaineDef).ID + "_customcocainebase";
			((Object)val).name = ((BaseItemDefinition)val).ID;
			((BaseItemDefinition)val).Name = ((Object)cocaineDef).name + " Base";
			if ((Object)(object)((StorableItemDefinition)baseCocaineBaseDefinition).StationItem != (Object)null)
			{
				StationItem val2 = Object.Instantiate<StationItem>(((StorableItemDefinition)baseCocaineBaseDefinition).StationItem, rootGameObject);
				((Object)val2).name = ((BaseItemDefinition)cocaineDef).ID + "_CocaineBaseStationItem";
				CookableModule module = val2.GetModule<CookableModule>();
				if ((Object)(object)module != (Object)null)
				{
					module.Product = (StorableItemDefinition)(object)cocaineDef;
					Utility.Log("CocaFactory: Set CookableModule.Product = " + ((BaseItemDefinition)cocaineDef).ID);
				}
				else
				{
					Utility.Error("CocaFactory: No CookableModule on StationItem for " + ((BaseItemDefinition)cocaineDef).ID + ". LabOven will output vanilla product.");
				}
				((StorableItemDefinition)val).StationItem = val2;
			}
			else
			{
				Utility.Error("CocaFactory: baseCocaineBaseDefinition.StationItem is null.");
			}
			CustomBaseIdToMixId[((BaseItemDefinition)val).ID] = ((BaseItemDefinition)cocaineDef).ID;
			return val;
		}

		private QualityItemDefinition CloneCustomCocaLeaf(QualityItemDefinition customBase, ProductDefinition cocaineDef)
		{
			QualityItemDefinition val = Object.Instantiate<QualityItemDefinition>(baseCocaLeafDefinition);
			((BaseItemDefinition)val).ID = ((BaseItemDefinition)cocaineDef).ID + "_customcocaleaf";
			((Object)val).name = ((BaseItemDefinition)val).ID;
			((BaseItemDefinition)val).Name = "Coca Leaf (" + ((Object)cocaineDef).name + ")";
			((StorableItemDefinition)val).StationItem = ((StorableItemDefinition)baseCocaLeafDefinition).StationItem;
			CustomLeafIdToBaseId[((BaseItemDefinition)val).ID] = ((BaseItemDefinition)customBase).ID;
			return val;
		}

		private CocaPlant CloneCocaPlant(QualityItemDefinition customLeaf)
		{
			CocaPlant val = Object.Instantiate<CocaPlant>(baseCocaPlantPrefab, rootGameObject);
			((Object)((Component)val).gameObject).name = ((BaseItemDefinition)customLeaf).ID + "_CocaPlant";
			PlantHarvestable val2 = Object.Instantiate<PlantHarvestable>(baseHarvestable, rootGameObject);
			((Object)((Component)val2).gameObject).name = ((BaseItemDefinition)customLeaf).ID + "_Harvestable";
			val2.Product = (StorableItemDefinition)(object)customLeaf;
			val.Harvestable = val2;
			foreach (PlantHarvestable componentsInChild in ((Component)val).GetComponentsInChildren<PlantHarvestable>())
			{
				componentsInChild.Product = (StorableItemDefinition)(object)customLeaf;
			}
			return val;
		}

		private FunctionalSeed CloneFunctionalSeedPrefab(string seedDefId)
		{
			if ((Object)(object)baseFunctionalSeedPrefab == (Object)null)
			{
				throw new InvalidOperationException("Base functional seed prefab not initialized.");
			}
			FunctionalSeed val = Object.Instantiate<FunctionalSeed>(baseFunctionalSeedPrefab, rootGameObject);
			((Object)((Component)val).gameObject).name = seedDefId + "_Functional";
			return val;
		}

		private Equippable_Seed CloneEquippableSeedPrefab(SeedDefinition newDef)
		{
			if ((Object)(object)baseEquippableSeedPrefab == (Object)null)
			{
				throw new InvalidOperationException("Base equippable seed prefab not initialized.");
			}
			Equippable_Seed val = Object.Instantiate<Equippable_Seed>(baseEquippableSeedPrefab, rootGameObject);
			((Object)((Component)val).gameObject).name = ((BaseItemDefinition)newDef).ID + "_Equippable";
			((Component)val).gameObject.layer = ((Component)baseEquippableSeedPrefab).gameObject.layer;
			val.Seed = newDef;
			((Equippable_Viewmodel)val).AvatarEquippable = CloneAvatarEquippablePrefab(((BaseItemDefinition)newDef).ID);
			((Object)((Equippable_Viewmodel)val).AvatarEquippable).name = ((BaseItemDefinition)newDef).ID + "_AvatarEquippable";
			return val;
		}

		private AvatarEquippable CloneAvatarEquippablePrefab(string newDefId)
		{
			if ((Object)(object)baseAvatarEquippablePrefab == (Object)null)
			{
				throw new InvalidOperationException("Base avatar equippable prefab not initialized.");
			}
			AvatarEquippable val = Object.Instantiate<AvatarEquippable>(baseAvatarEquippablePrefab, rootGameObject);
			((Object)((Component)val).gameObject).name = newDefId + "_AvatarEquippable";
			return val;
		}

		private StoredItem CloneStoredItem(string newDefId)
		{
			if ((Object)(object)baseStoredItem == (Object)null)
			{
				throw new InvalidOperationException("Base stored item not initialized.");
			}
			StoredItem val = Object.Instantiate<StoredItem>(baseStoredItem, rootGameObject);
			((Object)((Component)val).gameObject).name = newDefId + "_StoredItem";
			return val;
		}

		public static void AddLeafToCauldrons(QualityItemDefinition customLeaf)
		{
			Cauldron[] array = Il2CppArrayBase<Cauldron>.op_Implicit(Object.FindObjectsOfType<Cauldron>());
			int num = 0;
			Cauldron[] array2 = array;
			foreach (Cauldron val in array2)
			{
				foreach (ItemSlot item in (Il2CppArrayBase<ItemSlot>)(object)val.IngredientSlots)
				{
					Enumerator<ItemFilter> enumerator2 = item.HardFilters.GetEnumerator();
					while (enumerator2.MoveNext())
					{
						ItemFilter current2 = enumerator2.Current;
						ItemFilter_ID val2 = ((Il2CppObjectBase)current2).TryCast<ItemFilter_ID>();
						if (val2 != null && !val2.IDs.Contains(((BaseItemDefinition)customLeaf).ID))
						{
							val2.IDs.Add(((BaseItemDefinition)customLeaf).ID);
							num++;
						}
					}
				}
			}
			Utility.Log($"CocaFactory: Added '{((BaseItemDefinition)customLeaf).ID}' to {num} cauldron slot filter(s).");
		}
	}
	public class SyringeFactory
	{
		private Transform rootGameObject;

		private SporeSyringeDefinition baseSyringeDef;

		private ShroomSpawnDefinition baseSpawnDefinition;

		private ShroomColony baseColonyPrefab;

		private ShroomDefinition baseShroomDef;

		private SpawnChunk baseChunkPrefab;

		public SyringeFactory(SporeSyringeDefinition baseSyringe)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			baseSyringeDef = baseSyringe;
			baseSpawnDefinition = baseSyringe.SpawnDefinition;
			baseColonyPrefab = baseSpawnDefinition.ColonyPrefab;
			baseShroomDef = baseSpawnDefinition.Shroom;
			baseChunkPrefab = baseSpawnDefinition.ChunkPrefab;
			GameObject val = new GameObject(((BaseItemDefinition)baseSyringeDef).ID + "_CustomSyringes");
			val.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val);
			rootGameObject = val.transform;
		}

		public SporeSyringeDefinition CreateSyringeDefinition(ShroomDefinition shroomDef)
		{
			if ((Object)(object)baseSyringeDef == (Object)null)
			{
				throw new InvalidOperationException("Base syringe definition not initialized.");
			}
			SporeSyringeDefinition val = Object.Instantiate<SporeSyringeDefinition>(baseSyringeDef);
			((BaseItemDefinition)val).ID = ((BaseItemDefinition)shroomDef).ID + "_customsyringedefinition";
			((Object)val).name = ((BaseItemDefinition)val).ID;
			((BaseItemDefinition)val).Name = ((Object)shroomDef).name + " Spore Syringe";
			ShroomSpawnDefinition val2 = (val.SpawnDefinition = CloneSpawnDefinition(((BaseItemDefinition)shroomDef).ID, shroomDef));
			Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val2);
			Utility.Log("Registered ShroomSpawnDefinition: " + ((BaseItemDefinition)val2).ID);
			return val;
		}

		private ShroomSpawnDefinition CloneSpawnDefinition(string shroomId, ShroomDefinition shroomDef)
		{
			ShroomSpawnDefinition val = Object.Instantiate<ShroomSpawnDefinition>(baseSpawnDefinition);
			((BaseItemDefinition)val).ID = shroomId + "_customspawndefinition";
			((Object)val).name = ((BaseItemDefinition)val).ID;
			((BaseItemDefinition)val).Name = ((Object)shroomDef).name + " Spawn";
			val.Shroom = shroomDef;
			ShroomColony val2 = Object.Instantiate<ShroomColony>(baseColonyPrefab, rootGameObject);
			((Object)((Component)val2).gameObject).name = shroomId + "_Colony";
			val2._spawnDefinition = val;
			val.ColonyPrefab = val2;
			return val;
		}

		public void DeleteChildren()
		{
			TransformExt.DeleteChildren(rootGameObject, true, false);
		}
	}
	[Serializable]
	internal class LegacySeedData
	{
		public string seedId { get; set; }

		public string weedId { get; set; }

		public string baseSeedId { get; set; }

		public float price { get; set; }
	}
	[Serializable]
	internal class LegacyUnicornSeedData
	{
		public string seedId { get; set; }

		public string mixId { get; set; }

		public EDrugType drugType { get; set; }

		public float price { get; set; }
	}
	[Serializable]
	public class VariantSeedData
	{
		public string baseItemId { get; set; }

		public string seedId { get; set; }

		public float price { get; set; }
	}
	[Serializable]
	public class UnicornSeedData
	{
		public string mixId { get; set; }

		public EDrugType drugType { get; set; }

		public List<VariantSeedData> variants { get; set; } = new List<VariantSeedData>();

		[JsonIgnore]
		public string seedId => variants.FirstOrDefault()?.seedId;

		[JsonIgnore]
		public float price => variants.FirstOrDefault()?.price ?? 0f;

		public VariantSeedData GetVariant(string baseItemId)
		{
			return variants.FirstOrDefault((VariantSeedData v) => v.baseItemId == baseItemId);
		}

		public void SetSingleVariant(string baseItemId, string itemSeedId, float variantPrice)
		{
			variants = new List<VariantSeedData>
			{
				new VariantSeedData
				{
					baseItemId = baseItemId,
					seedId = itemSeedId,
					price = variantPrice
				}
			};
		}
	}
	public class SeedFactory
	{
		private Transform rootGameObject;

		private WeedPlant basePlantPrefab;

		private PlantHarvestable baseBranchPrefab;

		private FunctionalSeed baseFunctionalSeedPrefab;

		private Equippable_Seed baseEquippableSeedPrefab;

		private AvatarEquippable baseAvatarEquippablePrefab;

		private StoredItem baseStorableItem;

		public SeedDefinition baseSeedDefinition;

		public SeedFactory(SeedDefinition seedDefinition)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			baseSeedDefinition = seedDefinition;
			baseFunctionalSeedPrefab = seedDefinition.FunctionSeedPrefab;
			baseStorableItem = ((StorableItemDefinition)seedDefinition).StoredItem;
			InitializeBasePlant(seedDefinition);
			InitializeEquippable(seedDefinition);
			if ((Object)(object)rootGameObject == (Object)null)
			{
				GameObject val = new GameObject(((BaseItemDefinition)baseSeedDefinition).ID + "_CustomSeeds");
				val.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)val);
				rootGameObject = val.transform;
			}
		}

		private void InitializeBasePlant(SeedDefinition seedDefinition)
		{
			WeedPlant val = ((Il2CppObjectBase)seedDefinition.PlantPrefab).TryCast<WeedPlant>();
			if ((Object)(object)val != (Object)null)
			{
				basePlantPrefab = val;
				if ((Object)(object)basePlantPrefab != (Object)null)
				{
					baseBranchPrefab = basePlantPrefab.BranchPrefab;
				}
			}
			else
			{
				Utility.Log("Failed to cast PlantPrefab to WeedPlant.");
			}
		}

		private void InitializeEquippable(SeedDefinition seedDefinition)
		{
			Equippable_Seed val = ((Il2CppObjectBase)((ItemDefinition)seedDefinition).Equippable).TryCast<Equippable_Seed>();
			if ((Object)(object)val != (Object)null)
			{
				baseEquippableSeedPrefab = val;
				baseAvatarEquippablePrefab = ((Equippable_Viewmodel)val).AvatarEquippable;
			}
			else
			{
				Utility.Log("Failed to cast Equippable to Equippable_Seed.");
			}
		}

		public void DeleteChildren()
		{
			TransformExt.DeleteChildren(rootGameObject, true, false);
		}

		private void GrowLabel(Transform root, string seedDefId)
		{
			//IL_0072: 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)
			Transform val = null;
			Il2CppArrayBase<Transform> componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>();
			foreach (Transform item in componentsInChildren)
			{
				if (((Object)item).name == "Label")
				{
					val = ((Component)item).transform;
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				val.localScale = new Vector3(1.05f, 1.05f, 2f);
				val.position = new Vector3(0f, -0.05f, 0f);
				if ((Object)(object)SeedVisualsManager.customMat == (Object)null)
				{
					SeedVisualsManager.LoadSeedMaterial();
				}
				if ((Object)(object)SeedVisualsManager.customMat != (Object)null)
				{
					Renderer component = ((Component)val).GetComponent<Renderer>();
					component.material = SeedVisualsManager.customMat;
					((Component)val).gameObject.AddComponent<SeedVialLabel>();
					((Object)val).name = ((Object)val).name + ":" + seedDefId;
				}
				else
				{
					Utility.Log("MATERIAL NOT LOADED!!!");
				}
			}
		}

		public WeedPlant ClonePlantPrefab(WeedDefinition newDef)
		{
			if ((Object)(object)basePlantPrefab == (Object)null)
			{
				throw new InvalidOperationException("Base plant prefab not initialized.");
			}
			WeedPlant val = Object.Instantiate<WeedPlant>(basePlantPrefab, rootGameObject);
			SetPlantAppearance(newDef, val);
			PlantHarvestable val2 = CloneBranchPrefab(newDef);
			SetBranchAppearance(((Component)val2).transform, newDef);
			val.BranchPrefab = val2;
			Il2CppArrayBase<PlantHarvestable> componentsInChildren = ((Component)val).GetComponentsInChildren<PlantHarvestable>();
			foreach (PlantHarvestable item in componentsInChildren)
			{
				item.Product = (StorableItemDefinition)(object)newDef;
			}
			return val;
		}

		public void SetPlantAppearance(WeedDefinition newDef, WeedPlant plant)
		{
			//IL_00d0: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			foreach (PlantGrowthStage item in (Il2CppArrayBase<PlantGrowthStage>)(object)((Plant)plant).GrowthStages)
			{
				WeedAppearanceSettings val = newDef.appearance;
				if (val == null)
				{
					val = WeedDefinition.GetAppearanceSettings(((PropertyItemDefinition)newDef).Properties);
				}
				if ((Object)(object)item != (Object)null && val != null)
				{
					for (int i = 0; i < ((Component)item).transform.childCount; i++)
					{
						Transform child = ((Component)item).transform.GetChild(i);
						if ((Object)(object)child == (Object)null)
						{
							continue;
						}
						MeshRenderer component = ((Component)child).GetComponent<MeshRenderer>();
						if ((Object)(object)component == (Object)null)
						{
							continue;
						}
						Material material = ((Renderer)component).material;
						if ((Object)(object)material == (Object)null)
						{
							continue;
						}
						if (((Object)child).name == "Stem")
						{
							material.color = Color32.op_Implicit(val.StemColor);
						}
						if (((Object)child).name == "BigLeaves")
						{
							material.color = Color32.op_Implicit(val.LeafColor);
						}
						if (((Object)child).name == "SmallLeaves")
						{
							material.color = Color32.op_Implicit(val.LeafColor);
						}
						foreach (Transform item2 in (Il2CppArrayBase<Transform>)(object)item.GrowthSites)
						{
							if ((Object)(object)item2 != (Object)null)
							{
								Transform child2 = item2.GetChild(0);
								if (Object.op_Implicit((Object)(object)child2))
								{
									SetBranchAppearance(child2, val);
								}
							}
						}
					}
				}
				else
				{
					Utility.Error("Plant Stage is NULL! Thats impossible");
				}
			}
		}

		public void SetBranchAppearance(Transform branchTransform, WeedDefinition weedDef)
		{
			WeedAppearanceSettings val = weedDef.appearance;
			if (val == null)
			{
				val = WeedDefinition.GetAppearanceSettings(((PropertyItemDefinition)weedDef).Properties);
			}
			if (val != null && (Object)(object)branchTransform != (Object)null)
			{
				SetBranchAppearance(branchTransform, val);
			}
		}

		public void SetBranchAppearance(Transform branchTransform, WeedAppearanceSettings weedAppearance)
		{
			//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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			Transform child = branchTransform.GetChild(0);
			Transform val = ((child != null) ? child.GetChild(0) : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			for (int i = 0; i < val.childCount; i++)
			{
				Transform child2 = val.GetChild(i);
				if ((Object)(object)child2 == (Object)null)
				{
					continue;
				}
				MeshRenderer component = ((Component)child2).GetComponent<MeshRenderer>();
				if ((Object)(object)component == (Object)null)
				{
					continue;
				}
				Material material = ((Renderer)component).material;
				if (!((Object)(object)material == (Object)null))
				{
					if (((Object)child2).name == "Stem")
					{
						material.color = Color32.op_Implicit(weedAppearance.StemColor);
					}
					if (((Object)child2).name == "Leaves")
					{
						material.color = Color32.op_Implicit(weedAppearance.LeafColor);
					}
					if (((Object)child2).name == "Main")
					{
						material.color = Color32.op_Implicit(weedAppearance.MainColor);
					}
					if (((Object)child2).name == "Secondary")
					{
						material.color = Color32.op_Implicit(weedAppearance.SecondaryColor);
					}
				}
			}
		}

		public PlantHarvestable CloneBranchPrefab(WeedDefinition newDef)
		{
			if ((Object)(object)baseBranchPrefab == (Object)null)
			{
				throw new InvalidOperationException("Base branch prefab not initialized.");
			}
			PlantHarvestable val = Object.Instantiate<PlantHarvestable>(baseBranchPrefab, rootGameObject);
			((Object)((Component)val).gameObject).name = ((BaseItemDefinition)newDef).ID + "_Harvestable";
			((Component)val).gameObject.layer = ((Component)baseBranchPrefab).gameObject.layer;
			val.Product = (StorableItemDefinition)(object)newDef;
			return val;
		}

		public FunctionalSeed CloneFunctionalSeedPrefab(string seedDefId)
		{
			if ((Object)(object)baseFunctionalSeedPrefab == (Object)null)
			{
				throw new InvalidOperationException("Base functional seed prefab not initialized.");
			}
			FunctionalSeed val = Object.Instantiate<FunctionalSeed>(baseFunctionalSeedPrefab, rootGameObject);
			GrowLabel(((Component)val).transform, seedDefId);
			return val;
		}

		public Equippable_Seed CloneEquippableSeedPrefab(SeedDefinition newDef, WeedAppearanceSettings weedAppearance)
		{
			if ((Object)(object)baseEquippableSeedPrefab == (Object)null)
			{
				throw new InvalidOperationException("Base equippable seed prefab not initialized.");
			}
			Equippable_Seed val = Object.Instantiate<Equippable_Seed>(baseEquippableSeedPrefab, rootGameObject);
			GrowLabel(((Component)val).transform, ((BaseItemDefinition)newDef).ID);
			((Object)((Component)val).gameObject).name = ((BaseItemDefinition)newDef).ID + "_Equippable";
			((Component)val).gameObject.layer = ((Component)baseEquippableSeedPrefab).gameObject.layer;
			val.Seed = newDef;
			((Equippable_Viewmodel)val).AvatarEquippable = CloneAvatarEquippablePrefab(((BaseItemDefinition)newDef).ID);
			((Object)((Equippable_Viewmodel)val).AvatarEquippable).name = ((BaseItemDefinition)newDef).ID + "_AvatarEquippable";
			return val;
		}

		public AvatarEquippable CloneAvatarEquippablePrefab(string newDefId)
		{
			if ((Object)(object)baseAvatarEquippablePrefab == (Object)null)
			{
				throw new InvalidOperationException("Base avatar equippable prefab not initialized.");
			}
			AvatarEquippable val = Object.Instantiate<AvatarEquippable>(baseAvatarEquippablePrefab, rootGameObject);
			GrowLabel(((Component)val).transform, newDefId);
			return val;
		}

		public StoredItem CloneStoredItem(string newDefId)
		{
			if ((Object)(object)baseStorableItem == (Object)null)
			{
				throw new InvalidOperationException("Base Stored Item not initialized.");
			}
			StoredItem val = Object.Instantiate<StoredItem>(baseStorableItem, rootGameObject);
			GrowLabel(((Component)val).transform, newDefId);
			return val;
		}

		public SeedDefinition CreateSeedDefinition(WeedDefinition weedDef)
		{
			//IL_0145: 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_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)baseSeedDefinition == (Object)null)
			{
				throw new InvalidOperationException("Base seed definition not initialized.");
			}
			SeedDefinition val = Object.Instantiate<SeedDefinition>(baseSeedDefinition);
			WeedAppearanceSettings val2 = weedDef.appearance;
			if (val2 == null)
			{
				val2 = WeedDefinition.GetAppearanceSettings(((PropertyItemDefinition)weedDef).Properties);
			}
			((Object)val).name = ((BaseItemDefinition)weedDef).ID + "_customseeddefinition";
			((BaseItemDefinition)val).ID = ((BaseItemDefinition)weedDef).ID + "_customseeddefinition";
			((BaseItemDefinition)val).Name = ((Object)weedDef).name + " Seed";
			((BaseItemDefinition)val).Description = ((Object)weedDef).name + " Seed";
			((BaseItemDefinition)val).Icon = ((BaseItemDefinition)baseSeedDefinition).Icon;
			((ItemDefinition)val).Equippable = (Equippable)(object)CloneEquippableSeedPrefab(val, val2);
			val.PlantPrefab = (Plant)(object)ClonePlantPrefab(weedDef);
			val.PlantPrefab.SeedDefinition = val;
			val.FunctionSeedPrefab = CloneFunctionalSeedPrefab(((BaseItemDefinition)val).ID);
			((Object)val.FunctionSeedPrefab).name = ((BaseItemDefinition)weedDef).ID + "Seed_Functional";
			((StorableItemDefinition)val).StoredItem = CloneStoredItem(((BaseItemDefinition)val).ID);
			SeedVisualsManager.appearanceMap.Add(((BaseItemDefinition)val).ID, val2);
			if ((Object)(object)SeedVisualsManager.baseSeedSprite != (Object)null)
			{
				try
				{
					Sprite val3 = SeedVisualsManager.GenerateSpriteWithGradient(Color32.op_Implicit(val2.MainColor), Color32.op_Implicit(val2.SecondaryColor));
					((Object)val3).name = ((Object)val).name + "_icon";
					SeedVisualsManager.seedIcons.Add(((BaseItemDefinition)val).ID, val3);
					((BaseItemDefinition)val).Icon = val3;
				}
				catch (Exception e)
				{
					((BaseItemDefinition)val).Icon = SeedVisualsManager.baseSeedSprite;
					Utility.PrintException(e);
				}
			}
			return val;
		}
	}
	[RegisterTypeInIl2Cpp]
	public class SeedVialLabel : MonoBehaviour
	{
		private Renderer rend;

		private MaterialPropertyBlock block;

		public Color colorA;

		public Color colorB;

		public bool useRandomColors = false;

		private void Start()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			if (useRandomColors)
			{
				colorA = Random.ColorHSV();
				colorB = Random.ColorHSV();
			}
			rend = ((Component)this).GetComponent<Renderer>();
			block = new MaterialPropertyBlock();
			SetupLabel();
		}

		public void SetupLabel()
		{
			//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_00a7: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rend == (Object)null)
			{
				return;
			}
			MeshFilter component = ((Component)this).GetComponent<MeshFilter>();
			if ((Object)(object)component != (Object)null)
			{
				string key = ((Object)this).name.Split(':')[1];
				SeedVisualsManager.appearanceMap.TryGetValue(key, out var value);
				if (value != null)
				{
					colorA = Color32.op_Implicit(value.MainColor);
					colorB = Color32.op_Implicit(value.SecondaryColor);
				}
				Bounds bounds = component.sharedMesh.bounds;
				rend.GetPropertyBlock(block);
				block.SetColor("_ColorA", colorA);
				block.SetColor("_ColorB", colorB);
				block.SetFloat("_MinZ", ((Bounds)(ref bounds)).min.z);
				block.SetFloat("_MaxZ", ((Bounds)(ref bounds)).max.z);
				rend.SetPropertyBlock(block);
			}
		}
	}
}
namespace UnicornsCustomSeeds.SeedQuests
{
	public class CustomSeedQuest : Quest
	{
		[SaveableField("QuestData")]
		private CustomSeedQuestData _data = new CustomSeedQuestData();

		public QuestEntry customSeedEntry;

		protected override string Title => "Drop off the Mix";

		protected override string Description => $"Take {StashManager.StashQtyEntry.Value}x of your weed mix and ${StashManager.StashCostEntry.Value} dollary doos to Albert Hoovers supply stash";

		protected override void OnLoaded()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (base.QuestEntries.Count == 0)
			{
				customSeedEntry = ((Quest)this).AddEntry($"Give Albert {StashManager.StashQtyEntry.Value}x of a Weed Mix and ${StashManager.StashCostEntry.Value}", (Vector3?)((Component)StashManager.albertsStash).transform.position);
			}
		}

		protected override void OnCreated()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (base.QuestEntries.Count == 0)
			{
				customSeedEntry = ((Quest)this).AddEntry($"Give Albert {StashManager.StashQtyEntry.Value}x of a Weed Mix and ${StashManager.StashCostEntry.Value}", (Vector3?)((Component)StashManager.albertsStash).transform.position);
			}
		}
	}
	[Serializable]
	public class CustomSeedQuestData
	{
		public float quantity { get; set; } = 0f;

		public string seedId { get; set; } = string.Empty;
	}
}
namespace UnicornsCustomSeeds.Patches
{
	[HarmonyPatch(typeof(QuestManager), "OnSpawnServer")]
	public static class QuestManager_OnSpawnServer_Patch
	{
		public static void Postfix(NetworkConnection connection)
		{
			if (InstanceFinder.IsServer && QuestManager.GetQuestByName("Drop off the Mix") is CustomSeedQuest)
			{
				SeedQuestManager.BroadcastCustomQuest();
			}
		}
	}
	[HarmonyPatch(typeof(ProductManager), "OnSpawnServer")]
	public static class ProductManager_OnSpawnServer_NetTest
	{
		public static void Postfix(ProductManager __instance, NetworkConnection connection)
		{
			//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_0059: 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_006e: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			if (connection == (NetworkConnection)null || !InstanceFinder.IsServer || connection.IsHost)
			{
				return;
			}
			List<string> val = new List<string>();
			WeedAppearanceSettings val2 = new WeedAppearanceSettings(Color32.op_Implicit(__instance.DefaultWeed.MainMat.color), Color32.op_Implicit(__instance.DefaultWeed.SecondaryMat.color), Color32.op_Implicit(__instance.DefaultWeed.LeafMat.color), Color32.op_Implicit(__instance.DefaultWeed.StemMat.color));
			foreach (KeyValuePair<string, UnicornSeedData> discoveredSeed in CustomSeedsManager.DiscoveredSeeds)
			{
				__instance.CreateWeed_Server("[NET-JSON]" + JsonConvert.SerializeObject((object)discoveredSeed.Value, (Formatting)0), "ogkushseed", (EDrugType)0, val, val2);
			}
		}
	}
	[HarmonyPatch(typeof(ProductManager), "RpcLogic___CreateWeed_1777266891")]
	public static class ProductManager_RpcLogic_CreateWeed_NetTest
	{
		public static void Postfix(ProductManager __instance, NetworkConnection conn, string name, string id, EDrugType type, List<string> properties, WeedAppearanceSettings appearance)
		{
			if (id != "ogkushseed" || name == null)
			{
				return;
			}
			if (name.StartsWith("[NET-QUEST]") && InstanceFinder.IsClientOnly)
			{
				string text = name.Replace("[NET-QUEST]", "");
				try
				{
					string[] array = text.Split(',');
					if (array.Length == 3)
					{
						if (int.TryParse(array[0], out var result))
						{
							StashManager.StashCostEntry.Value = result;
						}
						if (int.TryParse(array[1], out var result2))
						{
							StashManager.StashQtyEntry.Value = result2;
						}
						if (int.TryParse(array[2], out var result3))
						{
							StashManager.SynthesizeTime.Value = result3;
						}
					}
				}
				catch (Exception e)
				{
					Utility.PrintException(e);
				}
				if ((Object)(object)StashManager.albertsStash == (Object)null)
				{
					StashManager.GetAlbertsStash();
				}
				CustomSeedQuest customSeedQuest = QuestManager.GetQuestByName("Drop off the Mix") as CustomSeedQuest;
				if (customSeedQuest == null)
				{
					SeedQuestManager.CreateQuestAsync();
				}
			}
			else
			{
				if (!name.StartsWith("[NET-JSON]"))
				{
					return;
				}
				string text2 = name.Replace("[NET-JSON]", "");
				try
				{
					UnicornSeedData unicornSeedData = JsonConvert.DeserializeObject<UnicornSeedData>(text2);
					if (Registry.ItemExists(unicornSeedData.seedId))
					{
						return;
					}
					if (!CustomSeedsManager.DiscoveredSeeds.ContainsKey(unicornSeedData.mixId))
					{
						CustomSeedsManager.DiscoveredSeeds.Add(unicornSeedData.mixId, unicornSeedData);
					}
					SeedDefinition val = CustomSeedsManager.SeedDefinitionLoader(unicornSeedData);
					if ((Object)(object)val != (Object)null)
					{
						try
						{
							WeedDefinition item = Registry.GetItem<WeedDefinition>(unicornSeedData.mixId);
							float ingredientCost = StashManager.GetIngredientCost((ProductDefinition)(object)item);
							Singleton<ManagementUtilities>.Instance.Seeds.Add(val);
							CustomSeedsManager.CreateShopListing(val, ingredientCost);
							CustomSeedsManager.AddSeedToPots(val);
							CustomSeedsManager.EnableSeedIndicator(unicornSeedData.mixId);
						}
						catch (Exception e2)
						{
							Utility.PrintException(e2);
						}
					}
					if (InstanceFinder.IsClient)
					{
						DeferredPlantsManager.TrySpawnQueuedPlants(((BaseItemDefinition)val).ID);
					}
				}
				catch (Exception e3)
				{
					Utility.PrintException(e3);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Pot), "RpcLogic___PlantSeed_Client_4077118173")]
	public static class Patch_Pot_RpcLogic___PlantSeed_Client_4077118173
	{
		public static bool Prefix(Pot __instance, NetworkConnection conn, string seedID, float normalizedSeedProgress)
		{
			if (!InstanceFinder.IsClient || InstanceFinder.IsServer)
			{
				return true;
			}
			if (DeferredPlantsManager.IsReplaying)
			{
				return true;
			}
			if (string.IsNullOrEmpty(seedID))
			{
				return true;
			}
			if (!seedID.Contains("customseeddefinition"))
			{
				return true;
			}
			if (Registry.ItemExists(seedID))
			{
				return true;
			}
			DeferredPlantsManager.AddDeferredSeed(__instance, seedID, normalizedSeedProgress);
			return false;
		}
	}
	[HarmonyPatch(typeof(Pot), "RpcLogic___SetHarvestableActive_Client_338960014")]
	public static class Patch_Pot_RpcLogic___SetHarvestableActive_Client_338960014
	{
		public static bool Prefix(Pot __instance, NetworkConnection conn, int harvestableIndex, bool active)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			if (!InstanceFinder.IsClient || InstanceFinder.IsServer)
			{
				return true;
			}
			if (DeferredPlantsManager.PendingPotGuids.Contains(((object)((BuildableItem)__instance).GUID/*cast due to .constrained prefix*/).ToString()))
			{
				DeferredPlantsManager.AddHarvestableUpdate(((object)((BuildableItem)__instance).GUID/*cast due to .constrained prefix*/).ToString(), harvestableIndex, active);
				return false;
			}
			return true;
		}
	}
	public class ProductManagerAppPatches
	{
		[HarmonyPatch(typeof(ProductManagerApp))]
		public static class ProductManagerApp_Patch
		{
			[HarmonyPrefix]
			[HarmonyPatch("Start")]
			public static bool StartPatch(ProductManagerApp __instance)
			{
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Expected O, but got Unknown
				//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e0: 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)
				if ((Object)(object)__instance != (Object)null && (Object)(object)__instance.EntryPrefab != (Object)null && (Object)(object)__instance.EntryPrefab.transform.Find("SeedIndicator") == (Object)null)
				{
					GameObject val = new GameObject("Temp");
					val.SetActive(false);
					GameObject val2 = Object.Instantiate<GameObject>(__instance.EntryPrefab, val.transform);
					ProductEntry component = __instance.EntryPrefab.GetComponent<ProductEntry>();
					GameObject val3 = Object.Instantiate<GameObject>(((Component)component.FavouriteButton).gameObject, val2.transform);
					Button component2 = val3.GetComponent<Button>();
					Object.Destroy((Object)(object)component2);
					((Object)val3).name = "SeedIndicator";
					RectTransform component3 = val3.GetComponent<RectTransform>();
					if ((Object)(object)component3 != (Object)null)
					{
						component3.anchoredPosition = new Vector2(15f, -15f);
						component3.anchorMax = new Vector2(0f, 1f);
						component3.anchorMin = new Vector2(0f, 1f);
					}
					TrySetSeedIconSprite(val3);
					__instance.EntryPrefab = val2;
					isPrefabInitialized = true;
				}
				return true;
			}

			[HarmonyPostfix]
			[HarmonyPatch("Start")]
			public static void StartPostfix(ProductManagerApp __instance)
			{
				UpdatePendingIndicators();
			}
		}

		[HarmonyPatch(typeof(ProductEntry), "Initialize")]
		public static class ProductEntry_Initialize_Patch
		{
			[HarmonyPostfix]
			public static void Postfix(ProductEntry __instance, ProductDefinition definition)
			{
				if (!((Object)(object)__instance != (Object)null) || !((Object)(object)definition != (Object)null))
				{
					return;
				}
				Transform val = ((Component)__instance).transform.Find("SeedIndicator");
				if ((Object)(object)val != (Object)null)
				{
					TrySetSeedIconSprite(((Component)val).gameObject);
					if (CustomSeedsManager.DiscoveredSeeds.ContainsKey(((BaseItemDefinition)definition).ID))
					{
						((Component)val).gameObject.SetActive(true);
					}
					else
					{
						((Component)val).gameObject.SetActive(false);
					}
				}
			}
		}

		private static bool isPrefabInitialized = false;

		private static List<GameObject> pendingIndicators = new List<GameObject>();

		private static void TrySetSeedIconSprite(GameObject indicatorObject)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)SeedVisualsManager.seedIcon == (Object)null)
				{
					SeedVisualsManager.LoadSeedMaterial();
				}
				Image component = ((Component)indicatorObject.transform.GetChild(0)).GetComponent<Image>();
				if ((Object)(object)component != (Object)null)
				{
					if ((Object)(object)SeedVisualsManager.seedIcon != (Object)null)
					{
						component.sprite = SeedVisualsManager.seedIcon;
						((Graphic)component).color = Color.white;
					}
					else if (!pendingIndicators.Contains(indicatorObject))
					{
						pendingIndicators.Add(indicatorObject);
						Utility.Log("Seed icon not loaded yet, added to pending list");
					}
				}
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
		}

		private static void UpdatePendingIndicators()
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			if (pendingIndicators.Count == 0)
			{
				return;
			}
			for (int num = pendingIndicators.Count - 1; num >= 0; num--)
			{
				GameObject val = pendingIndicators[num];
				if ((Object)(object)val == (Object)null)
				{
					pendingIndicators.RemoveAt(num);
				}
				else
				{
					try
					{
						Image component = ((Component)val.transform.GetChild(0)).GetComponent<Image>();
						if ((Object)(object)component != (Object)null && (Object)(object)SeedVisualsManager.seedIcon != (Object)null)
						{
							component.sprite = SeedVisualsManager.seedIcon;
							((Graphic)component).color = Color.white;
							pendingIndicators.RemoveAt(num);
						}
					}
					catch (Exception e)
					{
						Utility.PrintException(e);
						pendingIndicators.RemoveAt(num);
					}
				}
			}
		}

		public static void ClearPendingIndicators()
		{
			pendingIndicators.Clear();
			isPrefabInitialized = false;
		}
	}
	[HarmonyPatch(typeof(ProductDefinition), "AddRecipe")]
	public class ProductDefinition_AddRecipe_Patch
	{
		private static void Postfix(ProductDefinition __instance)
		{
			StashManager.ProcessNewRecipe(__instance);
		}
	}
	[HarmonyPatch(typeof(SendableMessage), "IsValid")]
	public class SendableMessage_IsValid_Patch
	{
		public static bool Prefix(SendableMessage __instance, ref bool __result, out string invalidReason)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			invalidReason = string.Empty;
			if (__instance.Text != null && __instance.Text == SeedQuestManager.messageId)
			{
				if (SeedQuestManager.HasActiveQuest)
				{
					invalidReason = "Seed Synthesizing is already in progress";
					__result = false;
				}
				else if ((Object)(object)DeadDrop.GetRandomEmptyDrop(((Component)Player.Local).transform.position) == (Object)null)
				{
					invalidReason = "No deaddrops are available";
					__result = false;
				}
				else if ((Object)(object)ConversationManager.albert == (Object)null || ((NPC)ConversationManager.albert).RelationData.RelationDelta < 4f)
				{
					invalidReason = "Relationship isn't good enough";
					__result = false;
				}
				else
				{
					__result = true;
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(LoadManager), "ExitToMenu")]
	public static class LoadManager_ExitToMenu_Patch
	{
		public static void Postfix(LoadManager __instance, SaveInfo autoLoadSave, Data mainMenuPopup, bool preventLeaveLobby)
		{
			List<SeedDefinition> seeds = Singleton<ManagementUtilities>.Instance.Seeds;
			List<SeedDefinition> val = new List<SeedDefinition>();
			Enumerator<SeedDefinition> enumerator = seeds.GetEnumerator();
			while (enumerator.MoveNext())
			{
				SeedDefinition current = enumerator.Current;
				if ((Object)(object)current != (Object)null && !((BaseItemDefinition)current).ID.Contains("customseeddefinition"))
				{
					val.Add(current);
				}
			}
			Singleton<ManagementUtilities>.Instance.Seeds = val;
		}
	}
	[HarmonyPatch(typeof(LoadManager), "StartGame")]
	public static class LoadManager_StartGame_Patch
	{
		public static void Postfix(LoadManager __instance)
		{
			if ((Object)(object)__instance == (Object)null || string.IsNullOrEmpty(__instance.LoadedGameFolderPath))
			{
				return;
			}
			try
			{
				string loadedGameFolderPath = __instance.LoadedGameFolderPath;
				LoadDiscoveredSeeds(loadedGameFolderPath);
				LoadActiveCooking(loadedGameFolderPath);
			}
			catch (Exception value)
			{
				MelonLogger.Error($"PersistencePatches.StartGame: {value}");
			}
		}

		private static void LoadDiscoveredSeeds(string saveFolder)
		{
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected I4, but got Unknown
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(saveFolder, "DiscoveredCustomSeeds.json");
			List<UnicornSeedData> list = new List<UnicornSeedData>();
			if (File.Exists(path))
			{
				CustomSeedsManager.FirstLoad = false;
				string text = File.ReadAllText(path);
				try
				{
					JArray val = JArray.Parse(text);
					if (((JContainer)val).Count > 0)
					{
						JToken obj = val[0];
						JObject val2 = (JObject)(object)((obj is JObject) ? obj : null);
						if (val2 != null && !val2.ContainsKey("variants"))
						{
							Utility.Success($"Migrating {((JContainer)val).Count} legacy seed records.");
							list = MigrateLegacySeedData(text, val2);
							goto IL_00d1;
						}
					}
					CustomSeedsManager.letsMigrate = false;
					list = JsonConvert.DeserializeObject<List<UnicornSeedData>>(text) ?? new List<UnicornSeedData>();
					goto IL_00d1;
					IL_00d1:
					Utility.Success($"Loaded {list.Count} custom seeds.");
				}
				catch (Exception e)
				{
					Utility.PrintException(e);
					CustomSeedsManager.FirstLoad = true;
					list = new List<UnicornSeedData>();
				}
			}
			else
			{
				CustomSeedsManager.FirstLoad = true;
			}
			foreach (UnicornSeedData item in list)
			{
				if (item == null)
				{
					continue;
				}
				EDrugType drugType = item.drugType;
				EDrugType val3 = drugType;
				switch ((int)val3)
				{
				case 0:
					if (!CustomSeedsManager.DiscoveredSeeds.ContainsKey(item.mixId))
					{
						CustomSeedsManager.DiscoveredSeeds.Add(item.mixId, item);
					}
					break;
				case 4:
					if (!CustomShroomsManager.DiscoveredShrooms.ContainsKey(item.mixId))
					{
						CustomShroomsManager.DiscoveredShrooms.Add(item.mixId, item);
					}
					break;
				case 2:
					if (!CustomCocaSeedsManager.DiscoveredCocaSeeds.ContainsKey(item.mixId))
					{
						CustomCocaSeedsManager.DiscoveredCocaSeeds.Add(item.mixId, item);
					}
					break;
				default:
					Utility.Error($"PersistencePatches: Unknown EDrugType '{item.drugType}' for seed '{item.seedId}' — skipped.");
					break;
				}
			}
		}

		private static List<UnicornSeedData> MigrateLegacySeedData(string json, JObject first)
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			List<UnicornSeedData> list = new List<UnicornSeedData>();
			if (first.ContainsKey("weedId"))
			{
				CustomSeedsManager.letsMigrate = true;
				List<LegacySeedData> list2 = JsonConvert.DeserializeObject<List<LegacySeedData>>(json) ?? new List<LegacySeedData>();
				foreach (LegacySeedData item in list2)
				{
					UnicornSeedData unicornSeedData = new UnicornSeedData
					{
						mixId = item.weedId,
						drugType = (EDrugType)0
					};
					unicornSeedData.SetSingleVariant("ogkushseed", item.seedId, item.price);
					list.Add(unicornSeedData);
				}
				return list;
			}
			CustomSeedsManager.letsMigrate = true;
			List<LegacyUnicornSeedData> list3 = JsonConvert.DeserializeObject<List<LegacyUnicornSeedData>>(json) ?? new List<LegacyUnicornSeedData>();
			foreach (LegacyUnicornSeedData item2 in list3)
			{
				UnicornSeedData unicornSeedData2 = new UnicornSeedData
				{
					mixId = item2.mixId,
					drugType = item2.drugType
				};
				string baseItemId = ResolveLegacyBaseItemId(item2);
				unicornSeedData2.SetSingleVariant(baseItemId, item2.seedId, item2.price);
				list.Add(unicornSeedData2);
			}
			return list;
		}

		private static string ResolveLegacyBaseItemId(LegacyUnicornSeedData data)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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_0024: Expected I4, but got Unknown
			EDrugType drugType = data.drugType;
			EDrugType val = drugType;
			return (int)val switch
			{
				0 => "ogkushseed", 
				4 => "sporesyringe", 
				2 => "cocaseed", 
				_ => string.Empty, 
			};
		}

		private static void LoadActiveCooking(string saveFolder)
		{
			string path = Path.Combine(saveFolder, "UnicornsActiveCooking.json");
			if (!File.Exists(path))
			{
				return;
			}
			try
			{
				string text = File.ReadAllText(path);
				List<ActiveCookingEntry> list = JsonConvert.DeserializeObject<List<ActiveCookingEntry>>(text);
				if (list == null)
				{
					return;
				}
				foreach (ActiveCookingEntry item in list)
				{
					if (!string.IsNullOrEmpty(item?.stationGuid) && !string.IsNullOrEmpty(item.mixId))
					{
						ActiveCookingRegistry.Register(item.stationGuid, item.mixId);
					}
				}
				Utility.Success($"Loaded {list.Count} active cooking entries.");
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
		}
	}
	[HarmonyPatch(typeof(ProductManager), "CreateWeed")]
	public static class Patch_ProductManager_CreateWeed
	{
		public static void Postfix(NetworkConnection conn, string name, string id, EDrugType type, List<string> properties, WeedAppearanceSettings appearance)
		{
			if (Registry.ItemExists(id + "_customseeddefinition") || !CustomSeedsManager.DiscoveredSeeds.TryGetValue(id, out var value))
			{
				return;
			}
			SeedDefinition val = CustomSeedsManager.SeedDefinitionLoader(value);
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			try
			{
				Singleton<ManagementUtilities>.Instance.Seeds.Add(val);
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
		}
	}
	[HarmonyPatch(typeof(ProductManager), "CreateCocaine")]
	public static class Patch_ProductManager_CreateCocaine
	{
		public static void Postfix(NetworkConnection conn, string name, string id, EDrugType type, List<string> properties, CocaineAppearanceSettings appearance)
		{
			if (Registry.ItemExists(id + "_customcocaseed") || !CustomCocaSeedsManager.DiscoveredCocaSeeds.TryGetValue(id, out var _))
			{
				return;
			}
			if (CustomCocaSeedsManager.factory == null)
			{
				Utility.Error("Patch_ProductManager_CreateCocaine: factory is null for '" + id + "'.");
				return;
			}
			try
			{
				ProductDefinition item = Registry.GetItem<ProductDefinition>(id);
				if ((Object)(object)item == (Object)null)
				{
					Utility.Error("Patch_ProductManager_CreateCocaine: Could not resolve ProductDefinition '" + id + "'.");
					return;
				}
				SeedDefinition val = CustomCocaSeedsManager.factory.CreateCocaSeedDefinition(item);
				if (!((Object)(object)val == (Object)null))
				{
					Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val);
					try
					{
						Singleton<ManagementUtilities>.Instance.Seeds.Add(val);
					}
					catch (Exception e)
					{
						Utility.PrintException(e);
					}
					string text = id + "_customcocaleaf";
					QualityItemDefinition item2 = Registry.GetItem<QualityItemDefinition>(text);
					if ((Object)(object)item2 != (Object)null)
					{
						CocaFactory.AddLeafToCauldrons(item2);
					}
					else
					{
						Utility.Error("Patch_ProductManager_CreateCocaine: Could not resolve leaf '" + text + "' from Registry — cauldrons will not accept this leaf.");
					}
					Utility.Log("Patch_ProductManager_CreateCocaine: Reloaded coca seed '" + ((BaseItemDefinition)val).ID + "'.");
				}
			}
			catch (Exception e2)
			{
				Utility.PrintException(e2);
			}
		}
	}
	[HarmonyPatch(typeof(ProductManager), "CreateShroom_Server")]
	public static class Patch_ProductManager_CreateShroom
	{
		public static void Postfix(string name, string id, EDrugType type, List<string> properties, ShroomAppearanceSettings appearance)
		{
			string text = id + "_customsyringedefinition";
			if (Registry.ItemExists(text) || !CustomShroomsManager.DiscoveredShrooms.TryGetValue(id, out var value))
			{
				return;
			}
			if (CustomShroomsManager.factory == null)
			{
				Utility.Error("Patch_ProductManager_CreateShroom: factory is null for '" + id + "'.");
				return;
			}
			try
			{
				SporeSyringeDefinition val = CustomShroomsManager.SyringeDefinitionLoader(value);
				if ((Object)(object)val != (Object)null)
				{
					Utility.Log("Patch_ProductManager_CreateShroom: Reloaded syringe '" + ((BaseItemDefinition)val).ID + "'.");
				}
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
		}
	}
}
namespace UnicornsCustomSeeds.Managers
{
	public static class ActiveCookingRegistry
	{
		public static readonly Dictionary<string, string> GuidToMixId = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

		public static void Register(string stationGuid, string mixId)
		{
			GuidToMixId[stationGuid] = mixId;
		}

		public static void Unregister(string stationGuid)
		{
			GuidToMixId.Remove(stationGuid);
		}

		public static string GetMixId(string stationGuid)
		{
			GuidToMixId.TryGetValue(stationGuid, out var value);
			return value;
		}

		public static void Clear()
		{
			GuidToMixId.Clear();
		}
	}
	[Serializable]
	public class ActiveCookingEntry
	{
		public string stationGuid { get; set; }

		public string mixId { get; set; }
	}
	public static class ConversationManager
	{
		public static Dictionary<string, MSGConversation> Conversations = new Dictionary<string, MSGConversation>();

		public static Albert albert;

		public static NPCRelationData albertRelation;

		public static string welcomeMessage = "A <color='#FA2FBD'><b>Unicorn</b></color> I know can synthesize your custom mixes into seeds. If you'd like to use that service, send me a text.";

		public static void Init()
		{
			albert = Object.FindObjectOfType<Albert>();
			if ((Object)(object)albert != (Object)null)
			{
				if (((NPC)albert).MSGConversation != null)
				{
					RegisterConversation("Albert", ((NPC)albert).MSGConversation);
					albertRelation = ((NPC)albert).RelationData;
				}
				if (!CustomSeedsManager.FirstLoad || ((NPC)albert).RelationData == null)
				{
					return;
				}
				if (((NPC)albert).RelationData.RelationDelta >= 4f)
				{
					MelonCoroutines.Start(WelcomeRoutine());
					return;
				}
				DialogueDatabase database = ((NPC)albert).DialogueHandler.Database;
				DialogueModule module = database.GetModule((EDialogueModule)0);
				for (int i = 0; i < module.Entries.Count; i++)
				{
					if (module.Entries[i] != null && module.Entries[i].Key == "supplier_meetings_unlocked")
					{
						Entry val = module.Entries[i];
						DialogueChain val2 = ((Il2CppArrayBase<DialogueChain>)(object)val.Chains)[0];
						if (val2 != null && ((Il2CppArrayBase<string>)(object)val2.Lines)[((Il2CppArrayBase<string>)(object)val2.Lines).Length - 1] != welcomeMessage)
						{
							string[] array = Il2CppArrayBase<string>.op_Implicit((Il2CppArrayBase<string>)(object)val2.Lines);
							string[] array2 = new string[array.Length + 1];
							array2[0] = array[0];
							array2[1] = array[1];
							array2[2] = welcomeMessage;
							val2.Lines = Il2CppStringArray.op_Implicit(array2);
						}
					}
				}
			}
			else
			{
				Utility.Error("ConversationManager: Could not find Albert or his conversation.");
			}
		}

		public static void RegisterConversation(string name, MSGConversation convo)
		{
			if (!Conversations.ContainsKey(name))
			{
				Conversations.Add(name, convo);
			}
			else
			{
				Conversations[name] = convo;
			}
		}

		public static MSGConversation GetConversation(string name)
		{
			if (Conversations.TryGetValue(name, out var value))
			{
				return value;
			}
			return null;
		}

		public static void SendMessage(string characterName, string text)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			if (!InstanceFinder.IsServer)
			{
				return;
			}
			if (Conversations.TryGetValue(characterName, out var value))
			{
				if (value != null)
				{
					value.SendMessage(new Message(text, (ESenderType)1, true, -1), true, true);
				}
			}
			else
			{
				Utility.Error("ConversationManager: Conversation for " + characterName + " not found.");
			}
		}

		public static void SendMessageChain(string characterName, List<string> messages)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			if (!InstanceFinder.IsServer)
			{
				return;
			}
			if (Conversations.TryGetValue(characterName, out var value))
			{
				if (value == null)
				{
					return;
				}
				MessageChain val = new MessageChain();
				foreach (string message in messages)
				{
					val.Messages.Add(message);
				}
				val.id = Random.Range(int.MinValue, int.MaxValue);
				value.SendMessageChain(val, 0.5f, true, true);
			}
			else
			{
				Utility.Error("Conversation for " + characterName + " not found.");
			}
		}

		public static void AlbertWelcomeMessage(EUnlockType type, bool temp)
		{
			SendMessage("Albert", welcomeMessage);
		}

		private static IEnumerator WelcomeRoutine()
		{
			yield return (object)new WaitForSeconds(10f);
			AlbertWelcomeMessage((EUnlockType)1, temp: true);
		}
	}
	public static class CustomCocaSeedsManager
	{
		public const string BASE_SEED_ID = "cocaseed";

		public const string BASE_LEAF_ID = "cocaleaf";

		public const string BASE_BASE_ID = "cocainebase";

		public static readonly string[] TEST_COCAINE_MIX_IDS = new string[6] { "bighaze", "gorillaghost", "lasmegma", "hairygold", "miraclefruit", "afghancake" };

		public static CocaFactory factory;

		public static Dictionary<string, UnicornSeedData> DiscoveredCocaSeeds = new Dictionary<string, UnicornSeedData>();

		public static ShopInterface SalvadorShop = null;

		public static Salvador salvador = null;

		public static void Initialize()
		{
			RestoreLeafFilters();
			salvador = Object.FindObjectOfType<Salvador>();
			if ((Object)(object)salvador != (Object)null)
			{
				SalvadorShop = ((Supplier)salvador).Shop;
				if ((Object)(object)SalvadorShop == (Object)null)
				{
					Utility.Error("CustomCocaSeedsManager: Salvador's shop is null!");
				}
				if (((NPC)salvador).MSGConversation != null)
				{
					ConversationManager.RegisterConversation("Salvador", ((NPC)salvador).MSGConversation);
				}
				{
					foreach (KeyValuePair<string, UnicornSeedData> discoveredCocaSeed in DiscoveredCocaSeeds)
					{
						SeedDefinition item = Registry.GetItem<SeedDefinition>(discoveredCocaSeed.Value.seedId);
						if ((Object)(object)item != (Object)null)
						{
							CreateShopListing(item, discoveredCocaSeed.Value.price);
						}
					}
					return;
				}
			}
			Utility.Error("CustomCocaSeedsManager: Could not find Salvador NPC in scene. Verify Salvador is present and unlocked.");
		}

		public static IEnumerator CreateCocaSeed(ProductDefinition cocaineDef)
		{
			yield return (object)new WaitForSeconds(5f);
			if (factory == null)
			{
				Utility.Error("CustomCocaSeedsManager: CocaFactory is null! Ensure factory was initialized in Core.OnSceneWasLoaded.");
				yield break;
			}
			if (DiscoveredCocaSeeds.ContainsKey(((BaseItemDefinition)cocaineDef).ID))
			{
				Utility.Log("CustomCocaSeedsManager: Coca seed for '" + ((BaseItemDefinition)cocaineDef).ID + "' already exists, skipping.");
				yield break;
			}
			SeedDefinition newSeed = factory.CreateCocaSeedDefinition(cocaineDef);
			if ((Object)(object)newSeed == (Object)null)
			{
				Utility.Error("CustomCocaSeedsManager: CreateCocaSeedDefinition returned null.");
				yield break;
			}
			Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)newSeed);
			Utility.Log("CustomCocaSeedsManager: Registered seed '" + ((BaseItemDefinition)newSeed).ID + "' in Registry.");
			Singleton<ManagementUtilities>.Instance.Seeds.Add(newSeed);
			CustomSeedsManager.AddSeedToPots(newSeed);
			QualityItemDefinition customLeaf = Registry.GetItem<QualityItemDefinition>(((BaseItemDefinition)cocaineDef).ID + "_customcocaleaf");
			if ((Object)(object)customLeaf != (Object)null)
			{
				CocaFactory.AddLeafToCauldrons(customLeaf);
			}
			else
			{
				Utility.Error("CustomCocaSeedsManager: Could not resolve custom leaf from Registry after registration.");
			}
			((StorableItemDefinition)newSeed).BasePurchasePrice = ((StorableItemDefinition)newSeed).BasePurchasePrice + StashManager.GetIngredientCost(cocaineDef);
			UnicornSeedData newData = new UnicornSeedData
			{
				mixId = ((BaseItemDefinition)cocaineDef).ID,
				drugType = (EDrugType)2
			};
			newData.SetSingleVariant("cocaseed", ((BaseItemDefinition)newSeed).ID, ((StorableItemDefinition)newSeed).BasePurchasePrice);
			DiscoveredCocaSeeds.Add(newData.mixId, newData);
			CreateShopListing(newSeed, newData.price);
			DeadDrop randomDrop = DeadDrop.GetRandomEmptyDrop(((Component)Player.Local).transform.position);
			if ((Object)(object)randomDrop != (Object)null && InstanceFinder.IsServer)
			{
				ItemInstance defaultInstance = ((ItemDefinition)newSeed).GetDefaultInstance(1);
				((BaseItemInstance)defaultInstance).SetQuantity(3);
				((StorageEntity)randomDrop.Storage).InsertItem(defaultInstance, true);
				string guidString = ((object)GUIDManager.GenerateUniqueGUID()/*cast due to .constrained prefix*/).ToString();
				NetworkSingleton<QuestManager>.Instance.CreateDeaddropCollectionQuest((NetworkConnection)null, ((object)randomDrop.GUID/*cast due to .constrained prefix*/).ToString(), guidString);
				ConversationManager.SendMessage("Salvador", ((Object)cocaineDef).name + " coca seed synthesized and placed in a dead drop.");
				Utility.Log($"CustomCocaSeedsManager: Placed 3x '{((BaseItemDefinition)newSeed).ID}' in dead drop '{randomDrop.GUID}'.");
			}
			else
			{
				Utility.Error("CustomCocaSeedsManager: No available dead drop for coca seed placement, or not server.");
			}
		}

		public static void CreateShopListing(SeedDefinition newSeed, float price = 10f)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)SalvadorShop == (Object)null))
			{
				ShopListing val = new ShopListing();
				val.name = $"{((BaseItemDefinition)newSeed).ID} (${price}) (Coca, )";
				val.Item = (StorableItemDefinition)(object)newSeed;
				val.IconTint = new Color(0.9f, 0.9f, 0.9f, 1f);
				val.MinimumGameCreationVersion = 27f;
				val.DefaultStock = 1000;
				val.CurrentStock = 100000;
				val.CanBeDelivered = true;
				SalvadorShop.Listings.Add(val);
				SalvadorShop.CreateListingUI(val);
				CreatePhoneShopListing(newSeed);
				CreateDeliveryListing(val);
				SalvadorShop.RefreshShownItems();
			}
		}

		public static void CreatePhoneShopListing(SeedDefinition newSeed)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if (!((Object)(object)salvador == (Object)null))
			{
				Listing val = new Listing((StorableItemDefinition)(object)newSeed);
				IEnumerable<Listing> source = CollectionExtensions.AddItem<Listing>((IEnumerable<Listing>)((Supplier)salvador).SupplierData.DeliveryShopListings, val);
				((Supplier)salvador).SupplierData.DeliveryShopListings = Il2CppReferenceArray<Listing>.op_Implicit(source.ToArray());
			}
		}

		public static void CreateDeliveryListing(ShopListing newListing)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)SalvadorShop == (Object)null))
			{
				DeliveryApp instance = PlayerSingleton<DeliveryApp>.Instance;
				DeliveryShop val = ((instance != null) ? instance.GetShop(SalvadorShop.ShopName) : null);
				if (!((Object)(object)val == (Object)null))
				{
					ListingEntry val2 = Object.Instantiate<ListingEntry>(val.ListingEntryPrefab, (Transform)(object)val.ListingContainer);
					val2.Initialize(newListing);
					val2.onQuantityChanged.AddListener(UnityAction.op_Implicit((Action)val.RefreshCart));
					val.listingEntries.Add(val2);
					val.ListingContainer.sizeDelta = new Vector2(val.ListingContainer.sizeDelta.x, 230f + (float)Math.Ceiling((double)val.listingEntries.Count / 2.0) * 60f);
				}
			}
		}

		public static void ClearAll()
		{
			DiscoveredCocaSeeds.Clear();
			SalvadorShop = null;
			salvador = null;
			if (factory != null)
			{
				factory.DeleteChildren();
			}
		}

		public static void RestoreLeafFilters()
		{
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			if (DiscoveredCocaSeeds.Count == 0)
			{
				return;
			}
			if (factory == null)
			{
				Utility.Error("CustomCocaSeedsManager.RestoreLeafFilters: factory is null \ufffd cannot restore leaf filters.");
				return;
			}
			foreach (KeyValuePair<string, UnicornSeedData> discoveredCocaSeed in DiscoveredCocaSeeds)
			{
				string key = discoveredCocaSeed.Key;
				if (!Registry.ItemExists(key + "_customcocaseed"))
				{
					ProductDefinition item = Registry.GetItem<ProductDefinition>(key);
					if ((Object)(object)item == (Object)null)
					{
						Utility.Error("CustomCocaSeedsManager.RestoreLeafFilters: ProductDefinition '" + key + "' not in Registry \ufffd skipping.");
						continue;
					}
					SeedDefinition val = factory.CreateCocaSeedDefinition(item);
					if ((Object)(object)val == (Object)null)
					{
						Utility.Error("CustomCocaSeedsManager.RestoreLeafFilters: CreateCocaSeedDefinition returned null for '" + key + "'.");
						continue;
					}
					Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val);
					CreateShopListing(val, discoveredCocaSeed.Value.price);
					Utility.Log("CustomCocaSeedsManager.RestoreLeafFilters: Rebuilt seed '" + ((BaseItemDefinition)val).ID + "'.");
				}
				string text = key + "_customcocaleaf";
				QualityItemDefinition item2 = Registry.GetItem<QualityItemDefinition>(text);
				if ((Object)(object)item2 != (Object)null)
				{
					CocaFactory.AddLeafToCauldrons(item2);
					Utility.Log("CustomCocaSeedsManager.RestoreLeafFilters: Added '" + text + "' to cauldron filters.");
				}
				else
				{
					Utility.Error("CustomCocaSeedsManager.RestoreLeafFilters: Could not resolve '" + text + "' from Registry.");
				}
			}
		}
	}
	public static class CustomShroomsManager
	{
		public const string BASE_SYRINGE_ID = "sporesyringe";

		public static SyringeFactory factory;

		public static Dictionary<string, UnicornSeedData> DiscoveredShrooms = new Dictionary<string, UnicornSeedData>();

		public static ShopInterface PhilShop = null;

		public static GameObject PhilShopGo = null;

		public static Phil phil = null;

		public static void Initialize()
		{
			phil = Object.FindObjectOfType<Phil>();
			if ((Object)(object)phil != (Object)null)
			{
				PhilShop = ((Supplier)phil).Shop;
				ShopInterface philShop = PhilShop;
				PhilShopGo = ((philShop != null) ? ((Component)philShop).gameObject : null);
				if ((Object)(object)PhilShop == (Object)null)
				{
					Utility.Error("CustomShroomsManager: Phil's shop is null!");
				}
				if (((NPC)phil).MSGConversation != null)
				{
					ConversationManager.RegisterConversation("Phil", ((NPC)phil).MSGConversation);
				}
				{
					foreach (KeyValuePair<string, UnicornSeedData> discoveredShroom in DiscoveredShrooms)
					{
						if (!Registry.ItemExists(discoveredShroom.Value.seedId))
						{
							SyringeDefinitionLoader(discoveredShroom.Value);
							continue;
						}
						SporeSyringeDefinition item = Registry.GetItem<SporeSyringeDefinition>(discoveredShroom.Value.seedId);
						AddSyringeToSpawnStations(item);
						CreateShopListing(item, discoveredShroom.Value.price);
					}
					return;
				}
			}
			Utility.Error("CustomShroomsManager: Could not find Phil.");
		}

		public static SporeSyringeDefinition SyringeDefinitionLoader(UnicornSeedData data)
		{
			if (factory == null)
			{
				Utility.Error("SyringeDefinitionLoader: factory is null for '" + data.mixId + "'.");
				return null;
			}
			ShroomDefinition item = Registry.GetItem<ShroomDefinition>(data.mixId);
			if ((Object)(object)item == (Object)null)
			{
				Utility.Error("SyringeDefinitionLoader: Could not resolve ShroomDefinition '" + data.mixId + "'.");
				return null;
			}
			SporeSyringeDefinition val = factory.CreateSyringeDefinition(item);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val);
			try
			{
				Singleton<ManagementUtilities>.Instance.MushroomSpawns.Add(val.SpawnDefinition);
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
			AddSyringeToSpawnStations(val);
			CreateShopListing(val, data.price);
			Utility.Log("SyringeDefinitionLoader: Reloaded syringe '" + ((BaseItemDefinition)val).ID + "'.");
			return val;
		}

		public static void StartSyringeCreation(ShroomDefinition shroomDef)
		{
			MelonCoroutines.Start(CreateSyringe(shroomDef));
		}

		public static IEnumerator CreateSyringe(ShroomDefinition shroomDef)
		{
			yield return (object)new WaitForSeconds(5f);
			if (factory == null)
			{
				Utility.Error("SyringeFactory is null!");
				yield break;
			}
			SporeSyringeDefinition newSyringe = factory.CreateSyringeDefinition(shroomDef);
			if ((Object)(object)newSyringe == (Object)null)
			{
				Utility.Error("Failed to create custom syringe definition.");
				yield break;
			}
			Utility.Log("Created new syringe definition: " + ((BaseItemDefinition)newSyringe).ID + " for shroom: " + ((BaseItemDefinition)shroomDef).ID);
			Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)newSyringe);
			Singleton<ManagementUtilities>.Instance.MushroomSpawns.Add(newSyringe.SpawnDefinition);
			AddSpawnToMushroomBeds(newSyringe.SpawnDefinition);
			AddSyringeToSpawnStations(newSyringe);
			((StorableItemDefinition)newSyringe).BasePurchasePrice = ((StorableItemDefinition)newSyringe).BasePurchasePrice + StashManager.GetIngredientCost((ProductDefinition)(object)shroomDef);
			UnicornSeedData newData = new UnicornSeedData
			{
				mixId = ((BaseItemDefinition)shroomDef).ID,
				drugType = (EDrugType)4
			};
			newData.SetSingleVariant("sporesyringe", ((BaseItemDefinition)newSyringe).ID, ((StorableItemDefinition)newSyringe).BasePurchasePrice);
			DiscoveredShrooms.Add(newData.mixId, newData);
			CreateShopListing(newSyringe, newData.price);
			DeadDrop randomDrop = DeadDrop.GetRandomEmptyDrop(((Component)Player.Local).transform.position);
			if ((Object)(object)randomDrop != (Object)null && InstanceFinder.IsServer)
			{
				ItemInstance defaultInstance = ((ItemDefinition)newSyringe).GetDefaultInstance(1);
				((BaseItemInstance)defaultInstance).SetQuantity(3);
				((StorageEntity)randomDrop.Storage).InsertItem(defaultInstance, true);
				string guidString = ((object)GUIDManager.GenerateUniqueGUID()/*cast due to .constrained prefix*/).ToString();
				NetworkSingleton<QuestManager>.Instance.CreateDeaddropCollectionQuest((NetworkConnection)null, ((object)randomDrop.GUID/*cast due to .constrained prefix*/).ToString(), guidString);
				ConversationManager.SendMessage("Phil", ((Object)shroomDef).name + " syringe synthesized and placed in a dead drop.");
			}
			else
			{
				Utility.Error("No available dead drop for syringe placement.");
			}
		}

		public static void AddSpawnToMushroomBeds(ShroomSpawnDefinition newSpawn)
		{
			Il2CppArrayBase<MushroomBed> val = Object.FindObjectsOfType<MushroomBed>();
			foreach (MushroomBed item in val)
			{
				MushroomBedConfiguration val2 = ((Il2CppObjectBase)item.Configuration).TryCast<MushroomBedConfiguration>();
				if (val2 != null)
				{
					val2.Spawn.Options.Add((ItemDefinition)(object)newSpawn);
				}
			}
		}

		public static void AddSyringeToSpawnStations(SporeSyringeDefinition newSyringe)
		{
			Il2CppArrayBase<MushroomSpawnStation> val = Object.FindObjectsOfType<MushroomSpawnStation>();
			foreach (MushroomSpawnStation item in val)
			{
				if (item.SyringeSlot == null)
				{
					continue;
				}
				Enumerator<ItemFilter> enumerator2 = item.SyringeSlot.HardFilters.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					ItemFilter current2 = enumerator2.Current;
					ItemFilter_ID val2 = ((Il2CppObjectBase)current2).TryCast<ItemFilter_ID>();
					if (val2 != null && !val2.IDs.Contains(((BaseItemDefinition)newSyringe).ID))
					{
						val2.IDs.Add(((BaseItemDefinition)newSyringe).ID);
					}
				}
			}
		}

		public static void CreateShopListing(SporeSyringeDefinition newSyringe, float price = 10f)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)PhilShop == (Object)null))
			{
				ShopListing val = new ShopListing();
				val.name = $"{((BaseItemDefinition)newSyringe).ID} (${price}) (Shrooms, )";
				val.Item = (StorableItemDefinition)(object)newSyringe;
				val.IconTint = new Color(0.6f, 0.2f, 0.8f, 1f);
				val.MinimumGameCreationVersion = 27f;
				val.DefaultStock = 1000;
				val.CurrentStock = 100000;
				val.CanBeDelivered = true;
				PhilShop.Listings.Add(val);
				PhilShop.CreateListingUI(val);
				CreatePhoneShopListing(newSyringe);
				CreateDeliveryListing(val);
				PhilShop.RefreshShownItems();
			}
		}

		public static void CreatePhoneShopListing(SporeSyringeDefinition newSyringe)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if (!((Object)(object)phil == (Object)null))
			{
				Listing val = new Listing((StorableItemDefinition)(object)newSyringe);
				IEnumerable<Listing> source = CollectionExtensions.AddItem<Listing>((IEnumerable<Listing>)((Supplier)phil).SupplierData.DeliveryShopListings, val);
				((Supplier)phil).SupplierData.DeliveryShopListings = Il2CppReferenceArray<Listing>.op_Implicit(source.ToArray());
			}
		}

		public static void CreateDeliveryListing(ShopListing newListing)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)PhilShop == (Object)null))
			{
				DeliveryApp instance = PlayerSingleton<DeliveryApp>.Instance;
				DeliveryShop val = ((instance != null) ? instance.GetShop(PhilShop.ShopName) : null);
				if (!((Object)(object)val == (Object)null))
				{
					ListingEntry val2 = Object.Instantiate<ListingEntry>(val.ListingEntryPrefab, (Transform)(object)val.ListingContainer);
					val2.Initialize(newListing);
					val2.onQuantityChanged.AddListener(UnityAction.op_Implicit((Action)val.RefreshCart));
					val.listingEntries.Add(val2);
					val.ListingContainer.sizeDelta = new Vector2(val.ListingContainer.sizeDelta.x, 230f + (float)Math.Ceiling((double)val.listingEntries.Count / 2.0) * 60f);
				}
			}
		}

		public static void ClearAll()
		{
			DiscoveredShrooms.Clear();
			PhilShop = null;
			PhilShopGo = null;
			phil = null;
			if (factory != null)
			{
				factory.DeleteChildren();
			}
		}
	}
	public static class DeferredPlantsManager
	{
		public struct DeferredSeedData
		{
			public Pot Pot;

			public string SeedId;

			public float Progress;
		}

		public struct HarvestableUpdateData
		{
			public int Index;

			public bool Active;
		}

		public static bool IsReplaying = false;

		public static HashSet<string> PendingPotGuids = new HashSet<string>();

		public static Dictionary<string, List<DeferredSeedData>> seedsToLoad = new Dictionary<string, List<DeferredSeedData>>();

		public static Dictionary<string, List<HarvestableUpdateData>> DeferredHarvestables = new Dictionary<string, List<HarvestableUpdateData>>();

		public static void AddDeferredSeed(Pot pot, string seedId, float progress)
		{
			//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)
			if (seedsToLoad.ContainsKey(seedId))
			{
				seedsToLoad[seedId].Add(new DeferredSeedData
				{
					Pot = pot,
					SeedId = seedId,
					Progress = progress
				});
			}
			else
			{
				List<DeferredSeedData> list = new List<DeferredSeedData>();
				list.Add(new DeferredSeedData
				{
					Pot = pot,
					SeedId = seedId,
					Progress = progress
				});
				seedsToLoad.Add(seedId, list);
			}
			PendingPotGuids.Add(((object)((BuildableItem)pot).GUID/*cast due to .constrained prefix*/).ToString());
		}

		public static void AddHarvestableUpdate(string potGuid, int index, bool active)
		{
			if (!DeferredHarvestables.ContainsKey(potGuid))
			{
				DeferredHarvestables[potGuid] = new List<HarvestableUpdateData>();
			}
			DeferredHarvestables[potGuid].Add(new HarvestableUpdateData
			{
				Index = index,
				Active = active
			});
		}

		public static void TrySpawnQueuedPlants(string seedId)
		{
			//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)
			if (!seedsToLoad.ContainsKey(seedId))
			{
				return;
			}
			List<DeferredSeedData> list = seedsToLoad[seedId];
			foreach (DeferredSeedData item in list)
			{
				item.Pot.PlantSeed_Client((NetworkConnection)null, item.SeedId, item.Progress);
				string text = ((object)((BuildableItem)item.Pot).GUID/*cast due to .constrained prefix*/).ToString();
				if (DeferredHarvestables.ContainsKey(text))
				{
					foreach (HarvestableUpdateData item2 in DeferredHarvestables[text])
					{
						item.Pot.Plant.SetHarvestableActive(item2.Index, item2.Active);
					}
					DeferredHarvestables.Remove(text);
				}
				PendingPotGuids.Remove(text);
			}
		}
	}
	public static class SeedQuestManager
	{
		public static CustomSeedQuest seedDropoff;

		public static string messageId = "Synthesize Seeds";

		public static bool IsWaitingForDropoff = false;

		private static float lastSentTime = 0f;

		public static bool HasActiveQuest => IsWaitingForDropoff;

		public static void Init()
		{
			if (QuestManager.GetQuestByName("Drop off the Mix") is CustomSeedQuest customSeedQuest)
			{
				seedDropoff = customSeedQuest;
				IsWaitingForDropoff = true;
			}
			else
			{
				IsWaitingForDropoff = false;
			}
			MSGConversation conversation = ConversationManager.GetConversation("Albert");
			if (conversation != null)
			{
				MessageSenderInterface senderInterface = conversation.senderInterface;
				SendableMessage val = conversation.CreateSendableMessage(messageId);
				val.onSent += Action.op_Implicit((Action)OnSent);
			}
		}

		public static void OnSent()
		{
			if (!InstanceFinder.IsServer || Time.time - lastSentTime < 1f)
			{
				return;
			}
			List<string> list = new List<string>();
			list.Add("Drop the weed mix and cash in my drop box.");
			ConversationManager.SendMessageChain("Albert", list);
			IsWaitingForDropoff = true;
			if (seedDropoff == null)
			{
				if (InstanceFinder.IsServer)
				{
					BroadcastCustomQuest();
				}
				seedDropoff = QuestManager.CreateQuest<CustomSeedQuest>((string)null) as CustomSeedQuest;
			}
		}

		public static void BroadcastCustomQuest()
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_00b1: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			ProductManager instance = NetworkSingleton<ProductManager>.Instance;
			string text = $"[NET-QUEST]{StashManager.StashCostEntry.Value},{StashManager.StashQtyEntry.Value},{StashManager.SynthesizeTime.Value}";
			List<string> val = new List<string>();
			WeedAppearanceSettings val2 = new WeedAppearanceSettings(Color32.op_Implicit(instance.DefaultWeed.MainMat.color), Color32.op_Implicit(instance.DefaultWeed.SecondaryMat.color), Color32.op_Implicit(instance.DefaultWeed.LeafMat.color), Color32.op_Implicit(instance.DefaultWeed.StemMat.color));
			instance.CreateWeed_Server(text, "ogkushseed", (EDrugType)0, val, val2);
		}

		public static void CreateQuestAsync()
		{
			MelonCoroutines.Start(CreateQuestCoroutine());
		}

		private static IEnumerator CreateQuestCoroutine()
		{
			int attemptCount = 0;
			while (attemptCount < 5)
			{
				attemptCount++;
				try
				{
					if (QuestManager.GetQuestByName("Drop off the Mix") is CustomSeedQuest existingQuest)
					{
						seedDropoff = existingQuest;
						IsWaitingForDropoff = true;
						yield break;
					}
					seedDropoff = QuestManager.CreateQuest<CustomSeedQuest>((string)null) as CustomSeedQuest;
					if (seedDropoff != null)
					{
						IsWaitingForDropoff = true;
						yield break;
					}
				}
				catch
				{
				}
				if (attemptCount < 5)
				{
					yield return (object)new WaitForSeconds(1f);
				}
			}
			Utility.Error($"[CreateQuestAsync] Failed to Load Quest after {5} attempts");
		}

		public static void CompleteQuest()
		{
			if (seedDropoff != null)
			{
				((Quest)seedDropoff).Complete();
				seedDropoff = null;
			}
			IsWaitingForDropoff = false;
		}

		public static void SendMessage(string text)
		{
			ConversationManager.SendMessage("Albert", text);
		}

		public static void OnSelected()
		{
			MSGConversation conversation = ConversationManager.GetConversation("Albert");
			if (conversation != null)
			{
				conversation.senderInterface.SetVisibility((EVisibility)1);
			}
		}
	}
	public static class SeedVisualsManager
	{
		public enum BlendMode
		{
			Lerp,
			Multiply,
			Add,
			Screen
		}

		public static Dictionary<string, Sprite> seedIcons = new Dictionary<string, Sprite>();

		public static Dictionary<string, WeedAppearanceSettings> appearanceMap = new Dictionary<string, WeedAppearanceSettings>();

		public static Shader customShader;

		public static Material customMat;

		public static Sprite baseSeedSprite;

		public static Sprite seedIcon;

		public static BlendMode blendMode = BlendMode.Lerp;

		public static Rect gradientArea01 = new Rect(0.37f, 0.312f, 0.24f, 0.38f);

		public static float gradientOpacity = 1f;

		public static void LoadSeedMaterial()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			try

UnicornsCustomSeeds_Mono_1.1.2.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using FishNet;
using FishNet.Connection;
using FluffyUnderware.DevTools.Extensions;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using S1API.Quests;
using S1API.Saveables;
using ScheduleOne;
using ScheduleOne.AvatarFramework.Equipping;
using ScheduleOne.Core.Items.Framework;
using ScheduleOne.DevUtilities;
using ScheduleOne.Dialogue;
using ScheduleOne.Economy;
using ScheduleOne.EntityFramework;
using ScheduleOne.Equipping;
using ScheduleOne.Growing;
using ScheduleOne.ItemFramework;
using ScheduleOne.Management;
using ScheduleOne.Messaging;
using ScheduleOne.NPCs;
using ScheduleOne.NPCs.CharacterClasses;
using ScheduleOne.NPCs.Relation;
using ScheduleOne.ObjectScripts;
using ScheduleOne.Persistence;
using ScheduleOne.PlayerScripts;
using ScheduleOne.PlayerTasks;
using ScheduleOne.Product;
using ScheduleOne.Quests;
using ScheduleOne.StationFramework;
using ScheduleOne.Storage;
using ScheduleOne.UI.MainMenu;
using ScheduleOne.UI.Phone;
using ScheduleOne.UI.Phone.Delivery;
using ScheduleOne.UI.Phone.Messages;
using ScheduleOne.UI.Phone.ProductManagerApp;
using ScheduleOne.UI.Shop;
using UnicornsCustomSeeds;
using UnicornsCustomSeeds.Managers;
using UnicornsCustomSeeds.Patches;
using UnicornsCustomSeeds.SeedQuests;
using UnicornsCustomSeeds.Seeds;
using UnicornsCustomSeeds.TemplateUtils;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "Unicorns Custom Seeds", "1.1.2", "OverweightUnicorn", null)]
[assembly: MelonColor(255, 191, 0, 255)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ScheduleOne.Core")]
[assembly: AssemblyCompany("UnicornsCustomSeeds_Mono_1.1.2")]
[assembly: AssemblyConfiguration("MONO")]
[assembly: AssemblyFileVersion("1.1.2")]
[assembly: AssemblyInformationalVersion("1.0.0+fa9d831ee061a32a32b6003c2f58a81608632142")]
[assembly: AssemblyProduct("UnicornsCustomSeeds_Mono_1.1.2")]
[assembly: AssemblyTitle("UnicornsCustomSeeds_Mono_1.1.2")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.0")]
[module: UnverifiableCode]
[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 UnicornsCustomSeeds
{
	public static class BuildInfo
	{
		public const string Name = "Unicorns Custom Seeds";

		public const string Description = "Your good buddy Unicorn can help you synthesize seeds";

		public const string Author = "OverweightUnicorn";

		public const string Company = "UnicornsCanMod";

		public const string Version = "1.1.2";

		public const string DownloadLink = null;
	}
	public class Core : MelonMod
	{
		public override void OnInitializeMelon()
		{
			AssetBundleUtils.Initialize(this);
		}

		public override void OnLateInitializeMelon()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			StashManager.InitializeConfig();
			SeedVisualsManager.LoadSeedMaterial();
			Singleton<LoadManager>.Instance.onLoadComplete.AddListener(new UnityAction(InitMod));
			Singleton<SaveManager>.Instance.onSaveComplete.AddListener(new UnityAction(SaveData));
		}

		public void SaveData()
		{
			try
			{
				string loadedGameFolderPath = Singleton<LoadManager>.Instance.LoadedGameFolderPath;
				if (string.IsNullOrEmpty(loadedGameFolderPath) || !Directory.Exists(loadedGameFolderPath))
				{
					return;
				}
				List<UnicornSeedData> list = new List<UnicornSeedData>();
				list.AddRange(CustomSeedsManager.DiscoveredSeeds.Values);
				list.AddRange(CustomShroomsManager.DiscoveredShrooms.Values);
				list.AddRange(CustomCocaSeedsManager.DiscoveredCocaSeeds.Values);
				string contents = JsonConvert.SerializeObject((object)list, (Formatting)1);
				File.WriteAllText(Path.Combine(loadedGameFolderPath, "DiscoveredCustomSeeds.json"), contents);
				List<ActiveCookingEntry> list2 = new List<ActiveCookingEntry>();
				foreach (KeyValuePair<string, string> item in ActiveCookingRegistry.GuidToMixId)
				{
					list2.Add(new ActiveCookingEntry
					{
						stationGuid = item.Key,
						mixId = item.Value
					});
				}
				string contents2 = JsonConvert.SerializeObject((object)list2, (Formatting)1);
				File.WriteAllText(Path.Combine(loadedGameFolderPath, "UnicornsActiveCooking.json"), contents2);
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
		}

		public void InitMod()
		{
			CustomSeedsManager.Initialize();
			CustomShroomsManager.Initialize();
			CustomCocaSeedsManager.Initialize();
			StashManager.GetAlbertsStash();
			if (CustomSeedsManager.letsMigrate)
			{
				if (CustomSeedsManager.DiscoveredSeeds.Count > 0 || CustomShroomsManager.DiscoveredShrooms.Count > 0 || CustomCocaSeedsManager.DiscoveredCocaSeeds.Count > 0)
				{
					SaveData();
				}
				else
				{
					Utility.Error("Core: migration was flagged but nothing loaded — skipping the save so the existing file isn't overwritten with an empty list.");
				}
				Utility.Success($"Successfully migrated {CustomSeedsManager.DiscoveredSeeds.Count} seed(s)");
				CustomSeedsManager.letsMigrate = false;
			}
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			SeedDefinition item = Registry.GetItem<SeedDefinition>("ogkushseed");
			if (CustomSeedsManager.factory == null && (Object)(object)item != (Object)null)
			{
				CustomSeedsManager.factory = new SeedFactory(item);
			}
			SporeSyringeDefinition item2 = Registry.GetItem<SporeSyringeDefinition>("sporesyringe");
			if (CustomShroomsManager.factory == null && (Object)(object)item2 != (Object)null)
			{
				CustomShroomsManager.factory = new SyringeFactory(item2);
			}
			Dictionary<int, ItemRegister> itemDictionary = Singleton<Registry>.Instance.ItemDictionary;
			SeedDefinition item3 = Registry.GetItem<SeedDefinition>("cocaseed");
			QualityItemDefinition item4 = Registry.GetItem<QualityItemDefinition>("cocaleaf");
			QualityItemDefinition item5 = Registry.GetItem<QualityItemDefinition>("cocainebase");
			if (CustomCocaSeedsManager.factory == null && (Object)(object)item3 != (Object)null && (Object)(object)item4 != (Object)null && (Object)(object)item5 != (Object)null)
			{
				CustomCocaSeedsManager.factory = new CocaFactory(item3, item4, item5);
			}
			else if (CustomCocaSeedsManager.factory == null)
			{
				Utility.Error($"Core: CocaFactory init failed — cocaseed={(Object)(object)item3 != (Object)null}, cocaleaf={(Object)(object)item4 != (Object)null}, cocainebase={(Object)(object)item5 != (Object)null}");
			}
			StashManager.GetAlbertsStash();
			if (sceneName.ToLower() != "main")
			{
				CustomSeedsManager.ClearAll();
				CustomShroomsManager.ClearAll();
				CustomCocaSeedsManager.ClearAll();
				ActiveCookingRegistry.Clear();
				ProductManagerAppPatches.ClearPendingIndicators();
				StashManager.ClearCaches();
			}
			else if ((Object)(object)SeedVisualsManager.seedIcon == (Object)null || (Object)(object)SeedVisualsManager.baseSeedSprite == (Object)null)
			{
				SeedVisualsManager.LoadSeedMaterial();
			}
		}
	}
}
namespace UnicornsCustomSeeds.TemplateUtils
{
	public static class AssetBundleUtils
	{
		private static Core mod;

		private static MelonAssembly melonAssembly;

		private static Dictionary<string, AssetBundle> assetBundles = new Dictionary<string, AssetBundle>();

		private static string DataFolderName = "UnicornsCanBundle";

		private static string ModFolderName = "UnicornsCustomSeeds";

		public static void Initialize(Core coreMod)
		{
			mod = coreMod;
			melonAssembly = ((MelonBase)mod).MelonAssembly;
		}

		public static AssetBundle LoadAssetBundle(string bundleFileName)
		{
			if (assetBundles.TryGetValue(bundleFileName, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			try
			{
				string text = typeof(Core).Namespace + ".Assets." + bundleFileName;
				Stream manifestResourceStream = melonAssembly.Assembly.GetManifestResourceStream(text ?? "");
				if (manifestResourceStream == null)
				{
					((MelonBase)mod).Unregister("AssetBundle resource '" + text + "' not found.", false);
					return null;
				}
				byte[] array;
				using (manifestResourceStream)
				{
					using MemoryStream memoryStream = new MemoryStream();
					manifestResourceStream.CopyTo(memoryStream);
					array = memoryStream.ToArray();
				}
				if (array.Length == 0)
				{
					((MelonBase)mod).Unregister("AssetBundle '" + bundleFileName + "' is empty.", false);
					return null;
				}
				AssetBundle val = AssetBundle.LoadFromMemory(array);
				if ((Object)(object)val == (Object)null)
				{
					((MelonBase)mod).Unregister("Failed to load required AssetBundle '" + bundleFileName + "'.", false);
					return null;
				}
				assetBundles[bundleFileName] = val;
				return val;
			}
			catch (Exception arg)
			{
				((MelonBase)mod).Unregister($"Failed to load required AssetBundle '{bundleFileName}': {arg}", false);
				return null;
			}
		}

		public static void ClearCache()
		{
			assetBundles.Clear();
		}

		public static AssetBundle GetLoadedAssetBundle(string bundleName)
		{
			if (assetBundles.ContainsKey(bundleName))
			{
				return assetBundles[bundleName];
			}
			MelonLogger.Warning("Asset bundle '" + bundleName + "' is not loaded.");
			return null;
		}

		public static T LoadAssetFromBundle<T>(string assetName, string bundleName) where T : Object
		{
			AssetBundle loadedAssetBundle = GetLoadedAssetBundle(bundleName);
			if ((Object)(object)loadedAssetBundle == (Object)null)
			{
				MelonLogger.Error("Couldn't find loaded bundle '" + bundleName + "'.");
				return default(T);
			}
			T val = default(T);
			try
			{
				val = loadedAssetBundle.LoadAsset<T>(assetName);
			}
			catch (Exception arg)
			{
				MelonLogger.Error($"Failed loading asset '{assetName}' from bundle '{bundleName}'. The bundle may be invalid or have a zero internal pointer. {arg}");
				return default(T);
			}
			if ((Object)(object)val == (Object)null)
			{
				MelonLogger.Error("Asset '" + assetName + "' not found in bundle '" + bundleName + "'.");
				return default(T);
			}
			return val;
		}

		public static Texture2D LoadTextureContaining(string bundleName, params string[] contains)
		{
			AssetBundle loadedAssetBundle = GetLoadedAssetBundle(bundleName);
			if ((Object)(object)loadedAssetBundle == (Object)null)
			{
				return null;
			}
			string[] allAssetNames = loadedAssetBundle.GetAllAssetNames();
			for (int i = 0; i < allAssetNames.Length; i++)
			{
				string text = allAssetNames[i].ToLowerInvariant();
				bool flag = true;
				for (int j = 0; j < contains.Length; j++)
				{
					if (!text.Contains(contains[j].ToLowerInvariant()))
					{
						flag = false;
						break;
					}
				}
				if (!flag)
				{
					continue;
				}
				try
				{
					Texture2D val = loadedAssetBundle.LoadAsset<Texture2D>(allAssetNames[i]);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Warning("Failed loading texture '" + allAssetNames[i] + "' from bundle '" + bundleName + "': " + ex.Message);
				}
			}
			return null;
		}
	}
	public static class Utility
	{
		public static void PrintException(Exception e)
		{
			MelonLogger.Msg(ConsoleColor.Red, e.GetType().FullName);
			MelonLogger.Msg(ConsoleColor.DarkRed, e.Message);
			if (!string.IsNullOrWhiteSpace(e.StackTrace))
			{
				MelonLogger.Msg(ConsoleColor.DarkRed, "StackTrace:");
				string[] array = e.StackTrace.Split('\n');
				foreach (string text in array)
				{
					MelonLogger.Msg(ConsoleColor.DarkRed, "    " + text.Trim());
				}
			}
			if (e.InnerException != null)
			{
				MelonLogger.Msg(ConsoleColor.DarkRed, "  -- Inner Exception --");
				PrintException(e.InnerException);
			}
		}

		public static void Error(string msg)
		{
			MelonLogger.Msg(ConsoleColor.Red, msg);
		}

		public static void Log(string msg)
		{
			MelonLogger.Msg(ConsoleColor.DarkMagenta, msg);
		}

		public static void Success(string msg)
		{
			MelonLogger.Msg(ConsoleColor.Green, msg);
		}
	}
}
namespace UnicornsCustomSeeds.Seeds
{
	public class CocaFactory
	{
		public static readonly Dictionary<string, string> CustomLeafIdToBaseId = new Dictionary<string, string>();

		public static readonly Dictionary<string, string> CustomBaseIdToMixId = new Dictionary<string, string>();

		private Transform rootGameObject;

		private SeedDefinition baseSeedDefinition;

		private CocaPlant baseCocaPlantPrefab;

		private PlantHarvestable baseHarvestable;

		private FunctionalSeed baseFunctionalSeedPrefab;

		private Equippable_Seed baseEquippableSeedPrefab;

		private AvatarEquippable baseAvatarEquippablePrefab;

		private StoredItem baseStoredItem;

		private QualityItemDefinition baseCocaLeafDefinition;

		private QualityItemDefinition baseCocaineBaseDefinition;

		public CocaFactory(SeedDefinition baseSeed, QualityItemDefinition baseCocaLeaf, QualityItemDefinition baseCocaineBase)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			baseSeedDefinition = baseSeed;
			baseCocaLeafDefinition = baseCocaLeaf;
			baseCocaineBaseDefinition = baseCocaineBase;
			baseCocaPlantPrefab = (CocaPlant)baseSeed.PlantPrefab;
			if ((Object)(object)baseCocaPlantPrefab == (Object)null)
			{
				Utility.Error("CocaFactory: Failed to cast PlantPrefab to CocaPlant.");
			}
			baseHarvestable = baseCocaPlantPrefab?.Harvestable;
			baseFunctionalSeedPrefab = baseSeed.FunctionSeedPrefab;
			baseStoredItem = ((StorableItemDefinition)baseSeed).StoredItem;
			baseEquippableSeedPrefab = (Equippable_Seed)((ItemDefinition)baseSeed).Equippable;
			if ((Object)(object)baseEquippableSeedPrefab == (Object)null)
			{
				Utility.Error("CocaFactory: Failed to cast Equippable to Equippable_Seed.");
			}
			baseAvatarEquippablePrefab = ((Equippable_Viewmodel)(baseEquippableSeedPrefab?)).AvatarEquippable;
			GameObject val = new GameObject(((BaseItemDefinition)baseSeedDefinition).ID + "_CustomCocaSeeds");
			val.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val);
			rootGameObject = val.transform;
		}

		public void DeleteChildren()
		{
			TransformExt.DeleteChildren(rootGameObject, true, false);
			CustomLeafIdToBaseId.Clear();
			CustomBaseIdToMixId.Clear();
		}

		public SeedDefinition CreateCocaSeedDefinition(ProductDefinition cocaineDef)
		{
			if ((Object)(object)baseSeedDefinition == (Object)null)
			{
				throw new InvalidOperationException("Base seed definition not initialized.");
			}
			QualityItemDefinition val = CloneCustomCocaineBase(cocaineDef);
			QualityItemDefinition val2 = CloneCustomCocaLeaf(val, cocaineDef);
			CocaPlant plantPrefab = CloneCocaPlant(val2);
			SeedDefinition val3 = Object.Instantiate<SeedDefinition>(baseSeedDefinition);
			((BaseItemDefinition)val3).ID = ((BaseItemDefinition)cocaineDef).ID + "_customcocaseed";
			((Object)val3).name = ((BaseItemDefinition)val3).ID;
			((BaseItemDefinition)val3).Name = ((Object)cocaineDef).name + " Coca Seed";
			((BaseItemDefinition)val3).Description = "A custom coca seed that produces " + ((Object)cocaineDef).name + ".";
			((BaseItemDefinition)val3).Icon = ((BaseItemDefinition)baseSeedDefinition).Icon;
			val3.PlantPrefab = (Plant)(object)plantPrefab;
			val3.PlantPrefab.SeedDefinition = val3;
			val3.FunctionSeedPrefab = CloneFunctionalSeedPrefab(((BaseItemDefinition)val3).ID);
			((Object)val3.FunctionSeedPrefab).name = ((BaseItemDefinition)cocaineDef).ID + "CocaSeed_Functional";
			((ItemDefinition)val3).Equippable = (Equippable)(object)CloneEquippableSeedPrefab(val3);
			((StorableItemDefinition)val3).StoredItem = CloneStoredItem(((BaseItemDefinition)val3).ID);
			Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val2);
			Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val);
			Utility.Log("CocaFactory: " + ((BaseItemDefinition)val3).ID + " ? leaf:" + ((BaseItemDefinition)val2).ID + " ? base:" + ((BaseItemDefinition)val).ID + " ? mix:" + ((BaseItemDefinition)cocaineDef).ID);
			return val3;
		}

		private QualityItemDefinition CloneCustomCocaineBase(ProductDefinition cocaineDef)
		{
			QualityItemDefinition val = Object.Instantiate<QualityItemDefinition>(baseCocaineBaseDefinition);
			((BaseItemDefinition)val).ID = ((BaseItemDefinition)cocaineDef).ID + "_customcocainebase";
			((Object)val).name = ((BaseItemDefinition)val).ID;
			((BaseItemDefinition)val).Name = ((Object)cocaineDef).name + " Base";
			if ((Object)(object)((StorableItemDefinition)baseCocaineBaseDefinition).StationItem != (Object)null)
			{
				StationItem val2 = Object.Instantiate<StationItem>(((StorableItemDefinition)baseCocaineBaseDefinition).StationItem, rootGameObject);
				((Object)val2).name = ((BaseItemDefinition)cocaineDef).ID + "_CocaineBaseStationItem";
				CookableModule module = val2.GetModule<CookableModule>();
				if ((Object)(object)module != (Object)null)
				{
					module.Product = (StorableItemDefinition)(object)cocaineDef;
					Utility.Log("CocaFactory: Set CookableModule.Product = " + ((BaseItemDefinition)cocaineDef).ID);
				}
				else
				{
					Utility.Error("CocaFactory: No CookableModule on StationItem for " + ((BaseItemDefinition)cocaineDef).ID + ". LabOven will output vanilla product.");
				}
				((StorableItemDefinition)val).StationItem = val2;
			}
			else
			{
				Utility.Error("CocaFactory: baseCocaineBaseDefinition.StationItem is null.");
			}
			CustomBaseIdToMixId[((BaseItemDefinition)val).ID] = ((BaseItemDefinition)cocaineDef).ID;
			return val;
		}

		private QualityItemDefinition CloneCustomCocaLeaf(QualityItemDefinition customBase, ProductDefinition cocaineDef)
		{
			QualityItemDefinition val = Object.Instantiate<QualityItemDefinition>(baseCocaLeafDefinition);
			((BaseItemDefinition)val).ID = ((BaseItemDefinition)cocaineDef).ID + "_customcocaleaf";
			((Object)val).name = ((BaseItemDefinition)val).ID;
			((BaseItemDefinition)val).Name = "Coca Leaf (" + ((Object)cocaineDef).name + ")";
			((StorableItemDefinition)val).StationItem = ((StorableItemDefinition)baseCocaLeafDefinition).StationItem;
			CustomLeafIdToBaseId[((BaseItemDefinition)val).ID] = ((BaseItemDefinition)customBase).ID;
			return val;
		}

		private CocaPlant CloneCocaPlant(QualityItemDefinition customLeaf)
		{
			CocaPlant val = Object.Instantiate<CocaPlant>(baseCocaPlantPrefab, rootGameObject);
			((Object)((Component)val).gameObject).name = ((BaseItemDefinition)customLeaf).ID + "_CocaPlant";
			PlantHarvestable val2 = Object.Instantiate<PlantHarvestable>(baseHarvestable, rootGameObject);
			((Object)((Component)val2).gameObject).name = ((BaseItemDefinition)customLeaf).ID + "_Harvestable";
			val2.Product = (StorableItemDefinition)(object)customLeaf;
			val.Harvestable = val2;
			PlantHarvestable[] componentsInChildren = ((Component)val).GetComponentsInChildren<PlantHarvestable>();
			foreach (PlantHarvestable val3 in componentsInChildren)
			{
				val3.Product = (StorableItemDefinition)(object)customLeaf;
			}
			return val;
		}

		private FunctionalSeed CloneFunctionalSeedPrefab(string seedDefId)
		{
			if ((Object)(object)baseFunctionalSeedPrefab == (Object)null)
			{
				throw new InvalidOperationException("Base functional seed prefab not initialized.");
			}
			FunctionalSeed val = Object.Instantiate<FunctionalSeed>(baseFunctionalSeedPrefab, rootGameObject);
			((Object)((Component)val).gameObject).name = seedDefId + "_Functional";
			return val;
		}

		private Equippable_Seed CloneEquippableSeedPrefab(SeedDefinition newDef)
		{
			if ((Object)(object)baseEquippableSeedPrefab == (Object)null)
			{
				throw new InvalidOperationException("Base equippable seed prefab not initialized.");
			}
			Equippable_Seed val = Object.Instantiate<Equippable_Seed>(baseEquippableSeedPrefab, rootGameObject);
			((Object)((Component)val).gameObject).name = ((BaseItemDefinition)newDef).ID + "_Equippable";
			((Component)val).gameObject.layer = ((Component)baseEquippableSeedPrefab).gameObject.layer;
			val.Seed = newDef;
			((Equippable_Viewmodel)val).AvatarEquippable = CloneAvatarEquippablePrefab(((BaseItemDefinition)newDef).ID);
			((Object)((Equippable_Viewmodel)val).AvatarEquippable).name = ((BaseItemDefinition)newDef).ID + "_AvatarEquippable";
			return val;
		}

		private AvatarEquippable CloneAvatarEquippablePrefab(string newDefId)
		{
			if ((Object)(object)baseAvatarEquippablePrefab == (Object)null)
			{
				throw new InvalidOperationException("Base avatar equippable prefab not initialized.");
			}
			AvatarEquippable val = Object.Instantiate<AvatarEquippable>(baseAvatarEquippablePrefab, rootGameObject);
			((Object)((Component)val).gameObject).name = newDefId + "_AvatarEquippable";
			return val;
		}

		private StoredItem CloneStoredItem(string newDefId)
		{
			if ((Object)(object)baseStoredItem == (Object)null)
			{
				throw new InvalidOperationException("Base stored item not initialized.");
			}
			StoredItem val = Object.Instantiate<StoredItem>(baseStoredItem, rootGameObject);
			((Object)((Component)val).gameObject).name = newDefId + "_StoredItem";
			return val;
		}

		public static void AddLeafToCauldrons(QualityItemDefinition customLeaf)
		{
			Cauldron[] array = Object.FindObjectsOfType<Cauldron>();
			int num = 0;
			Cauldron[] array2 = array;
			foreach (Cauldron val in array2)
			{
				ItemSlot[] ingredientSlots = val.IngredientSlots;
				foreach (ItemSlot val2 in ingredientSlots)
				{
					foreach (ItemFilter hardFilter in val2.HardFilters)
					{
						ItemFilter_ID val3 = (ItemFilter_ID)(object)((hardFilter is ItemFilter_ID) ? hardFilter : null);
						if (val3 != null && !val3.IDs.Contains(((BaseItemDefinition)customLeaf).ID))
						{
							val3.IDs.Add(((BaseItemDefinition)customLeaf).ID);
							num++;
						}
					}
				}
			}
			Utility.Log($"CocaFactory: Added '{((BaseItemDefinition)customLeaf).ID}' to {num} cauldron slot filter(s).");
		}
	}
	public class SyringeFactory
	{
		private Transform rootGameObject;

		private SporeSyringeDefinition baseSyringeDef;

		private ShroomSpawnDefinition baseSpawnDefinition;

		private ShroomColony baseColonyPrefab;

		private ShroomDefinition baseShroomDef;

		private SpawnChunk baseChunkPrefab;

		public SyringeFactory(SporeSyringeDefinition baseSyringe)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			baseSyringeDef = baseSyringe;
			baseSpawnDefinition = baseSyringe.SpawnDefinition;
			baseColonyPrefab = baseSpawnDefinition.ColonyPrefab;
			baseShroomDef = baseSpawnDefinition.Shroom;
			baseChunkPrefab = baseSpawnDefinition.ChunkPrefab;
			GameObject val = new GameObject(((BaseItemDefinition)baseSyringeDef).ID + "_CustomSyringes");
			val.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val);
			rootGameObject = val.transform;
		}

		public SporeSyringeDefinition CreateSyringeDefinition(ShroomDefinition shroomDef)
		{
			if ((Object)(object)baseSyringeDef == (Object)null)
			{
				throw new InvalidOperationException("Base syringe definition not initialized.");
			}
			SporeSyringeDefinition val = Object.Instantiate<SporeSyringeDefinition>(baseSyringeDef);
			((BaseItemDefinition)val).ID = ((BaseItemDefinition)shroomDef).ID + "_customsyringedefinition";
			((Object)val).name = ((BaseItemDefinition)val).ID;
			((BaseItemDefinition)val).Name = ((Object)shroomDef).name + " Spore Syringe";
			ShroomSpawnDefinition val2 = (val.SpawnDefinition = CloneSpawnDefinition(((BaseItemDefinition)shroomDef).ID, shroomDef));
			Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val2);
			Utility.Log("Registered ShroomSpawnDefinition: " + ((BaseItemDefinition)val2).ID);
			return val;
		}

		private ShroomSpawnDefinition CloneSpawnDefinition(string shroomId, ShroomDefinition shroomDef)
		{
			ShroomSpawnDefinition val = Object.Instantiate<ShroomSpawnDefinition>(baseSpawnDefinition);
			((BaseItemDefinition)val).ID = shroomId + "_customspawndefinition";
			((Object)val).name = ((BaseItemDefinition)val).ID;
			((BaseItemDefinition)val).Name = ((Object)shroomDef).name + " Spawn";
			val.Shroom = shroomDef;
			ShroomColony val2 = Object.Instantiate<ShroomColony>(baseColonyPrefab, rootGameObject);
			((Object)((Component)val2).gameObject).name = shroomId + "_Colony";
			val2._spawnDefinition = val;
			val.ColonyPrefab = val2;
			return val;
		}

		public void DeleteChildren()
		{
			TransformExt.DeleteChildren(rootGameObject, true, false);
		}
	}
	[Serializable]
	internal class LegacySeedData
	{
		public string seedId { get; set; }

		public string weedId { get; set; }

		public string baseSeedId { get; set; }

		public float price { get; set; }
	}
	[Serializable]
	internal class LegacyUnicornSeedData
	{
		public string seedId { get; set; }

		public string mixId { get; set; }

		public EDrugType drugType { get; set; }

		public float price { get; set; }
	}
	[Serializable]
	public class VariantSeedData
	{
		public string baseItemId { get; set; }

		public string seedId { get; set; }

		public float price { get; set; }
	}
	[Serializable]
	public class UnicornSeedData
	{
		public string mixId { get; set; }

		public EDrugType drugType { get; set; }

		public List<VariantSeedData> variants { get; set; } = new List<VariantSeedData>();

		[JsonIgnore]
		public string seedId => variants.FirstOrDefault()?.seedId;

		[JsonIgnore]
		public float price => variants.FirstOrDefault()?.price ?? 0f;

		public VariantSeedData GetVariant(string baseItemId)
		{
			return variants.FirstOrDefault((VariantSeedData v) => v.baseItemId == baseItemId);
		}

		public void SetSingleVariant(string baseItemId, string itemSeedId, float variantPrice)
		{
			variants = new List<VariantSeedData>
			{
				new VariantSeedData
				{
					baseItemId = baseItemId,
					seedId = itemSeedId,
					price = variantPrice
				}
			};
		}
	}
	public class SeedFactory
	{
		private Transform rootGameObject;

		private WeedPlant basePlantPrefab;

		private PlantHarvestable baseBranchPrefab;

		private FunctionalSeed baseFunctionalSeedPrefab;

		private Equippable_Seed baseEquippableSeedPrefab;

		private AvatarEquippable baseAvatarEquippablePrefab;

		private StoredItem baseStorableItem;

		public SeedDefinition baseSeedDefinition;

		public SeedFactory(SeedDefinition seedDefinition)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			baseSeedDefinition = seedDefinition;
			baseFunctionalSeedPrefab = seedDefinition.FunctionSeedPrefab;
			baseStorableItem = ((StorableItemDefinition)seedDefinition).StoredItem;
			InitializeBasePlant(seedDefinition);
			InitializeEquippable(seedDefinition);
			if ((Object)(object)rootGameObject == (Object)null)
			{
				GameObject val = new GameObject(((BaseItemDefinition)baseSeedDefinition).ID + "_CustomSeeds");
				val.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)val);
				rootGameObject = val.transform;
			}
		}

		private void InitializeBasePlant(SeedDefinition seedDefinition)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			WeedPlant val = (WeedPlant)seedDefinition.PlantPrefab;
			if ((Object)(object)val != (Object)null)
			{
				basePlantPrefab = val;
				if ((Object)(object)basePlantPrefab != (Object)null)
				{
					baseBranchPrefab = basePlantPrefab.BranchPrefab;
				}
			}
			else
			{
				Utility.Log("Failed to cast PlantPrefab to WeedPlant.");
			}
		}

		private void InitializeEquippable(SeedDefinition seedDefinition)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			Equippable_Seed val = (Equippable_Seed)((ItemDefinition)seedDefinition).Equippable;
			if ((Object)(object)val != (Object)null)
			{
				baseEquippableSeedPrefab = val;
				baseAvatarEquippablePrefab = ((Equippable_Viewmodel)val).AvatarEquippable;
			}
			else
			{
				Utility.Log("Failed to cast Equippable to Equippable_Seed.");
			}
		}

		public void DeleteChildren()
		{
			TransformExt.DeleteChildren(rootGameObject, true, false);
		}

		private void GrowLabel(Transform root, string seedDefId)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			Transform val = null;
			Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>();
			Transform[] array = componentsInChildren;
			foreach (Transform val2 in array)
			{
				if (((Object)val2).name == "Label")
				{
					val = ((Component)val2).transform;
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				val.localScale = new Vector3(1.05f, 1.05f, 2f);
				val.position = new Vector3(0f, -0.05f, 0f);
				if ((Object)(object)SeedVisualsManager.customMat == (Object)null)
				{
					SeedVisualsManager.LoadSeedMaterial();
				}
				if ((Object)(object)SeedVisualsManager.customMat != (Object)null)
				{
					Renderer component = ((Component)val).GetComponent<Renderer>();
					component.material = SeedVisualsManager.customMat;
					((Component)val).gameObject.AddComponent<SeedVialLabel>();
					((Object)val).name = ((Object)val).name + ":" + seedDefId;
				}
				else
				{
					Utility.Log("MATERIAL NOT LOADED!!!");
				}
			}
		}

		public WeedPlant ClonePlantPrefab(WeedDefinition newDef)
		{
			if ((Object)(object)basePlantPrefab == (Object)null)
			{
				throw new InvalidOperationException("Base plant prefab not initialized.");
			}
			WeedPlant val = Object.Instantiate<WeedPlant>(basePlantPrefab, rootGameObject);
			SetPlantAppearance(newDef, val);
			PlantHarvestable val2 = CloneBranchPrefab(newDef);
			SetBranchAppearance(((Component)val2).transform, newDef);
			val.BranchPrefab = val2;
			PlantHarvestable[] componentsInChildren = ((Component)val).GetComponentsInChildren<PlantHarvestable>();
			PlantHarvestable[] array = componentsInChildren;
			foreach (PlantHarvestable val3 in array)
			{
				val3.Product = (StorableItemDefinition)(object)newDef;
			}
			return val;
		}

		public void SetPlantAppearance(WeedDefinition newDef, WeedPlant plant)
		{
			//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_00f8: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			PlantGrowthStage[] growthStages = ((Plant)plant).GrowthStages;
			foreach (PlantGrowthStage val in growthStages)
			{
				WeedAppearanceSettings val2 = newDef.appearance;
				if (val2 == null)
				{
					val2 = WeedDefinition.GetAppearanceSettings(((PropertyItemDefinition)newDef).Properties);
				}
				if ((Object)(object)val != (Object)null && val2 != null)
				{
					for (int j = 0; j < ((Component)val).transform.childCount; j++)
					{
						Transform child = ((Component)val).transform.GetChild(j);
						if ((Object)(object)child == (Object)null)
						{
							continue;
						}
						MeshRenderer component = ((Component)child).GetComponent<MeshRenderer>();
						if ((Object)(object)component == (Object)null)
						{
							continue;
						}
						Material material = ((Renderer)component).material;
						if ((Object)(object)material == (Object)null)
						{
							continue;
						}
						if (((Object)child).name == "Stem")
						{
							material.color = Color32.op_Implicit(val2.StemColor);
						}
						if (((Object)child).name == "BigLeaves")
						{
							material.color = Color32.op_Implicit(val2.LeafColor);
						}
						if (((Object)child).name == "SmallLeaves")
						{
							material.color = Color32.op_Implicit(val2.LeafColor);
						}
						Transform[] growthSites = val.GrowthSites;
						foreach (Transform val3 in growthSites)
						{
							if ((Object)(object)val3 != (Object)null)
							{
								Transform child2 = val3.GetChild(0);
								if (Object.op_Implicit((Object)(object)child2))
								{
									SetBranchAppearance(child2, val2);
								}
							}
						}
					}
				}
				else
				{
					Utility.Error("Plant Stage is NULL! Thats impossible");
				}
			}
		}

		public void SetBranchAppearance(Transform branchTransform, WeedDefinition weedDef)
		{
			WeedAppearanceSettings val = weedDef.appearance;
			if (val == null)
			{
				val = WeedDefinition.GetAppearanceSettings(((PropertyItemDefinition)weedDef).Properties);
			}
			if (val != null && (Object)(object)branchTransform != (Object)null)
			{
				SetBranchAppearance(branchTransform, val);
			}
		}

		public void SetBranchAppearance(Transform branchTransform, WeedAppearanceSettings weedAppearance)
		{
			//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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			Transform child = branchTransform.GetChild(0);
			Transform val = ((child != null) ? child.GetChild(0) : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			for (int i = 0; i < val.childCount; i++)
			{
				Transform child2 = val.GetChild(i);
				if ((Object)(object)child2 == (Object)null)
				{
					continue;
				}
				MeshRenderer component = ((Component)child2).GetComponent<MeshRenderer>();
				if ((Object)(object)component == (Object)null)
				{
					continue;
				}
				Material material = ((Renderer)component).material;
				if (!((Object)(object)material == (Object)null))
				{
					if (((Object)child2).name == "Stem")
					{
						material.color = Color32.op_Implicit(weedAppearance.StemColor);
					}
					if (((Object)child2).name == "Leaves")
					{
						material.color = Color32.op_Implicit(weedAppearance.LeafColor);
					}
					if (((Object)child2).name == "Main")
					{
						material.color = Color32.op_Implicit(weedAppearance.MainColor);
					}
					if (((Object)child2).name == "Secondary")
					{
						material.color = Color32.op_Implicit(weedAppearance.SecondaryColor);
					}
				}
			}
		}

		public PlantHarvestable CloneBranchPrefab(WeedDefinition newDef)
		{
			if ((Object)(object)baseBranchPrefab == (Object)null)
			{
				throw new InvalidOperationException("Base branch prefab not initialized.");
			}
			PlantHarvestable val = Object.Instantiate<PlantHarvestable>(baseBranchPrefab, rootGameObject);
			((Object)((Component)val).gameObject).name = ((BaseItemDefinition)newDef).ID + "_Harvestable";
			((Component)val).gameObject.layer = ((Component)baseBranchPrefab).gameObject.layer;
			val.Product = (StorableItemDefinition)(object)newDef;
			return val;
		}

		public FunctionalSeed CloneFunctionalSeedPrefab(string seedDefId)
		{
			if ((Object)(object)baseFunctionalSeedPrefab == (Object)null)
			{
				throw new InvalidOperationException("Base functional seed prefab not initialized.");
			}
			FunctionalSeed val = Object.Instantiate<FunctionalSeed>(baseFunctionalSeedPrefab, rootGameObject);
			GrowLabel(((Component)val).transform, seedDefId);
			return val;
		}

		public Equippable_Seed CloneEquippableSeedPrefab(SeedDefinition newDef, WeedAppearanceSettings weedAppearance)
		{
			if ((Object)(object)baseEquippableSeedPrefab == (Object)null)
			{
				throw new InvalidOperationException("Base equippable seed prefab not initialized.");
			}
			Equippable_Seed val = Object.Instantiate<Equippable_Seed>(baseEquippableSeedPrefab, rootGameObject);
			GrowLabel(((Component)val).transform, ((BaseItemDefinition)newDef).ID);
			((Object)((Component)val).gameObject).name = ((BaseItemDefinition)newDef).ID + "_Equippable";
			((Component)val).gameObject.layer = ((Component)baseEquippableSeedPrefab).gameObject.layer;
			val.Seed = newDef;
			((Equippable_Viewmodel)val).AvatarEquippable = CloneAvatarEquippablePrefab(((BaseItemDefinition)newDef).ID);
			((Object)((Equippable_Viewmodel)val).AvatarEquippable).name = ((BaseItemDefinition)newDef).ID + "_AvatarEquippable";
			return val;
		}

		public AvatarEquippable CloneAvatarEquippablePrefab(string newDefId)
		{
			if ((Object)(object)baseAvatarEquippablePrefab == (Object)null)
			{
				throw new InvalidOperationException("Base avatar equippable prefab not initialized.");
			}
			AvatarEquippable val = Object.Instantiate<AvatarEquippable>(baseAvatarEquippablePrefab, rootGameObject);
			GrowLabel(((Component)val).transform, newDefId);
			return val;
		}

		public StoredItem CloneStoredItem(string newDefId)
		{
			if ((Object)(object)baseStorableItem == (Object)null)
			{
				throw new InvalidOperationException("Base Stored Item not initialized.");
			}
			StoredItem val = Object.Instantiate<StoredItem>(baseStorableItem, rootGameObject);
			GrowLabel(((Component)val).transform, newDefId);
			return val;
		}

		public SeedDefinition CreateSeedDefinition(WeedDefinition weedDef)
		{
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)baseSeedDefinition == (Object)null)
			{
				throw new InvalidOperationException("Base seed definition not initialized.");
			}
			SeedDefinition val = Object.Instantiate<SeedDefinition>(baseSeedDefinition);
			WeedAppearanceSettings val2 = weedDef.appearance;
			if (val2 == null)
			{
				val2 = WeedDefinition.GetAppearanceSettings(((PropertyItemDefinition)weedDef).Properties);
			}
			((Object)val).name = ((BaseItemDefinition)weedDef).ID + "_customseeddefinition";
			((BaseItemDefinition)val).ID = ((BaseItemDefinition)weedDef).ID + "_customseeddefinition";
			((BaseItemDefinition)val).Name = ((Object)weedDef).name + " Seed";
			((BaseItemDefinition)val).Description = ((Object)weedDef).name + " Seed";
			((BaseItemDefinition)val).Icon = ((BaseItemDefinition)baseSeedDefinition).Icon;
			((ItemDefinition)val).Equippable = (Equippable)(object)CloneEquippableSeedPrefab(val, val2);
			val.PlantPrefab = (Plant)(object)ClonePlantPrefab(weedDef);
			val.PlantPrefab.SeedDefinition = val;
			val.FunctionSeedPrefab = CloneFunctionalSeedPrefab(((BaseItemDefinition)val).ID);
			((Object)val.FunctionSeedPrefab).name = ((BaseItemDefinition)weedDef).ID + "Seed_Functional";
			((StorableItemDefinition)val).StoredItem = CloneStoredItem(((BaseItemDefinition)val).ID);
			SeedVisualsManager.appearanceMap.Add(((BaseItemDefinition)val).ID, val2);
			if ((Object)(object)SeedVisualsManager.baseSeedSprite != (Object)null)
			{
				try
				{
					Sprite val3 = SeedVisualsManager.GenerateSpriteWithGradient(Color32.op_Implicit(val2.MainColor), Color32.op_Implicit(val2.SecondaryColor));
					((Object)val3).name = ((Object)val).name + "_icon";
					SeedVisualsManager.seedIcons.Add(((BaseItemDefinition)val).ID, val3);
					((BaseItemDefinition)val).Icon = val3;
				}
				catch (Exception e)
				{
					((BaseItemDefinition)val).Icon = SeedVisualsManager.baseSeedSprite;
					Utility.PrintException(e);
				}
			}
			return val;
		}
	}
	[RegisterTypeInIl2Cpp]
	public class SeedVialLabel : MonoBehaviour
	{
		private Renderer rend;

		private MaterialPropertyBlock block;

		public Color colorA;

		public Color colorB;

		public bool useRandomColors = false;

		private void Start()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			if (useRandomColors)
			{
				colorA = Random.ColorHSV();
				colorB = Random.ColorHSV();
			}
			rend = ((Component)this).GetComponent<Renderer>();
			block = new MaterialPropertyBlock();
			SetupLabel();
		}

		public void SetupLabel()
		{
			//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_00a7: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rend == (Object)null)
			{
				return;
			}
			MeshFilter component = ((Component)this).GetComponent<MeshFilter>();
			if ((Object)(object)component != (Object)null)
			{
				string key = ((Object)this).name.Split(':')[1];
				SeedVisualsManager.appearanceMap.TryGetValue(key, out var value);
				if (value != null)
				{
					colorA = Color32.op_Implicit(value.MainColor);
					colorB = Color32.op_Implicit(value.SecondaryColor);
				}
				Bounds bounds = component.sharedMesh.bounds;
				rend.GetPropertyBlock(block);
				block.SetColor("_ColorA", colorA);
				block.SetColor("_ColorB", colorB);
				block.SetFloat("_MinZ", ((Bounds)(ref bounds)).min.z);
				block.SetFloat("_MaxZ", ((Bounds)(ref bounds)).max.z);
				rend.SetPropertyBlock(block);
			}
		}
	}
}
namespace UnicornsCustomSeeds.SeedQuests
{
	public class CustomSeedQuest : Quest
	{
		[SaveableField("QuestData")]
		private CustomSeedQuestData _data = new CustomSeedQuestData();

		public QuestEntry customSeedEntry;

		protected override string Title => "Drop off the Mix";

		protected override string Description => $"Take {StashManager.StashQtyEntry.Value}x of your weed mix and ${StashManager.StashCostEntry.Value} dollary doos to Albert Hoovers supply stash";

		protected override void OnLoaded()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (base.QuestEntries.Count == 0)
			{
				customSeedEntry = ((Quest)this).AddEntry($"Give Albert {StashManager.StashQtyEntry.Value}x of a Weed Mix and ${StashManager.StashCostEntry.Value}", (Vector3?)((Component)StashManager.albertsStash).transform.position);
			}
		}

		protected override void OnCreated()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (base.QuestEntries.Count == 0)
			{
				customSeedEntry = ((Quest)this).AddEntry($"Give Albert {StashManager.StashQtyEntry.Value}x of a Weed Mix and ${StashManager.StashCostEntry.Value}", (Vector3?)((Component)StashManager.albertsStash).transform.position);
			}
		}
	}
	[Serializable]
	public class CustomSeedQuestData
	{
		public float quantity { get; set; } = 0f;

		public string seedId { get; set; } = string.Empty;
	}
}
namespace UnicornsCustomSeeds.Patches
{
	[HarmonyPatch(typeof(QuestManager), "OnSpawnServer")]
	public static class QuestManager_OnSpawnServer_Patch
	{
		public static void Postfix(NetworkConnection connection)
		{
			if (InstanceFinder.IsServer && QuestManager.GetQuestByName("Drop off the Mix") is CustomSeedQuest)
			{
				SeedQuestManager.BroadcastCustomQuest();
			}
		}
	}
	[HarmonyPatch(typeof(ProductManager), "OnSpawnServer")]
	public static class ProductManager_OnSpawnServer_NetTest
	{
		public static void Postfix(ProductManager __instance, NetworkConnection connection)
		{
			//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_0059: 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_006e: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			if (connection == (NetworkConnection)null || !InstanceFinder.IsServer || connection.IsHost)
			{
				return;
			}
			List<string> list = new List<string>();
			WeedAppearanceSettings val = new WeedAppearanceSettings(Color32.op_Implicit(__instance.DefaultWeed.MainMat.color), Color32.op_Implicit(__instance.DefaultWeed.SecondaryMat.color), Color32.op_Implicit(__instance.DefaultWeed.LeafMat.color), Color32.op_Implicit(__instance.DefaultWeed.StemMat.color));
			foreach (KeyValuePair<string, UnicornSeedData> discoveredSeed in CustomSeedsManager.DiscoveredSeeds)
			{
				__instance.CreateWeed_Server("[NET-JSON]" + JsonConvert.SerializeObject((object)discoveredSeed.Value, (Formatting)0), "ogkushseed", (EDrugType)0, list, val);
			}
		}
	}
	[HarmonyPatch(typeof(ProductManager), "RpcLogic___CreateWeed_1777266891")]
	public static class ProductManager_RpcLogic_CreateWeed_NetTest
	{
		public static void Postfix(ProductManager __instance, NetworkConnection conn, string name, string id, EDrugType type, List<string> properties, WeedAppearanceSettings appearance)
		{
			if (id != "ogkushseed" || name == null)
			{
				return;
			}
			if (name.StartsWith("[NET-QUEST]") && InstanceFinder.IsClientOnly)
			{
				string text = name.Replace("[NET-QUEST]", "");
				try
				{
					string[] array = text.Split(',');
					if (array.Length == 3)
					{
						if (int.TryParse(array[0], out var result))
						{
							StashManager.StashCostEntry.Value = result;
						}
						if (int.TryParse(array[1], out var result2))
						{
							StashManager.StashQtyEntry.Value = result2;
						}
						if (int.TryParse(array[2], out var result3))
						{
							StashManager.SynthesizeTime.Value = result3;
						}
					}
				}
				catch (Exception e)
				{
					Utility.PrintException(e);
				}
				if ((Object)(object)StashManager.albertsStash == (Object)null)
				{
					StashManager.GetAlbertsStash();
				}
				CustomSeedQuest customSeedQuest = QuestManager.GetQuestByName("Drop off the Mix") as CustomSeedQuest;
				if (customSeedQuest == null)
				{
					SeedQuestManager.CreateQuestAsync();
				}
			}
			else
			{
				if (!name.StartsWith("[NET-JSON]"))
				{
					return;
				}
				string text2 = name.Replace("[NET-JSON]", "");
				try
				{
					UnicornSeedData unicornSeedData = JsonConvert.DeserializeObject<UnicornSeedData>(text2);
					if (Registry.ItemExists(unicornSeedData.seedId))
					{
						return;
					}
					if (!CustomSeedsManager.DiscoveredSeeds.ContainsKey(unicornSeedData.mixId))
					{
						CustomSeedsManager.DiscoveredSeeds.Add(unicornSeedData.mixId, unicornSeedData);
					}
					SeedDefinition val = CustomSeedsManager.SeedDefinitionLoader(unicornSeedData);
					if ((Object)(object)val != (Object)null)
					{
						try
						{
							WeedDefinition item = Registry.GetItem<WeedDefinition>(unicornSeedData.mixId);
							float ingredientCost = StashManager.GetIngredientCost((ProductDefinition)(object)item);
							Singleton<ManagementUtilities>.Instance.Seeds.Add(val);
							CustomSeedsManager.CreateShopListing(val, ingredientCost);
							CustomSeedsManager.AddSeedToPots(val);
							CustomSeedsManager.EnableSeedIndicator(unicornSeedData.mixId);
						}
						catch (Exception e2)
						{
							Utility.PrintException(e2);
						}
					}
					if (InstanceFinder.IsClient)
					{
						DeferredPlantsManager.TrySpawnQueuedPlants(((BaseItemDefinition)val).ID);
					}
				}
				catch (Exception e3)
				{
					Utility.PrintException(e3);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Pot), "RpcLogic___PlantSeed_Client_4077118173")]
	public static class Patch_Pot_RpcLogic___PlantSeed_Client_4077118173
	{
		public static bool Prefix(Pot __instance, NetworkConnection conn, string seedID, float normalizedSeedProgress)
		{
			if (!InstanceFinder.IsClient || InstanceFinder.IsServer)
			{
				return true;
			}
			if (DeferredPlantsManager.IsReplaying)
			{
				return true;
			}
			if (string.IsNullOrEmpty(seedID))
			{
				return true;
			}
			if (!seedID.Contains("customseeddefinition"))
			{
				return true;
			}
			if (Registry.ItemExists(seedID))
			{
				return true;
			}
			DeferredPlantsManager.AddDeferredSeed(__instance, seedID, normalizedSeedProgress);
			return false;
		}
	}
	[HarmonyPatch(typeof(Pot), "RpcLogic___SetHarvestableActive_Client_338960014")]
	public static class Patch_Pot_RpcLogic___SetHarvestableActive_Client_338960014
	{
		public static bool Prefix(Pot __instance, NetworkConnection conn, int harvestableIndex, bool active)
		{
			if (!InstanceFinder.IsClient || InstanceFinder.IsServer)
			{
				return true;
			}
			if (DeferredPlantsManager.PendingPotGuids.Contains(((BuildableItem)__instance).GUID.ToString()))
			{
				DeferredPlantsManager.AddHarvestableUpdate(((BuildableItem)__instance).GUID.ToString(), harvestableIndex, active);
				return false;
			}
			return true;
		}
	}
	public class ProductManagerAppPatches
	{
		[HarmonyPatch(typeof(ProductManagerApp))]
		public static class ProductManagerApp_Patch
		{
			[HarmonyPrefix]
			[HarmonyPatch("Start")]
			public static bool StartPatch(ProductManagerApp __instance)
			{
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Expected O, but got Unknown
				//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e0: 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)
				if ((Object)(object)__instance != (Object)null && (Object)(object)__instance.EntryPrefab != (Object)null && (Object)(object)__instance.EntryPrefab.transform.Find("SeedIndicator") == (Object)null)
				{
					GameObject val = new GameObject("Temp");
					val.SetActive(false);
					GameObject val2 = Object.Instantiate<GameObject>(__instance.EntryPrefab, val.transform);
					ProductEntry component = __instance.EntryPrefab.GetComponent<ProductEntry>();
					GameObject val3 = Object.Instantiate<GameObject>(((Component)component.FavouriteButton).gameObject, val2.transform);
					Button component2 = val3.GetComponent<Button>();
					Object.Destroy((Object)(object)component2);
					((Object)val3).name = "SeedIndicator";
					RectTransform component3 = val3.GetComponent<RectTransform>();
					if ((Object)(object)component3 != (Object)null)
					{
						component3.anchoredPosition = new Vector2(15f, -15f);
						component3.anchorMax = new Vector2(0f, 1f);
						component3.anchorMin = new Vector2(0f, 1f);
					}
					TrySetSeedIconSprite(val3);
					__instance.EntryPrefab = val2;
					isPrefabInitialized = true;
				}
				return true;
			}

			[HarmonyPostfix]
			[HarmonyPatch("Start")]
			public static void StartPostfix(ProductManagerApp __instance)
			{
				UpdatePendingIndicators();
			}
		}

		[HarmonyPatch(typeof(ProductEntry), "Initialize")]
		public static class ProductEntry_Initialize_Patch
		{
			[HarmonyPostfix]
			public static void Postfix(ProductEntry __instance, ProductDefinition definition)
			{
				if (!((Object)(object)__instance != (Object)null) || !((Object)(object)definition != (Object)null))
				{
					return;
				}
				Transform val = ((Component)__instance).transform.Find("SeedIndicator");
				if ((Object)(object)val != (Object)null)
				{
					TrySetSeedIconSprite(((Component)val).gameObject);
					if (CustomSeedsManager.DiscoveredSeeds.ContainsKey(((BaseItemDefinition)definition).ID))
					{
						((Component)val).gameObject.SetActive(true);
					}
					else
					{
						((Component)val).gameObject.SetActive(false);
					}
				}
			}
		}

		private static bool isPrefabInitialized = false;

		private static List<GameObject> pendingIndicators = new List<GameObject>();

		private static void TrySetSeedIconSprite(GameObject indicatorObject)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)SeedVisualsManager.seedIcon == (Object)null)
				{
					SeedVisualsManager.LoadSeedMaterial();
				}
				Image component = ((Component)indicatorObject.transform.GetChild(0)).GetComponent<Image>();
				if ((Object)(object)component != (Object)null)
				{
					if ((Object)(object)SeedVisualsManager.seedIcon != (Object)null)
					{
						component.sprite = SeedVisualsManager.seedIcon;
						((Graphic)component).color = Color.white;
					}
					else if (!pendingIndicators.Contains(indicatorObject))
					{
						pendingIndicators.Add(indicatorObject);
						Utility.Log("Seed icon not loaded yet, added to pending list");
					}
				}
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
		}

		private static void UpdatePendingIndicators()
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			if (pendingIndicators.Count == 0)
			{
				return;
			}
			for (int num = pendingIndicators.Count - 1; num >= 0; num--)
			{
				GameObject val = pendingIndicators[num];
				if ((Object)(object)val == (Object)null)
				{
					pendingIndicators.RemoveAt(num);
				}
				else
				{
					try
					{
						Image component = ((Component)val.transform.GetChild(0)).GetComponent<Image>();
						if ((Object)(object)component != (Object)null && (Object)(object)SeedVisualsManager.seedIcon != (Object)null)
						{
							component.sprite = SeedVisualsManager.seedIcon;
							((Graphic)component).color = Color.white;
							pendingIndicators.RemoveAt(num);
						}
					}
					catch (Exception e)
					{
						Utility.PrintException(e);
						pendingIndicators.RemoveAt(num);
					}
				}
			}
		}

		public static void ClearPendingIndicators()
		{
			pendingIndicators.Clear();
			isPrefabInitialized = false;
		}
	}
	[HarmonyPatch(typeof(ProductDefinition), "AddRecipe")]
	public class ProductDefinition_AddRecipe_Patch
	{
		private static void Postfix(ProductDefinition __instance)
		{
			StashManager.ProcessNewRecipe(__instance);
		}
	}
	[HarmonyPatch(typeof(SendableMessage), "IsValid")]
	public class SendableMessage_IsValid_Patch
	{
		public static bool Prefix(SendableMessage __instance, ref bool __result, out string invalidReason)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			invalidReason = string.Empty;
			if (__instance.Text != null && __instance.Text == SeedQuestManager.messageId)
			{
				if (SeedQuestManager.HasActiveQuest)
				{
					invalidReason = "Seed Synthesizing is already in progress";
					__result = false;
				}
				else if ((Object)(object)DeadDrop.GetRandomEmptyDrop(((Component)Player.Local).transform.position) == (Object)null)
				{
					invalidReason = "No deaddrops are available";
					__result = false;
				}
				else if ((Object)(object)ConversationManager.albert == (Object)null || ((NPC)ConversationManager.albert).RelationData.RelationDelta < 4f)
				{
					invalidReason = "Relationship isn't good enough";
					__result = false;
				}
				else
				{
					__result = true;
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(LoadManager), "ExitToMenu")]
	public static class LoadManager_ExitToMenu_Patch
	{
		public static void Postfix(LoadManager __instance, SaveInfo autoLoadSave, Data mainMenuPopup, bool preventLeaveLobby)
		{
			List<SeedDefinition> seeds = Singleton<ManagementUtilities>.Instance.Seeds;
			List<SeedDefinition> list = new List<SeedDefinition>();
			foreach (SeedDefinition item in seeds)
			{
				if ((Object)(object)item != (Object)null && !((BaseItemDefinition)item).ID.Contains("customseeddefinition"))
				{
					list.Add(item);
				}
			}
			Singleton<ManagementUtilities>.Instance.Seeds = list;
		}
	}
	[HarmonyPatch(typeof(LoadManager), "StartGame")]
	public static class LoadManager_StartGame_Patch
	{
		public static void Postfix(LoadManager __instance)
		{
			if ((Object)(object)__instance == (Object)null || string.IsNullOrEmpty(__instance.LoadedGameFolderPath))
			{
				return;
			}
			try
			{
				string loadedGameFolderPath = __instance.LoadedGameFolderPath;
				LoadDiscoveredSeeds(loadedGameFolderPath);
				LoadActiveCooking(loadedGameFolderPath);
			}
			catch (Exception arg)
			{
				MelonLogger.Error($"PersistencePatches.StartGame: {arg}");
			}
		}

		private static void LoadDiscoveredSeeds(string saveFolder)
		{
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected I4, but got Unknown
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(saveFolder, "DiscoveredCustomSeeds.json");
			List<UnicornSeedData> list = new List<UnicornSeedData>();
			if (File.Exists(path))
			{
				CustomSeedsManager.FirstLoad = false;
				string text = File.ReadAllText(path);
				try
				{
					JArray val = JArray.Parse(text);
					if (((JContainer)val).Count > 0)
					{
						JToken obj = val[0];
						JObject val2 = (JObject)(object)((obj is JObject) ? obj : null);
						if (val2 != null && !val2.ContainsKey("variants"))
						{
							Utility.Success($"Preparing to migrate {((JContainer)val).Count} legacy seed(s).");
							list = MigrateLegacySeedData(text, val2);
							goto IL_00ad;
						}
					}
					CustomSeedsManager.letsMigrate = false;
					list = JsonConvert.DeserializeObject<List<UnicornSeedData>>(text) ?? new List<UnicornSeedData>();
					goto IL_00ad;
					IL_00ad:
					Utility.Success($"Loaded {list.Count} custom seeds.");
				}
				catch (Exception e)
				{
					Utility.PrintException(e);
					CustomSeedsManager.FirstLoad = true;
					list = new List<UnicornSeedData>();
				}
			}
			else
			{
				CustomSeedsManager.FirstLoad = true;
			}
			foreach (UnicornSeedData item in list)
			{
				if (item == null)
				{
					continue;
				}
				EDrugType drugType = item.drugType;
				EDrugType val3 = drugType;
				switch ((int)val3)
				{
				case 0:
					if (!CustomSeedsManager.DiscoveredSeeds.ContainsKey(item.mixId))
					{
						CustomSeedsManager.DiscoveredSeeds.Add(item.mixId, item);
					}
					break;
				case 4:
					if (!CustomShroomsManager.DiscoveredShrooms.ContainsKey(item.mixId))
					{
						CustomShroomsManager.DiscoveredShrooms.Add(item.mixId, item);
					}
					break;
				case 2:
					if (!CustomCocaSeedsManager.DiscoveredCocaSeeds.ContainsKey(item.mixId))
					{
						CustomCocaSeedsManager.DiscoveredCocaSeeds.Add(item.mixId, item);
					}
					break;
				default:
					Utility.Error($"PersistencePatches: Unknown EDrugType '{item.drugType}' for seed '{item.seedId}' — skipped.");
					break;
				}
			}
		}

		private static List<UnicornSeedData> MigrateLegacySeedData(string json, JObject first)
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			List<UnicornSeedData> list = new List<UnicornSeedData>();
			if (first.ContainsKey("weedId"))
			{
				CustomSeedsManager.letsMigrate = true;
				List<LegacySeedData> list2 = JsonConvert.DeserializeObject<List<LegacySeedData>>(json) ?? new List<LegacySeedData>();
				foreach (LegacySeedData item in list2)
				{
					UnicornSeedData unicornSeedData = new UnicornSeedData
					{
						mixId = item.weedId,
						drugType = (EDrugType)0
					};
					unicornSeedData.SetSingleVariant("ogkushseed", item.seedId, item.price);
					list.Add(unicornSeedData);
				}
				return list;
			}
			CustomSeedsManager.letsMigrate = true;
			List<LegacyUnicornSeedData> list3 = JsonConvert.DeserializeObject<List<LegacyUnicornSeedData>>(json) ?? new List<LegacyUnicornSeedData>();
			foreach (LegacyUnicornSeedData item2 in list3)
			{
				UnicornSeedData unicornSeedData2 = new UnicornSeedData
				{
					mixId = item2.mixId,
					drugType = item2.drugType
				};
				string baseItemId = ResolveLegacyBaseItemId(item2);
				unicornSeedData2.SetSingleVariant(baseItemId, item2.seedId, item2.price);
				list.Add(unicornSeedData2);
			}
			return list;
		}

		private static string ResolveLegacyBaseItemId(LegacyUnicornSeedData data)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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_0024: Expected I4, but got Unknown
			EDrugType drugType = data.drugType;
			EDrugType val = drugType;
			return (int)val switch
			{
				0 => "ogkushseed", 
				4 => "sporesyringe", 
				2 => "cocaseed", 
				_ => string.Empty, 
			};
		}

		private static void LoadActiveCooking(string saveFolder)
		{
			string path = Path.Combine(saveFolder, "UnicornsActiveCooking.json");
			if (!File.Exists(path))
			{
				return;
			}
			try
			{
				string text = File.ReadAllText(path);
				List<ActiveCookingEntry> list = JsonConvert.DeserializeObject<List<ActiveCookingEntry>>(text);
				if (list == null)
				{
					return;
				}
				foreach (ActiveCookingEntry item in list)
				{
					if (!string.IsNullOrEmpty(item?.stationGuid) && !string.IsNullOrEmpty(item.mixId))
					{
						ActiveCookingRegistry.Register(item.stationGuid, item.mixId);
					}
				}
				Utility.Success($"Loaded {list.Count} active cooking entries.");
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
		}
	}
	[HarmonyPatch(typeof(ProductManager), "CreateWeed")]
	public static class Patch_ProductManager_CreateWeed
	{
		public static void Postfix(NetworkConnection conn, string name, string id, EDrugType type, List<string> properties, WeedAppearanceSettings appearance)
		{
			if (Registry.ItemExists(id + "_customseeddefinition") || !CustomSeedsManager.DiscoveredSeeds.TryGetValue(id, out var value))
			{
				return;
			}
			SeedDefinition val = CustomSeedsManager.SeedDefinitionLoader(value);
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			try
			{
				Singleton<ManagementUtilities>.Instance.Seeds.Add(val);
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
		}
	}
	[HarmonyPatch(typeof(ProductManager), "CreateCocaine")]
	public static class Patch_ProductManager_CreateCocaine
	{
		public static void Postfix(NetworkConnection conn, string name, string id, EDrugType type, List<string> properties, CocaineAppearanceSettings appearance)
		{
			if (Registry.ItemExists(id + "_customcocaseed") || !CustomCocaSeedsManager.DiscoveredCocaSeeds.TryGetValue(id, out var _))
			{
				return;
			}
			if (CustomCocaSeedsManager.factory == null)
			{
				Utility.Error("Patch_ProductManager_CreateCocaine: factory is null for '" + id + "'.");
				return;
			}
			try
			{
				ProductDefinition item = Registry.GetItem<ProductDefinition>(id);
				if ((Object)(object)item == (Object)null)
				{
					Utility.Error("Patch_ProductManager_CreateCocaine: Could not resolve ProductDefinition '" + id + "'.");
					return;
				}
				SeedDefinition val = CustomCocaSeedsManager.factory.CreateCocaSeedDefinition(item);
				if (!((Object)(object)val == (Object)null))
				{
					Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val);
					try
					{
						Singleton<ManagementUtilities>.Instance.Seeds.Add(val);
					}
					catch (Exception e)
					{
						Utility.PrintException(e);
					}
					string text = id + "_customcocaleaf";
					QualityItemDefinition item2 = Registry.GetItem<QualityItemDefinition>(text);
					if ((Object)(object)item2 != (Object)null)
					{
						CocaFactory.AddLeafToCauldrons(item2);
					}
					else
					{
						Utility.Error("Patch_ProductManager_CreateCocaine: Could not resolve leaf '" + text + "' from Registry — cauldrons will not accept this leaf.");
					}
					Utility.Log("Patch_ProductManager_CreateCocaine: Reloaded coca seed '" + ((BaseItemDefinition)val).ID + "'.");
				}
			}
			catch (Exception e2)
			{
				Utility.PrintException(e2);
			}
		}
	}
	[HarmonyPatch(typeof(ProductManager), "CreateShroom_Server")]
	public static class Patch_ProductManager_CreateShroom
	{
		public static void Postfix(string name, string id, EDrugType type, List<string> properties, ShroomAppearanceSettings appearance)
		{
			string text = id + "_customsyringedefinition";
			if (Registry.ItemExists(text) || !CustomShroomsManager.DiscoveredShrooms.TryGetValue(id, out var value))
			{
				return;
			}
			if (CustomShroomsManager.factory == null)
			{
				Utility.Error("Patch_ProductManager_CreateShroom: factory is null for '" + id + "'.");
				return;
			}
			try
			{
				SporeSyringeDefinition val = CustomShroomsManager.SyringeDefinitionLoader(value);
				if ((Object)(object)val != (Object)null)
				{
					Utility.Log("Patch_ProductManager_CreateShroom: Reloaded syringe '" + ((BaseItemDefinition)val).ID + "'.");
				}
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
		}
	}
}
namespace UnicornsCustomSeeds.Managers
{
	public static class ActiveCookingRegistry
	{
		public static readonly Dictionary<string, string> GuidToMixId = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

		public static void Register(string stationGuid, string mixId)
		{
			GuidToMixId[stationGuid] = mixId;
		}

		public static void Unregister(string stationGuid)
		{
			GuidToMixId.Remove(stationGuid);
		}

		public static string GetMixId(string stationGuid)
		{
			GuidToMixId.TryGetValue(stationGuid, out var value);
			return value;
		}

		public static void Clear()
		{
			GuidToMixId.Clear();
		}
	}
	[Serializable]
	public class ActiveCookingEntry
	{
		public string stationGuid { get; set; }

		public string mixId { get; set; }
	}
	public static class ConversationManager
	{
		public static Dictionary<string, MSGConversation> Conversations = new Dictionary<string, MSGConversation>();

		public static Albert albert;

		public static NPCRelationData albertRelation;

		public static string welcomeMessage = "A <color='#FA2FBD'><b>Unicorn</b></color> I know can synthesize your custom mixes into seeds. If you'd like to use that service, send me a text.";

		public static void Init()
		{
			//IL_00d1: 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_00fd: 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)
			albert = Object.FindObjectOfType<Albert>();
			if ((Object)(object)albert != (Object)null)
			{
				if (((NPC)albert).MSGConversation != null)
				{
					RegisterConversation("Albert", ((NPC)albert).MSGConversation);
					albertRelation = ((NPC)albert).RelationData;
				}
				if (!CustomSeedsManager.FirstLoad || ((NPC)albert).RelationData == null)
				{
					return;
				}
				if (((NPC)albert).RelationData.RelationDelta >= 4f)
				{
					MelonCoroutines.Start(WelcomeRoutine());
					return;
				}
				DialogueDatabase database = ((NPC)albert).DialogueHandler.Database;
				DialogueModule module = database.GetModule((EDialogueModule)0);
				for (int i = 0; i < module.Entries.Count; i++)
				{
					if (module.Entries[i].Key == "supplier_meetings_unlocked")
					{
						Entry val = module.Entries[i];
						DialogueChain val2 = val.Chains[0];
						if (val2 != null && val2.Lines[val2.Lines.Length - 1] != welcomeMessage)
						{
							string[] lines = val2.Lines;
							string[] array = new string[lines.Length + 1];
							array[0] = lines[0];
							array[1] = lines[1];
							array[2] = welcomeMessage;
							val2.Lines = array;
						}
					}
				}
			}
			else
			{
				Utility.Error("ConversationManager: Could not find Albert or his conversation.");
			}
		}

		public static void RegisterConversation(string name, MSGConversation convo)
		{
			if (!Conversations.ContainsKey(name))
			{
				Conversations.Add(name, convo);
			}
			else
			{
				Conversations[name] = convo;
			}
		}

		public static MSGConversation GetConversation(string name)
		{
			if (Conversations.TryGetValue(name, out var value))
			{
				return value;
			}
			return null;
		}

		public static void SendMessage(string characterName, string text)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			if (!InstanceFinder.IsServer)
			{
				return;
			}
			if (Conversations.TryGetValue(characterName, out var value))
			{
				if (value != null)
				{
					value.SendMessage(new Message(text, (ESenderType)1, true, -1), true, true);
				}
			}
			else
			{
				Utility.Error("ConversationManager: Conversation for " + characterName + " not found.");
			}
		}

		public static void SendMessageChain(string characterName, List<string> messages)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			if (!InstanceFinder.IsServer)
			{
				return;
			}
			if (Conversations.TryGetValue(characterName, out var value))
			{
				if (value == null)
				{
					return;
				}
				MessageChain val = new MessageChain();
				foreach (string message in messages)
				{
					val.Messages.Add(message);
				}
				val.id = Random.Range(int.MinValue, int.MaxValue);
				value.SendMessageChain(val, 0.5f, true, true);
			}
			else
			{
				Utility.Error("Conversation for " + characterName + " not found.");
			}
		}

		public static void AlbertWelcomeMessage(EUnlockType type, bool temp)
		{
			SendMessage("Albert", welcomeMessage);
		}

		private static IEnumerator WelcomeRoutine()
		{
			yield return (object)new WaitForSeconds(10f);
			AlbertWelcomeMessage((EUnlockType)1, temp: true);
		}
	}
	public static class CustomCocaSeedsManager
	{
		public const string BASE_SEED_ID = "cocaseed";

		public const string BASE_LEAF_ID = "cocaleaf";

		public const string BASE_BASE_ID = "cocainebase";

		public static readonly string[] TEST_COCAINE_MIX_IDS = new string[6] { "bighaze", "gorillaghost", "lasmegma", "hairygold", "miraclefruit", "afghancake" };

		public static CocaFactory factory;

		public static Dictionary<string, UnicornSeedData> DiscoveredCocaSeeds = new Dictionary<string, UnicornSeedData>();

		public static ShopInterface SalvadorShop = null;

		public static Salvador salvador = null;

		public static void Initialize()
		{
			RestoreLeafFilters();
			salvador = Object.FindObjectOfType<Salvador>();
			if ((Object)(object)salvador != (Object)null)
			{
				SalvadorShop = ((Supplier)salvador).Shop;
				if ((Object)(object)SalvadorShop == (Object)null)
				{
					Utility.Error("CustomCocaSeedsManager: Salvador's shop is null!");
				}
				if (((NPC)salvador).MSGConversation != null)
				{
					ConversationManager.RegisterConversation("Salvador", ((NPC)salvador).MSGConversation);
				}
				{
					foreach (KeyValuePair<string, UnicornSeedData> discoveredCocaSeed in DiscoveredCocaSeeds)
					{
						SeedDefinition item = Registry.GetItem<SeedDefinition>(discoveredCocaSeed.Value.seedId);
						if ((Object)(object)item != (Object)null)
						{
							CreateShopListing(item, discoveredCocaSeed.Value.price);
						}
					}
					return;
				}
			}
			Utility.Error("CustomCocaSeedsManager: Could not find Salvador NPC in scene. Verify Salvador is present and unlocked.");
		}

		public static IEnumerator CreateCocaSeed(ProductDefinition cocaineDef)
		{
			yield return (object)new WaitForSeconds(5f);
			if (factory == null)
			{
				Utility.Error("CustomCocaSeedsManager: CocaFactory is null! Ensure factory was initialized in Core.OnSceneWasLoaded.");
				yield break;
			}
			if (DiscoveredCocaSeeds.ContainsKey(((BaseItemDefinition)cocaineDef).ID))
			{
				Utility.Log("CustomCocaSeedsManager: Coca seed for '" + ((BaseItemDefinition)cocaineDef).ID + "' already exists, skipping.");
				yield break;
			}
			SeedDefinition newSeed = factory.CreateCocaSeedDefinition(cocaineDef);
			if ((Object)(object)newSeed == (Object)null)
			{
				Utility.Error("CustomCocaSeedsManager: CreateCocaSeedDefinition returned null.");
				yield break;
			}
			Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)newSeed);
			Utility.Log("CustomCocaSeedsManager: Registered seed '" + ((BaseItemDefinition)newSeed).ID + "' in Registry.");
			Singleton<ManagementUtilities>.Instance.Seeds.Add(newSeed);
			CustomSeedsManager.AddSeedToPots(newSeed);
			QualityItemDefinition customLeaf = Registry.GetItem<QualityItemDefinition>(((BaseItemDefinition)cocaineDef).ID + "_customcocaleaf");
			if ((Object)(object)customLeaf != (Object)null)
			{
				CocaFactory.AddLeafToCauldrons(customLeaf);
			}
			else
			{
				Utility.Error("CustomCocaSeedsManager: Could not resolve custom leaf from Registry after registration.");
			}
			((StorableItemDefinition)newSeed).BasePurchasePrice = ((StorableItemDefinition)newSeed).BasePurchasePrice + StashManager.GetIngredientCost(cocaineDef);
			UnicornSeedData newData = new UnicornSeedData
			{
				mixId = ((BaseItemDefinition)cocaineDef).ID,
				drugType = (EDrugType)2
			};
			newData.SetSingleVariant("cocaseed", ((BaseItemDefinition)newSeed).ID, ((StorableItemDefinition)newSeed).BasePurchasePrice);
			DiscoveredCocaSeeds.Add(newData.mixId, newData);
			CreateShopListing(newSeed, newData.price);
			DeadDrop randomDrop = DeadDrop.GetRandomEmptyDrop(((Component)Player.Local).transform.position);
			if ((Object)(object)randomDrop != (Object)null && InstanceFinder.IsServer)
			{
				ItemInstance defaultInstance = ((ItemDefinition)newSeed).GetDefaultInstance(1);
				((BaseItemInstance)defaultInstance).SetQuantity(3);
				((StorageEntity)randomDrop.Storage).InsertItem(defaultInstance, true);
				string guidString = GUIDManager.GenerateUniqueGUID().ToString();
				NetworkSingleton<QuestManager>.Instance.CreateDeaddropCollectionQuest((NetworkConnection)null, randomDrop.GUID.ToString(), guidString);
				ConversationManager.SendMessage("Salvador", ((Object)cocaineDef).name + " coca seed synthesized and placed in a dead drop.");
				Utility.Log($"CustomCocaSeedsManager: Placed 3x '{((BaseItemDefinition)newSeed).ID}' in dead drop '{randomDrop.GUID}'.");
			}
			else
			{
				Utility.Error("CustomCocaSeedsManager: No available dead drop for coca seed placement, or not server.");
			}
		}

		public static void CreateShopListing(SeedDefinition newSeed, float price = 10f)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)SalvadorShop == (Object)null))
			{
				ShopListing val = new ShopListing();
				val.name = $"{((BaseItemDefinition)newSeed).ID} (${price}) (Coca, )";
				val.Item = (StorableItemDefinition)(object)newSeed;
				val.IconTint = new Color(0.9f, 0.9f, 0.9f, 1f);
				val.MinimumGameCreationVersion = 27f;
				val.DefaultStock = 1000;
				val.CurrentStock = 100000;
				val.CanBeDelivered = true;
				SalvadorShop.Listings.Add(val);
				SalvadorShop.CreateListingUI(val);
				CreatePhoneShopListing(newSeed);
				CreateDeliveryListing(val);
				SalvadorShop.RefreshShownItems();
			}
		}

		public static void CreatePhoneShopListing(SeedDefinition newSeed)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if (!((Object)(object)salvador == (Object)null))
			{
				Listing val = new Listing((StorableItemDefinition)(object)newSeed);
				IEnumerable<Listing> source = CollectionExtensions.AddItem<Listing>((IEnumerable<Listing>)((Supplier)salvador).SupplierData.DeliveryShopListings, val);
				((Supplier)salvador).SupplierData.DeliveryShopListings = source.ToArray();
			}
		}

		public static void CreateDeliveryListing(ShopListing newListing)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_008c: 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)
			if (!((Object)(object)SalvadorShop == (Object)null))
			{
				DeliveryApp instance = PlayerSingleton<DeliveryApp>.Instance;
				DeliveryShop val = ((instance != null) ? instance.GetShop(SalvadorShop.ShopName) : null);
				if (!((Object)(object)val == (Object)null))
				{
					ListingEntry val2 = Object.Instantiate<ListingEntry>(val.ListingEntryPrefab, (Transform)(object)val.ListingContainer);
					val2.Initialize(newListing);
					val2.onQuantityChanged.AddListener(new UnityAction(val.RefreshCart));
					val.listingEntries.Add(val2);
					val.ListingContainer.sizeDelta = new Vector2(val.ListingContainer.sizeDelta.x, 230f + (float)Math.Ceiling((double)val.listingEntries.Count / 2.0) * 60f);
				}
			}
		}

		public static void ClearAll()
		{
			DiscoveredCocaSeeds.Clear();
			SalvadorShop = null;
			salvador = null;
			if (factory != null)
			{
				factory.DeleteChildren();
			}
		}

		public static void RestoreLeafFilters()
		{
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			if (DiscoveredCocaSeeds.Count == 0)
			{
				return;
			}
			if (factory == null)
			{
				Utility.Error("CustomCocaSeedsManager.RestoreLeafFilters: factory is null \ufffd cannot restore leaf filters.");
				return;
			}
			foreach (KeyValuePair<string, UnicornSeedData> discoveredCocaSeed in DiscoveredCocaSeeds)
			{
				string key = discoveredCocaSeed.Key;
				if (!Registry.ItemExists(key + "_customcocaseed"))
				{
					ProductDefinition item = Registry.GetItem<ProductDefinition>(key);
					if ((Object)(object)item == (Object)null)
					{
						Utility.Error("CustomCocaSeedsManager.RestoreLeafFilters: ProductDefinition '" + key + "' not in Registry \ufffd skipping.");
						continue;
					}
					SeedDefinition val = factory.CreateCocaSeedDefinition(item);
					if ((Object)(object)val == (Object)null)
					{
						Utility.Error("CustomCocaSeedsManager.RestoreLeafFilters: CreateCocaSeedDefinition returned null for '" + key + "'.");
						continue;
					}
					Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val);
					CreateShopListing(val, discoveredCocaSeed.Value.price);
					Utility.Log("CustomCocaSeedsManager.RestoreLeafFilters: Rebuilt seed '" + ((BaseItemDefinition)val).ID + "'.");
				}
				string text = key + "_customcocaleaf";
				QualityItemDefinition item2 = Registry.GetItem<QualityItemDefinition>(text);
				if ((Object)(object)item2 != (Object)null)
				{
					CocaFactory.AddLeafToCauldrons(item2);
					Utility.Log("CustomCocaSeedsManager.RestoreLeafFilters: Added '" + text + "' to cauldron filters.");
				}
				else
				{
					Utility.Error("CustomCocaSeedsManager.RestoreLeafFilters: Could not resolve '" + text + "' from Registry.");
				}
			}
		}
	}
	public static class CustomShroomsManager
	{
		public const string BASE_SYRINGE_ID = "sporesyringe";

		public static SyringeFactory factory;

		public static Dictionary<string, UnicornSeedData> DiscoveredShrooms = new Dictionary<string, UnicornSeedData>();

		public static ShopInterface PhilShop = null;

		public static GameObject PhilShopGo = null;

		public static Phil phil = null;

		public static void Initialize()
		{
			phil = Object.FindObjectOfType<Phil>();
			if ((Object)(object)phil != (Object)null)
			{
				PhilShop = ((Supplier)phil).Shop;
				ShopInterface philShop = PhilShop;
				PhilShopGo = ((philShop != null) ? ((Component)philShop).gameObject : null);
				if ((Object)(object)PhilShop == (Object)null)
				{
					Utility.Error("CustomShroomsManager: Phil's shop is null!");
				}
				if (((NPC)phil).MSGConversation != null)
				{
					ConversationManager.RegisterConversation("Phil", ((NPC)phil).MSGConversation);
				}
				{
					foreach (KeyValuePair<string, UnicornSeedData> discoveredShroom in DiscoveredShrooms)
					{
						if (!Registry.ItemExists(discoveredShroom.Value.seedId))
						{
							SyringeDefinitionLoader(discoveredShroom.Value);
							continue;
						}
						SporeSyringeDefinition item = Registry.GetItem<SporeSyringeDefinition>(discoveredShroom.Value.seedId);
						AddSyringeToSpawnStations(item);
						CreateShopListing(item, discoveredShroom.Value.price);
					}
					return;
				}
			}
			Utility.Error("CustomShroomsManager: Could not find Phil.");
		}

		public static SporeSyringeDefinition SyringeDefinitionLoader(UnicornSeedData data)
		{
			if (factory == null)
			{
				Utility.Error("SyringeDefinitionLoader: factory is null for '" + data.mixId + "'.");
				return null;
			}
			ShroomDefinition item = Registry.GetItem<ShroomDefinition>(data.mixId);
			if ((Object)(object)item == (Object)null)
			{
				Utility.Error("SyringeDefinitionLoader: Could not resolve ShroomDefinition '" + data.mixId + "'.");
				return null;
			}
			SporeSyringeDefinition val = factory.CreateSyringeDefinition(item);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val);
			try
			{
				Singleton<ManagementUtilities>.Instance.MushroomSpawns.Add(val.SpawnDefinition);
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
			AddSyringeToSpawnStations(val);
			CreateShopListing(val, data.price);
			Utility.Log("SyringeDefinitionLoader: Reloaded syringe '" + ((BaseItemDefinition)val).ID + "'.");
			return val;
		}

		public static void StartSyringeCreation(ShroomDefinition shroomDef)
		{
			MelonCoroutines.Start(CreateSyringe(shroomDef));
		}

		public static IEnumerator CreateSyringe(ShroomDefinition shroomDef)
		{
			yield return (object)new WaitForSeconds(5f);
			if (factory == null)
			{
				Utility.Error("SyringeFactory is null!");
				yield break;
			}
			SporeSyringeDefinition newSyringe = factory.CreateSyringeDefinition(shroomDef);
			if ((Object)(object)newSyringe == (Object)null)
			{
				Utility.Error("Failed to create custom syringe definition.");
				yield break;
			}
			Utility.Log("Created new syringe definition: " + ((BaseItemDefinition)newSyringe).ID + " for shroom: " + ((BaseItemDefinition)shroomDef).ID);
			Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)newSyringe);
			Singleton<ManagementUtilities>.Instance.MushroomSpawns.Add(newSyringe.SpawnDefinition);
			AddSpawnToMushroomBeds(newSyringe.SpawnDefinition);
			AddSyringeToSpawnStations(newSyringe);
			((StorableItemDefinition)newSyringe).BasePurchasePrice = ((StorableItemDefinition)newSyringe).BasePurchasePrice + StashManager.GetIngredientCost((ProductDefinition)(object)shroomDef);
			UnicornSeedData newData = new UnicornSeedData
			{
				mixId = ((BaseItemDefinition)shroomDef).ID,
				drugType = (EDrugType)4
			};
			newData.SetSingleVariant("sporesyringe", ((BaseItemDefinition)newSyringe).ID, ((StorableItemDefinition)newSyringe).BasePurchasePrice);
			DiscoveredShrooms.Add(newData.mixId, newData);
			CreateShopListing(newSyringe, newData.price);
			DeadDrop randomDrop = DeadDrop.GetRandomEmptyDrop(((Component)Player.Local).transform.position);
			if ((Object)(object)randomDrop != (Object)null && InstanceFinder.IsServer)
			{
				ItemInstance defaultInstance = ((ItemDefinition)newSyringe).GetDefaultInstance(1);
				((BaseItemInstance)defaultInstance).SetQuantity(3);
				((StorageEntity)randomDrop.Storage).InsertItem(defaultInstance, true);
				string guidString = GUIDManager.GenerateUniqueGUID().ToString();
				NetworkSingleton<QuestManager>.Instance.CreateDeaddropCollectionQuest((NetworkConnection)null, randomDrop.GUID.ToString(), guidString);
				ConversationManager.SendMessage("Phil", ((Object)shroomDef).name + " syringe synthesized and placed in a dead drop.");
			}
			else
			{
				Utility.Error("No available dead drop for syringe placement.");
			}
		}

		public static void AddSpawnToMushroomBeds(ShroomSpawnDefinition newSpawn)
		{
			MushroomBed[] array = Object.FindObjectsOfType<MushroomBed>();
			MushroomBed[] array2 = array;
			foreach (MushroomBed val in array2)
			{
				EntityConfiguration configuration = val.Configuration;
				((MushroomBedConfiguration)(((configuration is MushroomBedConfiguration) ? configuration : null)?)).Spawn.Options.Add((ItemDefinition)(object)newSpawn);
			}
		}

		public static void AddSyringeToSpawnStations(SporeSyringeDefinition newSyringe)
		{
			MushroomSpawnStation[] array = Object.FindObjectsOfType<MushroomSpawnStation>();
			MushroomSpawnStation[] array2 = array;
			foreach (MushroomSpawnStation val in array2)
			{
				if (val.SyringeSlot == null)
				{
					continue;
				}
				foreach (ItemFilter hardFilter in val.SyringeSlot.HardFilters)
				{
					ItemFilter_ID val2 = (ItemFilter_ID)(object)((hardFilter is ItemFilter_ID) ? hardFilter : null);
					if (val2 != null && !val2.IDs.Contains(((BaseItemDefinition)newSyringe).ID))
					{
						val2.IDs.Add(((BaseItemDefinition)newSyringe).ID);
					}
				}
			}
		}

		public static void CreateShopListing(SporeSyringeDefinition newSyringe, float price = 10f)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)PhilShop == (Object)null))
			{
				ShopListing val = new ShopListing();
				val.name = $"{((BaseItemDefinition)newSyringe).ID} (${price}) (Shrooms, )";
				val.Item = (StorableItemDefinition)(object)newSyringe;
				val.IconTint = new Color(0.6f, 0.2f, 0.8f, 1f);
				val.MinimumGameCreationVersion = 27f;
				val.DefaultStock = 1000;
				val.CurrentStock = 100000;
				val.CanBeDelivered = true;
				PhilShop.Listings.Add(val);
				PhilShop.CreateListingUI(val);
				CreatePhoneShopListing(newSyringe);
				CreateDeliveryListing(val);
				PhilShop.RefreshShownItems();
			}
		}

		public static void CreatePhoneShopListing(SporeSyringeDefinition newSyringe)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if (!((Object)(object)phil == (Object)null))
			{
				Listing val = new Listing((StorableItemDefinition)(object)newSyringe);
				IEnumerable<Listing> source = CollectionExtensions.AddItem<Listing>((IEnumerable<Listing>)((Supplier)phil).SupplierData.DeliveryShopListings, val);
				((Supplier)phil).SupplierData.DeliveryShopListings = source.ToArray();
			}
		}

		public static void CreateDeliveryListing(ShopListing newListing)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_008c: 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)
			if (!((Object)(object)PhilShop == (Object)null))
			{
				DeliveryApp instance = PlayerSingleton<DeliveryApp>.Instance;
				DeliveryShop val = ((instance != null) ? instance.GetShop(PhilShop.ShopName) : null);
				if (!((Object)(object)val == (Object)null))
				{
					ListingEntry val2 = Object.Instantiate<ListingEntry>(val.ListingEntryPrefab, (Transform)(object)val.ListingContainer);
					val2.Initialize(newListing);
					val2.onQuantityChanged.AddListener(new UnityAction(val.RefreshCart));
					val.listingEntries.Add(val2);
					val.ListingContainer.sizeDelta = new Vector2(val.ListingContainer.sizeDelta.x, 230f + (float)Math.Ceiling((double)val.listingEntries.Count / 2.0) * 60f);
				}
			}
		}

		public static void ClearAll()
		{
			DiscoveredShrooms.Clear();
			PhilShop = null;
			PhilShopGo = null;
			phil = null;
			if (factory != null)
			{
				factory.DeleteChildren();
			}
		}
	}
	public static class DeferredPlantsManager
	{
		public struct DeferredSeedData
		{
			public Pot Pot;

			public string SeedId;

			public float Progress;
		}

		public struct HarvestableUpdateData
		{
			public int Index;

			public bool Active;
		}

		public static bool IsReplaying = false;

		public static HashSet<string> PendingPotGuids = new HashSet<string>();

		public static Dictionary<string, List<DeferredSeedData>> seedsToLoad = new Dictionary<string, List<DeferredSeedData>>();

		public static Dictionary<string, List<HarvestableUpdateData>> DeferredHarvestables = new Dictionary<string, List<HarvestableUpdateData>>();

		public static void AddDeferredSeed(Pot pot, string seedId, float progress)
		{
			if (seedsToLoad.ContainsKey(seedId))
			{
				seedsToLoad[seedId].Add(new DeferredSeedData
				{
					Pot = pot,
					SeedId = seedId,
					Progress = progress
				});
			}
			else
			{
				List<DeferredSeedData> list = new List<DeferredSeedData>();
				list.Add(new DeferredSeedData
				{
					Pot = pot,
					SeedId = seedId,
					Progress = progress
				});
				seedsToLoad.Add(seedId, list);
			}
			PendingPotGuids.Add(((BuildableItem)pot).GUID.ToString());
		}

		public static void AddHarvestableUpdate(string potGuid, int index, bool active)
		{
			if (!DeferredHarvestables.ContainsKey(potGuid))
			{
				DeferredHarvestables[potGuid] = new List<HarvestableUpdateData>();
			}
			DeferredHarvestables[potGuid].Add(new HarvestableUpdateData
			{
				Index = index,
				Active = active
			});
		}

		public static void TrySpawnQueuedPlants(string seedId)
		{
			if (!seedsToLoad.ContainsKey(seedId))
			{
				return;
			}
			List<DeferredSeedData> list = seedsToLoad[seedId];
			foreach (DeferredSeedData item in list)
			{
				item.Pot.PlantSeed_Client((NetworkConnection)null, item.SeedId, item.Progress);
				string text = ((BuildableItem)item.Pot).GUID.ToString();
				if (DeferredHarvestables.ContainsKey(text))
				{
					foreach (HarvestableUpdateData item2 in DeferredHarvestables[text])
					{
						item.Pot.Plant.SetHarvestableActive(item2.Index, item2.Active);
					}
					DeferredHarvestables.Remove(text);
				}
				PendingPotGuids.Remove(text);
			}
		}
	}
	public static class SeedQuestManager
	{
		public static CustomSeedQuest seedDropoff;

		public static string messageId = "Synthesize Seeds";

		public static bool IsWaitingForDropoff = false;

		private static float lastSentTime = 0f;

		public static bool HasActiveQuest => IsWaitingForDropoff;

		public static void Init()
		{
			if (QuestManager.GetQuestByName("Drop off the Mix") is CustomSeedQuest customSeedQuest)
			{
				seedDropoff = customSeedQuest;
				IsWaitingForDropoff = true;
			}
			else
			{
				IsWaitingForDropoff = false;
			}
			MSGConversation conversation = ConversationManager.GetConversation("Albert");
			if (conversation != null)
			{
				MessageSenderInterface senderInterface = conversation.senderInterface;
				SendableMessage val = conversation.CreateSendableMessage(messageId);
				val.onSent = (Action)Delegate.Combine(val.onSent, new Action(OnSent));
			}
		}

		public static void OnSent()
		{
			if (!InstanceFinder.IsServer || Time.time - lastSentTime < 1f)
			{
				return;
			}
			List<string> list = new List<string>();
			list.Add("Drop the weed mix and cash in my drop box.");
			ConversationManager.SendMessageChain("Albert", list);
			IsWaitingForDropoff = true;
			if (seedDropoff == null)
			{
				if (InstanceFinder.IsServer)
				{
					BroadcastCustomQuest();
				}
				seedDropoff = QuestManager.CreateQuest<CustomSeedQuest>((string)null) as CustomSeedQuest;
			}
		}

		public static void BroadcastCustomQuest()
		{
			//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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_009f: Expected O, but got Unknown
			ProductManager instance = NetworkSingleton<ProductManager>.Instance;
			string text = $"[NET-QUEST]{StashManager.StashCostEntry.Value},{StashManager.StashQtyEntry.Value},{StashManager.SynthesizeTime.Value}";
			List<string> list = new List<string>();
			WeedAppearanceSettings val = new WeedAppearanceSettings(Color32.op_Implicit(instance.DefaultWeed.MainMat.color), Color32.op_Implicit(instance.DefaultWeed.SecondaryMat.color), Color32.op_Implicit(instance.DefaultWeed.LeafMat.color), Color32.op_Implicit(instance.DefaultWeed.StemMat.color));
			instance.CreateWeed_Server(text, "ogkushseed", (EDrugType)0, list, val);
		}

		public static void CreateQuestAsync()
		{
			MelonCoroutines.Start(CreateQuestCoroutine());
		}

		private static IEnumerator CreateQuestCoroutine()
		{
			int attemptCount = 0;
			while (attemptCount < 5)
			{
				attemptCount++;
				try
				{
					if (QuestManager.GetQuestByName("Drop off the Mix") is CustomSeedQuest existingQuest)
					{
						seedDropoff = existingQuest;
						IsWaitingForDropoff = true;
						yield break;
					}
					seedDropoff = QuestManager.CreateQuest<CustomSeedQuest>((string)null) as CustomSeedQuest;
					if (seedDropoff != null)
					{
						IsWaitingForDropoff = true;
						yield break;
					}
				}
				catch
				{
				}
				if (attemptCount < 5)
				{
					yield return (object)new WaitForSeconds(1f);
				}
			}
			Utility.Error($"[CreateQuestAsync] Failed to Load Quest after {5} attempts");
		}

		public static void CompleteQuest()
		{
			if (seedDropoff != null)
			{
				((Quest)seedDropoff).Complete();
				seedDropoff = null;
			}
			IsWaitingForDropoff = false;
		}

		public static void SendMessage(string text)
		{
			ConversationManager.SendMessage("Albert", text);
		}

		public static void OnSelected()
		{
			MSGConversation conversation = ConversationManager.GetConversation("Albert");
			if (conversation != null)
			{
				conversation.senderInterface.SetVisibility((EVisibility)1);
			}
		}
	}
	public static class SeedVisualsManager
	{
		public enum BlendMode
		{
			Lerp,
			Multiply,
			Add,
			Screen
		}

		public static Dictionary<string, Sprite> seedIcons = new Dictionary<string, Sprite>();

		public static Dictionary<string, WeedAppearanceSettings> appearanceMap = new Dictionary<string, WeedAppearanceSettings>();

		public static Shader customShader;

		public static Material customMat;

		public static Sprite baseSeedSprite;

		public static Sprite seedIcon;

		public static BlendMode blendMode = BlendMode.Lerp;

		public static Rect gradientArea01 = new Rect(0.37f, 0.312f, 0.24f, 0.38f);

		public static float gradientOpacity = 1f;

		public static void LoadSeedMaterial()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			try
			{
				AssetBundleUtils.LoadAssetBundle("customshaders");
				Sprite val = AssetBundleUtils.LoadAssetFromBundle<Sprite>("customseed_icon.png", "customshaders");
				if ((Object)(object)val != (Object)null)
				{
					baseSeedSprite = val;
					Object.DontDestroyOnLoad((Object)(object)baseSeedSprite);
				}
				Sprite val2 = AssetBundleUtils.LoadAssetFromBundle<Sprite>("seedicon.png", "customshaders");
				if ((Object)(object)val2 != (Object)null)
				{
					seedIcon = val2;
					Object.DontDestroyOnLoad((Object)(object)seedIcon);
				}
				Shader val3 = AssetBundleUtils.LoadAssetFromBundle<Shader>("labelgradient.shader", "customshaders");
				if ((Object)(object)val3 != (Object)null)
				{
					customShader = val3;
					Material val4 = new Material(customShader);
					if ((Object)(object)val4 != (Object)null)
					{
						customMat = val4;
						Object.DontDestroyOnLoad((Object)(object)val3);
					}
				}
				else
				{
					Utility.Error("Fail");
				}
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
		}

		public static Sprite GenerateSpriteWithGradient(Color topColor, Color bottomColor)
		{
			//IL_004b: 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_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_012f: 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_0177: Expected O, but got Unknown
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)baseSeedSprite == (Object)null || (Object)(object)baseSeedSprite.texture == (Object)null)
			{
				Utility.Error("[VialTextureGenerator] Base Sprite is missing.");
				return null;
			}
			Texture2D texture = baseSeedSprite.texture;
			Rect rect = baseSeedSprite.rect;
			((Rect)(ref rect)).x = ((Rect)(ref rect)).x / (float)((Texture)texture).width;
			((Rect)(ref rect)).y = ((Rect)(ref rect)).y / (float)((Texture)texture).height;
			((Rect)(ref rect)).width = ((Rect)(ref rect)).width / (float)((Texture)texture).width;
			((Rect)(ref rect)).height = ((Rect)(ref rect)).height / (float)((Texture)texture).height;
			Color[] pixels = texture.GetPixels(Mathf.FloorToInt(((Rect)(ref rect)).x * (float)((Texture)texture).width), Mathf.FloorToInt(((Rect)(ref rect)).y * (float)((Texture)texture).height), Mathf.FloorToInt(((Rect)(ref rect)).width * (float)((Texture)texture).width), Mathf.FloorToInt(((Rect)(ref rect)).height * (float)((Texture)texture).height));
			ApplyVerticalGradientInRect(pixels, Mathf.FloorToInt(((Rect)(ref rect)).width * (float)((Texture)texture).width), Mathf.FloorToInt(((Rect)(ref rect)).height * (float)((Texture)texture).height), gradientArea01, topColor, bottomColor, gradientOpacity, blendMode);
			int num = Mathf.FloorToInt(((Rect)(ref rect)).width * (float)((Texture)texture).width);
			int num2 = Mathf.FloorToInt(((Rect)(ref rect)).height * (float)((Texture)texture).height);
			Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false);
			val.SetPixels(pixels);
			val.Apply();
			((Object)val).name = "Copy";
			return Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num2), new Vector2(0.5f, 0.5f));
		}

		private static void ApplyVerticalGradientInRect(Color[] pixels, int width, int height, Rect rect01, Color top, Color bottom, float opacity, BlendMode mode)
		{
			//IL_009e: Unknown result t