void ReadIconAndTitle(int iconAndTitleOffset) { if (iconAndTitleOffset == 0) { return; } // Read the palette. Reader.BaseStream.Position = iconAndTitleOffset + 0x220; Color[] colors = new Color[16]; for (int index = 0; index < 16; index++) { Reader.ReadNDSColor(forceTransparent: index == 0); } PaletteAsset palette = new PaletteAsset(Manager, "Icon palette", colors); // Read the icon. Reader.BaseStream.Position = iconAndTitleOffset + 0x20; Vector2i iconSize = new Vector2i(32, 32); Vector2i tileSize = iconSize / 8; int[] indices = new int[iconSize.X * iconSize.Y]; for (Vector2i tile = Vector2i.Zero; tile.Y < tileSize.Y; tile.Y++) { for (tile.X = 0; tile.X < tileSize.X; tile.X++) { for (Vector2i pixel = Vector2i.Zero; pixel.Y < 8; pixel.Y++) { for (pixel.X = 0; pixel.X < 4; pixel.X++) { int x = pixel.X + tile.X * 4; int y = pixel.Y + tile.Y * 8; int offset = x + y * iconSize.X; byte pair = Reader.ReadByte(); indices[offset + 0] = pair & 0x0F; indices[offset + 1] = pair >> 4; } } } } Icon = new IndexedTextureAsset(Manager, "Icon", palette, iconSize.X, iconSize.Y, indices); // Read the title. Name = Reader.ReadStringzAt(iconAndTitleOffset + 0x240, Encoding.Unicode); TitleEnglish = Reader.ReadStringzAt(iconAndTitleOffset + 0x340, Encoding.Unicode); TitleFrench = Reader.ReadStringzAt(iconAndTitleOffset + 0x440, Encoding.Unicode); TitleGerman = Reader.ReadStringzAt(iconAndTitleOffset + 0x540, Encoding.Unicode); TitleItalian = Reader.ReadStringzAt(iconAndTitleOffset + 0x640, Encoding.Unicode); TitleSpanish = Reader.ReadStringzAt(iconAndTitleOffset + 0x740, Encoding.Unicode); }
internal Image(AssetManager manager, BinaryReader reader, string name, Asset context) : base(manager, name) { using (reader) { int height = reader.ReadByte(); int width = reader.ReadByte() * 8; reader.RequireZeroes(4); int frameCount = reader.ReadUInt16(); if (frameCount == 0) { throw new InvalidDataException(); } byte baseColorIndex = reader.ReadByte(); int colorCount = reader.ReadByte() + 1; // Need to initialize palette. Color[] colors = new Color[256]; for (int index = 0; index < 16; index++) { colors[index] = Raster.DefaultEgaColors[index]; } for (int index = 0; index < colorCount; index++) { colors[index + baseColorIndex] = Color.FromArgb(reader.ReadByte() * 255 / 63, reader.ReadByte() * 255 / 63, reader.ReadByte() * 255 / 63); } PaletteAsset palette = new PaletteAsset(Manager, Name + " palette", colors); Unknowns.ReadBytes(reader, (colorCount + 1) / 2); // EGA color map, two colours per byte. Unknowns.ReadBytes(reader, 4); int remaining = checked ((int)(reader.BaseStream.Length - reader.BaseStream.Position)); if (remaining == width * height * frameCount + 28) { Unknowns.ReadBytes(reader, 28); remaining -= 28; } if (remaining != width * height * frameCount || (height != 0 && remaining % height != 0)) { throw new InvalidDataException("Expected file length is not correct."); } int[] indices = new int[width * height]; if (width == 0 || height == 0) { AddChild(palette); } else { for (int index = 0; index < frameCount; index++) { reader.ReadBytesAsInt32(indices, 0, indices.Length); var resource = new IndexedTextureAsset(Manager, "Frame " + index, palette, width, height, indices); AddChild(resource); } } // Hack for "over.dax" files to use their multiple palettes. if (context is ArchiveRecord && ((ArchiveRecord)context).Id >= 51 && string.Equals(Path.GetFileName(context.Parent.Name), "over.dax", StringComparison.InvariantCultureIgnoreCase)) { Archive archive = (Archive)context.Parent; for (int id = 1; id <= 4; id++) { palette = (PaletteAsset)archive.RecordsById[id].Contents.Children[0]; var frame = new IndexedTextureAsset(Manager, "Palette " + id, palette, width, height, indices); AddChild(frame); } } } }