Decompiled source of BetterDirectionalDrones v1.0.0

BetterDirectionalDrones.dll

Decompiled 2 months ago
using System;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BetterDirectionalDrones")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BetterDirectionalDrones")]
[assembly: AssemblyTitle("BetterDirectionalDrones")]
[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;
		}
	}
}
namespace BetterDirectionalDrones
{
	[BepInPlugin("BetterDirectionalDrones", "BetterDirectionalDrones", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ItemDrone), "TargetFindPlayer")]
		internal static class ItemDronePlayerTargetPatch
		{
			private static void Postfix(ItemDrone __instance, ref bool __result)
			{
				if (__result && (Object)(object)__instance.playerAvatarTarget == (Object)null)
				{
					__result = false;
				}
			}
		}

		[HarmonyPatch(typeof(ItemDrone), "ActivateMagnet")]
		internal static class ItemDroneActivateMagnetPatch
		{
			private static bool IsTransformFacing(Transform fromTransform, Transform targetTransform, float viewAngle = 45f)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: 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_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = targetTransform.position - fromTransform.position;
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				float num = Vector3.Dot(fromTransform.forward, normalized);
				return Mathf.Acos(num) * 57.29578f <= viewAngle;
			}

			private static Transform RecursiveFindChild(Transform parent, string childName)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Expected O, but got Unknown
				foreach (Transform item in parent)
				{
					Transform val = item;
					if (((Object)val).name == childName)
					{
						return val;
					}
					Transform val2 = RecursiveFindChild(val, childName);
					if ((Object)(object)val2 != (Object)null)
					{
						return val2;
					}
				}
				return null;
			}

			private static bool Prefix(ItemDrone __instance)
			{
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)__instance.playerAvatarTarget != (Object)null)
				{
					Transform fromTransform = ((Component)__instance).transform.Find("Line Start");
					Transform val = RecursiveFindChild(((Component)__instance.playerAvatarTarget).transform.parent, "ANIM HEAD BOT");
					if ((Object)(object)val == (Object)null)
					{
						Logger.LogError((object)"Player is missing `ANIM HEAD BOT` object");
						return true;
					}
					if (!IsTransformFacing(fromTransform, val, 60f))
					{
						__instance.playerAvatarTarget = null;
						__instance.playerTumbleTarget = null;
						__instance.targetIsPlayer = false;
						__instance.targetIsLocalPlayer = false;
						__instance.attachPoint = Vector3.zero;
						__instance.FullReset();
						return false;
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(ItemDrone), "MagnetActiveToggleLogic")]
		internal static class ItemDroneActivateMagnetTogglePatch
		{
			private static bool Prefix(ItemDrone __instance, ref bool activated)
			{
				return __instance.magnetActive != activated;
			}
		}

		private readonly Harmony _harmony = new Harmony("BetterDirectionalDrones");

		internal static ManualLogSource Logger;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony.PatchAll(typeof(ItemDronePlayerTargetPatch));
			_harmony.PatchAll(typeof(ItemDroneActivateMagnetPatch));
			_harmony.PatchAll(typeof(ItemDroneActivateMagnetTogglePatch));
			Logger.LogInfo((object)"Plugin BetterDirectionalDrones is loaded!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BetterDirectionalDrones";

		public const string PLUGIN_NAME = "BetterDirectionalDrones";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}