using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Fxcpds;
using GrowthSpeedModifier;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using ScheduleOne.Core.Items.Framework;
using ScheduleOne.Growing;
using ScheduleOne.ItemFramework;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Mod), "Growth Speed Modifiers", "1.0.1", "Foxcapades", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PlantGrowthModifiers")]
[assembly: AssemblyConfiguration("Mono")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e3dc66aa38fea459c3fdefd95a2f6a06fbec862d")]
[assembly: AssemblyProduct("PlantGrowthModifiers")]
[assembly: AssemblyTitle("PlantGrowthModifiers")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace Fxcpds
{
public sealed class NumberValidator<T> : ValueValidator where T : IComparable<T>
{
private readonly T min;
private readonly T max;
public NumberValidator(T min, T max)
{
this.min = min;
this.max = max;
}
public override bool IsValid(object value)
{
T val = (T)value;
return val.CompareTo(min) > -1 && val.CompareTo(max) < 1;
}
public override object EnsureValid(object value)
{
T val = (T)value;
if (val.CompareTo(min) < 0)
{
return min;
}
if (val.CompareTo(max) > 0)
{
return max;
}
return value;
}
}
}
namespace GrowthSpeedModifier
{
public class Mod : MelonMod
{
[HarmonyPatch(typeof(ShroomColony), "SetGrowthPercentage")]
private static class ShroomColonyPatch
{
private static void Prefix(ref float percent, ShroomColony __instance)
{
if (__instance.GrowthProgress != 0f)
{
float num = percent - __instance.GrowthProgress;
percent = __instance.GrowthProgress + num * shroomModifier.Value;
}
}
}
[HarmonyPatch(typeof(Plant))]
private static class PlantPatch
{
private static bool growth;
[HarmonyPrefix]
[HarmonyPatch("SetNormalizedGrowthProgress")]
private static void SetNormalizedGrowthProgressPrefix(ref float progress, Plant __instance)
{
if (growth)
{
growth = false;
}
else if (__instance.NormalizedGrowthProgress != 0f)
{
float num = progress - __instance.NormalizedGrowthProgress;
progress = __instance.NormalizedGrowthProgress + num * getModifier(__instance);
}
}
[HarmonyPrefix]
[HarmonyPatch("AdditiveApplied")]
private static void AdditiveAppliedPrefix(AdditiveDefinition additive, bool isInitialApplication)
{
if (isInitialApplication && additive.InstantGrowth > 0f)
{
growth = true;
}
}
}
public const string MOD_NAME = "Growth Speed Modifiers";
private static MelonPreferences_Entry<float>? cocaModifier;
private static MelonPreferences_Entry<float>? shroomModifier;
private static MelonPreferences_Entry<float>? weedModifier;
public override void OnInitializeMelon()
{
NumberValidator<float> numberValidator = new NumberValidator<float>(0.1f, 50f);
MelonPreferences_Category val = MelonPreferences.CreateCategory("Growth Speed Modifiers", "Modifiers");
cocaModifier = val.CreateEntry<float>("cocaModifier", 1f, "Coca Growth Multiplier", (string)null, false, false, (ValueValidator)(object)numberValidator, (string)null);
shroomModifier = val.CreateEntry<float>("shroomModifier", 1f, "Mushroom Growth Multiplier", (string)null, false, false, (ValueValidator)(object)numberValidator, (string)null);
weedModifier = val.CreateEntry<float>("weedModifier", 1f, "Weed Growth Multiplier", (string)null, false, false, (ValueValidator)(object)numberValidator, (string)null);
}
private static float getModifier(Plant plant)
{
switch (((BaseItemDefinition)plant.SeedDefinition).ID)
{
case "cocaseed":
return cocaModifier.Value;
case "granddaddypurpleseed":
case "greencrackseed":
case "ogkushseed":
case "sourdieselseed":
return weedModifier.Value;
default:
return 1f;
}
}
}
}