Johnnydue
Recruit
I'm trying to make an damage/armor mod but got into some problems while trying out stuff.
I'm an experienced linux/python/c programmer but just leaned c# modding today.
If I try to patch ComputeRawDamageNew everything work as expected.
If I try to patch CalculateStrikeMagnitudeForSwing the game get stuck at loading save and harmony.log gets lots of print out of "PatchSwing".
If I try to patch CalculateStrikeMagnitudeForThrust the game will crash before main menu.
The functions are in TaleWorlds.Core / CombatStatCalculator
@Ster you seem experienced, could you give a hint?
I'm an experienced linux/python/c programmer but just leaned c# modding today.
If I try to patch ComputeRawDamageNew everything work as expected.
If I try to patch CalculateStrikeMagnitudeForSwing the game get stuck at loading save and harmony.log gets lots of print out of "PatchSwing".
If I try to patch CalculateStrikeMagnitudeForThrust the game will crash before main menu.
The functions are in TaleWorlds.Core / CombatStatCalculator
C#:
using TaleWorlds.Core;
using TaleWorlds.MountAndBlade;
using HarmonyLib;
namespace ExampleMod
{
public static class MyPatcher
{
public static void DoPatching()
{
var harmony = new Harmony("com.jj.patch");
harmony.PatchAll();
}
}
[HarmonyPatch(typeof(CombatStatCalculator))]
[HarmonyPatch("CalculateStrikeMagnitudeForSwing")]
class PatchSwing
{
static bool Prefix(float swingSpeed, float impactPointAsPercent, float weaponWeight, float weaponLength, float weaponInertia, float weaponCoM, float extraLinearSpeed, ref float __result)
{
FileLog.Log("PatchSwing");
FileLog.Log(swingSpeed.ToString());
FileLog.Log(impactPointAsPercent.ToString());
FileLog.Log(weaponWeight.ToString());
FileLog.Log(weaponLength.ToString());
FileLog.Log(weaponInertia.ToString());
FileLog.Log(weaponCoM.ToString());
FileLog.Log(extraLinearSpeed.ToString());
return true;
}
}
[HarmonyPatch(typeof(CombatStatCalculator))]
[HarmonyPatch("CalculateStrikeMagnitudeForThrust")]
class PatchThrust
{
static bool Prefix(float thrustWeaponSpeed, float weaponWeight, float extraLinearSpeed, bool isThrow)
{
FileLog.Log("PatchThrust");
//FileLog.Log(thrustWeaponSpeed.ToString());
//FileLog.Log(weaponWeight.ToString());
//FileLog.Log(extraLinearSpeed.ToString());
//FileLog.Log(isThrow.ToString());
return true;
}
}
[HarmonyPatch(typeof(CombatStatCalculator))]
[HarmonyPatch("ComputeRawDamageNew")]
class PatchArmor
{
static bool Prefix(DamageTypes damageType, float magnitude, float armorEffectiveness, float absorbedDamageRatio, ref float __result)
{
FileLog.Log("PatchArmor");
FileLog.Log(damageType.ToString());
FileLog.Log(magnitude.ToString());
FileLog.Log(armorEffectiveness.ToString());
FileLog.Log(absorbedDamageRatio.ToString());
return true;
}
}
class MySubModule : MBSubModuleBase
{
protected override void OnSubModuleLoad()
{
MyPatcher.DoPatching();
}
}
}