Decompiled source of WindIndicatorUI v1.1.1

plugins/LeerWindIndicatorUI.dll

Decompiled 3 months ago
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PEAK")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PEAK")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("94d12321-9932-43d2-ba03-502c40b6fcee")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.leer.windicon", "Wind Zone Icon", "1.0.1")]
public class WindZoneIconMod : BaseUnityPlugin
{
	private Sprite windSprite;

	private CanvasGroup iconGroup;

	private WindChillZone[] windZones;

	private float fadeSpeed = 1f;

	private ConfigEntry<Vector2> iconPosition;

	private void Awake()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		iconPosition = ((BaseUnityPlugin)this).Config.Bind<Vector2>("UI", "IconPosition", new Vector2(0f, -60f), "Position of the wind icon on screen (x, y)");
		SceneManager.sceneLoaded += OnSceneLoaded;
		LoadIcon();
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		CreateUI();
		windZones = Object.FindObjectsOfType<WindChillZone>();
	}

	private void LoadIcon()
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		//IL_005a: 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)
		string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "windindicatorui_sprites", "WindIndicator.png");
		if (File.Exists(text))
		{
			byte[] array = File.ReadAllBytes(text);
			Texture2D val = new Texture2D(2, 2);
			if (ImageConversion.LoadImage(val, array))
			{
				windSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			}
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Icon not found at: " + text));
		}
	}

	private void CreateUI()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Expected O, but got Unknown
		//IL_00b2: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)GameObject.Find("WindIconCanvas") != (Object)null))
		{
			GameObject val = new GameObject("WindIconCanvas");
			Canvas obj = val.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 1000;
			CanvasScaler obj2 = val.AddComponent<CanvasScaler>();
			obj2.uiScaleMode = (ScaleMode)1;
			obj2.referenceResolution = new Vector2(1920f, 1080f);
			obj2.matchWidthOrHeight = 0.5f;
			val.AddComponent<GraphicRaycaster>();
			GameObject val2 = new GameObject("WindIcon");
			val2.transform.SetParent(val.transform, false);
			Image obj3 = val2.AddComponent<Image>();
			obj3.sprite = windSprite;
			Shadow obj4 = val2.AddComponent<Shadow>();
			obj4.effectColor = new Color(0f, 0f, 0f, 0.6f);
			obj4.effectDistance = new Vector2(2f, -2f);
			RectTransform rectTransform = ((Graphic)obj3).rectTransform;
			rectTransform.anchorMin = new Vector2(0.5f, 1f);
			rectTransform.anchorMax = new Vector2(0.5f, 1f);
			rectTransform.pivot = new Vector2(0.5f, 1f);
			rectTransform.anchoredPosition = iconPosition.Value;
			rectTransform.sizeDelta = new Vector2(64f, 64f);
			iconGroup = val2.AddComponent<CanvasGroup>();
			iconGroup.alpha = 0f;
		}
	}

	private void Update()
	{
		if ((Object)(object)iconGroup == (Object)null || windZones == null || windZones.Length == 0)
		{
			return;
		}
		float num = (((Object)(object)Character.localCharacter != (Object)null && (Object)(object)Character.observedCharacter == (Object)(object)Character.localCharacter && windZones.Any(delegate(WindChillZone zone)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			if (zone.windPlayerFactor > 0.01f)
			{
				StormVisual componentInChildren = ((Component)zone).GetComponentInChildren<StormVisual>();
				if (componentInChildren != null)
				{
					return (int)componentInChildren.stormType == 1;
				}
			}
			return false;
		})) ? 1f : 0f);
		iconGroup.alpha = Mathf.MoveTowards(iconGroup.alpha, num, Time.deltaTime * fadeSpeed);
	}
}