Decompiled source of TweakAI v1.2.0

TweakAI.dll

Decompiled 3 weeks 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 IL.RoR2.CharacterAI;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2.CharacterAI;
using RoR2;
using RoR2.CharacterAI;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("TweakAI")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1d0a89cc405c78452a187159158041b19ee44e18")]
[assembly: AssemblyProduct("TweakAI")]
[assembly: AssemblyTitle("TweakAI")]
[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 TweakAI
{
	[BepInPlugin("com.Nuxlar.TweakAI", "TweakAI", "1.2.0")]
	public class TweakAI : BaseUnityPlugin
	{
		public void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			BaseAI.FindEnemyHurtBox += new Manipulator(TargetMainlyPlayers);
			BaseAI.FindEnemyHurtBox += new hook_FindEnemyHurtBox(InfiniVision);
		}

		private void TargetMainlyPlayers(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<BullseyeSearch>(x, "GetResults")
			}))
			{
				return;
			}
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Func<IEnumerable<HurtBox>, BaseAI, IEnumerable<HurtBox>>>((Func<IEnumerable<HurtBox>, BaseAI, IEnumerable<HurtBox>>)delegate(IEnumerable<HurtBox> results, BaseAI instance)
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Invalid comparison between Unknown and I4
				if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.body.teamComponent) && (int)instance.body.teamComponent.teamIndex != 1)
				{
					IEnumerable<HurtBox> enumerable = results.Where(delegate(HurtBox hurtBox)
					{
						GameObject val2 = HurtBox.FindEntityObject(hurtBox);
						CharacterBody val3 = default(CharacterBody);
						return Object.op_Implicit((Object)(object)val2) && val2.TryGetComponent<CharacterBody>(ref val3) && val3.isPlayerControlled;
					});
					if (!enumerable.Any())
					{
						return results;
					}
					return enumerable;
				}
				return results;
			});
		}

		private HurtBox InfiniVision(orig_FindEnemyHurtBox orig, BaseAI self, float maxDistance, bool full360Vision, bool filterByLoS)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			if (Object.op_Implicit((Object)(object)self) && Object.op_Implicit((Object)(object)self.body.teamComponent) && (int)self.body.teamComponent.teamIndex != 1)
			{
				maxDistance = float.PositiveInfinity;
				filterByLoS = false;
				full360Vision = true;
			}
			return orig.Invoke(self, maxDistance, full360Vision, filterByLoS);
		}
	}
}