public static void gotSection(File f, int offs, int size) { uint magic = f.getUintAt(offs); if (magic == 0x504C5454) //PLTT new PaletteViewer(new InlineFile(f, offs + 0x18, size - 0x18, f.name)).Show(); else if (magic == 0x43484152) //CHAR { LevelChooser.showImgMgr(); int tileWidth = f.getUshortAt(offs + 0xA); if (tileWidth == 0xFFFF) tileWidth = 8; LevelChooser.imgMgr.m.addImage(new Image2D(new InlineFile(f, offs + 0x20, size - 0x20, f.name), 8*tileWidth, true, false)); } else if (magic == 0x5343524E) //SCRN { if (LevelChooser.imgMgr == null) return; Image2D img = LevelChooser.imgMgr.m.getSelectedImage(); Palette[] pals = LevelChooser.imgMgr.m.getPalettes(); if (img == null) return; if (pals == null) return; if (pals.Length == 0) return; InlineFile ff = new InlineFile(f, offs + 0x14, size - 0x14, f.name); Tilemap t = new Tilemap(ff, 32, img, pals, 0, 0); new TilemapEditorWindow(t).Show(); } else Console.WriteLine(String.Format("Unknown magic: {0:X8}", magic)); }
public void beginEditInline(InlineFile f) { if (inlineEditors.Count == 0) { beginEdit(this); } inlineEditors.Add(f); }
public Image3D(InlineFile f, bool color0, int width, int height, int format, long offset2) { this.f = f; this.color0Transp = color0; this.color0 = color0; this.width = width; this.height = height; this.format = format; offset = offset2; f.beginEdit(this); data = f.getContents(); }
public void endEditInline(InlineFile f) { if (!inlineEditors.Contains(f)) { throw new Exception("ERROR: INLINE FILE"); } inlineEditors.Remove(f); if (inlineEditors.Count == 0) { endEdit(this); } }
public Image3Dformat5(InlineFile f, InlineFile f5, int width, int height) { this.f = f; this.f5 = f5; f.beginEdit(this); f5.beginEdit(this); this.width = width; this.height = height; offset = f.fileBegin; offset5 = f5.fileBegin; fdata = f.getContents(); f5data = f5.getContents(); format = 5; }
ushort unk; //Let's save it just in case. public Bncd(File f) { ByteArrayInputStream inp = new ByteArrayInputStream(f.getContents()); inp.readInt(); //Magic; unk = inp.readUShort(); ushort entryCount = inp.readUShort(); uint entriesOffset = inp.readUInt(); uint subEntriesOffset = inp.readUInt(); uint dataOffset = inp.readUInt(); uint dataSize = inp.readUInt(); inp.seek(entriesOffset); //Stores tilenum, tilecount to imageid Dictionary<uint, int> imagesDict = new Dictionary<uint, int> (); for(uint entryId = 0; entryId < entryCount; entryId++) { BncdEntry e = new BncdEntry(); e.width = inp.readByte(); e.height = inp.readByte(); uint subEntryIdx = inp.readUShort(); uint subEntryCt = inp.readUShort(); inp.savePos(); inp.seek(subEntriesOffset + subEntryIdx*12); for(int i = 0; i < subEntryCt; i++) { BncdSubEntry se = new BncdSubEntry(); e.subEntries.Add(se); se.oamAttr0 = inp.readUShort(); se.oamAttr1 = inp.readUShort(); se.unk = inp.readUInt(); se.tileNumber = inp.readUShort(); se.tileCount = inp.readUShort(); uint imageCode = (uint) ((se.tileNumber << 16) | se.tileCount); int imageId = imagesDict.Count; if(imagesDict.ContainsKey(imageCode)) imageId = imagesDict[imageCode]; else { imagesDict[imageCode] = imageId; BncdImage img = new BncdImage(); images.Add(img); img.tileNumber = se.tileNumber; img.tileCount = se.tileCount; int oamShape = se.oamAttr0>>14; int oamSize = se.oamAttr1>>14; img.tileWidth = widths[oamSize, oamShape]; } se.imageId = imageId; } inp.loadPos(); } LevelChooser.showImgMgr(); int tileLen = 8*8/2; foreach(BncdImage img in images) { File imgFile = new InlineFile(f, (int)dataOffset+img.tileNumber*tileLen, img.tileCount*tileLen, f.name); LevelChooser.imgMgr.m.addImage(new Image2D(imgFile, 8*img.tileWidth, true, false)); } }
private void addPalette(int i) { int palSize = 256; if (is4bpp.Checked) palSize = 16; int palOffs = i * palSize; int palLen = palSize; if (palOffs + palLen > pal.Length) palLen = pal.Length - palOffs; File ifl = new InlineFile(f, palOffs * 2, palLen * 2, f.name + " - "+i); LevelChooser.showImgMgr(); LevelChooser.imgMgr.m.addPalette(new FilePalette(ifl)); }
private void fileTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Node.Tag is Directory) { e.Node.Expand(); return; } File f = e.Node.Tag as File; String filename = f.name; filename = filename.ToLowerInvariant(); try { if (filename == "banner.bin") { LevelChooser.showImgMgr(); File imgFile = new InlineFile(f, 0x20, 0x200, f.name); File palFile = new InlineFile(f, 0x220, 0x20, f.name); LevelChooser.imgMgr.m.addImage(new Image2D(imgFile, 32, true, false)); LevelChooser.imgMgr.m.addPalette(new FilePalette(palFile)); } else if (filename.EndsWith(".enpg")) { LevelChooser.showImgMgr(); LZFile fileLz = new LZFile(f, LZFile.CompressionType.LZ); File imgFile = new InlineFile(fileLz, 0, 0x10000, f.name); File palFile = new InlineFile(fileLz, 0x10000, 0x200, f.name); LevelChooser.imgMgr.m.addImage(new EnpgImage2D(imgFile)); LevelChooser.imgMgr.m.addPalette(new FilePalette(palFile)); } else if (filename.EndsWith(".bncd")) { new Bncd(f); } if (filename.EndsWith(".nsbtx") || filename.EndsWith(".nsbmd")) { new NSBTX(f); } else if (filename.EndsWith(".nscr") || filename.EndsWith(".ncgr") || filename.EndsWith(".nclr")) { SectionFileLoader.load(f); } else if (filename.EndsWith(".narc")) { new FilesystemBrowserDialog(new NarcFilesystem(f)).Show(); } else if (filename.EndsWith(".carc")) { new FilesystemBrowserDialog(new NarcFilesystem(f, true)).Show(); } else if (filename.Contains("_ncl.bin")) { new PaletteViewer(new LZFile(f, LZFile.CompressionType.MaybeLZ)).Show(); } else if (filename.Contains("_nsc.bin")) { if (LevelChooser.imgMgr == null) { return; } Image2D img = LevelChooser.imgMgr.m.getSelectedImage(); Palette[] pals = LevelChooser.imgMgr.m.getPalettes(); if (img == null) { return; } if (pals == null) { return; } if (pals.Length == 0) { return; } Tilemap t = new Tilemap(f, 32, img, pals, 0, 0); new TilemapEditorWindow(t).Show(); } else if (filename.Contains("_ncg.bin")) { LevelChooser.showImgMgr(); LevelChooser.imgMgr.m.addImage(new Image2D(f, 256, false)); } } catch (AlreadyEditingException ex) { MessageBox.Show(this, (LanguageManager.Get("Errors", "File"))); } }
private void fileTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Node.Tag is Directory) { e.Node.Expand(); return; } File f = e.Node.Tag as File; String filename = f.name; filename = filename.ToLowerInvariant(); try { if (filename == "banner.bin") { LevelChooser.showImgMgr(); File imgFile = new InlineFile(f, 0x20, 0x200, f.name); File palFile = new InlineFile(f, 0x220, 0x20, f.name); LevelChooser.imgMgr.m.addImage(new Image2D(imgFile, 32, true, false)); LevelChooser.imgMgr.m.addPalette(new FilePalette(palFile)); } else if (filename.EndsWith(".enpg")) { LevelChooser.showImgMgr(); LZFile fileLz = new LZFile(f, LZFile.CompressionType.LZ); File imgFile = new InlineFile(fileLz, 0, 0x10000, f.name); File palFile = new InlineFile(fileLz, 0x10000, 0x200, f.name); LevelChooser.imgMgr.m.addImage(new EnpgImage2D(imgFile)); LevelChooser.imgMgr.m.addPalette(new FilePalette(palFile)); } else if (filename.EndsWith(".bncd")) new Bncd(f); if (filename.EndsWith(".nsbtx") || filename.EndsWith(".nsbmd")) new NSBTX(f); else if (filename.EndsWith(".nscr") || filename.EndsWith(".ncgr") || filename.EndsWith(".nclr")) SectionFileLoader.load(f); else if (filename.EndsWith(".narc")) new FilesystemBrowserDialog(new NarcFilesystem(f)).Show(); else if (filename.EndsWith(".carc")) new FilesystemBrowserDialog(new NarcFilesystem(f, true)).Show(); else if (filename.Contains("_ncl.bin")) new PaletteViewer(new LZFile(f, LZFile.CompressionType.MaybeLZ)).Show(); else if (filename.Contains("_nsc.bin")) { if (LevelChooser.imgMgr == null) return; Image2D img = LevelChooser.imgMgr.m.getSelectedImage(); Palette[] pals = LevelChooser.imgMgr.m.getPalettes(); if (img == null) return; if (pals == null) return; if (pals.Length == 0) return; Tilemap t = new Tilemap(f, 32, img, pals, 0, 0); new TilemapEditorWindow(t).Show(); } else if (filename.Contains("_ncg.bin")) { LevelChooser.showImgMgr(); LevelChooser.imgMgr.m.addImage(new Image2D(f, 256, false)); } } catch (AlreadyEditingException ex) { MessageBox.Show(this, (LanguageManager.Get("Errors", "File"))); } }
public void endEditInline(InlineFile f) { if (!inlineEditors.Contains(f)) throw new Exception("ERROR: INLINE FILE"); inlineEditors.Remove(f); if (inlineEditors.Count == 0) endEdit(this); }
public void beginEditInline(InlineFile f) { if (inlineEditors.Count == 0) beginEdit(this); inlineEditors.Add(f); }
private Bitmap RenderBackground(File GFXFile, File PalFile, File LayoutFile, int offs, int palOffs) { LayoutFile = new InlineFile(LayoutFile, 0, 2 * 64 * 64, LayoutFile.name, null, InlineFile.CompressionType.LZComp); Image2D i = new Image2D(GFXFile, 256, false); Palette pal1 = new FilePalette(new InlineFile(PalFile, 0, 512, PalFile.name, null, InlineFile.CompressionType.LZComp)); Palette pal2 = new FilePalette(new InlineFile(PalFile, 512, 512, PalFile.name, null, InlineFile.CompressionType.LZComp)); Tilemap t = new Tilemap(LayoutFile, 64, i, new Palette[] { pal1, pal2 }, offs, palOffs); t.render(); return t.buffer; }