// NEEDS TO BE MOVED TO THE FORMS SIDE public static void GetAndDrawTrainerPic(this PictureBox picBox, int index) { var sOffset = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "TrainerImageTable", ""), System.Globalization.NumberStyles.HexNumber) + index * 8; var pOffset = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "TrainerPaletteTable", ""), System.Globalization.NumberStyles.HexNumber) + index * 8; var temp = new byte[4096]; var image = new byte[65536]; var palette15 = new byte[4096]; Color[] palette32; Bitmap bSprite; using (var fs = new FileStream(MainObject.LoadedRom, FileMode.Open, FileAccess.Read)) { using var r = new BinaryReader(fs); fs.Position = sOffset; sOffset = r.ReadInt32() - 0x8000000; fs.Position = sOffset; r.Read(temp, 0, 0xFFF); Lz77.Lz77UnComp(temp, image); temp = new byte[4096]; fs.Position = pOffset; pOffset = r.ReadInt32() - 0x8000000; fs.Position = pOffset; r.Read(temp, 0, 0xFFF); Lz77.Lz77UnComp(temp, palette15); palette32 = GetImageFunctions.LoadPalette(palette15); } bSprite = GetImageFunctions.LoadSprite(ref image, palette32, 64, 64, Conversions.ToBoolean(Ini.GetString(MainObject.AppPath + "GBAPGESettings.ini", "Settings", "TransparentImages", "0"))); picBox.Image = bSprite; picBox.Refresh(); }
public static void GetAndDrawFrontPokemonPicBlack(this PictureBox picBox, int index) { var sOffset = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "PokemonFrontSprites", ""), System.Globalization.NumberStyles.HexNumber) + index * 8; // Pointer to Pokemon front sprites, + 8 = Bulbasaur. var pOffset = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "PokemonNormalPal", ""), System.Globalization.NumberStyles.HexNumber) + index * 8; // Pointer to Pokemon normal palettes, + 8 = Bulbasaur. var temp = new byte[4096]; var image = new byte[65536]; var palette15 = new byte[4096]; Color[] palette32; Bitmap bSprite; using (var fileStream = new FileStream(MainObject.LoadedRom, FileMode.Open, FileAccess.Read)) { using var r = new BinaryReader(fileStream); fileStream.Position = sOffset; sOffset = r.ReadInt32() - 0x8000000; fileStream.Position = sOffset; r.Read(temp, 0, 0xFFF); Lz77.Lz77UnComp(temp, image); temp = new byte[4096]; fileStream.Position = pOffset; pOffset = r.ReadInt32() - 0x8000000; fileStream.Position = pOffset; r.Read(temp, 0, 0xFFF); Lz77.Lz77UnComp(temp, palette15); palette32 = GetImageFunctions.LoadPalette(palette15); palette32[1] = Color.Black; palette32[2] = Color.Black; palette32[3] = Color.Black; palette32[4] = Color.Black; palette32[5] = Color.Black; palette32[6] = Color.Black; palette32[7] = Color.Black; palette32[8] = Color.Black; palette32[9] = Color.Black; palette32[10] = Color.Black; palette32[11] = Color.Black; palette32[12] = Color.Black; palette32[13] = Color.Black; palette32[14] = Color.Black; palette32[15] = Color.Black; } bSprite = GetImageFunctions.LoadSprite(ref image, palette32, 64, 64, Conversions.ToBoolean(Ini.GetString(MainObject.AppPath + "GBAPGESettings.ini", "Settings", "TransparentImages", "0"))); picBox.Image = bSprite; picBox.Refresh(); }
public Form1() { InitializeComponent(); lz77Obj = new Lz77(); for (int i = 3; i <= 15; i++) { offsetSizeBox.Items.Add(i); } offsetSizeBox.SelectedIndex = 0; for (int i = 2; i <= 7; i++) { lengthSizeBox.Items.Add(i); } lengthSizeBox.SelectedIndex = 0; }
private void cbSourceSound_CheckedChanged(object sender, EventArgs e) { if (cbSourceSound.Checked) { tbAudioFile.Text = "Internal Sound"; if (Lz77.IsLz77Compressed(sourceSound)) { Lz77 l = new Lz77(); sourceSound = l.Decompress(sourceSound); } foreach (Label thisLabel in gbWaveInfo.Controls) { if (thisLabel.Name.ToLower().Contains("value")) { thisLabel.ForeColor = System.Drawing.Color.Black; thisLabel.Text = "Gathering"; } } bwGatherInfo.RunWorkerAsync(sourceSound); //this.Size = new System.Drawing.Size(510, 220); this.Size = new System.Drawing.Size(gbWaveInfo.Location.X + gbWaveInfo.Size.Width + 15, this.Size.Height); } else { if (tbAudioFile.Text == "Internal Sound") { tbAudioFile.Text = string.Empty; } //this.Size = new System.Drawing.Size(358, 220); this.Size = new System.Drawing.Size(btnCancel.Location.X + btnCancel.Size.Width + 15, this.Size.Height); } }
// 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; } }
public Bitmap Decode() { MemoryStream Stream = new MemoryStream(); Open().CopyTo(Stream); Stream.Position = 0; if (Compressed && SteamVersion.Value) { Stream = new MemoryStream(LZSSDecompress(Stream)); } else if (Compressed) { var Decompressor = new Lz77(); MemoryStream Buffer = new MemoryStream(); Decompressor.Decompress(Stream).CopyTo(Buffer); Stream.Close(); Stream = Buffer; } Bitmap Output; if (SteamVersion.Value) { Output = new Bitmap(TexSize.Width, TexSize.Height); byte[] Buffer = Stream.ToArray(); fixed(void *pAddr = &Buffer[0]) { #if DEBUG System.Diagnostics.Debug.Assert(Buffer.Length == TexSize.Width * TexSize.Height); #endif uint *pPixels = (uint *)pAddr; int Stride = TexSize.Width; for (int i = 0; i < Buffer.Length / 4; i++, pPixels++) { int X = i % Stride; int Y = i / Stride; unchecked { uint ARGB = *pPixels; //ABGR => ARGB ARGB = (ARGB & 0xFF00FF00) | ((ARGB & 0x00FF0000) >> 8 * 2) | ((ARGB & 0x000000FF) << 8 * 2); Output.SetPixel(X, Y, Color.FromArgb((int)ARGB)); } } } } else { Output = Image.FromStream(Stream) as Bitmap; } Stream.Close(); TexSize = Output.Size; if (Tiled) { Output = Untile(Output); } return(Output); }