Beispiel #1
0
 public static bool Check(this EBulkData bulkData, uint bulkDataFlags) => ((int)bulkData & bulkDataFlags) != 0;
Beispiel #2
0
        public FByteBulkData(FAssetArchive Ar)
        {
            Header = new FByteBulkDataHeader(Ar);
            var bulkDataFlags = Header.BulkDataFlags;

            if (Header.ElementCount == 0)
            {
                // Nothing to do here
            }
            else if (EBulkData.BULKDATA_Unused.Check(bulkDataFlags))
            {
                BulkDataFlag = EBulkData.BULKDATA_Unused;
                Log.Warning("Bulk with no data");
            }
            else if (EBulkData.BULKDATA_ForceInlinePayload.Check(bulkDataFlags))
            {
                BulkDataFlag = EBulkData.BULKDATA_ForceInlinePayload;
#if DEBUG
                Log.Debug($"bulk data in .uexp file (Force Inline Payload) (flags={bulkDataFlags}, pos={Header.OffsetInFile}, size={Header.SizeOnDisk}))");
#endif
                Data = new byte[Header.ElementCount];
                Ar.Read(Data, 0, Header.ElementCount);
            }
            else if (EBulkData.BULKDATA_OptionalPayload.Check(bulkDataFlags))
            {
                BulkDataFlag = EBulkData.BULKDATA_OptionalPayload;
#if DEBUG
                Log.Debug($"bulk data in .uptnl file (Optional Payload) (flags={bulkDataFlags}, pos={Header.OffsetInFile}, size={Header.SizeOnDisk}))");
#endif
                if (!Ar.TryGetPayload(PayloadType.UPTNL, out var uptnlAr) || uptnlAr == null)
                {
                    return;
                }

                Data             = new byte[Header.ElementCount];
                uptnlAr.Position = Header.OffsetInFile;
                uptnlAr.Read(Data, 0, Header.ElementCount);
            }
            else if (EBulkData.BULKDATA_PayloadInSeperateFile.Check(bulkDataFlags))
            {
                BulkDataFlag = EBulkData.BULKDATA_PayloadInSeperateFile;
#if DEBUG
                Log.Debug($"bulk data in .ubulk file (Payload In Separate File) (flags={bulkDataFlags}, pos={Header.OffsetInFile}, size={Header.SizeOnDisk}))");
#endif
                if (!Ar.TryGetPayload(PayloadType.UBULK, out var ubulkAr) || ubulkAr == null)
                {
                    return;
                }

                Data             = new byte[Header.ElementCount];
                ubulkAr.Position = Header.OffsetInFile;
                ubulkAr.Read(Data, 0, Header.ElementCount);
            }
            else if (EBulkData.BULKDATA_PayloadAtEndOfFile.Check(bulkDataFlags))
            {
                BulkDataFlag = EBulkData.BULKDATA_PayloadAtEndOfFile;
#if DEBUG
                Log.Debug($"bulk data in .uexp file (Payload At End Of File) (flags={bulkDataFlags}, pos={Header.OffsetInFile}, size={Header.SizeOnDisk}))");
#endif
                //stored in same file, but at different position
                //save archive position
                var savePos = Ar.Position;
                if (Header.OffsetInFile + Header.ElementCount <= Ar.Length)
                {
                    Data        = new byte[Header.ElementCount];
                    Ar.Position = Header.OffsetInFile;
                    Ar.Read(Data, 0, Header.ElementCount);
                }
                else
                {
                    throw new ParserException(Ar, $"Failed to read PayloadAtEndOfFile, {Header.OffsetInFile} is out of range");
                }

                Ar.Position = savePos;
            }
            else if (EBulkData.BULKDATA_CompressedZlib.Check(bulkDataFlags))
            {
                BulkDataFlag = EBulkData.BULKDATA_CompressedZlib;
                throw new ParserException(Ar, "TODO: CompressedZlib");
            }
        }