private static Overlay[] loadOvTable(File table) { Overlay[] ovs = new Overlay[table.fileSize / 32]; ByteArrayInputStream tbl = new ByteArrayInputStream(table.getContents()); int i = 0; while (tbl.lengthAvailable(32)) { uint ovId = tbl.readUInt(); uint ramAddr = tbl.readUInt(); uint ramSize = tbl.readUInt(); uint bssSize = tbl.readUInt(); uint staticInitStart = tbl.readUInt(); uint staticInitEnd = tbl.readUInt(); ushort fileID = tbl.readUShort(); tbl.skip(6); //unused 0's ovs[ovId] = new Overlay(FS.getFileById(fileID), table, (uint)i * 32); i++; } return(ovs); }
private static Overlay[] loadOvTable2(File table) { Overlay[] ovs2 = new Overlay[table.fileSize / 32]; // initialize secondary overlay table ByteArrayInputStream tbl = new ByteArrayInputStream(table.getContents()); int i = 0; while (tbl.lengthAvailable(32)) { uint ovId = tbl.readUInt(); uint ramAddr = tbl.readUInt(); uint ramSize = tbl.readUInt(); uint bssSize = tbl.readUInt(); uint staticInitStart = tbl.readUInt(); uint staticInitEnd = tbl.readUInt(); ushort fileID = tbl.readUShort(); tbl.skip(6); //unused 0's ovs2[fileID] = new Overlay(FS.getFileById(fileID), table, (uint)i * 32); //secondary overlay table used for overlay decompression i++; } return(ovs2); }
public ObjectDefTile(ByteArrayInputStream inp, NSMBTileset t) { this.t = t; if (inp.available < 1) //This should never happen. But sometimes, it does. { controlByte = 0xFF; //Simulate object end. return; } controlByte = inp.readByte(); if (!controlTile) { byte a, b; a = inp.readByte(); b = inp.readByte(); tileID = a + ((b - t.ObjectDefTileOffset) << 8); if ((controlByte & 64) != 0) //OVERRIDES { tileID += 768; } if (a == 0 && b == 0) { tileID = -1; } } }
public override void save(ExportedLevel level) { ByteArrayInputStream strm = new ByteArrayInputStream(new byte[0]); System.IO.BinaryWriter bw = new System.IO.BinaryWriter(strm); level.Write(bw); copyData(strm.getData()); }
public static Color[] arrayToPalette(byte[] data) { ByteArrayInputStream ii = new ByteArrayInputStream(data); Color[] pal = new Color[data.Length / 2]; for (int i = 0; i < pal.Length; i++) { pal[i] = NSMBTileset.fromRGB15(ii.readUShort()); } return(pal); }
public static NSMBView read(ByteArrayInputStream inp, ByteArrayInputStream cam) { NSMBView v = new NSMBView(); v.X = inp.readUShort(); v.Y = inp.readUShort(); v.Width = inp.readUShort(); v.Height = inp.readUShort(); v.Number = inp.readByte(); int camID = inp.readByte(); v.Music = inp.readByte(); v.Unknown1 = inp.readByte(); v.Unknown2 = inp.readByte(); v.Unknown3 = inp.readByte(); v.Lighting = inp.readByte(); v.FlagpoleID = inp.readByte(); cam.seek(0); int camCount = (int)cam.available / 24; // Console.Out.WriteLine("CamCount: " + camCount); int goodCam = -1; for (int i = 0; i < camCount; i++) { cam.seek(i * 24 + 16); int thisCam = cam.readUShort(); // Console.Out.WriteLine("Cam ID: " + thisCam); if (thisCam == camID) { goodCam = i; break; } } if (goodCam == -1) { Console.Out.WriteLine("Warning: Could not find camera ID " + camID); } else { cam.seek(goodCam * 24); v.CameraTop = cam.readInt(); v.CameraBottom = cam.readInt(); v.CameraTopSpin = cam.readInt(); v.CameraBottomSpin = cam.readInt(); cam.skip(2); v.CameraBottomStick = cam.readUShort(); } return(v); }
private void exportClipboard_Click(object sender, EventArgs e) { string LevelFilename = (string)levelTreeView.SelectedNode.Tag; DSFileSystem.File LevelFile = ROM.getLevelFile(LevelFilename); DSFileSystem.File BGFile = ROM.getBGDatFile(LevelFilename); ByteArrayInputStream strm = new ByteArrayInputStream(new byte[0]); BinaryWriter bw = new BinaryWriter(strm); new ExportedLevel(LevelFile, BGFile).Write(bw); ClipboardLevelSource.copyData(strm.getData()); bw.Close(); }
protected virtual void load() { height = (f.fileSize / 2 + width - 1) / width; tiles = new Tile[width, height]; ByteArrayInputStream b = new ByteArrayInputStream(f.getContents()); for (int i = 0; i < f.fileSize / 2; i++) { int x = i % width; int y = i / width; tiles[x, y] = shortToTile(b.readUShort()); } }
public static NSMBView readZone(ByteArrayInputStream inp) { NSMBView v = new NSMBView(); v.X = inp.readUShort(); v.Y = inp.readUShort(); v.Width = inp.readUShort(); v.Height = inp.readUShort(); v.Number = inp.readByte(); v.isZone = true; inp.skip(3); return(v); }
public static NSMBPathPoint read(ByteArrayInputStream inp, NSMBPath parent) { NSMBPathPoint p = new NSMBPathPoint(parent); p.X = inp.readUShort(); p.Y = inp.readUShort(); p.Unknown1 = inp.readUShort(); p.Unknown2 = inp.readUShort(); p.Unknown3 = inp.readUShort(); p.Unknown4 = inp.readUShort(); p.Unknown5 = inp.readUShort(); p.Unknown6 = inp.readUShort(); return(p); }
protected override void load() { height = (f.fileSize / 2 + width - 1) / width; tiles = new Tile[width, height]; ByteArrayInputStream b = new ByteArrayInputStream(f.getContents()); for (int i = 0; i < f.fileSize / 8; i++) { int x = (i % (width / 2)) * 2; int y = (i / (width / 2)) * 2; tiles[x, y] = shortToTile(b.readUShort()); tiles[x + 1, y] = shortToTile(b.readUShort()); tiles[x, y + 1] = shortToTile(b.readUShort()); tiles[x + 1, y + 1] = shortToTile(b.readUShort()); } }
public static NSMBPath read(ByteArrayInputStream inp, ByteArrayInputStream nodes, bool isProgressPath) { NSMBPath p = new NSMBPath(); p.isProgressPath = isProgressPath; p.id = inp.readUShort(); int row = inp.readUShort(); int len = inp.readUShort(); inp.skip(2); //unused values nodes.seek(row * 16); for (int i = 0; i < len; i++) { p.points.Add(NSMBPathPoint.read(nodes, p)); } return(p); }
public void loadObjects() { ByteArrayInputStream eObjIndexFile = new ByteArrayInputStream(ObjIndexFile.getContents()); ByteArrayInputStream eObjFile = new ByteArrayInputStream(ObjFile.getContents()); Objects = new ObjectDef[objectCount]; //read object index int obj = 0; while (eObjIndexFile.lengthAvailable(4) && obj < Objects.Length) { Objects[obj] = new ObjectDef(this); int offset = eObjIndexFile.readUShort(); Objects[obj].width = eObjIndexFile.readByte(); Objects[obj].height = eObjIndexFile.readByte(); eObjFile.seek(offset); Objects[obj].load(eObjFile); obj++; } }
public void load(ByteArrayInputStream inp) { tiles = new List <List <ObjectDefTile> >(); List <ObjectDefTile> row = new List <ObjectDefTile>(); while (true) { ObjectDefTile t = new ObjectDefTile(inp, this.t); if (t.lineBreak) { tiles.Add(row); row = new List <ObjectDefTile>(); } else if (t.objectEnd) { break; } else { row.Add(t); } } }
private void loadTileBehaviors() { byte[] x = null; if (TilesetNumber == 0) { x = ROM.GetInlineFile(ROM.Data.File_Jyotyu_CHK); } else if (TilesetNumber == 1 || TilesetNumber == 2) { x = TileBehaviorFile.getContents(); } ByteArrayInputStream inp = new ByteArrayInputStream(x); int len = inp.available / 4; TileBehaviors = new uint[len]; for (int i = 0; i < len; i++) { TileBehaviors[i] = inp.readUInt(); } }
public ClipboardLevelSource(string loadFileName) { BinaryReader br; if (loadFileName == "") { string leveltxt = Clipboard.GetText(); if (!(leveltxt.StartsWith(clipboardHeader) && leveltxt.EndsWith(clipboardFooter))) { throw new Exception(); } leveltxt = leveltxt.Substring(11, leveltxt.Length - 12); byte[] leveldata = ROM.LZ77_Decompress(Convert.FromBase64String(leveltxt), false); ByteArrayInputStream strm = new ByteArrayInputStream(leveldata); br = new BinaryReader(strm); } else { FileStream fs = new FileStream(loadFileName, FileMode.Open, FileAccess.Read, FileShare.Read); br = new BinaryReader(fs); } level = new ExportedLevel(br); br.Close(); }
public NSMBLevel(LevelSource source) { this.source = source; this.name = source.getLevelName(); byte[] eLevelFile = source.getData(); byte[] eBGFile = source.getBGDatData(); int FilePos; // Level loading time yay. // Since I don't know the format for every block, I will just load them raw. Blocks = new byte[][] { null, null, null, null, null, null, null, null, null, null, null, null, null, null }; FilePos = 0; for (int BlockIdx = 0; BlockIdx < 14; BlockIdx++) { int BlockOffset = eLevelFile[FilePos] | (eLevelFile[FilePos + 1] << 8) | (eLevelFile[FilePos + 2] << 16) | eLevelFile[FilePos + 3] << 24; FilePos += 4; int BlockSize = eLevelFile[FilePos] | (eLevelFile[FilePos + 1] << 8) | (eLevelFile[FilePos + 2] << 16) | eLevelFile[FilePos + 3] << 24; FilePos += 4; Blocks[BlockIdx] = new byte[BlockSize]; Array.Copy(eLevelFile, BlockOffset, Blocks[BlockIdx], 0, BlockSize); } byte TilesetID = Blocks[0][0x0C]; byte BGNSCID = Blocks[2][2]; GFX = new NSMBGraphics(); GFX.LoadTilesets(TilesetID, BGNSCID); // Now objects. int ObjectCount = eBGFile.Length / 10; Objects = new List <NSMBObject>(ObjectCount); FilePos = 0; for (int ObjectIdx = 0; ObjectIdx < ObjectCount; ObjectIdx++) { int ObjID = eBGFile[FilePos] | (eBGFile[FilePos + 1] << 8); //int ObjX = eBGFile[FilePos + 2] | (eBGFile[FilePos + 3] << 8); //int ObjY = eBGFile[FilePos + 4] | (eBGFile[FilePos + 5] << 8); int ObjX = BitConverter.ToInt16(eBGFile, FilePos + 2); int ObjY = BitConverter.ToInt16(eBGFile, FilePos + 4); int ObjWidth = eBGFile[FilePos + 6] | (eBGFile[FilePos + 7] << 8); int ObjHeight = eBGFile[FilePos + 8] | (eBGFile[FilePos + 9] << 8); Objects.Add(new NSMBObject(ObjID & 4095, (ObjID & 61440) >> 12, ObjX, ObjY, ObjWidth, ObjHeight, GFX)); FilePos += 10; } /* * Sprite struct: * Offs Len Dat * 0x0 2 Sprite id * 0x2 2 X * 0x4 2 Y * 0x6 6 Dat * 0xD end */ // Sprites byte[] SpriteBlock = Blocks[6]; int SpriteCount = (SpriteBlock.Length - 2) / 12; Sprites = new List <NSMBSprite>(SpriteCount); FilePos = 0; for (int SpriteIdx = 0; SpriteIdx < SpriteCount; SpriteIdx++) { NSMBSprite Sprite = new NSMBSprite(this); Sprite.Type = SpriteBlock[FilePos] | (SpriteBlock[FilePos + 1] << 8); Sprite.X = SpriteBlock[FilePos + 2] | (SpriteBlock[FilePos + 3] << 8); Sprite.Y = SpriteBlock[FilePos + 4] | (SpriteBlock[FilePos + 5] << 8); Sprite.Data = new byte[6]; FilePos += 6; Sprite.Data[0] = SpriteBlock[FilePos + 1]; Sprite.Data[1] = SpriteBlock[FilePos + 0]; Sprite.Data[2] = SpriteBlock[FilePos + 5]; Sprite.Data[3] = SpriteBlock[FilePos + 4]; Sprite.Data[4] = SpriteBlock[FilePos + 3]; Sprite.Data[5] = SpriteBlock[FilePos + 2]; // Array.Copy(SpriteBlock, FilePos + 6, Sprite.Data, 0, 6); Sprites.Add(Sprite); FilePos += 6; } // Entrances. byte[] EntranceBlock = Blocks[5]; int EntranceCount = EntranceBlock.Length / 20; Entrances = new List <NSMBEntrance>(EntranceCount); FilePos = 0; for (int EntIdx = 0; EntIdx < EntranceCount; EntIdx++) { NSMBEntrance Entrance = new NSMBEntrance(); Entrance.X = EntranceBlock[FilePos] | (EntranceBlock[FilePos + 1] << 8); Entrance.Y = EntranceBlock[FilePos + 2] | (EntranceBlock[FilePos + 3] << 8); Entrance.CameraX = EntranceBlock[FilePos + 4] | (EntranceBlock[FilePos + 5] << 8); Entrance.CameraY = EntranceBlock[FilePos + 6] | (EntranceBlock[FilePos + 7] << 8); Entrance.Number = EntranceBlock[FilePos + 8]; Entrance.DestArea = EntranceBlock[FilePos + 9]; Entrance.ConnectedPipeID = EntranceBlock[FilePos + 10]; Entrance.DestEntrance = EntranceBlock[FilePos + 12]; Entrance.Type = EntranceBlock[FilePos + 14]; Entrance.Settings = EntranceBlock[FilePos + 15]; Entrance.Unknown1 = EntranceBlock[FilePos + 16]; Entrance.EntryView = EntranceBlock[FilePos + 18]; Entrance.Unknown2 = EntranceBlock[FilePos + 19]; //Array.Copy(EntranceBlock, FilePos, Entrance.Data, 0, 20); Entrances.Add(Entrance); FilePos += 20; } // Views ByteArrayInputStream ViewBlock = new ByteArrayInputStream(Blocks[7]); ByteArrayInputStream CamBlock = new ByteArrayInputStream(Blocks[1]); Views = new List <NSMBView>(); while (ViewBlock.lengthAvailable(16)) { Views.Add(NSMBView.read(ViewBlock, CamBlock)); } // Zones ByteArrayInputStream ZoneBlock = new ByteArrayInputStream(Blocks[8]); Zones = new List <NSMBView>(); while (ZoneBlock.lengthAvailable(12)) { Zones.Add(NSMBView.readZone(ZoneBlock)); } // Paths ByteArrayInputStream PathBlock = new ByteArrayInputStream(Blocks[10]); ByteArrayInputStream PathNodeBlock = new ByteArrayInputStream(Blocks[12]); Paths = new List <NSMBPath>(); while (!PathBlock.end()) { Paths.Add(NSMBPath.read(PathBlock, PathNodeBlock, false)); } PathBlock = new ByteArrayInputStream(Blocks[9]); PathNodeBlock = new ByteArrayInputStream(Blocks[11]); ProgressPaths = new List <NSMBPath>(); while (!PathBlock.end()) { ProgressPaths.Add(NSMBPath.read(PathBlock, PathNodeBlock, true)); } //Extra Data (decompiled, so messy code) byte[] block3 = this.Blocks[13]; int capacity4 = (block3.Length - 16) / 16; int num4 = 16; this.ExtraData = new List <NSMBExtraData>(capacity4); for (int index2 = 0; index2 < capacity4; ++index2) { NSMBExtraData nsmbExtraData = new NSMBExtraData(); for (int index3 = 0; index3 < 16; ++index3) { nsmbExtraData.data[index3] = block3[num4 + index3]; } this.ExtraData.Add(nsmbExtraData); num4 += 16; } CalculateSpriteModifiers(); repaintAllTilemap(); }
public override Bitmap render(Palette p) { int w = getWidth(); int h = getHeight(); Bitmap b = new Bitmap(w, h); ByteArrayInputStream f5data = new ByteArrayInputStream(f5.getContents()); ByteArrayInputStream data = new ByteArrayInputStream(f.getContents()); for (uint y = 0; y < h / 4; y++) { for (uint x = 0; x < w / 4; x++) { ushort palDat = f5data.readUShort(); ushort palOffs = (ushort)((palDat & 0x3FFF) * 2); ushort mode = (ushort)((palDat >> 14) & 3); for (uint yy = 0; yy < 4; yy++) { byte row = data.readByte(); for (uint xx = 0; xx < 4; xx++) { byte color = (byte)(row >> (byte)(xx * 2)); color &= 3; Color col; col = p.getColorSafe(palOffs + color); switch (mode) { case 0: if (color == 3) { col = Color.Transparent; } break; case 1: if (color == 2) { col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 1, 1); } if (color == 3) { col = Color.Transparent; } break; case 3: if (color == 2) { col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 5, 3); } if (color == 3) { col = ImageTiler.colorMean(p.getColorSafe(palOffs), p.getColorSafe(palOffs + 1), 3, 5); } break; } b.SetPixel((int)x * 4 + (int)xx, (int)y * 4 + (int)yy, col); } } } } return(b); }
public static void load(Filesystem fs) { filename = fs.getRomPath(); FS = fs; if (fs is NitroROMFilesystem) { romfile = new System.IO.FileInfo(filename); } arm9binFile = FS.getFileByName("arm9.bin"); arm9ovFile = FS.getFileByName("arm9ovt.bin"); arm9ovs = loadOvTable(arm9ovFile); arm9ovs2 = loadOvTable2(arm9ovFile); arm7binFile = FS.getFileByName("arm7.bin"); arm7ovFile = FS.getFileByName("arm7ovt.bin"); arm7ovs = loadOvTable(arm7ovFile); rsaSigFile = FS.getFileByName("rsasig.bin"); headerFile = FS.getFileByName("header.bin"); arm9RAMAddress = headerFile.getUintAt(0x28); ByteArrayInputStream header = new ByteArrayInputStream(headerFile.getContents()); romInternalName = header.ReadString(12); romGamecode = header.ReadString(4); ASMOffset = 0xE00; // New Super Mario Bros. if (romGamecode == "A2DE") // English { Region = Origin.US; } else if (romGamecode == "A2DP") // European { Region = Origin.EU; OverlayCount = 134; } else if (romGamecode == "A2DJ") // Japanese { Region = Origin.JP; } else if (romGamecode == "A2DK") // Korean { Region = Origin.KR; } else if (romGamecode == "A2DC") // Chinese { Region = Origin.CH; } else { isNSMBRom = false; Region = Origin.UNK; // Pokémon Diamond Version if (romGamecode == "ADAE") // English { ASMOffset = 0x106770; } else if (romGamecode == "ADAJ") // Japanese { ASMOffset = 0x108070; } else if (romGamecode == "ADAF") // French { ASMOffset = 0x1068F0; } else if (romGamecode == "ADAS") // Spanish { ASMOffset = 0x106910; } else if (romGamecode == "ADAI") // Italian { ASMOffset = 0x106850; } else if (romGamecode == "ADAD") // German { ASMOffset = 0x1068B0; } else if (romGamecode == "ADAK") // Korean { ASMOffset = 0x103C70; } // Pokémon Pearl Version else if (romGamecode == "APAE") // English { ASMOffset = 0x106770; } else if (romGamecode == "APAJ") // Japanese { ASMOffset = 0x1081B0; } else if (romGamecode == "APAF") // French { ASMOffset = 0x1068F0; } else if (romGamecode == "APAS") // Spanish { ASMOffset = 0x106910; } else if (romGamecode == "APAI") // Italian { ASMOffset = 0x106850; } else if (romGamecode == "APAD") // German { ASMOffset = 0x1068B0; } else if (romGamecode == "APAK") // Korean { ASMOffset = 0x103C80; } // Pokémon Platinum Version else if (romGamecode == "CPUE") // English { ASMOffset = 0x1010A0; } else if (romGamecode == "CPUJ") // Japanese { ASMOffset = 0x100490; } else if (romGamecode == "CPUF") // French { ASMOffset = 0x101280; } else if (romGamecode == "CPUS") // Spanish { ASMOffset = 0x1012A0; } else if (romGamecode == "CPUI") // Italian { ASMOffset = 0x101200; } else if (romGamecode == "CPUD") // German { ASMOffset = 0x101240; } else if (romGamecode == "CPUK") // Korean { ASMOffset = 0x101F90; } // Pokémon HeartGold Version else if (romGamecode == "IPKE") // English { ASMOffset = 0x110BE0; } else if (romGamecode == "IPKJ") // Japanese { ASMOffset = 0x110110; } else if (romGamecode == "IPKF") // French { ASMOffset = 0x110C00; } else if (romGamecode == "IPKS") // Spanish { ASMOffset = 0x110C00; } else if (romGamecode == "IPKI") // Italian { ASMOffset = 0x110B80; } else if (romGamecode == "IPKD") // German { ASMOffset = 0x110BC0; } else if (romGamecode == "IPKK") // Korean { ASMOffset = 0x1115D0; } // Pokémon SoulSilver Version else if (romGamecode == "IPGE") // English { ASMOffset = 0x110BE0; } else if (romGamecode == "IPGJ") // Japanese { ASMOffset = 0x110110; } else if (romGamecode == "IPGF") // French { ASMOffset = 0x110C00; } else if (romGamecode == "IPGS") // Spanish { ASMOffset = 0x110C20; } else if (romGamecode == "IPGI") // Italian { ASMOffset = 0x110B80; } else if (romGamecode == "IPGD") // German { ASMOffset = 0x110BC0; } else if (romGamecode == "IPGK") // Korean { ASMOffset = 0x1115D0; } } if (isNSMBRom) { headerFile.setByteAt(0x1D, 0x00); UserInfo = new ROMUserInfo(filename); LoadOverlay0(); } }
public Bncd256(File f) { ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(f.getContents()); arrayInputStream.readInt(); this.unk = arrayInputStream.readUShort(); ushort num1 = arrayInputStream.readUShort(); uint pos = arrayInputStream.readUInt(); uint num2 = arrayInputStream.readUInt(); uint num3 = arrayInputStream.readUInt(); arrayInputStream.readUInt(); arrayInputStream.seek(pos); Dictionary <uint, int> dictionary = new Dictionary <uint, int>(); for (uint index1 = 0; index1 < (uint)num1; ++index1) { Bncd256.Bncd256Entry bncdEntry = new Bncd256.Bncd256Entry(); bncdEntry.width = (int)arrayInputStream.readByte(); bncdEntry.height = (int)arrayInputStream.readByte(); uint num4 = (uint)arrayInputStream.readUShort(); uint num5 = (uint)arrayInputStream.readUShort(); arrayInputStream.savePos(); arrayInputStream.seek(num2 + num4 * 12U); for (int index2 = 0; (long)index2 < (long)num5; ++index2) { Bncd256.Bncd256SubEntry bncdSubEntry = new Bncd256.Bncd256SubEntry(); bncdEntry.subEntries.Add(bncdSubEntry); bncdSubEntry.oamAttr0 = arrayInputStream.readUShort(); bncdSubEntry.oamAttr1 = arrayInputStream.readUShort(); bncdSubEntry.unk = arrayInputStream.readUInt(); bncdSubEntry.tileNumber = arrayInputStream.readUShort(); bncdSubEntry.tileCount = arrayInputStream.readUShort(); bncdSubEntry.tileCount *= (ushort)2; uint key = (uint)bncdSubEntry.tileNumber << 16 | (uint)bncdSubEntry.tileCount; int count = dictionary.Count; if (dictionary.ContainsKey(key)) { count = dictionary[key]; } else { dictionary[key] = count; Bncd256.Bncd256Image bncdImage = new Bncd256.Bncd256Image(); this.images.Add(bncdImage); bncdImage.tileNumber = (int)bncdSubEntry.tileNumber; bncdImage.tileCount = (int)bncdSubEntry.tileCount; int index3 = (int)bncdSubEntry.oamAttr0 >> 14; int index4 = (int)bncdSubEntry.oamAttr1 >> 14; bncdImage.tileWidth = Bncd256.widths[index4, index3]; } bncdSubEntry.imageId = count; } arrayInputStream.loadPos(); } LevelChooser.showImgMgr(); int num6 = 32; foreach (Bncd256.Bncd256Image image in this.images) { File f1 = (File) new InlineFile(f, (int)num3 + image.tileNumber * num6, image.tileCount * num6, f.name); LevelChooser.imgMgr.m.addImage((PalettedImage) new Image2D(f1, 8 * image.tileWidth, false)); } }
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(); bool BPP4 = true; //*/BPP4 = false; 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(); //*/se.tileCount *= 2; 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, BPP4)); } }