0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:10:44 -05:00

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: SPT-AKI/Modules#113
Co-authored-by: kiobu <kiobu@sdf.org>
Co-committed-by: kiobu <kiobu@sdf.org>
This commit is contained in:
kiobu 2024-04-28 08:17:13 +00:00 committed by chomp
parent 2abc1ab0ce
commit cc2377bf72
7 changed files with 73 additions and 33 deletions

View File

@ -77,6 +77,7 @@ namespace Aki.Custom
new CultistAmuletRemovalPatch().Enable(); new CultistAmuletRemovalPatch().Enable();
new HalloweenExtractPatch().Enable(); new HalloweenExtractPatch().Enable();
new ClampRagdollPatch().Enable(); new ClampRagdollPatch().Enable();
new DisablePvEPatch().Enable();
HookObject.AddOrGetComponent<MenuNotificationManager>(); HookObject.AddOrGetComponent<MenuNotificationManager>();
} }

View File

@ -1,24 +1,43 @@
using System.Runtime.Serialization; using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Aki.Custom.Models namespace Aki.Custom.Models
{ {
[DataContract] [Serializable]
public struct DifficultyInfo public struct DifficultyInfo
{ {
[DataMember(Name = "role")] public Dictionary<string, object> this[string key]
public string Role;
[DataMember(Name = "difficulty")]
public string Difficulty;
[DataMember(Name = "data")]
public string Data;
public DifficultyInfo(string role, string difficulty, string data)
{ {
Role = role; get
Difficulty = difficulty; {
Data = data; 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<string, object> easy;
[JsonProperty("hard")]
public Dictionary<string, object> hard;
[JsonProperty("impossible")]
public Dictionary<string, object> impossible;
[JsonProperty("normal")]
public Dictionary<string, object> normal;
}
} }

View File

@ -20,8 +20,8 @@ namespace Aki.Custom.Patches
[PatchPrefix] [PatchPrefix]
private static bool PatchPrefix(ref string __result) private static bool PatchPrefix(ref string __result)
{ {
// core difficulty is requested before the others // fetch all bot difficulties to be used in BotDifficultyPatch
// so update the others now! // this is called here since core difficulties are fetched before bot-specific difficulties are
DifficultyManager.Update(); DifficultyManager.Update();
// update core difficulty // update core difficulty

View File

@ -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<HoverTooltipArea>().Where(o => o.name == "Locked").Single().SetMessageText("<color=#51c6db>SPT-AKI</color> is already PvE.");
return false;
}
}
}

View File

@ -8,11 +8,11 @@ namespace Aki.Custom.Utils
{ {
public static class DifficultyManager public static class DifficultyManager
{ {
public static List<DifficultyInfo> Difficulties { get; private set; } public static Dictionary<string, DifficultyInfo> Difficulties { get; private set; }
static DifficultyManager() static DifficultyManager()
{ {
Difficulties = new List<DifficultyInfo>(); Difficulties = new Dictionary<string, DifficultyInfo>();
} }
public static void Update() public static void Update()
@ -22,21 +22,13 @@ namespace Aki.Custom.Utils
// get new difficulties // get new difficulties
var json = RequestHandler.GetJson("/singleplayer/settings/bot/difficulties"); var json = RequestHandler.GetJson("/singleplayer/settings/bot/difficulties");
Difficulties = Json.Deserialize<List<DifficultyInfo>>(json); Difficulties = Json.Deserialize<Dictionary<string, DifficultyInfo>>(json);
} }
public static string Get(BotDifficulty botDifficulty, WildSpawnType role) public static string Get(BotDifficulty botDifficulty, WildSpawnType role)
{ {
foreach (var entry in Difficulties) var difficultyMatrix = Difficulties[role.ToString().ToLower()];
{ return Json.Serialize(difficultyMatrix[botDifficulty.ToString().ToLower()]);
if (botDifficulty.ToString().ToLower() == entry.Difficulty
&& role.ToString().ToLower() == entry.Role)
{
return entry.Data;
}
}
return string.Empty;
} }
} }
} }

View File

@ -11,8 +11,8 @@ namespace Aki.PrePatch
{ {
public static IEnumerable<string> TargetDLLs { get; } = new[] { "Assembly-CSharp.dll" }; public static IEnumerable<string> TargetDLLs { get; } = new[] { "Assembly-CSharp.dll" };
public static int sptUsecValue = 49; public static int sptUsecValue = 51;
public static int sptBearValue = 50; public static int sptBearValue = 52;
private static string _sptPluginFolder = "plugins/spt"; private static string _sptPluginFolder = "plugins/spt";

View File

@ -46,7 +46,7 @@ namespace Aki.SinglePlayer.Patches.ScavMode
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
{ {
// `MatchMakerSelectionLocationScreen` OnShowNextScreen // `MatchMakerSelectionLocationScreen` OnShowNextScreen
return AccessTools.Method(typeof(MainMenuController), nameof(MainMenuController.method_71)); return AccessTools.Method(typeof(MainMenuController), nameof(MainMenuController.method_70));
} }
[PatchTranspiler] [PatchTranspiler]