public LoadResult Load(string filename) { LoadResult result = LoadResult.Success; _fileInfo = new FileInfo(filename); if (_fileInfo.Exists) { _darc = new DARC(_fileInfo.FullName); } else { result = LoadResult.FileNotFound; } return(result); }
/// <summary> /// Process data in an input file that contains a layout. /// </summary> /// <param name="filename"></param> bool ProcessData(string filename, byte[] inData) { EndianBinaryReader reader = null; // now we need to decide what they just opened if (inData == null && filename != "") { reader = new EndianBinaryReader(File.Open(filename, FileMode.Open), Encoding.GetEncoding(932)); } else { reader = new EndianBinaryReader(inData); } string magic = ""; // we have a Yaz0 compressed file if (reader.ReadStringFrom(0, 4) == "Yaz0") { // we have to close our reader so we can properly read this file as a Yaz0 stream reader.Close(); MemoryStream ms = null; if (inData == null) { ms = new Yaz0(File.Open(filename, FileMode.Open)); } else { ms = new Yaz0(new MemoryStream(inData)); } reader = new EndianBinaryReader(ms); magic = reader.ReadStringFrom(0, 4); } // we have a LZ compressed file else if (reader.ReadByteFrom(0) == 0x11) { LZ77 lzFile = new LZ77(ref reader); byte[] lzData = lzFile.getData(); // close our current reader to open a new one with our input data reader.Close(); reader = new EndianBinaryReader(lzData); magic = reader.ReadStringFrom(0, 4); } // no compression else { // it is not yaz0 compressed, so we see the magic magic = reader.ReadStringFrom(0, 4); } // now we have to check our magic to see what kind of file it is switch (magic) { case "darc": mArchive = new DARC(ref reader); break; case "NARC": mArchive = new NARC(ref reader); break; case "SARC": mArchive = new SARC(ref reader); break; case "RARC": reader.SetEndianess(Endianess.Big); mArchive = new RARC(ref reader); break; case "U?8-": reader.SetEndianess(Endianess.Big); mArchive = new U8(ref reader); break; default: MessageBox.Show("Error. Unsupported format with magic: " + magic); break; } string layoutType = ""; // some files have their string table nullified, which makes the names obfuscated // I've only seen this in SARCs from MK7, but there's probably more if (mArchive != null) { if (mArchive.isStringTableObfuscated()) { MessageBox.Show("This file has obfuscated file names. The editor attempted to find layout files, but cannot supply names."); } } reader.Close(); if (mArchive == null) { MessageBox.Show("Format not supported."); return(false); } // the only familiar format with archives in archives is SARC and RARC if (mArchive.getType() == ArchiveType.SARC || mArchive.getType() == ArchiveType.RARC) { List <string> names = mArchive.getArchiveFileNames(); if (names.Count != 0) { DialogResult res = MessageBox.Show("This archive has another archive inside of it.\nDo you wish to choose one of the found archives to select a layout?", "Internal Archive", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { LayoutChooser archiveChooser = new LayoutChooser(); archiveChooser.insertEntries(names); archiveChooser.ShowDialog(); // if this worked, we dont need to do anything bool result = ProcessData(archiveChooser.getSelectedFile(), mArchive.getDataByName(archiveChooser.getSelectedFile())); if (result) { return(true); } else { MessageBox.Show("Failed to get the internal file."); return(false); } } } } // get all of our needed files mLayoutFiles = mArchive.getLayoutFiles(); mLayoutAnimFiles = mArchive.getLayoutAnimations(); mLayoutImages = mArchive.getLayoutImages(); mLayoutControls = mArchive.getLayoutControls(); if (mLayoutFiles.Count == 0) { MessageBox.Show("This file contains no layouts."); return(false); } LayoutChooser layoutChooser = new LayoutChooser(); layoutChooser.insertEntries(new List <string>(mLayoutFiles.Keys)); layoutChooser.ShowDialog(); string selectedFile = layoutChooser.getSelectedFile(); if (selectedFile == null) { return(false); } string[] sections = selectedFile.Split('/'); mMainRoot = ""; // remove "lyt" part and the file name // this will be our main root of the entire opened file for (int i = 0; i < sections.Length - 2; i++) { mMainRoot += sections[i] + "/"; } if (layoutType == "") { layoutType = Path.GetExtension(selectedFile); } // now we have to init a layout reader EndianBinaryReader layoutReader = null; byte[] data; switch (layoutType) { case ".brlyt": data = mLayoutFiles[selectedFile]; layoutReader = new EndianBinaryReader(data); mMainLayout = new BRLYT(ref layoutReader); layoutReader.Close(); break; case ".bclyt": data = mLayoutFiles[selectedFile]; layoutReader = new EndianBinaryReader(data); mMainLayout = new BCLYT(ref layoutReader); break; case ".bflyt": data = mLayoutFiles[selectedFile]; layoutReader = new EndianBinaryReader(data); mMainLayout = new BFLYT(ref layoutReader); break; case ".blo": data = mLayoutFiles[selectedFile]; layoutReader = new EndianBinaryReader(data); if (layoutReader.ReadStringFrom(4, 4) == "blo1") { mMainLayout = new BLO1(ref layoutReader); } else { mMainLayout = new BLO2(ref layoutReader); } break; default: MessageBox.Show("This format is not supported yet."); break; } layoutReader.Close(); if (mMainLayout == null) { return(false); } // set our propertygrid with our LYT object mainPropertyGrid.SelectedObject = mMainLayout.getLayoutParams(); if (mMainLayout.getRootPanel() == null) { MessageBox.Show("Error, the root pane in this layout is not specified."); return(false); } LayoutBase pane = null; LayoutBase group = null; // now we have to grab our root panel, which is different on each console // so we have to specifically get the one we want // the same applies to our root group pane = mMainLayout.getRootPanel(); // this should be RootPane TreeNode n1 = new TreeNode { Tag = pane, Name = pane.mName, Text = pane.mName, }; panelList.Nodes.Add(n1); fillNodes(pane.getChildren()); // now for our groups group = mMainLayout.getRootGroup(); if (group != null) { TreeNode n1_1 = new TreeNode { Tag = group, Name = group.mName, Text = group.mName, }; panelList.Nodes.Add(n1_1); fillNodes(group.getChildren()); } // now for textures and fonts // but it is possible for either one to not exist if (mMainLayout.containsTextures()) { foreach (string str in mMainLayout.getTextureNames()) { texturesList.Items.Add(str); } } if (mMainLayout.containsFonts()) { foreach (string str in mMainLayout.getFontNames()) { fontsList.Items.Add(str); } } // and our materials if (mMainLayout.containsMaterials()) { foreach (string str in mMainLayout.getMaterialNames()) { materialList.Items.Add(str); } } // this draws the border of the layout mMainLayout.draw(); layoutViewer.Refresh(); return(true); }
public static file load(Stream data) { //Too small if (data.Length < 0x10) { data.Close(); return(new file { type = formatType.unsupported }); } BinaryReader input = new BinaryReader(data); uint magic, length; switch (peek(input)) { case 0x00010000: return(new file { data = GfModel.load(data), type = formatType.model }); case 0x00060000: return(new file { data = GfMotion.loadAnim(input), type = formatType.anims }); case 0x15041213: return(new file { data = GfTexture.load(data), type = formatType.image }); case 0x15122117: RenderBase.OModelGroup mdls = new RenderBase.OModelGroup(); mdls.model.Add(GfModel.loadModel(data)); return(new file { data = mdls, type = formatType.model }); } switch (getMagic(input, 5)) { case "MODEL": return(new file { data = DQVIIPack.load(data), type = formatType.container }); } switch (getMagic(input, 4)) { case "CGFX": return(new file { data = CGFX.load(data), type = formatType.model }); case "CRAG": return(new file { data = GARC.load(data), type = formatType.container }); case "darc": return(new file { data = DARC.load(data), type = formatType.container }); case "FPT0": return(new file { data = FPT0.load(data), type = formatType.container }); case "IECP": magic = input.ReadUInt32(); length = input.ReadUInt32(); return(load(new MemoryStream(LZSS.decompress(data, length)))); case "NLK2": data.Seek(0x80, SeekOrigin.Begin); return(new file { data = CGFX.load(data), type = formatType.model }); case "SARC": return(new file { data = SARC.load(data), type = formatType.container }); case "SMES": return(new file { data = NLP.loadMesh(data), type = formatType.model }); case "Yaz0": magic = input.ReadUInt32(); length = IOUtils.endianSwap(input.ReadUInt32()); data.Seek(8, SeekOrigin.Current); return(load(new MemoryStream(Yaz0.decompress(data, length)))); case "zmdl": return(new file { data = ZMDL.load(data), type = formatType.model }); case "ztex": return(new file { data = ZTEX.load(data), type = formatType.texture }); } //Check if is a BCLIM or BFLIM file (header on the end) if (data.Length > 0x28) { data.Seek(-0x28, SeekOrigin.End); string clim = IOUtils.readStringWithLength(input, 4); if (clim == "CLIM" || clim == "FLIM") { return new file { data = BCLIM.load(data), type = formatType.image } } ; } switch (getMagic(input, 3)) { case "BCH": byte[] buffer = new byte[data.Length]; input.Read(buffer, 0, buffer.Length); data.Close(); return(new file { data = BCH.load(new MemoryStream(buffer)), type = formatType.model }); case "DMP": return(new file { data = DMP.load(data), type = formatType.image }); } string magic2b = getMagic(input, 2); switch (magic2b) { case "AD": return(new file { data = AD.load(data), type = formatType.model }); case "BM": return(new file { data = MM.load(data), type = formatType.model }); case "BS": return(new file { data = BS.load(data), type = formatType.anims }); case "CM": return(new file { data = CM.load(data), type = formatType.model }); case "CP": return(new file { data = CP.load(data), type = formatType.model }); case "GR": return(new file { data = GR.load(data), type = formatType.model }); case "MM": return(new file { data = MM.load(data), type = formatType.model }); case "PC": return(new file { data = PC.load(data), type = formatType.model }); case "PT": return(new file { data = PT.load(data), type = formatType.texture }); } if (magic2b.Length == 2) { if ((magic2b[0] >= 'A' && magic2b[0] <= 'Z') && (magic2b[1] >= 'A' && magic2b[1] <= 'Z')) { return(new file { data = PkmnContainer.load(data), type = formatType.container }); } } //Compressions data.Seek(0, SeekOrigin.Begin); uint cmp = input.ReadUInt32(); if ((cmp & 0xff) == 0x13) { cmp = input.ReadUInt32(); } switch (cmp & 0xff) { case 0x11: return(load(new MemoryStream(LZSS_Ninty.decompress(data, cmp >> 8)))); case 0x90: byte[] buffer = BLZ.decompress(data); byte[] newData = new byte[buffer.Length - 1]; Buffer.BlockCopy(buffer, 1, newData, 0, newData.Length); return(load(new MemoryStream(newData))); } data.Close(); return(new file { type = formatType.unsupported }); }
public DARCViewer(DARC Archive) { Root = Archive.ToFileSystem(); InitializeComponent(); }