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 Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using MonoMod.Utils;
using NoAllyAttackBlock.Utils;
using NoAllyAttackBlock.Utils.Extensions;
using On.RoR2;
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+f8a2c4b5c18afdcfd7c49f94dc329d73436606ce")]
[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
{
private static readonly StringBuilder _sharedStringBuilder;
private static readonly int _cachedCallerPathPrefixLength;
private static ManualLogSource _logSource;
static Log()
{
_sharedStringBuilder = new StringBuilder(256);
_cachedCallerPathPrefixLength = getCallerPathPrefixLength("D:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Log.cs");
static int getCallerPathPrefixLength([CallerFilePath] string callerPath = null)
{
int num = callerPath.LastIndexOf("NoAllyAttackBlock\\");
if (num >= 0)
{
return num + "NoAllyAttackBlock\\".Length;
}
Debug.LogError((object)"[NoAllyAttackBlock] Logger failed to determine caller path prefix length");
return 0;
}
}
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
private static StringBuilder AppendCallerPrefix(this StringBuilder stringBuilder, string callerPath, string callerMemberName, int callerLineNumber)
{
return stringBuilder.Append(callerPath, _cachedCallerPathPrefixLength, callerPath.Length - _cachedCallerPathPrefixLength).Append(':').Append(callerLineNumber)
.Append(" (")
.Append(callerMemberName)
.Append("):");
}
private static StringBuilder buildCallerLogString(string callerPath, string callerMemberName, int callerLineNumber, object data)
{
return _sharedStringBuilder.Clear().AppendCallerPrefix(callerPath, callerMemberName, callerLineNumber).Append(' ')
.Append(data);
}
[Conditional("DEBUG")]
internal static void Debug(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
{
_logSource.LogDebug((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Conditional("DEBUG")]
internal static void Debug_NoCallerPrefix(object data)
{
_logSource.LogDebug(data);
}
internal static void Error(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
{
_logSource.LogError((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
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)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
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)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
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)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
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)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void Warning_NoCallerPrefix(object data)
{
_logSource.LogWarning(data);
}
internal static void LogType(LogLevel level, object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
if ((level & 0x20) == 0)
{
_logSource.Log(level, (object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void LogType_NoCallerPrefix(LogLevel level, object data)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
if ((level & 0x20) == 0)
{
_logSource.Log(level, data);
}
}
}
[BepInPlugin("Gorakh.NoAllyAttackBlock", "NoAllyAttackBlock", "1.2.4")]
[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.4";
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;
[SystemInitializer(new Type[] { typeof(ProjectileCatalog) })]
private static void Init()
{
for (int i = 0; i < ProjectileCatalog.projectilePrefabCount; i++)
{
GameObject projectilePrefab = ProjectileCatalog.GetProjectilePrefab(i);
if (Object.op_Implicit((Object)(object)projectilePrefab))
{
projectilePrefab.AddComponent<ProjectileIgnoreCollisions>();
}
}
}
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 ILVariablePool
{
private readonly ILContext _context;
private readonly List<VariableDefinition> _variables = new List<VariableDefinition>();
public ILVariablePool(ILContext context)
{
_context = context;
}
public VariableDefinition GetOrCreate<T>()
{
return GetOrCreate(typeof(T));
}
public VariableDefinition GetOrCreate(Type variableType)
{
return GetOrCreate(_context.Import(variableType));
}
public VariableDefinition GetOrCreate(TypeReference variableType)
{
VariableDefinition val = null;
for (int i = 0; i < _variables.Count; i++)
{
VariableDefinition val2 = _variables[i];
if (((MemberReference)((VariableReference)val2).VariableType).FullName == ((MemberReference)variableType).FullName)
{
val = val2;
_variables.RemoveAt(i);
break;
}
}
if (val == null)
{
val = _context.AddVariable(variableType);
}
return val;
}
public void Return(VariableDefinition variable)
{
_variables.Add(variable);
}
}
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}'", "D:\\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.Utils.Extensions
{
public static class PatchExtensions
{
public static void EmitSkipMethodCall(this ILCursor c, MethodDefinition method = null)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
c.EmitSkipMethodCall(OpCodes.Br, method);
}
public static void EmitSkipMethodCall(this ILCursor c, OpCode branchOpCode, MethodDefinition method = null)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
c.EmitSkipMethodCall(branchOpCode, null, method);
}
public static void EmitSkipMethodCall(this ILCursor c, OpCode branchOpCode, Action<ILCursor> emitSkippedReturnValue, MethodDefinition method = null)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Invalid comparison between Unknown and I4
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
if (c == null)
{
throw new ArgumentNullException("c");
}
if ((int)((OpCode)(ref branchOpCode)).FlowControl != 0 && (int)((OpCode)(ref branchOpCode)).FlowControl != 3)
{
throw new ArgumentException($"Invalid branch OpCode: {branchOpCode}");
}
if (method == null)
{
MethodReference val = default(MethodReference);
if (!ILPatternMatchingExt.MatchCallOrCallvirt(c.Next, ref val))
{
Log.Error($"Failed to find method call to skip: {((MemberReference)c.Context.Method).FullName} at instruction {c.Next} ({c.Index})", "D:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Utils\\Extensions\\PatchExtensions.cs", "EmitSkipMethodCall", 34);
return;
}
method = Extensions.SafeResolve(val);
if (method == null)
{
Log.Error($"Failed to resolve method '{((MemberReference)val).FullName}': {((MemberReference)c.Context.Method).FullName} at instruction {c.Next} ({c.Index})", "D:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Utils\\Extensions\\PatchExtensions.cs", "EmitSkipMethodCall", 42);
return;
}
}
int num = ((MethodReference)method).Parameters.Count + ((!method.IsStatic) ? 1 : 0);
bool flag = Extensions.Is((MemberReference)(object)((MethodReference)method).ReturnType, (MemberInfo)typeof(void));
ILLabel val2 = c.DefineLabel();
c.Emit(branchOpCode, (object)val2);
int index = c.Index;
c.Index = index + 1;
if (num > 0 || !flag)
{
ILLabel val3 = c.DefineLabel();
c.Emit(OpCodes.Br, (object)val3);
c.MarkLabel(val2);
for (int i = 0; i < num; i++)
{
c.Emit(OpCodes.Pop);
}
if (emitSkippedReturnValue != null)
{
emitSkippedReturnValue(c);
}
else if (!flag)
{
Log.Warning($"Skipped method ({((MemberReference)method).FullName}) is not void, emitting default value: {((MemberReference)c.Context.Method).FullName} at instruction {c.Next} ({c.Index})", "D:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Utils\\Extensions\\PatchExtensions.cs", "EmitSkipMethodCall", 74);
if (((MethodReference)method).ReturnType.IsValueType)
{
VariableDefinition val4 = c.Context.AddVariable(((MethodReference)method).ReturnType);
c.Emit(OpCodes.Ldloca, val4);
c.Emit(OpCodes.Initobj, ((MethodReference)method).ReturnType);
c.Emit(OpCodes.Ldloc, val4);
}
else
{
c.Emit(OpCodes.Ldnull);
}
}
c.MarkLabel(val3);
}
else
{
c.MarkLabel(val2);
}
}
public static bool TryFindParameter(this MethodReference method, Type type, string name, out ParameterDefinition parameter)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
if (type == null && string.IsNullOrEmpty(name))
{
Log.Error("Cannot find parameter for method " + ((MemberReference)method).FullName + ": Neither parameter type or name specified", "D:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Utils\\Extensions\\PatchExtensions.cs", "TryFindParameter", 103);
parameter = null;
return false;
}
Enumerator<ParameterDefinition> enumerator = method.Parameters.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
ParameterDefinition current = enumerator.Current;
if ((string.IsNullOrEmpty(name) || ((ParameterReference)current).Name == name) && (type == null || Extensions.Is((MemberReference)(object)((ParameterReference)current).ParameterType, (MemberInfo)type)))
{
parameter = current;
return true;
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
parameter = null;
return false;
}
public static bool TryFindParameter(this MethodReference method, string name, out ParameterDefinition parameter)
{
return method.TryFindParameter(null, name, out parameter);
}
public static bool TryFindParameter(this MethodReference method, Type type, out ParameterDefinition parameter)
{
return method.TryFindParameter(type, null, out parameter);
}
public static bool TryFindParameter<T>(this MethodReference method, string name, out ParameterDefinition parameter)
{
return method.TryFindParameter(typeof(T), name, out parameter);
}
public static bool TryFindParameter<T>(this MethodReference method, out ParameterDefinition parameter)
{
return method.TryFindParameter(typeof(T), null, out parameter);
}
public static VariableDefinition AddVariable(this ILContext context, TypeReference variableType)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
VariableDefinition val = new VariableDefinition(variableType);
context.Method.Body.Variables.Add(val);
return val;
}
public static VariableDefinition AddVariable(this ILContext context, Type variableType)
{
return context.AddVariable(context.Import(variableType));
}
public static VariableDefinition AddVariable<T>(this ILContext context)
{
return context.AddVariable(context.Import(typeof(T)));
}
public static void EmitStoreStack(this ILCursor cursor, IList<VariableDefinition> variables)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
if (cursor == null)
{
throw new ArgumentNullException("cursor");
}
if (variables == null)
{
throw new ArgumentNullException("variables");
}
if (variables.Count != 0)
{
for (int num = variables.Count - 1; num >= 1; num--)
{
cursor.Emit(OpCodes.Stloc, variables[num]);
}
cursor.Emit(OpCodes.Dup);
cursor.Emit(OpCodes.Stloc, variables[0]);
for (int i = 1; i < variables.Count; i++)
{
cursor.Emit(OpCodes.Ldloc, variables[i]);
}
}
}
}
}
namespace NoAllyAttackBlock.Patches
{
internal static class AttackCollisionHooks
{
[CompilerGenerated]
private static class <>O
{
public static hook_DefaultFilterCallbackImplementation <0>__BulletAttack_DefaultFilterCallbackImplementation;
}
[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
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;
}
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;
}
}
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_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)bodyObject) || hits == null || hits.Length == 0 || !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
{
[CompilerGenerated]
private static class <>O
{
public static Action <0>__onLoad;
public static Func<Instruction, bool> <1>__matchRaycastMethodCall;
public static Manipulator <2>__replaceRaycastManipulator;
public static Func<Vector3, Vector3, Ray> <3>__getRay;
public static <>F{00080080}<object, Ray, RaycastHit, float, int, QueryTriggerInteraction, bool, bool> <4>__tryReplaceRaycast;
}
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()
{
RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(onLoad));
}
private static void onLoad()
{
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Expected O, but got Unknown
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Expected O, but got Unknown
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Expected O, but got Unknown
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Expected O, but got Unknown
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
HashSet<Type> hashSet = new HashSet<Type>(EntityStateCatalog.stateIndexToType.Length);
for (int i = 0; i < EntityStateCatalog.stateIndexToType.Length; i++)
{
Type type = EntityStateCatalog.stateIndexToType[i];
while (type != null && typeof(EntityState).IsAssignableFrom(type) && hashSet.Add(type))
{
type = type.BaseType;
}
}
stopwatch.Restart();
int num = 0;
foreach (Type item in hashSet)
{
try
{
MethodInfo[] methods = item.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (MethodInfo methodInfo in methods)
{
ILHook val = null;
try
{
_ = methodInfo.DeclaringType;
if (methodInfo.IsGenericMethod || !MethodBaseExtensions.HasMethodBody((MethodBase)methodInfo))
{
continue;
}
DynamicMethodDefinition val2 = new DynamicMethodDefinition((MethodBase)methodInfo);
try
{
ILContext val3 = new ILContext(val2.Definition);
try
{
if (new ILCursor(val3).TryGotoNext(new Func<Instruction, bool>[1] { matchRaycastMethodCall }))
{
object obj = <>O.<2>__replaceRaycastManipulator;
if (obj == null)
{
Manipulator val4 = replaceRaycastManipulator;
<>O.<2>__replaceRaycastManipulator = val4;
obj = (object)val4;
}
val = new ILHook((MethodBase)methodInfo, (Manipulator)obj, new ILHookConfig
{
ManualApply = true
});
val.Apply();
}
}
finally
{
((IDisposable)val3)?.Dispose();
}
}
finally
{
((IDisposable)val2)?.Dispose();
}
goto IL_01e7;
}
catch (Exception ex)
{
Log.Warning("Failed to apply raycast hook to " + methodInfo.DeclaringType.FullName + "." + methodInfo.Name + " (" + item.Assembly.FullName + "): " + ex.Message, "D:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Patches\\CharacterRaycastPatches.cs", "onLoad", 80);
if (val != null)
{
val.Dispose();
}
val = null;
goto IL_01e7;
}
IL_01e7:
if (val != null)
{
num++;
}
}
}
catch (Exception ex2)
{
Log.Warning("Failed to scan type for raycast hooks: " + item.FullName + " (" + item.Assembly.FullName + "): " + ex2.Message, "D:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Patches\\CharacterRaycastPatches.cs", "onLoad", 94);
}
}
}
private static bool matchRaycastMethodCall(Instruction x)
{
return ILPatternMatchingExt.MatchCallOrCallvirt(x, typeof(Physics), "Raycast");
}
private static void replaceRaycastManipulator(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_0227: Unknown result type (might be due to invalid IL or missing references)
//IL_0235: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_0265: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_0277: 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_029c: Unknown result type (might be due to invalid IL or missing references)
//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
//IL_02be: Unknown result type (might be due to invalid IL or missing references)
//IL_02db: Unknown result type (might be due to invalid IL or missing references)
//IL_030f: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
ILVariablePool iLVariablePool = new ILVariablePool(il);
int num = 0;
while (val.TryGotoNext((MoveType)1, new Func<Instruction, bool>[1] { matchRaycastMethodCall }))
{
MethodReference val2 = (MethodReference)val.Next.Operand;
VariableDefinition val3 = null;
VariableDefinition val4 = null;
VariableDefinition val5 = null;
VariableDefinition val6 = null;
VariableDefinition val7 = null;
VariableDefinition val8 = null;
VariableDefinition val9 = null;
List<VariableDefinition> list = new List<VariableDefinition>();
List<VariableDefinition> list2 = new List<VariableDefinition>();
Enumerator<ParameterDefinition> enumerator = val2.Parameters.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
ParameterDefinition current = enumerator.Current;
TypeReference parameterType = ((ParameterReference)current).ParameterType;
string name = ((ParameterReference)current).Name;
VariableDefinition orCreate = iLVariablePool.GetOrCreate(parameterType);
if (Extensions.Is((MemberReference)(object)parameterType, (MemberInfo)typeof(Ray)))
{
val3 = orCreate;
}
else if (Extensions.Is((MemberReference)(object)parameterType, (MemberInfo)typeof(Vector3)))
{
if (string.Equals(name, "origin", StringComparison.OrdinalIgnoreCase))
{
val4 = orCreate;
}
else if (string.Equals(name, "direction", StringComparison.OrdinalIgnoreCase))
{
val5 = orCreate;
}
}
else if (Extensions.Is((MemberReference)(object)parameterType, (MemberInfo)typeof(RaycastHit).MakeByRefType()))
{
val6 = orCreate;
}
else if (Extensions.Is((MemberReference)(object)parameterType, (MemberInfo)typeof(float)))
{
if (string.Equals(name, "maxDistance", StringComparison.OrdinalIgnoreCase))
{
val7 = orCreate;
}
}
else if (Extensions.Is((MemberReference)(object)parameterType, (MemberInfo)typeof(int)))
{
if (string.Equals(name, "layerMask", StringComparison.OrdinalIgnoreCase))
{
val8 = orCreate;
}
}
else if (Extensions.Is((MemberReference)(object)parameterType, (MemberInfo)typeof(QueryTriggerInteraction)))
{
val9 = orCreate;
}
list2.Add(orCreate);
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
list.AddRange(list2);
val.EmitStoreStack(list2);
if (val6 == null)
{
val6 = iLVariablePool.GetOrCreate(typeof(RaycastHit).MakeByRefType());
list.Add(val6);
VariableDefinition orCreate2 = iLVariablePool.GetOrCreate<RaycastHit>();
list.Add(orCreate2);
val.Emit(OpCodes.Ldloca, orCreate2);
val.Emit(OpCodes.Stloc, val6);
}
VariableDefinition replacementRaycastResultVar = iLVariablePool.GetOrCreate<bool>();
list.Add(replacementRaycastResultVar);
val.Emit(OpCodes.Ldarg_0);
if (val3 != null)
{
val.Emit(OpCodes.Ldloc, val3);
}
else
{
val.Emit(OpCodes.Ldloc, val4);
val.Emit(OpCodes.Ldloc, val5);
val.EmitDelegate<Func<Vector3, Vector3, Ray>>((Func<Vector3, Vector3, Ray>)getRay);
}
val.Emit(OpCodes.Ldloc, val6);
if (val7 != null)
{
val.Emit(OpCodes.Ldloc, val7);
}
else
{
val.Emit(OpCodes.Ldc_R4, float.PositiveInfinity);
}
if (val8 != null)
{
val.Emit(OpCodes.Ldloc, val8);
}
else
{
val.Emit(OpCodes.Ldc_I4, -5);
}
if (val9 != null)
{
val.Emit(OpCodes.Ldloc, val9);
}
else
{
val.Emit(OpCodes.Ldc_I4, 0);
}
val.Emit(OpCodes.Ldloca, replacementRaycastResultVar);
val.EmitDelegate<<>F{00080080}<object, Ray, RaycastHit, float, int, QueryTriggerInteraction, bool, bool>>((<>F{00080080}<object, Ray, RaycastHit, float, int, QueryTriggerInteraction, bool, bool>)tryReplaceRaycast);
val.EmitSkipMethodCall(OpCodes.Brtrue, delegate(ILCursor c)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
c.Emit(OpCodes.Ldloc, replacementRaycastResultVar);
}, null);
foreach (VariableDefinition item in list)
{
iLVariablePool.Return(item);
}
num++;
val.SearchTarget = (SearchTarget)1;
}
if (num == 0)
{
Log.Warning("Found 0 patch locations in " + ((MemberReference)il.Method).FullName, "D:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Patches\\CharacterRaycastPatches.cs", "replaceRaycastManipulator", 294);
}
static Ray getRay(Vector3 origin, Vector3 direction)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return new Ray(origin, direction);
}
static bool tryReplaceRaycast(object instance, Ray ray, out 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_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: 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)
if ((layerMask & LayerMask.op_Implicit(_layersToPatch)) == 0)
{
hitInfo = default(RaycastHit);
raycastResult = false;
return false;
}
if (instance == null)
{
hitInfo = default(RaycastHit);
raycastResult = false;
return false;
}
EntityState val10 = (EntityState)((instance is EntityState) ? instance : null);
if (val10 == null)
{
Log.Error("Instance type " + instance.GetType().FullName + " is not implemented", "D:\\Git\\RoR2\\NoAllyAttackBlock\\NoAllyAttackBlock\\Patches\\CharacterRaycastPatches.cs", "replaceRaycastManipulator", 267);
hitInfo = default(RaycastHit);
raycastResult = false;
return false;
}
CharacterBody characterBody = val10.characterBody;
GameObject val11 = (Object.op_Implicit((Object)(object)characterBody) ? ((Component)characterBody).gameObject : null);
raycastResult = Util.CharacterRaycast(val11, ray, ref hitInfo, maxDistance, LayerMask.op_Implicit(layerMask), queryTriggerInteraction);
return true;
}
}
}
}