54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using System;
|
|
using HarmonyLib;
|
|
using Il2CppInterop.Runtime;
|
|
using Il2CppScheduleOne.Growing;
|
|
using Il2CppScheduleOne.ItemFramework;
|
|
using Il2CppScheduleOne.ObjectScripts;
|
|
using Il2CppScheduleOne.PlayerTasks.Tasks;
|
|
using MelonLoader;
|
|
|
|
namespace AbsorbentSoil
|
|
{
|
|
[HarmonyPatch(typeof(PourSoilTask), "OnInitialPour")]
|
|
internal static class PourSoilTask_OnInitialPour_Patch
|
|
{
|
|
private static unsafe void Postfix(PourSoilTask __instance)
|
|
{
|
|
if (!RuntimeSafety.CanMutateState())
|
|
return;
|
|
|
|
try
|
|
{
|
|
nint basePtr = (nint)IL2CPP.Il2CppObjectBaseToPtrNotNull(__instance);
|
|
|
|
nint soilDefPtr = *(nint*)(basePtr + 0xD0);
|
|
nint growContainerPtr = *(nint*)(basePtr + 0xE8);
|
|
|
|
SoilDefinition soilDef = soilDefPtr != 0
|
|
? new SoilDefinition(soilDefPtr)
|
|
: null;
|
|
|
|
GrowContainer growContainer = growContainerPtr != 0
|
|
? new GrowContainer(growContainerPtr)
|
|
: null;
|
|
|
|
Pot pot = growContainer?.TryCast<Pot>();
|
|
|
|
MelonLogger.Msg($"PourSoilTask.OnInitialPour offset-read fired. Soil={soilDef?.ID}, Uses={soilDef?.Uses}, Pot={pot?.name}");
|
|
|
|
if (pot == null || soilDef == null)
|
|
return;
|
|
|
|
SoilHelper.SetRemainingSoilUses(pot, soilDef.Uses);
|
|
AdditiveMemory.Forget(pot);
|
|
|
|
MelonLogger.Msg($"[Absorbent Soil] Fresh soil added. Pot='{PotKeyHelper.GetPotKey(pot)}', Soil='{soilDef.ID}', Uses={soilDef.Uses}. Cleared old additives.");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MelonLogger.Warning($"PourSoilTask.OnInitialPour postfix failed: {ex}");
|
|
}
|
|
}
|
|
}
|
|
}
|