using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.IO.Compression; using System.IO.MemoryMappedFiles; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using Il2CppInterop.Common; using Il2CppInterop.Common.Attributes; using Il2CppInterop.Common.Host; using Il2CppInterop.Common.Maps; using Il2CppInterop.Common.XrefScans; using Il2CppInterop.Generator.Contexts; using Il2CppInterop.Generator.Extensions; using Il2CppInterop.Generator.MetadataAccess; using Il2CppInterop.Generator.Passes; using Il2CppInterop.Generator.Runners; using Il2CppInterop.Generator.Utils; using Il2CppInterop.Generator.XrefScans; using Microsoft.CodeAnalysis; using Microsoft.Extensions.Logging; using Mono.Cecil; using Mono.Cecil.Cil; using Mono.Collections.Generic; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")] [assembly: AssemblyCompany("knah, BepInEx et al.")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Library for generating assemblies and metadata for calling Il2Cpp functions from .NET")] [assembly: AssemblyFileVersion("1.4.6.0")] [assembly: AssemblyInformationalVersion("1.4.6-ci.389")] [assembly: AssemblyProduct("Il2CppInterop.Generator")] [assembly: AssemblyTitle("Il2CppInterop.Generator")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.4.6.0")] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class IsUnmanagedAttribute : Attribute { } [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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NativeIntegerAttribute : Attribute { public readonly bool[] TransformFlags; public NativeIntegerAttribute() { TransformFlags = new bool[1] { true }; } public NativeIntegerAttribute(bool[] P_0) { TransformFlags = P_0; } } } namespace Il2CppInterop.Generator { public class GeneratorOptions { public enum PrefixMode { OptIn, OptOut } public List? Source { get; set; } public string? OutputDir { get; set; } public string? UnityBaseLibsDir { get; set; } public List AdditionalAssembliesBlacklist { get; } = new List(); public int TypeDeobfuscationCharsPerUniquifier { get; set; } = 2; public int TypeDeobfuscationMaxUniquifiers { get; set; } = 10; public string? GameAssemblyPath { get; set; } public bool Verbose { get; set; } public bool NoXrefCache { get; set; } public Regex? ObfuscatedNamesRegex { get; set; } public Dictionary RenameMap { get; } = new Dictionary(); public bool PassthroughNames { get; set; } public bool Parallel { get; set; } = true; public PrefixMode Il2CppPrefixMode { get; set; } public HashSet NamespacesAndAssembliesToPrefix { get; } = new HashSet { "System", "mscorlib", "Microsoft", "Mono", "I18N" }; public HashSet NamespacesAndAssembliesToNotPrefix { get; } = new HashSet { "Assembly-CSharp", "Unity" }; public List DeobfuscationGenerationAssemblies { get; } = new List(); public string? DeobfuscationNewAssembliesPath { get; set; } public void ReadRenameMap(string fileName) { using FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); ReadRenameMap(fileStream, fileName.EndsWith(".gz")); } public void ReadRenameMap(Stream fileStream, bool isGzip) { if (isGzip) { using (GZipStream fileStream2 = new GZipStream(fileStream, CompressionMode.Decompress, leaveOpen: true)) { ReadRenameMap(fileStream2, isGzip: false); return; } } using StreamReader streamReader = new StreamReader(fileStream, Encoding.UTF8, detectEncodingFromByteOrderMarks: false, 65536, leaveOpen: true); while (!streamReader.EndOfStream) { string text = streamReader.ReadLine(); if (!string.IsNullOrEmpty(text) && !text.StartsWith("#")) { string[] array = text.Split(';'); if (array.Length >= 2) { RenameMap[array[0]] = array[1]; } } } } } public sealed class Il2CppInteropGenerator : BaseHost { private readonly List _runners = new List(); private GeneratorOptions Options { get; init; } private Il2CppInteropGenerator() { } public static Il2CppInteropGenerator Create(GeneratorOptions options) { Il2CppInteropGenerator obj = new Il2CppInteropGenerator { Options = options }; XrefScannerManagerExtensions.AddXrefScanner(obj); return obj; } public override void Start() { ((BaseHost)this).Start(); foreach (IRunner runner in _runners) { Logger.Instance.LogTrace("Running {RunnerName}", runner.GetType().Name); runner.Run(Options); } } public override void Dispose() { foreach (IRunner runner in _runners) { runner.Dispose(); } _runners.Clear(); ((BaseHost)this).Dispose(); } public void Run() { ((BaseHost)this).Start(); ((BaseHost)this).Dispose(); } internal Il2CppInteropGenerator AddRunner() where T : IRunner, new() { _runners.Add(new T()); return this; } } } namespace Il2CppInterop.Generator.XrefScans { internal class XrefScanImpl : IXrefScannerImpl { public (InitMetadataForMethod, IntPtr)? GetMetadataResolver() { return null; } public bool XrefGlobalClassFilter(IntPtr movTarget) { return false; } } } namespace Il2CppInterop.Generator.Utils { internal static class CorlibReferences { public static void RewriteReferenceToMscorlib(AssemblyNameReference assemblyNameReference) { assemblyNameReference.Name = "mscorlib"; assemblyNameReference.Version = new Version(4, 0, 0, 0); assemblyNameReference.PublicKeyToken = new byte[8] { 183, 122, 92, 86, 25, 52, 224, 137 }; assemblyNameReference.Culture = ""; } public static TypeReference ImportCorlibReference(this ModuleDefinition module, string @namespace, string type) { return module.ImportReference(typeof(string).Assembly.GetType(@namespace + "." + type)); } public static TypeReference Void(this ModuleDefinition module) { return module.ImportReference(typeof(void)); } public static TypeReference Bool(this ModuleDefinition module) { return module.ImportReference(typeof(bool)); } public static TypeReference IntPtr(this ModuleDefinition module) { return module.ImportReference(typeof(IntPtr)); } public static TypeReference String(this ModuleDefinition module) { return module.ImportReference(typeof(string)); } public static TypeReference SByte(this ModuleDefinition module) { return module.ImportReference(typeof(sbyte)); } public static TypeReference Byte(this ModuleDefinition module) { return module.ImportReference(typeof(byte)); } public static TypeReference Short(this ModuleDefinition module) { return module.ImportReference(typeof(short)); } public static TypeReference Int(this ModuleDefinition module) { return module.ImportReference(typeof(int)); } public static TypeReference Long(this ModuleDefinition module) { return module.ImportReference(typeof(long)); } public static TypeReference UShort(this ModuleDefinition module) { return module.ImportReference(typeof(ushort)); } public static TypeReference UInt(this ModuleDefinition module) { return module.ImportReference(typeof(uint)); } public static TypeReference ULong(this ModuleDefinition module) { return module.ImportReference(typeof(ulong)); } public static TypeReference Float(this ModuleDefinition module) { return module.ImportReference(typeof(float)); } public static TypeReference Double(this ModuleDefinition module) { return module.ImportReference(typeof(double)); } public static TypeReference Char(this ModuleDefinition module) { return module.ImportReference(typeof(char)); } public static TypeReference Type(this ModuleDefinition module) { return module.ImportReference(typeof(Type)); } public static TypeReference Object(this ModuleDefinition module) { return module.ImportReference(typeof(object)); } public static TypeReference Enum(this ModuleDefinition module) { return module.ImportReference(typeof(Enum)); } public static TypeReference ValueType(this ModuleDefinition module) { return module.ImportReference(typeof(ValueType)); } public static TypeReference Delegate(this ModuleDefinition module) { return module.ImportReference(typeof(Delegate)); } public static TypeReference MulticastDelegate(this ModuleDefinition module) { return module.ImportReference(typeof(MulticastDelegate)); } public static TypeReference DefaultMemberAttribute(this ModuleDefinition module) { return module.ImportReference(typeof(DefaultMemberAttribute)); } public static TypeReference NotSupportedException(this ModuleDefinition module) { return module.ImportReference(typeof(NotSupportedException)); } public static TypeReference FlagsAttribute(this ModuleDefinition module) { return module.ImportReference(typeof(FlagsAttribute)); } public static TypeReference ObsoleteAttribute(this ModuleDefinition module) { return module.ImportReference(typeof(ObsoleteAttribute)); } public static TypeReference Attribute(this ModuleDefinition module) { return module.ImportReference(typeof(Attribute)); } public static TypeReference RuntimeTypeHandle(this ModuleDefinition module) { return module.ImportReference(typeof(RuntimeTypeHandle)); } public static TypeReference ExtensionAttribute(this ModuleDefinition module) { return module.ImportReference(typeof(ExtensionAttribute)); } public static TypeReference ParamArrayAttribute(this ModuleDefinition module) { return module.ImportReference(typeof(ParamArrayAttribute)); } public static TypeReference Action(this ModuleDefinition module, int n = 0) { return (TypeReference)(n switch { 0 => module.ImportCorlibReference("System", "Action"), 1 => module.ImportCorlibReference("System", "Action`1"), _ => module.ImportCorlibReference("System", $"Action`{n}"), }); } public static TypeReference Func(this ModuleDefinition module, int n = 0) { return (TypeReference)(n switch { 0 => module.ImportCorlibReference("System", "Func`1"), 1 => module.ImportCorlibReference("System", "Func`2"), _ => module.ImportCorlibReference("System", $"Func`{n}"), }); } public static MethodReference TypeGetTypeFromHandle(this ModuleDefinition module) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_0030: Expected O, but got Unknown //IL_0031: Expected O, but got Unknown TypeReference val = module.Type(); MethodReference val2 = new MethodReference("GetTypeFromHandle", val, val) { HasThis = false }; val2.Parameters.Add(new ParameterDefinition(module.RuntimeTypeHandle())); return val2; } public static MethodReference TypeGetIsValueType(this ModuleDefinition module) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown TypeReference val = module.Type(); return new MethodReference("get_IsValueType", module.Bool(), val) { HasThis = true }; } public static MethodReference TypeGetFullName(this ModuleDefinition module) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown TypeReference val = module.Type(); return new MethodReference("get_FullName", module.String(), val) { HasThis = true }; } public static MethodReference StringEquals(this ModuleDefinition module) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown //IL_004a: Expected O, but got Unknown MethodReference val = new MethodReference("Equals", module.Bool(), module.String()) { HasThis = false }; val.Parameters.Add(new ParameterDefinition(module.String())); val.Parameters.Add(new ParameterDefinition(module.String())); return val; } public static MethodReference ExtensionAttributeCtor(this ModuleDefinition module) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown return new MethodReference(".ctor", module.Void(), module.ExtensionAttribute()) { HasThis = true }; } public static MethodReference ParamArrayAttributeCtor(this ModuleDefinition module) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown return new MethodReference(".ctor", module.Void(), module.ParamArrayAttribute()) { HasThis = true }; } public static MethodReference FlagsAttributeCtor(this ModuleDefinition module) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown return new MethodReference(".ctor", module.Void(), module.FlagsAttribute()) { HasThis = true }; } public static MethodReference NotSupportedExceptionCtor(this ModuleDefinition module) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0034: Expected O, but got Unknown MethodReference val = new MethodReference(".ctor", module.Void(), module.NotSupportedException()) { HasThis = true }; val.Parameters.Add(new ParameterDefinition(module.String())); return val; } public static MethodReference ObsoleteAttributeCtor(this ModuleDefinition module) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0034: Expected O, but got Unknown MethodReference val = new MethodReference(".ctor", module.Void(), module.ObsoleteAttribute()) { HasThis = true }; val.Parameters.Add(new ParameterDefinition(module.String())); return val; } } internal static class FieldAccessorGenerator { public static void MakeGetter(FieldDefinition field, FieldRewriteContext fieldContext, PropertyDefinition property, RuntimeAssemblyReferences imports) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: 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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Expected O, but got Unknown //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Unknown result type (might be due to invalid IL or missing references) //IL_0295: 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_0081: Expected O, but got Unknown //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Expected O, but got Unknown //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Expected O, but got Unknown //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) MethodDefinition val = new MethodDefinition("get_" + ((MemberReference)property).Name, (MethodAttributes)(Field2MethodAttrs(field.Attributes) | 0x800 | 0x80), ((PropertyReference)property).PropertyType); ILProcessor iLProcessor = val.Body.GetILProcessor(); property.DeclaringType.Methods.Add(val); if (field.IsStatic) { VariableDefinition val2 = new VariableDefinition(((PropertyReference)property).PropertyType.IsValueType ? ((PropertyReference)property).PropertyType : imports.Module.IntPtr()); val.Body.Variables.Add(val2); bool flag = false; if (((FieldReference)field).FieldType.IsValueType && !((PropertyReference)property).PropertyType.IsValueType) { GenericInstanceType val3 = new GenericInstanceType(imports.Il2CppClassPointerStore); val3.GenericArguments.Add(((PropertyReference)property).PropertyType); TypeReference val4 = ((MemberReference)property.DeclaringType).Module.ImportReference((TypeReference)(object)val3); iLProcessor.Emit(OpCodes.Ldsfld, new FieldReference("NativeClassPtr", imports.Module.IntPtr(), val4)); iLProcessor.Emit(OpCodes.Ldc_I4, 0); iLProcessor.Emit(OpCodes.Conv_U); iLProcessor.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_class_value_size.Value); iLProcessor.Emit(OpCodes.Conv_U); iLProcessor.Emit(OpCodes.Localloc); iLProcessor.Emit(OpCodes.Stloc, val2); flag = true; } iLProcessor.Emit(OpCodes.Ldsfld, fieldContext.PointerField); if (flag) { iLProcessor.Emit(OpCodes.Ldloc, val2); } else { iLProcessor.Emit(OpCodes.Ldloca_S, val2); } iLProcessor.Emit(OpCodes.Conv_U); iLProcessor.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_field_static_get_value.Value); if (((PropertyReference)property).PropertyType.IsValueType) { iLProcessor.Emit(OpCodes.Ldloc, val2); iLProcessor.Emit(OpCodes.Ret); property.GetMethod = val; return; } } else { VariableDefinition val5 = new VariableDefinition(imports.Module.IntPtr()); val.Body.Variables.Add(val5); iLProcessor.EmitObjectToPointer((TypeReference)(object)fieldContext.DeclaringType.OriginalType, (TypeReference)(object)fieldContext.DeclaringType.NewType, fieldContext.DeclaringType, 0, valueTypeArgument0IsAPointer: false, allowNullable: false, unboxNonBlittableType: false, unboxNonBlittableGeneric: false, out VariableDefinition _); iLProcessor.Emit(OpCodes.Ldsfld, fieldContext.PointerField); iLProcessor.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_field_get_offset.Value); iLProcessor.Emit(OpCodes.Add); iLProcessor.Emit(OpCodes.Stloc_0); } iLProcessor.EmitPointerToObject(((FieldReference)fieldContext.OriginalField).FieldType, ((PropertyReference)property).PropertyType, fieldContext.DeclaringType, iLProcessor.Create(OpCodes.Ldloc_0), !field.IsStatic, unboxValueType: false); iLProcessor.Emit(OpCodes.Ret); property.GetMethod = val; } public static void MakeSetter(FieldDefinition field, FieldRewriteContext fieldContext, PropertyDefinition property, RuntimeAssemblyReferences imports) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) MethodDefinition val = new MethodDefinition("set_" + ((MemberReference)property).Name, (MethodAttributes)(Field2MethodAttrs(field.Attributes) | 0x800 | 0x80), imports.Module.Void()); ((MethodReference)val).Parameters.Add(new ParameterDefinition(((PropertyReference)property).PropertyType)); property.DeclaringType.Methods.Add(val); ILProcessor iLProcessor = val.Body.GetILProcessor(); VariableDefinition refVariable; if (field.IsStatic) { iLProcessor.Emit(OpCodes.Ldsfld, fieldContext.PointerField); iLProcessor.EmitObjectToPointer(((FieldReference)field).FieldType, ((PropertyReference)property).PropertyType, fieldContext.DeclaringType, 0, valueTypeArgument0IsAPointer: false, allowNullable: true, unboxNonBlittableType: true, unboxNonBlittableGeneric: true, out refVariable); iLProcessor.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_field_static_set_value.Value); } else { iLProcessor.EmitObjectToPointer((TypeReference)(object)fieldContext.DeclaringType.OriginalType, (TypeReference)(object)fieldContext.DeclaringType.NewType, fieldContext.DeclaringType, 0, valueTypeArgument0IsAPointer: false, allowNullable: false, unboxNonBlittableType: false, unboxNonBlittableGeneric: false, out refVariable); iLProcessor.Emit(OpCodes.Dup); iLProcessor.Emit(OpCodes.Ldsfld, fieldContext.PointerField); iLProcessor.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_field_get_offset.Value); iLProcessor.Emit(OpCodes.Add); iLProcessor.EmitObjectStore(((FieldReference)field).FieldType, ((PropertyReference)property).PropertyType, fieldContext.DeclaringType, 1); } iLProcessor.Emit(OpCodes.Ret); property.SetMethod = val; } private static MethodAttributes Field2MethodAttrs(FieldAttributes fieldAttributes) { //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) if ((fieldAttributes & 0x10) == 0) { return (MethodAttributes)6; } return (MethodAttributes)22; } } public class Memoize { private readonly Dictionary _cache = new Dictionary(); private readonly Func _func; public Memoize(Func func) { _func = func; } public TResult Get(TParam param) { if (_cache.TryGetValue(param.GetHashCode(), out var value)) { return value; } value = _func(param); _cache.Add(param.GetHashCode(), value); return value; } } public class RuntimeAssemblyReferences { private readonly Dictionary allTypes = new Dictionary(); private readonly RewriteGlobalContext globalCtx; public ModuleDefinition Module { get; } public Memoize Il2CppRefrenceArrayctor { get; private set; } public Lazy Il2CppStringArrayctor { get; private set; } public Memoize Il2CppStructArrayctor { get; private set; } public Memoize Il2CppRefrenceArrayctor_size { get; private set; } public Lazy Il2CppStringArrayctor_size { get; private set; } public Memoize Il2CppStructArrayctor_size { get; private set; } public Lazy IL2CPP_Il2CppObjectBaseToPtr { get; private set; } public Lazy IL2CPP_Il2CppObjectBaseToPtrNotNull { get; private set; } public Lazy IL2CPP_Il2CppStringToManaged { get; private set; } public Lazy IL2CPP_ManagedStringToIl2Cpp { get; private set; } public Lazy Il2CppObjectBase_Cast { get; private set; } public Lazy Il2CppObjectBase_TryCast { get; private set; } public Lazy Il2CppObjectPool_Get { get; private set; } public Lazy IL2CPP_ResolveICall { get; private set; } public Lazy IL2CPP_il2cpp_gc_wbarrier_set_field { get; private set; } public Lazy IL2CPP_FieldWriteWbarrierStub { get; private set; } public Lazy IL2CPP_il2cpp_field_get_offset { get; private set; } public Lazy IL2CPP_il2cpp_field_static_get_value { get; private set; } public Lazy IL2CPP_il2cpp_field_static_set_value { get; private set; } public Lazy IL2CPP_il2cpp_runtime_invoke { get; private set; } public Lazy IL2CPP_il2cpp_runtime_class_init { get; private set; } public Lazy IL2CPP_il2cpp_object_unbox { get; private set; } public Lazy IL2CPP_il2cpp_value_box { get; private set; } public Lazy IL2CPP_il2cpp_class_value_size { get; private set; } public Lazy IL2CPP_il2cpp_object_get_class { get; private set; } public Lazy IL2CPP_il2cpp_class_is_valuetype { get; private set; } public Lazy Il2CppException_RaiseExceptionIfNecessary { get; private set; } public Lazy IL2CPP_il2cpp_object_get_virtual_method { get; private set; } public Lazy IL2CPP_GetIl2CppField { get; private set; } public Lazy IL2CPP_GetIl2CppNestedType { get; private set; } public Lazy IL2CPP_GetIl2CppClass { get; private set; } public Lazy IL2CPP_GetIl2CppMethod { get; private set; } public Lazy IL2CPP_GetIl2CppMethodByToken { get; private set; } public Lazy IL2CPP_il2cpp_class_get_type { get; private set; } public Lazy IL2CPP_il2cpp_class_from_type { get; private set; } public Lazy IL2CPP_il2cpp_object_new { get; private set; } public Lazy IL2CPP_il2cpp_method_get_from_reflection { get; private set; } public Lazy IL2CPP_il2cpp_method_get_object { get; private set; } public Lazy IL2CPP_PointerToValueGeneric { get; private set; } public Lazy IL2CPP_RenderTypeName { get; private set; } public Lazy OriginalNameAttributector { get; private set; } public Lazy ObfuscatedNameAttributector { get; private set; } public Lazy CallerCountAttributector { get; private set; } public Lazy CachedScanResultsAttributector { get; private set; } public Lazy Il2CppSystemDelegateCombine { get; private set; } public Lazy Il2CppSystemDelegateRemove { get; private set; } public Lazy Il2CppSystemRuntimeTypeHandleGetRuntimeTypeHandle { get; private set; } public MethodReference WriteFieldWBarrier { get { if (!globalCtx.HasGcWbarrierFieldWrite) { return IL2CPP_FieldWriteWbarrierStub.Value; } return IL2CPP_il2cpp_gc_wbarrier_set_field.Value; } } public TypeReference Il2CppObjectBase { get; private set; } public TypeReference Il2CppObjectPool { get; private set; } public TypeReference Il2CppStringArray { get; private set; } public TypeReference Il2CppArrayBase { get; private set; } public TypeReference Il2CppStructArray { get; private set; } public TypeReference Il2CppReferenceArray { get; private set; } public TypeReference Il2CppClassPointerStore { get; private set; } public TypeReference Il2Cpp { get; set; } public TypeReference RuntimeReflectionHelper { get; private set; } public TypeReference DelegateSupport { get; private set; } public TypeReference Il2CppException { get; private set; } public RuntimeAssemblyReferences(ModuleDefinition module, RewriteGlobalContext globalContext) { Module = module; globalCtx = globalContext; InitTypeRefs(); InitMethodRefs(); } private TypeReference ResolveType(string typeName) { return allTypes[typeName]; } private unsafe void InitTypeRefs() { //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Expected O, but got Unknown //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Expected O, but got Unknown //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Expected O, but got Unknown //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Expected O, but got Unknown //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Expected O, but got Unknown //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Expected O, but got Unknown //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Expected O, but got Unknown //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Expected O, but got Unknown //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Expected O, but got Unknown //IL_02e9: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Expected O, but got Unknown //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_030f: Expected O, but got Unknown //IL_0325: Unknown result type (might be due to invalid IL or missing references) //IL_032f: Expected O, but got Unknown //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Expected O, but got Unknown //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_0367: Expected O, but got Unknown //IL_0379: Unknown result type (might be due to invalid IL or missing references) //IL_0383: Expected O, but got Unknown //IL_0395: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Expected O, but got Unknown allTypes["System.Void"] = Module.ImportReference(typeof(void)); allTypes["System.String[]"] = Module.ImportReference(typeof(string[])); allTypes["System.IntPtr"] = Module.ImportReference(typeof(IntPtr)); allTypes["System.String"] = Module.ImportReference(typeof(string)); allTypes["System.UInt32"] = Module.ImportReference(typeof(uint)); allTypes["System.Void*"] = Module.ImportReference(typeof(void*)); allTypes["System.Void**"] = Module.ImportReference(typeof(void**)); allTypes["System.IntPtr&"] = Module.ImportReference(typeof(IntPtr).MakeByRefType()); allTypes["System.Int32"] = Module.ImportReference(typeof(int)); allTypes["System.UInt32&"] = Module.ImportReference(typeof(uint).MakeByRefType()); allTypes["System.Boolean"] = Module.ImportReference(typeof(bool)); allTypes["System.Int64"] = Module.ImportReference(typeof(long)); AssemblyNameReference val = new AssemblyNameReference("Il2CppInterop.Runtime", new Version(0, 0, 0, 0)); Module.AssemblyReferences.Add(val); Il2CppObjectBase = new TypeReference("Il2CppInterop.Runtime.InteropTypes", "Il2CppObjectBase", Module, (IMetadataScope)(object)val); Il2CppObjectPool = new TypeReference("Il2CppInterop.Runtime.Runtime", "Il2CppObjectPool", Module, (IMetadataScope)(object)val); Il2CppStringArray = new TypeReference("Il2CppInterop.Runtime.InteropTypes.Arrays", "Il2CppStringArray", Module, (IMetadataScope)(object)val); Il2CppArrayBase = new TypeReference("Il2CppInterop.Runtime.InteropTypes.Arrays", "Il2CppArrayBase`1", Module, (IMetadataScope)(object)val); Il2CppArrayBase.GenericParameters.Add(new GenericParameter("T", (IGenericParameterProvider)(object)Il2CppArrayBase)); Il2CppStructArray = new TypeReference("Il2CppInterop.Runtime.InteropTypes.Arrays", "Il2CppStructArray`1", Module, (IMetadataScope)(object)val); Il2CppStructArray.GenericParameters.Add(new GenericParameter("T", (IGenericParameterProvider)(object)Il2CppStructArray)); Il2CppReferenceArray = new TypeReference("Il2CppInterop.Runtime.InteropTypes.Arrays", "Il2CppReferenceArray`1", Module, (IMetadataScope)(object)val); Il2CppReferenceArray.GenericParameters.Add(new GenericParameter("T", (IGenericParameterProvider)(object)Il2CppReferenceArray)); Il2CppClassPointerStore = new TypeReference("Il2CppInterop.Runtime", "Il2CppClassPointerStore`1", Module, (IMetadataScope)(object)val); Il2CppClassPointerStore.GenericParameters.Add(new GenericParameter("T", (IGenericParameterProvider)(object)Il2CppClassPointerStore)); Il2Cpp = new TypeReference("Il2CppInterop.Runtime", "IL2CPP", Module, (IMetadataScope)(object)val); RuntimeReflectionHelper = new TypeReference("Il2CppInterop.Runtime", "RuntimeReflectionHelper", Module, (IMetadataScope)(object)val); DelegateSupport = new TypeReference("Il2CppInterop.Runtime", "DelegateSupport", Module, (IMetadataScope)(object)val); Il2CppException = new TypeReference("Il2CppInterop.Runtime", "Il2CppException", Module, (IMetadataScope)(object)val); allTypes["Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase"] = Il2CppObjectBase; allTypes["Il2CppInterop.Runtime.Runtime.Il2CppObjectPool"] = Il2CppObjectPool; allTypes["Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppStringArray"] = Il2CppStringArray; allTypes["Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppReferenceArray"] = Il2CppReferenceArray; allTypes["Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppStructArray"] = Il2CppStructArray; allTypes["Il2CppInterop.Runtime.Il2CppException"] = Il2CppException; allTypes["Il2CppInterop.Runtime.IL2CPP"] = Il2Cpp; } private void InitMethodRefs() { Il2CppRefrenceArrayctor = new Memoize(delegate(TypeReference param) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown //IL_0066: Expected O, but got Unknown TypeReference obj2 = ResolveType("Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppReferenceArray"); GenericParameter val56 = obj2.GenericParameters[0]; GenericInstanceType val57 = new GenericInstanceType(obj2); val57.GenericArguments.Add(param); MethodReference val58 = new MethodReference(".ctor", ResolveType("System.Void"), (TypeReference)(object)val57) { HasThis = true }; ArrayType val59 = new ArrayType((TypeReference)(object)val56); val58.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, (TypeReference)(object)val59)); return val58; }); Il2CppStringArrayctor = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val55 = new MethodReference(".ctor", ResolveType("System.Void"), ResolveType("Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppStringArray")) { HasThis = true }; val55.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.String[]"))); return val55; }); Il2CppStructArrayctor = new Memoize(delegate(TypeReference param) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown //IL_0066: Expected O, but got Unknown TypeReference obj = ResolveType("Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppStructArray"); GenericParameter val51 = obj.GenericParameters[0]; GenericInstanceType val52 = new GenericInstanceType(obj); val52.GenericArguments.Add(param); MethodReference val53 = new MethodReference(".ctor", ResolveType("System.Void"), (TypeReference)(object)val52) { HasThis = true }; ArrayType val54 = new ArrayType((TypeReference)(object)val51); val53.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, (TypeReference)(object)val54)); return val53; }); Il2CppRefrenceArrayctor_size = new Memoize(delegate(TypeReference param) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_005c: Expected O, but got Unknown GenericInstanceType val49 = new GenericInstanceType(ResolveType("Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppReferenceArray")); val49.GenericArguments.Add(param); MethodReference val50 = new MethodReference(".ctor", ResolveType("System.Void"), (TypeReference)(object)val49) { HasThis = true }; val50.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.Int64"))); return val50; }); Il2CppStringArrayctor_size = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val48 = new MethodReference(".ctor", ResolveType("System.Void"), ResolveType("Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppStringArray")) { HasThis = true }; val48.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.Int64"))); return val48; }); Il2CppStructArrayctor_size = new Memoize(delegate(TypeReference param) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_005c: Expected O, but got Unknown GenericInstanceType val46 = new GenericInstanceType(ResolveType("Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppStructArray")); val46.GenericArguments.Add(param); MethodReference val47 = new MethodReference(".ctor", ResolveType("System.Void"), (TypeReference)(object)val46) { HasThis = true }; val47.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.Int64"))); return val47; }); IL2CPP_Il2CppObjectBaseToPtr = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val45 = new MethodReference("Il2CppObjectBaseToPtr", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val45.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase"))); return val45; }); IL2CPP_Il2CppObjectBaseToPtrNotNull = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val44 = new MethodReference("Il2CppObjectBaseToPtrNotNull", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val44.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase"))); return val44; }); IL2CPP_Il2CppStringToManaged = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val43 = new MethodReference("Il2CppStringToManaged", ResolveType("System.String"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val43.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val43; }); IL2CPP_ManagedStringToIl2Cpp = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val42 = new MethodReference("ManagedStringToIl2Cpp", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val42.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.String"))); return val42; }); Il2CppObjectBase_Cast = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown MethodReference val40 = new MethodReference("Cast", Module.Void(), ResolveType("Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase")); GenericParameter val41 = new GenericParameter("T", (IGenericParameterProvider)(object)val40); val40.GenericParameters.Add(val41); val40.ReturnType = (TypeReference)(object)val41; val40.HasThis = true; return val40; }); Il2CppObjectBase_TryCast = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown MethodReference val38 = new MethodReference("TryCast", Module.Void(), ResolveType("Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase")); GenericParameter val39 = new GenericParameter("T", (IGenericParameterProvider)(object)val38); val38.GenericParameters.Add(val39); val38.ReturnType = (TypeReference)(object)val39; val38.HasThis = true; return val38; }); Il2CppObjectPool_Get = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected O, but got Unknown MethodReference val36 = new MethodReference("Get", Module.Void(), ResolveType("Il2CppInterop.Runtime.Runtime.Il2CppObjectPool")); GenericParameter val37 = new GenericParameter("T", (IGenericParameterProvider)(object)val36); val36.GenericParameters.Add(val37); val36.ReturnType = (TypeReference)(object)val37; val36.HasThis = false; val36.Parameters.Add(new ParameterDefinition("ptr", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val36; }); IL2CPP_ResolveICall = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected O, but got Unknown MethodReference val34 = new MethodReference("ResolveICall", Module.Void(), ResolveType("Il2CppInterop.Runtime.IL2CPP")); GenericParameter val35 = new GenericParameter("T", (IGenericParameterProvider)(object)val34); val34.GenericParameters.Add(val35); val34.ReturnType = (TypeReference)(object)val35; val34.HasThis = false; val34.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.String"))); return val34; }); IL2CPP_il2cpp_gc_wbarrier_set_field = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_0069: 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_008a: Expected O, but got Unknown //IL_008b: Expected O, but got Unknown MethodReference val33 = new MethodReference("il2cpp_gc_wbarrier_set_field", ResolveType("System.Void"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val33.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val33.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val33.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val33; }); IL2CPP_FieldWriteWbarrierStub = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_0069: 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_008a: Expected O, but got Unknown //IL_008b: Expected O, but got Unknown MethodReference val32 = new MethodReference("FieldWriteWbarrierStub", ResolveType("System.Void"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val32.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val32.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val32.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val32; }); IL2CPP_il2cpp_field_get_offset = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val31 = new MethodReference("il2cpp_field_get_offset", ResolveType("System.UInt32"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val31.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val31; }); IL2CPP_il2cpp_field_static_get_value = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_006a: Expected O, but got Unknown MethodReference val30 = new MethodReference("il2cpp_field_static_get_value", ResolveType("System.Void"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val30.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val30.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.Void*"))); return val30; }); IL2CPP_il2cpp_field_static_set_value = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_006a: Expected O, but got Unknown MethodReference val29 = new MethodReference("il2cpp_field_static_set_value", ResolveType("System.Void"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val29.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val29.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.Void*"))); return val29; }); IL2CPP_il2cpp_runtime_invoke = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_0069: 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_008a: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_00ac: Expected O, but got Unknown MethodReference val28 = new MethodReference("il2cpp_runtime_invoke", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val28.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val28.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val28.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.Void**"))); val28.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr&"))); return val28; }); IL2CPP_il2cpp_runtime_class_init = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val27 = new MethodReference("il2cpp_runtime_class_init", ResolveType("System.Void"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val27.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val27; }); IL2CPP_il2cpp_object_unbox = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val26 = new MethodReference("il2cpp_object_unbox", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val26.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val26; }); IL2CPP_il2cpp_value_box = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_006a: Expected O, but got Unknown MethodReference val25 = new MethodReference("il2cpp_value_box", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val25.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val25.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val25; }); IL2CPP_il2cpp_class_value_size = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_006a: Expected O, but got Unknown MethodReference val24 = new MethodReference("il2cpp_class_value_size", ResolveType("System.Int32"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val24.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val24.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.UInt32&"))); return val24; }); IL2CPP_il2cpp_object_get_class = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val23 = new MethodReference("il2cpp_object_get_class", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val23.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val23; }); IL2CPP_il2cpp_class_is_valuetype = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val22 = new MethodReference("il2cpp_class_is_valuetype", ResolveType("System.Boolean"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val22.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val22; }); Il2CppException_RaiseExceptionIfNecessary = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val21 = new MethodReference("RaiseExceptionIfNecessary", ResolveType("System.Void"), ResolveType("Il2CppInterop.Runtime.Il2CppException")) { HasThis = false }; val21.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val21; }); IL2CPP_il2cpp_object_get_virtual_method = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_006a: Expected O, but got Unknown MethodReference val20 = new MethodReference("il2cpp_object_get_virtual_method", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val20.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val20.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val20; }); IL2CPP_GetIl2CppField = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_006a: Expected O, but got Unknown MethodReference val19 = new MethodReference("GetIl2CppField", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val19.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val19.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.String"))); return val19; }); IL2CPP_GetIl2CppNestedType = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_006a: Expected O, but got Unknown MethodReference val18 = new MethodReference("GetIl2CppNestedType", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val18.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val18.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.String"))); return val18; }); IL2CPP_GetIl2CppClass = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_0069: 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_008a: Expected O, but got Unknown //IL_008b: Expected O, but got Unknown MethodReference val17 = new MethodReference("GetIl2CppClass", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val17.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.String"))); val17.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.String"))); val17.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.String"))); return val17; }); IL2CPP_GetIl2CppMethod = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_0069: 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_008a: Expected O, but got Unknown //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Expected O, but got Unknown //IL_00cd: Expected O, but got Unknown MethodReference val16 = new MethodReference("GetIl2CppMethod", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val16.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val16.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.Boolean"))); val16.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.String"))); val16.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.String"))); val16.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.String[]"))); return val16; }); IL2CPP_GetIl2CppMethodByToken = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_006a: Expected O, but got Unknown MethodReference val15 = new MethodReference("GetIl2CppMethodByToken", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val15.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val15.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.Int32"))); return val15; }); IL2CPP_il2cpp_class_get_type = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val14 = new MethodReference("il2cpp_class_get_type", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val14.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val14; }); IL2CPP_il2cpp_class_from_type = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val13 = new MethodReference("il2cpp_class_from_type", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val13.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val13; }); IL2CPP_il2cpp_object_new = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val12 = new MethodReference("il2cpp_object_new", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val12.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val12; }); IL2CPP_il2cpp_method_get_from_reflection = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0049: Expected O, but got Unknown MethodReference val11 = new MethodReference("il2cpp_method_get_from_reflection", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val11.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val11; }); IL2CPP_il2cpp_method_get_object = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0048: Expected O, but got Unknown //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_006a: Expected O, but got Unknown MethodReference val10 = new MethodReference("il2cpp_method_get_object", ResolveType("System.IntPtr"), ResolveType("Il2CppInterop.Runtime.IL2CPP")) { HasThis = false }; val10.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val10.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); return val10; }); IL2CPP_PointerToValueGeneric = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Expected O, but got Unknown //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Expected O, but got Unknown //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Expected O, but got Unknown MethodReference val8 = new MethodReference("PointerToValueGeneric", Module.Void(), ResolveType("Il2CppInterop.Runtime.IL2CPP")); GenericParameter val9 = new GenericParameter("T", (IGenericParameterProvider)(object)val8); val8.GenericParameters.Add(val9); val8.ReturnType = (TypeReference)(object)val9; val8.HasThis = false; val8.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.IntPtr"))); val8.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.Boolean"))); val8.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.Boolean"))); return val8; }); IL2CPP_RenderTypeName = new Lazy((Func)delegate { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown MethodReference val6 = new MethodReference("RenderTypeName", ResolveType("System.String"), ResolveType("Il2CppInterop.Runtime.IL2CPP")); GenericParameter val7 = new GenericParameter("T", (IGenericParameterProvider)(object)val6); val6.GenericParameters.Add(val7); val6.HasThis = false; val6.Parameters.Add(new ParameterDefinition("", (ParameterAttributes)0, ResolveType("System.Boolean"))); return val6; }); OriginalNameAttributector = new Lazy((Func)delegate { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //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: 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_0067: Expected O, but got Unknown //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_0083: Expected O, but got Unknown MethodReference val5 = new MethodReference(".ctor", Module.Void(), Module.ImportReference(typeof(OriginalNameAttribute))) { HasThis = true }; val5.Parameters.Add(new ParameterDefinition(Module.String())); val5.Parameters.Add(new ParameterDefinition(Module.String())); val5.Parameters.Add(new ParameterDefinition(Module.String())); return val5; }); ObfuscatedNameAttributector = new Lazy((Func)delegate { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //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_004d: Expected O, but got Unknown MethodReference val4 = new MethodReference(".ctor", Module.Void(), Module.ImportReference(typeof(ObfuscatedNameAttribute))) { HasThis = true }; val4.Parameters.Add(new ParameterDefinition(Module.String())); return val4; }); CallerCountAttributector = new Lazy((Func)delegate { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //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_004d: Expected O, but got Unknown MethodReference val3 = new MethodReference(".ctor", Module.Void(), Module.ImportReference(typeof(CallerCountAttribute))) { HasThis = true }; val3.Parameters.Add(new ParameterDefinition(Module.Int())); return val3; }); CachedScanResultsAttributector = new Lazy((Func)(() => new MethodReference(".ctor", Module.Void(), Module.ImportReference(typeof(CachedScanResultsAttribute))) { HasThis = true })); Il2CppSystemDelegateCombine = new Lazy((Func)(() => Module.ImportReference((MethodReference)(object)((IEnumerable)globalCtx.GetAssemblyByName("mscorlib").NewAssembly.MainModule.GetType("Il2CppSystem.Delegate").Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "Combine" && ((MethodReference)m).Parameters.Count == 2)))); Il2CppSystemDelegateRemove = new Lazy((Func)(() => Module.ImportReference((MethodReference)(object)((IEnumerable)globalCtx.GetAssemblyByName("mscorlib").NewAssembly.MainModule.GetType("Il2CppSystem.Delegate").Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "Remove")))); Il2CppSystemRuntimeTypeHandleGetRuntimeTypeHandle = new Lazy((Func)delegate { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown TypeReference runtimeReflectionHelper = RuntimeReflectionHelper; TypeReference val = Module.ImportReference((TypeReference)(object)globalCtx.GetAssemblyByName("mscorlib").NewAssembly.MainModule.GetType("Il2CppSystem.RuntimeTypeHandle")); MethodReference val2 = new MethodReference("GetRuntimeTypeHandle", val, runtimeReflectionHelper) { HasThis = false }; val2.GenericParameters.Add(new GenericParameter("T", (IGenericParameterProvider)(object)val2)); return Module.ImportReference(val2); }); } } internal readonly struct TimingCookie : IDisposable { private readonly Stopwatch myStopwatch; public TimingCookie(string message) { Logger.Instance.LogInformation("{Message}...", message); myStopwatch = Stopwatch.StartNew(); } public void Dispose() { Logger.Instance.LogInformation("Done in {Elapsed}", myStopwatch.Elapsed); } } public class UniquificationContext { private class Item2Comparer : IComparer<(string, float)> { public int Compare((string, float) x, (string, float) y) { return x.Item2.CompareTo(y.Item2); } } private readonly GeneratorOptions myGeneratorOptions; private readonly SortedSet<(string, float)> myPrefixes = new SortedSet<(string, float)>(new Item2Comparer()); private readonly Dictionary myUniquifiersCount = new Dictionary(); public UniquificationContext(GeneratorOptions generatorOptions) { myGeneratorOptions = generatorOptions; } public bool CheckFull() { return myUniquifiersCount.Count >= myGeneratorOptions.TypeDeobfuscationMaxUniquifiers; } public void Push(string str, bool noSubstring = false) { if (!str.IsInvalidInSource()) { string text = (noSubstring ? str : SubstringBounded(str, 0, myGeneratorOptions.TypeDeobfuscationCharsPerUniquifier)); int num2 = (myUniquifiersCount[text] = myUniquifiersCount.GetOrCreate(text, (string _) => 0) + 1); int num3 = num2; myPrefixes.Add((text, (float)(myUniquifiersCount.Count + num3 * 2) + (float)myPrefixes.Count / 100f)); } } public void Push(List strings, bool noSubstring = false) { foreach (string @string in strings) { Push(@string, noSubstring); } } public string GetTop() { return string.Join("", from it in myPrefixes.Take(myGeneratorOptions.TypeDeobfuscationMaxUniquifiers) select it.Item1); } private static string SubstringBounded(string str, int startIndex, int length) { length = Math.Min(length, str.Length); return str.Substring(startIndex, length); } } public static class UnstripGenerator { public static TypeDefinition CreateDelegateTypeForICallMethod(MethodDefinition unityMethod, MethodDefinition convertedMethod, RuntimeAssemblyReferences imports) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Expected O, but got Unknown //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Expected O, but got Unknown //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Expected O, but got Unknown TypeDefinition val = new TypeDefinition("", ((MemberReference)unityMethod).Name + "Delegate", (TypeAttributes)259, imports.Module.MulticastDelegate()); MethodDefinition val2 = new MethodDefinition(".ctor", (MethodAttributes)6278, imports.Module.Void()); ((MethodReference)val2).Parameters.Add(new ParameterDefinition(imports.Module.Object())); ((MethodReference)val2).Parameters.Add(new ParameterDefinition(imports.Module.IntPtr())); val2.ImplAttributes = (MethodImplAttributes)3; val.Methods.Add(val2); MethodDefinition val3 = new MethodDefinition("Invoke", (MethodAttributes)454, imports.Module.Void()); val3.ImplAttributes = (MethodImplAttributes)3; val.Methods.Add(val3); ((MethodReference)val3).ReturnType = (((MethodReference)convertedMethod).ReturnType.IsValueType ? ((MethodReference)convertedMethod).ReturnType : imports.Module.IntPtr()); if (((MethodReference)convertedMethod).HasThis) { ((MethodReference)val3).Parameters.Add(new ParameterDefinition("@this", (ParameterAttributes)0, imports.Module.IntPtr())); } Enumerator enumerator = ((MethodReference)convertedMethod).Parameters.GetEnumerator(); try { while (enumerator.MoveNext()) { ParameterDefinition current = enumerator.Current; ((MethodReference)val3).Parameters.Add(new ParameterDefinition(((ParameterReference)current).Name, (ParameterAttributes)(current.Attributes & 0xFFEF), ((ParameterReference)current).ParameterType.IsValueType ? ((ParameterReference)current).ParameterType : imports.Module.IntPtr())); } return val; } finally { ((IDisposable)enumerator).Dispose(); } } public static void GenerateInvokerMethodBody(MethodDefinition newMethod, FieldDefinition delegateField, TypeDefinition delegateType, TypeRewriteContext enclosingType, RuntimeAssemblyReferences imports) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Expected O, but got Unknown //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) ILProcessor iLProcessor = newMethod.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldsfld, (FieldReference)(object)delegateField); if (((MethodReference)newMethod).HasThis) { iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Call, imports.IL2CPP_Il2CppObjectBaseToPtrNotNull.Value); } int num = (((MethodReference)newMethod).HasThis ? 1 : 0); for (int i = 0; i < ((MethodReference)newMethod).Parameters.Count; i++) { ParameterDefinition val = ((MethodReference)newMethod).Parameters[i]; TypeReference parameterType = ((ParameterReference)val).ParameterType; if (parameterType.IsValueType || (parameterType.IsByReference && parameterType.GetElementType().IsValueType)) { iLProcessor.Emit(OpCodes.Ldarg, i + num); continue; } iLProcessor.EmitObjectToPointer(((ParameterReference)val).ParameterType, ((ParameterReference)val).ParameterType, enclosingType, i + num, valueTypeArgument0IsAPointer: false, allowNullable: true, unboxNonBlittableType: true, unboxNonBlittableGeneric: true, out VariableDefinition refVariable); if (refVariable != null) { Logger.Instance.LogTrace("Method {NewMethod} has a reference-typed ref parameter, this will be ignored", ((object)newMethod).ToString()); } } iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)((IEnumerable)delegateType.Methods).Single((MethodDefinition it) => ((MemberReference)it).Name == "Invoke")); if (!((MethodReference)newMethod).ReturnType.IsValueType) { VariableDefinition val2 = new VariableDefinition(imports.Module.IntPtr()); newMethod.Body.Variables.Add(val2); iLProcessor.Emit(OpCodes.Stloc, val2); Instruction loadPointer = iLProcessor.Create(OpCodes.Ldloc, val2); iLProcessor.EmitPointerToObject(((MethodReference)newMethod).ReturnType, ((MethodReference)newMethod).ReturnType, enclosingType, loadPointer, extraDerefForNonValueTypes: false, unboxValueType: false); } iLProcessor.Emit(OpCodes.Ret); } public static FieldDefinition GenerateStaticCtorSuffix(TypeDefinition enclosingType, TypeDefinition delegateType, MethodDefinition unityMethod, RuntimeAssemblyReferences imports) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Expected O, but got Unknown //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown //IL_0079: Unknown result type (might be due to invalid IL or missing references) FieldDefinition val = new FieldDefinition(((MemberReference)delegateType).Name + "Field", (FieldAttributes)49, (TypeReference)(object)delegateType); enclosingType.Fields.Add(val); MethodDefinition val2 = ((IEnumerable)enclosingType.Methods).SingleOrDefault((Func)((MethodDefinition it) => ((MemberReference)it).Name == ".cctor")); if (val2 == null) { val2 = new MethodDefinition(".cctor", (MethodAttributes)6289, imports.Module.Void()); val2.Body.GetILProcessor().Emit(OpCodes.Ret); enclosingType.Methods.Add(val2); } ILProcessor iLProcessor = val2.Body.GetILProcessor(); iLProcessor.Remove(((IEnumerable)val2.Body.Instructions).Last()); iLProcessor.Emit(OpCodes.Ldstr, GetICallSignature(unityMethod)); GenericInstanceMethod val3 = new GenericInstanceMethod(imports.IL2CPP_ResolveICall.Value); val3.GenericArguments.Add((TypeReference)(object)delegateType); iLProcessor.Emit(OpCodes.Call, ((MemberReference)enclosingType).Module.ImportReference((MethodReference)(object)val3)); iLProcessor.Emit(OpCodes.Stsfld, (FieldReference)(object)val); iLProcessor.Emit(OpCodes.Ret); return val; } private static string GetICallSignature(MethodDefinition unityMethod) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(((MemberReference)unityMethod.DeclaringType).FullName); stringBuilder.Append("::"); stringBuilder.Append(((MemberReference)unityMethod).Name); return stringBuilder.ToString(); } } public static class UnstripTranslator { public static bool TranslateMethod(MethodDefinition original, MethodDefinition target, TypeRewriteContext typeRewriteContext, RuntimeAssemblyReferences imports) { //IL_0021: 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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Invalid comparison between Unknown and I4 //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Invalid comparison between Unknown and I4 //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown //IL_034a: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Unknown result type (might be due to invalid IL or missing references) //IL_035a: Invalid comparison between Unknown and I4 //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Expected O, but got Unknown //IL_0596: Unknown result type (might be due to invalid IL or missing references) //IL_059b: Unknown result type (might be due to invalid IL or missing references) //IL_059f: Unknown result type (might be due to invalid IL or missing references) //IL_05a5: Invalid comparison between Unknown and I4 //IL_036f: Unknown result type (might be due to invalid IL or missing references) //IL_0379: Expected O, but got Unknown //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0143: 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_05b1: Unknown result type (might be due to invalid IL or missing references) //IL_05b6: Unknown result type (might be due to invalid IL or missing references) //IL_05ba: Unknown result type (might be due to invalid IL or missing references) //IL_05c1: Invalid comparison between Unknown and I4 //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_02a8: Expected O, but got Unknown //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_041f: Unknown result type (might be due to invalid IL or missing references) //IL_0424: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_047d: Unknown result type (might be due to invalid IL or missing references) //IL_0482: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_04db: Unknown result type (might be due to invalid IL or missing references) //IL_04e0: Unknown result type (might be due to invalid IL or missing references) //IL_043f: Unknown result type (might be due to invalid IL or missing references) //IL_0455: Unknown result type (might be due to invalid IL or missing references) //IL_045a: Unknown result type (might be due to invalid IL or missing references) //IL_0471: Expected O, but got Unknown //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_0693: Unknown result type (might be due to invalid IL or missing references) //IL_06a9: Unknown result type (might be due to invalid IL or missing references) //IL_06ae: Unknown result type (might be due to invalid IL or missing references) //IL_06c5: Expected O, but got Unknown //IL_057e: Unknown result type (might be due to invalid IL or missing references) //IL_049d: Unknown result type (might be due to invalid IL or missing references) //IL_04b3: Unknown result type (might be due to invalid IL or missing references) //IL_04b8: Unknown result type (might be due to invalid IL or missing references) //IL_04cf: Expected O, but got Unknown //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Expected O, but got Unknown //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_04fe: Unknown result type (might be due to invalid IL or missing references) //IL_050e: Unknown result type (might be due to invalid IL or missing references) //IL_0513: Unknown result type (might be due to invalid IL or missing references) //IL_0527: Expected O, but got Unknown //IL_0528: Unknown result type (might be due to invalid IL or missing references) //IL_0545: Unknown result type (might be due to invalid IL or missing references) //IL_054a: Unknown result type (might be due to invalid IL or missing references) //IL_0551: Unknown result type (might be due to invalid IL or missing references) //IL_0562: Unknown result type (might be due to invalid IL or missing references) //IL_056c: Expected O, but got Unknown //IL_0571: Expected O, but got Unknown //IL_0216: Unknown result type (might be due to invalid IL or missing references) if (!original.HasBody) { return true; } RewriteGlobalContext globalContext = typeRewriteContext.AssemblyContext.GlobalContext; Enumerator enumerator = original.Body.Variables.GetEnumerator(); try { while (enumerator.MoveNext()) { VariableDefinition current = enumerator.Current; TypeReference val = Pass80UnstripMethods.ResolveTypeInNewAssemblies(globalContext, ((VariableReference)current).VariableType, imports); if (val == null) { return false; } target.Body.Variables.Add(new VariableDefinition(val)); } } finally { ((IDisposable)enumerator).Dispose(); } ILProcessor iLProcessor = target.Body.GetILProcessor(); Enumerator enumerator2 = original.Body.Instructions.GetEnumerator(); try { TypeReference targetTok = default(TypeReference); while (enumerator2.MoveNext()) { Instruction current2 = enumerator2.Current; OpCode opCode = current2.OpCode; if ((int)((OpCode)(ref opCode)).OperandType == 1) { FieldReference fieldArg = (FieldReference)current2.Operand; TypeReference val2 = Pass80UnstripMethods.ResolveTypeInNewAssembliesRaw(globalContext, ((MemberReference)fieldArg).DeclaringType, imports); if (val2 == null) { return false; } FieldDefinition val3 = ((IEnumerable)val2.Resolve().Fields).SingleOrDefault((Func)((FieldDefinition it) => ((MemberReference)it).Name == ((MemberReference)fieldArg).Name)); if (val3 != null) { iLProcessor.Emit(current2.OpCode, imports.Module.ImportReference((FieldReference)(object)val3)); continue; } if (current2.OpCode == OpCodes.Ldfld || current2.OpCode == OpCodes.Ldsfld) { PropertyDefinition? obj = ((IEnumerable)val2.Resolve().Properties).SingleOrDefault((Func)((PropertyDefinition it) => ((MemberReference)it).Name == ((MemberReference)fieldArg).Name)); MethodDefinition val4 = ((obj != null) ? obj.GetMethod : null); if (val4 == null) { return false; } iLProcessor.Emit(OpCodes.Call, imports.Module.ImportReference((MethodReference)(object)val4)); continue; } if (current2.OpCode == OpCodes.Stfld || current2.OpCode == OpCodes.Stsfld) { PropertyDefinition? obj2 = ((IEnumerable)val2.Resolve().Properties).SingleOrDefault((Func)((PropertyDefinition it) => ((MemberReference)it).Name == ((MemberReference)fieldArg).Name)); MethodDefinition val5 = ((obj2 != null) ? obj2.SetMethod : null); if (val5 == null) { return false; } iLProcessor.Emit(OpCodes.Call, imports.Module.ImportReference((MethodReference)(object)val5)); continue; } return false; } opCode = current2.OpCode; if ((int)((OpCode)(ref opCode)).OperandType == 4) { MethodReference val6 = (MethodReference)current2.Operand; TypeReference val7 = Pass80UnstripMethods.ResolveTypeInNewAssemblies(globalContext, ((MemberReference)val6).DeclaringType, imports); if (val7 == null) { return false; } TypeReference val8 = Pass80UnstripMethods.ResolveTypeInNewAssemblies(globalContext, val6.ReturnType, imports); if (val8 == null) { return false; } MethodReference val9 = new MethodReference(((MemberReference)val6).Name, val8, val7); val9.HasThis = val6.HasThis; Enumerator enumerator3 = val6.Parameters.GetEnumerator(); try { while (enumerator3.MoveNext()) { ParameterDefinition current3 = enumerator3.Current; TypeReference val10 = Pass80UnstripMethods.ResolveTypeInNewAssemblies(globalContext, ((ParameterReference)current3).ParameterType, imports); if (val10 == null) { return false; } ParameterDefinition val11 = new ParameterDefinition(((ParameterReference)current3).Name, current3.Attributes, val10); val9.Parameters.Add(val11); } } finally { ((IDisposable)enumerator3).Dispose(); } iLProcessor.Emit(current2.OpCode, imports.Module.ImportReference(val9)); continue; } opCode = current2.OpCode; if ((int)((OpCode)(ref opCode)).OperandType == 12) { TypeReference targetType = (TypeReference)current2.Operand; TypeReference obj3 = targetType; GenericParameter val12 = (GenericParameter)(object)((obj3 is GenericParameter) ? obj3 : null); if (val12 != null) { IGenericParameterProvider owner = val12.Owner; TypeReference val13 = (TypeReference)(object)((owner is TypeReference) ? owner : null); if (val13 != null) { TypeReference val14 = Pass80UnstripMethods.ResolveTypeInNewAssemblies(globalContext, val13, imports); if (val14 == null) { return false; } targetType = (TypeReference)(object)((IEnumerable)val14.GenericParameters).Single((GenericParameter it) => ((MemberReference)it).Name == ((MemberReference)targetType).Name); } else { targetType = (TypeReference)(object)((IEnumerable)((MethodReference)target).GenericParameters).Single((GenericParameter it) => ((MemberReference)it).Name == ((MemberReference)targetType).Name); } } else { targetType = Pass80UnstripMethods.ResolveTypeInNewAssemblies(globalContext, targetType, imports); if (targetType == null) { return false; } } if (current2.OpCode == OpCodes.Castclass && !targetType.IsValueType) { OpCode call = OpCodes.Call; ModuleDefinition module = imports.Module; GenericInstanceMethod val15 = new GenericInstanceMethod(imports.Il2CppObjectBase_Cast.Value); val15.GenericArguments.Add(targetType); iLProcessor.Emit(call, module.ImportReference((MethodReference)val15)); } else if (current2.OpCode == OpCodes.Isinst && !targetType.IsValueType) { OpCode call2 = OpCodes.Call; ModuleDefinition module2 = imports.Module; GenericInstanceMethod val16 = new GenericInstanceMethod(imports.Il2CppObjectBase_TryCast.Value); val16.GenericArguments.Add(targetType); iLProcessor.Emit(call2, module2.ImportReference((MethodReference)val16)); } else if (current2.OpCode == OpCodes.Newarr && !targetType.IsValueType) { iLProcessor.Emit(OpCodes.Conv_I8); GenericInstanceType val17 = new GenericInstanceType(imports.Il2CppReferenceArray); val17.GenericArguments.Add(targetType); GenericInstanceType val18 = val17; OpCode newobj = OpCodes.Newobj; ModuleDefinition module3 = imports.Module; MethodReference val19 = new MethodReference(".ctor", imports.Module.Void(), (TypeReference)(object)val18) { HasThis = true }; val19.Parameters.Add(new ParameterDefinition(imports.Module.Long())); iLProcessor.Emit(newobj, module3.ImportReference(val19)); } else { iLProcessor.Emit(current2.OpCode, targetType); } continue; } opCode = current2.OpCode; if ((int)((OpCode)(ref opCode)).OperandType == 8) { return false; } opCode = current2.OpCode; if ((int)((OpCode)(ref opCode)).OperandType == 11) { ref TypeReference reference = ref targetTok; object operand = current2.Operand; reference = (TypeReference)((operand is TypeReference) ? operand : null); if (targetTok == null) { return false; } TypeReference obj4 = targetTok; GenericParameter val20 = (GenericParameter)(object)((obj4 is GenericParameter) ? obj4 : null); if (val20 != null) { IGenericParameterProvider owner2 = val20.Owner; TypeReference val21 = (TypeReference)(object)((owner2 is TypeReference) ? owner2 : null); if (val21 != null) { TypeReference val22 = Pass80UnstripMethods.ResolveTypeInNewAssemblies(globalContext, val21, imports); if (val22 == null) { return false; } targetTok = (TypeReference)(object)((IEnumerable)val22.GenericParameters).Single((GenericParameter it) => ((MemberReference)it).Name == ((MemberReference)targetTok).Name); } else { targetTok = (TypeReference)(object)((IEnumerable)((MethodReference)target).GenericParameters).Single((GenericParameter it) => ((MemberReference)it).Name == ((MemberReference)targetTok).Name); } } else { targetTok = Pass80UnstripMethods.ResolveTypeInNewAssemblies(globalContext, targetTok, imports); if (targetTok == null) { return false; } } OpCode call3 = OpCodes.Call; ModuleDefinition module4 = imports.Module; GenericInstanceMethod val23 = new GenericInstanceMethod(imports.Il2CppSystemRuntimeTypeHandleGetRuntimeTypeHandle.Value); val23.GenericArguments.Add(targetTok); iLProcessor.Emit(call3, module4.ImportReference((MethodReference)val23)); } else { iLProcessor.Append(current2); } } } finally { ((IDisposable)enumerator2).Dispose(); } return true; } public static void ReplaceBodyWithException(MethodDefinition newMethod, RuntimeAssemblyReferences imports) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) newMethod.Body.Variables.Clear(); newMethod.Body.Instructions.Clear(); ILProcessor iLProcessor = newMethod.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldstr, "Method unstripping failed"); iLProcessor.Emit(OpCodes.Newobj, imports.Module.NotSupportedExceptionCtor()); iLProcessor.Emit(OpCodes.Throw); iLProcessor.Emit(OpCodes.Ret); } } internal static class XrefScanMetadataGenerationUtil { internal static long MetadataInitForMethodRva; internal static IntPtr MetadataInitForMethodFileOffset; private static readonly (string Assembly, string Type, string Method)[] MetadataInitCandidates = new(string, string, string)[3] { ("UnityEngine.CoreModule", "UnityEngine.Object", ".cctor"), ("mscorlib", "System.Exception", "get_Message"), ("mscorlib", "System.IntPtr", "Equals") }; private static void FindMetadataInitForMethod(RewriteGlobalContext context, long gameAssemblyBase) { (string, string, string)[] metadataInitCandidates = MetadataInitCandidates; for (int i = 0; i < metadataInitCandidates.Length; i++) { (string Assembly, string Type, string Method) metadataInitCandidate = metadataInitCandidates[i]; AssemblyRewriteContext? assemblyRewriteContext = context.Assemblies.FirstOrDefault((AssemblyRewriteContext it) => ((AssemblyNameReference)it.OriginalAssembly.Name).Name == metadataInitCandidate.Assembly); object obj; if (assemblyRewriteContext == null) { obj = null; } else { TypeRewriteContext? typeRewriteContext = assemblyRewriteContext.TryGetTypeByName(metadataInitCandidate.Type); obj = ((typeRewriteContext != null) ? ((IEnumerable)typeRewriteContext.OriginalType.Methods).FirstOrDefault((Func)((MethodDefinition it) => ((MemberReference)it).Name == metadataInitCandidate.Method)) : null); } MethodDefinition val = (MethodDefinition)obj; if (val != null) { MetadataInitForMethodFileOffset = (IntPtr)(long)XrefScannerLowLevel.JumpTargets((IntPtr)(gameAssemblyBase + ((ICustomAttributeProvider)(object)val).ExtractOffset()), false).First(); MetadataInitForMethodRva = (long)MetadataInitForMethodFileOffset - gameAssemblyBase - ((ICustomAttributeProvider)(object)val).ExtractOffset() + ((ICustomAttributeProvider)(object)val).ExtractRva(); return; } } throw new ApplicationException("Unable to find a method with metadata init reference"); } internal static (long FlagRva, long TokenRva) FindMetadataInitForMethod(MethodRewriteContext method, long gameAssemblyBase) { if (MetadataInitForMethodRva == 0L) { FindMetadataInitForMethod(method.DeclaringType.AssemblyContext.GlobalContext, gameAssemblyBase); } IntPtr intPtr = (IntPtr)(gameAssemblyBase + method.FileOffset); IntPtr intPtr2 = XrefScannerLowLevel.JumpTargets(intPtr, false).FirstOrDefault(); if (intPtr2 != MetadataInitForMethodFileOffset || intPtr2 == IntPtr.Zero) { return (0L, 0L); } IntPtr intPtr3 = XrefScanUtilFinder.FindLastRcxReadAddressBeforeCallTo(intPtr, MetadataInitForMethodFileOffset); IntPtr intPtr4 = XrefScanUtilFinder.FindByteWriteTargetRightAfterCallTo(intPtr, MetadataInitForMethodFileOffset); if (intPtr3 == IntPtr.Zero || intPtr4 == IntPtr.Zero) { return (0L, 0L); } return ((long)intPtr4 - gameAssemblyBase - method.FileOffset + method.Rva, (long)intPtr3 - gameAssemblyBase - method.FileOffset + method.Rva); } } } namespace Il2CppInterop.Generator.Runners { public static class DeobfuscationAnalyzer { public static Il2CppInteropGenerator AddDeobfuscationAnalyzer(this Il2CppInteropGenerator gen) { return gen.AddRunner(); } } internal class DeobfuscationAnalyzerRunner : IRunner, IDisposable { public void Dispose() { } public void Run(GeneratorOptions options) { IIl2CppMetadataAccess gameAssemblies; using (new TimingCookie("Reading assemblies")) { gameAssemblies = new CecilMetadataAccess(options.Source); } RewriteGlobalContext rewriteGlobalContext; using (new TimingCookie("Creating assembly contexts")) { rewriteGlobalContext = new RewriteGlobalContext(options, gameAssemblies, NullMetadataAccess.Instance); } for (int i = 1; i <= 3; i++) { for (int j = 3; j <= 15; j++) { options.TypeDeobfuscationCharsPerUniquifier = i; options.TypeDeobfuscationMaxUniquifiers = j; rewriteGlobalContext.RenamedTypes.Clear(); rewriteGlobalContext.RenameGroups.Clear(); Pass05CreateRenameGroups.DoPass(rewriteGlobalContext); int num = rewriteGlobalContext.RenameGroups.Values.Count((List it) => it.Count == 1); int num2 = rewriteGlobalContext.RenameGroups.Values.Count((List it) => it.Count > 1); Console.WriteLine($"Chars=\t{i}\tMaxU=\t{j}\tUniq=\t{num}\tNonUniq=\t{num2}"); } } } } public static class DeobfuscationMapGenerator { public static Il2CppInteropGenerator AddDeobfuscationMapGenerator(this Il2CppInteropGenerator gen) { return gen.AddRunner(); } } internal class DeobfuscationMapGeneratorRunner : IRunner, IDisposable { public void Run(GeneratorOptions options) { if (options.Source == null || !options.Source.Any()) { Console.WriteLine("No input specified; use -h for help"); return; } if (string.IsNullOrEmpty(options.OutputDir)) { Console.WriteLine("No target dir specified; use -h for help"); return; } if (string.IsNullOrEmpty(options.DeobfuscationNewAssembliesPath)) { Console.WriteLine("No obfuscated assembly path specified; use -h for help"); return; } if (!Directory.Exists(options.OutputDir)) { Directory.CreateDirectory(options.OutputDir); } IIl2CppMetadataAccess gameAssemblies; using (new TimingCookie("Reading assemblies")) { gameAssemblies = new CecilMetadataAccess(Directory.EnumerateFiles(options.DeobfuscationNewAssembliesPath, "*.dll")); } RewriteGlobalContext rewriteGlobalContext; using (new TimingCookie("Creating rewrite assemblies")) { rewriteGlobalContext = new RewriteGlobalContext(options, gameAssemblies, NullMetadataAccess.Instance); } using (new TimingCookie("Computing renames")) { Pass05CreateRenameGroups.DoPass(rewriteGlobalContext); } using (new TimingCookie("Creating typedefs")) { Pass10CreateTypedefs.DoPass(rewriteGlobalContext); } using (new TimingCookie("Computing struct blittability")) { Pass11ComputeTypeSpecifics.DoPass(rewriteGlobalContext); } using (new TimingCookie("Filling typedefs")) { Pass12FillTypedefs.DoPass(rewriteGlobalContext); } using (new TimingCookie("Filling generic constraints")) { Pass13FillGenericConstraints.DoPass(rewriteGlobalContext); } using (new TimingCookie("Creating members")) { Pass15GenerateMemberContexts.DoPass(rewriteGlobalContext); } IIl2CppMetadataAccess gameAssemblies2; using (new TimingCookie("Reading clean assemblies")) { gameAssemblies2 = new CecilMetadataAccess(options.Source); } RewriteGlobalContext rewriteGlobalContext2; using (new TimingCookie("Creating clean rewrite assemblies")) { rewriteGlobalContext2 = new RewriteGlobalContext(options, gameAssemblies2, NullMetadataAccess.Instance); } using (new TimingCookie("Computing clean assembly renames")) { Pass05CreateRenameGroups.DoPass(rewriteGlobalContext2); } using (new TimingCookie("Creating clean assembly typedefs")) { Pass10CreateTypedefs.DoPass(rewriteGlobalContext2); } Dictionary usedNames = new Dictionary(); StreamWriter writer; using (FileStream stream = new FileStream(options.OutputDir + Path.DirectorySeparatorChar + "RenameMap.csv.gz", FileMode.Create, FileAccess.Write)) { using GZipStream stream2 = new GZipStream(stream, CompressionLevel.Optimal, leaveOpen: true); writer = new StreamWriter(stream2, Encoding.UTF8, 65536, leaveOpen: true); try { foreach (AssemblyRewriteContext assembly in rewriteGlobalContext.Assemblies) { if (options.DeobfuscationGenerationAssemblies.Count > 0 && !options.DeobfuscationGenerationAssemblies.Contains(((AssemblyNameReference)assembly.NewAssembly.Name).Name)) { continue; } AssemblyRewriteContext cleanAssembly = rewriteGlobalContext2.GetAssemblyByName(((AssemblyNameReference)assembly.OriginalAssembly.Name).Name); foreach (TypeRewriteContext type in assembly.Types) { if (type.NewType.DeclaringType == null) { DoType(type, null); } } void DoType(TypeRewriteContext typeContext, TypeRewriteContext? enclosingType) { //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) if (typeContext.OriginalNameWasObfuscated) { (TypeRewriteContext, int) tuple = FindBestMatchType(typeContext, cleanAssembly, enclosingType); if (tuple.Item1 != null && (!usedNames.TryGetValue(tuple.Item1.NewType, out (string, int, bool) value) || value.Item2 < tuple.Item2)) { usedNames[tuple.Item1.NewType] = (((TypeReference)(object)typeContext.NewType).GetNamespacePrefix() + "." + ((MemberReference)typeContext.NewType).Name, tuple.Item2, ((TypeReference)typeContext.OriginalType).Namespace != ((TypeReference)tuple.Item1.OriginalType).Namespace); if (typeContext.OriginalType.IsEnum) { DoEnum(typeContext, tuple.Item1); } Enumerator enumerator5 = typeContext.OriginalType.NestedTypes.GetEnumerator(); try { while (enumerator5.MoveNext()) { TypeDefinition current5 = enumerator5.Current; DoType(typeContext.AssemblyContext.GetContextForOriginalType(current5), tuple.Item1); } } finally { ((IDisposable)enumerator5).Dispose(); } } } } } foreach (KeyValuePair item in usedNames) { writer.WriteLine(item.Value.Item1 + ";" + (item.Value.Item3 ? (((TypeReference)item.Key).Namespace + ".") : "") + ((MemberReference)item.Key).Name + ";" + item.Value.Item2); } Logger.Instance.LogInformation("Done!"); rewriteGlobalContext.Dispose(); } finally { if (writer != null) { ((IDisposable)writer).Dispose(); } } } void DoEnum(TypeRewriteContext obfuscatedType, TypeRewriteContext cleanType) { //IL_000b: 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) Enumerator enumerator4 = obfuscatedType.OriginalType.Fields.GetEnumerator(); try { while (enumerator4.MoveNext()) { FieldDefinition current4 = enumerator4.Current; if (((MemberReference)current4).Name.IsObfuscated(obfuscatedType.AssemblyContext.GlobalContext.Options)) { FieldDefinition val = cleanType.OriginalType.Fields[obfuscatedType.OriginalType.Fields.IndexOf(current4)]; writer.WriteLine(((TypeReference)(object)obfuscatedType.NewType).GetNamespacePrefix() + "." + ((MemberReference)obfuscatedType.NewType).Name + "::" + Pass22GenerateEnums.GetUnmangledName(current4) + ";" + ((MemberReference)val).Name + ";0"); } } } finally { ((IDisposable)enumerator4).Dispose(); } } } private static (TypeRewriteContext?, int) FindBestMatchType(TypeRewriteContext obfType, AssemblyRewriteContext cleanAssembly, TypeRewriteContext? enclosingCleanType) { //IL_02b5: 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_0380: Unknown result type (might be due to invalid IL or missing references) //IL_0385: Unknown result type (might be due to invalid IL or missing references) int num = 0; TypeReference baseType = obfType.OriginalType.BaseType; while (baseType != null) { TypeRewriteContext typeRewriteContext = obfType.AssemblyContext.GlobalContext.TryGetNewTypeForOriginal(baseType.Resolve()); if (typeRewriteContext == null || !typeRewriteContext.OriginalNameWasObfuscated) { break; } num++; baseType = typeRewriteContext.OriginalType.BaseType; } int num2 = int.MinValue; TypeRewriteContext item = null; foreach (TypeRewriteContext item2 in ((enclosingCleanType != null) ? ((IEnumerable)enclosingCleanType.OriginalType.NestedTypes).Select((TypeDefinition it) => cleanAssembly.GlobalContext.GetNewTypeForOriginal(it)) : null) ?? cleanAssembly.Types.Where((TypeRewriteContext it) => it.NewType.DeclaringType == null)) { if (obfType.OriginalType.HasMethods != item2.OriginalType.HasMethods || obfType.OriginalType.HasFields != item2.OriginalType.HasFields || (obfType.OriginalType.IsEnum && obfType.OriginalType.Fields.Count != item2.OriginalType.Fields.Count)) { continue; } int num3 = 0; TypeReference val = item2.OriginalType.BaseType; int num4 = 0; while (val != null && (!(((val != null) ? ((MemberReference)val).Name : null) == ((baseType != null) ? ((MemberReference)baseType).Name : null)) || !(((val != null) ? val.Namespace : null) == ((baseType != null) ? baseType.Namespace : null)))) { val = ((val != null) ? val.Resolve().BaseType : null); num4++; } if (val == null && baseType != null) { continue; } int num5 = Math.Abs(num4 - num); if (num5 > 1) { continue; } num3 -= num5 * 50; num3 -= Math.Abs(item2.OriginalType.Fields.Count - obfType.OriginalType.Fields.Count) * 5; num3 -= Math.Abs(obfType.OriginalType.NestedTypes.Count - item2.OriginalType.NestedTypes.Count) * 10; num3 -= Math.Abs(obfType.OriginalType.Properties.Count - item2.OriginalType.Properties.Count) * 5; num3 -= Math.Abs(obfType.OriginalType.Interfaces.Count - item2.OriginalType.Interfaces.Count) * 35; GeneratorOptions options = obfType.AssemblyContext.GlobalContext.Options; Enumerator enumerator2 = obfType.OriginalType.Fields.GetEnumerator(); try { while (enumerator2.MoveNext()) { FieldDefinition obfuscatedField = enumerator2.Current; if (((MemberReference)obfuscatedField).Name.IsObfuscated(options)) { int num6 = ((IEnumerable)item2.OriginalType.Fields).Max((FieldDefinition it) => TypeMatchWeight(((FieldReference)obfuscatedField).FieldType, ((FieldReference)it).FieldType, options)); num3 += num6 * ((num6 < 0) ? 10 : 2); } else if (((IEnumerable)item2.OriginalType.Fields).Any((FieldDefinition it) => ((MemberReference)it).Name == ((MemberReference)obfuscatedField).Name)) { num3 += 10; } } } finally { ((IDisposable)enumerator2).Dispose(); } Enumerator enumerator3 = obfType.OriginalType.Methods.GetEnumerator(); try { while (enumerator3.MoveNext()) { MethodDefinition obfuscatedMethod = enumerator3.Current; if (((MemberReference)obfuscatedMethod).Name.Contains(".ctor")) { continue; } if (((MemberReference)obfuscatedMethod).Name.IsObfuscated(options)) { int num7 = ((IEnumerable)item2.OriginalType.Methods).Max((MethodDefinition it) => MethodSignatureMatchWeight(obfuscatedMethod, it, options)); num3 += num7 * ((num7 >= 0) ? 1 : 10); } else if (((IEnumerable)item2.OriginalType.Methods).Any((MethodDefinition it) => ((MemberReference)it).Name == ((MemberReference)obfuscatedMethod).Name)) { num3 += ((MemberReference)obfuscatedMethod).Name.Length / 10 * 5 + 1; } } } finally { ((IDisposable)enumerator3).Dispose(); } if (num3 == num2) { item = null; } else if (num3 > num2) { num2 = num3; item = item2; } } return (item, num2); } private static int TypeMatchWeight(TypeReference a, TypeReference b, GeneratorOptions options) { if (((object)a).GetType() != ((object)b).GetType()) { return -1; } int runningSum = 0; ArrayType val = (ArrayType)(object)((a is ArrayType) ? a : null); if (val == null) { ByReferenceType val2 = (ByReferenceType)(object)((a is ByReferenceType) ? a : null); if (val2 == null) { GenericInstanceType val3 = (GenericInstanceType)(object)((a is GenericInstanceType) ? a : null); if (val3 == null) { if (a is GenericParameter) { if (!(b is GenericParameter)) { return -1; } return 5; } if (a.IsNested) { if (!b.IsNested) { return -1; } if (((MemberReference)a).Name.IsObfuscated(options)) { return 0; } if (TypeMatchWeight(((MemberReference)a).DeclaringType, ((MemberReference)b).DeclaringType, options) == -1 || ((MemberReference)a).Name != ((MemberReference)b).Name) { return -1; } return 1; } if (((MemberReference)a).Name.IsObfuscated(options)) { return 0; } if (!(((MemberReference)a).Name == ((MemberReference)b).Name) || !(a.Namespace == b.Namespace)) { return -1; } return 1; } GenericInstanceType val4 = (GenericInstanceType)(object)((b is GenericInstanceType) ? b : null); if (val4 == null) { return -1; } if (val3.GenericArguments.Count != val4.GenericArguments.Count) { return -1; } Accumulate(TypeMatchWeight(((TypeSpecification)val3).ElementType, ((TypeSpecification)val4).ElementType, options)); for (int j = 0; j < val3.GenericArguments.Count; j++) { Accumulate(TypeMatchWeight(val3.GenericArguments[j], val4.GenericArguments[j], options)); } return runningSum * 5; } ByReferenceType val5 = (ByReferenceType)(object)((b is ByReferenceType) ? b : null); if (val5 == null) { return -1; } return TypeMatchWeight(((TypeSpecification)val2).ElementType, ((TypeSpecification)val5).ElementType, options) * 5; } ArrayType val6 = (ArrayType)(object)((b is ArrayType) ? b : null); if (val6 == null) { return -1; } return TypeMatchWeight(((TypeSpecification)val).ElementType, ((TypeSpecification)val6).ElementType, options) * 5; void Accumulate(int i) { if (i < 0 || runningSum < 0) { runningSum = -1; } else { runningSum += i; } } } private static int MethodSignatureMatchWeight(MethodDefinition a, MethodDefinition b, GeneratorOptions options) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) if (((MethodReference)a).Parameters.Count != ((MethodReference)b).Parameters.Count || a.IsStatic != b.IsStatic || (a.Attributes & 7) != (b.Attributes & 7)) { return -1; } int runningSum = TypeMatchWeight(((MethodReference)a).ReturnType, ((MethodReference)b).ReturnType, options); if (runningSum == -1) { return -1; } for (int j = 0; j < ((MethodReference)a).Parameters.Count; j++) { Accumulate(TypeMatchWeight(((ParameterReference)((MethodReference)a).Parameters[j]).ParameterType, ((ParameterReference)((MethodReference)b).Parameters[j]).ParameterType, options)); } return runningSum * (((MethodReference)a).Parameters.Count + 1); void Accumulate(int i) { if (i < 0 || runningSum < 0) { runningSum = -1; } else { runningSum += i; } } } public void Dispose() { } } public static class InteropAssemblyGenerator { public static Il2CppInteropGenerator AddInteropAssemblyGenerator(this Il2CppInteropGenerator gen) { return gen.AddRunner(); } } internal class InteropAssemblyGeneratorRunner : IRunner, IDisposable { public void Run(GeneratorOptions options) { if (options.Source == null || !options.Source.Any()) { Console.WriteLine("No input specified; use -h for help"); return; } if (string.IsNullOrEmpty(options.OutputDir)) { Console.WriteLine("No target dir specified; use -h for help"); return; } if (!Directory.Exists(options.OutputDir)) { Directory.CreateDirectory(options.OutputDir); } IIl2CppMetadataAccess gameAssemblies; using (new TimingCookie("Reading assemblies")) { gameAssemblies = new CecilMetadataAccess(options.Source); } IMetadataAccess unityAssemblies; if (!string.IsNullOrEmpty(options.UnityBaseLibsDir)) { using (new TimingCookie("Reading unity assemblies")) { unityAssemblies = new CecilMetadataAccess(Directory.EnumerateFiles(options.UnityBaseLibsDir, "*.dll")); } } else { unityAssemblies = NullMetadataAccess.Instance; } RewriteGlobalContext rewriteGlobalContext; using (new TimingCookie("Creating rewrite assemblies")) { rewriteGlobalContext = new RewriteGlobalContext(options, gameAssemblies, unityAssemblies); } using (new TimingCookie("Computing renames")) { Pass05CreateRenameGroups.DoPass(rewriteGlobalContext); } using (new TimingCookie("Creating typedefs")) { Pass10CreateTypedefs.DoPass(rewriteGlobalContext); } using (new TimingCookie("Computing struct blittability")) { Pass11ComputeTypeSpecifics.DoPass(rewriteGlobalContext); } using (new TimingCookie("Filling typedefs")) { Pass12FillTypedefs.DoPass(rewriteGlobalContext); } using (new TimingCookie("Filling generic constraints")) { Pass13FillGenericConstraints.DoPass(rewriteGlobalContext); } using (new TimingCookie("Creating members")) { Pass15GenerateMemberContexts.DoPass(rewriteGlobalContext); } using (new TimingCookie("Scanning method cross-references")) { Pass16ScanMethodRefs.DoPass(rewriteGlobalContext, options); } using (new TimingCookie("Finalizing method declarations")) { Pass18FinalizeMethodContexts.DoPass(rewriteGlobalContext); } Logger.Instance.LogInformation("{DeadMethodsCount} total potentially dead methods", Pass18FinalizeMethodContexts.TotalPotentiallyDeadMethods); using (new TimingCookie("Filling method parameters")) { Pass19CopyMethodParameters.DoPass(rewriteGlobalContext); } using (new TimingCookie("Creating static constructors")) { Pass20GenerateStaticConstructors.DoPass(rewriteGlobalContext); } using (new TimingCookie("Creating value type fields")) { Pass21GenerateValueTypeFields.DoPass(rewriteGlobalContext); } using (new TimingCookie("Creating enums")) { Pass22GenerateEnums.DoPass(rewriteGlobalContext); } using (new TimingCookie("Creating IntPtr constructors")) { Pass23GeneratePointerConstructors.DoPass(rewriteGlobalContext); } using (new TimingCookie("Creating non-blittable struct constructors")) { Pass25GenerateNonBlittableValueTypeDefaultCtors.DoPass(rewriteGlobalContext); } using (new TimingCookie("Creating generic method static constructors")) { Pass30GenerateGenericMethodStoreConstructors.DoPass(rewriteGlobalContext); } using (new TimingCookie("Creating field accessors")) { Pass40GenerateFieldAccessors.DoPass(rewriteGlobalContext); } using (new TimingCookie("Filling methods")) { Pass50GenerateMethods.DoPass(rewriteGlobalContext); } using (new TimingCookie("Generating implicit conversions")) { Pass60AddImplicitConversions.DoPass(rewriteGlobalContext); } using (new TimingCookie("Creating properties")) { Pass70GenerateProperties.DoPass(rewriteGlobalContext); } if (options.UnityBaseLibsDir != null) { using (new TimingCookie("Unstripping types")) { Pass79UnstripTypes.DoPass(rewriteGlobalContext); } using (new TimingCookie("Unstripping fields")) { Pass80UnstripFields.DoPass(rewriteGlobalContext); } using (new TimingCookie("Unstripping methods")) { Pass80UnstripMethods.DoPass(rewriteGlobalContext); } using (new TimingCookie("Unstripping method bodies")) { Pass81FillUnstrippedMethodBodies.DoPass(rewriteGlobalContext); } } else { Logger.Instance.LogWarning("Not performing unstripping as unity libs are not specified"); } using (new TimingCookie("Writing xref cache")) { Pass89GenerateMethodXrefCache.DoPass(rewriteGlobalContext, options); } using (new TimingCookie("Writing assemblies")) { Pass90WriteToDisk.DoPass(rewriteGlobalContext, options); } using (new TimingCookie("Writing method pointer map")) { Pass91GenerateMethodPointerMap.DoPass(rewriteGlobalContext, options); } Logger.Instance.LogInformation("Done!"); rewriteGlobalContext.Dispose(); } public void Dispose() { } } internal interface IRunner : IDisposable { void Run(GeneratorOptions options); } } namespace Il2CppInterop.Generator.Passes { public static class Pass05CreateRenameGroups { private static readonly string[] ClassAccessNames = new string[8] { "Private", "Public", "NPublic", "NPrivate", "NProtected", "NInternal", "NFamAndAssem", "NFamOrAssem" }; public static void DoPass(RewriteGlobalContext context) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) foreach (AssemblyRewriteContext assembly in context.Assemblies) { Enumerator enumerator2 = assembly.OriginalAssembly.MainModule.Types.GetEnumerator(); try { while (enumerator2.MoveNext()) { TypeDefinition current = enumerator2.Current; ProcessType(context, current, allowExtraHeuristics: false); } } finally { ((IDisposable)enumerator2).Dispose(); } } foreach (KeyValuePair<(object, string, int), List> item in context.RenameGroups.Where((KeyValuePair<(object, string, int), List> it) => it.Value.Count > 1).ToList()) { context.RenameGroups.Remove(item.Key); foreach (TypeDefinition item2 in item.Value) { context.RenamedTypes.Remove(item2); } } foreach (KeyValuePair renamedType in context.RenamedTypes) { context.PreviousRenamedTypes[renamedType.Key] = renamedType.Value; } foreach (AssemblyRewriteContext assembly2 in context.Assemblies) { Enumerator enumerator2 = assembly2.OriginalAssembly.MainModule.Types.GetEnumerator(); try { while (enumerator2.MoveNext()) { TypeDefinition current5 = enumerator2.Current; ProcessType(context, current5, allowExtraHeuristics: true); } } finally { ((IDisposable)enumerator2).Dispose(); } } } private static void ProcessType(RewriteGlobalContext context, TypeDefinition originalType, bool allowExtraHeuristics) { //IL_0006: 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) Enumerator enumerator = originalType.NestedTypes.GetEnumerator(); try { while (enumerator.MoveNext()) { TypeDefinition current = enumerator.Current; ProcessType(context, current, allowExtraHeuristics); } } finally { ((IDisposable)enumerator).Dispose(); } if (context.RenamedTypes.ContainsKey(originalType)) { return; } string unobfuscatedNameBase = GetUnobfuscatedNameBase(context, originalType, allowExtraHeuristics); if (unobfuscatedNameBase != null) { context.RenameGroups.GetOrCreate((((object)originalType.DeclaringType) ?? ((object)((TypeReference)originalType).Namespace), unobfuscatedNameBase, ((TypeReference)originalType).GenericParameters.Count), ((object, string, int) _) => new List()).Add(originalType); context.RenamedTypes[originalType] = unobfuscatedNameBase; } } private static string? GetUnobfuscatedNameBase(RewriteGlobalContext context, TypeDefinition typeDefinition, bool allowExtraHeuristics) { //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: 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_0217: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_03db: Unknown result type (might be due to invalid IL or missing references) //IL_03e0: Unknown result type (might be due to invalid IL or missing references) //IL_0378: Unknown result type (might be due to invalid IL or missing references) //IL_037d: Unknown result type (might be due to invalid IL or missing references) //IL_0420: Unknown result type (might be due to invalid IL or missing references) //IL_0425: Unknown result type (might be due to invalid IL or missing references) GeneratorOptions options = context.Options; if (options.PassthroughNames || !((MemberReference)typeDefinition).Name.IsObfuscated(context.Options)) { return null; } int num = 0; TypeReference val = typeDefinition.BaseType; while (val != null && ((MemberReference)val).Name.IsObfuscated(context.Options)) { TypeReference baseType = val.Resolve().BaseType; val = (TypeReference)(object)((baseType != null) ? baseType.Resolve() : null); num++; } IEnumerable enumerable = from it in (IEnumerable)typeDefinition.Interfaces select it.InterfaceType into it where !((MemberReference)it).Name.IsObfuscated(context.Options) select it; string value = ClassAccessNames[typeDefinition.Attributes & 7]; string text = (typeDefinition.IsInterface ? "Interface" : (((TypeReference)typeDefinition).IsValueType ? "Struct" : "Class")); string value2 = (((MemberReference)typeDefinition).Name.StartsWith("<") ? "CompilerGenerated" : ""); string value3 = (typeDefinition.IsAbstract ? "Abstract" : ""); string value4 = (typeDefinition.IsSealed ? "Sealed" : ""); string value5 = (typeDefinition.IsSpecialName ? "SpecialName" : ""); StringBuilder stringBuilder = new StringBuilder(); object obj; if (val == null) { obj = null; } else { List list = val.GenericNameToStrings(context); obj = ((list != null) ? list.ConcatAll() : null); } if (obj == null) { obj = text; } stringBuilder.Append((string?)obj); if (num > 0) { stringBuilder.Append(num); } stringBuilder.Append(value2); stringBuilder.Append(value); stringBuilder.Append(value3); stringBuilder.Append(value4); stringBuilder.Append(value5); foreach (TypeReference item in enumerable) { stringBuilder.Append(item.GenericNameToStrings(context).ConcatAll()); } UniquificationContext uniquificationContext = new UniquificationContext(options); Enumerator enumerator2 = typeDefinition.Fields.GetEnumerator(); try { while (enumerator2.MoveNext()) { FieldDefinition current2 = enumerator2.Current; if (!typeDefinition.IsEnum) { uniquificationContext.Push(((FieldReference)current2).FieldType.GenericNameToStrings(context)); } uniquificationContext.Push(((MemberReference)current2).Name); if (uniquificationContext.CheckFull()) { break; } } } finally { ((IDisposable)enumerator2).Dispose(); } if (typeDefinition.IsEnum) { uniquificationContext.Push(typeDefinition.Fields.Count + "v"); } Enumerator enumerator3 = typeDefinition.Properties.GetEnumerator(); try { while (enumerator3.MoveNext()) { PropertyDefinition current3 = enumerator3.Current; uniquificationContext.Push(((PropertyReference)current3).PropertyType.GenericNameToStrings(context)); uniquificationContext.Push(((MemberReference)current3).Name); if (uniquificationContext.CheckFull()) { break; } } } finally { ((IDisposable)enumerator3).Dispose(); } if (((val != null) ? ((MemberReference)val).Name : null) == "MulticastDelegate") { MethodDefinition val2 = ((IEnumerable)typeDefinition.Methods).SingleOrDefault((Func)((MethodDefinition it) => ((MemberReference)it).Name == "Invoke")); if (val2 != null) { uniquificationContext.Push(((MethodReference)val2).ReturnType.GenericNameToStrings(context)); Enumerator enumerator4 = ((MethodReference)val2).Parameters.GetEnumerator(); try { while (enumerator4.MoveNext()) { ParameterDefinition current4 = enumerator4.Current; uniquificationContext.Push(((ParameterReference)current4).ParameterType.GenericNameToStrings(context)); if (uniquificationContext.CheckFull()) { break; } } } finally { ((IDisposable)enumerator4).Dispose(); } } } if (typeDefinition.IsInterface || allowExtraHeuristics) { Enumerator enumerator5 = typeDefinition.Methods.GetEnumerator(); try { while (enumerator5.MoveNext()) { MethodDefinition current5 = enumerator5.Current; uniquificationContext.Push(((MemberReference)current5).Name); uniquificationContext.Push(((MethodReference)current5).ReturnType.GenericNameToStrings(context)); Enumerator enumerator4 = ((MethodReference)current5).Parameters.GetEnumerator(); try { while (enumerator4.MoveNext()) { ParameterDefinition current6 = enumerator4.Current; uniquificationContext.Push(((ParameterReference)current6).Name); uniquificationContext.Push(((ParameterReference)current6).ParameterType.GenericNameToStrings(context)); if (uniquificationContext.CheckFull()) { break; } } } finally { ((IDisposable)enumerator4).Dispose(); } if (uniquificationContext.CheckFull()) { break; } } } finally { ((IDisposable)enumerator5).Dispose(); } } stringBuilder.Append(uniquificationContext.GetTop()); return stringBuilder.ToString(); } private static string ConcatAll(this List strings) { return string.Concat(strings); } private static string NameOrRename(this TypeReference typeRef, RewriteGlobalContext context) { TypeDefinition val = typeRef.Resolve(); if (val != null && context.PreviousRenamedTypes.TryGetValue(val, out var value)) { return (value.StableHash() % (ulong)Math.Pow(10.0, context.Options.TypeDeobfuscationCharsPerUniquifier)).ToString(); } return ((MemberReference)typeRef).Name; } private static List GenericNameToStrings(this TypeReference typeRef, RewriteGlobalContext context) { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) ArrayType val = (ArrayType)(object)((typeRef is ArrayType) ? typeRef : null); if (val != null) { return ((TypeSpecification)val).ElementType.GenericNameToStrings(context); } GenericInstanceType val2 = (GenericInstanceType)(object)((typeRef is GenericInstanceType) ? typeRef : null); if (val2 != null) { string text = ((TypeReference)val2).GetElementType().NameOrRename(context); int num = text.IndexOf('`'); if (num >= 0) { text = text.Substring(0, num); } List list = new List(); list.Add(text); list.Add(val2.GenericArguments.Count.ToString()); Enumerator enumerator = val2.GenericArguments.GetEnumerator(); try { while (enumerator.MoveNext()) { TypeReference current = enumerator.Current; list.AddRange(current.GenericNameToStrings(context)); } return list; } finally { ((IDisposable)enumerator).Dispose(); } } if (typeRef.NameOrRename(context).IsObfuscated(context.Options)) { return new List { "Obf" }; } return new List { typeRef.NameOrRename(context) }; } } public static class Pass10CreateTypedefs { public static void DoPass(RewriteGlobalContext context) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) foreach (AssemblyRewriteContext assembly in context.Assemblies) { Enumerator enumerator2 = assembly.OriginalAssembly.MainModule.Types.GetEnumerator(); try { while (enumerator2.MoveNext()) { TypeDefinition current2 = enumerator2.Current; if (!IsCpp2ILInjectedType(current2) && ((MemberReference)current2).Name != "") { ProcessType(current2, assembly, null); } } } finally { ((IDisposable)enumerator2).Dispose(); } } static bool IsCpp2ILInjectedType(TypeDefinition type) { return ((TypeReference)type).Namespace?.StartsWith("Cpp2ILInjected", StringComparison.Ordinal) ?? false; } } private static void ProcessType(TypeDefinition type, AssemblyRewriteContext assemblyContext, TypeDefinition? parentType) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //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) (string, string) convertedTypeName = GetConvertedTypeName(assemblyContext.GlobalContext, type, parentType); TypeDefinition val = new TypeDefinition(convertedTypeName.Item1 ?? GetNamespace(type, assemblyContext), convertedTypeName.Item2, AdjustAttributes(type.Attributes)); val.IsSequentialLayout = false; if (type.IsSealed && type.IsAbstract) { bool isSealed = (val.IsAbstract = true); val.IsSealed = isSealed; } if (parentType == null) { assemblyContext.NewAssembly.MainModule.Types.Add(val); } else { parentType.NestedTypes.Add(val); val.DeclaringType = parentType; } Enumerator enumerator = type.NestedTypes.GetEnumerator(); try { while (enumerator.MoveNext()) { ProcessType(enumerator.Current, assemblyContext, val); } } finally { ((IDisposable)enumerator).Dispose(); } assemblyContext.RegisterTypeRewrite(new TypeRewriteContext(assemblyContext, type, val)); static string GetNamespace(TypeDefinition type, AssemblyRewriteContext assemblyContext) { if (((MemberReference)type).Name == "" || type.DeclaringType != null) { return ((TypeReference)type).Namespace; } return ((TypeReference)type).Namespace.UnSystemify(assemblyContext.GlobalContext.Options); } } internal static (string? Namespace, string Name) GetConvertedTypeName(RewriteGlobalContext assemblyContextGlobalContext, TypeDefinition type, TypeDefinition? enclosingType) { if (assemblyContextGlobalContext.Options.PassthroughNames) { return (null, ((MemberReference)type).Name); } if (((MemberReference)type).Name.IsObfuscated(assemblyContextGlobalContext.Options)) { string text = assemblyContextGlobalContext.RenamedTypes[type]; int count = ((TypeReference)type).GenericParameters.Count; List list = assemblyContextGlobalContext.RenameGroups[(((object)type.DeclaringType) ?? ((object)((TypeReference)type).Namespace), text, count)]; string text2 = ((count == 0) ? "" : ("`" + count)); string text3 = text + ((list.Count == 1) ? "Unique" : list.IndexOf(type).ToString()) + text2; string text4 = ((enclosingType == null) ? ((TypeReference)type).Namespace : (((TypeReference)(object)enclosingType).GetNamespacePrefix() + "." + ((MemberReference)enclosingType).Name)); if (assemblyContextGlobalContext.Options.RenameMap.TryGetValue(text4 + "." + text3, out var newName)) { if (((IEnumerable)((MemberReference)type).Module.Types).Any((TypeDefinition t) => ((MemberReference)t).FullName == newName)) { Logger.Instance.LogWarning("[Rename map issue] {NewName} already exists in {ModuleName} (mapped from {MappedNamespace}.{MappedType})", newName, ((ModuleReference)((MemberReference)type).Module).Name, text4, text3); newName += "_Duplicate"; } int num = newName.LastIndexOf("."); if (num >= 0) { string item = newName.Substring(0, num); string item2 = newName.Substring(num + 1); return (item, item2); } text3 = newName; } return (null, text3); } if (((MemberReference)type).Name.IsInvalidInSource()) { return (null, ((MemberReference)type).Name.FilterInvalidInSourceChars()); } return (null, ((MemberReference)type).Name); } private static TypeAttributes AdjustAttributes(TypeAttributes typeAttributes) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0014: 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_0016: 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_001f: 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_001b: Invalid comparison between Unknown and I4 //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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) typeAttributes = (TypeAttributes)(typeAttributes | 0x100000); typeAttributes = (TypeAttributes)(typeAttributes & -161); TypeAttributes val = (TypeAttributes)(typeAttributes & 7); if ((int)val == 0 || (int)val == 1) { return (TypeAttributes)(typeAttributes | 1); } return (TypeAttributes)((typeAttributes & -8) | 2); } } public static class Pass11ComputeTypeSpecifics { public static void DoPass(RewriteGlobalContext context) { foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { ComputeSpecifics(type); } } } private static void ComputeSpecifics(TypeRewriteContext typeContext) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) if (typeContext.ComputedTypeSpecifics != 0) { return; } typeContext.ComputedTypeSpecifics = TypeRewriteContext.TypeSpecifics.Computing; Enumerator enumerator = typeContext.OriginalType.Fields.GetEnumerator(); try { while (enumerator.MoveNext()) { FieldDefinition current = enumerator.Current; if (((ICustomAttributeProvider)(object)current).ExtractFieldOffset() >= 134217728) { typeContext.ComputedTypeSpecifics = TypeRewriteContext.TypeSpecifics.NonBlittableStruct; return; } if (current.IsStatic) { continue; } TypeReference fieldType = ((FieldReference)current).FieldType; if (!fieldType.IsPrimitive && !fieldType.IsPointer) { if (((MemberReference)fieldType).FullName == "System.String" || ((MemberReference)fieldType).FullName == "System.Object" || fieldType.IsArray || fieldType.IsByReference || fieldType.IsGenericParameter || fieldType.IsGenericInstance) { typeContext.ComputedTypeSpecifics = TypeRewriteContext.TypeSpecifics.NonBlittableStruct; return; } TypeRewriteContext newTypeForOriginal = typeContext.AssemblyContext.GlobalContext.GetNewTypeForOriginal(fieldType.Resolve()); ComputeSpecifics(newTypeForOriginal); if (newTypeForOriginal.ComputedTypeSpecifics != TypeRewriteContext.TypeSpecifics.BlittableStruct) { typeContext.ComputedTypeSpecifics = TypeRewriteContext.TypeSpecifics.NonBlittableStruct; return; } } } } finally { ((IDisposable)enumerator).Dispose(); } typeContext.ComputedTypeSpecifics = TypeRewriteContext.TypeSpecifics.BlittableStruct; } } public static class Pass12FillTypedefs { public static void DoPass(RewriteGlobalContext context) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { Enumerator enumerator3 = ((TypeReference)type.OriginalType).GenericParameters.GetEnumerator(); try { while (enumerator3.MoveNext()) { GenericParameter current3 = enumerator3.Current; GenericParameter val = new GenericParameter(((MemberReference)current3).Name, (IGenericParameterProvider)(object)type.NewType); ((TypeReference)type.NewType).GenericParameters.Add(val); val.Attributes = current3.Attributes.StripValueTypeConstraint(); } } finally { ((IDisposable)enumerator3).Dispose(); } if (type.OriginalType.IsEnum) { type.NewType.BaseType = assembly.Imports.Module.Enum(); } else if (type.ComputedTypeSpecifics == TypeRewriteContext.TypeSpecifics.BlittableStruct) { type.NewType.BaseType = assembly.Imports.Module.ValueType(); } } } foreach (AssemblyRewriteContext assembly2 in context.Assemblies) { foreach (TypeRewriteContext type2 in assembly2.Types) { if (!type2.OriginalType.IsEnum && type2.ComputedTypeSpecifics != TypeRewriteContext.TypeSpecifics.BlittableStruct) { type2.NewType.BaseType = assembly2.RewriteTypeRef(type2.OriginalType.BaseType); } } } } } public static class Pass13FillGenericConstraints { public static void DoPass(RewriteGlobalContext context) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Expected O, but got Unknown foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { for (int i = 0; i < ((TypeReference)type.OriginalType).GenericParameters.Count; i++) { GenericParameter obj = ((TypeReference)type.OriginalType).GenericParameters[i]; GenericParameter val = ((TypeReference)type.NewType).GenericParameters[i]; Enumerator enumerator3 = obj.Constraints.GetEnumerator(); try { while (enumerator3.MoveNext()) { GenericParameterConstraint current3 = enumerator3.Current; if (!(((MemberReference)current3.ConstraintType).FullName == "System.ValueType")) { TypeDefinition obj2 = current3.ConstraintType.Resolve(); if (obj2 == null || !obj2.IsInterface) { val.Constraints.Add(new GenericParameterConstraint(assembly.RewriteTypeRef(current3.ConstraintType))); } } } } finally { ((IDisposable)enumerator3).Dispose(); } } } } } } public static class Pass15GenerateMemberContexts { public static bool HasObfuscatedMethods; public static void DoPass(RewriteGlobalContext context) { foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { type.AddMembers(); } } } } public static class Pass16ScanMethodRefs { public static readonly HashSet NonDeadMethods = new HashSet(); public static IDictionary> MapOfCallers = new Dictionary>(); public unsafe static void DoPass(RewriteGlobalContext context, GeneratorOptions options) { if (string.IsNullOrEmpty(options.GameAssemblyPath)) { Pass15GenerateMemberContexts.HasObfuscatedMethods = false; return; } ConcurrentDictionary> methodToCalleesMap; using (MemoryMappedFile memoryMappedFile = MemoryMappedFile.CreateFromFile(options.GameAssemblyPath, FileMode.Open, null, 0L, MemoryMappedFileAccess.Read)) { using MemoryMappedViewAccessor memoryMappedViewAccessor = memoryMappedFile.CreateViewAccessor(0L, 0L, MemoryMappedFileAccess.Read); byte* pointer = null; memoryMappedViewAccessor.SafeMemoryMappedViewHandle.AcquirePointer(ref pointer); nint gameAssemblyPtr = (nint)pointer; context.HasGcWbarrierFieldWrite = FindByteSequence(gameAssemblyPtr, memoryMappedViewAccessor.Capacity, "il2cpp_gc_wbarrier_set_field"); if (!Pass15GenerateMemberContexts.HasObfuscatedMethods) { return; } ConcurrentDictionary> methodToCallersMap = new ConcurrentDictionary>(); methodToCalleesMap = new ConcurrentDictionary>(); context.MethodStartAddresses.Sort(); context.Assemblies.SelectMany((AssemblyRewriteContext it) => it.Types).SelectMany((TypeRewriteContext it) => it.Methods).AsParallel() .ForAll(delegate(MethodRewriteContext originalTypeMethod) { //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Invalid comparison between Unknown and I4 //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) long fileOffset = originalTypeMethod.FileOffset; if (fileOffset == 0L) { return; } if (!options.NoXrefCache) { (originalTypeMethod.MetadataInitFlagRva, originalTypeMethod.MetadataInitTokenRva) = XrefScanMetadataGenerationUtil.FindMetadataInitForMethod(originalTypeMethod, gameAssemblyPtr); } int num = context.MethodStartAddresses.BinarySearch(fileOffset + 1); if (num < 0) { num = ~num; } long num2 = ((num >= context.MethodStartAddresses.Count) ? 1048576 : (context.MethodStartAddresses[num] - fileOffset)); foreach (XrefInstance item in XrefScanner.XrefScanImpl(XrefScanner.DecoderForAddress(IntPtr.Add(gameAssemblyPtr, (int)fileOffset), (int)num2), true)) { XrefInstance current3 = item; XrefInstance val = ((XrefInstance)(ref current3)).RelativeToBase((IntPtr)(gameAssemblyPtr + (nint)originalTypeMethod.FileOffset - (nint)originalTypeMethod.Rva)); if ((int)val.Type == 1) { IntPtr pointer2 = val.Pointer; methodToCallersMap.GetOrAdd((long)pointer2, (long _) => new List()).AddLocked(new XrefInstance((XrefType)1, (IntPtr)(nint)originalTypeMethod.Rva, val.FoundAt)); methodToCalleesMap.GetOrAdd(originalTypeMethod.Rva, (long _) => new List()).AddLocked(pointer2); } if (!options.NoXrefCache) { originalTypeMethod.XrefScanResults.Add(val); } } }); MapOfCallers = methodToCallersMap; foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { foreach (MethodRewriteContext method in type.Methods) { if (method.FileOffset != 0L) { MethodDefinition originalMethod = method.OriginalMethod; if (!((MemberReference)originalMethod).Name.IsObfuscated(options) || originalMethod.IsVirtual) { MarkMethodAlive(method.Rva); } } } } } } void MarkMethodAlive(long address) { if (!NonDeadMethods.Add(address) || !methodToCalleesMap.TryGetValue(address, out List value)) { return; } foreach (IntPtr item2 in value) { MarkMethodAlive((long)item2); } } } private unsafe static bool FindByteSequence(nint basePtr, long length, string str) { byte[] bytes = Encoding.UTF8.GetBytes(str); for (long num = 0L; num < length; num++) { int num2 = 0; while (true) { if (num2 < bytes.Length) { if (*(byte*)(basePtr + (nint)(num + num2)) != bytes[num2]) { break; } num2++; continue; } return true; } } return false; } } public static class Pass18FinalizeMethodContexts { public static int TotalPotentiallyDeadMethods; public static void DoPass(RewriteGlobalContext context) { //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { foreach (MethodRewriteContext method in type.Methods) { method.CtorPhase2(); if (!Pass15GenerateMemberContexts.HasObfuscatedMethods) { continue; } int num5 = 0; if (Pass16ScanMethodRefs.MapOfCallers.TryGetValue(method.Rva, out var value)) { num5 = value.Count; } Collection customAttributes = method.NewMethod.CustomAttributes; CustomAttribute val = new CustomAttribute(assembly.Imports.CallerCountAttributector.Value); val.ConstructorArguments.Add(new CustomAttributeArgument(assembly.Imports.Module.Int(), (object)num5)); customAttributes.Add(val); if (!Pass15GenerateMemberContexts.HasObfuscatedMethods || !method.UnmangledName.Contains("_PDM_")) { continue; } TotalPotentiallyDeadMethods++; bool flag = num5 == 0; if (((TypeReference)method.DeclaringType.OriginalType).IsNested) { if (flag) { num++; } else { num2++; } } else if (flag) { num3++; } else { num4++; } } } } if (Pass15GenerateMemberContexts.HasObfuscatedMethods) { Logger.Instance.LogTrace("Dead method statistics: 0t={Top0Caller} mt={TopNZCaller} 0n={Nested0Caller} mn={NestedNZCaller}", num3, num4, num, num2); } } } public static class Pass19CopyMethodParameters { public static void DoPass(RewriteGlobalContext context) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Expected O, but got Unknown foreach (AssemblyRewriteContext assemblyContext in context.Assemblies) { foreach (TypeRewriteContext type in assemblyContext.Types) { foreach (MethodRewriteContext method in type.Methods) { MethodDefinition originalMethod = method.OriginalMethod; MethodDefinition newMethod = method.NewMethod; Enumerator enumerator4 = ((MethodReference)originalMethod).Parameters.GetEnumerator(); try { while (enumerator4.MoveNext()) { ParameterDefinition current3 = enumerator4.Current; ParameterDefinition val = new ParameterDefinition(((ParameterReference)current3).Name.IsObfuscated(context.Options) ? $"param_{current3.Sequence}" : ((ParameterReference)current3).Name, (ParameterAttributes)(current3.Attributes & 0xDFFF), assemblyContext.RewriteTypeRef(((ParameterReference)current3).ParameterType)); if (current3.IsParamsArray()) { val.Constant = null; val.IsOptional = true; } else { val.Constant = current3.Constant; } ((MethodReference)newMethod).Parameters.Add(val); } } finally { ((IDisposable)enumerator4).Dispose(); } MethodDefinition val2 = context.CreateParamsMethod(originalMethod, newMethod, assemblyContext.Imports, (TypeReference type) => assemblyContext.RewriteTypeRef(type)); if (val2 != null) { type.NewType.Methods.Add(val2); } } } } } } public static class Pass20GenerateStaticConstructors { private static int ourTokenlessMethods; public static void DoPass(RewriteGlobalContext context) { foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { GenerateStaticProxy(assembly, type); } } Logger.Instance.LogTrace("Tokenless method count: {TokenlessMethodCount}", ourTokenlessMethods); } private static void GenerateStaticProxy(AssemblyRewriteContext assemblyContext, TypeRewriteContext typeContext) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: 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_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_03e7: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0193: 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_01b3: Expected O, but got Unknown //IL_01b8: Expected O, but got Unknown //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_0400: Unknown result type (might be due to invalid IL or missing references) //IL_0411: Unknown result type (might be due to invalid IL or missing references) //IL_0434: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Expected O, but got Unknown //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Expected O, but got Unknown //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Unknown result type (might be due to invalid IL or missing references) //IL_028f: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Expected O, but got Unknown //IL_029e: Expected O, but got Unknown //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02e0: Expected O, but got Unknown //IL_02e1: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_0325: Unknown result type (might be due to invalid IL or missing references) //IL_032f: Expected O, but got Unknown //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_0334: Expected O, but got Unknown //IL_0339: Expected O, but got Unknown //IL_033a: Unknown result type (might be due to invalid IL or missing references) //IL_0348: Unknown result type (might be due to invalid IL or missing references) //IL_034d: Unknown result type (might be due to invalid IL or missing references) //IL_0354: Unknown result type (might be due to invalid IL or missing references) //IL_035c: Unknown result type (might be due to invalid IL or missing references) //IL_0366: Expected O, but got Unknown //IL_036b: Expected O, but got Unknown //IL_036c: Unknown result type (might be due to invalid IL or missing references) //IL_0393: Unknown result type (might be due to invalid IL or missing references) //IL_0398: Unknown result type (might be due to invalid IL or missing references) //IL_03a4: Expected O, but got Unknown //IL_03a5: Unknown result type (might be due to invalid IL or missing references) //IL_03c1: Unknown result type (might be due to invalid IL or missing references) //IL_03cb: Expected O, but got Unknown //IL_03cc: Unknown result type (might be due to invalid IL or missing references) //IL_0458: Unknown result type (might be due to invalid IL or missing references) //IL_0469: Unknown result type (might be due to invalid IL or missing references) //IL_0480: Unknown result type (might be due to invalid IL or missing references) //IL_049b: Unknown result type (might be due to invalid IL or missing references) //IL_04df: Unknown result type (might be due to invalid IL or missing references) //IL_0657: Unknown result type (might be due to invalid IL or missing references) //IL_069e: Unknown result type (might be due to invalid IL or missing references) //IL_0672: Unknown result type (might be due to invalid IL or missing references) //IL_052c: Unknown result type (might be due to invalid IL or missing references) //IL_0525: Unknown result type (might be due to invalid IL or missing references) //IL_0537: Unknown result type (might be due to invalid IL or missing references) //IL_0579: Unknown result type (might be due to invalid IL or missing references) //IL_0595: Unknown result type (might be due to invalid IL or missing references) //IL_05b5: Unknown result type (might be due to invalid IL or missing references) //IL_060b: Unknown result type (might be due to invalid IL or missing references) //IL_0631: Unknown result type (might be due to invalid IL or missing references) TypeDefinition originalType = typeContext.OriginalType; TypeDefinition newType = typeContext.NewType; if (newType.IsEnum) { return; } MethodDefinition val = new MethodDefinition(".cctor", (MethodAttributes)6289, assemblyContext.Imports.Module.Void()); newType.Methods.Add(val); ILProcessor iLProcessor = val.Body.GetILProcessor(); if (((TypeReference)newType).IsNested) { iLProcessor.Emit(OpCodes.Ldsfld, assemblyContext.GlobalContext.GetNewTypeForOriginal(originalType.DeclaringType).ClassPointerFieldRef); iLProcessor.Emit(OpCodes.Ldstr, ((MemberReference)originalType).Name); iLProcessor.Emit(OpCodes.Call, assemblyContext.Imports.IL2CPP_GetIl2CppNestedType.Value); } else { iLProcessor.Emit(OpCodes.Ldstr, ((ModuleReference)((MemberReference)originalType).Module).Name); iLProcessor.Emit(OpCodes.Ldstr, ((TypeReference)originalType).Namespace); iLProcessor.Emit(OpCodes.Ldstr, ((MemberReference)originalType).Name); iLProcessor.Emit(OpCodes.Call, assemblyContext.Imports.IL2CPP_GetIl2CppClass.Value); } if (((TypeReference)originalType).HasGenericParameters) { TypeRewriteContext typeByName = assemblyContext.GlobalContext.GetAssemblyByName("mscorlib").GetTypeByName("System.Type"); TypeReference val2 = ((MemberReference)newType).Module.ImportReference((TypeReference)(object)typeByName.NewType); TypeRewriteContext typeByName2 = assemblyContext.GlobalContext.GetAssemblyByName("mscorlib").GetTypeByName("System.RuntimeTypeHandle"); TypeReference val3 = ((MemberReference)newType).Module.ImportReference((TypeReference)(object)typeByName2.NewType); iLProcessor.Emit(OpCodes.Call, assemblyContext.Imports.IL2CPP_il2cpp_class_get_type.Value); OpCode call = OpCodes.Call; MethodReference val4 = new MethodReference("internal_from_handle", val2, val2); val4.Parameters.Add(new ParameterDefinition(assemblyContext.Imports.Module.IntPtr())); iLProcessor.Emit(call, val4); iLProcessor.EmitLdcI4(((TypeReference)originalType).GenericParameters.Count); iLProcessor.Emit(OpCodes.Newarr, val2); for (int i = 0; i < ((TypeReference)originalType).GenericParameters.Count; i++) { iLProcessor.Emit(OpCodes.Dup); iLProcessor.EmitLdcI4(i); GenericParameter val5 = ((TypeReference)originalType).GenericParameters[i]; GenericInstanceType val6 = new GenericInstanceType(assemblyContext.Imports.Il2CppClassPointerStore); val6.GenericArguments.Add((TypeReference)(object)val5); GenericInstanceType val7 = val6; FieldReference val8 = new FieldReference("NativeClassPtr", assemblyContext.Imports.Module.IntPtr(), (TypeReference)(object)val7); iLProcessor.Emit(OpCodes.Ldsfld, val8); iLProcessor.Emit(OpCodes.Call, assemblyContext.Imports.IL2CPP_il2cpp_class_get_type.Value); OpCode call2 = OpCodes.Call; MethodReference val9 = new MethodReference("internal_from_handle", val2, val2); val9.Parameters.Add(new ParameterDefinition(assemblyContext.Imports.Module.IntPtr())); iLProcessor.Emit(call2, val9); iLProcessor.Emit(OpCodes.Stelem_Ref); } GenericInstanceType val10 = new GenericInstanceType(assemblyContext.Imports.Il2CppReferenceArray); val10.GenericArguments.Add(val2); GenericInstanceType val11 = val10; OpCode newobj = OpCodes.Newobj; MethodReference val12 = new MethodReference(".ctor", assemblyContext.Imports.Module.Void(), (TypeReference)(object)val11) { HasThis = true }; val12.Parameters.Add(new ParameterDefinition((TypeReference)new ArrayType((TypeReference)(object)assemblyContext.Imports.Il2CppReferenceArray.GenericParameters[0]))); iLProcessor.Emit(newobj, val12); OpCode call3 = OpCodes.Call; MethodReference val13 = new MethodReference("MakeGenericType", val2, val2) { HasThis = true }; val13.Parameters.Add(new ParameterDefinition((TypeReference)(object)val11)); iLProcessor.Emit(call3, val13); iLProcessor.Emit(OpCodes.Call, new MethodReference(typeof(Type).GetProperty("TypeHandle").GetMethod.Name, val3, val2) { HasThis = true }); iLProcessor.Emit(OpCodes.Ldfld, new FieldReference("value", assemblyContext.Imports.Module.IntPtr(), val3)); iLProcessor.Emit(OpCodes.Call, assemblyContext.Imports.IL2CPP_il2cpp_class_from_type.Value); } iLProcessor.Emit(OpCodes.Stsfld, typeContext.ClassPointerFieldRef); if (originalType.IsBeforeFieldInit) { iLProcessor.Emit(OpCodes.Ldsfld, typeContext.ClassPointerFieldRef); iLProcessor.Emit(OpCodes.Call, assemblyContext.Imports.IL2CPP_il2cpp_runtime_class_init.Value); } if (originalType.IsEnum) { iLProcessor.Emit(OpCodes.Ret); return; } foreach (FieldRewriteContext field in typeContext.Fields) { iLProcessor.Emit(OpCodes.Ldsfld, typeContext.ClassPointerFieldRef); iLProcessor.Emit(OpCodes.Ldstr, ((MemberReference)field.OriginalField).Name); iLProcessor.Emit(OpCodes.Call, assemblyContext.Imports.IL2CPP_GetIl2CppField.Value); iLProcessor.Emit(OpCodes.Stsfld, field.PointerField); } foreach (MethodRewriteContext method in typeContext.Methods) { iLProcessor.Emit(OpCodes.Ldsfld, typeContext.ClassPointerFieldRef); long num = ((ICustomAttributeProvider)(object)method.OriginalMethod).ExtractToken(); if (num == 0L) { ourTokenlessMethods++; iLProcessor.Emit((((MethodReference)method.OriginalMethod).GenericParameters.Count > 0) ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); iLProcessor.Emit(OpCodes.Ldstr, ((MemberReference)method.OriginalMethod).Name); iLProcessor.EmitLoadTypeNameString(assemblyContext.Imports, method.OriginalMethod, ((MethodReference)method.OriginalMethod).ReturnType, ((MethodReference)method.NewMethod).ReturnType); iLProcessor.Emit(OpCodes.Ldc_I4, ((MethodReference)method.OriginalMethod).Parameters.Count); iLProcessor.Emit(OpCodes.Newarr, assemblyContext.Imports.Module.String()); for (int j = 0; j < ((MethodReference)method.OriginalMethod).Parameters.Count; j++) { iLProcessor.Emit(OpCodes.Dup); iLProcessor.EmitLdcI4(j); iLProcessor.EmitLoadTypeNameString(assemblyContext.Imports, method.OriginalMethod, ((ParameterReference)((MethodReference)method.OriginalMethod).Parameters[j]).ParameterType, ((ParameterReference)((MethodReference)method.NewMethod).Parameters[j]).ParameterType); iLProcessor.Emit(OpCodes.Stelem_Ref); } iLProcessor.Emit(OpCodes.Call, assemblyContext.Imports.IL2CPP_GetIl2CppMethod.Value); } else { iLProcessor.EmitLdcI4((int)num); iLProcessor.Emit(OpCodes.Call, assemblyContext.Imports.IL2CPP_GetIl2CppMethodByToken.Value); } iLProcessor.Emit(OpCodes.Stsfld, method.NonGenericMethodInfoPointerField); } iLProcessor.Emit(OpCodes.Ret); } private static void EmitLoadTypeNameString(this ILProcessor ctorBuilder, RuntimeAssemblyReferences imports, MethodDefinition originalMethod, TypeReference originalTypeReference, TypeReference newTypeReference) { //IL_001b: 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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown if (((MethodReference)originalMethod).HasGenericParameters || ((MemberReference)originalTypeReference).FullName == "System.Void") { ctorBuilder.Emit(OpCodes.Ldstr, ((MemberReference)originalTypeReference).FullName); return; } ctorBuilder.Emit(newTypeReference.IsByReference ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); OpCode call = OpCodes.Call; ModuleDefinition module = imports.Module; GenericInstanceMethod val = new GenericInstanceMethod(imports.IL2CPP_RenderTypeName.Value); val.GenericArguments.Add(newTypeReference.IsByReference ? newTypeReference.GetElementType() : newTypeReference); ctorBuilder.Emit(call, module.ImportReference((MethodReference)val)); } } public static class Pass21GenerateValueTypeFields { public static void DoPass(RewriteGlobalContext context) { //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0098: 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_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Expected O, but got Unknown //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Expected O, but got Unknown foreach (AssemblyRewriteContext assembly in context.Assemblies) { TypeRewriteContext typeByName = assembly.GlobalContext.GetAssemblyByName("mscorlib").GetTypeByName("System.Object"); TypeReference il2CppObjectTypeDef = assembly.NewAssembly.MainModule.ImportReference((TypeReference)(object)typeByName.NewType); foreach (TypeRewriteContext type in assembly.Types) { if (type.ComputedTypeSpecifics != TypeRewriteContext.TypeSpecifics.BlittableStruct || type.OriginalType.IsEnum) { continue; } try { TypeDefinition newType = type.NewType; newType.Attributes = (TypeAttributes)((newType.Attributes & -25) | 0x10); ILGeneratorEx.GenerateBoxMethod(assembly.Imports, newType, type.ClassPointerFieldRef, il2CppObjectTypeDef); foreach (FieldRewriteContext field in type.Fields) { FieldDefinition originalField = field.OriginalField; if (!originalField.IsStatic) { FieldDefinition val = new FieldDefinition(field.UnmangledName, originalField.Attributes.ForcePublic(), (!((FieldReference)originalField).FieldType.IsValueType) ? assembly.Imports.Module.IntPtr() : assembly.RewriteTypeRef(((FieldReference)originalField).FieldType)); val.Offset = ((ICustomAttributeProvider)(object)originalField).ExtractFieldOffset(); if (((MemberReference)((FieldReference)val).FieldType).FullName == "System.Boolean") { val.MarshalInfo = new MarshalInfo((NativeType)4); } newType.Fields.Add(val); } } } catch (Exception innerException) { throw new Exception($"Failed to generate value type fields for type {((MemberReference)type.OriginalType).FullName} in assembly {type.AssemblyContext.OriginalAssembly.Name}", innerException); } } } } } public static class Pass22GenerateEnums { public static void DoPass(RewriteGlobalContext context) { //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: 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) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Expected O, but got Unknown //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Expected O, but got Unknown //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Expected O, but got Unknown foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { if (!type.OriginalType.IsEnum) { continue; } TypeDefinition originalType = type.OriginalType; TypeDefinition newType = type.NewType; if (((TypeReference)originalType).Namespace.NameShouldBePrefixed(context.Options)) { Collection customAttributes = newType.CustomAttributes; CustomAttribute val = new CustomAttribute(assembly.Imports.OriginalNameAttributector.Value); val.ConstructorArguments.Add(new CustomAttributeArgument(assembly.Imports.Module.String(), (object)((ModuleReference)((MemberReference)originalType).Module).Name)); val.ConstructorArguments.Add(new CustomAttributeArgument(assembly.Imports.Module.String(), (object)((TypeReference)originalType).Namespace)); val.ConstructorArguments.Add(new CustomAttributeArgument(assembly.Imports.Module.String(), (object)((MemberReference)originalType).Name)); customAttributes.Add(val); } if (((IEnumerable)originalType.CustomAttributes).Any((CustomAttribute it) => ((MemberReference)it.AttributeType).FullName == "System.FlagsAttribute")) { newType.CustomAttributes.Add(new CustomAttribute(assembly.Imports.Module.FlagsAttributeCtor())); } Enumerator enumerator3 = originalType.Fields.GetEnumerator(); try { while (enumerator3.MoveNext()) { FieldDefinition current3 = enumerator3.Current; string text = ((MemberReference)current3).Name; if (!context.Options.PassthroughNames && text.IsObfuscated(context.Options)) { text = GetUnmangledName(current3); } if (context.Options.RenameMap.TryGetValue(((TypeReference)(object)type.NewType).GetNamespacePrefix() + "." + ((MemberReference)type.NewType).Name + "::" + text, out var value)) { text = value; } FieldDefinition val2 = new FieldDefinition(text, (FieldAttributes)(current3.Attributes | 0x8000), assembly.RewriteTypeRef(((FieldReference)current3).FieldType)); newType.Fields.Add(val2); val2.Constant = current3.Constant; } } finally { ((IDisposable)enumerator3).Dispose(); } } } } public static string GetUnmangledName(FieldDefinition field) { return "EnumValue" + field.Constant; } } public static class Pass23GeneratePointerConstructors { public static void DoPass(RewriteGlobalContext context) { //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Expected O, but got Unknown //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Expected O, but got Unknown //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Expected O, but got Unknown //IL_011f: Unknown result type (might be due to invalid IL or missing references) foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { if (type.ComputedTypeSpecifics != TypeRewriteContext.TypeSpecifics.BlittableStruct && !type.OriginalType.IsEnum) { TypeDefinition newType = type.NewType; MethodDefinition val = new MethodDefinition(".ctor", (MethodAttributes)6278, assembly.Imports.Module.Void()); ((MethodReference)val).Parameters.Add(new ParameterDefinition("pointer", (ParameterAttributes)0, assembly.Imports.Module.IntPtr())); ILProcessor iLProcessor = val.Body.GetILProcessor(); newType.Methods.Add(val); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldarg_1); OpCode call = OpCodes.Call; MethodReference val2 = new MethodReference(".ctor", assembly.Imports.Module.Void(), newType.BaseType); val2.Parameters.Add(new ParameterDefinition(assembly.Imports.Module.IntPtr())); val2.HasThis = true; iLProcessor.Emit(call, val2); iLProcessor.Emit(OpCodes.Ret); } } } } } public static class Pass25GenerateNonBlittableValueTypeDefaultCtors { public static void DoPass(RewriteGlobalContext context) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Expected O, but got Unknown //IL_01a1: Expected O, but got Unknown //IL_01a1: Unknown result type (might be due to invalid IL or missing references) foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { if (type.ComputedTypeSpecifics == TypeRewriteContext.TypeSpecifics.NonBlittableStruct) { MethodDefinition val = new MethodDefinition(".ctor", (MethodAttributes)6278, assembly.Imports.Module.Void()); type.NewType.Methods.Add(val); VariableDefinition val2 = new VariableDefinition(assembly.Imports.Module.IntPtr()); val.Body.Variables.Add(val2); ILProcessor iLProcessor = val.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldsfld, type.ClassPointerFieldRef); iLProcessor.Emit(OpCodes.Ldc_I4_0); iLProcessor.Emit(OpCodes.Conv_U); iLProcessor.Emit(OpCodes.Call, assembly.Imports.IL2CPP_il2cpp_class_value_size.Value); iLProcessor.Emit(OpCodes.Conv_U); iLProcessor.Emit(OpCodes.Localloc); iLProcessor.Emit(OpCodes.Stloc_0); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldsfld, type.ClassPointerFieldRef); iLProcessor.Emit(OpCodes.Ldloc_0); iLProcessor.Emit(OpCodes.Call, assembly.Imports.IL2CPP_il2cpp_value_box.Value); OpCode call = OpCodes.Call; MethodReference val3 = new MethodReference(".ctor", assembly.Imports.Module.Void(), type.NewType.BaseType) { HasThis = true }; val3.Parameters.Add(new ParameterDefinition(assembly.Imports.Module.IntPtr())); iLProcessor.Emit(call, val3); iLProcessor.Emit(OpCodes.Ret); } } } } } public static class Pass30GenerateGenericMethodStoreConstructors { public static void DoPass(RewriteGlobalContext context) { //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Expected O, but got Unknown //IL_010d: 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_0132: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Expected O, but got Unknown //IL_019b: Expected O, but got Unknown //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Expected O, but got Unknown //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Expected O, but got Unknown //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0260: 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_027b: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Expected O, but got Unknown //IL_028a: Expected O, but got Unknown //IL_028c: 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_02bf: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Expected O, but got Unknown //IL_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_02ec: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Expected O, but got Unknown //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_0323: Expected O, but got Unknown //IL_0328: Expected O, but got Unknown //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Unknown result type (might be due to invalid IL or missing references) //IL_033d: Unknown result type (might be due to invalid IL or missing references) //IL_0344: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) //IL_0356: Expected O, but got Unknown //IL_035b: Expected O, but got Unknown //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_0379: Unknown result type (might be due to invalid IL or missing references) //IL_0395: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_03c0: Expected O, but got Unknown //IL_03c2: Unknown result type (might be due to invalid IL or missing references) foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { foreach (MethodRewriteContext method in type.Methods) { MethodDefinition originalMethod = method.OriginalMethod; TypeDefinition genericInstantiationsStore = method.GenericInstantiationsStore; if (genericInstantiationsStore != null) { MethodDefinition val = new MethodDefinition(".cctor", (MethodAttributes)6289, assembly.Imports.Module.Void()); genericInstantiationsStore.Methods.Add(val); ILProcessor iLProcessor = val.Body.GetILProcessor(); TypeRewriteContext typeByName = assembly.GlobalContext.GetAssemblyByName("mscorlib").GetTypeByName("System.Type"); TypeReference val2 = assembly.NewAssembly.MainModule.ImportReference((TypeReference)(object)typeByName.NewType); TypeRewriteContext typeByName2 = assembly.GlobalContext.GetAssemblyByName("mscorlib").GetTypeByName("System.Reflection.MethodInfo"); TypeReference val3 = assembly.NewAssembly.MainModule.ImportReference((TypeReference)(object)typeByName2.NewType); iLProcessor.Emit(OpCodes.Ldsfld, method.NonGenericMethodInfoPointerField); iLProcessor.Emit(OpCodes.Ldsfld, type.ClassPointerFieldRef); iLProcessor.Emit(OpCodes.Call, assembly.Imports.IL2CPP_il2cpp_method_get_object.Value); OpCode newobj = OpCodes.Newobj; MethodReference val4 = new MethodReference(".ctor", assembly.Imports.Module.Void(), val3) { HasThis = true }; val4.Parameters.Add(new ParameterDefinition(assembly.Imports.Module.IntPtr())); iLProcessor.Emit(newobj, val4); iLProcessor.EmitLdcI4(((MethodReference)originalMethod).GenericParameters.Count); iLProcessor.Emit(OpCodes.Newarr, val2); for (int i = 0; i < ((MethodReference)originalMethod).GenericParameters.Count; i++) { iLProcessor.Emit(OpCodes.Dup); iLProcessor.EmitLdcI4(i); GenericParameter val5 = ((TypeReference)genericInstantiationsStore).GenericParameters[i]; GenericInstanceType val6 = new GenericInstanceType(assembly.Imports.Il2CppClassPointerStore); val6.GenericArguments.Add((TypeReference)(object)val5); GenericInstanceType val7 = val6; FieldReference val8 = new FieldReference("NativeClassPtr", assembly.Imports.Module.IntPtr(), (TypeReference)(object)val7); iLProcessor.Emit(OpCodes.Ldsfld, val8); iLProcessor.Emit(OpCodes.Call, assembly.Imports.IL2CPP_il2cpp_class_get_type.Value); OpCode call = OpCodes.Call; MethodReference val9 = new MethodReference("internal_from_handle", val2, val2); val9.Parameters.Add(new ParameterDefinition(assembly.Imports.Module.IntPtr())); iLProcessor.Emit(call, val9); iLProcessor.Emit(OpCodes.Stelem_Ref); } GenericInstanceType val10 = new GenericInstanceType(assembly.Imports.Il2CppReferenceArray); val10.GenericArguments.Add(val2); GenericInstanceType val11 = val10; OpCode newobj2 = OpCodes.Newobj; MethodReference val12 = new MethodReference(".ctor", assembly.Imports.Module.Void(), (TypeReference)(object)val11) { HasThis = true }; val12.Parameters.Add(new ParameterDefinition((TypeReference)new ArrayType((TypeReference)(object)assembly.Imports.Il2CppReferenceArray.GenericParameters[0]))); iLProcessor.Emit(newobj2, val12); OpCode call2 = OpCodes.Call; MethodReference val13 = new MethodReference("MakeGenericMethod", val3, val3) { HasThis = true }; val13.Parameters.Add(new ParameterDefinition((TypeReference)(object)val11)); iLProcessor.Emit(call2, val13); iLProcessor.Emit(OpCodes.Call, assembly.Imports.IL2CPP_Il2CppObjectBaseToPtrNotNull.Value); iLProcessor.Emit(OpCodes.Call, assembly.Imports.IL2CPP_il2cpp_method_get_from_reflection.Value); iLProcessor.Emit(OpCodes.Stsfld, new FieldReference("Pointer", assembly.Imports.Module.IntPtr(), method.GenericInstantiationsStoreSelfSubstRef)); iLProcessor.Emit(OpCodes.Ret); } } } } } } public static class Pass40GenerateFieldAccessors { public static void DoPass(RewriteGlobalContext context) { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { foreach (FieldRewriteContext field in type.Fields) { if (type.ComputedTypeSpecifics != TypeRewriteContext.TypeSpecifics.BlittableStruct || field.OriginalField.IsStatic) { FieldDefinition originalField = field.OriginalField; PropertyDefinition val = new PropertyDefinition(field.UnmangledName, (PropertyAttributes)0, assembly.RewriteTypeRef(((FieldReference)field.OriginalField).FieldType)); type.NewType.Properties.Add(val); FieldAccessorGenerator.MakeGetter(originalField, field, val, assembly.Imports); FieldAccessorGenerator.MakeSetter(originalField, field, val, assembly.Imports); } } } } } } public static class Pass50GenerateMethods { public static void DoPass(RewriteGlobalContext context) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Expected O, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Expected O, but got Unknown //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Expected O, but got Unknown //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_0397: Unknown result type (might be due to invalid IL or missing references) //IL_03a3: Unknown result type (might be due to invalid IL or missing references) //IL_03bb: Unknown result type (might be due to invalid IL or missing references) //IL_03c7: Unknown result type (might be due to invalid IL or missing references) //IL_036a: Unknown result type (might be due to invalid IL or missing references) //IL_0376: Unknown result type (might be due to invalid IL or missing references) //IL_02a0: 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_02be: 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_02f2: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Expected O, but got Unknown //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_031f: Expected O, but got Unknown //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_03d3: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Unknown result type (might be due to invalid IL or missing references) //IL_0350: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: Unknown result type (might be due to invalid IL or missing references) //IL_041b: Unknown result type (might be due to invalid IL or missing references) //IL_0427: Unknown result type (might be due to invalid IL or missing references) //IL_043f: Unknown result type (might be due to invalid IL or missing references) //IL_044b: Unknown result type (might be due to invalid IL or missing references) //IL_073b: Unknown result type (might be due to invalid IL or missing references) //IL_0710: Unknown result type (might be due to invalid IL or missing references) //IL_072d: Unknown result type (might be due to invalid IL or missing references) //IL_0737: Expected O, but got Unknown //IL_061d: Unknown result type (might be due to invalid IL or missing references) //IL_04a1: Unknown result type (might be due to invalid IL or missing references) //IL_04a8: Expected O, but got Unknown //IL_059c: Unknown result type (might be due to invalid IL or missing references) //IL_05aa: Unknown result type (might be due to invalid IL or missing references) //IL_05b8: Unknown result type (might be due to invalid IL or missing references) //IL_04c9: Unknown result type (might be due to invalid IL or missing references) //IL_04d7: Unknown result type (might be due to invalid IL or missing references) //IL_04ef: Unknown result type (might be due to invalid IL or missing references) //IL_0507: Unknown result type (might be due to invalid IL or missing references) //IL_0515: Unknown result type (might be due to invalid IL or missing references) //IL_0523: Unknown result type (might be due to invalid IL or missing references) //IL_0539: Unknown result type (might be due to invalid IL or missing references) //IL_0547: Unknown result type (might be due to invalid IL or missing references) //IL_0555: Unknown result type (might be due to invalid IL or missing references) //IL_0561: Unknown result type (might be due to invalid IL or missing references) //IL_0578: Unknown result type (might be due to invalid IL or missing references) //IL_0757: Unknown result type (might be due to invalid IL or missing references) //IL_0682: Unknown result type (might be due to invalid IL or missing references) //IL_068e: Unknown result type (might be due to invalid IL or missing references) //IL_0782: Unknown result type (might be due to invalid IL or missing references) //IL_0790: Unknown result type (might be due to invalid IL or missing references) //IL_079e: Unknown result type (might be due to invalid IL or missing references) //IL_07b6: Unknown result type (might be due to invalid IL or missing references) //IL_07c4: Unknown result type (might be due to invalid IL or missing references) //IL_07d2: Unknown result type (might be due to invalid IL or missing references) //IL_06da: Unknown result type (might be due to invalid IL or missing references) //IL_06af: Unknown result type (might be due to invalid IL or missing references) //IL_06cc: Unknown result type (might be due to invalid IL or missing references) //IL_06d6: Expected O, but got Unknown //IL_06ed: Unknown result type (might be due to invalid IL or missing references) //IL_0926: Unknown result type (might be due to invalid IL or missing references) //IL_093b: Unknown result type (might be due to invalid IL or missing references) //IL_0840: Unknown result type (might be due to invalid IL or missing references) //IL_0858: Unknown result type (might be due to invalid IL or missing references) //IL_0870: Unknown result type (might be due to invalid IL or missing references) //IL_0888: Unknown result type (might be due to invalid IL or missing references) //IL_0896: Unknown result type (might be due to invalid IL or missing references) //IL_08c2: Unknown result type (might be due to invalid IL or missing references) foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { foreach (MethodRewriteContext method in type.Methods) { MethodDefinition originalMethod = method.OriginalMethod; MethodDefinition newMethod = method.NewMethod; RuntimeAssemblyReferences imports = assembly.Imports; ILProcessor iLProcessor = newMethod.Body.GetILProcessor(); VariableDefinition val = new VariableDefinition(imports.Module.IntPtr()); VariableDefinition val2 = new VariableDefinition((TypeReference)new PointerType(imports.Module.IntPtr())); VariableDefinition val3 = new VariableDefinition(imports.Module.IntPtr()); VariableDefinition val4 = new VariableDefinition(((MethodReference)newMethod).ReturnType); newMethod.Body.Variables.Add(val); newMethod.Body.Variables.Add(val2); newMethod.Body.Variables.Add(val3); if (((MemberReference)((VariableReference)val4).VariableType).FullName != "System.Void") { newMethod.Body.Variables.Add(val4); } Instruction val5 = null; for (int i = 0; i < ((MethodReference)originalMethod).Parameters.Count; i++) { ParameterDefinition val6 = ((MethodReference)newMethod).Parameters[i]; ParameterDefinition val7 = ((MethodReference)originalMethod).Parameters[i]; if (val7.IsParamsArray()) { TypeReference elementType = ((TypeSpecification)(ArrayType)((ParameterReference)val7).ParameterType).ElementType; if (val5 != null) { iLProcessor.Append(val5); } val5 = iLProcessor.Create(OpCodes.Nop); iLProcessor.Emit(OpCodes.Ldarg, val6); iLProcessor.Emit(OpCodes.Brtrue, val5); iLProcessor.Emit(OpCodes.Ldc_I4_0); iLProcessor.Emit(OpCodes.Conv_I8); ModuleDefinition module = imports.Module; MethodReference val8 = ((((MemberReference)elementType).FullName == "System.String") ? imports.Il2CppStringArrayctor_size.Value : ((!elementType.IsValueType) ? imports.Il2CppRefrenceArrayctor_size.Get(((GenericInstanceType)((ParameterReference)val6).ParameterType).GenericArguments[0]) : imports.Il2CppStructArrayctor_size.Get(((GenericInstanceType)((ParameterReference)val6).ParameterType).GenericArguments[0]))); iLProcessor.Emit(OpCodes.Newobj, module.ImportReference(val8)); iLProcessor.Emit(OpCodes.Starg, val6); } } if (val5 != null) { iLProcessor.Append(val5); } if (type.ComputedTypeSpecifics != TypeRewriteContext.TypeSpecifics.BlittableStruct) { if (originalMethod.IsConstructor) { iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldsfld, type.ClassPointerFieldRef); iLProcessor.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_object_new.Value); OpCode call = OpCodes.Call; MethodReference val9 = new MethodReference(".ctor", imports.Module.Void(), type.SelfSubstitutedRef); val9.Parameters.Add(new ParameterDefinition(imports.Module.IntPtr())); val9.HasThis = true; iLProcessor.Emit(call, val9); } else if (!originalMethod.IsStatic) { iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Call, imports.IL2CPP_Il2CppObjectBaseToPtrNotNull.Value); iLProcessor.Emit(OpCodes.Pop); } } if (((MethodReference)originalMethod).Parameters.Count == 0) { iLProcessor.Emit(OpCodes.Ldc_I4_0); iLProcessor.Emit(OpCodes.Conv_U); } else { iLProcessor.EmitLdcI4(((MethodReference)originalMethod).Parameters.Count); iLProcessor.Emit(OpCodes.Conv_U); iLProcessor.Emit(OpCodes.Sizeof, imports.Module.IntPtr()); iLProcessor.Emit(OpCodes.Mul_Ovf_Un); iLProcessor.Emit(OpCodes.Localloc); } iLProcessor.Emit(OpCodes.Stloc, val2); int num = ((!originalMethod.IsStatic) ? 1 : 0); List<(int, VariableDefinition)> list = new List<(int, VariableDefinition)>(); for (int j = 0; j < ((MethodReference)newMethod).Parameters.Count; j++) { iLProcessor.Emit(OpCodes.Ldloc, val2); if (j > 0) { iLProcessor.EmitLdcI4(j); iLProcessor.Emit(OpCodes.Conv_U); iLProcessor.Emit(OpCodes.Sizeof, imports.Module.IntPtr()); iLProcessor.Emit(OpCodes.Mul_Ovf_Un); iLProcessor.Emit(OpCodes.Add); } ParameterDefinition val10 = ((MethodReference)newMethod).Parameters[j]; if (val10.IsOut && !((ParameterReference)val10).ParameterType.GetElementType().IsValueType) { TypeReference elementType2 = ((ParameterReference)val10).ParameterType.GetElementType(); VariableDefinition val11 = new VariableDefinition(imports.Module.IntPtr()); iLProcessor.Body.Variables.Add(val11); if (elementType2.IsGenericParameter) { iLProcessor.Emit(OpCodes.Ldtoken, elementType2); iLProcessor.Emit(OpCodes.Call, imports.Module.TypeGetTypeFromHandle()); iLProcessor.Emit(OpCodes.Callvirt, imports.Module.TypeGetIsValueType()); Instruction val12 = iLProcessor.Create(OpCodes.Nop); Instruction val13 = iLProcessor.Create(OpCodes.Nop); iLProcessor.Emit(OpCodes.Brtrue, val12); iLProcessor.EmitLdcI4(0); iLProcessor.Emit(OpCodes.Stloc, val11); iLProcessor.Emit(OpCodes.Ldloca, val11); iLProcessor.Emit(OpCodes.Conv_I); iLProcessor.Emit(OpCodes.Br_S, val13); iLProcessor.Append(val12); iLProcessor.Emit(OpCodes.Ldarg, num + j); iLProcessor.Append(val13); } else { iLProcessor.EmitLdcI4(0); iLProcessor.Emit(OpCodes.Stloc, val11); iLProcessor.Emit(OpCodes.Ldloca, val11); iLProcessor.Emit(OpCodes.Conv_I); } list.Add((j, val11)); } else { iLProcessor.EmitObjectToPointer(((ParameterReference)((MethodReference)originalMethod).Parameters[j]).ParameterType, ((ParameterReference)val10).ParameterType, method.DeclaringType, num + j, valueTypeArgument0IsAPointer: false, allowNullable: true, unboxNonBlittableType: true, unboxNonBlittableGeneric: false, out VariableDefinition refVariable); if (refVariable != null) { list.Add((j, refVariable)); } } iLProcessor.Emit(OpCodes.Stind_I); } if (!originalMethod.DeclaringType.IsSealed && !originalMethod.IsFinal && ((originalMethod.IsVirtual && !((TypeReference)originalMethod.DeclaringType).IsValueType) || originalMethod.IsAbstract)) { iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Call, imports.IL2CPP_Il2CppObjectBaseToPtr.Value); if (method.GenericInstantiationsStoreSelfSubstRef != null) { iLProcessor.Emit(OpCodes.Ldsfld, new FieldReference("Pointer", imports.Module.IntPtr(), method.GenericInstantiationsStoreSelfSubstMethodRef)); } else { iLProcessor.Emit(OpCodes.Ldsfld, method.NonGenericMethodInfoPointerField); } iLProcessor.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_object_get_virtual_method.Value); } else if (method.GenericInstantiationsStoreSelfSubstRef != null) { iLProcessor.Emit(OpCodes.Ldsfld, new FieldReference("Pointer", imports.Module.IntPtr(), method.GenericInstantiationsStoreSelfSubstMethodRef)); } else { iLProcessor.Emit(OpCodes.Ldsfld, method.NonGenericMethodInfoPointerField); } if (originalMethod.IsStatic) { iLProcessor.Emit(OpCodes.Ldc_I4_0); } else { iLProcessor.EmitObjectToPointer((TypeReference)(object)originalMethod.DeclaringType, (TypeReference)(object)newMethod.DeclaringType, type, 0, valueTypeArgument0IsAPointer: true, allowNullable: false, unboxNonBlittableType: true, unboxNonBlittableGeneric: true, out VariableDefinition _); } iLProcessor.Emit(OpCodes.Ldloc, val2); iLProcessor.Emit(OpCodes.Ldloca, val); iLProcessor.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_runtime_invoke.Value); iLProcessor.Emit(OpCodes.Stloc, val3); iLProcessor.Emit(OpCodes.Ldloc, val); iLProcessor.Emit(OpCodes.Call, imports.Il2CppException_RaiseExceptionIfNecessary.Value); foreach (var item3 in list) { int item = item3.Item1; VariableDefinition item2 = item3.Item2; ParameterDefinition val14 = ((MethodReference)newMethod).Parameters[item]; if (val14.IsOut && ((ParameterReference)val14).ParameterType.GetElementType().IsGenericParameter) { iLProcessor.Emit(OpCodes.Ldtoken, ((ParameterReference)val14).ParameterType.GetElementType()); iLProcessor.Emit(OpCodes.Call, imports.Module.TypeGetTypeFromHandle()); iLProcessor.Emit(OpCodes.Callvirt, imports.Module.TypeGetIsValueType()); Instruction val15 = iLProcessor.Create(OpCodes.Nop); iLProcessor.Emit(OpCodes.Brtrue, val15); iLProcessor.EmitUpdateRef(((MethodReference)newMethod).Parameters[item], item + num, item2, imports); iLProcessor.Emit(OpCodes.Br_S, val15); iLProcessor.Append(val15); } else { iLProcessor.EmitUpdateRef(((MethodReference)newMethod).Parameters[item], item + num, item2, imports); } } iLProcessor.EmitPointerToObject(((MethodReference)originalMethod).ReturnType, ((MethodReference)newMethod).ReturnType, type, iLProcessor.Create(OpCodes.Ldloc, val3), extraDerefForNonValueTypes: false, unboxValueType: true); iLProcessor.Emit(OpCodes.Ret); } } } } } public static class Pass60AddImplicitConversions { private const MethodAttributes OperatorAttributes = 2198; public static void DoPass(RewriteGlobalContext context) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Expected O, but got Unknown //IL_0126: Expected O, but got Unknown //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Expected O, but got Unknown //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Expected O, but got Unknown //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Expected O, but got Unknown //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Expected O, but got Unknown //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_03c6: Expected O, but got Unknown //IL_03d5: Unknown result type (might be due to invalid IL or missing references) //IL_03df: Expected O, but got Unknown //IL_03ed: Unknown result type (might be due to invalid IL or missing references) //IL_03f4: Expected O, but got Unknown //IL_0408: Unknown result type (might be due to invalid IL or missing references) //IL_0415: Unknown result type (might be due to invalid IL or missing references) //IL_0422: Unknown result type (might be due to invalid IL or missing references) //IL_042f: Unknown result type (might be due to invalid IL or missing references) //IL_043a: Unknown result type (might be due to invalid IL or missing references) //IL_0470: Unknown result type (might be due to invalid IL or missing references) //IL_047d: Unknown result type (might be due to invalid IL or missing references) //IL_04b2: Unknown result type (might be due to invalid IL or missing references) AssemblyRewriteContext assemblyByName = context.GetAssemblyByName("mscorlib"); TypeRewriteContext typeByName = assemblyByName.GetTypeByName("System.String"); TypeRewriteContext typeByName2 = assemblyByName.GetTypeByName("System.Object"); MethodDefinition val = new MethodDefinition("op_Implicit", (MethodAttributes)2198, (TypeReference)(object)typeByName.NewType); ((MethodReference)val).Parameters.Add(new ParameterDefinition(assemblyByName.Imports.Module.String())); typeByName.NewType.Methods.Add(val); ILProcessor iLProcessor = val.Body.GetILProcessor(); Instruction val2 = iLProcessor.Create(OpCodes.Nop); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Dup); iLProcessor.Emit(OpCodes.Brtrue_S, val2); iLProcessor.Emit(OpCodes.Ret); iLProcessor.Append(val2); iLProcessor.Emit(OpCodes.Call, assemblyByName.Imports.IL2CPP_ManagedStringToIl2Cpp.Value); OpCode newobj = OpCodes.Newobj; MethodReference val3 = new MethodReference(".ctor", assemblyByName.Imports.Module.Void(), (TypeReference)(object)typeByName.NewType) { HasThis = true }; val3.Parameters.Add(new ParameterDefinition(assemblyByName.Imports.Module.IntPtr())); iLProcessor.Emit(newobj, val3); iLProcessor.Emit(OpCodes.Ret); MethodDefinition val4 = new MethodDefinition("op_Implicit", (MethodAttributes)2198, (TypeReference)(object)typeByName2.NewType); ((MethodReference)val4).Parameters.Add(new ParameterDefinition(assemblyByName.Imports.Module.String())); typeByName2.NewType.Methods.Add(val4); ILProcessor iLProcessor2 = val4.Body.GetILProcessor(); iLProcessor2.Emit(OpCodes.Ldarg_0); iLProcessor2.Emit(OpCodes.Call, (MethodReference)(object)val); iLProcessor2.Emit(OpCodes.Ret); MethodDefinition val5 = new MethodDefinition("op_Implicit", (MethodAttributes)2198, assemblyByName.Imports.Module.String()); ((MethodReference)val5).Parameters.Add(new ParameterDefinition((TypeReference)(object)typeByName.NewType)); typeByName.NewType.Methods.Add(val5); ILProcessor iLProcessor3 = val5.Body.GetILProcessor(); Instruction val6 = iLProcessor3.Create(OpCodes.Nop); iLProcessor3.Emit(OpCodes.Ldarg_0); iLProcessor3.Emit(OpCodes.Call, assemblyByName.Imports.IL2CPP_Il2CppObjectBaseToPtr.Value); iLProcessor3.Emit(OpCodes.Dup); iLProcessor3.Emit(OpCodes.Brtrue_S, val6); iLProcessor3.Emit(OpCodes.Pop); iLProcessor3.Emit(OpCodes.Ldnull); iLProcessor3.Emit(OpCodes.Ret); iLProcessor3.Append(val6); iLProcessor3.Emit(OpCodes.Call, assemblyByName.Imports.IL2CPP_Il2CppStringToManaged.Value); iLProcessor3.Emit(OpCodes.Ret); AddDelegateConversions(context); TypeReference[] array = (TypeReference[])(object)new TypeReference[12] { assemblyByName.Imports.Module.SByte(), assemblyByName.Imports.Module.Byte(), assemblyByName.Imports.Module.Short(), assemblyByName.Imports.Module.UShort(), assemblyByName.Imports.Module.Int(), assemblyByName.Imports.Module.UInt(), assemblyByName.Imports.Module.Long(), assemblyByName.Imports.Module.ULong(), assemblyByName.Imports.Module.Float(), assemblyByName.Imports.Module.Double(), assemblyByName.Imports.Module.Char(), assemblyByName.Imports.Module.Bool() }; foreach (TypeReference val7 in array) { TypeDefinition newType = assemblyByName.GetTypeByName(((MemberReference)val7).FullName).NewType; MethodDefinition val8 = new MethodDefinition("op_Implicit", (MethodAttributes)2198, (TypeReference)(object)typeByName2.NewType); ((MethodReference)val8).Parameters.Add(new ParameterDefinition("value", (ParameterAttributes)0, val7)); ILProcessor iLProcessor4 = val8.Body.GetILProcessor(); VariableDefinition val9 = new VariableDefinition((TypeReference)(object)newType); val8.Body.Variables.Add(val9); iLProcessor4.Emit(OpCodes.Ldloca, val9); iLProcessor4.Emit(OpCodes.Initobj, (TypeReference)(object)newType); iLProcessor4.Emit(OpCodes.Ldloca, val9); iLProcessor4.Emit(OpCodes.Ldarg_0); iLProcessor4.Emit(OpCodes.Stfld, (FieldReference)(object)((IEnumerable)newType.Fields).Single((FieldDefinition f) => ((MemberReference)f).Name == "m_value")); iLProcessor4.Emit(OpCodes.Ldloca_S, val9); iLProcessor4.Emit(OpCodes.Call, (MethodReference)(object)((IEnumerable)newType.Methods).Single((MethodDefinition m) => ((MemberReference)m).Name == "BoxIl2CppObject")); iLProcessor4.Emit(OpCodes.Ret); typeByName2.NewType.Methods.Add(val8); } } private static void AddDelegateConversions(RewriteGlobalContext context) { //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Expected O, but got Unknown //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Expected O, but got Unknown //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Expected O, but got Unknown //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Expected O, but got Unknown //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Expected O, but got Unknown //IL_028c: Expected O, but got Unknown //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Expected O, but got Unknown //IL_02b5: 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_02cd: Expected O, but got Unknown //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_030b: Expected O, but got Unknown //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_0334: Expected O, but got Unknown //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Expected O, but got Unknown //IL_0358: Unknown result type (might be due to invalid IL or missing references) //IL_0363: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Unknown result type (might be due to invalid IL or missing references) //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_03a9: Unknown result type (might be due to invalid IL or missing references) //IL_03ae: Unknown result type (might be due to invalid IL or missing references) //IL_03c4: Expected O, but got Unknown //IL_03c9: Unknown result type (might be due to invalid IL or missing references) //IL_03e3: Unknown result type (might be due to invalid IL or missing references) //IL_03ea: Expected O, but got Unknown //IL_0409: Unknown result type (might be due to invalid IL or missing references) //IL_0413: Expected O, but got Unknown //IL_0420: Unknown result type (might be due to invalid IL or missing references) //IL_042a: Expected O, but got Unknown //IL_0437: Unknown result type (might be due to invalid IL or missing references) //IL_0442: Unknown result type (might be due to invalid IL or missing references) //IL_044d: Unknown result type (might be due to invalid IL or missing references) //IL_0468: Unknown result type (might be due to invalid IL or missing references) //IL_0473: Unknown result type (might be due to invalid IL or missing references) //IL_0480: Unknown result type (might be due to invalid IL or missing references) //IL_048d: Unknown result type (might be due to invalid IL or missing references) //IL_04ad: Unknown result type (might be due to invalid IL or missing references) //IL_04b2: Unknown result type (might be due to invalid IL or missing references) //IL_04c8: Expected O, but got Unknown foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { TypeReference baseType = type.OriginalType.BaseType; if (((baseType != null) ? ((MemberReference)baseType).FullName : null) != "System.MulticastDelegate") { continue; } MethodDefinition val = ((IEnumerable)type.NewType.Methods).Single((MethodDefinition it) => ((MemberReference)it).Name == "Invoke"); if (((MethodReference)val).Parameters.Count > 8 || ((IEnumerable)((MethodReference)val).Parameters).Any((ParameterDefinition it) => ((ParameterReference)it).ParameterType.IsByReference || ((ParameterReference)it).ParameterType.IsPointer)) { continue; } MethodDefinition val2 = new MethodDefinition("op_Implicit", (MethodAttributes)2198, type.SelfSubstitutedRef); type.NewType.Methods.Add(val2); bool flag = ((MemberReference)((MethodReference)val).ReturnType).FullName != "System.Void"; bool flag2 = ((MethodReference)val).Parameters.Count > 0; TypeReference val3 = ((!flag && !flag2) ? ((MemberReference)type.NewType).Module.Action() : (flag ? ((MemberReference)type.NewType).Module.Func(((MethodReference)val).Parameters.Count) : ((MemberReference)type.NewType).Module.Action(((MethodReference)val).Parameters.Count))); GenericInstanceType val4 = null; if (flag2) { val4 = new GenericInstanceType(val3); Enumerator enumerator3 = ((MethodReference)val).Parameters.GetEnumerator(); try { while (enumerator3.MoveNext()) { ParameterDefinition current3 = enumerator3.Current; val4.GenericArguments.Add(((ParameterReference)current3).ParameterType); } } finally { ((IDisposable)enumerator3).Dispose(); } } if (flag) { if (val4 == null) { val4 = new GenericInstanceType(val3); } val4.GenericArguments.Add(((MethodReference)val).ReturnType); } ((MethodReference)val2).Parameters.Add(new ParameterDefinition((val4 != null) ? ((MemberReference)type.NewType).Module.ImportReference((TypeReference)(object)val4) : val3)); ILProcessor iLProcessor = val2.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldarg_0); TypeReference delegateSupport = type.AssemblyContext.Imports.DelegateSupport; MethodReference val5 = new MethodReference("ConvertDelegate", assembly.Imports.Module.Void(), delegateSupport) { HasThis = false }; val5.Parameters.Add(new ParameterDefinition(assembly.Imports.Module.Delegate())); MethodReference val6 = val5; val6.GenericParameters.Add(new GenericParameter((IGenericParameterProvider)(object)val6)); val6.ReturnType = (TypeReference)(object)val6.GenericParameters[0]; GenericInstanceMethod val7 = new GenericInstanceMethod(val6); val7.GenericArguments.Add(type.SelfSubstitutedRef); GenericInstanceMethod val8 = val7; iLProcessor.Emit(OpCodes.Call, ((MemberReference)type.NewType).Module.ImportReference((MethodReference)(object)val8)); iLProcessor.Emit(OpCodes.Ret); MethodDefinition val9 = new MethodDefinition("op_Addition", (MethodAttributes)2198, type.SelfSubstitutedRef); type.NewType.Methods.Add(val9); ((MethodReference)val9).Parameters.Add(new ParameterDefinition(type.SelfSubstitutedRef)); ((MethodReference)val9).Parameters.Add(new ParameterDefinition(type.SelfSubstitutedRef)); ILProcessor iLProcessor2 = val9.Body.GetILProcessor(); iLProcessor2.Emit(OpCodes.Ldarg_0); iLProcessor2.Emit(OpCodes.Ldarg_1); iLProcessor2.Emit(OpCodes.Call, assembly.Imports.Il2CppSystemDelegateCombine.Value); OpCode call = OpCodes.Call; ModuleDefinition module = assembly.Imports.Module; GenericInstanceMethod val10 = new GenericInstanceMethod(assembly.Imports.Il2CppObjectBase_Cast.Value); val10.GenericArguments.Add(type.SelfSubstitutedRef); iLProcessor2.Emit(call, module.ImportReference((MethodReference)val10)); iLProcessor2.Emit(OpCodes.Ret); MethodDefinition val11 = new MethodDefinition("op_Subtraction", (MethodAttributes)2198, type.SelfSubstitutedRef); type.NewType.Methods.Add(val11); ((MethodReference)val11).Parameters.Add(new ParameterDefinition(type.SelfSubstitutedRef)); ((MethodReference)val11).Parameters.Add(new ParameterDefinition(type.SelfSubstitutedRef)); ILProcessor iLProcessor3 = val11.Body.GetILProcessor(); iLProcessor3.Emit(OpCodes.Ldarg_0); iLProcessor3.Emit(OpCodes.Ldarg_1); iLProcessor3.Emit(OpCodes.Call, assembly.Imports.Il2CppSystemDelegateRemove.Value); iLProcessor3.Emit(OpCodes.Dup); Instruction val12 = iLProcessor3.Create(OpCodes.Ret); iLProcessor3.Emit(OpCodes.Brfalse_S, val12); OpCode call2 = OpCodes.Call; ModuleDefinition module2 = assembly.Imports.Module; GenericInstanceMethod val13 = new GenericInstanceMethod(assembly.Imports.Il2CppObjectBase_Cast.Value); val13.GenericArguments.Add(type.SelfSubstitutedRef); iLProcessor3.Emit(call2, module2.ImportReference((MethodReference)val13)); iLProcessor3.Append(val12); } } } } public static class Pass70GenerateProperties { public static void DoPass(RewriteGlobalContext context) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Expected O, but got Unknown //IL_0285: Expected O, but got Unknown //IL_0280: 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_029d: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Expected O, but got Unknown //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: 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_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Expected O, but got Unknown foreach (AssemblyRewriteContext assembly in context.Assemblies) { foreach (TypeRewriteContext type in assembly.Types) { TypeDefinition originalType = type.OriginalType; Dictionary countsByBaseName = new Dictionary(); Enumerator enumerator3 = originalType.Properties.GetEnumerator(); try { while (enumerator3.MoveNext()) { PropertyDefinition current3 = enumerator3.Current; MethodDefinition getMethod = current3.GetMethod; if (getMethod != null && getMethod.HasOverrides) { continue; } MethodDefinition setMethod = current3.SetMethod; if (setMethod != null && setMethod.HasOverrides) { continue; } PropertyDefinition val = new PropertyDefinition(UnmanglePropertyName(assembly, current3, (TypeReference)(object)type.NewType, countsByBaseName), current3.Attributes, assembly.RewriteTypeRef(((PropertyReference)current3).PropertyType)); Enumerator enumerator4 = ((PropertyReference)current3).Parameters.GetEnumerator(); try { while (enumerator4.MoveNext()) { ParameterDefinition current4 = enumerator4.Current; ((PropertyReference)val).Parameters.Add(new ParameterDefinition(((ParameterReference)current4).Name, current4.Attributes, assembly.RewriteTypeRef(((ParameterReference)current4).ParameterType))); } } finally { ((IDisposable)enumerator4).Dispose(); } type.NewType.Properties.Add(val); if (current3.GetMethod != null) { val.GetMethod = type.GetMethodByOldMethod(current3.GetMethod).NewMethod; } if (current3.SetMethod != null) { val.SetMethod = type.GetMethodByOldMethod(current3.SetMethod).NewMethod; } } } finally { ((IDisposable)enumerator3).Dispose(); } string text = null; if (((IEnumerable)originalType.CustomAttributes).FirstOrDefault((Func)((CustomAttribute it) => ((MemberReference)it.AttributeType).Name == "AttributeAttribute" && ((IEnumerable)it.Fields).Any(delegate(CustomAttributeNamedArgument it) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (((CustomAttributeNamedArgument)(ref it)).Name == "Name") { CustomAttributeArgument argument = ((CustomAttributeNamedArgument)(ref it)).Argument; return (string)((CustomAttributeArgument)(ref argument)).Value == "DefaultMemberAttribute"; } return false; }))) != null) { text = "Item"; } else { CustomAttribute val2 = ((IEnumerable)originalType.CustomAttributes).FirstOrDefault((Func)((CustomAttribute it) => ((MemberReference)it.AttributeType).Name == "DefaultMemberAttribute")); if (val2 != null) { CustomAttributeArgument val3 = val2.ConstructorArguments[0]; text = ((CustomAttributeArgument)(ref val3)).Value?.ToString() ?? "Item"; } } if (text != null) { Collection customAttributes = type.NewType.CustomAttributes; MethodReference val4 = new MethodReference(".ctor", assembly.Imports.Module.Void(), assembly.Imports.Module.DefaultMemberAttribute()) { HasThis = true }; val4.Parameters.Add(new ParameterDefinition(assembly.Imports.Module.String())); CustomAttribute val5 = new CustomAttribute(val4); val5.ConstructorArguments.Add(new CustomAttributeArgument(assembly.Imports.Module.String(), (object)text)); customAttributes.Add(val5); } } } } private static string UnmanglePropertyName(AssemblyRewriteContext assemblyContext, PropertyDefinition prop, TypeReference declaringType, Dictionary countsByBaseName) { if (assemblyContext.GlobalContext.Options.PassthroughNames || !((MemberReference)prop).Name.IsObfuscated(assemblyContext.GlobalContext.Options)) { return ((MemberReference)prop).Name; } string text = "prop_" + assemblyContext.RewriteTypeRef(((PropertyReference)prop).PropertyType).GetUnmangledName(); countsByBaseName.TryGetValue(text, out var value); countsByBaseName[text] = value + 1; string text2 = text + "_" + value; if (assemblyContext.GlobalContext.Options.RenameMap.TryGetValue(declaringType.GetNamespacePrefix() + "::" + text2, out var value2)) { text2 = value2; } return text2; } } public static class Pass79UnstripTypes { public static void DoPass(RewriteGlobalContext context) { //IL_007d: 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) int typesUnstripped = 0; foreach (AssemblyDefinition assembly in context.UnityAssemblies.Assemblies) { AssemblyRewriteContext assemblyRewriteContext = context.TryGetAssemblyByName(((AssemblyNameReference)assembly.Name).Name); if (assemblyRewriteContext == null) { AssemblyRewriteContext assemblyRewriteContext2 = new AssemblyRewriteContext(context, assembly, AssemblyDefinition.CreateAssembly(assembly.Name, ((ModuleReference)assembly.MainModule).Name, (ModuleKind)0)); context.AddAssemblyContext(((AssemblyNameReference)assembly.Name).Name, assemblyRewriteContext2); assemblyRewriteContext = assemblyRewriteContext2; } RuntimeAssemblyReferences imports = assemblyRewriteContext.Imports; Enumerator enumerator2 = assembly.MainModule.Types.GetEnumerator(); try { while (enumerator2.MoveNext()) { TypeDefinition current2 = enumerator2.Current; ProcessType(assemblyRewriteContext, current2, null, imports, ref typesUnstripped); } } finally { ((IDisposable)enumerator2).Dispose(); } } Logger.Instance.LogTrace("Unstripped {UnstrippedTypeCount} types", typesUnstripped); } private static void ProcessType(AssemblyRewriteContext processedAssembly, TypeDefinition unityType, TypeDefinition? enclosingNewType, RuntimeAssemblyReferences imports, ref int typesUnstripped) { //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Expected O, but got Unknown if (((MemberReference)unityType).Name == "" || (unityType.BaseType != null && ((MemberReference)unityType.BaseType).FullName == "System.MulticastDelegate")) { return; } ModuleDefinition mainModule = processedAssembly.NewAssembly.MainModule; TypeDefinition val = (TypeDefinition)((enclosingNewType != null) ? ((object)((IEnumerable)enclosingNewType.NestedTypes).SingleOrDefault((Func)((TypeDefinition it) => ((MemberReference)it).Name == ((MemberReference)unityType).Name))) : ((object)processedAssembly.TryGetTypeByName(((MemberReference)unityType).FullName)?.NewType)); if (unityType.IsEnum) { if (val == null) { typesUnstripped++; TypeDefinition val2 = CloneEnum(unityType, imports); if (enclosingNewType == null) { mainModule.Types.Add(val2); } else { enclosingNewType.NestedTypes.Add(val2); val2.DeclaringType = enclosingNewType; } processedAssembly.RegisterTypeRewrite(new TypeRewriteContext(processedAssembly, null, val2)); } return; } if (val == null && !unityType.IsEnum && !HasNonBlittableFields(unityType) && !((TypeReference)unityType).HasGenericParameters) { typesUnstripped++; TypeDefinition val3 = new TypeDefinition(((TypeReference)unityType).Namespace, ((MemberReference)unityType).Name, ForcePublic(unityType.Attributes), (unityType.BaseType == null) ? null : mainModule.ImportReference(unityType.BaseType)); if (enclosingNewType == null) { mainModule.Types.Add(val3); } else { enclosingNewType.NestedTypes.Add(val3); val3.DeclaringType = enclosingNewType; } if (!((TypeReference)val3).IsValueType && (val3.IsExplicitLayout || val3.IsSequentialLayout)) { bool isExplicitLayout = (val3.IsSequentialLayout = false); val3.IsExplicitLayout = isExplicitLayout; val3.IsAutoLayout = true; } processedAssembly.RegisterTypeRewrite(new TypeRewriteContext(processedAssembly, null, val3)); val = val3; } Enumerator enumerator = unityType.NestedTypes.GetEnumerator(); try { while (enumerator.MoveNext()) { TypeDefinition current = enumerator.Current; ProcessType(processedAssembly, current, val, imports, ref typesUnstripped); } } finally { ((IDisposable)enumerator).Dispose(); } } private static TypeDefinition CloneEnum(TypeDefinition sourceEnum, RuntimeAssemblyReferences imports) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_0086: Expected O, but got Unknown TypeDefinition val = new TypeDefinition(((TypeReference)sourceEnum).Namespace, ((MemberReference)sourceEnum).Name, ForcePublic(sourceEnum.Attributes), imports.Module.Enum()); Enumerator enumerator = sourceEnum.Fields.GetEnumerator(); try { while (enumerator.MoveNext()) { FieldDefinition current = enumerator.Current; FieldDefinition val2 = new FieldDefinition(((MemberReference)current).Name, current.Attributes, (TypeReference)((((MemberReference)current).Name == "value__") ? ((object)imports.Module.ImportCorlibReference(((FieldReference)current).FieldType.Namespace, ((MemberReference)((FieldReference)current).FieldType).Name)) : ((object)val))); val2.Constant = current.Constant; val.Fields.Add(val2); } return val; } finally { ((IDisposable)enumerator).Dispose(); } } private static bool HasNonBlittableFields(TypeDefinition type) { //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) if (!((TypeReference)type).IsValueType) { return false; } Enumerator enumerator = type.Fields.GetEnumerator(); try { while (enumerator.MoveNext()) { FieldDefinition current = enumerator.Current; if (!current.IsStatic && ((FieldReference)current).FieldType != type) { if (!((FieldReference)current).FieldType.IsValueType) { return true; } if (((FieldReference)current).FieldType.Namespace.StartsWith("System") && HasNonBlittableFields(((FieldReference)current).FieldType.Resolve())) { return true; } } } } finally { ((IDisposable)enumerator).Dispose(); } return false; } private static TypeAttributes ForcePublic(TypeAttributes typeAttributes) { //IL_0000: 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) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0004: 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_000d: 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_0009: Invalid comparison between Unknown and I4 //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) TypeAttributes val = (TypeAttributes)(typeAttributes & 7); if ((int)val == 0 || (int)val == 1) { return (TypeAttributes)(typeAttributes | 1); } return (TypeAttributes)((typeAttributes & -8) | 2); } } public static class Pass80UnstripFields { public static void DoPass(RewriteGlobalContext context) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Expected O, but got Unknown int num = 0; int num2 = 0; foreach (AssemblyDefinition assembly in context.UnityAssemblies.Assemblies) { AssemblyRewriteContext assemblyRewriteContext = context.TryGetAssemblyByName(((AssemblyNameReference)assembly.Name).Name); if (assemblyRewriteContext == null) { continue; } RuntimeAssemblyReferences imports = assemblyRewriteContext.Imports; Enumerator enumerator2 = assembly.MainModule.Types.GetEnumerator(); try { while (enumerator2.MoveNext()) { TypeDefinition current2 = enumerator2.Current; TypeRewriteContext typeRewriteContext = assemblyRewriteContext.TryGetTypeByName(((MemberReference)current2).FullName); if (typeRewriteContext == null || !((TypeReference)current2).IsValueType || current2.IsEnum) { continue; } Enumerator enumerator3 = current2.Fields.GetEnumerator(); try { while (enumerator3.MoveNext()) { FieldDefinition current3 = enumerator3.Current; if ((current3.IsStatic && !current3.HasConstant) || (typeRewriteContext.NewType.IsExplicitLayout && !current3.IsStatic) || typeRewriteContext.TryGetFieldByUnityAssemblyField(current3) != null) { continue; } TypeReference val = Pass80UnstripMethods.ResolveTypeInNewAssemblies(context, ((FieldReference)current3).FieldType, imports); if (val == null) { Logger.Instance.LogTrace("Field {UnityField} on type {UnityType} has unsupported type {UnityFieldType}, the type will be unusable", ((object)current3).ToString(), ((MemberReference)current2).FullName, ((object)((FieldReference)current3).FieldType).ToString()); num2++; continue; } FieldDefinition val2 = new FieldDefinition(((MemberReference)current3).Name, (FieldAttributes)((current3.Attributes & 0xFFF8) | 6), val); if (current3.HasConstant) { val2.Constant = current3.Constant; } typeRewriteContext.NewType.Fields.Add(val2); num++; } } finally { ((IDisposable)enumerator3).Dispose(); } } } finally { ((IDisposable)enumerator2).Dispose(); } } Logger.Instance.LogInformation("Restored {FieldsUnstripped} fields", num); Logger.Instance.LogInformation("Failed to restore {FieldsIgnored} fields", num2); } } public static class Pass80UnstripMethods { internal sealed class TypeComparer : IEqualityComparer { public bool Equals(ParameterDefinition x, ParameterDefinition y) { if (x == null) { return y == null; } if (y == null) { return false; } return ((MemberReference)((ParameterReference)x).ParameterType).FullName.Equals(((MemberReference)((ParameterReference)y).ParameterType).FullName); } public int GetHashCode(ParameterDefinition obj) { return ((MemberReference)((ParameterReference)obj).ParameterType).FullName.GetHashCode(); } } public static void DoPass(RewriteGlobalContext context) { //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Invalid comparison between Unknown and I4 //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Expected O, but got Unknown //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_022d: 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_023e: Expected O, but got Unknown //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Expected O, but got Unknown //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_02a8: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Expected O, but got Unknown int num = 0; int num2 = 0; foreach (AssemblyDefinition assembly in context.UnityAssemblies.Assemblies) { AssemblyRewriteContext assemblyRewriteContext = context.TryGetAssemblyByName(((AssemblyNameReference)assembly.Name).Name); if (assemblyRewriteContext == null) { continue; } RuntimeAssemblyReferences imports = assemblyRewriteContext.Imports; Enumerator enumerator2 = assembly.MainModule.Types.GetEnumerator(); try { while (enumerator2.MoveNext()) { TypeDefinition current2 = enumerator2.Current; TypeRewriteContext typeRewriteContext = assemblyRewriteContext.TryGetTypeByName(((MemberReference)current2).FullName); if (typeRewriteContext == null) { continue; } Enumerator enumerator3 = current2.Methods.GetEnumerator(); try { while (enumerator3.MoveNext()) { MethodDefinition current3 = enumerator3.Current; bool flag = (current3.ImplAttributes & 0x1000) > 0; if (((MemberReference)current3).Name == ".cctor" || ((MemberReference)current3).Name == ".ctor" || current3.IsAbstract || (!current3.HasBody && !flag) || typeRewriteContext.TryGetMethodByUnityAssemblyMethod(current3) != null) { continue; } TypeReference val = ResolveTypeInNewAssemblies(context, ((MethodReference)current3).ReturnType, imports); if (val == null) { Logger.Instance.LogTrace("Method {UnityMethod} has unsupported return type {UnityMethodReturnType}", ((object)current3).ToString(), ((object)((MethodReference)current3).ReturnType).ToString()); num2++; continue; } MethodDefinition val2 = new MethodDefinition(((MemberReference)current3).Name, (MethodAttributes)((current3.Attributes & 0xFFF8) | 6), val); bool flag2 = false; Enumerator enumerator4 = ((MethodReference)current3).Parameters.GetEnumerator(); try { while (enumerator4.MoveNext()) { ParameterDefinition current4 = enumerator4.Current; TypeReference val3 = ResolveTypeInNewAssemblies(context, ((ParameterReference)current4).ParameterType, imports); if (val3 == null) { flag2 = true; Logger.Instance.LogTrace("Method {UnityMethod} has unsupported parameter type {UnityMethodParameter}", ((object)current3).ToString(), ((object)current4).ToString()); break; } ((MethodReference)val2).Parameters.Add(new ParameterDefinition(((ParameterReference)current4).Name, current4.Attributes, val3)); } } finally { ((IDisposable)enumerator4).Dispose(); } if (flag2) { num2++; continue; } Enumerator enumerator5 = ((MethodReference)current3).GenericParameters.GetEnumerator(); try { while (enumerator5.MoveNext()) { GenericParameter current5 = enumerator5.Current; GenericParameter val4 = new GenericParameter(((MemberReference)current5).Name, (IGenericParameterProvider)(object)val2); val4.Attributes = current5.Attributes; Enumerator enumerator6 = current5.Constraints.GetEnumerator(); try { while (enumerator6.MoveNext()) { GenericParameterConstraint current6 = enumerator6.Current; if (!(((MemberReference)current6.ConstraintType).FullName == "System.ValueType") && !current6.ConstraintType.Resolve().IsInterface) { TypeReference val5 = ResolveTypeInNewAssemblies(context, current6.ConstraintType, imports); if (val5 != null) { val4.Constraints.Add(new GenericParameterConstraint(val5)); } } } } finally { ((IDisposable)enumerator6).Dispose(); } ((MethodReference)val2).GenericParameters.Add(val4); } } finally { ((IDisposable)enumerator5).Dispose(); } if (flag) { TypeDefinition val6 = UnstripGenerator.CreateDelegateTypeForICallMethod(current3, val2, imports); typeRewriteContext.NewType.NestedTypes.Add(val6); val6.DeclaringType = typeRewriteContext.NewType; typeRewriteContext.NewType.Methods.Add(val2); FieldDefinition delegateField = UnstripGenerator.GenerateStaticCtorSuffix(typeRewriteContext.NewType, val6, current3, imports); UnstripGenerator.GenerateInvokerMethodBody(val2, delegateField, val6, typeRewriteContext, imports); } else { Pass81FillUnstrippedMethodBodies.PushMethod(current3, val2, typeRewriteContext, imports); typeRewriteContext.NewType.Methods.Add(val2); } if (current3.IsGetter) { GetOrCreateProperty(current3, val2).GetMethod = val2; } else if (current3.IsSetter) { GetOrCreateProperty(current3, val2).SetMethod = val2; } MethodDefinition val7 = context.CreateParamsMethod(current3, val2, imports, (TypeReference type) => ResolveTypeInNewAssemblies(context, type, imports)); if (val7 != null) { typeRewriteContext.NewType.Methods.Add(val7); } num++; } } finally { ((IDisposable)enumerator3).Dispose(); } } } finally { ((IDisposable)enumerator2).Dispose(); } } Logger.Instance.LogInformation("Restored {UnstrippedMethods} methods", num); Logger.Instance.LogInformation("Failed to restore {IgnoredMethods} methods", num2); } private static PropertyDefinition GetOrCreateProperty(MethodDefinition unityMethod, MethodDefinition newMethod) { //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown PropertyDefinition unityProperty = ((IEnumerable)unityMethod.DeclaringType.Properties).Single((PropertyDefinition it) => it.SetMethod == unityMethod || it.GetMethod == unityMethod); PropertyDefinition val = ((IEnumerable)newMethod.DeclaringType.Properties).SingleOrDefault((Func)((PropertyDefinition it) => ((MemberReference)it).Name == ((MemberReference)unityProperty).Name && ((PropertyReference)it).Parameters.Count == ((PropertyReference)unityProperty).Parameters.Count && ((IEnumerable)((PropertyReference)it).Parameters).SequenceEqual((IEnumerable)((PropertyReference)unityProperty).Parameters, new TypeComparer()))); if (val == null) { val = new PropertyDefinition(((MemberReference)unityProperty).Name, (PropertyAttributes)0, unityMethod.IsGetter ? ((MethodReference)newMethod).ReturnType : ((ParameterReference)((IEnumerable)((MethodReference)newMethod).Parameters).Last()).ParameterType); newMethod.DeclaringType.Properties.Add(val); } return val; } internal static TypeReference? ResolveTypeInNewAssemblies(RewriteGlobalContext context, TypeReference unityType, RuntimeAssemblyReferences imports) { TypeReference val = ResolveTypeInNewAssembliesRaw(context, unityType, imports); if (val == null) { return null; } return imports.Module.ImportReference(val); } internal static TypeReference? ResolveTypeInNewAssembliesRaw(RewriteGlobalContext context, TypeReference unityType, RuntimeAssemblyReferences imports) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Expected O, but got Unknown //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Expected O, but got Unknown //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Expected O, but got Unknown if (unityType is ByReferenceType) { TypeReference val = ResolveTypeInNewAssemblies(context, unityType.GetElementType(), imports); if (val != null) { return (TypeReference?)new ByReferenceType(val); } return null; } if (unityType is GenericParameter) { return null; } TypeReference obj = unityType; ArrayType val2 = (ArrayType)(object)((obj is ArrayType) ? obj : null); if (val2 != null) { if (val2.Rank != 1) { return null; } TypeReference val3 = ResolveTypeInNewAssemblies(context, unityType.GetElementType(), imports); if (val3 == null) { return null; } if (((MemberReference)val3).FullName == "System.String") { return imports.Il2CppStringArray; } GenericInstanceType val4 = new GenericInstanceType(val3.IsValueType ? imports.Il2CppStructArray : imports.Il2CppReferenceArray); val4.GenericArguments.Add(val3); return (TypeReference?)val4; } if (((MemberReference)unityType).DeclaringType != null) { TypeReference val5 = ResolveTypeInNewAssembliesRaw(context, ((MemberReference)unityType).DeclaringType, imports); if (val5 == null) { return null; } TypeDefinition val6 = ((IEnumerable)val5.Resolve().NestedTypes).FirstOrDefault((Func)((TypeDefinition it) => ((MemberReference)it).Name == ((MemberReference)unityType).Name)); if (val6 == null) { return null; } return (TypeReference?)(object)val6; } if (unityType is PointerType) { TypeReference val7 = ResolveTypeInNewAssemblies(context, unityType.GetElementType(), imports); if (val7 != null) { return (TypeReference?)new PointerType(val7); } return null; } TypeReference obj2 = unityType; GenericInstanceType val8 = (GenericInstanceType)(object)((obj2 is GenericInstanceType) ? obj2 : null); if (val8 != null) { TypeReference val9 = ResolveTypeInNewAssembliesRaw(context, ((TypeSpecification)val8).ElementType, imports); if (val9 == null) { return null; } GenericInstanceType val10 = new GenericInstanceType(val9); Enumerator enumerator = val8.GenericArguments.GetEnumerator(); try { while (enumerator.MoveNext()) { TypeReference current = enumerator.Current; TypeReference val11 = ResolveTypeInNewAssemblies(context, current, imports); if (val11 == null) { return null; } val10.GenericArguments.Add(val11); } return (TypeReference?)(object)val10; } finally { ((IDisposable)enumerator).Dispose(); } } string text = unityType.Scope.Name; if (text.EndsWith(".dll")) { text = text.Substring(0, text.Length - 4); } if ((text == "mscorlib" || text == "netstandard") && (unityType.IsValueType || ((MemberReference)unityType).FullName == "System.String" || ((MemberReference)unityType).FullName == "System.Void") && ((MemberReference)unityType).FullName != "System.RuntimeTypeHandle") { return imports.Module.ImportCorlibReference(unityType.Namespace, ((MemberReference)unityType).Name); } if (text == "UnityEngine") { foreach (AssemblyRewriteContext assembly in context.Assemblies) { if (((AssemblyNameReference)assembly.NewAssembly.Name).Name.StartsWith("UnityEngine")) { TypeDefinition val12 = assembly.TryGetTypeByName(((MemberReference)unityType).FullName)?.NewType; if (val12 != null) { return (TypeReference?)(object)val12; } } } } return (TypeReference?)(object)context.TryGetAssemblyByName(text)?.TryGetTypeByName(((MemberReference)unityType).FullName)?.NewType; } } public static class Pass81FillUnstrippedMethodBodies { private static readonly List<(MethodDefinition unityMethod, MethodDefinition newMethod, TypeRewriteContext processedType, RuntimeAssemblyReferences imports)> StuffToProcess = new List<(MethodDefinition, MethodDefinition, TypeRewriteContext, RuntimeAssemblyReferences)>(); public static void DoPass(RewriteGlobalContext context) { int num = 0; int num2 = 0; foreach (var (original, val, typeRewriteContext, imports) in StuffToProcess) { if (!UnstripTranslator.TranslateMethod(original, val, typeRewriteContext, imports)) { num2++; UnstripTranslator.ReplaceBodyWithException(val, imports); } else { num++; } } Logger.Instance.LogInformation("IL unstrip statistics: {MethodsSucceeded} successful, {MethodsFailed} failed", num, num2); } public static void PushMethod(MethodDefinition unityMethod, MethodDefinition newMethod, TypeRewriteContext processedType, RuntimeAssemblyReferences imports) { StuffToProcess.Add((unityMethod, newMethod, processedType, imports)); } } public static class Pass89GenerateForwarders { public static void DoPass(RewriteGlobalContext context) { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown AssemblyRewriteContext assemblyRewriteContext = context.TryGetAssemblyByName("UnityEngine"); if (assemblyRewriteContext == null) { Logger.Instance.LogInformation("No UnityEngine.dll, will not generate forwarders"); return; } ModuleDefinition mainModule = assemblyRewriteContext.NewAssembly.MainModule; foreach (AssemblyRewriteContext assembly in context.Assemblies) { if (!((AssemblyNameReference)assembly.NewAssembly.Name).Name.StartsWith("UnityEngine.")) { continue; } Enumerator enumerator2 = assembly.NewAssembly.MainModule.Types.GetEnumerator(); try { while (enumerator2.MoveNext()) { TypeDefinition current2 = enumerator2.Current; if (!(((MemberReference)current2).Name == "")) { TypeReference val = mainModule.ImportReference((TypeReference)(object)current2); ExportedType val2 = new ExportedType(((TypeReference)current2).Namespace, ((MemberReference)current2).Name, ((MemberReference)val).Module, val.Scope) { Attributes = (TypeAttributes)2097152 }; mainModule.ExportedTypes.Add(val2); AddNestedTypes(current2, val2, mainModule); } } } finally { ((IDisposable)enumerator2).Dispose(); } } } private static void AddNestedTypes(TypeDefinition mainModuleType, ExportedType importedType, ModuleDefinition targetModule) { //IL_0006: 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_0017: 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_001f: Invalid comparison between Unknown and I4 //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown Enumerator enumerator = mainModuleType.NestedTypes.GetEnumerator(); try { while (enumerator.MoveNext()) { TypeDefinition current = enumerator.Current; if ((current.Attributes & 7) == 2) { TypeReference val = targetModule.ImportReference((TypeReference)(object)current); ExportedType val2 = new ExportedType(val.Namespace, ((MemberReference)val).Name, ((MemberReference)val).Module, val.Scope) { Attributes = (TypeAttributes)2097152 }; val2.DeclaringType = importedType; targetModule.ExportedTypes.Add(val2); AddNestedTypes(current, val2, targetModule); } } } finally { ((IDisposable)enumerator).Dispose(); } } } public static class Pass89GenerateMethodXrefCache { public static void DoPass(RewriteGlobalContext context, GeneratorOptions options) { //IL_048e: Unknown result type (might be due to invalid IL or missing references) //IL_04b4: Unknown result type (might be due to invalid IL or missing references) //IL_04b6: Unknown result type (might be due to invalid IL or missing references) //IL_04db: Unknown result type (might be due to invalid IL or missing references) //IL_04ed: Unknown result type (might be due to invalid IL or missing references) //IL_04f2: Unknown result type (might be due to invalid IL or missing references) //IL_04f5: Unknown result type (might be due to invalid IL or missing references) //IL_0558: Unknown result type (might be due to invalid IL or missing references) //IL_055d: Unknown result type (might be due to invalid IL or missing references) //IL_056d: Unknown result type (might be due to invalid IL or missing references) //IL_0582: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_011a: 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) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Expected O, but got Unknown //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_02d5: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_0307: Unknown result type (might be due to invalid IL or missing references) //IL_0325: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_0334: Unknown result type (might be due to invalid IL or missing references) //IL_0352: Unknown result type (might be due to invalid IL or missing references) //IL_0357: Unknown result type (might be due to invalid IL or missing references) //IL_0361: Unknown result type (might be due to invalid IL or missing references) //IL_037f: Unknown result type (might be due to invalid IL or missing references) //IL_0384: Unknown result type (might be due to invalid IL or missing references) //IL_038e: Unknown result type (might be due to invalid IL or missing references) //IL_03b1: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_03c0: Unknown result type (might be due to invalid IL or missing references) //IL_03e3: Unknown result type (might be due to invalid IL or missing references) //IL_03e8: Unknown result type (might be due to invalid IL or missing references) //IL_03f7: Expected O, but got Unknown //IL_03fa: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: Unknown result type (might be due to invalid IL or missing references) //IL_0407: Unknown result type (might be due to invalid IL or missing references) //IL_040f: Unknown result type (might be due to invalid IL or missing references) //IL_0417: Unknown result type (might be due to invalid IL or missing references) //IL_041f: Unknown result type (might be due to invalid IL or missing references) //IL_042c: Unknown result type (might be due to invalid IL or missing references) //IL_043e: Expected O, but got Unknown //IL_0279: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Unknown result type (might be due to invalid IL or missing references) List list = new List(); Dictionary dictionary = new Dictionary(); if (!options.NoXrefCache) { foreach (AssemblyRewriteContext assembly in context.Assemblies) { if (options.AdditionalAssembliesBlacklist.Contains(((AssemblyNameReference)assembly.NewAssembly.Name).Name)) { continue; } RuntimeAssemblyReferences imports = assembly.Imports; foreach (TypeRewriteContext type in assembly.Types) { foreach (MethodRewriteContext method in type.Methods) { long rva = method.Rva; if (dictionary.TryGetValue(rva, out var value)) { Collection customAttributes = method.NewMethod.CustomAttributes; CustomAttribute val = new CustomAttribute(imports.CachedScanResultsAttributector.Value); val.Fields.Add(new CustomAttributeNamedArgument("RefRangeStart", new CustomAttributeArgument(imports.Module.Int(), (object)value.RefRangeStart))); val.Fields.Add(new CustomAttributeNamedArgument("RefRangeEnd", new CustomAttributeArgument(imports.Module.Int(), (object)value.RefRangeEnd))); val.Fields.Add(new CustomAttributeNamedArgument("XrefRangeStart", new CustomAttributeArgument(imports.Module.Int(), (object)value.RefRangeStart))); val.Fields.Add(new CustomAttributeNamedArgument("XrefRangeEnd", new CustomAttributeArgument(imports.Module.Int(), (object)value.RefRangeEnd))); val.Fields.Add(new CustomAttributeNamedArgument("MetadataInitTokenRva", new CustomAttributeArgument(imports.Module.Long(), (object)value.MetadataInitTokenRva))); val.Fields.Add(new CustomAttributeNamedArgument("MetadataInitFlagRva", new CustomAttributeArgument(imports.Module.Long(), (object)value.MetadataInitFlagRva))); customAttributes.Add(val); continue; } int count = list.Count; foreach (XrefInstance xrefScanResult in method.XrefScanResults) { list.Add(MethodData.FromXrefInstance(xrefScanResult)); } int count2 = list.Count; int num = 0; int num2 = 0; if (rva != 0L && Pass16ScanMethodRefs.MapOfCallers.TryGetValue(rva, out var value2)) { num = list.Count; foreach (XrefInstance item in value2) { list.Add(MethodData.FromXrefInstance(item)); } num2 = list.Count; } if (count2 != count || num != num2) { Collection customAttributes2 = method.NewMethod.CustomAttributes; CustomAttribute val2 = new CustomAttribute(imports.CachedScanResultsAttributector.Value); val2.Fields.Add(new CustomAttributeNamedArgument("RefRangeStart", new CustomAttributeArgument(imports.Module.Int(), (object)num))); val2.Fields.Add(new CustomAttributeNamedArgument("RefRangeEnd", new CustomAttributeArgument(imports.Module.Int(), (object)num2))); val2.Fields.Add(new CustomAttributeNamedArgument("XrefRangeStart", new CustomAttributeArgument(imports.Module.Int(), (object)count))); val2.Fields.Add(new CustomAttributeNamedArgument("XrefRangeEnd", new CustomAttributeArgument(imports.Module.Int(), (object)count2))); val2.Fields.Add(new CustomAttributeNamedArgument("MetadataInitTokenRva", new CustomAttributeArgument(imports.Module.Long(), (object)method.MetadataInitTokenRva))); val2.Fields.Add(new CustomAttributeNamedArgument("MetadataInitFlagRva", new CustomAttributeArgument(imports.Module.Long(), (object)method.MetadataInitFlagRva))); customAttributes2.Add(val2); dictionary[rva] = new CachedScanResultsAttribute { RefRangeStart = num, RefRangeEnd = num2, XrefRangeStart = count, XrefRangeEnd = count2, MetadataInitFlagRva = method.MetadataInitFlagRva, MetadataInitTokenRva = method.MetadataInitTokenRva }; } } } } } FileHeader val3 = default(FileHeader); val3.Magic = 1129860437; val3.Version = 1; val3.InitMethodMetadataRva = XrefScanMetadataGenerationUtil.MetadataInitForMethodRva; FileHeader value3 = val3; using BinaryWriter writer = new BinaryWriter(new FileStream(Path.Combine(options.OutputDir, "MethodXrefScanCache.db"), FileMode.Create, FileAccess.Write), Encoding.UTF8, leaveOpen: false); writer.Write(value3); foreach (MethodData item2 in list) { writer.Write(item2); } if (!options.Verbose) { return; } using StreamWriter streamWriter = new StreamWriter(Path.Combine(options.OutputDir, "MethodXrefScanCache.db.txt")); for (int i = 0; i < list.Count; i++) { streamWriter.WriteLine($"{i}\t{list[i].Type}\t{list[i].Address}\t{list[i].FoundAt}"); } } } public static class Pass90WriteToDisk { public static void DoPass(RewriteGlobalContext context, GeneratorOptions options) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) MethodInfo method = typeof(DefaultAssemblyResolver).GetMethod("RegisterAssembly", BindingFlags.Instance | BindingFlags.NonPublic); foreach (AssemblyRewriteContext assembly in context.Assemblies) { ModuleDefinition mainModule = assembly.NewAssembly.MainModule; IAssemblyResolver assemblyResolver = mainModule.AssemblyResolver; DefaultAssemblyResolver val = (DefaultAssemblyResolver)(object)((assemblyResolver is DefaultAssemblyResolver) ? assemblyResolver : null); if (val == null) { continue; } Enumerator enumerator2 = mainModule.AssemblyReferences.GetEnumerator(); try { while (enumerator2.MoveNext()) { AssemblyNameReference reference = enumerator2.Current; if (reference.Name == "System.Private.CoreLib") { CorlibReferences.RewriteReferenceToMscorlib(reference); continue; } AssemblyRewriteContext assemblyRewriteContext = context.Assemblies.FirstOrDefault((AssemblyRewriteContext f) => f.NewAssembly.FullName == reference.FullName); if (assemblyRewriteContext != null) { method.Invoke(val, new object[1] { assemblyRewriteContext.NewAssembly }); } } } finally { ((IDisposable)enumerator2).Dispose(); } } IEnumerable enumerable = context.Assemblies.Where((AssemblyRewriteContext it) => !options.AdditionalAssembliesBlacklist.Contains(((AssemblyNameReference)it.NewAssembly.Name).Name)); if (options.Parallel) { Parallel.ForEach(enumerable, Processor); return; } foreach (AssemblyRewriteContext item in enumerable) { Processor(item); } void Processor(AssemblyRewriteContext assemblyContext) { assemblyContext.NewAssembly.Write(Path.Combine(options.OutputDir ?? ".", ((AssemblyNameReference)assemblyContext.NewAssembly.Name).Name + ".dll")); } } } public static class Pass91GenerateMethodPointerMap { public static void DoPass(RewriteGlobalContext context, GeneratorOptions options) { //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0162: 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_0189: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Unknown result type (might be due to invalid IL or missing references) List<(long, int, int)> list = new List<(long, int, int)>(); List list2 = new List(); foreach (AssemblyRewriteContext assembly in context.Assemblies) { if (options.AdditionalAssembliesBlacklist.Contains(((AssemblyNameReference)assembly.NewAssembly.Name).Name)) { continue; } list2.Add(assembly.NewAssembly.FullName); foreach (TypeRewriteContext type in assembly.Types) { foreach (MethodRewriteContext method in type.Methods) { long rva = method.Rva; if (rva != 0L) { MetadataToken metadataToken = ((MemberReference)method.NewMethod).MetadataToken; list.Add((rva, ((MetadataToken)(ref metadataToken)).ToInt32(), list2.Count - 1)); } } } } list.Sort(((long, int, int) a, (long, int, int) b) => a.Item1.CompareTo(b.Item1)); MethodAddressToTokenMapFileHeader val = default(MethodAddressToTokenMapFileHeader); val.Magic = 1297370453; val.Version = 1; val.NumMethods = list.Count; val.NumAssemblies = list2.Count; MethodAddressToTokenMapFileHeader value = val; using BinaryWriter binaryWriter = new BinaryWriter(new FileStream(Path.Combine(options.OutputDir, "MethodAddressToToken.db"), FileMode.Create, FileAccess.Write), Encoding.UTF8, leaveOpen: false); binaryWriter.Write(value); foreach (string item in list2) { binaryWriter.Write(item); } value.DataOffset = (int)binaryWriter.BaseStream.Position; foreach (var item2 in list) { binaryWriter.Write(item2.Item1); } foreach (var item3 in list) { binaryWriter.Write(item3.Item2); binaryWriter.Write(item3.Item3); } binaryWriter.BaseStream.Position = 0L; binaryWriter.Write(value); if (!options.Verbose) { return; } using StreamWriter streamWriter = new StreamWriter(Path.Combine(options.OutputDir, "MethodAddressToToken.db.txt")); for (int i = 0; i < list.Count; i++) { streamWriter.WriteLine($"{i}\t{list[i].Item1}\t{list[i].Item2}\t{list[i].Item3}"); } } } } namespace Il2CppInterop.Generator.MetadataAccess { public class CecilMetadataAccess : IIl2CppMetadataAccess, IMetadataAccess, IDisposable { private class Resolver : DefaultAssemblyResolver { public void Register(AssemblyDefinition ass) { ((DefaultAssemblyResolver)this).RegisterAssembly(ass); } } private readonly List myAssemblies = new List(); private readonly Dictionary myAssembliesByName = new Dictionary(); private readonly Resolver myAssemblyResolver = new Resolver(); private readonly Dictionary<(string AssemblyName, string TypeName), TypeDefinition> myTypesByName = new Dictionary<(string, string), TypeDefinition>(); public IList Assemblies => myAssemblies; public CecilMetadataAccess(IEnumerable assemblyPaths) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown MetadataResolver metadataResolver = new MetadataResolver((IAssemblyResolver)(object)myAssemblyResolver); Load(assemblyPaths.Select((string path) => AssemblyDefinition.ReadAssembly(path, new ReaderParameters((ReadingMode)2) { MetadataResolver = (IMetadataResolver)(object)metadataResolver }))); } public CecilMetadataAccess(IEnumerable assemblies) { Load(assemblies); } public void Dispose() { foreach (AssemblyDefinition myAssembly in myAssemblies) { myAssembly.Dispose(); } myAssemblies.Clear(); myAssembliesByName.Clear(); ((BaseAssemblyResolver)myAssemblyResolver).Dispose(); } public AssemblyDefinition? GetAssemblyBySimpleName(string name) { if (!myAssembliesByName.TryGetValue(name, out var value)) { return null; } return value; } public TypeDefinition? GetTypeByName(string assemblyName, string typeName) { if (!myTypesByName.TryGetValue((assemblyName, typeName), out var value)) { return null; } return value; } public IList? GetKnownInstantiationsFor(TypeDefinition genericDeclaration) { return null; } public string? GetStringStoredAtAddress(long offsetInMemory) { return null; } public MethodReference? GetMethodRefStoredAt(long offsetInMemory) { return null; } private void Load(IEnumerable assemblies) { //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) foreach (AssemblyDefinition assembly in assemblies) { myAssemblyResolver.Register(assembly); myAssemblies.Add(assembly); myAssembliesByName[((AssemblyNameReference)assembly.Name).Name] = assembly; } foreach (AssemblyDefinition myAssembly in myAssemblies) { string name = ((AssemblyNameReference)myAssembly.Name).Name; Enumerator enumerator3 = myAssembly.MainModule.Types.GetEnumerator(); try { while (enumerator3.MoveNext()) { TypeDefinition current3 = enumerator3.Current; myTypesByName[(name, ((MemberReference)current3).FullName)] = current3; } } finally { ((IDisposable)enumerator3).Dispose(); } } } } public interface IIl2CppMetadataAccess : IMetadataAccess, IDisposable { IList? GetKnownInstantiationsFor(TypeDefinition genericDeclaration); string? GetStringStoredAtAddress(long offsetInMemory); MethodReference? GetMethodRefStoredAt(long offsetInMemory); } public interface IMetadataAccess : IDisposable { IList Assemblies { get; } AssemblyDefinition? GetAssemblyBySimpleName(string name); TypeDefinition? GetTypeByName(string assemblyName, string typeName); } public class NullMetadataAccess : IMetadataAccess, IDisposable { public static readonly NullMetadataAccess Instance = new NullMetadataAccess(); public IList Assemblies => (IList)ReadOnlyCollection.Empty; public void Dispose() { } public AssemblyDefinition? GetAssemblyBySimpleName(string name) { return null; } public TypeDefinition? GetTypeByName(string assemblyName, string typeName) { return null; } public IList? GetKnownInstantiationsFor(TypeReference genericDeclaration) { return null; } public string? GetStringStoredAtAddress(long offsetInMemory) { return null; } public MethodReference? GetMethodRefStoredAt(long offsetInMemory) { return null; } } } namespace Il2CppInterop.Generator.Extensions { public static class CollectionEx { public static TV GetOrCreate(this IDictionary dict, TK key, Func valueFactory) where TK : notnull { if (!dict.TryGetValue(key, out var value)) { value = (dict[key] = valueFactory(key)); } return value; } public static void AddLocked(this List list, T value) { lock (list) { list.Add(value); } } } public static class CustomAttributeEx { public static long ExtractOffset(this ICustomAttributeProvider originalMethod) { return originalMethod.ExtractLong("AddressAttribute", "Offset"); } public static long ExtractRva(this ICustomAttributeProvider originalMethod) { return originalMethod.ExtractLong("AddressAttribute", "RVA"); } public static long ExtractToken(this ICustomAttributeProvider originalMethod) { return originalMethod.ExtractLong("TokenAttribute", "Token"); } public static int ExtractFieldOffset(this ICustomAttributeProvider originalField) { return originalField.ExtractInt("FieldOffsetAttribute", "Offset"); } private static string Extract(this ICustomAttributeProvider originalMethod, string attributeName, string parameterName) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) CustomAttribute? obj = ((IEnumerable)originalMethod.CustomAttributes).SingleOrDefault((Func)((CustomAttribute it) => ((MemberReference)it.AttributeType).Name == attributeName)); CustomAttributeNamedArgument? val = ((obj != null) ? new CustomAttributeNamedArgument?(((IEnumerable)obj.Fields).SingleOrDefault((Func)((CustomAttributeNamedArgument it) => ((CustomAttributeNamedArgument)(ref it)).Name == parameterName))) : null); object obj2; CustomAttributeNamedArgument val2; if (!val.HasValue) { obj2 = null; } else { val2 = val.GetValueOrDefault(); obj2 = ((CustomAttributeNamedArgument)(ref val2)).Name; } if (obj2 == null) { return null; } val2 = val.Value; CustomAttributeArgument argument = ((CustomAttributeNamedArgument)(ref val2)).Argument; return (string)((CustomAttributeArgument)(ref argument)).Value; } private static long ExtractLong(this ICustomAttributeProvider originalMethod, string attributeName, string parameterName) { return Convert.ToInt64(originalMethod.Extract(attributeName, parameterName), 16); } private static int ExtractInt(this ICustomAttributeProvider originalMethod, string attributeName, string parameterName) { return Convert.ToInt32(originalMethod.Extract(attributeName, parameterName), 16); } } public static class EnumEx { public static FieldAttributes ForcePublic(this FieldAttributes fieldAttributes) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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) //IL_000e: Unknown result type (might be due to invalid IL or missing references) return (FieldAttributes)((fieldAttributes & 0xFFF8 & 0xEFFF) | 6); } public static GenericParameterAttributes StripValueTypeConstraint(this GenericParameterAttributes parameterAttributes) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) return (GenericParameterAttributes)(parameterAttributes & 0xFFF4); } } public static class ILGeneratorEx { private static readonly OpCode[] I4Constants = (OpCode[])(object)new OpCode[10] { OpCodes.Ldc_I4_M1, OpCodes.Ldc_I4_0, OpCodes.Ldc_I4_1, OpCodes.Ldc_I4_2, OpCodes.Ldc_I4_3, OpCodes.Ldc_I4_4, OpCodes.Ldc_I4_5, OpCodes.Ldc_I4_6, OpCodes.Ldc_I4_7, OpCodes.Ldc_I4_8 }; public static void EmitLdcI4(this ILProcessor body, int constant) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) if (constant >= -1 && constant <= 8) { body.Emit(I4Constants[constant + 1]); } else if (constant >= 0 && constant <= 255) { body.Emit(OpCodes.Ldc_I4_S, (sbyte)constant); } else { body.Emit(OpCodes.Ldc_I4, constant); } } public static void EmitObjectStore(this ILProcessor body, TypeReference originalType, TypeReference newType, TypeRewriteContext enclosingType, int argumentIndex) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Expected O, but got Unknown //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Expected O, but got Unknown //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0094: 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) if (originalType is GenericParameter) { EmitObjectStoreGeneric(body, originalType, newType, enclosingType, argumentIndex); return; } RuntimeAssemblyReferences imports = enclosingType.AssemblyContext.Imports; if (((MemberReference)originalType).FullName == "System.String") { body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Call, imports.IL2CPP_ManagedStringToIl2Cpp.Value); body.Emit(OpCodes.Call, imports.WriteFieldWBarrier); } else if (originalType.IsValueType) { if (enclosingType.AssemblyContext.GlobalContext.JudgeSpecificsByOriginalType(originalType) == TypeRewriteContext.TypeSpecifics.BlittableStruct) { body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Stobj, newType); body.Emit(OpCodes.Pop); return; } body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Call, imports.IL2CPP_Il2CppObjectBaseToPtr.Value); body.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_object_unbox.Value); GenericInstanceType val = new GenericInstanceType(imports.Il2CppClassPointerStore); val.GenericArguments.Add(newType); GenericInstanceType val2 = val; FieldReference val3 = new FieldReference("NativeClassPtr", imports.Module.IntPtr(), (TypeReference)(object)val2); body.Emit(OpCodes.Ldsfld, ((MemberReference)enclosingType.NewType).Module.ImportReference(val3)); body.Emit(OpCodes.Ldc_I4_0); body.Emit(OpCodes.Conv_U); body.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_class_value_size.Value); body.Emit(OpCodes.Cpblk); body.Emit(OpCodes.Pop); } else { body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Call, imports.IL2CPP_Il2CppObjectBaseToPtr.Value); body.Emit(OpCodes.Call, imports.WriteFieldWBarrier); } } private static void EmitObjectStoreGeneric(ILProcessor body, TypeReference originalType, TypeReference newType, TypeRewriteContext enclosingType, int argumentIndex) { //IL_000d: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Expected O, but got Unknown //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0210: 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_0231: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_0301: Unknown result type (might be due to invalid IL or missing references) RuntimeAssemblyReferences imports = enclosingType.AssemblyContext.Imports; body.Emit(OpCodes.Ldtoken, newType); body.Emit(OpCodes.Call, ((MemberReference)enclosingType.NewType).Module.TypeGetTypeFromHandle()); body.Emit(OpCodes.Dup); body.Emit(OpCodes.Callvirt, ((MemberReference)enclosingType.NewType).Module.TypeGetIsValueType()); Instruction val = body.Create(OpCodes.Nop); Instruction val2 = body.Create(OpCodes.Nop); Instruction val3 = body.Create(OpCodes.Nop); Instruction val4 = body.Create(OpCodes.Nop); body.Emit(OpCodes.Brtrue, val3); body.Emit(OpCodes.Callvirt, ((MemberReference)enclosingType.NewType).Module.TypeGetFullName()); body.Emit(OpCodes.Ldstr, "System.String"); body.Emit(OpCodes.Call, ((MemberReference)enclosingType.NewType).Module.StringEquals()); body.Emit(OpCodes.Brtrue_S, val2); body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Box, newType); body.Emit(OpCodes.Isinst, imports.Il2CppObjectBase); body.Emit(OpCodes.Call, imports.IL2CPP_Il2CppObjectBaseToPtr.Value); body.Emit(OpCodes.Dup); body.Emit(OpCodes.Brfalse_S, val4); body.Emit(OpCodes.Dup); body.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_object_get_class.Value); body.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_class_is_valuetype.Value); body.Emit(OpCodes.Brfalse_S, val4); body.Emit(OpCodes.Dup); VariableDefinition val5 = new VariableDefinition(imports.Module.IntPtr()); body.Body.Variables.Add(val5); body.Emit(OpCodes.Stloc, val5); body.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_object_unbox.Value); body.Emit(OpCodes.Ldloc, val5); body.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_object_get_class.Value); body.Emit(OpCodes.Ldc_I4_0); body.Emit(OpCodes.Conv_U); body.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_class_value_size.Value); body.Emit(OpCodes.Cpblk); body.Emit(OpCodes.Pop); body.Emit(OpCodes.Br_S, val); body.Append(val4); body.Emit(OpCodes.Call, imports.WriteFieldWBarrier); body.Emit(OpCodes.Br_S, val); body.Append(val2); body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Box, newType); body.Emit(OpCodes.Isinst, imports.Module.String()); body.Emit(OpCodes.Call, imports.IL2CPP_ManagedStringToIl2Cpp.Value); body.Emit(OpCodes.Call, imports.WriteFieldWBarrier); body.Emit(OpCodes.Br_S, val); body.Append(val3); body.Emit(OpCodes.Pop); body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Stobj, newType); body.Emit(OpCodes.Pop); body.Append(val); } public static void EmitObjectToPointer(this ILProcessor body, TypeReference originalType, TypeReference newType, TypeRewriteContext enclosingType, int argumentIndex, bool valueTypeArgument0IsAPointer, bool allowNullable, bool unboxNonBlittableType, bool unboxNonBlittableGeneric, out VariableDefinition? refVariable) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0076: 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_019d: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) refVariable = null; if (originalType is GenericParameter) { EmitObjectToPointerGeneric(body, originalType, newType, enclosingType, argumentIndex, valueTypeArgument0IsAPointer, allowNullable, unboxNonBlittableGeneric); return; } RuntimeAssemblyReferences imports = enclosingType.AssemblyContext.Imports; if (originalType is ByReferenceType) { if (newType.GetElementType().IsValueType) { body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Conv_I); return; } if (originalType.GetElementType().IsValueType) { body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Ldind_Ref); body.Emit(OpCodes.Call, imports.IL2CPP_Il2CppObjectBaseToPtrNotNull.Value); return; } VariableDefinition val = (refVariable = new VariableDefinition(imports.Module.IntPtr())); body.Body.Variables.Add(val); body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Ldind_Ref); if (((MemberReference)originalType.GetElementType()).FullName == "System.String") { body.Emit(OpCodes.Call, imports.IL2CPP_ManagedStringToIl2Cpp.Value); } else { body.Emit(OpCodes.Call, imports.IL2CPP_Il2CppObjectBaseToPtr.Value); } body.Emit(OpCodes.Stloc, val); body.Emit(OpCodes.Ldloca, val); body.Emit(OpCodes.Conv_I); } else if (originalType.IsValueType) { if (newType.IsValueType) { if (argumentIndex == 0 && valueTypeArgument0IsAPointer) { body.Emit(OpCodes.Ldarg_0); } else { body.Emit(OpCodes.Ldarga, argumentIndex); } return; } body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Call, imports.IL2CPP_Il2CppObjectBaseToPtrNotNull.Value); if (unboxNonBlittableType) { body.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_object_unbox.Value); } } else if (((MemberReference)originalType).FullName == "System.String") { body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Call, imports.IL2CPP_ManagedStringToIl2Cpp.Value); } else { body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Call, allowNullable ? imports.IL2CPP_Il2CppObjectBaseToPtr.Value : imports.IL2CPP_Il2CppObjectBaseToPtrNotNull.Value); } } private static void EmitObjectToPointerGeneric(ILProcessor body, TypeReference originalType, TypeReference newType, TypeRewriteContext enclosingType, int argumentIndex, bool valueTypeArgument0IsAPointer, bool allowNullable, bool unboxNonBlittableType) { //IL_000d: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) RuntimeAssemblyReferences imports = enclosingType.AssemblyContext.Imports; body.Emit(OpCodes.Ldtoken, newType); body.Emit(OpCodes.Call, ((MemberReference)enclosingType.NewType).Module.TypeGetTypeFromHandle()); body.Emit(OpCodes.Callvirt, ((MemberReference)enclosingType.NewType).Module.TypeGetIsValueType()); Instruction val = body.Create(OpCodes.Nop); Instruction val2 = body.Create(OpCodes.Nop); Instruction val3 = body.Create(OpCodes.Nop); body.Emit(OpCodes.Brtrue, val2); body.Emit(OpCodes.Ldarg, argumentIndex); body.Emit(OpCodes.Box, newType); body.Emit(OpCodes.Dup); body.Emit(OpCodes.Isinst, imports.Module.String()); body.Emit(OpCodes.Brtrue_S, val3); body.Emit(OpCodes.Isinst, imports.Il2CppObjectBase); body.Emit(OpCodes.Call, allowNullable ? imports.IL2CPP_Il2CppObjectBaseToPtr.Value : imports.IL2CPP_Il2CppObjectBaseToPtrNotNull.Value); if (unboxNonBlittableType) { body.Emit(OpCodes.Dup); body.Emit(OpCodes.Brfalse_S, val); body.Emit(OpCodes.Dup); body.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_object_get_class.Value); body.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_class_is_valuetype.Value); body.Emit(OpCodes.Brfalse_S, val); body.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_object_unbox.Value); } body.Emit(OpCodes.Br, val); body.Append(val3); body.Emit(OpCodes.Isinst, imports.Module.String()); body.Emit(OpCodes.Call, imports.IL2CPP_ManagedStringToIl2Cpp.Value); body.Emit(OpCodes.Br_S, val); body.Append(val2); body.Emit(OpCodes.Ldarga, argumentIndex); body.Append(val); } public static void EmitPointerToObject(this ILProcessor body, TypeReference originalReturnType, TypeReference convertedReturnType, TypeRewriteContext enclosingType, Instruction loadPointer, bool extraDerefForNonValueTypes, bool unboxValueType) { //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_0230: 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_0246: Expected O, but got Unknown //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Expected O, but got Unknown //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Expected O, but got Unknown //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: 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) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_02a0: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: 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) //IL_0129: Expected O, but got Unknown //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Expected O, but got Unknown //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Expected O, but got Unknown //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Expected O, but got Unknown //IL_020b: Expected O, but got Unknown //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) if (originalReturnType is GenericParameter) { EmitPointerToObjectGeneric(body, originalReturnType, convertedReturnType, enclosingType, loadPointer, extraDerefForNonValueTypes, unboxValueType); return; } RuntimeAssemblyReferences imports = enclosingType.AssemblyContext.Imports; if (((MemberReference)originalReturnType).FullName == "System.Void") { return; } if (originalReturnType.IsValueType) { if (convertedReturnType.IsValueType) { body.Append(loadPointer); if (unboxValueType) { body.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_object_unbox.Value); } body.Emit(OpCodes.Ldobj, convertedReturnType); return; } if (unboxValueType) { body.Append(loadPointer); } else { GenericInstanceType val = new GenericInstanceType(imports.Il2CppClassPointerStore); val.GenericArguments.Add(convertedReturnType); GenericInstanceType val2 = val; FieldReference val3 = new FieldReference("NativeClassPtr", imports.Module.IntPtr(), (TypeReference)(object)val2); body.Emit(OpCodes.Ldsfld, ((MemberReference)enclosingType.NewType).Module.ImportReference(val3)); body.Append(loadPointer); body.Emit(OpCodes.Call, imports.IL2CPP_il2cpp_value_box.Value); } OpCode newobj = OpCodes.Newobj; MethodReference val4 = new MethodReference(".ctor", imports.Module.Void(), convertedReturnType); val4.Parameters.Add(new ParameterDefinition(imports.Module.IntPtr())); val4.HasThis = true; body.Emit(newobj, val4); } else if (((MemberReference)originalReturnType).FullName == "System.String") { body.Append(loadPointer); if (extraDerefForNonValueTypes) { body.Emit(OpCodes.Ldind_I); } body.Emit(OpCodes.Call, imports.IL2CPP_Il2CppStringToManaged.Value); } else if (originalReturnType.IsArray && originalReturnType.GetElementType().IsGenericParameter) { body.Append(loadPointer); if (extraDerefForNonValueTypes) { body.Emit(OpCodes.Ldind_I); } ModuleDefinition module = imports.Module; GenericInstanceType val5 = new GenericInstanceType(imports.Il2CppArrayBase); val5.GenericArguments.Add((TypeReference)(object)imports.Il2CppArrayBase.GenericParameters[0]); TypeReference val6 = module.ImportReference((TypeReference)val5); MethodReference val7 = new MethodReference("WrapNativeGenericArrayPointer", val6, convertedReturnType) { HasThis = false }; val7.Parameters.Add(new ParameterDefinition(imports.Module.IntPtr())); MethodReference val8 = val7; body.Emit(OpCodes.Call, val8); } else { OpCode call = OpCodes.Call; ModuleDefinition module2 = imports.Module; GenericInstanceMethod val9 = new GenericInstanceMethod(imports.Il2CppObjectPool_Get.Value); val9.GenericArguments.Add(convertedReturnType); Instruction val10 = body.Create(call, module2.ImportReference((MethodReference)val9)); Instruction val11 = body.Create(OpCodes.Nop); body.Append(loadPointer); if (extraDerefForNonValueTypes) { body.Emit(OpCodes.Ldind_I); } body.Emit(OpCodes.Dup); body.Emit(OpCodes.Brtrue_S, val10); body.Emit(OpCodes.Pop); body.Emit(OpCodes.Ldnull); body.Emit(OpCodes.Br, val11); body.Append(val10); body.Append(val11); } } private static void EmitPointerToObjectGeneric(ILProcessor body, TypeReference originalReturnType, TypeReference newReturnType, TypeRewriteContext enclosingType, Instruction loadPointer, bool extraDerefForNonValueTypes, bool unboxValueType) { //IL_0020: 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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown RuntimeAssemblyReferences imports = enclosingType.AssemblyContext.Imports; body.Append(loadPointer); body.Emit(extraDerefForNonValueTypes ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); body.Emit(unboxValueType ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); OpCode call = OpCodes.Call; ModuleDefinition module = imports.Module; GenericInstanceMethod val = new GenericInstanceMethod(imports.IL2CPP_PointerToValueGeneric.Value); val.GenericArguments.Add(newReturnType); body.Emit(call, module.ImportReference((MethodReference)val)); } public static void GenerateBoxMethod(RuntimeAssemblyReferences imports, TypeDefinition targetType, FieldReference classHandle, TypeReference il2CppObjectTypeDef) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected O, but got Unknown //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) MethodDefinition val = new MethodDefinition("BoxIl2CppObject", (MethodAttributes)134, ((MemberReference)targetType).Module.ImportReference(il2CppObjectTypeDef)); targetType.Methods.Add(val); ILProcessor iLProcessor = val.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldsfld, classHandle); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Call, ((MemberReference)targetType).Module.ImportReference(imports.IL2CPP_il2cpp_value_box.Value)); OpCode newobj = OpCodes.Newobj; MethodReference val2 = new MethodReference(".ctor", ((MemberReference)targetType).Module.Void(), il2CppObjectTypeDef); val2.Parameters.Add(new ParameterDefinition(((MemberReference)targetType).Module.IntPtr())); val2.HasThis = true; iLProcessor.Emit(newobj, val2); iLProcessor.Emit(OpCodes.Ret); } public static void EmitUpdateRef(this ILProcessor body, ParameterDefinition newMethodParameter, int argIndex, VariableDefinition paramVariable, RuntimeAssemblyReferences imports) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Expected O, but got Unknown //IL_0136: Expected O, but got Unknown //IL_0092: 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_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Expected O, but got Unknown //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0137: 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) body.Emit(OpCodes.Ldarg, argIndex); body.Emit(OpCodes.Ldloc, paramVariable); if (((MemberReference)((ParameterReference)newMethodParameter).ParameterType.GetElementType()).FullName == "System.String") { body.Emit(OpCodes.Call, imports.IL2CPP_Il2CppStringToManaged.Value); } else { body.Emit(OpCodes.Dup); Instruction val = body.Create(OpCodes.Pop); Instruction val2 = body.Create(OpCodes.Nop); body.Emit(OpCodes.Brfalse_S, val); if (((ParameterReference)newMethodParameter).ParameterType.GetElementType() is GenericParameter) { body.Emit(OpCodes.Ldc_I4_0); body.Emit(OpCodes.Ldc_I4_0); OpCode call = OpCodes.Call; ModuleDefinition module = imports.Module; GenericInstanceMethod val3 = new GenericInstanceMethod(imports.IL2CPP_PointerToValueGeneric.Value); val3.GenericArguments.Add(((ParameterReference)newMethodParameter).ParameterType.GetElementType()); body.Emit(call, module.ImportReference((MethodReference)val3)); } else { OpCode newobj = OpCodes.Newobj; MethodReference val4 = new MethodReference(".ctor", imports.Module.Void(), ((ParameterReference)newMethodParameter).ParameterType.GetElementType()) { HasThis = true }; val4.Parameters.Add(new ParameterDefinition(imports.Module.IntPtr())); body.Emit(newobj, val4); } body.Emit(OpCodes.Br_S, val2); body.Append(val); body.Emit(OpCodes.Ldnull); body.Append(val2); } body.Emit(OpCodes.Stind_Ref); } } internal static class ParameterDefinitionEx { public static bool IsParamsArray(this ParameterDefinition self) { TypeReference parameterType = ((ParameterReference)self).ParameterType; ArrayType val = (ArrayType)(object)((parameterType is ArrayType) ? parameterType : null); if (val != null && val.Rank == 1) { return ((IEnumerable)self.CustomAttributes).Any((CustomAttribute attribute) => ((MemberReference)attribute.AttributeType).FullName == typeof(ParamArrayAttribute).FullName); } return false; } } public static class StringEx { public static bool NameShouldBePrefixed(this string str, GeneratorOptions options) { if (options.Il2CppPrefixMode == GeneratorOptions.PrefixMode.OptIn) { foreach (string item in options.NamespacesAndAssembliesToPrefix) { if (str.StartsWith(item, StringComparison.Ordinal)) { return true; } } return false; } foreach (string item2 in options.NamespacesAndAssembliesToNotPrefix) { if (str.StartsWith(item2, StringComparison.Ordinal)) { return false; } } return true; } public static string UnSystemify(this string str, GeneratorOptions options) { if (!str.NameShouldBePrefixed(options)) { return str; } return "Il2Cpp" + str; } public static string FilterInvalidInSourceChars(this string str) { char[] array = str.ToCharArray(); for (int i = 0; i < array.Length; i++) { char c = array[i]; if (!char.IsDigit(c) && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_' && c != '`') { array[i] = '_'; } } return new string(array); } public static bool IsInvalidInSource(this string str) { foreach (char c in str) { if (!char.IsDigit(c) && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_' && c != '`') { return true; } } return false; } public static bool IsObfuscated(this string str, GeneratorOptions options) { if (options.ObfuscatedNamesRegex != null) { return options.ObfuscatedNamesRegex.IsMatch(str); } foreach (char c in str) { if (!char.IsDigit(c) && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_' && c != '`' && c != '.' && c != '<' && c != '>') { return true; } } return false; } public static ulong StableHash(this string str) { ulong num = 0uL; for (int i = 0; i < str.Length; i++) { num = num * 37 + str[i]; } return num; } public static string GetUnmangledName(this TypeReference typeRef) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder(); GenericInstanceType val = (GenericInstanceType)(object)((typeRef is GenericInstanceType) ? typeRef : null); if (val != null) { stringBuilder.Append(((TypeSpecification)val).ElementType.GetUnmangledName()); Enumerator enumerator = val.GenericArguments.GetEnumerator(); try { while (enumerator.MoveNext()) { TypeReference current = enumerator.Current; stringBuilder.Append("_"); stringBuilder.Append(current.GetUnmangledName()); } } finally { ((IDisposable)enumerator).Dispose(); } } else { ByReferenceType val2 = (ByReferenceType)(object)((typeRef is ByReferenceType) ? typeRef : null); if (val2 != null) { stringBuilder.Append("byref_"); stringBuilder.Append(((TypeSpecification)val2).ElementType.GetUnmangledName()); } else { PointerType val3 = (PointerType)(object)((typeRef is PointerType) ? typeRef : null); if (val3 != null) { stringBuilder.Append("ptr_"); stringBuilder.Append(((TypeSpecification)val3).ElementType.GetUnmangledName()); } else if (typeRef.Namespace == "Il2CppInterop.Runtime" && ((MemberReference)typeRef).Name.StartsWith("Il2Cpp") && ((MemberReference)typeRef).Name.Contains("Array")) { stringBuilder.Append("ArrayOf"); } else { stringBuilder.Append(((MemberReference)typeRef).Name.Replace('`', '_')); } } } return stringBuilder.ToString(); } } public static class TypeReferenceEx { public static bool UnmangledNamesMatch(this TypeReference typeRefA, TypeReference typeRefB) { //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Expected O, but got Unknown bool num = ((object)typeRefA).GetType() == typeof(TypeReference) || ((object)typeRefA).GetType() == typeof(TypeDefinition); bool flag = ((object)typeRefB).GetType() == typeof(TypeReference) || ((object)typeRefB).GetType() == typeof(TypeDefinition); if (!(num && flag) && ((object)typeRefA).GetType() != ((object)typeRefB).GetType()) { return false; } PointerType val = (PointerType)(object)((typeRefA is PointerType) ? typeRefA : null); if (val == null) { ByReferenceType val2 = (ByReferenceType)(object)((typeRefA is ByReferenceType) ? typeRefA : null); if (val2 == null) { ArrayType val3 = (ArrayType)(object)((typeRefA is ArrayType) ? typeRefA : null); if (val3 == null) { GenericInstanceType val4 = (GenericInstanceType)(object)((typeRefA is GenericInstanceType) ? typeRefA : null); if (val4 != null) { TypeReference elementType = ((TypeSpecification)val4).ElementType; GenericInstanceType val5 = (GenericInstanceType)typeRefB; TypeReference elementType2 = ((TypeSpecification)val5).ElementType; if (!elementType.UnmangledNamesMatch(elementType2)) { return false; } if (val4.GenericArguments.Count != val5.GenericArguments.Count) { return false; } for (int i = 0; i < val4.GenericArguments.Count; i++) { if (!val4.GenericArguments[i].UnmangledNamesMatch(val5.GenericArguments[i])) { return false; } } return true; } return ((MemberReference)typeRefA).Name == ((MemberReference)typeRefB).Name; } return ((TypeSpecification)val3).ElementType.UnmangledNamesMatch(((TypeSpecification)(ArrayType)typeRefB).ElementType); } return ((TypeSpecification)val2).ElementType.UnmangledNamesMatch(((TypeSpecification)(ByReferenceType)typeRefB).ElementType); } return ((TypeSpecification)val).ElementType.UnmangledNamesMatch(((TypeSpecification)(PointerType)typeRefB).ElementType); } public static string GetNamespacePrefix(this TypeReference type) { if (type.IsNested) { return ((MemberReference)type).DeclaringType.GetNamespacePrefix() + "." + ((MemberReference)((MemberReference)type).DeclaringType).Name; } return type.Namespace; } } public static class WriterEx { [ThreadStatic] private static byte[]? ourBuffer; public unsafe static void Write(this BinaryWriter writer, T value) where T : unmanaged { int num = Marshal.SizeOf(); if (ourBuffer == null || ourBuffer.Length < num) { ourBuffer = new byte[num]; } fixed (byte* ptr = ourBuffer) { *(T*)ptr = value; } writer.Write(ourBuffer, 0, num); } } } namespace Il2CppInterop.Generator.Contexts { public class AssemblyRewriteContext { private static readonly Dictionary ImportsMap = new Dictionary(); public readonly RewriteGlobalContext GlobalContext; public readonly RuntimeAssemblyReferences Imports; private readonly Dictionary myNameTypeMap = new Dictionary(); private readonly Dictionary myNewTypeMap = new Dictionary(); private readonly Dictionary myOldTypeMap = new Dictionary(); public readonly AssemblyDefinition NewAssembly; public readonly AssemblyDefinition OriginalAssembly; public IEnumerable Types => myOldTypeMap.Values; public AssemblyRewriteContext(RewriteGlobalContext globalContext, AssemblyDefinition originalAssembly, AssemblyDefinition newAssembly) { OriginalAssembly = originalAssembly; NewAssembly = newAssembly; GlobalContext = globalContext; Imports = ImportsMap.GetOrCreate(newAssembly.MainModule, (ModuleDefinition mod) => new RuntimeAssemblyReferences(mod, globalContext)); } public TypeRewriteContext GetContextForOriginalType(TypeDefinition type) { return myOldTypeMap[type]; } public TypeRewriteContext? TryGetContextForOriginalType(TypeDefinition type) { if (!myOldTypeMap.TryGetValue(type, out var value)) { return null; } return value; } public TypeRewriteContext GetContextForNewType(TypeDefinition type) { return myNewTypeMap[type]; } public void RegisterTypeRewrite(TypeRewriteContext context) { if (context.OriginalType != null) { myOldTypeMap[context.OriginalType] = context; } myNewTypeMap[context.NewType] = context; myNameTypeMap[((MemberReference)(context.OriginalType ?? context.NewType)).FullName] = context; } public MethodReference RewriteMethodRef(MethodReference methodRef) { return (MethodReference)(object)GlobalContext.GetNewTypeForOriginal(((MemberReference)methodRef).DeclaringType.Resolve()).GetMethodByOldMethod(methodRef.Resolve()).NewMethod; } public TypeReference RewriteTypeRef(TypeReference? typeRef) { //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Expected O, but got Unknown //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Expected O, but got Unknown //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Expected O, but got Unknown //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown if (typeRef == null) { return Imports.Il2CppObjectBase; } ModuleDefinition mainModule = NewAssembly.MainModule; ArrayType val = (ArrayType)(object)((typeRef is ArrayType) ? typeRef : null); if (val != null) { if (val.Rank != 1) { return Imports.Il2CppObjectBase; } TypeReference elementType = ((TypeSpecification)val).ElementType; if (((MemberReference)elementType).FullName == "System.String") { return Imports.Il2CppStringArray; } TypeReference val2 = RewriteTypeRef(elementType); if (elementType.IsGenericParameter) { GenericInstanceType val3 = new GenericInstanceType(Imports.Il2CppArrayBase); val3.GenericArguments.Add(val2); return (TypeReference)val3; } GenericInstanceType val4 = new GenericInstanceType(val2.IsValueType ? Imports.Il2CppStructArray : Imports.Il2CppReferenceArray); val4.GenericArguments.Add(val2); return (TypeReference)val4; } GenericParameter val5 = (GenericParameter)(object)((typeRef is GenericParameter) ? typeRef : null); if (val5 != null) { TypeReference declaringType = ((MemberReference)val5).DeclaringType; if (declaringType != null) { return (TypeReference)(object)RewriteTypeRef(declaringType).GenericParameters[val5.Position]; } return (TypeReference)(object)RewriteMethodRef(val5.DeclaringMethod).GenericParameters[val5.Position]; } ByReferenceType val6 = (ByReferenceType)(object)((typeRef is ByReferenceType) ? typeRef : null); if (val6 != null) { return (TypeReference)new ByReferenceType(RewriteTypeRef(((TypeSpecification)val6).ElementType)); } PointerType val7 = (PointerType)(object)((typeRef is PointerType) ? typeRef : null); if (val7 != null) { return (TypeReference)new PointerType(RewriteTypeRef(((TypeSpecification)val7).ElementType)); } GenericInstanceType val8 = (GenericInstanceType)(object)((typeRef is GenericInstanceType) ? typeRef : null); if (val8 != null) { GenericInstanceType val9 = new GenericInstanceType(RewriteTypeRef(((TypeSpecification)val8).ElementType)); Enumerator enumerator = val8.GenericArguments.GetEnumerator(); try { while (enumerator.MoveNext()) { TypeReference current = enumerator.Current; val9.GenericArguments.Add(RewriteTypeRef(current)); } return (TypeReference)(object)val9; } finally { ((IDisposable)enumerator).Dispose(); } } if (typeRef.IsPrimitive || ((MemberReference)typeRef).FullName == "System.TypedReference") { return mainModule.ImportCorlibReference(typeRef.Namespace, ((MemberReference)typeRef).Name); } if (((MemberReference)typeRef).FullName == "System.Void") { return Imports.Module.Void(); } if (((MemberReference)typeRef).FullName == "System.String") { return Imports.Module.String(); } if (((MemberReference)typeRef).FullName == "System.Object") { return mainModule.ImportReference((TypeReference)(object)GlobalContext.GetAssemblyByName("mscorlib").GetTypeByName("System.Object").NewType); } if (((MemberReference)typeRef).FullName == "System.Attribute") { return mainModule.ImportReference((TypeReference)(object)GlobalContext.GetAssemblyByName("mscorlib").GetTypeByName("System.Attribute").NewType); } TypeDefinition val10 = typeRef.Resolve(); TypeDefinition newType = GlobalContext.GetNewAssemblyForOriginal(((MemberReference)val10).Module.Assembly).GetContextForOriginalType(val10).NewType; return mainModule.ImportReference((TypeReference)(object)newType); } public TypeRewriteContext GetTypeByName(string name) { return myNameTypeMap[name]; } public TypeRewriteContext? TryGetTypeByName(string name) { if (!myNameTypeMap.TryGetValue(name, out var value)) { return null; } return value; } } public class FieldRewriteContext { private static readonly string[] MethodAccessTypeLabels = new string[7] { "CompilerControlled", "Private", "FamAndAssem", "Internal", "Protected", "FamOrAssem", "Public" }; public readonly TypeRewriteContext DeclaringType; public readonly FieldDefinition OriginalField; public readonly FieldReference PointerField; public readonly string UnmangledName; public FieldRewriteContext(TypeRewriteContext declaringType, FieldDefinition originalField, Dictionary? renamedFieldCounts = null) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown DeclaringType = declaringType; OriginalField = originalField; UnmangledName = UnmangleFieldName(originalField, declaringType.AssemblyContext.GlobalContext.Options, renamedFieldCounts); FieldDefinition val = new FieldDefinition("NativeFieldInfoPtr_" + UnmangledName, (FieldAttributes)49, declaringType.AssemblyContext.Imports.Module.IntPtr()); declaringType.NewType.Fields.Add(val); PointerField = new FieldReference(((MemberReference)val).Name, ((FieldReference)val).FieldType, DeclaringType.SelfSubstitutedRef); } private string UnmangleFieldNameBase(FieldDefinition field, GeneratorOptions options) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) if (options.PassthroughNames) { return ((MemberReference)field).Name; } if (!((MemberReference)field).Name.IsObfuscated(options)) { if (!((MemberReference)field).Name.IsInvalidInSource()) { return ((MemberReference)field).Name; } return ((MemberReference)field).Name.FilterInvalidInSourceChars(); } string text = MethodAccessTypeLabels[field.Attributes & 7]; string text2 = (field.IsStatic ? "_Static" : ""); return "field_" + text + text2 + "_" + DeclaringType.AssemblyContext.RewriteTypeRef(((FieldReference)field).FieldType).GetUnmangledName(); } private string UnmangleFieldName(FieldDefinition field, GeneratorOptions options, Dictionary? renamedFieldCounts) { if (options.PassthroughNames) { return ((MemberReference)field).Name; } if (!((MemberReference)field).Name.IsObfuscated(options)) { if (!((MemberReference)field).Name.IsInvalidInSource()) { return ((MemberReference)field).Name; } return ((MemberReference)field).Name.FilterInvalidInSourceChars(); } if (renamedFieldCounts == null) { throw new ArgumentNullException("renamedFieldCounts"); } string text = UnmangleFieldNameBase(field, options); renamedFieldCounts.TryGetValue(text, out var value); renamedFieldCounts[text] = value + 1; text = text + "_" + value; if (DeclaringType.AssemblyContext.GlobalContext.Options.RenameMap.TryGetValue(((TypeReference)(object)DeclaringType.NewType).GetNamespacePrefix() + "." + ((MemberReference)DeclaringType.NewType).Name + "::" + text, out var value2)) { text = value2; } return text; } } public class MethodRewriteContext { private static readonly string[] MethodAccessTypeLabels = new string[7] { "CompilerControlled", "Private", "FamAndAssem", "Internal", "Protected", "FamOrAssem", "Public" }; private static readonly (MethodSemanticsAttributes, string)[] SemanticsToCheck = new(MethodSemanticsAttributes, string)[6] { ((MethodSemanticsAttributes)1, "_set"), ((MethodSemanticsAttributes)2, "_get"), ((MethodSemanticsAttributes)4, "_oth"), ((MethodSemanticsAttributes)8, "_add"), ((MethodSemanticsAttributes)16, "_rem"), ((MethodSemanticsAttributes)32, "_fire") }; public readonly TypeRewriteContext DeclaringType; public readonly long FileOffset; public readonly MethodDefinition NewMethod; public readonly MethodDefinition OriginalMethod; public readonly bool OriginalNameObfuscated; public readonly long Rva; public readonly List XrefScanResults = new List(); public long MetadataInitFlagRva; public long MetadataInitTokenRva; public string UnmangledName { get; private set; } public string UnmangledNameWithSignature { get; private set; } public TypeDefinition? GenericInstantiationsStore { get; private set; } public TypeReference? GenericInstantiationsStoreSelfSubstRef { get; private set; } public TypeReference? GenericInstantiationsStoreSelfSubstMethodRef { get; private set; } public FieldReference NonGenericMethodInfoPointerField { get; private set; } public bool HasExtensionAttribute { get; } public MethodRewriteContext(TypeRewriteContext declaringType, MethodDefinition originalMethod) { //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Expected O, but got Unknown //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Expected O, but got Unknown //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) DeclaringType = declaringType; OriginalMethod = originalMethod; bool passthroughNames = declaringType.AssemblyContext.GlobalContext.Options.PassthroughNames; int originalNameObfuscated; if (!passthroughNames) { MethodDefinition originalMethod2 = OriginalMethod; originalNameObfuscated = (((originalMethod2 == null) ? null : ((MemberReference)originalMethod2).Name?.IsObfuscated(declaringType.AssemblyContext.GlobalContext.Options)).GetValueOrDefault() ? 1 : 0); } else { originalNameObfuscated = 0; } OriginalNameObfuscated = (byte)originalNameObfuscated != 0; MethodDefinition val = (NewMethod = new MethodDefinition("", AdjustAttributes(originalMethod.Attributes, ((MemberReference)originalMethod).Name == "Finalize"), declaringType.AssemblyContext.Imports.Module.Void())); HasExtensionAttribute = ((IEnumerable)originalMethod.CustomAttributes).Any((CustomAttribute x) => ((MemberReference)x.AttributeType).FullName == typeof(ExtensionAttribute).FullName); if (HasExtensionAttribute) { val.CustomAttributes.Add(new CustomAttribute(declaringType.AssemblyContext.Imports.Module.ExtensionAttributeCtor())); } if (((MethodReference)originalMethod).HasGenericParameters) { Enumerator enumerator = ((MethodReference)originalMethod).GenericParameters.GetEnumerator(); try { while (enumerator.MoveNext()) { GenericParameter current = enumerator.Current; GenericParameter val2 = new GenericParameter(((MemberReference)current).Name, (IGenericParameterProvider)(object)val); val2.Attributes = current.Attributes.StripValueTypeConstraint(); ((MethodReference)val).GenericParameters.Add(val2); } } finally { ((IDisposable)enumerator).Dispose(); } } if (!Pass15GenerateMemberContexts.HasObfuscatedMethods && !passthroughNames && ((MemberReference)originalMethod).Name.IsObfuscated(declaringType.AssemblyContext.GlobalContext.Options)) { Pass15GenerateMemberContexts.HasObfuscatedMethods = true; } FileOffset = ((ICustomAttributeProvider)(object)originalMethod).ExtractOffset(); if (FileOffset < 0) { FileOffset = 0L; } Rva = ((ICustomAttributeProvider)(object)originalMethod).ExtractRva(); if (FileOffset != 0L) { declaringType.AssemblyContext.GlobalContext.MethodStartAddresses.Add(FileOffset); } } public void CtorPhase2() { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Expected O, but got Unknown //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Expected O, but got Unknown //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Expected O, but got Unknown //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Expected O, but got Unknown //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Expected O, but got Unknown //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Expected O, but got Unknown //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Expected O, but got Unknown UnmangledName = UnmangleMethodName(); UnmangledNameWithSignature = UnmangleMethodNameWithSignature(); ((MemberReference)NewMethod).Name = UnmangledName; ((MethodReference)NewMethod).ReturnType = DeclaringType.AssemblyContext.RewriteTypeRef(((MethodReference)OriginalMethod).ReturnType); FieldDefinition val = new FieldDefinition("NativeMethodInfoPtr_" + UnmangledNameWithSignature, (FieldAttributes)49, DeclaringType.AssemblyContext.Imports.Module.IntPtr()); DeclaringType.NewType.Fields.Add(val); NonGenericMethodInfoPointerField = new FieldReference(((MemberReference)val).Name, ((FieldReference)val).FieldType, DeclaringType.SelfSubstitutedRef); if (((MethodReference)OriginalMethod).HasGenericParameters) { Collection genericParameters = ((MethodReference)OriginalMethod).GenericParameters; TypeDefinition val2 = new TypeDefinition("", "MethodInfoStoreGeneric_" + UnmangledNameWithSignature + "`" + genericParameters.Count, (TypeAttributes)1048835, DeclaringType.AssemblyContext.Imports.Module.Object()); val2.DeclaringType = DeclaringType.NewType; DeclaringType.NewType.NestedTypes.Add(val2); GenericInstantiationsStore = val2; GenericInstanceType val3 = new GenericInstanceType((TypeReference)(object)val2); GenericInstanceType val4 = new GenericInstanceType((TypeReference)(object)val2); for (int i = 0; i < genericParameters.Count; i++) { GenericParameter obj = genericParameters[i]; GenericParameter val5 = new GenericParameter(((MemberReference)obj).Name, (IGenericParameterProvider)(object)val2); ((TypeReference)val2).GenericParameters.Add(val5); val3.GenericArguments.Add((TypeReference)(object)val5); GenericParameter val6 = ((MethodReference)NewMethod).GenericParameters[i]; val4.GenericArguments.Add((TypeReference)(object)val6); Enumerator enumerator = obj.Constraints.GetEnumerator(); try { while (enumerator.MoveNext()) { GenericParameterConstraint current = enumerator.Current; if (!(((MemberReference)current.ConstraintType).FullName == "System.ValueType")) { TypeDefinition obj2 = current.ConstraintType.Resolve(); if (obj2 == null || !obj2.IsInterface) { val6.Constraints.Add(new GenericParameterConstraint(DeclaringType.AssemblyContext.RewriteTypeRef(current.ConstraintType))); } } } } finally { ((IDisposable)enumerator).Dispose(); } } FieldDefinition val7 = new FieldDefinition("Pointer", (FieldAttributes)19, DeclaringType.AssemblyContext.Imports.Module.IntPtr()); val2.Fields.Add(val7); GenericInstantiationsStoreSelfSubstRef = ((MemberReference)DeclaringType.NewType).Module.ImportReference((TypeReference)(object)val3); GenericInstantiationsStoreSelfSubstMethodRef = ((MemberReference)DeclaringType.NewType).Module.ImportReference((TypeReference)(object)val4); } DeclaringType.NewType.Methods.Add(NewMethod); } private MethodAttributes AdjustAttributes(MethodAttributes original, bool stripVirtual) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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) //IL_003c: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) original = (MethodAttributes)(original & 0xFFF8); original = (MethodAttributes)(original & 0xDFFF); original = (MethodAttributes)(original & 0xFBFF); if (stripVirtual) { original = (MethodAttributes)(original & 0xFFBF); } original = (MethodAttributes)(original & 0xFFDF); if (stripVirtual) { original = (MethodAttributes)(original & 0xFEFF); } original = (MethodAttributes)(original & 0xFFFF); original = (MethodAttributes)(original & 0xFDFF); original = (MethodAttributes)(original | 6); return original; } private string UnmangleMethodName() { MethodDefinition originalMethod = OriginalMethod; if (((MemberReference)originalMethod).Name == "GetType" && ((MethodReference)originalMethod).Parameters.Count == 0) { return "GetIl2CppType"; } if (DeclaringType.AssemblyContext.GlobalContext.Options.PassthroughNames) { return ((MemberReference)originalMethod).Name; } if (((MemberReference)originalMethod).Name == ".ctor") { return ".ctor"; } if (((MemberReference)originalMethod).Name.IsObfuscated(DeclaringType.AssemblyContext.GlobalContext.Options)) { return UnmangleMethodNameWithSignature(); } if (((MemberReference)originalMethod).Name.IsInvalidInSource()) { return ((MemberReference)originalMethod).Name.FilterInvalidInSourceChars(); } return ((MemberReference)originalMethod).Name; } private string ProduceMethodSignatureBase() { //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) MethodDefinition originalMethod = OriginalMethod; string text = ((MemberReference)originalMethod).Name; if (((MemberReference)originalMethod).Name.IsObfuscated(DeclaringType.AssemblyContext.GlobalContext.Options)) { text = "Method"; } if (text.IsInvalidInSource()) { text = text.FilterInvalidInSourceChars(); } if (((MemberReference)originalMethod).Name == "GetType" && ((MethodReference)originalMethod).Parameters.Count == 0) { text = "GetIl2CppType"; } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(text); stringBuilder.Append('_'); stringBuilder.Append(MethodAccessTypeLabels[originalMethod.Attributes & 7]); if (originalMethod.IsAbstract) { stringBuilder.Append("_Abstract"); } if (originalMethod.IsVirtual) { stringBuilder.Append("_Virtual"); } if (originalMethod.IsStatic) { stringBuilder.Append("_Static"); } if (originalMethod.IsFinal) { stringBuilder.Append("_Final"); } if (originalMethod.IsNewSlot) { stringBuilder.Append("_New"); } (MethodSemanticsAttributes, string)[] semanticsToCheck = SemanticsToCheck; for (int i = 0; i < semanticsToCheck.Length; i++) { var (val, value) = semanticsToCheck[i]; if ((val & originalMethod.SemanticsAttributes) != 0) { stringBuilder.Append(value); } } stringBuilder.Append('_'); stringBuilder.Append(DeclaringType.AssemblyContext.RewriteTypeRef(((MethodReference)originalMethod).ReturnType).GetUnmangledName()); Enumerator enumerator = ((MethodReference)originalMethod).Parameters.GetEnumerator(); try { while (enumerator.MoveNext()) { ParameterDefinition current = enumerator.Current; stringBuilder.Append('_'); stringBuilder.Append(DeclaringType.AssemblyContext.RewriteTypeRef(((ParameterReference)current).ParameterType).GetUnmangledName()); } } finally { ((IDisposable)enumerator).Dispose(); } long rva = Rva; if (rva != 0L && Pass15GenerateMemberContexts.HasObfuscatedMethods && !Pass16ScanMethodRefs.NonDeadMethods.Contains(rva)) { stringBuilder.Append("_PDM"); } return stringBuilder.ToString(); } private string UnmangleMethodNameWithSignature() { string text = ProduceMethodSignatureBase() + "_" + DeclaringType.Methods.Where(ParameterSignatureMatchesThis).TakeWhile((MethodRewriteContext it) => it != this).Count(); if (DeclaringType.AssemblyContext.GlobalContext.Options.RenameMap.TryGetValue(((TypeReference)(object)DeclaringType.NewType).GetNamespacePrefix() + "::" + text, out var value)) { text = value; } return text; } private bool ParameterSignatureMatchesThis(MethodRewriteContext otherRewriteContext) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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) //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) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) MethodDefinition originalMethod = otherRewriteContext.OriginalMethod; MethodDefinition originalMethod2 = OriginalMethod; if (!otherRewriteContext.OriginalNameObfuscated) { return false; } MethodAttributes val = (MethodAttributes)1399; if ((originalMethod.Attributes & val) != (originalMethod2.Attributes & val)) { return false; } if (originalMethod.SemanticsAttributes != originalMethod2.SemanticsAttributes) { return false; } if (((MemberReference)((MethodReference)originalMethod).ReturnType).FullName != ((MemberReference)((MethodReference)originalMethod2).ReturnType).FullName) { return false; } Collection parameters = ((MethodReference)originalMethod).Parameters; Collection parameters2 = ((MethodReference)originalMethod2).Parameters; if (parameters.Count != parameters2.Count) { return false; } for (int i = 0; i < parameters.Count; i++) { if (((MemberReference)((ParameterReference)parameters[i]).ParameterType).FullName != ((MemberReference)((ParameterReference)parameters2[i]).ParameterType).FullName) { return false; } } if (Pass15GenerateMemberContexts.HasObfuscatedMethods) { long rva = otherRewriteContext.Rva; long rva2 = Rva; if (rva != 0L && rva2 != 0L && Pass16ScanMethodRefs.NonDeadMethods.Contains(rva) != Pass16ScanMethodRefs.NonDeadMethods.Contains(rva2)) { return false; } } return true; } } public class RewriteGlobalContext : IDisposable { internal readonly List MethodStartAddresses = new List(); private readonly Dictionary myAssemblies = new Dictionary(); private readonly Dictionary myAssembliesByOld = new Dictionary(); internal readonly Dictionary PreviousRenamedTypes = new Dictionary(); internal readonly Dictionary RenamedTypes = new Dictionary(); internal readonly Dictionary<(object, string, int), List> RenameGroups = new Dictionary<(object, string, int), List>(); public GeneratorOptions Options { get; } public IIl2CppMetadataAccess GameAssemblies { get; } public IMetadataAccess UnityAssemblies { get; } public IEnumerable Assemblies => myAssemblies.Values; internal bool HasGcWbarrierFieldWrite { get; set; } public RewriteGlobalContext(GeneratorOptions options, IIl2CppMetadataAccess gameAssemblies, IMetadataAccess unityAssemblies) { //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown Options = options; GameAssemblies = gameAssemblies; UnityAssemblies = unityAssemblies; foreach (AssemblyDefinition assembly in gameAssemblies.Assemblies) { string name = ((AssemblyNameReference)assembly.Name).Name; if (name == "Il2CppDummyDll") { assembly.Dispose(); continue; } AssemblyDefinition newAssembly = AssemblyDefinition.CreateAssembly(new AssemblyNameDefinition(((AssemblyNameReference)assembly.Name).Name.UnSystemify(options), ((AssemblyNameReference)assembly.Name).Version), ((ModuleReference)assembly.MainModule).Name.UnSystemify(options), assembly.MainModule.Kind); AssemblyRewriteContext context = new AssemblyRewriteContext(this, assembly, newAssembly); AddAssemblyContext(name, context); } } public void Dispose() { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown FieldInfo field = typeof(DefaultAssemblyResolver).GetField("cache", BindingFlags.Instance | BindingFlags.NonPublic); foreach (AssemblyRewriteContext assembly in Assemblies) { Enumerator enumerator2 = assembly.NewAssembly.Modules.GetEnumerator(); try { while (enumerator2.MoveNext()) { DefaultAssemblyResolver obj = (DefaultAssemblyResolver)enumerator2.Current.AssemblyResolver; ((Dictionary)field.GetValue(obj)).Clear(); } } finally { ((IDisposable)enumerator2).Dispose(); } assembly.NewAssembly.Dispose(); assembly.OriginalAssembly.Dispose(); } UnityAssemblies.Dispose(); } internal void AddAssemblyContext(string assemblyName, AssemblyRewriteContext context) { myAssemblies[assemblyName] = context; if (context.OriginalAssembly != null) { myAssembliesByOld[context.OriginalAssembly] = context; } } public AssemblyRewriteContext GetNewAssemblyForOriginal(AssemblyDefinition oldAssembly) { return myAssembliesByOld[oldAssembly]; } public TypeRewriteContext GetNewTypeForOriginal(TypeDefinition originalType) { return GetNewAssemblyForOriginal(((MemberReference)originalType).Module.Assembly).GetContextForOriginalType(originalType); } public TypeRewriteContext? TryGetNewTypeForOriginal(TypeDefinition originalType) { if (!myAssembliesByOld.TryGetValue(((MemberReference)originalType).Module.Assembly, out var value)) { return null; } return value.TryGetContextForOriginalType(originalType); } public TypeRewriteContext.TypeSpecifics JudgeSpecificsByOriginalType(TypeReference typeRef) { if (typeRef.IsPrimitive || typeRef.IsPointer || ((MemberReference)typeRef).FullName == "System.TypedReference") { return TypeRewriteContext.TypeSpecifics.BlittableStruct; } if (((MemberReference)typeRef).FullName == "System.String" || ((MemberReference)typeRef).FullName == "System.Object" || typeRef.IsArray || typeRef.IsByReference || typeRef.IsGenericParameter || typeRef.IsGenericInstance) { return TypeRewriteContext.TypeSpecifics.ReferenceType; } return GetNewTypeForOriginal(typeRef.Resolve()).ComputedTypeSpecifics; } public AssemblyRewriteContext GetAssemblyByName(string name) { return myAssemblies[name]; } public AssemblyRewriteContext? TryGetAssemblyByName(string name) { if (myAssemblies.TryGetValue(name, out var value)) { return value; } if (name == "netstandard") { if (!myAssemblies.TryGetValue("mscorlib", out var value2)) { return null; } return value2; } return null; } public MethodDefinition? CreateParamsMethod(MethodDefinition originalMethod, MethodDefinition newMethod, RuntimeAssemblyReferences imports, Func resolve) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown //IL_0068: 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_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Expected O, but got Unknown //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Expected O, but got Unknown //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) if (((MemberReference)newMethod).Name == "Invoke") { return null; } ParameterDefinition[] source = ((IEnumerable)((MethodReference)originalMethod).Parameters).Where(delegate(ParameterDefinition parameter) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (parameter.IsParamsArray()) { TypeReference obj = resolve(((TypeSpecification)(ArrayType)((ParameterReference)parameter).ParameterType).ElementType); return obj != null && !obj.IsGenericParameter; } return false; }).ToArray(); if (source.Any()) { MethodDefinition val = new MethodDefinition(((MemberReference)newMethod).Name, newMethod.Attributes, ((MethodReference)newMethod).ReturnType); Enumerator enumerator = ((MethodReference)newMethod).GenericParameters.GetEnumerator(); try { while (enumerator.MoveNext()) { GenericParameter current = enumerator.Current; ((MethodReference)val).GenericParameters.Add(current); } } finally { ((IDisposable)enumerator).Dispose(); } Enumerator enumerator2 = ((MethodReference)originalMethod).Parameters.GetEnumerator(); try { while (enumerator2.MoveNext()) { ParameterDefinition current2 = enumerator2.Current; bool num = source.Contains(current2); TypeReference val4; if (num) { TypeReference parameterType = ((ParameterReference)current2).ParameterType; ArrayType val2 = (ArrayType)(object)((parameterType is ArrayType) ? parameterType : null); if (val2 != null) { TypeReference val3 = resolve(((TypeReference)val2).GetElementType()); val4 = (TypeReference)((val3 == null) ? ((ArrayType)null) : new ArrayType(val3, val2.Rank)); goto IL_0119; } } val4 = resolve(((ParameterReference)current2).ParameterType); goto IL_0119; IL_0119: ParameterDefinition val5 = new ParameterDefinition(((ParameterReference)current2).Name, current2.Attributes, val4); if (num) { val5.CustomAttributes.Add(new CustomAttribute(((MemberReference)newMethod).Module.ParamArrayAttributeCtor())); } ((MethodReference)val).Parameters.Add(val5); } } finally { ((IDisposable)enumerator2).Dispose(); } ILProcessor iLProcessor = val.Body.GetILProcessor(); if (((MethodReference)newMethod).HasThis) { iLProcessor.Emit(OpCodes.Ldarg_0); } int num2 = (((MethodReference)newMethod).HasThis ? 1 : 0); for (int i = 0; i < ((MethodReference)newMethod).Parameters.Count; i++) { iLProcessor.Emit(OpCodes.Ldarg, num2 + i); ParameterDefinition val6 = ((MethodReference)originalMethod).Parameters[i]; if (source.Contains(val6)) { TypeReference elementType = ((TypeReference)(ArrayType)((ParameterReference)val6).ParameterType).GetElementType(); MethodReference val7; if (((MemberReference)elementType).FullName == "System.String") { val7 = imports.Il2CppStringArrayctor.Value; } else { TypeReference val8 = resolve(elementType); val7 = imports.Module.ImportReference(val8.IsValueType ? imports.Il2CppStructArrayctor.Get(val8) : imports.Il2CppRefrenceArrayctor.Get(val8)); } iLProcessor.Emit(OpCodes.Newobj, val7); } } iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)newMethod); iLProcessor.Emit(OpCodes.Ret); return val; } return null; } } public class TypeRewriteContext { public enum TypeSpecifics { NotComputed, Computing, ReferenceType, BlittableStruct, NonBlittableStruct } public readonly AssemblyRewriteContext AssemblyContext; private readonly Dictionary myFieldContexts = new Dictionary(); private readonly Dictionary myMethodContexts = new Dictionary(); private readonly Dictionary myMethodContextsByName = new Dictionary(); public readonly TypeDefinition NewType; public readonly bool OriginalNameWasObfuscated; public readonly TypeDefinition OriginalType; public TypeSpecifics ComputedTypeSpecifics; public FieldReference ClassPointerFieldRef { get; private set; } public TypeReference SelfSubstitutedRef { get; private set; } public IEnumerable Fields => myFieldContexts.Values; public IEnumerable Methods => myMethodContexts.Values; public TypeRewriteContext(AssemblyRewriteContext assemblyContext, TypeDefinition originalType, TypeDefinition newType) { //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Expected O, but got Unknown AssemblyContext = assemblyContext ?? throw new ArgumentNullException("assemblyContext"); OriginalType = originalType; NewType = newType ?? throw new ArgumentNullException("newType"); if (OriginalType != null) { OriginalNameWasObfuscated = ((MemberReference)OriginalType).Name != ((MemberReference)NewType).Name; if (OriginalNameWasObfuscated) { Collection customAttributes = NewType.CustomAttributes; CustomAttribute val = new CustomAttribute(assemblyContext.Imports.ObfuscatedNameAttributector.Value); val.ConstructorArguments.Add(new CustomAttributeArgument(assemblyContext.Imports.Module.String(), (object)((MemberReference)originalType).FullName)); customAttributes.Add(val); } if (!((TypeReference)OriginalType).IsValueType) { ComputedTypeSpecifics = TypeSpecifics.ReferenceType; } else if (OriginalType.IsEnum) { ComputedTypeSpecifics = TypeSpecifics.BlittableStruct; } else if (((TypeReference)OriginalType).HasGenericParameters) { ComputedTypeSpecifics = TypeSpecifics.NonBlittableStruct; } } } public void AddMembers() { //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Expected O, but got Unknown //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //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) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Expected O, but got Unknown //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Expected O, but got Unknown //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_0303: Expected O, but got Unknown if (((TypeReference)NewType).HasGenericParameters) { GenericInstanceType val = new GenericInstanceType((TypeReference)(object)NewType); Enumerator enumerator = ((TypeReference)NewType).GenericParameters.GetEnumerator(); try { while (enumerator.MoveNext()) { GenericParameter current = enumerator.Current; val.GenericArguments.Add((TypeReference)(object)current); } } finally { ((IDisposable)enumerator).Dispose(); } SelfSubstitutedRef = ((MemberReference)NewType).Module.ImportReference((TypeReference)(object)val); GenericInstanceType val2 = new GenericInstanceType(AssemblyContext.Imports.Il2CppClassPointerStore); val2.GenericArguments.Add(SelfSubstitutedRef); GenericInstanceType val3 = val2; ClassPointerFieldRef = new FieldReference("NativeClassPtr", AssemblyContext.Imports.Module.IntPtr(), ((MemberReference)NewType).Module.ImportReference((TypeReference)(object)val3)); } else { SelfSubstitutedRef = (TypeReference)(object)NewType; GenericInstanceType val4 = new GenericInstanceType(AssemblyContext.Imports.Il2CppClassPointerStore); if (((TypeReference)OriginalType).IsPrimitive || ((MemberReference)OriginalType).FullName == "System.String") { val4.GenericArguments.Add(((MemberReference)NewType).Module.ImportCorlibReference(((TypeReference)OriginalType).Namespace, ((MemberReference)OriginalType).Name)); } else { val4.GenericArguments.Add(SelfSubstitutedRef); } ClassPointerFieldRef = new FieldReference("NativeClassPtr", AssemblyContext.Imports.Module.IntPtr(), ((MemberReference)NewType).Module.ImportReference((TypeReference)(object)val4)); } if (OriginalType.IsEnum) { return; } Dictionary renamedFieldCounts = new Dictionary(); Enumerator enumerator2 = OriginalType.Fields.GetEnumerator(); try { while (enumerator2.MoveNext()) { FieldDefinition current2 = enumerator2.Current; myFieldContexts[current2] = new FieldRewriteContext(this, current2, renamedFieldCounts); } } finally { ((IDisposable)enumerator2).Dispose(); } bool flag = false; Enumerator enumerator3 = OriginalType.Methods.GetEnumerator(); try { while (enumerator3.MoveNext()) { MethodDefinition current3 = enumerator3.Current; if (!(((MemberReference)current3).Name == ".cctor") && (!(((MemberReference)current3).Name == ".ctor") || ((MethodReference)current3).Parameters.Count != 1 || !(((MemberReference)((ParameterReference)((MethodReference)current3).Parameters[0]).ParameterType).FullName == "System.IntPtr")) && !current3.HasOverrides) { MethodRewriteContext methodRewriteContext = new MethodRewriteContext(this, current3); myMethodContexts[current3] = methodRewriteContext; myMethodContextsByName[((MemberReference)current3).Name] = methodRewriteContext; if (methodRewriteContext.HasExtensionAttribute) { flag = true; } } } } finally { ((IDisposable)enumerator3).Dispose(); } if (flag) { NewType.CustomAttributes.Add(new CustomAttribute(AssemblyContext.Imports.Module.ExtensionAttributeCtor())); } } public FieldRewriteContext GetFieldByOldField(FieldDefinition field) { return myFieldContexts[field]; } public MethodRewriteContext GetMethodByOldMethod(MethodDefinition method) { return myMethodContexts[method]; } public MethodRewriteContext? TryGetMethodByOldMethod(MethodDefinition method) { if (!myMethodContexts.TryGetValue(method, out var value)) { return null; } return value; } public MethodRewriteContext? TryGetMethodByName(string name) { if (!myMethodContextsByName.TryGetValue(name, out var value)) { return null; } return value; } public MethodRewriteContext? TryGetMethodByUnityAssemblyMethod(MethodDefinition method) { foreach (KeyValuePair myMethodContext in myMethodContexts) { MethodDefinition originalMethod = myMethodContext.Value.OriginalMethod; if (((MemberReference)originalMethod).Name != ((MemberReference)method).Name || ((MethodReference)originalMethod).Parameters.Count != ((MethodReference)method).Parameters.Count) { continue; } bool flag = false; for (int i = 0; i < ((MethodReference)originalMethod).Parameters.Count; i++) { if (((MemberReference)((ParameterReference)((MethodReference)originalMethod).Parameters[i]).ParameterType).FullName != ((MemberReference)((ParameterReference)((MethodReference)method).Parameters[i]).ParameterType).FullName) { flag = true; break; } } if (!flag) { return myMethodContext.Value; } } return null; } public FieldRewriteContext? TryGetFieldByUnityAssemblyField(FieldDefinition field) { foreach (KeyValuePair myFieldContext in myFieldContexts) { FieldDefinition originalField = myFieldContext.Value.OriginalField; if (!(((MemberReference)originalField).Name != ((MemberReference)field).Name) && !(((MemberReference)((FieldReference)originalField).FieldType).FullName != ((MemberReference)((FieldReference)field).FieldType).FullName)) { return myFieldContext.Value; } } return null; } } } namespace System.Runtime.CompilerServices { [ExcludeFromCodeCoverage] [DebuggerNonUserCode] internal static class IsExternalInit { } }