Esempio n. 1
0
        public unsafe static ushort[] GetGump(int index, out int width, out int height)
        {
            (int length, int extra, bool patcher) = _file.SeekByEntryIndex(index);

            if (extra == -1)
            {
                width = 0; height = 0;
                return(null);
            }

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

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

            ushort[] pixels     = new ushort[width * height];
            int *    lookuplist = (int *)(_file.StartAddress + _file.Position);

            for (int y = 0; y < height; y++)
            {
                int gsize = 0;
                if (y < height - 1)
                {
                    gsize = lookuplist[y + 1] - lookuplist[y];
                }
                else
                {
                    gsize = (length / 4) - lookuplist[y];
                }


                GumpBlock *gmul = (GumpBlock *)(_file.StartAddress + _file.Position + lookuplist[y] * 4);
                int        pos  = y * width;

                for (int i = 0; i < gsize; i++)
                {
                    ushort val   = gmul[i].Value;
                    ushort a     = (ushort)((val > 0 ? 0x8000 : 0) | val);
                    int    count = gmul[i].Run;
                    for (int j = 0; j < count; j++)
                    {
                        pixels[pos++] = a;
                    }
                }
            }

            return(pixels);
        }
Esempio n. 2
0
        public static unsafe ushort[] GetGumpPixels(int index, out int width, out int height)
        {
            (int length, int extra, bool patcher) = _file.SeekByEntryIndex(index);

            if (extra == -1)
            {
                width  = 0;
                height = 0;

                return(null);
            }

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

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

            //width = PaddedRowWidth(16, width, 4) >> 1;
            IntPtr dataStart = _file.PositionAddress;

            ushort[] pixels     = new ushort[width * height];
            int *    lookuplist = (int *)dataStart;

            for (int y = 0; y < height; y++)
            {
                int gsize = 0;

                if (y < height - 1)
                {
                    gsize = lookuplist[y + 1] - lookuplist[y];
                }
                else
                {
                    gsize = (length >> 2) - lookuplist[y];
                }
                GumpBlock *gmul = (GumpBlock *)(dataStart + lookuplist[y] * 4);
                int        pos  = y * width;
                int        x    = 0;

                for (int i = 0; i < gsize; i++)
                {
                    ushort val   = gmul[i].Value;
                    int    count = gmul[i].Run;

                    if (val > 0)
                    {
                        for (int j = 0; j < count; j++)
                        {
                            pixels[pos + x++] = (ushort)(0x8000 | val);
                        }
                    }
                    else
                    {
                        x += count;
                    }

                    //ushort a = (ushort) ((val > 0 ? 0x8000 : 0) | val);
                    //int count = gmul[i].Run;
                    //for (int j = 0; j < count; j++)
                    //    pixels[pos++] = a;
                }
            }

            return(pixels);
        }
Esempio n. 3
0
        //public void ClearUnusedTextures()
        //{
        //    long ticks = Engine.Ticks - Constants.CLEAR_TEXTURES_DELAY;

        //    ResourceDictionary
        //       .Where(s => s.Value.Ticks < ticks)
        //       .Take(Constants.MAX_GUMP_OBJECT_REMOVED_BY_GARBAGE_COLLECTOR)
        //       .ToList()
        //       .ForEach(s =>
        //        {
        //            s.Value.Dispose();
        //            ResourceDictionary.Remove(s.Key);
        //        });

        //    //int count = 0;
        //    //long ticks = Engine.Ticks - Constants.CLEAR_TEXTURES_DELAY;

        //    //for (int i = 0; i < _usedIndex.Count; i++)
        //    //{
        //    //    uint g = _usedIndex[i];
        //    //    UOTexture texture = ResourceDictionary[g];

        //    //    if (texture.Ticks < ticks)
        //    //    {
        //    //        texture.Dispose();
        //    //        _usedIndex.RemoveAt(i--);
        //    //        ResourceDictionary.Remove(g);

        //    //        if (++count >= Constants.MAX_GUMP_OBJECT_REMOVED_BY_GARBAGE_COLLECTOR)
        //    //            break;
        //    //    }
        //    //}
        //}


        public unsafe ushort[] GetGumpPixels(uint index, out int width, out int height)
        {
            (int length, int extra, bool patcher) = _file.SeekByEntryIndex((int)index);

            if (extra == -1)
            {
                width  = 0;
                height = 0;

                return(null);
            }

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

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

            //width = PaddedRowWidth(16, width, 4) >> 1;
            IntPtr dataStart = _file.PositionAddress;

            ushort[] pixels     = new ushort[width * height];
            int *    lookuplist = (int *)dataStart;

            for (int y = 0; y < height; y++)
            {
                int gsize = 0;

                if (y < height - 1)
                {
                    gsize = lookuplist[y + 1] - lookuplist[y];
                }
                else
                {
                    gsize = (length >> 2) - lookuplist[y];
                }
                GumpBlock *gmul = (GumpBlock *)(dataStart + (lookuplist[y] << 2));
                int        pos  = y * width;

                for (int i = 0; i < gsize; i++)
                {
                    ushort val = gmul[i].Value;
                    ushort hue = (ushort)((val != 0 ? 0x8000 : 0) | val);

                    int count = gmul[i].Run;

                    //byte a = (byte)(((val & 0x8000) >> 0) << 0);
                    //byte r = (byte)(((val & 0x7C00) >> 0) << 0);
                    //byte g = (byte)(((val & 0x3E0) >> 0) << 0);
                    //byte b = (byte)(((val & 0x1F) >> 0) << 0);

                    //byte r = (byte) (( (val >> 10) ) );
                    //byte g = (byte) (( (val >> 5)  ) );
                    //byte b = (byte) (( (val >> 0)  ) );
                    //byte a = (byte) (( (val >> 15) ) );


                    //if (b == 8)
                    //{
                    //    hue = (ushort)((
                    //                       (a << 15) |
                    //                       (r << 10) |
                    //                       (g << 5)  |
                    //                       b)
                    //                   );
                    //    hue |= 0x8000;
                    //}

                    for (int j = 0; j < count; j++)
                    {
                        pixels[pos++] = hue;
                    }
                }
            }

            return(pixels);
        }