Beispiel #1
0
        public MPQDCC(byte[] data, Palette palette)
        {
            var bm = new BitMuncher(data);

            Signature = bm.GetByte();
            if (Signature != 0x74)
            {
                throw new OpenDiablo2Exception("Signature expected to be 0x74 but it is not.");
            }

            Version            = bm.GetByte();
            NumberOfDirections = bm.GetByte();
            FramesPerDirection = bm.GetInt32();

            if (bm.GetInt32() != 1)
            {
                throw new OpenDiablo2Exception("This value isn't 1. It has to be 1.");
            }

            bm.GetInt32(); // TotalSizeCoded
            var directionOffsets = new int[NumberOfDirections];

            for (var i = 0; i < NumberOfDirections; i++)
            {
                directionOffsets[i] = bm.GetInt32();
            }

            Directions = new MPQDCCDirection[NumberOfDirections];
            for (var i = 0; i < NumberOfDirections; i++)
            {
                Directions[i] = new MPQDCCDirection(new BitMuncher(data, directionOffsets[i] * 8), this);
            }
        }
Beispiel #2
0
            public MPQDCCDirectionFrame(BitMuncher bits, MPQDCCDirection direction)
            {
                bits.GetBits(direction.Variable0Bits); // Variable0
                Width   = (int)bits.GetBits(direction.WidthBits);
                Height  = (int)bits.GetBits(direction.HeightBits);
                XOffset = bits.GetSignedBits(direction.XOffsetBits);
                YOffset = bits.GetSignedBits(direction.YOffsetBits);
                NumberOfOptionalBytes = (int)bits.GetBits(direction.OptionalDataBits);
                NumberOfCodedBytes    = (int)bits.GetBits(direction.CodedBytesBits);
                FrameIsBottomUp       = bits.GetBit() == 1;

                Box = new Rectangle(
                    XOffset,
                    YOffset - Height + 1,
                    Width,
                    Height
                    );
            }
Beispiel #3
0
            public void CalculateCells(MPQDCCDirection direction)
            {
                var w = 4 - ((Box.Left - direction.Box.Left) % 4); // Width of the first column (in pixels)

                if ((Width - w) <= 1)
                {
                    HorizontalCellCount = 1;
                }
                else
                {
                    var tmp = Width - w - 1;
                    HorizontalCellCount = 2 + (tmp / 4);
                    if ((tmp % 4) == 0)
                    {
                        HorizontalCellCount--;
                    }
                }


                var h = 4 - ((Box.Top - direction.Box.Top) % 4); // Height of the first column (in pixels)

                if ((Height - h) <= 1)
                {
                    VerticalCellCount = 1;
                }
                else
                {
                    var tmp = Height - h - 1;
                    VerticalCellCount = 2 + (tmp / 4);
                    if ((tmp % 4) == 0)
                    {
                        VerticalCellCount--;
                    }
                }

                Cells = new Cell[HorizontalCellCount * VerticalCellCount];

                // Calculate the cell widths and heights
                var cellWidths = new int[HorizontalCellCount];

                if (HorizontalCellCount == 1)
                {
                    cellWidths[0] = Width;
                }
                else
                {
                    cellWidths[0] = w;
                    for (var i = 1; i < (HorizontalCellCount - 1); i++)
                    {
                        cellWidths[i] = 4;
                    }
                    cellWidths[HorizontalCellCount - 1] = Width - w - (4 * (HorizontalCellCount - 2));
                }

                var cellHeights = new int[VerticalCellCount];

                if (VerticalCellCount == 1)
                {
                    cellHeights[0] = Height;
                }
                else
                {
                    cellHeights[0] = h;
                    for (var i = 1; i < (VerticalCellCount - 1); i++)
                    {
                        cellHeights[i] = 4;
                    }
                    cellHeights[VerticalCellCount - 1] = Height - h - (4 * (VerticalCellCount - 2));
                }

                Cells = new Cell[HorizontalCellCount * VerticalCellCount];
                var offsetY = Box.Top - direction.Box.Top;

                for (var y = 0; y < VerticalCellCount; y++)
                {
                    var offsetX = Box.Left - direction.Box.Left;
                    for (var x = 0; x < HorizontalCellCount; x++)
                    {
                        Cells[x + (y * HorizontalCellCount)] = new Cell
                        {
                            XOffset = offsetX,
                            YOffset = offsetY,
                            Width   = cellWidths[x],
                            Height  = cellHeights[y]
                        };
                        offsetX += cellWidths[x];
                    }
                    offsetY += cellHeights[y];
                }
            }