From 5b959e3d62885f831f95e642ea0e5cbb32aa671d Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Sun, 8 Dec 2024 00:45:23 +0100 Subject: [PATCH] Fix kills not tracking - Weapon was null, causing early return Fixes #207 --- Fika.Core/Coop/Players/CoopPlayer.cs | 30 ++++---------------- Fika.Core/Coop/Players/ObservedCoopPlayer.cs | 24 ++++++++++++++++ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/Fika.Core/Coop/Players/CoopPlayer.cs b/Fika.Core/Coop/Players/CoopPlayer.cs index fa7e49a6..d02f37e9 100644 --- a/Fika.Core/Coop/Players/CoopPlayer.cs +++ b/Fika.Core/Coop/Players/CoopPlayer.cs @@ -432,6 +432,10 @@ public void HandleTeammateKill(ref DamageInfoStruct damage, EBodyPart bodyPart, return; } +#if DEBUG + FikaPlugin.Instance.FikaLogger.LogWarning($"HandleTeammateKill: Weapon {(damage.Weapon != null ? damage.Weapon.Name.Localized() : "None")}"); +#endif + if (role != WildSpawnType.pmcBEAR) { if (role == WildSpawnType.pmcUSEC) @@ -813,37 +817,13 @@ public override void OnDead(EDamageType damageType) { StartCoroutine(LocalPlayerDied()); } - } - - private void FindKillerWeapon() - { - GStruct448 itemResult = FindItemById(lastWeaponId, false, false); - if (!itemResult.Succeeded) - { - foreach (ThrowWeapItemClass grenadeClass in Singleton.Instance.CoopHandler.LocalGameInstance.ThrownGrenades) - { - if (grenadeClass.Id == lastWeaponId) - { - LastDamageInfo.Weapon = grenadeClass; - break; - } - } - return; - } - - LastDamageInfo.Weapon = itemResult.Value; - } + } /// /// TODO: Refactor... BSG code makes this difficult /// private void GenerateDogtagDetails() { - if (LastDamageInfo.Weapon is null && !string.IsNullOrEmpty(lastWeaponId)) - { - FindKillerWeapon(); - } - string accountId = AccountId; string profileId = ProfileId; string nickname = Profile.Nickname; diff --git a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs index 2ce268bd..7004b8b4 100644 --- a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs +++ b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs @@ -1548,6 +1548,30 @@ public void SetAggressorData(string killerId, EBodyPart bodyPart, string weaponI } LastBodyPart = bodyPart; lastWeaponId = weaponId; + + if (LastDamageInfo.Weapon is null && !string.IsNullOrEmpty(lastWeaponId)) + { + FindKillerWeapon(); + } + } + + private void FindKillerWeapon() + { + GStruct448 itemResult = FindItemById(lastWeaponId, false, false); + if (!itemResult.Succeeded) + { + foreach (ThrowWeapItemClass grenadeClass in Singleton.Instance.CoopHandler.LocalGameInstance.ThrownGrenades) + { + if (grenadeClass.Id == lastWeaponId) + { + LastDamageInfo.Weapon = grenadeClass; + break; + } + } + return; + } + + LastDamageInfo.Weapon = itemResult.Value; } private class RemoveHandsControllerHandler(ObservedCoopPlayer coopPlayer, Callback callback)