struct CPVS
{
int[] Indices;
byte[] Data;
public int Length => Indices.Length - 1;
public CPVS(BinaryReader reader)
{
if (reader.ReadUInt32() != 0x30535650 /*PVS0*/)
{
throw new Exception("Invalid Magic");
}
Indices = new int[reader.ReadUInt32()];
Indices[0] = 0;
for (int i = 1; i < Indices.Length; ++i)
Indices[i] = reader.ReadInt32();
Data = reader.ReadBytes((int) (reader.BaseStream.Length - reader.BaseStream.Position));
}
public byte[] Decompress(int index)
{
byte[] result = new byte[512];
for (int input = Indices[index], output = 0; input < Indices[index + 1];)
{
byte size = Data[input++];
if (size >= 128) // Copy
{
size -= 127;
for (int j = 0; j < size; ++j)
result[output++] = Data[input++];
}
else // Fill
{
byte value = Data[input++];
for (int j = 0; j < size; ++j)
result[output++] = value;
}
}
return result;
}
}
Comments
0 B
|👍
/👎