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 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(MapleLib.WzLib.Util.WzBinaryWriter writer) { writer.WriteStringValue("Shape2D#Convex2D", 0x73, 0x1B); writer.WriteCompressedInt(ExtendedProperties.Length); for (int i = 0; i < ExtendedProperties.Length; i++) { ExtendedProperties[i].ExtendedProperty.WriteValue(writer); } }
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(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; }
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); } }
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) { bool bIsLuaProperty = false; if (properties.Count == 1 && properties[0] is WzLuaProperty) { bIsLuaProperty = true; } if (!bIsLuaProperty) { writer.WriteStringValue("Property", 0x73, 0x1B); } WzImageProperty.WritePropertyList(writer, properties); }
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) + "/"; }
public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer) { List <IExtended> extendedProps = new List <IExtended>(properties.Count); foreach (IWzImageProperty prop in properties) { if (prop is IExtended) { extendedProps.Add((IExtended)prop); } } writer.WriteStringValue("Shape2D#Convex2D", 0x73, 0x1B); writer.WriteCompressedInt(extendedProps.Count); for (int i = 0; i < extendedProps.Count; i++) { 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); }
/// <summary> /// Saves a .img inside a WZ File /// </summary> /// <param name="mVersion">The wz files maple version (GMS, MSEA, or BMS)</param> public void SaveImage(WzMapleVersion mVersion) { MemoryStream memStream = new MemoryStream(); WzBinaryWriter imgWriter = new WzBinaryWriter(memStream, WzTool.GetIvByMapleVersion(mVersion)); SaveImage(imgWriter); }
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(); } }
public override void WriteValue(WzBinaryWriter writer) { throw new NotImplementedException("Cannot write a PngProperty"); }
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 abstract void WriteValue(WzBinaryWriter writer);
public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer) { WzImageProperty.WritePropertyList(writer, properties); }
/// <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(); }
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; } }
public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer) { writer.WriteStringValue("Property", 0x73, 0x1B); IWzImageProperty.WritePropertyList(writer, properties.ToArray()); }
public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer) { writer.Write((byte)3); writer.WriteCompressedInt(Value); }
internal void SaveImage(WzBinaryWriter writer) { 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); }
internal int GenerateDataFile(string fileName) { size = 0; int entryCount = subDirs.Count + images.Count; if (entryCount == 0) { offsetSize = 1; return (size = 0); } size = WzTool.GetCompressedIntLength(entryCount); offsetSize = WzTool.GetCompressedIntLength(entryCount); WzBinaryWriter imgWriter = null; MemoryStream memStream = null; FileStream fileWrite = new FileStream(fileName, FileMode.Append, FileAccess.Write); WzImage img; for (int i = 0; i < images.Count; i++) { img = images[i]; if (img.changed) { memStream = new MemoryStream(); imgWriter = new WzBinaryWriter(memStream, this.WzIv); img.SaveImage(imgWriter); img.checksum = 0; foreach (byte b in memStream.ToArray()) { img.checksum += b; } img.tempFileStart = fileWrite.Position; fileWrite.Write(memStream.ToArray(), 0, (int)memStream.Length); img.tempFileEnd = fileWrite.Position; memStream.Dispose(); } else { img.tempFileStart = img.offset; img.tempFileEnd = img.offset + img.size; } img.UnparseImage(); int nameLen = WzTool.GetWzObjectValueLength(img.name, 4); size += nameLen; int imgLen = img.size; size += WzTool.GetCompressedIntLength(imgLen); size += imgLen; size += WzTool.GetCompressedIntLength(img.Checksum); size += 4; offsetSize += nameLen; offsetSize += WzTool.GetCompressedIntLength(imgLen); offsetSize += WzTool.GetCompressedIntLength(img.Checksum); offsetSize += 4; if (img.changed) imgWriter.Close(); } fileWrite.Close(); WzDirectory dir; for (int i = 0; i < subDirs.Count; i++) { dir = subDirs[i]; int nameLen = WzTool.GetWzObjectValueLength(dir.name, 3); size += nameLen; size += subDirs[i].GenerateDataFile(fileName); size += WzTool.GetCompressedIntLength(dir.size); size += WzTool.GetCompressedIntLength(dir.checksum); size += 4; offsetSize += nameLen; offsetSize += WzTool.GetCompressedIntLength(dir.size); offsetSize += WzTool.GetCompressedIntLength(dir.checksum); offsetSize += 4; } return size; }
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)2); writer.Write(Value); }
private void serializeImageInternal(WzImage img, string outPath) { FileStream stream = File.Create(outPath); WzBinaryWriter wzWriter = new WzBinaryWriter(stream, ((WzDirectory)img.parent).WzIv); img.SaveImage(wzWriter); wzWriter.Close(); }
public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer) { writer.WriteStringValue("Shape2D#Vector2D", 0x73, 0x1B); writer.WriteCompressedInt(X.Value); writer.WriteCompressedInt(Y.Value); }
internal WzImage ParseXMLWzImg(XmlElement imgElement) { string name = imgElement.GetAttribute("name"); WzImage result = new WzImage(name); foreach (XmlElement subelement in imgElement) result.WzProperties.Add(ParsePropertyFromXMLElement(subelement)); result.Changed = true; if (this.useMemorySaving) { string path = Path.GetTempFileName(); WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(path), iv); result.SaveImage(wzWriter); wzWriter.Close(); result.Dispose(); result = imgDeserializer.WzImageFromIMGFile(path, iv, name); } return result; }
public override void WriteValue(MapleLib.WzLib.Util.WzBinaryWriter writer) { writer.Write((byte)8); writer.WriteStringValue(Value, 0, 1); }
private byte[] serializeImageInternal(WzImage img) { MemoryStream stream = new MemoryStream(); WzBinaryWriter wzWriter = new WzBinaryWriter(stream, ((WzDirectory)img.parent).WzIv); img.SaveImage(wzWriter); byte[] result = stream.ToArray(); wzWriter.Close(); return result; }