From cc2377bf72c7b5c0310b3d666f91128e16b3bba5 Mon Sep 17 00:00:00 2001 From: kiobu Date: Sun, 28 Apr 2024 08:17:13 +0000 Subject: [PATCH] fix: difficulties response parsing (!113) fixed bot difficulties model to match server response for `/singleplayer/settings/bot/difficulties` also bumps up the sptBear and sptUsec enums so they don't collide with new pmcUSEC and pmcBEAR Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/113 Co-authored-by: kiobu Co-committed-by: kiobu --- project/Aki.Custom/AkiCustomPlugin.cs | 1 + project/Aki.Custom/Models/DifficultyInfo.cs | 49 +++++++++++++------ .../Aki.Custom/Patches/CoreDifficultyPatch.cs | 4 +- project/Aki.Custom/Patches/DisablePvEPatch.cs | 28 +++++++++++ project/Aki.Custom/Utils/DifficultyManager.cs | 18 ++----- project/Aki.PrePatch/AkiBotsPrePatcher.cs | 4 +- .../ScavMode/LoadOfflineRaidScreenPatch.cs | 2 +- 7 files changed, 73 insertions(+), 33 deletions(-) create mode 100644 project/Aki.Custom/Patches/DisablePvEPatch.cs diff --git a/project/Aki.Custom/AkiCustomPlugin.cs b/project/Aki.Custom/AkiCustomPlugin.cs index 326122b..e665f18 100644 --- a/project/Aki.Custom/AkiCustomPlugin.cs +++ b/project/Aki.Custom/AkiCustomPlugin.cs @@ -77,6 +77,7 @@ namespace Aki.Custom new CultistAmuletRemovalPatch().Enable(); new HalloweenExtractPatch().Enable(); new ClampRagdollPatch().Enable(); + new DisablePvEPatch().Enable(); HookObject.AddOrGetComponent(); } diff --git a/project/Aki.Custom/Models/DifficultyInfo.cs b/project/Aki.Custom/Models/DifficultyInfo.cs index 7531773..721111a 100644 --- a/project/Aki.Custom/Models/DifficultyInfo.cs +++ b/project/Aki.Custom/Models/DifficultyInfo.cs @@ -1,24 +1,43 @@ -using System.Runtime.Serialization; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Reflection; namespace Aki.Custom.Models { - [DataContract] + [Serializable] public struct DifficultyInfo { - [DataMember(Name = "role")] - public string Role; - - [DataMember(Name = "difficulty")] - public string Difficulty; - - [DataMember(Name = "data")] - public string Data; - - public DifficultyInfo(string role, string difficulty, string data) + public Dictionary this[string key] { - Role = role; - Difficulty = difficulty; - Data = data; + get + { + switch (key) + { + case "easy": + return easy; + case "hard": + return hard; + case "impossible": + return impossible; + case "normal": + return normal; + default: + throw new ArgumentException($"Difficulty '{key}' does not exist in DifficultyInfo."); + } + } } + + [JsonProperty("easy")] + public Dictionary easy; + + [JsonProperty("hard")] + public Dictionary hard; + + [JsonProperty("impossible")] + public Dictionary impossible; + + [JsonProperty("normal")] + public Dictionary normal; } } \ No newline at end of file diff --git a/project/Aki.Custom/Patches/CoreDifficultyPatch.cs b/project/Aki.Custom/Patches/CoreDifficultyPatch.cs index 26c8383..6c243c4 100644 --- a/project/Aki.Custom/Patches/CoreDifficultyPatch.cs +++ b/project/Aki.Custom/Patches/CoreDifficultyPatch.cs @@ -20,8 +20,8 @@ namespace Aki.Custom.Patches [PatchPrefix] private static bool PatchPrefix(ref string __result) { - // core difficulty is requested before the others - // so update the others now! + // fetch all bot difficulties to be used in BotDifficultyPatch + // this is called here since core difficulties are fetched before bot-specific difficulties are DifficultyManager.Update(); // update core difficulty diff --git a/project/Aki.Custom/Patches/DisablePvEPatch.cs b/project/Aki.Custom/Patches/DisablePvEPatch.cs new file mode 100644 index 0000000..b5ece0f --- /dev/null +++ b/project/Aki.Custom/Patches/DisablePvEPatch.cs @@ -0,0 +1,28 @@ +using Aki.Common.Http; +using Aki.Reflection.Patching; +using System.Reflection; +using EFT; +using EFT.UI; +using HarmonyLib; +using UnityEngine; +using TMPro; +using System.Linq; + +namespace Aki.Custom.Patches +{ + public class DisablePvEPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(ChangeGameModeButton), nameof(ChangeGameModeButton.Show)); + } + + [PatchPrefix] + private static bool PatchPrefix(ESessionMode sessionMode, Profile profile, ref GameObject ____notAvailableState) + { + ____notAvailableState.SetActive(true); + Object.FindObjectsOfType().Where(o => o.name == "Locked").Single().SetMessageText("SPT-AKI is already PvE."); + return false; + } + } +} diff --git a/project/Aki.Custom/Utils/DifficultyManager.cs b/project/Aki.Custom/Utils/DifficultyManager.cs index b9de3d9..e7a3349 100644 --- a/project/Aki.Custom/Utils/DifficultyManager.cs +++ b/project/Aki.Custom/Utils/DifficultyManager.cs @@ -8,11 +8,11 @@ namespace Aki.Custom.Utils { public static class DifficultyManager { - public static List Difficulties { get; private set; } + public static Dictionary Difficulties { get; private set; } static DifficultyManager() { - Difficulties = new List(); + Difficulties = new Dictionary(); } public static void Update() @@ -22,21 +22,13 @@ namespace Aki.Custom.Utils // get new difficulties var json = RequestHandler.GetJson("/singleplayer/settings/bot/difficulties"); - Difficulties = Json.Deserialize>(json); + Difficulties = Json.Deserialize>(json); } public static string Get(BotDifficulty botDifficulty, WildSpawnType role) { - foreach (var entry in Difficulties) - { - if (botDifficulty.ToString().ToLower() == entry.Difficulty - && role.ToString().ToLower() == entry.Role) - { - return entry.Data; - } - } - - return string.Empty; + var difficultyMatrix = Difficulties[role.ToString().ToLower()]; + return Json.Serialize(difficultyMatrix[botDifficulty.ToString().ToLower()]); } } } diff --git a/project/Aki.PrePatch/AkiBotsPrePatcher.cs b/project/Aki.PrePatch/AkiBotsPrePatcher.cs index 29ed39e..7f9d33c 100644 --- a/project/Aki.PrePatch/AkiBotsPrePatcher.cs +++ b/project/Aki.PrePatch/AkiBotsPrePatcher.cs @@ -11,8 +11,8 @@ namespace Aki.PrePatch { public static IEnumerable TargetDLLs { get; } = new[] { "Assembly-CSharp.dll" }; - public static int sptUsecValue = 49; - public static int sptBearValue = 50; + public static int sptUsecValue = 51; + public static int sptBearValue = 52; private static string _sptPluginFolder = "plugins/spt"; diff --git a/project/Aki.SinglePlayer/Patches/ScavMode/LoadOfflineRaidScreenPatch.cs b/project/Aki.SinglePlayer/Patches/ScavMode/LoadOfflineRaidScreenPatch.cs index 6d4b8d1..ec0eb52 100644 --- a/project/Aki.SinglePlayer/Patches/ScavMode/LoadOfflineRaidScreenPatch.cs +++ b/project/Aki.SinglePlayer/Patches/ScavMode/LoadOfflineRaidScreenPatch.cs @@ -46,7 +46,7 @@ namespace Aki.SinglePlayer.Patches.ScavMode protected override MethodBase GetTargetMethod() { // `MatchMakerSelectionLocationScreen` OnShowNextScreen - return AccessTools.Method(typeof(MainMenuController), nameof(MainMenuController.method_71)); + return AccessTools.Method(typeof(MainMenuController), nameof(MainMenuController.method_70)); } [PatchTranspiler]