/// <summary> /// Saves a wz file to the disk, AKA repacking. /// </summary> /// <param name="pPath">Path to the output wz file</param> public void SaveToDisk(string pPath) { mWzIv = WzTool.GetIvByMapleVersion(mMapleVersion); CreateVersionHash(); SetHash(mVersionHash); string tempFile = Path.GetFileNameWithoutExtension(pPath) + ".TEMP"; File.Create(tempFile).Close(); GenerateDataFile(tempFile); WzTool.StringCache.Clear(); uint totalLen = GetImgOffsets(GetOffsets(Header.FStart + 2)); WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(pPath), mWzIv) { Hash = mVersionHash }; Header.FSize = totalLen - Header.FStart; wzWriter.Write(Header.Ident, false); wzWriter.Write((long)Header.FSize); wzWriter.Write(Header.FStart); wzWriter.WriteNullTerminatedString(Header.Copyright); wzWriter.Write(new byte[Header.ExtraBytes]); wzWriter.Write(mVersion); wzWriter.Header = Header; SaveDirectory(wzWriter); wzWriter.StringCache.Clear(); FileStream fs = File.OpenRead(tempFile); SaveImages(wzWriter, fs); fs.Close(); File.Delete(tempFile); wzWriter.StringCache.Clear(); wzWriter.Close(); }
public override void WriteValue(WzBinaryWriter writer) { writer.WriteStringValue("Sound_DX8", 0x73, 0x1B); writer.Write((byte)0); writer.WriteCompressedInt(SoundData.Length); writer.WriteCompressedInt(0); writer.Write(SoundData); }
/// <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(); }
public override void WriteValue(WzBinaryWriter pWriter) { byte[] data = GetBytes(); pWriter.WriteStringValue("Sound_DX8", 0x73, 0x1B); pWriter.Write((byte)0); pWriter.WriteCompressedInt(data.Length); pWriter.WriteCompressedInt(0); pWriter.Write(data); }
public override void WriteValue(WzBinaryWriter writer) { byte[] data = GetBytes(false); writer.WriteStringValue("Sound_DX8", WzImage.WzImageHeaderByte_WithoutOffset, WzImage.WzImageHeaderByte_WithOffset); writer.Write((byte)0); writer.WriteCompressedInt(data.Length); writer.WriteCompressedInt(len_ms); writer.Write(header); writer.Write(data); }
public override void WriteValue(WzBinaryWriter writer) { byte[] data = GetBytes(false); writer.WriteStringValue("Sound_DX8", 0x73, 0x1B); writer.Write((byte)0); writer.WriteCompressedInt(data.Length); writer.WriteCompressedInt(len_ms); writer.Write(header); writer.Write(data); }
internal void CompressPng(Bitmap bmp) { byte[] buf = new byte[bmp.Width * bmp.Height * 8]; format = 2; format2 = 0; width = bmp.Width; height = bmp.Height; //byte[] bmpBytes = bmp.BitmapToBytes(); /* if (SquishPNGWrapper.CheckAndLoadLibrary()) * { * byte[] bmpBytes = bmp.BitmapToBytes(); * SquishPNGWrapper.CompressImage(bmpBytes, width, height, buf, (int)SquishPNGWrapper.FlagsEnum.kDxt1); * } * else * {*/ int curPos = 0; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color curPixel = bmp.GetPixel(j, i); buf[curPos] = curPixel.B; buf[curPos + 1] = curPixel.G; buf[curPos + 2] = curPixel.R; buf[curPos + 3] = curPixel.A; curPos += 4; } } compressedImageBytes = Compress(buf); buf = null; if (listWzUsed) { using (MemoryStream memStream = new MemoryStream()) { using (WzBinaryWriter writer = new WzBinaryWriter(memStream, WzTool.GetIvByMapleVersion(WzMapleVersion.GMS))) { writer.Write(2); for (int i = 0; i < 2; i++) { writer.Write((byte)(compressedImageBytes[i] ^ writer.WzKey[i])); } writer.Write(compressedImageBytes.Length - 2); for (int i = 2; i < compressedImageBytes.Length; i++) { writer.Write((byte)(compressedImageBytes[i] ^ writer.WzKey[i - 2])); } compressedImageBytes = memStream.GetBuffer(); } } } }
internal void SaveToDisk(string pPath) { WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(pPath), mWzIv); foreach (string entry in mListEntries) { string newEntry = entry + "\0"; wzWriter.Write(newEntry.Length); wzWriter.Write(newEntry, true, true); } wzWriter.Close(); }
public override void WriteValue(WzBinaryWriter pWriter) { pWriter.Write((byte)4); if (Value == 0f) { pWriter.Write((byte)0); } else { pWriter.Write((byte)0x80); pWriter.Write(Value); } }
public override void WriteValue(WzBinaryWriter writer) { writer.WriteStringValue("Canvas", 0x73, 0x1B); writer.Write((byte)0); if (WzProperties.Count > 0) { writer.Write((byte)1); WritePropertyList(writer, WzProperties); } else { writer.Write((byte)0); } writer.WriteCompressedInt(PngProperty.Width); writer.WriteCompressedInt(PngProperty.Height); writer.WriteCompressedInt(PngProperty.Format1); writer.Write((byte)PngProperty.Format2); writer.Write(0); var bytes = PngProperty.GetCompressedBytes(false); writer.Write(bytes.Length + 1); writer.Write((byte)0); writer.Write(bytes); }
public override void WriteValue(WzBinaryWriter writer) { writer.Write((byte)9); long beforePos = writer.BaseStream.Position; writer.Write(0); // Placeholder ExtendedProperty.WriteValue(writer); int len = (int)(writer.BaseStream.Position - beforePos); long newPos = writer.BaseStream.Position; writer.BaseStream.Position = beforePos; writer.Write(len - 4); writer.BaseStream.Position = newPos; }
public override void WriteValue(WzBinaryWriter writer) { writer.WriteStringValue("Canvas", WzImage.WzImageHeaderByte_WithoutOffset, WzImage.WzImageHeaderByte_WithOffset); writer.Write((byte)0); if (properties.Count > 0) // subproperty in the canvas { writer.Write((byte)1); WzImageProperty.WritePropertyList(writer, properties); } else { writer.Write((byte)0); } // Image info writer.WriteCompressedInt(PngProperty.Width); writer.WriteCompressedInt(PngProperty.Height); writer.WriteCompressedInt(PngProperty.Format); writer.Write((byte)PngProperty.Format2); writer.Write((Int32)0); // Write image byte[] bytes = PngProperty.GetCompressedBytes(false); writer.Write(bytes.Length + 1); writer.Write((byte)0); // header? see WzImageProperty.ParseExtendedProp "0x00" writer.Write(bytes); }
internal static void WriteExtendedValue(WzBinaryWriter writer, IExtended property) { writer.Write((byte)9); long beforePos = writer.BaseStream.Position; writer.Write((Int32)0); // Placeholder property.WriteValue(writer); int len = (int)(writer.BaseStream.Position - beforePos); long newPos = writer.BaseStream.Position; writer.BaseStream.Position = beforePos; writer.Write(len - 4); writer.BaseStream.Position = newPos; }
internal static void WriteExtendedProperty(WzBinaryWriter pWriter, AWzImageProperty pProp) { pWriter.Write((byte)9); long beforePos = pWriter.BaseStream.Position; pWriter.Write(0); // Placeholder pProp.WriteValue(pWriter); int len = (int)(pWriter.BaseStream.Position - beforePos); long newPos = pWriter.BaseStream.Position; pWriter.BaseStream.Position = beforePos; pWriter.Write(len - 4); pWriter.BaseStream.Position = newPos; }
/// <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(); }
internal void SaveDirectory(WzBinaryWriter writer) { offset = (uint)writer.BaseStream.Position; int entryCount = subDirs.Count + images.Count; if (entryCount == 0) { BlockSize = 0; return; } writer.WriteCompressedInt(entryCount); foreach (WzImage img in images) { writer.WriteWzObjectValue(img.name, 4); writer.WriteCompressedInt(img.BlockSize); writer.WriteCompressedInt(img.Checksum); writer.WriteOffset(img.Offset); } foreach (WzDirectory dir in subDirs) { writer.WriteWzObjectValue(dir.name, 3); writer.WriteCompressedInt(dir.BlockSize); writer.WriteCompressedInt(dir.Checksum); writer.WriteOffset(dir.Offset); } foreach (WzDirectory dir in subDirs) if (dir.BlockSize > 0) dir.SaveDirectory(writer); else writer.Write((byte)0); }
/// <summary> /// Writes the WzImage object to the underlying WzBinaryWriter /// </summary> /// <param name="writer"></param> /// <param name="bIsWzUserKeyDefault">Uses the default MapleStory UserKey or a custom key.</param> /// <param name="forceReadFromData">Read from data regardless of base data that's changed or not.</param> public void SaveImage(WzBinaryWriter writer, bool bIsWzUserKeyDefault = true, bool forceReadFromData = false) { if (bIsImageChanged || !bIsWzUserKeyDefault || // everything needs to be re-written when a custom UserKey is used forceReadFromData) // if its not being force-read and written, it saves with the previous WZ encryption IV. { if (reader != null && !parsed) { this.ParseEverything = true; ParseImage(forceReadFromData); } WzSubProperty imgProp = new WzSubProperty(); long startPos = writer.BaseStream.Position; imgProp.AddPropertiesForWzImageDumping(WzProperties); imgProp.WriteValue(writer); writer.StringCache.Clear(); size = (int)(writer.BaseStream.Position - startPos); } else { long pos = reader.BaseStream.Position; reader.BaseStream.Position = offset; writer.Write(reader.ReadBytes(size)); reader.BaseStream.Position = pos; } }
/// <summary> /// Writes the WzImage object to the underlying WzBinaryWriter /// </summary> /// <param name="writer"></param> /// <param name="forceReadFromData">Read from data regardless of base data that's changed or not.</param> public void SaveImage(WzBinaryWriter writer, bool forceReadFromData = false) { if (changed || forceReadFromData) { if (reader != null && !parsed) { this.ParseEverything = true; ParseImage(forceReadFromData); } WzSubProperty imgProp = new WzSubProperty(); long startPos = writer.BaseStream.Position; imgProp.AddPropertiesForWzImageDumping(WzProperties); imgProp.WriteValue(writer); writer.StringCache.Clear(); size = (int)(writer.BaseStream.Position - startPos); } else { long pos = reader.BaseStream.Position; reader.BaseStream.Position = offset; writer.Write(reader.ReadBytes(size)); reader.BaseStream.Position = pos; } }
internal static void WritePropertyList(WzBinaryWriter writer, List <WzImageProperty> properties) { if (properties.Count == 1 && properties[0] is WzLuaProperty) { properties[0].WriteValue(writer); } else { writer.WriteStringValue("Property", 0x73, 0x1B); writer.Write((ushort)0); writer.WriteCompressedInt(properties.Count); for (int i = 0; i < properties.Count; i++) { writer.WriteStringValue(properties[i].Name, 0x00, 0x01); if (properties[i] is WzExtended) { WriteExtendedValue(writer, (WzExtended)properties[i]); } else { properties[i].WriteValue(writer); } } } }
internal void CompressPng(Bitmap bmp) { byte[] buf = new byte[bmp.Width * bmp.Height * 8]; format = 2; format2 = 0; width = bmp.Width; height = bmp.Height; int curPos = 0; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color curPixel = bmp.GetPixel(j, i); buf[curPos] = curPixel.B; buf[curPos + 1] = curPixel.G; buf[curPos + 2] = curPixel.R; buf[curPos + 3] = curPixel.A; curPos += 4; } } compressedImageBytes = Compress(buf); if (listWzUsed) { using (MemoryStream memStream = new MemoryStream()) { using (WzBinaryWriter writer = new WzBinaryWriter(memStream, WzTool.GetIvByMapleVersion(WzMapleVersion.GMS))) { writer.Write(2); for (int i = 0; i < 2; i++) { writer.Write((byte)(compressedImageBytes[i] ^ writer.WzKey[i])); } writer.Write(compressedImageBytes.Length - 2); for (int i = 2; i < compressedImageBytes.Length; i++) { writer.Write((byte)(compressedImageBytes[i] ^ writer.WzKey[i - 2])); } compressedImageBytes = memStream.GetBuffer(); } } } }
internal static void WritePropertyList(WzBinaryWriter writer, IWzImageProperty[] properties) { writer.Write((ushort)0); writer.WriteCompressedInt(properties.Length); for (int i = 0; i < properties.Length; i++) { writer.WriteStringValue(properties[i].Name, 0x00, 0x01); properties[i].WriteValue(writer); } }
/// <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(); }
public static void SaveToDisk(string path, byte[] wzIv, List <string> listEntries) { var lastIndex = listEntries.Count - 1; var lastEntry = listEntries[lastIndex]; listEntries[lastIndex] = lastEntry.Substring(0, lastEntry.Length - 1) + "/"; var wzWriter = new WzBinaryWriter(File.Create(path), wzIv); foreach (var entry in listEntries) { wzWriter.Write(entry.Length); var encryptedChars = wzWriter.EncryptString(entry + (char)0); foreach (var encryptedChar in encryptedChars) { wzWriter.Write((short)encryptedChar); } } listEntries[lastIndex] = lastEntry.Substring(0, lastEntry.Length - 1) + "/"; }
internal void CompressPng(Bitmap pBmp) { byte[] buf = new byte[pBmp.Width * pBmp.Height * 8]; mFormat = 2; mFormat2 = 0; mWidth = pBmp.Width; mHeight = pBmp.Height; int curPos = 0; for (int i = 0; i < mHeight; i++) { for (int j = 0; j < mWidth; j++) { Color curPixel = pBmp.GetPixel(j, i); buf[curPos] = curPixel.B; buf[curPos + 1] = curPixel.G; buf[curPos + 2] = curPixel.R; buf[curPos + 3] = curPixel.A; curPos += 4; } } mCompressedBytes = Compress(buf); //if (!mIsNew) // return; MemoryStream memStream = new MemoryStream(); WzBinaryWriter writer = new WzBinaryWriter(memStream, WzTool.GetIvByMapleVersion(WzMapleVersion.GMS)); writer.Write(2); for (int i = 0; i < 2; i++) { writer.Write((byte)(mCompressedBytes[i] ^ writer.WzKey[i])); } writer.Write(mCompressedBytes.Length - 2); for (int i = 2; i < mCompressedBytes.Length; i++) { writer.Write((byte)(mCompressedBytes[i] ^ writer.WzKey[i - 2])); } mCompressedBytes = memStream.GetBuffer(); writer.Close(); }
public static void SaveToDisk(string path, byte[] WzIv, List <string> listEntries) { int lastIndex = listEntries.Count - 1; string lastEntry = listEntries[lastIndex]; listEntries[lastIndex] = lastEntry.Substring(0, lastEntry.Length - 1) + "/"; WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(path), WzIv); string s; for (int i = 0; i < listEntries.Count; i++) { s = listEntries[i]; wzWriter.Write((int)s.Length); char[] encryptedChars = wzWriter.EncryptString(s + (char)0); for (int j = 0; j < encryptedChars.Length; j++) { wzWriter.Write((short)encryptedChars[j]); } } listEntries[lastIndex] = lastEntry.Substring(0, lastEntry.Length - 1) + "/"; }
internal static void WritePropertyList(WzBinaryWriter writer, List <IWzImageProperty> properties) { writer.Write((ushort)0); writer.WriteCompressedInt(properties.Count); for (int i = 0; i < properties.Count; i++) { writer.WriteStringValue(properties[i].Name, 0x00, 0x01); if (properties[i] is IExtended) { WriteExtendedValue(writer, (IExtended)properties[i]); } else { properties[i].WriteValue(writer); } } }
internal static void WritePropertyList(WzBinaryWriter pWriter, List <AWzImageProperty> pProperties) { pWriter.Write((ushort)0); pWriter.WriteCompressedInt(pProperties.Count); foreach (AWzImageProperty prop in pProperties) { pWriter.WriteStringValue(prop.Name, 0x00, 0x01); if (prop is IExtended) { WriteExtendedProperty(pWriter, prop); } else { prop.WriteValue(pWriter); } } }
/// <summary> /// Gets a wz property by it's name /// </summary> /// <param name="pWriter">The name of the property</param> /// <returns>The wz property with the specified name</returns> public override void WriteValue(WzBinaryWriter pWriter) { pWriter.WriteStringValue("Canvas", 0x73, 0x1B); pWriter.Write((byte)0); if (mProperties.Count > 0) { pWriter.Write((byte)1); WritePropertyList(pWriter, mProperties); } else { pWriter.Write((byte)0); } pWriter.WriteCompressedInt(PngProperty.Width); pWriter.WriteCompressedInt(PngProperty.Height); pWriter.WriteCompressedInt(PngProperty.mFormat); pWriter.Write((byte)PngProperty.mFormat2); pWriter.Write(0); byte[] bytes = PngProperty.GetCompressedBytes(); pWriter.Write(bytes.Length + 1); pWriter.Write((byte)0); pWriter.Write(bytes); }
internal void SaveDirectory(WzBinaryWriter writer) { Offset = (uint)writer.BaseStream.Position; var entryCount = WzDirectories.Count + WzImages.Count; if (entryCount == 0) { BlockSize = 0; return; } writer.WriteCompressedInt(entryCount); foreach (var img in WzImages) { writer.WriteWzObjectValue(img.Name, 4); writer.WriteCompressedInt(img.BlockSize); writer.WriteCompressedInt(img.Checksum); writer.WriteOffset(img.Offset); } foreach (var dir in WzDirectories) { writer.WriteWzObjectValue(dir.Name, 3); writer.WriteCompressedInt(dir.BlockSize); writer.WriteCompressedInt(dir.Checksum); writer.WriteOffset(dir.Offset); } foreach (var dir in WzDirectories) { if (dir.BlockSize > 0) { dir.SaveDirectory(writer); } else { writer.Write((byte)0); } } }
internal void SaveImage(WzBinaryWriter writer) { if (changed) { if (reader != null && !parsed) { ParseImage(); } WzSubProperty imgProp = new WzSubProperty(); long startPos = writer.BaseStream.Position; imgProp.AddProperties(WzProperties); imgProp.WriteValue(writer); writer.StringCache.Clear(); size = (int)(writer.BaseStream.Position - startPos); } else { long pos = reader.BaseStream.Position; reader.BaseStream.Position = offset; writer.Write(reader.ReadBytes(size)); reader.BaseStream.Position = pos; } }