public override bool Patch(PatchData data) { ModuleDefinition gameModule = data.ReadModuleDefinition(data.InitialDllLocation); ModuleDefinition modsModule = data.ReadModuleDefinition(data.ModsDllTempLocation); var builtInPatches = Assembly.GetExecutingAssembly().GetInterfaceImplementers <IPatcherMod>(); foreach (var patch in builtInPatches) { patch.Link(gameModule, modsModule); } IPatcherMod[] patches = null; var didRun = data.Compiler.RunPatchScripts(data, out patches); if (didRun) { Logging.Log("Link patching " + patches.Length + " files"); foreach (var patch in patches) { patch.Link(gameModule, modsModule); } gameModule.Write(data.LinkedDllLocation); modsModule.Write(data.ModDllLocation); } return(didRun); }
public override bool Patch(PatchData data) { ModuleDefinition gameModule = data.ReadModuleDefinition(data.BackupDllLocataion); ModuleDefinition dmt = data.ReadModuleDefinition(data.ManagedFolder + "DMT.dll"); var builtInPatches = Assembly.GetExecutingAssembly().GetInterfaceImplementers <IPatcherMod>(); foreach (var patch in builtInPatches) { patch.Patch(gameModule); } IPatcherMod[] patches = null; var didRun = data.Compiler.RunPatchScripts(data, out patches); if (didRun) { foreach (var patch in patches) { patch.Patch(gameModule); } new BuiltInPatches().Patch(gameModule, dmt); gameModule.Write(data.BuildFolder + "InitialPatch.dll"); } return(didRun); }
public static CompilerSettings CreatePatchScripts(PatchData data) { CompilerSettings compilerSettings = new CompilerSettings(); var patchScriptPaths = data.FindFiles("PatchScripts", "*.cs", true); if (patchScriptPaths.Count == 0) { //return compilerSettings; } foreach (string path in patchScriptPaths) { compilerSettings.Files.Add(path); } compilerSettings.GenerateInMemory = true; compilerSettings.AddReference("DMT.dll"); compilerSettings.AddReference("Mono.Cecil.dll"); compilerSettings.AddReferences(data.FindFiles("PatchScripts", "*.dll", true)); var dllPaths = Directory.GetFiles(data.ManagedFolder, "*.dll").Where(d => d.EndsWith("/Mods.dll") == false && d.Contains("Assembly-CSharp") == false).ToArray(); compilerSettings.AddReferences(dllPaths); if (data.RunSection == RunSection.InitialPatch) { compilerSettings.AddReference(data.BackupDllLocataion); } else if (data.RunSection == RunSection.LinkedPatch) { compilerSettings.AddReference(data.InitialDllLocation); //compilerSettings.AddReference(data.ManagedFolder + "Assembly-CSharp.dll"); } else { compilerSettings.AddReference(data.LinkedDllLocation); } //for (int i = 0; i < dllPaths.Length; i++) //{ // var path = dllPaths[i]; // if (path.EndsWith(Path.DirectorySeparatorChar + "Assembly-CSharp.dll")) // { // var z = dllPaths[0]; // dllPaths[0] = path; // dllPaths[i] = z; // break; // } //} List <string> namespaces = new List <string>(); for (int i = 0; i < dllPaths.Length; i++) { string dllPath = dllPaths[i]; if (!Path.GetFileName(dllPath).Contains("mscorlib") && !Path.GetFileName(dllPath).Contains("Mono.Cecil")) // { var mod = data.ReadModuleDefinition(dllPath); if (namespaces.Contains(mod.Name)) { Logging.LogWarning($"Duplicate dll namespace found '{mod.Name}'. Skipping dll at path: '{dllPath}'"); continue; } namespaces.Add(mod.Name); compilerSettings.AddReference(dllPath); } } compilerSettings.GenerateInMemory = true; return(compilerSettings); }