Decompiled source of Drone v1.0.2

plugins/com.github.SebastianYang4249.PEAKdrone.dll

Decompiled 16 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.SebastianYang4249.PEAKdrone")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+fe3ae1acd867abb01dabddd22427d2a4638c6b53")]
[assembly: AssemblyProduct("com.github.SebastianYang4249.PEAKdrone")]
[assembly: AssemblyTitle("drone")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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;
		}
	}
}
[RequireComponent(typeof(LineRenderer))]
public class AnimatedLine : MonoBehaviour
{
	public float animationSpeed = -1.5f;

	public Color lineColor = Color.cyan;

	[Range(0.05f, 0.5f)]
	public float lineWidth = 0.2f;

	private LineRenderer lineRenderer;

	private Material lineMaterial;

	private void Awake()
	{
		lineRenderer = ((Component)this).GetComponent<LineRenderer>();
		SetupAnimatedMaterial();
	}

	private void SetupAnimatedMaterial()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		lineMaterial = new Material(Shader.Find("Legacy Shaders/Particles/Alpha Blended Premultiply"));
		Texture2D mainTexture = CreateDashTexture();
		lineMaterial.mainTexture = (Texture)(object)mainTexture;
		lineMaterial.SetColor("_TintColor", lineColor);
		((Renderer)lineRenderer).material = lineMaterial;
		lineRenderer.startWidth = lineWidth;
		lineRenderer.endWidth = lineWidth;
	}

	private Texture2D CreateDashTexture()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Expected O, but got Unknown
		//IL_002f: 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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		int num = 32;
		Texture2D val = new Texture2D(num, 1, (TextureFormat)4, false);
		((Texture)val).wrapMode = (TextureWrapMode)0;
		Color val2 = default(Color);
		((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
		Color cyan = Color.cyan;
		for (int i = 0; i < num; i++)
		{
			val.SetPixel(i, 0, val2);
		}
		for (int j = num / 4; j < num * 3 / 4; j++)
		{
			val.SetPixel(j, 0, cyan);
		}
		val.Apply();
		return val;
	}

	private void Update()
	{
		//IL_0030: 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_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)lineMaterial != (Object)null)
		{
			float num = Time.time * animationSpeed % 1f;
			lineMaterial.mainTextureOffset = new Vector2(num, 0f);
			if (lineRenderer.positionCount > 1)
			{
				float num2 = Vector3.Distance(lineRenderer.GetPosition(0), lineRenderer.GetPosition(lineRenderer.positionCount - 1));
				lineMaterial.mainTextureScale = new Vector2(num2 / (lineWidth * 10f), 1f);
			}
		}
	}
}
public class DroneItemMarkerManager : MonoBehaviour
{
	private class MarkerInfo
	{
		public TextMeshProUGUI Label;

		public Transform TargetTransform;

		public Item TargetItem;

		public string CachedItemName;

		public float LastKnownDistance;
	}

	[Header("性能与显示设置")]
	[Tooltip("只显示此距离(米)以内的物品标点")]
	public float maxDisplayDistance = 100f;

	[Tooltip("每隔多少秒重新扫描一次场景中的物品")]
	public float scanInterval = 2f;

	[Tooltip("距离变化超过多少米才更新一次UI文本,减少GC")]
	private const float DistanceUpdateThreshold = 1f;

	private Canvas markerCanvas;

	private Camera droneCamera;

	private Transform droneTransform;

	private readonly Dictionary<Transform, MarkerInfo> _activeMarkers = new Dictionary<Transform, MarkerInfo>();

	private bool isRunning;

	private float nextScanTime;

	private float maxDisplayDistanceSqr;

	private static readonly Type[] ScanTypes = new Type[1] { typeof(Item) };

	public static DroneItemMarkerManager Instance { get; private set; }

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			CreateCanvas();
		}
		else
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}

	public void StartManager(Camera cam, Transform drone)
	{
		droneCamera = cam;
		droneTransform = drone;
		isRunning = true;
		((Component)markerCanvas).gameObject.SetActive(true);
		nextScanTime = Time.time;
		maxDisplayDistanceSqr = maxDisplayDistance * maxDisplayDistance;
	}

	public void StopManager()
	{
		isRunning = false;
		if ((Object)(object)markerCanvas != (Object)null)
		{
			((Component)markerCanvas).gameObject.SetActive(false);
		}
		ClearAllMarkers();
	}

	private void Update()
	{
		if (isRunning && !((Object)(object)droneCamera == (Object)null) && !((Object)(object)droneTransform == (Object)null))
		{
			if (Time.time >= nextScanTime)
			{
				ScanForTargets();
				nextScanTime = Time.time + scanInterval;
			}
			UpdateMarkerPositions();
		}
	}

	private void ScanForTargets()
	{
		HashSet<Transform> hashSet = new HashSet<Transform>();
		Type[] scanTypes = ScanTypes;
		foreach (Type type in scanTypes)
		{
			Object[] array = Object.FindObjectsOfType(type);
			foreach (Object val in array)
			{
				MonoBehaviour val2 = (MonoBehaviour)(object)((val is MonoBehaviour) ? val : null);
				if (IsTargetValid(val2))
				{
					hashSet.Add(((Component)val2).transform);
				}
			}
		}
		List<Transform> list = _activeMarkers.Keys.Except(hashSet).ToList();
		foreach (Transform item in list)
		{
			RemoveMarkerFor(item);
		}
		foreach (Transform item2 in hashSet)
		{
			if (!_activeMarkers.ContainsKey(item2))
			{
				CreateMarkerFor(item2);
			}
		}
	}

	private bool IsTargetValid(MonoBehaviour target)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		if ((Object)(object)target == (Object)null || !((Component)target).gameObject.activeInHierarchy)
		{
			return false;
		}
		Item component = ((Component)target).GetComponent<Item>();
		if ((Object)(object)component != (Object)null)
		{
			return (int)component.itemState == 0;
		}
		return false;
	}

	private void CreateMarkerFor(Transform target)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		Item component = ((Component)target).GetComponent<Item>();
		if (!((Object)(object)component == (Object)null))
		{
			GameObject val = new GameObject("Marker_" + ((Object)target).name);
			val.transform.SetParent(((Component)markerCanvas).transform, false);
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)Plugin.GameFont != (Object)null)
			{
				((TMP_Text)val2).font = Plugin.GameFont;
			}
			else
			{
				Plugin.Log.LogWarning((object)"GameFont is null. UI text may not display correctly.");
			}
			((TMP_Text)val2).fontSize = 14f;
			((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
			((Graphic)val2).color = Color.cyan;
			((TMP_Text)val2).fontStyle = (FontStyles)1;
			((TMP_Text)val2).outlineWidth = 0.1f;
			((TMP_Text)val2).outlineColor = Color32.op_Implicit(Color.black);
			MarkerInfo value = new MarkerInfo
			{
				Label = val2,
				TargetTransform = target,
				TargetItem = component,
				CachedItemName = component.GetItemName((ItemInstanceData)null),
				LastKnownDistance = -1f
			};
			_activeMarkers[target] = value;
		}
	}

	private void RemoveMarkerFor(Transform target)
	{
		if (_activeMarkers.TryGetValue(target, out MarkerInfo value))
		{
			if ((Object)(object)value.Label != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)value.Label).gameObject);
			}
			_activeMarkers.Remove(target);
		}
	}

	private void UpdateMarkerPositions()
	{
		//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)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: 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_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: 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_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		List<Transform> list = new List<Transform>();
		foreach (KeyValuePair<Transform, MarkerInfo> activeMarker in _activeMarkers)
		{
			MarkerInfo value = activeMarker.Value;
			Transform targetTransform = value.TargetTransform;
			if ((Object)(object)targetTransform == (Object)null)
			{
				list.Add(activeMarker.Key);
				Object.Destroy((Object)(object)((Component)value.Label).gameObject);
				continue;
			}
			Vector3 position = targetTransform.position;
			Vector3 position2 = droneTransform.position;
			Vector3 val = position - position2;
			float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
			if (sqrMagnitude > maxDisplayDistanceSqr)
			{
				((Behaviour)value.Label).enabled = false;
				continue;
			}
			Vector3 val2 = droneCamera.WorldToScreenPoint(position);
			if (val2.z < 0f)
			{
				((Behaviour)value.Label).enabled = false;
				continue;
			}
			((Behaviour)value.Label).enabled = true;
			((Transform)((TMP_Text)value.Label).rectTransform).position = val2;
			float num = Mathf.Sqrt(sqrMagnitude);
			if (Mathf.Abs(num - value.LastKnownDistance) > 1f)
			{
				((TMP_Text)value.Label).text = $"{value.CachedItemName}\n[{num:F1}m]";
				value.LastKnownDistance = num;
			}
		}
		foreach (Transform item in list)
		{
			_activeMarkers.Remove(item);
		}
	}

	private void ClearAllMarkers()
	{
		foreach (MarkerInfo value in _activeMarkers.Values)
		{
			if ((Object)(object)value.Label != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)value.Label).gameObject);
			}
		}
		_activeMarkers.Clear();
	}

	private void CreateCanvas()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		GameObject val = new GameObject("DroneMarkerCanvas");
		markerCanvas = val.AddComponent<Canvas>();
		markerCanvas.renderMode = (RenderMode)0;
		markerCanvas.sortingOrder = 999;
		Object.DontDestroyOnLoad((Object)(object)val);
		val.SetActive(false);
	}
}
public class DroneSyncManager : MonoBehaviourPun
{
	private List<GameObject> markerSpheres = new List<GameObject>();

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

	public static DroneSyncManager Instance { get; private set; }

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		else
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}

	public void RequestPlaceMarker(Vector3 position)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		((MonoBehaviourPun)this).photonView.RPC("RPC_PlaceMarker", (RpcTarget)0, new object[1] { position });
	}

	public void RequestCancelLastMarker()
	{
		((MonoBehaviourPun)this).photonView.RPC("RPC_CancelLastMarker", (RpcTarget)0, Array.Empty<object>());
	}

	public void RequestClearAllMarkers()
	{
		((MonoBehaviourPun)this).photonView.RPC("RPC_ClearAllMarkers", (RpcTarget)0, Array.Empty<object>());
	}

	[PunRPC]
	private void RPC_PlaceMarker(Vector3 position)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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_002d: 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_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
		val.transform.position = position + Vector3.up * 0.2f;
		val.transform.localScale = Vector3.one * 0.7f;
		Collider component = val.GetComponent<Collider>();
		if ((Object)(object)component != (Object)null)
		{
			Object.Destroy((Object)(object)component);
		}
		Renderer component2 = val.GetComponent<Renderer>();
		if ((Object)(object)component2 != (Object)null)
		{
			component2.material.color = Color.yellow;
		}
		markerSpheres.Add(val);
		Plugin.Log.LogInfo((object)$"[Drone Sync] Received RPC to place marker #{markerSpheres.Count} at {position}.");
		if (markerSpheres.Count > 1)
		{
			GameObject val2 = markerSpheres[markerSpheres.Count - 2];
			GameObject item = CreateGroundClampedLine(val2.transform.position, val.transform.position);
			markerLines.Add(item);
		}
	}

	[PunRPC]
	private void RPC_CancelLastMarker()
	{
		if (markerSpheres.Count > 0)
		{
			GameObject val = markerSpheres[markerSpheres.Count - 1];
			markerSpheres.RemoveAt(markerSpheres.Count - 1);
			Object.Destroy((Object)(object)val);
			Plugin.Log.LogInfo((object)"[Drone Sync] Received RPC to remove the last marker.");
		}
		if (markerLines.Count > 0)
		{
			GameObject val2 = markerLines[markerLines.Count - 1];
			markerLines.RemoveAt(markerLines.Count - 1);
			Object.Destroy((Object)(object)val2);
			Plugin.Log.LogInfo((object)"[Drone Sync] Received RPC to remove the last line.");
		}
	}

	[PunRPC]
	private void RPC_ClearAllMarkers()
	{
		Plugin.Log.LogInfo((object)"[Drone Sync] Received RPC to clear all markers and lines...");
		foreach (GameObject markerSphere in markerSpheres)
		{
			Object.Destroy((Object)(object)markerSphere);
		}
		foreach (GameObject markerLine in markerLines)
		{
			Object.Destroy((Object)(object)markerLine);
		}
		markerSpheres.Clear();
		markerLines.Clear();
	}

	private GameObject CreateGroundClampedLine(Vector3 start, Vector3 end)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0028: 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_002c: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: 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)
		GameObject val = new GameObject("MarkerLine_Synced");
		LineRenderer val2 = val.AddComponent<LineRenderer>();
		int num = 20;
		List<Vector3> list = new List<Vector3>();
		RaycastHit val4 = default(RaycastHit);
		for (int i = 0; i <= num; i++)
		{
			float num2 = (float)i / (float)num;
			Vector3 val3 = Vector3.Lerp(start, end, num2);
			if (Physics.Raycast(val3 + Vector3.up * 5f, Vector3.down, ref val4, 5f))
			{
				list.Add(((RaycastHit)(ref val4)).point + Vector3.up * 0.1f);
			}
			else
			{
				list.Add(val3);
			}
		}
		val2.positionCount = list.Count;
		val2.SetPositions(list.ToArray());
		val.AddComponent<AnimatedLine>();
		return val;
	}
}
[BepInPlugin("com.SebastianYang.DronePlugin", "Drone Plugin", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
	private GameObject? droneObject;

	private bool isDroneActive;

	private CharacterMovement playerMovementComponent;

	private float currentYaw;

	private float currentPitch;

	public float moveSpeed = 10f;

	public float rotationSpeed = 100f;

	public float maxDistanceFromPlayer = 15f;

	private DroneItemMarkerManager itemMarkerManager;

	internal static ManualLogSource Log { get; private set; }

	public static TMP_FontAsset GameFont { get; internal set; }

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		GameObject val = new GameObject("DroneItemMarkerManager_Instance");
		itemMarkerManager = val.AddComponent<DroneItemMarkerManager>();
		Object.DontDestroyOnLoad((Object)(object)val);
		Log.LogInfo((object)"[Drone Plugin]    DroneItemMarkerManager initialized.");
		new Harmony("com.SebastianYang.DronePlugin.Patch").PatchAll();
		Log.LogInfo((object)"[Drone Plugin]    Plugin is loaded and patched!");
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)116))
		{
			ToggleDrone();
		}
		if (isDroneActive)
		{
			MoveDroneAndHandleMarkers();
		}
	}

	private void ToggleDrone()
	{
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Expected O, but got Unknown
		//IL_013b: 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_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: 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_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		isDroneActive = !isDroneActive;
		Log.LogInfo((object)$"[Drone Plugin]    Drone mode toggled. Now active: {isDroneActive}");
		if ((Object)(object)Character.localCharacter != (Object)null && (Object)(object)playerMovementComponent == (Object)null)
		{
			playerMovementComponent = Character.localCharacter.refs.movement;
		}
		if ((Object)(object)playerMovementComponent == (Object)null)
		{
			Log.LogError((object)"[Drone Plugin]    Unable to find CharacterMovement component. Drone mode cannot be toggled.");
			isDroneActive = false;
		}
		else if (isDroneActive)
		{
			((Behaviour)playerMovementComponent).enabled = false;
			foreach (Bodypart part in Character.localCharacter.refs.ragdoll.partList)
			{
				if ((Object)(object)part.Rig != (Object)null)
				{
					part.Rig.isKinematic = true;
				}
			}
			Log.LogInfo((object)"[Drone Plugin]    Player control disabled, original gravity enabled.");
			if ((Object)(object)MainCamera.instance == (Object)null)
			{
				isDroneActive = false;
				EnablePlayerControl();
				return;
			}
			droneObject = new GameObject("MyDrone_Remote");
			droneObject.transform.position = Character.localCharacter.Head + ((Component)Character.localCharacter).transform.up * 0.5f + ((Component)Character.localCharacter).transform.forward * 1f;
			CameraOverride val = droneObject.AddComponent<CameraOverride>();
			val.fov = 70f;
			val.DoOverride();
			Quaternion rotation = ((Component)Character.localCharacter).transform.rotation;
			Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
			currentYaw = eulerAngles.y;
			currentPitch = eulerAngles.x;
			if ((Object)(object)MainCamera.instance != (Object)null)
			{
				itemMarkerManager.StartManager(MainCamera.instance.cam, droneObject.transform);
				Log.LogInfo((object)"[Drone Plugin]    Item Marker Manager started.");
			}
		}
		else
		{
			Log.LogInfo((object)"[Drone Plugin]    Item Marker Manager stopped.");
			itemMarkerManager.StopManager();
			EnablePlayerControl();
			if ((Object)(object)MainCamera.instance != (Object)null)
			{
				MainCamera.instance.SetCameraOverride((CameraOverride)null);
			}
			if ((Object)(object)droneObject != (Object)null)
			{
				Object.Destroy((Object)(object)droneObject);
			}
		}
	}

	private void EnablePlayerControl()
	{
		if ((Object)(object)playerMovementComponent == (Object)null || (Object)(object)Character.localCharacter == (Object)null)
		{
			return;
		}
		foreach (Bodypart part in Character.localCharacter.refs.ragdoll.partList)
		{
			if ((Object)(object)part.Rig != (Object)null)
			{
				part.Rig.isKinematic = false;
			}
		}
		Log.LogInfo((object)"[]Drone Plugin]    Original gravity disabled.");
		((Behaviour)playerMovementComponent).enabled = true;
		Log.LogInfo((object)"[Drone Plugin]    Player control re-enabled.");
	}

	private void MoveDroneAndHandleMarkers()
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: 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_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: 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_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)droneObject == (Object)null || (Object)(object)Character.localCharacter == (Object)null)
		{
			return;
		}
		Keyboard current = Keyboard.current;
		Mouse current2 = Mouse.current;
		if (current != null && current2 != null)
		{
			Vector2 val = ((InputControl<Vector2>)(object)((Pointer)current2).delta).ReadValue() * 0.1f;
			currentYaw += val.x * rotationSpeed * Time.deltaTime;
			currentPitch -= val.y * rotationSpeed * Time.deltaTime;
			currentPitch = Mathf.Clamp(currentPitch, -89f, 89f);
			droneObject.transform.rotation = Quaternion.Euler(currentPitch, currentYaw, 0f);
			Vector3 zero = Vector3.zero;
			if (((ButtonControl)current.wKey).isPressed)
			{
				zero.z = 1f;
			}
			if (((ButtonControl)current.sKey).isPressed)
			{
				zero.z = -1f;
			}
			if (((ButtonControl)current.dKey).isPressed)
			{
				zero.x = 1f;
			}
			if (((ButtonControl)current.aKey).isPressed)
			{
				zero.x = -1f;
			}
			Vector3 val2 = droneObject.transform.forward * zero.z + droneObject.transform.right * zero.x;
			if (((ButtonControl)current.spaceKey).isPressed)
			{
				val2.y = 1f;
			}
			if (((ButtonControl)current.leftCtrlKey).isPressed)
			{
				val2.y = -1f;
			}
			Transform transform = droneObject.transform;
			transform.position += ((Vector3)(ref val2)).normalized * moveSpeed * Time.deltaTime;
			RaycastHit val3 = default(RaycastHit);
			if (current2.leftButton.wasPressedThisFrame && Physics.Raycast(droneObject.transform.position, droneObject.transform.forward, ref val3, 10000f))
			{
				DroneSyncManager.Instance?.RequestPlaceMarker(((RaycastHit)(ref val3)).point);
			}
			if (current2.rightButton.wasPressedThisFrame)
			{
				DroneSyncManager.Instance?.RequestCancelLastMarker();
			}
			if (((ButtonControl)current.rKey).wasPressedThisFrame)
			{
				DroneSyncManager.Instance?.RequestClearAllMarkers();
			}
		}
	}
}
[HarmonyPatch]
public static class Patch
{
	[HarmonyPatch(typeof(RunManager), "Awake")]
	[HarmonyPostfix]
	public static void AddDroneSyncManager(RunManager __instance)
	{
		if ((Object)(object)((Component)__instance).gameObject.GetComponent<DroneSyncManager>() == (Object)null)
		{
			DroneSyncManager droneSyncManager = ((Component)__instance).gameObject.AddComponent<DroneSyncManager>();
			PhotonView component = ((Component)__instance).gameObject.GetComponent<PhotonView>();
			if ((Object)(object)component == (Object)null)
			{
				component = ((Component)__instance).gameObject.AddComponent<PhotonView>();
			}
			Plugin.Log.LogInfo((object)"DroneSyncManager has been added to the RunManager.");
		}
	}
}
[HarmonyPatch(typeof(GUIManager), "InitReticleList")]
public static class FontCapturePatch
{
	[HarmonyPostfix]
	public static void CaptureGameFont(GUIManager __instance)
	{
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Invalid comparison between Unknown and I4
		if ((Object)(object)Plugin.GameFont != (Object)null)
		{
			return;
		}
		try
		{
			Plugin.Log.LogInfo((object)"Attempting to capture game's main font...");
			TMP_Text componentInChildren = ((Component)__instance).GetComponentInChildren<TMP_Text>(true);
			if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.font != (Object)null)
			{
				Plugin.GameFont = componentInChildren.font;
				Plugin.Log.LogInfo((object)("Successfully captured font: [" + ((Object)Plugin.GameFont).name + "]"));
				return;
			}
			Plugin.Log.LogWarning((object)"Could not find font in GUIManager, searching entire scene as a fallback...");
			TMP_Text[] array = Object.FindObjectsOfType<TMP_Text>(true);
			TMP_Text[] array2 = array;
			foreach (TMP_Text val in array2)
			{
				if ((Object)(object)val.font != (Object)null && (int)val.font.atlasPopulationMode == 1)
				{
					Plugin.GameFont = val.font;
					Plugin.Log.LogInfo((object)("Successfully captured font via fallback method: [" + ((Object)Plugin.GameFont).name + "]"));
					return;
				}
			}
			Plugin.Log.LogError((object)"Failed to capture any valid TMP_FontAsset from the scene!");
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("An error occurred while capturing font: " + ex.Message));
		}
	}
}
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 System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}