public byte[] TextureData;                     // varying length texture data

        public DLCVillager()
        {
            Header = new DLCVillagerHeader();
            unsafe
            {
                fixed(byte *name = Header.Name)
                {
                    Utility.DnMStringToBytePtr(name, "Animal", 6);
                }

                fixed(byte *catchphrase = Header.Catchphrase)
                {
                    Utility.DnMStringToBytePtr(catchphrase, "none", 4);
                }
            }

            Header.CardId = byte.MaxValue;
            Header.Model  = ModelType.Cat;
            Header.HouseRoomBaseLayerInfoId   = 0x1A0;
            Header.HouseRoomSecondLayerInfoId = 0x1A1;
            TextureData = new byte[VillagerDatabase.GetImageDataSize(Header.Model)];
        }
        public DLCVillager(Stream villagerFile)
        {
            using (var reader = new BinaryReader(villagerFile))
            {
                Header = StructReader.ReadStruct <DLCVillagerHeader>(villagerFile);
                //Header.HouseRoomBaseLayerInfoId = Header.HouseRoomBaseLayerInfoId.Reverse();
                //Header.HouseRoomSecondLayerInfoId = Header.HouseRoomSecondLayerInfoId.Reverse();

                if (Header.HouseRoomBaseLayerInfoId < 0x1A0)
                {
                    Header.HouseRoomBaseLayerInfoId = 0x1A0;
                }

                if (Header.HouseRoomSecondLayerInfoId < 0x1A0)
                {
                    Header.HouseRoomSecondLayerInfoId = 0x1A0;
                }

                //Header.Unknown1 = Header.Unknown1.Reverse(); // Swap endianness
                villagerFile.Seek(0x25, SeekOrigin.Begin);
                villagerFile.Read(GBATextureData, 0, 0x800);

                for (var i = 0; i < 16; i++)
                {
                    GBAPalette[i] = reader.ReadUInt16().Reverse();
                }

                // Test
                var outputLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                                  "AFe_GBA_Textures");
                Directory.CreateDirectory(outputLocation);

                for (var i = 0; i < 16; i++)
                {
                    var texture = new GBATexture(GBATextureData.Skip(i * 0x80).Take(0x80).ToArray(), GBAPalette,
                                                 new Size(16, 16));

                    texture.Texture.Save(Path.Combine(outputLocation, $"Texture_{i}.png"), ImageFormat.Png);
                }

                // Dump palette.
                var gbaPalette = GBAPalette.Select(GCNToolKit.Formats.Colors.RGB5A3.ToARGB8).Select(c => Color.FromArgb((int)c)).ToArray();
                var bmp        = new Bitmap(32, 32 * 16);
                for (var i = 0; i < 16; i++)
                {
                    for (var y = 0; y < 32; y++)
                    {
                        for (var x = 0; x < 32; x++)
                        {
                            bmp.SetPixel(x, y + i * 32, gbaPalette[i]);
                        }
                    }
                }

                bmp.Save(Path.Combine(outputLocation, "Palette.png"), ImageFormat.Png);
                bmp.Dispose();

                villagerFile.Seek(0x845, SeekOrigin.Begin);
                for (var i = 0; i < 16; i++)
                {
                    Palette[i] = reader.ReadUInt16().Reverse();
                }

                TextureData = new byte[villagerFile.Length - 0x865];
                villagerFile.Seek(0x865, SeekOrigin.Begin);
                villagerFile.Read(TextureData, 0, TextureData.Length);
            }
        }