Decompiled source of HaldorOverhaul v1.0.17

HaldorOverhaul.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Haldor Overhaul")]
[assembly: AssemblyDescription("Custom buy/sell trading for Haldor")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HaldorOverhaul")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b7e4f347-ccbb-4fa9-9a20-b39679b6d0f7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HaldorOverhaul
{
	public static class ConfigLoader
	{
		private static string BuyFile => Path.Combine(Paths.ConfigPath, "HaldorOverhaul.haldor.buy.json");

		private static string SellFile => Path.Combine(Paths.ConfigPath, "HaldorOverhaul.haldor.sell.json");

		public static List<TradeEntry> BuyEntries { get; private set; } = new List<TradeEntry>();


		public static List<TradeEntry> SellEntries { get; private set; } = new List<TradeEntry>();


		public static void Initialize()
		{
			EnsureConfigFilesExist();
			LoadBuyConfig();
			LoadSellConfig();
			ValidateAndLogStats();
		}

		private static void ValidateAndLogStats()
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			foreach (TradeEntry item in BuyEntries.ToList())
			{
				if (!ValidateEntry(item, "BUY"))
				{
					BuyEntries.Remove(item);
					num2++;
				}
				else
				{
					num++;
				}
			}
			foreach (TradeEntry item2 in SellEntries.ToList())
			{
				if (!ValidateEntry(item2, "SELL"))
				{
					SellEntries.Remove(item2);
					num4++;
				}
				else
				{
					num3++;
				}
			}
			if (num2 > 0 || num4 > 0)
			{
				HaldorOverhaul.Log.LogWarning((object)$"[ConfigLoader] Removed {num2} invalid BUY entries and {num4} invalid SELL entries.");
			}
			HaldorOverhaul.Log.LogInfo((object)string.Format("{0} Config validated: {1} BUY entries, {2} SELL entries.", "[ConfigLoader]", num, num3));
		}

		private static bool ValidateEntry(TradeEntry entry, string type)
		{
			if (entry == null)
			{
				HaldorOverhaul.Log.LogWarning((object)("[ConfigLoader] " + type + " entry is null, skipping."));
				return false;
			}
			if (string.IsNullOrWhiteSpace(entry.prefab))
			{
				HaldorOverhaul.Log.LogWarning((object)("[ConfigLoader] " + type + " entry has empty prefab name, skipping."));
				return false;
			}
			if (entry.price < 0)
			{
				HaldorOverhaul.Log.LogWarning((object)string.Format("{0} {1} entry '{2}' has negative price ({3}), setting to 0.", "[ConfigLoader]", type, entry.prefab, entry.price));
				entry.price = 0;
			}
			if (entry.stack <= 0)
			{
				HaldorOverhaul.Log.LogWarning((object)string.Format("{0} {1} entry '{2}' has invalid stack ({3}), setting to 1.", "[ConfigLoader]", type, entry.prefab, entry.stack));
				entry.stack = 1;
			}
			return true;
		}

		private static void EnsureConfigFilesExist()
		{
			if (!File.Exists(BuyFile))
			{
				File.WriteAllText(BuyFile, DefaultBuyJson());
				HaldorOverhaul.Log.LogInfo((object)"[ConfigLoader] Created default BUY config.");
			}
			if (!File.Exists(SellFile))
			{
				File.WriteAllText(SellFile, DefaultSellJson());
				HaldorOverhaul.Log.LogInfo((object)"[ConfigLoader] Created default SELL config.");
			}
		}

		private static void LoadBuyConfig()
		{
			try
			{
				BuyEntries = JsonConvert.DeserializeObject<List<TradeEntry>>(File.ReadAllText(BuyFile)) ?? new List<TradeEntry>();
				HaldorOverhaul.Log.LogInfo((object)$"[ConfigLoader] Loaded {BuyEntries.Count} BUY entries.");
			}
			catch (Exception arg)
			{
				HaldorOverhaul.Log.LogError((object)$"[ConfigLoader] Error loading BUY config: {arg}");
				BuyEntries = new List<TradeEntry>();
			}
		}

		private static void LoadSellConfig()
		{
			try
			{
				SellEntries = JsonConvert.DeserializeObject<List<TradeEntry>>(File.ReadAllText(SellFile)) ?? new List<TradeEntry>();
				HaldorOverhaul.Log.LogInfo((object)$"[ConfigLoader] Loaded {SellEntries.Count} SELL entries.");
			}
			catch (Exception arg)
			{
				HaldorOverhaul.Log.LogError((object)$"[ConfigLoader] Error loading SELL config: {arg}");
				SellEntries = new List<TradeEntry>();
			}
		}

		private static string DefaultBuyJson()
		{
			return JsonConvert.SerializeObject((object)new List<TradeEntry>
			{
				new TradeEntry
				{
					prefab = "Wood",
					stack = 50,
					price = 25,
					requiredGlobalKey = "defeated_eikthyr"
				}
			}, (Formatting)1);
		}

		private static string DefaultSellJson()
		{
			return JsonConvert.SerializeObject((object)new List<TradeEntry>
			{
				new TradeEntry
				{
					prefab = "Wood",
					stack = 1,
					price = 1
				}
			}, (Formatting)1);
		}
	}
	public class TradeEntry
	{
		[JsonProperty("item_prefab")]
		public string prefab = "";

		[JsonProperty("item_quantity")]
		public int stack = 1;

		[JsonProperty("item_price")]
		public int price = 1;

		[JsonProperty("must_defeated_boss")]
		public string requiredGlobalKey = "";
	}
	[BepInPlugin("com.haldor.overhaul", "Haldor Overhaul", "1.0.17")]
	public class HaldorOverhaul : BaseUnityPlugin
	{
		public const string PluginGUID = "com.haldor.overhaul";

		public const string PluginName = "Haldor Overhaul";

		public const string PluginVersion = "1.0.17";

		private static Harmony _harmony;

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"Haldor Overhaul v1.0.17 loading...");
			ConfigLoader.Initialize();
			TraderUI traderUI = ((Component)this).gameObject.AddComponent<TraderUI>();
			TraderPatches.SetTraderUI(traderUI);
			BankUI bankUI = ((Component)this).gameObject.AddComponent<BankUI>();
			TraderPatches.SetBankUI(bankUI);
			_harmony = new Harmony("com.haldor.overhaul");
			_harmony.PatchAll(typeof(TraderPatches));
			Log.LogInfo((object)"Haldor Overhaul loaded successfully!");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Log.LogInfo((object)"Haldor Overhaul unloaded.");
		}
	}
	public static class TraderPatches
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ConsoleEvent <>9__11_0;

			internal void <Terminal_InitTerminal_Postfix>b__11_0(ConsoleEventArgs args)
			{
				string s = null;
				if (args.Length >= 3 && args[1] == "=")
				{
					s = args[2];
				}
				else if (args.Length >= 2 && args[1] != "=")
				{
					s = args[1];
				}
				if (!int.TryParse(s, out var result) || result < 0)
				{
					args.Context.AddString("Usage: setbankbalance <amount>");
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null)
				{
					args.Context.AddString("No player found.");
					return;
				}
				int result2 = 0;
				if (localPlayer.m_customData.TryGetValue("HaldorBank_Balance", out var value))
				{
					int.TryParse(value, out result2);
				}
				localPlayer.m_customData["HaldorBank_Balance"] = result.ToString();
				GetTraderUI()?.ReloadBankBalance();
				((Character)localPlayer).Message((MessageType)2, $"Bank balance set to {result:N0}", 0, (Sprite)null);
				args.Context.AddString($"Bank balance set to {result:N0} (was {result2:N0})");
			}
		}

		private static TraderUI _traderUI;

		private static BankUI _bankUI;

		internal static void SetTraderUI(TraderUI ui)
		{
			_traderUI = ui;
		}

		internal static void SetBankUI(BankUI ui)
		{
			_bankUI = ui;
		}

		internal static TraderUI GetTraderUI()
		{
			return _traderUI;
		}

		[HarmonyPatch(typeof(StoreGui), "Show")]
		[HarmonyPrefix]
		private static bool StoreGui_Show_Prefix(StoreGui __instance, Trader trader)
		{
			if ((Object)(object)_traderUI == (Object)null)
			{
				return true;
			}
			_traderUI.Show(trader, __instance);
			return false;
		}

		[HarmonyPatch(typeof(StoreGui), "Hide")]
		[HarmonyPostfix]
		private static void StoreGui_Hide_Postfix()
		{
			if ((Object)(object)_traderUI != (Object)null && _traderUI.IsVisible)
			{
				_traderUI.Hide();
			}
		}

		[HarmonyPatch(typeof(StoreGui), "IsVisible")]
		[HarmonyPostfix]
		private static void StoreGui_IsVisible_Postfix(ref bool __result)
		{
			if ((Object)(object)_traderUI != (Object)null && _traderUI.IsVisible)
			{
				__result = true;
			}
			if ((Object)(object)_bankUI != (Object)null && _bankUI.IsVisible)
			{
				__result = true;
			}
		}

		[HarmonyPatch(typeof(Chat), "SetNpcText")]
		[HarmonyPrefix]
		private static bool Chat_SetNpcText_Prefix()
		{
			if ((Object)(object)_traderUI != (Object)null && _traderUI.IsVisible)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(Chat), "HasFocus")]
		[HarmonyPostfix]
		private static void Chat_HasFocus_Postfix(ref bool __result)
		{
			if (!__result && (Object)(object)_traderUI != (Object)null && _traderUI.IsSearchFocused)
			{
				__result = true;
			}
		}

		[HarmonyPatch(typeof(Player), "TakeInput")]
		[HarmonyPrefix]
		private static bool Player_TakeInput_Prefix(ref bool __result)
		{
			if (((Object)(object)_traderUI != (Object)null && _traderUI.IsVisible) || ((Object)(object)_bankUI != (Object)null && _bankUI.IsVisible))
			{
				__result = false;
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(Terminal), "InitTerminal")]
		[HarmonyPostfix]
		private static void Terminal_InitTerminal_Postfix()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			object obj = <>c.<>9__11_0;
			if (obj == null)
			{
				ConsoleEvent val = delegate(ConsoleEventArgs args)
				{
					string s = null;
					if (args.Length >= 3 && args[1] == "=")
					{
						s = args[2];
					}
					else if (args.Length >= 2 && args[1] != "=")
					{
						s = args[1];
					}
					if (!int.TryParse(s, out var result) || result < 0)
					{
						args.Context.AddString("Usage: setbankbalance <amount>");
					}
					else
					{
						Player localPlayer = Player.m_localPlayer;
						if ((Object)(object)localPlayer == (Object)null)
						{
							args.Context.AddString("No player found.");
						}
						else
						{
							int result2 = 0;
							if (localPlayer.m_customData.TryGetValue("HaldorBank_Balance", out var value))
							{
								int.TryParse(value, out result2);
							}
							localPlayer.m_customData["HaldorBank_Balance"] = result.ToString();
							GetTraderUI()?.ReloadBankBalance();
							((Character)localPlayer).Message((MessageType)2, $"Bank balance set to {result:N0}", 0, (Sprite)null);
							args.Context.AddString($"Bank balance set to {result:N0} (was {result2:N0})");
						}
					}
				};
				<>c.<>9__11_0 = val;
				obj = (object)val;
			}
			new ConsoleCommand("setbankbalance", "Set Haldor's bank balance. Usage: setbankbalance <amount>  or  setbankbalance = <amount>", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}
	}
	public static class TextureLoader
	{
		private static readonly Dictionary<string, Texture2D> Cache = new Dictionary<string, Texture2D>();

		private static readonly Assembly ModAssembly = Assembly.GetExecutingAssembly();

		private static readonly MethodInfo LoadImageMethod = ResolveLoadImage();

		private static MethodInfo ResolveLoadImage()
		{
			return Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule")?.GetMethod("LoadImage", new Type[2]
			{
				typeof(Texture2D),
				typeof(byte[])
			});
		}

		public static Texture2D LoadUITexture(string name)
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			if (string.IsNullOrEmpty(name))
			{
				return null;
			}
			string key = "UI_" + name;
			if (Cache.TryGetValue(key, out var value))
			{
				return value;
			}
			if (LoadImageMethod == null)
			{
				HaldorOverhaul.Log.LogWarning((object)"TextureLoader: ImageConversion.LoadImage not found via reflection.");
				return null;
			}
			string text = "HaldorOverhaul.Resources.Textures.UI." + name + ".png";
			using Stream stream = ModAssembly.GetManifestResourceStream(text);
			if (stream == null)
			{
				HaldorOverhaul.Log.LogWarning((object)("TextureLoader: UI resource '" + text + "' not found."));
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if ((bool)LoadImageMethod.Invoke(null, new object[2] { val, array }))
			{
				((Object)val).name = name;
				Cache[key] = val;
				return val;
			}
			Object.Destroy((Object)(object)val);
			return null;
		}
	}
	public class BankUI : MonoBehaviour
	{
		private bool _isVisible;

		private bool _uiBuilt;

		private int _bankBalance;

		private GameObject _canvasGO;

		private GameObject _mainPanel;

		private TMP_Text _titleText;

		private TMP_Text _bankBalanceText;

		private TMP_Text _inventoryCoinsText;

		private TMP_Text _totalWealthText;

		private TMP_Text _statusText;

		private Button _depositButton;

		private TMP_Text _depositLabel;

		private GameObject _depositSelected;

		private Button _withdrawButton;

		private TMP_Text _withdrawLabel;

		private GameObject _withdrawSelected;

		private Sprite _bgSprite;

		private TMP_FontAsset _valheimFont;

		private GameObject _buttonTemplate;

		private float _btnHeight = 36f;

		private int _focusedButton;

		private static readonly Color ColOverlay = new Color(0f, 0f, 0f, 0.65f);

		private static readonly Color GoldTextColor = new Color(0.83f, 0.52f, 0.18f, 1f);

		private static readonly Color PanelBgColor = new Color(0.22f, 0.1f, 0.04f, 0.65f);

		private static readonly Color SelectedColor = new Color(1f, 0.82f, 0.24f, 0.25f);

		private const float PanelWidth = 420f;

		private const float PanelHeight = 320f;

		private const string CustomDataKey = "HaldorBank_Balance";

		public bool IsVisible => _isVisible;

		public void Show()
		{
			if (!_uiBuilt)
			{
				BuildUI();
			}
			if (_uiBuilt)
			{
				LoadBalance();
				_canvasGO.SetActive(true);
				_isVisible = true;
				_focusedButton = 0;
				RefreshDisplay();
				UpdateControllerHighlight();
			}
		}

		public void Hide()
		{
			_isVisible = false;
			if ((Object)(object)_canvasGO != (Object)null)
			{
				_canvasGO.SetActive(false);
			}
		}

		private void Update()
		{
			if (_isVisible)
			{
				if (Input.GetKeyDown((KeyCode)27))
				{
					Hide();
					return;
				}
				UpdateGamepadInput();
				RefreshDisplay();
			}
		}

		private void LateUpdate()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (!_isVisible)
			{
				return;
			}
			if (!ZInput.IsGamepadActive())
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			else
			{
				Cursor.visible = false;
			}
			Hud instance = Hud.instance;
			if ((Object)(object)instance != (Object)null)
			{
				if ((Object)(object)instance.m_crosshair != (Object)null)
				{
					((Graphic)instance.m_crosshair).color = Color.clear;
				}
				if ((Object)(object)instance.m_hoverName != (Object)null)
				{
					((TMP_Text)instance.m_hoverName).text = "";
				}
			}
			if (ZInput.IsGamepadActive() && (Object)(object)EventSystem.current != (Object)null)
			{
				EventSystem.current.SetSelectedGameObject((GameObject)null);
			}
		}

		private void UpdateGamepadInput()
		{
			if (ZInput.GetButtonDown("JoyButtonB"))
			{
				Hide();
				return;
			}
			if (ZInput.GetButtonDown("JoyLStickLeft") || ZInput.GetButtonDown("JoyDPadLeft") || ZInput.GetButtonDown("JoyLStickUp") || ZInput.GetButtonDown("JoyDPadUp"))
			{
				_focusedButton = 0;
				UpdateControllerHighlight();
			}
			if (ZInput.GetButtonDown("JoyLStickRight") || ZInput.GetButtonDown("JoyDPadRight") || ZInput.GetButtonDown("JoyLStickDown") || ZInput.GetButtonDown("JoyDPadDown"))
			{
				_focusedButton = 1;
				UpdateControllerHighlight();
			}
			if (ZInput.GetButtonDown("JoyButtonA"))
			{
				if (_focusedButton == 0 && (Object)(object)_depositButton != (Object)null && ((Selectable)_depositButton).interactable)
				{
					OnDeposit();
				}
				else if (_focusedButton == 1 && (Object)(object)_withdrawButton != (Object)null && ((Selectable)_withdrawButton).interactable)
				{
					OnWithdraw();
				}
			}
		}

		private void UpdateControllerHighlight()
		{
			bool flag = ZInput.IsGamepadActive();
			if ((Object)(object)_depositSelected != (Object)null)
			{
				_depositSelected.SetActive(flag && _focusedButton == 0);
			}
			if ((Object)(object)_withdrawSelected != (Object)null)
			{
				_withdrawSelected.SetActive(flag && _focusedButton == 1);
			}
		}

		private void BuildUI()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected O, but got Unknown
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Expected O, but got Unknown
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0502: Unknown result type (might be due to invalid IL or missing references)
			//IL_052f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			//IL_055b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0571: Unknown result type (might be due to invalid IL or missing references)
			//IL_0587: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0603: Unknown result type (might be due to invalid IL or missing references)
			//IL_0619: Unknown result type (might be due to invalid IL or missing references)
			//IL_062f: Unknown result type (might be due to invalid IL or missing references)
			//IL_064c: Unknown result type (might be due to invalid IL or missing references)
			//IL_069e: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b4: Expected O, but got Unknown
			//IL_06da: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f0: Expected O, but got Unknown
			if (!ExtractAssets())
			{
				HaldorOverhaul.Log.LogError((object)"[BankUI] Failed to extract Valheim assets.");
				return;
			}
			_canvasGO = new GameObject("HaldorBank_Canvas");
			_canvasGO.transform.SetParent(((Component)this).transform);
			Canvas val = _canvasGO.AddComponent<Canvas>();
			val.renderMode = (RenderMode)0;
			val.sortingOrder = 101;
			CanvasScaler val2 = _canvasGO.AddComponent<CanvasScaler>();
			val2.uiScaleMode = (ScaleMode)1;
			val2.referenceResolution = new Vector2(1920f, 1080f);
			val2.matchWidthOrHeight = 0.5f;
			_canvasGO.AddComponent<GraphicRaycaster>();
			GameObject val3 = new GameObject("Overlay", new Type[1] { typeof(RectTransform) });
			val3.transform.SetParent(_canvasGO.transform, false);
			RectTransform component = val3.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			((Graphic)val3.AddComponent<Image>()).color = ColOverlay;
			_mainPanel = new GameObject("BankPanel", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			_mainPanel.transform.SetParent(_canvasGO.transform, false);
			RectTransform component2 = _mainPanel.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0.5f, 0.5f);
			component2.anchorMax = new Vector2(0.5f, 0.5f);
			component2.pivot = new Vector2(0.5f, 0.5f);
			component2.sizeDelta = new Vector2(420f, 320f);
			component2.anchoredPosition = Vector2.zero;
			Image component3 = _mainPanel.GetComponent<Image>();
			if ((Object)(object)_bgSprite != (Object)null)
			{
				component3.sprite = _bgSprite;
				component3.type = (Type)0;
				component3.preserveAspect = false;
				((Graphic)component3).color = Color.white;
			}
			else
			{
				((Graphic)component3).color = new Color(0.18f, 0.14f, 0.09f, 0.92f);
			}
			GameObject val4 = new GameObject("InnerPanel", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val4.transform.SetParent(_mainPanel.transform, false);
			RectTransform component4 = val4.GetComponent<RectTransform>();
			component4.anchorMin = Vector2.zero;
			component4.anchorMax = Vector2.one;
			component4.offsetMin = new Vector2(14f, 14f);
			component4.offsetMax = new Vector2(-14f, -14f);
			((Graphic)val4.GetComponent<Image>()).color = PanelBgColor;
			Transform transform = val4.transform;
			_titleText = CreateText(transform, "Title", "Haldor's Bank", 26f, GoldTextColor, (TextAlignmentOptions)514);
			RectTransform component5 = ((Component)_titleText).GetComponent<RectTransform>();
			component5.anchorMin = new Vector2(0f, 1f);
			component5.anchorMax = new Vector2(1f, 1f);
			component5.pivot = new Vector2(0.5f, 1f);
			component5.sizeDelta = new Vector2(0f, 36f);
			component5.anchoredPosition = new Vector2(0f, -8f);
			CreateSeparator(transform, -48f);
			_bankBalanceText = CreateText(transform, "BankBalance", "Bank Balance: 0", 26f, GoldTextColor, (TextAlignmentOptions)514);
			RectTransform component6 = ((Component)_bankBalanceText).GetComponent<RectTransform>();
			component6.anchorMin = new Vector2(0f, 1f);
			component6.anchorMax = new Vector2(1f, 1f);
			component6.pivot = new Vector2(0.5f, 1f);
			component6.sizeDelta = new Vector2(0f, 36f);
			component6.anchoredPosition = new Vector2(0f, -64f);
			_inventoryCoinsText = CreateText(transform, "InventoryCoins", "Inventory Coins: 0", 20f, new Color(0.85f, 0.85f, 0.85f), (TextAlignmentOptions)514);
			RectTransform component7 = ((Component)_inventoryCoinsText).GetComponent<RectTransform>();
			component7.anchorMin = new Vector2(0f, 1f);
			component7.anchorMax = new Vector2(1f, 1f);
			component7.pivot = new Vector2(0.5f, 1f);
			component7.sizeDelta = new Vector2(0f, 28f);
			component7.anchoredPosition = new Vector2(0f, -104f);
			_totalWealthText = CreateText(transform, "TotalWealth", "Total Wealth: 0", 16f, new Color(0.58f, 0.58f, 0.58f), (TextAlignmentOptions)514);
			RectTransform component8 = ((Component)_totalWealthText).GetComponent<RectTransform>();
			component8.anchorMin = new Vector2(0f, 1f);
			component8.anchorMax = new Vector2(1f, 1f);
			component8.pivot = new Vector2(0.5f, 1f);
			component8.sizeDelta = new Vector2(0f, 22f);
			component8.anchoredPosition = new Vector2(0f, -136f);
			CreateSeparator(transform, -164f);
			_statusText = CreateText(transform, "Status", "", 16f, new Color(0.7f, 0.7f, 0.7f), (TextAlignmentOptions)514);
			RectTransform component9 = ((Component)_statusText).GetComponent<RectTransform>();
			component9.anchorMin = new Vector2(0f, 0f);
			component9.anchorMax = new Vector2(1f, 0f);
			component9.pivot = new Vector2(0.5f, 0f);
			component9.sizeDelta = new Vector2(0f, 24f);
			component9.anchoredPosition = new Vector2(0f, _btnHeight + 20f);
			float num = 160f;
			float num2 = 16f;
			float num3 = num * 2f + num2;
			float num4 = (0f - num3) / 2f;
			float y = 10f;
			_depositButton = CreateActionButton(transform, "DepositButton", "Deposit All", num4, y, num, new UnityAction(OnDeposit), out _depositLabel, out _depositSelected);
			_withdrawButton = CreateActionButton(transform, "WithdrawButton", "Withdraw All", num4 + num + num2, y, num, new UnityAction(OnWithdraw), out _withdrawLabel, out _withdrawSelected);
			_canvasGO.SetActive(false);
			_uiBuilt = true;
		}

		private Button CreateActionButton(Transform parent, string name, string label, float x, float y, float width, UnityAction onClick, out TMP_Text outLabel, out GameObject outSelected)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			outLabel = null;
			outSelected = null;
			if ((Object)(object)_buttonTemplate == (Object)null)
			{
				return null;
			}
			GameObject val = Object.Instantiate<GameObject>(_buttonTemplate, parent);
			((Object)val).name = name;
			val.SetActive(true);
			Button component = val.GetComponent<Button>();
			if ((Object)(object)component != (Object)null)
			{
				((UnityEventBase)component.onClick).RemoveAllListeners();
				((UnityEvent)component.onClick).AddListener(onClick);
				Navigation navigation = default(Navigation);
				((Navigation)(ref navigation)).mode = (Mode)0;
				((Selectable)component).navigation = navigation;
			}
			outLabel = val.GetComponentInChildren<TMP_Text>(true);
			if ((Object)(object)outLabel != (Object)null)
			{
				((Component)outLabel).gameObject.SetActive(true);
				outLabel.text = label;
			}
			StripButtonHints(val, outLabel);
			RectTransform component2 = val.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0.5f, 0f);
			component2.anchorMax = new Vector2(0.5f, 0f);
			component2.pivot = new Vector2(0f, 0f);
			component2.sizeDelta = new Vector2(width, _btnHeight);
			component2.anchoredPosition = new Vector2(x, y);
			GameObject val2 = new GameObject("selected", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val2.transform.SetParent(val.transform, false);
			val2.transform.SetAsFirstSibling();
			RectTransform component3 = val2.GetComponent<RectTransform>();
			component3.anchorMin = Vector2.zero;
			component3.anchorMax = Vector2.one;
			component3.offsetMin = new Vector2(-4f, -4f);
			component3.offsetMax = new Vector2(4f, 4f);
			((Graphic)val2.GetComponent<Image>()).color = SelectedColor;
			val2.SetActive(false);
			outSelected = val2;
			return component;
		}

		private void CreateSeparator(Transform parent, float yPos)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Separator", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.05f, 1f);
			component.anchorMax = new Vector2(0.95f, 1f);
			component.pivot = new Vector2(0.5f, 1f);
			component.sizeDelta = new Vector2(0f, 2f);
			component.anchoredPosition = new Vector2(0f, yPos);
			((Graphic)val.GetComponent<Image>()).color = new Color(GoldTextColor.r, GoldTextColor.g, GoldTextColor.b, 0.3f);
		}

		private void OnDeposit()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			if (inventory == null)
			{
				return;
			}
			string coinName = GetCoinName();
			if (!string.IsNullOrEmpty(coinName))
			{
				int num = inventory.CountItems(coinName, -1, true);
				if (num <= 0)
				{
					SetStatus("No coins to deposit!");
					return;
				}
				inventory.RemoveItem(coinName, num, -1, true);
				_bankBalance += num;
				SaveBalance();
				RefreshDisplay();
				SetStatus($"Deposited {num:N0} coins");
				((Character)localPlayer).Message((MessageType)2, $"Deposited {num:N0} coins", 0, (Sprite)null);
			}
		}

		private void OnWithdraw()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			if (inventory == null)
			{
				return;
			}
			if (_bankBalance <= 0)
			{
				SetStatus("Bank is empty!");
				return;
			}
			ObjectDB instance = ObjectDB.instance;
			GameObject val = ((instance != null) ? instance.GetItemPrefab("Coins") : null);
			ItemDrop val2 = ((val != null) ? val.GetComponent<ItemDrop>() : null);
			if (!((Object)(object)val2 == (Object)null))
			{
				int bankBalance = _bankBalance;
				ItemData val3 = inventory.AddItem("Coins", bankBalance, val2.m_itemData.m_quality, val2.m_itemData.m_variant, 0L, "", false);
				if (val3 == null)
				{
					SetStatus("Inventory full!");
					return;
				}
				_bankBalance = 0;
				SaveBalance();
				RefreshDisplay();
				SetStatus($"Withdrew {bankBalance:N0} coins");
				((Character)localPlayer).Message((MessageType)2, $"Withdrew {bankBalance:N0} coins", 0, (Sprite)null);
			}
		}

		private void RefreshDisplay()
		{
			int inventoryCoins = GetInventoryCoins();
			if ((Object)(object)_bankBalanceText != (Object)null)
			{
				_bankBalanceText.text = $"Bank Balance: {_bankBalance:N0}";
			}
			if ((Object)(object)_inventoryCoinsText != (Object)null)
			{
				_inventoryCoinsText.text = $"Inventory Coins: {inventoryCoins:N0}";
			}
			if ((Object)(object)_totalWealthText != (Object)null)
			{
				_totalWealthText.text = $"Total Wealth: {_bankBalance + inventoryCoins:N0}";
			}
			if ((Object)(object)_depositButton != (Object)null)
			{
				((Selectable)_depositButton).interactable = inventoryCoins > 0;
			}
			if ((Object)(object)_withdrawButton != (Object)null)
			{
				((Selectable)_withdrawButton).interactable = _bankBalance > 0;
			}
			UpdateControllerHighlight();
		}

		private void SetStatus(string msg)
		{
			if ((Object)(object)_statusText != (Object)null)
			{
				_statusText.text = msg;
			}
		}

		private void LoadBalance()
		{
			_bankBalance = 0;
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null) && localPlayer.m_customData.TryGetValue("HaldorBank_Balance", out var value))
			{
				int.TryParse(value, out _bankBalance);
			}
		}

		private void SaveBalance()
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				localPlayer.m_customData["HaldorBank_Balance"] = _bankBalance.ToString();
			}
		}

		private int GetInventoryCoins()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return 0;
			}
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			string coinName = GetCoinName();
			if (inventory == null || string.IsNullOrEmpty(coinName))
			{
				return 0;
			}
			return inventory.CountItems(coinName, -1, true);
		}

		private string GetCoinName()
		{
			ObjectDB instance = ObjectDB.instance;
			GameObject val = ((instance != null) ? instance.GetItemPrefab("Coins") : null);
			return ((val != null) ? val.GetComponent<ItemDrop>() : null)?.m_itemData?.m_shared?.m_name;
		}

		private bool ExtractAssets()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			Texture2D val = TextureLoader.LoadUITexture("PanelBackground");
			if ((Object)(object)val != (Object)null)
			{
				_bgSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			}
			if ((Object)(object)instance.m_craftButton != (Object)null)
			{
				RectTransform component = ((Component)instance.m_craftButton).GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					Rect rect = component.rect;
					_btnHeight = Mathf.Max(((Rect)(ref rect)).height, 36f);
				}
				_buttonTemplate = Object.Instantiate<GameObject>(((Component)instance.m_craftButton).gameObject);
				((Object)_buttonTemplate).name = "BankButtonTemplate";
				_buttonTemplate.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)_buttonTemplate);
			}
			_valheimFont = FindValheimFont();
			return (Object)(object)_buttonTemplate != (Object)null;
		}

		private TMP_Text CreateText(Transform parent, string name, string text, float fontSize, Color color, TextAlignmentOptions alignment)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)_valheimFont != (Object)null)
			{
				((TMP_Text)val2).font = _valheimFont;
			}
			((TMP_Text)val2).fontSize = fontSize;
			((Graphic)val2).color = color;
			((TMP_Text)val2).alignment = alignment;
			((TMP_Text)val2).text = text;
			((TMP_Text)val2).overflowMode = (TextOverflowModes)1;
			return (TMP_Text)(object)val2;
		}

		private TMP_FontAsset FindValheimFont()
		{
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance != (Object)null)
			{
				if ((Object)(object)instance.m_recipeName != (Object)null && (Object)(object)instance.m_recipeName.font != (Object)null)
				{
					return instance.m_recipeName.font;
				}
				if ((Object)(object)instance.m_recipeDecription != (Object)null && (Object)(object)instance.m_recipeDecription.font != (Object)null)
				{
					return instance.m_recipeDecription.font;
				}
			}
			TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			foreach (TMP_FontAsset val in array)
			{
				if (((Object)val).name.Contains("Valheim") || ((Object)val).name.Contains("Averia"))
				{
					return val;
				}
			}
			return null;
		}

		private static void StripButtonHints(GameObject buttonGO, TMP_Text labelText)
		{
			for (int num = buttonGO.transform.childCount - 1; num >= 0; num--)
			{
				Transform child = buttonGO.transform.GetChild(num);
				if (!((Object)(object)labelText != (Object)null) || (!((Object)(object)((Component)child).gameObject == (Object)(object)((Component)labelText).gameObject) && !labelText.transform.IsChildOf(child)))
				{
					Object.DestroyImmediate((Object)(object)((Component)child).gameObject);
				}
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)_buttonTemplate != (Object)null)
			{
				Object.Destroy((Object)(object)_buttonTemplate);
			}
		}
	}
	public class TraderUI : MonoBehaviour
	{
		private class BuyEntry
		{
			public string PrefabName;

			public string Name;

			public string Description;

			public int Price;

			public int Stack;

			public string Category;

			public Sprite Icon;
		}

		private class SellEntry
		{
			public ItemData Item;

			public string PrefabName;

			public string Name;

			public int Price;

			public int ConfigStack;

			public string Category;

			public Sprite Icon;
		}

		private bool _isVisible;

		private Trader _currentTrader;

		private StoreGui _currentStoreGui;

		private int _activeTab;

		private static readonly string[] TabNames = new string[3] { "Buy", "Sell", "Bank" };

		private int _selectedBuyIndex = -1;

		private int _selectedSellIndex = -1;

		private readonly Dictionary<string, bool> _buyCategoryCollapsed = new Dictionary<string, bool>();

		private readonly Dictionary<string, bool> _sellCategoryCollapsed = new Dictionary<string, bool>();

		private static readonly string[] CategoryBuckets = new string[9] { "Weapons", "Armor", "Shields", "Ammo", "Consumables", "Materials", "Utility", "Trophies", "Misc" };

		private string _searchFilter = "";

		private TMP_InputField _searchInput;

		private string _activeCategoryFilter;

		private readonly List<Button> _categoryFilterButtons = new List<Button>();

		private readonly List<string> _categoryFilterKeys = new List<string>();

		private int _joyCategoryFocusIndex = -1;

		private GameObject _canvasGO;

		private bool _uiBuilt;

		private Sprite _bgSprite;

		private Sprite _textFieldSprite;

		private Sprite _catBtnSprite;

		private GameObject _recipeElementPrefab;

		private GameObject _buttonTemplate;

		private float _scrollSensitivity = 40f;

		private TMP_FontAsset _valheimFont;

		private GameObject _mainPanel;

		private RectTransform _leftColumn;

		private RectTransform _middleColumn;

		private RectTransform _rightColumn;

		private GameObject _tabBuy;

		private GameObject _tabSell;

		private GameObject _tabBank;

		private int _bankBalance;

		private int _bankFocusedButton;

		private GameObject _bankContentPanel;

		private TMP_Text _bankBalanceText;

		private TMP_Text _bankInvCoinsText;

		private TMP_Text _bankTotalText;

		private TMP_Text _bankStatusText;

		private Button _bankDepositButton;

		private Button _bankWithdrawButton;

		private GameObject _bankDepositSelected;

		private GameObject _bankWithdrawSelected;

		private const string BankDataKey = "HaldorBank_Balance";

		private RectTransform _listRoot;

		private ScrollRect _listScrollRect;

		private TMP_Text _itemNameText;

		private TMP_Text _itemDescText;

		private ScrollRect _descScrollRect;

		private int _descScrollResetFrames;

		private Button _actionButton;

		private TMP_Text _actionButtonLabel;

		private TMP_Text _coinDisplayText;

		private RenderTexture _playerPreviewRT;

		private GameObject _playerCamGO;

		private Camera _playerCam;

		private GameObject _playerClone;

		private GameObject _playerLightRig;

		private RawImage _playerPreviewImg;

		private static readonly Vector3 PlayerSpawnPos = new Vector3(10000f, 5000f, 10000f);

		private RenderTexture _haldorPreviewRT;

		private GameObject _haldorCamGO;

		private Camera _haldorCam;

		private GameObject _haldorClone;

		private GameObject _haldorLightRig;

		private RawImage _haldorPreviewImg;

		private static readonly Vector3 HaldorSpawnPos = new Vector3(10000f, 5000f, 10020f);

		private Color _savedAmbientColor;

		private float _savedAmbientIntensity;

		private AmbientMode _savedAmbientMode;

		private float _previewRotation;

		private const float AutoRotateSpeed = 12f;

		private bool _isDraggingPlayerPreview;

		private float _lastMouseX;

		private const float MouseDragSensitivity = 0.5f;

		private const float ColGap = 4f;

		private const float TabTopGap = 6f;

		private const float ExtraMiddleWidth = 80f;

		private const float OuterPad = 6f;

		private const float SearchBoxHeight = 32f;

		private const float FilterRowHeight = 38f;

		private static readonly Color ColOverlay = new Color(0f, 0f, 0f, 0f);

		private static readonly Color GoldColor = new Color(0.83f, 0.64f, 0.31f, 1f);

		private static readonly Color GoldTextColor = new Color(0.83f, 0.52f, 0.18f, 1f);

		private static readonly Color CategoryHeaderBg = new Color(0.3f, 0.25f, 0.15f, 0.85f);

		private static readonly Color CategoryHeaderText = new Color(1f, 0.9f, 0.5f, 1f);

		private float _panelWidth;

		private float _panelHeight;

		private float _leftColWidth;

		private float _midColWidth;

		private float _rightColWidth;

		private float _leftPad;

		private float _bottomPad;

		private float _colTopInset;

		private float _tabBtnHeight;

		private float _craftBtnHeight;

		private readonly List<BuyEntry> _allBuyEntries = new List<BuyEntry>();

		private readonly List<SellEntry> _allSellEntries = new List<SellEntry>();

		private readonly List<(GameObject go, int dataIndex)> _listElements = new List<(GameObject, int)>();

		private readonly List<GameObject> _categoryHeaders = new List<GameObject>();

		private int _lastInventoryHash;

		private int _lastCoinDisplayCount = -1;

		private int _lastBankBalanceDisplay = -1;

		private int _lastBankInvCoinsDisplay = -1;

		private Dictionary<string, string> _savedEquipSlots;

		public bool IsVisible => _isVisible;

		public bool IsSearchFocused
		{
			get
			{
				if ((Object)(object)_searchInput != (Object)null)
				{
					return _searchInput.isFocused;
				}
				return false;
			}
		}

		public void Show(Trader trader, StoreGui storeGui)
		{
			_currentTrader = trader;
			_currentStoreGui = storeGui;
			if (!_uiBuilt)
			{
				BuildUI();
			}
			if (_uiBuilt)
			{
				_canvasGO.SetActive(true);
				_isVisible = true;
				_activeTab = 0;
				_selectedBuyIndex = -1;
				_selectedSellIndex = -1;
				_searchFilter = "";
				if ((Object)(object)_searchInput != (Object)null)
				{
					_searchInput.text = "";
				}
				_activeCategoryFilter = null;
				_joyCategoryFocusIndex = -1;
				_lastInventoryHash = 0;
				_lastCoinDisplayCount = -1;
				_lastBankBalanceDisplay = -1;
				_lastBankInvCoinsDisplay = -1;
				SetupPlayerPreview();
				SetupHaldorPreview();
				_previewRotation = 0f;
				EnablePreviewCameras();
				LoadBankBalance();
				BuildBuyEntries();
				BuildSellEntries();
				RefreshTabHighlights();
				RefreshTabPanels();
				UpdateCoinDisplay();
			}
		}

		public void Hide()
		{
			_isVisible = false;
			DisablePreviewCameras();
			ClearPlayerPreview();
			ClearHaldorPreview();
			if ((Object)(object)_canvasGO != (Object)null)
			{
				_canvasGO.SetActive(false);
			}
			_currentTrader = null;
			_currentStoreGui = null;
		}

		private void Update()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (!_isVisible)
			{
				return;
			}
			if ((Object)(object)_currentTrader != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				float num = Vector3.Distance(((Component)Player.m_localPlayer).transform.position, ((Component)_currentTrader).transform.position);
				if (num > 15f)
				{
					Hide();
					return;
				}
			}
			if (!ZInput.IsGamepadActive())
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			else
			{
				Cursor.visible = false;
			}
			if (Input.GetKeyDown((KeyCode)27))
			{
				Hide();
				return;
			}
			if (!IsSearchFocused)
			{
				if (Input.GetKeyDown((KeyCode)113))
				{
					SwitchTab(Mathf.Max(0, _activeTab - 1));
				}
				if (Input.GetKeyDown((KeyCode)101))
				{
					SwitchTab(Mathf.Min(2, _activeTab + 1));
				}
			}
			UpdatePlayerPreviewRotation();
			UpdatePlayerCamera();
			RefreshSellListIfChanged();
			UpdateCoinDisplay();
			if (_activeTab == 2)
			{
				RefreshBankDisplay();
			}
			UpdateGamepadInput();
		}

		private void LateUpdate()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if (!_isVisible)
			{
				return;
			}
			Hud instance = Hud.instance;
			if ((Object)(object)instance != (Object)null)
			{
				if ((Object)(object)instance.m_crosshair != (Object)null)
				{
					((Graphic)instance.m_crosshair).color = Color.clear;
				}
				if ((Object)(object)instance.m_hoverName != (Object)null)
				{
					((TMP_Text)instance.m_hoverName).text = "";
				}
			}
			if (_descScrollResetFrames > 0 && (Object)(object)_descScrollRect != (Object)null)
			{
				_descScrollRect.verticalNormalizedPosition = 1f;
				_descScrollRect.velocity = Vector2.zero;
				_descScrollResetFrames--;
			}
			if ((Object)(object)EventSystem.current != (Object)null && (Object)(object)EventSystem.current.currentSelectedGameObject != (Object)null && ((Object)(object)_searchInput == (Object)null || (Object)(object)EventSystem.current.currentSelectedGameObject != (Object)(object)((Component)_searchInput).gameObject))
			{
				EventSystem.current.SetSelectedGameObject((GameObject)null);
			}
			SaveAmbient();
			try
			{
				SetPreviewAmbient();
				if (_activeTab == 0 && (Object)(object)_playerCam != (Object)null)
				{
					_playerCam.Render();
				}
				else if (_activeTab == 1 && (Object)(object)_haldorCam != (Object)null)
				{
					_haldorCam.Render();
				}
			}
			finally
			{
				RestoreAmbient();
			}
		}

		private void OnDestroy()
		{
			ClearPlayerPreview();
			ClearHaldorPreview();
			if ((Object)(object)_playerCamGO != (Object)null)
			{
				Object.Destroy((Object)(object)_playerCamGO);
			}
			if ((Object)(object)_haldorCamGO != (Object)null)
			{
				Object.Destroy((Object)(object)_haldorCamGO);
			}
			if ((Object)(object)_playerPreviewRT != (Object)null)
			{
				_playerPreviewRT.Release();
				Object.Destroy((Object)(object)_playerPreviewRT);
			}
			if ((Object)(object)_haldorPreviewRT != (Object)null)
			{
				_haldorPreviewRT.Release();
				Object.Destroy((Object)(object)_haldorPreviewRT);
			}
			if ((Object)(object)_buttonTemplate != (Object)null)
			{
				Object.Destroy((Object)(object)_buttonTemplate);
			}
			if ((Object)(object)_canvasGO != (Object)null)
			{
				Object.Destroy((Object)(object)_canvasGO);
			}
		}

		private void UpdateGamepadInput()
		{
			if (ZInput.GetButtonDown("JoyTabLeft"))
			{
				SwitchTab(Mathf.Max(0, _activeTab - 1));
			}
			if (ZInput.GetButtonDown("JoyTabRight"))
			{
				SwitchTab(Mathf.Min(2, _activeTab + 1));
			}
			if (ZInput.GetButtonDown("JoyButtonB"))
			{
				Hide();
				return;
			}
			if (ZInput.GetButtonDown("JoyLStickDown") || ZInput.GetButtonDown("JoyDPadDown"))
			{
				_joyCategoryFocusIndex = -1;
				UpdateCategoryFilterVisuals();
				MoveSelection(1);
				if ((Object)(object)EventSystem.current != (Object)null)
				{
					EventSystem.current.SetSelectedGameObject((GameObject)null);
				}
			}
			if (ZInput.GetButtonDown("JoyLStickUp") || ZInput.GetButtonDown("JoyDPadUp"))
			{
				_joyCategoryFocusIndex = -1;
				UpdateCategoryFilterVisuals();
				MoveSelection(-1);
				if ((Object)(object)EventSystem.current != (Object)null)
				{
					EventSystem.current.SetSelectedGameObject((GameObject)null);
				}
			}
			if (ZInput.GetButtonDown("JoyLStickLeft") || ZInput.GetButtonDown("JoyDPadLeft"))
			{
				if (_activeTab == 2)
				{
					_bankFocusedButton = 0;
					UpdateBankHighlight();
				}
				else
				{
					NavigateCategoryButtons(-1);
				}
			}
			if (ZInput.GetButtonDown("JoyLStickRight") || ZInput.GetButtonDown("JoyDPadRight"))
			{
				if (_activeTab == 2)
				{
					_bankFocusedButton = 1;
					UpdateBankHighlight();
				}
				else
				{
					NavigateCategoryButtons(1);
				}
			}
			if (ZInput.GetButtonDown("JoyButtonA"))
			{
				if (_joyCategoryFocusIndex >= 0 && _joyCategoryFocusIndex < _categoryFilterKeys.Count)
				{
					OnCategoryFilterClicked(_categoryFilterKeys[_joyCategoryFocusIndex]);
					_joyCategoryFocusIndex = -1;
					UpdateCategoryFilterVisuals();
				}
				else if (_activeTab == 2)
				{
					if (_bankFocusedButton == 0)
					{
						OnBankDeposit();
					}
					else
					{
						OnBankWithdraw();
					}
				}
				else if ((Object)(object)_actionButton != (Object)null && ((Selectable)_actionButton).interactable)
				{
					OnActionButtonClicked();
				}
			}
			if (ZInput.GetButtonDown("JoyButtonX"))
			{
				ToggleFocusedCategory();
			}
			if ((Object)(object)_descScrollRect != (Object)null)
			{
				float num = 2f;
				if (ZInput.GetButton("JoyRStickDown"))
				{
					ScrollRect descScrollRect = _descScrollRect;
					descScrollRect.verticalNormalizedPosition -= num * Time.deltaTime;
					_descScrollRect.verticalNormalizedPosition = Mathf.Clamp01(_descScrollRect.verticalNormalizedPosition);
				}
				if (ZInput.GetButton("JoyRStickUp"))
				{
					ScrollRect descScrollRect2 = _descScrollRect;
					descScrollRect2.verticalNormalizedPosition += num * Time.deltaTime;
					_descScrollRect.verticalNormalizedPosition = Mathf.Clamp01(_descScrollRect.verticalNormalizedPosition);
				}
			}
		}

		private void NavigateCategoryButtons(int dir)
		{
			if (_categoryFilterButtons.Count != 0)
			{
				if (_joyCategoryFocusIndex < 0)
				{
					_joyCategoryFocusIndex = ((dir <= 0) ? (_categoryFilterButtons.Count - 1) : 0);
				}
				else
				{
					_joyCategoryFocusIndex = Mathf.Clamp(_joyCategoryFocusIndex + dir, 0, _categoryFilterButtons.Count - 1);
				}
				UpdateCategoryFilterVisuals();
			}
		}

		private void MoveSelection(int direction)
		{
			if (_activeTab == 0)
			{
				int visibleBuyCount = GetVisibleBuyCount();
				if (visibleBuyCount != 0)
				{
					int num = _selectedBuyIndex + direction;
					num = Mathf.Clamp(num, 0, visibleBuyCount - 1);
					SelectBuyItem(num);
					EnsureItemVisible(num);
				}
			}
			else if (_activeTab == 1)
			{
				int visibleSellCount = GetVisibleSellCount();
				if (visibleSellCount != 0)
				{
					int num2 = _selectedSellIndex + direction;
					num2 = Mathf.Clamp(num2, 0, visibleSellCount - 1);
					SelectSellItem(num2);
					EnsureItemVisible(num2);
				}
			}
			else if (_activeTab == 2)
			{
				_bankFocusedButton = ((direction > 0) ? 1 : 0);
				UpdateBankHighlight();
			}
		}

		private void ToggleFocusedCategory()
		{
			if (_activeTab == 0 && _selectedBuyIndex >= 0)
			{
				List<BuyEntry> filteredBuyEntries = GetFilteredBuyEntries();
				if (_selectedBuyIndex < filteredBuyEntries.Count)
				{
					string category = filteredBuyEntries[_selectedBuyIndex].Category;
					_buyCategoryCollapsed[category] = !(_buyCategoryCollapsed.TryGetValue(category, out var value) && value);
					PopulateCurrentList();
				}
			}
			else if (_activeTab == 1 && _selectedSellIndex >= 0)
			{
				List<SellEntry> filteredSellEntries = GetFilteredSellEntries();
				if (_selectedSellIndex < filteredSellEntries.Count)
				{
					string category2 = filteredSellEntries[_selectedSellIndex].Category;
					_sellCategoryCollapsed[category2] = !(_sellCategoryCollapsed.TryGetValue(category2, out var value2) && value2);
					PopulateCurrentList();
				}
			}
		}

		private void BuildUI()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected O, but got Unknown
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			if (!ExtractAssets())
			{
				HaldorOverhaul.Log.LogError((object)"[TraderUI] Failed to extract Valheim assets.");
				return;
			}
			_canvasGO = new GameObject("HaldorOverhaul_Canvas");
			_canvasGO.transform.SetParent(((Component)this).transform);
			Canvas val = _canvasGO.AddComponent<Canvas>();
			val.renderMode = (RenderMode)0;
			val.sortingOrder = 100;
			CanvasScaler val2 = _canvasGO.AddComponent<CanvasScaler>();
			val2.uiScaleMode = (ScaleMode)1;
			val2.referenceResolution = new Vector2(1920f, 1080f);
			val2.matchWidthOrHeight = 0.5f;
			_canvasGO.AddComponent<GraphicRaycaster>();
			GameObject val3 = new GameObject("Overlay", new Type[1] { typeof(RectTransform) });
			val3.transform.SetParent(_canvasGO.transform, false);
			RectTransform component = val3.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			((Graphic)val3.AddComponent<Image>()).color = ColOverlay;
			_mainPanel = new GameObject("MainPanel", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			_mainPanel.transform.SetParent(_canvasGO.transform, false);
			RectTransform component2 = _mainPanel.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0.5f, 0.5f);
			component2.anchorMax = new Vector2(0.5f, 0.5f);
			component2.pivot = new Vector2(0.5f, 0.5f);
			component2.sizeDelta = new Vector2(_panelWidth, _panelHeight);
			component2.anchoredPosition = Vector2.zero;
			Image component3 = _mainPanel.GetComponent<Image>();
			if ((Object)(object)_bgSprite != (Object)null)
			{
				component3.sprite = _bgSprite;
				component3.type = (Type)0;
				component3.preserveAspect = false;
				((Graphic)component3).color = Color.white;
			}
			else
			{
				((Graphic)component3).color = new Color(0.18f, 0.14f, 0.09f, 0.92f);
			}
			float num = _leftPad + _leftColWidth + 4f;
			float num2 = num + _midColWidth + 4f;
			_leftColumn = CreateColumn("LeftColumn", _leftPad, _leftPad + _leftColWidth);
			_middleColumn = CreateColumn("MiddleColumn", num, num + _midColWidth);
			_rightColumn = CreateColumn("RightColumn", num2, num2 + _rightColWidth);
			BuildItemListArea();
			BuildDescriptionColumn();
			BuildPreviewColumn();
			_tabBuy = CreateTabButton("Buy", 0, _leftPad + _leftColWidth / 2f, _leftColWidth, 6f);
			_tabSell = CreateTabButton("Sell", 1, num + _midColWidth / 2f, _midColWidth, 6f);
			_tabBank = CreateTabButton("Bank", 2, num2 + _rightColWidth / 2f, _rightColWidth, 6f);
			BuildBankPanel();
			_canvasGO.SetActive(false);
			_uiBuilt = true;
		}

		private bool ExtractAssets()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_crafting == (Object)null)
			{
				return false;
			}
			Texture2D val = TextureLoader.LoadUITexture("PanelBackground");
			if ((Object)(object)val != (Object)null)
			{
				_bgSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			}
			_recipeElementPrefab = instance.m_recipeElementPrefab;
			if ((Object)(object)_recipeElementPrefab == (Object)null)
			{
				return false;
			}
			Texture2D val2 = TextureLoader.LoadUITexture("SearchBarBackground");
			if ((Object)(object)val2 != (Object)null)
			{
				_textFieldSprite = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f));
			}
			Texture2D val3 = TextureLoader.LoadUITexture("CategoryBackground");
			if ((Object)(object)val3 != (Object)null)
			{
				_catBtnSprite = Sprite.Create(val3, new Rect(0f, 0f, (float)((Texture)val3).width, (float)((Texture)val3).height), new Vector2(0.5f, 0.5f));
			}
			_craftBtnHeight = 30f;
			Rect rect;
			if ((Object)(object)instance.m_craftButton != (Object)null)
			{
				RectTransform component = ((Component)instance.m_craftButton).GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					rect = component.rect;
					_craftBtnHeight = Mathf.Max(((Rect)(ref rect)).height, 30f);
				}
				_buttonTemplate = Object.Instantiate<GameObject>(((Component)instance.m_craftButton).gameObject);
				((Object)_buttonTemplate).name = "ButtonTemplate";
				_buttonTemplate.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)_buttonTemplate);
			}
			if ((Object)(object)instance.m_recipeListRoot != (Object)null)
			{
				ScrollRect componentInParent = ((Component)instance.m_recipeListRoot).GetComponentInParent<ScrollRect>();
				if ((Object)(object)componentInParent != (Object)null)
				{
					_scrollSensitivity = componentInParent.scrollSensitivity;
				}
			}
			_valheimFont = FindValheimFont();
			RectTransform component2 = ((Component)instance.m_crafting).GetComponent<RectTransform>();
			rect = component2.rect;
			float width = ((Rect)(ref rect)).width;
			rect = component2.rect;
			float num = ((Rect)(ref rect)).height;
			if (width <= 10f)
			{
				width = 567f;
			}
			if (num <= 10f)
			{
				num = 480f;
			}
			float num2 = 260f;
			Transform val4 = ((Component)instance.m_crafting).transform.Find("Decription");
			if ((Object)(object)val4 != (Object)null)
			{
				RectTransform val5 = (RectTransform)(object)((val4 is RectTransform) ? val4 : null);
				if ((Object)(object)val5 != (Object)null)
				{
					rect = val5.rect;
					float width2 = ((Rect)(ref rect)).width;
					if (width2 > 10f)
					{
						num2 = width2;
					}
				}
			}
			_leftColWidth = num2;
			_midColWidth = num2 + 80f;
			_rightColWidth = num2;
			_leftPad = 6f;
			float num3 = _leftColWidth + 4f + _midColWidth + 4f + _rightColWidth;
			_panelWidth = num3 + 12f;
			_panelHeight = num * 0.9f;
			_bottomPad = 6f;
			_tabBtnHeight = Mathf.Max(_craftBtnHeight, 30f);
			_colTopInset = 6f + _tabBtnHeight + 6f;
			return true;
		}

		private RectTransform CreateColumn(string name, float xLeft, float xRight)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent(_mainPanel.transform, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(0f, 1f);
			component.pivot = new Vector2(0f, 0.5f);
			component.offsetMin = new Vector2(xLeft, _bottomPad);
			component.offsetMax = new Vector2(xRight, 0f - _colTopInset);
			ApplyPanelStyle(val.GetComponent<Image>());
			return component;
		}

		private void BuildItemListArea()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			BuildSearchBox();
			BuildCategoryFilterRow();
			GameObject val = new GameObject("ItemListScroll", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Mask)
			});
			val.transform.SetParent((Transform)(object)_leftColumn, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = new Vector2(2f, 2f);
			component.offsetMax = new Vector2(-2f, -80f);
			((Graphic)val.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.01f);
			val.GetComponent<Mask>().showMaskGraphic = false;
			GameObject val2 = new GameObject("Content", new Type[1] { typeof(RectTransform) });
			val2.transform.SetParent(val.transform, false);
			_listRoot = val2.GetComponent<RectTransform>();
			_listRoot.anchorMin = new Vector2(0f, 1f);
			_listRoot.anchorMax = new Vector2(1f, 1f);
			_listRoot.pivot = new Vector2(0.5f, 1f);
			_listRoot.anchoredPosition = Vector2.zero;
			_listRoot.sizeDelta = Vector2.zero;
			Scrollbar verticalScrollbar = CreateHiddenScrollbar((Transform)(object)_leftColumn);
			_listScrollRect = val.AddComponent<ScrollRect>();
			_listScrollRect.content = _listRoot;
			_listScrollRect.viewport = component;
			_listScrollRect.vertical = true;
			_listScrollRect.horizontal = false;
			_listScrollRect.movementType = (MovementType)2;
			_listScrollRect.scrollSensitivity = _scrollSensitivity * 4f;
			_listScrollRect.verticalScrollbar = verticalScrollbar;
			_listScrollRect.verticalScrollbarVisibility = (ScrollbarVisibility)0;
		}

		private void BuildSearchBox()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Expected O, but got Unknown
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Expected O, but got Unknown
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("SearchField", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent((Transform)(object)_leftColumn, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(0.5f, 1f);
			component.sizeDelta = new Vector2(0f, 32f);
			component.anchoredPosition = new Vector2(0f, -2f);
			Image component2 = val.GetComponent<Image>();
			if ((Object)(object)_textFieldSprite != (Object)null)
			{
				component2.sprite = _textFieldSprite;
				component2.type = (Type)1;
				((Graphic)component2).color = Color.white;
			}
			else
			{
				((Graphic)component2).color = new Color(0.12f, 0.08f, 0.04f, 0.9f);
			}
			GameObject val2 = new GameObject("TextArea", new Type[2]
			{
				typeof(RectTransform),
				typeof(RectMask2D)
			});
			val2.transform.SetParent(val.transform, false);
			RectTransform component3 = val2.GetComponent<RectTransform>();
			component3.anchorMin = Vector2.zero;
			component3.anchorMax = Vector2.one;
			component3.offsetMin = new Vector2(8f, 2f);
			component3.offsetMax = new Vector2(-8f, -2f);
			GameObject val3 = new GameObject("Placeholder", new Type[1] { typeof(RectTransform) });
			val3.SetActive(false);
			val3.transform.SetParent(val2.transform, false);
			TextMeshProUGUI val4 = val3.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)_valheimFont != (Object)null)
			{
				((TMP_Text)val4).font = _valheimFont;
			}
			((TMP_Text)val4).text = "Search...";
			((TMP_Text)val4).fontSize = 16f;
			((Graphic)val4).color = new Color(0.6f, 0.55f, 0.45f, 0.7f);
			((TMP_Text)val4).alignment = (TextAlignmentOptions)4097;
			RectTransform component4 = val3.GetComponent<RectTransform>();
			component4.anchorMin = Vector2.zero;
			component4.anchorMax = Vector2.one;
			component4.offsetMin = Vector2.zero;
			component4.offsetMax = Vector2.zero;
			val3.SetActive(true);
			GameObject val5 = new GameObject("Text", new Type[1] { typeof(RectTransform) });
			val5.SetActive(false);
			val5.transform.SetParent(val2.transform, false);
			TextMeshProUGUI val6 = val5.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)_valheimFont != (Object)null)
			{
				((TMP_Text)val6).font = _valheimFont;
			}
			((TMP_Text)val6).fontSize = 16f;
			((Graphic)val6).color = Color.white;
			((TMP_Text)val6).alignment = (TextAlignmentOptions)4097;
			RectTransform component5 = val5.GetComponent<RectTransform>();
			component5.anchorMin = Vector2.zero;
			component5.anchorMax = Vector2.one;
			component5.offsetMin = Vector2.zero;
			component5.offsetMax = Vector2.zero;
			val5.SetActive(true);
			_searchInput = val.AddComponent<TMP_InputField>();
			_searchInput.textViewport = component3;
			_searchInput.textComponent = (TMP_Text)(object)val6;
			_searchInput.placeholder = (Graphic)(object)val4;
			if ((Object)(object)_valheimFont != (Object)null)
			{
				_searchInput.fontAsset = _valheimFont;
			}
			_searchInput.pointSize = 16f;
			_searchInput.characterLimit = 50;
			((UnityEvent<string>)(object)_searchInput.onValueChanged).AddListener((UnityAction<string>)OnSearchChanged);
		}

		private void BuildCategoryFilterRow()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			GameObject val = new GameObject("CategoryFilterRow", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent((Transform)(object)_leftColumn, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(0.5f, 1f);
			component.sizeDelta = new Vector2(-4f, 38f);
			component.anchoredPosition = new Vector2(0f, -38f);
			((Graphic)val.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0f);
			HorizontalLayoutGroup val2 = val.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)val2).spacing = 2f;
			((LayoutGroup)val2).padding = new RectOffset(2, 2, 2, 2);
			((LayoutGroup)val2).childAlignment = (TextAnchor)4;
			((HorizontalOrVerticalLayoutGroup)val2).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)val2).childForceExpandHeight = true;
			((HorizontalOrVerticalLayoutGroup)val2).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)val2).childControlHeight = true;
			_categoryFilterButtons.Clear();
			_categoryFilterKeys.Clear();
			Dictionary<string, string> dictionary = new Dictionary<string, string>
			{
				{ "Weapons", "AxeBronze" },
				{ "Armor", "HelmetTrollLeather" },
				{ "Shields", "ShieldWood" },
				{ "Ammo", "ArrowObsidian" },
				{ "Consumables", "MeadStaminaMinor" },
				{ "Materials", "Bronze" },
				{ "Utility", "BeltStrength" },
				{ "Trophies", "TrophySkeleton" },
				{ "Misc", "Coins" }
			};
			string[] categoryBuckets = CategoryBuckets;
			foreach (string text in categoryBuckets)
			{
				string value;
				string text2 = (dictionary.TryGetValue(text, out value) ? value : null);
				Sprite icon = ((text2 != null) ? GetItemIcon(text2) : null);
				Button val3 = CreateCategoryFilterButton(val.transform, text, icon);
				if ((Object)(object)val3 != (Object)null)
				{
					_categoryFilterButtons.Add(val3);
					_categoryFilterKeys.Add(text);
				}
			}
			UpdateCategoryFilterVisuals();
		}

		private Button CreateCategoryFilterButton(Transform parent, string category, Sprite icon)
		{
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Expected O, but got Unknown
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_buttonTemplate == (Object)null)
			{
				return null;
			}
			GameObject val = Object.Instantiate<GameObject>(_buttonTemplate, parent);
			((Object)val).name = "CatBtn_" + category;
			val.SetActive(true);
			for (int num = val.transform.childCount - 1; num >= 0; num--)
			{
				Object.DestroyImmediate((Object)(object)((Component)val.transform.GetChild(num)).gameObject);
			}
			Animator component = val.GetComponent<Animator>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			ContentSizeFitter component2 = val.GetComponent<ContentSizeFitter>();
			if ((Object)(object)component2 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component2);
			}
			LayoutElement component3 = val.GetComponent<LayoutElement>();
			if ((Object)(object)component3 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component3);
			}
			Image component4 = val.GetComponent<Image>();
			if ((Object)(object)component4 != (Object)null)
			{
				if ((Object)(object)_catBtnSprite != (Object)null)
				{
					component4.sprite = _catBtnSprite;
					component4.type = (Type)1;
				}
				((Graphic)component4).color = Color.white;
			}
			Button component5 = val.GetComponent<Button>();
			if ((Object)(object)component5 != (Object)null)
			{
				((UnityEventBase)component5.onClick).RemoveAllListeners();
				((Selectable)component5).transition = (Transition)1;
				string cat = category;
				((UnityEvent)component5.onClick).AddListener((UnityAction)delegate
				{
					OnCategoryFilterClicked(cat);
				});
				Navigation navigation = default(Navigation);
				((Navigation)(ref navigation)).mode = (Mode)0;
				((Selectable)component5).navigation = navigation;
				ColorBlock colors = ((Selectable)component5).colors;
				((ColorBlock)(ref colors)).normalColor = Color.white;
				((ColorBlock)(ref colors)).highlightedColor = new Color(0.85f, 0.85f, 0.85f, 1f);
				((ColorBlock)(ref colors)).pressedColor = new Color(0.65f, 0.65f, 0.65f, 1f);
				((ColorBlock)(ref colors)).selectedColor = Color.white;
				((ColorBlock)(ref colors)).colorMultiplier = 1f;
				((ColorBlock)(ref colors)).fadeDuration = 0.08f;
				((Selectable)component5).colors = colors;
			}
			if ((Object)(object)icon != (Object)null)
			{
				GameObject val2 = new GameObject("Icon", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				val2.transform.SetParent(val.transform, false);
				RectTransform component6 = val2.GetComponent<RectTransform>();
				component6.anchorMin = new Vector2(0.15f, 0.15f);
				component6.anchorMax = new Vector2(0.85f, 0.85f);
				component6.offsetMin = Vector2.zero;
				component6.offsetMax = Vector2.zero;
				Image component7 = val2.GetComponent<Image>();
				component7.sprite = icon;
				component7.preserveAspect = true;
				((Graphic)component7).raycastTarget = false;
			}
			return component5;
		}

		private void OnCategoryFilterClicked(string category)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			_activeCategoryFilter = ((_activeCategoryFilter == category) ? null : category);
			_selectedBuyIndex = -1;
			_selectedSellIndex = -1;
			UpdateCategoryFilterVisuals();
			if ((Object)(object)_listScrollRect != (Object)null)
			{
				_listScrollRect.verticalNormalizedPosition = 1f;
				_listScrollRect.velocity = Vector2.zero;
			}
			PopulateCurrentList();
		}

		private void UpdateCategoryFilterVisuals()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < _categoryFilterButtons.Count; i++)
			{
				Button val = _categoryFilterButtons[i];
				if (!((Object)(object)val == (Object)null))
				{
					bool flag = _activeCategoryFilter == _categoryFilterKeys[i];
					bool flag2 = _joyCategoryFocusIndex == i;
					Image component = ((Component)val).GetComponent<Image>();
					if ((Object)(object)component != (Object)null)
					{
						((Graphic)component).color = (Color)(flag ? new Color(1f, 0.75f, 0.3f, 1f) : (flag2 ? new Color(0.85f, 0.75f, 0.6f, 1f) : Color.white));
					}
				}
			}
		}

		private static Sprite GetItemIcon(string prefabName)
		{
			if ((Object)(object)ObjectDB.instance == (Object)null)
			{
				return null;
			}
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefabName);
			ItemDrop val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
			if (val == null)
			{
				return null;
			}
			ItemData itemData = val.m_itemData;
			if (itemData == null)
			{
				return null;
			}
			return itemData.GetIcon();
		}

		private static Sprite FindSpriteByName(string spriteName)
		{
			Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
			foreach (Sprite val in array)
			{
				if ((Object)(object)val != (Object)null && ((Object)val).name.Equals(spriteName, StringComparison.OrdinalIgnoreCase))
				{
					return val;
				}
			}
			return null;
		}

		private void BuildDescriptionColumn()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0497: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Expected O, but got Unknown
			//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04db: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0516: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Expected O, but got Unknown
			//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_060d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0623: Unknown result type (might be due to invalid IL or missing references)
			//IL_0639: Unknown result type (might be due to invalid IL or missing references)
			//IL_0645: Unknown result type (might be due to invalid IL or missing references)
			//IL_0651: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Expected O, but got Unknown
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Expected O, but got Unknown
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			float craftBtnHeight = _craftBtnHeight;
			GameObject val = new GameObject("ItemName", new Type[1] { typeof(RectTransform) });
			val.SetActive(false);
			val.transform.SetParent((Transform)(object)_middleColumn, false);
			_itemNameText = (TMP_Text)(object)val.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)_valheimFont != (Object)null)
			{
				_itemNameText.font = _valheimFont;
			}
			_itemNameText.fontSize = 24f;
			((Graphic)_itemNameText).color = Color.white;
			_itemNameText.alignment = (TextAlignmentOptions)514;
			_itemNameText.text = "";
			val.SetActive(true);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(0.5f, 1f);
			component.sizeDelta = new Vector2(-20f, 32f);
			component.anchoredPosition = new Vector2(0f, -4f);
			GameObject val2 = new GameObject("CoinDisplay", new Type[1] { typeof(RectTransform) });
			val2.SetActive(false);
			val2.transform.SetParent((Transform)(object)_middleColumn, false);
			_coinDisplayText = (TMP_Text)(object)val2.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)_valheimFont != (Object)null)
			{
				_coinDisplayText.font = _valheimFont;
			}
			_coinDisplayText.fontSize = 24f;
			((Graphic)_coinDisplayText).color = GoldTextColor;
			_coinDisplayText.alignment = (TextAlignmentOptions)514;
			_coinDisplayText.text = "Coins: 0";
			val2.SetActive(true);
			RectTransform component2 = val2.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0f, 0f);
			component2.anchorMax = new Vector2(1f, 0f);
			component2.pivot = new Vector2(0.5f, 0f);
			component2.sizeDelta = new Vector2(-24f, 24f);
			component2.anchoredPosition = new Vector2(0f, craftBtnHeight + 14f);
			if ((Object)(object)_buttonTemplate != (Object)null)
			{
				GameObject val3 = Object.Instantiate<GameObject>(_buttonTemplate, (Transform)(object)_middleColumn);
				((Object)val3).name = "ActionButton";
				val3.SetActive(true);
				_actionButton = val3.GetComponent<Button>();
				if ((Object)(object)_actionButton != (Object)null)
				{
					((UnityEventBase)_actionButton.onClick).RemoveAllListeners();
					((UnityEvent)_actionButton.onClick).AddListener(new UnityAction(OnActionButtonClicked));
					((Selectable)_actionButton).interactable = false;
					Button actionButton = _actionButton;
					Navigation navigation = default(Navigation);
					((Navigation)(ref navigation)).mode = (Mode)0;
					((Selectable)actionButton).navigation = navigation;
				}
				_actionButtonLabel = val3.GetComponentInChildren<TMP_Text>(true);
				if ((Object)(object)_actionButtonLabel != (Object)null)
				{
					((Component)_actionButtonLabel).gameObject.SetActive(true);
					_actionButtonLabel.text = "Select an item";
				}
				StripButtonHints(val3, _actionButtonLabel);
				GameObject val4 = new GameObject("Tint", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				val4.transform.SetParent(val3.transform, false);
				val4.transform.SetAsFirstSibling();
				RectTransform component3 = val4.GetComponent<RectTransform>();
				component3.anchorMin = Vector2.zero;
				component3.anchorMax = Vector2.one;
				component3.offsetMin = Vector2.zero;
				component3.offsetMax = Vector2.zero;
				Image component4 = val4.GetComponent<Image>();
				((Graphic)component4).color = new Color(0f, 0f, 0f, 0.75f);
				((Graphic)component4).raycastTarget = false;
				RectTransform component5 = val3.GetComponent<RectTransform>();
				component5.anchorMin = new Vector2(0f, 0f);
				component5.anchorMax = new Vector2(1f, 0f);
				component5.pivot = new Vector2(0.5f, 0f);
				component5.sizeDelta = new Vector2(-24f, craftBtnHeight);
				component5.anchoredPosition = new Vector2(0f, 8f);
			}
			float num = craftBtnHeight + 44f;
			GameObject val5 = new GameObject("DescScrollArea", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Mask)
			});
			val5.transform.SetParent((Transform)(object)_middleColumn, false);
			RectTransform component6 = val5.GetComponent<RectTransform>();
			component6.anchorMin = Vector2.zero;
			component6.anchorMax = Vector2.one;
			component6.offsetMin = new Vector2(8f, num);
			component6.offsetMax = new Vector2(-14f, -38f);
			((Graphic)val5.GetComponent<Image>()).color = new Color(1f, 1f, 1f, 0.003f);
			val5.GetComponent<Mask>().showMaskGraphic = false;
			GameObject val6 = new GameObject("DescText", new Type[1] { typeof(RectTransform) });
			val6.SetActive(false);
			val6.transform.SetParent(val5.transform, false);
			_itemDescText = (TMP_Text)(object)val6.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)_valheimFont != (Object)null)
			{
				_itemDescText.font = _valheimFont;
			}
			_itemDescText.fontSize = 18f;
			((Graphic)_itemDescText).color = Color.white;
			_itemDescText.alignment = (TextAlignmentOptions)257;
			_itemDescText.textWrappingMode = (TextWrappingModes)1;
			_itemDescText.overflowMode = (TextOverflowModes)0;
			_itemDescText.richText = true;
			_itemDescText.text = "";
			RectTransform component7 = val6.GetComponent<RectTransform>();
			component7.anchorMin = new Vector2(0f, 1f);
			component7.anchorMax = new Vector2(1f, 1f);
			component7.pivot = new Vector2(0.5f, 1f);
			component7.anchoredPosition = Vector2.zero;
			component7.sizeDelta = Vector2.zero;
			val6.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			val6.SetActive(true);
			Scrollbar verticalScrollbar = CreateHiddenScrollbar((Transform)(object)_middleColumn);
			_descScrollRect = val5.AddComponent<ScrollRect>();
			_descScrollRect.content = component7;
			_descScrollRect.viewport = component6;
			_descScrollRect.vertical = true;
			_descScrollRect.horizontal = false;
			_descScrollRect.movementType = (MovementType)2;
			_descScrollRect.scrollSensitivity = _scrollSensitivity * 8f;
			_descScrollRect.verticalScrollbar = verticalScrollbar;
			_descScrollRect.verticalScrollbarVisibility = (ScrollbarVisibility)0;
		}

		private void BuildPreviewColumn()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Expected O, but got Unknown
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Expected O, but got Unknown
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			float rightColWidth = _rightColWidth;
			float num = _panelHeight - _colTopInset - _bottomPad;
			int num2 = 4;
			int num3 = Mathf.Max(64, Mathf.RoundToInt(rightColWidth) * num2);
			int num4 = Mathf.Max(64, Mathf.RoundToInt(num) * num2);
			_playerPreviewRT = new RenderTexture(num3, num4, 24, (RenderTextureFormat)0);
			_playerPreviewRT.antiAliasing = 4;
			((Texture)_playerPreviewRT).filterMode = (FilterMode)2;
			_playerCamGO = new GameObject("TraderUI_PlayerCam");
			Object.DontDestroyOnLoad((Object)(object)_playerCamGO);
			_playerCam = _playerCamGO.AddComponent<Camera>();
			_playerCam.targetTexture = _playerPreviewRT;
			_playerCam.clearFlags = (CameraClearFlags)2;
			_playerCam.backgroundColor = new Color(0f, 0f, 0f, 0f);
			_playerCam.fieldOfView = 30f;
			_playerCam.nearClipPlane = 0.1f;
			_playerCam.farClipPlane = 10f;
			_playerCam.depth = -2f;
			((Behaviour)_playerCam).enabled = false;
			int num5 = LayerMask.NameToLayer("character");
			if (num5 < 0)
			{
				num5 = 9;
			}
			int num6 = LayerMask.NameToLayer("character_net");
			int num7 = 1 << num5;
			if (num6 >= 0)
			{
				num7 |= 1 << num6;
			}
			_playerCam.cullingMask = num7;
			_haldorPreviewRT = new RenderTexture(num3, num4, 24, (RenderTextureFormat)0);
			_haldorPreviewRT.antiAliasing = 4;
			((Texture)_haldorPreviewRT).filterMode = (FilterMode)2;
			_haldorCamGO = new GameObject("TraderUI_HaldorCam");
			Object.DontDestroyOnLoad((Object)(object)_haldorCamGO);
			_haldorCam = _haldorCamGO.AddComponent<Camera>();
			_haldorCam.targetTexture = _haldorPreviewRT;
			_haldorCam.clearFlags = (CameraClearFlags)2;
			_haldorCam.backgroundColor = new Color(0f, 0f, 0f, 0f);
			_haldorCam.fieldOfView = 30f;
			_haldorCam.nearClipPlane = 0.1f;
			_haldorCam.farClipPlane = 10f;
			_haldorCam.depth = -2f;
			((Behaviour)_haldorCam).enabled = false;
			_haldorCam.cullingMask = num7;
			GameObject val = new GameObject("PlayerPreview", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent((Transform)(object)_rightColumn, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			_playerPreviewImg = val.AddComponent<RawImage>();
			_playerPreviewImg.texture = (Texture)(object)_playerPreviewRT;
			((Graphic)_playerPreviewImg).color = Color.white;
			((Graphic)_playerPreviewImg).raycastTarget = false;
			GameObject val2 = new GameObject("HaldorPreview", new Type[1] { typeof(RectTransform) });
			val2.transform.SetParent((Transform)(object)_rightColumn, false);
			RectTransform component2 = val2.GetComponent<RectTransform>();
			component2.anchorMin = Vector2.zero;
			component2.anchorMax = Vector2.one;
			component2.offsetMin = Vector2.zero;
			component2.offsetMax = Vector2.zero;
			_haldorPreviewImg = val2.AddComponent<RawImage>();
			_haldorPreviewImg.texture = (Texture)(object)_haldorPreviewRT;
			((Graphic)_haldorPreviewImg).color = Color.white;
			((Graphic)_haldorPreviewImg).raycastTarget = false;
		}

		private void ApplyPanelStyle(Image img)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)img == (Object)null))
			{
				img.sprite = null;
				((Graphic)img).color = new Color(0f, 0f, 0f, 0.75f);
			}
		}

		private Scrollbar CreateHiddenScrollbar(Transform parent)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			float num = 10f;
			GameObject val = new GameObject("Scrollbar", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(1f, 0f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(1f, 0.5f);
			component.sizeDelta = new Vector2(num, 0f);
			component.offsetMin = new Vector2(0f - num, 4f);
			component.offsetMax = new Vector2(-2f, -4f);
			((Graphic)val.AddComponent<Image>()).color = Color.clear;
			GameObject val2 = new GameObject("Sliding Area", new Type[1] { typeof(RectTransform) });
			val2.transform.SetParent(val.transform, false);
			RectTransform component2 = val2.GetComponent<RectTransform>();
			component2.anchorMin = Vector2.zero;
			component2.anchorMax = Vector2.one;
			component2.offsetMin = Vector2.zero;
			component2.offsetMax = Vector2.zero;
			GameObject val3 = new GameObject("Handle", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val3.transform.SetParent(val2.transform, false);
			RectTransform component3 = val3.GetComponent<RectTransform>();
			component3.anchorMin = Vector2.zero;
			component3.anchorMax = Vector2.one;
			component3.offsetMin = Vector2.zero;
			component3.offsetMax = Vector2.zero;
			((Graphic)val3.GetComponent<Image>()).color = Color.clear;
			Scrollbar val4 = val.AddComponent<Scrollbar>();
			val4.handleRect = component3;
			val4.direction = (Direction)2;
			((Selectable)val4).targetGraphic = (Graphic)(object)val3.GetComponent<Image>();
			return val4;
		}

		private GameObject CreateTabButton(string label, int tabIndex, float centerX, float width, float topGap)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to inval