Decompiled source of Remaining Items List v1.0.3

RemainingItemsList.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
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("YourName")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ddb21bd15a286096b933960648366f65be352dcd")]
[assembly: AssemblyProduct("RemainingItemsList")]
[assembly: AssemblyTitle("RemainingItemsList")]
[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 RemainingItemsList
{
	[BepInPlugin("YourName.RemainingItemsList", "RemainingItemsList", "1.0.0")]
	public class RemainingItemsList : BaseUnityPlugin
	{
		public static GameObject listPanelInstance;

		public static TextMeshProUGUI itemListText;

		public static float AutoHideDelay = 30f;

		public static bool isPanelVisible = false;

		internal static RemainingItemsList Instance { get; private set; } = null;


		internal static ManualLogSource Logger => Instance._logger;

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

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		public static List<ValuableObject> GetRemainingItems()
		{
			return Object.FindObjectsOfType<ValuableObject>().ToList();
		}

		public static void ShowRemainingItemsUI(List<ValuableObject> items)
		{
			if (items == null || items.Count == 0)
			{
				Logger.LogInfo((object)"No items remaining in the level");
				return;
			}
			if ((Object)(object)listPanelInstance == (Object)null)
			{
				CreateItemListUI();
			}
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("REMAINING ITEMS:");
			stringBuilder.AppendLine("----------------");
			float num = 0f;
			var orderedEnumerable = from item in items
				group item by CleanItemName(((Object)item).name) into @group
				select new
				{
					Name = @group.Key,
					Count = @group.Count(),
					TotalValue = @group.Sum((ValuableObject item) => item.dollarValueCurrent)
				} into g
				orderby g.TotalValue descending
				select g;
			foreach (var item in orderedEnumerable)
			{
				stringBuilder.Append($"{item.Name} x{item.Count}: <color=#00FF00>${item.TotalValue:F0}</color>\n");
				num += item.TotalValue;
			}
			stringBuilder.AppendLine("----------------");
			stringBuilder.AppendLine($"TOTAL VALUE: <color=#00FF00>${num:F0}</color>");
			stringBuilder.AppendLine("");
			stringBuilder.AppendLine("<color=#FFFF00>Press G to close</color>");
			((TMP_Text)itemListText).text = stringBuilder.ToString();
			listPanelInstance.SetActive(true);
			isPanelVisible = true;
			ResizePanelToFitContent();
			((MonoBehaviour)Instance).StartCoroutine(Utilities.HideUIAfterDelay(AutoHideDelay));
			Logger.LogInfo((object)("\n" + stringBuilder.ToString()));
		}

		private static string CleanItemName(string name)
		{
			string input = name.Replace("(Clone)", "").Trim();
			return Regex.Replace(input, "^Valuable\\s*", "", RegexOptions.IgnoreCase);
		}

		private static void ResizePanelToFitContent()
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)itemListText == (Object)null) && !((Object)(object)listPanelInstance == (Object)null))
			{
				((TMP_Text)itemListText).ForceMeshUpdate(false, false);
				float num = ((TMP_Text)itemListText).preferredHeight + 20f;
				float num2 = 250f;
				float num3 = 500f;
				float num4 = Mathf.Clamp(num, num2, num3);
				RectTransform component = ((Component)listPanelInstance.transform.GetChild(0)).GetComponent<RectTransform>();
				RectTransform component2 = listPanelInstance.GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null)
				{
					component.sizeDelta = new Vector2(200f, num4);
					component2.sizeDelta = new Vector2(200f, num4);
				}
			}
		}

		private static void CreateItemListUI()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_00d2: 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_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Expected O, but got Unknown
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: 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_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: 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_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Game Hud");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)"Could not find Game Hud");
				return;
			}
			TMP_FontAsset val2 = null;
			GameObject val3 = GameObject.Find("Tax Haul");
			if ((Object)(object)val3 != (Object)null)
			{
				TMP_Text component = val3.GetComponent<TMP_Text>();
				val2 = ((component != null) ? component.font : null);
			}
			listPanelInstance = new GameObject("Remaining Items Panel");
			listPanelInstance.transform.SetParent(val.transform, false);
			GameObject val4 = new GameObject("Background");
			val4.transform.SetParent(listPanelInstance.transform, false);
			val4.AddComponent<RectTransform>();
			val4.AddComponent<CanvasRenderer>();
			Image val5 = val4.AddComponent<Image>();
			((Graphic)val5).color = new Color(0f, 0f, 0f, 0.7f);
			RectTransform component2 = val4.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(200f, 250f);
			component2.anchoredPosition = Vector2.zero;
			GameObject val6 = new GameObject("ItemListText");
			val6.transform.SetParent(val4.transform, false);
			itemListText = val6.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)val2 != (Object)null)
			{
				((TMP_Text)itemListText).font = val2;
			}
			((TMP_Text)itemListText).fontSize = 16f;
			((Graphic)itemListText).color = new Color(0.7882f, 0.9137f, 0.902f, 1f);
			((TMP_Text)itemListText).alignment = (TextAlignmentOptions)258;
			((TMP_Text)itemListText).enableWordWrapping = true;
			((TMP_Text)itemListText).lineSpacing = -10f;
			RectTransform component3 = val6.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0f, 0f);
			component3.anchorMax = new Vector2(1f, 1f);
			component3.pivot = new Vector2(0.5f, 0.5f);
			component3.sizeDelta = new Vector2(-20f, -20f);
			component3.anchoredPosition = Vector2.zero;
			RectTransform val7 = listPanelInstance.AddComponent<RectTransform>();
			val7.anchorMin = new Vector2(0.5f, 0.5f);
			val7.anchorMax = new Vector2(0.5f, 0.5f);
			val7.pivot = new Vector2(0.5f, 0.5f);
			val7.sizeDelta = new Vector2(200f, 250f);
			val7.anchoredPosition = Vector2.zero;
			listPanelInstance.SetActive(false);
			isPanelVisible = false;
		}

		private void Update()
		{
			if (isPanelVisible && Input.GetKeyDown((KeyCode)103) && (Object)(object)listPanelInstance != (Object)null)
			{
				listPanelInstance.SetActive(false);
				isPanelVisible = false;
			}
		}

		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();
			}
		}
	}
	public static class Utilities
	{
		public static IEnumerator HideUIAfterDelay(float delay)
		{
			yield return (object)new WaitForSeconds(delay);
			if (Object.op_Implicit((Object)(object)RemainingItemsList.listPanelInstance))
			{
				RemainingItemsList.listPanelInstance.SetActive(false);
				RemainingItemsList.isPanelVisible = false;
			}
		}
	}
}
namespace RemainingItemsList.Patches
{
	[HarmonyPatch(typeof(RoundDirector))]
	public static class RoundDirectorPatches
	{
		[HarmonyPatch("ExtractionCompleted")]
		[HarmonyPostfix]
		public static void ExtractionComplete()
		{
			if (!((Object)(object)RoundDirector.instance == (Object)null) && IsInLevel() && RoundDirector.instance.allExtractionPointsCompleted)
			{
				RemainingItemsList.Logger.LogInfo((object)"Extraction Completed! Checking for remaining items...");
				List<ValuableObject> remainingItems = RemainingItemsList.GetRemainingItems();
				RemainingItemsList.ShowRemainingItemsUI(remainingItems);
			}
		}

		private static bool IsInLevel()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			int result;
			if ((Object)(object)RoundDirector.instance != (Object)null)
			{
				Scene scene = ((Component)RoundDirector.instance).gameObject.scene;
				if (((Scene)(ref scene)).isLoaded)
				{
					result = (((Behaviour)RoundDirector.instance).isActiveAndEnabled ? 1 : 0);
					goto IL_0034;
				}
			}
			result = 0;
			goto IL_0034;
			IL_0034:
			return (byte)result != 0;
		}
	}
}