Decompiled source of QualityPlants v1.2.0

QualityPlants-1.2.0.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2CppFishNet.Object;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppScheduleOne;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Growing;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Levelling;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using QualityPlants;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(global::QualityPlants.QualityPlants), "Quality Plants", "1.0", "SoulDaSythe", null)]
[assembly: MelonColor]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("QualityPlants")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9212bfe85956267681ff522464bb7d25ab4a3b73")]
[assembly: AssemblyProduct("QualityPlants")]
[assembly: AssemblyTitle("QualityPlants")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 QualityPlants
{
	public static class BuildInfo
	{
		public const string Name = "Quality Plants";

		public const string Description = "Ugh, who knew \"gardening\" was so hard?";

		public const string Author = "SoulDaSythe";

		public const string Company = null;

		public const string Version = "1.0";

		public const string DownloadLink = null;
	}
	public class QualityPlants : MelonMod
	{
		[HarmonyPatch(typeof(Plant), "Initialize")]
		public static class PlantQualityPatch
		{
			public static void Postfix(Plant __instance, NetworkObject pot, float growthProgress, float yieldLevel, float qualityLevel)
			{
				Array array = Array.Empty<Plant>();
				if ((Object)(object)__instance.Pot != (Object)null && loaded)
				{
					string text = __instance.Pot.Name.ToString();
					if (text.Equals("Grow Tent"))
					{
						__instance.QualityLevel = 0.1f;
					}
					if (text.Equals("Plastic Pot"))
					{
						__instance.QualityLevel = 0.26f;
					}
					if (text.Equals("Moisture-Preserving Pot"))
					{
						__instance.QualityLevel = 0.5f;
					}
					if (text.Equals("Air Pot"))
					{
						__instance.QualityLevel = 0.8f;
					}
				}
			}
		}

		public static class RankPatcher
		{
			private static MelonPreferences_Category category;

			public static readonly Dictionary<string, (MelonPreferences_Entry<string> Rank, MelonPreferences_Entry<int> Tier)> ConfigEntries = new Dictionary<string, (MelonPreferences_Entry<string>, MelonPreferences_Entry<int>)>();

			private static readonly Dictionary<string, FullRank> DefaultRanks = new Dictionary<string, FullRank>
			{
				{
					"moisturepreservingpot",
					new FullRank((ERank)1, 5)
				},
				{
					"ledgrowlight",
					new FullRank((ERank)1, 3)
				},
				{
					"plasticpot",
					new FullRank((ERank)0, 5)
				},
				{
					"halogengrowlight",
					new FullRank((ERank)0, 5)
				},
				{
					"airpot",
					new FullRank((ERank)3, 5)
				},
				{
					"fullspectrumgrowlight",
					new FullRank((ERank)1, 5)
				},
				{
					"dryingrack",
					new FullRank((ERank)0, 5)
				}
			};

			public static void GenerateConfig()
			{
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				category = MelonPreferences.CreateCategory("BuildableRankOverrides", "Buildable Rank Overrides");
				foreach (KeyValuePair<string, FullRank> defaultRank in DefaultRanks)
				{
					string key = defaultRank.Key;
					FullRank value = defaultRank.Value;
					MelonPreferences_Entry<string> item = category.CreateEntry<string>(key + "_Rank", ((object)(ERank)(ref value.Rank)).ToString(), "Rank for " + key, (string)null, false, false, (ValueValidator)null, (string)null);
					MelonPreferences_Entry<int> item2 = category.CreateEntry<int>(key + "_Tier", value.Tier, "Tier for " + key, (string)null, false, false, (ValueValidator)null, (string)null);
					ConfigEntries[key] = (item, item2);
				}
				Melon<QualityPlants>.Logger.Msg("[RankConfig] Config entries generated.");
			}

			public static Dictionary<string, (string Rank, int Tier)> LoadRankOverrides()
			{
				Dictionary<string, (string, int)> dictionary = new Dictionary<string, (string, int)>();
				foreach (KeyValuePair<string, (MelonPreferences_Entry<string>, MelonPreferences_Entry<int>)> configEntry in ConfigEntries)
				{
					string key = configEntry.Key;
					string value = configEntry.Value.Item1.Value;
					int value2 = configEntry.Value.Item2.Value;
					dictionary[key] = (value, value2);
				}
				return dictionary;
			}

			public static void ApplyRanksWithFallback()
			{
				//IL_0227: Unknown result type (might be due to invalid IL or missing references)
				//IL_022c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0263: Unknown result type (might be due to invalid IL or missing references)
				//IL_0265: Unknown result type (might be due to invalid IL or missing references)
				//IL_027f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0198: 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_02a9: Unknown result type (might be due to invalid IL or missing references)
				Melon<QualityPlants>.Logger.Msg("[RankPatcher] Starting ApplyRanksWithFallback via Registry.ItemRegistry...");
				Dictionary<string, (string, int)> dictionary = LoadRankOverrides();
				Melon<QualityPlants>.Logger.Msg($"[RankPatcher] Loaded {dictionary.Count} config overrides.");
				Melon<QualityPlants>.Logger.Msg($"[RankPatcher] DefaultRanks has {DefaultRanks.Count} entries.");
				Registry instance = Singleton<Registry>.instance;
				if ((Object)(object)instance == (Object)null || instance.ItemRegistry == null)
				{
					Melon<QualityPlants>.Logger.Warning("[RankPatcher] Registry or ItemRegistry is null!");
					return;
				}
				int num = 0;
				Enumerator<ItemRegister> enumerator = instance.ItemRegistry.GetEnumerator();
				FullRank val2 = default(FullRank);
				while (enumerator.MoveNext())
				{
					ItemRegister current = enumerator.Current;
					if ((Object)(object)((current != null) ? current.Definition : null) == (Object)null)
					{
						continue;
					}
					BuildableItemDefinition val = ((Il2CppObjectBase)current.Definition).TryCast<BuildableItemDefinition>();
					if (val == null || ((ItemDefinition)val).ID == null)
					{
						continue;
					}
					string text = ((ItemDefinition)val).ID.ToString().ToLowerInvariant();
					if (DefaultRanks.ContainsKey(text))
					{
						if (dictionary.TryGetValue(text, out var value) && TryParseRank(value.Item1, out var result))
						{
							((FullRank)(ref val2))..ctor(result, value.Item2);
							Melon<QualityPlants>.Logger.Msg($"[RankPatcher] Overridden rank for {text}: {result} (Tier {value.Item2})");
						}
						else
						{
							val2 = DefaultRanks[text];
							Melon<QualityPlants>.Logger.Msg($"[RankPatcher] Fallback rank for {text}: {val2.Rank} (Tier {val2.Tier})");
						}
						((StorableItemDefinition)val).RequiredRank = val2;
						num++;
					}
				}
				Melon<QualityPlants>.Logger.Msg($"[RankPatcher] Finished. Patched {num} BuildableItemDefinitions.");
			}

			private static bool TryParseRank(string input, out ERank result)
			{
				return Enum.TryParse<ERank>(input, ignoreCase: true, out result);
			}
		}

		internal static bool loaded;

		public override void OnInitializeMelon()
		{
			Melon<QualityPlants>.Logger.Msg("Initialized!");
			SceneManager.sceneLoaded += UnityAction<Scene, LoadSceneMode>.op_Implicit((Action<Scene, LoadSceneMode>)OnSceneLoaded);
			RankPatcher.GenerateConfig();
			MelonPreferences.Save();
			((MelonBase)this).OnInitializeMelon();
		}

		private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (((Scene)(ref scene)).name.Equals("Main"))
			{
				MelonCoroutines.Start(Load());
			}
			else
			{
				loaded = false;
			}
		}

		private static IEnumerator Load()
		{
			Melon<QualityPlants>.Logger.Msg("[QualityPlants] Coroutine started. Waiting for scene to initialize...");
			for (int i = 0; i < 40; i++)
			{
				yield return (object)new WaitForEndOfFrame();
			}
			Melon<QualityPlants>.Logger.Msg("[QualityPlants] Running ApplyRanksWithFallback after delay...");
			RankPatcher.ApplyRanksWithFallback();
			loaded = true;
			Melon<QualityPlants>.Logger.Msg("[QualityPlants] Load complete!");
		}
	}
}