stage 2 complete. cleaned up verbose code and double logging

This commit is contained in:
2026-05-18 23:19:56 -04:00
parent b21db135db
commit 75ee5ce621
9 changed files with 59 additions and 37 deletions
@@ -2,32 +2,42 @@ using System;
using HarmonyLib;
using Il2CppScheduleOne.Growing;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.ObjectScripts;
using MelonLoader;
namespace AbsorbentSoil
{
[HarmonyPatch(typeof(Plant), nameof(Plant.AdditiveApplied))]
internal static class Plant_AdditiveApplied_Patch
public static class PlantAdditiveAppliedPatch
{
public static void Postfix(Plant __instance, AdditiveDefinition additive, bool isInitialApplication)
{
try
if (__instance == null || additive == null)
return;
// Important cleanup:
// Initial applications are caused by load/init/reapply behavior.
// Do NOT treat them as a fresh additive pour.
if (isInitialApplication)
{
MelonLogger.Msg($"Plant.AdditiveApplied fired. Plant={__instance?.name}, Pot={__instance?.Pot?.name}, Additive={additive?.ID}, Initial={isInitialApplication}");
if (AbsorbentSoilMod.VerboseLogging)
MelonLogger.Msg($"[Absorbent Soil] Ignored initial additive fire: {additive.ID}");
if (__instance == null || __instance.Pot == null || additive == null)
return;
string additiveId = additive.ID;
if (string.IsNullOrWhiteSpace(additiveId))
return;
AdditiveMemory.Remember(__instance.Pot, additiveId);
}
catch (Exception ex)
{
MelonLogger.Warning($"Plant.AdditiveApplied postfix failed: {ex}");
return;
}
Pot pot = __instance.Pot;
if (pot == null)
return;
string potKey = PotKeyHelper.GetPotKey(pot);
if (string.IsNullOrWhiteSpace(potKey))
return;
AdditiveMemory.Remember(pot, additive.ID);
if (AbsorbentSoilMod.VerboseLogging)
MelonLogger.Msg($"[Absorbent Soil] Remembered player additive '{additive.ID}' for pot '{potKey}'");
}
}
}
+32 -20
View File
@@ -3,34 +3,46 @@ using HarmonyLib;
using Il2CppScheduleOne.Growing;
using Il2CppScheduleOne.ObjectScripts;
using MelonLoader;
using System.Collections.Generic;
namespace AbsorbentSoil
{
[HarmonyPatch(typeof(Plant), nameof(Plant.Initialize))]
internal static class Plant_Initialize_Patch
public static class PlantInitializePatch
{
private static readonly HashSet<int> ReappliedPlants = new HashSet<int>();
public static void Postfix(Plant __instance)
{
try
if (__instance == null)
return;
int plantId = __instance.GetInstanceID();
if (ReappliedPlants.Contains(plantId))
return;
ReappliedPlants.Add(plantId);
Pot pot = __instance.Pot;
if (pot == null)
return;
string potKey = PotKeyHelper.GetPotKey(pot);
if (string.IsNullOrWhiteSpace(potKey))
return;
var additives = AdditiveMemory.Get(pot);
if (additives == null || additives.Count == 0)
return;
if (AbsorbentSoilMod.VerboseLogging)
MelonLogger.Msg($"[Absorbent Soil] Reapplying {additives.Count} remembered additive(s) to plant in pot '{potKey}'");
foreach (string additiveId in additives)
{
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}");
pot.ApplyAdditive(additiveId, true);
}
}
}
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+162a1ce7951370e4cbd8c674c284b30f8a85cbd4")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b21db135dbb267f14ba001c06d5e767684e16748")]
[assembly: System.Reflection.AssemblyProductAttribute("AbsorbentSoil")]
[assembly: System.Reflection.AssemblyTitleAttribute("AbsorbentSoil")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
67d62e0901b35175e30da93a43a11d964fe004e1a9681a2e3903abe5b9ef6961
b9ad6f2e98c8850d94d764bf380f030dbfc6c348e959950e4fa42b574c0504d4
Binary file not shown.
Binary file not shown.