private void LoadForm(object sender, EventArgs e) { if (Host.Filename != null && Host.Filename != null) { //Creates a new read object Read = new NSE_Framework.Read(Host.Filename); //Creates a new write object Write = new NSE_Framework.Write(Host.Filename); //see if were eddting a pokemon game if (Read.ReadString(0xA0, 7).ToLower() == "pokemon") { //gets the header Header = Read.ReadString(0xAC, 4); if (Header.Substring(0, 2) == "BP") { #region FIRERED_LEAFGREEN_EMERALD FrontTable = Read.ReadPointer(0x128); BackTable = Read.ReadPointer(0x12C); NormalTable = Read.ReadPointer(0x130); ShinyTable = Read.ReadPointer(0x134); MiniSpriteTable = Read.ReadPointer(0x138); MiniPaletteIndex = Read.ReadPointer(0x13C); MiniPalettes = Read.ReadPointer(0x140); MAX = 439; if (!NSE2.Program.MainForm.SafetyRepointing) { if (MessageBox.Show(this, "It seems that SafetyRepointing is disabled:\nIt's suggested that you enable SafetyRepointing for best results.\nEnable SafetyRepointing?", "Notice:", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes) { NSE2.Program.MainForm.SafetyRepointing = true; } } CanNavigate = true; #endregion } else { MessageBox.Show("Currently this plugin only supports Firered, Leafgreen and Emerald.\n-Link12552", "Notice:", MessageBoxButtons.OK); } Navigate(); NumericUpDownPalette.Enabled = true; // Wires the EDITBOX to NSE Host.SetEditor(ref EditBox); } } }
void navigate() { sHeaderOffset = BitConverter.ToInt32(read.ReadBytes(SpriteTable + 4 * Index, 4), 0) - 0x8000000; byte[] HeaderBytes = read.ReadBytes(sHeaderOffset, 36); sWidth = BitConverter.ToInt32(new byte[4] { HeaderBytes[8], HeaderBytes[9], 0, 0 }, 0); sHeight = BitConverter.ToInt32(new byte[4] { HeaderBytes[10], HeaderBytes[11], 0, 0 }, 0); sPaletteIndex = HeaderBytes[2]; sPointer1 = BitConverter.ToInt32(new byte[4] { HeaderBytes[16], HeaderBytes[17], HeaderBytes[18], HeaderBytes[19] }, 0) - 0x8000000; sPointer2 = BitConverter.ToInt32(new byte[4] { HeaderBytes[20], HeaderBytes[21], HeaderBytes[22], HeaderBytes[23] }, 0) - 0x8000000; sPointer3 = BitConverter.ToInt32(new byte[4] { HeaderBytes[28], HeaderBytes[29], HeaderBytes[30], HeaderBytes[31] }, 0) - 0x8000000; ImageOffset = read.ReadPointer(sPointer3 + 8 * Frame); cFrameSize = read.ReadBytes(sPointer3 + 8 * Frame + 4, 2); #region FindPalette PaletteOffset = read.ReadPointer(PaletteTable); byte indicator = 0x1; int take = 0; while (indicator != 0x0) { if (read.ReadByte(PaletteTable + 8 * take + 4) == sPaletteIndex) { PaletteOffset = read.ReadPointer(PaletteTable + 8 * take); indicator = 0x0; } else { indicator = read.ReadByte(PaletteTable + 8 * take + 5); take++; } } #endregion NSE_Framework.Data.Sprite OW = new NSE_Framework.Data.Sprite(ImageOffset, PaletteOffset, sWidth / 8, sHeight / 8, NSE_Framework.Data.Sprite.SpriteType.Color16, read); Sprite = new Bitmap(sWidth, sHeight);//new Bitmap(sWidth * 2, sHeight * 2); byteSprite = read.ReadBytes(ImageOffset, sWidth * sHeight / 2); SpritePalette = new NSE_Framework.Data.SpritePalette(NSE_Framework.Data.SpritePalette.PaletteType.Color16, read.ReadBytes(PaletteOffset, 32)); NSE_Framework.Draw.uDrawData(ref Sprite, byteSprite, SpritePalette, new Size(sWidth / 8, sHeight / 8)); PictureBoxSprite.Image = Sprite; PictureBoxSprite.BackColor = SpritePalette.Colors[0].Color; PictureBoxSprite.Size = new System.Drawing.Size(sWidth * 2, sHeight * 2); PictureBoxSprite.Invalidate(); #region Labels LabelPaletteOffset.Text = "Palette " + sPaletteIndex.ToString("X2") + " Offset:"; dLabelStarterBytes.Text = HeaderBytes[0].ToString("X2") + HeaderBytes[1].ToString("X2"); // Byte 2 is the palette index // Byte 3 is always 0x11 dLabelTypeSize.Text = HeaderBytes[4].ToString("X2") + HeaderBytes[5].ToString("X2"); dLabelFrameSize.Text = HeaderBytes[7].ToString("X2") + HeaderBytes[6].ToString("X2"); // Bytes 8,9,10,11 are width and height dLabelWidth.Text = sWidth.ToString(); dLabelHeight.Text = sHeight.ToString(); dLabelPalReg.Text = HeaderBytes[12].ToString("X2") + "-" + HeaderBytes[13].ToString("X2") + " " + HeaderBytes[14].ToString("X2") + HeaderBytes[15].ToString("X2"); dLabelPointer1.Text = HeaderBytes[19].ToString("X2") + HeaderBytes[18].ToString("X2") + HeaderBytes[17].ToString("X2") + HeaderBytes[16].ToString("X2"); dLabelPointer2.Text = HeaderBytes[23].ToString("X2") + HeaderBytes[22].ToString("X2") + HeaderBytes[21].ToString("X2") + HeaderBytes[20].ToString("X2"); dLabelAnim.Text = HeaderBytes[27].ToString("X2") + HeaderBytes[26].ToString("X2") + HeaderBytes[25].ToString("X2") + HeaderBytes[24].ToString("X2"); dLabelPointer3.Text = HeaderBytes[31].ToString("X2") + HeaderBytes[30].ToString("X2") + HeaderBytes[29].ToString("X2") + HeaderBytes[28].ToString("X2"); dLabelSpriteOffset.Text = "0x" + sHeaderOffset.ToString("X2"); dLabelImageOffset.Text = "0x" + ImageOffset.ToString("X2"); dLabelPaletteOffset.Text = "0x" + PaletteOffset.ToString("X2"); dLabelCFrameSize.Text = cFrameSize[1].ToString("X2") + cFrameSize[0].ToString("X2"); TextBoxPalette.Text = sPaletteIndex.ToString("X2"); #endregion editBlock = 0; drawBlock(); fillCanvas(); fillPalette(); iSelectedColor.BackColor = SpritePalette.Colors[editColorIndex].Color; }
// 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; } }