diff --git a/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs b/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs index e6e4b5a..943549a 100644 --- a/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs +++ b/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs @@ -51,6 +51,7 @@ namespace Aki.SinglePlayer new PlayerToggleSoundFixPatch().Enable(); new PluginErrorNotifierPatch().Enable(); new SpawnProcessNegativeValuePatch().Enable(); + new InsuredItemManagerStartPatch().Enable(); } catch (Exception ex) { diff --git a/project/Aki.SinglePlayer/Models/Progression/SaveProfileRequest.cs b/project/Aki.SinglePlayer/Models/Progression/SaveProfileRequest.cs index de70b7c..acf4441 100644 --- a/project/Aki.SinglePlayer/Models/Progression/SaveProfileRequest.cs +++ b/project/Aki.SinglePlayer/Models/Progression/SaveProfileRequest.cs @@ -1,6 +1,8 @@ -using Aki.SinglePlayer.Models.Healing; -using Newtonsoft.Json; +using Newtonsoft.Json; using EFT; +using System.Collections.Generic; +using Aki.SinglePlayer.Models.Healing; +using Aki.SinglePlayer.Models.RaidFix; namespace Aki.SinglePlayer.Models.Progression { @@ -18,6 +20,9 @@ namespace Aki.SinglePlayer.Models.Progression [JsonProperty("health")] public PlayerHealth Health; + [JsonProperty("insurance")] + public List Insurance; + public SaveProfileRequest() { Exit = "left"; diff --git a/project/Aki.SinglePlayer/Models/RaidFix/AkiInsuredItemClass.cs b/project/Aki.SinglePlayer/Models/RaidFix/AkiInsuredItemClass.cs new file mode 100644 index 0000000..6c445b6 --- /dev/null +++ b/project/Aki.SinglePlayer/Models/RaidFix/AkiInsuredItemClass.cs @@ -0,0 +1,10 @@ +namespace Aki.SinglePlayer.Models.RaidFix +{ + public class AkiInsuredItemClass + { + public string id; + public float? durability = null; + public float? maxDurability = null; + public byte? hits = null; + } +} diff --git a/project/Aki.SinglePlayer/Patches/Progression/OfflineSaveProfilePatch.cs b/project/Aki.SinglePlayer/Patches/Progression/OfflineSaveProfilePatch.cs index 50efd9a..79fb0ec 100644 --- a/project/Aki.SinglePlayer/Patches/Progression/OfflineSaveProfilePatch.cs +++ b/project/Aki.SinglePlayer/Patches/Progression/OfflineSaveProfilePatch.cs @@ -59,10 +59,11 @@ namespace Aki.SinglePlayer.Patches.Progression : PatchConstants.BackEndSession.Profile; SaveProfileRequest request = new SaveProfileRequest - { - Exit = result.Value0.ToString().ToLowerInvariant(), - Profile = profile, - Health = Utils.Healing.HealthListener.Instance.CurrentHealth, + { + Exit = result.Value0.ToString().ToLowerInvariant(), + Profile = profile, + Health = Utils.Healing.HealthListener.Instance.CurrentHealth, + Insurance = Utils.Insurance.InsuredItemManager.Instance.GetTrackedItems(), IsPlayerScav = ____raidSettings.IsScav }; diff --git a/project/Aki.SinglePlayer/Patches/RaidFix/InsuredItemManagerStartPatch.cs b/project/Aki.SinglePlayer/Patches/RaidFix/InsuredItemManagerStartPatch.cs new file mode 100644 index 0000000..2df1b2c --- /dev/null +++ b/project/Aki.SinglePlayer/Patches/RaidFix/InsuredItemManagerStartPatch.cs @@ -0,0 +1,21 @@ +using Aki.Reflection.Patching; +using EFT; +using System.Reflection; +using Aki.SinglePlayer.Utils.Insurance; + +namespace Aki.SinglePlayer.Patches.RaidFix +{ + public class InsuredItemManagerStartPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return typeof(GameWorld).GetMethod(nameof(GameWorld.OnGameStarted)); + } + + [PatchPostfix] + public static void PatchPostFix() + { + InsuredItemManager.Instance.Init(); + } + } +} diff --git a/project/Aki.SinglePlayer/Utils/Insurance/InsuredItemManager.cs b/project/Aki.SinglePlayer/Utils/Insurance/InsuredItemManager.cs new file mode 100644 index 0000000..792431a --- /dev/null +++ b/project/Aki.SinglePlayer/Utils/Insurance/InsuredItemManager.cs @@ -0,0 +1,64 @@ +using Aki.SinglePlayer.Models.RaidFix; +using Comfort.Common; +using EFT; +using EFT.InventoryLogic; +using System.Collections.Generic; +using System.Linq; + +namespace Aki.SinglePlayer.Utils.Insurance +{ + public class InsuredItemManager + { + private static InsuredItemManager _instance; + private List items; + + public static InsuredItemManager Instance + { + get + { + if (_instance == null) + { + _instance = new InsuredItemManager(); + } + + return _instance; + } + } + + public void Init() + { + items = Singleton.Instance?.MainPlayer?.Profile?.Inventory?.AllRealPlayerItems.ToList(); + } + + public List GetTrackedItems() + { + var itemsToSend = new List(); + foreach (var item in items) + { + var aki = new AkiInsuredItemClass + { + id = item.Id + }; + + var dura = item.GetItemComponent(); + + if (dura != null) + { + aki.durability = dura.Durability; + aki.maxDurability = dura.MaxDurability; + } + + var faceshield = item.GetItemComponent(); + + if (faceshield != null) + { + aki.hits = faceshield.Hits; + } + + itemsToSend.Add(aki); + } + + return itemsToSend; + } + } +}