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); }
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)); } }
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 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 int[len]; for (int i = 0; i < len; i++) TileBehaviors[i] = inp.readInt(); }
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)); } }