protected override void ProcessModule()
        {
            AssemblyWrapper assemblyWrapper = base.ModuleContext.GetAssemblyWrapper();

            if (assemblyWrapper != null)
            {
                this.unityTypeType           = base.ModuleContext.Import(this.unityTypeTypeDefinition);
                this.objectType              = base.ModuleContext.GetCorLibType("System.Object");
                this.typeType                = base.ModuleContext.GetCorLibType("System.Type");
                this.getTypeFromHandleMethod = base.ModuleContext.GetCorLibMethod(this.typeType, "GetTypeFromHandle");
                foreach (TypeWrapper wrapper2 in assemblyWrapper.Types)
                {
                    wrapper2.UnityType = this.AddUnityTypeClass(wrapper2);
                }
                if (base.IsUnityEngine)
                {
                    using (IEnumerator <AssemblyWrapper> enumerator = base.MetadataContainer.Assemblies.Where <AssemblyWrapper>((< > c.< > 9__6_0 ?? (< > c.< > 9__6_0 = new Func <AssemblyWrapper, bool>(< > c.< > 9. < ProcessModule > b__6_0)))).GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            foreach (TypeWrapper wrapper3 in enumerator.Current.Types)
                            {
                                wrapper3.UnityType = this.AddUnityTypeClass(wrapper3);
                            }
                        }
                    }
                }
                this.unityTypeType           = null;
                this.objectType              = null;
                this.typeType                = null;
                this.getTypeFromHandleMethod = null;
            }
        }
        private MethodDefinition AddGetUnityTypeMethod(TypeDefinition type, AssemblyWrapper assemblyWrapper)
        {
            MethodDefinition item = new MethodDefinition("GetUnityType", MethodAttributes.CompilerControlled | MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.HideBySig | MethodAttributes.Static, base.ModuleContext.GetCorLibType("System.IntPtr"));

            type.Methods.Add(item);
            ParameterDefinition definition2 = new ParameterDefinition("id", ParameterAttributes.None, base.ModuleContext.GetCorLibType("System.Int32"));

            item.Parameters.Add(definition2);
            MethodBody  body        = item.Body;
            ILProcessor iLProcessor = body.GetILProcessor();
            Collection <Instruction> instructions = body.Instructions;

            iLProcessor.EmitLdarg(definition2);
            iLProcessor.EmitLdc_I4(assemblyWrapper.FirstTypeId);
            iLProcessor.Emit(OpCodes.Sub);
            Instruction[] targets = new Instruction[assemblyWrapper.Types.Length];
            iLProcessor.Emit(OpCodes.Switch, targets);
            iLProcessor.EmitLdc_I4(0);
            iLProcessor.Emit(OpCodes.Conv_I);
            iLProcessor.Emit(OpCodes.Ret);
            for (int i = 0; i < assemblyWrapper.Types.Length; i++)
            {
                iLProcessor.Emit(OpCodes.Newobj, assemblyWrapper.Types[i].UnityType.Methods.Single <MethodDefinition>(< > c.< > 9__3_0 ?? (< > c.< > 9__3_0 = new Func <MethodDefinition, bool>(< > c.< > 9. < AddGetUnityTypeMethod > b__3_0))));
                targets[i] = instructions.Last <Instruction>();
                iLProcessor.Emit(OpCodes.Call, this.allocMethod);
                iLProcessor.Emit(OpCodes.Call, this.toIntPtrMethod);
                iLProcessor.Emit(OpCodes.Ret);
            }
            return(item);
        }
        protected override void ProcessModule()
        {
            AssemblyWrapper assemblyWrapper = base.ModuleContext.GetAssemblyWrapper();

            if (assemblyWrapper != null)
            {
                this.int64Type = base.ModuleContext.GetCorLibType("System.Int64");
                this.objectToGCHandleMethod            = base.ModuleContext.Import(base.OperationContext.GCHandledObjectsObjectToGCHandleMethod);
                this.gcHandleToObjectMethod            = base.ModuleContext.Import(base.OperationContext.GCHandledObjectsGCHandleToObjectMethod);
                this.gcHandleToPinnedArrayObjectMethod = base.ModuleContext.Import(base.OperationContext.GCHandledObjectsGCHandleToPinnedArrayObjectMethod);
                this.ptrToStringUniMethod = base.ModuleContext.GetCorLibMethod("System.Runtime.InteropServices.Marshal", <> c.< > 9__6_0 ?? (< > c.< > 9__6_0 = new Func <MethodDefinition, bool>(< > c.< > 9. < ProcessModule > b__6_0)));
                Dictionary <TypeDefinition, int> dictionary = new Dictionary <TypeDefinition, int>();
                foreach (TypeWrapper wrapper2 in assemblyWrapper.Types)
                {
                    TypeDefinition definition = wrapper2.Type.Resolve();
                    if (wrapper2.Methods != null)
                    {
                        foreach (MethodWrapper wrapper3 in wrapper2.Methods)
                        {
                            int            num3;
                            TypeDefinition declaringType = wrapper3.TargetMethod.DeclaringType;
                            if (!dictionary.TryGetValue(declaringType, out num3))
                            {
                                num3 = 0;
                            }
                            MethodDefinition item = Process(base.ModuleContext, wrapper3, num3);
                            if (definition.IsInterface)
                            {
                                wrapper2.UnityType.Methods.Add(item);
                            }
                            else if (definition.HasGenericParameters)
                            {
                                wrapper2.UnityType.Methods.Add(item);
                                MethodDefinition targetMethod = wrapper3.TargetMethod;
                                if (targetMethod.IsPrivate || targetMethod.IsFamilyAndAssembly)
                                {
                                    targetMethod.IsAssembly = true;
                                }
                                else if (targetMethod.IsFamily)
                                {
                                    targetMethod.IsFamilyOrAssembly = true;
                                }
                            }
                            else
                            {
                                declaringType.Methods.Add(item);
                            }
                            dictionary[declaringType] = num3 + 1;
                        }
                    }
                }
                this.int64Type = null;
                this.objectToGCHandleMethod            = null;
                this.gcHandleToObjectMethod            = null;
                this.ptrToStringUniMethod              = null;
                this.gcHandleToPinnedArrayObjectMethod = null;
            }
        }
Пример #4
0
        private void AddAssembly64(AssemblyWrapper value)
        {
            value.Offset = this.CurrentOffset;
            this.Write64(0L);
            this.AddString64(value.Name);
            this.Write64(0L);
            int num = (value.Types != null) ? value.Types.Length : 0;

            this.Write64((long)num);
            this.Write64(0L);
        }
Пример #5
0
        private void AddAssembly32(AssemblyWrapper value)
        {
            value.Offset = this.CurrentOffset;
            this.Write32(0);
            this.AddString32(value.Name);
            this.Write32(0);
            int num = (value.Types != null) ? value.Types.Length : 0;

            this.Write32(num);
            this.Write32(0);
        }
Пример #6
0
        public AssemblyWrapper GetAssembly(IMetadataScope scope)
        {
            AssemblyWrapper wrapper;
            string          assemblyName = scope.GetAssemblyName();
            string          key          = assemblyName + ".dll";

            if (!this.assemblies.TryGetValue(key, out wrapper))
            {
                bool system = this.OperationContext.IsSystemAssembly(assemblyName);
                wrapper = new AssemblyWrapper(this, key, system);
                this.assemblies.Add(wrapper.Name, wrapper);
            }
            return(wrapper);
        }
        public TypeWrapper(AssemblyWrapper assembly, TypeReference type)
        {
            this.Assembly = assembly;
            this.Type     = type;
            this.Name     = GetName(type);
            this.FullName = GetFullName(type);
            TypeDefinition definition = type.Resolve();
            TypeFlag       none       = TypeFlag.None;

            using (Collection <CustomAttribute> .Enumerator enumerator = definition.CustomAttributes.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    TypeReference attributeType = enumerator.Current.AttributeType;
                    if (!(attributeType.GetAssemblyName() != "UnityEngine") && (attributeType.FullName == "UnityEngine.SharedBetweenAnimatorsAttribute"))
                    {
                        none |= TypeFlag.HasSharedBetweenAnimatorsAttribute;
                    }
                }
            }
            if (definition.IsInterface)
            {
                none |= TypeFlag.Interface;
            }
            if (definition.IsAbstract)
            {
                none |= TypeFlag.Abstract;
            }
            if (type.IsGenericInstance)
            {
                none |= TypeFlag.GenericInstance;
            }
            if (type.HasGenericParameters)
            {
                none |= TypeFlag.GenericDefinition;
            }
            this.Flags = none;
            this.DefaultConstructor = definition.Methods.SingleOrDefault <MethodDefinition>(< > c.< > 9__70_0 ?? (< > c.< > 9__70_0 = new Func <MethodDefinition, bool>(< > c.< > 9. <.ctor > b__70_0)));
            if (type.IsGenericInstance && (this.DefaultConstructor != null))
            {
                this.DefaultConstructor = this.DefaultConstructor.MakeGenericMethod(((GenericInstanceType)type).GenericArguments.ToArray());
            }
        }
Пример #8
0
        protected override void ProcessModule()
        {
            AssemblyWrapper assemblyWrapper = base.ModuleContext.GetAssemblyWrapper();

            if (assemblyWrapper != null)
            {
                foreach (TypeWrapper wrapper2 in assemblyWrapper.Types)
                {
                    if (!this.Process(wrapper2))
                    {
                        wrapper2.SpecialConstructor            = null;
                        wrapper2.ImplementCreateInstanceMethod = false;
                    }
                    else if (wrapper2.Type.IsGenericInstance)
                    {
                        wrapper2.ImplementCreateInstanceMethod = false;
                    }
                }
            }
        }
        protected override void ProcessModule()
        {
            AssemblyWrapper assemblyWrapper = base.ModuleContext.GetAssemblyWrapper();

            if (assemblyWrapper != null)
            {
                ModuleDefinition corLib = base.OperationContext.CorLib;
                this.attributeType     = new TypeReference("System", "Attribute", corLib, corLib, false);
                this.exceptionType     = new TypeReference("System", "Exception", corLib, corLib, false);
                this.delegateType      = new TypeReference("System", "Delegate", corLib, corLib, false);
                this.weakReferenceType = new TypeReference("System", "WeakReference", corLib, corLib, false);
                foreach (TypeWrapper wrapper2 in assemblyWrapper.Types)
                {
                    this.Process(wrapper2);
                }
                this.attributeType     = null;
                this.exceptionType     = null;
                this.delegateType      = null;
                this.weakReferenceType = null;
            }
        }
        protected override void ProcessModule()
        {
            AssemblyWrapper assemblyWrapper = base.ModuleContext.GetAssemblyWrapper();

            if (assemblyWrapper != null)
            {
                this.allocMethod    = base.ModuleContext.GetCorLibMethod("System.Runtime.InteropServices.GCHandle", <> c.< > 9__2_0 ?? (< > c.< > 9__2_0 = new Func <MethodDefinition, bool>(< > c.< > 9. < ProcessModule > b__2_0)));
                this.toIntPtrMethod = base.ModuleContext.GetCorLibMethod("System.Runtime.InteropServices.GCHandle", "ToIntPtr");
                TypeDefinition type = base.AddStaticClass("UnityEngine.Internal", "$Metadata");
                assemblyWrapper.GetUnityTypeMethod = this.AddGetUnityTypeMethod(type, assemblyWrapper);
                if (base.IsUnityEngine)
                {
                    foreach (AssemblyWrapper wrapper2 in base.MetadataContainer.Assemblies.Where <AssemblyWrapper>(< > c.< > 9__2_1 ?? (< > c.< > 9__2_1 = new Func <AssemblyWrapper, bool>(< > c.< > 9. < ProcessModule > b__2_1))))
                    {
                        TypeDefinition definition2 = base.AddStaticClass("UnityEngine.Internal", string.Format("$Metadata{0}", wrapper2.SystemAssemblyId));
                        wrapper2.GetUnityTypeMethod = this.AddGetUnityTypeMethod(definition2, wrapper2);
                    }
                }
                this.allocMethod    = null;
                this.toIntPtrMethod = null;
            }
        }
 internal bool <ProcessModule> b__6_0(AssemblyWrapper a)
 {
     return(a.System);
 }