Decompiled source of Motion Tracker Extended v0.1.2

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 BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
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);
		}
	}
}
public struct ScannedEntity
{
	public Collider collider;

	public Vector3 position;

	public float speed;
}
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()
		{
			AssetBundle val = AssetBundle.LoadFromMemory(MotionTrackerResource.motiontrackerled);
			((BaseUnityPlugin)this).Logger.LogInfo((object)val);
			string[] allAssetNames = val.GetAllAssetNames();
			foreach (string text in allAssetNames)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Asset name: " + text));
			}
			motionTrackerLED_Item = val.LoadAsset<Item>("assets/MotionTrackerItem.asset");
			motionTrackerLED_Item.spawnPrefab.AddComponent<NetworkObject>();
			((Object)motionTrackerLED_Item.spawnPrefab.GetComponent<NetworkObject>()).name = "MotionNetObj";
			spawnedMotionTracker = motionTrackerLED_Item.spawnPrefab.AddComponent<MotionTrackerScript>();
			((GrabbableObject)spawnedMotionTracker).itemProperties = motionTrackerLED_Item;
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Registering: {motionTrackerLED_Item}");
			Items.RegisterShopItem(motionTrackerLED_Item, 30);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Done registering: {motionTrackerLED_Item}");
			foreach (ShopItem shopItem in Items.shopItems)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Item: " + shopItem.modName));
			}
			NetworkPrefabs.RegisterNetworkPrefab(motionTrackerLED_Item.spawnPrefab);
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			Utils.Main.IsIngame();
		}
	}
}
namespace MotionTracker.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class MotionTracker
	{
		private static ManualLogSource logger = null;

		private static List<ScannedEntity> scannedEntities = new List<ScannedEntity>();

		private static Item motionTrackerLED;

		private static MotionTrackerScript spawnedMotionTracker;

		private static LineDrawer _lineDrawer;

		private static void InitLogger()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			if (logger == null)
			{
				_lineDrawer = default(LineDrawer);
				logger = new ManualLogSource("LC_MotionTracker_Log");
				Logger.Sources.Add((ILogSource)(object)logger);
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Jump_performed")]
		[HarmonyPostfix]
		public static void PostJump(PlayerControllerB __instance)
		{
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPostfix]
		public static void Update(PlayerControllerB __instance)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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)
			if (((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled && (Object)(object)spawnedMotionTracker != (Object)null)
			{
				InitLogger();
				_lineDrawer.DrawLineInGameView(((Component)__instance).transform.position, ((Component)spawnedMotionTracker).transform.position, new Color(0f, 1f, 1f));
			}
		}
	}
	public struct ScannedEntity
	{
		public Collider obj;

		public Vector3 position;

		public Vector3 rawPosition;

		public float speed;

		public GameObject blip;
	}
	public class MotionTrackerScript : PhysicsProp
	{
		private ParticleSystem particleSystem;

		private AudioSource audioSource;

		public AudioClip shootSound;

		public AudioClip noammoSound;

		private RoundManager roundManager;

		private GameObject baseRadar;

		private RectTransform baseRadarRect;

		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 Start()
		{
			((GrabbableObject)this).Start();
			Debug.Log((object)string.Format("Found GameObject: {0}", GameObject.Find("/Environment/Props").transform));
		}

		public void Awake()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			particleSystem = ((Component)this).GetComponentInChildren<ParticleSystem>();
			audioSource = ((Component)((Component)this).transform).gameObject.AddComponent<AudioSource>();
			roundManager = Object.FindObjectOfType<RoundManager>();
			((GrabbableObject)this).grabbable = true;
			((GrabbableObject)this).grabbableToEnemies = true;
			((GrabbableObject)this).mainObjectRenderer = ((Component)this).GetComponent<MeshRenderer>();
			((GrabbableObject)this).useCooldown = 1f;
			((GrabbableObject)this).insertedBattery = new Battery(false, 1f);
			baseRadar = ((Component)((Component)this).transform.Find("Canvas/BaseRadar")).gameObject;
			baseRadarRect = baseRadar.GetComponent<RectTransform>();
			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);
			if (((NetworkBehaviour)this).IsHost)
			{
				for (int i = 0; i < maxEntities; i++)
				{
					GameObject val = Object.Instantiate<GameObject>(blip, baseRadar.transform);
					val.transform.parent = blipParent.transform;
					val.SetActive(false);
					blipPool.Add(val);
				}
			}
			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 (((GrabbableObject)this).isPocketed)
			{
				Enable(enable: false, inHand: false);
			}
			else
			{
				if (!((GrabbableObject)this).isBeingUsed)
				{
					return;
				}
				if (((GrabbableObject)this).isHeld)
				{
					Enable(enable: true);
					blipParent.transform.localRotation = Quaternion.Euler(0f, 0f, ((Component)((GrabbableObject)this).playerHeldBy).transform.eulerAngles.y + 0f);
				}
				else
				{
					Enable(enable: false, inHand: false);
				}
				if (((GrabbableObject)this).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);
						if ((double)scannedEntity2.speed > 0.06)
						{
							scannedEntity2.blip.SetActive(true);
						}
						else
						{
							scannedEntity2.blip.SetActive(false);
						}
						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;
		}
	}
}