Decompiled source of CursorClarity v1.0.3

plugins/CursorClarity/CursorClarity.dll

Decompiled 9 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CursorClarity")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("CursorClarity")]
[assembly: AssemblyTitle("CursorClarity")]
[assembly: AssemblyVersion("1.0.3.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CursorClarity
{
	internal enum CrosshairColor
	{
		Cyan,
		Magenta,
		Yellow,
		Green,
		Red,
		Blue,
		Orange,
		Purple,
		White,
		Lime,
		Pink
	}
	[BepInPlugin("com.naccel.cursorclarity", "CursorClarity", "1.0.3")]
	public sealed class Plugin : BasePlugin
	{
		public const string PluginGuid = "com.naccel.cursorclarity";

		public const string PluginName = "CursorClarity";

		public const string PluginVersion = "1.0.3";

		internal static ManualLogSource Logger;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<CrosshairColor> ColorName;

		internal static ConfigEntry<int> Size;

		internal static ConfigEntry<float> Opacity;

		public override void Load()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			Enabled = ((BasePlugin)this).Config.Bind<bool>("Cursor", "Enabled", true, "Show a high-contrast crosshair at the mouse position.");
			ColorName = ((BasePlugin)this).Config.Bind<CrosshairColor>("Cursor", "Color", CrosshairColor.Cyan, "Crosshair color.");
			Size = ((BasePlugin)this).Config.Bind<int>("Cursor", "Size", 36, new ConfigDescription("Crosshair size in pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(12, 64), Array.Empty<object>()));
			Opacity = ((BasePlugin)this).Config.Bind<float>("Cursor", "Opacity", 1f, new ConfigDescription("Crosshair opacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 1f), Array.Empty<object>()));
			ClassInjector.RegisterTypeInIl2Cpp<CursorOverlay>();
			((BasePlugin)this).AddComponent<CursorOverlay>();
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(8, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("CursorClarity");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded.");
			}
			log.LogInfo(val);
		}
	}
	public sealed class CursorOverlay : MonoBehaviour
	{
		private Texture2D _reticle;

		private Image _reticleImage;

		private RectTransform _reticleTransform;

		private bool _loggedVisible;

		public CursorOverlay(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Awake()
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: 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_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: 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_005a: Expected O, but got Unknown
			string text = Assembly.GetExecutingAssembly().GetManifestResourceNames().FirstOrDefault((string name) => name.EndsWith("aim-reticle.png", StringComparison.OrdinalIgnoreCase));
			if (text != null)
			{
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(text);
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				_reticle = new Texture2D(2, 2, (TextureFormat)4, false);
				ImageConversion.LoadImage(_reticle, Il2CppStructArray<byte>.op_Implicit(memoryStream.ToArray()), false);
			}
			if ((Object)(object)_reticle != (Object)null)
			{
				((Texture)_reticle).wrapMode = (TextureWrapMode)1;
				GameObject val = new GameObject("CursorClarityScreenOverlay");
				val.transform.SetParent(((Component)this).transform, false);
				Canvas obj = val.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.overrideSorting = true;
				obj.sortingOrder = 32760;
				val.AddComponent<CanvasScaler>().uiScaleMode = (ScaleMode)0;
				GameObject val2 = new GameObject("RunReticle");
				val2.transform.SetParent(val.transform, false);
				_reticleImage = val2.AddComponent<Image>();
				_reticleTransform = val2.GetComponent<RectTransform>();
				_reticleTransform.anchorMin = new Vector2(0.5f, 0.5f);
				_reticleTransform.anchorMax = new Vector2(0.5f, 0.5f);
				_reticleTransform.pivot = new Vector2(0.5f, 0.5f);
				_reticleImage.sprite = Sprite.Create(_reticle, new Rect(0f, 0f, (float)((Texture)_reticle).width, (float)((Texture)_reticle).height), new Vector2(0.5f, 0.5f));
				((Graphic)_reticleImage).raycastTarget = false;
				((Behaviour)_reticleImage).enabled = false;
			}
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			ManualLogSource logger = Plugin.Logger;
			if (logger != null)
			{
				logger.LogInfo((object)(((Object)(object)_reticle != (Object)null) ? "Run reticle initialized." : "Run reticle image failed to load."));
			}
		}

		private void LateUpdate()
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Invalid comparison between Unknown and I4
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_reticleImage == (Object)null || (Object)(object)_reticleTransform == (Object)null)
			{
				return;
			}
			string text = FindLoadedRunScene();
			bool flag = Plugin.Enabled != null && Plugin.Enabled.Value && text != null;
			((Behaviour)_reticleImage).enabled = flag;
			if (!flag)
			{
				return;
			}
			if (!_loggedVisible)
			{
				ManualLogSource logger = Plugin.Logger;
				if (logger != null)
				{
					bool flag2 = default(bool);
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(31, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Run reticle active in scene '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'.");
					}
					logger.LogInfo(val);
				}
				_loggedVisible = true;
			}
			Color color = GetColor(Plugin.ColorName.Value);
			color.a = Plugin.Opacity.Value;
			((Graphic)_reticleImage).color = color;
			Vector3 mousePosition = Input.mousePosition;
			float num = mousePosition.x;
			float num2 = mousePosition.y;
			if ((int)Cursor.lockState == 1 || num <= 0f || num >= (float)Screen.width || num2 <= 0f || num2 >= (float)Screen.height)
			{
				num = (float)Screen.width / 2f;
				num2 = (float)Screen.height / 2f;
			}
			float num3 = Plugin.Size.Value;
			_reticleTransform.anchoredPosition = new Vector2(num - (float)Screen.width / 2f, num2 - (float)Screen.height / 2f);
			_reticleTransform.sizeDelta = new Vector2(num3, num3);
		}

		private static string FindLoadedRunScene()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < SceneManager.sceneCount; i++)
			{
				Scene sceneAt = SceneManager.GetSceneAt(i);
				string name = ((Scene)(ref sceneAt)).name;
				if (name.Contains("Aurora", StringComparison.OrdinalIgnoreCase) || name.Contains("Celestium", StringComparison.OrdinalIgnoreCase) || name.Contains("Purgatory17", StringComparison.OrdinalIgnoreCase) || name.Contains("Aridune", StringComparison.OrdinalIgnoreCase) || name.Contains("Palium", StringComparison.OrdinalIgnoreCase))
				{
					return name;
				}
			}
			return null;
		}

		private static Color GetColor(CrosshairColor name)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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)
			return (Color)(name switch
			{
				CrosshairColor.Magenta => new Color(1f, 0.1f, 0.9f, 1f), 
				CrosshairColor.Yellow => new Color(1f, 0.95f, 0.1f, 1f), 
				CrosshairColor.Green => new Color(0.2f, 1f, 0.2f, 1f), 
				CrosshairColor.Red => new Color(1f, 0.15f, 0.12f, 1f), 
				CrosshairColor.Blue => new Color(0.15f, 0.4f, 1f, 1f), 
				CrosshairColor.Orange => new Color(1f, 0.48f, 0.08f, 1f), 
				CrosshairColor.Purple => new Color(0.68f, 0.28f, 1f, 1f), 
				CrosshairColor.White => Color.white, 
				CrosshairColor.Lime => new Color(0.68f, 1f, 0.12f, 1f), 
				CrosshairColor.Pink => new Color(1f, 0.35f, 0.65f, 1f), 
				_ => new Color(0.1f, 0.95f, 1f, 1f), 
			});
		}
	}
}