Decompiled source of MerchantTracker v1.0.0

MerchantTracker.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("MerchantTracker")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a45c570d17c512d77d75166ff42bc1dee72ef243")]
[assembly: AssemblyProduct("MerchantTracker")]
[assembly: AssemblyTitle("MerchantTracker")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 MerchantTracker
{
	[BepInPlugin("com.koendertjh.merchanttracker", "MerchantTracker", "1.0.0")]
	public class MerchantTrackerPlugin : BaseUnityPlugin
	{
		public const string ModGuid = "com.koendertjh.merchanttracker";

		public const string ModName = "MerchantTracker";

		public const string ModVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> NewMarker;

		internal static ConfigEntry<string> MarkerText;

		internal static ConfigEntry<bool> LockedWaresRow;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			NewMarker = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "NewMarker", true, "Wares you have never owned get a marker after their name.");
			MarkerText = ((BaseUnityPlugin)this).Config.Bind<string>("1 - General", "MarkerText", "<color=#ffb347>new</color>", "The marker. Rich text is allowed.");
			LockedWaresRow = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "LockedWaresRow", true, "A last row counting the wares the trader will only sell later.");
			_harmony = new Harmony("com.koendertjh.merchanttracker");
			_harmony.PatchAll(typeof(MerchantTrackerPlugin).Assembly);
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(StoreGui), "FillList")]
	internal static class StorePatch
	{
		private static GameObject s_lockedRow;

		private static void Prefix()
		{
			if ((Object)(object)s_lockedRow != (Object)null)
			{
				Object.Destroy((Object)(object)s_lockedRow);
			}
			s_lockedRow = null;
		}

		private static void Postfix(StoreGui __instance, Trader ___m_trader, List<GameObject> ___m_itemList)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)___m_trader == (Object)null || (Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			List<TradeItem> availableItems = ___m_trader.GetAvailableItems();
			if (MerchantTrackerPlugin.NewMarker.Value)
			{
				for (int i = 0; i < availableItems.Count && i < ___m_itemList.Count; i++)
				{
					ItemDrop prefab = availableItems[i].m_prefab;
					if (!((Object)(object)prefab == (Object)null) && !localPlayer.IsMaterialKnown(prefab.m_itemData.m_shared.m_name))
					{
						Transform obj = ___m_itemList[i].transform.Find("name");
						TMP_Text val = ((obj != null) ? ((Component)obj).GetComponent<TMP_Text>() : null);
						if ((Object)(object)val != (Object)null)
						{
							val.text = val.text + " " + MerchantTrackerPlugin.MarkerText.Value;
						}
					}
				}
			}
			if (MerchantTrackerPlugin.LockedWaresRow.Value)
			{
				AddLockedRow(__instance, ___m_trader, availableItems.Count);
			}
		}

		private static int CountLocked(Trader trader)
		{
			int num = 0;
			foreach (TradeItem item in trader.m_items)
			{
				if (!string.IsNullOrEmpty(item.m_requiredGlobalKey) && !ZoneSystem.instance.GetGlobalKey(item.m_requiredGlobalKey) && (string.IsNullOrEmpty(item.m_buyKey) || !((Humanoid)Player.m_localPlayer).HaveUniqueKey(item.m_buyKey)))
				{
					num++;
				}
			}
			return num;
		}

		private static void AddLockedRow(StoreGui gui, Trader trader, int rows)
		{
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Expected O, but got Unknown
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: 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_0168: 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_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: 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: Unknown result type (might be due to invalid IL or missing references)
			int num = CountLocked(trader);
			if (num != 0)
			{
				RectTransform listRoot = gui.m_listRoot;
				s_lockedRow = Object.Instantiate<GameObject>(gui.m_listElement, (Transform)(object)listRoot);
				((Object)s_lockedRow).name = "MerchantTrackerLocked";
				s_lockedRow.SetActive(true);
				Object.Destroy((Object)(object)s_lockedRow.GetComponent<Button>());
				Object.Destroy((Object)(object)s_lockedRow.GetComponent<UITooltip>());
				Transform val = s_lockedRow.transform.Find("icon");
				if ((Object)(object)val != (Object)null)
				{
					((Component)val).gameObject.SetActive(false);
				}
				Transform val2 = Utils.FindChild(s_lockedRow.transform, "price", (IterativeSearchType)0);
				if ((Object)(object)val2 != (Object)null)
				{
					((Component)(((Object)(object)val2.parent != (Object)(object)s_lockedRow.transform) ? val2.parent : val2)).gameObject.SetActive(false);
				}
				Transform obj = s_lockedRow.transform.Find("name");
				TMP_Text val3 = ((obj != null) ? ((Component)obj).GetComponent<TMP_Text>() : null);
				if ((Object)(object)val3 != (Object)null)
				{
					string arg = Localization.instance.Localize(trader.m_name);
					val3.text = $"Only Odin knows what else {arg} will sell ({num})";
					((Graphic)val3).color = Color.grey;
					val3.fontStyle = (FontStyles)(val3.fontStyle | 2);
				}
				RectTransform val4 = (RectTransform)s_lockedRow.transform;
				Rect rect = listRoot.rect;
				float width = ((Rect)(ref rect)).width;
				rect = val4.rect;
				float num2 = (width - ((Rect)(ref rect)).width) / 2f;
				val4.anchoredPosition = new Vector2(num2, (float)rows * (0f - gui.m_itemSpacing) - num2);
				float num3 = (float)(rows + 1) * gui.m_itemSpacing;
				rect = listRoot.rect;
				if (((Rect)(ref rect)).height < num3)
				{
					listRoot.SetSizeWithCurrentAnchors((Axis)1, num3);
				}
			}
		}
	}
	internal static class PluginInfo
	{
		public const string Version = "1.0.0";
	}
}