Beispiel #1
0
        public static Bitmap GetLand(int index)
        {
            index &= 0x3FFF;

            if (m_Cache[index] != null)
            {
                return(m_Cache[index]);
            }

            int    length, extra;
            bool   patched;
            Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(null);
            }

            return(m_Cache[index] = LoadLand(stream));
        }
Beispiel #2
0
        public static MultiComponentList Load(int index)
        {
            try
            {
                int    length, extra;
                bool   patched;
                Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

                if (stream == null)
                {
                    return(MultiComponentList.Empty);
                }

                return(new MultiComponentList(new BinaryReader(stream), length / 12));
            }
            catch
            {
                return(MultiComponentList.Empty);
            }
        }
Beispiel #3
0
        public unsafe static Bitmap GetTexture(int index)
        {
            int  length, extra;
            bool patched;

            Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(null);
            }

            int size = extra == 0 ? 64 : 128;

            Bitmap       bmp = new Bitmap(size, size, PixelFormat.Format16bppArgb1555);
            BitmapData   bd  = bmp.LockBits(new Rectangle(0, 0, size, size), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);
            BinaryReader bin = new BinaryReader(stream);

            ushort *line  = (ushort *)bd.Scan0;
            int     delta = bd.Stride >> 1;

            for (int y = 0; y < size; ++y, line += delta)
            {
                ushort *cur = line;
                ushort *end = cur + size;

                while (cur < end)
                {
                    *cur++ = (ushort)(bin.ReadUInt16() ^ 0x8000);
                }
            }

            bmp.UnlockBits(bd);

            return(bmp);
        }
Beispiel #4
0
        public unsafe static Bitmap GetGump(int index, Hue hue, bool onlyHueGrayPixels)
        {
            int    length, extra;
            bool   patched;
            Stream stream = m_FileIndex.Seek(index, out length, out extra, out patched);

            if (stream == null)
            {
                return(null);
            }

            int width  = (extra >> 16) & 0xFFFF;
            int height = extra & 0xFFFF;

            if (width <= 0 || height <= 0)
            {
                return(null);
            }

            int bytesPerLine   = width << 1;
            int bytesPerStride = (bytesPerLine + 3) & ~3;
            int bytesForImage  = height * bytesPerStride;

            int pixelsPerStride      = (width + 1) & ~1;
            int pixelsPerStrideDelta = pixelsPerStride - width;

            byte[] pixelBuffer = m_PixelBuffer;

            if (pixelBuffer == null || pixelBuffer.Length < bytesForImage)
            {
                m_PixelBuffer = pixelBuffer = new byte[(bytesForImage + 2047) & ~2047];
            }

            byte[] streamBuffer = m_StreamBuffer;

            if (streamBuffer == null || streamBuffer.Length < length)
            {
                m_StreamBuffer = streamBuffer = new byte[(length + 2047) & ~2047];
            }

            byte[] colorTable = m_ColorTable;

            if (colorTable == null)
            {
                m_ColorTable = colorTable = new byte[128];
            }

            stream.Read(streamBuffer, 0, length);

            fixed(short *psHueColors = hue.Colors)
            {
                fixed(byte *pbStream = streamBuffer)
                {
                    fixed(byte *pbPixels = pixelBuffer)
                    {
                        fixed(byte *pbColorTable = colorTable)
                        {
                            ushort *pHueColors    = (ushort *)psHueColors;
                            ushort *pHueColorsEnd = pHueColors + 32;

                            ushort *pColorTable = (ushort *)pbColorTable;

                            ushort *pColorTableOpaque = pColorTable;

                            while (pHueColors < pHueColorsEnd)
                            {
                                *pColorTableOpaque++ = *pHueColors++;
                            }

                            ushort *pPixelDataStart = (ushort *)pbPixels;

                            int *pLookup        = (int *)pbStream;
                            int *pLookupEnd     = pLookup + height;
                            int *pPixelRleStart = pLookup;
                            int *pPixelRle;

                            ushort *pPixel    = pPixelDataStart;
                            ushort *pRleEnd   = pPixel;
                            ushort *pPixelEnd = pPixel + width;

                            ushort color, count;

                            if (onlyHueGrayPixels)
                            {
                                while (pLookup < pLookupEnd)
                                {
                                    pPixelRle = pPixelRleStart + *pLookup++;
                                    pRleEnd   = pPixel;

                                    while (pPixel < pPixelEnd)
                                    {
                                        color = *(ushort *)pPixelRle;
                                        count = *(1 + (ushort *)pPixelRle);
                                        ++pPixelRle;

                                        pRleEnd += count;

                                        if (color != 0 && (color & 0x1F) == ((color >> 5) & 0x1F) && (color & 0x1F) == ((color >> 10) & 0x1F))
                                        {
                                            color = pColorTable[color >> 10];
                                        }
                                        else if (color != 0)
                                        {
                                            color ^= 0x8000;
                                        }

                                        while (pPixel < pRleEnd)
                                        {
                                            *pPixel++ = color;
                                        }
                                    }

                                    pPixel    += pixelsPerStrideDelta;
                                    pPixelEnd += pixelsPerStride;
                                }
                            }
                            else
                            {
                                while (pLookup < pLookupEnd)
                                {
                                    pPixelRle = pPixelRleStart + *pLookup++;
                                    pRleEnd   = pPixel;

                                    while (pPixel < pPixelEnd)
                                    {
                                        color = *(ushort *)pPixelRle;
                                        count = *(1 + (ushort *)pPixelRle);
                                        ++pPixelRle;

                                        pRleEnd += count;

                                        if (color != 0)
                                        {
                                            color = pColorTable[color >> 10];
                                        }

                                        while (pPixel < pRleEnd)
                                        {
                                            *pPixel++ = color;
                                        }
                                    }

                                    pPixel    += pixelsPerStrideDelta;
                                    pPixelEnd += pixelsPerStride;
                                }
                            }

                            return(new Bitmap(width, height, bytesPerStride, PixelFormat.Format16bppArgb1555, (IntPtr)pPixelDataStart));
                        }
                    }
                }
            }
        }
        private void InternalCompare()
        {
            if (_usesIdx)
            {
                    byte[] buffOne = new byte[0xFFFF];
                    byte[] buffTwo = new byte[0xFFFF];

                    FileInfo infoOne = new FileInfo(_pathOneIdx);
                    FileInfo infoTwo = new FileInfo(_pathTwoIdx);

                    long lengthOne = infoOne.Length;
                    long lengthTwo = infoTwo.Length;

                    int maxIndexes = (int)Math.Min(lengthOne / 12, lengthTwo / 12);

                    FileIndex indexOne = new FileIndex(Path.GetDirectoryName(_pathOneMul), Path.GetFileName(_pathOneIdx), Path.GetFileName(_pathOneMul), maxIndexes);
                    FileIndex indexTwo = new FileIndex(Path.GetDirectoryName(_pathTwoMul), Path.GetFileName(_pathTwoIdx), Path.GetFileName(_pathTwoMul), maxIndexes);

                    for (int i = 0; i < maxIndexes; i++)
                    {
                        Stream streamOne = indexOne.Seek(i);
                        Stream streamTwo = indexTwo.Seek(i);
                        BinaryReader readerOne = null;
                        BinaryReader readerTwo = null;

                        if (streamOne == null && streamTwo == null)
                            continue;

                        if (streamOne != null)
                            readerOne = new BinaryReader(streamOne);

                        if (streamTwo != null)
                            readerTwo = new BinaryReader(streamTwo);

                        if (readerOne != null && readerTwo == null)
                            CreatePatchFromIdxMul(readerOne, indexOne.Index[i]);
                        else if (readerOne == null && readerTwo != null)
                            CreatePatchFromIdxMul(readerTwo, indexTwo.Index[i]);
                        else
                        {
                            Entry3D entryOne = indexOne.Index[i];
                            Entry3D entryTwo = indexTwo.Index[i];

                            if (entryOne.length != entryTwo.length)
                            {
                                CreatePatchFromIdxMul(readerOne, entryOne);
                                CreatePatchFromIdxMul(readerTwo, entryTwo);
                            }
                            else
                            {
                                while (readerOne.BaseStream.Position != readerOne.BaseStream.Length)
                                {
                                    int toRead = Math.Min(buffOne.Length, (int)(readerOne.BaseStream.Length - readerOne.BaseStream.Position));

                                    readerOne.Read(buffOne, 0, toRead);
                                    readerTwo.Read(buffTwo, 0, toRead);

                                    bool match = true;

                                    for (int a = 0; a < buffOne.Length; a++)
                                        if (buffOne[a] != buffTwo[a])
                                        {
                                            match = false;
                                            break;
                                        }

                                    if (!match)
                                    {
                                        CreatePatchFromIdxMul(readerOne, entryOne);
                                        CreatePatchFromIdxMul(readerTwo, entryTwo);
                                    }
                                }
                            }
                        }
                    }

            }
            else
            {

            }
        }