diff --git a/AbsorbentSoil/Config/AbsorbentSoilConfig.cs b/AbsorbentSoil/Config/AbsorbentSoilConfig.cs new file mode 100644 index 0000000..69274d2 --- /dev/null +++ b/AbsorbentSoil/Config/AbsorbentSoilConfig.cs @@ -0,0 +1,25 @@ +using MelonLoader; + +namespace AbsorbentSoil.Config +{ + internal static class AbsorbentSoilConfig + { + private static MelonPreferences_Category Category; + private static MelonPreferences_Entry 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); + } + } +} \ No newline at end of file diff --git a/AbsorbentSoil/Helpers/RuntimeSafetyHelper.cs b/AbsorbentSoil/Helpers/RuntimeSafetyHelper.cs new file mode 100644 index 0000000..7237906 --- /dev/null +++ b/AbsorbentSoil/Helpers/RuntimeSafetyHelper.cs @@ -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; + } +} \ No newline at end of file diff --git a/AbsorbentSoil/Patches/PlantAdditiveAppliedPatch.cs b/AbsorbentSoil/Patches/PlantAdditiveAppliedPatch.cs index c9440d5..4c77e18 100644 --- a/AbsorbentSoil/Patches/PlantAdditiveAppliedPatch.cs +++ b/AbsorbentSoil/Patches/PlantAdditiveAppliedPatch.cs @@ -12,6 +12,9 @@ namespace AbsorbentSoil { public static void Postfix(Plant __instance, AdditiveDefinition additive, bool isInitialApplication) { + if (!RuntimeSafety.CanMutateState()) + return; + if (__instance == null || additive == null) return; diff --git a/AbsorbentSoil/Patches/PotHarvestDestroyPatches.cs b/AbsorbentSoil/Patches/PotHarvestDestroyPatches.cs index 6640dc2..4c7616b 100644 --- a/AbsorbentSoil/Patches/PotHarvestDestroyPatches.cs +++ b/AbsorbentSoil/Patches/PotHarvestDestroyPatches.cs @@ -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 { diff --git a/AbsorbentSoil/Patches/PourSoilTaskOnInitialPourPatch.cs b/AbsorbentSoil/Patches/PourSoilTaskOnInitialPourPatch.cs index b11c28b..1679b32 100644 --- a/AbsorbentSoil/Patches/PourSoilTaskOnInitialPourPatch.cs +++ b/AbsorbentSoil/Patches/PourSoilTaskOnInitialPourPatch.cs @@ -14,6 +14,9 @@ namespace AbsorbentSoil { private static unsafe void Postfix(PourSoilTask __instance) { + if (!RuntimeSafety.CanMutateState()) + return; + try { nint basePtr = (nint)IL2CPP.Il2CppObjectBaseToPtrNotNull(__instance); diff --git a/AbsorbentSoil/State/SoilHelper.cs b/AbsorbentSoil/State/SoilHelper.cs index 9408b69..89d2b17 100644 --- a/AbsorbentSoil/State/SoilHelper.cs +++ b/AbsorbentSoil/State/SoilHelper.cs @@ -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; diff --git a/AbsorbentSoil/bin/Release/net6.0/AbsorbentSoil.pdb b/AbsorbentSoil/bin/Release/net6.0/AbsorbentSoil.pdb index 909799c..9450a95 100644 Binary files a/AbsorbentSoil/bin/Release/net6.0/AbsorbentSoil.pdb and b/AbsorbentSoil/bin/Release/net6.0/AbsorbentSoil.pdb differ diff --git a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfo.cs b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfo.cs index 175fbe1..c89ff9a 100644 --- a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfo.cs +++ b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfo.cs @@ -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+b21db135dbb267f14ba001c06d5e767684e16748")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+75ee5ce621b167f1457e04cef2d427eb9879c0e5")] [assembly: System.Reflection.AssemblyProductAttribute("AbsorbentSoil")] [assembly: System.Reflection.AssemblyTitleAttribute("AbsorbentSoil")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfoInputs.cache b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfoInputs.cache index f77f843..378d7e4 100644 --- a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfoInputs.cache +++ b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfoInputs.cache @@ -1 +1 @@ -b9ad6f2e98c8850d94d764bf380f030dbfc6c348e959950e4fa42b574c0504d4 +e3d03f6c9dfc521324738d04ad4228faed1bb64eafad7288d3a595d219e15990 diff --git a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.csproj.CoreCompileInputs.cache b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.csproj.CoreCompileInputs.cache index 8297418..ae047d1 100644 --- a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.csproj.CoreCompileInputs.cache +++ b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -5c030080472ae1536e3626b995d635d8af1656efb3cdf494e4087a4281d4934d +04cacbb88ccbdb0ef16f25557f16c2a1f76e1e74a1eff95472a744bd5aa2b973 diff --git a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.dll b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.dll index ffc449b..6239f80 100644 Binary files a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.dll and b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.dll differ diff --git a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.pdb b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.pdb index 909799c..9450a95 100644 Binary files a/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.pdb and b/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.pdb differ diff --git a/AbsorbentSoil/obj/Release/net6.0/ref/AbsorbentSoil.dll b/AbsorbentSoil/obj/Release/net6.0/ref/AbsorbentSoil.dll index 8d7cb45..465c083 100644 Binary files a/AbsorbentSoil/obj/Release/net6.0/ref/AbsorbentSoil.dll and b/AbsorbentSoil/obj/Release/net6.0/ref/AbsorbentSoil.dll differ diff --git a/AbsorbentSoil/obj/Release/net6.0/refint/AbsorbentSoil.dll b/AbsorbentSoil/obj/Release/net6.0/refint/AbsorbentSoil.dll index 8d7cb45..465c083 100644 Binary files a/AbsorbentSoil/obj/Release/net6.0/refint/AbsorbentSoil.dll and b/AbsorbentSoil/obj/Release/net6.0/refint/AbsorbentSoil.dll differ