0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-12 16:50:43 -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.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>("RaidSettings").Value;
raidSettings.RaidMode = ERaidMode.Local;
raidSettings.BotSettings.IsEnabled = true;
@ -40,30 +39,30 @@ namespace Aki.Custom.Patches
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)
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<UiElementBlocker>();
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!");
}
}
}

View File

@ -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<UiElementBlocker>();
coopModeComponent.SetBlock(true, "SPT will never support Co-op");
____coopModeBlocker.SetBlock(true, "SPT will never support Co-op");
}
}
}