Decompiled source of RepoSkinCounter v0.1.0

plugins/RepoSkinCounter.dll

Decompiled 5 hours ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;

[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: AssemblyCompany("RepoSkinCounter")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RepoSkinCounter")]
[assembly: AssemblyTitle("RepoSkinCounter")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RepoSkinCounter;

[BepInPlugin("RepoSkinCounter", "R.E.P.O. Skin Counter", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public static ConfigEntry<bool> ShowRarityDetails;

	public static ConfigEntry<bool> ShowOnlyOnTab;

	private float currentAlpha = 0f;

	private float currentY = -60f;

	private float targetY = 15f;

	private float animSpeed = 8f;

	private float closeDelayTimer = 0f;

	private const float CLOSE_DELAY = 0.15f;

	private float timeToNextScan = 0f;

	private const float SCAN_INTERVAL = 0.5f;

	private string cachedLineTop = "";

	private string cachedLineBottom = "";

	private CosmeticWorldObject[] cachedBoxes = (CosmeticWorldObject[])(object)new CosmeticWorldObject[0];

	private readonly Color coreColor = new Color(1f, 0.75f, 0.15f);

	private readonly Color glowColor = new Color(1f, 0.85f, 0.2f);

	private const int TEXT_GLOW_RADIUS = 16;

	private const float TEXT_GLOW_INTENSITY = 0.02f;

	private readonly Dictionary<Rarity, Color> rarityColors = new Dictionary<Rarity, Color>
	{
		{
			(Rarity)0,
			new Color(0.15f, 1f, 0.15f)
		},
		{
			(Rarity)1,
			new Color(0.1f, 0.85f, 1f)
		},
		{
			(Rarity)2,
			new Color(1f, 0.1f, 0.5f)
		},
		{
			(Rarity)3,
			new Color(1f, 0.8f, 0f)
		}
	};

	private void Awake()
	{
		ShowOnlyOnTab = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowOnlyOnTab", true, "Exibe o contador apenas ao segurar TAB.");
		ShowRarityDetails = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowRarityDetails", true, "Exibe os detalhes das raridades.");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"R.E.P.O. Skin Counter Atualizado com Sucesso!");
	}

	private void OnGUI()
	{
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: 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)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Expected O, but got Unknown
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		if (!SemiFunc.RunIsLevel() || (Object)(object)RoundDirector.instance == (Object)null || (Object)(object)ValuableDirector.instance == (Object)null)
		{
			currentAlpha = 0f;
			currentY = -60f;
			closeDelayTimer = 0f;
			return;
		}
		bool key = Input.GetKey((KeyCode)9);
		bool flag = !ShowOnlyOnTab.Value || key;
		if (flag)
		{
			closeDelayTimer = 0.15f;
		}
		else if (closeDelayTimer > 0f)
		{
			closeDelayTimer -= Time.deltaTime;
			flag = true;
		}
		float num = (flag ? 1f : 0f);
		float num2 = (flag ? targetY : (-60f));
		currentAlpha = Mathf.Lerp(currentAlpha, num, Time.deltaTime * animSpeed);
		currentY = Mathf.Lerp(currentY, num2, Time.deltaTime * animSpeed);
		if (!(currentAlpha <= 0.01f))
		{
			if (Time.time >= timeToNextScan)
			{
				timeToNextScan = Time.time + 0.5f;
				UpdateCachedData();
			}
			GUIStyle style = new GUIStyle
			{
				fontSize = 22,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)1,
				richText = true
			};
			float num3 = 700f;
			float num4 = 100f;
			float num5 = ((float)Screen.width - num3) / 2f;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(num5, currentY, num3, num4);
			DrawTrueGlowText(val, cachedLineTop, cachedLineBottom, style, currentAlpha);
			DrawRealSquares(val, style, currentAlpha);
		}
	}

	private void UpdateCachedData()
	{
		cachedBoxes = Object.FindObjectsOfType<CosmeticWorldObject>();
		int num = ((cachedBoxes != null) ? cachedBoxes.Length : 0);
		cachedLineTop = $"SKINS ON MAP: {num}".ToUpper();
		string text = "";
		if (cachedBoxes != null && num > 0 && ShowRarityDetails.Value)
		{
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			CosmeticWorldObject[] array = cachedBoxes;
			foreach (CosmeticWorldObject val in array)
			{
				string key = ((object)Unsafe.As<Rarity, Rarity>(ref val.rarity)/*cast due to .constrained prefix*/).ToString();
				if (!dictionary.ContainsKey(key))
				{
					dictionary[key] = 0;
				}
				dictionary[key]++;
			}
			text = "<size=15>";
			foreach (KeyValuePair<string, int> item in dictionary)
			{
				text += $"[{item.Key}: {item.Value}] ";
			}
			text += "</size>";
		}
		cachedLineBottom = text.ToUpper();
	}

	private void DrawRealSquares(Rect textRect, GUIStyle style, float alpha)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		//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_004a: 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)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: 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_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: 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_016e: Unknown result type (might be due to invalid IL or missing references)
		if (cachedBoxes == null || cachedBoxes.Length == 0)
		{
			return;
		}
		GUIContent val = new GUIContent(cachedLineTop);
		Vector2 val2 = style.CalcSize(val);
		float num = ((Rect)(ref textRect)).x + ((Rect)(ref textRect)).width / 2f + val2.x / 2f + 10f;
		float num2 = 13f;
		float num3 = ((Rect)(ref textRect)).y + 6f;
		float num4 = 17f;
		Texture2D whiteTexture = Texture2D.whiteTexture;
		Rect val4 = default(Rect);
		for (int i = 0; i < cachedBoxes.Length; i++)
		{
			Rarity rarity = cachedBoxes[i].rarity;
			Color val3 = (rarityColors.ContainsKey(rarity) ? rarityColors[rarity] : Color.white);
			float num5 = num + (float)i * num4;
			int num6 = 8;
			for (int j = -num6; j <= num6; j += 2)
			{
				for (int k = -num6; k <= num6; k += 2)
				{
					if (j != 0 || k != 0)
					{
						float num7 = Mathf.Sqrt((float)(j * j + k * k));
						if (!(num7 > (float)num6))
						{
							float num8 = Mathf.SmoothStep(1f, 0f, num7 / (float)num6);
							float num9 = num8 * 0.12f * alpha;
							GUI.color = new Color(val3.r, val3.g, val3.b, num9);
							GUI.DrawTexture(new Rect(num5 + (float)j, num3 + (float)k, num2, num2), (Texture)(object)whiteTexture);
						}
					}
				}
			}
			GUI.color = new Color(val3.r, val3.g, val3.b, alpha);
			((Rect)(ref val4))..ctor(num5, num3, num2, num2);
			GUI.DrawTexture(val4, (Texture)(object)whiteTexture);
		}
		GUI.color = Color.white;
	}

	private void DrawTrueGlowText(Rect rect, string lineTop, string lineBottom, GUIStyle style, float alpha)
	{
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: 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)
		string text = lineTop;
		if (!string.IsNullOrEmpty(lineBottom))
		{
			text = text + "\n" + lineBottom;
		}
		Rect val = default(Rect);
		for (int i = -16; i <= 16; i += 2)
		{
			for (int j = -16; j <= 16; j += 2)
			{
				if (i != 0 || j != 0)
				{
					float num = Mathf.Sqrt((float)(i * i + j * j));
					if (!(num > 16f))
					{
						float num2 = num / 16f;
						float num3 = Mathf.SmoothStep(1f, 0f, num2);
						float num4 = num3 * 0.02f * alpha;
						style.normal.textColor = new Color(glowColor.r, glowColor.g, glowColor.b, num4);
						((Rect)(ref val))..ctor(((Rect)(ref rect)).x + (float)i, ((Rect)(ref rect)).y + (float)j, ((Rect)(ref rect)).width, ((Rect)(ref rect)).height);
						GUI.Label(val, text, style);
					}
				}
			}
		}
		style.normal.textColor = new Color(coreColor.r, coreColor.g, coreColor.b, coreColor.a * alpha);
		GUI.Label(rect, text, style);
	}
}