Decompiled source of ShowPlayerName v1.0.0

ShowPlayerName.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 Mirror;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("ShowPlayerName")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Show Player Name - Display all player names with outline")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ShowPlayerName")]
[assembly: AssemblyTitle("ShowPlayerName")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[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 ShowPlayerName
{
	public static class PlayerESP
	{
		private static Font _font;

		private static GUIStyle _name;

		private static GUIStyle _outline;

		private static bool _init;

		private static readonly List<PlayerObjectController> _list;

		private static float _nextRefresh;

		private static int _lastScene;

		private static readonly Rect[] _r;

		static PlayerESP()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			_list = new List<PlayerObjectController>();
			_r = (Rect[])(object)new Rect[9];
			for (int i = 0; i < 9; i++)
			{
				_r[i] = default(Rect);
			}
		}

		public static void Draw()
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: 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_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			if (!_init)
			{
				_init = true;
				string[] array = new string[5] { "Microsoft YaHei", "SimHei", "SimSun", "Arial Unicode MS", "Arial" };
				for (int i = 0; i < array.Length; i++)
				{
					try
					{
						_font = Font.CreateDynamicFontFromOSFont(array[i], 28);
						if ((Object)(object)_font != (Object)null)
						{
							break;
						}
					}
					catch
					{
					}
				}
				if ((Object)(object)_font == (Object)null)
				{
					_font = GUI.skin.font;
				}
				_name = MakeStyle(new Color(0.2f, 0.5f, 1f, 1f));
				_outline = MakeStyle(new Color(0f, 0.9f, 0.2f, 1f));
			}
			Scene activeScene = SceneManager.GetActiveScene();
			int handle = ((Scene)(ref activeScene)).handle;
			if (handle != _lastScene)
			{
				_lastScene = handle;
				_list.Clear();
				_nextRefresh = 0f;
				return;
			}
			float time = Time.time;
			if (time >= _nextRefresh)
			{
				_nextRefresh = time + 3f;
				_list.Clear();
				NetworkManager singleton = NetworkManager.singleton;
				CustomNetworkManager val = (CustomNetworkManager)(object)((singleton is CustomNetworkManager) ? singleton : null);
				if (((val != null) ? val.GamePlayers : null) != null)
				{
					foreach (PlayerObjectController gamePlayer in val.GamePlayers)
					{
						if ((Object)(object)gamePlayer != (Object)null && Object.op_Implicit((Object)(object)gamePlayer))
						{
							_list.Add(gamePlayer);
						}
					}
				}
			}
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				return;
			}
			for (int num = _list.Count - 1; num >= 0; num--)
			{
				PlayerObjectController val2 = _list[num];
				if ((Object)(object)val2 == (Object)null || !Object.op_Implicit((Object)(object)val2))
				{
					_list.RemoveAt(num);
					continue;
				}
				string playerName;
				try
				{
					playerName = val2.PlayerName;
				}
				catch
				{
					continue;
				}
				if (string.IsNullOrEmpty(playerName))
				{
					continue;
				}
				Vector3 val3;
				try
				{
					Vector3 position = ((Component)val2).transform.position;
					position.y += 2.2f;
					val3 = main.WorldToScreenPoint(position);
					if (val3.z <= 0f || val3.z > 200f)
					{
						continue;
					}
					goto IL_0263;
				}
				catch
				{
				}
				continue;
				IL_0263:
				float x = val3.x;
				float num2 = (float)Screen.height - val3.y;
				if (!(x < -200f) && !(x > (float)(Screen.width + 200)) && !(num2 < -200f) && !(num2 > (float)(Screen.height + 200)))
				{
					float num3 = 10f / Mathf.Max(val3.z, 0.1f);
					int num4 = (int)Mathf.Clamp(28f * num3, 12f, 48f);
					GUIStyle name = _name;
					int fontSize = (_outline.fontSize = num4);
					name.fontSize = fontSize;
					float num6 = (float)(playerName.Length * num4) * 0.7f + 16f;
					float num7 = (float)num4 + 14f;
					float num8 = x - num6 * 0.5f;
					float num9 = num2 - num7 * 0.5f;
					float num10 = (float)num4 * 0.1f + 1f;
					((Rect)(ref _r[0])).Set(num8 - num10, num9 - num10, num6, num7);
					((Rect)(ref _r[1])).Set(num8 + num10, num9 - num10, num6, num7);
					((Rect)(ref _r[2])).Set(num8 - num10, num9 + num10, num6, num7);
					((Rect)(ref _r[3])).Set(num8 + num10, num9 + num10, num6, num7);
					((Rect)(ref _r[4])).Set(num8 - num10, num9, num6, num7);
					((Rect)(ref _r[5])).Set(num8 + num10, num9, num6, num7);
					((Rect)(ref _r[6])).Set(num8, num9 - num10, num6, num7);
					((Rect)(ref _r[7])).Set(num8, num9 + num10, num6, num7);
					for (int j = 0; j < 8; j++)
					{
						GUI.Label(_r[j], playerName, _outline);
					}
					((Rect)(ref _r[8])).Set(num8, num9, num6, num7);
					GUI.Label(_r[8], playerName, _name);
				}
			}
		}

		private static GUIStyle MakeStyle(Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			GUIStyle val = new GUIStyle
			{
				font = _font,
				fontSize = 28,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)4
			};
			val.normal.textColor = c;
			val.wordWrap = false;
			val.clipping = (TextClipping)0;
			return val;
		}
	}
	[BepInPlugin("com.showplayername.mod", "ShowPlayerName", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ShowPlayerName loaded");
		}

		private void OnGUI()
		{
			PlayerESP.Draw();
		}
	}
}