/// <summary> /// Parse a WZ image from .img file/ /// </summary> /// <param name="inPath"></param> /// <param name="iv"></param> /// <param name="name"></param> /// <param name="successfullyParsedImage"></param> /// <returns></returns> public WzImage WzImageFromIMGFile(string inPath, byte[] iv, string name, out bool successfullyParsedImage) { FileStream stream = File.OpenRead(inPath); WzBinaryReader wzReader = new WzBinaryReader(stream, iv); WzImage img = new WzImage(name, wzReader); img.BlockSize = (int)stream.Length; img.Checksum = 0; byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); stream.Position = 0; foreach (byte b in bytes) { img.Checksum += b; } img.Offset = 0; if (freeResources) { successfullyParsedImage = img.ParseImage(true); img.Changed = true; wzReader.Close(); } else { successfullyParsedImage = true; } return(img); }
/// <summary> /// Parses the wz list file /// </summary> public void ParseWzFile() { //WzTools.CreateWzKey(WzMapleVersion.GMS);//what? WzBinaryReader wzParser = new WzBinaryReader(new MemoryStream(wzFileBytes), WzIv); while (wzParser.PeekChar() != -1) { int Len = wzParser.ReadInt32(); char[] List = new char[Len]; for (int i = 0; i < Len; i++) { List[i] = (char)wzParser.ReadInt16(); } wzParser.ReadUInt16(); string Decrypted = wzParser.DecryptString(List); if (wzParser.PeekChar() == -1) { if (Decrypted[Decrypted.Length - 1] == '/') { Decrypted = Decrypted.TrimEnd("/".ToCharArray()) + "g"; // Last char should always be a g (.img) } } listEntries.Add(Decrypted); } wzParser.Close(); }
/// <summary> /// Parses a wz list file on the disk /// </summary> /// <param name="filePath">Path to the wz file</param> /// <param name="wzIv"></param> public static List <string> ParseListFile(string filePath, byte[] wzIv) { var listEntries = new List <string>(); var wzFileBytes = File.ReadAllBytes(filePath); var wzParser = new WzBinaryReader(new MemoryStream(wzFileBytes), wzIv); while (wzParser.PeekChar() != -1) { var len = wzParser.ReadInt32(); var strChrs = new char[len]; for (var i = 0; i < len; i++) { strChrs[i] = (char)wzParser.ReadInt16(); } wzParser.ReadUInt16(); //encrypted null var decryptedStr = wzParser.DecryptString(strChrs); listEntries.Add(decryptedStr); } wzParser.Close(); var lastIndex = listEntries.Count - 1; var lastEntry = listEntries[lastIndex]; listEntries[lastIndex] = lastEntry.Substring(0, lastEntry.Length - 1) + "g"; return(listEntries); }
public WzImage WzImageFromIMGBytes(byte[] bytes, WzMapleVersion version, string name, bool freeResources) { byte[] iv = WzTool.GetIvByMapleVersion(version); MemoryStream stream = new MemoryStream(bytes); WzBinaryReader wzReader = new WzBinaryReader(stream, iv); WzImage img = new WzImage(name, wzReader); img.BlockSize = bytes.Length; img.Checksum = 0; foreach (byte b in bytes) { img.Checksum += b; } img.Offset = 0; if (freeResources) { img.ParseImage(true); img.Changed = true; wzReader.Close(); } return(img); }