Decompiled source of LootLeftCounter v1.0.3

BepInEx/plugins/LootLeftCounter.dll

Decompiled 9 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
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: AssemblyTitle("REPOMOD2.0")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("REPOMOD2.0")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("30f16c99-62bb-47f4-b509-69db2604c238")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LootLeftCounter;

public class LootCounterBehaviour : MonoBehaviour
{
	private TextMeshProUGUI labelText;

	private TextMeshProUGUI valueText;

	private GameObject containerGO;

	private Vector2 labelPosition = new Vector2(361.8f, 143.6f);

	private Vector2 valuePosition = new Vector2(363.3f, 47.5f);

	private float labelFontSize = 32f;

	private float valueFontSize = 48f;

	private Color labelColor = new Color(0.3f, 0.3f, 0.3f, 0.9f);

	private Color valueColorLow = new Color(0.6f, 0.2f, 0.2f, 0.9f);

	private Color valueColorMedium = new Color(0.7f, 0.6f, 0.2f, 0.9f);

	private Color valueColorHigh = new Color(0.3f, 0.7f, 0.3f, 0.9f);

	private bool isOpening = false;

	private float openTimer = 0f;

	private bool isClosing = false;

	private float closeTimer = 0f;

	private float closeDelay = 0.15f;

	private float delayTimer = 0f;

	private bool isWaitingForClose = false;

	private float animationDuration = 0.2f;

	private Vector2 startPos;

	private Vector2 endPos;

	private Vector2 exitPos;

	private FieldInfo dollarValueField;

	private FieldInfo inStartRoomField;

	private TMP_FontAsset tekoFont;

	private bool isInitialized = false;

	public static LootCounterBehaviour Instance { get; private set; }

	private void Awake()
	{
		if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
		{
			Object.Destroy((Object)(object)this);
			return;
		}
		Instance = this;
		LoadTekoFont();
	}

	private void LoadTekoFont()
	{
		string[] array = new string[4] { "Fonts & Materials/Teko-Regular SDF", "Fonts/Teko/Teko-Medium SDF", "Teko-Regular SDF", "Teko-Medium SDF" };
		string[] array2 = array;
		foreach (string text in array2)
		{
			tekoFont = Resources.Load<TMP_FontAsset>(text);
			if ((Object)(object)tekoFont != (Object)null)
			{
				return;
			}
		}
		TMP_FontAsset[] array3 = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
		TMP_FontAsset[] array4 = array3;
		foreach (TMP_FontAsset val in array4)
		{
			if (((Object)val).name.ToLower().Contains("teko"))
			{
				tekoFont = val;
				break;
			}
		}
	}

	private void Start()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		//IL_007f: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: 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_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Expected O, but got Unknown
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Expected O, but got Unknown
		//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_030b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0322: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
		if (isInitialized)
		{
			return;
		}
		Canvas[] array = Object.FindObjectsOfType<Canvas>();
		if (array.Length != 0)
		{
			Canvas val = array[0];
			containerGO = new GameObject("LootCounterContainer", new Type[1] { typeof(RectTransform) });
			containerGO.transform.SetParent(((Component)val).transform, false);
			RectTransform component = containerGO.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.02f, 0.05f);
			component.anchorMax = new Vector2(0.02f, 0.05f);
			component.pivot = new Vector2(0f, 0.5f);
			component.sizeDelta = new Vector2(400f, 150f);
			startPos = new Vector2(200f, -40f);
			endPos = new Vector2(20f, 0f);
			exitPos = new Vector2(200f, -40f);
			component.anchoredPosition = startPos;
			GameObject val2 = new GameObject("LabelText", new Type[2]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer)
			});
			val2.transform.SetParent(containerGO.transform, false);
			RectTransform component2 = val2.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0.5f, 0.5f);
			component2.anchorMax = new Vector2(0.5f, 0.5f);
			component2.pivot = new Vector2(0.5f, 1f);
			component2.anchoredPosition = labelPosition;
			component2.sizeDelta = new Vector2(300f, 40f);
			labelText = val2.AddComponent<TextMeshProUGUI>();
			((TMP_Text)labelText).text = "LEFT";
			((TMP_Text)labelText).fontSize = labelFontSize;
			((TMP_Text)labelText).fontStyle = (FontStyles)1;
			((TMP_Text)labelText).alignment = (TextAlignmentOptions)514;
			if ((Object)(object)tekoFont != (Object)null)
			{
				((TMP_Text)labelText).font = tekoFont;
			}
			((Graphic)labelText).color = new Color(labelColor.r, labelColor.g, labelColor.b, 0f);
			GameObject val3 = new GameObject("ValueText", new Type[2]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer)
			});
			val3.transform.SetParent(containerGO.transform, false);
			RectTransform component3 = val3.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0.5f, 0.5f);
			component3.anchorMax = new Vector2(0.5f, 0.5f);
			component3.pivot = new Vector2(0.5f, 0f);
			component3.anchoredPosition = valuePosition;
			component3.sizeDelta = new Vector2(350f, 80f);
			valueText = val3.AddComponent<TextMeshProUGUI>();
			((TMP_Text)valueText).text = "$0";
			((TMP_Text)valueText).fontSize = valueFontSize;
			((TMP_Text)valueText).fontStyle = (FontStyles)1;
			((TMP_Text)valueText).alignment = (TextAlignmentOptions)514;
			if ((Object)(object)tekoFont != (Object)null)
			{
				((TMP_Text)valueText).font = tekoFont;
			}
			((Graphic)valueText).color = new Color(valueColorHigh.r, valueColorHigh.g, valueColorHigh.b, 0f);
			containerGO.SetActive(false);
			isInitialized = true;
		}
	}

	public void OnMapOpened()
	{
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: 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_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		if (isInitialized && !((Object)(object)labelText == (Object)null) && !((Object)(object)valueText == (Object)null) && !((Object)(object)containerGO == (Object)null))
		{
			isClosing = false;
			UpdateLootValue();
			isOpening = true;
			openTimer = 0f;
			containerGO.SetActive(true);
			RectTransform component = containerGO.GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				component.anchoredPosition = startPos;
			}
			((Graphic)labelText).color = new Color(labelColor.r, labelColor.g, labelColor.b, 0f);
			((Graphic)valueText).color = new Color(((Graphic)valueText).color.r, ((Graphic)valueText).color.g, ((Graphic)valueText).color.b, 0f);
		}
	}

	public void OnMapClosed()
	{
		if (isInitialized && !((Object)(object)containerGO == (Object)null) && containerGO.activeSelf)
		{
			isOpening = false;
			isWaitingForClose = true;
			delayTimer = 0f;
		}
	}

	private void UpdateLootValue()
	{
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: 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_01a1: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)valueText == (Object)null)
		{
			return;
		}
		float num = 0f;
		if ((Object)(object)ValuableDirector.instance == (Object)null || ValuableDirector.instance.valuableList == null)
		{
			((TMP_Text)valueText).text = "$0";
			return;
		}
		if (dollarValueField == null)
		{
			dollarValueField = typeof(ValuableObject).GetField("dollarValueCurrent", BindingFlags.Instance | BindingFlags.NonPublic);
			inStartRoomField = typeof(ValuableObject).GetField("inStartRoom", BindingFlags.Instance | BindingFlags.NonPublic);
		}
		foreach (ValuableObject valuable in ValuableDirector.instance.valuableList)
		{
			if (!((Object)(object)valuable == (Object)null))
			{
				bool flag = (bool)inStartRoomField.GetValue(valuable);
				float num2 = (float)dollarValueField.GetValue(valuable);
				if (!flag)
				{
					num += num2;
				}
			}
		}
		int num3 = Mathf.RoundToInt(num);
		((TMP_Text)valueText).text = $"${num3}";
		if (num3 < 500)
		{
			((Graphic)valueText).color = valueColorLow;
		}
		else if (num3 < 2000)
		{
			((Graphic)valueText).color = valueColorMedium;
		}
		else
		{
			((Graphic)valueText).color = valueColorHigh;
		}
		((Graphic)labelText).color = labelColor;
	}

	private void Update()
	{
		//IL_0088: 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_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: 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_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_028c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0298: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)containerGO == (Object)null || !containerGO.activeSelf)
		{
			return;
		}
		RectTransform component = containerGO.GetComponent<RectTransform>();
		if (isOpening)
		{
			openTimer += Time.deltaTime;
			float num = Mathf.Clamp01(openTimer / animationDuration);
			num = Mathf.SmoothStep(0f, 1f, num);
			if ((Object)(object)component != (Object)null)
			{
				Vector2 anchoredPosition = Vector2.Lerp(startPos, endPos, num);
				component.anchoredPosition = anchoredPosition;
			}
			if ((Object)(object)labelText != (Object)null)
			{
				((Graphic)labelText).color = new Color(((Graphic)labelText).color.r, ((Graphic)labelText).color.g, ((Graphic)labelText).color.b, num * labelColor.a);
			}
			if ((Object)(object)valueText != (Object)null)
			{
				Color color = ((Graphic)valueText).color;
				((Graphic)valueText).color = new Color(color.r, color.g, color.b, num * 0.9f);
			}
			if (num >= 1f)
			{
				isOpening = false;
			}
		}
		if (isWaitingForClose)
		{
			delayTimer += Time.deltaTime;
			if (delayTimer >= closeDelay)
			{
				isWaitingForClose = false;
				isClosing = true;
				closeTimer = 0f;
			}
		}
		if (!isClosing)
		{
			return;
		}
		closeTimer += Time.deltaTime;
		float num2 = Mathf.Clamp01(closeTimer / animationDuration);
		num2 = Mathf.SmoothStep(0f, 1f, num2);
		if ((Object)(object)component != (Object)null)
		{
			Vector2 anchoredPosition2 = Vector2.Lerp(endPos, exitPos, num2);
			component.anchoredPosition = anchoredPosition2;
		}
		if ((Object)(object)labelText != (Object)null)
		{
			float num3 = Mathf.Lerp(labelColor.a, 0f, num2);
			((Graphic)labelText).color = new Color(((Graphic)labelText).color.r, ((Graphic)labelText).color.g, ((Graphic)labelText).color.b, num3);
		}
		if ((Object)(object)valueText != (Object)null)
		{
			float num4 = Mathf.Lerp(0.9f, 0f, num2);
			((Graphic)valueText).color = new Color(((Graphic)valueText).color.r, ((Graphic)valueText).color.g, ((Graphic)valueText).color.b, num4);
		}
		if (num2 >= 1f)
		{
			isClosing = false;
			containerGO.SetActive(false);
			if ((Object)(object)component != (Object)null)
			{
				component.anchoredPosition = startPos;
			}
		}
	}
}
[BepInPlugin("GildMade.LootLeftCounter", "Loot Left Counter", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private const string modGUID = "GildMade.LootLeftCounter";

	private const string modName = "Loot Left Counter";

	private const string modVersion = "1.0.0";

	private readonly Harmony harmony = new Harmony("GildMade.LootLeftCounter");

	public static ManualLogSource mls;

	private void Awake()
	{
		mls = Logger.CreateLogSource("GildMade.LootLeftCounter");
		mls.LogInfo((object)"Мод Loot Left Counter успешно загружен!");
		harmony.PatchAll(typeof(MapPatch));
	}
}
[HarmonyPatch(typeof(Map))]
internal class MapPatch
{
	[HarmonyPatch("Awake")]
	[HarmonyPostfix]
	private static void AwakePostfix(Map __instance)
	{
		if ((Object)(object)((Component)__instance).gameObject.GetComponent<LootCounterBehaviour>() == (Object)null)
		{
			((Component)__instance).gameObject.AddComponent<LootCounterBehaviour>();
		}
	}

	[HarmonyPatch("ActiveSet", new Type[] { typeof(bool) })]
	[HarmonyPostfix]
	private static void ActiveSetPostfix(Map __instance, bool active)
	{
		LootCounterBehaviour component = ((Component)__instance).GetComponent<LootCounterBehaviour>();
		if ((Object)(object)component != (Object)null)
		{
			if (active)
			{
				component.OnMapOpened();
			}
			else
			{
				component.OnMapClosed();
			}
		}
	}
}