diff --git a/src/CommunityPatch/CommunityPatch.csproj b/src/CommunityPatch/CommunityPatch.csproj
index a93a40a..eca9d7b 100644
--- a/src/CommunityPatch/CommunityPatch.csproj
+++ b/src/CommunityPatch/CommunityPatch.csproj
@@ -6,7 +6,7 @@
Debug;Release
x64
x64
-
+
Community Patch
Tyler Young
The Mount & Blade II: Bannerlord Community
@@ -33,6 +33,7 @@
True
+
SubModule.xml
@@ -40,24 +41,24 @@
README.md
-
+
-
-
+
+
True
NU1701
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
diff --git a/src/CommunityPatch/Patches/Perks/Endurance/Riding/TramplerPatch2.cs b/src/CommunityPatch/Patches/Perks/Endurance/Riding/TramplerPatch2.cs
index af779bd..61d98d4 100644
--- a/src/CommunityPatch/Patches/Perks/Endurance/Riding/TramplerPatch2.cs
+++ b/src/CommunityPatch/Patches/Perks/Endurance/Riding/TramplerPatch2.cs
@@ -4,6 +4,7 @@
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
using HarmonyLib;
+using JetBrains.Annotations;
using TaleWorlds.Engine;
using TaleWorlds.MountAndBlade;
using static System.Reflection.BindingFlags;
@@ -12,21 +13,21 @@
namespace CommunityPatch.Patches.Perks.Endurance.Riding {
public sealed class TramplerPatch2 : PerkPatchBase {
+
public override bool Applied { get; protected set; }
private static readonly MethodInfo OverloadedTargetMethodInfo = typeof(Mission).GetMethod("GetAttackCollisionResults", Public | Static | DeclaredOnly);
- private static readonly Type AttackInformationType = Type.GetType("AttackInformation");
-
- private static readonly ConstructorInfo TargetConstructorInfo = typeof(AttackInformation).GetConstructor(new [] {
+ [CanBeNull]
+ private static readonly Type AttackInformationType = Type.GetType("TaleWorlds.MountAndBlade.AttackInformation, TaleWorlds.MountAndBlade, Version=1.0.0.0, Culture=neutral", false);
+
+ private static readonly ConstructorInfo TargetConstructorInfo = AttackInformationType?.GetConstructor(new[] {
typeof(Agent), typeof(Agent), typeof(GameEntity), typeof(AttackCollisionData).MakeByRefType()
});
- private static readonly MethodInfo UpdateCharacterPostfixPatchMethodInfo = typeof(TramplerPatch2).
- GetMethod(nameof(UpdateCorrectCharacterForHorseChargeDamagePostfix), NonPublic | Static | DeclaredOnly);
+ private static readonly MethodInfo UpdateCharacterPostfixPatchMethodInfo = typeof(TramplerPatch2).GetMethod(nameof(UpdateCorrectCharacterForHorseChargeDamagePostfix), NonPublic | Static | DeclaredOnly);
- private static readonly MethodInfo UpdateHorseDamagePostfixPatchMethodInfo = typeof(TramplerPatch2).
- GetMethod(nameof(UpdateHorseDamagePostfix), NonPublic | Static | DeclaredOnly);
+ private static readonly MethodInfo UpdateHorseDamagePostfixPatchMethodInfo = typeof(TramplerPatch2).GetMethod(nameof(UpdateHorseDamagePostfix), NonPublic | Static | DeclaredOnly);
public override IEnumerable GetMethodsChecked() {
yield return TargetConstructorInfo;
@@ -42,7 +43,7 @@ public override IEnumerable GetMethodsChecked() {
0x90, 0x4E, 0x8B, 0x8C, 0x14, 0xB1, 0xE6, 0xC7
}
};
-
+
public static readonly byte[][] ConstructorHashes = {
new byte[] {
// e1.4.0.228616
@@ -57,19 +58,18 @@ public TramplerPatch2() : base("GKlmIYik") {
}
public override bool? IsApplicable(Game game) {
-
if (OverloadedTargetMethodInfo == null)
return false;
-
+
if (AlreadyPatchedByOthers(Harmony.GetPatchInfo(OverloadedTargetMethodInfo)))
return false;
if (!OverloadedTargetMethodInfo.MakeCilSignatureSha256().MatchesAnySha256(OverloadedTargetHashes))
return false;
-
+
if (TargetConstructorInfo == null)
return false;
-
+
if (AlreadyPatchedByOthers(Harmony.GetPatchInfo(TargetConstructorInfo)))
return false;
@@ -82,30 +82,26 @@ public TramplerPatch2() : base("GKlmIYik") {
public override void Apply(Game game) {
if (Applied) return;
- CommunityPatchSubModule.Harmony.Patch(TargetConstructorInfo,
- postfix: new HarmonyMethod(UpdateCharacterPostfixPatchMethodInfo));
+ CommunityPatchSubModule.Harmony.Patch(TargetConstructorInfo,
+ postfix: new HarmonyMethod(UpdateCharacterPostfixPatchMethodInfo));
- CommunityPatchSubModule.Harmony.Patch(OverloadedTargetMethodInfo,
- postfix: new HarmonyMethod(UpdateHorseDamagePostfixPatchMethodInfo));
+ CommunityPatchSubModule.Harmony.Patch(OverloadedTargetMethodInfo,
+ postfix: new HarmonyMethod(UpdateHorseDamagePostfixPatchMethodInfo));
Applied = true;
}
-
- private static readonly FieldInfo AttackerAgentCharacterFieldInfo = typeof(AttackInformation)
- .GetField(nameof(AttackInformation.AttackerAgentCharacter), Public | Instance | DeclaredOnly);
-
- private static void SetAttackerAgentCharacter(ref AttackInformation attackInformation, BasicCharacterObject attackerCharacter) {
- object boxed = attackInformation;
- AttackerAgentCharacterFieldInfo.SetValue(boxed, attackerCharacter);
- attackInformation = (AttackInformation) boxed;
- }
-
- private static void UpdateCorrectCharacterForHorseChargeDamagePostfix(ref AttackInformation __instance, Agent attackerAgent, ref AttackCollisionData attackCollisionData) {
- if (attackCollisionData.IsHorseCharge && attackerAgent.RiderAgent?.Character != null) {
- SetAttackerAgentCharacter(ref __instance, attackerAgent.RiderAgent.Character);
- }
+
+ private static readonly FieldInfo AttackerAgentCharacterFieldInfo = AttackInformationType?.GetField("AttackerAgentCharacter", Public | Instance | DeclaredOnly);
+
+ [CanBeNull]
+ private static readonly AccessTools.FieldRef