private void UpdateTextures() { if (meta.TextureData == null || meta.TextureData.Length == 0) { labelTextureSectionSize.Text = "Section size: 0 bytes"; labelNumberTextures.Text = "Number of textures: 0"; labelTextureDimensions.Text = ""; labelTextureSize.Text = ""; listBoxTextures.Items.Clear(); listBoxTextures.SelectedIndex = -1; pictureBoxTexture.Image = new Bitmap(32, 32); return; } puyo = new PuyoFile(meta.TextureData); listBoxTextures.Items.Clear(); int index = 0; foreach (PVMEntry pvme in puyo.Entries) { listBoxTextures.Items.Add(index.ToString() + ": " + pvme.Name); index++; } labelTextureSectionSize.Text = "Section size: " + meta.TextureData.Length.ToString() + " bytes"; labelNumberTextures.Text = "Number of textures: " + puyo.Entries.Count.ToString(); listBoxTextures.SelectedIndex = 0; }
public EditorDLCObjectEditor(VMS_DLC meta, PuyoFile pvm) { editorMeta = meta; puyo = pvm; InitializeComponent(); InitializeMetadata(); }
/// <summary> /// Main function for extracting archives. /// </summary> static void ExtractArchive(string[] args) { GenericArchive arc; string arcname = extension.ToUpperInvariant(); Console.WriteLine("Extracting {0} file: {1}", arcname.Substring(1, arcname.Length - 1), filePath); byte[] arcdata = File.ReadAllBytes(filePath); outputPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)); switch (extension.ToLowerInvariant()) { case (".rel"): outputPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + "_dec.rel"); Console.WriteLine("Output file: {0}", outputPath); byte[] inputData = File.ReadAllBytes(args[0]); byte[] outputData = SplitTools.HelperFunctions.DecompressREL(inputData); File.WriteAllBytes(outputPath, outputData); Console.WriteLine("File extracted!"); return; case (".pvmx"): arc = new PVMXFile(arcdata); break; case (".arcx"): arc = new ARCXFile(arcdata); break; case (".prs"): arcdata = FraGag.Compression.Prs.Decompress(arcdata); if (ARCXFile.Identify(arcdata)) { arc = new ARCXFile(arcdata); } else if (PuyoFile.Identify(arcdata) == PuyoArchiveType.Unknown) { outputPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + ".bin"); Console.WriteLine("Output file: {0}", Path.GetFullPath(outputPath)); File.WriteAllBytes(outputPath, arcdata); Console.WriteLine("Archive extracted!"); return; } else { arc = new PuyoFile(arcdata); } break; case (".pvm"): case (".gvm"): arc = new PuyoFile(arcdata); break; case (".xvm"): arc = new XVM(arcdata); break; case (".pb"): arc = new PBFile(arcdata); break; case (".pak"): arc = new PAKFile(filePath); break; case (".dat"): arc = new DATFile(arcdata); break; case (".mdl"): arc = new MDLArchive(arcdata); break; case (".mdt"): arc = new MDTArchive(arcdata); break; case (".mld"): arc = new MLDArchive(arcdata); break; case (".mlt"): case (".gcaxmlt"): string test = System.Text.Encoding.ASCII.GetString(arcdata, 0, 4); if (test == "gcax") { arc = new gcaxMLTFile(arcdata, Path.GetFileNameWithoutExtension(filePath)); } else { arc = new MLTFile(arcdata, Path.GetFileNameWithoutExtension(filePath)); } break; default: Console.WriteLine("Unknown archive type"); return; } Console.WriteLine("Output folder: {0}", Path.GetFullPath(outputPath)); Directory.CreateDirectory(outputPath); foreach (GenericArchiveEntry entry in arc.Entries) { if (entry.Data == null) { Console.WriteLine("Entry {0} has no data", entry.Name); continue; } Console.WriteLine("Extracting file: {0}", entry.Name); if (arc is ARCXFile) { ARCXFile.ARCXEntry ARCXentry = (ARCXFile.ARCXEntry)entry; Directory.CreateDirectory(Path.Combine(outputPath, ARCXentry.Folder)); File.WriteAllBytes(Path.Combine(outputPath, ARCXentry.Folder, entry.Name), entry.Data); } else { File.WriteAllBytes(Path.Combine(outputPath, entry.Name), entry.Data); } } arc.CreateIndexFile(outputPath); Console.WriteLine("Archive extracted!"); }
/// <summary> /// Main function for automatic archive building from a folder. /// </summary> static void BuildFromFolder(string[] args) { bool createPB = false; filePath = args[0]; compressPRS = false; for (int a = 0; a < args.Length; a++) { if (args[a] == "-prs") { compressPRS = true; } if (args[a] == "-pb") { createPB = true; } } //Folder mode if (Directory.Exists(filePath)) { GenericArchive arc; string indexfilename = Path.Combine(filePath, "index.txt"); List <string> filenames = new List <string>(File.ReadAllLines(indexfilename).Where(a => !string.IsNullOrEmpty(a))); string ext = Path.GetExtension(filenames[0]).ToLowerInvariant(); switch (ext) { case ".pvr": if (createPB) { folderMode = ArchiveFromFolderMode.PB; arc = new PBFile(); } else { folderMode = ArchiveFromFolderMode.PVM; arc = new PuyoFile(); } break; case ".gvr": arc = new PuyoFile(true); folderMode = ArchiveFromFolderMode.GVM; break; case ".wav": case ".adx": folderMode = ArchiveFromFolderMode.DAT; arc = new DATFile(); break; case ".png": case ".jpg": case ".bmp": case ".dds": case ".gif": default: folderMode = ArchiveFromFolderMode.PVMX; arc = new PVMXFile(); break; } Console.WriteLine("Creating {0} archive from folder: {1}", folderMode.ToString(), filePath); int id = 0; foreach (string line in filenames) { string[] split = line.Split(','); string filename = split[0]; switch (folderMode) { case ArchiveFromFolderMode.DAT: arc.Entries.Add(new DATEntry(Path.Combine(filePath, filename))); extension = ".dat"; break; case ArchiveFromFolderMode.PVM: arc.Entries.Add(new PVMEntry(Path.Combine(filePath, filename))); extension = ".pvm"; break; case ArchiveFromFolderMode.GVM: arc.Entries.Add(new GVMEntry(Path.Combine(filePath, filename))); extension = ".gvm"; break; case ArchiveFromFolderMode.PB: PBFile pbf = (PBFile)arc; arc.Entries.Add(new PBEntry(Path.Combine(filePath, filename), pbf.GetCurrentOffset(id, filenames.Count))); extension = ".pb"; break; case ArchiveFromFolderMode.PVMX: extension = ".pvmx"; filename = split[1]; int width = 0; int height = 0; uint gbix = uint.Parse(split[0]); if (split.Length > 2) { width = int.Parse(split[2].Split('x')[0]); height = int.Parse(split[2].Split('x')[1]); } arc.Entries.Add(new PVMXEntry(Path.GetFileName(filename), gbix, File.ReadAllBytes(Path.Combine(filePath, filename)), width, height)); break; default: extension = ".bin"; break; } Console.WriteLine("Added entry {0}: {1}", id.ToString(), filename); id++; } byte[] data = arc.GetBytes(); outputPath = Path.GetFullPath(filePath) + extension; if (compressPRS) { Console.WriteLine("Compressing to PRS..."); data = FraGag.Compression.Prs.Compress(data); outputPath = Path.ChangeExtension(outputPath, ".PRS"); } Console.WriteLine("Output file: {0}", outputPath); File.WriteAllBytes(outputPath, data); } }
/// <summary> /// Convert PVM or GVM to a texture pack. /// </summary> static void Puyo2Texpack(string[] args) { Queue <string> files = new Queue <string>(); for (int u = 1; u < args.Length; u++) { files.Enqueue(args[u]); } if (files.Count == 0) { Console.Write("File: "); files.Enqueue(Console.ReadLine()); } while (files.Count > 0) { string filename = files.Dequeue(); outputPath = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(filename)), Path.GetFileNameWithoutExtension(filename)); string filename_full = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(filename)), Path.GetFileName(filename)); Console.WriteLine("Converting file to texture pack: {0}", filename_full); Console.WriteLine("Output folder: {0}", Path.GetFullPath(outputPath)); Directory.CreateDirectory(outputPath); byte[] filedata = File.ReadAllBytes(filename_full); if (Path.GetExtension(filename_full).ToLowerInvariant() == ".prs") { filedata = FraGag.Compression.Prs.Decompress(filedata); } PuyoFile puyo = new PuyoFile(filedata); using (TextWriter texList = File.CreateText(Path.Combine(outputPath, "index.txt"))) { try { foreach (GenericArchiveEntry entry in puyo.Entries) { uint gbix = 0; if (entry is PVMEntry pvme) { gbix = pvme.GetGBIX(); } else if (entry is GVMEntry gvme) { gbix = gvme.GetGBIX(); } Bitmap bmp = entry.GetBitmap(); Console.WriteLine("Converting entry: {0}", entry.Name); texList.WriteLine(string.Join(",", gbix, Path.GetFileNameWithoutExtension(entry.Name) + ".png", bmp.Width + "x" + bmp.Height)); bmp.Save(Path.Combine(outputPath, Path.GetFileNameWithoutExtension(entry.Name) + ".png"), System.Drawing.Imaging.ImageFormat.Png); } } catch (Exception ex) { Console.WriteLine("Exception thrown: " + ex.ToString() + "\nCanceling conversion."); return; } Console.WriteLine("Conversion complete!"); if (files.Count > 0) { Console.WriteLine(); } } } }
/// <summary> /// Convert a GBIX indexed texture pack to PVM. /// </summary> static void TexPack2PVM(string[] args) { bool compressPRS = false; if (args[args.Length - 1] == "-prs") { compressPRS = true; } filePath = args[1]; string FullLine; string texturename; uint GBIX = 0; List <string> textureNames = new List <String>(); List <PvrTexture> finalTextureList = new List <PvrTexture>(); directoryName = Path.GetDirectoryName(filePath); string archiveName = Path.GetFileNameWithoutExtension(filePath); if (Directory.Exists(filePath)) { Console.WriteLine("Converting texture pack to PVM: {0}", Path.GetFullPath(filePath)); StreamReader texlistStream = File.OpenText(Path.Combine(filePath, "index.txt")); while (!texlistStream.EndOfStream) { textureNames.Add(texlistStream.ReadLine()); } PuyoFile puyo = new PuyoFile(); outputPath = Path.ChangeExtension(filePath, ".pvm"); // Reading in textures for (uint imgIndx = 0; imgIndx < textureNames.Count; imgIndx++) { FullLine = textureNames[(int)imgIndx]; if (string.IsNullOrEmpty(FullLine)) { continue; } string[] substrings = FullLine.Split(','); GBIX = UInt32.Parse(substrings[0]); texturename = substrings[1]; Bitmap tempTexture = new Bitmap(8, 8); string texturePath = Path.Combine(filePath, Path.ChangeExtension(texturename, ".png")); if (File.Exists(texturePath)) { Console.WriteLine("Adding texture: " + (texturePath)); tempTexture = (Bitmap)Bitmap.FromFile(texturePath); tempTexture = tempTexture.Clone(new Rectangle(Point.Empty, tempTexture.Size), System.Drawing.Imaging.PixelFormat.Format32bppArgb); } else { Console.WriteLine(string.Concat("Texture ", textureNames[(int)imgIndx], " not found. Generating a placeholder. Check your files.")); } System.Drawing.Imaging.BitmapData bmpd = tempTexture.LockBits(new Rectangle(Point.Empty, tempTexture.Size), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); int stride = bmpd.Stride; byte[] bits = new byte[Math.Abs(stride) * bmpd.Height]; System.Runtime.InteropServices.Marshal.Copy(bmpd.Scan0, bits, 0, bits.Length); tempTexture.UnlockBits(bmpd); int tlevels = 0; for (int y = 0; y < tempTexture.Height; y++) { int srcaddr = y * Math.Abs(stride); for (int x = 0; x < tempTexture.Width; x++) { Color c = Color.FromArgb(BitConverter.ToInt32(bits, srcaddr + (x * 4))); if (c.A == 0) { tlevels = 1; } else if (c.A < 255) { tlevels = 2; break; } } if (tlevels == 2) { break; } } PvrPixelFormat ppf = PvrPixelFormat.Rgb565; if (tlevels == 1) { ppf = PvrPixelFormat.Argb1555; } else if (tlevels == 2) { ppf = PvrPixelFormat.Argb4444; } PvrDataFormat pdf = PvrDataFormat.Rectangle; if (tempTexture.Width == tempTexture.Height) { pdf = PvrDataFormat.SquareTwiddled; } PvrTextureEncoder encoder = new PvrTextureEncoder(tempTexture, ppf, pdf); encoder.GlobalIndex = GBIX; string pvrPath = Path.ChangeExtension(texturePath, ".pvr"); encoder.Save(pvrPath); puyo.Entries.Add(new PVMEntry(pvrPath)); } File.WriteAllBytes(outputPath, puyo.GetBytes()); if (compressPRS) { Console.WriteLine("Compressing to PRS..."); byte[] pvmdata = File.ReadAllBytes(Path.ChangeExtension(filePath, ".pvm")); pvmdata = FraGag.Compression.Prs.Compress(pvmdata); outputPath = Path.ChangeExtension(filePath, ".prs"); File.WriteAllBytes(outputPath, pvmdata); File.Delete(Path.ChangeExtension(filePath, ".pvm")); } Console.WriteLine("Output file: {0}", Path.GetFullPath(outputPath)); Console.WriteLine("Archive was compiled successfully!"); } else { Console.WriteLine("Supplied texture list does not exist!"); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); return; } }
public static BMPInfo[] GetTextures(string filename) { if (!File.Exists(filename)) { return(null); } GenericArchive arc; List <BMPInfo> textures = new List <BMPInfo>(); byte[] file = File.ReadAllBytes(filename); string ext = Path.GetExtension(filename).ToLowerInvariant(); switch (ext) { // Folder texture pack case ".txt": string[] files = File.ReadAllLines(filename); List <BMPInfo> txts = new List <BMPInfo>(); for (int s = 0; s < files.Length; s++) { string[] entry = files[s].Split(','); txts.Add(new BMPInfo(Path.GetFileNameWithoutExtension(entry[1]), new System.Drawing.Bitmap(Path.Combine(Path.GetDirectoryName(filename), entry[1])))); } return(txts.ToArray()); case ".pak": arc = new PAKFile(filename); string filenoext = Path.GetFileNameWithoutExtension(filename).ToLowerInvariant(); PAKFile pak = (PAKFile)arc; // Get sorted entires from the INF file if it exists List <PAKFile.PAKEntry> sorted = pak.GetSortedEntries(filenoext); arc.Entries = new List <GenericArchiveEntry>(sorted.Cast <GenericArchiveEntry>()); break; case ".pvmx": arc = new PVMXFile(file); break; case ".pb": arc = new PBFile(file); break; case ".pvr": case ".gvr": arc = new PuyoFile(ext == ".gvr"); PuyoFile parcx = (PuyoFile)arc; if (ext == ".gvr") { arc.Entries.Add(new GVMEntry(filename)); } else { arc.Entries.Add(new PVMEntry(filename)); } if (parcx.PaletteRequired) { parcx.AddPalette(Path.GetDirectoryName(filename)); } break; case ".prs": file = FraGag.Compression.Prs.Decompress(file); goto default; case ".pvm": case ".gvm": default: arc = new PuyoFile(file); PuyoFile parc = (PuyoFile)arc; if (parc.PaletteRequired) { parc.AddPalette(Path.GetDirectoryName(filename)); } break; } foreach (GenericArchiveEntry entry in arc.Entries) { textures.Add(new BMPInfo(Path.GetFileNameWithoutExtension(entry.Name), entry.GetBitmap())); } return(textures.ToArray()); }
/// <summary> /// Convert GVM to PVM. /// </summary> static void GVM2PVM(string[] args) { filePath = args[1]; if (args.Length > 2 && args[2] == "-prs") { compressPRS = true; } Console.WriteLine("Converting GVM to PVM: {0}", filePath); directoryName = Path.GetDirectoryName(filePath); extension = Path.GetExtension(filePath).ToLowerInvariant(); if (!File.Exists(filePath)) { Console.WriteLine("Supplied GVM archive does not exist!"); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); return; } if (extension != ".gvm") { Console.WriteLine("GVM2PVM mode can only be used with GVM files."); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); return; } fileNameFromFolder = Path.Combine(directoryName, Path.GetFileNameWithoutExtension(filePath)); Directory.CreateDirectory(fileNameFromFolder); using (TextWriter texList = File.CreateText(Path.Combine(fileNameFromFolder, Path.GetFileName(fileNameFromFolder) + ".txt"))) { try { PuyoFile gvmFile = new PuyoFile(File.ReadAllBytes(filePath)); PuyoFile pvmFile = new PuyoFile(); outputPath = Path.ChangeExtension(filePath, ".pvm"); foreach (GVMEntry file in gvmFile.Entries) { if (!File.Exists(Path.Combine(fileNameFromFolder, file.Name))) { File.WriteAllBytes(Path.Combine(fileNameFromFolder, file.Name), file.Data); } Stream data = File.Open(Path.Combine(fileNameFromFolder, file.Name), FileMode.Open); VrTexture vrfile = new GvrTexture(data); Bitmap tempTexture = vrfile.ToBitmap(); System.Drawing.Imaging.BitmapData bmpd = tempTexture.LockBits(new Rectangle(Point.Empty, tempTexture.Size), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); int stride = bmpd.Stride; byte[] bits = new byte[Math.Abs(stride) * bmpd.Height]; System.Runtime.InteropServices.Marshal.Copy(bmpd.Scan0, bits, 0, bits.Length); tempTexture.UnlockBits(bmpd); int tlevels = 0; for (int y = 0; y < tempTexture.Height; y++) { int srcaddr = y * Math.Abs(stride); for (int x = 0; x < tempTexture.Width; x++) { Color c = Color.FromArgb(BitConverter.ToInt32(bits, srcaddr + (x * 4))); if (c.A == 0) { tlevels = 1; } else if (c.A < 255) { tlevels = 2; break; } } if (tlevels == 2) { break; } } PvrPixelFormat ppf = PvrPixelFormat.Rgb565; if (tlevels == 1) { ppf = PvrPixelFormat.Argb1555; } else if (tlevels == 2) { ppf = PvrPixelFormat.Argb4444; } PvrDataFormat pdf; if (!vrfile.HasMipmaps) { if (tempTexture.Width == tempTexture.Height) { pdf = PvrDataFormat.SquareTwiddled; } else { pdf = PvrDataFormat.Rectangle; } } else { if (tempTexture.Width == tempTexture.Height) { pdf = PvrDataFormat.SquareTwiddledMipmaps; } else { pdf = PvrDataFormat.RectangleTwiddled; } } PvrTextureEncoder encoder = new PvrTextureEncoder(tempTexture, ppf, pdf); encoder.GlobalIndex = vrfile.GlobalIndex; string pvrPath = Path.ChangeExtension(Path.Combine(fileNameFromFolder, file.Name), ".pvr"); if (!File.Exists(pvrPath)) { encoder.Save(pvrPath); } data.Close(); File.Delete(Path.Combine(fileNameFromFolder, file.Name)); MemoryStream readfile = new MemoryStream(File.ReadAllBytes(pvrPath)); pvmFile.Entries.Add(new PVMEntry(pvrPath)); texList.WriteLine(Path.GetFileName(pvrPath)); Console.WriteLine("Adding texture {0}", pvrPath); } File.WriteAllBytes(outputPath, pvmFile.GetBytes()); texList.Flush(); texList.Close(); } catch (Exception ex) { Console.WriteLine("Exception thrown: {0}", ex.ToString()); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); return; } } if (compressPRS) { outputPath = Path.ChangeExtension(filePath, ".PVM.PRS"); Console.WriteLine("Compressing to PRS..."); byte[] pvmdata = File.ReadAllBytes(Path.ChangeExtension(filePath, ".pvm")); pvmdata = FraGag.Compression.Prs.Compress(pvmdata); File.WriteAllBytes(outputPath, pvmdata); File.Delete(Path.ChangeExtension(filePath, ".PVM")); } Console.WriteLine("Output file: {0}", Path.GetFullPath(outputPath)); Console.WriteLine("Archive converted!"); Directory.Delete(fileNameFromFolder, true); }
/// <summary> /// Main function for automatic archive building from a folder. /// </summary> static void BuildFromFolder(string[] args) { bool createPB = false; bool createARCX = false; filePath = args[0]; compressPRS = false; for (int a = 0; a < args.Length; a++) { if (args[a] == "-prs") { compressPRS = true; } if (args[a] == "-pb") { createPB = true; } if (args[a] == "-arcx") { createARCX = true; } } // Folder mode if (Directory.Exists(filePath)) { GenericArchive arc; string indexfilename = Path.Combine(filePath, "index.txt"); if (createARCX) { CreateARCX(filePath); return; } if (!File.Exists(indexfilename)) { BuildPAK(filePath); return; } List <string> filenames = new List <string>(File.ReadAllLines(indexfilename).Where(a => !string.IsNullOrEmpty(a))); string ext = Path.GetExtension(filenames[0]).ToLowerInvariant(); if (filenames[0].Contains(",")) { string[] checkf = filenames[0].Split(','); ext = Path.GetExtension(checkf[0].ToLowerInvariant()); } switch (ext) { case ".pvr": if (createPB) { folderMode = ArchiveFromFolderMode.PB; arc = new PBFile(); } else { folderMode = ArchiveFromFolderMode.PVM; arc = new PuyoFile(); } break; case ".gvr": arc = new PuyoFile(true); folderMode = ArchiveFromFolderMode.GVM; break; case ".xvr": arc = new XVM(); folderMode = ArchiveFromFolderMode.XVM; break; case ".wav": case ".adx": folderMode = ArchiveFromFolderMode.DAT; arc = new DATFile(); break; case ".mpb": case ".mdb": case ".msb": case ".osb": case ".fpb": case ".fob": case ".fpw": case ".psr": folderMode = ArchiveFromFolderMode.MLT; arc = new MLTFile(); break; case ".gcaxmpb": case ".gcaxmsb": folderMode = ArchiveFromFolderMode.gcaxMLT; arc = new gcaxMLTFile(); break; case ".png": case ".jpg": case ".bmp": case ".dds": case ".gif": default: folderMode = ArchiveFromFolderMode.PVMX; arc = new PVMXFile(); break; } Console.WriteLine("Creating {0} archive from folder: {1}", folderMode.ToString(), filePath); int id = 0; foreach (string line in filenames) { string[] split = line.Split(','); string filename = split[0]; switch (folderMode) { case ArchiveFromFolderMode.gcaxMLT: int bIDgc = int.Parse(split[1]); arc.Entries.Add(new gcaxMLTEntry(Path.Combine(filePath, filename), bIDgc)); extension = ".mlt"; break; case ArchiveFromFolderMode.MLT: int bID = int.Parse(split[1]); int mem = int.Parse(split[2], System.Globalization.NumberStyles.HexNumber); int sz = int.Parse(split[3]); int version = 1; int revision = 1; string versionfilename = Path.Combine(filePath, "version.txt"); if (File.Exists(versionfilename)) { string[] ver = File.ReadAllLines(versionfilename); version = int.Parse(ver[0]); revision = int.Parse(ver[1]); MLTFile mlt = (MLTFile)arc; mlt.Version = (byte)version; mlt.Revision = (byte)revision; } arc.Entries.Add(new MLTEntry(Path.Combine(filePath, filename), bID, mem, sz)); extension = ".mlt"; break; case ArchiveFromFolderMode.DAT: arc.Entries.Add(new DATEntry(Path.Combine(filePath, filename))); extension = ".dat"; break; case ArchiveFromFolderMode.PVM: arc.Entries.Add(new PVMEntry(Path.Combine(filePath, filename))); extension = ".pvm"; break; case ArchiveFromFolderMode.GVM: arc.Entries.Add(new GVMEntry(Path.Combine(filePath, filename))); extension = ".gvm"; break; case ArchiveFromFolderMode.PB: PBFile pbf = (PBFile)arc; arc.Entries.Add(new PBEntry(Path.Combine(filePath, filename), pbf.GetCurrentOffset(id, filenames.Count))); extension = ".pb"; break; case ArchiveFromFolderMode.PVMX: extension = ".pvmx"; filename = split[1]; int width = 0; int height = 0; uint gbix = uint.Parse(split[0]); if (split.Length > 2) { width = int.Parse(split[2].Split('x')[0]); height = int.Parse(split[2].Split('x')[1]); } arc.Entries.Add(new PVMXEntry(Path.GetFileName(filename), gbix, File.ReadAllBytes(Path.Combine(filePath, filename)), width, height)); break; case ArchiveFromFolderMode.XVM: arc.Entries.Add(new XVMEntry(Path.Combine(filePath, filename))); extension = ".xvm"; break; default: extension = ".bin"; break; } Console.WriteLine("Added entry {0}: {1}", id.ToString(), filename); id++; } byte[] data = arc.GetBytes(); outputPath = Path.GetFullPath(filePath) + extension; if (compressPRS) { Console.WriteLine("Compressing to PRS..."); data = FraGag.Compression.Prs.Compress(data); outputPath = Path.ChangeExtension(outputPath, ".PRS"); } Console.WriteLine("Output file: {0}", outputPath); File.WriteAllBytes(outputPath, data); } }
/// <summary> /// Main function for extracting archives. /// </summary> static void ExtractArchive(string[] args) { GenericArchive arc; string arcname = extension.ToUpperInvariant(); Console.WriteLine("Extracting {0} file: {1}", arcname.Substring(1, arcname.Length - 1), filePath); byte[] arcdata = File.ReadAllBytes(filePath); outputPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)); switch (extension.ToLowerInvariant()) { case (".rel"): outputPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + "_dec.rel"); Console.WriteLine("Output file: {0}", outputPath); byte[] inputData = File.ReadAllBytes(args[0]); byte[] outputData = SA_Tools.HelperFunctions.DecompressREL(inputData); File.WriteAllBytes(outputPath, outputData); Console.WriteLine("File extracted!"); return; case (".pvmx"): arc = new PVMXFile(arcdata); break; case (".prs"): arcdata = FraGag.Compression.Prs.Decompress(arcdata); if (PuyoFile.Identify(arcdata) == PuyoArchiveType.Unknown) { outputPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + ".bin"); Console.WriteLine("Output file: {0}", Path.GetFullPath(outputPath)); File.WriteAllBytes(outputPath, arcdata); Console.WriteLine("Archive extracted!"); return; } arc = new PuyoFile(arcdata); break; case (".pvm"): case (".gvm"): arc = new PuyoFile(arcdata); break; case (".pb"): arc = new PBFile(arcdata); break; case (".pak"): arc = new PAKFile(filePath); break; case (".dat"): arc = new DATFile(arcdata); break; case (".mdl"): arc = new MDLArchive(arcdata); break; case (".mdt"): arc = new MDTArchive(arcdata); break; case (".mld"): arc = new MLDArchive(arcdata); break; case (".mlt"): arc = new MLTArchive(arcdata); break; default: Console.WriteLine("Unknown archive type"); return; } Console.WriteLine("Output folder: {0}", Path.GetFullPath(outputPath)); Directory.CreateDirectory(outputPath); foreach (GenericArchiveEntry entry in arc.Entries) { Console.WriteLine("Extracting file: {0}", entry.Name); File.WriteAllBytes(Path.Combine(outputPath, entry.Name), entry.Data); } arc.CreateIndexFile(outputPath); Console.WriteLine("Archive extracted!"); }