Decompiled source of Lethal Crumbs v1.1.0

LethalCrumbs.dll

Decompiled 8 months 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.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LethalCrumbs")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Find your way back to the entrace")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("LethalCrumbs")]
[assembly: AssemblyTitle("LethalCrumbs")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 LethalCrumbs
{
	[BepInPlugin("LethalCrumbs", "LethalCrumbs", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony harmony = new Harmony("LethalCrumbs");

		public static ConfigEntry<float> CrumbInterval;

		public static ConfigEntry<float> CrumbSize;

		public static ConfigEntry<KeyboardShortcut> ToggleRender;

		private void Awake()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			CrumbInterval = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CrumbInterval", 5f, "How far apart the crumbs are");
			CrumbSize = ((BaseUnityPlugin)this).Config.Bind<float>("General", "CrumbSize", 0.5f, "How big the crumbs (arrows) are");
			ToggleRender = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("KeyBinds", "ToggleKey", new KeyboardShortcut((KeyCode)112, Array.Empty<KeyCode>()), "The key to use for toggling crumb rendering");
			harmony.PatchAll(typeof(Plugin));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin LethalCrumbs is loaded!");
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPostfix]
		public static void PlayerUpdate(PlayerControllerB __instance)
		{
			if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject) && (Object)(object)((Component)__instance).GetComponent<PlayerCrumbs>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<PlayerCrumbs>();
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "ResetPlayersLoadedValueClientRpc")]
		[HarmonyPostfix]
		public static void LoadNewMap()
		{
			PlayerCrumbs[] array = Object.FindObjectsOfType<PlayerCrumbs>();
			for (int i = 0; i < array.Length; i++)
			{
				array[i].crumbs.Clear();
			}
		}
	}
	internal class PlayerCrumbs : MonoBehaviour
	{
		public List<Vector3> crumbs = new List<Vector3>();

		private Mesh markerMesh;

		private Material markerMaterial;

		private List<Matrix4x4> markerMatricies = new List<Matrix4x4>();

		private bool shouldRender = true;

		private int floorMask = LayerMask.GetMask(new string[1] { "Room" });

		private void Start()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			markerMesh = GenerateArrow(1f, 0.35f, 0.8f, 0.8f);
			markerMaterial = new Material(Shader.Find("HDRP/Lit"));
			markerMaterial.enableInstancing = true;
			Color green = Color.green;
			markerMaterial.SetColor("_BaseColor", green);
			markerMaterial.EnableKeyword("_EMISSION");
			markerMaterial.SetColor("_EmissiveColor", green);
			markerMaterial.SetFloat("_EmissiveIntensity", 4f);
		}

		private void Update()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_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_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: 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_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = Plugin.ToggleRender.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				shouldRender = !shouldRender;
			}
			float value2 = Plugin.CrumbInterval.Value;
			float value3 = Plugin.CrumbSize.Value;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(value3, value3, value3);
			Vector3 position = ((Component)this).transform.position;
			(float, int) tuple = (float.MaxValue, crumbs.Count - 1);
			Vector3 val3;
			for (int i = 0; i < crumbs.Count; i++)
			{
				Vector3 val2 = crumbs[i];
				val3 = val2 - position;
				float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
				if (tuple.Item1 > sqrMagnitude)
				{
					tuple = (sqrMagnitude, i);
				}
				if (!shouldRender)
				{
					continue;
				}
				if (i > 0)
				{
					val3 = val2 - crumbs[i - 1];
					if ((double)((Vector3)(ref val3)).sqrMagnitude - 1.0 > (double)(value2 * value2))
					{
						continue;
					}
				}
				Quaternion val4 = Quaternion.identity;
				if (i > 0)
				{
					val4 = Quaternion.LookRotation(crumbs[i - 1] - val2, Vector3.upVector);
				}
				markerMatricies.Add(Matrix4x4.TRS(val2, val4, val));
				markerMatricies.Add(Matrix4x4.TRS(val2, val4 * Quaternion.Euler(Vector3.forwardVector * 180f), val));
			}
			if (shouldRender)
			{
				Graphics.DrawMeshInstanced(markerMesh, 0, markerMaterial, markerMatricies);
				markerMatricies.Clear();
			}
			bool num = (double)tuple.Item1 <= (double)value2 * 3.0;
			int item = tuple.Item2;
			if (num && item >= 0 && item != crumbs.Count - 1)
			{
				int count = crumbs.Count - item - 1;
				crumbs.RemoveRange(item + 1, count);
			}
			if (crumbs.Count > 0)
			{
				val3 = position - crumbs[crumbs.Count - 1];
				if (((Vector3)(ref val3)).magnitude <= value2)
				{
					return;
				}
			}
			RaycastHit val5 = default(RaycastHit);
			if (!Physics.Raycast(((Component)this).transform.position + Vector3.upVector * 0.1f, Vector3.downVector, ref val5, 10f, floorMask, (QueryTriggerInteraction)1) || !((Object)((RaycastHit)(ref val5)).transform).name.Contains("Ship", StringComparison.InvariantCultureIgnoreCase))
			{
				crumbs.Add(position);
			}
		}

		private static Mesh GenerateArrow(float stemLength, float stemWidth, float tipLength, float tipWidth)
		{
			//IL_000c: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0034: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_00ea: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Expected O, but got Unknown
			List<Vector3> list = new List<Vector3>();
			List<int> list2 = new List<int>();
			Vector3 zero = Vector3.zero;
			float num = stemWidth / 2f;
			list.Add(zero + num * Vector3.right);
			list.Add(zero + num * Vector3.left);
			list.Add(list[0] + stemLength * Vector3.forward);
			list.Add(list[1] + stemLength * Vector3.forward);
			list2.Add(0);
			list2.Add(1);
			list2.Add(3);
			list2.Add(0);
			list2.Add(3);
			list2.Add(2);
			Vector3 val = stemLength * Vector3.forward;
			float num2 = tipWidth / 2f;
			list.Add(val + num2 * Vector3.left);
			list.Add(val + num2 * Vector3.right);
			list.Add(val + tipLength * Vector3.forward);
			list2.Add(4);
			list2.Add(6);
			list2.Add(5);
			return new Mesh
			{
				vertices = list.ToArray(),
				triangles = list2.ToArray()
			};
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LethalCrumbs";

		public const string PLUGIN_NAME = "LethalCrumbs";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}