protected void LoadModificationAssemblies() { foreach (string asmPath in GlobModificationAssemblies()) { Assembly asm = null; try { asm = Assembly.LoadFile(asmPath); foreach (Type t in asm.GetTypes()) { if (t.BaseType != typeof(ModificationBase)) { continue; } //Prevent duplicates caused from modifications referencing other modifications (ie core/xna) if (!Modifications.Any(m => m.GetType().FullName == t.FullName)) { ModificationBase mod = LoadModification(t); if (mod != null) { //Is the mod applicable to the current source assembly? if (mod.AssemblyTargets.Contains(SourceAssembly.Name.FullName)) { mod.SourceDefinition = SourceAssembly; mod.SourceDefinitionFilePath = asmPath; System.Diagnostics.Debug.WriteLine($"Ready to run modification {t.FullName}"); Modifications.Add(mod); } else { System.Diagnostics.Debug.WriteLine($"Modification {t.FullName} not supported"); } } } else { System.Diagnostics.Debug.WriteLine($"Skipping modification {t.FullName}"); } } } catch (ReflectionTypeLoadException rtle) { Console.Error.WriteLine($" * Error loading modification from {asmPath}, it will be skipped."); foreach (var error in rtle.LoaderExceptions) { Console.Error.WriteLine($" -- > {error.Message}"); } continue; } } }
protected void LoadModificationAssemblies() { //var assemblies = new List<(AssemblyDefinition Assembly, string Path)>(); //modificationAssemblies = assemblies; foreach (string asmPath in GlobModificationAssemblies()) { Assembly asm = null; try { asm = Assembly.LoadFile(asmPath); AddReference(asmPath); //assemblies.Add(new(ReadAssembly(asmPath), asmPath)); var types = asm.GetTypes(); foreach (Type t in types) { if (t.BaseType != typeof(ModificationBase)) { continue; } //Prevent duplicates caused from modifications referencing other modifications (ie core/xna) if (!Modifications.Any(m => m.GetType().FullName == t.FullName)) { ModificationBase mod = LoadModification(t); if (mod != null) { //Is the mod applicable to the current source assembly? if (mod.AssemblyTargets.Contains(SourceAssembly.Name.FullName)) { mod.SourceDefinition = SourceAssembly; mod.SourceDefinitionFilePath = asmPath; //Console.WriteLine($"Ready to run modification {t.FullName}"); Modifications.Add(mod); } else { Console.WriteLine($"Modification {t.FullName} does not support {SourceAssembly.Name.FullName}."); } } } //else //{ // Console.WriteLine($"Skipping modification {t.FullName}"); //} } } catch (ReflectionTypeLoadException rtle) { Console.Error.WriteLine($" * Error loading modification from {asmPath}, it will be skipped."); foreach (var error in rtle.LoaderExceptions) { Console.Error.WriteLine($" -- > {error.Message}"); } continue; } catch (Exception ex) { Console.Error.WriteLine($" * Error loading modification from {asmPath}, it will be skipped.\n{ex}"); continue; } } }