Ejemplo n.º 1
0
 private static bool compareSaveImages(byte[] newchecksum, out CheckSums sum)
 {
     sum = new CheckSums();
     for (int i = 0; i < checksums.Count; ++i)
     {
         byte[] cmp = checksums[i].checksum;
         if (((cmp == null) || (newchecksum == null)) ||
             (cmp.Length != newchecksum.Length))
         {
             return(false);
         }
         bool valid = true;
         for (int j = 0; j < cmp.Length; ++j)
         {
             if (cmp[j] != newchecksum[j])
             {
                 valid = false;
                 break;
             }
         }
         if (valid)
         {
             sum = checksums[i];
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
        private static bool CompareSaveImagesStatic(byte[] newChecksum, out CheckSums sum)
        {
            sum = new CheckSums();
            for (int i = 0; i < _checksumsStatic.Count; ++i)
            {
                byte[] cmp = _checksumsStatic[i].checksum;
                if (cmp == null || newChecksum == null || cmp.Length != newChecksum.Length)
                {
                    return(false);
                }

                bool valid = true;

                for (int j = 0; j < cmp.Length; ++j)
                {
                    if (cmp[j] == newChecksum[j])
                    {
                        continue;
                    }

                    valid = false;
                    break;
                }

                if (!valid)
                {
                    continue;
                }

                sum = _checksumsStatic[i];
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        public unsafe static void Save(string path)
        {
            string idx = Path.Combine(path, "texidx.mul");
            string mul = Path.Combine(path, "texmaps.mul");

            checksums = new List <CheckSums>();
            using (FileStream fsidx = new FileStream(idx, FileMode.Create, FileAccess.Write, FileShare.Write),
                   fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                MemoryStream memidx = new MemoryStream();
                MemoryStream memmul = new MemoryStream();
                using (BinaryWriter binidx = new BinaryWriter(memidx),
                       binmul = new BinaryWriter(memmul))
                {
                    SHA256Managed sha = new SHA256Managed();
                    //StreamWriter Tex = new StreamWriter(new FileStream("d:/texlog.txt", FileMode.Create, FileAccess.ReadWrite));
                    for (int index = 0; index < GetIdxLength(); ++index)
                    {
                        if (m_Cache[index] == null)
                        {
                            m_Cache[index] = GetTexture(index);
                        }

                        Bitmap bmp = m_Cache[index];
                        if ((bmp == null) || (m_Removed[index]))
                        {
                            binidx.Write((int)-1);                            // lookup
                            binidx.Write((int)0);                             // length
                            binidx.Write((int)-1);                            // extra
                        }
                        else
                        {
                            MemoryStream ms = new MemoryStream();
                            bmp.Save(ms, ImageFormat.Bmp);
                            byte[]    checksum = sha.ComputeHash(ms.ToArray());
                            CheckSums sum;
                            if (compareSaveImages(checksum, out sum))
                            {
                                binidx.Write((int)sum.pos);                                 //lookup
                                binidx.Write((int)sum.length);
                                binidx.Write((int)0);
                                //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, (int)sum.pos, (int)sum.length));
                                //Tex.WriteLine(System.String.Format("0x{0:X4} -> 0x{1:X4}", sum.index, index));
                                continue;
                            }
                            BitmapData bd    = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format16bppArgb1555);
                            ushort *   line  = (ushort *)bd.Scan0;
                            int        delta = bd.Stride >> 1;

                            binidx.Write((int)binmul.BaseStream.Position);                             //lookup
                            int length = (int)binmul.BaseStream.Position;

                            for (int Y = 0; Y < bmp.Height; ++Y, line += delta)
                            {
                                ushort *cur = line;
                                for (int X = 0; X < bmp.Width; ++X)
                                {
                                    binmul.Write((ushort)(cur[X] ^ 0x8000));
                                }
                            }
                            int start = length;
                            length = (int)binmul.BaseStream.Position - length;
                            binidx.Write(length);
                            binidx.Write((int)(bmp.Width == 64 ? 0 : 1));
                            bmp.UnlockBits(bd);
                            CheckSums s = new CheckSums()
                            {
                                pos = start, length = length, checksum = checksum, index = index
                            };
                            //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, start, length));
                            checksums.Add(s);
                        }
                    }
                    memidx.WriteTo(fsidx);
                    memmul.WriteTo(fsmul);
                }
            }
        }
Ejemplo n.º 4
0
 private static bool compareSaveImages(byte[] newchecksum, out CheckSums sum)
 {
     sum = new CheckSums();
     for (int i = 0; i < checksums.Count; ++i)
     {
         byte[] cmp = checksums[i].checksum;
         if (((cmp == null) || (newchecksum == null))
             || (cmp.Length != newchecksum.Length))
         {
             return false;
         }
         bool valid = true;
         for (int j = 0; j < cmp.Length; ++j)
         {
             if (cmp[j] != newchecksum[j])
             {
                 valid = false;
                 break;
             }
         }
         if (valid)
         {
             sum = checksums[i];
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 5
0
        public static unsafe void Save(string path)
        {
            string idx = Path.Combine(path, "texidx.mul");
            string mul = Path.Combine(path, "texmaps.mul");
            checksums = new List<CheckSums>();
            using (FileStream fsidx = new FileStream(idx, FileMode.Create, FileAccess.Write, FileShare.Write),
                              fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                MemoryStream memidx = new MemoryStream();
                MemoryStream memmul = new MemoryStream();
                using (BinaryWriter binidx = new BinaryWriter(memidx),
                                    binmul = new BinaryWriter(memmul))
                {
                    SHA256Managed sha = new SHA256Managed();
                    //StreamWriter Tex = new StreamWriter(new FileStream("d:/texlog.txt", FileMode.Create, FileAccess.ReadWrite));
                    for (int index = 0; index < GetIdxLength(); ++index)
                    {
                        if (m_Cache[index] == null)
                            m_Cache[index] = GetTexture(index);

                        Bitmap bmp = m_Cache[index];
                        if ((bmp == null) || (m_Removed[index]))
                        {
                            binidx.Write((int)-1); // lookup
                            binidx.Write((int)0); // length
                            binidx.Write((int)-1); // extra
                        }
                        else
                        {
                            MemoryStream ms = new MemoryStream();
                            bmp.Save(ms, ImageFormat.Bmp);
                            byte[] checksum = sha.ComputeHash(ms.ToArray());
                            CheckSums sum;
                            if (compareSaveImages(checksum, out sum))
                            {
                                binidx.Write((int)sum.pos); //lookup
                                binidx.Write((int)sum.length);
                                binidx.Write((int)0);
                                //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, (int)sum.pos, (int)sum.length));
                                //Tex.WriteLine(System.String.Format("0x{0:X4} -> 0x{1:X4}", sum.index, index));
                                continue;
                            }
                            BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format16bppArgb1555);
                            ushort* line = (ushort*)bd.Scan0;
                            int delta = bd.Stride >> 1;

                            binidx.Write((int)binmul.BaseStream.Position); //lookup
                            int length = (int)binmul.BaseStream.Position;

                            for (int Y = 0; Y < bmp.Height; ++Y, line += delta)
                            {
                                ushort* cur = line;
                                for (int X = 0; X < bmp.Width; ++X)
                                {
                                    binmul.Write((ushort)(cur[X] ^ 0x8000));
                                }
                            }
                            int start = length;
                            length = (int)binmul.BaseStream.Position - length;
                            binidx.Write(length);
                            binidx.Write((int)(bmp.Width == 64 ? 0 : 1));
                            bmp.UnlockBits(bd);
                            CheckSums s = new CheckSums() { pos = start, length = length, checksum = checksum, index = index };
                            //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, start, length));
                            checksums.Add(s);
                        }
                    }
                    memidx.WriteTo(fsidx);
                    memmul.WriteTo(fsmul);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Saves mul
        /// </summary>
        /// <param name="path"></param>
        public static unsafe void Save(string path)
        {
            checksumsLand   = new List <CheckSums>();
            checksumsStatic = new List <CheckSums>();
            string idx = Path.Combine(path, "artidx.mul");
            string mul = Path.Combine(path, "art.mul");

            using (
                FileStream fsidx = new FileStream(idx, FileMode.Create, FileAccess.Write, FileShare.Write),
                fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                MemoryStream  memidx = new MemoryStream();
                MemoryStream  memmul = new MemoryStream();
                SHA256Managed sha    = new SHA256Managed();

                using (BinaryWriter binidx = new BinaryWriter(memidx), binmul = new BinaryWriter(memmul))
                {
                    for (int index = 0; index < GetIdxLength(); index++)
                    {
                        Files.FireFileSaveEvent();
                        if (m_Cache[index] == null)
                        {
                            if (index < 0x4000)
                            {
                                m_Cache[index] = GetLand(index);
                            }
                            else
                            {
                                m_Cache[index] = GetStatic(index - 0x4000, false);
                            }
                        }
                        Bitmap bmp = m_Cache[index];
                        if ((bmp == null) || (m_Removed[index]))
                        {
                            binidx.Write(-1); // lookup
                            binidx.Write(0);  // length
                            binidx.Write(-1); // extra
                        }
                        else if (index < 0x4000)
                        {
                            MemoryStream ms = new MemoryStream();
                            bmp.Save(ms, ImageFormat.Bmp);
                            byte[]    checksum = sha.ComputeHash(ms.ToArray());
                            CheckSums sum;
                            if (compareSaveImagesLand(checksum, out sum))
                            {
                                binidx.Write(sum.pos); //lookup
                                binidx.Write(sum.length);
                                binidx.Write(0);
                                continue;
                            }
                            //land
                            BitmapData bd = bmp.LockBits(
                                new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, Settings.PixelFormat);
                            ushort *line  = (ushort *)bd.Scan0;
                            int     delta = bd.Stride >> 1;
                            binidx.Write((int)binmul.BaseStream.Position); //lookup
                            int length    = (int)binmul.BaseStream.Position;
                            int x         = 22;
                            int y         = 0;
                            int linewidth = 2;
                            for (int m = 0; m < 22; ++m, ++y, line += delta, linewidth += 2)
                            {
                                --x;
                                ushort *cur = line;
                                for (int n = 0; n < linewidth; ++n)
                                {
                                    binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                                }
                            }
                            x         = 0;
                            linewidth = 44;
                            y         = 22;
                            line      = (ushort *)bd.Scan0;
                            line     += delta * 22;
                            for (int m = 0; m < 22; m++, y++, line += delta, ++x, linewidth -= 2)
                            {
                                ushort *cur = line;
                                for (int n = 0; n < linewidth; n++)
                                {
                                    binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                                }
                            }
                            int start = length;
                            length = (int)binmul.BaseStream.Position - length;
                            binidx.Write(length);
                            binidx.Write(0);
                            bmp.UnlockBits(bd);
                            CheckSums s = new CheckSums
                            {
                                pos      = start,
                                length   = length,
                                checksum = checksum,
                                index    = index
                            };
                            checksumsLand.Add(s);
                        }
                        else
                        {
                            MemoryStream ms = new MemoryStream();
                            bmp.Save(ms, ImageFormat.Bmp);
                            byte[]    checksum = sha.ComputeHash(ms.ToArray());
                            CheckSums sum;
                            if (compareSaveImagesStatic(checksum, out sum))
                            {
                                binidx.Write(sum.pos); //lookup
                                binidx.Write(sum.length);
                                binidx.Write(0);
                                continue;
                            }

                            // art
                            BitmapData bd = bmp.LockBits(
                                new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, Settings.PixelFormat);
                            ushort *line  = (ushort *)bd.Scan0;
                            int     delta = bd.Stride >> 1;
                            binidx.Write((int)binmul.BaseStream.Position); //lookup
                            int length = (int)binmul.BaseStream.Position;
                            binmul.Write(1234);                            // header
                            binmul.Write((short)bmp.Width);
                            binmul.Write((short)bmp.Height);
                            int lookup    = (int)binmul.BaseStream.Position;
                            int streamloc = lookup + bmp.Height * 2;
                            int width     = 0;
                            for (int i = 0; i < bmp.Height; ++i) // fill lookup
                            {
                                binmul.Write(width);
                            }
                            int X = 0;
                            for (int Y = 0; Y < bmp.Height; ++Y, line += delta)
                            {
                                ushort *cur = line;
                                width = (int)(binmul.BaseStream.Position - streamloc) / 2;
                                binmul.BaseStream.Seek(lookup + Y * 2, SeekOrigin.Begin);
                                binmul.Write(width);
                                binmul.BaseStream.Seek(streamloc + width * 2, SeekOrigin.Begin);
                                int i = 0;
                                int j = 0;
                                X = 0;
                                while (i < bmp.Width)
                                {
                                    i = X;
                                    for (i = X; i <= bmp.Width; ++i)
                                    {
                                        //first pixel set
                                        if (i < bmp.Width)
                                        {
                                            if (cur[i] != 0)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    if (i < bmp.Width)
                                    {
                                        for (j = (i + 1); j < bmp.Width; ++j)
                                        {
                                            //next non set pixel
                                            if (cur[j] == 0)
                                            {
                                                break;
                                            }
                                        }
                                        binmul.Write((short)(i - X)); //xoffset
                                        binmul.Write((short)(j - i)); //run
                                        for (int p = i; p < j; ++p)
                                        {
                                            binmul.Write((ushort)(cur[p] ^ 0x8000));
                                        }
                                        X = j;
                                    }
                                }
                                binmul.Write((short)0); //xOffset
                                binmul.Write((short)0); //Run
                            }
                            int start = length;
                            length = (int)binmul.BaseStream.Position - length;
                            binidx.Write(length);
                            binidx.Write(0);
                            bmp.UnlockBits(bd);
                            CheckSums s = new CheckSums
                            {
                                pos      = start,
                                length   = length,
                                checksum = checksum,
                                index    = index
                            };
                            checksumsStatic.Add(s);
                        }
                    }
                    memidx.WriteTo(fsidx);
                    memmul.WriteTo(fsmul);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Saves mul
        /// </summary>
        /// <param name="path"></param>
        public static unsafe void Save(string path)
        {
            checksumsLand   = new List <CheckSums>();
            checksumsStatic = new List <CheckSums>();
            var idx = Path.Combine(path, "artidx.mul");
            var mul = Path.Combine(path, "art.mul");

            using (FileStream fsidx = new FileStream(idx, FileMode.Create, FileAccess.Write, FileShare.Write),
                   fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                var memidx = new MemoryStream();
                var memmul = new MemoryStream();
                var sha    = new SHA256Managed();
                //StreamWriter Tex = new StreamWriter(new FileStream("d:/artlog.txt", FileMode.Create, FileAccess.ReadWrite));

                using (BinaryWriter binidx = new BinaryWriter(memidx), binmul = new BinaryWriter(memmul))
                {
                    for (var index = 0; index < GetIdxLength(); index++)
                    {
                        Files.FireFileSaveEvent();
                        if (m_Cache[index] == null)
                        {
                            if (index < 0x4000)
                            {
                                m_Cache[index] = GetLand(index);
                            }
                            else
                            {
                                m_Cache[index] = GetStatic(index - 0x4000, false);
                            }
                        }
                        var bmp = m_Cache[index];
                        if ((bmp == null) || (m_Removed[index]))
                        {
                            binidx.Write(-1);                            // lookup
                            binidx.Write(0);                             // length
                            binidx.Write(-1);                            // extra
                            //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, (int)-1, (int)-1));
                        }
                        else if (index < 0x4000)
                        {
                            var ms = new MemoryStream();
                            bmp.Save(ms, ImageFormat.Bmp);
                            var       checksum = sha.ComputeHash(ms.ToArray());
                            CheckSums sum;
                            if (compareSaveImagesLand(checksum, out sum))
                            {
                                binidx.Write(sum.pos);                                 //lookup
                                binidx.Write(sum.length);
                                binidx.Write(0);
                                //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, (int)sum.pos, (int)sum.length));
                                //Tex.WriteLine(System.String.Format("0x{0:X4} -> 0x{1:X4}", sum.index, index));
                                continue;
                            }
                            //land
                            var bd = bmp.LockBits(
                                new Rectangle(0, 0, bmp.Width, bmp.Height),
                                ImageLockMode.ReadOnly,
                                PixelFormat.Format16bppArgb1555);
                            var line  = (ushort *)bd.Scan0;
                            var delta = bd.Stride >> 1;
                            binidx.Write((int)binmul.BaseStream.Position);                             //lookup
                            var length    = (int)binmul.BaseStream.Position;
                            var x         = 22;
                            var y         = 0;
                            var linewidth = 2;
                            for (var m = 0; m < 22; ++m, ++y, line += delta, linewidth += 2)
                            {
                                --x;
                                var cur = line;
                                for (var n = 0; n < linewidth; ++n)
                                {
                                    binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                                }
                            }
                            x         = 0;
                            linewidth = 44;
                            y         = 22;
                            line      = (ushort *)bd.Scan0;
                            line     += delta * 22;
                            for (var m = 0; m < 22; m++, y++, line += delta, ++x, linewidth -= 2)
                            {
                                var cur = line;
                                for (var n = 0; n < linewidth; n++)
                                {
                                    binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                                }
                            }
                            var start = length;
                            length = (int)binmul.BaseStream.Position - length;
                            binidx.Write(length);
                            binidx.Write(0);
                            bmp.UnlockBits(bd);
                            var s = new CheckSums
                            {
                                pos      = start,
                                length   = length,
                                checksum = checksum,
                                index    = index
                            };
                            //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, start, length));
                            checksumsLand.Add(s);
                        }
                        else
                        {
                            var ms = new MemoryStream();
                            bmp.Save(ms, ImageFormat.Bmp);
                            var       checksum = sha.ComputeHash(ms.ToArray());
                            CheckSums sum;
                            if (compareSaveImagesStatic(checksum, out sum))
                            {
                                binidx.Write(sum.pos);                                 //lookup
                                binidx.Write(sum.length);
                                binidx.Write(0);
                                //Tex.WriteLine(System.String.Format("0x{0:X4} -> 0x{1:X4}", sum.index, index));
                                //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, sum.pos, sum.length));
                                continue;
                            }

                            // art
                            var bd = bmp.LockBits(
                                new Rectangle(0, 0, bmp.Width, bmp.Height),
                                ImageLockMode.ReadOnly,
                                PixelFormat.Format16bppArgb1555);
                            var line  = (ushort *)bd.Scan0;
                            var delta = bd.Stride >> 1;
                            binidx.Write((int)binmul.BaseStream.Position);  //lookup
                            var length = (int)binmul.BaseStream.Position;
                            binmul.Write(1234);                             // header
                            binmul.Write((short)bmp.Width);
                            binmul.Write((short)bmp.Height);
                            var lookup    = (int)binmul.BaseStream.Position;
                            var streamloc = lookup + bmp.Height * 2;
                            var width     = 0;
                            for (var i = 0; i < bmp.Height; ++i)                             // fill lookup
                            {
                                binmul.Write(width);
                            }
                            var X = 0;
                            for (var Y = 0; Y < bmp.Height; ++Y, line += delta)
                            {
                                var cur = line;
                                width = (int)(binmul.BaseStream.Position - streamloc) / 2;
                                binmul.BaseStream.Seek(lookup + Y * 2, SeekOrigin.Begin);
                                binmul.Write(width);
                                binmul.BaseStream.Seek(streamloc + width * 2, SeekOrigin.Begin);
                                var i = 0;
                                var j = 0;
                                X = 0;
                                while (i < bmp.Width)
                                {
                                    i = X;
                                    for (i = X; i <= bmp.Width; ++i)
                                    {
                                        //first pixel set
                                        if (i < bmp.Width)
                                        {
                                            if (cur[i] != 0)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    if (i < bmp.Width)
                                    {
                                        for (j = (i + 1); j < bmp.Width; ++j)
                                        {
                                            //next non set pixel
                                            if (cur[j] == 0)
                                            {
                                                break;
                                            }
                                        }
                                        binmul.Write((short)(i - X));                                         //xoffset
                                        binmul.Write((short)(j - i));                                         //run
                                        for (var p = i; p < j; ++p)
                                        {
                                            binmul.Write((ushort)(cur[p] ^ 0x8000));
                                        }
                                        X = j;
                                    }
                                }
                                binmul.Write((short)0);                                 //xOffset
                                binmul.Write((short)0);                                 //Run
                            }
                            var start = length;
                            length = (int)binmul.BaseStream.Position - length;
                            binidx.Write(length);
                            binidx.Write(0);
                            bmp.UnlockBits(bd);
                            var s = new CheckSums
                            {
                                pos      = start,
                                length   = length,
                                checksum = checksum,
                                index    = index
                            };
                            //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, start, length));
                            checksumsStatic.Add(s);
                        }
                    }
                    memidx.WriteTo(fsidx);
                    memmul.WriteTo(fsmul);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Saves mul
        /// </summary>
        /// <param name="path"></param>
        public static unsafe void Save(string path)
        {
            checksumsLand=new List<CheckSums>();
            checksumsStatic = new List<CheckSums>();
            string idx = Path.Combine(path, "artidx.mul");
            string mul = Path.Combine(path, "art.mul");
            using (FileStream fsidx = new FileStream(idx, FileMode.Create, FileAccess.Write, FileShare.Write),
                              fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                MemoryStream memidx = new MemoryStream();
                MemoryStream memmul = new MemoryStream();
                SHA256Managed sha = new SHA256Managed();
                //StreamWriter Tex = new StreamWriter(new FileStream("d:/artlog.txt", FileMode.Create, FileAccess.ReadWrite));

                using (BinaryWriter binidx = new BinaryWriter(memidx),
                                    binmul = new BinaryWriter(memmul))
                {
                    for (int index = 0; index < GetIdxLength(); index++)
                    {
                        Files.FireFileSaveEvent();
                        if (m_Cache[index] == null)
                        {
                            if (index < 0x4000)
                                m_Cache[index] = GetLand(index);
                            else
                                m_Cache[index] = GetStatic(index - 0x4000,false);
                        }
                        Bitmap bmp = m_Cache[index];
                        if ((bmp == null) || (m_Removed[index]))
                        {
                            binidx.Write((int)-1); // lookup
                            binidx.Write((int)0); // length
                            binidx.Write((int)-1); // extra
                            //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, (int)-1, (int)-1));
                        }
                        else if (index < 0x4000)
                        {
                            MemoryStream ms = new MemoryStream();
                            bmp.Save(ms, ImageFormat.Bmp);
                            byte[] checksum = sha.ComputeHash(ms.ToArray());
                            CheckSums sum;
                            if (compareSaveImagesLand(checksum, out sum))
                            {
                                binidx.Write((int)sum.pos); //lookup
                                binidx.Write((int)sum.length);
                                binidx.Write((int)0);
                                //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, (int)sum.pos, (int)sum.length));
                                //Tex.WriteLine(System.String.Format("0x{0:X4} -> 0x{1:X4}", sum.index, index));
                                continue;
                            }
                            //land
                            BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format16bppArgb1555);
                            ushort* line = (ushort*)bd.Scan0;
                            int delta = bd.Stride >> 1;
                            binidx.Write((int)binmul.BaseStream.Position); //lookup
                            int length = (int)binmul.BaseStream.Position;
                            int x = 22;
                            int y = 0;
                            int linewidth = 2;
                            for (int m = 0; m < 22; ++m, ++y, line += delta, linewidth += 2)
                            {
                                --x;
                                ushort* cur = line;
                                for (int n = 0; n < linewidth; ++n)
                                    binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                            }
                            x = 0;
                            linewidth = 44;
                            y = 22;
                            line = (ushort*)bd.Scan0;
                            line += delta * 22;
                            for (int m = 0; m < 22; m++, y++, line += delta, ++x, linewidth -= 2)
                            {
                                ushort* cur = line;
                                for (int n = 0; n < linewidth; n++)
                                    binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                            }
                            int start = length;
                            length = (int)binmul.BaseStream.Position - length;
                            binidx.Write(length);
                            binidx.Write((int)0);
                            bmp.UnlockBits(bd);
                            CheckSums s = new CheckSums() { pos = start, length = length, checksum = checksum, index=index };
                            //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, start, length));
                            checksumsLand.Add(s);
                        }
                        else
                        {
                            MemoryStream ms = new MemoryStream();
                            bmp.Save(ms, ImageFormat.Bmp);
                            byte[] checksum = sha.ComputeHash(ms.ToArray());
                            CheckSums sum;
                            if (compareSaveImagesStatic(checksum,out sum))
                            {
                                binidx.Write((int)sum.pos); //lookup
                                binidx.Write((int)sum.length);
                                binidx.Write((int)0);
                                //Tex.WriteLine(System.String.Format("0x{0:X4} -> 0x{1:X4}", sum.index, index));
                                //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, sum.pos, sum.length));
                                continue;
                            }

                            // art
                            BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format16bppArgb1555);
                            ushort* line = (ushort*)bd.Scan0;
                            int delta = bd.Stride >> 1;
                            binidx.Write((int)binmul.BaseStream.Position); //lookup
                            int length = (int)binmul.BaseStream.Position;
                            binmul.Write((int)1234); // header
                            binmul.Write((short)bmp.Width);
                            binmul.Write((short)bmp.Height);
                            int lookup = (int)binmul.BaseStream.Position;
                            int streamloc = lookup + bmp.Height * 2;
                            int width = 0;
                            for (int i = 0; i < bmp.Height; ++i)// fill lookup
                                binmul.Write(width);
                            int X = 0;
                            for (int Y = 0; Y < bmp.Height; ++Y, line += delta)
                            {
                                ushort* cur = line;
                                width = (int)(binmul.BaseStream.Position - streamloc) / 2;
                                binmul.BaseStream.Seek(lookup + Y * 2, SeekOrigin.Begin);
                                binmul.Write(width);
                                binmul.BaseStream.Seek(streamloc + width * 2, SeekOrigin.Begin);
                                int i = 0;
                                int j = 0;
                                X = 0;
                                while (i < bmp.Width)
                                {
                                    i = X;
                                    for (i = X; i <= bmp.Width; ++i)
                                    {
                                        //first pixel set
                                        if (i < bmp.Width)
                                        {
                                            if (cur[i] != 0)
                                                break;
                                        }
                                    }
                                    if (i < bmp.Width)
                                    {
                                        for (j = (i + 1); j < bmp.Width; ++j)
                                        {
                                            //next non set pixel
                                            if (cur[j] == 0)
                                                break;
                                        }
                                        binmul.Write((short)(i - X)); //xoffset
                                        binmul.Write((short)(j - i)); //run
                                        for (int p = i; p < j; ++p)
                                            binmul.Write((ushort)(cur[p] ^ 0x8000));
                                        X = j;
                                    }
                                }
                                binmul.Write((short)0); //xOffset
                                binmul.Write((short)0); //Run
                            }
                            int start = length;
                            length = (int)binmul.BaseStream.Position - length;
                            binidx.Write(length);
                            binidx.Write((int)0);
                            bmp.UnlockBits(bd);
                            CheckSums s = new CheckSums() { pos = start, length = length, checksum = checksum, index=index };
                            //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, start, length));
                            checksumsStatic.Add(s);
                        }
                    }
                    memidx.WriteTo(fsidx);
                    memmul.WriteTo(fsmul);
                }
            }
        }
Ejemplo n.º 9
0
 public int GetCheckSum(ReferenceType refType)
 {
     return(CheckSums.GetCheckSum(TSAuthentication.GetLoginUser(), refType));
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Saves mul
        /// </summary>
        /// <param name="path"></param>
        public static unsafe void Save(string path)
        {
            _checksumsLand   = new List <CheckSums>();
            _checksumsStatic = new List <CheckSums>();

            string idx = Path.Combine(path, "artidx.mul");
            string mul = Path.Combine(path, "art.mul");

            using (var fsidx = new FileStream(idx, FileMode.Create, FileAccess.Write, FileShare.Write))
                using (var fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write))
                {
                    var memidx = new MemoryStream();
                    var memmul = new MemoryStream();
                    //var sha = new SHA256Managed();
                    //StreamWriter Tex = new StreamWriter(new FileStream("d:/artlog.txt", FileMode.Create, FileAccess.ReadWrite));

                    using (var binidx = new BinaryWriter(memidx))
                        using (var binmul = new BinaryWriter(memmul))
                        {
                            for (int index = 0; index < GetIdxLength(); index++)
                            {
                                Files.FireFileSaveEvent();
                                if (_cache[index] == null)
                                {
                                    if (index < 0x4000)
                                    {
                                        _cache[index] = GetLand(index);
                                    }
                                    else
                                    {
                                        _cache[index] = GetStatic(index - 0x4000, false);
                                    }
                                }

                                Bitmap bmp = _cache[index];
                                if (bmp == null || _removed[index])
                                {
                                    binidx.Write(-1); // lookup
                                    binidx.Write(0);  // length
                                    binidx.Write(-1); // extra
                                    //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, (int)-1, (int)-1));
                                }
                                else if (index < 0x4000)
                                {
                                    byte[] checksum = bmp.ToArray(PixelFormat.Format16bppArgb1555).ToSha256();
                                    if (CompareSaveImagesLand(checksum, out CheckSums sum))
                                    {
                                        binidx.Write(sum.pos); //lookup
                                        binidx.Write(sum.length);
                                        binidx.Write(0);
                                        //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, (int)sum.pos, (int)sum.length));
                                        //Tex.WriteLine(System.String.Format("0x{0:X4} -> 0x{1:X4}", sum.index, index));
                                        continue;
                                    }

                                    //land
                                    BitmapData bd = bmp.LockBits(
                                        new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly,
                                        PixelFormat.Format16bppArgb1555);
                                    var line  = (ushort *)bd.Scan0;
                                    int delta = bd.Stride >> 1;
                                    binidx.Write((int)binmul.BaseStream.Position); //lookup
                                    var length    = (int)binmul.BaseStream.Position;
                                    int x         = 22;
                                    int y         = 0;
                                    int lineWidth = 2;
                                    for (int m = 0; m < 22; ++m, ++y, line += delta, lineWidth += 2)
                                    {
                                        --x;
                                        ushort *cur = line;
                                        for (int n = 0; n < lineWidth; ++n)
                                        {
                                            binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                                        }
                                    }

                                    x         = 0;
                                    lineWidth = 44;
                                    y         = 22;
                                    line      = (ushort *)bd.Scan0;
                                    line     += delta * 22;
                                    for (int m = 0; m < 22; m++, y++, line += delta, ++x, lineWidth -= 2)
                                    {
                                        ushort *cur = line;
                                        for (int n = 0; n < lineWidth; n++)
                                        {
                                            binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                                        }
                                    }

                                    int start = length;
                                    length = (int)binmul.BaseStream.Position - length;
                                    binidx.Write(length);
                                    binidx.Write(0);
                                    bmp.UnlockBits(bd);
                                    CheckSums s = new CheckSums
                                    {
                                        pos = start, length = length, checksum = checksum, index = index
                                    };
                                    //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, start, length));
                                    _checksumsLand.Add(s);
                                }
                                else
                                {
                                    byte[] checksum = bmp.ToArray(PixelFormat.Format16bppArgb1555).ToSha256();
                                    if (CompareSaveImagesStatic(checksum, out CheckSums sum))
                                    {
                                        binidx.Write(sum.pos); //lookup
                                        binidx.Write(sum.length);
                                        binidx.Write(0);
                                        //Tex.WriteLine(System.String.Format("0x{0:X4} -> 0x{1:X4}", sum.index, index));
                                        //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, sum.pos, sum.length));
                                        continue;
                                    }

                                    // art
                                    BitmapData bd    = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format16bppArgb1555);
                                    var        line  = (ushort *)bd.Scan0;
                                    int        delta = bd.Stride >> 1;
                                    binidx.Write((int)binmul.BaseStream.Position); // lookup
                                    var length = (int)binmul.BaseStream.Position;
                                    binmul.Write(1234);                            // header
                                    binmul.Write((short)bmp.Width);
                                    binmul.Write((short)bmp.Height);
                                    var lookup    = (int)binmul.BaseStream.Position;
                                    int streamLoc = lookup + (bmp.Height * 2);
                                    int width     = 0;
                                    for (int i = 0; i < bmp.Height; ++i) // fill lookup
                                    {
                                        binmul.Write(width);
                                    }

                                    for (int y = 0; y < bmp.Height; ++y, line += delta)
                                    {
                                        ushort *cur = line;
                                        width = (int)(binmul.BaseStream.Position - streamLoc) / 2;
                                        binmul.BaseStream.Seek(lookup + (y * 2), SeekOrigin.Begin);
                                        binmul.Write(width);
                                        binmul.BaseStream.Seek(streamLoc + (width * 2), SeekOrigin.Begin);
                                        int i = 0;
                                        int x = 0;
                                        while (i < bmp.Width)
                                        {
                                            i = x;
                                            for (i = x; i <= bmp.Width; ++i)
                                            {
                                                // first pixel set
                                                if (i < bmp.Width)
                                                {
                                                    if (cur[i] != 0)
                                                    {
                                                        break;
                                                    }
                                                }
                                            }

                                            if (i >= bmp.Width)
                                            {
                                                continue;
                                            }

                                            int j;
                                            for (j = i + 1; j < bmp.Width; ++j)
                                            {
                                                // next non set pixel
                                                if (cur[j] == 0)
                                                {
                                                    break;
                                                }
                                            }

                                            binmul.Write((short)(i - x)); // xOffset
                                            binmul.Write((short)(j - i)); // run
                                            for (int p = i; p < j; ++p)
                                            {
                                                binmul.Write((ushort)(cur[p] ^ 0x8000));
                                            }

                                            x = j;
                                        }

                                        binmul.Write((short)0); // xOffset
                                        binmul.Write((short)0); // Run
                                    }

                                    int start = length;
                                    length = (int)binmul.BaseStream.Position - length;
                                    binidx.Write(length);
                                    binidx.Write(0);
                                    bmp.UnlockBits(bd);
                                    var s = new CheckSums {
                                        pos = start, length = length, checksum = checksum, index = index
                                    };
                                    //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, start, length));
                                    _checksumsStatic.Add(s);
                                }
                            }

                            memidx.WriteTo(fsidx);
                            memmul.WriteTo(fsmul);
                        }
                }
        }