Decompiled source of AimDistanceMeter v0.1.1

AimDistanceMeter.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AimDistanceMeter")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("AimDistanceMeter")]
[assembly: AssemblyTitle("AimDistanceMeter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
		}
	}
	[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 AimDistanceMeter
{
	public sealed class DistanceMeterBehaviour : MonoBehaviour
	{
		private const float LabelWidth = 180f;

		private const float LabelHeight = 40f;

		private GUIStyle? _textStyle;

		private GUIStyle? _shadowStyle;

		private bool _visible;

		private string _distanceText = string.Empty;

		private int _lastFontSize = -1;

		private string _lastColorText = string.Empty;

		private float _nextErrorLogTime;

		private void Update()
		{
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			_visible = false;
			if (!Plugin.Enabled.Value || !PlayerManager.HasLocalPlayerAgent())
			{
				return;
			}
			try
			{
				PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
				if ((Object)(object)localPlayerAgent == (Object)null || !((Agent)localPlayerAgent).Alive)
				{
					return;
				}
				FirstPersonItemHolder fPItemHolder = localPlayerAgent.FPItemHolder;
				if ((Object)(object)fPItemHolder == (Object)null || !fPItemHolder.ItemAimTrigger)
				{
					return;
				}
				FPSCamera fPSCamera = localPlayerAgent.FPSCamera;
				if (!((Object)(object)fPSCamera == (Object)null) && !((Object)(object)fPSCamera.CameraRayCollider == (Object)null))
				{
					float cameraRayDist = fPSCamera.CameraRayDist;
					if (!float.IsNaN(cameraRayDist) && !float.IsInfinity(cameraRayDist) && !(cameraRayDist <= 0f))
					{
						_distanceText = cameraRayDist.ToString($"F{Plugin.DecimalPlaces.Value}", CultureInfo.InvariantCulture) + " m";
						_visible = true;
					}
				}
			}
			catch (Exception ex)
			{
				if (Time.unscaledTime >= _nextErrorLogTime)
				{
					ManualLogSource logger = Plugin.Logger;
					bool flag = default(bool);
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(28, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Distance HUD update failed: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					logger.LogWarning(val);
					_nextErrorLogTime = Time.unscaledTime + 5f;
				}
			}
		}

		private void OnGUI()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			if (_visible)
			{
				RefreshStylesIfNeeded();
				GUI.depth = -1000;
				float num = (float)Screen.width * 0.5f + (float)Plugin.HorizontalOffset.Value;
				float num2 = (float)Screen.height * 0.5f + (float)Plugin.VerticalOffset.Value - 20f;
				Rect val = new Rect(num, num2, 180f, 40f);
				GUI.Label(new Rect(num + 2f, num2 + 2f, 180f, 40f), _distanceText, _shadowStyle);
				GUI.Label(val, _distanceText, _textStyle);
			}
		}

		private void RefreshStylesIfNeeded()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_00b0: Expected O, but got Unknown
			//IL_00bb: 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_00d2: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			int value = Plugin.FontSize.Value;
			string value2 = Plugin.TextColor.Value;
			if (_textStyle == null || _shadowStyle == null || _lastFontSize != value || !string.Equals(_lastColorText, value2, StringComparison.Ordinal))
			{
				Color textColor = default(Color);
				((Color)(ref textColor))..ctor(0.56f, 0.92f, 1f, 1f);
				if (!ColorUtility.TryParseHtmlString(value2, ref textColor))
				{
					((Color)(ref textColor))..ctor(0.56f, 0.92f, 1f, 1f);
				}
				_textStyle = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)3,
					fontSize = value,
					fontStyle = (FontStyle)1,
					clipping = (TextClipping)0
				};
				_textStyle.normal.textColor = textColor;
				_shadowStyle = new GUIStyle(_textStyle);
				_shadowStyle.normal.textColor = new Color(0f, 0f, 0f, 0.9f);
				_lastFontSize = value;
				_lastColorText = value2;
			}
		}
	}
	[BepInPlugin("qlsl.gtfo.aimdistancemeter", "Aim Distance Meter", "0.1.0")]
	public sealed class Plugin : BasePlugin
	{
		public const string PluginGuid = "qlsl.gtfo.aimdistancemeter";

		public const string PluginName = "Aim Distance Meter";

		public const string PluginVersion = "0.1.0";

		internal static ManualLogSource Logger { get; private set; }

		internal static ConfigEntry<bool> Enabled { get; private set; }

		internal static ConfigEntry<int> HorizontalOffset { get; private set; }

		internal static ConfigEntry<int> VerticalOffset { get; private set; }

		internal static ConfigEntry<int> FontSize { get; private set; }

		internal static ConfigEntry<int> DecimalPlaces { get; private set; }

		internal static ConfigEntry<string> TextColor { get; private set; }

		public override void Load()
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			Enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "Show the distance meter while aiming.");
			HorizontalOffset = ((BasePlugin)this).Config.Bind<int>("Position", "HorizontalOffsetPixels", 200, "Horizontal offset in screen pixels from the crosshair. Positive values move the text right.");
			VerticalOffset = ((BasePlugin)this).Config.Bind<int>("Position", "VerticalOffsetPixels", 0, "Vertical offset in screen pixels from the crosshair. Positive values move the text down.");
			FontSize = ((BasePlugin)this).Config.Bind<int>("Appearance", "FontSize", 20, new ConfigDescription("Distance text font size.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(8, 72), Array.Empty<object>()));
			DecimalPlaces = ((BasePlugin)this).Config.Bind<int>("Appearance", "DecimalPlaces", 1, new ConfigDescription("Number of decimal places shown for the distance.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 2), Array.Empty<object>()));
			TextColor = ((BasePlugin)this).Config.Bind<string>("Appearance", "TextColor", "#8FEAFF", "HTML color used for the distance text, for example #8FEAFF.");
			((BasePlugin)this).AddComponent<DistanceMeterBehaviour>();
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Aim Distance Meter");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded.");
			}
			log.LogInfo(val);
		}
	}
}