private static void InnerPatch(TmodFileWrapper.ITmodFile modFile, IEnumerable <Type> processors, string dll = null) { if (string.IsNullOrWhiteSpace(dll)) { dll = modFile.HasFile("All.dll") ? "All.dll" : "Windows.dll"; } Logger.Info(Strings.Patching, dll); var module = AssemblyDef.Load(modFile.GetFile(dll)).Modules.Single(); foreach (var processor in processors) { try { var proc = Activator.CreateInstance(processor, modFile, module, _language); var tran = LoadFiles(SourcePath, processor); processor.GetMethod(nameof(Processor <Content> .PatchContents))?.Invoke(proc, new[] { tran }); } catch (Exception ex) { Logger.Warn(Strings.ProcExceptionOccur, processor.FullName); Logger.Error(ex); } } using (var ms = new MemoryStream()) { module.Assembly.Write(ms); modFile.Files[dll] = ms.ToArray(); } }
private static void Patch(TmodFileWrapper.ITmodFile modFile, IEnumerable <Type> processors) { const string mono = "Mono.dll"; var procs = processors as Type[] ?? processors.ToArray(); if (modFile.HasFile(mono)) { InnerPatch(modFile, procs, mono); } InnerPatch(modFile, procs); // save mod file var file = string.Format(DefaultConfigurations.OutputFileNameFormat, modFile.Name); Logger.Warn(Strings.Saving, file); modFile.Write(file); }