diff --git a/1.6/1.6/Assemblies/ArachnaeSwarm.dll b/1.6/1.6/Assemblies/ArachnaeSwarm.dll index f396c6d..4e75ada 100644 Binary files a/1.6/1.6/Assemblies/ArachnaeSwarm.dll and b/1.6/1.6/Assemblies/ArachnaeSwarm.dll differ diff --git a/Source/ArachnaeSwarm/ArachnaeSwarm.csproj b/Source/ArachnaeSwarm/ArachnaeSwarm.csproj index 21dac4b..4449cdc 100644 --- a/Source/ArachnaeSwarm/ArachnaeSwarm.csproj +++ b/Source/ArachnaeSwarm/ArachnaeSwarm.csproj @@ -327,6 +327,7 @@ + diff --git a/Source/ArachnaeSwarm/HarmonyPatches/Projectile_Launch_Patch.cs b/Source/ArachnaeSwarm/HarmonyPatches/Projectile_Launch_Patch.cs new file mode 100644 index 0000000..bb6cafa --- /dev/null +++ b/Source/ArachnaeSwarm/HarmonyPatches/Projectile_Launch_Patch.cs @@ -0,0 +1,44 @@ +using HarmonyLib; +using RimWorld; +using System.Linq; +using System.Reflection; +using UnityEngine; +using Verse; + +namespace ArachnaeSwarm.HarmonyPatches +{ + [HarmonyPatch(typeof(Projectile), "CheckForFreeInterceptBetween")] + public static class Projectile_CheckForFreeInterceptBetween_Patch + { + private static readonly MethodInfo ImpactMethod = AccessTools.Method(typeof(Projectile), "Impact"); + + public static bool Prefix(Projectile __instance, Vector3 lastExactPos, Vector3 newExactPos) + { + if (__instance.Map == null || __instance.Destroyed) return true; + + foreach (Pawn pawn in __instance.Map.mapPawns.AllPawnsSpawned) + { + if (pawn.apparel != null) + { + foreach (Apparel apparel in pawn.apparel.WornApparel) + { + if (apparel.TryGetComp(out var interceptor)) + { + if (interceptor.TryIntercept(__instance, lastExactPos, newExactPos)) + { + // Directly destroy the projectile instead of calling Impact via reflection. + // This is cleaner and avoids the NRE that happens when the game engine + // continues to process a projectile that was destroyed mid-tick. + __instance.Destroy(DestroyMode.Vanish); + + return false; // Prevent original method from running. + } + } + } + } + } + + return true; + } + } +} \ No newline at end of file