static void PadROM(byte[] newfile, string outfile) { for (int m = 0; m < ROMMult.Length; m++) { int sizer = ROMMult[m]; if (sizer > newfile.Length) { byte[] final = FillArray(new byte[sizer]); LCompress.CopyBytes(newfile, final, true); File.WriteAllBytes(outfile, final); break; } } }
static void OutputDecompressedFile(string input, string output, string type, int lztype, int offset, int length) { if (File.Exists(input)) { if (!(output == "")) { byte[] file = File.ReadAllBytes(input); if (lztype > -1) {//then use lunar compress... Console.WriteLine("Commencing decompression with Lunar Compress Type " + lztype.ToString() + "..."); byte[] d1 = LCompress.Decompress(file, offset, 0x10000, (uint)lztype); byte[] d2 = new byte[LCompress.LastDecompressedSize]; Array.Copy(d1, d2, LCompress.LastDecompressedSize); File.WriteAllBytes(output, d2); } else { switch (type.ToLower()) { case "sbm5": Console.WriteLine("Commencing decompression with Super Bomberman 5 RLE Type..."); BM5RLE.Decompress(file, length, output); break; case "sfcw": Console.WriteLine("Commencing decompression with Super Famicom Wars RLE Type..."); byte[] data = SFCWRLE.Decompress(file); File.WriteAllBytes(output, data); break; default: Console.WriteLine("Type argument was invalid. Failed."); break; } } } else { Console.WriteLine("Missing output file argument. Failed."); //message - output file required } } else { Console.WriteLine("Invalid input file argument. Failed."); //message- input file required } }
static void InsertSection(string outfile, byte[] data, int offset) { byte[] outf = File.ReadAllBytes(outfile); //outf = InsertBytes(outf, data, offset); int reqlen = (offset + data.Length); byte[] temp = new byte[outf.Length]; if (!((outf.Length - reqlen) >= 0)) { temp = new byte[reqlen]; } LCompress.CopyBytes(outf, temp, true); File.WriteAllBytes(outfile, temp); ReplaceSection(outfile, data, offset); }
static void OutputCompressedFile(string input, string output, string type) { if (File.Exists(input)) { if (!(output == "")) { int lztype = -1; try {//if there is no error, then its an LZ type (Lunar) lztype = int.Parse(type); byte[] file = File.ReadAllBytes(input); byte[] outbyte = null; LCompress.Compress(file, out outbyte, LCompress.GetLZType(type)); File.WriteAllBytes(output, outbyte); } catch { switch (type.ToLower()) { case "sbm5": Console.WriteLine("Commencing Compression with Super Bomberman 5 RLE Type..."); BM5RLE.Compress(input, output); break; case "sfcw": Console.WriteLine("Commencing Compression with Super Famicom Wars LZ/RLE Type..."); byte[] data = SFCWRLE.Compress(File.ReadAllBytes(input)); File.WriteAllBytes(output, data); break; default: Console.WriteLine("Type argument was invalid. Failed."); break; } } } else { Console.WriteLine("Missing output file argument. Failed."); //message - output file required } } else { Console.WriteLine("Invalid input file argument. Failed."); //message- input file required } }
public static void DumpIndexedFiles(string inputrom, string addrtype, string outtype, string outfolder) { byte[] romfile = File.ReadAllBytes(inputrom); //the locations for the pointers... and the total number of pointers const int bankloc = 0x11E3; const int highloc = 0x12DC; const int lowloc = 0x13D5; const int bounds = 0xF9; byte[] bank = new byte[bounds]; for (int c = 0; c < bounds; c++) { bank[c] = romfile[bankloc + c]; } byte[] high = new byte[bounds]; for (int c = 0; c < bounds; c++) { high[c] = romfile[highloc + c]; } byte[] low = new byte[bounds]; for (int c = 0; c < bounds; c++) { low[c] = romfile[lowloc + c]; } for (int c = 0; c < bank.Length; c++) { byte bnk = Convert.ToByte(Convert.ToInt32(bank[c]) - 192); // Converts HIROM to PC string loc = bnk.ToString("X2") + high[c].ToString("X2") + low[c].ToString("X2"); int iloc = Convert.ToInt32(loc, 16); byte[] d1 = LCompress.Decompress(romfile, iloc, 0x10000, 1); byte[] d2 = new byte[LCompress.LastDecompressedSize]; for (int b = 0; b < LCompress.LastDecompressedSize; b++) { d2[b] = d1[b]; } File.WriteAllBytes(outfolder + @"\0x" + loc + ".bin", d2); } }
//new function- allow me to decompress files (or areas in files)...but just files for now!! static void DeCompressFile(string[] args) { string input = ""; string output = ""; string type = ""; int lztype = -1; string rletype = ""; string offs = ""; int offset = 0; string len = ""; int length = -1; Console.WriteLine("Parsing arguments..."); foreach (string a in args) { string ar = a.Trim().ToLower(); if (ar.StartsWith("/input:")) { int idx = ar.IndexOf(':') + 1; input = ar.Substring(idx); } else if (ar.StartsWith("/type:")) { int idx = ar.IndexOf(':') + 1; type = ar.Substring(idx).ToLower(); if (type.StartsWith("lz")) { string t = type.Replace("lz", ""); lztype = (int)LCompress.GetLZType(t); } } else if (ar.StartsWith("/output:")) { int idx = ar.IndexOf(':') + 1; output = ar.Substring(idx); } } OutputDecompressedFile(input, output, type, lztype, offset, length); }
static void Main(string[] args) { Console.Title = "MBuild - A Marvelous Translation and Hacking Tool"; Console.WriteLine("MBuild - " + Application.ProductVersion.ToString().Split('.')[0] + "." + Application.ProductVersion.ToString().Split('.')[1]); Console.WriteLine("A Marvelous Translation and Hacking Tool"); Console.WriteLine("Written by DackR aka Daniel Martin Burgess\r\n"); if (args.Length == 0) { Console.WriteLine("No Arguments specified."); UseXML("MBuild.MBXML", !Settings.Default.AutoBuild); } else { string mArg = args[0].Trim().ToLower(); switch (mArg) { case "build": BuildXML(args); break; case "dump-script": DumpScript(args); break; case "bin-script": BuildScript(args); break; case "comp": CompressFile(args); break; case "decomp": DeCompressFile(args); break; case "bpp-convert": //BuildScript(args); break; case "dmpptr": DumpPointers(); break; case "fixsum": FixCheckSum(args); break; case "mbxml-shell": string[] makeArg = new string[] { "-f", "-t", ".mbxml", "-si", Application.ExecutablePath, "-a", Application.ExecutablePath, "-sn", "MBXML File", "-sc", "MBuild_XML_File" }; //string[] assocArg = new string[] { "-f", "-t", ".txt", "-associate", Application.ExecutablePath }; CTypes.Main(makeArg); //CTypes.Main(assocArg); //FileAssociation.SetAssociation(".mbxml", "MBuild_XML_File", Application.ExecutablePath, "MBXML File", args); break; case "ips": MakeIPS(args); break; case "xdelta": MakexDelta(args); break; case "extract": //used to extract RAW binary data from a file ExtractBin(args); break; case "dmpdata": //Dump data located at the various pointers DumpData(args); break; case "bm5dump": SBM5.DumpDataFromPointerTab(@"F:\GoogleDrive\SBM5\Base\Base.sfc", @"F:\GoogleDrive\SBM5\Dump\"); break; case "test": string romfile = @"D:\GoogleDrive\SuperFamicomWars\base.sfc"; byte[] data = File.ReadAllBytes(romfile); MemoryStream ms = LZSS.Decompress(data); byte[] dcdata = ms.ToArray(); break; default: if (mArg.ToLower().Contains(".mbxml") && File.Exists(mArg)) { //detected xml file specified... Try to build. UseXML(mArg, false); //Console.WriteLine(mArg); //Console.ReadKey(true); } break; } } LCompress.LunarCompressCleanup(); xDelta.xDeltaCleanup(); bool wait = false; Console.Write("Press any key to exit (\"q\" to stop count-down)"); DateTime beginWait = DateTime.Now; while (!Console.KeyAvailable && DateTime.Now.Subtract(beginWait).TotalSeconds < 3) { Console.Write("."); Thread.Sleep(250); } if (Console.KeyAvailable && (Console.ReadKey(true).Key == ConsoleKey.Q)) { wait = true; } if (wait) { Console.CursorLeft = 0; Console.Write(("").PadLeft(79, ' ')); Console.CursorLeft = 0; Console.Write("Press any key to exit..."); Console.ReadKey(true); } }
static void BuildSection(string outfile, string sectfile, string buildpath, section s) { byte[] sect = null; if (sectfile.Contains("|")) { string[] fis = sectfile.Split('|'); Console.Write("Evaluating files: "); for (int m = 0; m < fis.Length; m++) { Console.Write(((m == 0) ? "" : " & ") + Path.GetFileName(fis[m])); } Console.Write("...\r\n"); sect = MergeFiles(sectfile.Split('|')); } else { Console.WriteLine("Evaluating file: " + Path.GetFileName(sectfile) + "..."); sect = File.ReadAllBytes(sectfile); } byte[] outbyte = null; string tablepath = Path.Combine(buildpath, s.table); string[] args = new string[] { }; string temp = ""; switch (s.type) { case "lzr": //use lunar compress and replace data LCompress.Compress(sect, out outbyte, GetLZType(s)); ReplaceSection(outfile, outbyte, s.offset); break; case "lzi": //use lunar compress and insert data LCompress.Compress(sect, out outbyte, GetLZType(s)); InsertSection(outfile, outbyte, s.offset); break; case "rep": //replace raw data ReplaceSection(outfile, sect, s.offset); break; case "ins": //insert raw data InsertSection(outfile, sect, s.offset); break; case "bpr": //bitplane convert and replace outbyte = ConvertBPP(sect, s.LZType); ReplaceSection(outfile, outbyte, s.offset); break; case "bpi": //bitplane convert and insert outbyte = ConvertBPP(sect, s.LZType); InsertSection(outfile, outbyte, s.offset); break; case "rlr": //rle compression and replace outbyte = RLECompression(sect, s.LZType); ReplaceSection(outfile, outbyte, s.offset); break; case "rli": //rle compression and insert outbyte = RLECompression(sect, s.LZType); InsertSection(outfile, outbyte, s.offset); break; case "sbi": //script build and insert temp = Script.BuildScriptThread(sectfile, "sctemp", tablepath); sect = File.ReadAllBytes(temp); File.Delete(temp); InsertSection(outfile, sect, s.offset); break; case "sbr": //script build and replace temp = Script.BuildScriptThread(sectfile, "sctemp", tablepath); sect = File.ReadAllBytes(temp); File.Delete(temp); ReplaceSection(outfile, sect, s.offset); break; } }
static uint GetLZType(section s) { return(LCompress.GetLZType(s.LZType)); }