using System;
using System.Collections.Generic;
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.Configuration;
using BepInEx.Logging;
using IL.RoR2.Projectile;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RoR2;
using RoR2.Projectile;
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("SmartMissiles")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+cfa65b8bacf4aff3088bfe423c20452f959a5399")]
[assembly: AssemblyProduct("SmartMissiles")]
[assembly: AssemblyTitle("SmartMissiles")]
[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 SmartMissiles
{
internal static class Log
{
private static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
internal static void Debug(object data)
{
_logSource.LogDebug(data);
}
internal static void Error(object data)
{
_logSource.LogError(data);
}
internal static void Fatal(object data)
{
_logSource.LogFatal(data);
}
internal static void Info(object data)
{
_logSource.LogInfo(data);
}
internal static void Message(object data)
{
_logSource.LogMessage(data);
}
internal static void Warning(object data)
{
_logSource.LogWarning(data);
}
}
public static class SmartBullseyeSearch
{
public static bool CheckImmune(CandidateInfo candidateInfo)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
HurtBox hurtBox = candidateInfo.hurtBox;
object obj;
if (hurtBox == null)
{
obj = null;
}
else
{
HealthComponent healthComponent = hurtBox.healthComponent;
obj = ((healthComponent != null) ? ((Component)healthComponent).GetComponent<CharacterBody>() : null);
}
CharacterBody val = (CharacterBody)obj;
if (val != null && (val.GetBuffCount(Buffs.Immune.buffIndex) > 0 || val.GetBuffCount(Buffs.HiddenInvincibility.buffIndex) > 0))
{
return true;
}
return false;
}
public static void RefreshCandidatesSmart(this BullseyeSearch bullseyeSearch)
{
//IL_0142: 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_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
Func<HurtBox, CandidateInfo> selector = bullseyeSearch.GetSelector();
int count = HurtBox.readOnlyBullseyesList.Count;
List<CandidateInfo> list = (bullseyeSearch.candidatesEnumerable = new List<CandidateInfo>(count));
bool filterByAngle = bullseyeSearch.filterByAngle;
bool filterByDistance = bullseyeSearch.filterByDistance;
float minDistanceSqr = 0f;
float maxDistanceSqr = 0f;
if (filterByDistance)
{
float num = bullseyeSearch.maxDistanceFilter;
if (Object.op_Implicit((Object)(object)bullseyeSearch.viewer))
{
num = Mathf.Min(num, bullseyeSearch.viewer.visionDistance);
}
minDistanceSqr = bullseyeSearch.minDistanceFilter * bullseyeSearch.minDistanceFilter;
maxDistanceSqr = num * num;
}
for (int i = 0; i < count; i++)
{
HurtBox val = HurtBox.readOnlyBullseyesList[i];
int item = 0;
if (bullseyeSearch.filterByDistinctEntity)
{
item = ((Object)val.healthComponent).GetInstanceID();
if (bullseyeSearch.DistinctEntityHash.Contains(item))
{
continue;
}
}
if (!((TeamMask)(ref bullseyeSearch.teamMaskFilter)).HasTeam(val.teamIndex))
{
continue;
}
CandidateInfo val2 = selector(val);
if ((!filterByAngle || DotOkay(val2)) && (!filterByDistance || DistanceOkay(val2)) && !CheckImmune(val2))
{
if (bullseyeSearch.filterByDistinctEntity)
{
bullseyeSearch.DistinctEntityHash.Add(item);
}
list.Add(val2);
}
}
Func<CandidateInfo, float> sorter = bullseyeSearch.GetSorter();
if (sorter != null)
{
Comparison<CandidateInfo> comparison = (CandidateInfo x, CandidateInfo y) => sorter(x).CompareTo(sorter(y));
list.Sort(comparison);
}
if (bullseyeSearch.filterByDistinctEntity)
{
bullseyeSearch.DistinctEntityHash.Clear();
}
bool DistanceOkay(CandidateInfo candidateInfo2)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
if (candidateInfo2.distanceSqr >= minDistanceSqr)
{
return candidateInfo2.distanceSqr <= maxDistanceSqr;
}
return false;
}
bool DotOkay(CandidateInfo candidateInfo2)
{
//IL_000c: 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)
if (bullseyeSearch.minThetaDot <= candidateInfo2.dot)
{
return candidateInfo2.dot <= bullseyeSearch.maxThetaDot;
}
return false;
}
}
}
[BepInPlugin("mwmw.SmartMissiles", "SmartMissiles", "1.0.0")]
public class SmartMissiles : BaseUnityPlugin
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__ReplaceMissileTargetRefresh;
public static Manipulator <1>__RefreshOnImmune;
}
public const string PluginGUID = "mwmw.SmartMissiles";
public const string PluginAuthor = "mwmw";
public const string PluginName = "SmartMissiles";
public const string PluginVersion = "1.0.0";
public static ConfigFile config;
public void Awake()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Expected O, but got Unknown
Log.Init(((BaseUnityPlugin)this).Logger);
object obj = <>O.<0>__ReplaceMissileTargetRefresh;
if (obj == null)
{
Manipulator val = ReplaceMissileTargetRefresh;
<>O.<0>__ReplaceMissileTargetRefresh = val;
obj = (object)val;
}
MissileController.FindTarget += (Manipulator)obj;
object obj2 = <>O.<1>__RefreshOnImmune;
if (obj2 == null)
{
Manipulator val2 = RefreshOnImmune;
<>O.<1>__RefreshOnImmune = val2;
obj2 = (object)val2;
}
MissileController.FixedUpdate += (Manipulator)obj2;
}
private static void RefreshOnImmune(ILContext il)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
Func<MissileController, bool> func = delegate(MissileController missileController)
{
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
object obj;
if (missileController == null)
{
obj = null;
}
else
{
ProjectileTargetComponent targetComponent = missileController.targetComponent;
if (targetComponent == null)
{
obj = null;
}
else
{
Transform target = targetComponent.target;
obj = ((target == null) ? null : ((Component)target).GetComponent<HurtBox>()?.healthComponent?.body);
}
}
CharacterBody val4 = (CharacterBody)obj;
return ((Object)(object)val4 != (Object)null && (val4.GetBuffCount(Buffs.Immune.buffIndex) > 0 || val4.GetBuffCount(Buffs.HiddenInvincibility.buffIndex) > 0)) ? true : false;
};
ILCursor val = new ILCursor(il);
ILLabel val2 = val.DefineLabel();
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, 3)
}))
{
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Func<MissileController, bool>>(func);
val.Emit(OpCodes.Brtrue, (object)val2);
ILLabel val3 = default(ILLabel);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchBrtrue(x, ref val3)
}))
{
val.MarkLabel(val2);
}
else
{
Log.Error("Part 2 of RefreshOnImmune ILHook failed. Missiles are slightly dumb still, or worse...");
}
}
else
{
Log.Error("Part 1 of RefreshOnImmune ILHook failed. Missiles are slightly dumb still...");
}
}
private static void ReplaceMissileTargetRefresh(ILContext il)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
Action<BullseyeSearch> action = delegate(BullseyeSearch bullseyeSearch)
{
bullseyeSearch.RefreshCandidatesSmart();
};
ILCursor val = new ILCursor(il);
if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<BullseyeSearch>(x, "RefreshCandidates")
}))
{
ILLabel val2 = val.DefineLabel();
val.EmitDelegate<Action<BullseyeSearch>>(action);
val.Emit(OpCodes.Br, (object)val2);
val.Emit(OpCodes.Ldnull);
val.Index += 1;
val.MarkLabel(val2);
}
else
{
Log.Error("ReplaceMissileTargetRefresh ILHook failed. Missiles remain dumb...");
}
}
}
}