public static PBFile readByPath(string pbFilePath) { PBFile pbFile = new PBFile(getCodeTextByPath(Path.Combine(curPath, pbFilePath))); pbFile.read(); return(pbFile); }
private void OnClickPBUnpack(object sender, EventArgs eventArgs) { TreeNode pbNode = treeView1.SelectedNode; PBFile pb = (PBFile)pbNode.Tag; Enabled = false; pb.Unpack(); Enabled = true; _state.SaveProject(); }
static void pbFileToMsgCtrl() { /* * string templentPath = Application.dataPath +"/Lua/plant.proto"; * string templentTxt; * using (StreamReader readerTemplentPath = new StreamReader(templentPath, Encoding.Default)) * { * templentTxt = readerTemplentPath.ReadToEnd(); * readerTemplentPath.Close(); * } */ //string protoPath = Application.dataPath +"/Lua/pblua/sewing.proto"; //string protoPath = Application.dataPath +"/Lua/pblua/plant.proto"; //string protoPath = Application.dataPath +"/Lua/pblua/test.proto"; //string protoPath = Application.dataPath +"/Lua/pblua/manor.proto"; //string protoPath = Application.dataPath +"/Lua/pblua/newproduct.proto"; //string protoPath = Application.dataPath +"/Lua/pblua/animal_combo.proto"; string protoPath = Application.dataPath + "/Resources/proto/addressbook.proto"; string protoTxt; //using (StreamReader readerTemplentPath = new StreamReader(protoPath, Encoding.GetEncoding("GBK"))) using (StreamReader readerTemplentPath = new StreamReader(protoPath, Encoding.GetEncoding("utf-8"))) { protoTxt = readerTemplentPath.ReadToEnd(); readerTemplentPath.Close(); } PBFile pbFile = new PBFile(protoTxt); pbFile.read(); PBLuaTp.toLuaMsgCtrl(protoPath, pbFile); AssetDatabase.Refresh(); }
public void Update(PBFile pbFile) { textBox_FileCount.Text = pbFile.Files.Count.ToString(); }
static void Main(string[] args) { ArchiveFromFolderMode folderMode; string dir; string filePath; string directoryName; ArchiveBase pvmArchive; ArchiveWriter pvmWriter; string archiveName; string path; byte[] filedata; bool isPRS; bool isBIN = false; string extension; // Usage if (args.Length == 0) { Console.WriteLine("ArchiveTool is a command line tool to extract and create PVM, GVM, PRS, DAT and PB archives.\nIt can also decompress SADX Gamecube 'SaCompGC' REL files.\n"); Console.WriteLine("Usage:\n"); Console.WriteLine("Extracting a PVM/GVM/PRS/PB/PVMX/DAT/REL file:\nArchiveTool <archivefile>\nIf the archive is PRS compressed, it will be decompressed first.\nIf the archive contains textures/sounds, the program will extract them and create a list of files named 'index.txt'.\n"); Console.WriteLine("Extracting an NjUtil archive: ArchiveTool -nju <archivefile>\n"); Console.WriteLine("Converting PVM/GVM to a folder texture pack: ArchiveTool -png <archivefile>\n"); Console.WriteLine("Creating a PB archive from a folder with textures: ArchiveTool -pb <foldername>"); Console.WriteLine("Creating a PVM/GVM/DAT/PVMX from a folder with textures/sounds: ArchiveTool <foldername> [-prs]\nThe program will create an archive from files listed in 'index.txt' in the folder.\nThe -prs option will make the program output a PRS compressed archive.\n"); Console.WriteLine("Creating a PVM from PNG textures: ArchiveTool -pvm <folder> [-prs]\nThe texture list 'index.txt' must contain global indices listed before each texture filename for this option to work.\n"); Console.WriteLine("Converting GVM to PVM (lossy): ArchiveTool -gvm2pvm <file.gvm> [-prs]\n"); Console.WriteLine("Creating a PRS compressed binary: ArchiveTool <file.bin>\nFile extension must be .BIN for this option to work.\n"); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); return; } switch (args[0].ToLowerInvariant()) { // GVM2PVM mode case "-gvm2pvm": filePath = args[1]; isPRS = false; if (args.Length > 2 && args[2] == "-prs") { isPRS = 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; } path = Path.Combine(directoryName, Path.GetFileNameWithoutExtension(filePath)); Directory.CreateDirectory(path); filedata = File.ReadAllBytes(filePath); using (TextWriter texList = File.CreateText(Path.Combine(path, Path.GetFileName(path) + ".txt"))) { try { ArchiveBase gvmfile = null; byte[] gvmdata = File.ReadAllBytes(filePath); gvmfile = new GvmArchive(); ArchiveReader gvmReader = gvmfile.Open(gvmdata); Stream pvmStream = File.Open(Path.ChangeExtension(filePath, ".pvm"), FileMode.Create); pvmArchive = new PvmArchive(); pvmWriter = pvmArchive.Create(pvmStream); foreach (ArchiveEntry file in gvmReader.Entries) { if (!File.Exists(Path.Combine(path, file.Name))) { gvmReader.ExtractToFile(file, Path.Combine(path, file.Name)); } Stream data = File.Open(Path.Combine(path, 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; archiveName = Path.GetFileNameWithoutExtension(filePath); 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(path, file.Name), ".pvr"); if (!File.Exists(pvrPath)) { encoder.Save(pvrPath); } data.Close(); File.Delete(Path.Combine(path, file.Name)); pvmWriter.CreateEntryFromFile(pvrPath); texList.WriteLine(Path.GetFileName(pvrPath)); Console.WriteLine("Adding texture {0}", pvrPath); } pvmWriter.Flush(); pvmStream.Flush(); pvmStream.Close(); if (isPRS) { Console.WriteLine("Compressing to PRS..."); byte[] pvmdata = File.ReadAllBytes(Path.ChangeExtension(filePath, ".pvm")); pvmdata = FraGag.Compression.Prs.Compress(pvmdata); File.WriteAllBytes(Path.ChangeExtension(filePath, ".PVM.PRS"), pvmdata); File.Delete(Path.ChangeExtension(filePath, ".PVM")); } Console.WriteLine("Archive converted!"); } catch (Exception ex) { Console.WriteLine("Exception thrown: {0}", ex.ToString()); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); return; } } break; // CompilePVM mode case "-pvm": bool IsPRS = false; if (args[args.Length - 1] == "-prs") { IsPRS = 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); archiveName = Path.GetFileNameWithoutExtension(filePath); if (Directory.Exists(filePath)) { Console.WriteLine("Converting texture pack to PVM: {0}", filePath); StreamReader texlistStream = File.OpenText(Path.Combine(filePath, "index.txt")); while (!texlistStream.EndOfStream) { textureNames.Add(texlistStream.ReadLine()); } pvmArchive = new PvmArchive(); Stream pvmStream = File.Open(Path.ChangeExtension(filePath, ".pvm"), FileMode.Create); pvmWriter = (PvmArchiveWriter)pvmArchive.Create(pvmStream); // 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); pvmWriter.CreateEntryFromFile(pvrPath); } pvmWriter.Flush(); pvmStream.Close(); if (IsPRS) { Console.WriteLine("Compressing to PRS..."); byte[] pvmdata = File.ReadAllBytes(Path.ChangeExtension(filePath, ".pvm")); pvmdata = FraGag.Compression.Prs.Compress(pvmdata); File.WriteAllBytes(Path.ChangeExtension(filePath, ".prs"), pvmdata); File.Delete(Path.ChangeExtension(filePath, ".pvm")); } Console.WriteLine("Archive was compiled successfully!"); } else { Console.WriteLine("Supplied texture list does not exist!"); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); return; } break; // Create PB mode case "-pb": filePath = args[1]; Console.WriteLine("Building PB from folder: {0}", filePath); if (Directory.Exists(filePath)) { string indexfilename = Path.Combine(filePath, "index.txt"); if (!File.Exists(indexfilename)) { Console.WriteLine("Supplied path does not have an index file."); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); return; } List <string> filenames = new List <string>(File.ReadAllLines(indexfilename).Where(a => !string.IsNullOrEmpty(a))); PBFile pba = new PBFile(filenames.Count); int l = 0; foreach (string tex in filenames) { byte[] texbytes = File.ReadAllBytes(Path.Combine(filePath, tex)); pba.AddPVR(texbytes, l); l++; } path = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(filePath)), Path.GetFileNameWithoutExtension(filePath)); string filename_full = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(filePath)), Path.GetFileName(filePath) + ".pb"); Console.WriteLine("Output file: {0}", filename_full); File.WriteAllBytes(filename_full, pba.GetBytes()); } else { Console.WriteLine("Supplied path does not exist."); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); return; } break; // Extract NjArchive mode case "-nju": filePath = args[1]; filedata = File.ReadAllBytes(filePath); if (Path.GetExtension(filePath).Equals(".prs", StringComparison.OrdinalIgnoreCase)) { filedata = FraGag.Compression.Prs.Decompress(filedata); } NjArchive njarc = new NjArchive(filedata); Console.WriteLine("Extracting Ninja archive: {0}", filePath); dir = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)); Console.WriteLine("Output folder: {0}", dir); Directory.CreateDirectory(dir); for (int i = 0; i < njarc.Entries.Count; i++) { byte[] data = njarc.Entries[i]; extension = ".bin"; string desc = "Unknown"; switch (System.Text.Encoding.ASCII.GetString(data, 0, 4)) { case "NJIN": desc = "Ninja Information"; extension = ".nji"; break; case "NJCM": desc = "Ninja Chunk model"; extension = ".nj"; break; case "GJCM": desc = "Ninja Chunk model (GC)"; extension = ".gj"; break; case "NJBM": desc = "Ninja Basic model"; extension = ".nj"; break; case "NMDM": desc = "Ninja Motion"; extension = ".njm"; break; case "NJLI": desc = "Ninja Light"; extension = ".njl"; break; case "NLIM": desc = "Ninja Light Motion"; extension = ".njlm"; break; case "NSSM": desc = "Ninja Simple Shape Motion"; extension = ".njsm"; break; case "NCAM": desc = "Ninja Camera Motion"; extension = ".ncm"; break; case "NJTL": desc = "Ninja Texlist"; extension = ".nj"; break; case "GJTL": desc = "Ninja Texlist (GC)"; extension = ".gj"; break; case "PVMH": desc = "PVM"; extension = ".pvm"; break; case "GVMH": desc = "GVM"; extension = ".gvm"; break; } Console.WriteLine("Entry {0} is {1}", i, desc); string outpath = Path.Combine(dir, i.ToString("D3") + extension); File.WriteAllBytes(outpath, njarc.Entries[i]); } break; // PVM2TexPack mode case "-png": 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(); path = 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); Directory.CreateDirectory(path); filedata = File.ReadAllBytes(filename_full); using (TextWriter texList = File.CreateText(Path.Combine(path, "index.txt"))) { try { if (PvrTexture.Is(filedata)) { if (!AddTexture(false, path, Path.GetFileName(filename_full), new MemoryStream(filedata), texList)) { texList.Close(); Directory.Delete(path, true); } continue; } else if (GvrTexture.Is(filedata)) { if (!AddTexture(true, path, Path.GetFileName(filename_full), new MemoryStream(filedata), texList)) { texList.Close(); Directory.Delete(path, true); } continue; } bool gvm = false; ArchiveBase pvmfile = null; byte[] pvmdata = File.ReadAllBytes(filename_full); if (Path.GetExtension(filename_full).Equals(".prs", StringComparison.OrdinalIgnoreCase)) { pvmdata = FraGag.Compression.Prs.Decompress(pvmdata); } pvmfile = new PvmArchive(); MemoryStream stream = new MemoryStream(pvmdata); if (!PvmArchive.Identify(stream)) { pvmfile = new GvmArchive(); gvm = true; } ArchiveEntryCollection pvmentries = pvmfile.Open(pvmdata).Entries; bool fail = false; foreach (ArchiveEntry file in pvmentries) { if (!AddTexture(gvm, path, file.Name, file.Open(), texList)) { texList.Close(); Directory.Delete(path, true); fail = true; break; } } if (fail) { continue; } } catch (Exception ex) { Console.WriteLine("Exception thrown: " + ex.ToString() + "\nCanceling conversion."); return; } Console.WriteLine("Conversion complete!"); } } break; // Other modes default: filePath = args[0]; IsPRS = false; if (args.Length > 1 && args[1] == "-prs") { IsPRS = true; } extension = Path.GetExtension(filePath).ToLowerInvariant(); //Folder mode if (Directory.Exists(filePath)) { 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(); pvmArchive = new PvmArchive(); switch (ext) { case ".pvr": folderMode = ArchiveFromFolderMode.PVM; break; case ".gvr": pvmArchive = new GvmArchive(); folderMode = ArchiveFromFolderMode.GVM; break; case ".wav": folderMode = ArchiveFromFolderMode.DAT; break; case ".png": case ".jpg": case ".bmp": case ".dds": case ".gif": default: folderMode = ArchiveFromFolderMode.PVMX; break; } Console.WriteLine("Creating {0} archive from folder: {1}", folderMode.ToString(), filePath); switch (folderMode) { case ArchiveFromFolderMode.DAT: // Load index DATFile dat = new DATFile(); TextReader tr = File.OpenText(Path.Combine(filePath, "index.txt")); string line = tr.ReadLine(); while (line != null) { Console.WriteLine("Adding file {0}", Path.Combine(filePath, line)); dat.AddFile(Path.Combine(filePath, line)); line = tr.ReadLine(); } tr.Close(); // Save DAT archive File.WriteAllBytes(filePath + ".DAT", dat.GetBytes()); if (IsPRS) { Console.WriteLine("Compressing to PRS..."); byte[] datdata = File.ReadAllBytes(filePath + ".DAT"); datdata = FraGag.Compression.Prs.Compress(datdata); File.WriteAllBytes(filePath + ".PRS", datdata); File.Delete(filePath + ".DAT"); } Console.WriteLine("Archive compiled successfully!"); return; case ArchiveFromFolderMode.PVM: case ArchiveFromFolderMode.GVM: if (filenames.Any(a => !Path.GetExtension(a).Equals(ext, StringComparison.OrdinalIgnoreCase))) { Console.WriteLine("Cannot create archive from mixed file types."); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); return; } ext = folderMode == ArchiveFromFolderMode.PVM ? ".pvm" : ".gvm"; using (Stream pvmStream = File.Open(Path.ChangeExtension(filePath, ext), FileMode.Create)) { pvmWriter = pvmArchive.Create(pvmStream); // Reading in textures foreach (string tex in filenames) { if (folderMode == ArchiveFromFolderMode.PVM) { pvmWriter.CreateEntryFromFile(Path.Combine(filePath, Path.ChangeExtension(tex, ".pvr"))); } else { pvmWriter.CreateEntryFromFile(Path.Combine(filePath, Path.ChangeExtension(tex, ".gvr"))); } Console.WriteLine("Adding file: {0}", tex); } pvmWriter.Flush(); } if (IsPRS) { Console.WriteLine("Compressing to PRS..."); byte[] pvmdata = File.ReadAllBytes(Path.ChangeExtension(filePath, ext)); pvmdata = FraGag.Compression.Prs.Compress(pvmdata); File.WriteAllBytes(Path.ChangeExtension(filePath, ".prs"), pvmdata); File.Delete(Path.ChangeExtension(filePath, ext)); } Console.WriteLine("Archive was compiled successfully!"); return; case ArchiveFromFolderMode.PVMX: // Load index PVMXFile pvmx = new PVMXFile(); TextReader trp = File.OpenText(Path.Combine(filePath, "index.txt")); foreach (string str in filenames) { string[] split = str.Split(','); string texfile = Path.Combine(Path.GetFullPath(filePath), split[1]); Console.WriteLine("Adding file {0}", texfile); if (split.Length > 2) { string[] dimensions = split[2].Split('x'); pvmx.AddFile(split[1], uint.Parse(split[0]), File.ReadAllBytes(texfile), int.Parse(dimensions[0]), int.Parse(dimensions[1])); } else { pvmx.AddFile(split[1], uint.Parse(split[0]), File.ReadAllBytes(texfile)); } } Console.WriteLine("Output file: {0}", Path.ChangeExtension(filePath, ".pvmx")); File.WriteAllBytes(Path.ChangeExtension(filePath, ".pvmx"), pvmx.GetBytes()); Console.WriteLine("Archive was compiled successfully!"); return; } } //Continue with file mode otherwise if (!File.Exists(filePath)) { Console.WriteLine("Supplied archive/texture list does not exist!"); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); return; } switch (extension) { case ".rel": Console.WriteLine("Decompressing REL file: {0}", filePath); byte[] input = File.ReadAllBytes(args[0]); byte[] output = SA_Tools.HelperFunctions.DecompressREL(input); File.WriteAllBytes(Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + "_dec.rel"), output); return; case ".dat": Console.WriteLine("Extracting DAT file: {0}", filePath); DATFile dat = new DATFile(File.ReadAllBytes(filePath)); dir = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)); if (Directory.Exists(dir)) { Directory.Delete(dir, true); } Directory.CreateDirectory(dir); using (StreamWriter sw = File.CreateText(Path.Combine(dir, "index.txt"))) { dat.Entries.Sort((f1, f2) => StringComparer.OrdinalIgnoreCase.Compare(f1.name, f2.name)); for (int i = 0; i < dat.GetCount(); i++) { string fname = dat.Entries[i].name; sw.WriteLine(fname); if (dat.Steam) { fname = Path.GetFileNameWithoutExtension(fname) + ".adx"; } Console.WriteLine("Extracting file: {0}", fname); File.WriteAllBytes(Path.Combine(dir, fname), dat.GetFile(i)); } sw.Flush(); sw.Close(); } Console.WriteLine("Archive extracted!"); break; case ".pvmx": Console.WriteLine("Extracting PVMX file: {0}", filePath); byte[] pvmxdata = File.ReadAllBytes(filePath); dir = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)); Directory.CreateDirectory(dir); PVMXFile pvmx = new PVMXFile(pvmxdata); using (TextWriter texList = File.CreateText(Path.Combine(dir, "index.txt"))) { for (int u = 0; u < pvmx.GetCount(); u++) { byte[] tdata = pvmx.GetFile(u); string outpath = Path.Combine(dir, pvmx.GetName(u)); File.WriteAllBytes(outpath, tdata); string entry; string dimensions = string.Join("x", pvmx.GetWidth(u).ToString(), pvmx.GetHeight(u).ToString()); if (pvmx.HasDimensions(u)) { entry = string.Join(",", pvmx.GetGBIX(u).ToString(), pvmx.GetName(u), dimensions); } else { entry = string.Join(",", pvmx.GetGBIX(u).ToString(), pvmx.GetName(u)); } texList.WriteLine(entry); } texList.Flush(); texList.Close(); } Console.WriteLine("Archive extracted!"); break; case ".pb": Console.WriteLine("Extracting PB file: {0}", filePath); byte[] pbdata = File.ReadAllBytes(filePath); dir = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)); Directory.CreateDirectory(dir); PBFile pba = new PBFile(pbdata); using (TextWriter texList = File.CreateText(Path.Combine(dir, "index.txt"))) { for (int u = 0; u < pba.GetCount(); u++) { byte[] pvrt = pba.GetPVR(u); string outpath = Path.Combine(dir, u.ToString("D3") + ".pvr"); File.WriteAllBytes(outpath, pvrt); texList.WriteLine(u.ToString("D3") + ".pvr"); } texList.Flush(); texList.Close(); } Console.WriteLine("Archive extracted!"); break; case ".bin": Console.WriteLine("Compressing BIN file: {0}", filePath); byte[] bindata = File.ReadAllBytes(Path.ChangeExtension(filePath, ".bin")); bindata = FraGag.Compression.Prs.Compress(bindata); File.WriteAllBytes(Path.ChangeExtension(filePath, ".prs"), bindata); Console.WriteLine("PRS archive was compiled successfully!"); return; case ".prs": case ".pvm": case ".gvm": Console.WriteLine("Extracting archive: {0}", filePath); path = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)); Directory.CreateDirectory(path); filedata = File.ReadAllBytes(filePath); using (TextWriter texList = File.CreateText(Path.Combine(path, "index.txt"))) { try { ArchiveBase pvmfile = null; byte[] pvmdata = File.ReadAllBytes(filePath); if (extension == ".prs") { pvmdata = FraGag.Compression.Prs.Decompress(pvmdata); } pvmfile = new PvmArchive(); MemoryStream stream = new MemoryStream(pvmdata); if (!PvmArchive.Identify(stream)) { pvmfile = new GvmArchive(); if (!GvmArchive.Identify(stream)) { File.WriteAllBytes(Path.ChangeExtension(filePath, ".bin"), pvmdata); isBIN = true; Console.WriteLine("PRS archive extracted!"); } } if (!isBIN) { ArchiveReader pvmReader = pvmfile.Open(pvmdata); foreach (ArchiveEntry pvmentry in pvmReader.Entries) { Console.WriteLine("Extracting file: {0}", pvmentry.Name); texList.WriteLine(pvmentry.Name); pvmReader.ExtractToFile(pvmentry, Path.Combine(path, pvmentry.Name)); } Console.WriteLine("Archive extracted!"); } } catch { Console.WriteLine("Exception thrown. Canceling conversion."); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); Directory.Delete(path, true); throw; } } if (isBIN) { Directory.Delete(path, true); } break; default: Console.WriteLine("Unknown extension \"{0}\".", extension); Console.WriteLine("Press ENTER to exit."); Console.ReadLine(); break; } break; } }
/// <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!"); }
public void Update(BaseFile baseFile) { if (baseFile == null) { if (EnabledLZB) { lzbControl.Visible = false; } if (EnabledTIM) { timControl.Visible = false; } if (EnabledPB) { pbControl.Visible = false; } if (EnabledBG) { bgControl.Visible = false; } textControl.Visible = false; return; } if (baseFile.GetType() == typeof(TIMFile) && EnabledTIM) { TIMFile timFile = (TIMFile)baseFile; timControl.Update(timFile); timControl.Visible = true; if (EnabledLZB) { lzbControl.Visible = false; } if (EnabledPB) { pbControl.Visible = false; } if (EnabledBG) { bgControl.Visible = false; } textControl.Visible = false; return; } if (baseFile.GetType() == typeof(LZBFile) && EnabledLZB) { LZBFile lzbFile = (LZBFile)baseFile; lzbControl.Update(lzbFile); lzbControl.Visible = true; if (EnabledTIM) { timControl.Visible = false; } if (EnabledPB) { pbControl.Visible = false; } if (EnabledBG) { bgControl.Visible = false; } textControl.Visible = false; return; } if (baseFile.GetType() == typeof(PBFile) && EnabledPB) { PBFile pbFile = (PBFile)baseFile; pbControl.Update(pbFile); pbControl.Visible = true; if (EnabledTIM) { timControl.Visible = false; } if (EnabledLZB) { lzbControl.Visible = false; } if (EnabledBG) { bgControl.Visible = false; } textControl.Visible = false; return; } if (baseFile.GetType() == typeof(BGFile) && EnabledBG) { BGFile bgFile = (BGFile)baseFile; bgControl.Update(bgFile); bgControl.Visible = true; if (EnabledTIM) { timControl.Visible = false; } if (EnabledLZB) { lzbControl.Visible = false; } if (EnabledPB) { pbControl.Visible = false; } textControl.Visible = false; return; } textControl.Update(baseFile); textControl.Visible = true; if (EnabledLZB) { lzbControl.Visible = false; } if (EnabledTIM) { timControl.Visible = false; } if (EnabledPB) { pbControl.Visible = false; } if (EnabledBG) { bgControl.Visible = false; } }
static public void toLuaMsgCtrl(string protoPath, PBFile pbFile) { init(); //string pbModularName = protoPath.Replace(Application.dataPath +"/Lua/pblua/","").Replace(".proto","").ToLower() + "_pb"; string pbModularName = Path.GetFileName(protoPath).ToLower() + "_pb"; string luaModularName = pbModularName.Substring(0, 1).ToUpper() + pbModularName.Substring(1, pbModularName.Length - 1).Replace("_pb", ""); string luaModularCtrlName = luaModularName + "MsgCtrl"; string luaModularCtrlFileName = luaModularName + "MsgCtrl"; string sendFunList = ""; string handleMsg = ""; foreach (PBElement chlidPBElement in pbFile.child) { //1. if (chlidPBElement.pb_type == PBElement.type_PBMessage && chlidPBElement.name.IndexOf("Usr") != -1) { string Params = ""; string InitMsg = initMsgTp.Replace("$pbModularName$", pbModularName).Replace("$msgName$", chlidPBElement.name); foreach (PBElement pElement in chlidPBElement.child) { if (pElement.pb_type == PBElement.type_PBAttribute) { PBAttribute attribute = (PBAttribute)pElement; if (attribute.name != "cmd") { Params += "," + attribute.name; } InitMsg += toLuaMsgAttributeSet(attribute, pbModularName); } /* * if(pElement.pb_type == PBElement.type_PBEnum){ * PBEnum pbEnum = (PBEnum)pElement; * Params += ","+pbEnum.name ; * toLuaMsgEnumSet(pbEnum,pbModularName); * }*/ } if (Params.Length > 0) { Params = Params.Substring(1, Params.Length - 1); } string funCode = sendFunTp.Replace("$Notes$", chlidPBElement.Notes).Replace("$luaModularCtrlName$", luaModularCtrlName).Replace("$MsgName$", chlidPBElement.name).Replace("$Params$", Params).Replace("$InitMsg$", InitMsg); Debug.LogWarning(funCode); if (funCode.StartsWith("--//申请收获")) { Debug.Log("xxx"); } sendFunList += funCode; } //2. if (chlidPBElement.pb_type == PBElement.type_PBMessage && chlidPBElement.name.IndexOf("Svr") != -1) { string checkResult = toLuaMsgCheckResult((PBMessage)chlidPBElement); string warnMsgAttribute = toLuaWarnMsgAttribute((PBMessage)chlidPBElement); if (chlidPBElement.name == "S_MsgSvrCollectionEnterFailed") { Debug.LogWarning(chlidPBElement.name); } handleMsg += handleMsgTp.Replace("$pbModularName$", pbModularName).Replace("$Default$", ((PBAttribute)chlidPBElement.getChildByName("cmd")).Default).Replace("$msgName$", chlidPBElement.name).Replace("$warnMsgAttribute$", warnMsgAttribute).Replace("$checkResult$", checkResult); } } string onPBMsgFunCode = onPBMsgFunTp.Replace("$luaModularCtrlName$", luaModularCtrlName).Replace("$handleMsg$", handleMsg); Debug.LogWarning(onPBMsgFunCode); newFileMsgCtrl(luaModularCtrlFileName, luaMsgCtrlCode.Replace("$proto$", pbFile.code).Replace("$pbModularName$", pbModularName).Replace("$luaModularCtrlName$", luaModularCtrlName).Replace("$sendFunList$", sendFunList).Replace("$onPBMsgFunCode$", onPBMsgFunCode) ); }
static void pbFileInfo() { string protoPath = Application.dataPath + "/Resources/proto/addressbook.proto"; PBFile.curPath = "/Users/zhuyuu3d/Downloads"; protoPath = PBFile.curPath + "/ZTest.proto"; PBFile.curPath = "C:/Users/Administrator.PC-20171226GAHY/Desktop/proto"; protoPath = "C:/Users/Administrator.PC-20171226GAHY/Desktop/proto/ZBank.proto"; string LuaCodeOutPath = "/Project/Editor/LuaCodeOut/"; string protoTxt; //using (StreamReader readerTemplentPath = new StreamReader(protoPath, Encoding.GetEncoding("GBK"))) using (StreamReader readerTemplentPath = new StreamReader(protoPath, Encoding.GetEncoding("utf-8"))) { protoTxt = readerTemplentPath.ReadToEnd(); readerTemplentPath.Close(); } string ModuleName = Path.GetFileName(protoPath).Replace(".proto", ""); PBFile pbFile = new PBFile(protoTxt); pbFile.read(); Debug.Log(">> package = " + pbFile.package); StringBuilder CmdKeyList = new StringBuilder(); StringBuilder CmdMappingList = new StringBuilder(); StringBuilder CmdSendFunList = new StringBuilder(); StringBuilder CmdReceiveList = new StringBuilder(); StringBuilder CmdAddlistenerList = new StringBuilder(); StringBuilder CmdRemlistenerList = new StringBuilder(); //pbFile.debug (); //循环 poto->Element 文件定义 foreach (PBElement chlidPBElement in pbFile.child) { Debug.LogFormat("消息 >> name = {0},pb_type = {1}", chlidPBElement.name, chlidPBElement.pb_type); //循环 poto->Element->Enum foreach (PBElement msgPBElement in chlidPBElement.child) { Debug.LogFormat("消息字段 >> >> name = {0},pb_type = {1}", msgPBElement.name, msgPBElement.pb_type); if (msgPBElement.pb_type == PBElement.type_PBEnum && msgPBElement.name.Equals("enumID")) { //消息 ID 枚举 PBEnum PBEnum = (PBEnum)msgPBElement; foreach (PBElement EnumPBElement in msgPBElement.child) { if (EnumPBElement is PBKeyValue) { PBKeyValue cmdID = (EnumPBElement as PBKeyValue); Debug.LogFormat(">> >> >> ID = {0},value = {1}", (EnumPBElement as PBKeyValue).key, (EnumPBElement as PBKeyValue).value); //string tp = "$MsgName$ = sib($ID$),"; CmdKeyList.AppendLine("\t$MsgName$ = sib($ID$),".Replace("$MsgName$", chlidPBElement.name).Replace("$ID$", cmdID.value)); } } } } CmdMappingList.AppendLine("\tpbtable [Cmd.$MsgName$] = \"$Package$.$MsgName$\"".Replace("$MsgName$", chlidPBElement.name).Replace("$Package$", pbFile.package)); //循环 poto->Element.name == CS_ if (chlidPBElement.name.StartsWith("CS_")) { CmdSendFunList.Append("function $ModuleName$ModuleData.send_$MsgName$(".Replace("$MsgName$", chlidPBElement.name).Replace("$ModuleName$", ModuleName)); //循环 poto->Element->Attribute //参数列表 int i = 0; foreach (PBElement msgPBElement in chlidPBElement.child) { if (msgPBElement.pb_type == PBElement.type_PBAttribute) { CmdSendFunList.Append(i > 0 ? "," + msgPBElement.name : msgPBElement.name); i++; } } CmdSendFunList.AppendLine(")"); CmdSendFunList.AppendLine("\tlocal " + chlidPBElement.name + " = {}"); //循环 poto->Element->Attribute foreach (PBElement msgPBElement in chlidPBElement.child) { if (msgPBElement.pb_type == PBElement.type_PBAttribute) { CmdSendFunList.AppendLine("\t" + chlidPBElement.name + "." + msgPBElement.name + " = " + msgPBElement.name); } } CmdSendFunList.AppendLine(string.Format("\tGameState.tcpClinet.sendmsg(Cmd.{0},{1})", chlidPBElement.name, chlidPBElement.name)); CmdSendFunList.AppendLine("end"); } //循环 poto->Element.name == SC_ if (chlidPBElement.name.StartsWith("SC_")) { CmdAddlistenerList.AppendLine("\ttcpClinet.addlistener(Cmd.$MsgName$,$ModuleName$ModuleData.on_msg)".Replace("$ModuleName$", ModuleName).Replace("$MsgName$", chlidPBElement.name)); CmdRemlistenerList.AppendLine("\ttcpClinet.removelistener(Cmd.$MsgName$,$ModuleName$ModuleData.on_msg)".Replace("$ModuleName$", ModuleName).Replace("$MsgName$", chlidPBElement.name)); CmdReceiveList.AppendLine("\tif key == Cmd.$MsgName$ then".Replace("$MsgName$", chlidPBElement.name)); CmdReceiveList.AppendLine("\t\tprint(\"$ModuleName$ >> on_msg >> user_para >> \".. Cmd.$MsgName$)\n".Replace("$ModuleName$", ModuleName).Replace("$MsgName$", chlidPBElement.name)); CmdReceiveList.AppendLine("\t\t$ModuleName$ModuleData.$MsgName$ = decode".Replace("$ModuleName$", ModuleName).Replace("$MsgName$", chlidPBElement.name)); foreach (PBElement msgPBElement in chlidPBElement.child) { if (msgPBElement.pb_type == PBElement.type_PBAttribute) { CmdReceiveList.AppendLine("\t\tprint(\"$MsgName$.$Attribute$ \".. decode.$Attribute$)").Replace("$MsgName$", chlidPBElement.name).Replace("$Attribute$", msgPBElement.name); } } CmdReceiveList.AppendLine("\tend"); } } /* * -- $ModuleName$ * -- $MsgName$ * -- $Package$ * -- $ID$ */ Dictionary <string, string> repkey = new Dictionary <string, string> (); repkey["$ModuleName$"] = ModuleName; repkey ["$CmdKeyList$"] = CmdKeyList.ToString(); repkey ["$CmdMappingList$"] = CmdMappingList.ToString(); repkey ["$CmdReceiveList$"] = CmdReceiveList.ToString(); repkey ["$CmdAddlistenerList$"] = CmdAddlistenerList.ToString(); repkey ["$CmdRemlistenerList$"] = CmdRemlistenerList.ToString(); repkey ["$CmdSendFunList$"] = CmdSendFunList.ToString(); repkey ["$Package$"] = pbFile.package; //"$MsgName$ = sib($ID$)," //$CmdKeyList$ string luaFilePath = Application.dataPath + string.Format("{0}/DataModules/{1}ModuleData.lua", LuaCodeOutPath, repkey ["$ModuleName$"]); CreateLuaCodeByTp(repkey, Application.dataPath + "/Project/Editor/LuaCodeTp/TP_ModuleData.lua", luaFilePath); }
public void read() { List <CodeKeyword> codekeyStack = new List <CodeKeyword>(); List <CodeSymbol> symbolStack = new List <CodeSymbol>(); List <PBElement> elementStack = new List <PBElement>(); elementStack.Add(this); if (charArr == null) { charArr = code.ToCharArray(); } PBElement curPBElement = null; int startIndex = 0; for (int i = 0; i < code.Length; i++) { startIndex = i; CodeSymbol curSymbol = FindNextSymbol(code, startIndex); int Index = curSymbol.Index; if (Index > 0) { //跳过注释 if (curSymbol.Symbol == '/') { if (charArr [curSymbol.Index + 1] == '*') { while (Index < charArr.Length) { curSymbol = FindNextSymbol(code, Index + 1, '/'); Index = curSymbol.Index; if (Index == -1) { Debug.LogErrorFormat("{0} not find '/' end", name); return; } if (charArr [curSymbol.Index - 1] == '*') { break; } } i = Index; Debug.LogWarningFormat("{0} jump /**/ index {1} ", name, Index); continue; } } string key = code.Substring(startIndex, Index - startIndex); if (curPBElement != null && key.StartsWith("//")) { // curPBElement.Notes = key; } if (key == "") { } else { //关键字压入 codekeyStack.Add(new CodeKeyword(startIndex, key)); } if (key.Equals("import")) { //PBFile pbFile = new PBFile (); PBImportFile pushPBImportFile = new PBImportFile(); pushPBImportFile.startIndex = startIndex; elementStack.Add(pushPBImportFile); curPBElement = pushPBImportFile; } else if (key.Equals("package")) { PBPackage pushPBPackage = new PBPackage(); pushPBPackage.startIndex = startIndex; elementStack.Add(pushPBPackage); curPBElement = pushPBPackage; } else if (key.Equals("required") || key.Equals("optional") || key.Equals("repeated")) { PBAttribute pushPBAttribute = new PBAttribute(); pushPBAttribute.startIndex = startIndex; elementStack.Add(pushPBAttribute); curPBElement = pushPBAttribute; } else //enum压入 if (key == "enum") { PBEnum pushPBElement = new PBEnum(); pushPBElement.pbFile = this; pushPBElement.name = key; pushPBElement.startIndex = Index; elementStack.Add(pushPBElement); curPBElement = pushPBElement; } else //message压入 if (key == "message") { PBMessage pushPBMessage = new PBMessage(); pushPBMessage.pbFile = this; pushPBMessage.name = key; pushPBMessage.startIndex = Index; elementStack.Add(pushPBMessage); curPBElement = pushPBMessage; if (codekeyStack.Count >= 2 && codekeyStack[codekeyStack.Count - 2].value.StartsWith("//")) { pushPBMessage.Notes = codekeyStack[codekeyStack.Count - 2].value; } } /* * if(curSymbol.Symbol == '='){ * string pname = (string)codekeyStack[codekeyStack.Count-1]; * Debug.LogWarning(" >> pname :))))) --------> " + pname); * }else */ if (curSymbol.Symbol == '{') { CodeKeyword ptype = codekeyStack[codekeyStack.Count - 2]; CodeKeyword pname = codekeyStack[codekeyStack.Count - 1]; //Debug.LogWarning(" >> Index :))))) --------> " + pname.Index + ", >> pname :))))) --------> " + pname.value ); //压入符号栈 symbolStack.Add(curSymbol); } else if (curSymbol.Symbol == '}') { //块结束 CodeSymbol pushSymbol = symbolStack[symbolStack.Count - 1]; if (pushSymbol.Symbol == '{') { symbolStack.RemoveAt(symbolStack.Count - 1); //弹出符号栈 PBElement popUpPBElement = elementStack[elementStack.Count - 1]; popUpPBElement.endIndex = Index; popUpPBElement.cut(code); elementStack.RemoveAt(elementStack.Count - 1); if (elementStack.Count > 0) { elementStack[elementStack.Count - 1].addChild(popUpPBElement); } } else { Debug.LogError("Symbol Error { "); } } else if (curSymbol.Symbol == '[') { symbolStack.Add(curSymbol); PBKeyValue pushPBKeyValue = new PBKeyValue(); pushPBKeyValue.startIndex = Index; elementStack.Add(pushPBKeyValue); } else if (curSymbol.Symbol == ']') { CodeSymbol pushSymbol = symbolStack[symbolStack.Count - 1]; if (pushSymbol.Symbol == '[') { symbolStack.RemoveAt(symbolStack.Count - 1); //弹出 PBElement popUpPBElement = elementStack[elementStack.Count - 1]; popUpPBElement.endIndex = Index; popUpPBElement.cut(code); elementStack.RemoveAt(elementStack.Count - 1); if (elementStack.Count > 0) { elementStack[elementStack.Count - 1].addChild(popUpPBElement); } } else { Debug.LogError("Symbol Error [ "); } } else if (curSymbol.Symbol == ';') { //弹出 PBElement popUpPBElement = elementStack[elementStack.Count - 1]; if (popUpPBElement.pb_type == PBElement.type_PBPackage) { popUpPBElement.endIndex = Index; popUpPBElement.cut(code); this.package = (popUpPBElement as PBPackage).pbPackageName; elementStack.RemoveAt(elementStack.Count - 1); } else if (popUpPBElement.pb_type == PBElement.type_PBImportFile) { popUpPBElement.endIndex = Index; popUpPBElement.cut(code); PBFile pbFile = new PBFile(); pbFile.name = (popUpPBElement as PBImportFile).pbFilePath; pbFile.readFile(pbFile.name); pbFile.read(); PBFileImportDic.Add(pbFile.name, pbFile); elementStack.RemoveAt(elementStack.Count - 1); } else //枚举 属性 if (popUpPBElement.pb_type == PBElement.type_PBEnum) { PBKeyValue PBKeyValue = new PBKeyValue(); PBKeyValue.key = codekeyStack[codekeyStack.Count - 2].value; PBKeyValue.value = codekeyStack[codekeyStack.Count - 1].value; PBKeyValue.startIndex = codekeyStack[codekeyStack.Count - 2].Index; PBKeyValue.endIndex = Index; PBKeyValue.cut(code); popUpPBElement.addChild(PBKeyValue); curPBElement = PBKeyValue; codekeyStack.RemoveAt(codekeyStack.Count - 1); codekeyStack.RemoveAt(codekeyStack.Count - 1); CodeSymbol nextSymbol = FindNextSymbol(code, Index + 1); string nextKey = code.Substring(Index + 1, nextSymbol.Index - (Index + 1)); if (curPBElement != null && nextKey.StartsWith("//")) { curPBElement.Notes = nextKey; } } else //message 属性 if (popUpPBElement.pb_type == PBElement.type_PBAttribute) { popUpPBElement.endIndex = Index; popUpPBElement.cut(code); elementStack.RemoveAt(elementStack.Count - 1); curPBElement = popUpPBElement; if (elementStack.Count > 0) { elementStack[elementStack.Count - 1].addChild(popUpPBElement); } CodeSymbol nextSymbol = PBFile.FindNextSymbol(code, Index + 1); string nextKey = code.Substring(Index + 1, nextSymbol.Index - (Index + 1)); if (curPBElement != null && nextKey.StartsWith("//")) { curPBElement.Notes = nextKey; } } } } i = Index; } //getAllChild(this); }
/// <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); } }
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()); }
private void UpdateTreeNodes() { treeView1.Nodes.Clear(); if (_state.ProjectFile == null) { return; } PSXImage image = _state.ProjectFile.ModifiedImage; TreeNode imageNode = new TreeNode(image.ToString()); imageNode.Tag = image; imageNode.Checked = false; foreach (string directory in ConanImage.Directories) { TreeNode directoryNode = new TreeNode(directory); directoryNode.ImageIndex = 0; PKNFile pkn = image.PKNFiles.Find(e => e.Name == directory); if (pkn != null) { TreeNode pknNode = new TreeNode(pkn.FileName); pknNode.ImageIndex = 1; pknNode.SelectedImageIndex = 1; pknNode.Tag = pkn; if (pkn.Files.Count != 0) { foreach (BaseFile file in pkn.Files) { TreeNode fileNode = new TreeNode(file.FileName); fileNode.Tag = file; if (file.GetType() == typeof(PBFile)) { PBFile pbFile = (PBFile)file; foreach (PBFileEntry entry in pbFile.Files) { TreeNode entryNode = new TreeNode(entry.File.FileName); entryNode.Tag = entry.File; fileNode.Nodes.Add(entryNode); } } if (file.GetType() == typeof(BGFile)) { BGFile bgFile = (BGFile)file; foreach (BaseFile entry in bgFile.Files) { TreeNode entryNode = new TreeNode(entry.FileName); entryNode.Tag = entry; fileNode.Nodes.Add(entryNode); } } pknNode.Nodes.Add(fileNode); } } directoryNode.Nodes.Add(pknNode); } else { foreach (ConanImageFile file in ConanImage.Files) { if (Path.GetDirectoryName(file.FilePath) == directory) { TreeNode fileNode = new TreeNode(Path.GetFileName(file.FilePath)); fileNode.Tag = file; //fileNode.Tag = HeaderList.GetTypeFromFile(Path.Combine(_state.ProjectFile.ModifiedImage.RippedDirectory,file.FilePath)); //LAAAAG directoryNode.Nodes.Add(fileNode); } } } imageNode.Nodes.Add(directoryNode); } treeView1.Nodes.Add(imageNode); }
public static BMPInfo[] GetTextures(string filename) { if (!File.Exists(filename)) { return(null); } string ext = Path.GetExtension(filename).ToLowerInvariant(); switch (ext) { case ".pak": PAKFile pak = new PAKFile(filename); string filenoext = Path.GetFileNameWithoutExtension(filename).ToLowerInvariant(); byte[] inf = pak.Files.Single((file) => file.Name.Equals(filenoext + '\\' + filenoext + ".inf", StringComparison.OrdinalIgnoreCase)).Data; List <BMPInfo> newtextures = new List <BMPInfo>(inf.Length / 0x3C); for (int i = 0; i < inf.Length; i += 0x3C) { System.Text.StringBuilder sb = new System.Text.StringBuilder(0x1C); for (int j = 0; j < 0x1C; j++) { if (inf[i + j] != 0) { sb.Append((char)inf[i + j]); } else { break; } } byte[] dds = pak.Files.First((file) => file.Name.Equals(filenoext + '\\' + sb.ToString() + ".dds", StringComparison.OrdinalIgnoreCase)).Data; using (MemoryStream str = new MemoryStream(dds)) { uint check = BitConverter.ToUInt32(dds, 0); if (check == 0x20534444) // DDS header { PixelFormat pxformat; var image = Pfim.Pfim.FromStream(str, new Pfim.PfimConfig()); switch (image.Format) { case Pfim.ImageFormat.Rgba32: pxformat = PixelFormat.Format32bppArgb; break; default: System.Windows.Forms.MessageBox.Show("Unsupported image format."); throw new NotImplementedException(); } var bitmap = new Bitmap(image.Width, image.Height, pxformat); BitmapData bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, pxformat); System.Runtime.InteropServices.Marshal.Copy(image.Data, 0, bmpData.Scan0, image.DataLen); bitmap.UnlockBits(bmpData); newtextures.Add(new BMPInfo(sb.ToString(), bitmap)); } else { newtextures.Add(new BMPInfo(sb.ToString(), new Bitmap(str))); } } } return(newtextures.ToArray()); case ".pvmx": PVMXFile pvmx = new PVMXFile(File.ReadAllBytes(filename)); List <BMPInfo> textures = new List <BMPInfo>(); for (int i = 0; i < pvmx.GetCount(); i++) { var bmp = new Bitmap(new MemoryStream(pvmx.GetFile(i))); textures.Add(new BMPInfo(pvmx.GetNameWithoutExtension(i), bmp)); } return(textures.ToArray()); 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(entry[1], new System.Drawing.Bitmap(Path.Combine(Path.GetDirectoryName(filename), entry[1])))); } return(txts.ToArray()); case ".pb": PBFile pbdata = new PBFile(File.ReadAllBytes(filename)); List <BMPInfo> txtsp = new List <BMPInfo>(); for (int i = 0; i < pbdata.GetCount(); i++) { PvrTexture pvr = new PvrTexture(pbdata.GetPVR(i)); txtsp.Add(new BMPInfo(i.ToString("D3"), pvr.ToBitmap())); } return(txtsp.ToArray()); case ".pvm": case ".gvm": default: List <BMPInfo> functionReturnValue = new List <BMPInfo>(); bool gvm = false; ArchiveBase pvmfile = null; byte[] pvmdata = File.ReadAllBytes(filename); if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase)) { pvmdata = FraGag.Compression.Prs.Decompress(pvmdata); } pvmfile = new PvmArchive(); MemoryStream stream = new MemoryStream(pvmdata); if (!PvmArchive.Identify(stream)) { pvmfile = new GvmArchive(); gvm = true; } VrSharp.VpPalette pvp = null; ArchiveEntryCollection pvmentries = pvmfile.Open(pvmdata).Entries; foreach (ArchiveEntry file in pvmentries) { VrTexture vrfile = gvm ? (VrTexture) new GvrTexture(file.Open()) : (VrTexture) new PvrTexture(file.Open()); if (vrfile.NeedsExternalPalette) { using (System.Windows.Forms.OpenFileDialog a = new System.Windows.Forms.OpenFileDialog { DefaultExt = gvm ? "gvp" : "pvp", Filter = gvm ? "GVP Files|*.gvp" : "PVP Files|*.pvp", InitialDirectory = System.IO.Path.GetDirectoryName(filename), Title = "External palette file" }) { if (pvp == null) { if (a.ShowDialog() == System.Windows.Forms.DialogResult.OK) { pvp = gvm ? (VpPalette) new GvpPalette(a.FileName) : (VpPalette) new PvpPalette(a.FileName); } else { return(new BMPInfo[0]); } } } if (gvm) { ((GvrTexture)vrfile).SetPalette((GvpPalette)pvp); } else { ((PvrTexture)vrfile).SetPalette((PvpPalette)pvp); } } try { functionReturnValue.Add(new BMPInfo(Path.GetFileNameWithoutExtension(file.Name), vrfile.ToBitmap())); } catch { functionReturnValue.Add(new BMPInfo(Path.GetFileNameWithoutExtension(file.Name), new Bitmap(1, 1))); } } return(functionReturnValue.ToArray()); } }
/// <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!"); }