From 355362a19e54b03402b19f92458cc452f48c417c Mon Sep 17 00:00:00 2001 From: SamSWAT Date: Wed, 8 Mar 2023 21:56:02 +0300 Subject: [PATCH] replace some GameObject.Find methods for better performance --- .../Patches/OfflineRaidMenuPatch.cs | 37 +++++++++---------- .../Patches/OfflineRaidSettingsMenuPatch.cs | 6 +-- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/project/Aki.Custom/Patches/OfflineRaidMenuPatch.cs b/project/Aki.Custom/Patches/OfflineRaidMenuPatch.cs index 9346db7..80b5cd0 100644 --- a/project/Aki.Custom/Patches/OfflineRaidMenuPatch.cs +++ b/project/Aki.Custom/Patches/OfflineRaidMenuPatch.cs @@ -5,9 +5,8 @@ using Aki.Custom.Models; using EFT.UI; using EFT.UI.Matchmaker; using System.Reflection; -using UnityEngine; using EFT; -using static EFT.UI.Matchmaker.MatchmakerOfflineRaidScreen; +using HarmonyLib; namespace Aki.Custom.Patches { @@ -25,9 +24,9 @@ namespace Aki.Custom.Patches } [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").Value; raidSettings.RaidMode = ERaidMode.Local; raidSettings.BotSettings.IsEnabled = true; @@ -40,30 +39,30 @@ namespace Aki.Custom.Patches var settings = Json.Deserialize(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) + if (settings == null) { - 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; + 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; } [PatchPostfix] - private static void PatchPostfix() + private static void PatchPostfix(MatchmakerOfflineRaidScreen __instance, UiElementBlocker ____onlineBlocker) { // Hide "no progression save" panel - var offlineRaidScreenContent = GameObject.Find("Matchmaker Offline Raid Screen").transform.Find("Content").transform; - var warningPanel = offlineRaidScreenContent.Find("WarningPanelHorLayout"); - warningPanel.gameObject.SetActive(false); - var spacer = offlineRaidScreenContent.Find("Space (1)"); - spacer.gameObject.SetActive(false); + 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 - var practiceModeComponent = GameObject.Find("SoloModeCheckmarkBlocker").GetComponent(); - practiceModeComponent.SetBlock(true, "Raids in SPT are always Offline raids. Don't worry - your progress will be saved!"); + ____onlineBlocker.SetBlock(true, "Raids in SPT are always Offline raids. Don't worry - your progress will be saved!"); } } } diff --git a/project/Aki.Custom/Patches/OfflineRaidSettingsMenuPatch.cs b/project/Aki.Custom/Patches/OfflineRaidSettingsMenuPatch.cs index a27f76c..eb8af81 100644 --- a/project/Aki.Custom/Patches/OfflineRaidSettingsMenuPatch.cs +++ b/project/Aki.Custom/Patches/OfflineRaidSettingsMenuPatch.cs @@ -2,7 +2,6 @@ using Aki.Reflection.Patching; using EFT.UI; using EFT.UI.Matchmaker; -using UnityEngine; namespace Aki.Custom.Patches { @@ -20,11 +19,10 @@ namespace Aki.Custom.Patches } [PatchPostfix] - private static void PatchPostfix() + private static void PatchPostfix(UiElementBlocker ____coopModeBlocker) { // Always disable the Coop Mode checkbox - var coopModeComponent = GameObject.Find("CoopModeCheckmarkBlocker").GetComponent(); - coopModeComponent.SetBlock(true, "SPT will never support Co-op"); + ____coopModeBlocker.SetBlock(true, "SPT will never support Co-op"); } } } \ No newline at end of file