Decompiled source of EconomyInfo v1.3.4

EconomyInfo.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EconomyInfo.money_inventory;
using EconomyInfo.money_vendor;
using EconomyInfo.tools;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("EconomyInfo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EconomyInfo")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("aae89eab-0761-4012-a8ed-ceadc086e98c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace EconomyInfo
{
	[BepInPlugin("Turbero.EconomyInfo", "Economy Info", "1.3.4")]
	public class EconomyInfo : BaseUnityPlugin
	{
		public const string GUID = "Turbero.EconomyInfo";

		public const string NAME = "Economy Info";

		public const string VERSION = "1.3.4";

		private readonly Harmony harmony = new Harmony("Turbero.EconomyInfo");

		private void Awake()
		{
			ConfigurationFile.LoadConfig((BaseUnityPlugin)(object)this);
			harmony.PatchAll();
		}

		private void onDestroy()
		{
			harmony.UnpatchSelf();
		}
	}
}
namespace EconomyInfo.tools
{
	internal class ConfigurationFile
	{
		public static ConfigEntry<bool> debug;

		public static ConfigEntry<bool> showInventoryMoneyBalance;

		public static ConfigEntry<bool> showContainerMoneyBalance;

		public static ConfigEntry<bool> advancedVendorMoneyPanel;

		private static ConfigFile configFile;

		private static string ConfigFileName = "Turbero.EconomyInfo.cfg";

		private static string ConfigFileFullPath;

		internal static void LoadConfig(BaseUnityPlugin plugin)
		{
			configFile = plugin.Config;
			debug = configFile.Bind<bool>("1 - General", "DebugMode", false, "Enabling/Disabling the debugging in the console (default = false)");
			showInventoryMoneyBalance = configFile.Bind<bool>("2 - Features", "Show Inventory Money Balance", true, "Enable/disable the inventory money balance (default = true)");
			showContainerMoneyBalance = configFile.Bind<bool>("2 - Features", "Show Container Money Balance", true, "Enable/disable the container money balance (default = true)");
			advancedVendorMoneyPanel = configFile.Bind<bool>("2 - Features", "Show Advanced Vendor Money Balance", true, "Enabling/disabling the advanced money balance with all valuables at the vendor window (default = true)");
			SetupWatcher();
		}

		private static void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private static void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(ConfigFileFullPath))
			{
				return;
			}
			try
			{
				Logger.Log("Attempting to reload configuration...");
				configFile.Reload();
				SettingsChanged(null, null);
			}
			catch (Exception arg)
			{
				Logger.LogError($"There was an issue loading {ConfigFileName}, {arg}");
			}
		}

		private static void SettingsChanged(object sender, EventArgs e)
		{
			if ((Object)(object)GameObject.Find("Store") != (Object)null)
			{
				MoneyStoreGuiShowPatch.enable(advancedVendorMoneyPanel.Value);
			}
			MoneyPanel moneyPanelInventory = InventoryGui_Show_Patch.moneyPanelInventory;
			if (moneyPanelInventory != null)
			{
				moneyPanelInventory.getGameObject().SetActive(showInventoryMoneyBalance.Value);
			}
			MoneyPanel moneyPanelContainer = InventoryGui_Show_Patch.moneyPanelContainer;
			if (moneyPanelContainer != null)
			{
				moneyPanelContainer.getGameObject().SetActive(showContainerMoneyBalance.Value);
			}
		}

		static ConfigurationFile()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
		}
	}
	public static class Logger
	{
		public static ManualLogSource logger = Logger.CreateLogSource("Economy Info");

		internal static void Log(object s)
		{
			if (ConfigurationFile.debug.Value)
			{
				logger.LogInfo((object)s?.ToString());
			}
		}

		internal static void LogInfo(object s)
		{
			logger.LogInfo((object)s?.ToString());
		}

		internal static void LogWarning(object s)
		{
			string text = "Economy Info 1.3.4: " + ((s != null) ? s.ToString() : "null");
			Debug.LogWarning((object)text);
		}

		internal static void LogError(object s)
		{
			string text = "Economy Info 1.3.4: " + ((s != null) ? s.ToString() : "null");
			Debug.LogError((object)text);
		}
	}
	public class ModUtils
	{
		private static Dictionary<string, Sprite> cachedSprites = new Dictionary<string, Sprite>();

		public static Sprite getSprite(string name)
		{
			if (!cachedSprites.ContainsKey(name))
			{
				Logger.Log("Finding " + name + " sprite...");
				Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
				foreach (Sprite val in array)
				{
					if (((Object)val).name == name)
					{
						Logger.Log(name + " sprite found.");
						cachedSprites.Add(name, val);
						return val;
					}
				}
				Logger.Log(name + " sprite NOT found.");
				return null;
			}
			return GeneralExtensions.GetValueSafe<string, Sprite>(cachedSprites, name);
		}

		public static void RunPrivateMethod(object obj, string name, object[] parameters = null, BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic)
		{
			obj.GetType().GetMethod(name, bindingAttr)?.Invoke(obj, parameters);
		}
	}
}
namespace EconomyInfo.money_vendor
{
	public static class TraderChecks
	{
		public static bool HasStoreGuiValidTrader()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			Trader val = (Trader)(typeof(StoreGui).GetField("m_trader", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(StoreGui.instance));
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Logger.Log("Trader.m_name: " + val.m_name);
			return true;
		}
	}
	[HarmonyPatch(typeof(StoreGui), "GetSellableItem")]
	public class MoneyStoreGuiSelectedItemPatch
	{
		public static string lastValuableToSell;

		public static void Postfix(StoreGui __instance, ref ItemData __result)
		{
			if (lastValuableToSell == null)
			{
				return;
			}
			foreach (ItemData allItem in ((Humanoid)Player.m_localPlayer).GetInventory().GetAllItems())
			{
				if (allItem.m_shared.m_name == lastValuableToSell)
				{
					Logger.Log(lastValuableToSell + " found in inventory to sell!");
					__result = allItem;
					return;
				}
			}
			__result = null;
		}
	}
	[HarmonyPatch(typeof(StoreGui), "Show")]
	public class MoneyStoreGuiShowPatch
	{
		private static VendorPanelValuable rubyPanel;

		private static VendorPanelValuable amberPanel;

		private static VendorPanelValuable pearlPanel;

		private static VendorPanelValuable silverNecklacePanel;

		private static VendorPanelValuable ancientCoinPanel;

		private static VendorPanelValuable grimvarnPanel;

		private static VendorPanelValuable solrythPanel;

		private static VendorPanelValuable veydrisPanel;

		private static VendorPanelValuable draumyxPanel;

		public static bool panelsCreated;

		public static void Postfix(StoreGui __instance, Trader trader)
		{
			if (!((Object)(object)trader == (Object)null))
			{
				Logger.Log("Trader.m_name: " + trader.m_name);
				createPanels();
				enable(ConfigurationFile.advancedVendorMoneyPanel.Value);
			}
		}

		public static void enable(bool enable)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = GameObject.Find("Store").transform;
			if (enable)
			{
				resize();
				updateValuables();
			}
			else
			{
				((Component)transform.Find("border (1)")).GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, 0f);
				((Component)transform.Find("border (1)")).GetComponent<RectTransform>().sizeDelta = new Vector2(40f, 40f);
				((Component)transform.Find("SellPanel")).GetComponent<RectTransform>().anchoredPosition = new Vector2(350f, -16f);
				enableValuablePanels(enable: false);
			}
			updateCoinsColor();
		}

		private static void resize()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.Find("Store");
			Transform val = ((obj != null) ? obj.transform : null);
			if ((Object)(object)val != (Object)null)
			{
				((Component)val.Find("border (1)")).GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, -100f);
				((Component)val.Find("border (1)")).GetComponent<RectTransform>().sizeDelta = new Vector2(200f, 260f);
				((Component)val.Find("SellPanel")).GetComponent<RectTransform>().anchoredPosition = new Vector2(430f, 20f);
				enableValuablePanels(enable: true);
			}
		}

		private static void createPanels()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: 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_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			if (ConfigurationFile.advancedVendorMoneyPanel.Value && (!panelsCreated || amberPanel == null || !((Object)(object)amberPanel.getMainPanel() != (Object)null)))
			{
				Transform transform = GameObject.Find("Store").transform;
				amberPanel = new VendorPanelValuable(transform, "amberPanel", "amber", new Vector2(-110f, -15f), (Vector2?)new Vector2(20f, 20f), (Vector2?)new Vector2(42f, 42f));
				pearlPanel = new VendorPanelValuable(transform, "amberpearlPanel", "AmberPearl", new Vector2(-110f, -60f), (Vector2?)new Vector2(8f, 32f), (Vector2?)null);
				rubyPanel = new VendorPanelValuable(transform, "rubyPanel", "ruby", new Vector2(-110f, -105f), (Vector2?)new Vector2(20f, 20f), (Vector2?)new Vector2(42f, 42f));
				silverNecklacePanel = new VendorPanelValuable(transform, "silverNecklacePanel", "silvernecklace", new Vector2(-110f, -150f), (Vector2?)new Vector2(18f, 20f), (Vector2?)new Vector2(46f, 46f));
				ancientCoinPanel = new VendorPanelValuable(transform, "ancientCoinPanel", "coin_ancient", new Vector2(0f, -192f), (Vector2?)new Vector2(20f, 20f), (Vector2?)new Vector2(42f, 42f));
				grimvarnPanel = new VendorPanelValuable(transform, "grimvarnPanel", "ancientgemstone_green", new Vector2(100f, -15f), (Vector2?)new Vector2(20f, 20f), (Vector2?)new Vector2(42f, 42f));
				solrythPanel = new VendorPanelValuable(transform, "solrythPanel", "ancientgemstone_orange", new Vector2(100f, -60f), (Vector2?)new Vector2(20f, 20f), (Vector2?)new Vector2(42f, 42f));
				veydrisPanel = new VendorPanelValuable(transform, "veydrisPanel", "ancientgemstone_purple", new Vector2(100f, -105f), (Vector2?)new Vector2(20f, 20f), (Vector2?)new Vector2(42f, 42f));
				draumyxPanel = new VendorPanelValuable(transform, "draumyxPanel", "ancientgemstone_black", new Vector2(100f, -150f), (Vector2?)new Vector2(20f, 20f), (Vector2?)new Vector2(42f, 42f));
				panelsCreated = true;
			}
		}

		private static void enableValuablePanels(bool enable)
		{
			createPanels();
			if (panelsCreated)
			{
				amberPanel.getMainPanel().SetActive(enable);
				pearlPanel.getMainPanel().SetActive(enable);
				rubyPanel.getMainPanel().SetActive(enable);
				silverNecklacePanel.getMainPanel().SetActive(enable);
				ancientCoinPanel.getMainPanel().SetActive(enable);
				grimvarnPanel.getMainPanel().SetActive(enable);
				solrythPanel.getMainPanel().SetActive(enable);
				veydrisPanel.getMainPanel().SetActive(enable);
				draumyxPanel.getMainPanel().SetActive(enable);
			}
		}

		public static void updateValuables()
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			int num5 = 0;
			int num6 = 0;
			int num7 = 0;
			int num8 = 0;
			int num9 = 0;
			int num10 = 0;
			int num11 = 0;
			int num12 = 0;
			int num13 = 0;
			int num14 = 0;
			int num15 = 0;
			int num16 = 0;
			int num17 = 0;
			int num18 = 0;
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				foreach (ItemData allItem in ((Humanoid)Player.m_localPlayer).GetInventory().GetAllItems())
				{
					if (allItem.m_shared.m_value > 0)
					{
						Logger.Log("Found in player inventory: " + allItem.m_shared.m_name + " = " + allItem.m_shared.m_value);
						if (allItem.m_shared.m_name.ToLower().Contains("amberpearl"))
						{
							num2 += allItem.m_stack * allItem.m_shared.m_value;
							num11 += allItem.m_stack;
						}
						else if (allItem.m_shared.m_name.ToLower().Contains("amber"))
						{
							num += allItem.m_stack * allItem.m_shared.m_value;
							num10 += allItem.m_stack;
						}
						else if (allItem.m_shared.m_name.ToLower().Contains("ruby"))
						{
							num3 += allItem.m_stack * allItem.m_shared.m_value;
							num12 += allItem.m_stack;
						}
						else if (allItem.m_shared.m_name.ToLower().Contains("silvernecklace"))
						{
							num4 += allItem.m_stack * allItem.m_shared.m_value;
							num13 += allItem.m_stack;
						}
						else if (allItem.m_shared.m_name.ToLower().Contains("ancientcoin"))
						{
							num5 += allItem.m_stack * allItem.m_shared.m_value;
							num14 += allItem.m_stack;
						}
						else if (allItem.m_shared.m_name.ToLower().Contains("ancientgemstone_green"))
						{
							num6 += allItem.m_stack * allItem.m_shared.m_value;
							num15 += allItem.m_stack;
						}
						else if (allItem.m_shared.m_name.ToLower().Contains("ancientgemstone_orange"))
						{
							num7 += allItem.m_stack * allItem.m_shared.m_value;
							num16 += allItem.m_stack;
						}
						else if (allItem.m_shared.m_name.ToLower().Contains("ancientgemstone_purple"))
						{
							num8 += allItem.m_stack * allItem.m_shared.m_value;
							num17 += allItem.m_stack;
						}
						else if (allItem.m_shared.m_name.ToLower().Contains("ancientgemstone_black"))
						{
							num9 += allItem.m_stack * allItem.m_shared.m_value;
							num18 += allItem.m_stack;
						}
					}
				}
			}
			amberPanel.updateValue(num10, num);
			pearlPanel.updateValue(num11, num2);
			rubyPanel.updateValue(num12, num3);
			silverNecklacePanel.updateValue(num13, num4);
			ancientCoinPanel.updateValue(num14, num5);
			grimvarnPanel.updateValue(num15, num6);
			solrythPanel.updateValue(num16, num7);
			veydrisPanel.updateValue(num17, num8);
			draumyxPanel.updateValue(num18, num9);
			updateCoinsColor();
		}

		public static void updateCoinsColor()
		{
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)GameObject.Find("Store").transform.Find("coins")).transform.Find("coins");
			TextMeshProUGUI component = ((Component)val).GetComponent<TextMeshProUGUI>();
			int num = ((Humanoid)Player.m_localPlayer).GetInventory().CountItems(StoreGui.instance.m_coinPrefab.m_itemData.m_shared.m_name, -1, true);
			Logger.Log("Value to calculate color: " + num);
			if (num == 0 && ConfigurationFile.advancedVendorMoneyPanel.Value)
			{
				((TMP_Text)component).faceColor = Color32.op_Implicit(new Color(255f, 0f, 0f, 255f));
			}
			else
			{
				((TMP_Text)component).faceColor = Color32.op_Implicit(new Color(255f, 255f, 255f, 255f));
			}
		}
	}
	[HarmonyPatch(typeof(StoreGui), "OnSellItem")]
	public class MoneyStoreGuiOnSellItemPatch
	{
		public static void Postfix(StoreGui __instance)
		{
			if (TraderChecks.HasStoreGuiValidTrader())
			{
				Logger.Log("Item sold. Recalculating...");
				MoneyStoreGuiShowPatch.updateValuables();
			}
		}
	}
	[HarmonyPatch(typeof(StoreGui), "OnBuyItem")]
	public class MoneyStoreGuiOnBuyItemPatch
	{
		public static void Postfix(StoreGui __instance)
		{
			if (TraderChecks.HasStoreGuiValidTrader())
			{
				Logger.Log("Item bought. Recalculating...");
				MoneyStoreGuiShowPatch.updateCoinsColor();
			}
		}
	}
	[HarmonyPatch(typeof(Inventory), "Changed")]
	internal class Inventory_Changed_StoreGui_Patch
	{
		public static void Postfix(Inventory __instance)
		{
			Player localPlayer = Player.m_localPlayer;
			if (__instance == ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null) && TraderChecks.HasStoreGuiValidTrader() && (Object)(object)GameObject.Find("Store") != (Object)null && MoneyStoreGuiShowPatch.panelsCreated)
			{
				Logger.Log("Inventory changed while trader opened. Recalculating...");
				MoneyStoreGuiShowPatch.updateValuables();
				MoneyStoreGuiShowPatch.updateCoinsColor();
			}
		}
	}
	public class VendorPanelValuable
	{
		private readonly GameObject vendorPanelValuableGO;

		private readonly UITooltip sellButtonTooltip;

		private readonly string spriteName;

		private readonly Button buttonSellButton;

		public VendorPanelValuable(Transform storeTransform, string valuableName, string spriteName, Vector2 anchoredPosition, Vector2? anchoredPositionIcon = null, Vector2? sizeDeltaIcon = null)
		{
			//IL_005e: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Expected O, but got Unknown
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Expected O, but got Unknown
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			VendorPanelValuable vendorPanelValuable = this;
			this.spriteName = spriteName;
			GameObject gameObject = ((Component)storeTransform.Find("coins")).gameObject;
			vendorPanelValuableGO = Object.Instantiate<GameObject>(gameObject, storeTransform);
			((Object)vendorPanelValuableGO).name = valuableName;
			vendorPanelValuableGO.GetComponent<RectTransform>().anchoredPosition = anchoredPosition;
			Transform child = vendorPanelValuableGO.transform.GetChild(0);
			((Object)child).name = "icon";
			((Component)child).GetComponent<Image>().sprite = ModUtils.getSprite(spriteName);
			if (anchoredPositionIcon.HasValue)
			{
				((Component)child).GetComponent<RectTransform>().anchoredPosition = anchoredPositionIcon.Value;
			}
			if (sizeDeltaIcon.HasValue)
			{
				((Component)child).GetComponent<RectTransform>().sizeDelta = sizeDeltaIcon.Value;
			}
			Transform child2 = vendorPanelValuableGO.transform.GetChild(1);
			((Object)child2).name = "amount";
			((TMP_Text)((Component)child2).GetComponent<TextMeshProUGUI>()).text = "0 (0)";
			GameObject val = Object.Instantiate<GameObject>(GameObject.Find("Store/SellPanel"), vendorPanelValuableGO.transform);
			((Object)val).name = "SellPanel";
			val.GetComponent<RectTransform>().anchoredPosition = new Vector2(245f, 8f);
			val.GetComponent<RectTransform>().sizeDelta = new Vector2(32f, 32f);
			Object.Destroy((Object)(object)val.GetComponent<Image>());
			Transform val2 = val.transform.Find("SellButton");
			((Component)val2).GetComponent<RectTransform>().sizeDelta = new Vector2(32f, 32f);
			((Component)((Component)val2).transform.Find("Image")).GetComponent<RectTransform>().sizeDelta = new Vector2(32f, 32f);
			((Component)((Component)val2).transform.Find("Image")).GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, -3.5f);
			sellButtonTooltip = ((Component)val2).GetComponent<UITooltip>();
			updateTooltip();
			buttonSellButton = val.GetComponentInChildren<Button>();
			buttonSellButton.onClick = new ButtonClickedEvent();
			((UnityEvent)buttonSellButton.onClick).AddListener((UnityAction)delegate
			{
				MoneyStoreGuiSelectedItemPatch.lastValuableToSell = "$item_" + spriteName.ToLowerInvariant();
				ModUtils.RunPrivateMethod(StoreGui.instance, "SellItem");
				MoneyStoreGuiSelectedItemPatch.lastValuableToSell = null;
				((Selectable)vendorPanelValuable.buttonSellButton).interactable = false;
			});
		}

		public void updateValue(int amount, int value)
		{
			//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)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			Transform child = vendorPanelValuableGO.transform.GetChild(1);
			((TMP_Text)((Component)child).GetComponent<TextMeshProUGUI>()).text = amount + " (" + value + ")";
			((TMP_Text)((Component)child).GetComponent<TextMeshProUGUI>()).faceColor = Color32.op_Implicit((amount == 0) ? new Color(255f, 0f, 0f, 255f) : new Color(255f, 255f, 255f, 255f));
			updateTooltip();
			((Selectable)buttonSellButton).interactable = amount > 0;
		}

		private void updateTooltip()
		{
			string text = "$item_" + spriteName.ToLowerInvariant();
			if (text.Contains("coin_ancient"))
			{
				text = "$item_ancientcoin";
			}
			sellButtonTooltip.m_text = (Player.m_localPlayer.IsKnownMaterial(text) ? ("$store_sell " + text) : "???");
		}

		public GameObject getMainPanel()
		{
			return vendorPanelValuableGO;
		}
	}
}
namespace EconomyInfo.money_inventory
{
	[HarmonyPatch(typeof(InventoryGui), "Show")]
	public class InventoryGui_Show_Patch
	{
		public static MoneyPanel moneyPanelInventory;

		public static MoneyPanel moneyPanelContainer;

		public static void Postfix(InventoryGui __instance)
		{
			Logger.Log("Inventory opened!");
			if (moneyPanelInventory == null)
			{
				Transform parentTransform = ((Component)InventoryGui.instance.m_inventoryRoot).transform.Find("Player");
				Transform parentTransform2 = ((Component)((Component)InventoryGui.instance.m_inventoryRoot).transform.Find("Player")).transform.Find("Container");
				moneyPanelInventory = new MoneyPanel(MoneyPanel.MoneyPanelType.Inventory, parentTransform);
				moneyPanelInventory.getGameObject().SetActive(ConfigurationFile.showInventoryMoneyBalance.Value);
				moneyPanelContainer = new MoneyPanel(MoneyPanel.MoneyPanelType.Container, parentTransform2);
				moneyPanelContainer.getGameObject().SetActive(ConfigurationFile.showContainerMoneyBalance.Value);
			}
			MoneyInventoryRecalculation.RecalculateMoneyInventoryValue();
		}
	}
	[HarmonyPatch(typeof(Inventory), "Changed")]
	internal class Inventory_Changed_Patch
	{
		public static void Postfix(Inventory __instance)
		{
			Player localPlayer = Player.m_localPlayer;
			if (__instance == ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null))
			{
				MoneyInventoryRecalculation.RecalculateMoneyInventoryValue();
			}
		}
	}
	[HarmonyPatch(typeof(Container), "Interact")]
	public class Container_Interact_Patch
	{
		public static void Postfix(Container __instance, Humanoid character, bool hold, bool alt, bool __result)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance != (Object)null)
			{
				Logger.Log($"Chest opened in {((Component)__instance).transform.position}!");
				MoneyInventoryRecalculation.RecalculateCalculateChestValue(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Container), "OnContainerChanged")]
	public class Container_Changed_patch
	{
		public static void Postfix(Container __instance)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance != (Object)null)
			{
				Logger.Log($"Chest opened in {((Component)__instance).transform.position}!");
				MoneyInventoryRecalculation.RecalculateCalculateChestValue(__instance);
			}
		}
	}
	public class MoneyInventoryRecalculation
	{
		public static void RecalculateMoneyInventoryValue()
		{
			if (InventoryGui_Show_Patch.moneyPanelInventory == null)
			{
				return;
			}
			int num = 0;
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				foreach (ItemData allItem in ((Humanoid)Player.m_localPlayer).GetInventory().GetAllItems())
				{
					if (allItem.m_shared.m_value > 0)
					{
						Logger.Log("Found in player inventory: " + allItem.m_shared.m_name + " = " + allItem.m_shared.m_value);
						num += allItem.m_stack * allItem.m_shared.m_value;
					}
				}
			}
			InventoryGui_Show_Patch.moneyPanelInventory.updateMoneyValue(num.ToString());
		}

		public static void RecalculateCalculateChestValue(Container chest)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			if (InventoryGui_Show_Patch.moneyPanelContainer == null)
			{
				return;
			}
			int num = 0;
			FieldInfo field = typeof(Container).GetField("m_inventory", BindingFlags.Instance | BindingFlags.NonPublic);
			Inventory val = (Inventory)field.GetValue(chest);
			foreach (ItemData allItem in val.GetAllItems())
			{
				if (allItem.m_shared.m_value > 0)
				{
					Logger.Log("Found in container inventory: " + allItem.m_shared.m_name + " = " + allItem.m_shared.m_value);
					num += allItem.m_stack * allItem.m_shared.m_value;
				}
			}
			InventoryGui_Show_Patch.moneyPanelContainer.updateMoneyValue(num.ToString());
		}
	}
	public class MoneyPanel
	{
		public enum MoneyPanelType
		{
			Inventory,
			Container
		}

		private readonly GameObject moneyPanelGameObject;

		private readonly Transform weightTransform;

		private TextMeshProUGUI moneyPanelValueComponentText;

		public MoneyPanel(MoneyPanelType moneyPanelType, Transform parentTransform)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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)
			weightTransform = ((Component)parentTransform).transform.Find("Weight");
			moneyPanelGameObject = new GameObject("MoneyPanel", new Type[1] { typeof(RectTransform) });
			moneyPanelGameObject.SetActive(true);
			moneyPanelGameObject.transform.SetParent(parentTransform);
			RectTransform component = moneyPanelGameObject.GetComponent<RectTransform>();
			component.sizeDelta = new Vector2(80f, 64f);
			switch (moneyPanelType)
			{
			case MoneyPanelType.Inventory:
				component.anchoredPosition = new Vector2(317f, -7f);
				break;
			case MoneyPanelType.Container:
				component.anchoredPosition = new Vector2(319f, -30f);
				break;
			}
			moneyPanelGameObject.transform.SetSiblingIndex(weightTransform.GetSiblingIndex() + 1);
			moneyPanelBackground();
			moneyPanelIcon();
			moneyPanelValue();
			((TMP_Text)moneyPanelValueComponentText).text = "0";
		}

		private void moneyPanelBackground()
		{
			GameObject gameObject = ((Component)weightTransform.Find("bkg")).gameObject;
			GameObject val = Object.Instantiate<GameObject>(gameObject, moneyPanelGameObject.transform);
			((Object)val).name = "moneypanel_bkg";
		}

		private void moneyPanelIcon()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("moneypanel_icon");
			val.transform.SetParent(moneyPanelGameObject.transform);
			Image val2 = val.AddComponent<Image>();
			val2.sprite = ModUtils.getSprite("coins");
			val2.type = (Type)1;
			RectTransform component = val.GetComponent<RectTransform>();
			component.sizeDelta = new Vector2(32f, 32f);
			component.anchoredPosition = new Vector2(2f, 25f);
		}

		private void moneyPanelValue()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)weightTransform.Find("weight_text")).gameObject;
			GameObject val = Object.Instantiate<GameObject>(gameObject, moneyPanelGameObject.transform);
			((Object)val).name = "moneypanel_value";
			RectTransform component = val.GetComponent<RectTransform>();
			component.sizeDelta = new Vector2(80f, 64f);
			component.anchoredPosition = new Vector2(0f, 0f);
			moneyPanelValueComponentText = val.GetComponent<TextMeshProUGUI>();
		}

		public void updateMoneyValue(string value)
		{
			((TMP_Text)moneyPanelValueComponentText).text = value;
		}

		public GameObject getGameObject()
		{
			return moneyPanelGameObject;
		}
	}
}