NScumm.Scumm.IO.ResourceFile0.ReadBoxes C# (CSharp) Method

ReadBoxes() private method

private ReadBoxes ( long offset, Room room ) : void
offset long
room Room
return void
        void ReadBoxes(long offset, Room room)
        {
            _reader.BaseStream.Seek(offset, SeekOrigin.Begin);
            byte x1;
            while ((x1 = _reader.ReadByte()) != 0xFF)
            {
                byte x2 = _reader.ReadByte();
                byte y1 = _reader.ReadByte();
                byte y2 = _reader.ReadByte();
                byte mask = _reader.ReadByte();
                var box = new Box
                {
                    Ulx = x1,
                    Uly = y1,
                    Urx = x2,
                    Ury = y1,
                    Llx = x1,
                    Lly = y2,
                    Lrx = x2,
                    Lry = y2,
                    Mask = mask,
                };

                if ((mask & 0x88) == 0x88)
                {
                    // walkbox for (right/left) corner
                    if ((mask & 0x04) != 0)
                    {
                        box.Urx = box.Ulx;
                        box.Ury = box.Uly;
                    }
                    else
                    {
                        box.Ulx = box.Urx;
                        box.Uly = box.Ury;
                    }
                }
                room.Boxes.Add(box);
            }

            var size = 0;
            var pos = _reader.BaseStream.Position;
            // Compute matrix size
            for (var i = 0; i < room.Boxes.Count; i++)
            {
                while (_reader.ReadByte() != 0xFF)
                {
                    size++;
                }
                size++;
            }

            _reader.BaseStream.Position = pos;
            room.BoxMatrix.AddRange(_reader.ReadBytes(size));
        }
    }