Decompiled source of NavigationTrail v2.0.0

Packer.NavigationTrail.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using FistVR;
using Microsoft.CodeAnalysis;
using Sodalite;
using Sodalite.Api;
using SupplyRaid;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("Packer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A waypoint path guide to get around in Take and Hold and Supply Raid(SR)")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0+ac6d25c37cb43634e367708551f51b9bac7a5df0")]
[assembly: AssemblyProduct("Packer.NavigationTrail")]
[assembly: AssemblyTitle("NavigationTrail")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.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 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 Packer
{
	[BepInPlugin("Packer.NavigationTrail", "NavigationTrail", "2.0.0")]
	[BepInProcess("h3vr.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class NavigationTrailPlugin : BaseUnityPlugin
	{
		public class PathLocations
		{
			public Vector3 position;

			public enumPathType path = enumPathType.MainPoint;
		}

		public enum enumPathType
		{
			MainPoint = 0,
			SupplyPoint = 1,
			Other = -1
		}

		public static bool supplyRaid;

		public GameObject trail;

		public int pathIndex = 0;

		public List<PathLocations> locations = new List<PathLocations>();

		[CompilerGenerated]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private ButtonClickEvent m_TrailButtonEvent;

		private NavMeshPath path;

		private LineRenderer line;

		private WristMenuButton navigateButton;

		private TNH_Manager tnhManager;

		private Text buttonText;

		private string lastText = "";

		private LayerMask mask;

		private Vector3 groundOffset = new Vector3(0f, 0.5f, 0f);

		private Texture2D waypointTexture;

		private Vector2 materialOffset;

		internal static ManualLogSource Logger { get; private set; }

		public event ButtonClickEvent TrailButtonEvent
		{
			[CompilerGenerated]
			add
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				ButtonClickEvent val = this.m_TrailButtonEvent;
				ButtonClickEvent val2;
				do
				{
					val2 = val;
					ButtonClickEvent value2 = (ButtonClickEvent)Delegate.Combine((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_TrailButtonEvent, value2, val2);
				}
				while (val != val2);
			}
			[CompilerGenerated]
			remove
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				ButtonClickEvent val = this.m_TrailButtonEvent;
				ButtonClickEvent val2;
				do
				{
					val2 = val;
					ButtonClickEvent value2 = (ButtonClickEvent)Delegate.Remove((Delegate?)(object)val2, (Delegate?)(object)value);
					val = Interlocked.CompareExchange(ref this.m_TrailButtonEvent, value2, val2);
				}
				while (val != val2);
			}
		}

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			supplyRaid = Chainloader.PluginInfos.ContainsKey("com.Packer.SupplyRaid");
		}

		private void Start()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			path = new NavMeshPath();
			TrailButtonEvent += new ButtonClickEvent(ShowPath);
			lastText = "Navigation Hint";
			navigateButton = new WristMenuButton(lastText, this.TrailButtonEvent);
			WristMenuAPI.Buttons.Add(navigateButton);
			mask = LayerMask.op_Implicit(LayerMask.NameToLayer("Enviroment"));
		}

		private void Update()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)line != (Object)null)
			{
				materialOffset.x -= Time.deltaTime;
				if (materialOffset.x < -1f)
				{
					materialOffset.x += 1f;
				}
				((Renderer)line).material.SetTextureOffset("_MainTex", materialOffset);
			}
		}

		private void ShowPath(object sender, ButtonClickEventArgs args)
		{
			//IL_0054: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Invalid comparison between Unknown and I4
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)tnhManager == (Object)null)
			{
				tnhManager = GM.TNH_Manager;
			}
			if ((Object)(object)line == (Object)null)
			{
				GenerateTrail();
			}
			CollectPaths();
			if (locations.Count == 0)
			{
				SM.PlayGlobalUISound((GlobalUISound)2, ((Component)this).transform.position);
				DisableTrail();
				return;
			}
			pathIndex++;
			if (pathIndex >= locations.Count)
			{
				pathIndex = -1;
				DisableTrail();
				SM.PlayGlobalUISound((GlobalUISound)1, ((Component)this).transform.position);
				return;
			}
			NavMesh.CalculatePath(GM.CurrentPlayerRoot.position, locations[pathIndex].position, -1, path);
			UpdateTexture(locations[pathIndex].path);
			if ((Object)(object)buttonText == (Object)null)
			{
				Text[] componentsInChildren = ((Component)WristMenuAPI.Instance2).GetComponentsInChildren<Text>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if (componentsInChildren[i].text == lastText)
					{
						buttonText = componentsInChildren[i];
					}
				}
			}
			string text = "Navigation Hint";
			switch (locations[pathIndex].path)
			{
			case enumPathType.MainPoint:
				text = ((!((Object)(object)tnhManager != (Object)null)) ? "Capture Point" : "System Node");
				break;
			case enumPathType.SupplyPoint:
				text = $"Supply Point ({pathIndex})";
				break;
			case enumPathType.Other:
				text = "Point";
				break;
			}
			buttonText.text = text;
			if ((int)path.status == 2)
			{
				SM.PlayGlobalUISound((GlobalUISound)2, ((Component)this).transform.position);
				DisableTrail();
			}
			else if (path.corners.Length != 0)
			{
				Vector3[] array = SmoothPath();
				if (array == null)
				{
					SM.PlayGlobalUISound((GlobalUISound)2, ((Component)this).transform.position);
					return;
				}
				line.positionCount = array.Length;
				line.SetPositions(array);
				SM.PlayGlobalUISound((GlobalUISound)0, ((Component)this).transform.position);
			}
			else
			{
				SM.PlayGlobalUISound((GlobalUISound)2, ((Component)this).transform.position);
				DisableTrail();
			}
		}

		private void DisableTrail()
		{
			line.positionCount = 0;
			if ((Object)(object)buttonText != (Object)null)
			{
				buttonText.text = "Navigation Hint";
			}
		}

		private Vector3[] SmoothPath()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: 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_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			list.Add(path.corners[0] + groundOffset);
			RaycastHit val = default(RaycastHit);
			for (int i = 1; i < path.corners.Length; i++)
			{
				if (Physics.Linecast(path.corners[i - 1], path.corners[i], ref val, LayerMask.op_Implicit(mask)))
				{
					if (Manhatten2DDistance(path.corners[i - 1], path.corners[i]) < 3f)
					{
						if (path.corners[i - 1].y > path.corners[i].y)
						{
							list.Add(path.corners[i] + groundOffset);
							continue;
						}
						Vector3 item = path.corners[i - 1];
						item.y = path.corners[i].y + groundOffset.y;
						list.Add(item);
						list.Add(path.corners[i] + groundOffset);
					}
					else
					{
						list.Add(((RaycastHit)(ref val)).point + groundOffset);
						list.Add(path.corners[i] + groundOffset);
					}
				}
				else
				{
					list.Add(path.corners[i] + groundOffset);
				}
			}
			if (list.Count <= 0)
			{
				return null;
			}
			return list.ToArray();
		}

		private float Manhatten2DDistance(Vector3 a, Vector3 b)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			float num = ((!(a.x > b.x)) ? (b.x - a.x) : (a.x - b.x));
			float num2 = ((!(a.z > b.z)) ? (b.z - a.z) : (a.z - b.z));
			return num * num + num2 * num2;
		}

		private void CollectPaths()
		{
			//IL_00a9: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			locations.Clear();
			if (supplyRaid && SupplyRaidSupport.HasManager())
			{
				locations.AddRange(SupplyRaidSupport.PopulateLocations());
			}
			else
			{
				if (!((Object)(object)tnhManager != (Object)null) || (Object)(object)tnhManager.m_curHoldPoint == (Object)null || (Object)(object)tnhManager.m_curHoldPoint.m_systemNode == (Object)null)
				{
					return;
				}
				locations.Add(new PathLocations
				{
					path = enumPathType.MainPoint,
					position = ((Component)tnhManager.m_curHoldPoint.m_systemNode).transform.position
				});
				NavMeshHit val = default(NavMeshHit);
				for (int i = 0; i < tnhManager.m_activeSupplyPointIndicies.Count; i++)
				{
					NavMesh.SamplePosition(((Component)tnhManager.SupplyPoints[tnhManager.m_activeSupplyPointIndicies[i]]).transform.position, ref val, 15f, -1);
					Vector3 position = ((NavMeshHit)(ref val)).position;
					if (position == Vector3.zero)
					{
						position = ((Component)tnhManager.SupplyPoints[i]).transform.position;
					}
					locations.Add(new PathLocations
					{
						path = enumPathType.SupplyPoint,
						position = position
					});
				}
			}
		}

		private void GenerateTrail()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			trail = Object.Instantiate<GameObject>(new GameObject(), ((Component)GM.CurrentPlayerRoot).transform.position, Quaternion.identity, (Transform)null);
			line = trail.AddComponent<LineRenderer>();
			DisableTrail();
			line.widthMultiplier = 1f;
			line.startWidth = 0.2f;
			line.endWidth = 0.05f;
			line.numCornerVertices = 4;
			line.textureMode = (LineTextureMode)1;
			((Renderer)line).material = new Material(Shader.Find("Unlit/Transparent"));
			((Renderer)line).material.SetTexture("_MainTex", (Texture)(object)UpdateTexture(enumPathType.MainPoint));
			((Renderer)line).material.SetTextureScale("_MainTex", new Vector2(0.25f, 1f));
		}

		private void OnDisable()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			TrailButtonEvent -= new ButtonClickEvent(ShowPath);
		}

		private Texture2D UpdateTexture(enumPathType type)
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			Color val = default(Color);
			switch (type)
			{
			case enumPathType.MainPoint:
				((Color)(ref val))..ctor(0.912f, 0.454f, 0.101f, 0.5f);
				break;
			case enumPathType.SupplyPoint:
				((Color)(ref val))..ctor(0.257f, 0.258f, 0.831f, 0.5f);
				break;
			default:
				((Color)(ref val))..ctor(0f, 0.8f, 0f, 0.5f);
				break;
			}
			int num = 16;
			Texture2D val2;
			if ((Object)(object)waypointTexture == (Object)null)
			{
				val2 = new Texture2D(num, num);
				((Texture)val2).filterMode = (FilterMode)0;
				((Texture)val2).anisoLevel = 1;
				((Texture)val2).wrapMode = (TextureWrapMode)0;
				((Texture)val2).mipMapBias = 0f;
				waypointTexture = val2;
			}
			else
			{
				val2 = waypointTexture;
			}
			Color[] array = (Color[])(object)new Color[num * num];
			val.a = 0.1f;
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = val;
			}
			val.a = 1f;
			for (int j = 0; j < num; j++)
			{
				array[j * num] = val;
			}
			val2.SetPixels(array);
			val2.Apply();
			return val2;
		}
	}
	public class SupplyRaidSupport
	{
		public static bool HasManager()
		{
			if (Object.op_Implicit((Object)(object)SR_Manager.instance))
			{
				return true;
			}
			return false;
		}

		public static List<NavigationTrailPlugin.PathLocations> PopulateLocations()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			List<NavigationTrailPlugin.PathLocations> list = new List<NavigationTrailPlugin.PathLocations>();
			NavigationTrailPlugin.PathLocations pathLocations = new NavigationTrailPlugin.PathLocations();
			pathLocations.path = NavigationTrailPlugin.enumPathType.MainPoint;
			pathLocations.position = SR_Manager.AttackSupplyPoint().captureZone.position;
			list.Add(pathLocations);
			NavigationTrailPlugin.PathLocations pathLocations2 = new NavigationTrailPlugin.PathLocations();
			pathLocations2.path = NavigationTrailPlugin.enumPathType.SupplyPoint;
			pathLocations2.position = SR_Manager.LastSupplyPoint().buyMenu.position;
			list.Add(pathLocations2);
			return list;
		}
	}
}