Decompiled source of ShopReceipt v1.0.0

ShopReceipt.dll

Decompiled a day ago
using System;
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 BepInEx;
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.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+ede55886130692c4f246c32ceb97ec518d377410")]
[assembly: AssemblyProduct("ShopReceipt")]
[assembly: AssemblyTitle("ShopReceipt")]
[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 ShopReceipt
{
	[HarmonyPatch(typeof(RoundDirector))]
	public static class ReceiptHudPatch
	{
		public static GameObject? textObject;

		public static TextMeshProUGUI? textMesh;

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		public static void UpdateReceiptHud()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.RunIsShop())
			{
				return;
			}
			bool extractionPointActive = RoundDirector.instance.extractionPointActive;
			bool flag = extractionPointActive;
			if ((Object)(object)textObject == (Object)null)
			{
				GameObject val = GameObject.Find("Game Hud");
				GameObject val2 = GameObject.Find("Tax Haul");
				if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
				{
					return;
				}
				textObject = new GameObject();
				textObject.SetActive(false);
				((Object)textObject).name = "Shop Receipt";
				textObject.AddComponent<TextMeshProUGUI>();
				textObject.transform.SetParent(val.transform, false);
				ContentSizeFitter val3 = textObject.AddComponent<ContentSizeFitter>();
				val3.verticalFit = (FitMode)2;
				val3.horizontalFit = (FitMode)0;
				textMesh = textObject.GetComponent<TextMeshProUGUI>();
				((TMP_Text)textMesh).font = val2.GetComponent<TMP_Text>().font;
				((Graphic)textMesh).color = new Color(1f, 1f, 1f, 1f);
				((TMP_Text)textMesh).fontSize = 24f;
				((TMP_Text)textMesh).enableWordWrapping = false;
				((TMP_Text)textMesh).horizontalAlignment = (HorizontalAlignmentOptions)4;
				((TMP_Text)textMesh).verticalAlignment = (VerticalAlignmentOptions)512;
				((TMP_Text)textMesh).alignment = (TextAlignmentOptions)4100;
				RectTransform component = textObject.GetComponent<RectTransform>();
				component.pivot = new Vector2(1f, 0.5f);
				component.anchorMin = new Vector2(0f, 0.5f);
				component.anchorMax = new Vector2(1f, 0.5f);
				component.anchoredPosition = new Vector2(0f, 0f);
			}
			if ((Object)(object)textMesh == (Object)null)
			{
				return;
			}
			string text = (flag ? ShopReceiptLogic.GetExtractionReceipt() : "");
			bool flag2 = text.Length > 0;
			textObject.SetActive(flag2);
			if (!flag2)
			{
				return;
			}
			int num = 1;
			for (int i = 0; i < text.Length; i++)
			{
				if (text[i] == '\n')
				{
					num++;
				}
			}
			int num2 = Mathf.Clamp((num - 3) / 3, 0, 3);
			float[] array = new float[4] { 24f, 18f, 14f, 11f };
			float num3 = array[num2];
			((TMP_Text)textMesh).SetText(text, true);
			((TMP_Text)textMesh).fontSize = num3;
			((TMP_Text)textMesh).lineSpacing = (0f - num3) * 2f;
		}
	}
	[BepInPlugin("McHorse.ShopReceipt", "ShopReceipt", "1.0")]
	public class ShopReceipt : BaseUnityPlugin
	{
		internal static ShopReceipt Instance { get; private set; }

		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!");
		}

		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()
		{
		}
	}
	public static class ShopReceiptLogic
	{
		private static readonly Color ColorCheap = new Color(2f / 15f, 1f, 0f);

		private static readonly Color ColorMid = new Color(1f, 13f / 15f, 0f);

		private static readonly Color ColorExpensive = new Color(1f, 0f, 2f / 15f);

		public static string GetExtractionReceipt()
		{
			if (!SemiFunc.RunIsShop() || (Object)(object)ShopManager.instance == (Object)null)
			{
				return "";
			}
			List<ItemAttributes> shoppingList = ShopManager.instance.shoppingList;
			if (shoppingList == null || shoppingList.Count == 0)
			{
				return "";
			}
			Dictionary<string, (int, int)> dictionary = new Dictionary<string, (int, int)>();
			foreach (ItemAttributes item4 in shoppingList)
			{
				if ((Object)(object)item4 == (Object)null || (Object)(object)item4.roomVolumeCheck == (Object)null)
				{
					continue;
				}
				item4.roomVolumeCheck.CheckSet();
				if (item4.roomVolumeCheck.inExtractionPoint)
				{
					object obj = item4.itemName;
					if (obj == null)
					{
						Item item = item4.item;
						obj = ((item != null) ? ((Object)item).name : null) ?? "?";
					}
					string key = (string)obj;
					int value = item4.value;
					if (dictionary.TryGetValue(key, out var value2))
					{
						dictionary[key] = (value2.Item1 + 1, value2.Item2 + value);
					}
					else
					{
						dictionary[key] = (1, value);
					}
				}
			}
			if (dictionary.Count == 0)
			{
				return "";
			}
			List<KeyValuePair<string, (int, int)>> source = dictionary.OrderByDescending<KeyValuePair<string, (int, int)>, int>((KeyValuePair<string, (int count, int totalPrice)> kv) => kv.Value.totalPrice).ToList();
			int minPrice = source.Min<KeyValuePair<string, (int, int)>>((KeyValuePair<string, (int count, int totalPrice)> kv) => kv.Value.totalPrice);
			int num = source.Max<KeyValuePair<string, (int, int)>>((KeyValuePair<string, (int count, int totalPrice)> kv) => kv.Value.totalPrice);
			int range = num - minPrice;
			IEnumerable<string> values = source.Select<KeyValuePair<string, (int, int)>, string>(delegate(KeyValuePair<string, (int count, int totalPrice)> kv)
			{
				(int count, int totalPrice) value3 = kv.Value;
				int item2 = value3.count;
				int item3 = value3.totalPrice;
				string text = ((item2 == 1) ? "" : (" x " + item2));
				string text2 = "$" + SemiFunc.DollarGetString(item3);
				float t = ((range > 0) ? ((float)(item3 - minPrice) / (float)range) : 1f);
				string text3 = PriceGradientHex(t);
				return kv.Key + text + " - <color=#" + text3 + ">" + text2 + "K</color>";
			});
			return string.Join("\n", values);
		}

		private static string PriceGradientHex(float t)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			t = Mathf.Clamp01(t);
			Color val = ((t <= 0.5f) ? Color.Lerp(ColorCheap, ColorMid, t * 2f) : Color.Lerp(ColorMid, ColorExpensive, (t - 0.5f) * 2f));
			return ColorUtility.ToHtmlStringRGB(val);
		}
	}
}