public override void Read(string fileIn) { BinaryReader br = new BinaryReader(File.OpenRead(fileIn)); char[] type = br.ReadChars(4); uint offset1 = br.ReadUInt32(); uint offset2 = br.ReadUInt32(); uint offset3 = br.ReadUInt32(); // Always 0x00 ? br.BaseStream.Position = offset1 + 0x1C; uint paletteOffset = br.ReadUInt32(); br.BaseStream.Position = 0x10; byte[] tiles = br.ReadBytes((int)(paletteOffset - 0x10)); br.BaseStream.Position = paletteOffset; Color[] colors = Actions.BGR555ToColor(br.ReadBytes(0x200)); RawPalette palette = new RawPalette(new Color[][] { colors }, false, ColorFormat.colors256, ""); pluginHost.Set_Palette(palette); br.Close(); Set_Tiles(tiles, 0x100, tiles.Length / 0x100, ColorFormat.colors256, TileForm.Lineal, false, 8); pluginHost.Set_Image(this); }
public override void Read(string fileIn) { byte[] data = File.ReadAllBytes(fileIn); data = Encryption.Image.Decrypt(data); int width = BitConverter.ToInt16(data, 8); int height = BitConverter.ToInt16(data, 0x0C); int num_colors = BitConverter.ToInt16(data, 0xE); int img_pos = num_colors * 2 + 0x20; // Get image byte[] tiles = new byte[width * height]; Array.Copy(data, img_pos, tiles, 0, tiles.Length); ColorFormat format = ColorFormat.colors256; if (num_colors == 0x10) { format = ColorFormat.colors16; width *= 2; } Set_Tiles(tiles, width, height, format, TileForm.Lineal, false); // Get palette byte[] pal = new byte[num_colors * 2]; Array.Copy(data, 0x20, pal, 0, pal.Length); Color[] colors = Actions.BGR555ToColor(pal); RawPalette palette = new RawPalette(new Color[][] { colors }, false, format); pluginHost.Set_Palette(palette); pluginHost.Set_Image(this); }
public System.Windows.Forms.Control Show_Info(sFile file) { if ((file.id >= 0x12C && file.id <= 0x165) || (file.id >= 0x65D && file.id <= 0x68A) || file.id == 0x16B || file.id == 0x16C) { return(new TextControl(pluginHost, file.path)); } if ((file.id >= 0x1E4 && file.id <= 0x1F4) || (file.id >= 0x1F7 && file.id <= 0x2FC)) { string[] p = new String[] { file.path, "Sounds.Main", file.name + ".adx", "" }; return((System.Windows.Forms.Control)pluginHost.Call_Plugin(p, file.id, 1)); } if (file.id >= 0x01 && file.id <= 0x1E3) { if (file.size == 512 || file.size == 128 || file.size == 32) { RawPalette palette = new RawPalette(file.path, file.id, false, 0, -1, file.name); pluginHost.Set_Palette(palette); return(new PaletteControl(pluginHost)); } else { return(new Images(pluginHost, file.path, file.id).Get_Control()); } } return(new System.Windows.Forms.Control()); }
public System.Windows.Forms.Control Show_Info(sFile file) { if (file.name.EndsWith(".acl")) { PaletteBase palette = new RawPalette(file.path, file.id, true, 0, -1, file.name); pluginHost.Set_Palette(palette); return(new PaletteControl(pluginHost)); } if (file.name.EndsWith(".acg")) { ColorFormat depth = (pluginHost.Get_Palette().Loaded ? pluginHost.Get_Palette().Depth : ColorFormat.colors256); ImageBase image = new RawImage(file.path, file.id, TileForm.Horizontal, depth, true, 0, -1, file.name); pluginHost.Set_Image(image); return(new ImageControl(pluginHost, false)); } if (file.name.EndsWith(".asc")) { MapBase map = new Naruto_ASC(file); pluginHost.Set_Map(map); return(new ImageControl(pluginHost, true)); } return(new System.Windows.Forms.Control()); }
private void btnExtract_Click(object sender, EventArgs e) { FolderBrowserDialog o = new FolderBrowserDialog(); o.Description = "Select the folder to extract the images"; o.ShowNewFolderButton = true; if (o.ShowDialog() != DialogResult.OK) { return; } string folderOut = o.SelectedPath + Path.DirectorySeparatorChar; this.Cursor = Cursors.WaitCursor; BinaryReader br = new BinaryReader(File.OpenRead(gbcs)); for (int i = 0; i < infos.Length; i++) { br.BaseStream.Position = infos[i].offset; char[] header = br.ReadChars(4); ushort width = br.ReadUInt16(); ushort height = br.ReadUInt16(); Color[][] palette = new Color[1][] { Actions.BGR555ToColor(br.ReadBytes(0x200)) }; byte[] tiles = br.ReadBytes((int)(infos[i].size - 0x208)); RawPalette pal = new RawPalette(palette, false, ColorFormat.colors256); RawImage img = new RawImage(tiles, TileForm.Horizontal, ColorFormat.colors256, (int)width, (int)height, false); img.Get_Image(pal).Save(folderOut + "Image" + i.ToString() + ".png"); } br.Close(); this.Cursor = Cursors.Default; }
private void UpdateTexture(int num_tex, int num_pal) { sBTX0.Texture.TextInfo texInfo = (sBTX0.Texture.TextInfo)btx0.texture.texInfo.infoBlock.infoData[num_tex]; sBTX0.Texture.PalInfo palInfo = (sBTX0.Texture.PalInfo)btx0.texture.palInfo.infoBlock.infoData[num_pal]; // Get texture data BinaryReader br = new BinaryReader(File.OpenRead(btx0.file)); if (texInfo.format != 5) { br.BaseStream.Position = texInfo.tex_offset * 8 + btx0.header.offset[0] + btx0.texture.header.textData_offset; } else { br.BaseStream.Position = btx0.header.offset[0] + btx0.texture.header.textCompressedData_offset + texInfo.tex_offset * 8; } Byte[] tile_data = br.ReadBytes((int)(texInfo.width * texInfo.height * texInfo.depth / 8)); // Get palette data br.BaseStream.Position = btx0.header.offset[0] + btx0.texture.header.paletteData_offset; br.BaseStream.Position += palInfo.palette_offset * 8; Byte[] palette_data = br.ReadBytes((int)PaletteSize[texInfo.format]); Color[] palette = Actions.BGR555ToColor(palette_data); br.Close(); picTex.Image = Draw_Texture(tile_data, texInfo, palette); Clipboard.SetImage(picTex.Image); PaletteBase p = new RawPalette(new Color[][] { palette }, false, ColorFormat.colors256); picPalette.Image = p.Get_Image(0); pluginHost.Set_Palette(p); Info(num_tex, num_pal); }
private void btnExtract_Click(object sender, EventArgs e) { string folder; FolderBrowserDialog o = new FolderBrowserDialog(); o.Description = "Select the folder where you want\nto extract all the images."; o.ShowNewFolderButton = true; if (o.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } folder = o.SelectedPath + Path.DirectorySeparatorChar; SpriteBase sprite = pluginHost.Get_Sprite(); this.Cursor = Cursors.WaitCursor; for (int i = 0; i < infos.Length; i++) { int offset = (int)infos[i].offset; int size = (int)infos[i].size; TileForm form = (images.EndsWith("Tex.dat") ? TileForm.Lineal : TileForm.Horizontal); RawImage image = new RawImage(images, -1, form, ColorFormat.colors256, false, offset + 0x220, size - 0x220); RawPalette palette = new RawPalette(images, -1, false, offset + 0x20, 0x200); sprite.Get_Image(image, palette, 0, 512, 256, false, false, false, true, true).Save(folder + "Image" + i.ToString() + ".png"); } this.Cursor = Cursors.Default; }
private void button1_Click(object sender, EventArgs e) { int num_tex = listTextures.SelectedIndex; int num_pal = listPalettes.SelectedIndex; sBTX0.Texture.TextInfo texInfo = (sBTX0.Texture.TextInfo)btx0.texture.texInfo.infoBlock.infoData[num_tex]; sBTX0.Texture.PalInfo palInfo = (sBTX0.Texture.PalInfo)btx0.texture.palInfo.infoBlock.infoData[num_pal]; // Get palette data BinaryReader br = new BinaryReader(File.OpenRead(btx0.file)); br.BaseStream.Position = btx0.header.offset[0] + btx0.texture.header.paletteData_offset; br.BaseStream.Position += palInfo.palette_offset * 8; Byte[] palette_data = br.ReadBytes((int)PaletteSize[texInfo.format]); Color[] palette = Actions.BGR555ToColor(palette_data); br.Close(); SaveFileDialog o = new SaveFileDialog(); o.AddExtension = true; o.CheckPathExists = true; o.DefaultExt = ".pal"; o.Filter = "Windows Palette for Gimp 2.8 (*.pal)|*.pal|" + "Windows Palette (*.pal)|*.pal|" + "Portable Network Graphics (*.png)|*.png|" + "Adobe COlor (*.aco)|*.aco"; o.OverwritePrompt = true; if (o.ShowDialog() != DialogResult.OK) { return; } if (o.FilterIndex == 3) { RawPalette p = new RawPalette(palette, false, ColorFormat.colors256); p.Get_Image(0).Save(o.FileName, System.Drawing.Imaging.ImageFormat.Png); } else if (o.FilterIndex == 1 || o.FilterIndex == 2) { Ekona.Images.Formats.PaletteWin palwin = new Ekona.Images.Formats.PaletteWin(palette); if (o.FilterIndex == 1) { palwin.Gimp_Error = true; } palwin.Write(o.FileName); } else if (o.FilterIndex == 4) { Ekona.Images.Formats.ACO palaco = new Ekona.Images.Formats.ACO(palette); palaco.Write(o.FileName); } o.Dispose(); }
public override void Read(string file) { BinaryReader br = new BinaryReader(File.OpenRead(file)); cgx = new sCGx(); cgx.type = br.ReadChars(4); // CG4 cgx.unknown1 = br.ReadUInt32(); cgx.unknown2 = br.ReadUInt32(); cgx.unknown3 = br.ReadUInt32(); // Usually 0 cgx.unknown4 = br.ReadUInt32(); // Usually 0 cgx.size_tiles = br.ReadUInt32(); cgx.unknown5 = br.ReadUInt32(); cgx.num_tiles = br.ReadUInt32(); cgx.palColors = br.ReadUInt32(); cgx.tileOffset = br.ReadUInt32(); cgx.palOffset = br.ReadUInt32(); cgx.unknonwnOffset = br.ReadUInt32(); // If 0, it doesn't exist // Read tiles br.BaseStream.Position = cgx.tileOffset; int tile_size = (depth == ColorFormat.colors16 ? 0x20 : 0x40); Byte[] tiles = br.ReadBytes((int)cgx.num_tiles * tile_size); Set_Tiles(tiles, WIDTH, (int)(tiles.Length / WIDTH), depth, TileForm.Horizontal, false); if (depth == Ekona.Images.ColorFormat.colors16) { Height *= 2; } // Read palette br.BaseStream.Position = cgx.palOffset; Color[][] colors; if (depth == Ekona.Images.ColorFormat.colors16) { colors = new Color[cgx.palColors / 0x10][]; for (int i = 0; i < colors.Length; i++) { colors[i] = Actions.BGR555ToColor(br.ReadBytes(32)); } } else { colors = new Color[1][]; colors[0] = Actions.BGR555ToColor(br.ReadBytes((int)cgx.palColors * 2)); } PaletteBase palette = new RawPalette(colors, false, depth); br.BaseStream.Position = cgx.unknonwnOffset; cgx.unknown = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position)); br.Close(); }
public void Read(sFile file) { if (file.id == 0xE7 || file.id == 0xEA) { RawPalette palette = new RawPalette(file.path, file.id, false, 0, -1); pluginHost.Set_Palette(palette); } else if (file.id == 0xE6 || file.id == 0xE9) { RawImage image = new RawImage(file.path, file.id, TileForm.Lineal, ColorFormat.colors16, false, 0, -1); image.Width = 0x80; image.Height = 0x200; pluginHost.Set_Image(image); } }
private void numImg_ValueChanged(object sender, EventArgs e) { int offset = (int)infos[(int)numImg.Value].offset; int size = (int)infos[(int)numImg.Value].size; TileForm form = (images.EndsWith("Tex.dat") ? TileForm.Lineal : TileForm.Horizontal); RawImage image = new RawImage(images, -1, form, ColorFormat.colors256, false, offset + 0x220, size - 0x220); pluginHost.Set_Image(image); RawPalette palette = new RawPalette(images, -1, false, offset + 0x20, 0x200); pluginHost.Set_Palette(palette); this.Controls.Remove(spriteControl1); spriteControl1 = new SpriteControl(pluginHost); this.Controls.Add(spriteControl1); }
private void numImg_ValueChanged(object sender, EventArgs e) { int i = (int)numImg.Value; BinaryReader br = new BinaryReader(File.OpenRead(gbcs)); br.BaseStream.Position = infos[i].offset; char[] header = br.ReadChars(4); ushort width = br.ReadUInt16(); ushort height = br.ReadUInt16(); Color[][] palette = new Color[1][] { Actions.BGR555ToColor(br.ReadBytes(0x200)) }; byte[] tiles = br.ReadBytes((int)(infos[i].size - 0x208)); br.Close(); RawPalette pal = new RawPalette(palette, false, ColorFormat.colors256); RawImage img = new RawImage(tiles, TileForm.Horizontal, ColorFormat.colors256, (int)width, (int)height, false); this.Controls.Remove(imgControl); this.imgControl = new ImageControl(pluginHost, img, pal); this.Controls.Add(imgControl); }
private System.Windows.Forms.Control ShowImage(sFile file) { #region Palette BinaryReader br = new BinaryReader(File.OpenRead(file.path)); br.ReadUInt32(); // 4 Bytes Stupid uint num_colors = 256; byte[] pal = br.ReadBytes((int)num_colors * 2); Color[] colors = Actions.BGR555ToColor(pal); PaletteBase palette = new RawPalette(colors, false, ColorFormat.colors256, file.name); br.ReadUInt32(); // 4 Bytes Stupid #endregion #region Map NTFS[] map_info = new NTFS[1024]; for (int i = 0; i < 1024; i++) { ushort value = br.ReadUInt16(); map_info[i] = Actions.MapInfo(value); } MapBase map = new RawMap(map_info, 256, 192, false, file.name); #endregion #region Tiles uint size_section = (uint)(br.ReadUInt32() * 64); Console.WriteLine("Size section: " + size_section.ToString("x")); byte[] readsize = br.ReadBytes((int)size_section); ImageBase image = new RawImage(readsize, TileForm.Horizontal, ColorFormat.colors256, 256, 192, false, file.name); #endregion br.Close(); pluginHost.Set_Palette(palette); pluginHost.Set_Image(image); pluginHost.Set_Map(map); return(new ImageControl(pluginHost, image, palette, map)); }
public void Decompress() { RawPalette.Decompress(_colorsRgb15Compressed).Should().Equal(_colorsRgb15); }
public void ProcessExportedFiles(string defaultDataFolder, IGraphicsInfo gInfo) { if (!(gInfo is PkmdlConstants pkmdlInfo)) { return; } string texLink = Path.Combine(defaultDataFolder, pkmdlInfo.TEXLink); string atxLink = Path.Combine(defaultDataFolder, pkmdlInfo.ATXLink); string dtxLink = Path.Combine(defaultDataFolder, pkmdlInfo.DTXLink); string pacLink = Path.Combine(defaultDataFolder, pkmdlInfo.PACLink); string texUnpacked = Path.Combine(defaultDataFolder, pkmdlInfo.TEXLinkFolder); string atxUnpacked = Path.Combine(defaultDataFolder, pkmdlInfo.ATXLinkFolder); string dtxUnpacked = Path.Combine(defaultDataFolder, pkmdlInfo.DTXLinkFolder); string pacUnpacked = Path.Combine(defaultDataFolder, pkmdlInfo.PACLinkFolder); string outFolderPath = Path.Combine(defaultDataFolder, pkmdlInfo.PngFolder); Directory.CreateDirectory(outFolderPath); LINK.Unpack(texLink, texUnpacked, false, 4); LINK.Unpack(atxLink, atxUnpacked, false, 4); LINK.Unpack(dtxLink, dtxUnpacked, false, 4); LINK.Unpack(pacLink, pacUnpacked, false, 4); int fileCount = Directory.GetFiles(texUnpacked).Length; Parallel.For(0, fileCount, i => { string fileName = i.ToString().PadLeft(4, '0'); string outFilePath = Path.Combine(outFolderPath, fileName + ".png"); BTX0 btx0 = new BTX0(Path.Combine(texUnpacked, fileName)); Rgba32[] palette = RawPalette.To32bitColors(btx0.Texture.Palette1); palette[0] = Color.Transparent; var texImg = ImageUtil.ToImage( new ImageInfo(btx0.Texture.PixelMap, palette, _pokemonSpriteWidth, btx0.Texture.PixelMap.Length / _pokemonSpriteWidth), PointUtil.GetPoint ); byte[] atxPixelmap = RawChar.Decompress(File.ReadAllBytes(Path.Combine(atxUnpacked, fileName))); var atxImg = ImageUtil.ToImage( new ImageInfo(atxPixelmap, palette, _pokemonSpriteWidth, atxPixelmap.Length / _pokemonSpriteWidth), PointUtil.GetPoint ); byte[] dtxPixelmap = RawChar.Decompress(File.ReadAllBytes(Path.Combine(dtxUnpacked, fileName))); var dtxImg = ImageUtil.ToImage( new ImageInfo(dtxPixelmap, palette, _pokemonSpriteWidth, dtxPixelmap.Length / _pokemonSpriteWidth), PointUtil.GetPoint ); string pacFile = Path.Combine(pacUnpacked, fileName); string pacUnpackedFolder = Path.Combine(pacUnpacked, fileName + "-Unpacked"); PAC.Unpack(pacFile, pacUnpackedFolder, false, 4); byte[] pacPixelmap = RawChar.Decompress(File.ReadAllBytes(Path.Combine(pacUnpackedFolder, "0003"))); var pacImg = ImageUtil.ToImage( new ImageInfo(pacPixelmap, palette, _pokemonSpriteWidth, pacPixelmap.Length / _pokemonSpriteWidth), PointUtil.GetPoint ); var totalWidth = texImg.Width + atxImg.Width + dtxImg.Width + pacImg.Width; var maxHeight = 1024; var combinedImage = new Image <Rgba32>(totalWidth, maxHeight); combinedImage.Mutate(g => { g.DrawImage( image: texImg, location: new Point(0, 0), opacity: 1 ); g.DrawImage( image: atxImg, location: new Point(texImg.Width, 0), opacity: 1 ); g.DrawImage( image: dtxImg, location: new Point(texImg.Width + atxImg.Width, 0), opacity: 1 ); g.DrawImage( image: pacImg, location: new Point(texImg.Width + atxImg.Width + dtxImg.Width, 0), opacity: 1 ); }); texImg.Dispose(); atxImg.Dispose(); dtxImg.Dispose(); pacImg.Dispose(); combinedImage.SaveAsPng(outFilePath); combinedImage.Dispose(); }); }
public override void Read(string fileIn) { BinaryReader br = new BinaryReader(File.OpenRead(fileIn)); // Header char[] type = br.ReadChars(4); // "STD " uint unknown_header = br.ReadUInt32(); ushort clrformat = br.ReadUInt16(); ColorFormat format = ColorFormat.colors256; if (clrformat == 0) { format = ColorFormat.colors16; } br.BaseStream.Position = 0x10; // Unknown values // Palette ushort unknown_pal = br.ReadUInt16(); ushort num_colors = br.ReadUInt16(); Color[] colors = Actions.BGR555ToColor(br.ReadBytes(num_colors * 2)); PaletteBase palette = new RawPalette(new Color[][] { colors }, false, format); // Map int tile_width = br.ReadUInt16() * 8; int tile_height = br.ReadUInt16() * 8; int tile_size = tile_width * tile_height; if (tile_height != tile_width) { System.Windows.Forms.MessageBox.Show("Different tile size; height != width"); } int width = br.ReadUInt16() * tile_width; int height = br.ReadUInt16() * tile_height; uint unknown2_map = br.ReadUInt32(); // Padding ? NTFS[] map = new NTFS[width * height / tile_size]; for (int i = 0; i < map.Length; i++) { map[i] = new NTFS(); uint mapv = br.ReadUInt32(); map[i].nTile = (ushort)(mapv & 0xFFFFFF); map[i].nTile /= (ushort)(tile_size / 0x40); map[i].nPalette = (byte)(mapv >> 28); } Set_Map(map, false, width, height); // Image if (clrformat == 2) { format = ColorFormat.A3I5; } else if (clrformat == 3) { format = ColorFormat.A5I3; } else if (clrformat != 0 && clrformat != 1) { System.Windows.Forms.MessageBox.Show("ClrFormat: " + clrformat.ToString()); } byte[] tiles = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position)); ImageBase image = new RawImage(tiles, TileForm.Horizontal, format, width, height, false); image.TileSize = tile_width; br.Close(); pluginHost.Set_Palette(palette); pluginHost.Set_Image(image); pluginHost.Set_Map(this); }
public override void Read(string file) { // It's compressed pluginHost.Decompress(file); string dec_file; sFolder dec_folder = pluginHost.Get_Files(); if (dec_folder.files is List <sFile> ) { dec_file = dec_folder.files[0].path; } else { string tempFile = Path.GetTempFileName(); Byte[] compressFile = new Byte[(new FileInfo(file).Length) - 0x08]; Array.Copy(File.ReadAllBytes(file), 0x08, compressFile, 0, compressFile.Length);; File.WriteAllBytes(tempFile, compressFile); pluginHost.Decompress(tempFile); dec_file = pluginHost.Get_Files().files[0].path; } BinaryReader br = new BinaryReader(File.OpenRead(dec_file)); // Bank info Ekona.Images.Bank[] banks = new Ekona.Images.Bank[br.ReadUInt32()]; uint num_cells = br.ReadUInt32(); uint unknown1 = br.ReadUInt32(); for (int i = 0; i < banks.Length; i++) { uint unk = br.ReadUInt16(); banks[i].oams = new OAM[br.ReadUInt16()]; } // Read cell information for (int i = 0; i < banks.Length; i++) { for (int j = 0; j < banks[i].oams.Length; j++) { banks[i].oams[j].obj1.xOffset = br.ReadInt16(); banks[i].oams[j].obj0.yOffset = br.ReadInt16(); uint size_b = br.ReadUInt32(); byte b1 = (byte)(size_b & 0x03); byte b2 = (byte)((size_b & 0x0C) >> 2); System.Drawing.Size size = Actions.Get_OAMSize(b1, b2); banks[i].oams[j].width = (ushort)size.Width; banks[i].oams[j].height = (ushort)size.Height; banks[i].oams[j].obj2.tileOffset = br.ReadUInt32(); banks[i].oams[j].obj2.index_palette = 0; banks[i].oams[j].num_cell = (ushort)j; } } Set_Banks(banks, 2, false); pluginHost.Set_Sprite(this); // Palette PaletteBase palette; int palette_length = (int)(br.BaseStream.Length - br.BaseStream.Position); Color[][] colors = new Color[1][]; colors[0] = Actions.BGR555ToColor(br.ReadBytes(palette_length)); br.Close(); palette = new RawPalette(colors, false, (palette_length > 0x20) ? ColorFormat.colors256 : ColorFormat.colors16); pluginHost.Set_Palette(palette); }
public override void Read(string file) { BinaryReader br = new BinaryReader(File.OpenRead(file)); info = new SIR0_Info(); PaletteBase palette; ImageBase image; Ekona.Images.Bank bank; // Read header char[] file_id = br.ReadChars(4); uint offset1 = br.ReadUInt32(); uint offset2 = br.ReadUInt32(); uint unknown = br.ReadUInt32(); String name = ""; do { byte c = br.ReadByte(); if (c == 0xAA) { c = 0x00; } name += (char)c; } while (name[name.Length - 1] != '\x0'); // Read info section // Info 1 br.BaseStream.Position = offset1; info.info1 = new SIR0_Info.Info1(); info.info1.constant = br.ReadUInt32(); info.info1.reserved = br.ReadBytes(0x3C); info.info1.info3_offset = br.ReadUInt32(); info.info1.reserved2 = br.ReadBytes((int)(offset2 - offset1)); // Info 2 br.BaseStream.Position = offset2; info.info2 = new SIR0_Info.Info2(); info.info2.unknown = br.ReadBytes(0x10); // Info 3 br.BaseStream.Position = info.info1.info3_offset; info.info3 = new SIR0_Info.Info3(); info.info3.tile_size = br.ReadUInt32(); info.info3.unknown1 = br.ReadUInt32(); info.info3.unknown2 = br.ReadUInt32(); info.info3.unknown3 = br.ReadUInt32(); info.info3.unknown4 = br.ReadUInt32(); info.info3.palette_offset = br.ReadUInt32(); info.info3.tile_offset = br.ReadUInt32(); info.info3.cell_offset = br.ReadUInt32(); info.info3.unknown5 = br.ReadUInt32(); info.info3.reserved = br.ReadBytes(0x3C); // Read palette br.BaseStream.Position = info.info3.palette_offset; Color[][] colors = new Color[1][]; colors[0] = Actions.BGR555ToColor(br.ReadBytes(0x200)); palette = new RawPalette(colors, false, ColorFormat.colors256, ""); // Read tiles br.BaseStream.Position = info.info3.tile_offset; byte[] tiles = new byte[info.info3.tile_size]; tiles = br.ReadBytes((int)info.info3.tile_size); image = new RawImage(tiles, TileForm.Lineal, ColorFormat.colors256, 0x40, (int)(info.info3.tile_size / 0x40), false, ""); // Read cell info uint bank_size; if (info.info3.unknown5 != 0x00) { bank_size = info.info3.unknown5 - info.info3.cell_offset - 0x06; } else { bank_size = info.info1.info3_offset - info.info3.cell_offset - 0x06; } br.BaseStream.Position = info.info3.cell_offset; bank = new Ekona.Images.Bank(); bank.oams = new OAM[bank_size / 0x0A]; for (int i = 0; i < bank.oams.Length; i++) { bank.oams[i].width = br.ReadUInt16(); bank.oams[i].height = br.ReadUInt16(); bank.oams[i].obj1.xOffset = br.ReadUInt16() - 0x80; bank.oams[i].obj0.yOffset = br.ReadUInt16() - 0x80; bank.oams[i].obj2.tileOffset = (uint)(br.ReadUInt16() / 0x20); bank.oams[i].num_cell = (ushort)i; } Set_Banks(new Ekona.Images.Bank[] { bank }, 0, false); br.Close(); pluginHost.Set_Palette(palette); pluginHost.Set_Image(image); pluginHost.Set_Sprite(this); }
public Format Read2(sFile file) { string ext = ""; if (file.size >= 4) { using (BinaryReader br = new BinaryReader(File.OpenRead(file.path))) { ext = new String(Encoding.ASCII.GetChars(br.ReadBytes(4))); br.Close(); } } // Palette if (file.name.ToUpper().EndsWith(".NTFP") || file.name.ToUpper().EndsWith(".PLT")) { RawPalette palette = new RawPalette(file.path, file.id, true, 0, -1, file.name); pluginHost.Set_Palette(palette); return(Format.Palette); } else if (ext == "RLCN") { PaletteBase palette = new NCLR(file.path, file.id, file.name); pluginHost.Set_Palette(palette); return(Format.Palette); } else if (ext == "NCCL") { NCCL palette = new NCCL(file.path, file.id, file.name); pluginHost.Set_Palette(palette); return(Format.Palette); } else if (file.name.ToUpper().EndsWith(".NBFP")) { RawPalette palette = new RawPalette(file.path, file.id, true, 0, -1, file.name); pluginHost.Set_Palette(palette); return(Format.Palette); } else if (file.name.ToUpper().EndsWith(".NCL.L") && ext[0] != '\x10') { RawPalette palette = new RawPalette(file.path, file.id, true, 0, -1, file.name); pluginHost.Set_Palette(palette); return(Format.Palette); } // Tile ColorFormat depth = ColorFormat.colors256; if (pluginHost.Get_Palette().Loaded) { depth = pluginHost.Get_Palette().Depth; } if (file.name.ToUpper().EndsWith(".NTFT")) { RawImage image = new RawImage(file.path, file.id, TileForm.Lineal, depth, true, 0, -1, file.name); pluginHost.Set_Image(image); return(Format.Tile); } else if (ext == "RGCN" || ext == "RBCN") { NCGR ncgr = new NCGR(file.path, file.id, file.name); pluginHost.Set_Image(ncgr); return(Format.Tile); } else if (ext == "NCCG") { NCCG image = new NCCG(file.path, file.id, file.name); pluginHost.Set_Image(image); return(Format.Tile); } else if (file.name.ToUpper().EndsWith(".NBFC") || file.name.ToUpper().EndsWith(".CHAR")) { RawImage image = new RawImage(file.path, file.id, TileForm.Horizontal, depth, true, 0, -1, file.name); pluginHost.Set_Image(image); return(Format.Tile); } else if (file.name.ToUpper().EndsWith(".NCG.L") && ext[0] != '\x10') { RawImage image = new RawImage(file.path, file.id, TileForm.Horizontal, depth, true, 0, -1, file.name); pluginHost.Set_Image(image); return(Format.Tile); } // Map if (file.name.ToUpper().EndsWith(".NBFS")) { RawMap map = new RawMap(file.path, file.id, 0, -1, true, file.name); pluginHost.Set_Map(map); return(Format.Map); } else if (ext == "RCSN") { NSCR nscr = new NSCR(file.path, file.id, file.name); pluginHost.Set_Map(nscr); return(Format.Map); } else if (ext == "NCSC") { NCSC map = new NCSC(file.path, file.id, file.name); pluginHost.Set_Map(map); return(Format.Map); } else if (file.name.ToUpper().EndsWith(".NSC.L") && ext[0] != '\x10') { RawMap map = new RawMap(file.path, file.id, 0, -1, true, file.name); pluginHost.Set_Map(map); return(Format.Map); } // Sprite if (ext == "NCOB") { NCOB sprite = new NCOB(file.path, file.id, file.name); pluginHost.Set_Sprite(sprite); pluginHost.Set_Image(sprite.Image); return(Format.Cell); } else if (ext == "RECN") { NCER ncer = new NCER(file.path, file.id, file.name); pluginHost.Set_Sprite(ncer); return(Format.Cell); } // Animation if (ext == "RNAN") { nanr = new NANR(pluginHost, file.path, file.id); return(Format.Animation); } return(Format.Unknown); }
public void GetFilesToPatch(ConcurrentBag <FileToPatch> filesToPatch, IGraphicsInfo gInfo) { if (!(gInfo is PkmdlConstants pkmdlInfo)) { return; } var spriteFiles = _overrideSpriteProvider.GetAllSpriteFiles(pkmdlInfo.Type); if (!spriteFiles.Any(i => i.IsOverride)) { return; } // temporary link files string texLink = Path.GetTempFileName(); string atxLink = Path.GetTempFileName(); string dtxLink = Path.GetTempFileName(); string pacLink = Path.GetTempFileName(); // link files unpacked previously string texUnpacked = Path.Combine(_graphicsProviderFolder, pkmdlInfo.TEXLinkFolder); string atxUnpacked = Path.Combine(_graphicsProviderFolder, pkmdlInfo.ATXLinkFolder); string dtxUnpacked = Path.Combine(_graphicsProviderFolder, pkmdlInfo.DTXLinkFolder); string pacUnpacked = Path.Combine(_graphicsProviderFolder, pkmdlInfo.PACLinkFolder); var spriteFileDict = spriteFiles.ToDictionary(i => i.Id); var texLinkFiles = new string[200]; var atxLinkFiles = new string[200]; var dtxLinkFiles = new string[200]; var pacLinkFiles = new string[200]; Parallel.For(0, 200, i => { string fileName = i.ToString().PadLeft(4, '0'); var spriteFile = spriteFileDict[i]; if (spriteFile.IsOverride) { using (var combinedImage = Image.Load <Rgba32>(spriteFile.File)) { // populate palette ------------------------------------------------------------------------------------------------------ var palette = new List <Rgba32> { Color.Transparent }; // TEX ------------------------------------------------------------------------------------------------------ string texSource = Path.Combine(texUnpacked, fileName); string texTemp = Path.GetTempFileName(); File.Copy(texSource, texTemp, true); BTX0 btx0 = new BTX0(texSource); int height = btx0.Texture.PixelMap.Length / _pokemonSpriteWidth; using (var texImg = combinedImage.Clone(g => { g.Crop(new Rectangle(0, 0, _pokemonSpriteWidth, height)); })) { btx0.Texture.PixelMap = ImageUtil.FromImage(texImg, palette, PointUtil.GetIndex); } // ATX ------------------------------------------------------------------------------------------------------ var atxDecompressedLen = new FileInfo(Path.Combine(atxUnpacked, fileName)).Length * 2; using (var atxImg = combinedImage.Clone(g => { g.Crop(new Rectangle(_pokemonSpriteWidth, 0, _pokemonSpriteWidth, (int)(atxDecompressedLen / _pokemonSpriteWidth))); })) { string atxTemp = Path.GetTempFileName(); File.WriteAllBytes(atxTemp, RawChar.Compress(ImageUtil.FromImage(atxImg, palette, PointUtil.GetIndex))); atxLinkFiles[i] = atxTemp; } // DTX ------------------------------------------------------------------------------------------------------ var dtxDecompressedLen = new FileInfo(Path.Combine(atxUnpacked, fileName)).Length * 2; using (var dtxImg = combinedImage.Clone(g => { g.Crop(new Rectangle(_pokemonSpriteWidth * 2, 0, _pokemonSpriteWidth, (int)(dtxDecompressedLen / _pokemonSpriteWidth))); })) { string dtxTemp = Path.GetTempFileName(); File.WriteAllBytes(dtxTemp, RawChar.Compress(ImageUtil.FromImage(dtxImg, palette, PointUtil.GetIndex))); dtxLinkFiles[i] = dtxTemp; } // PAC ------------------------------------------------------------------------------------------------------ string pacUnpackedFolder = Path.Combine(pacUnpacked, fileName + "-Unpacked"); var pacDecompressedLen = new FileInfo(Path.Combine(pacUnpackedFolder, "0003")).Length * 2; using (var pacImg = combinedImage.Clone(g => { g.Crop(new Rectangle(_pokemonSpriteWidth * 3, 0, _pokemonSpriteWidth, (int)(pacDecompressedLen / _pokemonSpriteWidth))); })) { string pacCharTemp = Path.GetTempFileName(); File.WriteAllBytes(pacCharTemp, RawChar.Compress(ImageUtil.FromImage(pacImg, palette, PointUtil.GetIndex))); string pacTemp = Path.GetTempFileName(); string[] pacFiles = new string[] { Path.Combine(pacUnpackedFolder, "0000"), Path.Combine(pacUnpackedFolder, "0001"), Path.Combine(pacUnpackedFolder, "0002"), pacCharTemp }; PAC.Pack(pacFiles, new[] { 0, 2, 5, 6 }, pacTemp, 1); File.Delete(pacCharTemp); pacLinkFiles[i] = pacTemp; } // TEX Palette ------------------------------------------------------------------------------------------- if (palette.Count > 16) { throw new System.Exception($"More than 16 colors in image when building tex file in {nameof(PkmdlPatchBuilder)}. This should have been filtered out by palette simplifier"); } var resizedPalette = new Rgba32[16]; for (int paletteIndex = 0; paletteIndex < palette.Count; paletteIndex++) { resizedPalette[paletteIndex] = palette[paletteIndex]; } resizedPalette[0] = Color.FromRgb(120, 120, 120); var convertedPalette = RawPalette.From32bitColors(resizedPalette); btx0.Texture.Palette1 = convertedPalette; btx0.Texture.Palette2 = convertedPalette; btx0.WriteTo(texTemp); texLinkFiles[i] = texTemp; } } else { texLinkFiles[i] = Path.Combine(texUnpacked, fileName); atxLinkFiles[i] = Path.Combine(atxUnpacked, fileName); dtxLinkFiles[i] = Path.Combine(dtxUnpacked, fileName); pacLinkFiles[i] = Path.Combine(pacUnpacked, fileName); } }); LINK.Pack(texLinkFiles, texLink); LINK.Pack(atxLinkFiles, atxLink); LINK.Pack(dtxLinkFiles, dtxLink); LINK.Pack(pacLinkFiles, pacLink); filesToPatch.Add(new FileToPatch(pkmdlInfo.TEXLink, texLink, FilePatchOptions.DeleteSourceWhenDone | FilePatchOptions.VariableLength)); filesToPatch.Add(new FileToPatch(pkmdlInfo.ATXLink, atxLink, FilePatchOptions.DeleteSourceWhenDone | FilePatchOptions.VariableLength)); filesToPatch.Add(new FileToPatch(pkmdlInfo.DTXLink, dtxLink, FilePatchOptions.DeleteSourceWhenDone | FilePatchOptions.VariableLength)); filesToPatch.Add(new FileToPatch(pkmdlInfo.PACLink, pacLink, FilePatchOptions.DeleteSourceWhenDone | FilePatchOptions.VariableLength)); }
public override void Read(string fileIn) { byte[] data = File.ReadAllBytes(fileIn); byte paletteType = data[5]; byte paletteSize = data[6]; short width = BitConverter.ToInt16(data, 8); short height = BitConverter.ToInt16(data, 10); int paletteEnd = paletteSize * 32 + 12; int startPalette = 12; int position = startPalette; if (BitConverter.ToInt32(data, position) == 0) { position += 4; while (BitConverter.ToInt32(data, position) == 0) { position += 4; } startPalette = position; } int paletteActualSize = paletteEnd - startPalette; position = startPalette; ColorFormat format; RawPalette palette; if (paletteType == 16) { int paletteColors = 16; int paletteColorSize = paletteColors * 2; format = ColorFormat.colors16; Color[][] palettes; decimal paletteNumber = Math.Ceiling((decimal)paletteActualSize / paletteColorSize); palettes = new Color[(int)paletteNumber][]; for (int i = 0; i < paletteNumber; i++) { byte[] aux = new byte[paletteColorSize]; Array.Copy(data, position, aux, 0, paletteColorSize); palettes[i] = Actions.BGR555ToColor(aux); } palette = new RawPalette(palettes, false, format); } else { format = ColorFormat.colors256; byte[] aux = new byte[paletteActualSize]; Array.Copy(data, position, aux, 0, paletteActualSize); Color[] p = Actions.BGR555ToColor(aux); palette = new RawPalette(new Color[][] { p }, false, format); } position = paletteEnd; pluginHost.Set_Palette(palette); // Get image byte[] tiles = new byte[data.Length - position]; Array.Copy(data, position, tiles, 0, data.Length - position); Set_Tiles(tiles, width, height, format, TileForm.Horizontal, false); pluginHost.Set_Image(this); }
public void Convert32To15() { RawPalette.From32bitColors(_colorsRgba32).Should().Equal(_colorsRgb15); }
public void Convert15To32() { RawPalette.To32bitColors(_colorsRgb15).Should().Equal(_colorsRgba32); }