warnings - not tracking

This commit is contained in:
2026-05-18 21:50:44 -04:00
parent 37e8635b49
commit df8a62295e
8 changed files with 66 additions and 15 deletions
+64 -13
View File
@@ -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<string, int> 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<Pot>();
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
{
Binary file not shown.
@@ -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")]
@@ -1 +1 @@
9c6b26084cb96fd78db85383b86eb4d039e88318cd7d033961d3866d747ac03a
e91a6e148fbebb52137b7ddb0d020d001faa537353e4a942e8c7b383650eef69
Binary file not shown.
Binary file not shown.