Decompiled source of WiresPings v0.1.2

WiresPings.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("WiresPings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WiresPings")]
[assembly: AssemblyTitle("WiresPings")]
[assembly: AssemblyVersion("1.0.0.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 WiresPings
{
	[BepInPlugin("wire.valheim.pings", "Wire's Pings", "0.1.2")]
	[BepInProcess("valheim.exe")]
	public sealed class Plugin : BaseUnityPlugin
	{
		private sealed class RaycastHitComparer : IComparer<RaycastHit>
		{
			public int Compare(RaycastHit a, RaycastHit b)
			{
				return ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance);
			}
		}

		public const string Guid = "wire.valheim.pings";

		public const string Name = "Wire's Pings";

		public const string Version = "0.1.2";

		private static readonly RaycastHit[] Hits = (RaycastHit[])(object)new RaycastHit[64];

		private static readonly RaycastHitComparer HitComparer = new RaycastHitComparer();

		private ConfigEntry<bool> _enabled;

		private ConfigEntry<KeyboardShortcut> _pingKey;

		private ConfigEntry<float> _maxDistance;

		private int _pingMask;

		private void Awake()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable aiming pings.");
			_pingKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "Ping Hotkey", new KeyboardShortcut((KeyCode)98, Array.Empty<KeyCode>()), "Ping the exact world position under the centre crosshair.");
			_maxDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Maximum Ping Distance", 1000f, new ConfigDescription("Maximum distance in metres for aimed pings.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 1000f), Array.Empty<object>()));
			_pingMask = LayerMask.GetMask(new string[11]
			{
				"Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "vehicle", "character", "character_net", "character_ghost",
				"hitbox"
			});
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Wire's Pings 0.1.2 loaded.");
		}

		private void Update()
		{
			//IL_0013: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Invalid comparison between Unknown and I4
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			if (!_enabled.Value)
			{
				return;
			}
			KeyboardShortcut value = _pingKey.Value;
			if (!((KeyboardShortcut)(ref value)).IsDown())
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)GameCamera.instance == (Object)null || (Object)(object)Chat.instance == (Object)null || Console.IsVisible() || TextInput.IsVisible() || Chat.instance.HasFocus() || InventoryGui.IsVisible() || ((Object)(object)Minimap.instance != (Object)null && (int)Minimap.instance.m_mode == 2))
			{
				return;
			}
			Camera mainCamera = Utils.GetMainCamera();
			if ((Object)(object)mainCamera == (Object)null)
			{
				return;
			}
			int num = Physics.RaycastNonAlloc(((Component)mainCamera).transform.position, ((Component)mainCamera).transform.forward, Hits, _maxDistance.Value, _pingMask, (QueryTriggerInteraction)1);
			if (num <= 0)
			{
				return;
			}
			Array.Sort(Hits, 0, num, HitComparer);
			for (int i = 0; i < num; i++)
			{
				Collider collider = ((RaycastHit)(ref Hits[i])).collider;
				if (!((Object)(object)collider == (Object)null) && !((Object)(object)((Component)collider).GetComponentInParent<Player>() == (Object)(object)localPlayer))
				{
					Vector3 point = ((RaycastHit)(ref Hits[i])).point;
					point.y = ((Component)localPlayer).transform.position.y;
					MoveExistingLocalPing(point);
					Chat.instance.SendPing(((RaycastHit)(ref Hits[i])).point);
					break;
				}
			}
		}

		private static void MoveExistingLocalPing(Vector3 position)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNet.instance == (Object)null || (Object)(object)Chat.instance == (Object)null)
			{
				return;
			}
			ZDOID localPlayerCharacterID = ZNet.instance.LocalPlayerCharacterID;
			long userID = ((ZDOID)(ref localPlayerCharacterID)).UserID;
			List<WorldTextInstance> worldTexts = Chat.instance.WorldTexts;
			for (int i = 0; i < worldTexts.Count; i++)
			{
				WorldTextInstance val = worldTexts[i];
				if (val != null && val.m_talkerID == userID)
				{
					val.m_go = null;
					val.m_position = position;
					val.m_timer = 0f;
					break;
				}
			}
		}
	}
}