using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using HarmonyLib; using MelonLoader; using MelonLoader.Preferences; using Microsoft.CodeAnalysis; using ScheduleOne; using ScheduleOne.Core.Items.Framework; using ScheduleOne.DevUtilities; using ScheduleOne.Equipping; using ScheduleOne.Growing; using ScheduleOne.ItemFramework; using ScheduleOne.ObjectScripts; using ScheduleOne.PlayerScripts; using ScheduleOne.PlayerTasks; using ScheduleOne.PlayerTasks.Tasks; using ScheduleOne.StationFramework; using ScheduleOne.Storage; using ScheduleOne.Trash; using ScheduleOne.UI.Stations; using SuperGrow; using SuperGrow.Features; using SuperGrow.Patches; using SuperGrow.Utils; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: MelonInfo(typeof(Core), "SuperGrow", "1.3.3", "HazDS", null)] [assembly: MelonGame("TVGS", "Schedule I")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("SuperGrow")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+3299f0b98073429beb1d9d070075813648d324d0")] [assembly: AssemblyProduct("SuperGrow")] [assembly: AssemblyTitle("SuperGrow")] [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.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; } } [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 SuperGrow { internal static class SuperGrowSettings { private static bool _initialized; private static MelonPreferences_Category? _prefsCategory; public static MelonPreferences_Entry PgrRequired { get; private set; } public static MelonPreferences_Entry SpeedGrowRequired { get; private set; } public static MelonPreferences_Entry FertilizerRequired { get; private set; } public static MelonPreferences_Entry OutputQuantity { get; private set; } public static MelonPreferences_Entry CookTimeMinutes { get; private set; } public static MelonPreferences_Entry YieldMultiplier { get; private set; } public static MelonPreferences_Entry InstantGrowth { get; private set; } public static MelonPreferences_Entry QualityChange { get; private set; } public static void Initialize() { if (!_initialized) { _prefsCategory = MelonPreferences.CreateCategory("SuperGrow", "SuperGrow Settings"); PgrRequired = _prefsCategory.CreateEntry("PgrRequired", 1, "PGR Required", "Amount of PGR needed per craft", false, false, (ValueValidator)null, (string)null); SpeedGrowRequired = _prefsCategory.CreateEntry("SpeedGrowRequired", 1, "Speed Grow Required", "Amount of Speed Grow needed per craft", false, false, (ValueValidator)null, (string)null); FertilizerRequired = _prefsCategory.CreateEntry("FertilizerRequired", 1, "Fertilizer Required", "Amount of Fertilizer needed per craft", false, false, (ValueValidator)null, (string)null); OutputQuantity = _prefsCategory.CreateEntry("OutputQuantity", 3, "Output Quantity", "Amount of SuperGrow produced per craft", false, false, (ValueValidator)null, (string)null); CookTimeMinutes = _prefsCategory.CreateEntry("CookTimeMinutes", 30, "Cook Time (Minutes)", "Chemistry Station cook time in in-game minutes", false, false, (ValueValidator)null, (string)null); YieldMultiplier = _prefsCategory.CreateEntry("YieldMultiplier", 1.5f, "Yield Multiplier", "Yield multiplier applied to plants (1.5 = 50% more yield)", false, false, (ValueValidator)null, (string)null); InstantGrowth = _prefsCategory.CreateEntry("InstantGrowth", 0.5f, "Instant Growth", "Instant growth progress (0.5 = 50% instant growth)", false, false, (ValueValidator)null, (string)null); QualityChange = _prefsCategory.CreateEntry("QualityChange", 1f, "Quality Change", "Quality modifier applied to plants", false, false, (ValueValidator)null, (string)null); Clamp(PgrRequired, 1, 10); Clamp(SpeedGrowRequired, 1, 10); Clamp(FertilizerRequired, 1, 10); Clamp(OutputQuantity, 1, 10); Clamp(CookTimeMinutes, 1, 240); Clamp(YieldMultiplier, 0.1f, 10f); Clamp(InstantGrowth, 0f, 1f); Clamp(QualityChange, -1f, 1f); _initialized = true; } } private static void Clamp(MelonPreferences_Entry entry, int min, int max) { if (entry.Value < min) { entry.Value = min; } if (entry.Value > max) { entry.Value = max; } } private static void Clamp(MelonPreferences_Entry entry, float min, float max) { if (entry.Value < min) { entry.Value = min; } if (entry.Value > max) { entry.Value = max; } } } public class Core : MelonMod { private bool _itemsInitialized; private int _nextInitAttemptTick; private const int InitAttemptIntervalMs = 250; public static Core Instance { get; private set; } public override void OnInitializeMelon() { Instance = this; SuperGrowSettings.Initialize(); MelonLogger.Msg("[SuperGrow v1.3.3] Initialized."); } public override void OnSceneWasLoaded(int buildIndex, string sceneName) { if (sceneName == "Menu") { _itemsInitialized = false; _nextInitAttemptTick = 0; ChemistryStationPatches.Reset(); } } public override void OnUpdate() { if (_itemsInitialized && (Object)(object)Registry.GetItem("supergrow") != (Object)null) { return; } if ((Object)(object)Registry.GetItem("supergrow") != (Object)null) { _itemsInitialized = true; } else if (ShouldAttemptInitNow()) { _itemsInitialized = false; if (SuperGrowWorldState.IsRegistryReady()) { SuperGrowCreator.CreateSuperGrowItem(); _itemsInitialized = (Object)(object)Registry.GetItem("supergrow") != (Object)null; } } } private bool ShouldAttemptInitNow() { int tickCount = Environment.TickCount; if (tickCount - _nextInitAttemptTick < 0) { return false; } _nextInitAttemptTick = tickCount + 250; return true; } } internal static class SuperGrowAssets { private const string IconResourceName = "SuperGrow.Assets.SuperGrow_Icon.png"; private const string LabelResourceName = "SuperGrow.Assets.SuperGrow_Label.png"; private static Sprite? _icon; private static Texture2D? _labelTexture; private static bool _loggedIconLoadException; private static bool _loggedLabelLoadException; private static bool _loggedImageLoadException; public static Sprite? GetIconSprite() { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_icon != (Object)null) { return _icon; } try { byte[] array = LoadEmbeddedResourceBytes("SuperGrow.Assets.SuperGrow_Icon.png"); if (array == null) { return null; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (!TryLoadImage(val, array)) { MelonLogger.Warning("Failed to decode SuperGrow.Assets.SuperGrow_Icon.png"); return null; } ((Object)val).name = "SuperGrow_Icon"; _icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f); return _icon; } catch (Exception ex) { if (!_loggedIconLoadException) { _loggedIconLoadException = true; MelonLogger.Warning("Failed to load icon: " + ex.Message); MelonLogger.Warning(ex.StackTrace ?? ""); } return null; } } public static Texture2D? GetLabelTexture() { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown if ((Object)(object)_labelTexture != (Object)null) { return _labelTexture; } try { byte[] array = LoadEmbeddedResourceBytes("SuperGrow.Assets.SuperGrow_Label.png"); if (array == null) { return null; } _labelTexture = new Texture2D(2, 2, (TextureFormat)4, false); if (!TryLoadImage(_labelTexture, array)) { MelonLogger.Warning("Failed to decode SuperGrow.Assets.SuperGrow_Label.png"); _labelTexture = null; return null; } ((Object)_labelTexture).name = "SuperGrow_Label"; return _labelTexture; } catch (Exception ex) { if (!_loggedLabelLoadException) { _loggedLabelLoadException = true; MelonLogger.Error("Failed to load SuperGrow label texture: " + ex.Message); MelonLogger.Error(ex.StackTrace ?? ""); } _labelTexture = null; return null; } } private static byte[]? LoadEmbeddedResourceBytes(string resourceName) { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); if (stream == null) { MelonLogger.Warning("Could not find embedded resource: " + resourceName); return null; } using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); return memoryStream.ToArray(); } private static bool TryLoadImage(Texture2D texture, byte[] bytes) { try { Type type = Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule") ?? typeof(Texture2D).Assembly.GetType("UnityEngine.ImageConversion"); if (type == null) { return false; } MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public); bool flag = default(bool); foreach (MethodInfo methodInfo in methods) { if (methodInfo.Name != "LoadImage") { continue; } ParameterInfo[] parameters = methodInfo.GetParameters(); if ((parameters.Length == 2 || parameters.Length == 3) && !(parameters[0].ParameterType != typeof(Texture2D)) && parameters[1].ParameterType == typeof(byte[])) { object obj = ((parameters.Length != 3) ? methodInfo.Invoke(null, new object[2] { texture, bytes }) : methodInfo.Invoke(null, new object[3] { texture, bytes, false })); int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } return (byte)((uint)num & (flag ? 1u : 0u)) != 0; } } return false; } catch (Exception ex) { if (!_loggedImageLoadException) { _loggedImageLoadException = true; MelonLogger.Warning("Failed to decode embedded image bytes via ImageConversion.LoadImage: " + ex.Message); MelonLogger.Warning(ex.StackTrace ?? ""); } return false; } } } internal static class SuperGrowWorldState { private static bool _loggedReady; private static bool _ready; private static bool _loggedRegistryReadyException; public static bool IsRegistryReady() { try { if (_ready) { return true; } ItemDefinition item = Registry.GetItem("pgr"); ItemDefinition obj = ((item is AdditiveDefinition) ? item : null); ItemDefinition item2 = Registry.GetItem("speedgrow"); AdditiveDefinition val = (AdditiveDefinition)(object)((item2 is AdditiveDefinition) ? item2 : null); ItemDefinition item3 = Registry.GetItem("fertilizer"); AdditiveDefinition val2 = (AdditiveDefinition)(object)((item3 is AdditiveDefinition) ? item3 : null); if ((Object)(object)obj == (Object)null && (Object)(object)val == (Object)null && (Object)(object)val2 == (Object)null) { return false; } _ready = true; if (!_loggedReady) { _loggedReady = true; } return true; } catch (Exception ex) { if (!_loggedRegistryReadyException) { _loggedRegistryReadyException = true; MelonLogger.Warning("Registry readiness check failed: " + ex.Message); MelonLogger.Warning(ex.StackTrace ?? ""); } return false; } } } } namespace SuperGrow.Utils { public static class Constants { public static class Game { public const string GAME_STUDIO = "TVGS"; public const string GAME_NAME = "Schedule I"; } public static class Additives { public const string PGR = "pgr"; public const string SPEED_GROW = "speedgrow"; public const string FERTILIZER = "fertilizer"; } public static class ItemIds { public const string SUPER_GROW = "supergrow"; } public static class DefaultEffects { public const float YIELD_MULTIPLIER = 1.5f; public const float INSTANT_GROWTH = 0.5f; public const float QUALITY_CHANGE = 1f; } public const string MOD_NAME = "SuperGrow"; public const string MOD_VERSION = "1.3.3"; public const string MOD_AUTHOR = "HazDS"; public const string PREFERENCES_CATEGORY = "SuperGrow"; } internal static class SuperGrowVisuals { internal static readonly Color PourColor = new Color(0.4f, 0.2f, 0.6f, 1f); internal static readonly Color LidTint = new Color(0.6f, 0.4f, 0.8f, 1f); internal static void ApplySuperGrowMaterialsToRenderers(Renderer[]? renderers) { //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) if (renderers == null) { return; } Texture2D labelTexture = SuperGrowAssets.GetLabelTexture(); if ((Object)(object)labelTexture == (Object)null) { MelonLogger.Warning("SuperGrow label texture is null, cannot apply"); return; } try { foreach (Renderer val in renderers) { if ((Object)(object)val == (Object)null) { continue; } string text = ((Object)val).name.ToLowerInvariant(); bool flag = text.Contains("label"); if (!flag) { Material[] sharedMaterials = val.sharedMaterials; foreach (Material val2 in sharedMaterials) { if ((Object)(object)val2 != (Object)null && ((Object)val2).name.ToLowerInvariant().Contains("label")) { flag = true; break; } } } bool flag2 = text.Contains("lid"); if (!flag2) { Material[] sharedMaterials = val.sharedMaterials; foreach (Material val3 in sharedMaterials) { if ((Object)(object)val3 != (Object)null && ((Object)val3).name.ToLowerInvariant().Contains("lid")) { flag2 = true; break; } } } if (flag) { Material[] materials = val.materials; foreach (Material val4 in materials) { if (!((Object)(object)val4 == (Object)null)) { val4.mainTexture = (Texture)(object)labelTexture; if (val4.HasProperty("_BaseMap")) { val4.SetTexture("_BaseMap", (Texture)(object)labelTexture); } if (val4.HasProperty("_MainTex")) { val4.SetTexture("_MainTex", (Texture)(object)labelTexture); } } } val.materials = materials; } else { if (!flag2) { continue; } Material[] materials2 = val.materials; foreach (Material val5 in materials2) { if (!((Object)(object)val5 == (Object)null)) { val5.color = LidTint; if (val5.HasProperty("_BaseColor")) { val5.SetColor("_BaseColor", LidTint); } if (val5.HasProperty("_Color")) { val5.SetColor("_Color", LidTint); } } } val.materials = materials2; } } } catch (Exception ex) { MelonLogger.Error("Failed to apply SuperGrow materials: " + ex.Message); MelonLogger.Error(ex.StackTrace); } } } } namespace SuperGrow.Patches { [HarmonyPatch] internal static class ChemistryStationPatches { private readonly struct PendingTrashReskin { public string TrashId { get; } public string AdditiveId { get; } public PendingTrashReskin(string trashId, string additiveId) { TrashId = trashId; AdditiveId = additiveId; } } [CompilerGenerated] private sealed class d__23 : IEnumerator, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__23(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(0.1f); <>1__state = 1; return true; case 1: <>1__state = -1; <>2__current = (object)new WaitForSeconds(0.4f); <>1__state = 2; return true; case 2: <>1__state = -1; <>2__current = (object)new WaitForSeconds(0.5f); <>1__state = 3; return true; case 3: <>1__state = -1; 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(); } } private static StationRecipe? _superGrowRecipe; private static bool _additivesPatched; private static bool _loggedMissingStationItemTemplate; private static bool _loggedRegistryStart; private static bool _loggedRecipeNotReady; private static int _superGrowBeginAuditUntilTick; private static int _superGrowBeginAuditSeq; private static ChemistryStation? _superGrowBeginStation; private static int _superGrowBeginStationSeq; private static string? _lastSelectedRecipeProductId; private static string? _lastSelectedRecipeTitle; private static string? _lastSelectedRecipeId; private static int _lastSelectedAtTick; private const string PgrBottleTrashId = "supergrow_pgr_bottle"; private const string SpeedGrowBottleTrashId = "supergrow_speedgrow_bottle"; private const string FertilizerBottleTrashId = "supergrow_fertilizer_bottle"; private const string SuperGrowBottleTrashId = "supergrow_bottle"; private static bool _monoTrashPrefabsInjected; private static readonly Dictionary _monoBottleTrashPrefabByAdditiveId = new Dictionary(); private static bool _loggedMonoTrashPrefabInjectionException; private static int _pendingStationTrashReskinExpireTick; private static readonly List _pendingStationTrashReskins = new List(); private static readonly Dictionary _pourablePrefabs = new Dictionary(); private static readonly Dictionary _additiveColors = new Dictionary { { "pgr", new Color(1f, 0.506f, 0.506f, 1f) }, { "speedgrow", new Color(0.506f, 0.812f, 1f, 1f) }, { "fertilizer", new Color(0.639f, 1f, 0.506f, 1f) }, { "supergrow", SuperGrowVisuals.PourColor } }; private const float LiquidScale = 0.65f; public static void Reset() { _superGrowRecipe = null; _additivesPatched = false; _loggedMissingStationItemTemplate = false; _loggedRegistryStart = false; _loggedRecipeNotReady = false; } [HarmonyPatch(typeof(ChemistryStationCanvas), "Awake")] [HarmonyPrefix] private static void ChemistryStationCanvas_Awake_Prefix(ChemistryStationCanvas __instance) { try { if ((Object)(object)__instance == (Object)null) { return; } SuperGrowCreator.CreateSuperGrowItem(); if ((Object)(object)_superGrowRecipe == (Object)null) { CreateSuperGrowRecipe(); } if ((Object)(object)_superGrowRecipe == (Object)null) { if (!_loggedRecipeNotReady) { _loggedRecipeNotReady = true; MelonLogger.Warning("SuperGrow recipe is null; cannot add to chemistry station yet"); } return; } List recipes = __instance.Recipes; if (recipes == null) { if (!_loggedRecipeNotReady) { _loggedRecipeNotReady = true; MelonLogger.Warning("ChemistryStationCanvas.Recipes is null; cannot add SuperGrow recipe"); } } else if (!recipes.Contains(_superGrowRecipe)) { recipes.Add(_superGrowRecipe); } } catch (Exception ex) { MelonLogger.Error("Failed to add SuperGrow recipe: " + ex.Message); MelonLogger.Error(ex.StackTrace ?? ""); } } [HarmonyPatch(typeof(ChemistryStationCanvas), "Awake")] [HarmonyPostfix] private static void ChemistryStationCanvas_Awake_Postfix(ChemistryStationCanvas __instance) { } [HarmonyPatch(typeof(ChemistryStationCanvas), "Start")] [HarmonyPrefix] private static void ChemistryStationCanvas_Start_Prefix(ChemistryStationCanvas __instance) { try { if (!((Object)(object)__instance == (Object)null)) { SetupAdditiveStationItems(); } } catch (Exception ex) { MelonLogger.Error("Failed to add SuperGrow recipe: " + ex.Message); MelonLogger.Error(ex.StackTrace ?? ""); } } [HarmonyPatch(typeof(ChemistryStationCanvas), "Start")] [HarmonyPostfix] private static void ChemistryStationCanvas_Start_Postfix(ChemistryStationCanvas __instance) { } [HarmonyPatch(typeof(ChemistryStationCanvas), "Open")] [HarmonyPrefix] private static void ChemistryStationCanvas_Open_PrefixAudit(ChemistryStationCanvas __instance, ChemistryStation station) { } [HarmonyPatch(typeof(ChemistryStationCanvas), "SetSelectedRecipe")] [HarmonyPrefix] private static void ChemistryStationCanvas_SetSelectedRecipe_Prefix(ChemistryStationCanvas __instance, StationRecipeEntry entry) { try { StationRecipe val = ((entry != null) ? entry.Recipe : null); string text = SafeGetProductId(val); if (!(text == "") && !(text == "")) { _lastSelectedRecipeProductId = text; _lastSelectedRecipeTitle = SafeGetRecipeEntryTitle(entry); _lastSelectedRecipeId = (((Object)(object)val == (Object)null) ? "" : SafeGetStationRecipeId(val)); _lastSelectedAtTick = Environment.TickCount; } } catch { } } [HarmonyPatch(typeof(ChemistryStationCanvas), "BeginButtonPressed")] [HarmonyPrefix] private static void ChemistryStationCanvas_BeginButtonPressed_Prefix(ChemistryStationCanvas __instance) { try { if (!((Object)(object)__instance == (Object)null)) { StationRecipeEntry? obj = TryGetSelectedRecipeEntry(__instance); string text = SafeGetProductId((obj != null) ? obj.Recipe : null); if (text == "" || text == "") { text = _lastSelectedRecipeProductId ?? text; } if (!(text != "supergrow")) { _superGrowBeginAuditSeq++; _superGrowBeginAuditUntilTick = Environment.TickCount + 10000; _superGrowBeginStation = __instance.ChemistryStation; _superGrowBeginStationSeq = _superGrowBeginAuditSeq; _ = _superGrowBeginAuditSeq; } } } catch (Exception ex) { MelonLogger.Error("SuperGrow Begin audit failed (Prefix): " + ex.Message); MelonLogger.Error(ex.StackTrace ?? ""); } } [HarmonyPatch(typeof(ChemistryStationCanvas), "BeginButtonPressed")] [HarmonyPostfix] private static void ChemistryStationCanvas_BeginButtonPressed_Postfix(ChemistryStationCanvas __instance) { try { if (!((Object)(object)__instance == (Object)null) && !TickExpired(_superGrowBeginAuditUntilTick)) { int superGrowBeginAuditSeq = _superGrowBeginAuditSeq; ChemistryStation val = __instance.ChemistryStation; if ((Object)(object)val == (Object)null && _superGrowBeginStationSeq == superGrowBeginAuditSeq) { val = _superGrowBeginStation; } _ = (Object)(object)val != (Object)null; } } catch (Exception ex) { MelonLogger.Error("SuperGrow Begin audit failed (Postfix): " + ex.Message); MelonLogger.Error(ex.StackTrace ?? ""); } } private static bool TickExpired(int untilTick) { return Environment.TickCount - untilTick >= 0; } [IteratorStateMachine(typeof(d__23))] private static IEnumerator DelayedChemistryIngredientAudit(int seq, ChemistryStation station) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__23(0); } private static StationRecipeEntry? TryGetSelectedRecipeEntry(ChemistryStationCanvas canvas) { try { Type typeFromHandle = typeof(ChemistryStationCanvas); FieldInfo field = typeFromHandle.GetField("selectedRecipe", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { object? value = field.GetValue(canvas); return (StationRecipeEntry?)((value is StationRecipeEntry) ? value : null); } PropertyInfo property = typeFromHandle.GetProperty("selectedRecipe", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null) { object? value2 = property.GetValue(canvas); return (StationRecipeEntry?)((value2 is StationRecipeEntry) ? value2 : null); } FieldInfo[] fields = typeFromHandle.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (!(fieldInfo.FieldType != typeof(StationRecipeEntry)) && !(fieldInfo.Name == "RecipeEntryPrefab") && !(fieldInfo.Name == "InProgressRecipeEntry")) { object? value3 = fieldInfo.GetValue(canvas); StationRecipeEntry val = (StationRecipeEntry)((value3 is StationRecipeEntry) ? value3 : null); if ((Object)(object)((val != null) ? val.Recipe : null) != (Object)null) { return val; } } } } catch { } return null; } private static string SafeGetRecipeEntryTitle(StationRecipeEntry? entry) { try { return ((Object)(object)entry?.TitleLabel == (Object)null) ? "" : (((TMP_Text)entry.TitleLabel).text ?? ""); } catch { return ""; } } private static bool SafeGetBeginInteractable(ChemistryStationCanvas canvas) { try { return (Object)(object)canvas.BeginButton != (Object)null && ((Selectable)canvas.BeginButton).interactable; } catch { return false; } } private static string SafeGetProductId(StationRecipe? recipe) { try { return ((BaseItemDefinition)(recipe?.Product?.Item?)).ID ?? ""; } catch { return ""; } } private static string SafeGetStationRecipeId(StationRecipe recipe) { try { return recipe.RecipeID ?? ""; } catch { return ""; } } private static void CreateSuperGrowRecipe() { //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Expected O, but got Unknown //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Expected O, but got Unknown //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Expected O, but got Unknown //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Expected O, but got Unknown //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) ItemDefinition item = Registry.GetItem("pgr"); ItemDefinition item2 = Registry.GetItem("speedgrow"); ItemDefinition item3 = Registry.GetItem("fertilizer"); ItemDefinition item4 = Registry.GetItem("supergrow"); if ((Object)(object)item == (Object)null || (Object)(object)item2 == (Object)null || (Object)(object)item3 == (Object)null) { MelonLogger.Error("Could not find one or more base additive definitions"); return; } if ((Object)(object)item4 == (Object)null) { SuperGrowCreator.CreateSuperGrowItem(); item4 = Registry.GetItem("supergrow"); if ((Object)(object)item4 == (Object)null) { MelonLogger.Warning("Could not find SuperGrow definition; will retry when registry is ready"); return; } } _superGrowRecipe = ScriptableObject.CreateInstance(); _superGrowRecipe.IsDiscovered = true; _superGrowRecipe.RecipeTitle = "SuperGrow"; _superGrowRecipe.CookTime_Mins = SuperGrowSettings.CookTimeMinutes.Value; _superGrowRecipe.Unlocked = true; List list = new List(); IngredientQuantity val = new IngredientQuantity(); List list2 = new List(); list2.Add(item); val.Items = list2; val.Quantity = SuperGrowSettings.PgrRequired.Value; list.Add(val); IngredientQuantity val2 = new IngredientQuantity(); List list3 = new List(); list3.Add(item2); val2.Items = list3; val2.Quantity = SuperGrowSettings.SpeedGrowRequired.Value; list.Add(val2); IngredientQuantity val3 = new IngredientQuantity(); List list4 = new List(); list4.Add(item3); val3.Items = list4; val3.Quantity = SuperGrowSettings.FertilizerRequired.Value; list.Add(val3); _superGrowRecipe.Ingredients = list; _superGrowRecipe.Product = new ItemQuantity { Item = item4, Quantity = SuperGrowSettings.OutputQuantity.Value }; _superGrowRecipe.FinalLiquidColor = SuperGrowVisuals.PourColor; } private static bool TryGetStationItemTemplate(out StationItem templateStationItem) { templateStationItem = null; string[] array = new string[4] { "acid", "pgr", "speedgrow", "fertilizer" }; string[] array2 = array; for (int i = 0; i < array2.Length; i++) { ItemDefinition item = Registry.GetItem(array2[i]); StorableItemDefinition val = (StorableItemDefinition)(object)((item is StorableItemDefinition) ? item : null); if ((Object)(object)val?.StationItem != (Object)null) { templateStationItem = val.StationItem; return true; } } if (!_loggedMissingStationItemTemplate) { _loggedMissingStationItemTemplate = true; MelonLogger.Warning("Could not find any StationItem template (acid/pgr/speedgrow/fertilizer)"); array2 = array; foreach (string text in array2) { ItemDefinition item2 = Registry.GetItem(text); StorableItemDefinition val2 = (StorableItemDefinition)(object)((item2 is StorableItemDefinition) ? item2 : null); MelonLogger.Warning(text + ": def=" + (((Object)(object)val2 == (Object)null) ? "" : ((object)val2).GetType().FullName) + " stationItem=" + (((Object)(object)val2?.StationItem == (Object)null) ? "" : ((object)val2.StationItem).GetType().FullName)); } } return false; } [HarmonyPatch(typeof(Registry), "Start")] [HarmonyPostfix] private static void Registry_Start_Postfix() { if (_loggedRegistryStart) { return; } _loggedRegistryStart = true; try { SuperGrowCreator.CreateSuperGrowItem(); } catch (Exception ex) { MelonLogger.Error("Registry.Start hook failed: " + ex.Message); MelonLogger.Error(ex.StackTrace ?? ""); } } public static void SetupAdditiveStationItems() { if (_additivesPatched) { return; } try { CachePourablePrefab("pgr", "growing/pgr/PGR_Pourable"); CachePourablePrefab("speedgrow", "growing/speedgrow/SpeedGrow_Pourable"); CachePourablePrefab("fertilizer", "growing/fertilizer/Fertilizer_Pourable"); if (TryGetStationItemTemplate(out StationItem templateStationItem)) { SetupAdditiveStationItem("pgr", templateStationItem); SetupAdditiveStationItem("speedgrow", templateStationItem); SetupAdditiveStationItem("fertilizer", templateStationItem); _additivesPatched = true; } } catch (Exception ex) { MelonLogger.Error("Failed to set up additive StationItems: " + ex.Message); MelonLogger.Error(ex.StackTrace); } } [HarmonyPatch(typeof(StoredItem), "InitializeStoredItem")] [HarmonyPostfix] private static void StoredItem_InitializeStoredItem_Postfix(StoredItem __instance, StorableItemInstance _item) { try { if (!(((_item == null) ? null : ((BaseItemDefinition)(((ItemInstance)_item).Definition?)).ID) != "supergrow")) { ApplySuperGrowMaterialsToRenderers(((Component)__instance).GetComponentsInChildren(true)); } } catch (Exception ex) { MelonLogger.Error("Failed to apply SuperGrow visuals to stored item: " + ex.Message); MelonLogger.Error(ex.StackTrace ?? ""); } } private static bool TrashPrefabsContainsId(TrashItem[]? prefabs, string id) { if (prefabs == null) { return false; } foreach (TrashItem val in prefabs) { if ((Object)(object)val != (Object)null && val.ID == id) { return true; } } return false; } private static bool TryGetMonoBottleTrashPrefab(string additiveId, out TrashItem prefab) { prefab = null; if (_monoBottleTrashPrefabByAdditiveId.TryGetValue(additiveId, out TrashItem value) && (Object)(object)value != (Object)null) { prefab = value; return true; } TrashManager val = Object.FindObjectOfType(); if ((Object)(object)val == (Object)null) { return false; } EnsureMonoBottleTrashPrefabsInjected(val); if (_monoBottleTrashPrefabByAdditiveId.TryGetValue(additiveId, out value) && (Object)(object)value != (Object)null) { prefab = value; return true; } return false; } private static void EnsureMonoBottleTrashPrefabsInjected(TrashManager manager) { if (_monoTrashPrefabsInjected || (Object)(object)manager == (Object)null) { return; } try { CachePourablePrefab("pgr", "growing/pgr/PGR_Pourable"); CachePourablePrefab("speedgrow", "growing/speedgrow/SpeedGrow_Pourable"); CachePourablePrefab("fertilizer", "growing/fertilizer/Fertilizer_Pourable"); TrashItem baseTrash = manager.GetTrashPrefab("acid"); TrashItem pgrTrash = manager.GetTrashPrefab("pgr"); if ((Object)(object)baseTrash == (Object)null || (Object)(object)((Component)baseTrash).gameObject == (Object)null) { return; } TrashItem[] prefabs = manager.TrashPrefabs ?? Array.Empty(); List additions = new List(); Ensure("pgr", "supergrow_pgr_bottle"); Ensure("speedgrow", "supergrow_speedgrow_bottle"); Ensure("fertilizer", "supergrow_fertilizer_bottle"); Ensure("supergrow", "supergrow_bottle"); if (additions.Count > 0) { TrashItem[] array = (TrashItem[])(object)new TrashItem[prefabs.Length + additions.Count]; Array.Copy(prefabs, array, prefabs.Length); for (int i = 0; i < additions.Count; i++) { array[prefabs.Length + i] = additions[i]; } manager.TrashPrefabs = array; } _monoTrashPrefabsInjected = true; void Ensure(string additiveId, string newId) { if (!TrashPrefabsContainsId(prefabs, newId)) { GameObject val = ((string.Equals(additiveId, "supergrow", StringComparison.OrdinalIgnoreCase) && (Object)(object)pgrTrash != (Object)null && (Object)(object)((Component)pgrTrash).gameObject != (Object)null) ? ((Component)pgrTrash).gameObject : ((Component)baseTrash).gameObject); GameObject val2 = Object.Instantiate(val); ((Object)val2).name = "SuperGrow_" + additiveId + "_TrashPrefab"; val2.SetActive(val.activeSelf); Object.DontDestroyOnLoad((Object)(object)val2); TrashItem component = val2.GetComponent(); if ((Object)(object)component == (Object)null) { Object.Destroy((Object)(object)val2); } else { component.ID = newId; SwapTrashItemVisualsById(additiveId, component); _monoBottleTrashPrefabByAdditiveId[additiveId] = component; additions.Add(component); } } } } catch (Exception ex) { if (!_loggedMonoTrashPrefabInjectionException) { _loggedMonoTrashPrefabInjectionException = true; MelonLogger.Warning("Failed to inject SuperGrow trash prefabs (Mono): " + ex.Message); MelonLogger.Warning(ex.StackTrace ?? ""); } } } [HarmonyPatch(typeof(TrashManager), "Start")] [HarmonyPostfix] private static void TrashManager_Start_Postfix_Mono(TrashManager __instance) { EnsureMonoBottleTrashPrefabsInjected(__instance); } private static void SetPendingStationTrashReskins(List reskins) { _pendingStationTrashReskins.Clear(); if (reskins.Count > 0) { _pendingStationTrashReskins.AddRange(reskins); _pendingStationTrashReskinExpireTick = Environment.TickCount + 5000; } else { _pendingStationTrashReskinExpireTick = 0; } } [HarmonyPatch(typeof(TrashItem), "Start")] [HarmonyPostfix] private static void TrashItem_Start_Postfix(TrashItem __instance) { try { if (_pendingStationTrashReskins.Count == 0) { return; } if (_pendingStationTrashReskinExpireTick != 0 && Environment.TickCount - _pendingStationTrashReskinExpireTick >= 0) { _pendingStationTrashReskins.Clear(); _pendingStationTrashReskinExpireTick = 0; return; } string iD = __instance.ID; if (string.IsNullOrEmpty(iD)) { return; } for (int i = 0; i < _pendingStationTrashReskins.Count; i++) { PendingTrashReskin pendingTrashReskin = _pendingStationTrashReskins[i]; if (!(pendingTrashReskin.TrashId != iD)) { _pendingStationTrashReskins.RemoveAt(i); SwapTrashItemVisualsById(pendingTrashReskin.AdditiveId, __instance); break; } } } catch (Exception ex) { MelonLogger.Error("Failed to apply SuperGrow visuals to trash item: " + ex.Message); MelonLogger.Error(ex.StackTrace ?? ""); } } private static bool IsChemistryBeakerFillable(Fillable fillable) { if ((Object)(object)fillable == (Object)null) { return false; } LiquidContainer liquidContainer = fillable.LiquidContainer; if ((Object)(object)liquidContainer == (Object)null || (Object)(object)((Component)liquidContainer).transform == (Object)null) { return false; } Transform transform = ((Component)liquidContainer).transform; if (!string.Equals(((Object)transform).name, "Liquid", StringComparison.OrdinalIgnoreCase)) { return false; } Transform parent = transform.parent; if ((Object)(object)parent == (Object)null || !string.Equals(((Object)parent).name, "Beaker", StringComparison.OrdinalIgnoreCase)) { return false; } Transform parent2 = parent.parent; if ((Object)(object)parent2 == (Object)null || !((Object)parent2).name.StartsWith("Beaker", StringComparison.OrdinalIgnoreCase)) { return false; } Transform val = parent2; while ((Object)(object)val != (Object)null) { if (((Object)val).name != null && ((Object)val).name.IndexOf("ChemistryStation", StringComparison.OrdinalIgnoreCase) >= 0) { return true; } val = val.parent; } return false; } private static void CachePourablePrefab(string additiveId, string pourablePath) { if (!_pourablePrefabs.ContainsKey(additiveId)) { GameObject val = Resources.Load(pourablePath); if ((Object)(object)val != (Object)null) { _pourablePrefabs[additiveId] = val; } else { MelonLogger.Warning("Could not load pourable prefab for " + additiveId + " at " + pourablePath); } } } private static Transform? FindStationItemBottleContainer(StationItem stationItem) { Transform val = ((Component)stationItem).transform.Find("Pourable"); if ((Object)(object)val == (Object)null) { return null; } Transform result = null; int childCount = val.childCount; for (int i = 0; i < childCount; i++) { Transform child = val.GetChild(i); if ((Object)(object)child != (Object)null && ((Object)child).name.IndexOf("Bottle", StringComparison.OrdinalIgnoreCase) >= 0) { result = child; break; } } return result; } private static void SwapBottleMeshesAndMaterials(GameObject templatePrefab, Transform targetRoot) { MeshFilter[] componentsInChildren = templatePrefab.GetComponentsInChildren(true); MeshFilter[] componentsInChildren2 = ((Component)targetRoot).GetComponentsInChildren(true); foreach (MeshFilter val in componentsInChildren2) { if ((Object)(object)val == (Object)null) { continue; } string text = ((Object)val).name.ToLowerInvariant(); MeshFilter[] array = componentsInChildren; foreach (MeshFilter val2 in array) { if ((Object)(object)val2 == (Object)null) { continue; } string text2 = ((Object)val2).name.ToLowerInvariant(); if ((text.Contains("body") && text2.Contains("body")) || (text.Contains("label") && text2.Contains("label")) || (text.Contains("lid") && text2.Contains("lid"))) { val.sharedMesh = val2.sharedMesh; MeshRenderer component = ((Component)val).GetComponent(); MeshRenderer component2 = ((Component)val2).GetComponent(); if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null) { ((Renderer)component).sharedMaterials = ((Renderer)component2).sharedMaterials; } break; } } } } private static void ApplySuperGrowMaterialsToRenderers(Renderer[]? renderers) { SuperGrowVisuals.ApplySuperGrowMaterialsToRenderers(renderers); } private static void SetupAdditiveStationItem(string additiveId, StationItem templateStationItem) { ItemDefinition item = Registry.GetItem(additiveId); StorableItemDefinition val = (StorableItemDefinition)(object)((item is StorableItemDefinition) ? item : null); if ((Object)(object)val == (Object)null) { MelonLogger.Warning("Could not find additive: " + additiveId); } else if (!((Object)(object)val.StationItem != (Object)null)) { val.StationItem = templateStationItem; } } private static void SwapTrashItemVisualsById(string id, TrashItem trashItem) { if ((Object)(object)trashItem == (Object)null || string.IsNullOrEmpty(id)) { return; } bool flag = id == "supergrow"; if (!flag && id != "pgr" && id != "speedgrow" && id != "fertilizer") { return; } GameObject value = null; if (flag) { _pourablePrefabs.TryGetValue("pgr", out value); } else { _pourablePrefabs.TryGetValue(id, out value); } if ((Object)(object)value == (Object)null) { return; } try { if (!((Object)(object)((Component)trashItem).transform == (Object)null)) { SwapBottleMeshesAndMaterials(value, ((Component)trashItem).transform); if (flag) { ApplySuperGrowMaterialsToRenderers(((Component)trashItem).GetComponentsInChildren(true)); } } } catch (Exception ex) { MelonLogger.Error("Failed to swap trash visuals for " + id + ": " + ex.Message); MelonLogger.Error(ex.StackTrace); } } private static void SwapStationItemVisualsById(string id, StationItem stationItem) { //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015b: 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) if ((Object)(object)stationItem == (Object)null || string.IsNullOrEmpty(id)) { return; } bool flag = id == "supergrow"; if (!flag && id != "pgr" && id != "speedgrow" && id != "fertilizer") { return; } GameObject value = null; if (flag) { _pourablePrefabs.TryGetValue("pgr", out value); } else { _pourablePrefabs.TryGetValue(id, out value); } if ((Object)(object)value == (Object)null) { return; } try { Transform val = FindStationItemBottleContainer(stationItem); if ((Object)(object)val == (Object)null) { return; } SwapBottleMeshesAndMaterials(value, val); if (flag) { ApplySuperGrowMaterialsToRenderers(((Component)val).GetComponentsInChildren(true)); } object obj; if (!((Object)(object)((Component)stationItem).transform != (Object)null)) { obj = null; } else { Transform obj2 = ((Component)stationItem).transform.Find("Pourable"); obj = ((obj2 != null) ? ((Component)obj2).GetComponent() : null); } PourableModule val2 = (PourableModule)obj; if ((Object)(object)val2 != (Object)null && (Object)(object)val2.LiquidContainer != (Object)null) { LiquidContainer liquidContainer = val2.LiquidContainer; if ((Object)(object)liquidContainer.LiquidVolume != (Object)null) { Transform transform = ((Component)liquidContainer.LiquidVolume).transform; transform.localScale *= 0.65f; } liquidContainer.MaxLevel *= 0.65f; if (_additiveColors.TryGetValue(id, out var value2)) { val2.LiquidType = id; val2.LiquidColor = value2; val2.PourParticlesColor = value2; liquidContainer.SetLiquidColor(value2, true, true); } } if (flag) { return; } switch (id) { case "pgr": case "speedgrow": case "fertilizer": { if (TryGetMonoBottleTrashPrefab(id, out TrashItem prefab)) { stationItem.TrashPrefab = prefab; } break; } } } catch (Exception ex) { MelonLogger.Error("Failed to swap station item visuals for " + id + ": " + ex.Message); MelonLogger.Error(ex.StackTrace); } } private static void SwapStationItemVisualsById(string id, StationItem stationItem, StorableItemDefinition itemDef) { if (!((Object)(object)stationItem == (Object)null) && !((Object)(object)itemDef == (Object)null)) { SwapStationItemVisualsById(id, stationItem); } } private static void SwapStationItemVisuals(StationItem stationItem, StorableItemDefinition itemDef) { SwapStationItemVisualsById(((BaseItemDefinition)itemDef).ID, stationItem, itemDef); } [HarmonyPatch(typeof(StationItem), "Initialize")] [HarmonyPostfix] private static void StationItem_Initialize_Postfix(StationItem __instance, StorableItemDefinition itemDefinition) { SwapStationItemVisuals(__instance, itemDefinition); } } [HarmonyPatch] internal static class GrowContainerPatches { private const string SuperGrowBottleTrashId = "supergrow_bottle"; private static bool _loggedGrowContainerTrashPrefabAssignException; private static readonly Vector3 HiddenPrefabPosition = new Vector3(100000f, 100000f, 100000f); private static Pourable? _superGrowPourablePrefab; private static int _removeItemDepth; private static bool _shouldReskinNextTrashSpawn; private static readonly HashSet _loggedReskinnedTrashIds = new HashSet(StringComparer.OrdinalIgnoreCase); private static void InjectSuperGrowIntoAllowedAdditives(GrowContainer container) { try { ItemDefinition item = Registry.GetItem("supergrow"); AdditiveDefinition val = (AdditiveDefinition)(object)((item is AdditiveDefinition) ? item : null); if ((Object)(object)val == (Object)null) { return; } if (container.AllowedAdditives != null) { AdditiveDefinition[] allowedAdditives = container.AllowedAdditives; foreach (AdditiveDefinition val2 in allowedAdditives) { if ((Object)(object)val2 != (Object)null && ((BaseItemDefinition)val2).ID == "supergrow") { return; } } } AdditiveDefinition[] obj = container.AllowedAdditives ?? Array.Empty(); AdditiveDefinition[] array = (AdditiveDefinition[])(object)new AdditiveDefinition[obj.Length + 1]; obj.CopyTo(array, 0); array[^1] = val; container.AllowedAdditives = array; } catch (Exception ex) { MelonLogger.Error("Failed to inject SuperGrow into AllowedAdditives: " + ex.Message); } } [HarmonyPatch(typeof(GrowContainer), "InitializeGridItem")] [HarmonyPrefix] private static void GrowContainer_InitializeGridItem_Prefix(GrowContainer __instance) { InjectSuperGrowIntoAllowedAdditives(__instance); } private static Pourable? GetOrCreateSuperGrowPourablePrefab(Pourable basePrefab) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_00e5: 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) if ((Object)(object)_superGrowPourablePrefab != (Object)null && (Object)(object)((Component)_superGrowPourablePrefab).gameObject != (Object)null) { return _superGrowPourablePrefab; } if ((Object)(object)basePrefab == (Object)null || (Object)(object)((Component)basePrefab).gameObject == (Object)null) { return null; } try { GameObject val = Object.Instantiate(((Component)basePrefab).gameObject); ((Object)val).name = "SuperGrow_PourablePrefab"; ((Object)val).hideFlags = (HideFlags)61; Object.DontDestroyOnLoad((Object)(object)val); val.transform.position = HiddenPrefabPosition; if (!val.activeSelf) { val.SetActive(true); } Pourable component = val.GetComponent(); if ((Object)(object)component == (Object)null) { Object.Destroy((Object)(object)val); return null; } PourableAdditive component2 = val.GetComponent(); if ((Object)(object)component2 != (Object)null) { component2.LiquidColor = SuperGrowVisuals.PourColor; } ParticleSystem[] componentsInChildren = val.GetComponentsInChildren(true); foreach (ParticleSystem val2 in componentsInChildren) { if (!((Object)(object)val2 == (Object)null)) { MainModule main = val2.main; ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(SuperGrowVisuals.PourColor); } } SuperGrowVisuals.ApplySuperGrowMaterialsToRenderers(val.GetComponentsInChildren(true)); try { TrashManager val3 = Object.FindObjectOfType(); if ((Object)(object)val3 != (Object)null) { TrashItem trashPrefab = val3.GetTrashPrefab("supergrow_bottle"); if ((Object)(object)trashPrefab != (Object)null) { component.TrashItem = trashPrefab; } } } catch (Exception ex) { if (!_loggedGrowContainerTrashPrefabAssignException) { _loggedGrowContainerTrashPrefabAssignException = true; MelonLogger.Warning("Failed to assign SuperGrow trash prefab to grow-container pourable: " + ex.Message); MelonLogger.Warning(ex.StackTrace ?? ""); } } _superGrowPourablePrefab = component; return _superGrowPourablePrefab; } catch (Exception ex2) { MelonLogger.Error("Failed to create SuperGrow pourable prefab: " + ex2.Message); MelonLogger.Error(ex2.StackTrace); return null; } } [HarmonyPatch(typeof(Equippable_Additive), "Equip")] [HarmonyPostfix] private static void Equippable_Additive_Equip_Postfix(Equippable_Additive __instance, ItemInstance item) { try { if (((item == null) ? null : ((BaseItemDefinition)(item.Definition?)).ID) != "supergrow") { return; } SuperGrowVisuals.ApplySuperGrowMaterialsToRenderers(((Component)__instance).GetComponentsInChildren(true)); Pourable pourablePrefab = ((Equippable_Pourable)__instance).PourablePrefab; if (!((Object)(object)pourablePrefab == (Object)null)) { Pourable orCreateSuperGrowPourablePrefab = GetOrCreateSuperGrowPourablePrefab(pourablePrefab); if ((Object)(object)orCreateSuperGrowPourablePrefab != (Object)null) { ((Equippable_Pourable)__instance).PourablePrefab = orCreateSuperGrowPourablePrefab; } } } catch (Exception ex) { MelonLogger.Error("Failed to apply SuperGrow grow-container pour visuals: " + ex.Message); MelonLogger.Error(ex.StackTrace); } } [HarmonyPatch(typeof(GrowContainerPourTask), "RemoveItem")] [HarmonyPrefix] private static void GrowContainerPourTask_RemoveItem_Prefix() { _removeItemDepth++; } [HarmonyPatch(typeof(GrowContainerPourTask), "RemoveItem")] [HarmonyFinalizer] private static void GrowContainerPourTask_RemoveItem_Finalizer(Exception __exception) { _removeItemDepth = Math.Max(0, _removeItemDepth - 1); _shouldReskinNextTrashSpawn = false; } [HarmonyPatch(typeof(PlayerInventory), "RemoveAmountOfItem")] [HarmonyPrefix] private static void PlayerInventory_RemoveAmountOfItem_Prefix(string ID) { if (_removeItemDepth > 0 && string.Equals(ID, "supergrow", StringComparison.OrdinalIgnoreCase)) { _shouldReskinNextTrashSpawn = true; } } [HarmonyPatch(typeof(TrashManager), "CreateAndReturnTrashItem")] [HarmonyPostfix] private static void TrashManager_CreateAndReturnTrashItem_Postfix_GrowContainerReskin(string id, object __result) { if (!_shouldReskinNextTrashSpawn) { return; } _shouldReskinNextTrashSpawn = false; try { if (__result != null) { object? obj = AccessTools.Property(__result.GetType(), "gameObject")?.GetValue(__result); GameObject val = (GameObject)((obj is GameObject) ? obj : null); if (!((Object)(object)val == (Object)null)) { SuperGrowVisuals.ApplySuperGrowMaterialsToRenderers(val.GetComponentsInChildren(true)); } } } catch (Exception ex) { MelonLogger.Error("Failed to reskin grow-container trash for SuperGrow: " + ex.Message); MelonLogger.Error(ex.StackTrace); } } } } namespace SuperGrow.Features { internal static class SuperGrowCreator { private static AdditiveDefinition? _superGrowDefinition; private static bool _loggedMissingAdditiveTemplate; private static bool _loggedRegistryUnavailable; public static void CreateSuperGrowItem() { try { if (!((Object)(object)Registry.GetItem("supergrow") != (Object)null)) { CreateAdditiveDefinition(); _ = (Object)(object)Registry.GetItem("supergrow") != (Object)null; } } catch (Exception ex) { MelonLogger.Error("Failed to create SuperGrow item: " + ex.Message); MelonLogger.Error(ex.StackTrace); } } private static void CreateAdditiveDefinition() { //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Expected O, but got Unknown if (!Singleton.InstanceExists && !_loggedRegistryUnavailable) { _loggedRegistryUnavailable = true; MelonLogger.Warning("Registry singleton is not available yet; will retry"); } Registry val = Singleton.Instance; if ((Object)(object)val == (Object)null) { val = Object.FindObjectOfType(); } if ((Object)(object)val == (Object)null) { if (!_loggedRegistryUnavailable) { _loggedRegistryUnavailable = true; MelonLogger.Warning("Registry instance is not available; cannot add SuperGrow definition yet."); } return; } ItemDefinition item = Registry.GetItem("pgr"); AdditiveDefinition val2 = (AdditiveDefinition)(((object)((item is AdditiveDefinition) ? item : null)) ?? ((object)(/*isinst with value type is only supported in some contexts*/ ?? /*isinst with value type is only supported in some contexts*/))); if ((Object)(object)val2 == (Object)null) { if (!_loggedMissingAdditiveTemplate) { _loggedMissingAdditiveTemplate = true; ItemDefinition item2 = Registry.GetItem("pgr"); ItemDefinition item3 = Registry.GetItem("speedgrow"); ItemDefinition item4 = Registry.GetItem("fertilizer"); MelonLogger.Error("Could not find any existing additive to clone from!"); MelonLogger.Error("pgr=" + (((Object)(object)item2 == (Object)null) ? "" : ((object)item2).GetType().FullName)); MelonLogger.Error("speedgrow=" + (((Object)(object)item3 == (Object)null) ? "" : ((object)item3).GetType().FullName)); MelonLogger.Error("fertilizer=" + (((Object)(object)item4 == (Object)null) ? "" : ((object)item4).GetType().FullName)); } return; } if ((Object)(object)_superGrowDefinition != (Object)null) { val.AddToRegistry((ItemDefinition)(object)_superGrowDefinition); return; } _superGrowDefinition = ScriptableObject.CreateInstance(); ((BaseItemDefinition)_superGrowDefinition).Category = ((BaseItemDefinition)val2).Category; ((BaseItemDefinition)_superGrowDefinition).StackLimit = ((BaseItemDefinition)val2).StackLimit; ((ItemDefinition)_superGrowDefinition).AvailableInDemo = ((ItemDefinition)val2).AvailableInDemo; ((BaseItemDefinition)_superGrowDefinition).UsableInFilters = ((BaseItemDefinition)val2).UsableInFilters; ((StorableItemDefinition)_superGrowDefinition).ResellMultiplier = ((StorableItemDefinition)val2).ResellMultiplier; ((StorableItemDefinition)_superGrowDefinition).ShopCategories = ((StorableItemDefinition)val2).ShopCategories; ((BaseItemDefinition)_superGrowDefinition).legalStatus = ((BaseItemDefinition)val2).legalStatus; ((ItemDefinition)_superGrowDefinition).Equippable = ((ItemDefinition)val2).Equippable; ((StorableItemDefinition)_superGrowDefinition).StoredItem = ((StorableItemDefinition)val2).StoredItem; ((StorableItemDefinition)_superGrowDefinition).StationItem = ((StorableItemDefinition)val2).StationItem; ((StorableItemDefinition)_superGrowDefinition).BasePurchasePrice = ((StorableItemDefinition)val2).BasePurchasePrice; ((BaseItemDefinition)_superGrowDefinition).ID = "supergrow"; ((BaseItemDefinition)_superGrowDefinition).Name = "SuperGrow"; ((BaseItemDefinition)_superGrowDefinition).Description = "A powerful growth enhancer combining the effects of PGR, Speed Grow, and Fertilizer. Apply to plants for increased yield, faster growth, and improved quality."; ((Object)_superGrowDefinition).name = "SuperGrow"; Sprite iconSprite = SuperGrowAssets.GetIconSprite(); ((BaseItemDefinition)_superGrowDefinition).Icon = iconSprite ?? ((BaseItemDefinition)val2).Icon; if ((Object)(object)val2.DisplayMaterial != (Object)null) { Material value = new Material(val2.DisplayMaterial) { color = new Color(0.3f, 0.9f, 0.3f, 1f) }; SetPrivateProperty(_superGrowDefinition, "DisplayMaterial", value); } SetPrivateProperty(_superGrowDefinition, "QualityChange", SuperGrowSettings.QualityChange.Value); SetPrivateProperty(_superGrowDefinition, "YieldMultiplier", SuperGrowSettings.YieldMultiplier.Value); SetPrivateProperty(_superGrowDefinition, "InstantGrowth", SuperGrowSettings.InstantGrowth.Value); val.AddToRegistry((ItemDefinition)(object)_superGrowDefinition); } private static void SetPrivateProperty(object obj, string propertyName, object value) { Type type = obj.GetType(); FieldInfo field = type.GetField("<" + propertyName + ">k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic); if (field != null) { field.SetValue(obj, value); return; } PropertyInfo property = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null && property.CanWrite) { property.SetValue(obj, value); } else { MelonLogger.Warning("Could not set property " + propertyName + " on " + type.Name); } } } }