Decompiled source of Motion Tracker v1.0.0

MotionTracker.dll

Decompiled a year ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using LC_API.ServerAPI;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using MotionTracker.Patches;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;

[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("MotionTracker")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MotionTracker")]
[assembly: AssemblyTitle("MotionTracker")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public struct LineDrawer
{
	private LineRenderer lineRenderer;

	private float lineSize;

	public LineDrawer(float lineSize = 0.2f)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		GameObject val = new GameObject("LineObj");
		lineRenderer = val.AddComponent<LineRenderer>();
		((Renderer)lineRenderer).material = new Material(Shader.Find("Hidden/Internal-Colored"));
		this.lineSize = lineSize;
	}

	private void init(float lineSize = 0.2f)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		if ((Object)(object)lineRenderer == (Object)null)
		{
			GameObject val = new GameObject("LineObj");
			lineRenderer = val.AddComponent<LineRenderer>();
			((Renderer)lineRenderer).material = new Material(Shader.Find("Hidden/Internal-Colored"));
			this.lineSize = lineSize;
		}
	}

	public void DrawLineInGameView(Vector3 start, Vector3 end, Color color)
	{
		//IL_001f: 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_0066: 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)
		if ((Object)(object)lineRenderer == (Object)null)
		{
			init();
		}
		lineRenderer.startColor = color;
		lineRenderer.endColor = color;
		lineRenderer.startWidth = lineSize;
		lineRenderer.endWidth = lineSize;
		lineRenderer.positionCount = 2;
		lineRenderer.SetPosition(0, start);
		lineRenderer.SetPosition(1, end);
	}

	public void Destroy()
	{
		if ((Object)(object)lineRenderer != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)lineRenderer).gameObject);
		}
	}
}
namespace LC_MotionTracker
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "MotionTracker";

		public const string PLUGIN_NAME = "MotionTracker";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace MotionTracker
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class MotionTrackerResource
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("LC_MotionTracker.MotionTrackerResource", typeof(MotionTrackerResource).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] motiontrackerled => (byte[])ResourceManager.GetObject("motiontrackerled", resourceCulture);

		internal MotionTrackerResource()
		{
		}
	}
	internal class Utils
	{
		public class Main
		{
			public static bool IsIngame()
			{
				if ((Object)(object)GameObject.Find("Environment") != (Object)null)
				{
					return true;
				}
				return false;
			}
		}
	}
	[BepInPlugin("com.cyanblob.motiontracker", "motiontracker", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private GameObject MotionTrackerLED;

		private static Item motionTrackerLED_Item;

		private static MotionTrackerScript spawnedMotionTracker;

		private void Awake()
		{
			motionTrackerLED_Item = AssetBundle.LoadFromMemory(MotionTrackerResource.motiontrackerled).LoadAsset<Item>("assets/MotionTrackerItem.asset");
			motionTrackerLED_Item.spawnPrefab.GetComponent<NetworkObject>().AutoObjectParentSync = false;
			spawnedMotionTracker = motionTrackerLED_Item.spawnPrefab.AddComponent<MotionTrackerScript>();
			((GrabbableObject)spawnedMotionTracker).itemProperties = motionTrackerLED_Item;
			((GrabbableObject)spawnedMotionTracker).isInFactory = true;
			Items.RegisterShopItem(motionTrackerLED_Item, 30);
			NetworkPrefabs.RegisterNetworkPrefab(motionTrackerLED_Item.spawnPrefab);
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (Utils.Main.IsIngame())
			{
				ModdedServer.SetServerModdedOnly();
			}
		}
	}
}
namespace MotionTracker.Patches
{
	public struct ScannedEntity
	{
		public Collider obj;

		public Vector3 position;

		public Vector3 rawPosition;

		public float speed;

		public GameObject blip;
	}
	public class MotionTrackerScript : GrabbableObject
	{
		private GameObject baseRadar;

		private GameObject baseRadarOff;

		private GameObject LED;

		private GameObject blip;

		private GameObject blipParent;

		private float searchRadius = 50f;

		private Hashtable scannedEntities = new Hashtable();

		private List<GameObject> blipPool = new List<GameObject>();

		private int maxEntities = 50;

		private Collider[] colliders = (Collider[])(object)new Collider[200];

		public void Awake()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			base.grabbable = true;
			base.grabbableToEnemies = true;
			base.mainObjectRenderer = ((Component)this).GetComponent<MeshRenderer>();
			base.useCooldown = 1f;
			base.insertedBattery = new Battery(false, 1f);
			baseRadar = ((Component)((Component)this).transform.Find("Canvas/BaseRadar")).gameObject;
			baseRadarOff = ((Component)((Component)this).transform.Find("Canvas/BaseRadar_off")).gameObject;
			LED = ((Component)((Component)this).transform.Find("LED")).gameObject;
			blipParent = ((Component)((Component)this).transform.Find("Canvas/BlipParent")).gameObject;
			blip = ((Component)((Component)this).transform.Find("Canvas/BlipParent/Blip")).gameObject;
			blip.SetActive(false);
			blipPool.Add(blip);
			for (int i = 1; i < maxEntities; i++)
			{
				blipPool.Add(((Component)((Component)this).transform.Find($"Canvas/BlipParent/Blip ({i})")).gameObject);
				blipPool[i].SetActive(false);
			}
			Enable(enable: false);
		}

		private void Enable(bool enable, bool inHand = true)
		{
			baseRadar.SetActive(enable);
			LED.SetActive(enable);
			if (inHand)
			{
				baseRadarOff.SetActive(!enable);
			}
			else
			{
				baseRadarOff.SetActive(false);
			}
			if (enable)
			{
				return;
			}
			foreach (GameObject item in blipPool)
			{
				item.SetActive(false);
			}
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			Enable(used);
			Debug.Log((object)$"Motion tracker activate? : {used}");
		}

		public override void UseUpBatteries()
		{
			((GrabbableObject)this).UseUpBatteries();
			Enable(enable: false, inHand: false);
		}

		public override void Update()
		{
			//IL_0052: 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)
			//IL_00cc: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: 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_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: 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_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).Update();
			if (base.isPocketed)
			{
				Enable(enable: false, inHand: false);
			}
			else
			{
				if (!base.isBeingUsed)
				{
					return;
				}
				if (base.isHeld)
				{
					Enable(enable: true);
					blipParent.transform.localRotation = Quaternion.Euler(0f, 0f, ((Component)base.playerHeldBy).transform.eulerAngles.y + 0f);
				}
				else
				{
					Enable(enable: false, inHand: false);
				}
				if (base.insertedBattery.empty)
				{
					Enable(enable: false);
					return;
				}
				for (int i = 0; i < maxEntities; i++)
				{
					blipPool[i].SetActive(false);
				}
				Hashtable hashtable = new Hashtable(scannedEntities);
				scannedEntities.Clear();
				int num = Physics.OverlapSphereNonAlloc(((Component)this).transform.position, searchRadius, colliders, 524296);
				int num2 = 0;
				for (int j = 0; j < num; j++)
				{
					Collider val = colliders[j];
					ScannedEntity scannedEntity = default(ScannedEntity);
					scannedEntity.obj = val;
					scannedEntity.position = ((Component)val).transform.position - baseRadar.transform.position;
					scannedEntity.rawPosition = ((Component)val).transform.position;
					ScannedEntity scannedEntity2 = scannedEntity;
					if (hashtable.Contains(((object)((Component)scannedEntity2.obj).transform).GetHashCode()))
					{
						Vector3 val2 = ((Component)val).transform.position - ((ScannedEntity)hashtable[((object)((Component)scannedEntity2.obj).transform).GetHashCode()]).rawPosition;
						scannedEntity2.speed = ((Vector3)(ref val2)).magnitude;
					}
					else
					{
						scannedEntity2.speed = 0f;
					}
					if (!scannedEntities.Contains(((object)((Component)scannedEntity2.obj).transform).GetHashCode()))
					{
						scannedEntity2.blip = blipPool[num2];
						num2++;
						Vector3 localPosition = scannedEntity2.blip.transform.localPosition;
						localPosition = scannedEntity2.position;
						scannedEntity2.blip.transform.localPosition = new Vector3(Remap(localPosition.x, 0f - searchRadius, searchRadius, -45f, 45f), Remap(localPosition.z, 0f - searchRadius, searchRadius, -45f, 45f), -0.1f);
						scannedEntity2.blip.SetActive((double)scannedEntity2.speed > 0.05);
						scannedEntities.Add(((object)((Component)scannedEntity2.obj).transform).GetHashCode(), scannedEntity2);
					}
				}
			}
		}

		public float Remap(float from, float fromMin, float fromMax, float toMin, float toMax)
		{
			float num = from - fromMin;
			float num2 = fromMax - fromMin;
			float num3 = num / num2;
			return (toMax - toMin) * num3 + toMin;
		}
	}
}