Decompiled source of MapDisplayPrices v1.1.0

plugins/MapDisplayPrices.dll

Decompiled 5 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("skey4ik")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Displays price label of valuable on the map.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MapDisplayPrices")]
[assembly: AssemblyTitle("MapDisplayPrices")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
}
internal static class ConfigManager
{
	public static ConfigFile ConfigFile { get; private set; }

	public static ConfigEntry<float> FontSize { get; private set; }

	public static ConfigEntry<string> TextColorHex { get; private set; }

	public static ConfigEntry<float> OffsetY { get; private set; }

	public static void Initialize(ConfigFile configFile)
	{
		ConfigFile = configFile;
		BindConfigs();
	}

	private static void BindConfigs()
	{
		FontSize = ConfigFile.Bind<float>("Visual", "FontSize", 2f, "Размер шрифта текста цены на карте.");
		TextColorHex = ConfigFile.Bind<string>("Visual", "TextColorHex", "#FFFF00", "Цвет текста цены.");
		OffsetY = ConfigFile.Bind<float>("Position", "Distance", 0.15f, "Distance from valuable");
	}
}
[BepInPlugin("MapDisplayPrices", "MapDisplayPrices", "1.0.0")]
public class Starter : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogInfo((object)"MapDisplayPrices has awoken");
		Harmony val = new Harmony("com.skey4ik.mapdisplayprices");
		ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
		val.PatchAll();
	}
}
namespace MapDisplayPrices
{
	[HarmonyPatch(typeof(Map), "AddValuable")]
	public class MapTextMod
	{
		public static Color GetConfigColor()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Color result = default(Color);
			if (ColorUtility.TryParseHtmlString(ConfigManager.TextColorHex.Value, ref result))
			{
				return result;
			}
			return Color.yellow;
		}

		[HarmonyPostfix]
		private static void Postfix(ValuableObject _valuable)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: 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)
			if (!((Object)(object)_valuable == (Object)null))
			{
				MapValuable val = ((Component)_valuable).GetComponentInChildren<MapValuable>();
				if ((Object)(object)val == (Object)null)
				{
					val = Object.FindObjectOfType<MapValuable>();
				}
				if ((Object)(object)val != (Object)null && (Object)(object)val.target == (Object)(object)_valuable && (Object)(object)((Component)val).transform.Find("MapText") == (Object)null)
				{
					GameObject val2 = new GameObject("MapText");
					val2.transform.SetParent(((Component)val).transform);
					val2.layer = ((Component)val).gameObject.layer;
					val2.transform.localScale = Vector3.one;
					val2.transform.localPosition = Vector3.zero;
					TextMeshPro obj = val2.AddComponent<TextMeshPro>();
					((TMP_Text)obj).fontSize = ConfigManager.FontSize.Value;
					((TMP_Text)obj).alignment = (TextAlignmentOptions)514;
					((Graphic)obj).color = GetConfigColor();
					((TMP_Text)obj).extraPadding = true;
					((TMP_Text)obj).outlineWidth = 0.25f;
					((TMP_Text)obj).outlineColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue);
					((TMP_Text)obj).fontMaterial.EnableKeyword("UNDERLAY_ON");
					((TMP_Text)obj).fontMaterial.SetColor(ShaderUtilities.ID_UnderlayColor, new Color(0f, 0f, 0f, 0.75f));
					((TMP_Text)obj).fontMaterial.SetVector(ShaderUtilities.ID_UnderlayOffset, new Vector4(0.1f, -0.1f, 0f, 0f));
					MapTextHelper mapTextHelper = val2.AddComponent<MapTextHelper>();
					mapTextHelper.targetValuable = _valuable;
					mapTextHelper.mapValuable = val;
				}
			}
		}
	}
	public class MapTextHelper : MonoBehaviour
	{
		public ValuableObject targetValuable;

		public MapValuable mapValuable;

		private TextMeshPro textMesh;

		private Camera mapCamera;

		private float lastPrice = -1f;

		private Color baseColor = Color.yellow;

		private FieldInfo dollarValueField;

		private FieldInfo itemValueField;

		private Component itemAttributesCache;

		private bool hasCachedFields;

		private const float MinAlphaThreshold = 0.3f;

		private void Start()
		{
			//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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			textMesh = ((Component)this).GetComponent<TextMeshPro>();
			mapCamera = Camera.main;
			if ((Object)(object)textMesh != (Object)null)
			{
				baseColor = MapTextMod.GetConfigColor();
				((Graphic)textMesh).color = baseColor;
				if ((Object)(object)((TMP_Text)textMesh).fontMaterial != (Object)null)
				{
					Material val = new Material(((TMP_Text)textMesh).fontMaterial);
					val.EnableKeyword("OUTLINE_ON");
					val.EnableKeyword("UNDERLAY_ON");
					val.SetColor("_OutlineColor", new Color(0f, 0f, 0f, 1f));
					val.SetFloat("_OutlineWidth", 0.12f);
					val.SetFloat("_OutlineSoftness", 0f);
					val.SetColor("_UnderlayColor", new Color(0f, 0f, 0f, 0.8f));
					val.SetVector("_UnderlayOffset", new Vector4(0.05f, -0.05f, 0f, 0f));
					val.SetFloat("_UnderlayBlur", 0f);
					val.renderQueue = 4000;
					val.SetInt("_ZTest", 8);
					((TMP_Text)textMesh).fontMaterial = val;
				}
			}
		}

		private void CacheFields()
		{
			if ((Object)(object)targetValuable != (Object)null)
			{
				dollarValueField = ((object)targetValuable).GetType().GetField("dollarValueCurrent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				itemAttributesCache = ((Component)targetValuable).GetComponent("ItemAttributes");
				if ((Object)(object)itemAttributesCache != (Object)null)
				{
					itemValueField = ((object)itemAttributesCache).GetType().GetField("value", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
			}
			hasCachedFields = true;
		}

		private void LateUpdate()
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: 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_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: 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_0247: 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)
			if ((Object)(object)targetValuable == (Object)null || (Object)(object)textMesh == (Object)null)
			{
				return;
			}
			if (!hasCachedFields)
			{
				CacheFields();
			}
			float num = 0f;
			if (dollarValueField != null)
			{
				num = (float)dollarValueField.GetValue(targetValuable);
			}
			if (num <= 0f && (Object)(object)itemAttributesCache != (Object)null && itemValueField != null)
			{
				num = (int)itemValueField.GetValue(itemAttributesCache);
			}
			if (!Mathf.Approximately(num, lastPrice))
			{
				string text = ((num > 0f) ? SemiFunc.DollarGetString(Mathf.CeilToInt(num)) : "...");
				((TMP_Text)textMesh).text = text;
				lastPrice = num;
			}
			if ((Object)(object)mapValuable != (Object)null && (Object)(object)mapValuable.spriteRenderer != (Object)null)
			{
				float a = mapValuable.spriteRenderer.color.a;
				float num2 = ((a > 0f) ? Mathf.Max(a, 0.3f) : 0f);
				if (!Mathf.Approximately(((Graphic)textMesh).color.a, num2))
				{
					baseColor.a = num2;
					((Graphic)textMesh).color = baseColor;
				}
			}
			if ((Object)(object)mapCamera == (Object)null)
			{
				mapCamera = Camera.main;
			}
			if ((Object)(object)mapCamera != (Object)null)
			{
				float num3 = ((Component)mapCamera).transform.eulerAngles.y * (MathF.PI / 180f);
				float num4 = Mathf.Sin(num3) * ConfigManager.OffsetY.Value;
				float num5 = Mathf.Cos(num3) * ConfigManager.OffsetY.Value;
				Vector3 val = (((Object)(object)((Component)this).transform.parent != (Object)null) ? ((Component)this).transform.parent.position : ((Component)this).transform.position);
				((Component)this).transform.position = new Vector3(val.x + num4, val.y + 0.05f, val.z + num5);
				((Component)this).transform.rotation = Quaternion.Euler(90f, ((Component)mapCamera).transform.eulerAngles.y, 0f);
			}
		}
	}
}