Files
AbsorbentSoil/AbsorbentSoil/Patches/PlantInitializePatch.cs
T

38 lines
1.2 KiB
C#

using System;
using HarmonyLib;
using Il2CppScheduleOne.Growing;
using Il2CppScheduleOne.ObjectScripts;
using MelonLoader;
namespace AbsorbentSoil
{
[HarmonyPatch(typeof(Plant), nameof(Plant.Initialize))]
internal static class Plant_Initialize_Patch
{
public static void Postfix(Plant __instance)
{
try
{
PersistenceStore.EnsureLoaded();
MelonLogger.Msg($"Plant.Initialize fired. Plant={__instance?.name}, Pot={__instance?.Pot?.name}");
if (__instance == null || __instance.Pot == null)
return;
Pot actualPot = __instance.Pot;
var additiveIds = AdditiveMemory.Get(actualPot);
MelonLogger.Msg($"Plant.Initialize pot key={PotKeyHelper.GetPotKey(actualPot)}, remembered additives={additiveIds.Count}");
foreach (string additiveId in additiveIds)
Pot_ApplyAdditive_Patch.ReapplyWithoutRecapture(actualPot, additiveId);
}
catch (Exception ex)
{
MelonLogger.Warning($"Plant.Initialize postfix failed: {ex}");
}
}
}
}