Exemplo n.º 1
0
        private void processWallSet(DaxFileBlock daxFileBlock)
        {
            byte[] data = daxFileBlock.Data;
            _blockIds.Add(daxFileBlock.Id);
            wallsets.Add(assembleWallSet(daxFileBlock, FileName, daxFileBlock.Id));

        }
Exemplo n.º 2
0
        public bool IsSatisfiedBy(DaxFileBlock block)
        {
            var length = block.Data.Length;

            if (length < 9)
            {
                return(false);
            }

            uint height  = ArrayToUshort(block.Data, 0);
            uint width   = ArrayToUshort(block.Data, 2);
            var  widthPx = width * 8;

            if (widthPx == 0 || height == 0 || widthPx > 320 || height > 200)
            {
                return(false);
            }

            uint itemCount = block.Data[8];

            const int egaDataOffset = 17;
            var       egaDataSize   = height * width * 4;

            if (block.Data.Length == (egaDataSize * (itemCount + 1)) + egaDataOffset)
            {
                // Death Knights of Krynn
                itemCount += 1;
            }

            return(block.Data.Length == ((egaDataSize * itemCount) + egaDataOffset));
        }
Exemplo n.º 3
0
        public bool IsSatisfiedBy(DaxFileBlock block)
        {
            var data = block.Data;

            if (data.Length < 20)
            {
                return(false);
            }

            int height = ArrayToUshort(data, 0);
            int width  = ArrayToUshort(data, 2);

            var widthPx  = width * 8;
            var heightPx = height;

            if (widthPx < 1 || heightPx < 1 || widthPx > 320 || heightPx > 200)
            {
                return(false);
            }

            int picCount = data[8];

            var dataOffset = getDataOffset(9, data);
            var dataLen    = (((5 * width * height) * picCount) + dataOffset);

            if (data.Length != dataLen)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        private bool isCombatPicture = false; // images used in combat mode have a slightly different EGA palette (colors 0 and 8 are swapped)
        public EgaBlock(DaxFileBlock block)
        {
            setBlockId(block.Id);
            var       data          = block.Data;
            uint      height        = ArrayToUshort(data, 0);
            uint      width         = ArrayToUshort(data, 2);
            uint      xPos          = ArrayToUshort(data, 4);
            uint      yPos          = ArrayToUshort(data, 6);
            uint      itemCount     = data[8];
            var       widthPx       = width * 8;
            var       heightPx      = height;
            var       xPosPx        = xPos * 8;
            var       yPosPx        = yPos * 8;
            const int egaDataOffset = 17;
            var       egaDataSize   = height * width * 4;

            EgaColors = EgaVgaPalette.EgaColors;

            var filename = block.FileNameUpperCase;

            if (filename.Contains("CPIC") || filename.Contains("CHEAD") || filename.Contains("CBODY") ||
                filename.Contains("DUNGCOM") || filename.Contains("WILDCOM") || filename.Contains("RANDCOM") ||
                filename.Contains("COMSPR"))
            {
                isCombatPicture = true;
                EgaColors       = EgaVgaPalette.EgaCombatColors;
            }

            if (data.Length == (egaDataSize * (itemCount + 1)) + egaDataOffset)
            {
                // Death Knights of Krynn
                itemCount += 1;
            }

            if (data.Length == (egaDataSize * itemCount) + egaDataOffset)
            {
                var offset = 0;
                for (var i = 0; i < itemCount; i++, offset += (int)egaDataSize)
                {
                    var bitmap = new Bitmap((int)(widthPx + xPosPx), (int)(heightPx + yPosPx),
                                            PixelFormat.Format16bppArgb1555);
                    for (var y = 0; y < heightPx; y++)
                    {
                        for (var x = 0; x < widthPx; x += 2)
                        {
                            var   b     = data[egaDataOffset + (y * width * 4) + (x / 2) + offset];
                            var   pxX   = (int)(x + 0 + xPosPx);
                            var   pxY   = (int)(y + yPosPx);
                            Color ctest = Color.FromArgb((int)EgaColors[b >> 4]);
                            bitmap.SetPixel(pxX, pxY, Color.FromArgb((int)EgaColors[b >> 4]));
                            bitmap.SetPixel(pxX + 1, pxY, Color.FromArgb((int)EgaColors[b & 0xF]));
                        }
                    }

                    Bitmaps.Add(bitmap);
                }
            }
        }
Exemplo n.º 5
0
        public VgaSpriteBlock(DaxFileBlock block)
        {
            setBlockId(block.Id);
            var data     = block.Data;
            var origData = data;

            int height       = data[0];
            int width        = data[2];
            var widthPx      = width * 8;
            var heightPx     = height;
            int frames       = data[8];
            int clrBase      = data[9];
            int clrCount     = data[10];
            var picSize      = widthPx * heightPx;
            var isSpriteFile = false;

            var clrs      = EgaVgaPalette.ExtractPalette(origData, clrCount, clrBase, 11);
            var dataStart = (clrCount * 3) + 132 + (3 * frames);

            if (block.FileNameUpperCase.StartsWith("SPRIT"))
            {
                clrs[0]      = Color.FromArgb(0);
                clrs[13]     = Color.FromArgb(0, 0, 0);
                isSpriteFile = true;
                if (clrBase == 176 && clrCount == 80)
                {
                    dataStart = 306;
                }
            }

            data = UnpackSpriteData(data, dataStart);
            var frameCount = data.Length / picSize;

            int mframe = origData[(clrCount * 3) + 132 - 5];

            if (isSpriteFile)
            {
                mframe = frameCount - 1;
            }

            for (var frame = 0; frame < frameCount; frame++)
            {
                var bitmap = new Bitmap(widthPx, heightPx, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);

                for (var y = 0; y < heightPx; y++)
                {
                    for (var x = 0; x < widthPx; x += 1)
                    {
                        var b1 = data[(y * widthPx) + x + (picSize * frame)];
                        var b3 = data[(y * widthPx) + x + (picSize * mframe)];
                        bitmap.SetPixel(x, y, frame != mframe ? clrs[b1 ^ b3] : clrs[b1]);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Exemplo n.º 6
0
        List <Bitmap> load8x8Bitmaps(DaxFileBlock daxFileBlock, string fileName, string tileFileName, int blockId)
        {
            var           bitmapcount = getBitmapCount(blockId, tileFileName);
            List <Bitmap> bitmaps8x8  = new List <Bitmap>();

            bitmaps8x8.Add(bitmapZero());

            if (bitmapcount >= 255)     // the bitmaps are in a single large file, load them all at once
            {
                if (bitmapcount == 256)
                {
                    bitmaps8x8.RemoveAt(0);                     //bitmapIdxOffset = 1;
                }
                // just load the 8x8 with the same id as the wall def
                loadBitmaps(blockId, tileFileName, bitmaps8x8);
            }
            else
            // the bitmaps are in small chunks in a universal file, and one or more wallset specific files
            {
                loadBitmaps(getUniversalTileBlockId(), getUniversalTileFileName(fileName), bitmaps8x8);

                // next load the ones which are specific to this wallset
                // how many wallsets are there in this walldef daxblock? We will need to load one 8x8 daxblock for each wallset in the walldef
                int wallsetCount = daxFileBlock.Data.Length / 780;

                // if there's just one wallset, the 8x8 daxblock needed has the same id as the walldef daxblock
                if (wallsetCount >= 1)
                {
                    loadBitmaps(blockId, tileFileName, bitmaps8x8);
                }

                // if there's 2 or 3, the Id's of 8x8 daxblocks are given by the current id*10 +1, +2 or +3
                // and if the current daxblock id is 0, consider to be 10 before multiplying by 10
                if (bitmaps8x8.Count < 255 && wallsetCount > 1)
                {
                    var baseBlockId = 10 * blockId;
                    if (blockId == 0)
                    {
                        baseBlockId = 10 * 10;
                    }
                    var block1 = baseBlockId + 1;
                    var block2 = baseBlockId + 2;
                    var block3 = baseBlockId + 3;

                    loadBitmaps(block1, tileFileName, bitmaps8x8);
                    loadBitmaps(block2, tileFileName, bitmaps8x8);
                    if (wallsetCount == 3)
                    {
                        loadBitmaps(block3, tileFileName, bitmaps8x8);
                    }
                }
            }
            bitmaps8x8[0] = bitmapZero();
            return(bitmaps8x8);
        }
Exemplo n.º 7
0
        public bool IsSatisfiedBy(DaxFileBlock block)
        {
            var data = block.Data;

            if (data.Length < 5)
            {
                return(false);
            }

            uint frames = data[0];

            if (frames > 8)
            {
                return(false);
            }

            int offset = 5;

            if (data.Length < 20 + offset)
            {
                return(false);
            }

            int height = ArrayToUshort(data, 0 + offset);
            int width  = ArrayToUshort(data, 2 + offset);

            int width_px = width * 8;

            int clr_count = data[9 + offset];
            int clr_start = data[10 + offset];

            if (width_px < 1 || height < 1 || width_px > 320 || height > 200)
            {
                return(false);
            }

            bool egaBlock  = (data[9 + offset] & 0xCC) == 0;
            int  blocksize = egaBlock ? (4 * width * height) : ((5 * width * height) + 14);

            if (data.Length < blocksize + 9 + offset)
            {
                return(false);
            }

            int data_offset = getDataOffset(9 + offset, data);

            if (data.Length < frames * blocksize)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        List <Bitmap> assembleWallSet(DaxFileBlock daxFileBlock, string fileName, int blockId)
        {
            string tileFileName = fileName.ToLower().Replace("walldef", "8x8d");
            var    dir          = Path.GetDirectoryName(fileName);

            // first the 8x8 tiles which are universal to all wallsets
            List <Bitmap>   tileBitmaps = load8x8Bitmaps(daxFileBlock, fileName, tileFileName, blockId); // return bitmaps
            List <byte[, ]> wallSetData = loadWallDefs(daxFileBlock);                                    // return walldef data

            for (int i = 0; i < wallSetData.Count; i++)
            {
                _bitmapIds.Add(daxFileBlock.Id);
            }

            return(aggregateWalls(wallSetData, tileBitmaps)); // return bitmap list
        }
Exemplo n.º 9
0
        public VgaBlock(DaxFileBlock block)
        {
            setBlockId(block.Id);

            var data = block.Data;

            int       height     = data[0];
            int       width      = data[1];
            const int xPos       = 0;
            const int yPos       = 0;
            var       widthPx    = width * 8;
            var       heightPx   = height;
            const int xPosPx     = xPos * 8;
            const int yPosPx     = yPos * 8;
            int       clrBase    = data[8];
            int       clrCount   = data[9] + 1;
            var       paletteEnd = 10 + (clrCount * 3);
            var       chunkSize  = (widthPx * heightPx);
            var       chunkCount = ArrayToUshort(data, 6);
            var       dataStart  = data.Length - (chunkCount * chunkSize);

            for (var chunk = 0; chunk < chunkCount; chunk++, dataStart += chunkSize)
            {
                var clrs = EgaVgaPalette.ExtractPalette(data, clrCount, clrBase, 10);

                if (clrs == null)
                {
                    return;
                }

                var bitmap = new Bitmap((widthPx + xPosPx), (heightPx + yPosPx), PixelFormat.Format16bppArgb1555);
                for (var y = 0; y < heightPx; y++)
                {
                    for (var x = 0; x < widthPx; x += 1)
                    {
                        var b   = data[dataStart + (y * widthPx) + x];
                        var pxX = (x + 0 + xPosPx);
                        var pxY = (y + yPosPx);
                        bitmap.SetPixel(pxX, pxY, clrs[b]);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Exemplo n.º 10
0
        List <byte[, ]> loadWallDefs(DaxFileBlock daxFileBlock)
        {
            // rows, columns and offsets of the subarrays holding walldefs for various viewing angles and distances
            // taken from Simeon Pilgrim's curse of the azure bonds code in ovr031.cs
            byte[] idxOffset = { 0, 2, 6, 10, 22, 38, 54, 110, 132, 154, 1 };  // seg600:0ADA
            int[]  colCount  = { 1, 1, 1, 3, 2, 2, 7, 2, 2, 1 };               // seg600:0AE4
            int[]  rowCount  = { 2, 4, 4, 4, 8, 8, 8, 11, 11, 2 };             // seg600:0AEE

            const int wallSliceSize = 156;

            byte[]          data        = daxFileBlock.Data;
            List <byte[, ]> wallSetData = new List <byte[, ]>();
            var             wallCount   = daxFileBlock.Data.Length / wallSliceSize;

            for (int wallNumber = 0; wallNumber < wallCount; wallNumber++)
            {
                for (int wallView = 0; wallView < 10; wallView++)
                {
                    var idx  = idxOffset[wallView];
                    var rows = rowCount[wallView];
                    var cols = colCount[wallView];

                    var i = idx;
                    byte[,] wall = new byte[rows, cols];
                    for (var r = 0; r < rows; r++)
                    {
                        for (var c = 0; c < cols; c++)
                        {
                            wall[r, c] = data[(wallSliceSize * wallNumber) + i];
                            i++;
                        }
                    }
                    wallSetData.Add(wall);
                }
            }
            return(wallSetData);
        }
Exemplo n.º 11
0
        public MonoBlock(DaxFileBlock block)
        {
            setBlockId(block.Id);

            int[] monoBitMask = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
            var   count       = block.Data.Length / 8;

            for (var ch = 0; ch < count; ch++)
            {
                var bitmap = new Bitmap(8, 8, PixelFormat.Format16bppArgb1555);

                for (var y = 0; y < 8; y++)
                {
                    for (var x = 0; x < 8; x++)
                    {
                        var b = block.Data[(ch * 8) + y];
                        var c = ((b & monoBitMask[x]) != 0) ? Color.White : Color.Black;
                        bitmap.SetPixel(x, y, c);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Exemplo n.º 12
0
        private string GetMapNameFrom(DaxFileBlock block)
        {
            var mapname = block.Id.ToString();

            var game = FileHelper.DetermineGameFrom(block.File);
            if (game != FileHelper.GameList.Unknown)
            {
                // do we have a map with that id?
                if(_mapNames.ContainsKey((int) game))
                {
                    var names = _mapNames[(int) game];
                    if(names.ContainsKey(block.Id))
                    {
                        mapname = names[block.Id];
                    }
                }
            }

            return mapname;
        }
Exemplo n.º 13
0
        List<Bitmap> load8x8Bitmaps(DaxFileBlock daxFileBlock, string fileName, string tileFileName, int blockId)
        {
            var bitmapcount = getBitmapCount(blockId, tileFileName);
            List<Bitmap> bitmaps8x8 = new List<Bitmap>();
            bitmaps8x8.Add(bitmapZero());

            if (bitmapcount >= 255)     // the bitmaps are in a single large file, load them all at once
            {
                if (bitmapcount == 256) bitmaps8x8.RemoveAt(0); //bitmapIdxOffset = 1;
                // just load the 8x8 with the same id as the wall def
                loadBitmaps(blockId, tileFileName, bitmaps8x8);
            }
            else
                // the bitmaps are in small chunks in a universal file, and one or more wallset specific files
            {
                loadBitmaps(getUniversalTileBlockId(), getUniversalTileFileName(fileName), bitmaps8x8);

                // next load the ones which are specific to this wallset
                // how many wallsets are there in this walldef daxblock? We will need to load one 8x8 daxblock for each wallset in the walldef
                int wallsetCount = daxFileBlock.Data.Length / 780;

                // if there's just one wallset, the 8x8 daxblock needed has the same id as the walldef daxblock
                if (wallsetCount >= 1)
                {
                    loadBitmaps(blockId, tileFileName, bitmaps8x8);
                }

                // if there's 2 or 3, the Id's of 8x8 daxblocks are given by the current id*10 +1, +2 or +3
                // and if the current daxblock id is 0, consider to be 10 before multiplying by 10
                if (bitmaps8x8.Count < 255 && wallsetCount > 1)
                {
                    var baseBlockId = 10 * blockId;
                    if (blockId == 0) { baseBlockId = 10 * 10; }
                    var block1 = baseBlockId + 1;
                    var block2 = baseBlockId + 2;
                    var block3 = baseBlockId + 3;

                    loadBitmaps(block1, tileFileName, bitmaps8x8);
                    loadBitmaps(block2, tileFileName, bitmaps8x8);
                    if (wallsetCount == 3) loadBitmaps(block3, tileFileName, bitmaps8x8);
                }
            }
            bitmaps8x8[0] = bitmapZero();
            return bitmaps8x8;
        }
Exemplo n.º 14
0
        public VgaStrataBlock(DaxFileBlock block)
        {
            setBlockId(block.Id);

            var data        = block.Data;
            int height      = ArrayToUshort(data, 0);
            int width       = ArrayToUshort(data, 2);
            int xPos        = ArrayToUshort(data, 4);
            int yPos        = ArrayToUshort(data, 6);
            int picCount    = data[8];
            var widthPx     = width * 8;
            var heightPx    = height;
            var pxlClrs     = new int[heightPx, widthPx];
            var xPosPx      = xPos * 8;
            var yPosPx      = yPos * 8;
            var tempPalette = new byte[59];
            var dataOffset  = GetDataOffset(tempPalette, 9, data);

            var       dd          = new int[48];
            const int paletteBase = 0x20;

            for (var i = 0; i < 24; i++)
            {
                var b = tempPalette[paletteBase + i];
                dd[0 + i]  = (b & 0x0f) * 4;
                dd[24 + i] = (b & 0xf0) / 4;
            }

            var egaPalette = EgaVgaPalette.PaletteBase();

            for (var i = 0; i < 14; i += 1)
            {
                var r = dd[(i * 3) + 6 + 0];
                var g = dd[(i * 3) + 6 + 1];
                var b = dd[(i * 3) + 6 + 2];
                egaPalette[i + 18] = Color.FromArgb(r * 4, g * 4, b * 4);
            }

            for (int pic = 0; pic < picCount; pic++)
            {
                var inOffset = dataOffset;

                for (var y = 0; y < height; y++)
                {
                    for (var x = 0; x < widthPx; x++)
                    {
                        var  mask      = 0x80 >> (x & 7);
                        var  inputByte = x / 8;
                        byte pxClr     = 0;

                        if ((data[inOffset + inputByte] & mask) != 0)
                        {
                            pxClr = 1;
                        }

                        if ((data[inOffset + inputByte + width] & mask) != 0)
                        {
                            pxClr += 2;
                        }

                        if ((data[inOffset + inputByte + (width * 2)] & mask) != 0)
                        {
                            pxClr += 4;
                        }

                        if ((data[inOffset + inputByte + (width * 3)] & mask) != 0)
                        {
                            pxClr += 8;
                        }

                        if ((data[inOffset + inputByte + (width * 4)] & mask) != 0)
                        {
                            pxClr += 0x10;
                        }

                        pxlClrs[y, x] = pxClr;
                    }

                    inOffset += width * 5;
                }

                dataOffset = inOffset;

                var bitmap = new Bitmap(widthPx + xPosPx, heightPx + yPosPx, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);
                for (var y = 0; y < heightPx; y++)
                {
                    for (var x = 0; x < widthPx; x += 1)
                    {
                        var pxX = x + xPosPx;
                        var pxY = y + yPosPx;
                        bitmap.SetPixel(pxX, pxY, egaPalette[pxlClrs[y, x]]);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Exemplo n.º 15
0
        public bool IsSatisfiedBy(DaxFileBlock block)
        {
            var data     = block.Data;
            var origData = data;

            if (data.Length < 20)
            {
                return(false);
            }

            if (data[1] != 0)
            {
                return(false);
            }

            int height   = data[0];
            int width    = data[2];
            var widthPx  = width * 8;
            var heightPx = height;

            if (widthPx < 1 || heightPx < 1 || widthPx > 320 || heightPx > 200)
            {
                return(false);
            }

            int frames   = data[8];
            int clrBase  = data[9];
            int clrCount = data[10];

            if (clrBase == 0)
            {
                return(false);
            }

            if (clrCount == 0)
            {
                return(false);
            }

            var dataStart = (clrCount * 3) + 132 + (3 * frames);

            if (block.FileNameUpperCase.StartsWith("SPRIT") && clrBase == 176 && clrCount == 80)
            {
                dataStart = 306;
            }

            data = UnpackSpriteData(data, dataStart);

            if (data.Length <= 0)
            {
                return(false);
            }

            var picSize = widthPx * heightPx;

            if (picSize <= 0)
            {
                return(false);
            }

            if (data.Length % picSize != 0)
            {
                return(false);
            }

            var frameCount = data.Length / picSize;

            if (picSize * frameCount > data.Length)
            {
                return(false);
            }

            var clrs = EgaVgaPalette.ExtractPalette(origData, clrCount, clrBase, 11);

            if (clrs == null)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 16
0
        List<byte[,]> loadWallDefs(DaxFileBlock daxFileBlock)
        {
            // rows, columns and offsets of the subarrays holding walldefs for various viewing angles and distances
            // taken from Simeon Pilgrim's curse of the azure bonds code in ovr031.cs
            byte[] idxOffset = { 0, 2, 6, 10, 22, 38, 54, 110, 132, 154, 1 };   // seg600:0ADA
            int[] colCount = { 1, 1, 1, 3, 2, 2, 7, 2, 2, 1 };                 // seg600:0AE4
            int[] rowCount = { 2, 4, 4, 4, 8, 8, 8, 11, 11, 2 };               // seg600:0AEE

            const int wallSliceSize = 156;
            byte[] data = daxFileBlock.Data;
            List<byte[,]> wallSetData = new List<byte[,]>();
            var wallCount = daxFileBlock.Data.Length / wallSliceSize;

            for (int wallNumber = 0; wallNumber < wallCount; wallNumber++)
            {
                for (int wallView = 0; wallView < 10; wallView++)
                {
                    var idx = idxOffset[wallView];
                    var rows = rowCount[wallView];
                    var cols = colCount[wallView];

                    var i = idx;
                    byte[,] wall = new byte[rows, cols];
                    for (var r = 0; r < rows; r++)
                    {
                        for (var c = 0; c < cols; c++)
                        {
                            wall[r, c] = data[(wallSliceSize * wallNumber) + i];
                            i++;
                        }
                    }
                    wallSetData.Add(wall);
                }
            }
            return wallSetData;
        }
Exemplo n.º 17
0
        List<Bitmap> assembleWallSet(DaxFileBlock daxFileBlock, string fileName, int blockId)
        {
            string tileFileName = fileName.ToLower().Replace("walldef", "8x8d");
            var dir = Path.GetDirectoryName(fileName);
 
            // first the 8x8 tiles which are universal to all wallsets
            List<Bitmap> tileBitmaps = load8x8Bitmaps(daxFileBlock, fileName, tileFileName, blockId); // return bitmaps
            List<byte[,]>  wallSetData = loadWallDefs(daxFileBlock); // return walldef data
            for (int i = 0; i < wallSetData.Count; i++)
                _bitmapIds.Add(daxFileBlock.Id);

            return aggregateWalls(wallSetData, tileBitmaps); // return bitmap list


        }
Exemplo n.º 18
0
 public bool IsSatisfiedBy(DaxFileBlock block)
 {
     return((block.Data.Length % 8) == 0 &&
            (block.FileNameUpperCase.StartsWith("8X8")));
 }
Exemplo n.º 19
0
        public bool IsSatisfiedBy(DaxFileBlock block)
        {
            var data   = block.Data;
            int frames = data[0];

            int offset = 1;

            if (frames == 0 || frames > 8)
            {
                return(false);
            }

            for (int frame = 0; frame < frames; frame++)
            {
                if (data.Length < 21 + offset)
                {
                    return(false);
                }

                offset += 4;
                int height = ArrayToUshort(data, offset);
                offset += 2;
                int width = ArrayToUshort(data, offset);
                offset += 2;
                int x_pos = ArrayToUshort(data, offset);
                offset += 2;
                int y_pos = ArrayToUshort(data, offset);
                offset += 3;
                offset += 8;

                // skip 1 byte
                // skip 8 bytes
                int width_px  = width * 8;
                int height_px = height;
                int x_pos_px  = x_pos * 8;
                int y_pos_px  = y_pos * 8;

                if (width_px < 1 || height_px < 1 || width_px > 320 || height_px > 200)
                {
                    return(false);
                }

                int egaDataSize = height * width * 4;

                if (data.Length < egaDataSize + offset)
                {
                    return(false);
                }

                offset += egaDataSize;
            }

            if (data.Length > offset)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 20
0
 // scan the designated ecl file/block for wallset loading commands, return the first one
 private void scanECLFileForWallset(DaxFileBlock block, int geoID, int blockID)
 {
         // scan for the load pieces command, which consists of the pattern 0x37 a 0x00 b 0x00 c 0x00, where a, b and c are the wallsets to load
         byte load_pieces = 0x37;
         for (int i = 0; i < block.Data.Length-7; i++)
         {
             if (block.Data[i] == load_pieces && block.Data[i + 1] == 0 && block.Data[i + 3] == 0 && block.Data[i + 5] == 0)
             {
                 int a = block.Data[i + 2];
                 int b = block.Data[i + 4];
                 int c = block.Data[i + 6];
                 int[] ws = { a, b, c };
                 if (isValidWallSetId(a) && isValidWallSetId(b) && isValidWallSetId(c))
                 {
                     if (!wallsetMapping.ContainsKey(geoID))
                         wallsetMapping.Add(geoID, ws);
                 }
             }
         }
 }
Exemplo n.º 21
0
        public VgaMixedBlock(DaxFileBlock block)
        {
            setBlockId(block.Id);

            var data     = block.Data;
            var origData = data;

            if (data.Length < 5)
            {
                return;
            }

            uint frames = data[0];
            int  offset = 5;

            if (frames > 8)
            {
                return;
            }

            if (data.Length < 20 + offset)
            {
                return;
            }

            // try single frame
            int height     = ArrayToUshort(data, 0 + offset);
            int width      = ArrayToUshort(data, 2 + offset);
            int x_pos      = ArrayToUshort(data, 4 + offset);
            int y_pos      = ArrayToUshort(data, 6 + offset);
            int item_count = data[8 + offset];

            int width_px  = width * 8;
            int height_px = height;
            int x_pos_px  = x_pos * 8;
            int y_pos_px  = y_pos * 8;

            if (width_px < 1 || height_px < 1 || width_px > 320 || height_px > 200)
            {
                return;
            }

            bool egaBlock  = (data[9 + offset] & 0xCC) == 0;
            int  blocksize = egaBlock ? (4 * width * height) : (5 * width * height);

            if (data.Length < blocksize + 9 + offset)
            {
                return;
            }


            byte[] tempPalette = new byte[0x3B];
            int    data_offset = DecodePaletteData(tempPalette, 9 + offset, data);

            int[] dd    = new int[48];
            int   _base = 0x20;

            for (int i = 0; i < 24; i++)
            {
                int b  = tempPalette[_base + i];
                int a1 = (b & 0x0f);
                int a2 = (b & 0xf0);
                dd[0 + i]  = (b & 0x0f) * 4;
                dd[24 + i] = (b & 0xf0) / 4;
            }

            var clrs = PaletteBase();

            for (int i = 0; i < 14; i += 1)
            {
                int r = dd[(i * 3) + 6 + 0];
                int g = dd[(i * 3) + 6 + 1];
                int b = dd[(i * 3) + 6 + 2];
                clrs[i + 18] = Color.FromArgb(r * 4, g * 4, b * 4);
            }

            int[,] pxl_clrs = new int[height_px, width_px];

            for (int frame = 0; frame < frames; frame++)
            {
                if (egaBlock)
                {
                    int in_offset = data_offset;
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width_px; x += 2)
                        {
                            pxl_clrs[y, x]     = data[in_offset] >> 4;
                            pxl_clrs[y, x + 1] = data[in_offset] & 0x0F;

                            in_offset += 1;
                        }
                    }

                    data_offset = in_offset;
                }
                else
                {
                    int in_offset  = data_offset;
                    int out_offset = 0;
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width_px; x++)
                        {
                            int  mask       = 0x80 >> (x & 7);
                            int  input_byte = x / 8;
                            byte px_clr     = 0;

                            if ((data[in_offset + input_byte] & mask) != 0)
                            {
                                px_clr = 1;
                            }

                            if ((data[in_offset + input_byte + width] & mask) != 0)
                            {
                                px_clr += 2;
                            }

                            if ((data[in_offset + input_byte + (width * 2)] & mask) != 0)
                            {
                                px_clr += 4;
                            }

                            if ((data[in_offset + input_byte + (width * 3)] & mask) != 0)
                            {
                                px_clr += 8;
                            }

                            if ((data[in_offset + input_byte + (width * 4)] & mask) != 0)
                            {
                                px_clr += 0x10;
                            }

                            pxl_clrs[y, x] ^= px_clr;
                        }

                        in_offset  += width * 5;
                        out_offset += width * 8;
                    }

                    data_offset = in_offset + 14;
                }

                var bitmap = new Bitmap(width_px + x_pos_px, height_px + y_pos_px, System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);
                for (int y = 0; y < height_px; y++)
                {
                    for (int x = 0; x < width_px; x += 1)
                    {
                        int pxX = x + x_pos_px;
                        int pxY = y + y_pos_px;
                        bitmap.SetPixel(pxX, pxY, clrs[pxl_clrs[y, x]]);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Exemplo n.º 22
0
 private void processWallSet(DaxFileBlock daxFileBlock)
 {
     byte[] data = daxFileBlock.Data;
     _blockIds.Add(daxFileBlock.Id);
     wallsets.Add(assembleWallSet(daxFileBlock, FileName, daxFileBlock.Id));
 }
Exemplo n.º 23
0
        public EgaSpriteBlock(DaxFileBlock block)
        {
            var data = block.Data;

            setBlockId(block.Id);
            uint frames = data[0];
            int  offset = 1;

            if (frames > 8)
            {
                return;
            }

            Color[] clrs = new Color[16];
            for (int i = 0; i < 16; i++)
            {
                clrs[i] = Color.FromArgb((int)EgaVgaPalette.EgaColors[i]);
            }

            var  filename  = block.FileNameUpperCase;
            bool xorFrames = filename.StartsWith("PIC", true, System.Globalization.CultureInfo.CurrentCulture);

            xorFrames |= filename.StartsWith("FINAL", true, System.Globalization.CultureInfo.CurrentCulture);

            if (filename.StartsWith("SPRI", true, System.Globalization.CultureInfo.CurrentCulture))
            {
                clrs[0]  = Color.FromArgb(0, 0, 0, 0);
                clrs[13] = Color.FromArgb((int)EgaVgaPalette.EgaColors[0]);
            }


            byte[] first_frame_ega_layout = null;

            for (int frame = 0; frame < frames; frame++)
            {
                if (data.Length < 21 + offset)
                {
                    return;
                }

                uint delay = ArrayToUint(data, offset);
                offset += 4;
                int height = ArrayToUshort(data, offset);
                offset += 2;
                int width = ArrayToUshort(data, offset);
                offset += 2;
                int x_pos = ArrayToUshort(data, offset);
                offset += 2;
                int y_pos = ArrayToUshort(data, offset);
                offset += 3;
                offset += 8;

                // skip 1 byte
                // skip 8 bytes
                int width_px  = width * 8;
                int height_px = height;
                int x_pos_px  = x_pos * 8;
                int y_pos_px  = y_pos * 8;

                if (width_px < 1 || height_px < 1 || width_px > 320 || height_px > 200)
                {
                    return;
                }

                int egaDataSize = height * width * 4;

                if (data.Length < egaDataSize + offset)
                {
                    return;
                }

                if (xorFrames)
                {
                    if (frame == 0)
                    {
                        first_frame_ega_layout = new byte[egaDataSize + 1];

                        System.Array.Copy(data, offset, first_frame_ega_layout, 0, egaDataSize);
                    }
                    else
                    {
                        for (int i = 0; i < egaDataSize; i++)
                        {
                            byte b = first_frame_ega_layout[i];
                            data[offset + i] ^= b;
                        }
                    }
                }

                var bitmap = new Bitmap((int)(width_px + x_pos_px), (int)(height_px + y_pos_px), System.Drawing.Imaging.PixelFormat.Format16bppArgb1555);
                for (int y = 0; y < height_px; y++)
                {
                    for (int x = 0; x < width_px; x += 2)
                    {
                        byte b   = data[(y * width * 4) + (x / 2) + offset];
                        int  pxX = (int)(x + 0 + x_pos_px);
                        int  pxY = (int)(y + y_pos_px);
                        bitmap.SetPixel(pxX, pxY, clrs[b >> 4]);
                        bitmap.SetPixel(pxX + 1, pxY, clrs[b & 0xF]);
                    }
                }

                Bitmaps.Add(bitmap);

                offset += egaDataSize;
            }
        }