public void compilePatch() { byte[] contents1 = ROM.arm9binFile.getContents(); byte[] contents2 = ROM.arm9ovFile.getContents(); byte[] contents3 = ROM.arm7binFile.getContents(); byte[] contents4 = ROM.arm7ovFile.getContents(); byte[] contents5 = ROM.headerFile.getContents(); Directory.CreateDirectory(codedir); Directory.CreateDirectory(codedir + "/root"); Directory.CreateDirectory(codedir + "/overlay9"); Directory.CreateDirectory(codedir + "/overlay7"); File.WriteAllBytes(codedir + "/arm9.bin", contents1); File.WriteAllBytes(codedir + "/arm9ovt.bin", contents2); File.WriteAllBytes(codedir + "/arm7.bin", contents3); File.WriteAllBytes(codedir + "/arm7ovt.bin", contents4); File.WriteAllBytes(codedir + "/header.bin", contents5); File.WriteAllBytes(codedir + "/fnt.bin", dummyFnt); DSFileSystem.Directory dirByPath1 = ROM.FS.getDirByPath("overlay9"); DSFileSystem.Directory dirByPath2 = ROM.FS.getDirByPath("overlay7"); foreach (DSFileSystem.File childrenFile in dirByPath1.childrenFiles) { File.WriteAllBytes(codedir + "/overlay9/" + childrenFile.name, childrenFile.getContents()); } foreach (DSFileSystem.File childrenFile in dirByPath2.childrenFiles) { File.WriteAllBytes(codedir + "/overlay7/" + childrenFile.name, childrenFile.getContents()); } PatchCompiler.compilePatchFF(romdir); }
public void compilePatch() { uint codeAddr = getCodeAddr(); PatchCompiler.compilePatch(codeAddr, romdir); }
public void insertCode(DirectoryInfo romdir, out string hookmap, out string replaces) { hookmap = ""; replaces = ""; try { if (!File.Exists(romdir.FullName + @"\bak_safe\main.bin")) { if (File.Exists(romdir.FullName + @"\bak\main.bin")) { if (!Directory.Exists(romdir.FullName + @"\bak_safe")) { Directory.CreateDirectory(romdir.FullName + @"\bak_safe"); } File.Copy(romdir.FullName + @"\bak\main.bin", romdir.FullName + @"\bak_safe\main.bin", true); } else { this.handler.makeBinBackup(-1, true); } } File.Copy(romdir.FullName + @"\bak_safe\main.bin", romdir.FullName + @"\bak\main.bin", true); } catch (Exception ex) { new ErrorMSGBox("", "", "", ex.ToString()).ShowDialog(); } FileInfo fileInfo1 = new FileInfo(romdir.FullName + "/codemap.x"); if (!fileInfo1.Exists) { return; } StreamReader streamReader1 = new StreamReader(fileInfo1.FullName, Encoding.UTF8); while (!streamReader1.EndOfStream) { string str1 = streamReader1.ReadLine(); string[] strArray = str1.Split(' '); if (strArray.Length != 2 && strArray.Length != 3) { new ErrorMSGBox("", "", "", "Error: Wrong Codemap line format (" + str1 + ")").ShowDialog(); } else { string str2 = strArray[0]; if (!Directory.Exists(romdir.FullName + "/" + str2)) { new ErrorMSGBox("", "", "", "Error: Directory \"" + str2 + "\" does not exist").ShowDialog(); } else { if (strArray[1].StartsWith("0x")) { strArray[1] = strArray[1].Substring(2); } if (strArray[2].StartsWith("0x")) { strArray[2] = strArray[2].Substring(2); } int hex = PatchMaker.parseHex(strArray[1]); if (hex < 33554432) { new ErrorMSGBox("", "", "", "Error: Destination address of " + strArray[0] + " is too small (0x" + hex.ToString("X8") + ")").ShowDialog(); } else if (hex > 50331647) { new ErrorMSGBox("", "", "", "Error: Destination address of " + strArray[0] + " is too big (0x" + hex.ToString("X8") + ")").ShowDialog(); } else { int num5 = -1; if (strArray.Length == 3) { num5 = PatchMaker.parseHex(strArray[2]); } PatchCompiler.runProcess("make clean", romdir.FullName + "/" + strArray[0]); if (PatchCompiler.runProcess("make CODEADDR=0x" + hex.ToString("X8"), romdir.FullName + "/" + strArray[0]) != 0) { new ErrorMSGBox("", "", "", "Error: Compilation of " + strArray[0] + " failed.").ShowDialog(); } else { string str3 = romdir.FullName + "/" + str2 + "/newcode.bin"; if (!File.Exists(str3)) { new ErrorMSGBox("", "", "", "Insert Code Binary \"" + str3 + "\" does not exist!").ShowDialog(); break; } long length1 = new FileInfo(str3).Length; if (length1 > (long)num5) { new ErrorMSGBox("", "", "", "Insert Code Binary \"" + str3 + "\" size (" + (object)length1 + ") exeeds given maximum size (" + (object)num5 + ")").ShowDialog(); break; } FileInfo fileInfo2 = new FileInfo(romdir.FullName + "/" + strArray[0] + "/replaces.x"); List <PatchMaker.Replace> replaceList = new List <PatchMaker.Replace>(); if (fileInfo2.Exists) { StreamReader streamReader2 = new StreamReader(fileInfo2.FullName, Encoding.UTF8); while (!streamReader2.EndOfStream) { string str4 = streamReader2.ReadLine().Replace("\n", "").Replace("\t", ""); if (str4.Contains("@")) { str4 = str4.Substring(0, str4.IndexOf("@")); } List <string> stringList = new List <string>((IEnumerable <string>)str4.Split(' ')); for (int index = stringList.Count - 1; index >= 0; --index) { if (stringList[index] == "") { stringList.RemoveAt(index); } } if (stringList.Count != 0) { if (stringList.Count != 2) { new ErrorMSGBox("", "", "", "Failed parsing replace: Wrong format.\n\nInput line: \"" + str4 + "\"").ShowDialog(); } else { int num8 = 9; if (stringList[0].Contains("_ov_")) { num8 += 6; } if (stringList[0].Length != num8 || !stringList[0].EndsWith(":")) { new ErrorMSGBox("", "", "", "Failed parsing replace: Wrong format.\n\nInput line: \"" + str4 + "\"").ShowDialog(); } else { PatchMaker.Replace replace; if (!int.TryParse(str4.Substring(0, 8), NumberStyles.HexNumber, (IFormatProvider)null, out replace.ramAddr)) { new ErrorMSGBox("", "", "", "Failed parsing replace: Wrong address format.\n\nInput address: \"" + str4.Substring(0, 8) + "\"").ShowDialog(); } else { replace.ovId = -1; if (stringList[0].Contains("_ov_") && !int.TryParse(str4.Substring(str4.IndexOf("_ov_") + 4, 2), NumberStyles.HexNumber, (IFormatProvider)null, out replace.ovId)) { new ErrorMSGBox("", "", "", "Failed parsing replace: Wrong overlay format.\n\nInput overlay: \"" + str4.Substring(str4.IndexOf("_ov_") + 4, 2) + "\"").ShowDialog(); } else { uint result; if (uint.TryParse(stringList[1].Replace("0x", ""), NumberStyles.HexNumber, (IFormatProvider)null, out result)) { replaces = replaces + str4 + "\n"; } else { replace.funcName = stringList[1]; replaceList.Add(replace); } } } } } } } streamReader2.Close(); } StreamReader streamReader3 = new StreamReader(romdir.FullName + "/" + strArray[0] + "/newcode.sym", Encoding.UTF8); while (!streamReader3.EndOfStream) { string str4 = streamReader3.ReadLine(); for (int index = replaceList.Count - 1; index >= 0; --index) { PatchMaker.Replace replace = replaceList[index]; if (str4.Contains(replace.funcName) && (str4.Contains(".text") || str4.Contains(".data"))) { uint result; if (!uint.TryParse(str4.Substring(0, 8), NumberStyles.HexNumber, (IFormatProvider)null, out result)) { new ErrorMSGBox("", "", "", "Failed parsing destination adress: Wrong adress format.\n\nInput adress: \"" + str4.Substring(0, 8) + "\"").ShowDialog(); } else { if (replace.ovId == -1) { replaces = replaces + replace.ramAddr.ToString("X8") + " 0x" + result.ToString("X8") + "\n"; } else { replaces = replaces + replace.ramAddr.ToString("X8") + "_ov_" + replace.ovId.ToString("X2") + " 0x" + result.ToString("X8") + "\n"; } replaceList.Remove(replace); } } } int startIndex = -1; if (str4.Contains("nsub_")) { startIndex = str4.IndexOf("nsub_"); } if (str4.Contains("hook_")) { startIndex = str4.IndexOf("hook_"); } if (str4.Contains("repl_")) { startIndex = str4.IndexOf("repl_"); } if (startIndex != -1) { string str5 = str4.Substring(startIndex); int length2 = 13; if (str5.Contains("_ov_")) { length2 += 6; } else if (str5.Contains("_main")) { length2 += 5; } string str6 = str5.Substring(0, length2); hookmap = hookmap + str6 + ": " + str4.Substring(0, 8) + "\n"; } } streamReader3.Close(); string str7 = ""; foreach (PatchMaker.Replace replace in replaceList) { str7 = str7 + "\n" + replace.funcName; } if (str7 != "") { new ErrorMSGBox("", "", "", "Some replaces were not found:\n" + str7).ShowDialog(); } string path = romdir.FullName + "/bak/main.bin"; if (!File.Exists(path)) { new ErrorMSGBox("", "", "", "ARM 9 Binary \"" + path + "\" does not exist!").ShowDialog(); break; } byte[] bytes = File.ReadAllBytes(romdir.ToString() + "/bak/main.bin"); byte[] numArray = File.ReadAllBytes(str3); Array.Copy((Array)numArray, 0, (Array)bytes, hex - 33554432, numArray.Length); File.WriteAllBytes(path, bytes); } } } } } }