diff --git a/AbsorbentSoil/AbsorbentSoilMod.cs b/AbsorbentSoil/AbsorbentSoilMod.cs index 4786335..bb080d9 100644 --- a/AbsorbentSoil/AbsorbentSoilMod.cs +++ b/AbsorbentSoil/AbsorbentSoilMod.cs @@ -17,7 +17,7 @@ namespace AbsorbentSoil { public sealed class AbsorbentSoilMod : MelonMod { - internal static bool VerboseLogging = false; + internal static bool VerboseLogging = true; public override void OnInitializeMelon() { @@ -142,27 +142,37 @@ namespace AbsorbentSoil internal static class SoilHelper { - private static readonly FieldInfo RemainingSoilUsesField = - AccessTools.Field(typeof(GrowContainer), "_remainingSoilUses"); + private static readonly Dictionary RemainingUsesByPotKey = new(); + + public static void SetRemainingSoilUses(Pot pot, int uses) + { + if (pot == null) + return; + + string key = PotKeyHelper.GetPotKey(pot); + if (string.IsNullOrWhiteSpace(key)) + return; + + RemainingUsesByPotKey[key] = uses; + + if (AbsorbentSoilMod.VerboseLogging) + MelonLogger.Msg($"Tracked soil uses for pot '{key}': {uses}"); + } public static int GetRemainingSoilUses(Pot pot) { - if (pot == null || RemainingSoilUsesField == null) + if (pot == null) return 0; - try - { - return (int)RemainingSoilUsesField.GetValue(pot); - } - catch - { + string key = PotKeyHelper.GetPotKey(pot); + if (string.IsNullOrWhiteSpace(key)) return 0; - } + + return RemainingUsesByPotKey.TryGetValue(key, out int uses) ? uses : 0; } public static bool CanCaptureNewAdditives(Pot pot) { - // Normal soil should have 1 use, long-life should have more than 1. return GetRemainingSoilUses(pot) > 1; } @@ -170,6 +180,13 @@ namespace AbsorbentSoil { return GetRemainingSoilUses(pot) > 0; } + + public static void Forget(Pot pot) + { + string key = PotKeyHelper.GetPotKey(pot); + if (!string.IsNullOrWhiteSpace(key)) + RemainingUsesByPotKey.Remove(key); + } } [HarmonyPatch(typeof(Pot), "ApplyAdditive")] @@ -273,15 +290,18 @@ namespace AbsorbentSoil { try { - if (__instance == null || uses > 0) - return; - Pot pot = __instance.TryCast(); if (pot == null) return; - AdditiveMemory.Forget(pot); - MelonLogger.Msg("[Absorbent Soil] Cleared retained additives because soil uses reached zero."); + SoilHelper.SetRemainingSoilUses(pot, uses); + + if (uses <= 0) + { + AdditiveMemory.Forget(pot); + SoilHelper.Forget(pot); + MelonLogger.Msg("[Absorbent Soil] Cleared retained additives because soil uses reached zero."); + } } catch (Exception ex) { diff --git a/AbsorbentSoil/bin/Release/net6.0/AbsorbentSoil.pdb b/AbsorbentSoil/bin/Release/net6.0/AbsorbentSoil.pdb index 74111c8..c8f390e 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 7699a91..4aaa553 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+3c7ea09f730c3ca38d3c004961f111503e0905c8")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+7eba0a03f019a3817f694cbae7ecb1d5f3104e45")] [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 e5d73e1..90cf241 100644 --- a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfoInputs.cache +++ b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfoInputs.cache @@ -1 +1 @@ -b331521ed94e421a5866942ca81a55cff8e0735dcb4bc556f934ca310386ca0f +27eaa669f94faac9705255117bf2c7e16542b7864e4480e4b988fcdf9942abbc diff --git a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.dll b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.dll index 9000eee..329eca1 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 74111c8..c8f390e 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 d656e87..7581fb7 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 d656e87..7581fb7 100644 Binary files a/AbsorbentSoil/obj/Release/net6.0/refint/AbsorbentSoil.dll and b/AbsorbentSoil/obj/Release/net6.0/refint/AbsorbentSoil.dll differ