private void MainForm_Load(object sender, EventArgs e) { this.RomHeader = read.ReadString(0xAC, 4); findTables(this.RomHeader); if (this.SpriteTable == 0x0) { this.Close(); return; } #region FindPalette foundPalettes = new List <byte>(); byte indicator = 0x1; int take = 0; byte b; while (indicator != 0x0) { b = read.ReadByte(PaletteTable + 8 * take + 4); if (!foundPalettes.Contains(b)) { foundPalettes.Add(b); } indicator = read.ReadByte(PaletteTable + 8 * take + 5); take++; } #endregion iEditBox.Image = new Bitmap(128, 128); iPaletteBox.Image = new Bitmap(32, 128); editColorIndex = 0; navigate(); LabelInfo.Text = this.RomHeader + " - " + read.ReadString(0xA0, 12); //this.Edit.Zoom = 2; }
// The NAVIGATE function void Navigate() { // Can we Navigate? if (Header != null && Header != "" && FrontTable != null) { // Say we're currently naviagting Navigating = true; // Create a new list of sprites in our EditBox EditBox.Sprites = new List <NSE_Framework.Data.Sprite>(6); #region Variables // The current POKEMON index int INDEX = int.Parse(IndexText.Text); // Define Variables int heightFront, heightBack; // The height of the front sprite and back sprite int lzSprite, normalLzPalette, shinyLzPalette; // Stores length of Lz77 compressed data ! RETURNS -1 IF NOT LZ77 COMPRESSED ! int spriteOffset, normalPaletteOffset, shinyPaletteOffset; // Temp sprite offset and palette offset variables byte[] spriteData, normalPaletteData, shinyPaletteData; // Temp sprite data and palette data byte[] #endregion #region FRONT_NORMAL // Offsets of front sprite and palette spriteOffset = Read.ReadPointer(FrontTable + 8 * INDEX); normalPaletteOffset = Read.ReadPointer(NormalTable + 8 * INDEX); // Front sprite's height heightFront = Lz77.CheckLz77(Read, spriteOffset, CheckLz77Type.Sprite) / 256; // Read and decompress data from offsets, output the lengths spriteData = Read.ReadLz77Bytes(spriteOffset, out lzSprite); normalPaletteData = Read.ReadLz77Bytes(normalPaletteOffset, out normalLzPalette); // Build FRONT_NORMAL sprite FN = new Sprite(spriteOffset, normalPaletteOffset, 8, heightFront, Sprite.SpriteType.Color16, spriteData, new SpritePalette(SpritePalette.PaletteType.Color16, normalPaletteData)); FN.CompressedSprite = lzSprite; FN.CompressedPalette = normalLzPalette; #endregion #region FRONT_SHINY // RE-USE LAST SPRITE_DATA // Offsets of shiny palette, RE-USE last sprite offset shinyPaletteOffset = Read.ReadPointer(ShinyTable + 8 * INDEX); // Read and decompress data from offset, output the length shinyPaletteData = Read.ReadLz77Bytes(shinyPaletteOffset, out shinyLzPalette); // Build FRONT_SHINY sprite FS = new Sprite(spriteOffset, shinyPaletteOffset, 8, heightFront, Sprite.SpriteType.Color16, spriteData, new SpritePalette(SpritePalette.PaletteType.Color16, shinyPaletteData)); FS.CompressedSprite = lzSprite; FS.CompressedPalette = shinyLzPalette; #endregion #region BACK_SHINY // Offsets of back sprite, RE-USE last palette offset spriteOffset = Read.ReadPointer(BackTable + 8 * INDEX); // Back sprite's height heightBack = Lz77.CheckLz77(Read, spriteOffset, CheckLz77Type.Sprite) / 256; // Read and decompress data from offset, output the length spriteData = Read.ReadLz77Bytes(spriteOffset, out lzSprite); // Build BACK_SHINY sprite BS = new NSE_Framework.Data.Sprite(spriteOffset, shinyPaletteOffset, 8, heightBack, Sprite.SpriteType.Color16, spriteData, FS.Palette); BS.CompressedSprite = lzSprite; BS.CompressedPalette = shinyLzPalette; #endregion #region BACK_NORMAL // Build BACK_NORMAL sprite RE-USING all data BN = new Sprite(spriteOffset, normalPaletteOffset, 8, heightBack, Sprite.SpriteType.Color16, spriteData, FN.Palette); BN.CompressedSprite = lzSprite; BN.CompressedPalette = normalLzPalette; #endregion #region MINI // Read sprite pointer spriteOffset = Read.ReadPointer(MiniSpriteTable + 4 * INDEX); // Palette index 0 - 2 byte pi = Read.ReadByte(MiniPaletteIndex + INDEX); // Read palette pointer normalPaletteOffset = Read.ReadPointer(MiniPalettes + 8 * pi); // Build both MINI frames M1 = new Sprite(spriteOffset, normalPaletteOffset, 4, 4, Sprite.SpriteType.Color16, Read); M2 = new Sprite(spriteOffset + 0x200, normalPaletteOffset, 4, 4, Sprite.SpriteType.Color16, Read); M2.Palette = M1.Palette; // Add the value to the numeric up down control NumericUpDownPalette.Value = pi; #endregion #region EDITBOX EditBox.Sprites.Add(FN); EditBox.Sprites.Add(BN); EditBox.Sprites.Add(FS); EditBox.Sprites.Add(BS); EditBox.Sprites.Add(M1); EditBox.Sprites.Add(M2); // MUST BE SET! EditBox.CurrentIndex = 0; #endregion #region PICTURES NSE_Framework.Draw.uDrawSprite(ref bFN, FN); NSE_Framework.Draw.uDrawSprite(ref bBN, BN); NSE_Framework.Draw.uDrawSprite(ref bFS, FS); NSE_Framework.Draw.uDrawSprite(ref bBS, BS); NSE_Framework.Draw.uDrawSprite(ref bM1, M1); NSE_Framework.Draw.uDrawSprite(ref bM2, M2); PictureboxFN.Image = bFN; PictureboxBN.Image = bBN; PictureboxFS.Image = bFS; PictureboxBS.Image = bBS; PictureboxA1.Image = bM1; PictureboxA2.Image = bM2; #endregion // Say we're done navigating Navigating = false; } }