/// <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> public static List<string> ParseListFile(string filePath, byte[] WzIv) { List<string> listEntries = new List<string>(); byte[] wzFileBytes = File.ReadAllBytes(filePath); WzBinaryReader wzParser = new WzBinaryReader(new MemoryStream(wzFileBytes), WzIv); while (wzParser.PeekChar() != -1) { int len = wzParser.ReadInt32(); char[] strChrs = new char[len]; for (int i = 0; i < len; i++) strChrs[i] = (char)wzParser.ReadInt16(); wzParser.ReadUInt16(); //encrypted null string decryptedStr = wzParser.DecryptString(strChrs); listEntries.Add(decryptedStr); } wzParser.Close(); int lastIndex= listEntries.Count - 1; string lastEntry = listEntries[lastIndex]; listEntries[lastIndex] = lastEntry.Substring(0, lastEntry.Length - 1) + "g"; return listEntries; }
public WzImage WzImageFromIMGFile(string inPath, byte[] iv, string name) { 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) { img.ParseImage(true); img.Changed = true; wzReader.Close(); } return img; }
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; }