stage 2 complete. cleaned up verbose code and double logging
This commit is contained in:
@@ -2,32 +2,42 @@ using System;
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using Il2CppScheduleOne.Growing;
|
using Il2CppScheduleOne.Growing;
|
||||||
using Il2CppScheduleOne.ItemFramework;
|
using Il2CppScheduleOne.ItemFramework;
|
||||||
|
using Il2CppScheduleOne.ObjectScripts;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
|
|
||||||
namespace AbsorbentSoil
|
namespace AbsorbentSoil
|
||||||
{
|
{
|
||||||
[HarmonyPatch(typeof(Plant), nameof(Plant.AdditiveApplied))]
|
[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)
|
public static void Postfix(Plant __instance, AdditiveDefinition additive, bool isInitialApplication)
|
||||||
{
|
{
|
||||||
try
|
if (__instance == null || additive == null)
|
||||||
{
|
|
||||||
MelonLogger.Msg($"Plant.AdditiveApplied fired. Plant={__instance?.name}, Pot={__instance?.Pot?.name}, Additive={additive?.ID}, Initial={isInitialApplication}");
|
|
||||||
|
|
||||||
if (__instance == null || __instance.Pot == null || additive == null)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string additiveId = additive.ID;
|
// Important cleanup:
|
||||||
if (string.IsNullOrWhiteSpace(additiveId))
|
// Initial applications are caused by load/init/reapply behavior.
|
||||||
|
// Do NOT treat them as a fresh additive pour.
|
||||||
|
if (isInitialApplication)
|
||||||
|
{
|
||||||
|
if (AbsorbentSoilMod.VerboseLogging)
|
||||||
|
MelonLogger.Msg($"[Absorbent Soil] Ignored initial additive fire: {additive.ID}");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pot pot = __instance.Pot;
|
||||||
|
if (pot == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AdditiveMemory.Remember(__instance.Pot, additiveId);
|
string potKey = PotKeyHelper.GetPotKey(pot);
|
||||||
}
|
if (string.IsNullOrWhiteSpace(potKey))
|
||||||
catch (Exception ex)
|
return;
|
||||||
{
|
|
||||||
MelonLogger.Warning($"Plant.AdditiveApplied postfix failed: {ex}");
|
AdditiveMemory.Remember(pot, additive.ID);
|
||||||
}
|
|
||||||
|
if (AbsorbentSoilMod.VerboseLogging)
|
||||||
|
MelonLogger.Msg($"[Absorbent Soil] Remembered player additive '{additive.ID}' for pot '{potKey}'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,34 +3,46 @@ using HarmonyLib;
|
|||||||
using Il2CppScheduleOne.Growing;
|
using Il2CppScheduleOne.Growing;
|
||||||
using Il2CppScheduleOne.ObjectScripts;
|
using Il2CppScheduleOne.ObjectScripts;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AbsorbentSoil
|
namespace AbsorbentSoil
|
||||||
{
|
{
|
||||||
[HarmonyPatch(typeof(Plant), nameof(Plant.Initialize))]
|
[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)
|
public static void Postfix(Plant __instance)
|
||||||
{
|
{
|
||||||
try
|
if (__instance == null)
|
||||||
{
|
|
||||||
PersistenceStore.EnsureLoaded();
|
|
||||||
|
|
||||||
MelonLogger.Msg($"Plant.Initialize fired. Plant={__instance?.name}, Pot={__instance?.Pot?.name}");
|
|
||||||
|
|
||||||
if (__instance == null || __instance.Pot == null)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Pot actualPot = __instance.Pot;
|
int plantId = __instance.GetInstanceID();
|
||||||
var additiveIds = AdditiveMemory.Get(actualPot);
|
|
||||||
|
|
||||||
MelonLogger.Msg($"Plant.Initialize pot key={PotKeyHelper.GetPotKey(actualPot)}, remembered additives={additiveIds.Count}");
|
if (ReappliedPlants.Contains(plantId))
|
||||||
|
return;
|
||||||
|
|
||||||
foreach (string additiveId in additiveIds)
|
ReappliedPlants.Add(plantId);
|
||||||
Pot_ApplyAdditive_Patch.ReapplyWithoutRecapture(actualPot, additiveId);
|
|
||||||
}
|
Pot pot = __instance.Pot;
|
||||||
catch (Exception ex)
|
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)
|
||||||
{
|
{
|
||||||
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.AssemblyCompanyAttribute("AbsorbentSoil")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[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.AssemblyProductAttribute("AbsorbentSoil")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("AbsorbentSoil")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("AbsorbentSoil")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
67d62e0901b35175e30da93a43a11d964fe004e1a9681a2e3903abe5b9ef6961
|
b9ad6f2e98c8850d94d764bf380f030dbfc6c348e959950e4fa42b574c0504d4
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user