public override void Construct(BinaryEndianReader br, QbItemType type) { //System.Diagnostics.Debug.WriteLine(string.Format("{0} - 0x{1}", type.ToString(), (base.StreamPos(br) - 4).ToString("X").PadLeft(8, '0'))); base.Construct(br, type); _unknown = br.ReadUInt32(base.Root.PakFormat.EndianType); uint decompressedSize = br.ReadUInt32(base.Root.PakFormat.EndianType); uint compressedSize = br.ReadUInt32(base.Root.PakFormat.EndianType); // Get script data Lzss lz = new Lzss(); _scriptData = br.ReadBytes((int)compressedSize); if (compressedSize < decompressedSize) { _scriptData = lz.Decompress(_scriptData); } if (_scriptData.Length != decompressedSize) { throw new ApplicationException(string.Format("Location 0x{0}: Script decompressed to {1} bytes not {2}", (base.StreamPos(br) - compressedSize).ToString("X").PadLeft(8, '0'), _scriptData.Length.ToString(), decompressedSize.ToString())); } // Padding... if ((base.StreamPos(br) % 4) != 0) { br.BaseStream.Seek(4 - (base.StreamPos(br) % 4), SeekOrigin.Current); } base.ConstructEnd(br); }
internal override void Write(BinaryEndianWriter bw) { base.StartLengthCheck(bw); base.Write(bw); bw.Write(_unknown, base.Root.PakFormat.EndianType); bw.Write((uint)_scriptData.Length, base.Root.PakFormat.EndianType); byte[] compScript; Lzss lz = new Lzss(); compScript = lz.Compress(_scriptData); if (compScript.Length >= _scriptData.Length) { compScript = _scriptData; } bw.Write((uint)compScript.Length, base.Root.PakFormat.EndianType); bw.Write(compScript); if (compScript.Length % 4 != 0) { for (int i = 0; i < 4 - (compScript.Length % 4); i++) { bw.Write((byte)0); } } base.WriteEnd(bw); ApplicationException ex = base.TestLengthCheck(this, bw); if (ex != null) { throw ex; } }
internal override void Write(BinaryEndianWriter bw) { base.StartLengthCheck(bw); base.Write(bw); bw.Write(_unknown, base.Root.PakFormat.EndianType); bw.Write((uint)_scriptData.Length, base.Root.PakFormat.EndianType); byte[] compScript; Lzss lz = new Lzss(); compScript = lz.Compress(_scriptData); if (compScript.Length >= _scriptData.Length) compScript = _scriptData; bw.Write((uint)compScript.Length, base.Root.PakFormat.EndianType); bw.Write(compScript); if (compScript.Length % 4 != 0) { for (int i = 0; i < 4 - (compScript.Length % 4); i++) bw.Write((byte)0); } base.WriteEnd(bw); ApplicationException ex = base.TestLengthCheck(this, bw); if (ex != null) throw ex; }
public override void Construct(BinaryEndianReader br, QbItemType type) { //System.Diagnostics.Debug.WriteLine(string.Format("{0} - 0x{1}", type.ToString(), (base.StreamPos(br) - 4).ToString("X").PadLeft(8, '0'))); base.Construct(br, type); _unknown = br.ReadUInt32(base.Root.PakFormat.EndianType); uint decompressedSize = br.ReadUInt32(base.Root.PakFormat.EndianType); uint compressedSize = br.ReadUInt32(base.Root.PakFormat.EndianType); // Get script data Lzss lz = new Lzss(); _scriptData = br.ReadBytes((int)compressedSize); if (compressedSize < decompressedSize) _scriptData = lz.Decompress(_scriptData); if (_scriptData.Length != decompressedSize) throw new ApplicationException(string.Format("Location 0x{0}: Script decompressed to {1} bytes not {2}", (base.StreamPos(br) - compressedSize).ToString("X").PadLeft(8, '0'), _scriptData.Length.ToString(), decompressedSize.ToString())); // Padding... if ((base.StreamPos(br) % 4) != 0) br.BaseStream.Seek(4 - (base.StreamPos(br) % 4), SeekOrigin.Current); base.ConstructEnd(br); }