Example #1
0
 public static void ConvertSprite(ref byte[] file, Sprite sprite)
 {
     try
     {
         sprite.animationByte = file[12];
         int        num1    = (int)file[6];
         int        num2    = (int)file[7];
         short      num3    = (short)(((int)file[0] << 8) + (int)file[1]);
         List <int> intList = new List <int>();
         int        num4    = 16 + (int)num3 * 4;
         for (int index = 16; index < 16 + (int)num3 * 4; index += 4)
         {
             intList.Add(((int)file[index] << 24) + ((int)file[index + 1] << 16) + ((int)file[index + 2] << 8) + (int)file[index + 3]);
         }
         int num5 = ((int)file[2] << 8) + (int)file[3];
         int num6 = ((int)file[num4 + intList[0] + 8] << 8) + (int)file[num4 + intList[0] + 9];
         sprite.imagesPerFrame = num6;
         foreach (int num7 in intList)
         {
             int    num8     = ((int)file[num4 + num7 + 4] << 8) + (int)file[num4 + num7 + 5];
             int    num9     = ((int)file[num4 + num7 + 6] << 8) + (int)file[num4 + num7 + 7];
             byte[] numArray = new byte[num8 * num9 * 4];
             int    num10    = num8 * num9;
             int    index1   = 0;
             sprite.textureFormat = (SpriteTextureFormat)num5;
             if (num5 == 1024)
             {
                 int    num11  = num4 + num7;
                 int    width  = ((int)file[num11 + 24] << 8) + (int)file[num11 + 25];
                 int    height = ((int)file[num11 + 26] << 8) + (int)file[num11 + 27];
                 int    num12  = num11 + 32;
                 int    num13  = width * height;
                 byte[] source = new byte[width * height * 4];
                 for (int index2 = 0; index2 < num13 * 2; index2 += 2)
                 {
                     bool   alpha    = false;
                     byte[] rgbA8888 = ImageHandler.RGBA5551ToRGBA8888(new byte[2]
                     {
                         file[num12 + index2],
                         file[num12 + index2 + 1]
                     }, ref alpha);
                     source[index1] = rgbA8888[2];
                     int index3 = index1 + 1;
                     source[index3] = rgbA8888[1];
                     int index4 = index3 + 1;
                     source[index4] = rgbA8888[0];
                     int index5 = index4 + 1;
                     source[index5] = rgbA8888[3];
                     index1         = index5 + 1;
                 }
                 Rectangle  rect       = new Rectangle(0, 0, width, height);
                 Bitmap     bitmap     = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                 BitmapData bitmapdata = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                 IntPtr     scan0      = bitmapdata.Scan0;
                 Marshal.Copy(source, 0, scan0, source.Length);
                 bitmap.UnlockBits(bitmapdata);
                 sprite.frames.Add(bitmap);
             }
             else
             {
                 int width       = 0;
                 int height      = 0;
                 int sourceIndex = num4 + num7 + 24;
                 int num11       = sourceIndex;
                 int num12       = num5 != 4 ? num11 + 32 : num11 + 512;
                 for (int index2 = 0; index2 < sprite.imagesPerFrame; ++index2)
                 {
                     int index3 = 0;
                     int num13  = num5 != 4 ? num12 + width * height / 2 : num12 + width * height;
                     width  = ((int)file[num13 + 4] << 8) + (int)file[num13 + 5];
                     height = ((int)file[num13 + 6] << 8) + (int)file[num13 + 7];
                     byte[] source = new byte[width * height * 4];
                     int    num14  = width * height;
                     num12 = num13 + 8;
                     if (num5 == 4)
                     {
                         byte[] palette = new byte[512];
                         Array.Copy((Array)file, sourceIndex, (Array)palette, 0, 512);
                         List <byte[]> numArrayList = ImageHandler.LoadPalette(ref palette, 512);
                         for (int index4 = 0; index4 < num14; ++index4)
                         {
                             int index5 = (int)file[num12 + index4];
                             source[index3] = numArrayList[index5][2];
                             int index6 = index3 + 1;
                             source[index6] = numArrayList[index5][1];
                             int index7 = index6 + 1;
                             source[index7] = numArrayList[index5][0];
                             int index8 = index7 + 1;
                             source[index8] = numArrayList[index5][3];
                             index3         = index8 + 1;
                         }
                     }
                     else
                     {
                         byte[] palette = new byte[32];
                         Array.Copy((Array)file, sourceIndex, (Array)palette, 0, 32);
                         List <byte[]> numArrayList = ImageHandler.LoadPalette(ref palette, 32);
                         int           num15        = num14 / 2;
                         for (int index4 = 0; index4 < num15; ++index4)
                         {
                             int index5 = (int)file[num12 + index4] >> 4;
                             source[index3] = numArrayList[index5][2];
                             int index6 = index3 + 1;
                             source[index6] = numArrayList[index5][1];
                             int index7 = index6 + 1;
                             source[index7] = numArrayList[index5][0];
                             int index8 = index7 + 1;
                             source[index8] = numArrayList[index5][3];
                             int index9  = index8 + 1;
                             int index10 = (int)file[num12 + index4] & 15;
                             source[index9] = numArrayList[index10][2];
                             int index11 = index9 + 1;
                             source[index11] = numArrayList[index10][1];
                             int index12 = index11 + 1;
                             source[index12] = numArrayList[index10][0];
                             int index13 = index12 + 1;
                             source[index13] = numArrayList[index10][3];
                             index3          = index13 + 1;
                         }
                     }
                     Rectangle  rect       = new Rectangle(0, 0, width, height);
                     Bitmap     bitmap     = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                     BitmapData bitmapdata = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                     IntPtr     scan0      = bitmapdata.Scan0;
                     Marshal.Copy(source, 0, scan0, source.Length);
                     bitmap.UnlockBits(bitmapdata);
                     sprite.frames.Add(bitmap);
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
Example #2
0
        public static Bitmap ConvertSpriteToImage(ref byte[] file)
        {
            try
            {
                short      num1    = (short)(((int)file[0] << 8) + (int)file[1]);
                List <int> intList = new List <int>();
                for (int index = 16; index < 16 + (int)num1 * 4; index += 4)
                {
                    intList.Add(((int)file[index] << 24) + ((int)file[index + 1] << 16) + ((int)file[index + 2] << 8) + (int)file[index + 3]);
                }
                int    num2        = 16 + (int)num1 * 4;
                int    num3        = (int)file[3];
                int    sourceIndex = num2 + 24;
                int    num4        = sourceIndex;
                int    num5        = (num3 != 4 ? num4 + 32 : num4 + 512) + 8;
                int    width       = ((int)file[num2 + 4] << 8) + (int)file[num2 + 5];
                int    height      = ((int)file[num2 + 6] << 8) + (int)file[num2 + 7];
                byte[] palette     = new byte[512];
                Array.Copy((Array)file, sourceIndex, (Array)palette, 0, 512);
                List <byte[]> numArrayList = ImageHandler.LoadPalette(ref palette, 512);
                byte[]        source       = new byte[width * height * 4];
                int           num6         = width * height;
                int           index1       = 0;
                switch (num3)
                {
                case 4:
                    for (int index2 = 0; index2 < num6; ++index2)
                    {
                        int index3 = (int)file[num5 + index2];
                        source[index1] = numArrayList[index3][2];
                        int index4 = index1 + 1;
                        source[index4] = numArrayList[index3][1];
                        int index5 = index4 + 1;
                        source[index5] = numArrayList[index3][0];
                        int index6 = index5 + 1;
                        source[index6] = numArrayList[index3][3];
                        index1         = index6 + 1;
                    }
                    goto case 1024;

                case 1024:
                    Rectangle  rect       = new Rectangle(0, 0, width, height);
                    Bitmap     bitmap     = new Bitmap(width, height, PixelFormat.Format32bppArgb);
                    BitmapData bitmapdata = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                    IntPtr     scan0      = bitmapdata.Scan0;
                    Marshal.Copy(source, 0, scan0, source.Length);
                    bitmap.UnlockBits(bitmapdata);
                    return(bitmap);

                default:
                    int num7 = num6 / 2;
                    for (int index2 = 0; index2 < num7; ++index2)
                    {
                        int index3 = (int)file[num5 + index2] >> 4;
                        source[index1] = numArrayList[index3][2];
                        int index4 = index1 + 1;
                        source[index4] = numArrayList[index3][1];
                        int index5 = index4 + 1;
                        source[index5] = numArrayList[index3][0];
                        int index6 = index5 + 1;
                        source[index6] = numArrayList[index3][3];
                        int index7 = index6 + 1;
                        int index8 = (int)file[num5 + index2] & 15;
                        source[index7] = numArrayList[index8][2];
                        int index9 = index7 + 1;
                        source[index9] = numArrayList[index8][1];
                        int index10 = index9 + 1;
                        source[index10] = numArrayList[index8][0];
                        int index11 = index10 + 1;
                        source[index11] = numArrayList[index8][3];
                        index1          = index11 + 1;
                    }
                    goto case 1024;
                }
            }
            catch
            {
            }
            return(new Bitmap(1, 1));
        }