From d4c10c476574fb22fc93d774ceb9a20e986cbd5a Mon Sep 17 00:00:00 2001 From: Lacyway Date: Sat, 24 Aug 2024 09:12:03 +0000 Subject: [PATCH] Rework RemoveStashUpgradeLabelPatch (!162) The `InventoryScreen` is part of the `CommonUI` which lives throughout the lifetime of the application. It should be safe to only delete this on `Awake()` rather than use `Find()` on a transform that has a fair bit of children every time the inventory screen is opened. ![image](/attachments/937a3954-210c-4fc7-a869-75458ae19d8d) I cannot extract on 3.10 currently so need someone to just verify that it sticks after an extract where the menu is reloaded. Co-authored-by: Lacyway <20912169+Lacyway@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT/Modules/pulls/162 Co-authored-by: Lacyway Co-committed-by: Lacyway --- .../Patches/MainMenu/RemoveStashUpgradeLabelPatch.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/project/SPT.SinglePlayer/Patches/MainMenu/RemoveStashUpgradeLabelPatch.cs b/project/SPT.SinglePlayer/Patches/MainMenu/RemoveStashUpgradeLabelPatch.cs index bfebaa3..c1250d5 100644 --- a/project/SPT.SinglePlayer/Patches/MainMenu/RemoveStashUpgradeLabelPatch.cs +++ b/project/SPT.SinglePlayer/Patches/MainMenu/RemoveStashUpgradeLabelPatch.cs @@ -13,13 +13,16 @@ public class RemoveStashUpgradeLabelPatch : ModulePatch { protected override MethodBase GetTargetMethod() { - // InventoryScreen has 2 Show methods - return AccessTools.FirstMethod(typeof(InventoryScreen), info => info.Name == "Show"); + return typeof(InventoryScreen).GetMethod(nameof(InventoryScreen.Awake)); } [PatchPostfix] public static void Postfix(SimpleStashPanel __instance) { - Object.Destroy(__instance.transform.Find("Items Panel/Stash Panel/Simple Panel/Header/ExternalObtain").gameObject); + GameObject externalObtain = __instance.transform.Find("Items Panel/Stash Panel/Simple Panel/Header/ExternalObtain").gameObject; + if (externalObtain != null) + { + Object.Destroy(externalObtain); + } } } \ No newline at end of file