From 37ae603982e912a35a7d179c3443707494ce909c Mon Sep 17 00:00:00 2001 From: Kaeno Date: Thu, 21 Mar 2024 11:04:53 +0000 Subject: [PATCH] Start of adding missing stats --- .../Patches/Stats/AmmoUsedPatch.cs | 39 +++++++++++++++++++ .../Patches/Stats/ArmorDamagePatch.cs | 34 ++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 project/Aki.Debugging/Patches/Stats/AmmoUsedPatch.cs create mode 100644 project/Aki.Debugging/Patches/Stats/ArmorDamagePatch.cs diff --git a/project/Aki.Debugging/Patches/Stats/AmmoUsedPatch.cs b/project/Aki.Debugging/Patches/Stats/AmmoUsedPatch.cs new file mode 100644 index 0000000..3e3b34c --- /dev/null +++ b/project/Aki.Debugging/Patches/Stats/AmmoUsedPatch.cs @@ -0,0 +1,39 @@ +using Aki.Reflection.Patching; +using EFT.HealthSystem; +using EFT; +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Reflection; +using EFT.InventoryLogic; +using Comfort.Common; +using EFT.UI; +using EFT.Ballistics; +using static EFT.Player.FirearmController; + + +namespace Aki.Debugging.Patches.Stats +{ + public class AmmoUsedPatch : ModulePatch + { + private static Player player; + + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(GameWorld), nameof(GameWorld.OnGameStarted)); + } + + [PatchPostfix] + private static void PatchPostfix() + { + player = Singleton.Instance.MainPlayer; + var firearmsController = player.HandsController as Player.FirearmController; + firearmsController.OnShot += Hook; + } + + private static void Hook() + { + player.Profile.EftStats.SessionCounters.AddLong(1L, GClass2200.AmmoUsed); + } + } +} diff --git a/project/Aki.Debugging/Patches/Stats/ArmorDamagePatch.cs b/project/Aki.Debugging/Patches/Stats/ArmorDamagePatch.cs new file mode 100644 index 0000000..6e5d08a --- /dev/null +++ b/project/Aki.Debugging/Patches/Stats/ArmorDamagePatch.cs @@ -0,0 +1,34 @@ +using Aki.Reflection.Patching; +using EFT; +using EFT.InventoryLogic; +using EFT.UI; +using HarmonyLib; +using Newtonsoft.Json; +using System; +using System.Reflection; + +namespace Aki.Debugging.Patches.Stats +{ + public class ArmorDamagePatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(Player), nameof(Player.ApplyDamageInfo)); + } + + [PatchPostfix] + private static void PatchPostfix(DamageInfo damageInfo) + { + if (!damageInfo.Player.iPlayer.IsYourPlayer) + { + return; + } + + if (damageInfo.Weapon is Weapon weapon && weapon.Chambers[0].ContainedItem is BulletClass bullet) + { + float newDamage = (float)Math.Round(bullet.Damage - damageInfo.Damage); + damageInfo.Player.iPlayer.Profile.EftStats.SessionCounters.AddFloat(newDamage, GClass2200.CauseArmorDamage); + } + } + } +}