public static IEnumerable <WZProperty> ImageChildren(WZProperty self) { using (WZReader reader = self.FileContainer.GetContentReader(null, self)) { if (self.Offset >= reader.BaseStream.Length) { yield break; } reader.BaseStream.Seek(self.Offset, SeekOrigin.Begin); if (reader.ReadByte() != 0x73) { throw new InvalidOperationException("Image should have header of 0x73"); } long oldPosition = reader.BaseStream.Position; if (!reader.ReadWZString(false, self.Encrypted).Equals("Property")) { reader.BaseStream.Position = oldPosition; if (!reader.ReadWZStringExpecting(out self.Encrypted, "Property", false)) { throw new InvalidOperationException("Unknown encryption method"); } } if (reader.ReadInt16() != 0) { throw new InvalidOperationException("Image needs to have 0 as part of header"); } foreach (WZProperty prop in PropertyList(reader, self).ToArray()) { yield return(prop); } } }
public static WZProperty Image(WZReader reader, WZProperty self) { if (self.Offset >= reader.BaseStream.Length) { return(self); } self.ContainerStartLocation = self.Offset; reader.Container = self; byte imgType = reader.ReadByte(); if (imgType == 1) { return(new WZPropertyWeak <string>(() => { using (reader = self.FileContainer.GetContentReader(null, self)) { reader.BaseStream.Seek(self.Offset, SeekOrigin.Begin); reader.ReadByte(); return reader.ReadLuaScript(); } }, self.NameWithoutExtension, self.Path, self.FileContainer, PropertyType.Lua, self.Parent, self.Size, self.Checksum, self.Offset)); } if (imgType != 0x73) { throw new InvalidOperationException("Unknown image type, not supported!"); } long oldPosition = reader.BaseStream.Position; if (!reader.ReadWZString(false, self.Encrypted).Equals("Property")) { reader.BaseStream.Position = oldPosition; if (!reader.ReadWZStringExpecting(out self.Encrypted, "Property", false)) { throw new InvalidOperationException("Unknown encryption method"); } } if (reader.ReadInt16() != 0) { throw new InvalidOperationException("Image needs to have 0 as part of header"); } return(self); }
private void GuessVersion(ushort?hint = null) { _r.BaseStream.Seek(_r.ContentsStart, SeekOrigin.Begin); short ver = _r.ReadInt16(); bool success; long oldPosition = _r.BaseStream.Position; long offset = TryFindImageInDir(out success); Logging($"Found img at {offset} {success}"); if (success) { success = GuessVersionWithImageOffsetAt(ver, offset); _r.BaseStream.Seek(_r.ContentsStart, SeekOrigin.Begin); if (success) { return; } } for (ushort v = 0; v < ushort.MaxValue; v++) { uint vHash = v.ToString() .Aggregate <char, uint>(0, (current, t) => (32 * current) + t + 1); if ((0xFF ^ (vHash >> 24) ^ (vHash << 8 >> 24) ^ (vHash << 16 >> 24) ^ (vHash << 24 >> 24)) != ver) { continue; } VersionKey = vHash; VersionId = v; _r.VersionKey = vHash; _r.BaseStream.Position = oldPosition; if (DepthFirstImageSearch(out offset)) { break; } } if (!GuessVersionWithImageOffsetAt(ver, offset)) { throw new Exception("Unable to guess WZ version."); } _r.BaseStream.Seek(_r.ContentsStart, SeekOrigin.Begin); }