64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using HarmonyLib;
|
|
using Il2CppScheduleOne.ItemFramework;
|
|
using Il2CppScheduleOne.ObjectScripts;
|
|
using MelonLoader;
|
|
|
|
namespace AbsorbentSoil
|
|
{
|
|
[HarmonyPatch(typeof(Pot), "ApplyAdditive")]
|
|
internal static class Pot_ApplyAdditive_Patch
|
|
{
|
|
private static bool _suppressCapture;
|
|
|
|
public static void Postfix(Pot __instance, AdditiveDefinition __result, string additiveID, bool isInitialApplication)
|
|
{
|
|
try
|
|
{
|
|
if (_suppressCapture)
|
|
return;
|
|
|
|
if (__instance == null || __result == null || string.IsNullOrWhiteSpace(additiveID))
|
|
return;
|
|
|
|
if (!SoilHelper.CanCaptureNewAdditives(__instance))
|
|
return;
|
|
|
|
AdditiveMemory.Remember(__instance, additiveID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MelonLogger.Warning($"ApplyAdditive postfix failed: {ex}");
|
|
}
|
|
}
|
|
|
|
public static void ReapplyWithoutRecapture(Pot pot, string additiveID)
|
|
{
|
|
if (pot == null || string.IsNullOrWhiteSpace(additiveID))
|
|
return;
|
|
|
|
MethodInfo applyAdditive = AccessTools.Method(typeof(Pot), "ApplyAdditive");
|
|
if (applyAdditive == null)
|
|
{
|
|
MelonLogger.Warning("Could not find Pot.ApplyAdditive via reflection.");
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
_suppressCapture = true;
|
|
applyAdditive.Invoke(pot, new object[] { additiveID, true });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MelonLogger.Warning($"Failed to reapply additive '{additiveID}': {ex}");
|
|
}
|
|
finally
|
|
{
|
|
_suppressCapture = false;
|
|
}
|
|
}
|
|
}
|
|
}
|