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); }
public override void WriteValue(WzBinaryWriter writer) { this.header = CreateHeader(this.frequency); 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); }
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.Write((byte)4); if (Value == 0f) { writer.Write((byte)0); } else { writer.Write((byte)0x80); writer.Write(Value); } }
public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer) { writer.WriteStringValue("Canvas", 0x73, 0x1B); 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); }
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, 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); } }
public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer) { writer.WriteStringValue("Canvas", 0x73, 0x1B); writer.Write((byte)0); if (properties.Count > 0) { writer.Write((byte)1); IWzImageProperty.WritePropertyList(writer, properties.ToArray()); } else { writer.Write((byte)0); } writer.WriteCompressedInt(PngProperty.Width); writer.WriteCompressedInt(PngProperty.Height); writer.WriteCompressedInt(PngProperty.format); writer.Write((byte)PngProperty.format2); writer.Write(0); writer.Write(PngProperty.CompressedBytes.Length + 1); writer.Write((byte)0); writer.Write(PngProperty.CompressedBytes); }
public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer) { writer.WriteStringValue("Canvas", 0x73, 0x1B); writer.Write((byte)0); if (properties.Count > 0) { writer.Write((byte)1); WzImageProperty.WritePropertyList(writer, properties); } else { writer.Write((byte)0); } writer.WriteCompressedInt(PngProperty.Width); writer.WriteCompressedInt(PngProperty.Height); writer.WriteCompressedInt(PngProperty.nPixFormat); writer.Write((byte)PngProperty.nMagLevel); writer.Write((Int32)0); byte[] bytes = PngProperty.GetCompressedBytes(false); writer.Write(bytes.Length + 1); writer.Write((byte)0); writer.Write(bytes); }
public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer) { writer.Write((byte)2); writer.Write(Value); }
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; } }
internal void CompressPng(Bitmap bmp) { //Console.WriteLine("a"); why was that here anyway... 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; } compressedBytes = Compress(buf); if (listWzUsed) { 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)(compressedBytes[i] ^ writer.WzKey[i])); } writer.Write(compressedBytes.Length - 2); for (int i = 2; i < compressedBytes.Length; i++) writer.Write((byte)(compressedBytes[i] ^ writer.WzKey[i - 2])); compressedBytes = memStream.GetBuffer(); writer.Close(); } }
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 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; }
/// <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), 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(); FileStream fs = File.OpenRead(tempFile); wzDir.SaveImages(wzWriter, fs); fs.Close(); File.Delete(tempFile); wzWriter.StringCache.Clear(); wzWriter.Close(); }
public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer) { writer.Write((byte)3); writer.WriteCompressedInt(Value); }
public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer) { writer.Write((byte)0x1); writer.WriteCompressedInt(encryptedBytes.Length); writer.Write(encryptedBytes); }
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); }
public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer) { writer.Write((byte)8); writer.WriteStringValue(Value, 0, 1); }
/// <summary> /// Saves a wz file to the disk, AKA repacking. /// </summary> /// <param name="path">Path to the output wz file</param> /// <param name="progressBar">Progressbar, optional. (Set to null if not in use)</param> public void SaveToDisk(string path, ProgressBar progressBar) { WzIv = WzTool.GetIvByMapleVersion(mapleVersion); CreateVersionHash(); wzDir.SetHash(versionHash); if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //30% string tempFile = Path.GetFileNameWithoutExtension(path) + ".TEMP"; File.Create(tempFile).Close(); wzDir.GenerateDataFile(tempFile); WzTool.StringCache.Clear(); if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //40% uint totalLen = wzDir.GetImgOffsets(wzDir.GetOffsets(Header.FStart + 2)); 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]); if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //50% wzWriter.Write((long)Header.FSize); wzWriter.Write(Header.FStart); wzWriter.WriteNullTerminatedString(Header.Copyright); if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //60% long extraHeaderLength = Header.FStart - wzWriter.BaseStream.Position; if (extraHeaderLength > 0) { wzWriter.Write(new byte[(int)extraHeaderLength]); } if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //70% wzWriter.Write(version); wzWriter.Header = Header; wzDir.SaveDirectory(wzWriter); wzWriter.StringCache.Clear(); FileStream fs = File.OpenRead(tempFile); wzDir.SaveImages(wzWriter, fs); fs.Close(); if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //80% File.Delete(tempFile); wzWriter.StringCache.Clear(); wzWriter.Close(); if (progressBar != null) { progressBar.PerformStep(); progressBar.Refresh(); } //90% GC.Collect(); GC.WaitForPendingFinalizers(); }