Пример #1
0
        public bitmap(CacheBase Cache, int Address)
        {
            EndianReader Reader = Cache.Reader;

            Reader.SeekTo(Address);

            #region Sequence Chunk
            Reader.SeekTo(Address + 60);
            int iCount  = Reader.ReadInt32();
            int iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Sequences.Add(new Sequence(Cache, iOffset + 60 * i));
            }
            #endregion

            #region BitmapData Chunk
            Reader.SeekTo(Address + 68);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Bitmaps.Add(new BitmapData(Cache, iOffset + 116 * i));
            }
            #endregion
        }
Пример #2
0
            public virtual void ReadChildData(BinaryReader reader)
            {
                int x = 0;

                _compressedColorPlateData.ReadBinary(reader);
                _processedPixelData.ReadBinary(reader);
                for (x = 0; (x < _sequences.Count); x = (x + 1))
                {
                    Sequences.Add(new BitmapGroupSequenceBlock());
                    Sequences[x].Read(reader);
                }
                for (x = 0; (x < _sequences.Count); x = (x + 1))
                {
                    Sequences[x].ReadChildData(reader);
                }
                for (x = 0; (x < _bitmaps.Count); x = (x + 1))
                {
                    Bitmaps.Add(new BitmapDataBlock());
                    Bitmaps[x].Read(reader);
                }
                for (x = 0; (x < _bitmaps.Count); x = (x + 1))
                {
                    Bitmaps[x].ReadChildData(reader);
                }
            }
Пример #3
0
        private bool isCombatPicture = false; // images used in combat mode have a slightly different EGA palette (colors 0 and 8 are swapped)
        public EgaBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);
            var       data          = parameters.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 = Path.GetFileName(parameters.Name).ToUpper();

            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);
                }
            }
        }
Пример #4
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);
            }
        }
Пример #5
0
        private void InitData(string id)
        {
            Bitmaps.Clear();
            BitmapsIndex = 0;
            string dir   = PathHelper.GetScreenShotDir(id);
            var    files = Directory.GetFiles(dir, "*.jpg");

            if (files.Length > 0)
            {
                for (int i = 0; i < files.Length; i++)
                {
                    Bitmaps.Add(i, new Bitmap(files[i]));
                }
                PicPreview.Image = Bitmaps[0];
            }
        }
Пример #6
0
        public bitmap(CacheBase Cache, int Address)
        {
            EndianReader Reader = Cache.Reader;

            Reader.SeekTo(Address);

            #region Sequence Chunk
            Reader.SeekTo(Address + 84);
            int iCount  = Reader.ReadInt32();
            int iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Sequences.Add(new Sequence(Cache, iOffset + 64 * i));
            }
            #endregion

            #region BitmapData Chunk
            Reader.SeekTo(Address + 96);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                Bitmaps.Add(new BitmapData(Cache, iOffset + 48 * i));
            }
            #endregion

            #region Raw Chunk A
            Reader.SeekTo(Address + 140);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                RawChunkAs.Add(new RawChunkA(Cache, iOffset + 8 * i));
            }
            #endregion

            #region Raw Chunk B
            Reader.SeekTo(Address + 152);
            iCount  = Reader.ReadInt32();
            iOffset = Reader.ReadInt32() - Cache.Magic;
            for (int i = 0; i < iCount; i++)
            {
                RawChunkBs.Add(new RawChunkB(Cache, iOffset + 8 * i));
            }
            Reader.SeekTo(Address + 164);
            #endregion
        }
Пример #7
0
        public bitmap(CacheBase Cache, int Address)
        {
            int          magic = Cache.Magic;
            EndianReader Reader;

            if (Address < 0) //external bitmap
            {
                var fs = new FileStream(Cache.FilePath + "\\bitmaps.map", FileMode.Open, FileAccess.Read);
                Reader = new EndianReader(fs, EndianFormat.LittleEndian);

                Reader.SeekTo(8);
                var indexOffset = Reader.ReadInt32();
                var index       = Address + Cache.Magic;

                Reader.SeekTo(indexOffset + 12 * index + 8);
                Address = Reader.ReadInt32();
                magic   = -Address;
            }
            else
            {
                Reader = Cache.Reader;
            }

            #region BitmapData Chunk
            Reader.SeekTo(Address + 96);
            int iCount  = Reader.ReadInt32();
            int iOffset = Reader.ReadInt32() - magic;
            for (int i = 0; i < iCount; i++)
            {
                Bitmaps.Add(new BitmapData(Reader, iOffset + 48 * i));
            }
            #endregion

            if (Reader != Cache.Reader)
            {
                Reader.Close();
                Reader.Dispose();

                //add flag so the GetRawFromID function
                //can tell that it's an external bitmap
                foreach (var bData in Bitmaps)
                {
                    bData.PixelsOffset |= int.MinValue; //0x80000000
                }
            }
        }
Пример #8
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);
            }
        }
Пример #9
0
        public MonoBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);

            int[] monoBitMask = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
            var   count       = parameters.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 = parameters.Data[(ch * 8) + y];
                        var c = ((b & monoBitMask[x]) != 0) ? Color.White : Color.Black;
                        bitmap.SetPixel(x, y, c);
                    }
                }

                Bitmaps.Add(bitmap);
            }
        }
Пример #10
0
        public EgaSpriteBlock(FileBlockParameters parameters)
        {
            var data = parameters.Data;

            setBlockId(parameters.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  = Path.GetFileName(parameters.Name).ToUpper();
            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;
            }
        }
Пример #11
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);
            }
        }
Пример #12
0
        public VgaMixedBlock(FileBlockParameters parameters)
        {
            setBlockId(parameters.Id);

            var data     = parameters.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);
            }
        }
Пример #13
0
 public void AddBitmap(Bitmap bitmap)
 {
     Bitmaps.Add(new Bitmap(bitmap));
     Invoke((Action)(() => trackBar1.Maximum = Bitmaps.Count - 1));
 }
Пример #14
0
        public void Read(Stream stream)
        {
            BinaryReader  br     = new BinaryReader(stream);
            HAMDataReader reader = new HAMDataReader();

            if (LoadData)
            {
                DataPointer = br.ReadInt32();
                //So there's no sig, so we're going to take a guess based on the pointer. If it's greater than max bitmaps, we'll assume it's a descent 1 1.4+ piggy file
                if (DataPointer <= 1800)
                {
                    throw new ArgumentException("Cannot read this .PIG file");
                }

                numTextures = br.ReadInt32();
                for (int i = 0; i < 800; i++)
                {
                    Textures[i] = br.ReadUInt16();
                }

                for (int i = 0; i < 800; i++)
                {
                    TMapInfo[i] = reader.ReadTMAPInfoDescent1(br);
                }

                SoundIDs  = br.ReadBytes(250);
                AltSounds = br.ReadBytes(250);

                numVClips = br.ReadInt32(); //this value is bogus. rip
                for (int i = 0; i < 70; i++)
                {
                    VClips[i] = reader.ReadVClip(br);
                }

                numEClips = br.ReadInt32();
                for (int i = 0; i < 60; i++)
                {
                    EClips[i] = reader.ReadEClip(br);
                }

                numWClips = br.ReadInt32();
                for (int i = 0; i < 30; i++)
                {
                    WClips[i] = reader.ReadWClipDescent1(br);
                }

                numRobots = br.ReadInt32();
                for (int i = 0; i < 30; i++)
                {
                    Robots[i] = reader.ReadRobotDescent1(br);
                }

                numJoints = br.ReadInt32();
                for (int i = 0; i < 600; i++)
                {
                    JointPos joint = new JointPos();
                    joint.JointNum = br.ReadInt16();
                    joint.Angles.P = br.ReadInt16();
                    joint.Angles.B = br.ReadInt16();
                    joint.Angles.H = br.ReadInt16();
                    Joints[i]      = joint;
                }

                numWeapons = br.ReadInt32();
                for (int i = 0; i < 30; i++)
                {
                    Weapons[i] = reader.ReadWeaponInfoDescent1(br);
                }

                numPowerups = br.ReadInt32();
                for (int i = 0; i < 29; i++)
                {
                    Powerup powerup = new Powerup();
                    powerup.VClipNum = br.ReadInt32();
                    powerup.HitSound = br.ReadInt32();
                    powerup.Size     = new Fix(br.ReadInt32());
                    powerup.Light    = new Fix(br.ReadInt32());
                    Powerups[i]      = powerup;
                }

                numModels = br.ReadInt32();
                for (int i = 0; i < numModels; i++)
                {
                    Models[i] = reader.ReadPolymodelInfo(br);
                }
                for (int i = 0; i < numModels; i++)
                {
                    Models[i].InterpreterData = br.ReadBytes(Models[i].ModelIDTASize);
                }
                for (int i = 0; i < Gauges.Length; i++)
                {
                    Gauges[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 85; i++)
                {
                    int num = br.ReadInt32();
                    if (i < numModels)
                    {
                        Models[i].DyingModelnum = num;
                    }
                    else
                    {
                        int wtfIsThis = num;
                    }
                }
                for (int i = 0; i < 85; i++)
                {
                    int num = br.ReadInt32();

                    if (i < numModels)
                    {
                        Models[i].DeadModelnum = num;
                    }
                    else
                    {
                        int wtfIsThis = num;
                    }
                }

                for (int i = 0; i < 210; i++)
                {
                    ObjBitmaps[i] = br.ReadUInt16();
                }
                for (int i = 0; i < 210; i++)
                {
                    ObjBitmapPointers[i] = br.ReadUInt16();
                }

                PlayerShip                   = new Ship();
                PlayerShip.ModelNum          = br.ReadInt32();
                PlayerShip.DeathVClipNum     = br.ReadInt32();
                PlayerShip.Mass              = new Fix(br.ReadInt32());
                PlayerShip.Drag              = new Fix(br.ReadInt32());
                PlayerShip.MaxThrust         = new Fix(br.ReadInt32());
                PlayerShip.ReverseThrust     = new Fix(br.ReadInt32());
                PlayerShip.Brakes            = new Fix(br.ReadInt32());
                PlayerShip.Wiggle            = new Fix(br.ReadInt32());
                PlayerShip.MaxRotationThrust = new Fix(br.ReadInt32());
                for (int x = 0; x < 8; x++)
                {
                    PlayerShip.GunPoints[x] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
                }
                numCockpits = br.ReadInt32();
                for (int i = 0; i < 4; i++)
                {
                    Cockpits[i] = br.ReadUInt16();
                }

                //heh
                SoundIDs  = br.ReadBytes(250);
                AltSounds = br.ReadBytes(250);

                numObjects = br.ReadInt32();
                for (int i = 0; i < 100; i++)
                {
                    ObjectTypes[i].type = (EditorObjectType)(br.ReadSByte());
                }
                for (int i = 0; i < 100; i++)
                {
                    ObjectTypes[i].id = br.ReadByte();
                }
                for (int i = 0; i < 100; i++)
                {
                    ObjectTypes[i].strength = new Fix(br.ReadInt32());
                    //Console.WriteLine("type: {0}({3})\nid: {1}\nstr: {2}", ObjectTypes[i].type, ObjectTypes[i].id, ObjectTypes[i].strength, (int)ObjectTypes[i].type);
                }
                FirstMultiBitmapNum = br.ReadInt32();
                reactor.NumGuns     = br.ReadInt32();
                for (int y = 0; y < 4; y++)
                {
                    reactor.GunPoints[y] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
                }
                for (int y = 0; y < 4; y++)
                {
                    reactor.GunDirs[y] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
                }

                exitModelnum          = br.ReadInt32();
                destroyedExitModelnum = br.ReadInt32();

                for (int i = 0; i < 1800; i++)
                {
                    BitmapXLATData[i] = br.ReadUInt16();
                }
            }


            //Init a bogus texture for all piggyfiles
            PIGImage bogusTexture = new PIGImage(64, 64, 0, 0, 0, 0, "bogus", 0);

            bogusTexture.Data = new byte[64 * 64];
            //Create an X using descent 1 palette indicies. For accuracy. Heh
            for (int i = 0; i < 4096; i++)
            {
                bogusTexture.Data[i] = 85;
            }
            for (int i = 0; i < 64; i++)
            {
                bogusTexture.Data[i * 64 + i]        = 193;
                bogusTexture.Data[i * 64 + (63 - i)] = 193;
            }
            Bitmaps.Add(bogusTexture);

            if (LoadData)
            {
                br.BaseStream.Seek(DataPointer, SeekOrigin.Begin);
            }

            int numBitmaps = br.ReadInt32();
            int numSounds  = br.ReadInt32();

            for (int i = 0; i < numBitmaps; i++)
            {
                bool hashitnull = false;

                byte[] localNameBytes = br.ReadBytes(8);
                char[] localname      = new char[8];

                for (int j = 0; j < 8; j++)
                {
                    char c = (char)localNameBytes[j];

                    if (c == 0)
                    {
                        hashitnull = true;
                    }
                    if (!hashitnull)
                    {
                        localname[j] = c;
                    }
                }

                string imagename = new String(localname);
                imagename = imagename.Trim(' ', '\0');
                byte framedata = br.ReadByte();
                byte lx        = br.ReadByte();
                byte ly        = br.ReadByte();
                byte flags     = br.ReadByte();
                byte average   = br.ReadByte();
                int  offset    = br.ReadInt32();

                PIGImage image = new PIGImage(lx, ly, framedata, flags, average, offset, imagename, big);
                image.LocalName = localNameBytes;
                Bitmaps.Add(image);
            }

            for (int i = 0; i < numSounds; i++)
            {
                bool hashitnull = false;

                byte[] localNameBytes = br.ReadBytes(8);
                char[] localname      = new char[8];

                for (int j = 0; j < 8; j++)
                {
                    char c = (char)localNameBytes[j];

                    if (c == 0)
                    {
                        hashitnull = true;
                    }
                    if (!hashitnull)
                    {
                        localname[j] = c;
                    }
                }

                string soundname = new string(localname);
                soundname = soundname.Trim(' ', '\0');
                int num1   = br.ReadInt32();
                int num2   = br.ReadInt32();
                int offset = br.ReadInt32();

                SoundData sound = new SoundData {
                    Data = null
                };
                sound.Name      = soundname;
                sound.LocalName = localNameBytes;
                sound.Offset    = offset;
                sound.Length    = num1;
                Sounds.Add(sound);
            }

            int basePointer = (int)br.BaseStream.Position;

            for (int i = 1; i < Bitmaps.Count; i++)
            {
                br.BaseStream.Seek(basePointer + Bitmaps[i].Offset, SeekOrigin.Begin);
                if ((Bitmaps[i].Flags & PIGImage.BM_FLAG_RLE) != 0)
                {
                    int compressedSize = br.ReadInt32();
                    Bitmaps[i].Data = br.ReadBytes(compressedSize - 4);
                }
                else
                {
                    Bitmaps[i].Data = br.ReadBytes(Bitmaps[i].Width * Bitmaps[i].Height);
                }
            }

            for (int i = 0; i < Sounds.Count; i++)
            {
                br.BaseStream.Seek(basePointer + Sounds[i].Offset, SeekOrigin.Begin);

                var soundBytes = br.ReadBytes(Sounds[i].Length);

                var ps = Sounds[i];

                ps.Data = soundBytes;
            }

            br.Dispose();
        }