0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00

Changed the way we count shot ammo. Fixed NRE when player is null when trying to calculate armor damage

This commit is contained in:
Kaeno 2024-03-22 18:45:49 +00:00
parent c29589768d
commit a77fc7f036
2 changed files with 7 additions and 12 deletions

View File

@ -2,7 +2,6 @@
using EFT; using EFT;
using HarmonyLib; using HarmonyLib;
using System.Reflection; using System.Reflection;
using Comfort.Common;
namespace Aki.SinglePlayer.Patches.MainMenu namespace Aki.SinglePlayer.Patches.MainMenu
{ {
@ -12,20 +11,16 @@ namespace Aki.SinglePlayer.Patches.MainMenu
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
{ {
return AccessTools.Method(typeof(GameWorld), nameof(GameWorld.OnGameStarted)); return AccessTools.Method(typeof(Player), nameof(Player.OnMakingShot));
} }
[PatchPostfix] [PatchPostfix]
private static void PatchPostfix() private static void PatchPostfix(Player __instance)
{ {
player = Singleton<GameWorld>.Instance.MainPlayer; if (__instance.IsYourPlayer)
var firearmsController = player.HandsController as Player.FirearmController; {
firearmsController.OnShot += Hook; __instance.Profile.EftStats.SessionCounters.AddLong(1L, SessionCounterTypesAbstractClass.AmmoUsed);
} }
private static void Hook()
{
player.Profile.EftStats.SessionCounters.AddLong(1L, SessionCounterTypesAbstractClass.AmmoUsed);
} }
} }
} }

View File

@ -17,7 +17,7 @@ namespace Aki.SinglePlayer.Patches.MainMenu
[PatchPostfix] [PatchPostfix]
private static void PatchPostfix(DamageInfo damageInfo) private static void PatchPostfix(DamageInfo damageInfo)
{ {
if (!damageInfo.Player.iPlayer.IsYourPlayer) if (damageInfo.Player == null || damageInfo.Player.iPlayer == null || !damageInfo.Player.iPlayer.IsYourPlayer)
{ {
return; return;
} }