From 0cc567a70418a75e395452dc19df6dfe3bb48564 Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Sun, 15 Sep 2024 14:38:22 -0700 Subject: [PATCH] Try to fix null ref in trader auto switch --- Patches/TradingAutoSwitchPatches.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Patches/TradingAutoSwitchPatches.cs b/Patches/TradingAutoSwitchPatches.cs index 7926174..c840046 100644 --- a/Patches/TradingAutoSwitchPatches.cs +++ b/Patches/TradingAutoSwitchPatches.cs @@ -58,29 +58,34 @@ public static class TradingAutoSwitchPatches TradingItemView __instance, PointerEventData.InputButton button, bool doubleClick, - ETradingItemViewType ___etradingItemViewType_0, bool ___bool_8) + ETradingItemViewType ___etradingItemViewType_0, + bool ___bool_8) { - if (!Settings.AutoSwitchTrading.Value) + if (!Settings.AutoSwitchTrading.Value || SellTab == null || BuyTab == null) + { + return true; + } + + var assortmentController = __instance.R().TraderAssortmentController; + if (assortmentController == null) { return true; } - var tradingItemView = __instance.R(); if (button != PointerEventData.InputButton.Left || ___etradingItemViewType_0 == ETradingItemViewType.TradingTable) { return true; } bool ctrlPressed = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); - if (!ctrlPressed && doubleClick) { return true; } - if (!___bool_8 && ctrlPressed && tradingItemView.TraderAssortmentController.QuickFindTradingAppropriatePlace(__instance.Item, null)) + if (!___bool_8 && ctrlPressed && assortmentController.QuickFindTradingAppropriatePlace(__instance.Item, null)) { - __instance.ItemContext.CloseDependentWindows(); + __instance.ItemContext?.CloseDependentWindows(); __instance.HideTooltip(); Singleton.Instance.PlayItemSound(__instance.Item.ItemSound, EInventorySoundType.pickup, false); @@ -91,7 +96,7 @@ public static class TradingAutoSwitchPatches if (___bool_8) { - tradingItemView.TraderAssortmentController.SelectItem(__instance.Item); + assortmentController.SelectItem(__instance.Item); BuyTab.OnPointerClick(null);