示例#1
0
        public void ProcessAssembly(ModuleDefinition module, string[] defines)
        {
            RegisterTypeProcessor typeRegister = new RegisterTypeProcessor(module);
            ResolverProcessor     resolver     = new ResolverProcessor(module);
            FormatterProcessor    formatter    = new FormatterProcessor(this, module, resolver);
            CustomDataProcessor   customData   = new CustomDataProcessor(this, module, typeRegister, resolver, formatter);

            bool isBuildingPlayer = true;

            for (int i = 0; i < defines.Length; i++)
            {
                if (defines[i] == "UNITY_EDITOR")
                {
                    isBuildingPlayer = false;
                    break;
                }
            }

            for (int i = 0; i < processors.Length; i++)
            {
                processors[i].Weaver           = this;
                processors[i].Module           = module;
                processors[i].TypeRegister     = typeRegister;
                processors[i].Resolver         = resolver;
                processors[i].Formatters       = formatter;
                processors[i].IsBuildingPlayer = isBuildingPlayer;
            }

            IEnumerable <TypeDefinition> types = module.GetTypes();

            foreach (TypeDefinition type in types)
            {
                if (type.HasAttribute <ALEProcessedAttribute>())
                {
                    continue;
                }

                for (int i = 0; i < processors.Length; i++)
                {
                    if (!processors[i].IsValidClass(type))
                    {
                        continue;
                    }

                    processors[i].Type = type;

                    processors[i].ProcessClass(type);
                    type.CustomAttributes.Add(new CustomAttribute(module.ImportReference(typeof(ALEProcessedAttribute).GetConstructor(Type.EmptyTypes))));
                }
            }

            customData.EndEditing();
            typeRegister.EndEditing(isBuildingPlayer);
            formatter.EndEditing(); // Important to be before resolver!
            resolver.EndEditing(isBuildingPlayer);
        }
        public CustomDataProcessor(Weaver weaver, ModuleDefinition module, RegisterTypeProcessor registerTypeProcessor, ResolverProcessor resolverProcessor, FormatterProcessor formatterProcessor)
        {
            this.weaver = weaver;
            this.module = module;
            this.registerTypeProcessor = registerTypeProcessor;
            this.resolverProcessor     = resolverProcessor;
            this.formatterProcessor    = formatterProcessor;

            addDataMethod = module.GetMethod <LevelEventArgs>("AddCustomData", typeof(string), typeof(object)).Resolve();
        }