private void compressBtn_Click(object sender, EventArgs e) { if (openZIPDialog.ShowDialog() == DialogResult.OK) { YAZ0 y = new YAZ0(); NARC SzsArch = new NARC(); SFSDirectory dir = new SFSDirectory("", true); using (ZipFile z = ZipFile.Read(openZIPDialog.FileName)) { for (int i = 0; i < z.Entries.Count; i++) { ZipEntry ze = z.Entries.ToArray()[i]; SFSFile file = new SFSFile(i, ze.FileName, dir); MemoryStream data = new MemoryStream(); ze.Extract(data); file.Data = data.ToArray(); data.Dispose(); dir.Files.Add(file); } foreach (ZipEntry ze in z) { Console.WriteLine(ze); } } SzsArch.FromFileSystem(dir); if (saveSZSDialog.ShowDialog() == DialogResult.OK) { File.WriteAllBytes(saveSZSDialog.FileName, y.Compress(SzsArch.Write())); MessageBox.Show("Done!"); } } }
private void decompressBtn_Click(object sender, EventArgs e) { if (openSZSDialog.ShowDialog() == DialogResult.OK) { string of = openSZSDialog.FileName; if (IsYaz0(of)) { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { string ep = folderBrowserDialog1.SelectedPath; YAZ0 y = new YAZ0(); NARC f = new NARC(y.Decompress(File.ReadAllBytes(of))); foreach (SFSFile file in f.ToFileSystem().Files) { Console.WriteLine(file.FileName); File.WriteAllBytes(ep + "\\" + file.FileName, file.Data); } MessageBox.Show("Done!"); } } else { MessageBox.Show("The SZS file is not compressed with Yaz0."); } } }
public void Save() { NARC.FromFileSystem(Fs); var dec_data = NARC.Write(); var data = NSMBeROM.LZ77_Compress(dec_data); ROMUtils.ROM.WriteFile(Name, data); }
public MKDSEditor( NARC.DirectoryEntry Root1, NARC.DirectoryEntry Root2, NARC.DirectoryEntry RomRoot) { this.Root1 = Root1; this.Root2 = Root2; this.RomRoot = RomRoot; this.nkm = new MKDS_Course_Modifier.MKDS.NKM(Root1.GetFileByPath("\\course_map.nkm").Content); this.Main = NARC.Unpack(Compression.LZ77Decompress(RomRoot.GetFileByPath("\\data\\Main\\MapObj.carc").Content)); this.MainRace = NARC.Unpack(Compression.LZ77Decompress(RomRoot.GetFileByPath("\\data\\MainRace.carc").Content)); this.nsbmd = new MKDS_Course_Modifier.G3D_Binary_File_Format.NSBMD(Root1.GetFileByPath("\\course_model.nsbmd").Content); if (this.nsbmd.TexPlttSet == null) { try { this.nsbmd.TexPlttSet = new MKDS_Course_Modifier.G3D_Binary_File_Format.NSBTX(Root2.GetFileByPath("\\course_model.nsbtx").Content).TexPlttSet; } catch { } } if (Root1.GetFileByPath("\\course_model_V.nsbmd") != null) { this.nsbmd2 = new MKDS_Course_Modifier.G3D_Binary_File_Format.NSBMD(Root1.GetFileByPath("\\course_model_V.nsbmd").Content); if (this.nsbmd2.TexPlttSet == null) { this.nsbmd2.TexPlttSet = new MKDS_Course_Modifier.G3D_Binary_File_Format.NSBTX(Root2.GetFileByPath("\\course_model_V.nsbtx").Content).TexPlttSet; } } this.InitializeComponent(); if (Root1.GetDirectoryByPath("\\MissionRun") != null) { foreach (NARC.FileEntry file in Root1.GetDirectoryByPath("\\MissionRun").Files) { this.toolStripSplitButton1.DropDownItems.Add(file.Name, (Image)null, new EventHandler(this.NKMClick)); } } this.simpleOpenGlControl1.MouseWheel += new MouseEventHandler(this.simpleOpenGlControl1_MouseWheel); }
/// <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 NARCViewer(NARC Archive) { this.Archive = Archive; Root = Archive.ToFileSystem(); InitializeComponent(); }
private void listView1_ItemActivate(object sender, EventArgs e) { int num = (int)new MKDSEditor(NARC.Unpack(Compression.LZ77Decompress(this.Rom.Root.GetFileByPath("\\data\\Course\\" + this.listView1.SelectedItems[0].Text + ".carc").Content)), NARC.Unpack(Compression.LZ77Decompress(this.Rom.Root.GetFileByPath("\\data\\Course\\" + this.listView1.SelectedItems[0].Text + "Tex.carc").Content)), this.Rom.Root).ShowDialog(); }
public NARCViewer(NARC Archive) { this.Archive = Archive; Root = Archive.ToFileSystem(); InitializeComponent(); }
private static bool Open(ByteFileInfo file, Form1 Owner, object Parameter = null, bool filedialog = false) { switch (FileHandler.GetType(file)) { case "NARC": NARC.DirectoryEntry Root = NARC.Unpack(file.Data); if (FileHandler.OpenedArchives.Count != 0 && !FileHandler.OpenedArchives[0].FileName.EndsWith(".nds")) { FileHandler.OpenedArchives.RemoveAt(FileHandler.OpenedArchives.Count - 1); } Owner.OpenNarc(Root); return(true); case "NCGR": NCGR Graphic = new NCGR(file.Data); switch (FileHandler.OpenDialog) { case MKDS_Course_Modifier.UI.BNCL _: ((MKDS_Course_Modifier.UI.BNCL)FileHandler.OpenDialog).SetNCGR(Graphic); break; case MKDS_Course_Modifier.UI.NCER _: ((MKDS_Course_Modifier.UI.NCER)FileHandler.OpenDialog).SetNCGR(Graphic, FileHandler.OpenedFiles.Count); return(true); } return(false); case "NCLR": MKDS_Course_Modifier.G2D_Binary_File_Format.NCLR nclr = new MKDS_Course_Modifier.G2D_Binary_File_Format.NCLR(file.Data); switch (FileHandler.OpenDialog) { case null: FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.NCLR(nclr); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case MKDS_Course_Modifier.UI.BNCL _: ((MKDS_Course_Modifier.UI.BNCL)FileHandler.OpenDialog).SetNCLR(nclr); break; case MKDS_Course_Modifier.UI.NCER _: ((MKDS_Course_Modifier.UI.NCER)FileHandler.OpenDialog).SetNCLR(nclr); break; } return(false); case "NSCR": MKDS_Course_Modifier.G2D_Binary_File_Format.NSCR nscr = new MKDS_Course_Modifier.G2D_Binary_File_Format.NSCR(file.Data); return(false); case "NSBMD": MKDS_Course_Modifier.G3D_Binary_File_Format.NSBMD nsbmd = new MKDS_Course_Modifier.G3D_Binary_File_Format.NSBMD(file.Data); if (FileHandler.OpenDialog is MKDS_Course_Modifier.UI.NSBMD) { FileHandler.OpenedFiles.RemoveAt(FileHandler.OpenedFiles.Count - 1); ((MKDS_Course_Modifier.UI.NSBMD)FileHandler.OpenDialog).SetNSBMD(nsbmd); return(true); } if (FileHandler.OpenDialog != null) { return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.NSBMD(nsbmd); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "NSBTX": MKDS_Course_Modifier.G3D_Binary_File_Format.NSBTX Btx = new MKDS_Course_Modifier.G3D_Binary_File_Format.NSBTX(file.Data); if (FileHandler.OpenDialog is MKDS_Course_Modifier.UI.NSBMD) { ((MKDS_Course_Modifier.UI.NSBMD)FileHandler.OpenDialog).SetNSBTX(Btx); return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.NSBTX(Btx); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "NSBCA": NSBCA Bca1 = new NSBCA(file.Data); if (!(FileHandler.OpenDialog is MKDS_Course_Modifier.UI.NSBMD)) { return(false); } ((MKDS_Course_Modifier.UI.NSBMD)FileHandler.OpenDialog).SetNSBCA(Bca1); return(false); case "NSBTA": MKDS_Course_Modifier.G3D_Binary_File_Format.NSBTA nsbta = new MKDS_Course_Modifier.G3D_Binary_File_Format.NSBTA(file.Data); int num = (int)MessageBox.Show("Due to problems with texture matrices, is nsbta temporary disabled."); return(false); case "NSBMA": NSBMA Bma = new NSBMA(file.Data); if (!(FileHandler.OpenDialog is MKDS_Course_Modifier.UI.NSBMD)) { return(false); } ((MKDS_Course_Modifier.UI.NSBMD)FileHandler.OpenDialog).SetNSBMA(Bma); return(false); case "NSBVA": NSBVA Bva = new NSBVA(file.Data); if (!(FileHandler.OpenDialog is MKDS_Course_Modifier.UI.NSBMD)) { return(false); } ((MKDS_Course_Modifier.UI.NSBMD)FileHandler.OpenDialog).SetNSBVA(Bva); return(false); case "NSBTP": NSBTP Btp = new NSBTP(file.Data); if (!(FileHandler.OpenDialog is MKDS_Course_Modifier.UI.NSBMD)) { return(false); } ((MKDS_Course_Modifier.UI.NSBMD)FileHandler.OpenDialog).SetNSBTP(Btp); return(false); case "KCL": KCL KCL = new KCL(file.Data); if (FileHandler.OpenDialog is MKDS_Course_Modifier.UI.MKDS.NKM) { ((MKDS_Course_Modifier.UI.MKDS.NKM)FileHandler.OpenDialog).SetKCL(KCL); } return(false); case "MR": MKDS_Course_Modifier.MKDS.MR Mission = new MKDS_Course_Modifier.MKDS.MR(file.Data); if (FileHandler.OpenDialog != null) { return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.MKDS.MR(Mission); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "NKM": MKDS_Course_Modifier.MKDS.NKM File1 = new MKDS_Course_Modifier.MKDS.NKM(file.Data); if (FileHandler.OpenDialog != null) { return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.MKDS.NKM(File1); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "NCG.BIN": return(false); case "NCL.BIN": return(false); case "NSC.BIN": return(false); case "SPA": MKDS_Course_Modifier.Particles.SPA Spa = new MKDS_Course_Modifier.Particles.SPA(file.Data); if (FileHandler.OpenDialog != null) { return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.SPA(Spa); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "SSEQ": MKDS_Course_Modifier.Sound.SSEQ file1 = new MKDS_Course_Modifier.Sound.SSEQ(file.Data); if (FileHandler.OpenDialog != null) { return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.SSEQ(file1, FileHandler.m); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "SBNK": SBNK k = new SBNK(file.Data); if (FileHandler.OpenDialog != null && FileHandler.OpenDialog is MKDS_Course_Modifier.UI.SSEQ) { SBNK s = SBNK.InitDLS(k, (SWAR[])Parameter); ((MKDS_Course_Modifier.UI.SSEQ)FileHandler.OpenDialog).SetDLS(SBNK.ToDLS(s)); } return(false); case "SDAT": SDAT SDAT = new SDAT(file.Data); Owner.OpenSDAT(SDAT); return(true); case "SSAR": MKDS_Course_Modifier.Sound.SSEQ file2 = new MKDS_Course_Modifier.Sound.SSEQ(file.Data, (int)Parameter); if (FileHandler.OpenDialog != null) { return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.SSEQ(file2, FileHandler.m); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "NDS": NDS Rom = new NDS(file.Data); FileHandler.OpenedArchives.Clear(); Owner.OpenNDS(Rom); return(true); case "NCER": MKDS_Course_Modifier.G2D_Binary_File_Format.NCER Cell = new MKDS_Course_Modifier.G2D_Binary_File_Format.NCER(file.Data); if (FileHandler.OpenDialog == null) { FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.NCER(Cell); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); } if (FileHandler.OpenDialog is MKDS_Course_Modifier.UI.BNCL) { ((MKDS_Course_Modifier.UI.BNCL)FileHandler.OpenDialog).SetNCER(Cell); } return(false); case "BMG": MKDS_Course_Modifier.Misc.BMG File2 = new MKDS_Course_Modifier.Misc.BMG(file.Data); if (FileHandler.OpenDialog != null) { return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.BMG(File2); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "SM64BMD": MKDS_Course_Modifier.SM64DS.BMD bmd = new MKDS_Course_Modifier.SM64DS.BMD(file.Data); if (FileHandler.OpenDialog is MKDS_Course_Modifier.UI.BMD) { ((MKDS_Course_Modifier.UI.BMD)FileHandler.OpenDialog).SetBMD(bmd); return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.BMD(bmd); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "SM64BCA": MKDS_Course_Modifier.SM64DS.BCA Bca2 = new MKDS_Course_Modifier.SM64DS.BCA(file.Data); if (!(FileHandler.OpenDialog is MKDS_Course_Modifier.UI.BMD)) { return(false); } ((MKDS_Course_Modifier.UI.BMD)FileHandler.OpenDialog).SetBCA(Bca2); return(true); case "BNCL": MKDS_Course_Modifier.Misc.BNCL Bncl = new MKDS_Course_Modifier.Misc.BNCL(file.Data); if (FileHandler.OpenDialog != null) { return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.BNCL(Bncl); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "GCNBMD": MKDS_Course_Modifier.GCN.BMD file3 = new MKDS_Course_Modifier.GCN.BMD(file.Data); if (FileHandler.OpenDialog != null) { return(false); } FileHandler.OpenDialog = (Form) new J3D1(file3); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "HBDF": HBDF hbdf = new HBDF(file.Data); if (hbdf.MDLFBlocks.Length > 0) { if (FileHandler.OpenDialog is MDLF) { ((MDLF)FileHandler.OpenDialog).SetHBDF(hbdf); } else { FileHandler.OpenDialog = (Form) new MDLF(hbdf); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); } } return(false); case "GCNBOL": BOL bol = new BOL(file.Data); return(false); case "PAZ": PAZ Arc = new PAZ(file.Data); Owner.OpenPAZ(Arc); return(true); case "TEX": TEX tex = new TEX(file.Data); return(false); case "GRPCONF": Grpconf grpconf = new Grpconf(file.Data); return(false); case "OBJ": MKDS_Course_Modifier._3D_Formats.OBJ obj = new MKDS_Course_Modifier._3D_Formats.OBJ(file.Path); if (FileHandler.OpenDialog != null) { return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.OBJ(obj, obj.MLTName == null ? (MLT)null : new MLT(obj.MLTName)); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "GCNBLO": MKDS_Course_Modifier.GCN.BLO Layout = new MKDS_Course_Modifier.GCN.BLO(file.Data, file.Path); if (FileHandler.OpenDialog != null) { return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.BLO(Layout); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "3DSCGFX": MKDS_Course_Modifier._3DS.CGFX cgfx = new MKDS_Course_Modifier._3DS.CGFX(file.Data); if (FileHandler.OpenDialog != null) { return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.CGFX(cgfx); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); case "FMVVideo": MKDS_Course_Modifier.Misc.FMV Video = new MKDS_Course_Modifier.Misc.FMV(file.Data); if (FileHandler.OpenDialog != null) { return(false); } FileHandler.OpenDialog = (Form) new MKDS_Course_Modifier.UI.FMV(Video); FileHandler.OpenDialog.Show((IWin32Window)Owner); FileHandler.OpenDialog.FormClosed += new FormClosedEventHandler(FileHandler.OpenDialog_FormClosed); return(true); default: return(false); } }
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = (BackgroundWorker)sender; worker.ReportProgress(0, new Tuple <int, string, int, int>(0, "Reading System Files", 0, 0)); string fsPath = path + "\\" + "File System"; try { Directory.CreateDirectory(fsPath); } catch (Exception exception) { DialogResult dialog = CustomMessageBox.Show( exception.Message, exception.GetType().ToString(), 400, new List <string>(), new List <DialogResult>()); return; } if (worker.CancellationPending) { e.Cancel = true; return; } File.Copy(file, path + "\\" + "[" + code + "] " + title + ".nds"); using (MemoryStream romStream = new MemoryStream(File.ReadAllBytes(file))) { using (BinaryReader romReader = new BinaryReader(romStream)) { romReader.BaseStream.Position = 32; int arm9Offset = Convert.ToInt32(romReader.ReadUInt32()); romReader.BaseStream.Position = 44; int arm9Length = Convert.ToInt32(romReader.ReadUInt32()); int arm7Offset = Convert.ToInt32(romReader.ReadUInt32()); romReader.BaseStream.Position = 60; int arm7Length = Convert.ToInt32(romReader.ReadUInt32()); int fntOffset = Convert.ToInt32(romReader.ReadUInt32()); int fntLength = Convert.ToInt32(romReader.ReadUInt32()); int fatOffset = Convert.ToInt32(romReader.ReadUInt32()); int fatLength = Convert.ToInt32(romReader.ReadUInt32()); int oat9Offset = Convert.ToInt32(romReader.ReadUInt32()); int oat9Length = Convert.ToInt32(romReader.ReadUInt32()); int oat7Offset = Convert.ToInt32(romReader.ReadUInt32()); int oat7Length = Convert.ToInt32(romReader.ReadUInt32()); romReader.BaseStream.Position = 104; int bnrOffset = Convert.ToInt32(romReader.ReadUInt32()); romReader.BaseStream.Position = bnrOffset; int bnrLength = Convert.ToInt32(romReader.ReadUInt16()); switch (bnrLength) { case 1: bnrLength = 2112; break; case 2: bnrLength = 2112; break; case 3: bnrLength = 3072; break; case 259: bnrLength = 9216; break; } byte[] fntArray = new byte[fntLength]; byte[] fatArray = new byte[fatLength]; romReader.BaseStream.Position = fntOffset; romReader.Read(fntArray, 0, fntLength); romReader.BaseStream.Position = fatOffset; romReader.Read(fatArray, 0, fatLength); if (fatArray.Count() % 8 > 0) { // Exception handling for rewrite later. throw new Exception( "Table length must be a multiple of 8. This table has a length of " + fatArray.Count() + "." + "\n " + fatArray.Count() + " ÷ 8 = " + (fatArray.Count() / 8) + "\n Remainder: " + (fatArray.Count() % 8) ); } List <NDSFile> fileList = new List <NDSFile>(); fileList.Add(new NDSFile("Header", "", "", 0, 16384)); fileList.Add(new NDSFile("File Name Table", "", "", fntOffset, fntLength)); fileList.Add(new NDSFile("File Allocation Table", "", "", fatOffset, fatLength)); fileList.Add(new NDSFile("Banner", "", ".bnr", bnrOffset, bnrLength)); fileList.Add(new NDSFile("ARM9 Binary", "", ".bin", arm9Offset, arm9Length)); fileList.Add(new NDSFile("ARM9 Overlay Table", "", "", oat9Offset, oat9Length)); if (arm7Length > 0) { fileList.Add(new NDSFile("ARM7 Binary", "", ".bin", arm7Offset, arm9Length)); } if (oat7Length > 0) { fileList.Add(new NDSFile("ARM7 Overlay Table", "", "", oat7Offset, oat9Length)); } int directoryCount = BitConverter.ToUInt16(fntArray, 6); int firstFile = BitConverter.ToInt16(fntArray, 4); int fileCount = fatArray.Count() / 8; int workload = (fileCount * 4) + (directoryCount * 2); int progress = 0; worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress, "Reading File Name And Allocation Tables", fileCount, 0)); NDSFile[] files = new NDSFile[fileCount]; for (int i = 0; i < fileCount; i++) { if (worker.CancellationPending) { e.Cancel = true; return; } files[i] = new NDSFile(); NDSFile currentFile = files[i]; files[i].Offset = Convert.ToInt32(BitConverter.ToUInt32(fatArray, i * 8)); files[i].Length = Convert.ToInt32(BitConverter.ToUInt32(fatArray, i * 8 + 4)) - files[i].Offset; progress++; worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress, "Reading File Allocation Table", fileCount, i + 1)); } worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress, "Reading Overlay Allocation Table", firstFile, 0)); string[] directories; List <string> dirList = new List <string>(); directories = new string[directoryCount]; if (firstFile > 0) { directories[0] = "\\Root"; dirList.Add("\\Overlays"); for (int i = 0; i < firstFile; i++) { if (worker.CancellationPending) { e.Cancel = true; return; } files[i].Name = "Overlay " + i.ToString("D" + firstFile.ToString().Length) + ".bin"; files[i].Path = "\\Overlays"; progress++; worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress, "Reading Overlay Allocation Table", firstFile, i + 1)); } } else { directories[0] = ""; } worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress, "Reading File Name Table", fileCount + directoryCount, 0)); int unnamedCount = 0; int dirProgress = 0; int fileProgress = 0; for (int i = 0; i < directoryCount; i++) { int entryPos = Convert.ToInt32(BitConverter.ToUInt32(fntArray, i * 8)); int fileIndex = Convert.ToInt32(BitConverter.ToUInt16(fntArray, (i * 8) + 4)); while (true) { if (worker.CancellationPending) { e.Cancel = true; return; } byte entryByte = fntArray[entryPos++]; if (entryByte == 0) { break; } else if (entryByte == 128) { int index = BitConverter.ToUInt16(fntArray, entryPos) - 61440; directories[index] = directories[i] + "\\Unnamed " + unnamedCount++; dirProgress++; entryPos += 2; } else if (entryByte > 128) { int index = BitConverter.ToUInt16(fntArray, (entryPos) + (entryByte - 128)) - 61440; directories[index] = directories[i] + "\\" + System.Text.Encoding.UTF8.GetString(fntArray, entryPos, entryByte - 128); dirProgress++; entryPos += (entryByte - 128) + 2; } else { files[fileIndex].Name = System.Text.Encoding.UTF8.GetString(fntArray, entryPos, entryByte); files[fileIndex].Path = directories[i]; fileIndex++; fileProgress++; entryPos += entryByte; } progress++; worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress, "Reading File Name Table", fileCount + directoryCount, dirProgress + fileProgress)); } } worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress, "Getting File Extensions", fileCount, 0)); fileList.AddRange(files.ToList()); dirList.AddRange(directories.ToList()); files = null; directories = null; List <NDSFile> narcList = new List <NDSFile>(); for (int i = 0; i < fileCount; i++) { if (worker.CancellationPending) { e.Cancel = true; return; } NDSFile file = fileList[i]; file.GetExtension(romStream); if (file.Extension == ".narc") { narcList.Add(file); workload++; } progress++; worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress, "Getting File Extensions", fileCount, i + 1)); } worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress, "Reading NARC Files", directoryCount, 0)); if (narcList.Count > 0) { for (int i = 0; i < narcList.Count; i++) { if (worker.CancellationPending) { e.Cancel = true; return; } NDSFile file = narcList[i]; NARC narc = new NARC(romStream, file); if (narc.isValid) { fileList.Remove(file); dirList.AddRange(narc.dirList); fileList.AddRange(narc.fileList); } progress++; worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress, "Reading NARC Files", narcList.Count, i + 1)); } } worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress, "Writing Folder Structure", directoryCount, 0)); double compWorkload = directoryCount / dirList.Count; for (int i = 0; i < dirList.Count; i++) { if (worker.CancellationPending) { e.Cancel = true; return; } Directory.CreateDirectory(fsPath + dirList[i]); int p = Convert.ToInt32((i + 1) * compWorkload); worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress + p, "Writing Folder Structure", directoryCount, (int)((i + 1) * compWorkload))); } progress += directoryCount; worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress, "Extracting Files", fileList.Count, 0)); compWorkload = (double)fileCount / (double)fileList.Count; for (int i = 0; i < fileList.Count; i++) { if (worker.CancellationPending) { e.Cancel = true; return; } NDSFile file = fileList[i]; romReader.BaseStream.Position = file.Offset; byte[] image = new byte[file.Length]; romReader.Read(image, 0, file.Length); Directory.CreateDirectory(path + "\\Text Files"); if (file.Path == "\\Root\\a\\0\\2\\7.narc") { PokeTextIV TextFile = new PokeTextIV(romStream, file); System.IO.File.WriteAllLines(path + "\\Text Files\\" + file.Name + ".txt", TextFile.StringList); } /* * using ( BinaryWriter writer = new BinaryWriter(File.Open(fsPath + file.Path + "\\" + file.Name + file.Extension, FileMode.Create)) ) * { * writer.Write(image, 0, file.Length); * } */ int p = Convert.ToInt32((i + 1) * compWorkload); worker.ReportProgress(workload, new Tuple <int, string, int, int>(progress + p, "Extracting Files", fileList.Count, (i + 1))); } } } }
public void Load() { if (ComboIndex < 0) { LanguageCombo.SelectedIndex = 0; } var rfs = MainWindow.LoadedROM.ToFileSystem(); string ext = GetCARCExtension(LanguageCombo.SelectedIndex); var cbmain2d = ROMUtils.GetFile("Main2D" + ext + ".carc", rfs); var bmain2d = ROM.LZ77_Decompress(cbmain2d); Main2D = new NARC(bmain2d); var dmain2d = Main2D.ToFileSystem(); var common = ROMUtils.GetFile("common.bmg", dmain2d); Common = new BMG(common); var cbstatic2d = ROMUtils.GetFile("Static2D.carc", rfs); var bstatic2d = ROM.LZ77_Decompress(cbstatic2d); Static2D = new NARC(bstatic2d); var dstatic2d = Static2D.ToFileSystem(); var mbchild = ROMUtils.GetFile("MBChild" + ext + ".bmg", dstatic2d); MBChild = new BMG(mbchild); var cbchksel = ROMUtils.GetFile("CharacterKartSelect" + ext + ".carc", rfs); var bchksel = ROM.LZ77_Decompress(cbchksel); CharacterKartSelect = new NARC(bchksel); var dchksel = CharacterKartSelect.ToFileSystem(); var ksel = ROMUtils.GetFile("kart_select.bmg", dchksel); KartSelect = new BMG(ksel); var cbwlmenu = ROMUtils.GetFile("WLMenu" + ext + ".carc", rfs); var bwlmenu = ROM.LZ77_Decompress(cbwlmenu); WLMenu = new NARC(bwlmenu); var dwlmenu = WLMenu.ToFileSystem(); var banner = ROMUtils.GetFile("banner.bmg", dwlmenu); Banner = new BMG(banner); CommonTextsList.Items.Clear(); MBChildTextsList.Items.Clear(); KartSelectTextsList.Items.Clear(); DlPlayTextsList.Items.Clear(); foreach (var str in Common.DAT1.Strings) { CommonTextsList.Items.Add(new TextBox() { TextWrapping = TextWrapping.Wrap, AcceptsReturn = true, Text = str, }); } foreach (var str in MBChild.DAT1.Strings) { MBChildTextsList.Items.Add(new TextBox() { TextWrapping = TextWrapping.Wrap, AcceptsReturn = true, Text = str, }); } foreach (var str in KartSelect.DAT1.Strings) { KartSelectTextsList.Items.Add(new TextBox() { TextWrapping = TextWrapping.Wrap, AcceptsReturn = true, Text = str, }); } foreach (var str in Banner.DAT1.Strings) { DlPlayTextsList.Items.Add(new TextBox() { TextWrapping = TextWrapping.Wrap, AcceptsReturn = true, Text = str, }); } }