Decompiled source of PingDistance v1.0.0

plugins/com.github.boxofbiscuits97.PingDistance.dll

Decompiled 4 days 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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.boxofbiscuits97.PingDistance")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+34a28102ab930186cce4cf77d3adb868af4b24e0")]
[assembly: AssemblyProduct("com.github.boxofbiscuits97.PingDistance")]
[assembly: AssemblyTitle("PingDistance")]
[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.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]
	[Microsoft.CodeAnalysis.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]
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace PingDistance
{
	[BepInPlugin("com.github.boxofbiscuits97.PingDistance", "PingDistance", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private static GameObject? TemplateText;

		private static readonly Dictionary<Character, GameObject> DistanceInstances = new Dictionary<Character, GameObject>();

		private static GameObject? PingDistanceCanvas;

		public const string Id = "com.github.boxofbiscuits97.PingDistance";

		internal static ManualLogSource Log { get; private set; } = null;


		public static string Name => "PingDistance";

		public static string Version => "1.0.0";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " Version " + Version + " is loaded!"));
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
		}

		[HarmonyPatch(typeof(PointPinger), "Awake")]
		[HarmonyPrefix]
		private static void PointPinger_Awake_Prefix(PointPinger __instance)
		{
			if ((Object)(object)PingDistanceCanvas == (Object)null)
			{
				CreatePingDistanceCanvas();
				DistanceInstances.Clear();
			}
		}

		[HarmonyPatch(typeof(PointPinger), "ReceivePoint_Rpc")]
		[HarmonyPrefix]
		private static void PointPinger_ReceivePoint_Rpc_Prefix(PointPinger __instance, ref Vector3 point, ref Vector3 hitNormal)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)PingDistanceCanvas == (Object)null || (Object)(object)TemplateText == (Object)null)
			{
				Log.LogError((object)"PingDistanceCanvas or templateText is not instantiated");
				return;
			}
			Character character = __instance.character;
			Vector3 position = point + hitNormal;
			if (DistanceInstances.TryGetValue(character, out GameObject value) && (Object)(object)value != (Object)null)
			{
				Object.Destroy((Object)(object)value);
			}
			GameObject val = Object.Instantiate<GameObject>(TemplateText, PingDistanceCanvas.transform);
			val.SetActive(true);
			PingDistance component = val.GetComponent<PingDistance>();
			component.Position = position;
			component.Character = character;
			DistanceInstances[character] = val;
			Object.Destroy((Object)(object)val, 1.25f);
		}

		private static void CreatePingDistanceCanvas()
		{
			GameObject val = GameObject.Find("GAME/GUIManager");
			GameObject val2 = GameObject.Find("GAME/GUIManager/Canvas_Names");
			PingDistanceCanvas = Object.Instantiate<GameObject>(val2, val.transform);
			((Object)PingDistanceCanvas).name = "Canvas_PingDistance";
			UIPlayerNames val3 = default(UIPlayerNames);
			if (PingDistanceCanvas.TryGetComponent<UIPlayerNames>(ref val3))
			{
				Object.Destroy((Object)(object)val3);
			}
			TemplateText = ((Component)PingDistanceCanvas.transform.GetChild(0)).gameObject;
			Object.Destroy((Object)(object)((Component)TemplateText.transform.GetChild(0)).gameObject);
			PlayerName val4 = default(PlayerName);
			if (TemplateText.TryGetComponent<PlayerName>(ref val4))
			{
				Object.Destroy((Object)(object)val4);
			}
			((Object)TemplateText).name = "DistanceText";
			TemplateText.AddComponent<PingDistance>();
			TemplateText.SetActive(false);
			for (int i = 0; i < PingDistanceCanvas.transform.childCount; i++)
			{
				GameObject gameObject = ((Component)PingDistanceCanvas.transform.GetChild(i)).gameObject;
				if (((Object)gameObject).name.Contains("UI_PlayerName"))
				{
					Object.Destroy((Object)(object)gameObject);
				}
			}
			Log.LogInfo((object)"PingDistanceCanvas created");
		}
	}
	public class PingDistance : MonoBehaviour
	{
		public Vector3 Position;

		public Character? Character;

		private TextMeshProUGUI? TMP;

		private void LateUpdate()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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)
			if (!((Object)(object)Camera.main == (Object)null))
			{
				Color color = (((Object)(object)Character != (Object)null) ? Character.refs.customization.PlayerColor : Color.white);
				float num = Mathf.Round(Vector3.Distance(Position, ((Component)Camera.main).transform.position));
				float num2 = Vector3.Angle(((Component)Camera.main).transform.forward, Position - ((Component)Camera.main).transform.position);
				if ((Object)(object)TMP == (Object)null)
				{
					TMP = ((Component)this).GetComponentInChildren<TextMeshProUGUI>();
				}
				((Component)this).transform.position = Camera.main.WorldToScreenPoint(Position);
				((TMP_Text)TMP).fontSize = 30f;
				((Graphic)TMP).color = color;
				((TMP_Text)TMP).text = $"{num}m";
				((Component)TMP).gameObject.SetActive(num2 < 90f);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}