Decompiled source of MonitorEnemies v1.2.0

NoteBoxz.MonitorEnemies.dll

Decompiled 3 days 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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LCMoniterEnemies.Patches;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
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("NoteBoxz.MonitorEnemies")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+95f4ae7846d685cd4e5a7556148665e6ed02e9bd")]
[assembly: AssemblyProduct("LCMoniterEnemies")]
[assembly: AssemblyTitle("NoteBoxz.MonitorEnemies")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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.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;
		}
	}
}
namespace LCMoniterEnemies
{
	public class EnemyPos : MonoBehaviour
	{
		public EnemyAI Root = null;

		public TransformAndName TnN = null;

		public void OnDestroy()
		{
			ManualCameraRendererPatch.RemoveEnemyFromRadarTargets(this);
		}

		public void LateUpdate()
		{
			//IL_000d: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.localPosition = new Vector3(((Component)this).transform.localPosition.x, LCMoniterEnemies.TargetYoffset.Value, ((Component)this).transform.localPosition.z);
		}
	}
	[BepInPlugin("NoteBoxz.MonitorEnemies", "LCMoniterEnemies", "1.2.0")]
	public class LCMoniterEnemies : BaseUnityPlugin
	{
		public static LCMoniterEnemies Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		internal static ConfigEntry<string> BlackList { get; set; }

		internal static ConfigEntry<float> TargetYoffset { get; set; }

		public static List<string> GetParsedAttackBlacklist()
		{
			if (string.IsNullOrEmpty(BlackList.Value))
			{
				return new List<string>();
			}
			return BlackList.Value.Split(',').ToList();
		}

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			BlackList = ((BaseUnityPlugin)this).Config.Bind<string>("Settings", "Attack Blacklist", "", "The list of enemy names that pikmin can't attack (separated by commas, no spaces in between) (item1,item2,item3...)");
			TargetYoffset = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Camera Target Y Offset", 0f, "The Y (Vertical) Offset of the Enemy's target.");
			Logger.LogInfo((object)"NoteBoxz.MonitorEnemies v1.2.0 has loaded!");
		}

		internal static void Patch()
		{
			//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_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("NoteBoxz.MonitorEnemies");
			}
			Harmony.PatchAll();
			Logger.LogDebug((object)"MoniterEnemies patched!");
		}

		internal static void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"MoniterEnemies unpatched!  Harmony unloaded.");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "NoteBoxz.MonitorEnemies";

		public const string PLUGIN_NAME = "LCMoniterEnemies";

		public const string PLUGIN_VERSION = "1.2.0";
	}
}
namespace LCMoniterEnemies.Patches
{
	[HarmonyPatch(typeof(EnemyAI))]
	internal class EnemyAIPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StarPostFix(EnemyAI __instance)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Expected O, but got Unknown
			EnemyAI __instance2 = __instance;
			if (!LCMoniterEnemies.GetParsedAttackBlacklist().Contains(__instance2.enemyType.enemyName) && (Object)(object)((Component)__instance2).GetComponentInChildren<EnemyPos>() == (Object)null)
			{
				int num = Object.FindObjectOfType<ManualCameraRenderer>().radarTargets.Count((TransformAndName target) => target.name.StartsWith(__instance2.enemyType.enemyName));
				string text = "???";
				text = ((num <= 0) ? (__instance2.enemyType.enemyName ?? "") : $"{__instance2.enemyType.enemyName} #{num}");
				GameObject val = new GameObject(text);
				Transform transform = ((Component)__instance2).transform;
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(0f, LCMoniterEnemies.TargetYoffset.Value, 0f);
				val.transform.position = transform.position + val2;
				val.transform.rotation = transform.rotation;
				val.transform.SetParent(transform, true);
				EnemyPos enemyPos = val.AddComponent<EnemyPos>();
				enemyPos.Root = __instance2;
				TransformAndName tnN = new TransformAndName(((Component)enemyPos).transform, text, true);
				enemyPos.TnN = tnN;
				ManualCameraRendererPatch.AddEnemyToRadarTargets(enemyPos);
			}
		}
	}
	[HarmonyPatch(typeof(ManualCameraRenderer))]
	internal class ManualCameraRendererPatch
	{
		public static void RemoveEnemyFromRadarTargets(EnemyPos enemyTransform)
		{
			if (enemyTransform.TnN == null)
			{
				LCMoniterEnemies.Logger.LogWarning((object)"EnemyPos's tranform and name was null when removing");
				return;
			}
			ManualCameraRenderer[] array = Object.FindObjectsOfType<ManualCameraRenderer>();
			ManualCameraRenderer[] array2 = array;
			foreach (ManualCameraRenderer val in array2)
			{
				if (val.targetTransformIndex + 1 >= val.radarTargets.Count && ((NetworkBehaviour)val).IsServer)
				{
					LCMoniterEnemies.Logger.LogWarning((object)$"{((Object)val).name} Predicted CameraViewIndex will be out of bounds when clearing, setting to {val.radarTargets.Count - 1}");
					val.SwitchRadarTargetAndSync(val.radarTargets.Count - 1);
				}
				if (val.radarTargets.Contains(enemyTransform.TnN))
				{
					val.radarTargets.Remove(enemyTransform.TnN);
				}
			}
		}

		public static void AddEnemyToRadarTargets(EnemyPos enemyTransform)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			if (enemyTransform.TnN == null)
			{
				LCMoniterEnemies.Logger.LogWarning((object)"EnemyPos's tranform and name was null when adding");
				return;
			}
			ManualCameraRenderer[] array = Object.FindObjectsOfType<ManualCameraRenderer>();
			ManualCameraRenderer[] array2 = array;
			foreach (ManualCameraRenderer val in array2)
			{
				if (enemyTransform.TnN == null)
				{
					LCMoniterEnemies.Logger.LogWarning((object)"EnemyPos's tranform and name was null when adding. Generateing new one...");
					TransformAndName tnN = new TransformAndName(((Component)enemyTransform).transform, ((Object)enemyTransform).name, true);
					enemyTransform.TnN = tnN;
				}
				if (!val.radarTargets.Contains(enemyTransform.TnN))
				{
					val.radarTargets.Add(enemyTransform.TnN);
				}
			}
		}
	}
}