/// <summary>
        /// Saves a wz file to the disk, AKA repacking.
        /// </summary>
        /// <param name="path">Path to the output wz file</param>
        public void SaveToDisk(string path, WzMapleVersion savingToPreferredWzVer = WzMapleVersion.UNKNOWN)
        {
            if (savingToPreferredWzVer == WzMapleVersion.UNKNOWN)
            {
                WzIv = WzTool.GetIvByMapleVersion(maplepLocalVersion); // get from local WzFile
            }
            else
            {
                WzIv = WzTool.GetIvByMapleVersion(savingToPreferredWzVer); // custom selected
            }
            wzDir.WzIv = WzIv;

            CreateVersionHash();
            wzDir.SetHash(versionHash);

            string tempFile = Path.GetFileNameWithoutExtension(path) + ".TEMP";

            File.Create(tempFile).Close();
            wzDir.GenerateDataFile(tempFile, WzIv);

            WzTool.StringCache.Clear();
            uint totalLen = wzDir.GetImgOffsets(wzDir.GetOffsets(Header.FStart + 2));

            using (WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(path), WzIv))
            {
                wzWriter.Hash = (uint)versionHash;
                Header.FSize  = totalLen - Header.FStart;
                for (int i = 0; i < 4; i++)
                {
                    wzWriter.Write((byte)Header.Ident[i]);
                }
                wzWriter.Write((long)Header.FSize);
                wzWriter.Write(Header.FStart);
                wzWriter.WriteNullTerminatedString(Header.Copyright);

                long extraHeaderLength = Header.FStart - wzWriter.BaseStream.Position;
                if (extraHeaderLength > 0)
                {
                    wzWriter.Write(new byte[(int)extraHeaderLength]);
                }
                wzWriter.Write(version);
                wzWriter.Header = Header;
                wzDir.SaveDirectory(wzWriter);
                wzWriter.StringCache.Clear();

                using (FileStream fs = File.OpenRead(tempFile))
                {
                    wzDir.SaveImages(wzWriter, fs);
                }
                File.Delete(tempFile);

                wzWriter.StringCache.Clear();
            }


            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Exemple #2
0
        /// <summary>
        /// Saves a wz file to the disk, AKA repacking.
        /// </summary>
        /// <param name="path">Path to the output wz file</param>
        public void SaveToDisk(string path)
        {
            _wzIv = WzTool.GetIvByMapleVersion(MapleVersion);
            CreateVersionHash();
            WzDirectory.SetHash(_versionHash);
            var tempFile = Path.GetFileNameWithoutExtension(path) + ".TEMP";

            File.Create(tempFile).Close();
            WzDirectory.GenerateDataFile(tempFile);
            WzTool.StringCache.Clear();
            var totalLen = WzDirectory.GetImgOffsets(WzDirectory.GetOffsets(Header.FStart + 2));
            var wzWriter = new WzBinaryWriter(File.Create(path), _wzIv)
            {
                Hash = _versionHash
            };

            Header.FSize = totalLen - Header.FStart;
            for (var i = 0; i < 4; i++)
            {
                {
                    wzWriter.Write((byte)Header.Ident[i]);
                }
            }

            wzWriter.Write((long)Header.FSize);
            wzWriter.Write(Header.FStart);
            wzWriter.WriteNullTerminatedString(Header.Copyright);
            var extraHeaderLength = Header.FStart - wzWriter.BaseStream.Position;

            if (extraHeaderLength > 0)
            {
                wzWriter.Write(new byte[(int)extraHeaderLength]);
            }

            wzWriter.Write(_version);
            wzWriter.Header = Header;
            WzDirectory.SaveDirectory(wzWriter);
            wzWriter.StringCache.Clear();
            var fs = File.OpenRead(tempFile);

            WzDirectory.SaveImages(wzWriter, fs);
            fs.Close();
            File.Delete(tempFile);
            wzWriter.StringCache.Clear();
            wzWriter.Close();
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Exemple #3
0
        /// <summary>
        /// Saves a wz file to the disk, AKA repacking.
        /// </summary>
        /// <param name="path">Path to the output wz file</param>
        public void SaveToDisk(string path)
        {
            CreateVersionHash();
            wzDir.SetHash(versionHash);
            string tempFile = Path.GetFileNameWithoutExtension(path) + ".TEMP";

            File.Create(tempFile).Close();
            wzDir.GenerateDataFile(tempFile);
            WzTool.StringCache.Clear();
            uint totalLen = wzDir.GetImgOffsets(wzDir.GetOffsets(Header.FStart + 2));

            WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(path), mapleVersion, false);

            wzWriter.Hash = (uint)versionHash;
            Header.FSize  = totalLen - Header.FStart;
            for (int i = 0; i < 4; i++)
            {
                wzWriter.Write((byte)Header.Ident[i]);
            }
            wzWriter.Write((long)Header.FSize);
            wzWriter.Write(Header.FStart);
            wzWriter.WriteNullTerminatedString(Header.Copyright);
            long extraHeaderLength = Header.FStart - wzWriter.BaseStream.Position;

            if (extraHeaderLength > 0)
            {
                wzWriter.Write(new byte[(int)extraHeaderLength]);
            }
            wzWriter.Write(version);
            wzWriter.Header = Header;
            wzDir.SaveDirectory(wzWriter);
            wzWriter.StringCache.Clear();
            using (FileStream fs = File.OpenRead(tempFile)) {
                wzDir.SaveImages(wzWriter, fs);
                fs.Close();
            }
            File.Delete(tempFile);
            wzWriter.StringCache.Clear();
            wzWriter.Close();
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
        /// <summary>
        /// Saves a wz file to the disk, AKA repacking.
        /// </summary>
        /// <param name="path">Path to the output wz file</param>
        public void SaveToDisk(string path, WzMapleVersion savingToPreferredWzVer = WzMapleVersion.UNKNOWN)
        {
            // WZ IV
            if (savingToPreferredWzVer == WzMapleVersion.UNKNOWN)
            {
                WzIv = WzTool.GetIvByMapleVersion(maplepLocalVersion); // get from local WzFile
            }
            else
            {
                WzIv = WzTool.GetIvByMapleVersion(savingToPreferredWzVer); // custom selected
            }
            bool bIsWzIvSimilar = WzIv.SequenceEqual(wzDir.WzIv);          // check if its saving to the same IV.

            wzDir.WzIv = WzIv;

            // MapleStory UserKey
            bool bIsWzUserKeyDefault = MapleCryptoConstants.IsDefaultMapleStoryUserKey(); // check if its saving to the same UserKey.

            //

            CreateWZVersionHash();
            wzDir.SetVersionHash(versionHash);

            string tempFile = Path.GetFileNameWithoutExtension(path) + ".TEMP";

            File.Create(tempFile).Close();
            using (FileStream fs = new FileStream(tempFile, FileMode.Append, FileAccess.Write))
            {
                wzDir.GenerateDataFile(bIsWzIvSimilar ? null : WzIv, bIsWzUserKeyDefault, fs);
            }

            WzTool.StringCache.Clear();
            uint totalLen = wzDir.GetImgOffsets(wzDir.GetOffsets(Header.FStart + 2));

            using (WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(path), WzIv))
            {
                wzWriter.Hash = versionHash;
                Header.FSize  = totalLen - Header.FStart;
                for (int i = 0; i < 4; i++)
                {
                    wzWriter.Write((byte)Header.Ident[i]);
                }
                wzWriter.Write((long)Header.FSize);
                wzWriter.Write(Header.FStart);
                wzWriter.WriteNullTerminatedString(Header.Copyright);

                long extraHeaderLength = Header.FStart - wzWriter.BaseStream.Position;
                if (extraHeaderLength > 0)
                {
                    wzWriter.Write(new byte[(int)extraHeaderLength]);
                }
                wzWriter.Write(version);
                wzWriter.Header = Header;
                wzDir.SaveDirectory(wzWriter);
                wzWriter.StringCache.Clear();

                using (FileStream fs = File.OpenRead(tempFile))
                {
                    wzDir.SaveImages(wzWriter, fs);
                }
                File.Delete(tempFile);

                wzWriter.StringCache.Clear();
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }