diff --git a/Assemblies/0JecsTools.dll b/Assemblies/0JecsTools.dll index 0db3ffa2..6ab10798 100644 Binary files a/Assemblies/0JecsTools.dll and b/Assemblies/0JecsTools.dll differ diff --git a/Assemblies/AbilityUser.dll b/Assemblies/AbilityUser.dll index 47439468..e5284fad 100644 Binary files a/Assemblies/AbilityUser.dll and b/Assemblies/AbilityUser.dll differ diff --git a/Assemblies/AbilityUserAI.dll b/Assemblies/AbilityUserAI.dll index dcd3dfe6..4b6668d3 100644 Binary files a/Assemblies/AbilityUserAI.dll and b/Assemblies/AbilityUserAI.dll differ diff --git a/Assemblies/CompActivatableEffect.dll b/Assemblies/CompActivatableEffect.dll index 60f7d966..70461c51 100644 Binary files a/Assemblies/CompActivatableEffect.dll and b/Assemblies/CompActivatableEffect.dll differ diff --git a/Assemblies/CompAnimated.dll b/Assemblies/CompAnimated.dll index c1e8581a..42817f7d 100644 Binary files a/Assemblies/CompAnimated.dll and b/Assemblies/CompAnimated.dll differ diff --git a/Assemblies/CompBalloon.dll b/Assemblies/CompBalloon.dll index 6c2392a6..174d0dda 100644 Binary files a/Assemblies/CompBalloon.dll and b/Assemblies/CompBalloon.dll differ diff --git a/Assemblies/CompDeflector.dll b/Assemblies/CompDeflector.dll index a6a7dde6..926f5e17 100644 Binary files a/Assemblies/CompDeflector.dll and b/Assemblies/CompDeflector.dll differ diff --git a/Assemblies/CompDelayedSpawner.dll b/Assemblies/CompDelayedSpawner.dll index 0fc1f11b..6f2973d9 100644 Binary files a/Assemblies/CompDelayedSpawner.dll and b/Assemblies/CompDelayedSpawner.dll differ diff --git a/Assemblies/CompExtraSounds.dll b/Assemblies/CompExtraSounds.dll index 761bc905..2d42c7ed 100644 Binary files a/Assemblies/CompExtraSounds.dll and b/Assemblies/CompExtraSounds.dll differ diff --git a/Assemblies/CompInstalledPart.dll b/Assemblies/CompInstalledPart.dll index 74013814..bde67c30 100644 Binary files a/Assemblies/CompInstalledPart.dll and b/Assemblies/CompInstalledPart.dll differ diff --git a/Assemblies/CompLumbering.dll b/Assemblies/CompLumbering.dll index c85ba98c..dffd28d9 100644 Binary files a/Assemblies/CompLumbering.dll and b/Assemblies/CompLumbering.dll differ diff --git a/Assemblies/CompOverlays.dll b/Assemblies/CompOverlays.dll index ae3589f6..bbd7d570 100644 Binary files a/Assemblies/CompOverlays.dll and b/Assemblies/CompOverlays.dll differ diff --git a/Assemblies/CompOversizedWeapon.dll b/Assemblies/CompOversizedWeapon.dll index 2716c3d2..1500eff3 100644 Binary files a/Assemblies/CompOversizedWeapon.dll and b/Assemblies/CompOversizedWeapon.dll differ diff --git a/Assemblies/CompSlotLoadable.dll b/Assemblies/CompSlotLoadable.dll index 1295407b..ac099f86 100644 Binary files a/Assemblies/CompSlotLoadable.dll and b/Assemblies/CompSlotLoadable.dll differ diff --git a/Assemblies/CompToggleDef.dll b/Assemblies/CompToggleDef.dll index 85f2af6b..e76a2fcb 100644 Binary files a/Assemblies/CompToggleDef.dll and b/Assemblies/CompToggleDef.dll differ diff --git a/Assemblies/CompVehicle.dll b/Assemblies/CompVehicle.dll index e1fcbd18..c3e3f46d 100644 Binary files a/Assemblies/CompVehicle.dll and b/Assemblies/CompVehicle.dll differ diff --git a/Assemblies/PawnShields.dll b/Assemblies/PawnShields.dll index c3ceb9ab..16d1d641 100644 Binary files a/Assemblies/PawnShields.dll and b/Assemblies/PawnShields.dll differ diff --git a/Source/AllModdingComponents/CompActivatableEffect/HarmonyCompActivatableEffect.cs b/Source/AllModdingComponents/CompActivatableEffect/HarmonyCompActivatableEffect.cs index c7bb73fb..8f93d57f 100644 --- a/Source/AllModdingComponents/CompActivatableEffect/HarmonyCompActivatableEffect.cs +++ b/Source/AllModdingComponents/CompActivatableEffect/HarmonyCompActivatableEffect.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Harmony; using RimWorld; @@ -17,9 +18,9 @@ static HarmonyCompActivatableEffect() harmony.Patch(typeof(Pawn).GetMethod("GetGizmos"), null, new HarmonyMethod(typeof(HarmonyCompActivatableEffect).GetMethod("GetGizmosPrefix"))); harmony.Patch(typeof(PawnRenderer).GetMethod("DrawEquipmentAiming"), null, - new HarmonyMethod(typeof(HarmonyCompActivatableEffect).GetMethod("DrawEquipmentAimingPostFix"))); + new HarmonyMethod(typeof(HarmonyCompActivatableEffect), nameof(DrawEquipmentAimingPostFix))); harmony.Patch(typeof(Verb).GetMethod("TryStartCastOn"), - new HarmonyMethod(typeof(HarmonyCompActivatableEffect).GetMethod("TryStartCastOnPrefix")), null); + new HarmonyMethod(typeof(HarmonyCompActivatableEffect), nameof(TryStartCastOnPrefix)), null); harmony.Patch(typeof(Pawn_DraftController).GetMethod("set_Drafted"), null, new HarmonyMethod(typeof(HarmonyCompActivatableEffect).GetMethod("set_Drafted_PostFix"))); harmony.Patch(typeof(Pawn).GetMethod("ExitMap"), @@ -74,31 +75,33 @@ public static bool TryStartCastOnPrefix(ref bool __result, Verb __instance) { if (__instance.caster is Pawn pawn) { - var pawn_EquipmentTracker = pawn.equipment; - if (pawn_EquipmentTracker != null) - { - //Log.Message("2"); - //ThingWithComps thingWithComps = (ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker); - var thingWithComps = - pawn_EquipmentTracker - .Primary; //(ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker); + var pawn_EquipmentTracker = pawn?.equipment; + if (pawn_EquipmentTracker == null) return true; - if (thingWithComps != null) - { - //Log.Message("3"); - var compActivatableEffect = thingWithComps.GetComp(); - if (compActivatableEffect != null) - if (__instance.EquipmentSource == thingWithComps) - if (compActivatableEffect.CurrentState != CompActivatableEffect.State.Activated) - { - if (Find.TickManager.TicksGame % 250 == 0) - Messages.Message("DeactivatedWarning".Translate(pawn.Label), - MessageTypeDefOf.RejectInput); - __result = false; - return false; - } - } + var thingWithComps = + pawn_EquipmentTracker?.Primary; //(ThingWithComps)AccessTools.Field(typeof(Pawn_EquipmentTracker), "primaryInt").GetValue(pawn_EquipmentTracker); + + var compActivatableEffect = thingWithComps?.GetComp(); + if (compActivatableEffect == null) return true; + + //Equipment source throws errors when checked while casting abilities with a weapon equipped. + // to avoid this error preventing our code from executing, we do a try/catch. + try + { + if (__instance?.EquipmentSource != thingWithComps) + return true; + } + catch (Exception e) + { } + + if (compActivatableEffect.CurrentState == CompActivatableEffect.State.Activated) return true; + + if (Find.TickManager.TicksGame % 250 == 0) + Messages.Message("DeactivatedWarning".Translate(pawn.Label), + MessageTypeDefOf.RejectInput); + __result = false; + return false; } return true; }