Decompiled source of FastGrow v1.1.0

Mods/FastGrow.dll

Decompiled 2 days ago
using System;
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 FastGrow;
using HarmonyLib;
using Il2CppScheduleOne.Growing;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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), "FastGrow", "1.0.3", "Kito & Bars", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("FastGrow")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FastGrow")]
[assembly: AssemblyTitle("FastGrow")]
[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 FastGrow
{
	public class Core : MelonMod
	{
		[HarmonyPatch(typeof(Plant), "MinPass")]
		private class PlantMinPassScalePatch
		{
			private static readonly Dictionary<int, float> _previousProgressByPlantId = new Dictionary<int, float>();

			private static void Prefix(Plant __instance)
			{
				_previousProgressByPlantId[((Object)__instance).GetInstanceID()] = __instance.NormalizedGrowthProgress;
			}

			private static void Postfix(Plant __instance)
			{
				int instanceID = ((Object)__instance).GetInstanceID();
				if (!_previousProgressByPlantId.TryGetValue(instanceID, out var value))
				{
					return;
				}
				_previousProgressByPlantId.Remove(instanceID);
				if (__instance.NormalizedGrowthProgress >= 1f)
				{
					return;
				}
				float num = __instance.NormalizedGrowthProgress - value;
				if (num == 0f)
				{
					return;
				}
				float num2 = Mathf.Clamp(growthMultiplier.Value, 0.01f, 100f);
				if (float.IsNaN(num2) || float.IsInfinity(num2))
				{
					num2 = 1f;
				}
				float num3 = 1f / num2;
				if (!Mathf.Approximately(num3, 1f))
				{
					float num4 = num * num3;
					float num5 = Mathf.Clamp(value + num4, 0f, 1f);
					if (!Mathf.Approximately(num5, __instance.NormalizedGrowthProgress))
					{
						__instance.SetNormalizedGrowthProgress(num5);
					}
				}
			}
		}

		private static MelonPreferences_Entry<float> growthMultiplier;

		public override void OnInitializeMelon()
		{
			MelonPreferences_Category val = MelonPreferences.CreateCategory("FastGrow", "FastGrow Settings");
			growthMultiplier = val.CreateEntry<float>("GrowthMultiplier", 0.25f, "Growth Multiplier", "Controls plant growth speed. Lower values = faster growth.\n• 0.25 = 4x faster growth\n• 1.0 = normal speed\n• 2.0 = 2x slower growth\nRange: 0.01 (100x faster) to 100.0 (100x slower)", false, false, (ValueValidator)null, (string)null);
			ValidateGrowthMultiplier();
			((MelonBase)this).LoggerInstance.Msg($"FastGrow initialized with multiplier: {growthMultiplier.Value}");
		}

		public override void OnPreferencesSaved(string filePath)
		{
			ValidateGrowthMultiplier();
		}

		private void ValidateGrowthMultiplier()
		{
			float value = growthMultiplier.Value;
			float num = Mathf.Clamp(value, 0.01f, 100f);
			if (!Mathf.Approximately(value, num))
			{
				((MelonBase)this).LoggerInstance.Warning($"GrowthMultiplier value {value} is out of range. Clamping to {num}");
				growthMultiplier.Value = num;
				MelonPreferences.Save();
			}
		}
	}
}