private static void Patch(String directory) { try { if (!Directory.Exists(directory)) { Console.WriteLine("Directory does not exist: {0}", directory); return; } Console.WriteLine("Patching..."); String modPath = Path.Combine(directory, "Memoria.dll"); File.Copy("Memoria.dll", modPath, true); String assemblyPath = Path.Combine(directory, "Assembly-CSharp.dll"); String backupPath = Path.Combine(directory, "Assembly-CSharp.bak"); RollbackPreviousPatches(assemblyPath, backupPath); InitializePatches(); AssemblyDefinition mod = AssemblyDefinition.ReadAssembly(modPath); foreach (ModuleDefinition module in mod.Modules) { PreparePatch(module); } AssemblyDefinition victim = AssemblyDefinition.ReadAssembly(assemblyPath); //JunkChecker.Check(victim, backupPath); foreach (ModuleDefinition module in victim.Modules) { PatchModule(module); } TypeExporters.Export(mod, victim); if (Changed) { String tmpPath = Path.Combine(directory, "Assembly-CSharp.tmp"); victim.Write(tmpPath); if (!File.Exists(backupPath)) { File.Copy(assemblyPath, backupPath); } File.Delete(assemblyPath); File.Move(tmpPath, assemblyPath); } Console.WriteLine("Success!"); } catch (Exception ex) { String message = $"Failed to patch assembly from a directory [{directory}]"; Console.WriteLine(message); Log.Error(ex, message); } }
public static void Export(AssemblyDefinition mod, AssemblyDefinition victim) { TypeExporters exporters = new TypeExporters(mod, victim); exporters.Export(); }