diff --git a/1.6/1.6/Assemblies/ArachnaeSwarm.dll b/1.6/1.6/Assemblies/ArachnaeSwarm.dll index 873e04e..d4b3de2 100644 Binary files a/1.6/1.6/Assemblies/ArachnaeSwarm.dll and b/1.6/1.6/Assemblies/ArachnaeSwarm.dll differ diff --git a/1.6/1.6/Assemblies/ArachnaeSwarm.pdb b/1.6/1.6/Assemblies/ArachnaeSwarm.pdb index f909b9a..e8efa02 100644 Binary files a/1.6/1.6/Assemblies/ArachnaeSwarm.pdb and b/1.6/1.6/Assemblies/ArachnaeSwarm.pdb differ diff --git a/Source/ArachnaeSwarm/ArachnaeSwarm.csproj b/Source/ArachnaeSwarm/ArachnaeSwarm.csproj index dbac7c6..cc4d741 100644 --- a/Source/ArachnaeSwarm/ArachnaeSwarm.csproj +++ b/Source/ArachnaeSwarm/ArachnaeSwarm.csproj @@ -74,349 +74,7 @@ ..\..\..\..\..\..\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.TextRenderingModule.dll False - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/Source/ArachnaeSwarm/HarmonyPatches/Patch_PlantPollutionNullCheck.cs b/Source/ArachnaeSwarm/HarmonyPatches/Patch_PlantPollutionNullCheck.cs new file mode 100644 index 0000000..6a947cd --- /dev/null +++ b/Source/ArachnaeSwarm/HarmonyPatches/Patch_PlantPollutionNullCheck.cs @@ -0,0 +1,67 @@ +using HarmonyLib; +using RimWorld; +using Verse; + +namespace ArachnaeSwarm +{ + /// + /// 修复原版 Plant 类在被 Pawn 携带/吃掉时的空引用异常。 + /// 当植物被 Pawn 吃掉时,它会被放入 Pawn 的 ThingOwner 中, + /// 此时 Map 为 null,但 Plant.TickLong() 仍然会被调用, + /// 导致多处访问 Map 相关方法时抛出 NullReferenceException。 + /// + [HarmonyPatch] + public static class Patch_PlantPollutionNullCheck + { + /// + /// Prefix for Plant.TickLong + /// 如果植物不在地图上,直接跳过整个 TickLong 方法 + /// 这是最根本的修复,可以防止所有后续的空引用异常 + /// + [HarmonyPatch(typeof(Plant), nameof(Plant.TickLong))] + [HarmonyPrefix] + public static bool TickLong_Prefix(Plant __instance) + { + // 如果植物未生成或不在地图上,跳过整个 TickLong + if (!__instance.Spawned || __instance.Map == null) + { + return false; // 跳过原方法 + } + return true; // 继续执行原方法 + } + + /// + /// Prefix for Plant.DyingFromPollution getter + /// 如果植物不在地图上,直接返回 false,跳过原方法 + /// + [HarmonyPatch(typeof(Plant), nameof(Plant.DyingFromPollution), MethodType.Getter)] + [HarmonyPrefix] + public static bool DyingFromPollution_Prefix(Plant __instance, ref bool __result) + { + // 如果植物未生成或不在地图上,返回 false 并跳过原方法 + if (!__instance.Spawned || __instance.Map == null) + { + __result = false; + return false; // 跳过原方法 + } + return true; // 继续执行原方法 + } + + /// + /// Prefix for Plant.DyingFromNoPollution getter + /// 如果植物不在地图上,直接返回 false,跳过原方法 + /// + [HarmonyPatch(typeof(Plant), nameof(Plant.DyingFromNoPollution), MethodType.Getter)] + [HarmonyPrefix] + public static bool DyingFromNoPollution_Prefix(Plant __instance, ref bool __result) + { + // 如果植物未生成或不在地图上,返回 false 并跳过原方法 + if (!__instance.Spawned || __instance.Map == null) + { + __result = false; + return false; // 跳过原方法 + } + return true; // 继续执行原方法 + } + } +}