0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-12 22:10:45 -05:00

replace some GameObject.Find methods for better performance

This commit is contained in:
SamSWAT 2023-03-08 21:56:02 +03:00
parent af55bbb4ea
commit 355362a19e
2 changed files with 20 additions and 23 deletions

View File

@ -5,9 +5,8 @@ using Aki.Custom.Models;
using EFT.UI; using EFT.UI;
using EFT.UI.Matchmaker; using EFT.UI.Matchmaker;
using System.Reflection; using System.Reflection;
using UnityEngine;
using EFT; using EFT;
using static EFT.UI.Matchmaker.MatchmakerOfflineRaidScreen; using HarmonyLib;
namespace Aki.Custom.Patches namespace Aki.Custom.Patches
{ {
@ -25,9 +24,9 @@ namespace Aki.Custom.Patches
} }
[PatchPrefix] [PatchPrefix]
private static void PatchPrefix(GClass2769 controller, UpdatableToggle ____offlineModeToggle) private static void PatchPrefix(object controller, UpdatableToggle ____offlineModeToggle)
{ {
var raidSettings = controller.RaidSettings; var raidSettings = Traverse.Create(controller).Field<RaidSettings>("RaidSettings").Value;
raidSettings.RaidMode = ERaidMode.Local; raidSettings.RaidMode = ERaidMode.Local;
raidSettings.BotSettings.IsEnabled = true; raidSettings.BotSettings.IsEnabled = true;
@ -40,30 +39,30 @@ namespace Aki.Custom.Patches
var settings = Json.Deserialize<DefaultRaidSettings>(json); 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 // TODO: Not all settings are used and they also don't cover all the new settings that are available client-side
if (settings != null) if (settings == null)
{ {
raidSettings.BotSettings.BotAmount = settings.AiAmount; return;
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.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;
} }
[PatchPostfix] [PatchPostfix]
private static void PatchPostfix() private static void PatchPostfix(MatchmakerOfflineRaidScreen __instance, UiElementBlocker ____onlineBlocker)
{ {
// Hide "no progression save" panel // Hide "no progression save" panel
var offlineRaidScreenContent = GameObject.Find("Matchmaker Offline Raid Screen").transform.Find("Content").transform; var warningPanel = __instance.transform.Find("Content/WarningPanelHorLayout").gameObject;
var warningPanel = offlineRaidScreenContent.Find("WarningPanelHorLayout"); warningPanel.SetActive(false);
warningPanel.gameObject.SetActive(false); var spacer = __instance.transform.Find("Content/Space (1)").gameObject;
var spacer = offlineRaidScreenContent.Find("Space (1)"); spacer.SetActive(false);
spacer.gameObject.SetActive(false);
// Disable "Enable practice mode for this raid" toggle // Disable "Enable practice mode for this raid" toggle
var practiceModeComponent = GameObject.Find("SoloModeCheckmarkBlocker").GetComponent<UiElementBlocker>(); ____onlineBlocker.SetBlock(true, "Raids in SPT are always Offline raids. Don't worry - your progress will be saved!");
practiceModeComponent.SetBlock(true, "Raids in SPT are always Offline raids. Don't worry - your progress will be saved!");
} }
} }
} }

View File

@ -2,7 +2,6 @@
using Aki.Reflection.Patching; using Aki.Reflection.Patching;
using EFT.UI; using EFT.UI;
using EFT.UI.Matchmaker; using EFT.UI.Matchmaker;
using UnityEngine;
namespace Aki.Custom.Patches namespace Aki.Custom.Patches
{ {
@ -20,11 +19,10 @@ namespace Aki.Custom.Patches
} }
[PatchPostfix] [PatchPostfix]
private static void PatchPostfix() private static void PatchPostfix(UiElementBlocker ____coopModeBlocker)
{ {
// Always disable the Coop Mode checkbox // Always disable the Coop Mode checkbox
var coopModeComponent = GameObject.Find("CoopModeCheckmarkBlocker").GetComponent<UiElementBlocker>(); ____coopModeBlocker.SetBlock(true, "SPT will never support Co-op");
coopModeComponent.SetBlock(true, "SPT will never support Co-op");
} }
} }
} }