internal Palette(AssetLoader loader)
: base(loader)
{
BinaryReader reader = loader.Reader;
Unknowns.ReadBytes(reader, 25); // Offset 0-24
int firstIndex = reader.ReadByte(); // Offset 25-25
Unknowns.ReadBytes(reader, 3); // Offset 26-28
int count = reader.ReadUInt16(); // Offset 29-30
Unknowns.ReadBytes(reader, 1); // Offset 31-31
byte format = reader.ReadByte(); // Offset 32-32
Unknowns.ReadBytes(reader, 4); // Offset 33-36
// Offset 37
PaletteColor[] colors = new PaletteColor[count];
Colors = new ReadOnlyCollection<PaletteColor>(colors);
FlatColors = new Codex<Color>(256);
for (int index = 0; index < firstIndex; index++)
FlatColors.Add(Color.Purple);
for (int index = 0; index < count; index++) {
PaletteColor color;
switch (format) {
case 0: // Variable (byte used, byte red, byte green, byte blue)
color = new PaletteColor(reader.ReadByte() != 0, reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
break;
case 1: // Constant (byte red, byte green, byte blue)
color = new PaletteColor(reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
break;
default:
throw new NotImplementedException();
}
colors[index] = color;
FlatColors.Add(color);
}
PaletteAsset = new PaletteAsset(Manager, Name ?? "Palette", FlatColors);
}