compile errors
This commit is contained in:
@@ -139,49 +139,31 @@ namespace AbsorbentSoil
|
||||
|
||||
internal static class SoilHelper
|
||||
{
|
||||
private static readonly FieldInfo RemainingSoilUsesField =
|
||||
AccessTools.Field(typeof(GrowContainer), "_remainingSoilUses");
|
||||
|
||||
public static bool IsRetainingSoil(Pot pot)
|
||||
{
|
||||
string soilId = GetSoilId(pot);
|
||||
if (string.IsNullOrWhiteSpace(soilId))
|
||||
if (pot == null || string.IsNullOrWhiteSpace(pot.SoilID))
|
||||
return false;
|
||||
|
||||
soilId = soilId.ToLowerInvariant();
|
||||
return soilId.Contains("longlifesoil") || soilId.Contains("extralonglifesoil");
|
||||
string soilId = pot.SoilID.ToLowerInvariant();
|
||||
|
||||
return soilId.Contains("longlifesoil") ||
|
||||
soilId.Contains("extralonglifesoil");
|
||||
}
|
||||
|
||||
public static string GetSoilId(Pot pot)
|
||||
public static int GetRemainingSoilUses(Pot pot)
|
||||
{
|
||||
if (pot == null)
|
||||
return string.Empty;
|
||||
if (pot == null || RemainingSoilUsesField == null)
|
||||
return 0;
|
||||
|
||||
object soilId = ReadMember(pot, "SoilID") ?? ReadMember(pot, "soilID") ?? ReadMember(pot, "SoilId") ?? ReadMember(pot, "soilId");
|
||||
return soilId?.ToString() ?? string.Empty;
|
||||
return (int)RemainingSoilUsesField.GetValue(pot);
|
||||
}
|
||||
|
||||
private static object ReadMember(object instance, string name)
|
||||
public static bool CanRetainAdditives(Pot pot)
|
||||
{
|
||||
if (instance == null || string.IsNullOrWhiteSpace(name))
|
||||
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;
|
||||
return IsRetainingSoil(pot) && GetRemainingSoilUses(pot) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +233,7 @@ namespace AbsorbentSoil
|
||||
|
||||
Pot pot = __instance.Pot;
|
||||
|
||||
if (!SoilHelper.IsRetainingSoil(pot))
|
||||
if (!SoilHelper.CanRetainAdditives(pot))
|
||||
{
|
||||
AdditiveMemory.Forget(pot);
|
||||
return;
|
||||
@@ -276,21 +258,15 @@ namespace AbsorbentSoil
|
||||
[HarmonyPatch(typeof(Pot), "OnPlantFullyHarvested")]
|
||||
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,
|
||||
// clear the retained additives so freshly re-poured soil starts clean.
|
||||
if (!SoilHelper.IsRetainingSoil(__instance))
|
||||
AdditiveMemory.Forget(__instance);
|
||||
}
|
||||
catch (Exception ex)
|
||||
if (!SoilHelper.CanRetainAdditives(__instance))
|
||||
{
|
||||
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.AssemblyConfigurationAttribute("Release")]
|
||||
[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.AssemblyTitleAttribute("AbsorbentSoil")]
|
||||
[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.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.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.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.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user