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 } }
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; } }