Example #1
0
        bool CheckCompilerGeneratedStateMachine(ILMethod ilm, Enviorment.AppDomain domain, int startLine, out ILMethod found)
        {
            var mDef = ilm.Definition;

            Mono.Cecil.CustomAttribute ca = null;
            found = null;
            foreach (var attr in mDef.CustomAttributes)
            {
                switch (attr.AttributeType.FullName)
                {
                case "System.Runtime.CompilerServices.AsyncStateMachineAttribute":
                case "System.Runtime.CompilerServices.IteratorStateMachineAttribute":
                    ca = attr;
                    break;
                }
            }
            if (ca != null)
            {
                if (ca.ConstructorArguments.Count > 0)
                {
                    var smType = domain.GetType(ca.ConstructorArguments[0].Value, null, null);
                    if (smType != null)
                    {
                        ilm = smType.GetMethod("MoveNext", 0, true) as ILMethod;
                        if (ilm != null && ilm.StartLine <= (startLine + 1) && ilm.EndLine >= (startLine + 1))
                        {
                            found = ilm;
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Example #2
0
        public static ulong ComputeVariantHash(Mono.Cecil.TypeReference variantType, Mono.Cecil.CustomAttribute attribute)
        {
            var hash          = TypeHash.FNV1A64(attribute.AttributeType.FullName);
            var componentType = attribute.ConstructorArguments[0].Value as Mono.Cecil.TypeReference;
            var variantName   = variantType.FullName;

            hash = TypeHash.CombineFNV1A64(hash, TypeHash.FNV1A64(componentType.FullName));
            hash = TypeHash.CombineFNV1A64(hash, TypeHash.FNV1A64(variantName));
            return(hash);
        }
Example #3
0
        /// <summary>
        /// Convert Mono.Cecil.CustomAttribute to <see cref="ICustomAttribute"/>.
        /// </summary>
        /// <param name="attribute">The custom attribute to be converted.</param>
        /// <param name="sequence">Sequence of the attribute in parameter, method, property or class.</param>
        /// <returns>The <see cref="ICustomAttribute"/> converted to.</returns>
        public static ICustomAttribute Convert(this Mono.Cecil.CustomAttribute attribute, int sequence)
        {
            var customAttribute = MetadataFactory.InitializeCustomAttribute(attribute.AttributeType.FullName, sequence);

            if (attribute.HasProperties)
            {
                for (var i = 0; i < attribute.Properties.Count; i++)
                {
                    customAttribute.AddAttributeProperty(Convert(attribute.Properties[i], i));
                }
            }

            return(customAttribute.Build());
        }
Example #4
0
        public override void Run()
        {
            var asm_fw   = typeof(Microsoft.Xna.Framework.Vector2).Assembly;
            var asm_game = typeof(Microsoft.Xna.Framework.Game).Assembly;
            var asm_gfx  = typeof(Microsoft.Xna.Framework.Graphics.AlphaTestEffect).Assembly;
            var asm_x    = typeof(Microsoft.Xna.Framework.Audio.AudioEngine).Assembly;

            var c = this.SourceDefinition.MainModule.Import(typeof(System.Runtime.CompilerServices.TypeForwardedToAttribute).GetConstructors().Single());

            var types = new[] {
                asm_fw,
                asm_game,
                asm_gfx,
                asm_x
            }.SelectMany(a => a.GetExportedTypes()).ToArray();

            foreach (var type in types)
            {
                var a = new Mono.Cecil.CustomAttribute(c);
                a.ConstructorArguments.Add(new Mono.Cecil.CustomAttributeArgument(
                                               this.SourceDefinition.MainModule.Import(typeof(System.Type)),
                                               this.SourceDefinition.MainModule.Import(type)
                                               ));

                this.SourceDefinition.CustomAttributes.Add(a);
            }

            //Context.OTAPI.MainModue.Resources.Clear();

            //System.AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            //var xnaFramework = SourceDefinition.MainModule.AssemblyReferences
            //    .Where(x => x.Name.StartsWith("Microsoft.Xna.Framework"))
            //    .ToArray();

            //for (var x = 0; x < xnaFramework.Length; x++)
            //{
            //    xnaFramework[x].Name = "OTAPI.Modifications.Xna"; //TODO: Fix me, ILRepack is adding .dll to the asm name      Context.OTAPI.Assembly.Name.Name;
            //    xnaFramework[x].PublicKey = ModificationDefinition.Name.PublicKey;
            //    xnaFramework[x].PublicKeyToken = ModificationDefinition.Name.PublicKeyToken;
            //    xnaFramework[x].Version = ModificationDefinition.Name.Version;
            //}

            ////To resolve the "OTAPI" from above until the .dll can be corrected.
            //Context.AssemblyResolver.AssemblyResolve += AssemblyResolver_AssemblyResolve;
        }
Example #5
0
        public static bool GetJITFlags(this Mono.Cecil.CustomAttribute attribute, Enviorment.AppDomain appdomain, out int flags)
        {
            var at = appdomain.GetType(attribute.AttributeType, null, null);

            flags = ILRuntimeJITFlags.None;
            if (at == appdomain.JITAttributeType)
            {
                if (attribute.HasConstructorArguments)
                {
                    flags = (int)attribute.ConstructorArguments[0].Value;
                }
                else
                {
                    flags = ILRuntimeJITFlags.JITOnDemand;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #6
0
 internal CustomAttribute(Mono.Cecil.CustomAttribute customAttribute)
 {
     _customAttribute = customAttribute;
 }