Exemple #1
0
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="targetPlatform">The current game platform.</param>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="paranoidMode">Whether to detect paranoid mode issues.</param>
        public AssemblyLoader(Platform targetPlatform, IMonitor monitor, bool paranoidMode)
        {
            this.Monitor      = monitor;
            this.ParanoidMode = paranoidMode;
            this.AssemblyMap  = this.TrackForDisposal(Constants.GetAssemblyMap(targetPlatform));
            this.AssemblyDefinitionResolver = this.TrackForDisposal(new AssemblyDefinitionResolver());
            this.AssemblyDefinitionResolver.AddSearchDirectory(Constants.ExecutionPath);
            this.AssemblyDefinitionResolver.AddSearchDirectory(Constants.InternalFilesPath);

            // generate type => assembly lookup for types which should be rewritten
            this.TypeAssemblies = new Dictionary <string, Assembly>();
            foreach (Assembly assembly in this.AssemblyMap.Targets)
            {
                ModuleDefinition module = this.AssemblyMap.TargetModules[assembly];
                foreach (TypeDefinition type in module.GetTypes())
                {
                    if (!type.IsPublic)
                    {
                        continue; // no need to rewrite
                    }
                    if (type.Namespace.Contains("<"))
                    {
                        continue; // ignore assembly metadata
                    }
                    this.TypeAssemblies[type.FullName] = assembly;
                }
            }
        }
        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="targetPlatform">The current game platform.</param>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="isDeveloperMode">Whether to enable developer mode logging.</param>
        public AssemblyLoader(Platform targetPlatform, IMonitor monitor, bool isDeveloperMode)
        {
            this.Monitor         = monitor;
            this.IsDeveloperMode = isDeveloperMode;
            this.AssemblyMap     = Constants.GetAssemblyMap(targetPlatform);

            // generate type => assembly lookup for types which should be rewritten
            this.TypeAssemblies = new Dictionary <string, Assembly>();
            foreach (Assembly assembly in this.AssemblyMap.Targets)
            {
                ModuleDefinition module = this.AssemblyMap.TargetModules[assembly];
                foreach (TypeDefinition type in module.GetTypes())
                {
                    if (!type.IsPublic)
                    {
                        continue; // no need to rewrite
                    }
                    if (type.Namespace.Contains("<"))
                    {
                        continue; // ignore assembly metadata
                    }
                    this.TypeAssemblies[type.FullName] = assembly;
                }
            }
        }