Decompiled source of CosmeticBoxScanner Fixed v1.0.9

Cosmetics_Box_Scanner.dll

Decompiled 3 weeks ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using Cosmetics_Box_Scanner.Models;
using Cosmetics_Box_Scanner.Patches;
using Cosmetics_Box_Scanner.Systems;
using Cosmetics_Box_Scanner.UI;
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: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Cosmetics_Box_Scanner")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.8.0")]
[assembly: AssemblyInformationalVersion("1.0.8")]
[assembly: AssemblyProduct("Cosmetics_Box_Scanner")]
[assembly: AssemblyTitle("Cosmetics_Box_Scanner")]
[assembly: AssemblyVersion("1.0.8.0")]
namespace Cosmetics_Box_Scanner
{
	[BepInPlugin("cosmetic.scanner", "Cosmetic Scanner", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		internal static Plugin Instance;

		internal static ManualLogSource Log;

		public static bool ShowGUI;

		private Harmony harmony;

		public ScannerUI scannerUI;

		private void Awake()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("cosmetic.scanner");
			harmony.PatchAll();
			Log.LogInfo((object)"Cosmetic Scanner Loaded");
		}

		public void ToggleGUI()
		{
			Log.LogInfo((object)"F6 PRESSED");
			if (scannerUI == null)
			{
				scannerUI = new ScannerUI();
				scannerUI.Create();
				Log.LogInfo((object)"UI CREATED");
			}
			ShowGUI = !ShowGUI;
			scannerUI.SetVisible(ShowGUI);
			PlayerUpdatePatch.ResetTimer();
			if (ShowGUI)
			{
				CosmeticScannerSystem.Scan();
				scannerUI.Refresh(CosmeticScannerSystem.Stats, visible: true);
				scannerUI.ShowStatus("Cosmetic Overlay Enabled");
			}
			else
			{
				scannerUI.Refresh(CosmeticScannerSystem.Stats, visible: false);
				scannerUI.ShowStatus("Cosmetic Overlay Disabled");
			}
		}
	}
}
namespace Cosmetics_Box_Scanner.UI
{
	internal class RarityRowFactory
	{
		public static GameObject CreateRarityRow(Transform parent, Rarity rarity, out TextMeshProUGUI textComponent, int index)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_003e: 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)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Expected O, but got Unknown
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(((object)(Rarity)(ref rarity)).ToString() + "Row");
			val.transform.SetParent(parent, false);
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.anchorMin = new Vector2(0f, 1f);
			val2.anchorMax = new Vector2(1f, 1f);
			val2.pivot = new Vector2(0.5f, 1f);
			val2.sizeDelta = new Vector2(0f, 40f);
			CosmeticTokenUIElement tokenPrefab = GameAssets.GetTokenPrefab();
			if ((Object)(object)tokenPrefab != (Object)null)
			{
				GameObject val3 = Object.Instantiate<GameObject>(((Component)tokenPrefab).gameObject, val.transform);
				((Object)val3).name = "Icon";
				CosmeticTokenUIElement component = val3.GetComponent<CosmeticTokenUIElement>();
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = false;
				}
				RectTransform component2 = val3.GetComponent<RectTransform>();
				component2.anchorMin = new Vector2(0f, 0.5f);
				component2.anchorMax = new Vector2(0f, 0.5f);
				component2.pivot = new Vector2(0f, 0.5f);
				component2.anchoredPosition = new Vector2(18f, 0f);
				((Transform)component2).localScale = Vector3.one * 0.75f;
				RawImage componentInChildren = val3.GetComponentInChildren<RawImage>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					((Graphic)componentInChildren).color = GameAssets.GetRarityColor(rarity);
				}
				Graphic[] componentsInChildren = val3.GetComponentsInChildren<Graphic>(true);
				Graphic[] array = componentsInChildren;
				foreach (Graphic val4 in array)
				{
					if (((Object)val4).name.Contains("Blink") || ((Object)val4).name.Contains("Sheen"))
					{
						((Component)val4).gameObject.SetActive(false);
					}
				}
			}
			GameObject val5 = new GameObject("Count");
			val5.transform.SetParent(val.transform, false);
			textComponent = val5.AddComponent<TextMeshProUGUI>();
			((TMP_Text)textComponent).fontSize = 18f;
			((Graphic)textComponent).color = Color.white;
			((TMP_Text)textComponent).alignment = (TextAlignmentOptions)513;
			((TMP_Text)textComponent).enableWordWrapping = false;
			((TMP_Text)textComponent).text = "0";
			RectTransform component3 = ((Component)textComponent).GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0f, 0f);
			component3.anchorMax = new Vector2(1f, 1f);
			component3.offsetMin = new Vector2(68f, 0f);
			component3.offsetMax = Vector2.zero;
			return val;
		}
	}
	public class ScannerUI
	{
		private GameObject canvasObject;

		private GameObject panelObject;

		private GameObject commonRow;

		private GameObject uncommonRow;

		private GameObject rareRow;

		private GameObject ultraRow;

		private TextMeshProUGUI commonText;

		private TextMeshProUGUI uncommonText;

		private TextMeshProUGUI rareText;

		private TextMeshProUGUI ultraText;

		private TextMeshProUGUI statusText;

		private float statusTimer;

		public void Create()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: 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_019e: Expected O, but got Unknown
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)canvasObject != (Object)null))
			{
				canvasObject = new GameObject("CosmeticScannerCanvas");
				Object.DontDestroyOnLoad((Object)(object)canvasObject);
				Canvas val = canvasObject.AddComponent<Canvas>();
				val.renderMode = (RenderMode)0;
				val.sortingOrder = 9999;
				CanvasScaler val2 = canvasObject.AddComponent<CanvasScaler>();
				val2.uiScaleMode = (ScaleMode)1;
				val2.referenceResolution = new Vector2(1920f, 1080f);
				canvasObject.AddComponent<GraphicRaycaster>();
				panelObject = new GameObject("Panel");
				panelObject.transform.SetParent(canvasObject.transform, false);
				RectTransform val3 = panelObject.AddComponent<RectTransform>();
				val3.anchorMin = new Vector2(1f, 0f);
				val3.anchorMax = new Vector2(1f, 0f);
				val3.pivot = new Vector2(1f, 0f);
				val3.anchoredPosition = new Vector2(-35f, 35f);
				commonRow = RarityRowFactory.CreateRarityRow(panelObject.transform, (Rarity)0, out commonText, 0);
				uncommonRow = RarityRowFactory.CreateRarityRow(panelObject.transform, (Rarity)1, out uncommonText, 1);
				rareRow = RarityRowFactory.CreateRarityRow(panelObject.transform, (Rarity)2, out rareText, 2);
				ultraRow = RarityRowFactory.CreateRarityRow(panelObject.transform, (Rarity)3, out ultraText, 3);
				GameObject val4 = new GameObject("StatusText");
				val4.transform.SetParent(canvasObject.transform, false);
				statusText = val4.AddComponent<TextMeshProUGUI>();
				((TMP_Text)statusText).fontSize = 28f;
				((Graphic)statusText).color = Color.white;
				((TMP_Text)statusText).alignment = (TextAlignmentOptions)514;
				RectTransform component = ((Component)statusText).GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0.5f, 0.1f);
				component.anchorMax = new Vector2(0.5f, 0.1f);
				component.pivot = new Vector2(0.5f, 0.5f);
				component.sizeDelta = new Vector2(600f, 80f);
				((Component)statusText).gameObject.SetActive(false);
				panelObject.SetActive(false);
			}
		}

		public void Refresh(CosmeticStats stats, bool visible)
		{
			if (!((Object)(object)commonText == (Object)null))
			{
				((TMP_Text)commonText).text = stats.Common.ToString();
				((TMP_Text)uncommonText).text = stats.Uncommon.ToString();
				((TMP_Text)rareText).text = stats.Rare.ToString();
				((TMP_Text)ultraText).text = stats.UltraRare.ToString();
				RebuildLayout(stats);
				bool flag = stats.Common > 0 || stats.Uncommon > 0 || stats.Rare > 0 || stats.UltraRare > 0;
				panelObject.SetActive(visible && flag);
			}
		}

		public void ShowStatus(string message)
		{
			if (!((Object)(object)statusText == (Object)null))
			{
				((TMP_Text)statusText).text = message;
				((Component)statusText).gameObject.SetActive(true);
				statusTimer = 2f;
			}
		}

		public void Tick()
		{
			if (!(statusTimer <= 0f))
			{
				statusTimer -= Time.deltaTime;
				if (statusTimer <= 0f)
				{
					((Component)statusText).gameObject.SetActive(false);
				}
			}
		}

		public void SetVisible(bool visible)
		{
			if ((Object)(object)panelObject != (Object)null)
			{
				panelObject.SetActive(visible);
			}
		}

		private void RebuildLayout(CosmeticStats stats)
		{
			int visibleIndex = 0;
			visibleIndex = PositionRow(commonRow, stats.Common > 0, visibleIndex);
			visibleIndex = PositionRow(uncommonRow, stats.Uncommon > 0, visibleIndex);
			visibleIndex = PositionRow(rareRow, stats.Rare > 0, visibleIndex);
			visibleIndex = PositionRow(ultraRow, stats.UltraRare > 0, visibleIndex);
		}

		private int PositionRow(GameObject row, bool active, int visibleIndex)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			row.SetActive(active);
			if (!active)
			{
				return visibleIndex;
			}
			RectTransform component = row.GetComponent<RectTransform>();
			component.anchoredPosition = new Vector2(0f, -15f - (float)visibleIndex * 30f);
			return visibleIndex + 1;
		}
	}
}
namespace Cosmetics_Box_Scanner.Systems
{
	public static class CosmeticScannerSystem
	{
		public static CosmeticStats Stats = new CosmeticStats();

		public static void Scan()
		{
			//IL_0040: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected I4, but got Unknown
			CosmeticWorldObject[] array = Object.FindObjectsOfType<CosmeticWorldObject>();
			Stats.Common = 0;
			Stats.Uncommon = 0;
			Stats.Rare = 0;
			Stats.UltraRare = 0;
			CosmeticWorldObject[] array2 = array;
			foreach (CosmeticWorldObject val in array2)
			{
				Rarity rarity = val.rarity;
				Rarity val2 = rarity;
				switch ((int)val2)
				{
				case 0:
					Stats.Common++;
					break;
				case 1:
					Stats.Uncommon++;
					break;
				case 2:
					Stats.Rare++;
					break;
				case 3:
					Stats.UltraRare++;
					break;
				}
			}
		}
	}
	public static class GameAssets
	{
		public static CosmeticTokenUIElement GetTokenPrefab()
		{
			CosmeticTokenUI val = Object.FindObjectOfType<CosmeticTokenUI>(true);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"TOKEN UI NOT FOUND");
				return null;
			}
			return val.tokenPrefab.GetComponent<CosmeticTokenUIElement>();
		}

		public static Color GetRarityColor(Rarity rarity)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected I4, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			return (Color)((int)rarity switch
			{
				0 => Color32.op_Implicit(new Color32((byte)0, byte.MaxValue, (byte)2, byte.MaxValue)), 
				1 => Color32.op_Implicit(new Color32((byte)0, (byte)195, byte.MaxValue, byte.MaxValue)), 
				2 => Color32.op_Implicit(new Color32(byte.MaxValue, (byte)110, (byte)244, byte.MaxValue)), 
				3 => Color32.op_Implicit(new Color32(byte.MaxValue, (byte)199, (byte)0, byte.MaxValue)), 
				_ => Color.white, 
			});
		}
	}
}
namespace Cosmetics_Box_Scanner.Patches
{
	[HarmonyPatch(typeof(PlayerAvatar))]
	[HarmonyPatch("Update")]
	public class PlayerUpdatePatch
	{
		private static float scanTimer;

		private static bool debugMode;

		public static void ResetTimer()
		{
			scanTimer = 0f;
		}

		private static void Postfix(PlayerAvatar __instance)
		{
			if ((Object)(object)__instance == (Object)null || (SemiFunc.IsMultiplayer() && ((Object)(object)__instance.photonView == (Object)null || !__instance.photonView.IsMine)))
			{
				return;
			}
			Plugin.Instance.scannerUI?.Tick();
			if (Input.GetKeyDown((KeyCode)287))
			{
				Plugin.Log.LogInfo((object)"F6 DETECTED");
				Plugin.Instance.ToggleGUI();
			}
			if ((Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303)) && Input.GetKeyDown((KeyCode)288))
			{
				debugMode = !debugMode;
				if (debugMode)
				{
					Plugin.Instance.scannerUI.Refresh(CosmeticStats.CreateDebugStats(), visible: true);
				}
				else
				{
					CosmeticScannerSystem.Scan();
					Plugin.Instance.scannerUI.Refresh(CosmeticScannerSystem.Stats, Plugin.ShowGUI);
				}
			}
			if (Plugin.ShowGUI && !debugMode)
			{
				scanTimer += Time.deltaTime;
				if (scanTimer >= 2f)
				{
					scanTimer = 0f;
					CosmeticScannerSystem.Scan();
					Plugin.Instance.scannerUI.Refresh(CosmeticScannerSystem.Stats, visible: true);
				}
			}
		}
	}
}
namespace Cosmetics_Box_Scanner.Models
{
	public class CosmeticStats
	{
		public int Common;

		public int Uncommon;

		public int Rare;

		public int UltraRare;

		public static CosmeticStats CreateDebugStats()
		{
			return new CosmeticStats
			{
				Common = 3,
				Uncommon = 2,
				Rare = 3,
				UltraRare = 1
			};
		}
	}
}