Skip to content

Commit

Permalink
Merge pull request #199 from JimWails/add-extra-stat-data
Browse files Browse the repository at this point in the history
Add extra stat data
  • Loading branch information
mihaicm93 authored Mar 28, 2024
2 parents b60930a + b00ab98 commit e33e007
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Source/AkiSupport/Singleplayer/AkiSingleplayerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public void Awake()
new LighthouseBridgePatch().Enable();
new LighthouseTransmitterPatch().Enable();
new LabsKeycardRemovalPatch().Enable();
new AmmoUsedCounterPatch().Enable();
new ArmorDamageCounterPatch().Enable();

// Scav Patches
new ScavExperienceGainPatch().Enable();
Expand All @@ -49,6 +51,7 @@ public void Awake()
new ScavEncyclopediaPatch().Enable();
new ScavItemCheckmarkPatch().Enable();
new IsHostileToEverybodyPatch().Enable();
new ScavRepAdjustmentPatch().Enable();

// Unused Patches
//new OfflineSaveProfilePatch().Enable();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using EFT;
using HarmonyLib;
using System.Reflection;

namespace StayInTarkov.AkiSupport.Singleplayer.Patches.MainMenu
{
/// <summary>
/// Created by: SPT-Aki team
/// Link: https://dev.sp-tarkov.com/SPT-AKI/Modules/src/branch/3.8.0/project/Aki.SinglePlayer/Patches/MainMenu/AmmoUsedCounterPatch.cs
/// Modified by: KWJimWails. Modified to use SIT ModulePatch
/// </summary>
public class AmmoUsedCounterPatch : ModulePatch
{
private static Player player;

Check warning on line 14 in Source/AkiSupport/Singleplayer/Patches/MainMenu/AmmoUsedCounterPatch.cs

View workflow job for this annotation

GitHub Actions / build (Release)

The field 'AmmoUsedCounterPatch.player' is never used

protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(Player), nameof(Player.OnMakingShot));
}

[PatchPostfix]
private static void PatchPostfix(Player __instance)
{
if (__instance.IsYourPlayer)
{
__instance.Profile.EftStats.SessionCounters.AddLong(1L, ASessionCounterManager.AmmoUsed);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Comfort.Common;
using EFT;
using EFT.InventoryLogic;
using HarmonyLib;
using System;
using System.Reflection;

namespace StayInTarkov.AkiSupport.Singleplayer.Patches.MainMenu
{
/// <summary>
/// Created by: SPT-Aki team
/// Link: https://dev.sp-tarkov.com/SPT-AKI/Modules/src/branch/3.8.0/project/Aki.SinglePlayer/Patches/MainMenu/ArmorDamageCounterPatch.cs
/// Modified by: KWJimWails. Modified to use SIT ModulePatch
/// </summary>
public class ArmorDamageCounterPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(Player), nameof(Player.ApplyDamageInfo));
}

[PatchPostfix]
private static void PatchPostfix(DamageInfo damageInfo)
{
if (damageInfo.SourceId == null)
{
return;
}

if (damageInfo.Player == null)
{
return;
}

if (damageInfo.Player.iPlayer == null)
{
return;
}

if (!damageInfo.Player.iPlayer.IsYourPlayer)
{
return;
}

if (damageInfo.Weapon is Weapon)
{
if (!Singleton<ItemFactory>.Instance.ItemTemplates.TryGetValue(damageInfo.SourceId, out var template))
{
return;
}

if (template is AmmoTemplate bulletTemplate)
{
float absorbedDamage = (float)Math.Round(bulletTemplate.Damage - damageInfo.Damage);
damageInfo.Player.iPlayer.Profile.EftStats.SessionCounters.AddFloat(absorbedDamage, ASessionCounterManager.CauseArmorDamage);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Comfort.Common;
using EFT;
using HarmonyLib;
using StayInTarkov;
using System;
using System.Reflection;

namespace StayInTarkov.AkiSupport.Singleplayer.Patches.ScavMode
{
/// <summary>
/// Created by: SPT-Aki team
/// Link: https://dev.sp-tarkov.com/SPT-AKI/Modules/src/branch/3.8.0/project/Aki.SinglePlayer/Patches/ScavMode/ScavRepAdjustmentPatch.cs
/// Modified by: KWJimWails. Modified to use SIT ModulePatch and Class Fix
/// </summary>
public class ScavRepAdjustmentPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(AStatisticsManagerForPlayer), nameof(AStatisticsManagerForPlayer.OnEnemyKill));
}

[PatchPrefix]
private static void PatchPrefix(string playerProfileId, out Tuple<Player, bool> __state)
{
var player = Singleton<GameWorld>.Instance.MainPlayer;
__state = new Tuple<Player, bool>(null, false);

if (player.Profile.Side != EPlayerSide.Savage)
{
return;
}

if (Singleton<GameWorld>.Instance.GetEverExistedPlayerByID(playerProfileId) is Player killedPlayer)
{
__state = new Tuple<Player, bool>(killedPlayer, killedPlayer.AIData.IsAI);
killedPlayer.AIData.IsAI = false;
player.Loyalty.method_1(killedPlayer);
}
}
[PatchPostfix]
private static void PatchPostfix(Tuple<Player, bool> __state)
{
if(__state.Item1 != null)
{
__state.Item1.AIData.IsAI = __state.Item2;
}
}
}
}
9 changes: 9 additions & 0 deletions Source/Coop/Components/CoopGameComponents/SITGameComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using StayInTarkov.Coop.NetworkPacket.Raid;
using Diz.Jobs;
using System.Net.NetworkInformation;
using EFT.Counters;

namespace StayInTarkov.Coop.Components.CoopGameComponents
{
Expand Down Expand Up @@ -429,6 +430,14 @@ private IEnumerator EverySecondCoroutine()
if (!ExtractedProfilesSent.Contains(profileId))
{
ExtractedProfilesSent.Add(profileId);
if (player.Profile.Side == EPlayerSide.Savage)
{
player.Profile.EftStats.SessionCounters.AddDouble(0.01,
[
CounterTag.FenceStanding,
EFenceStandingSource.ExitStanding
]);
}
AkiBackendCommunicationCoop.PostLocalPlayerData(player
, new Dictionary<string, object>() { { "m", "Extraction" }, { "Extracted", true } }
);
Expand Down
16 changes: 15 additions & 1 deletion Source/Coop/Players/CoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using EFT.InventoryLogic;
using Newtonsoft.Json.Linq;
using RootMotion.FinalIK;
using StayInTarkov.AkiSupport.Singleplayer.Utils.InRaid;
using StayInTarkov.Coop.Components.CoopGameComponents;
using StayInTarkov.Coop.Controllers;
using StayInTarkov.Coop.Controllers.CoopInventory;
Expand Down Expand Up @@ -436,7 +437,20 @@ public override void OnDead(EDamageType damageType)
// Paulov: Unknown / Unable to replicate issue where some User's feed would cause a crash
//if(PluginConfigSettings.Instance.CoopSettings.SETTING_ShowFeed)
// DisplayMessageNotifications.DisplayMessageNotification(attacker != null ? $"\"{GeneratePlayerNameWithSide(attacker)}\" killed \"{GeneratePlayerNameWithSide(victim)}\"" : $"\"{GeneratePlayerNameWithSide(victim)}\" has died because of \"{("DamageType_" + damageType.ToString()).Localized()}\"");


// Make it only working in Scav Raid
if (RaidChangesUtil.IsScavRaid)
{
if (victim.Profile.Side == EPlayerSide.Savage)
{
if (attacker != null && attacker.Profile.Side != EPlayerSide.Savage)
{
LastAggressor.Loyalty.method_2(victim);
LastAggressor.Loyalty.method_4(victim.Profile.Info.Settings);
}
}
}

using KillPacket killPacket = new KillPacket(ProfileId, damageType);
GameClient.SendData(killPacket.Serialize());
}
Expand Down

0 comments on commit e33e007

Please sign in to comment.