Beispiel #1
0
        static Hues()
        {
            string path  = Client.GetFilePath("hues.mul");
            int    index = 0;

            m_List = new Hue[3000];

            if (path != null)
            {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader bin = new BinaryReader(fs);

                    int blockCount = (int)fs.Length / 708;

                    if (blockCount > 375)
                    {
                        blockCount = 375;
                    }

                    for (int i = 0; i < blockCount; ++i)
                    {
                        bin.ReadInt32();

                        for (int j = 0; j < 8; ++j, ++index)
                        {
                            m_List[index] = new Hue(index, bin);
                        }
                    }
                }
            }

            for ( ; index < 3000; ++index)
            {
                m_List[index] = new Hue(index);
            }
        }
        public static unsafe 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 );
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public static Frame[] GetAnimation(int body, int action, int direction, int hue, bool preserveHue)
        {
            if (preserveHue)
            {
                Translate(ref body);
            }
            else
            {
                Translate(ref body, ref hue);
            }

            int       fileType = BodyConverter.Convert(ref body);
            FileIndex fileIndex;

            int index;

            switch (fileType)
            {
            default:
            case 1:
            {
                fileIndex = m_FileIndex;

                if (body < 200)
                {
                    index = body * 110;
                }
                else if (body < 400)
                {
                    index = 22000 + ((body - 200) * 65);
                }
                else
                {
                    index = 35000 + ((body - 400) * 175);
                }

                break;
            }

            case 2:
            {
                fileIndex = m_FileIndex2;

                if (body < 200)
                {
                    index = body * 110;
                }
                else
                {
                    index = 22000 + ((body - 200) * 65);
                }

                break;
            }

            case 3:
            {
                fileIndex = m_FileIndex3;

                if (body < 300)
                {
                    index = body * 65;
                }
                else if (body < 400)
                {
                    index = 33000 + ((body - 300) * 110);
                }
                else
                {
                    index = 35000 + ((body - 400) * 175);
                }

                break;
            }

            case 4:
            {
                fileIndex = m_FileIndex4;

                if (body < 200)
                {
                    index = body * 110;
                }
                else if (body < 400)
                {
                    index = 22000 + ((body - 200) * 65);
                }
                else
                {
                    index = 35000 + ((body - 400) * 175);
                }

                break;
            }

            case 5:
            {
                fileIndex = m_FileIndex5;

                if (body < 200 && body != 34)                                  // looks strange, though it works.
                {
                    index = body * 110;
                }
                else
                {
                    index = 35000 + ((body - 400) * 65);
                }

                break;
            }
            }

            index += action * 5;

            if (direction <= 4)
            {
                index += direction;
            }
            else
            {
                index += direction - (direction - 4) * 2;
            }

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

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

            bool flip = (direction > 4);

            BinaryReader bin = new BinaryReader(stream);

            ushort[] palette = new ushort[0x100];

            for (int i = 0; i < 0x100; ++i)
            {
                palette[i] = (ushort)(bin.ReadUInt16() ^ 0x8000);
            }

            int start      = (int)bin.BaseStream.Position;
            int frameCount = bin.ReadInt32();

            int[] lookups = new int[frameCount];

            for (int i = 0; i < frameCount; ++i)
            {
                lookups[i] = start + bin.ReadInt32();
            }

            bool onlyHueGrayPixels = ((hue & 0x8000) == 0);

            hue = (hue & 0x3FFF) - 1;

            Hue hueObject = null;

            if (hue >= 0 && hue < Hues.List.Length)
            {
                hueObject = Hues.List[hue];
            }

            Frame[] frames = new Frame[frameCount];

            for (int i = 0; i < frameCount; ++i)
            {
                bin.BaseStream.Seek(lookups[i], SeekOrigin.Begin);
                frames[i] = new Frame(palette, bin, flip);

                if (hueObject != null)
                {
                    hueObject.ApplyTo(frames[i].Bitmap, onlyHueGrayPixels);
                }
            }

            return(frames);
        }
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));
                        }
                    }
                }
            }
        }
        static Hues()
        {
            string path = Client.GetFilePath( "hues.mul" );
            int index = 0;

            m_List = new Hue[3000];

            if ( path != null )
            {
                using ( FileStream fs = new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read ) )
                {
                    BinaryReader bin = new BinaryReader( fs );

                    int blockCount = (int)fs.Length / 708;

                    if ( blockCount > 375 )
                        blockCount = 375;

                    for ( int i = 0; i < blockCount; ++i )
                    {
                        bin.ReadInt32();

                        for ( int j = 0; j < 8; ++j, ++index )
                            m_List[index] = new Hue( index, bin );
                    }
                }
            }

            for ( ; index < 3000; ++index )
                m_List[index] = new Hue( index );
        }