Decompiled source of LaserPointerDetonator v1.0.1

BepInEx\plugins\LaserPointerDetonator.dll

Decompiled 4 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LaserTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LaserTweaks")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4963e0ea-7a99-4390-9cae-a4bdd01b6b43")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[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]
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace LaserPointerDetonator
{
	public class LaserPointerTarget : MonoBehaviour
	{
		public static List<LaserPointerTarget> Instances = new List<LaserPointerTarget>();

		public float radius = 0.53f;

		public Vector3 offset = Vector3.up * 0.1f;

		private const float maxTemp = 1f;

		private float temp;

		private bool triggered;

		private Landmine landmine;

		private Vector3 hitPoint;

		public static int Count => Instances.Count;

		private void Awake()
		{
			landmine = ((Component)this).GetComponent<Landmine>();
			Instances.Add(this);
		}

		private void OnDestroy()
		{
			Instances.Remove(this);
		}

		public void AddTemp(Transform origin)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0036: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			if (!triggered && !landmine.hasExploded && LTDI(origin.position, origin.forward, ((Component)this).transform.position + offset, radius) && !Physics.Linecast(origin.position, hitPoint, 1051400, (QueryTriggerInteraction)1))
			{
				temp += Time.deltaTime;
				if (temp > 1f)
				{
					landmine.TriggerMineOnLocalClientByExiting();
					triggered = true;
				}
			}
		}

		private bool LTDI(Vector3 point, Vector3 direction, Vector3 center, float diskRadius = 1f)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0020: 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_002c: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			float num = Vector3.Dot(center - point, Vector3.up) / Vector3.Dot(direction, Vector3.up);
			hitPoint = point + direction * num;
			if (num > 0f)
			{
				return Vector3.Distance(center, hitPoint) <= diskRadius;
			}
			return false;
		}
	}
	internal class LaserPointerRaycast : MonoBehaviour
	{
		private FlashlightItem item;

		private Light light
		{
			get
			{
				if (!item.usingPlayerHelmetLight || !((Object)(object)((GrabbableObject)item).playerHeldBy != (Object)null))
				{
					return item.flashlightBulb;
				}
				return ((GrabbableObject)item).playerHeldBy.helmetLight;
			}
		}

		private bool state
		{
			get
			{
				if (((GrabbableObject)item).isBeingUsed)
				{
					return ((NetworkBehaviour)item).IsOwner;
				}
				return false;
			}
		}

		private void Awake()
		{
			item = ((Component)this).GetComponent<FlashlightItem>();
		}

		private void Update()
		{
			if (!state || LaserPointerTarget.Count <= 0)
			{
				return;
			}
			foreach (LaserPointerTarget instance in LaserPointerTarget.Instances)
			{
				instance.AddTemp(((Component)light).transform);
			}
		}
	}
	[BepInPlugin("Kittenji.LaserPointerDetonator", "Laser Pointer Detonator", "1.0.1")]
	public class Loader : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Landmine))]
		internal class LandminePatch
		{
			[HarmonyPatch("Start")]
			[HarmonyPostfix]
			private static void StartPatch(ref Landmine __instance)
			{
				((Component)__instance).gameObject.AddComponent<LaserPointerTarget>();
			}
		}

		[HarmonyPatch(typeof(StartOfRound))]
		internal class StartOfRoundPatch
		{
			[HarmonyPatch("Awake")]
			[HarmonyPostfix]
			private static void AwakePatch(ref StartOfRound __instance)
			{
				AllItemsList allItemsList = __instance.allItemsList;
				if ((Object)(object)allItemsList == (Object)null)
				{
					return;
				}
				List<Item> itemsList = allItemsList.itemsList;
				if (itemsList != null)
				{
					Item val = itemsList.Find((Item itm) => Object.op_Implicit((Object)(object)itm.spawnPrefab) && ((Object)itm.spawnPrefab).name == "LaserPointer");
					if ((Object)(object)val == (Object)null || (Object)(object)val.spawnPrefab == (Object)null)
					{
						Debug.LogError((object)"----------------- Failed to patch laser pointer item");
						return;
					}
					Debug.Log((object)"--------------------- Patching GameObject prefab");
					val.spawnPrefab.AddComponent<LaserPointerRaycast>();
				}
			}
		}

		private const string modGUID = "Kittenji.LaserPointerDetonator";

		private readonly Harmony harmony = new Harmony("Kittenji.LaserPointerDetonator");

		private void Awake()
		{
			harmony.PatchAll();
		}
	}
}