using System;
using System.Collections;
using System.Diagnostics;
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.Logging;
using HG;
using IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using R2API.AutoVersionGen;
using RoR2;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("R2API.ProcType")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c5f864efda9bc94ca1107a270818064876a74bf5")]
[assembly: AssemblyProduct("R2API.ProcType")]
[assembly: AssemblyTitle("R2API.ProcType")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullAttribute : Attribute
{
public string[] Members { get; }
public MemberNotNullAttribute(string member)
{
Members = new string[1] { member };
}
public MemberNotNullAttribute(params string[] members)
{
Members = members;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullWhenAttribute : Attribute
{
public bool ReturnValue { get; }
public string[] Members { get; }
public MemberNotNullWhenAttribute(bool returnValue, string member)
{
ReturnValue = returnValue;
Members = new string[1] { member };
}
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
{
ReturnValue = returnValue;
Members = members;
}
}
}
namespace R2API
{
public enum ModdedProcType
{
Invalid = -1
}
[AutoVersion]
public static class ProcTypeAPI
{
private delegate bool ProcChainMask_AppendToStringBuilder_Delegate(ref ProcChainMask procChainMask, StringBuilder stringBuilder, bool flag);
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__ProcChainMask_AppendToStringBuilder;
public static hook_Write_NetworkWriter_ProcChainMask <1>__NetworkExtensions_Write_NetworkWriter_ProcChainMask;
public static hook_ReadProcChainMask <2>__NetworkExtensions_ReadProcChainMask;
public static hook_GetHashCode <3>__ProcChainMask_GetHashCode;
public static hook_Equals_ProcChainMask <4>__ProcChainMask_Equals_ProcChainMask;
}
public const string PluginGUID = "com.bepis.r2api.proctype";
public const string PluginName = "R2API.ProcType";
private static bool _hookEnabled;
private static int _moddedProcTypeCount;
private static int byteCount;
private static byte[] buffer;
public const string PluginVersion = "1.0.0";
public static int ModdedProcTypeCount
{
get
{
return _moddedProcTypeCount;
}
private set
{
if (_moddedProcTypeCount != value)
{
_moddedProcTypeCount = value;
if (byteCount != (byteCount = value + 7 >> 3))
{
buffer = new byte[byteCount];
}
}
}
}
public static ModdedProcType ReserveProcType()
{
SetHooks();
if (ModdedProcTypeCount == int.MaxValue)
{
throw new IndexOutOfRangeException($"Reached the ModdedProcType limit ({int.MaxValue})! Please contact R2API developers to increase the limit");
}
return (ModdedProcType)(ModdedProcTypeCount++);
}
public static void AddModdedProc(this ref ProcChainMask procChainMask, ModdedProcType procType)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
if (procType <= ModdedProcType.Invalid || (int)procType >= ModdedProcTypeCount)
{
throw new ArgumentOutOfRangeException("procType");
}
SetHooks();
byte[] moddedMask = ProcTypeInterop.GetModdedMask(procChainMask);
int num = (int)procType >> 3;
byte[] array;
if (moddedMask == null)
{
array = new byte[num + 1];
array[num] = GetMaskingBit(num, procType);
}
else if (moddedMask.Length > num)
{
byte b = (byte)(moddedMask[num] | GetMaskingBit(num, procType));
if (b == moddedMask[num])
{
return;
}
array = ArrayUtils.Clone<byte>(moddedMask);
array[num] = b;
}
else
{
array = moddedMask;
Array.Resize(ref array, num + 1);
array[num] = GetMaskingBit(num, procType);
}
ProcTypeInterop.SetModdedMask(ref procChainMask, array);
}
public static void RemoveModdedProc(this ref ProcChainMask procChainMask, ModdedProcType procType)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
if (procType <= ModdedProcType.Invalid || (int)procType >= ModdedProcTypeCount)
{
throw new ArgumentOutOfRangeException("procType");
}
SetHooks();
byte[] array = ProcTypeInterop.GetModdedMask(procChainMask);
if (array == null)
{
return;
}
int num = (int)procType >> 3;
if (array.Length <= num)
{
return;
}
byte b = (byte)(array[num] & ~GetMaskingBit(num, procType));
if (b == array[num])
{
return;
}
if (b == 0 && array.Length == num + 1)
{
int num2 = 0;
for (int num3 = array.Length - 2; num3 >= 0; num3--)
{
if (array[num3] != 0)
{
num2 = num3 + 1;
break;
}
}
if (num2 == 0)
{
array = null;
}
else
{
Array.Resize(ref array, num2);
}
}
else
{
array = ArrayUtils.Clone<byte>(array);
array[num] = b;
}
ProcTypeInterop.SetModdedMask(ref procChainMask, array);
}
public static bool HasModdedProc(this ProcChainMask procChainMask, ModdedProcType procType)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
if (procType <= ModdedProcType.Invalid || (int)procType >= ModdedProcTypeCount)
{
throw new ArgumentOutOfRangeException("procType");
}
byte[] moddedMask = ProcTypeInterop.GetModdedMask(procChainMask);
if (moddedMask == null)
{
return false;
}
int num = (int)procType >> 3;
if (moddedMask.Length > num)
{
return (moddedMask[num] & GetMaskingBit(num, procType)) > 0;
}
return false;
}
public static BitArray GetModdedMask(ProcChainMask procChainMask)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
BitArray moddedMaskRaw = GetModdedMaskRaw(procChainMask);
moddedMaskRaw.Length = ModdedProcTypeCount;
return moddedMaskRaw;
}
public static void GetModdedMask(ProcChainMask procChainMask, BitArray dest)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
GetModdedMaskRaw(procChainMask, dest);
dest.Length = ModdedProcTypeCount;
}
public static BitArray GetModdedMaskRaw(ProcChainMask procChainMask)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
SetHooks();
byte[] moddedMask = ProcTypeInterop.GetModdedMask(procChainMask);
if (moddedMask == null)
{
return new BitArray(0);
}
return new BitArray(moddedMask);
}
public static void GetModdedMaskRaw(ProcChainMask procChainMask, BitArray dest)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
if (dest == null)
{
throw new ArgumentNullException("dest");
}
SetHooks();
byte[] moddedMask = ProcTypeInterop.GetModdedMask(procChainMask);
if (moddedMask != null)
{
dest.Length = moddedMask.Length << 3;
for (int i = 0; i < moddedMask.Length; i++)
{
byte b = moddedMask[i];
int num = i << 3;
dest[num] = (b & 1) > 0;
dest[num + 1] = (b & 2) > 0;
dest[num + 2] = (b & 4) > 0;
dest[num + 3] = (b & 8) > 0;
dest[num + 4] = (b & 0x10) > 0;
dest[num + 5] = (b & 0x20) > 0;
dest[num + 6] = (b & 0x40) > 0;
dest[num + 7] = (b & 0x80) > 0;
}
}
else
{
dest.Length = 0;
}
}
public static void SetModdedMask(ref ProcChainMask procChainMask, BitArray value)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
SetHooks();
int num = 0;
for (int num2 = value.Length - 1; num2 >= 0; num2--)
{
if (value[num2])
{
num = num2 + 7 >> 3;
break;
}
}
if (num > 0)
{
byte[] array = new byte[num];
value.CopyTo(buffer, 0);
Array.Copy(buffer, 0, array, 0, num);
ProcTypeInterop.SetModdedMask(ref procChainMask, array);
}
else
{
ProcTypeInterop.SetModdedMask(ref procChainMask, (byte[])null);
}
}
internal static void SetHooks()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Expected O, but got Unknown
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Expected O, but got Unknown
if (!_hookEnabled)
{
object obj = <>O.<0>__ProcChainMask_AppendToStringBuilder;
if (obj == null)
{
Manipulator val = ProcChainMask_AppendToStringBuilder;
<>O.<0>__ProcChainMask_AppendToStringBuilder = val;
obj = (object)val;
}
ProcChainMask.AppendToStringBuilder += (Manipulator)obj;
object obj2 = <>O.<1>__NetworkExtensions_Write_NetworkWriter_ProcChainMask;
if (obj2 == null)
{
hook_Write_NetworkWriter_ProcChainMask val2 = NetworkExtensions_Write_NetworkWriter_ProcChainMask;
<>O.<1>__NetworkExtensions_Write_NetworkWriter_ProcChainMask = val2;
obj2 = (object)val2;
}
NetworkExtensions.Write_NetworkWriter_ProcChainMask += (hook_Write_NetworkWriter_ProcChainMask)obj2;
object obj3 = <>O.<2>__NetworkExtensions_ReadProcChainMask;
if (obj3 == null)
{
hook_ReadProcChainMask val3 = NetworkExtensions_ReadProcChainMask;
<>O.<2>__NetworkExtensions_ReadProcChainMask = val3;
obj3 = (object)val3;
}
NetworkExtensions.ReadProcChainMask += (hook_ReadProcChainMask)obj3;
object obj4 = <>O.<3>__ProcChainMask_GetHashCode;
if (obj4 == null)
{
hook_GetHashCode val4 = ProcChainMask_GetHashCode;
<>O.<3>__ProcChainMask_GetHashCode = val4;
obj4 = (object)val4;
}
ProcChainMask.GetHashCode += (hook_GetHashCode)obj4;
object obj5 = <>O.<4>__ProcChainMask_Equals_ProcChainMask;
if (obj5 == null)
{
hook_Equals_ProcChainMask val5 = ProcChainMask_Equals_ProcChainMask;
<>O.<4>__ProcChainMask_Equals_ProcChainMask = val5;
obj5 = (object)val5;
}
ProcChainMask.Equals_ProcChainMask += (hook_Equals_ProcChainMask)obj5;
_hookEnabled = true;
}
}
internal static void UnsetHooks()
{
//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
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Expected O, but got Unknown
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Expected O, but got Unknown
object obj = <>O.<0>__ProcChainMask_AppendToStringBuilder;
if (obj == null)
{
Manipulator val = ProcChainMask_AppendToStringBuilder;
<>O.<0>__ProcChainMask_AppendToStringBuilder = val;
obj = (object)val;
}
ProcChainMask.AppendToStringBuilder -= (Manipulator)obj;
object obj2 = <>O.<1>__NetworkExtensions_Write_NetworkWriter_ProcChainMask;
if (obj2 == null)
{
hook_Write_NetworkWriter_ProcChainMask val2 = NetworkExtensions_Write_NetworkWriter_ProcChainMask;
<>O.<1>__NetworkExtensions_Write_NetworkWriter_ProcChainMask = val2;
obj2 = (object)val2;
}
NetworkExtensions.Write_NetworkWriter_ProcChainMask -= (hook_Write_NetworkWriter_ProcChainMask)obj2;
object obj3 = <>O.<2>__NetworkExtensions_ReadProcChainMask;
if (obj3 == null)
{
hook_ReadProcChainMask val3 = NetworkExtensions_ReadProcChainMask;
<>O.<2>__NetworkExtensions_ReadProcChainMask = val3;
obj3 = (object)val3;
}
NetworkExtensions.ReadProcChainMask -= (hook_ReadProcChainMask)obj3;
object obj4 = <>O.<3>__ProcChainMask_GetHashCode;
if (obj4 == null)
{
hook_GetHashCode val4 = ProcChainMask_GetHashCode;
<>O.<3>__ProcChainMask_GetHashCode = val4;
obj4 = (object)val4;
}
ProcChainMask.GetHashCode -= (hook_GetHashCode)obj4;
object obj5 = <>O.<4>__ProcChainMask_Equals_ProcChainMask;
if (obj5 == null)
{
hook_Equals_ProcChainMask val5 = ProcChainMask_Equals_ProcChainMask;
<>O.<4>__ProcChainMask_Equals_ProcChainMask = val5;
obj5 = (object)val5;
}
ProcChainMask.Equals_ProcChainMask -= (hook_Equals_ProcChainMask)obj5;
_hookEnabled = false;
}
private static void ProcChainMask_AppendToStringBuilder(ILContext il)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected O, but got Unknown
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
int locFlagIndex = -1;
ILCursor val = new ILCursor(il);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
{
(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref locFlagIndex)
}) && val.TryGotoNext((MoveType)1, new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1),
(Instruction x) => ILPatternMatchingExt.MatchLdstr(x, ")"),
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<StringBuilder>(x, "Append")
}))
{
val.Emit(OpCodes.Ldarg, 0);
val.Emit(OpCodes.Ldarg, 1);
val.Emit(OpCodes.Ldloc, locFlagIndex);
val.EmitDelegate<ProcChainMask_AppendToStringBuilder_Delegate>((ProcChainMask_AppendToStringBuilder_Delegate)delegate(ref ProcChainMask procChainMask, StringBuilder stringBuilder, bool flag)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
byte[] moddedMask = ProcTypeInterop.GetModdedMask(procChainMask);
if (moddedMask != null)
{
for (int i = 0; i < moddedMask.Length; i++)
{
for (int j = 0; j < 8; j++)
{
if ((moddedMask[i] & (1 << j)) > 0)
{
if (flag)
{
stringBuilder.Append("|");
}
stringBuilder.Append(string.Format("({0}){1}", "ModdedProcType", (i << 3) + j));
flag = true;
}
}
}
}
return flag;
});
val.Emit(OpCodes.Stloc, locFlagIndex);
}
else
{
ProcTypePlugin.Logger.LogError((object)"ProcTypeAPI.ProcChainMask_AppendToStringBuilder IL match failed.");
}
}
private static void NetworkExtensions_Write_NetworkWriter_ProcChainMask(orig_Write_NetworkWriter_ProcChainMask orig, NetworkWriter writer, ProcChainMask procChainMask)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
orig.Invoke(writer, procChainMask);
writer.NetworkWriteModdedMask(ProcTypeInterop.GetModdedMask(procChainMask));
}
private static ProcChainMask NetworkExtensions_ReadProcChainMask(orig_ReadProcChainMask orig, NetworkReader reader)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: 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)
ProcChainMask result = orig.Invoke(reader);
ProcTypeInterop.SetModdedMask(ref result, NetworkReadModdedMask(reader));
return result;
}
private static int ProcChainMask_GetHashCode(orig_GetHashCode orig, ref ProcChainMask self)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
return (orig.Invoke(ref self) * 397) ^ ModdedMaskHashCode(ProcTypeInterop.GetModdedMask(self));
}
private static bool ProcChainMask_Equals_ProcChainMask(orig_Equals_ProcChainMask orig, ref ProcChainMask self, ProcChainMask other)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: 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)
if (orig.Invoke(ref self, other))
{
return ModdedMaskEquals(ProcTypeInterop.GetModdedMask(self), ProcTypeInterop.GetModdedMask(other));
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static byte GetMaskingBit(int maskIndex, ModdedProcType procType)
{
return (byte)(1 << (int)(procType - (maskIndex << 3)));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void NetworkWriteModdedMask(this NetworkWriter writer, byte[] mask)
{
int num = ((mask != null) ? mask.Length : 0);
if (ModdedProcTypeCount <= 255)
{
writer.Write((byte)num);
}
else if (ModdedProcTypeCount <= 65535)
{
writer.Write((ushort)num);
}
else
{
writer.Write(num);
}
if (num != 0)
{
writer.Write(mask, num);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static byte[] NetworkReadModdedMask(NetworkReader reader)
{
int moddedProcTypeCount = ModdedProcTypeCount;
int num = ((moddedProcTypeCount <= 255) ? reader.ReadByte() : ((moddedProcTypeCount > 65535) ? reader.ReadInt32() : reader.ReadUInt16()));
int num2 = num;
if (num2 <= 0)
{
return null;
}
return reader.ReadBytes(num2);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int ModdedMaskHashCode(byte[] mask)
{
int num = 0;
if (mask != null)
{
for (int i = 0; i < mask.Length; i++)
{
num = HashCode.Combine(num, mask[i]);
}
}
return num;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool ModdedMaskEquals(byte[] a, byte[] b)
{
return ArrayUtils.SequenceEquals<byte>(a ?? Array.Empty<byte>(), b ?? Array.Empty<byte>());
}
}
[BepInPlugin("com.bepis.r2api.proctype", "R2API.ProcType", "1.0.0")]
public sealed class ProcTypePlugin : BaseUnityPlugin
{
internal static ManualLogSource Logger { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
}
private void OnDestroy()
{
ProcTypeAPI.UnsetHooks();
}
}
}
namespace R2API.AutoVersionGen
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal class AutoVersionAttribute : Attribute
{
}
}