compile errors

This commit is contained in:
2026-05-18 20:23:21 -04:00
parent 57f6a7917f
commit 3c7ea09f73
10 changed files with 23 additions and 77 deletions
+21 -45
View File
@@ -139,49 +139,31 @@ namespace AbsorbentSoil
internal static class SoilHelper internal static class SoilHelper
{ {
private static readonly FieldInfo RemainingSoilUsesField =
AccessTools.Field(typeof(GrowContainer), "_remainingSoilUses");
public static bool IsRetainingSoil(Pot pot) public static bool IsRetainingSoil(Pot pot)
{ {
string soilId = GetSoilId(pot); if (pot == null || string.IsNullOrWhiteSpace(pot.SoilID))
if (string.IsNullOrWhiteSpace(soilId))
return false; return false;
soilId = soilId.ToLowerInvariant(); string soilId = pot.SoilID.ToLowerInvariant();
return soilId.Contains("longlifesoil") || soilId.Contains("extralonglifesoil");
return soilId.Contains("longlifesoil") ||
soilId.Contains("extralonglifesoil");
} }
public static string GetSoilId(Pot pot) public static int GetRemainingSoilUses(Pot pot)
{ {
if (pot == null) if (pot == null || RemainingSoilUsesField == null)
return string.Empty; return 0;
object soilId = ReadMember(pot, "SoilID") ?? ReadMember(pot, "soilID") ?? ReadMember(pot, "SoilId") ?? ReadMember(pot, "soilId"); return (int)RemainingSoilUsesField.GetValue(pot);
return soilId?.ToString() ?? string.Empty;
} }
private static object ReadMember(object instance, string name) public static bool CanRetainAdditives(Pot pot)
{ {
if (instance == null || string.IsNullOrWhiteSpace(name)) return IsRetainingSoil(pot) && GetRemainingSoilUses(pot) > 0;
return null;
Type type = instance.GetType();
while (type != null)
{
PropertyInfo prop = AccessTools.Property(type, name);
if (prop != null)
{
try { return prop.GetValue(instance); } catch { }
}
FieldInfo field = AccessTools.Field(type, name);
if (field != null)
{
try { return field.GetValue(instance); } catch { }
}
type = type.BaseType;
}
return null;
} }
} }
@@ -251,7 +233,7 @@ namespace AbsorbentSoil
Pot pot = __instance.Pot; Pot pot = __instance.Pot;
if (!SoilHelper.IsRetainingSoil(pot)) if (!SoilHelper.CanRetainAdditives(pot))
{ {
AdditiveMemory.Forget(pot); AdditiveMemory.Forget(pot);
return; return;
@@ -276,21 +258,15 @@ namespace AbsorbentSoil
[HarmonyPatch(typeof(Pot), "OnPlantFullyHarvested")] [HarmonyPatch(typeof(Pot), "OnPlantFullyHarvested")]
internal static class Pot_OnPlantFullyHarvested_Patch internal static class Pot_OnPlantFullyHarvested_Patch
{ {
public static void Postfix(Pot __instance) private static void Postfix(Pot __instance)
{ {
try if (__instance == null)
{ return;
if (__instance == null)
return;
// After the game's harvest logic runs, if soil was consumed/removed or is no longer retaining soil, if (!SoilHelper.CanRetainAdditives(__instance))
// clear the retained additives so freshly re-poured soil starts clean.
if (!SoilHelper.IsRetainingSoil(__instance))
AdditiveMemory.Forget(__instance);
}
catch (Exception ex)
{ {
MelonLogger.Warning($"OnPlantFullyHarvested postfix failed: {ex}"); AdditiveMemory.Forget(__instance);
MelonLogger.Msg("[Absorbent Soil] Cleared retained additives because soil has no retaining uses left.");
} }
} }
} }
@@ -1,23 +0,0 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"AbsorbentSoil/1.0.0": {
"runtime": {
"AbsorbentSoil.dll": {}
}
}
}
},
"libraries": {
"AbsorbentSoil/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
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+1374b2e929263849b9362bc2032e73ac19079563")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+57f6a7917f7640bd65cefb3f66b24ea34b817e0c")]
[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 @@
c2488a0a4e0149be33c85611dadce8edca6655bd5fdedcb3c238565f85b2d0ec 8a3855f139cd66387b0e747834f0fb38e6416f2dc381e733183dbdeaa1f21465
@@ -1,12 +1,5 @@
/home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/bin/Release/net6.0/AbsorbentSoil.deps.json
/home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/bin/Release/net6.0/AbsorbentSoil.dll
/home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/bin/Release/net6.0/AbsorbentSoil.pdb
/home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.csproj.AssemblyReference.cache /home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.csproj.AssemblyReference.cache
/home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.GeneratedMSBuildEditorConfig.editorconfig /home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.GeneratedMSBuildEditorConfig.editorconfig
/home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfoInputs.cache /home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfoInputs.cache
/home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfo.cs /home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.AssemblyInfo.cs
/home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.csproj.CoreCompileInputs.cache /home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.csproj.CoreCompileInputs.cache
/home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.dll
/home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/refint/AbsorbentSoil.dll
/home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/AbsorbentSoil.pdb
/home/attila/Projects/Schedule-1/AbsorbentSoilMod/AbsorbentSoil/obj/Release/net6.0/ref/AbsorbentSoil.dll
Binary file not shown.
Binary file not shown.