Decompiled source of PlayerDistanceDisplay v1.0.1

BepInEx/plugins/welniany/PlayerDistanceDisplay.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PlayerDistanceDisplay")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("PlayerDistanceDisplay")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 PlayerDistanceDisplay
{
	[BepInPlugin("org.bepinex.plugins.welniany.playerdistancedisplay", "PlayerDistanceDisplay", "1.2.0.0")]
	[BepInProcess("PEAK.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PlayerDistanceDisplay loaded!");
			GameObject val = new GameObject("PlayerDistanceDisplayManager");
			Object.DontDestroyOnLoad((Object)(object)val);
			val.AddComponent<PlayerDistanceDisplayManager>();
		}
	}
	public class PlayerDistanceDisplayManager : MonoBehaviour
	{
		private class PlayerLabelData
		{
			public Transform target;

			public string nick;

			public float spawnTime;

			public float distance;

			public float nextDistanceUpdate;

			public Vector3 screenPos;

			public bool isActive;
		}

		public float labelAliveTime = 8f;

		public float distanceUpdateInterval = 0.2f;

		private Camera mainCamera;

		private List<PlayerLabelData> labels = new List<PlayerLabelData>();

		private void Start()
		{
			mainCamera = Camera.main;
			SceneManager.activeSceneChanged += OnSceneChanged;
		}

		private void OnDestroy()
		{
			SceneManager.activeSceneChanged -= OnSceneChanged;
		}

		private void OnSceneChanged(Scene oldScene, Scene newScene)
		{
			labels.Clear();
		}

		private void Update()
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)mainCamera == (Object)null)
			{
				mainCamera = Camera.main;
			}
			foreach (PlayerLabelData label in labels)
			{
				if (label.isActive)
				{
					if (Time.time > label.nextDistanceUpdate)
					{
						label.distance = Vector3.Distance(((Component)mainCamera).transform.position, label.target.position);
						label.nextDistanceUpdate = Time.time + distanceUpdateInterval;
					}
					Vector3 val = label.target.position + Vector3.up * 1.2f;
					label.screenPos = mainCamera.WorldToScreenPoint(val);
					if (Time.time - label.spawnTime > labelAliveTime)
					{
						label.isActive = false;
					}
				}
			}
			if (Input.GetKeyDown((KeyCode)116))
			{
				ActivateLabels();
			}
		}

		private void ActivateLabels()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: 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)
			int num = LayerMask.NameToLayer("Character");
			Scene activeScene = SceneManager.GetActiveScene();
			GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
			foreach (GameObject val in rootGameObjects)
			{
				if (val.layer != num)
				{
					continue;
				}
				Transform charLight = val.transform.Find("Scout/Misc/CharacterLight");
				if (!((Object)(object)charLight == (Object)null))
				{
					PlayerLabelData playerLabelData = labels.Find((PlayerLabelData l) => (Object)(object)l.target == (Object)(object)charLight);
					if (playerLabelData != null)
					{
						playerLabelData.isActive = true;
						playerLabelData.spawnTime = Time.time;
						Vector3 val2 = charLight.position + Vector3.up * 1.2f;
						playerLabelData.screenPos = mainCamera.WorldToScreenPoint(val2);
						playerLabelData.distance = Vector3.Distance(((Component)mainCamera).transform.position, charLight.position);
						playerLabelData.nextDistanceUpdate = Time.time + distanceUpdateInterval;
					}
					else
					{
						string nick = ExtractDisplayName(((Object)val).name);
						Vector3 val3 = charLight.position + Vector3.up * 1.2f;
						Vector3 screenPos = mainCamera.WorldToScreenPoint(val3);
						labels.Add(new PlayerLabelData
						{
							target = charLight,
							nick = nick,
							spawnTime = Time.time,
							distance = Vector3.Distance(((Component)mainCamera).transform.position, charLight.position),
							nextDistanceUpdate = Time.time + distanceUpdateInterval,
							screenPos = screenPos,
							isActive = true
						});
					}
				}
			}
		}

		private string ExtractDisplayName(string objName)
		{
			int num = objName.IndexOf('[');
			int num2 = objName.LastIndexOf(':');
			if (num != -1 && num2 != -1)
			{
				return objName.Substring(num + 1, num2 - num - 1).Trim();
			}
			return objName;
		}

		private void OnGUI()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_0091: 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_0107: Expected O, but got Unknown
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Expected O, but got Unknown
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				fontSize = 20,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)4
			};
			Color white = Color.white;
			val.normal.textColor = white;
			val.hover.textColor = white;
			val.active.textColor = white;
			val.focused.textColor = white;
			val.onNormal.textColor = white;
			val.onHover.textColor = white;
			val.onActive.textColor = white;
			val.onFocused.textColor = white;
			val.normal.background = null;
			val.hover.background = null;
			val.active.background = null;
			val.focused.background = null;
			val.onNormal.background = null;
			val.onHover.background = null;
			val.onActive.background = null;
			val.onFocused.background = null;
			GUIStyle val2 = new GUIStyle(val);
			Color black = Color.black;
			val2.normal.textColor = black;
			val2.hover.textColor = black;
			val2.active.textColor = black;
			val2.focused.textColor = black;
			val2.onNormal.textColor = black;
			val2.onHover.textColor = black;
			val2.onActive.textColor = black;
			val2.onFocused.textColor = black;
			val2.normal.background = null;
			val2.hover.background = null;
			val2.active.background = null;
			val2.focused.background = null;
			val2.onNormal.background = null;
			val2.onHover.background = null;
			val2.onActive.background = null;
			val2.onFocused.background = null;
			Rect val4 = default(Rect);
			foreach (PlayerLabelData label in labels)
			{
				if (!label.isActive || label.screenPos.z <= 0f || label.distance < 10f || label.distance > 2000f)
				{
					continue;
				}
				string text = $"{label.nick}: {label.distance:F0}m";
				Vector2 val3 = val.CalcSize(new GUIContent(text));
				float num = 12f;
				float num2 = (float)Screen.height - label.screenPos.y;
				((Rect)(ref val4))..ctor(label.screenPos.x - val3.x / 2f - num, num2 - val3.y / 2f - num / 2f, val3.x + num * 2f, val3.y + num);
				for (int i = -1; i <= 1; i++)
				{
					for (int j = -1; j <= 1; j++)
					{
						if (i != 0 || j != 0)
						{
							GUI.Label(new Rect(((Rect)(ref val4)).x + (float)i, ((Rect)(ref val4)).y + (float)j, ((Rect)(ref val4)).width, ((Rect)(ref val4)).height), text, val2);
						}
					}
				}
				GUI.Label(val4, text, val);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "PlayerDistanceDisplay";

		public const string PLUGIN_NAME = "My first plugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}