Try to fix null ref in trader auto switch

This commit is contained in:
Tyfon
2024-09-15 14:38:22 -07:00
parent a9db6ce524
commit 0cc567a704

View File

@@ -58,29 +58,34 @@ public static class TradingAutoSwitchPatches
TradingItemView __instance, TradingItemView __instance,
PointerEventData.InputButton button, PointerEventData.InputButton button,
bool doubleClick, 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; return true;
} }
var tradingItemView = __instance.R();
if (button != PointerEventData.InputButton.Left || ___etradingItemViewType_0 == ETradingItemViewType.TradingTable) if (button != PointerEventData.InputButton.Left || ___etradingItemViewType_0 == ETradingItemViewType.TradingTable)
{ {
return true; return true;
} }
bool ctrlPressed = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); bool ctrlPressed = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
if (!ctrlPressed && doubleClick) if (!ctrlPressed && doubleClick)
{ {
return true; 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(); __instance.HideTooltip();
Singleton<GUISounds>.Instance.PlayItemSound(__instance.Item.ItemSound, EInventorySoundType.pickup, false); Singleton<GUISounds>.Instance.PlayItemSound(__instance.Item.ItemSound, EInventorySoundType.pickup, false);
@@ -91,7 +96,7 @@ public static class TradingAutoSwitchPatches
if (___bool_8) if (___bool_8)
{ {
tradingItemView.TraderAssortmentController.SelectItem(__instance.Item); assortmentController.SelectItem(__instance.Item);
BuyTab.OnPointerClick(null); BuyTab.OnPointerClick(null);