diff --git a/AbsorbentSoil/AbsorbentSoilMod.cs b/AbsorbentSoil/AbsorbentSoilMod.cs index 4a35e98..38b5420 100644 --- a/AbsorbentSoil/AbsorbentSoilMod.cs +++ b/AbsorbentSoil/AbsorbentSoilMod.cs @@ -8,6 +8,8 @@ using Il2CppInterop.Runtime; using Il2CppScheduleOne.Growing; using Il2CppScheduleOne.ItemFramework; using Il2CppScheduleOne.ObjectScripts; +using Il2CppScheduleOne.PlayerTasks.Tasks; +using Il2CppScheduleOne.ObjectScripts.Soil; using UnityEngine; [assembly: MelonInfo(typeof(AbsorbentSoil.AbsorbentSoilMod), "Absorbent Soil", "0.1.0", "AttilaG")] @@ -144,6 +146,22 @@ namespace AbsorbentSoil { private static readonly Dictionary RemainingUsesByPotKey = new(); + public static int DecrementRemainingSoilUses(Pot pot) + { + if (pot == null) + return 0; + + string key = PotKeyHelper.GetPotKey(pot); + if (string.IsNullOrWhiteSpace(key)) + return 0; + + int current = RemainingUsesByPotKey.TryGetValue(key, out int uses) ? uses : 0; + int next = Math.Max(0, current - 1); + + RemainingUsesByPotKey[key] = next; + return next; + } + public static void SetRemainingSoilUses(Pot pot, int uses) { if (pot == null) @@ -273,23 +291,20 @@ namespace AbsorbentSoil [HarmonyPatch(typeof(Pot), "OnPlantFullyHarvested")] internal static class Pot_OnPlantFullyHarvested_Patch { - private static void Prefix(Pot __instance) - { - try - { - MelonLogger.Msg($"Pot.OnPlantFullyHarvested fired. Pot={__instance?.name}, key={PotKeyHelper.GetPotKey(__instance)}"); - } - catch (Exception ex) - { - MelonLogger.Warning($"OnPlantFullyHarvested prefix failed: {ex}"); - } - } - private static void Postfix(Pot __instance) { try { - MelonLogger.Msg($"Pot.OnPlantFullyHarvested postfix. Pot={__instance?.name}, key={PotKeyHelper.GetPotKey(__instance)}"); + int remaining = SoilHelper.DecrementRemainingSoilUses(__instance); + + MelonLogger.Msg($"[Absorbent Soil] Harvest consumed soil use. Remaining uses={remaining}"); + + if (remaining <= 0) + { + AdditiveMemory.Forget(__instance); + SoilHelper.Forget(__instance); + MelonLogger.Msg($"[Absorbent Soil] Soil depleted. Cleared additives for pot '{PotKeyHelper.GetPotKey(__instance)}'."); + } } catch (Exception ex) { @@ -323,6 +338,42 @@ namespace AbsorbentSoil } } + [HarmonyPatch(typeof(PourSoilTask), "OnInitialPour")] + internal static class PourSoilTask_OnInitialPour_Patch + { + private static readonly FieldInfo SoilDefinitionField = + AccessTools.Field(typeof(PourSoilTask), "_soilDefinition"); + + private static readonly FieldInfo GrowContainerField = + AccessTools.Field(typeof(PourSoilTask), "_growContainer"); + + private static void Postfix(PourSoilTask __instance) + { + try + { + var soilDef = SoilDefinitionField?.GetValue(__instance) as SoilDefinition; + var growContainer = GrowContainerField?.GetValue(__instance) as GrowContainer; + var pot = growContainer?.TryCast(); + + MelonLogger.Msg($"PourSoilTask.OnInitialPour fired. Soil={soilDef?.ID}, Uses={soilDef?.Uses}, Pot={pot?.name}"); + + if (pot == null || soilDef == null) + return; + + SoilHelper.SetRemainingSoilUses(pot, soilDef.Uses); + + // New soil means fresh soil. Clear old retained additives. + AdditiveMemory.Forget(pot); + + MelonLogger.Msg($"[Absorbent Soil] Fresh soil added to pot '{PotKeyHelper.GetPotKey(pot)}'. Max uses={soilDef.Uses}. Cleared old additives."); + } + catch (Exception ex) + { + MelonLogger.Warning($"PourSoilTask.OnInitialPour postfix failed: {ex}"); + } + } + } + [HarmonyPatch(typeof(Pot), "Destroy")] internal static class Pot_Destroy_Patch { diff --git a/AbsorbentSoil/bin/Release/net6.0/AbsorbentSoil.pdb b/AbsorbentSoil/bin/Release/net6.0/AbsorbentSoil.pdb index 7bce297..7b4c4ed 100644 Binary files a/AbsorbentSoil/bin/Release/net6.0/AbsorbentSoil.pdb and b/AbsorbentSoil/bin/Release/net6.0/AbsorbentSoil.pdb differ diff --git a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfo.cs b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfo.cs index 6b8e5a0..bdc2b09 100644 --- a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfo.cs +++ b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("AbsorbentSoil")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Release")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c81eda518c4dc37d7c33aea9be3dc937cc9f721a")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+37e8635b49f6dac44b046923e2d6164f21e21c5e")] [assembly: System.Reflection.AssemblyProductAttribute("AbsorbentSoil")] [assembly: System.Reflection.AssemblyTitleAttribute("AbsorbentSoil")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfoInputs.cache b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfoInputs.cache index 6bfa032..74932c3 100644 --- a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfoInputs.cache +++ b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfoInputs.cache @@ -1 +1 @@ -9c6b26084cb96fd78db85383b86eb4d039e88318cd7d033961d3866d747ac03a +e91a6e148fbebb52137b7ddb0d020d001faa537353e4a942e8c7b383650eef69 diff --git a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.dll b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.dll index bfd1b7e..e40fa05 100644 Binary files a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.dll and b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.dll differ diff --git a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.pdb b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.pdb index 7bce297..7b4c4ed 100644 Binary files a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.pdb and b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.pdb differ diff --git a/AbsorbentSoil/obj/Release/net6.0/ref/AbsorbentSoil.dll b/AbsorbentSoil/obj/Release/net6.0/ref/AbsorbentSoil.dll index 785d922..765291d 100644 Binary files a/AbsorbentSoil/obj/Release/net6.0/ref/AbsorbentSoil.dll and b/AbsorbentSoil/obj/Release/net6.0/ref/AbsorbentSoil.dll differ diff --git a/AbsorbentSoil/obj/Release/net6.0/refint/AbsorbentSoil.dll b/AbsorbentSoil/obj/Release/net6.0/refint/AbsorbentSoil.dll index 785d922..765291d 100644 Binary files a/AbsorbentSoil/obj/Release/net6.0/refint/AbsorbentSoil.dll and b/AbsorbentSoil/obj/Release/net6.0/refint/AbsorbentSoil.dll differ