예제 #1
0
        public unsafe Texture2D GetGumpTexture(int textureID, bool replaceMask080808 = false)
        {
            if (textureID < 0)
            {
                return(null);
            }

            if (m_TextureCache[textureID] == null)
            {
                int              length, extra;
                bool             patched;
                BinaryFileReader reader = m_FileIndex.Seek(textureID, out length, out extra, out patched);
                if (reader == null)
                {
                    return(null);
                }
                int width  = (extra >> 16) & 0xFFFF;
                int height = extra & 0xFFFF;
                if (width == 0 || height == 0)
                {
                    return(null);
                }
                int shortsToRead = length - (height * 2);
                if (reader.Stream.Length - reader.Position < (shortsToRead * 2))
                {
                    Tracer.Error($"Could not read gump {textureID:X4}: not enough data. Gump texture file truncated?");
                    return(null);
                }
                int[]    lookups = reader.ReadInts(height);
                int      metrics_dataread_start = (int)reader.Position;
                ushort[] fileData = reader.ReadUShorts(shortsToRead);
                ushort[] pixels   = new ushort[width * height];
                fixed(ushort *line = &pixels[0])
                {
                    fixed(ushort *data = &fileData[0])
                    {
                        for (int y = 0; y < height; ++y)
                        {
                            ushort *dataRef = data + (lookups[y] - height) * 2;
                            ushort *cur     = line + (y * width);
                            ushort *end     = cur + width;
                            while (cur < end)
                            {
                                ushort  color = *dataRef++;
                                ushort *next  = cur + *dataRef++;
                                if (color == 0)
                                {
                                    cur = next;
                                }
                                else
                                {
                                    color |= 0x8000;
                                    while (cur < next)
                                    {
                                        *cur++ = color;
                                    }
                                }
                            }
                        }
                    }
                }

                Metrics.ReportDataRead(length);
                if (replaceMask080808)
                {
                    for (int i = 0; i < pixels.Length; i++)
                    {
                        if (pixels[i] == 0x8421)
                        {
                            pixels[i] = 0xFC1F;
                        }
                    }
                }
                Texture2D texture = new Texture2D(m_graphicsDevice, width, height, false, SurfaceFormat.Bgra5551);
                texture.SetData(pixels);
                m_TextureCache[textureID] = texture;
                m_Picking.Set(textureID, width, height, pixels);
            }
            return(m_TextureCache[textureID]);
        }
예제 #2
0
        public unsafe Texture2D GetGumpXNA(int index, bool replaceMask080808 = false)
        {
            if (index < 0)
            {
                return(null);
            }

            if (m_TextureCache[index] == null)
            {
                int  length, extra;
                bool patched;

                BinaryFileReader reader = m_FileIndex.Seek(index, out length, out extra, out patched);
                if (reader == null)
                {
                    return(null);
                }

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

                int metrics_dataread_start = (int)reader.Position;

                int[]    lookups  = reader.ReadInts(height);
                ushort[] fileData = reader.ReadUShorts(length - (height * 2));

                ushort[] pixels = new ushort[width * height];

                fixed(ushort *line = &pixels[0])
                {
                    fixed(ushort *data = &fileData[0])
                    {
                        for (int y = 0; y < height; ++y)
                        {
                            ushort *dataRef = data + (lookups[y] - height) * 2;

                            ushort *cur = line + (y * width);
                            ushort *end = cur + width;

                            while (cur < end)
                            {
                                ushort  color = *dataRef++;
                                ushort *next  = cur + *dataRef++;

                                if (color == 0)
                                {
                                    cur = next;
                                }
                                else
                                {
                                    color |= 0x8000;
                                    while (cur < next)
                                    {
                                        *cur++ = color;
                                    }
                                }
                            }
                        }
                    }
                }

                Metrics.ReportDataRead(length);

                if (replaceMask080808)
                {
                    for (int i = 0; i < pixels.Length; i++)
                    {
                        if (pixels[i] == 0x8421)
                        {
                            pixels[i] = 0xFC1F;
                        }
                    }
                }

                Texture2D texture = new Texture2D(m_graphicsDevice, width, height, false, SurfaceFormat.Bgra5551);
                texture.SetData(pixels);
                m_TextureCache[index] = texture;
            }
            return(m_TextureCache[index]);
        }
예제 #3
0
        public unsafe static Texture2D GetGumpXNA(int index)
        {
            if (index < 0)
            {
                return(null);
            }
            if (m_cache[index] == null)
            {
                int  length, extra;
                bool patched;

                BinaryFileReader reader = m_FileIndex.Seek(index, out length, out extra, out patched);
                if (reader == null)
                {
                    return(null);
                }

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

                int metrics_dataread_start = (int)reader.Position;

                int[]    lookups  = reader.ReadInts(height);
                ushort[] fileData = reader.ReadUShorts(length - (height * 2));

                uint[] pixels = new uint[width * height];

                fixed(uint *line = &pixels[0])
                {
                    fixed(ushort *data = &fileData[0])
                    {
                        for (int y = 0; y < height; ++y)
                        {
                            ushort *dataRef = data + (lookups[y] - height) * 2;

                            uint *cur = line + (y * width);
                            uint *end = cur + width;

                            while (cur < end)
                            {
                                uint  color = *dataRef++;
                                uint *next  = cur + *dataRef++;

                                if (color == 0)
                                {
                                    cur = next;
                                }
                                else
                                {
                                    uint color32 = 0xFF000000 + (
                                        ((((color >> 10) & 0x1F) * multiplier)) |
                                        ((((color >> 5) & 0x1F) * multiplier) << 8) |
                                        (((color & 0x1F) * multiplier) << 16)
                                        );
                                    while (cur < next)
                                    {
                                        *cur++ = color32;
                                    }
                                }
                            }
                        }
                    }
                }

                Metrics.ReportDataRead(length);

                Texture2D texture = new Texture2D(m_graphicsDevice, width, height, false, SurfaceFormat.Color);
                texture.SetData(pixels);
                m_cache[index] = texture;
            }
            return(m_cache[index]);
        }