-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnDamagePatch.cs
More file actions
43 lines (38 loc) · 1.3 KB
/
OnDamagePatch.cs
File metadata and controls
43 lines (38 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Reflection;
using EFT;
using HarmonyLib;
using SPT.Reflection.Patching;
using UnityEngine;
namespace ZSlayerHeadlessTelemetry;
/// <summary>
/// Harmony patch on Player.ApplyDamageInfo to track hits/damage dealt by human players.
/// </summary>
public class OnDamagePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(Player).GetMethod(nameof(Player.ApplyDamageInfo),
BindingFlags.Public | BindingFlags.Instance);
}
[PatchPostfix]
private static void Postfix(Player __instance, DamageInfoStruct damageInfo, EBodyPart bodyPartType)
{
try
{
// Only track damage dealt by human players
var attacker = damageInfo.Player as Player;
if (attacker == null || attacker.IsAI) return;
float distance = 0f;
try
{
distance = Vector3.Distance(attacker.Position, __instance.Position);
}
catch { /* ignore position errors */ }
var attackerId = attacker.ProfileId ?? "";
var victimId = __instance.ProfileId ?? "";
DamageTracker.RecordHit(attackerId, victimId, (int)bodyPartType, damageInfo.Damage, distance);
}
catch { /* never crash the game */ }
}
}