Decompiled source of UnicornsCustomSeeds v1.0.2

UnicornsCustomSeeds_IL2Cpp_1.0.2.dll

Decompiled 2 days 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.Connection;
using Il2CppFluffyUnderware.DevTools.Extensions;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.AvatarFramework.Equipping;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Dialogue;
using Il2CppScheduleOne.Economy;
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.Product;
using Il2CppScheduleOne.Product.Packaging;
using Il2CppScheduleOne.Quests;
using Il2CppScheduleOne.StationFramework;
using Il2CppScheduleOne.Storage;
using Il2CppScheduleOne.UI.MainMenu;
using Il2CppScheduleOne.UI.Phone.Messages;
using Il2CppScheduleOne.UI.Shop;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.IO;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using S1API.Quests;
using S1API.Saveables;
using UnicornsCustomSeeds;
using UnicornsCustomSeeds.Managers;
using UnicornsCustomSeeds.SeedQuests;
using UnicornsCustomSeeds.Seeds;
using UnicornsCustomSeeds.TemplateUtils;
using UnityEngine;
using UnityEngine.Events;

[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.0.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.0.2")]
[assembly: AssemblyConfiguration("IL2CPP")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: AssemblyInformationalVersion("1.0.0+e201a2dfb0a917f3ca9b295052f663041007cf2e")]
[assembly: AssemblyProduct("UnicornsCustomSeeds_IL2Cpp_1.0.2")]
[assembly: AssemblyTitle("UnicornsCustomSeeds_IL2Cpp_1.0.2")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
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.0.2";

		public const string DownloadLink = null;
	}
	public class Core : MelonMod
	{
		public override void OnLateInitializeMelon()
		{
			StashManager.InitializeConfig();
			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))
				{
					string path = Path.Combine(loadedGameFolderPath, "DiscoveredCustomSeeds.json");
					List<UnicornSeedData> list = CustomSeedsManager.DiscoveredSeeds.Values.ToList();
					string contents = JsonConvert.SerializeObject((object)list, (Formatting)1);
					File.WriteAllText(path, contents);
				}
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
		}

		public void InitMod()
		{
			CustomSeedsManager.Initialize();
			StashManager.GetAlbertsStash();
		}

		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);
			}
			if ((Object)(object)StashManager.albertsStash == (Object)null)
			{
				StashManager.GetAlbertsStash();
			}
			if (sceneName.ToLower() != "main")
			{
				CustomSeedsManager.ClearAll();
			}
		}
	}
	public static class Utility
	{
		public static void PrintException(Exception e)
		{
			MelonLogger.Msg(ConsoleColor.Red, e.Source);
			MelonLogger.Msg(ConsoleColor.DarkRed, e.Message);
		}

		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.TemplateUtils
{
	public static class AssetBundleUtils
	{
		private static Core mod = MelonAssembly.FindMelonInstance<Core>();

		private static MelonAssembly melonAssembly = ((MelonBase)mod).MelonAssembly;

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

		public static Il2CppAssetBundle LoadAssetBundle(string bundleFileName)
		{
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			if (assetBundles.ContainsKey(bundleFileName))
			{
				return assetBundles[bundleFileName];
			}
			try
			{
				string text = typeof(Core).Namespace + ".Assets." + bundleFileName;
				Stream manifestResourceStream = melonAssembly.Assembly.GetManifestResourceStream(text ?? "");
				if (manifestResourceStream == null)
				{
					((MelonBase)mod).Unregister($"AssetBundle: '{text}' not found. \nOpen .csproj file and search for '{bundleFileName}'.\nIf it doesn't exist,\nCopy your asset to Assets/ folder then look for 'your.assetbundle' in .csproj file.", false);
					return null;
				}
				byte[] array;
				using (MemoryStream memoryStream = new MemoryStream())
				{
					manifestResourceStream.CopyTo(memoryStream);
					array = memoryStream.ToArray();
				}
				Stream val = (Stream)new MemoryStream(Il2CppStructArray<byte>.op_Implicit(array));
				Il2CppAssetBundle val2 = Il2CppAssetBundleManager.LoadFromStream(val);
				assetBundles.Add(bundleFileName, val2);
				return val2;
			}
			catch (Exception value)
			{
				((MelonBase)mod).Unregister($"Failed to load AssetBundle. Please report to dev: {value}", false);
				return null;
			}
		}

		public static Il2CppAssetBundle GetLoadedAssetBundle(string bundleName)
		{
			if (assetBundles.ContainsKey(bundleName))
			{
				return assetBundles[bundleName];
			}
			((MelonBase)mod).Unregister("Failed to get " + bundleName, false);
			throw new Exception("Asset '" + bundleName + "' has not been loaded in yet");
		}

		public static T LoadAssetFromBundle<T>(string assetName, string bundleName) where T : Object
		{
			Il2CppAssetBundle loadedAssetBundle = GetLoadedAssetBundle(bundleName);
			if (loadedAssetBundle == null)
			{
				throw new Exception("Bundle not found for asset: " + assetName);
			}
			T result = loadedAssetBundle.LoadAsset<T>(assetName);
			if (loadedAssetBundle == null)
			{
				throw new Exception(assetName + " not found in bundle " + bundleName);
			}
			return result;
		}
	}
}
namespace UnicornsCustomSeeds.Seeds
{
	[Serializable]
	public class UnicornSeedData
	{
		public string seedId { get; set; }

		public string weedId { get; set; }

		public string baseSeedId { get; set; }

		public float price { get; set; }
	}
	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(((ItemDefinition)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 = ((ItemDefinition)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, ((ItemDefinition)newDef).ID);
			((Object)((Component)val).gameObject).name = ((ItemDefinition)newDef).ID + "_Equippable";
			((Component)val).gameObject.layer = ((Component)baseEquippableSeedPrefab).gameObject.layer;
			val.Seed = newDef;
			((Equippable_Viewmodel)val).AvatarEquippable = CloneAvatarEquippablePrefab(((ItemDefinition)newDef).ID);
			((Object)((Equippable_Viewmodel)val).AvatarEquippable).name = ((ItemDefinition)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 = ((ItemDefinition)weedDef).ID + "_customseeddefinition";
			((ItemDefinition)val).ID = ((ItemDefinition)weedDef).ID + "_customseeddefinition";
			((ItemDefinition)val).Name = ((Object)weedDef).name + " Seed";
			((ItemDefinition)val).Description = ((Object)weedDef).name + " Seed";
			((ItemDefinition)val).Icon = ((ItemDefinition)baseSeedDefinition).Icon;
			((ItemDefinition)val).Equippable = (Equippable)(object)CloneEquippableSeedPrefab(val, val2);
			val.PlantPrefab = (Plant)(object)ClonePlantPrefab(weedDef);
			val.PlantPrefab.SeedDefinition = val;
			val.FunctionSeedPrefab = CloneFunctionalSeedPrefab(((ItemDefinition)val).ID);
			((Object)val.FunctionSeedPrefab).name = ((ItemDefinition)weedDef).ID + "Seed_Functional";
			((StorableItemDefinition)val).StoredItem = CloneStoredItem(((ItemDefinition)val).ID);
			SeedVisualsManager.appearanceMap.Add(((ItemDefinition)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(((ItemDefinition)val).ID, val3);
					((ItemDefinition)val).Icon = val3;
				}
				catch (Exception e)
				{
					((ItemDefinition)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.Patches
{
	[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 && !((ItemDefinition)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;
				if (string.IsNullOrEmpty(loadedGameFolderPath))
				{
					return;
				}
				string path = Path.Combine(loadedGameFolderPath, "DiscoveredCustomSeeds.json");
				List<UnicornSeedData> list = new List<UnicornSeedData>();
				if (File.Exists(path))
				{
					CustomSeedsManager.FirstLoad = false;
					string text = File.ReadAllText(path);
					try
					{
						list = JsonConvert.DeserializeObject<List<UnicornSeedData>>(text) ?? new List<UnicornSeedData>();
						Utility.Success($"Successfully 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)
				{
					ItemDefinition val = Singleton<Registry>.Instance._GetItem(item.weedId, true);
					if (item != null && !CustomSeedsManager.DiscoveredSeeds.ContainsKey(item.weedId))
					{
						CustomSeedsManager.DiscoveredSeeds.Add(item.weedId, item);
					}
				}
			}
			catch (Exception value)
			{
				MelonLogger.Error($"Error handling DiscoveredCustomSeeds.json: {value}");
			}
		}
	}
	[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 (!CustomSeedsManager.DiscoveredSeeds.TryGetValue(id, out var value))
			{
				return;
			}
			SeedDefinition val = CustomSeedsManager.SeedDefinitionLoader(value);
			if ((Object)(object)val != (Object)null)
			{
				try
				{
					Singleton<ManagementUtilities>.Instance.Seeds.Add(val);
				}
				catch (Exception e)
				{
					Utility.PrintException(e);
				}
			}
		}
	}
}
namespace UnicornsCustomSeeds.SeedQuests
{
	public class CustomSeedQuest : Quest
	{
		public WeedDefinition WeedDefinition;

		[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.Managers
{
	public static class ConversationManager
	{
		[CompilerGenerated]
		private sealed class <WelcomeRoutine>d__10 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(10f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					AlbertWelcomeMessage((EUnlockType)1, temp: true);
					return false;
				}
			}

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

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

		public 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			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);
		}

		[IteratorStateMachine(typeof(<WelcomeRoutine>d__10))]
		private static IEnumerator WelcomeRoutine()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WelcomeRoutine>d__10(0);
		}
	}
	public static class SeedQuestManager
	{
		public static CustomSeedQuest seedDropoff;

		public static string messageId = "Synthesize Seeds";

		public static bool HasActiveQuest => QuestManager.GetQuestByName("Drop off the Mix") != null;

		public static void Init()
		{
			if (QuestManager.GetQuestByName("Drop off the Mix") is CustomSeedQuest customSeedQuest)
			{
				seedDropoff = customSeedQuest;
			}
			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()
		{
			List<string> list = new List<string>();
			list.Add("Drop the weed mix and cash in my drop box.");
			ConversationManager.SendMessageChain("Albert", list);
			if (seedDropoff == null)
			{
				seedDropoff = QuestManager.CreateQuest<CustomSeedQuest>((string)null) as CustomSeedQuest;
			}
		}

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

		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 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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;
				}
				Shader val2 = AssetBundleUtils.LoadAssetFromBundle<Shader>("labelgradient.shader", "customshaders");
				if ((Object)(object)val2 != (Object)null)
				{
					customShader = val2;
					Material val3 = new Material(customShader);
					if ((Object)(object)val3 != (Object)null)
					{
						customMat = 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Expected O, but got Unknown
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: 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[] array = Il2CppArrayBase<Color>.op_Implicit((Il2CppArrayBase<Color>)(object)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(array, 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(Il2CppStructArray<Color>.op_Implicit(array));
			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 type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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)
			int num = Mathf.RoundToInt(((Rect)(ref rect01)).x * (float)width);
			int num2 = Mathf.RoundToInt(((Rect)(ref rect01)).y * (float)height);
			int num3 = Mathf.RoundToInt(((Rect)(ref rect01)).width * (float)width);
			int num4 = Mathf.RoundToInt(((Rect)(ref rect01)).height * (float)height);
			num = Mathf.Clamp(num, 0, width);
			num2 = Mathf.Clamp(num2, 0, height);
			num3 = Mathf.Clamp(num3, 0, width - num);
			num4 = Mathf.Clamp(num4, 0, height - num2);
			if (num3 <= 0 || num4 <= 0)
			{
				return;
			}
			for (int i = 0; i < num4; i++)
			{
				float num5 = (float)i / (float)((num4 - 1 <= 0) ? 1 : (num4 - 1));
				Color dst = Color.Lerp(bottom, top, num5);
				dst.a *= opacity;
				int num6 = num2 + i;
				int num7 = num6 * width;
				for (int j = 0; j < num3; j++)
				{
					int num8 = num + j;
					int num9 = num7 + num8;
					Color src = pixels[num9];
					pixels[num9] = Blend(dst, src, mode);
				}
			}
		}

		private static Color Blend(Color dst, Color src, BlendMode mode)
		{
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: 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_013b: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			switch (mode)
			{
			case BlendMode.Multiply:
				return new Color(dst.r * Mathf.Lerp(1f, src.r, src.a), dst.g * Mathf.Lerp(1f, src.g, src.a), dst.b * Mathf.Lerp(1f, src.b, src.a), Mathf.Max(dst.a, src.a));
			case BlendMode.Add:
				return new Color(Mathf.Clamp01(dst.r + src.r * src.a), Mathf.Clamp01(dst.g + src.g * src.a), Mathf.Clamp01(dst.b + src.b * src.a), Mathf.Max(dst.a, src.a));
			case BlendMode.Screen:
			{
				float num = 1f - (1f - dst.r) * (1f - src.r * src.a);
				float num2 = 1f - (1f - dst.g) * (1f - src.g * src.a);
				float num3 = 1f - (1f - dst.b) * (1f - src.b * src.a);
				return new Color(num, num2, num3, Mathf.Max(dst.a, src.a));
			}
			default:
				return new Color(Mathf.Lerp(dst.r, src.r, src.a), Mathf.Lerp(dst.g, src.g, src.a), Mathf.Lerp(dst.b, src.b, src.a), Mathf.Max(dst.a, src.a));
			}
		}
	}
	public struct SeedComponents
	{
		public string seedId;

		public string baseSeedId;
	}
	public static class CustomSeedsManager
	{
		public delegate bool ValidityCheckDelegate(SendableMessage message, out String invalidReason);

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

			private object <>2__current;

			public WeedDefinition weedDef;

			private SeedDefinition <newSeed>5__1;

			private float <price>5__2;

			private UnicornSeedData <newSeedData>5__3;

			private Il2CppArrayBase<Pot> <pots>5__4;

			private DeadDrop <randomEmptyDrop>5__5;

			private IEnumerator<Pot> <>s__6;

			private Pot <pot>5__7;

			private PotConfiguration <config>5__8;

			private ItemInstance <defaultInstance>5__9;

			private string <guidString>5__10;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<newSeed>5__1 = null;
				<newSeedData>5__3 = null;
				<pots>5__4 = null;
				<randomEmptyDrop>5__5 = null;
				<>s__6 = null;
				<pot>5__7 = null;
				<config>5__8 = null;
				<defaultInstance>5__9 = null;
				<guidString>5__10 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_0207: Unknown result type (might be due to invalid IL or missing references)
				//IL_020c: Unknown result type (might be due to invalid IL or missing references)
				//IL_022b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0230: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds((float)StashManager.SynthesizeTime.Value);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<newSeed>5__1 = factory.CreateSeedDefinition(weedDef);
					Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)<newSeed>5__1);
					<price>5__2 = StashManager.GetIngredientCost((ProductDefinition)(object)weedDef);
					<newSeedData>5__3 = new UnicornSeedData
					{
						seedId = ((ItemDefinition)<newSeed>5__1).ID,
						weedId = ((ItemDefinition)weedDef).ID,
						baseSeedId = "ogkushseed",
						price = <price>5__2
					};
					DiscoveredSeeds.Add(((ItemDefinition)<newSeed>5__1).ID, <newSeedData>5__3);
					CreateShopListing(<newSeed>5__1, <price>5__2);
					<pots>5__4 = Object.FindObjectsOfType<Pot>();
					<>s__6 = <pots>5__4.GetEnumerator();
					try
					{
						while (<>s__6.MoveNext())
						{
							<pot>5__7 = <>s__6.Current;
							<config>5__8 = ((Il2CppObjectBase)<pot>5__7.Configuration).TryCast<PotConfiguration>();
							if (<config>5__8 != null)
							{
								<config>5__8.Seed.Options.Add((ItemDefinition)(object)<newSeed>5__1);
							}
							<config>5__8 = null;
							<pot>5__7 = null;
						}
					}
					finally
					{
						if (<>s__6 != null)
						{
							<>s__6.Dispose();
						}
					}
					<>s__6 = null;
					<randomEmptyDrop>5__5 = DeadDrop.GetRandomEmptyDrop(((Component)Player.Local).transform.position);
					if ((Object)(object)<randomEmptyDrop>5__5 != (Object)null)
					{
						<defaultInstance>5__9 = ((ItemDefinition)<newSeed>5__1).GetDefaultInstance(1);
						<defaultInstance>5__9.SetQuantity(10);
						((StorageEntity)<randomEmptyDrop>5__5.Storage).InsertItem(<defaultInstance>5__9, true);
						Guid val = GUIDManager.GenerateUniqueGUID();
						<guidString>5__10 = ((object)(Guid)(ref val)).ToString();
						QuestManager instance = NetworkSingleton<QuestManager>.Instance;
						val = <randomEmptyDrop>5__5.GUID;
						instance.CreateDeaddropCollectionQuest((NetworkConnection)null, ((object)(Guid)(ref val)).ToString(), <guidString>5__10);
						SeedQuestManager.SendMessage(((Object)weedDef).name + " is synthesized and placed in the deaddrop");
						<defaultInstance>5__9 = null;
						<guidString>5__10 = null;
					}
					else
					{
						SeedQuestManager.SendMessage(((Object)weedDef).name + " is synthesized and available in the shop");
					}
					return false;
				}
			}

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

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

		public const string BASE_SEED_ID = "ogkushseed";

		public static SeedFactory factory;

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

		public static ShopInterface Shop = null;

		public static GameObject shopGo = null;

		public static Dictionary<string, SeedDefinition> baseSeedDefinitions = new Dictionary<string, SeedDefinition>();

		public static Dictionary<string, ShopListing> baseShopListing = new Dictionary<string, ShopListing>();

		public static bool FirstLoad = false;

		public static void Initialize()
		{
			Il2CppArrayBase<ShopInterface> val = Object.FindObjectsOfType<ShopInterface>();
			foreach (ShopInterface item2 in val)
			{
				if (((Object)((Component)item2).gameObject).name == "WeedSupplierInterface")
				{
					Utility.Log("Found Weed Supplier Interface");
					shopGo = ((Component)item2).gameObject;
					Shop = item2;
					break;
				}
			}
			if ((Object)(object)Shop == (Object)null)
			{
				Utility.Error("Shop is null!");
				return;
			}
			ConversationManager.Init();
			SeedQuestManager.Init();
			SeedVisualsManager.LoadSeedMaterial();
			InitDictionary();
			foreach (KeyValuePair<string, UnicornSeedData> discoveredSeed in DiscoveredSeeds)
			{
				SeedDefinition item = Registry.GetItem<SeedDefinition>(discoveredSeed.Value.seedId);
				if ((Object)(object)item != (Object)null)
				{
					CreateShopListing(item, discoveredSeed.Value.price);
				}
			}
		}

		public static void ClearAll()
		{
			SeedVisualsManager.seedIcons.Clear();
			SeedVisualsManager.appearanceMap.Clear();
			SeedQuestManager.seedDropoff = null;
			DiscoveredSeeds.Clear();
			factory.DeleteChildren();
			FirstLoad = false;
		}

		public static void StartSeedCreation(WeedDefinition weedDef)
		{
			MelonCoroutines.Start(CreateSeed(weedDef));
		}

		public static void BroadcastCustomSeed(UnicornSeedData seed)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			ProductManager instance = NetworkSingleton<ProductManager>.Instance;
			string text = JsonConvert.SerializeObject((object)seed);
			string text2 = "[UNISEED]" + text;
			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(text2, "ogkushseed", (EDrugType)0, val, val2);
		}

		[IteratorStateMachine(typeof(<CreateSeed>d__13))]
		public static IEnumerator CreateSeed(WeedDefinition weedDef)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CreateSeed>d__13(0)
			{
				weedDef = weedDef
			};
		}

		public static void InitDictionary()
		{
			List<ShopListing> listings = Shop.Listings;
			Enumerator<ShopListing> enumerator = listings.GetEnumerator();
			while (enumerator.MoveNext())
			{
				ShopListing current = enumerator.Current;
				SeedDefinition val = ((Il2CppObjectBase)current.Item).TryCast<SeedDefinition>();
				if (val != null)
				{
					if (!baseSeedDefinitions.ContainsKey(((ItemDefinition)val).ID))
					{
						baseSeedDefinitions.Add(((ItemDefinition)val).ID, val);
						baseShopListing.Add(((ItemDefinition)val).ID, current);
					}
				}
				else
				{
					MelonLogger.Warning(current.name + " could not be cast to SeedDefinition");
				}
			}
		}

		public static void CreateShopListing(SeedDefinition newSeed, float price = 10f)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			ShopListing val = Shop.Listings[0];
			val.name = "Test";
			ShopListing val2 = new ShopListing();
			val2.name = $"{((ItemDefinition)newSeed).ID} (${price}) (Agriculture, )";
			val2.OverridePrice = true;
			val2.OverriddenPrice = price;
			val2.Item = (StorableItemDefinition)(object)newSeed;
			val2.IconTint = new Color(0f, 0.859f, 1f, 1f);
			val2.MinimumGameCreationVersion = 27f;
			val2.DefaultStock = 1000;
			val2.CurrentStock = 100000;
			Shop.Listings.Add(val2);
			Shop.CreateListingUI(val2);
			Shop.RefreshShownItems();
		}

		public static void SeedFactoryLoader()
		{
			SeedDefinition item = Registry.GetItem<SeedDefinition>("ogkushseed");
			if ((Object)(object)item != (Object)null)
			{
				factory = new SeedFactory(item);
			}
		}

		public static SeedDefinition SeedDefinitionLoader(UnicornSeedData newSeedData)
		{
			SeedDefinition val = null;
			WeedDefinition item = Registry.GetItem<WeedDefinition>(newSeedData.weedId);
			if ((Object)(object)item != (Object)null)
			{
				val = factory.CreateSeedDefinition(item);
				if ((Object)(object)val == (Object)null)
				{
					Utility.Log("New Seed returned null?");
				}
				Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val);
			}
			else
			{
				MelonLogger.Error("Could not parse weed and seed defitions");
			}
			return val;
		}
	}
	public static class StashManager
	{
		private static Dictionary<string, List<PropertyItemDefinition>> ingredientsCache = new Dictionary<string, List<PropertyItemDefinition>>();

		private static Dictionary<string, float> ingredientCostCache = new Dictionary<string, float>();

		public static SupplierStash albertsStash;

		public static bool onClosedExecuting = false;

		public static MelonPreferences_Category ConfigCategory;

		public static MelonPreferences_Entry<int> StashCostEntry;

		public static MelonPreferences_Entry<int> StashQtyEntry;

		public static MelonPreferences_Entry<int> SynthesizeTime;

		public static void InitializeConfig()
		{
			ConfigCategory = MelonPreferences.CreateCategory("Unicorns Custom Seeds");
			StashCostEntry = ConfigCategory.CreateEntry<int>("StashCostRequirement", 500, "Stash Cost Requirement", "The price that Albert charges to synthesize seeds", false, false, (ValueValidator)null, (string)null);
			StashQtyEntry = ConfigCategory.CreateEntry<int>("StashQtyRequirement", 20, "Stash Quantity Requirement", "The quantity of weed that needs to be provided of a certain mix", false, false, (ValueValidator)null, (string)null);
			SynthesizeTime = ConfigCategory.CreateEntry<int>("SynthesizeTime", 30, "Synthesize Time", "Time in secondsd that it will take for Albert to synthesize a seed", false, false, (ValueValidator)null, (string)null);
		}

		public static void GetAlbertsStash()
		{
			Il2CppArrayBase<SupplierStash> val = Object.FindObjectsOfType<SupplierStash>();
			foreach (SupplierStash item in val)
			{
				if ((Object)(object)item != (Object)null && ((Object)((Component)item).gameObject).name.ToLower().Contains("albert"))
				{
					Utility.Log("Alberts Ready to Synthesize");
					albertsStash = item;
					StorageEntity storage = item.Storage;
					storage.onClosed += Action.op_Implicit((Action)AlbertsStashClosed);
				}
			}
		}

		public static void AlbertsStashClosed()
		{
			if (onClosedExecuting)
			{
				return;
			}
			onClosedExecuting = true;
			ItemSlot val = null;
			CashInstance val2 = null;
			ItemSlot val3 = null;
			WeedInstance val4 = null;
			List<ItemInstance> allItems = albertsStash.Storage.GetAllItems();
			Enumerator<ItemSlot> enumerator = albertsStash.Storage.ItemSlots.GetEnumerator();
			while (enumerator.MoveNext())
			{
				ItemSlot current = enumerator.Current;
				if (((current != null) ? current.ItemInstance : null) == null)
				{
					continue;
				}
				CashInstance val5 = ((Il2CppObjectBase)current.ItemInstance).TryCast<CashInstance>();
				if (val5 != null)
				{
					val = current;
					val2 = val5;
					continue;
				}
				WeedInstance val6 = ((Il2CppObjectBase)current.ItemInstance).TryCast<WeedInstance>();
				if (val6 != null)
				{
					val3 = current;
					val4 = val6;
				}
			}
			if (val2 != null && val4 != null)
			{
				PackagingDefinition appliedPackaging = ((ProductItemInstance)val4).AppliedPackaging;
				string packaging = ((appliedPackaging != null) ? ((ItemDefinition)appliedPackaging).Name : null);
				int quantity = ((ItemInstance)val4).Quantity;
				uint num = PackageAmount(packaging);
				if (num == 0)
				{
					return;
				}
				uint num2 = (uint)(quantity * num);
				if (val2.Balance >= (float)StashCostEntry.Value && num2 >= StashQtyEntry.Value)
				{
					WeedDefinition val7 = ((Il2CppObjectBase)((ItemInstance)val4).Definition).TryCast<WeedDefinition>();
					if ((Object)(object)val7 != (Object)null && !CustomSeedsManager.DiscoveredSeeds.ContainsKey(((ItemInstance)val4).Definition.ID) && SeedQuestManager.HasActiveQuest)
					{
						val3.ChangeQuantity(-(StashQtyEntry.Value / (int)num), false);
						val2.ChangeBalance((float)(-StashCostEntry.Value));
						SeedQuestManager.CompleteQuest();
						SeedQuestManager.SendMessage("I will begin synthesizing the seed");
						CustomSeedsManager.StartSeedCreation(val7);
					}
				}
			}
			onClosedExecuting = false;
		}

		private static uint PackageAmount(string packaging)
		{
			if (1 == 0)
			{
			}
			uint result = packaging switch
			{
				"Brick" => 20u, 
				"Jar" => 5u, 
				"Baggie" => 1u, 
				_ => 0u, 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		public static WeedDefinition GetBaseStrain(ProductDefinition product)
		{
			List<PropertyItemDefinition> recipe = GetRecipe(product);
			PropertyItemDefinition val = recipe[0];
			WeedDefinition val2 = ((Il2CppObjectBase)val).TryCast<WeedDefinition>();
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
			return null;
		}

		public static List<PropertyItemDefinition> GetRecipe(ProductDefinition product)
		{
			if (ingredientsCache.ContainsKey(((ItemDefinition)product).ID))
			{
				return ingredientsCache[((ItemDefinition)product).ID];
			}
			return DeepSearchRecipe(product);
		}

		public static float GetIngredientCost(ProductDefinition product)
		{
			if (ingredientCostCache.ContainsKey(((ItemDefinition)product).ID))
			{
				return ingredientCostCache[((ItemDefinition)product).ID];
			}
			List<PropertyItemDefinition> recipe = GetRecipe(product);
			float num = CalculateTotalCost(recipe);
			ingredientCostCache.Add(((ItemDefinition)product).ID, num);
			return num;
		}

		public static void ProcessNewRecipe(ProductDefinition product)
		{
			if (!((Object)(object)product == (Object)null))
			{
				List<PropertyItemDefinition> ingredients = DeepSearchRecipe(product);
				float num = CalculateTotalCost(ingredients);
			}
		}

		private static float CalculateTotalCost(List<PropertyItemDefinition> ingredients)
		{
			float num = 0f;
			foreach (PropertyItemDefinition ingredient in ingredients)
			{
				if (!(ingredient is ProductDefinition))
				{
					num += ((StorableItemDefinition)ingredient).BasePurchasePrice;
				}
			}
			return num;
		}

		public static List<PropertyItemDefinition> DeepSearchRecipe(ProductDefinition product)
		{
			if (ingredientsCache.ContainsKey(((ItemDefinition)product).ID))
			{
				return ingredientsCache[((ItemDefinition)product).ID];
			}
			List<PropertyItemDefinition> list = new List<PropertyItemDefinition>();
			HashSet<string> visited = new HashSet<string>();
			DeepSearchRecursive(product, list, visited);
			ingredientsCache.Add(((ItemDefinition)product).ID, list);
			return list;
		}

		private static void DeepSearchRecursive(ProductDefinition product, List<PropertyItemDefinition> result, HashSet<string> visited)
		{
			if ((Object)(object)product == (Object)null || visited.Contains(((ItemDefinition)product).ID))
			{
				return;
			}
			visited.Add(((ItemDefinition)product).ID);
			if (product.Recipes.Count == 0)
			{
				result.Insert(0, (PropertyItemDefinition)(object)product);
				return;
			}
			Enumerator<IngredientQuantity> enumerator = product.Recipes[0].Ingredients.GetEnumerator();
			while (enumerator.MoveNext())
			{
				IngredientQuantity current = enumerator.Current;
				if (current == null)
				{
					continue;
				}
				ProductDefinition val = ((Il2CppObjectBase)current.Item).TryCast<ProductDefinition>();
				if (val != null)
				{
					DeepSearchRecursive(val, result, visited);
					continue;
				}
				PropertyItemDefinition val2 = ((Il2CppObjectBase)current.Item).TryCast<PropertyItemDefinition>();
				if (val2 != null)
				{
					result.Add(val2);
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}

UnicornsCustomSeeds_Mono_1.0.2.dll

Decompiled 2 days 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.Connection;
using FluffyUnderware.DevTools.Extensions;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using S1API.Quests;
using S1API.Saveables;
using ScheduleOne;
using ScheduleOne.AvatarFramework.Equipping;
using ScheduleOne.DevUtilities;
using ScheduleOne.Dialogue;
using ScheduleOne.Economy;
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.Product;
using ScheduleOne.Quests;
using ScheduleOne.StationFramework;
using ScheduleOne.Storage;
using ScheduleOne.UI.MainMenu;
using ScheduleOne.UI.Phone.Messages;
using ScheduleOne.UI.Shop;
using UnicornsCustomSeeds;
using UnicornsCustomSeeds.Managers;
using UnicornsCustomSeeds.SeedQuests;
using UnicornsCustomSeeds.Seeds;
using UnicornsCustomSeeds.TemplateUtils;
using UnityEngine;
using UnityEngine.Events;

[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.0.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: AssemblyCompany("UnicornsCustomSeeds_Mono_1.0.2")]
[assembly: AssemblyConfiguration("MONO")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: AssemblyInformationalVersion("1.0.0+e201a2dfb0a917f3ca9b295052f663041007cf2e")]
[assembly: AssemblyProduct("UnicornsCustomSeeds_Mono_1.0.2")]
[assembly: AssemblyTitle("UnicornsCustomSeeds_Mono_1.0.2")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
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.0.2";

		public const string DownloadLink = null;
	}
	public class Core : MelonMod
	{
		public override void OnLateInitializeMelon()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			StashManager.InitializeConfig();
			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))
				{
					string path = Path.Combine(loadedGameFolderPath, "DiscoveredCustomSeeds.json");
					List<UnicornSeedData> list = CustomSeedsManager.DiscoveredSeeds.Values.ToList();
					string contents = JsonConvert.SerializeObject((object)list, (Formatting)1);
					File.WriteAllText(path, contents);
				}
			}
			catch (Exception e)
			{
				Utility.PrintException(e);
			}
		}

		public void InitMod()
		{
			CustomSeedsManager.Initialize();
			StashManager.GetAlbertsStash();
		}

		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);
			}
			if ((Object)(object)StashManager.albertsStash == (Object)null)
			{
				StashManager.GetAlbertsStash();
			}
			if (sceneName.ToLower() != "main")
			{
				CustomSeedsManager.ClearAll();
			}
		}
	}
	public static class Utility
	{
		public static void PrintException(Exception e)
		{
			MelonLogger.Msg(ConsoleColor.Red, e.Source);
			MelonLogger.Msg(ConsoleColor.DarkRed, e.Message);
		}

		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.TemplateUtils
{
	public static class AssetBundleUtils
	{
		private static Core mod = MelonAssembly.FindMelonInstance<Core>();

		private static MelonAssembly melonAssembly = ((MelonBase)mod).MelonAssembly;

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

		public static AssetBundle LoadAssetBundle(string bundleFileName)
		{
			if (assetBundles.ContainsKey(bundleFileName))
			{
				return assetBundles[bundleFileName];
			}
			try
			{
				string text = typeof(Core).Namespace + ".Assets." + bundleFileName;
				Stream manifestResourceStream = melonAssembly.Assembly.GetManifestResourceStream(text ?? "");
				if (manifestResourceStream == null)
				{
					((MelonBase)mod).Unregister("AssetBundle: '" + text + "' not found. \nOpen .csproj file and search for '" + bundleFileName + "'.\nIf it doesn't exist,\nCopy your asset to Assets/ folder then look for 'your.assetbundle' in .csproj file.", false);
					return null;
				}
				AssetBundle val = AssetBundle.LoadFromStream(manifestResourceStream);
				assetBundles.Add(bundleFileName, val);
				return val;
			}
			catch (Exception arg)
			{
				((MelonBase)mod).Unregister($"Failed to load AssetBundle. Please report to dev: {arg}", false);
				return null;
			}
		}

		public static AssetBundle GetLoadedAssetBundle(string bundleName)
		{
			if (assetBundles.ContainsKey(bundleName))
			{
				return assetBundles[bundleName];
			}
			((MelonBase)mod).Unregister("Failed to get " + bundleName, false);
			throw new Exception("Asset '" + bundleName + "' has not been loaded in yet");
		}

		public static T LoadAssetFromBundle<T>(string assetName, string bundleName) where T : Object
		{
			AssetBundle loadedAssetBundle = GetLoadedAssetBundle(bundleName);
			if ((Object)(object)loadedAssetBundle == (Object)null)
			{
				throw new Exception("Bundle not found for asset: " + assetName);
			}
			T result = loadedAssetBundle.LoadAsset<T>(assetName);
			if ((Object)(object)loadedAssetBundle == (Object)null)
			{
				throw new Exception(assetName + " not found in bundle " + bundleName);
			}
			return result;
		}
	}
}
namespace UnicornsCustomSeeds.Seeds
{
	[Serializable]
	public class UnicornSeedData
	{
		public string seedId { get; set; }

		public string weedId { get; set; }

		public string baseSeedId { get; set; }

		public float price { get; set; }
	}
	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(((ItemDefinition)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 = ((ItemDefinition)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, ((ItemDefinition)newDef).ID);
			((Object)((Component)val).gameObject).name = ((ItemDefinition)newDef).ID + "_Equippable";
			((Component)val).gameObject.layer = ((Component)baseEquippableSeedPrefab).gameObject.layer;
			val.Seed = newDef;
			((Equippable_Viewmodel)val).AvatarEquippable = CloneAvatarEquippablePrefab(((ItemDefinition)newDef).ID);
			((Object)((Equippable_Viewmodel)val).AvatarEquippable).name = ((ItemDefinition)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 = ((ItemDefinition)weedDef).ID + "_customseeddefinition";
			((ItemDefinition)val).ID = ((ItemDefinition)weedDef).ID + "_customseeddefinition";
			((ItemDefinition)val).Name = ((Object)weedDef).name + " Seed";
			((ItemDefinition)val).Description = ((Object)weedDef).name + " Seed";
			((ItemDefinition)val).Icon = ((ItemDefinition)baseSeedDefinition).Icon;
			((ItemDefinition)val).Equippable = (Equippable)(object)CloneEquippableSeedPrefab(val, val2);
			val.PlantPrefab = (Plant)(object)ClonePlantPrefab(weedDef);
			val.PlantPrefab.SeedDefinition = val;
			val.FunctionSeedPrefab = CloneFunctionalSeedPrefab(((ItemDefinition)val).ID);
			((Object)val.FunctionSeedPrefab).name = ((ItemDefinition)weedDef).ID + "Seed_Functional";
			((StorableItemDefinition)val).StoredItem = CloneStoredItem(((ItemDefinition)val).ID);
			SeedVisualsManager.appearanceMap.Add(((ItemDefinition)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(((ItemDefinition)val).ID, val3);
					((ItemDefinition)val).Icon = val3;
				}
				catch (Exception e)
				{
					((ItemDefinition)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.Patches
{
	[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 && !((ItemDefinition)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;
				if (string.IsNullOrEmpty(loadedGameFolderPath))
				{
					return;
				}
				string path = Path.Combine(loadedGameFolderPath, "DiscoveredCustomSeeds.json");
				List<UnicornSeedData> list = new List<UnicornSeedData>();
				if (File.Exists(path))
				{
					CustomSeedsManager.FirstLoad = false;
					string text = File.ReadAllText(path);
					try
					{
						list = JsonConvert.DeserializeObject<List<UnicornSeedData>>(text) ?? new List<UnicornSeedData>();
						Utility.Success($"Successfully 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)
				{
					ItemDefinition val = Singleton<Registry>.Instance._GetItem(item.weedId, true);
					if (item != null && !CustomSeedsManager.DiscoveredSeeds.ContainsKey(item.weedId))
					{
						CustomSeedsManager.DiscoveredSeeds.Add(item.weedId, item);
					}
				}
			}
			catch (Exception arg)
			{
				MelonLogger.Error($"Error handling DiscoveredCustomSeeds.json: {arg}");
			}
		}
	}
	[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 (!CustomSeedsManager.DiscoveredSeeds.TryGetValue(id, out var value))
			{
				return;
			}
			SeedDefinition val = CustomSeedsManager.SeedDefinitionLoader(value);
			if ((Object)(object)val != (Object)null)
			{
				try
				{
					Singleton<ManagementUtilities>.Instance.Seeds.Add(val);
				}
				catch (Exception e)
				{
					Utility.PrintException(e);
				}
			}
		}
	}
}
namespace UnicornsCustomSeeds.SeedQuests
{
	public class CustomSeedQuest : Quest
	{
		public WeedDefinition WeedDefinition;

		[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.Managers
{
	public static class ConversationManager
	{
		[CompilerGenerated]
		private sealed class <WelcomeRoutine>d__10 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(10f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					AlbertWelcomeMessage((EUnlockType)1, temp: true);
					return false;
				}
			}

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

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

		public 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			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);
		}

		[IteratorStateMachine(typeof(<WelcomeRoutine>d__10))]
		private static IEnumerator WelcomeRoutine()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WelcomeRoutine>d__10(0);
		}
	}
	public static class SeedQuestManager
	{
		public static CustomSeedQuest seedDropoff;

		public static string messageId = "Synthesize Seeds";

		public static bool HasActiveQuest => QuestManager.GetQuestByName("Drop off the Mix") != null;

		public static void Init()
		{
			if (QuestManager.GetQuestByName("Drop off the Mix") is CustomSeedQuest customSeedQuest)
			{
				seedDropoff = customSeedQuest;
			}
			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()
		{
			List<string> list = new List<string>();
			list.Add("Drop the weed mix and cash in my drop box.");
			ConversationManager.SendMessageChain("Albert", list);
			if (seedDropoff == null)
			{
				seedDropoff = QuestManager.CreateQuest<CustomSeedQuest>((string)null) as CustomSeedQuest;
			}
		}

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

		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 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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;
				}
				Shader val2 = AssetBundleUtils.LoadAssetFromBundle<Shader>("labelgradient.shader", "customshaders");
				if ((Object)(object)val2 != (Object)null)
				{
					customShader = val2;
					Material val3 = new Material(customShader);
					if ((Object)(object)val3 != (Object)null)
					{
						customMat = 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 type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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)
			int num = Mathf.RoundToInt(((Rect)(ref rect01)).x * (float)width);
			int num2 = Mathf.RoundToInt(((Rect)(ref rect01)).y * (float)height);
			int num3 = Mathf.RoundToInt(((Rect)(ref rect01)).width * (float)width);
			int num4 = Mathf.RoundToInt(((Rect)(ref rect01)).height * (float)height);
			num = Mathf.Clamp(num, 0, width);
			num2 = Mathf.Clamp(num2, 0, height);
			num3 = Mathf.Clamp(num3, 0, width - num);
			num4 = Mathf.Clamp(num4, 0, height - num2);
			if (num3 <= 0 || num4 <= 0)
			{
				return;
			}
			for (int i = 0; i < num4; i++)
			{
				float num5 = (float)i / (float)((num4 - 1 <= 0) ? 1 : (num4 - 1));
				Color dst = Color.Lerp(bottom, top, num5);
				dst.a *= opacity;
				int num6 = num2 + i;
				int num7 = num6 * width;
				for (int j = 0; j < num3; j++)
				{
					int num8 = num + j;
					int num9 = num7 + num8;
					Color src = pixels[num9];
					pixels[num9] = Blend(dst, src, mode);
				}
			}
		}

		private static Color Blend(Color dst, Color src, BlendMode mode)
		{
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: 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_013b: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			switch (mode)
			{
			case BlendMode.Multiply:
				return new Color(dst.r * Mathf.Lerp(1f, src.r, src.a), dst.g * Mathf.Lerp(1f, src.g, src.a), dst.b * Mathf.Lerp(1f, src.b, src.a), Mathf.Max(dst.a, src.a));
			case BlendMode.Add:
				return new Color(Mathf.Clamp01(dst.r + src.r * src.a), Mathf.Clamp01(dst.g + src.g * src.a), Mathf.Clamp01(dst.b + src.b * src.a), Mathf.Max(dst.a, src.a));
			case BlendMode.Screen:
			{
				float num = 1f - (1f - dst.r) * (1f - src.r * src.a);
				float num2 = 1f - (1f - dst.g) * (1f - src.g * src.a);
				float num3 = 1f - (1f - dst.b) * (1f - src.b * src.a);
				return new Color(num, num2, num3, Mathf.Max(dst.a, src.a));
			}
			default:
				return new Color(Mathf.Lerp(dst.r, src.r, src.a), Mathf.Lerp(dst.g, src.g, src.a), Mathf.Lerp(dst.b, src.b, src.a), Mathf.Max(dst.a, src.a));
			}
		}
	}
	public struct SeedComponents
	{
		public string seedId;

		public string baseSeedId;
	}
	public static class CustomSeedsManager
	{
		public delegate bool ValidityCheckDelegate(SendableMessage message, out string invalidReason);

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

			private object <>2__current;

			public WeedDefinition weedDef;

			private SeedDefinition <newSeed>5__1;

			private float <price>5__2;

			private UnicornSeedData <newSeedData>5__3;

			private Pot[] <pots>5__4;

			private DeadDrop <randomEmptyDrop>5__5;

			private Pot[] <>s__6;

			private int <>s__7;

			private Pot <pot>5__8;

			private PotConfiguration <config>5__9;

			private ItemInstance <defaultInstance>5__10;

			private string <guidString>5__11;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<newSeed>5__1 = null;
				<newSeedData>5__3 = null;
				<pots>5__4 = null;
				<randomEmptyDrop>5__5 = null;
				<>s__6 = null;
				<pot>5__8 = null;
				<config>5__9 = null;
				<defaultInstance>5__10 = null;
				<guidString>5__11 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds((float)StashManager.SynthesizeTime.Value);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<newSeed>5__1 = factory.CreateSeedDefinition(weedDef);
					Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)<newSeed>5__1);
					<price>5__2 = StashManager.GetIngredientCost((ProductDefinition)(object)weedDef);
					<newSeedData>5__3 = new UnicornSeedData
					{
						seedId = ((ItemDefinition)<newSeed>5__1).ID,
						weedId = ((ItemDefinition)weedDef).ID,
						baseSeedId = "ogkushseed",
						price = <price>5__2
					};
					DiscoveredSeeds.Add(((ItemDefinition)<newSeed>5__1).ID, <newSeedData>5__3);
					CreateShopListing(<newSeed>5__1, <price>5__2);
					<pots>5__4 = Object.FindObjectsOfType<Pot>();
					<>s__6 = <pots>5__4;
					for (<>s__7 = 0; <>s__7 < <>s__6.Length; <>s__7++)
					{
						<pot>5__8 = <>s__6[<>s__7];
						EntityConfiguration configuration = <pot>5__8.Configuration;
						<config>5__9 = (PotConfiguration)(object)((configuration is PotConfiguration) ? configuration : null);
						if (<config>5__9 != null)
						{
							<config>5__9.Seed.Options.Add((ItemDefinition)(object)<newSeed>5__1);
						}
						<config>5__9 = null;
						<pot>5__8 = null;
					}
					<>s__6 = null;
					<randomEmptyDrop>5__5 = DeadDrop.GetRandomEmptyDrop(((Component)Player.Local).transform.position);
					if ((Object)(object)<randomEmptyDrop>5__5 != (Object)null)
					{
						<defaultInstance>5__10 = ((ItemDefinition)<newSeed>5__1).GetDefaultInstance(1);
						<defaultInstance>5__10.SetQuantity(10);
						((StorageEntity)<randomEmptyDrop>5__5.Storage).InsertItem(<defaultInstance>5__10, true);
						<guidString>5__11 = GUIDManager.GenerateUniqueGUID().ToString();
						NetworkSingleton<QuestManager>.Instance.CreateDeaddropCollectionQuest((NetworkConnection)null, <randomEmptyDrop>5__5.GUID.ToString(), <guidString>5__11);
						SeedQuestManager.SendMessage(((Object)weedDef).name + " is synthesized and placed in the deaddrop");
						<defaultInstance>5__10 = null;
						<guidString>5__11 = null;
					}
					else
					{
						SeedQuestManager.SendMessage(((Object)weedDef).name + " is synthesized and available in the shop");
					}
					return false;
				}
			}

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

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

		public const string BASE_SEED_ID = "ogkushseed";

		public static SeedFactory factory;

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

		public static ShopInterface Shop = null;

		public static GameObject shopGo = null;

		public static Dictionary<string, SeedDefinition> baseSeedDefinitions = new Dictionary<string, SeedDefinition>();

		public static Dictionary<string, ShopListing> baseShopListing = new Dictionary<string, ShopListing>();

		public static bool FirstLoad = false;

		public static void Initialize()
		{
			ShopInterface[] array = Object.FindObjectsOfType<ShopInterface>();
			ShopInterface[] array2 = array;
			foreach (ShopInterface val in array2)
			{
				if (((Object)((Component)val).gameObject).name == "WeedSupplierInterface")
				{
					Utility.Log("Found Weed Supplier Interface");
					shopGo = ((Component)val).gameObject;
					Shop = val;
					break;
				}
			}
			if ((Object)(object)Shop == (Object)null)
			{
				Utility.Error("Shop is null!");
				return;
			}
			ConversationManager.Init();
			SeedQuestManager.Init();
			SeedVisualsManager.LoadSeedMaterial();
			InitDictionary();
			foreach (KeyValuePair<string, UnicornSeedData> discoveredSeed in DiscoveredSeeds)
			{
				SeedDefinition item = Registry.GetItem<SeedDefinition>(discoveredSeed.Value.seedId);
				if ((Object)(object)item != (Object)null)
				{
					CreateShopListing(item, discoveredSeed.Value.price);
				}
			}
		}

		public static void ClearAll()
		{
			SeedVisualsManager.seedIcons.Clear();
			SeedVisualsManager.appearanceMap.Clear();
			SeedQuestManager.seedDropoff = null;
			DiscoveredSeeds.Clear();
			factory.DeleteChildren();
			FirstLoad = false;
		}

		public static void StartSeedCreation(WeedDefinition weedDef)
		{
			MelonCoroutines.Start(CreateSeed(weedDef));
		}

		public static void BroadcastCustomSeed(UnicornSeedData seed)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			ProductManager instance = NetworkSingleton<ProductManager>.Instance;
			string text = JsonConvert.SerializeObject((object)seed);
			string text2 = "[UNISEED]" + text;
			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(text2, "ogkushseed", (EDrugType)0, list, val);
		}

		[IteratorStateMachine(typeof(<CreateSeed>d__13))]
		public static IEnumerator CreateSeed(WeedDefinition weedDef)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CreateSeed>d__13(0)
			{
				weedDef = weedDef
			};
		}

		public static void InitDictionary()
		{
			List<ShopListing> listings = Shop.Listings;
			foreach (ShopListing item2 in listings)
			{
				StorableItemDefinition item = item2.Item;
				SeedDefinition val = (SeedDefinition)(object)((item is SeedDefinition) ? item : null);
				if (val != null)
				{
					if (!baseSeedDefinitions.ContainsKey(((ItemDefinition)val).ID))
					{
						baseSeedDefinitions.Add(((ItemDefinition)val).ID, val);
						baseShopListing.Add(((ItemDefinition)val).ID, item2);
					}
				}
				else
				{
					MelonLogger.Warning(item2.name + " could not be cast to SeedDefinition");
				}
			}
		}

		public static void CreateShopListing(SeedDefinition newSeed, float price = 10f)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0069: 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)
			ShopListing val = Shop.Listings[0];
			val.name = "Test";
			ShopListing val2 = new ShopListing();
			val2.name = $"{((ItemDefinition)newSeed).ID} (${price}) (Agriculture, )";
			val2.OverridePrice = true;
			val2.OverriddenPrice = price;
			val2.Item = (StorableItemDefinition)(object)newSeed;
			val2.IconTint = new Color(0f, 0.859f, 1f, 1f);
			val2.MinimumGameCreationVersion = 27f;
			val2.DefaultStock = 1000;
			val2.CurrentStock = 100000;
			Shop.Listings.Add(val2);
			Shop.CreateListingUI(val2);
			Shop.RefreshShownItems();
		}

		public static void SeedFactoryLoader()
		{
			SeedDefinition item = Registry.GetItem<SeedDefinition>("ogkushseed");
			if ((Object)(object)item != (Object)null)
			{
				factory = new SeedFactory(item);
			}
		}

		public static SeedDefinition SeedDefinitionLoader(UnicornSeedData newSeedData)
		{
			SeedDefinition val = null;
			WeedDefinition item = Registry.GetItem<WeedDefinition>(newSeedData.weedId);
			if ((Object)(object)item != (Object)null)
			{
				val = factory.CreateSeedDefinition(item);
				if ((Object)(object)val == (Object)null)
				{
					Utility.Log("New Seed returned null?");
				}
				Singleton<Registry>.Instance.AddToRegistry((ItemDefinition)(object)val);
			}
			else
			{
				MelonLogger.Error("Could not parse weed and seed defitions");
			}
			return val;
		}
	}
	public static class StashManager
	{
		private static Dictionary<string, List<PropertyItemDefinition>> ingredientsCache = new Dictionary<string, List<PropertyItemDefinition>>();

		private static Dictionary<string, float> ingredientCostCache = new Dictionary<string, float>();

		public static SupplierStash albertsStash;

		public static bool onClosedExecuting = false;

		public static MelonPreferences_Category ConfigCategory;

		public static MelonPreferences_Entry<int> StashCostEntry;

		public static MelonPreferences_Entry<int> StashQtyEntry;

		public static MelonPreferences_Entry<int> SynthesizeTime;

		public static void InitializeConfig()
		{
			ConfigCategory = MelonPreferences.CreateCategory("Unicorns Custom Seeds");
			StashCostEntry = ConfigCategory.CreateEntry<int>("StashCostRequirement", 500, "Stash Cost Requirement", "The price that Albert charges to synthesize seeds", false, false, (ValueValidator)null, (string)null);
			StashQtyEntry = ConfigCategory.CreateEntry<int>("StashQtyRequirement", 20, "Stash Quantity Requirement", "The quantity of weed that needs to be provided of a certain mix", false, false, (ValueValidator)null, (string)null);
			SynthesizeTime = ConfigCategory.CreateEntry<int>("SynthesizeTime", 30, "Synthesize Time", "Time in secondsd that it will take for Albert to synthesize a seed", false, false, (ValueValidator)null, (string)null);
		}

		public static void GetAlbertsStash()
		{
			SupplierStash[] array = Object.FindObjectsOfType<SupplierStash>();
			SupplierStash[] array2 = array;
			foreach (SupplierStash val in array2)
			{
				if ((Object)(object)val != (Object)null && ((Object)((Component)val).gameObject).name.ToLower().Contains("albert"))
				{
					Utility.Log("Alberts Ready to Synthesize");
					albertsStash = val;
					StorageEntity storage = val.Storage;
					storage.onClosed = (Action)Delegate.Combine(storage.onClosed, new Action(AlbertsStashClosed));
				}
			}
		}

		public static void AlbertsStashClosed()
		{
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Expected O, but got Unknown
			if (onClosedExecuting)
			{
				return;
			}
			onClosedExecuting = true;
			ItemSlot val = null;
			CashInstance val2 = null;
			ItemSlot val3 = null;
			WeedInstance val4 = null;
			List<ItemInstance> allItems = albertsStash.Storage.GetAllItems();
			foreach (ItemSlot itemSlot in albertsStash.Storage.ItemSlots)
			{
				if (((itemSlot != null) ? itemSlot.ItemInstance : null) == null)
				{
					continue;
				}
				ItemInstance itemInstance = itemSlot.ItemInstance;
				CashInstance val5 = (CashInstance)(object)((itemInstance is CashInstance) ? itemInstance : null);
				if (val5 != null)
				{
					val = itemSlot;
					val2 = val5;
					continue;
				}
				ItemInstance itemInstance2 = itemSlot.ItemInstance;
				WeedInstance val6 = (WeedInstance)(object)((itemInstance2 is WeedInstance) ? itemInstance2 : null);
				if (val6 != null)
				{
					val3 = itemSlot;
					val4 = val6;
				}
			}
			if (val2 != null && val4 != null)
			{
				string packaging = ((ItemDefinition)(((ProductItemInstance)val4).AppliedPackaging?)).Name;
				int quantity = ((ItemInstance)val4).Quantity;
				uint num = PackageAmount(packaging);
				if (num == 0)
				{
					return;
				}
				uint num2 = (uint)(quantity * num);
				if (val2.Balance >= (float)StashCostEntry.Value && num2 >= StashQtyEntry.Value)
				{
					WeedDefinition val7 = (WeedDefinition)((ItemInstance)val4).Definition;
					if ((Object)(object)val7 != (Object)null && !CustomSeedsManager.DiscoveredSeeds.ContainsKey(((ItemInstance)val4).Definition.ID) && SeedQuestManager.HasActiveQuest)
					{
						val3.ChangeQuantity(-(StashQtyEntry.Value / (int)num), false);
						val2.ChangeBalance((float)(-StashCostEntry.Value));
						SeedQuestManager.CompleteQuest();
						SeedQuestManager.SendMessage("I will begin synthesizing the seed");
						CustomSeedsManager.StartSeedCreation(val7);
					}
				}
			}
			onClosedExecuting = false;
		}

		private static uint PackageAmount(string packaging)
		{
			if (1 == 0)
			{
			}
			uint result = packaging switch
			{
				"Brick" => 20u, 
				"Jar" => 5u, 
				"Baggie" => 1u, 
				_ => 0u, 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		public static WeedDefinition GetBaseStrain(ProductDefinition product)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			List<PropertyItemDefinition> recipe = GetRecipe(product);
			PropertyItemDefinition val = recipe[0];
			WeedDefinition val2 = (WeedDefinition)val;
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
			return null;
		}

		public static List<PropertyItemDefinition> GetRecipe(ProductDefinition product)
		{
			if (ingredientsCache.ContainsKey(((ItemDefinition)product).ID))
			{
				return ingredientsCache[((ItemDefinition)product).ID];
			}
			return DeepSearchRecipe(product);
		}

		public static float GetIngredientCost(ProductDefinition product)
		{
			if (ingredientCostCache.ContainsKey(((ItemDefinition)product).ID))
			{
				return ingredientCostCache[((ItemDefinition)product).ID];
			}
			List<PropertyItemDefinition> recipe = GetRecipe(product);
			float num = CalculateTotalCost(recipe);
			ingredientCostCache.Add(((ItemDefinition)product).ID, num);
			return num;
		}

		public static void ProcessNewRecipe(ProductDefinition product)
		{
			if (!((Object)(object)product == (Object)null))
			{
				List<PropertyItemDefinition> ingredients = DeepSearchRecipe(product);
				float num = CalculateTotalCost(ingredients);
			}
		}

		private static float CalculateTotalCost(List<PropertyItemDefinition> ingredients)
		{
			float num = 0f;
			foreach (PropertyItemDefinition ingredient in ingredients)
			{
				if (!(ingredient is ProductDefinition))
				{
					num += ((StorableItemDefinition)ingredient).BasePurchasePrice;
				}
			}
			return num;
		}

		public static List<PropertyItemDefinition> DeepSearchRecipe(ProductDefinition product)
		{
			if (ingredientsCache.ContainsKey(((ItemDefinition)product).ID))
			{
				return ingredientsCache[((ItemDefinition)product).ID];
			}
			List<PropertyItemDefinition> list = new List<PropertyItemDefinition>();
			HashSet<string> visited = new HashSet<string>();
			DeepSearchRecursive(product, list, visited);
			ingredientsCache.Add(((ItemDefinition)product).ID, list);
			return list;
		}

		private static void DeepSearchRecursive(ProductDefinition product, List<PropertyItemDefinition> result, HashSet<string> visited)
		{
			if ((Object)(object)product == (Object)null || visited.Contains(((ItemDefinition)product).ID))
			{
				return;
			}
			visited.Add(((ItemDefinition)product).ID);
			if (product.Recipes.Count == 0)
			{
				result.Insert(0, (PropertyItemDefinition)(object)product);
				return;
			}
			foreach (IngredientQuantity ingredient in product.Recipes[0].Ingredients)
			{
				if (ingredient == null)
				{
					continue;
				}
				ItemDefinition item = ingredient.Item;
				ProductDefinition val = (ProductDefinition)(object)((item is ProductDefinition) ? item : null);
				if (val != null)
				{
					DeepSearchRecursive(val, result, visited);
					continue;
				}
				ItemDefinition item2 = ingredient.Item;
				PropertyItemDefinition val2 = (PropertyItemDefinition)(object)((item2 is PropertyItemDefinition) ? item2 : null);
				if (val2 != null)
				{
					result.Add(val2);
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}