Decompiled source of NoAllyAttackBlock v1.2.0

plugins/NoAllyAttackBlock/NoAllyAttackBlock.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using HG;
using HG.Reflection;
using HarmonyLib;
using IL.EntityStates.Commando.CommandoWeapon;
using IL.EntityStates.Drone.DroneWeapon;
using IL.EntityStates.FalseSon;
using IL.EntityStates.FalseSonBoss;
using IL.EntityStates.GolemMonster;
using IL.EntityStates.Halcyonite;
using IL.EntityStates.HermitCrab;
using IL.EntityStates.MiniMushroom;
using IL.EntityStates.Scorchling;
using IL.EntityStates.TitanMonster;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
using Mono.Collections.Generic;
using MonoMod.Cil;
using NoAllyAttackBlock.Utils;
using On.RoR2;
using On.RoR2.Projectile;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.Projectile;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NoAllyAttackBlock")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyInformationalVersion("1.0.0+2e87e59b3b477bdb6b19c834269516c2ecb45942")]
[assembly: AssemblyProduct("NoAllyAttackBlock")]
[assembly: AssemblyTitle("NoAllyAttackBlock")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 NoAllyAttackBlock
{
	internal static class Log
	{
		internal static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		private static string getLogPrefix(string callerPath, string callerMemberName, int callerLineNumber)
		{
			int num = callerPath.LastIndexOf("NoAllyAttackBlock\\");
			if (num >= 0)
			{
				callerPath = callerPath.Substring(num + "NoAllyAttackBlock\\".Length);
			}
			return $"{callerPath}:{callerLineNumber} ({callerMemberName}) ";
		}

		internal static void Error(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogError((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

		internal static void Error_NoCallerPrefix(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogFatal((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

		internal static void Fatal_NoCallerPrefix(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogInfo((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

		internal static void Info_NoCallerPrefix(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogMessage((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

		internal static void Message_NoCallerPrefix(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogWarning((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

		internal static void Warning_NoCallerPrefix(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInPlugin("Gorakh.NoAllyAttackBlock", "NoAllyAttackBlock", "1.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class NoAllyAttackBlockPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "Gorakh.NoAllyAttackBlock";

		public const string PluginAuthor = "Gorakh";

		public const string PluginName = "NoAllyAttackBlock";

		public const string PluginVersion = "1.2.0";

		public static NoAllyAttackBlockPlugin Instance { get; private set; }

		public static ConfigEntry<bool> EnablePassThroughForEnemies { get; private set; }

		public static ConfigEntry<bool> IgnoreStickProjectiles { get; private set; }

		public static ParsedBodyListConfig IgnoreAttackers { get; private set; }

		public static ParsedBodyListConfig IgnoreVictims { get; private set; }

		public static bool ShouldIgnoreAttackCollision(HealthComponent victim, GameObject attacker)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Invalid comparison between Unknown and I4
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0044: Invalid comparison between Unknown and I4
			if (!Object.op_Implicit((Object)(object)victim) || !Object.op_Implicit((Object)(object)attacker))
			{
				return false;
			}
			CharacterBody val = default(CharacterBody);
			if (attacker.TryGetComponent<CharacterBody>(ref val))
			{
				if (IgnoreAttackers.Contains(val.bodyIndex))
				{
					return false;
				}
				if (!val.isPlayerControlled && (int)val.teamComponent.teamIndex != 1 && !EnablePassThroughForEnemies.Value)
				{
					return false;
				}
			}
			if (Object.op_Implicit((Object)(object)victim.body) && IgnoreVictims.Contains(victim.body.bodyIndex))
			{
				return false;
			}
			TeamIndex objectTeam = TeamComponent.GetObjectTeam(attacker);
			if ((int)objectTeam == -1 || FriendlyFireManager.ShouldDirectHitProceed(victim, objectTeam))
			{
				return false;
			}
			return true;
		}

		private void Awake()
		{
			//IL_0031: 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)
			//IL_004c: Expected O, but got Unknown
			//IL_004c: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_007c: Expected O, but got Unknown
			//IL_0091: 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_00b0: Expected O, but got Unknown
			//IL_00b0: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_00e9: Expected O, but got Unknown
			Stopwatch stopwatch = Stopwatch.StartNew();
			Instance = SingletonHelper.Assign<NoAllyAttackBlockPlugin>(Instance, this);
			Log.Init(((BaseUnityPlugin)this).Logger);
			EnablePassThroughForEnemies = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("General", "Enable Pass-Through For Enemies"), false, new ConfigDescription("If enabled, enemy attacks will pass through other enemies", (AcceptableValueBase)null, Array.Empty<object>()));
			IgnoreStickProjectiles = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition("General", "Exclude Sticking Projectiles"), false, new ConfigDescription("If enabled, projectiles that can stick to characters (loader grapple, engi spider mines, etc.) will always have collision enabled", (AcceptableValueBase)null, Array.Empty<object>()));
			IgnoreAttackers = new ParsedBodyListConfig(((BaseUnityPlugin)this).Config.Bind<string>(new ConfigDefinition("General", "Exclude Projectiles From"), "", new ConfigDescription("A comma-separated list of characters to exclude from the mod. Any attack owned by one of these characters will not ignore collisions with allies. Both internal and English display names are accepted, with whitespace and commas removed.", (AcceptableValueBase)null, Array.Empty<object>())));
			IgnoreVictims = new ParsedBodyListConfig(((BaseUnityPlugin)this).Config.Bind<string>(new ConfigDefinition("General", "Never Ignore Collisions With"), "", new ConfigDescription("A comma-separated list of characters to never ignore collisions with. Any character in this list will always have collision with incoming ally attacks. Both internal and English display names are accepted, with whitespace and commas removed.", (AcceptableValueBase)null, Array.Empty<object>())));
			if (RiskOfOptionsCompat.Active)
			{
				RiskOfOptionsCompat.Run();
			}
			stopwatch.Stop();
			Log.Message_NoCallerPrefix($"Initialized in {stopwatch.Elapsed.TotalSeconds:F2} seconds");
		}

		private void OnDestroy()
		{
			IgnoreAttackers.Dispose();
			IgnoreVictims.Dispose();
			Instance = SingletonHelper.Unassign<NoAllyAttackBlockPlugin>(Instance, this);
		}
	}
	public class ProjectileIgnoreCollisions : MonoBehaviour
	{
		private ProjectileController _projectileController;

		private ProjectileStickOnImpact _projectileStickOnImpact;

		private readonly HashSet<CharacterBody> _ignoringCollisionsWith = new HashSet<CharacterBody>();

		private float _ignoringCollisionsCleanTimer;

		private void Awake()
		{
			_projectileController = ((Component)this).GetComponent<ProjectileController>();
			_projectileStickOnImpact = ((Component)this).GetComponent<ProjectileStickOnImpact>();
		}

		private void Start()
		{
			updateAllCharacterCollisions();
		}

		private void OnEnable()
		{
			_ignoringCollisionsWith.RemoveWhere((CharacterBody b) => !Object.op_Implicit((Object)(object)b));
			updateAllCharacterCollisions();
			CharacterBody.onBodyStartGlobal += updateIgnoreCollisions;
			TeamComponent.onJoinTeamGlobal += onJoinTeamGlobal;
			NoAllyAttackBlockPlugin.EnablePassThroughForEnemies.SettingChanged += EnablePassThroughForEnemies_SettingChanged;
			NoAllyAttackBlockPlugin.IgnoreStickProjectiles.SettingChanged += IgnoreStickProjectiles_SettingChanged;
			NoAllyAttackBlockPlugin.IgnoreAttackers.OnValueChanged += updateAllCharacterCollisions;
			NoAllyAttackBlockPlugin.IgnoreVictims.OnValueChanged += updateAllCharacterCollisions;
		}

		private void OnDisable()
		{
			CharacterBody.onBodyStartGlobal -= updateIgnoreCollisions;
			TeamComponent.onJoinTeamGlobal -= onJoinTeamGlobal;
			NoAllyAttackBlockPlugin.EnablePassThroughForEnemies.SettingChanged -= EnablePassThroughForEnemies_SettingChanged;
			NoAllyAttackBlockPlugin.IgnoreStickProjectiles.SettingChanged -= IgnoreStickProjectiles_SettingChanged;
			NoAllyAttackBlockPlugin.IgnoreAttackers.OnValueChanged -= updateAllCharacterCollisions;
			NoAllyAttackBlockPlugin.IgnoreVictims.OnValueChanged -= updateAllCharacterCollisions;
		}

		private void FixedUpdate()
		{
			if (!Object.op_Implicit((Object)(object)_projectileController))
			{
				return;
			}
			_ignoringCollisionsCleanTimer -= Time.fixedDeltaTime;
			if (_ignoringCollisionsCleanTimer <= 0f)
			{
				if (_ignoringCollisionsWith.RemoveWhere((CharacterBody b) => !Object.op_Implicit((Object)(object)b)) > 0)
				{
					_ignoringCollisionsCleanTimer += 10f;
				}
				else
				{
					_ignoringCollisionsCleanTimer += 30f;
				}
			}
		}

		private void EnablePassThroughForEnemies_SettingChanged(object sender, EventArgs e)
		{
			updateAllCharacterCollisions();
		}

		private void IgnoreStickProjectiles_SettingChanged(object sender, EventArgs e)
		{
			updateAllCharacterCollisions();
		}

		private void onJoinTeamGlobal(TeamComponent teamComponent, TeamIndex newTeam)
		{
			updateIgnoreCollisions(teamComponent.body);
		}

		private void updateAllCharacterCollisions()
		{
			foreach (CharacterBody readOnlyInstances in CharacterBody.readOnlyInstancesList)
			{
				updateIgnoreCollisions(readOnlyInstances);
			}
		}

		private void updateIgnoreCollisions(CharacterBody body)
		{
			if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.healthComponent) && Object.op_Implicit((Object)(object)_projectileController) && Object.op_Implicit((Object)(object)_projectileController.owner) && !((Object)(object)((Component)body).gameObject == (Object)(object)_projectileController.owner))
			{
				bool ignore = NoAllyAttackBlockPlugin.ShouldIgnoreAttackCollision(body.healthComponent, _projectileController.owner);
				if (NoAllyAttackBlockPlugin.IgnoreStickProjectiles.Value && Object.op_Implicit((Object)(object)_projectileStickOnImpact) && !_projectileStickOnImpact.ignoreCharacters)
				{
					ignore = false;
				}
				setIgnoreCollisions(body, ignore);
			}
		}

		private void setIgnoreCollisions(CharacterBody body, bool ignore)
		{
			if (!Object.op_Implicit((Object)(object)body) || !(ignore ? _ignoringCollisionsWith.Add(body) : _ignoringCollisionsWith.Remove(body)))
			{
				return;
			}
			Collider[] myColliders = _projectileController.myColliders;
			if (myColliders == null || myColliders.Length == 0)
			{
				return;
			}
			Collider[] a = ((Component)body).GetComponentsInChildren<Collider>(true);
			ModelLocator modelLocator = body.modelLocator;
			if (Object.op_Implicit((Object)(object)modelLocator))
			{
				Transform modelTransform = modelLocator.modelTransform;
				if (Object.op_Implicit((Object)(object)modelTransform) && !modelTransform.IsChildOf(body.transform))
				{
					Collider[] componentsInChildren = ((Component)modelTransform).GetComponentsInChildren<Collider>(true);
					ArrayUtil.Append(ref a, componentsInChildren);
				}
			}
			Collider[] array = a;
			foreach (Collider val in array)
			{
				Collider[] array2 = myColliders;
				for (int j = 0; j < array2.Length; j++)
				{
					Physics.IgnoreCollision(array2[j], val, ignore);
				}
			}
		}
	}
	internal static class RiskOfOptionsCompat
	{
		public static bool Active => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void Run()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_004d: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0077: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(NoAllyAttackBlockPlugin.EnablePassThroughForEnemies), "Gorakh.NoAllyAttackBlock", "Disable Ally Attack Collision");
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(NoAllyAttackBlockPlugin.IgnoreStickProjectiles), "Gorakh.NoAllyAttackBlock", "Disable Ally Attack Collision");
			ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(NoAllyAttackBlockPlugin.IgnoreAttackers.Config, new InputFieldConfig
			{
				submitOn = (SubmitEnum)6
			}), "Gorakh.NoAllyAttackBlock", "Disable Ally Attack Collision");
			ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(NoAllyAttackBlockPlugin.IgnoreVictims.Config, new InputFieldConfig
			{
				submitOn = (SubmitEnum)6
			}), "Gorakh.NoAllyAttackBlock", "Disable Ally Attack Collision");
			FileInfo fileInfo = null;
			DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(((BaseUnityPlugin)NoAllyAttackBlockPlugin.Instance).Info.Location));
			do
			{
				FileInfo[] files = directoryInfo.GetFiles("icon.png", SearchOption.TopDirectoryOnly);
				if (files != null && files.Length != 0)
				{
					fileInfo = files[0];
					break;
				}
				directoryInfo = directoryInfo.Parent;
			}
			while (directoryInfo != null && !string.Equals(directoryInfo.Name, "plugins", StringComparison.OrdinalIgnoreCase));
			if (fileInfo != null)
			{
				Texture2D val = new Texture2D(256, 256);
				((Object)val).name = "NoAllyAttackBlockIcon";
				if (ImageConversion.LoadImage(val, File.ReadAllBytes(fileInfo.FullName)))
				{
					Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
					((Object)obj).name = "NoAllyAttackBlockIcon";
					ModSettingsManager.SetModIcon(obj, "Gorakh.NoAllyAttackBlock", "Disable Ally Attack Collision");
				}
			}
		}
	}
}
namespace NoAllyAttackBlock.Utils
{
	public static class ArrayUtil
	{
		public static void Append<T>(ref T[] a, T[] b)
		{
			if (a == null)
			{
				a = b;
			}
			else if (a.Length == 0)
			{
				a = b ?? Array.Empty<T>();
			}
			else if (b != null && b.Length != 0)
			{
				T[] array = new T[a.Length + b.Length];
				Array.Copy(a, 0, array, 0, a.Length);
				Array.Copy(b, 0, array, a.Length, b.Length);
				a = array;
			}
		}
	}
	public class BodyIndexComparer : IComparer<BodyIndex>
	{
		public static BodyIndexComparer Instance { get; } = new BodyIndexComparer();


		public int Compare(BodyIndex x, BodyIndex y)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Expected I4, but got Unknown
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected I4, but got Unknown
			return ((int)x).CompareTo((int)y);
		}
	}
	public class ParsedBodyListConfig : IReadOnlyList<BodyIndex>, IEnumerable<BodyIndex>, IEnumerable, IReadOnlyCollection<BodyIndex>, IDisposable
	{
		private IComparer<BodyIndex> _comparer = BodyIndexComparer.Instance;

		private BodyIndex[] _parsedArray;

		private bool _catalogAvailable;

		private bool _isDisposed;

		public ConfigEntry<string> Config { get; }

		public IComparer<BodyIndex> Comparer
		{
			get
			{
				return _comparer;
			}
			set
			{
				_comparer = value;
				refreshValue();
			}
		}

		public int Count => _parsedArray.Length;

		public BodyIndex this[int index] => _parsedArray[index];

		public event Action OnValueChanged;

		public ParsedBodyListConfig(ConfigEntry<string> config)
		{
			Config = config;
			Config.SettingChanged += Config_SettingChanged;
			((ResourceAvailability)(ref BodyCatalog.availability)).CallWhenAvailable((Action)onCatalogAvailable);
		}

		public void Dispose()
		{
			if (!_isDisposed)
			{
				_isDisposed = true;
				Config.SettingChanged -= Config_SettingChanged;
			}
		}

		public IEnumerator<BodyIndex> GetEnumerator()
		{
			return ((IEnumerable<BodyIndex>)_parsedArray).GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return _parsedArray.GetEnumerator();
		}

		public int IndexOf(BodyIndex value)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (_parsedArray == null || _parsedArray.Length == 0)
			{
				return -1;
			}
			int num = Array.BinarySearch(_parsedArray, value, Comparer);
			if (num < 0)
			{
				return -1;
			}
			return num;
		}

		public bool Contains(BodyIndex value)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return IndexOf(value) >= 0;
		}

		private void Config_SettingChanged(object sender, EventArgs e)
		{
			refreshValue();
		}

		private void onCatalogAvailable()
		{
			_catalogAvailable = true;
			refreshValue();
		}

		private void refreshValue()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (!_catalogAvailable)
			{
				return;
			}
			string[] array = Config.Value.Split(new string[1] { "," }, StringSplitOptions.RemoveEmptyEntries);
			List<BodyIndex> list = new List<BodyIndex>(array.Length);
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = array[i].Trim();
				if (parseBodyIndex(array[i], out var bodyIndex))
				{
					list.Add(bodyIndex);
				}
				else
				{
					Log.Warning($"Failed to find character matching '{array[i]}' for '{((ConfigEntryBase)Config).Definition}'", "X:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Utils\\ParsedBodyListConfig.cs", "refreshValue", 112);
				}
			}
			_parsedArray = list.ToArray();
			Array.Sort(_parsedArray, Comparer);
			this.OnValueChanged?.Invoke();
		}

		private bool parseBodyIndex(string input, out BodyIndex bodyIndex)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected I4, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected I4, but got Unknown
			bodyIndex = (BodyIndex)(int)BodyCatalog.FindBodyIndex(input);
			if ((int)bodyIndex != -1)
			{
				return false;
			}
			foreach (CharacterBody allBodyPrefabBodyBodyComponent in BodyCatalog.allBodyPrefabBodyBodyComponents)
			{
				string name2 = ((Object)allBodyPrefabBodyBodyComponent).name;
				if (checkName(name2) || (name2.EndsWith("body", StringComparison.OrdinalIgnoreCase) && checkName(name2.Remove(name2.Length - 4))) || checkName(allBodyPrefabBodyBodyComponent.baseNameToken) || (!Language.IsTokenInvalid(allBodyPrefabBodyBodyComponent.baseNameToken) && checkName(Language.english.GetLocalizedStringByToken(allBodyPrefabBodyBodyComponent.baseNameToken))))
				{
					bodyIndex = (BodyIndex)(int)allBodyPrefabBodyBodyComponent.bodyIndex;
					return true;
				}
			}
			bodyIndex = (BodyIndex)(-1);
			return false;
			bool checkName(string name)
			{
				StringBuilder stringBuilder = StringBuilderPool.RentStringBuilder();
				StringBuilder stringBuilder2 = StringBuilderPool.RentStringBuilder();
				StringBuilder stringBuilder3 = StringBuilderPool.RentStringBuilder();
				for (int i = 0; i < name.Length; i++)
				{
					if (!char.IsWhiteSpace(name[i]) && name[i] != ',')
					{
						stringBuilder.Append(name[i]);
						if (name[i] <= '\u007f')
						{
							stringBuilder2.Append(name[i]);
						}
						if (char.IsLetterOrDigit(name[i]))
						{
							stringBuilder3.Append(name[i]);
						}
					}
				}
				string a = stringBuilder.ToString();
				string a2 = stringBuilder2.ToString();
				string a3 = stringBuilder3.ToString();
				StringBuilderPool.ReturnStringBuilder(stringBuilder3);
				StringBuilderPool.ReturnStringBuilder(stringBuilder2);
				StringBuilderPool.ReturnStringBuilder(stringBuilder);
				if (!string.Equals(a, input, StringComparison.OrdinalIgnoreCase) && !string.Equals(a2, input, StringComparison.OrdinalIgnoreCase))
				{
					return string.Equals(a3, input, StringComparison.OrdinalIgnoreCase);
				}
				return true;
			}
		}
	}
}
namespace NoAllyAttackBlock.Patches
{
	internal static class AttackCollisionHooks
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_DefaultFilterCallbackImplementation <0>__BulletAttack_DefaultFilterCallbackImplementation;

			public static hook_Awake <1>__ProjectileController_Awake;
		}

		[SystemInitializer(new Type[] { })]
		private static void Init()
		{
			//IL_0010: 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_001b: Expected O, but got Unknown
			//IL_0030: 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_003b: Expected O, but got Unknown
			object obj = <>O.<0>__BulletAttack_DefaultFilterCallbackImplementation;
			if (obj == null)
			{
				hook_DefaultFilterCallbackImplementation val = BulletAttack_DefaultFilterCallbackImplementation;
				<>O.<0>__BulletAttack_DefaultFilterCallbackImplementation = val;
				obj = (object)val;
			}
			BulletAttack.DefaultFilterCallbackImplementation += (hook_DefaultFilterCallbackImplementation)obj;
			object obj2 = <>O.<1>__ProjectileController_Awake;
			if (obj2 == null)
			{
				hook_Awake val2 = ProjectileController_Awake;
				<>O.<1>__ProjectileController_Awake = val2;
				obj2 = (object)val2;
			}
			ProjectileController.Awake += (hook_Awake)obj2;
		}

		private static bool BulletAttack_DefaultFilterCallbackImplementation(orig_DefaultFilterCallbackImplementation orig, BulletAttack bulletAttack, ref BulletHit hitInfo)
		{
			bool result = orig.Invoke(bulletAttack, ref hitInfo);
			try
			{
				if (NoAllyAttackBlockPlugin.ShouldIgnoreAttackCollision(hitInfo.hitHurtBox?.healthComponent, bulletAttack.owner))
				{
					return false;
				}
			}
			catch (Exception data)
			{
				Log.Error_NoCallerPrefix(data);
			}
			return result;
		}

		private static void ProjectileController_Awake(orig_Awake orig, ProjectileController self)
		{
			orig.Invoke(self);
			((Component)self).gameObject.AddComponent<ProjectileIgnoreCollisions>();
		}
	}
	internal static class CharacterRaycastCollisionHooks
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_GeneratePingInfo <0>__PingerController_GeneratePingInfo;

			public static hook_HandleCharacterPhysicsCastResults <1>__Util_HandleCharacterPhysicsCastResults;
		}

		private static bool _isGeneratingPingInfo;

		private static bool raycastHookEnabled
		{
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			get
			{
				return !_isGeneratingPingInfo;
			}
		}

		[SystemInitializer(new Type[] { })]
		private static void Init()
		{
			//IL_0010: 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_001b: Expected O, but got Unknown
			//IL_0030: 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_003b: Expected O, but got Unknown
			object obj = <>O.<0>__PingerController_GeneratePingInfo;
			if (obj == null)
			{
				hook_GeneratePingInfo val = PingerController_GeneratePingInfo;
				<>O.<0>__PingerController_GeneratePingInfo = val;
				obj = (object)val;
			}
			PingerController.GeneratePingInfo += (hook_GeneratePingInfo)obj;
			object obj2 = <>O.<1>__Util_HandleCharacterPhysicsCastResults;
			if (obj2 == null)
			{
				hook_HandleCharacterPhysicsCastResults val2 = Util_HandleCharacterPhysicsCastResults;
				<>O.<1>__Util_HandleCharacterPhysicsCastResults = val2;
				obj2 = (object)val2;
			}
			Util.HandleCharacterPhysicsCastResults += (hook_HandleCharacterPhysicsCastResults)obj2;
		}

		private static bool PingerController_GeneratePingInfo(orig_GeneratePingInfo orig, Ray aimRay, GameObject bodyObject, out PingInfo result)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			_isGeneratingPingInfo = true;
			try
			{
				return orig.Invoke(aimRay, bodyObject, ref result);
			}
			finally
			{
				_isGeneratingPingInfo = false;
			}
		}

		private static void tryRemoveIgnoredRaycastHits(GameObject bodyObject, RaycastHit[] hits, ref int hitsLength)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)bodyObject) || !raycastHookEnabled)
			{
				return;
			}
			int num = 0;
			int num2 = 0;
			HurtBox val2 = default(HurtBox);
			HealthComponent val3 = default(HealthComponent);
			while (num2 < hitsLength - num)
			{
				if (num > 0)
				{
					hits[num2] = hits[num2 + num];
				}
				Transform transform = ((RaycastHit)(ref hits[num2])).transform;
				HealthComponent val = null;
				if (((Component)transform).TryGetComponent<HurtBox>(ref val2))
				{
					val = val2.healthComponent;
				}
				else if (((Component)transform).TryGetComponent<HealthComponent>(ref val3))
				{
					val = val3;
				}
				if (Object.op_Implicit((Object)(object)val) && NoAllyAttackBlockPlugin.ShouldIgnoreAttackCollision(val, bodyObject))
				{
					num++;
				}
				else
				{
					num2++;
				}
			}
			hitsLength -= num;
		}

		private static bool Util_HandleCharacterPhysicsCastResults(orig_HandleCharacterPhysicsCastResults orig, GameObject bodyObject, Ray ray, int numHits, RaycastHit[] hits, out RaycastHit hitInfo)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			tryRemoveIgnoredRaycastHits(bodyObject, hits, ref numHits);
			return orig.Invoke(bodyObject, ray, numHits, hits, ref hitInfo);
		}
	}
	internal static class CharacterRaycastPatches
	{
		private static readonly LayerMask _layersToPatch = LayerMask.op_Implicit(LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.entityPrecise)).mask) | LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.playerBody)).mask) | LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.enemyBody)).mask));

		[SystemInitializer(new Type[] { })]
		private static void Init()
		{
			MethodInfo method = typeof(Physics).GetMethod("Raycast", new Type[5]
			{
				typeof(Ray),
				typeof(RaycastHit).MakeByRefType(),
				typeof(float),
				typeof(int),
				typeof(QueryTriggerInteraction)
			});
			if (method != null)
			{
				Manipulator replaceRaycastManipulator = getReplaceRaycastManipulator(method);
				WhirlwindRush.HandleIdentifySafePathForward += replaceRaycastManipulator;
				FireMortar.Fire += replaceRaycastManipulator;
				SporeGrenade.FireGrenade += replaceRaycastManipulator;
				ScorchlingLavaBomb.Spit += replaceRaycastManipulator;
			}
			else
			{
				Log.Error("Failed to find method UnityEngine.Physics.Raycast(Ray, out RaycastHit, float, int, QueryTriggerInteraction)", "X:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Patches\\CharacterRaycastPatches.cs", "Init", 39);
			}
			MethodInfo method2 = typeof(Physics).GetMethod("Raycast", new Type[4]
			{
				typeof(Ray),
				typeof(RaycastHit).MakeByRefType(),
				typeof(float),
				typeof(int)
			});
			if (method2 != null)
			{
				Manipulator replaceRaycastManipulator2 = getReplaceRaycastManipulator(method2);
				FireShrapnel.OnEnter += replaceRaycastManipulator2;
				FireTwinRocket.FireProjectile += replaceRaycastManipulator2;
				LaserFatherBurst.FireBurstLaser += replaceRaycastManipulator2;
				LunarGazeCharge.Update += replaceRaycastManipulator2;
				ChargeLaser.Update += replaceRaycastManipulator2;
				FireLaser.OnEnter += replaceRaycastManipulator2;
				ChargeTriLaser.Update += replaceRaycastManipulator2;
				TriLaser.FireTriLaser += replaceRaycastManipulator2;
				ChargeMegaLaser.Update += replaceRaycastManipulator2;
			}
			else
			{
				Log.Error("Failed to find method UnityEngine.Physics.Raycast(Ray, out RaycastHit, float, int)", "X:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Patches\\CharacterRaycastPatches.cs", "Init", 70);
			}
		}

		private static Manipulator getReplaceRaycastManipulator(MethodInfo raycastMethod)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			return new Manipulator(manipulator);
			void manipulator(ILContext il)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Expected O, but got Unknown
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Expected O, but got Unknown
				//IL_0165: Unknown result type (might be due to invalid IL or missing references)
				//IL_016c: Expected O, but got Unknown
				//IL_0188: Unknown result type (might be due to invalid IL or missing references)
				//IL_018f: Expected O, but got Unknown
				//IL_0198: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d1: Expected O, but got Unknown
				//IL_01da: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0243: Unknown result type (might be due to invalid IL or missing references)
				//IL_024a: Expected O, but got Unknown
				//IL_0209: Unknown result type (might be due to invalid IL or missing references)
				//IL_0210: Expected O, but got Unknown
				//IL_0219: Unknown result type (might be due to invalid IL or missing references)
				//IL_0226: Unknown result type (might be due to invalid IL or missing references)
				//IL_0269: Unknown result type (might be due to invalid IL or missing references)
				//IL_0285: Unknown result type (might be due to invalid IL or missing references)
				//IL_0291: Unknown result type (might be due to invalid IL or missing references)
				//IL_029e: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_030d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0323: Unknown result type (might be due to invalid IL or missing references)
				//IL_0345: Unknown result type (might be due to invalid IL or missing references)
				ILCursor val3 = new ILCursor(il);
				int num = 0;
				Collection<VariableDefinition> variables = il.Method.Body.Variables;
				VariableDefinition val4 = null;
				VariableDefinition val5 = null;
				VariableDefinition val6 = null;
				VariableDefinition val7 = null;
				VariableDefinition val8 = null;
				ParameterInfo[] parameters = raycastMethod.GetParameters();
				VariableDefinition[] array = (VariableDefinition[])(object)new VariableDefinition[parameters.Length];
				for (int i = 0; i < parameters.Length; i++)
				{
					Type parameterType = parameters[i].ParameterType;
					string name = parameters[i].Name;
					VariableDefinition val9 = new VariableDefinition(il.Import(parameterType));
					variables.Add(val9);
					array[i] = val9;
					if (parameterType == typeof(Ray))
					{
						val4 = val9;
					}
					else if (parameterType == typeof(RaycastHit).MakeByRefType())
					{
						val5 = val9;
					}
					else if (parameterType == typeof(float))
					{
						if (string.Equals(name, "maxDistance", StringComparison.OrdinalIgnoreCase))
						{
							val6 = val9;
						}
					}
					else if (parameterType == typeof(int))
					{
						if (string.Equals(name, "layerMask", StringComparison.OrdinalIgnoreCase))
						{
							val7 = val9;
						}
					}
					else if (parameterType == typeof(QueryTriggerInteraction))
					{
						val8 = val9;
					}
				}
				if (val4 == null)
				{
					Log.Error("Raycast method is missing ray parameter", "X:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Patches\\CharacterRaycastPatches.cs", "getReplaceRaycastManipulator", 131);
				}
				else
				{
					if (val5 == null)
					{
						val5 = new VariableDefinition((TypeReference)(object)TypeReferenceRocks.MakeByReferenceType(il.Import(typeof(RaycastHit))));
						variables.Add(val5);
					}
					if (val6 == null)
					{
						val6 = new VariableDefinition(il.Import(typeof(float)));
						variables.Add(val6);
						val3.Emit(OpCodes.Ldc_R4, float.PositiveInfinity);
						val3.Emit(OpCodes.Stloc, val6);
					}
					if (val7 == null)
					{
						val7 = new VariableDefinition(il.Import(typeof(int)));
						variables.Add(val7);
						val3.Emit(OpCodes.Ldc_I4, -5);
						val3.Emit(OpCodes.Stloc, val7);
					}
					if (val8 == null)
					{
						val8 = new VariableDefinition(il.Import(typeof(QueryTriggerInteraction)));
						variables.Add(val8);
						val3.Emit(OpCodes.Ldc_I4, 0);
						val3.Emit(OpCodes.Stloc, val8);
					}
					VariableDefinition val10 = new VariableDefinition(il.Import(typeof(bool)));
					variables.Add(val10);
					while (val3.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
					{
						(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)raycastMethod)
					}))
					{
						val3.MoveAfterLabels();
						for (int num2 = array.Length - 1; num2 >= 0; num2--)
						{
							val3.Emit(OpCodes.Stloc, array[num2]);
						}
						val3.Emit(OpCodes.Ldarg_0);
						val3.Emit(OpCodes.Ldloc, val4);
						val3.Emit(OpCodes.Ldloc, val5);
						val3.Emit(OpCodes.Ldloc, val6);
						val3.Emit(OpCodes.Ldloc, val7);
						val3.Emit(OpCodes.Ldloc, val8);
						val3.Emit(OpCodes.Ldloca, val10);
						val3.EmitDelegate<<>F{00080040}<object, Ray, RaycastHit, float, int, QueryTriggerInteraction, bool, bool>>((<>F{00080040}<object, Ray, RaycastHit, float, int, QueryTriggerInteraction, bool, bool>)tryReplaceRaycast);
						ILLabel val11 = val3.DefineLabel();
						val3.Emit(OpCodes.Brfalse, (object)val11);
						val3.Emit(OpCodes.Ldloc, val10);
						ILLabel val12 = val3.DefineLabel();
						val3.Emit(OpCodes.Br, (object)val12);
						val3.MarkLabel(val11);
						val3.MoveAfterLabels();
						for (int j = 0; j < array.Length; j++)
						{
							val3.Emit(OpCodes.Ldloc, array[j]);
						}
						int index = val3.Index;
						val3.Index = index + 1;
						val3.MarkLabel(val12);
						num++;
					}
					if (num == 0)
					{
						Log.Warning("Found 0 patch locations for raycast method " + GeneralExtensions.FullDescription((MethodBase)raycastMethod) + " in " + ((MemberReference)il.Method).FullName, "X:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Patches\\CharacterRaycastPatches.cs", "getReplaceRaycastManipulator", 247);
					}
				}
			}
			static bool tryReplaceRaycast(object instance, Ray ray, ref RaycastHit hitInfo, float maxDistance, int layerMask, QueryTriggerInteraction queryTriggerInteraction, out bool raycastResult)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				if ((layerMask & LayerMask.op_Implicit(_layersToPatch)) == 0)
				{
					Log.Warning($"Raycast on layers {layerMask} does not match required layers", "X:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Patches\\CharacterRaycastPatches.cs", "getReplaceRaycastManipulator", 195);
					raycastResult = false;
					return false;
				}
				if (instance == null)
				{
					raycastResult = false;
					return false;
				}
				EntityState val = (EntityState)((instance is EntityState) ? instance : null);
				if (val == null)
				{
					Log.Error("Instance type " + instance.GetType().FullName + " is not implemented", "X:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Patches\\CharacterRaycastPatches.cs", "getReplaceRaycastManipulator", 211);
					raycastResult = false;
					return false;
				}
				CharacterBody characterBody = val.characterBody;
				GameObject val2 = ((characterBody != null) ? ((Component)characterBody).gameObject : null);
				raycastResult = Util.CharacterRaycast(val2, ray, ref hitInfo, maxDistance, LayerMask.op_Implicit(layerMask), queryTriggerInteraction);
				return true;
			}
		}
	}
}