internal ExteriorChunkArea(ExteriorChunk chunk, bool isExterior, BinaryReader reader)
            : base(chunk.State)
        {
            Chunk = chunk;

            byte modelCount   = reader.ReadByte();
            byte flatCount    = reader.ReadByte();
            byte sectionCount = reader.ReadByte();
            byte personCount  = reader.ReadByte();
            byte doorCount    = reader.ReadByte();

            Unknowns.Add("a", reader.ReadUInt16());
            Unknowns.Add("b", reader.ReadUInt16()); // always non-zero
            Unknowns.Add("c", reader.ReadUInt16());
            Unknowns.Add("d", reader.ReadUInt16()); // always non-zero
            Unknowns.Add("e", reader.ReadUInt16()); // always non-zero
            Unknowns.Add("f", reader.ReadUInt16()); // always non-zero

            ExteriorChunkModel[] models = new ExteriorChunkModel[modelCount];
            for (int index = 0; index < modelCount; index++)
            {
                models[index] = new ExteriorChunkModel(this, index, reader);
            }
            Models = new ReadOnlyCollection <ExteriorChunkModel>(models);

            ExteriorChunkFlat[] flats = new ExteriorChunkFlat[flatCount];
            for (int index = 0; index < flatCount; index++)
            {
                flats[index] = new ExteriorChunkFlat(this, index, reader);
            }
            Flats = new ReadOnlyCollection <ExteriorChunkFlat>(flats);

            ExteriorChunkSection[] sections = new ExteriorChunkSection[sectionCount];
            for (int index = 0; index < sectionCount; index++)
            {
                sections[index] = new ExteriorChunkSection(this, index, reader);
            }
            Sections = new ReadOnlyCollection <ExteriorChunkSection>(sections);

            ExteriorChunkPerson[] persons = new ExteriorChunkPerson[personCount];
            for (int index = 0; index < personCount; index++)
            {
                persons[index] = new ExteriorChunkPerson(this, index, reader);
            }
            Persons = new ReadOnlyCollection <ExteriorChunkPerson>(persons);

            ExteriorChunkDoor[] doors = new ExteriorChunkDoor[doorCount];
            for (int index = 0; index < doorCount; index++)
            {
                doors[index] = new ExteriorChunkDoor(this, index, reader);
            }
            Doors = new ReadOnlyCollection <ExteriorChunkDoor>(doors);
            if (doorCount > 0 || sectionCount > 0 || personCount > 0)
            {
            }
        }
        internal ExteriorBlock(State state, BinaryReader reader, BlockArchive.Record record) : base(state, reader)
        {
            this.ChunkCount = reader.ReadByte();
            int modelCount = reader.ReadByte();
            int flatCount  = reader.ReadByte();

            for (int index = 0; index < Chunks.Length; index++)
            {
                Chunks[index] = new ExteriorChunk(this, reader, index);
            }
            for (int index = 0; index < Chunks.Length; index++)
            {
                Chunks[index].building = new Building(null, this, index, reader);
            }
            for (int index = 0; index < Chunks.Length; index++)
            {
                Chunks[index].Unknowns.Add(reader.ReadUInt16());
                Chunks[index].Unknowns.Add(reader.ReadUInt16());
            }

            int[] chunkSizeList = new int[32];
            for (int index = 0; index < chunkSizeList.Length; index++)
            {
                chunkSizeList[index] = reader.ReadInt32();
            }

            U1 = reader.ReadBytes(8);
            for (int y = 0, yCount = Ground.GetLength(1); y < yCount; y++)
            {
                for (int x = 0, xCount = Ground.GetLength(0); x < xCount; x++)
                {
                    Ground[x, y] = new Ground(reader.ReadByte());
                }
            }
            U2 = reader.ReadBytes(256);

            for (int y = 0, yCount = Automap.GetLength(1); y < yCount; y++)
            {
                for (int x = 0, xCount = Automap.GetLength(0); x < xCount; x++)
                {
                    Automap[x, y] = reader.ReadByte();
                }
            }

            string filename = reader.ReadNulTerminatedAsciiString(13);

            if (filename != record.Key)
            {
                throw new Exception();
            }
            for (int index = 0; index < Chunks.Length; index++)
            {
                Chunks[index].LoadFilename(reader);
            }

            for (int index = 0; index < ChunkCount; index++)
            {
                long start = reader.BaseStream.Position;
                Chunks[index].LoadContents(reader);
                int  required = chunkSizeList[index];
                long size     = reader.BaseStream.Position - start;

                if (size == required - 1)
                {
                    reader.ReadByte();
                    size++;
                }

                if (required != size)
                {
                    throw new Exception();
                }
            }
        }