public static LensFlareBinaryOverlay LensFlareFactory( OverlayStream stream, BinaryOverlayFactoryPackage package, TypedParseParams?parseParams = null) { stream = PluginUtilityTranslation.DecompressStream(stream); var ret = new LensFlareBinaryOverlay( bytes: HeaderTranslation.ExtractRecordMemory(stream.RemainingMemory, package.MetaData.Constants), package: package); var finalPos = checked ((int)(stream.Position + stream.GetMajorRecord().TotalLength)); int offset = stream.Position + package.MetaData.Constants.MajorConstants.TypeAndLengthLength; ret._package.FormVersion = ret; stream.Position += 0x10 + package.MetaData.Constants.MajorConstants.TypeAndLengthLength; ret.CustomFactoryEnd( stream: stream, finalPos: finalPos, offset: offset); ret.FillSubrecordTypes( majorReference: ret, stream: stream, finalPos: finalPos, offset: offset, parseParams: parseParams, fill: ret.FillRecordType); return(ret); }
public static ActorValueInformationBinaryOverlay ActorValueInformationFactory( OverlayStream stream, BinaryOverlayFactoryPackage package, RecordTypeConverter?recordTypeConverter = null) { stream = UtilityTranslation.DecompressStream(stream); var ret = new ActorValueInformationBinaryOverlay( bytes: HeaderTranslation.ExtractRecordMemory(stream.RemainingMemory, package.MetaData.Constants), package: package); var finalPos = checked ((int)(stream.Position + stream.GetMajorRecord().TotalLength)); int offset = stream.Position + package.MetaData.Constants.MajorConstants.TypeAndLengthLength; ret._package.FormVersion = ret; stream.Position += 0x10 + package.MetaData.Constants.MajorConstants.TypeAndLengthLength; ret.CustomFactoryEnd( stream: stream, finalPos: finalPos, offset: offset); ret.FillSubrecordTypes( majorReference: ret, stream: stream, finalPos: finalPos, offset: offset, recordTypeConverter: recordTypeConverter, fill: ret.FillRecordType); return(ret); }
public static OverlayStream DecompressStream(OverlayStream stream) { var majorMeta = stream.GetMajorRecord(); if (majorMeta.IsCompressed) { uint uncompressedLength = BinaryPrimitives.ReadUInt32LittleEndian(stream.RemainingSpan.Slice(majorMeta.HeaderLength)); byte[] buf = new byte[majorMeta.HeaderLength + checked ((int)uncompressedLength)]; // Copy major meta bytes over stream.RemainingSpan.Slice(0, majorMeta.HeaderLength).CopyTo(buf.AsSpan()); // Set length bytes BinaryPrimitives.WriteUInt32LittleEndian(buf.AsSpan().Slice(Constants.HeaderLength), uncompressedLength); // Remove compression flag BinaryPrimitives.WriteInt32LittleEndian(buf.AsSpan().Slice(stream.MetaData.Constants.MajorConstants.FlagLocationOffset), majorMeta.MajorRecordFlags & ~Constants.CompressedFlag); // Copy uncompressed data over using (var compessionStream = new ZlibStream(new ByteMemorySliceStream(stream.RemainingMemory.Slice(majorMeta.HeaderLength + 4)), CompressionMode.Decompress)) { compessionStream.Read(buf, majorMeta.HeaderLength, checked ((int)uncompressedLength)); } stream.Position += checked ((int)majorMeta.TotalLength); stream = new OverlayStream(buf, stream.MetaData); } return(stream); }