Decompiled source of ValuableList v1.0.0

ValuableList.dll

Decompiled 6 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MenuLib;
using MenuLib.MonoBehaviors;
using MenuLib.Structs;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("McHorse")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+da1e30360035a25f6efdce54b0ee05a74a2f950c")]
[assembly: AssemblyProduct("ValuableList")]
[assembly: AssemblyTitle("ValuableList")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 ValuableList
{
	[HarmonyPatch(typeof(RoundDirector))]
	internal static class RoundDirectorPatch
	{
		private static GameObject? labelObject;

		private static TextMeshProUGUI? labelText;

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		private static void UpdateHudLabel()
		{
			if (!SemiFunc.RunIsLevel())
			{
				SetLabelActive(active: false);
				return;
			}
			EnsureLabel();
			if ((Object)(object)labelText == (Object)null)
			{
				return;
			}
			if (!ValuableList.Instance.ShowMostExpensiveHudLabelEnabled)
			{
				SetLabelActive(active: false);
				return;
			}
			ValuableEntry? mostExpensiveInCurrentRoom = ValuableUtils.GetMostExpensiveInCurrentRoom();
			if (!mostExpensiveInCurrentRoom.HasValue)
			{
				SetLabelActive(active: false);
				return;
			}
			((TMP_Text)labelText).text = mostExpensiveInCurrentRoom.Value.Name + " - " + ValuableUtils.FormatPrice(mostExpensiveInCurrentRoom.Value.Price);
			SetLabelActive(active: true);
		}

		private static void EnsureLabel()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: 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)
			if ((Object)(object)labelObject != (Object)null)
			{
				return;
			}
			GameObject val = GameObject.Find("Game Hud");
			if (!((Object)(object)val == (Object)null))
			{
				labelObject = new GameObject("ValuableList Most Expensive Valuable");
				labelObject.transform.SetParent(val.transform, false);
				labelText = labelObject.AddComponent<TextMeshProUGUI>();
				((TMP_Text)labelText).fontSize = 16f;
				((Graphic)labelText).color = Color.white;
				((TMP_Text)labelText).enableWordWrapping = false;
				((TMP_Text)labelText).alignment = (TextAlignmentOptions)514;
				GameObject val2 = GameObject.Find("Tax Haul");
				TMP_Text val3 = (((Object)(object)val2 != (Object)null) ? val2.GetComponent<TMP_Text>() : null);
				if ((Object)(object)val3 != (Object)null)
				{
					((TMP_Text)labelText).font = val3.font;
				}
				ContentSizeFitter val4 = labelObject.AddComponent<ContentSizeFitter>();
				val4.horizontalFit = (FitMode)2;
				val4.verticalFit = (FitMode)2;
				RectTransform component = labelObject.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0.5f, 1f);
				component.anchorMax = new Vector2(0.5f, 1f);
				component.pivot = new Vector2(0.5f, 1f);
				component.anchoredPosition = new Vector2(0f, 10f);
			}
		}

		private static void SetLabelActive(bool active)
		{
			if ((Object)(object)labelObject != (Object)null && labelObject.activeSelf != active)
			{
				labelObject.SetActive(active);
			}
		}
	}
	[BepInPlugin("McHorse.ValuableList", "ValuableList", "1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ValuableList : BaseUnityPlugin
	{
		private ValuablesMenu? valuablesMenu;

		private ConfigEntry<KeyCode>? openMenuKeybind;

		private ConfigEntry<bool>? roundPrices;

		private ConfigEntry<bool>? showMostExpensiveValuable;

		internal static ValuableList Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		internal bool RoundPricesEnabled => roundPrices?.Value ?? true;

		internal bool ShowMostExpensiveHudLabelEnabled => showMostExpensiveValuable?.Value ?? true;

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			openMenuKeybind = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "Open Menu", (KeyCode)107, "Keyboard key used to open the valuables menu.");
			roundPrices = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RoundPrices", true, "Round list prices to thousands with one decimal place (e.g. 15.4k).");
			showMostExpensiveValuable = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowMostExpensiveValuable", false, "Show a HUD label with the most expensive valuable in your current room.");
			Patch();
			valuablesMenu = new ValuablesMenu(Logger);
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.RunIsLevel() && SemiFunc.NoTextInputsActive() && openMenuKeybind != null && Input.GetKeyDown(openMenuKeybind.Value))
			{
				valuablesMenu?.Toggle();
			}
		}
	}
	internal sealed class ValuablesMenu
	{
		private readonly struct ValuableRowVisual
		{
			internal REPOLabel Label { get; }

			internal string NameLower { get; }

			internal bool IsInCartOrExtraction { get; }

			internal int Price { get; }

			internal ValuableRowVisual(REPOLabel label, string name, bool isInCartOrExtraction, int price)
			{
				Label = label;
				NameLower = name.ToLowerInvariant();
				IsInCartOrExtraction = isInCartOrExtraction;
				Price = price;
			}
		}

		private readonly struct RoomGroupVisual
		{
			internal string RoomName { get; }

			internal REPOLabel Header { get; }

			internal List<ValuableRowVisual> Rows { get; }

			internal REPOSpacer? Spacer { get; }

			internal RoomGroupVisual(string roomName, REPOLabel header, List<ValuableRowVisual> rows, REPOSpacer? spacer)
			{
				RoomName = roomName;
				Header = header;
				Rows = rows;
				Spacer = spacer;
			}
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ScrollViewBuilderDelegate <>9__16_1;

			public static Func<ValuableEntry, int> <>9__16_2;

			public static Func<IGrouping<string, ValuableEntry>, int> <>9__21_0;

			public static Func<ValuableEntry, bool> <>9__21_3;

			public static Func<IGrouping<string, ValuableEntry>, int> <>9__21_1;

			internal RectTransform <AddGroupedValuables>b__16_1(Transform parent)
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				REPOLabel val = MenuAPI.CreateREPOLabel("No valuables found.", parent, default(Vector2));
				((TMP_Text)val.labelTMP).fontStyle = (FontStyles)0;
				((TMP_Text)val.labelTMP).fontSize = 16f;
				((Graphic)val.labelTMP).color = ValueLabelColor;
				return ((REPOElement)val).rectTransform;
			}

			internal int <AddGroupedValuables>b__16_2(ValuableEntry entry)
			{
				return entry.Price;
			}

			internal int <AddCollectedSummaryLabel>b__21_0(IGrouping<string, ValuableEntry> group)
			{
				return group.Count();
			}

			internal int <AddCollectedSummaryLabel>b__21_1(IGrouping<string, ValuableEntry> group)
			{
				return group.Count((ValuableEntry entry) => entry.IsInCartOrExtraction);
			}

			internal bool <AddCollectedSummaryLabel>b__21_3(ValuableEntry entry)
			{
				return entry.IsInCartOrExtraction;
			}
		}

		private static readonly Color ModuleHeaderColor = new Color(4f / 15f, 8f / 15f, 1f, 1f);

		private static readonly Color ValueLabelColor = Color.white;

		private static readonly Color HighlightValueLabelColor = new Color(0f, 1f, 4f / 15f, 1f);

		private static readonly Color ActiveRoomHeaderColor = Color.Lerp(ModuleHeaderColor, HighlightValueLabelColor, 0.75f);

		private readonly ManualLogSource logger;

		private REPOPopupPage? currentPage;

		private bool isOpen;

		private readonly List<RoomGroupVisual> roomGroupVisuals = new List<RoomGroupVisual>();

		private REPOLabel? noResultsLabel;

		private REPOButton? toggleCollectedButton;

		private bool hideCollectedValuables;

		private string currentSearchQuery = string.Empty;

		internal ValuablesMenu(ManualLogSource logger)
		{
			this.logger = logger;
		}

		internal void Toggle()
		{
			if (isOpen)
			{
				CloseCurrentPage();
			}
			else if (!SemiFunc.MenuLevel() && !IsAnotherMenuOpen())
			{
				Open();
			}
		}

		private void Open()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_0054: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				CloseCurrentPage();
				REPOPopupPage val = MenuAPI.CreateREPOPopupPage("Valuables", (PresetSide)0, false, true, 0f);
				val.scrollView.scrollSpeed = 3f;
				val.onEscapePressed = (ShouldCloseMenuDelegate)Delegate.Combine((Delegate?)(object)val.onEscapePressed, (Delegate?)new ShouldCloseMenuDelegate(HandleEscapePressed));
				Padding maskPadding = val.maskPadding;
				maskPadding.top = 35f;
				val.maskPadding = maskPadding;
				currentSearchQuery = string.Empty;
				List<IGrouping<string, ValuableEntry>> groupedValuables = ValuableUtils.GetGroupedValuables();
				AddSearchBox(val);
				AddGroupedValuables(val, groupedValuables);
				AddCollectedButton(val);
				AddCollectedSummaryLabel(val, groupedValuables);
				currentPage = val;
				isOpen = true;
				val.OpenPage(false);
				((MonoBehaviour)ValuableList.Instance).StartCoroutine(ScrollToCurrentPlayerRoomAfterOpen(val, groupedValuables));
			}
			catch (Exception arg)
			{
				logger.LogError((object)$"Failed to open valuables menu: {arg}");
				isOpen = false;
				currentPage = null;
			}
		}

		private bool HandleEscapePressed()
		{
			isOpen = false;
			currentPage = null;
			return true;
		}

		private void AddGroupedValuables(REPOPopupPage page, List<IGrouping<string, ValuableEntry>> grouped)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Expected O, but got Unknown
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Expected O, but got Unknown
			roomGroupVisuals.Clear();
			noResultsLabel = null;
			page.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform parent)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				noResultsLabel = MenuAPI.CreateREPOLabel("No matching valuables found.", parent, default(Vector2));
				((TMP_Text)noResultsLabel.labelTMP).fontStyle = (FontStyles)0;
				((TMP_Text)noResultsLabel.labelTMP).fontSize = 16f;
				((Graphic)noResultsLabel.labelTMP).color = ValueLabelColor;
				SetLabelVisibility(noResultsLabel, visible: false);
				return ((REPOElement)noResultsLabel).rectTransform;
			}, 0f, 0f);
			string currentRoom = ValuableUtils.GetCurrentPlayerRoomName();
			if (grouped.Count == 0)
			{
				object obj = <>c.<>9__16_1;
				if (obj == null)
				{
					ScrollViewBuilderDelegate val = delegate(Transform parent)
					{
						//IL_0009: Unknown result type (might be due to invalid IL or missing references)
						//IL_000f: Unknown result type (might be due to invalid IL or missing references)
						//IL_003a: Unknown result type (might be due to invalid IL or missing references)
						REPOLabel val3 = MenuAPI.CreateREPOLabel("No valuables found.", parent, default(Vector2));
						((TMP_Text)val3.labelTMP).fontStyle = (FontStyles)0;
						((TMP_Text)val3.labelTMP).fontSize = 16f;
						((Graphic)val3.labelTMP).color = ValueLabelColor;
						return ((REPOElement)val3).rectTransform;
					};
					<>c.<>9__16_1 = val;
					obj = (object)val;
				}
				page.AddElementToScrollView((ScrollViewBuilderDelegate)obj, 0f, 0f);
				return;
			}
			for (int i = 0; i < grouped.Count; i++)
			{
				IGrouping<string, ValuableEntry> roomGroup = grouped[i];
				int rawPrice = roomGroup.Sum((ValuableEntry entry) => entry.Price);
				string roomHeaderText = roomGroup.Key + " (" + ValuableUtils.FormatPrice(rawPrice) + ")";
				REPOLabel groupHeader = null;
				page.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform parent)
				{
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0011: 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)
					//IL_0084: Unknown result type (might be due to invalid IL or missing references)
					groupHeader = MenuAPI.CreateREPOLabel(roomHeaderText, parent, default(Vector2));
					((TMP_Text)groupHeader.labelTMP).fontStyle = (FontStyles)1;
					((TMP_Text)groupHeader.labelTMP).fontSize = 24f;
					bool flag = !string.IsNullOrWhiteSpace(currentRoom) && string.Equals(roomGroup.Key, currentRoom, StringComparison.OrdinalIgnoreCase);
					((Graphic)groupHeader.labelTMP).color = (flag ? ActiveRoomHeaderColor : ModuleHeaderColor);
					return ((REPOElement)groupHeader).rectTransform;
				}, 0f, 0f);
				List<ValuableRowVisual> list = new List<ValuableRowVisual>();
				foreach (ValuableEntry entry2 in roomGroup)
				{
					REPOLabel lineLabelRef = null;
					page.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform parent)
					{
						//IL_0033: Unknown result type (might be due to invalid IL or missing references)
						//IL_0039: Unknown result type (might be due to invalid IL or missing references)
						//IL_0084: Unknown result type (might be due to invalid IL or missing references)
						//IL_007d: 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_009a: 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)
						//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
						//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
						REPOLabel val2 = (lineLabelRef = MenuAPI.CreateREPOLabel(entry2.Name + " - " + ValuableUtils.FormatPrice(entry2.Price), parent, default(Vector2)));
						((TMP_Text)val2.labelTMP).fontStyle = (FontStyles)0;
						((TMP_Text)val2.labelTMP).fontSize = 16f;
						((Graphic)val2.labelTMP).color = (entry2.IsInCartOrExtraction ? HighlightValueLabelColor : ValueLabelColor);
						Vector2 sizeDelta = ((REPOElement)val2).rectTransform.sizeDelta;
						((REPOElement)val2).rectTransform.sizeDelta = new Vector2(sizeDelta.x, sizeDelta.y * 0.625f);
						return ((REPOElement)val2).rectTransform;
					}, 0f, 0f);
					if ((Object)(object)lineLabelRef != (Object)null)
					{
						list.Add(new ValuableRowVisual(lineLabelRef, entry2.Name, entry2.IsInCartOrExtraction, entry2.Price));
					}
				}
				REPOSpacer spacer = null;
				if (i < grouped.Count - 1)
				{
					page.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform parent)
					{
						//IL_0005: Unknown result type (might be due to invalid IL or missing references)
						//IL_000b: Unknown result type (might be due to invalid IL or missing references)
						//IL_0016: Unknown result type (might be due to invalid IL or missing references)
						spacer = MenuAPI.CreateREPOSpacer(parent, default(Vector2), new Vector2(0f, 8f));
						return ((REPOElement)spacer).rectTransform;
					}, 0f, 0f);
				}
				if ((Object)(object)groupHeader != (Object)null)
				{
					roomGroupVisuals.Add(new RoomGroupVisual(roomGroup.Key, groupHeader, list, spacer));
				}
			}
		}

		private void AddSearchBox(REPOPopupPage page)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			REPOPopupPage page2 = page;
			page2.AddElement((BuilderDelegate)delegate(Transform parent)
			{
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				((Component)MenuAPI.CreateREPOInputField("Search", (Action<string>)delegate(string query)
				{
					currentSearchQuery = query ?? string.Empty;
					ApplySearchFilter(page2, currentSearchQuery);
				}, parent, new Vector2(83f, 272f), false, "", "")).transform.localScale = Vector3.one * 0.95f;
			});
		}

		private void ApplySearchFilter(REPOPopupPage page, string query)
		{
			try
			{
				string value = (string.IsNullOrWhiteSpace(query) ? string.Empty : query.Trim().ToLowerInvariant());
				int num = 0;
				foreach (RoomGroupVisual roomGroupVisual in roomGroupVisuals)
				{
					bool flag = false;
					int num2 = 0;
					foreach (ValuableRowVisual row in roomGroupVisual.Rows)
					{
						bool flag2 = string.IsNullOrEmpty(value) || row.NameLower.Contains(value);
						bool flag3 = !hideCollectedValuables || !row.IsInCartOrExtraction;
						bool flag4 = flag2 && flag3;
						SetLabelVisibility(row.Label, flag4);
						flag = flag || flag4;
						if (flag4)
						{
							num2 += row.Price;
						}
					}
					SetLabelVisibility(roomGroupVisual.Header, flag);
					((TMP_Text)roomGroupVisual.Header.labelTMP).text = roomGroupVisual.RoomName + " (" + ValuableUtils.FormatPrice(num2) + ")";
					if (flag)
					{
						num++;
					}
				}
				foreach (RoomGroupVisual roomGroupVisual2 in roomGroupVisuals)
				{
					if (!((Object)(object)roomGroupVisual2.Spacer == (Object)null))
					{
						SetSpacerVisibility(roomGroupVisual2.Spacer, IsLabelVisible(roomGroupVisual2.Header));
					}
				}
				SetLabelVisibility(noResultsLabel, roomGroupVisuals.Count > 0 && num == 0);
				UpdateToggleButtonVisual();
				page.scrollView.SetScrollPosition(0f);
			}
			catch (Exception arg)
			{
				logger.LogError((object)$"Search filter update failed: {arg}");
			}
		}

		private static void ScrollToCurrentPlayerRoom(REPOPopupPage page, List<IGrouping<string, ValuableEntry>> grouped)
		{
			if (grouped.Count == 0)
			{
				return;
			}
			string currentRoom = ValuableUtils.GetCurrentPlayerRoomName();
			if (string.IsNullOrWhiteSpace(currentRoom))
			{
				page.scrollView.SetScrollPosition(0f);
				return;
			}
			int num = grouped.FindIndex((IGrouping<string, ValuableEntry> group) => string.Equals(group.Key, currentRoom, StringComparison.OrdinalIgnoreCase));
			if (num < 0)
			{
				page.scrollView.SetScrollPosition(0f);
				return;
			}
			if (num == 0)
			{
				page.scrollView.SetScrollPosition(0f);
				return;
			}
			float scrollPosition = (float)num / (float)Math.Max(1, grouped.Count - 1);
			page.scrollView.SetScrollPosition(scrollPosition);
		}

		private IEnumerator ScrollToCurrentPlayerRoomAfterOpen(REPOPopupPage page, List<IGrouping<string, ValuableEntry>> grouped)
		{
			yield return null;
			yield return null;
			if (isOpen && !((Object)(object)currentPage != (Object)(object)page))
			{
				ApplySearchFilter(page, string.Empty);
				ScrollToCurrentPlayerRoom(page, grouped);
			}
		}

		private void AddCollectedSummaryLabel(REPOPopupPage page, List<IGrouping<string, ValuableEntry>> grouped)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			int allCount = grouped.Sum((IGrouping<string, ValuableEntry> group) => group.Count());
			int collectedCount = grouped.Sum((IGrouping<string, ValuableEntry> group) => group.Count((ValuableEntry entry) => entry.IsInCartOrExtraction));
			bool flag = allCount > 0 && collectedCount == allCount;
			Color summaryColor = (flag ? HighlightValueLabelColor : ValueLabelColor);
			page.AddElement((BuilderDelegate)delegate(Transform parent)
			{
				//IL_002c: 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)
				REPOLabel val = MenuAPI.CreateREPOLabel($"{collectedCount}/{allCount}", parent, new Vector2(120f, 20f));
				((TMP_Text)val.labelTMP).fontStyle = (FontStyles)0;
				((TMP_Text)val.labelTMP).fontSize = 24f;
				((Graphic)val.labelTMP).color = summaryColor;
				((TMP_Text)val.labelTMP).alignment = (TextAlignmentOptions)516;
			});
		}

		private void AddCollectedButton(REPOPopupPage page)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			REPOPopupPage page2 = page;
			page2.AddElement((BuilderDelegate)delegate(Transform parent)
			{
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				toggleCollectedButton = MenuAPI.CreateREPOButton("Collected", (Action)delegate
				{
					hideCollectedValuables = !hideCollectedValuables;
					ApplySearchFilter(page2, currentSearchQuery);
				}, parent, new Vector2(66f, 18f));
				UpdateToggleButtonVisual();
			});
		}

		private void CloseCurrentPage()
		{
			if ((Object)(object)currentPage != (Object)null)
			{
				currentPage.ClosePage(true);
			}
			currentPage = null;
			isOpen = false;
		}

		private static bool IsAnotherMenuOpen()
		{
			return Object.op_Implicit((Object)(object)MenuManager.instance) && Object.op_Implicit((Object)(object)MenuManager.instance.currentMenuPage);
		}

		private void UpdateToggleButtonVisual()
		{
			if (!((Object)(object)toggleCollectedButton?.labelTMP == (Object)null))
			{
				((TMP_Text)toggleCollectedButton.labelTMP).text = (hideCollectedValuables ? "Show Collected" : "Hide Collected");
			}
		}

		private static void SetLabelVisibility(REPOLabel? label, bool visible)
		{
			if (!((Object)(object)label == (Object)null) && !((Object)(object)((REPOElement)label).repoScrollViewElement == (Object)null))
			{
				((REPOElement)label).repoScrollViewElement.visibility = visible;
			}
		}

		private static bool IsLabelVisible(REPOLabel? label)
		{
			if ((Object)(object)label == (Object)null || (Object)(object)((REPOElement)label).repoScrollViewElement == (Object)null)
			{
				return false;
			}
			return ((REPOElement)label).repoScrollViewElement.visibility;
		}

		private static void SetSpacerVisibility(REPOSpacer? spacer, bool visible)
		{
			if (!((Object)(object)spacer == (Object)null) && !((Object)(object)((REPOElement)spacer).repoScrollViewElement == (Object)null))
			{
				((REPOElement)spacer).repoScrollViewElement.visibility = visible;
			}
		}
	}
	internal static class ValuableUtils
	{
		private static readonly Regex RoomMetadataPrefixRegex = new Regex("^[^-]+?\\s*-\\s*[A-Z]+\\s*-\\s*\\d+\\s*-\\s*(.+)$", RegexOptions.Compiled);

		internal static List<IGrouping<string, ValuableEntry>> GetGroupedValuables()
		{
			return (from v in GetValuableEntries().OrderBy<ValuableEntry, string>((ValuableEntry v) => v.Room, StringComparer.OrdinalIgnoreCase).ThenBy((ValuableEntry v) => v.IsInCartOrExtraction).ThenByDescending((ValuableEntry v) => v.Price)
					.ThenBy<ValuableEntry, string>((ValuableEntry v) => v.Name, StringComparer.OrdinalIgnoreCase)
				group v by v.Room).ToList();
		}

		internal static ValuableEntry? GetMostExpensiveInCurrentRoom()
		{
			string currentRoom = GetCurrentPlayerRoomName();
			if (string.IsNullOrWhiteSpace(currentRoom))
			{
				return null;
			}
			ValuableEntry value = (from v in GetValuableEntries()
				where string.Equals(v.Room, currentRoom, StringComparison.OrdinalIgnoreCase)
				where !v.IsInCartOrExtraction
				orderby v.Price descending
				select v).ThenBy<ValuableEntry, string>((ValuableEntry v) => v.Name, StringComparer.OrdinalIgnoreCase).FirstOrDefault();
			if (string.IsNullOrWhiteSpace(value.Name))
			{
				return null;
			}
			return value;
		}

		internal static string? GetCurrentPlayerRoomName()
		{
			RoomVolume val = PlayerAvatar.instance?.RoomVolumeCheck?.CurrentRooms?.FirstOrDefault((Func<RoomVolume, bool>)((RoomVolume r) => (Object)(object)r != (Object)null && (Object)(object)r.Module != (Object)null));
			if ((Object)(object)val?.Module == (Object)null)
			{
				return null;
			}
			return CleanRoomName(((Object)val.Module).name);
		}

		private static string GetRoomName(ValuableObject valuable)
		{
			RoomVolume val = valuable.roomVolumeCheck?.CurrentRooms?.FirstOrDefault((Func<RoomVolume, bool>)((RoomVolume r) => (Object)(object)r != (Object)null && (Object)(object)r.Module != (Object)null));
			if ((Object)(object)val?.Module == (Object)null)
			{
				return "Unknown";
			}
			return CleanRoomName(((Object)val.Module).name);
		}

		private static bool IsInCartOrExtraction(ValuableObject valuable)
		{
			bool flag = (Object)(object)valuable.physGrabObject != (Object)null && (Object)(object)valuable.physGrabObject.impactDetector != (Object)null && valuable.physGrabObject.impactDetector.inCart;
			bool flag2 = (Object)(object)valuable.roomVolumeCheck != (Object)null && valuable.roomVolumeCheck.inExtractionPoint;
			return flag || flag2;
		}

		private static string CleanValuableName(string source)
		{
			string text = CleanBasicName(source);
			if (text.StartsWith("Valuable ", StringComparison.OrdinalIgnoreCase))
			{
				int num = text.IndexOf(' ');
				if (num >= 0)
				{
					int num2 = text.IndexOf(' ', num + 1);
					if (num2 >= 0 && num2 + 1 < text.Length)
					{
						return text.Substring(num2 + 1).Trim();
					}
				}
			}
			return text.Replace(" Valuable ", " ").Trim();
		}

		private static string CleanRoomName(string source)
		{
			string text = StripPrefix(CleanBasicName(source), "Module - ");
			if (text.IndexOf("Start Room", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return "Start Room";
			}
			Match match = RoomMetadataPrefixRegex.Match(text);
			if (match.Success)
			{
				string text2 = match.Groups[1].Value.Trim();
				if (!string.IsNullOrWhiteSpace(text2))
				{
					return text2;
				}
			}
			return text;
		}

		private static string CleanBasicName(string source)
		{
			if (string.IsNullOrWhiteSpace(source))
			{
				return "Unknown";
			}
			return source.Replace("(Clone)", string.Empty).Trim();
		}

		private static string StripPrefix(string source, string prefix)
		{
			if (source.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
			{
				return source.Substring(prefix.Length).Trim();
			}
			return source;
		}

		private static IEnumerable<ValuableEntry> GetValuableEntries()
		{
			return from v in Object.FindObjectsOfType<ValuableObject>()
				where Object.op_Implicit((Object)(object)v) && ((Component)v).gameObject.activeInHierarchy
				select new ValuableEntry(CleanValuableName(((Object)((Component)v).gameObject).name), Mathf.RoundToInt(v.dollarValueCurrent), GetRoomName(v), IsInCartOrExtraction(v));
		}

		public static string FormatPrice(int rawPrice)
		{
			if (ValuableList.Instance.RoundPricesEnabled)
			{
				return "$" + ((float)rawPrice / 1000f).ToString("0.0", CultureInfo.InvariantCulture) + "K";
			}
			return $"${rawPrice}";
		}
	}
	internal readonly struct ValuableEntry
	{
		public string Name { get; }

		public int Price { get; }

		public string Room { get; }

		public bool IsInCartOrExtraction { get; }

		internal ValuableEntry(string name, int price, string room, bool isInCartOrExtraction)
		{
			Name = name;
			Price = price;
			Room = room;
			IsInCartOrExtraction = isInCartOrExtraction;
		}
	}
}