public override bool Patch(PatchData data) { LogInternal("Compiling Mods.dll..."); CompilerSettings compilerSettings = new CompilerSettings(); compilerSettings.OutputPath = data.ModsDllTempLocation; var scriptPaths = data.FindFiles("Scripts", "*.cs", true); for (int i = 0; i < scriptPaths.Count; ++i) { compilerSettings.Files.Add(scriptPaths[i]); } var sdxfakeFile = @"namespace SDX.Compiler { public class SDXCompilerWrapper {} } namespace SDX { public class SDXWrapper {} } namespace SDX.Core { public class SDXCoreWrapper {} } namespace SDX.Payload { public class SDXPayloadWrapper {} }"; var sdxtempPath = (data.BuildFolder + "BlankClass.cs").Replace("/", "\\"); File.WriteAllText(sdxtempPath, sdxfakeFile); compilerSettings.Files.Add(sdxtempPath); compilerSettings.AddReference("DMT.dll"); var dllRefs = Directory.GetFiles(data.ManagedFolder, "*.dll").Where(d => d.EndsWith("/Mods.dll") == false && d.Contains("Assembly-CSharp") == false).ToArray(); compilerSettings.AddReferences(dllRefs); var patchedDll = $"{data.BuildFolder}InitialPatch.dll"; compilerSettings.AddReferenceAtIndex(patchedDll, 0); var dllPaths = data.FindFiles("Scripts", "*.dll", true); for (int i = 0; i < dllPaths.Count; ++i) { compilerSettings.AddReference(dllPaths[i]); Logging.LogInfo($"Copy file {dllPaths[i]} -> {data.ManagedFolder}"); Helper.CopyFileToDir(dllPaths[i], data.ManagedFolder); } var compilerResults = data.Compiler.Compile(data, compilerSettings); Logging.LogInfo($"Built in {compilerResults.Duration}ms"); if (compilerResults.Success == false) { for (int i = 0; i < compilerResults.Errors.Count; ++i) { LogWarning(compilerResults.Errors[i]); } LogError("Failed to compile Mods.dll"); return(false); } Log("Mods.dll compile successful"); return(true); }
private void PatchTextFile(PatchData data, string sourcePath, string destPath, string patchFilePath) { LocalisationTable locTable = new LocalisationTable(); var files = data.FindFiles(patchFilePath); if (files.Count() == 0) { File.Copy(sourcePath, destPath, true); return; } locTable.Load(sourcePath); foreach (string filePath in files) { Log("PatchFile: " + filePath); LocalisationTable otherTable = new LocalisationTable(); otherTable.Load(filePath); locTable.Merge(otherTable); } Log("Save text file: " + destPath); locTable.Save(destPath); }
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); }