Compare commits
3 Commits
b21db135db
...
795dbe9acc
| Author | SHA1 | Date | |
|---|---|---|---|
| 795dbe9acc | |||
| 41aead008b | |||
| 75ee5ce621 |
@@ -1,18 +1,21 @@
|
||||
using System;
|
||||
using MelonLoader;
|
||||
|
||||
[assembly: MelonInfo(typeof(AbsorbentSoil.AbsorbentSoilMod), "Absorbent Soil", "0.1.0", "AttilaG")]
|
||||
[assembly: MelonGame(null, "Schedule I")]
|
||||
[assembly: MelonInfo(typeof(AbsorbentSoil.AbsorbentSoilMod), "Absorbent Soil", "1.9.5", "9ate7six")]
|
||||
[assembly: MelonGame("TVGS", "Schedule I")]
|
||||
|
||||
namespace AbsorbentSoil
|
||||
{
|
||||
public sealed class AbsorbentSoilMod : MelonMod
|
||||
{
|
||||
internal static bool VerboseLogging = true;
|
||||
internal static bool VerboseLogging =>
|
||||
Config.AbsorbentSoilConfig.VerboseLogging;
|
||||
|
||||
public override void OnInitializeMelon()
|
||||
{
|
||||
AbsorbentSoil.Config.AbsorbentSoilConfig.Init();
|
||||
PersistenceStore.EnsureLoaded();
|
||||
|
||||
MelonLogger.Msg("Absorbent Soil loaded. Additive retention is active for long-life soils.");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using MelonLoader;
|
||||
|
||||
namespace AbsorbentSoil.Config
|
||||
{
|
||||
internal static class AbsorbentSoilConfig
|
||||
{
|
||||
private static MelonPreferences_Category Category;
|
||||
private static MelonPreferences_Entry<bool> VerboseLoggingEntry;
|
||||
|
||||
public static bool VerboseLogging => VerboseLoggingEntry?.Value ?? false;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
Category = MelonPreferences.CreateCategory("AbsorbentSoil");
|
||||
|
||||
VerboseLoggingEntry = Category.CreateEntry(
|
||||
"VerboseLogging",
|
||||
false,
|
||||
"Verbose Logging",
|
||||
"Enable detailed troubleshooting logs for Absorbent Soil.");
|
||||
|
||||
Category.SaveToFile(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Il2CppScheduleOne.Persistence;
|
||||
using MelonLoader;
|
||||
|
||||
internal static class RuntimeSafety
|
||||
{
|
||||
public static bool CanMutateState()
|
||||
{
|
||||
// Single-player usually passes.
|
||||
// In multiplayer, this should ideally be host/server only.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2,32 +2,45 @@ 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
|
||||
{
|
||||
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)
|
||||
if (!RuntimeSafety.CanMutateState())
|
||||
return;
|
||||
|
||||
string additiveId = additive.ID;
|
||||
if (string.IsNullOrWhiteSpace(additiveId))
|
||||
if (__instance == null || additive == null)
|
||||
return;
|
||||
|
||||
AdditiveMemory.Remember(__instance.Pot, additiveId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
// Important cleanup:
|
||||
// Initial applications are caused by load/init/reapply behavior.
|
||||
// Do NOT treat them as a fresh additive pour.
|
||||
if (isInitialApplication)
|
||||
{
|
||||
MelonLogger.Warning($"Plant.AdditiveApplied postfix failed: {ex}");
|
||||
}
|
||||
if (AbsorbentSoilMod.VerboseLogging)
|
||||
MelonLogger.Msg($"[Absorbent Soil] Ignored initial additive fire: {additive.ID}");
|
||||
|
||||
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}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
PersistenceStore.EnsureLoaded();
|
||||
|
||||
MelonLogger.Msg($"Plant.Initialize fired. Plant={__instance?.name}, Pot={__instance?.Pot?.name}");
|
||||
|
||||
if (__instance == null || __instance.Pot == null)
|
||||
if (__instance == null)
|
||||
return;
|
||||
|
||||
Pot actualPot = __instance.Pot;
|
||||
var additiveIds = AdditiveMemory.Get(actualPot);
|
||||
int plantId = __instance.GetInstanceID();
|
||||
|
||||
MelonLogger.Msg($"Plant.Initialize pot key={PotKeyHelper.GetPotKey(actualPot)}, remembered additives={additiveIds.Count}");
|
||||
if (ReappliedPlants.Contains(plantId))
|
||||
return;
|
||||
|
||||
foreach (string additiveId in additiveIds)
|
||||
Pot_ApplyAdditive_Patch.ReapplyWithoutRecapture(actualPot, additiveId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
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)
|
||||
{
|
||||
MelonLogger.Warning($"Plant.Initialize postfix failed: {ex}");
|
||||
pot.ApplyAdditive(additiveId, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ namespace AbsorbentSoil
|
||||
{
|
||||
public static void Prefix(Pot __instance)
|
||||
{
|
||||
if (!RuntimeSafety.CanMutateState())
|
||||
return;
|
||||
|
||||
// If the pot itself is destroyed/sold, stop tracking its additives.
|
||||
try
|
||||
{
|
||||
|
||||
@@ -14,6 +14,9 @@ namespace AbsorbentSoil
|
||||
{
|
||||
private static unsafe void Postfix(PourSoilTask __instance)
|
||||
{
|
||||
if (!RuntimeSafety.CanMutateState())
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
nint basePtr = (nint)IL2CPP.Il2CppObjectBaseToPtrNotNull(__instance);
|
||||
|
||||
@@ -11,6 +11,9 @@ namespace AbsorbentSoil
|
||||
|
||||
public static int DecrementRemainingSoilUses(Pot pot)
|
||||
{
|
||||
if (!RuntimeSafety.CanMutateState())
|
||||
return 0;
|
||||
|
||||
if (pot == null)
|
||||
return 0;
|
||||
|
||||
@@ -28,6 +31,9 @@ namespace AbsorbentSoil
|
||||
|
||||
public static void SetRemainingSoilUses(Pot pot, int uses)
|
||||
{
|
||||
if (!RuntimeSafety.CanMutateState())
|
||||
return;
|
||||
|
||||
if (pot == null)
|
||||
return;
|
||||
|
||||
|
||||
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+41aead008b6360d5bcd9ec7582d4f5227870e88e")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("AbsorbentSoil")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("AbsorbentSoil")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
67d62e0901b35175e30da93a43a11d964fe004e1a9681a2e3903abe5b9ef6961
|
||||
5b3843bf5d032d4965db2bf686646296b18d42f85ea867f9b81bf1117453f45b
|
||||
|
||||
@@ -1 +1 @@
|
||||
5c030080472ae1536e3626b995d635d8af1656efb3cdf494e4087a4281d4934d
|
||||
c4aee16fa9119b298402ca973e24c641ed042847f3a55a64c8b8a5107dac9e48
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user