0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 08:50:43 -05:00
modules/project/SPT.Custom/Patches/OfflineRaidMenuPatch.cs
2024-05-21 19:10:17 +01:00

66 lines
2.6 KiB
C#

using SPT.Common.Http;
using SPT.Common.Utils;
using SPT.Reflection.Patching;
using SPT.Custom.Models;
using EFT.UI;
using EFT.UI.Matchmaker;
using System.Reflection;
using EFT;
using HarmonyLib;
using SPT.Reflection.Utils;
namespace SPT.Custom.Patches
{
public class OfflineRaidMenuPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.GetDeclaredMethods(typeof(MatchmakerOfflineRaidScreen))
.SingleCustom(m => m.Name == nameof(MatchmakerOfflineRaidScreen.Show) && m.GetParameters().Length == 1);
}
[PatchPrefix]
private static void PatchPrefix(object controller, UpdatableToggle ____offlineModeToggle)
{
var raidSettings = Traverse.Create(controller).Field<RaidSettings>("RaidSettings").Value;
raidSettings.RaidMode = ERaidMode.Local;
// Default checkbox to be ticked
____offlineModeToggle.isOn = true;
// get settings from server
var json = RequestHandler.GetJson("/singleplayer/settings/raid/menu");
var settings = Json.Deserialize<DefaultRaidSettings>(json);
// TODO: Not all settings are used and they also don't cover all the new settings that are available client-side
if (settings == null)
{
return;
}
raidSettings.BotSettings.BotAmount = settings.AiAmount;
raidSettings.WavesSettings.BotAmount = settings.AiAmount;
raidSettings.WavesSettings.BotDifficulty = settings.AiDifficulty;
raidSettings.WavesSettings.IsBosses = settings.BossEnabled;
raidSettings.BotSettings.IsScavWars = false;
raidSettings.WavesSettings.IsTaggedAndCursed = settings.TaggedAndCursed;
raidSettings.TimeAndWeatherSettings.IsRandomWeather = settings.RandomWeather;
raidSettings.TimeAndWeatherSettings.IsRandomTime = settings.RandomTime;
}
[PatchPostfix]
private static void PatchPostfix(MatchmakerOfflineRaidScreen __instance, UiElementBlocker ____onlineBlocker)
{
// Hide "no progression save" panel
var warningPanel = __instance.transform.Find("Content/WarningPanelHorLayout").gameObject;
warningPanel.SetActive(false);
var spacer = __instance.transform.Find("Content/Space (1)").gameObject;
spacer.SetActive(false);
// Disable "Enable practice mode for this raid" toggle
____onlineBlocker.SetBlock(true, "Raids in SPT are always Offline raids. Don't worry - your progress will be saved!");
}
}
}