Decompiled source of EconomyInfo v1.0.0

EconomyInfo.dll

Decompiled 21 hours 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.tools;
using HarmonyLib;
using TMPro;
using UnityEngine;
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
{
	[HarmonyPatch(typeof(InventoryGui), "Awake")]
	public class MoneyInventoryGuiPatch
	{
		public static MoneyPanel moneyPanelInventory;

		public static MoneyPanel moneyPanelContainer;

		public static void Postfix(InventoryGui __instance)
		{
			Transform parentTransform = ((Component)InventoryGui.instance.m_inventoryRoot).transform.Find("Player");
			Transform parentTransform2 = ((Component)InventoryGui.instance.m_inventoryRoot).transform.Find("Container");
			moneyPanelInventory = new MoneyPanel(MoneyPanel.MoneyPanelType.Inventory, parentTransform);
			moneyPanelInventory.getGameObject().SetActive(true);
			moneyPanelContainer = new MoneyPanel(MoneyPanel.MoneyPanelType.Container, parentTransform2);
			moneyPanelContainer.getGameObject().SetActive(true);
		}
	}
	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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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)
			if (moneyPanelType == MoneyPanelType.Inventory)
			{
				weightTransform = ((Component)((Component)InventoryGui.instance.m_inventoryRoot).transform.Find("Player")).transform.Find("Weight");
			}
			else
			{
				weightTransform = ((Component)((Component)InventoryGui.instance.m_inventoryRoot).transform.Find("Container")).transform.Find("Weight");
			}
			moneyPanelGameObject = new GameObject("MoneyPanel", new Type[1] { typeof(RectTransform) });
			moneyPanelGameObject.SetActive(false);
			moneyPanelGameObject.transform.SetParent(parentTransform, false);
			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;
		}
	}
	[BepInPlugin("Turbero.EconomyInfo", "Economy Info", "1.0.0")]
	public class EconomyInfo : BaseUnityPlugin
	{
		public const string GUID = "Turbero.EconomyInfo";

		public const string NAME = "Economy Info";

		public const string VERSION = "1.0.0";

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

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

		private void onDestroy()
		{
			harmony.UnpatchSelf();
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Show")]
	public class InventoryGui_Show_Patch
	{
		public static void Postfix(InventoryGui __instance)
		{
			Logger.Log("Inventory opened!");
			Recalculation.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))
			{
				Recalculation.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}!");
				Recalculation.RecalculateCalculateChestValue(__instance);
			}
		}
	}
	[HarmonyPatch]
	public class Container_Changed_patch
	{
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(typeof(Container), "OnContainerChanged", (Type[])null, (Type[])null);
		}

		public static void Postfix(ref Container __instance)
		{
			//IL_001a: 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}!");
				Recalculation.RecalculateCalculateChestValue(__instance);
			}
		}
	}
	public class Recalculation
	{
		public static void RecalculateMoneyInventoryValue()
		{
			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;
					}
				}
			}
			MoneyInventoryGuiPatch.moneyPanelInventory.updateMoneyValue(num.ToString());
		}

		public static void RecalculateCalculateChestValue(Container chest)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			if ((Object)(object)chest == (Object)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;
				}
			}
			MoneyInventoryGuiPatch.moneyPanelContainer.updateMoneyValue(num.ToString());
		}
	}
}
namespace EconomyInfo.tools
{
	internal class ConfigurationFile
	{
		public static ConfigEntry<bool> debug;

		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)");
			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();
			}
			catch
			{
				Logger.LogError("There was an issue loading " + ConfigFileName);
			}
		}

		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.0.0: " + ((s != null) ? s.ToString() : "null");
			Debug.LogWarning((object)text);
		}

		internal static void LogError(object s)
		{
			string text = "Economy Info 1.0.0: " + ((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);
		}
	}
}