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)); } CalculateSpriteModifiers(); repaintAllTilemap(); }
private void LevelChooser_Load(object sender, EventArgs e) { useMDI.Checked = Properties.Settings.Default.mdi; autoUpdate.Checked = Properties.Settings.Default.AutoUpdateSD; chkAutoBackup.Checked = Properties.Settings.Default.AutoBackup > 0; if (chkAutoBackup.Checked) { autoBackupTime.Value = Properties.Settings.Default.AutoBackup; } init = true; filesystemBrowser1.Load(ROM.FS); LoadLevelNames(); if (ROM.UserInfo != null) { musicList.Items.AddRange(ROM.UserInfo.getFullList("Music").ToArray()); } LanguageManager.ApplyToContainer(this, "LevelChooser"); openROMDialog.Filter = LanguageManager.Get("Filters", "rom"); importLevelDialog.Filter = LanguageManager.Get("Filters", "level"); exportLevelDialog.Filter = LanguageManager.Get("Filters", "level"); openPatchDialog.Filter = LanguageManager.Get("Filters", "patch"); savePatchDialog.Filter = LanguageManager.Get("Filters", "patch"); openTextFileDialog.Filter = LanguageManager.Get("Filters", "text"); saveTextFileDialog.Filter = LanguageManager.Get("Filters", "text"); this.Activate(); //Get Language Files string langDir = System.IO.Path.Combine(Application.StartupPath, "Languages"); if (System.IO.Directory.Exists(langDir)) { string[] files = System.IO.Directory.GetFiles(langDir); for (int l = 0; l < files.Length; l++) { if (files[l].EndsWith(".ini")) { int startPos = files[l].LastIndexOf(System.IO.Path.DirectorySeparatorChar) + 1; languageListBox.Items.Add(files[l].Substring(startPos, files[l].LastIndexOf('.') - startPos)); } } } // Load file backups from crash string backupPath = Path.Combine(Application.StartupPath, "Backup"); if (ROM.fileBackups.Count > 0) { foreach (string filename in ROM.fileBackups) { try { new LevelEditor(new NSMBLevel(LevelSource.getForBackupLevel(filename, backupPath))).Show(); } catch (Exception) { } } } this.Text = "NSMB Editor 5.2 Beta - " + ROM.filename; label3.Text = "NSMB Editor 5.2 " + Properties.Resources.version.Trim(); this.Icon = Properties.Resources.nsmbe; if (!ROM.isNSMBRom) { tabControl1.TabPages.Remove(tabPage2); tabControl1.TabPages.Remove(tabPage5); tabControl1.TabPages.Remove(tabPage6); nsmbToolsGroupbox.Enabled = false; musicSlotsGrp.Enabled = false; } // new LevelEditor("A01_1", "LOL").Show(); }
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)); } CalculateSpriteModifiers(); repaintAllTilemap(); }