示例#1
0
        private VManifest(FArchive Ar)
        {
            using (Ar)
            {
                Header = new VHeader(Ar);
                var compressedBuffer   = Ar.ReadBytes((int)Header.CompressedSize);
                var uncompressedBuffer = ZlibStream.UncompressBuffer(compressedBuffer);
                if (uncompressedBuffer.Length != Header.UncompressedSize)
                {
                    throw new ParserException(Ar, $"Decompression failed, {uncompressedBuffer.Length} != {Header.UncompressedSize}");
                }

                using var manifest = new FByteArchive("UncompressedValorantManifest", uncompressedBuffer);
                Chunks             = manifest.ReadArray <VChunk>((int)Header.ChunkCount);
                Paks = manifest.ReadArray((int)Header.PakCount, () => new VPak(manifest));

                if (manifest.Position != manifest.Length)
                {
                    throw new ParserException(manifest, $"Parsing failed, {manifest.Position} != {manifest.Length}");
                }
            }

            _client = new HttpClient(new HttpClientHandler
            {
                UseProxy                       = false,
                UseCookies                     = false,
                AutomaticDecompression         = DecompressionMethods.All,
                CheckCertificateRevocationList = false,
                PreAuthenticate                = false,
                MaxConnectionsPerServer        = 1337,
                UseDefaultCredentials          = false,
                AllowAutoRedirect              = false
            });
        }
 public void InitViewsFromBuffer(byte[] bulkData)
 {
     using var tempAr = new FByteArchive("SerializedByteStream", bulkData);
     tempAr.ReadArray(CompressedTrackOffsets);
     tempAr.ReadArray(CompressedScaleOffsets.OffsetData);
     tempAr.ReadArray(CompressedByteStream);
 }
示例#3
0
        // UE4.23-4.24 has changed compressed data layout for streaming, so it's worth making a separate
        // serializer function for it.
        private void SerializeCompressedData2(FAssetArchive Ar)
        {
            var compressedRawDataSize = Ar.Read <int>();

            CompressedTrackToSkeletonMapTable = Ar.ReadArray <FTrackToSkeletonMap>();
            var compressedCurveNames = Ar.ReadArray(() => new FSmartName(Ar));

            // Since 4.23, this is FUECompressedAnimData::SerializeCompressedData
            KeyEncodingFormat            = Ar.Read <AnimationKeyFormat>();
            TranslationCompressionFormat = Ar.Read <AnimationCompressionFormat>();
            RotationCompressionFormat    = Ar.Read <AnimationCompressionFormat>();
            ScaleCompressionFormat       = Ar.Read <AnimationCompressionFormat>();

            var compressedNumFrames = Ar.Read <int>();

            // SerializeView() just serializes array size
            var compressedTrackOffsetsNum = Ar.Read <int>();
            var compressedScaleOffsetsNum = Ar.Read <int>();

            CompressedScaleOffsets = new FCompressedOffsetData(Ar.Read <int>());
            var compressedByteStreamNum = Ar.Read <int>();
            // ... end of FUECompressedAnimData::SerializeCompressedData

            var numBytes            = Ar.Read <int>();
            var bUseBulkDataForLoad = Ar.ReadBoolean();

            // In UE4.23 CompressedByteStream field exists in FUECompressedAnimData (as TArrayView) and in
            // FCompressedAnimSequence (as byte array). Serialization is done in FCompressedAnimSequence,
            // either as TArray or as bulk, and then array is separated onto multiple "views" for
            // FUECompressedAnimData. We'll use a different name for "joined" serialized array here to
            // avoid confuse.
            byte[] serializedByteStream;

            if (bUseBulkDataForLoad)
            {
                throw new NotImplementedException("Anim: bUseBulkDataForLoad not implemented");
                //todo: read from bulk to serializedByteStream
            }
            else
            {
                serializedByteStream = Ar.ReadBytes(numBytes);
            }

            // Setup all array views from single array. In UE4 this is done in FUECompressedAnimData::InitViewsFromBuffer.
            // We'll simply copy array data away from SerializedByteStream, and then SerializedByteStream
            // will be released from memory as it is a local variable here.
            // Note: copying is not byte-order wise, so if there will be any problems in the future,
            // should use byte swap functions.
            using (var tempAr = new FByteArchive("SerializedByteStream", serializedByteStream, Ar.Versions))
            {
                CompressedTrackOffsets            = tempAr.ReadArray <int>(compressedTrackOffsetsNum);
                CompressedScaleOffsets.OffsetData = tempAr.ReadArray <int>(compressedScaleOffsetsNum);
                CompressedByteStream = tempAr.ReadBytes(compressedByteStreamNum);
            }

            var curveCodecPath            = Ar.ReadFString();
            var compressedCurveByteStream = Ar.ReadArray <byte>();
        }
        public FRawStaticIndexBuffer(FArchive Ar) : this()
        {
            if (Ar.Ver < EUnrealEngineObjectUE4Version.SUPPORT_32BIT_STATIC_MESH_INDICES)
            {
                Indices16 = Ar.ReadBulkArray <ushort>();
            }
            else
            {
                var is32bit = Ar.ReadBoolean();
                var data    = Ar.ReadBulkArray <byte>();
                var tempAr  = new FByteArchive("IndicesReader", data, Ar.Versions);

                if (Ar.Versions["RawIndexBuffer.HasShouldExpandTo32Bit"])
                {
                    var bShouldExpandTo32Bit = Ar.ReadBoolean();
                }

                if (tempAr.Length == 0)
                {
                    tempAr.Dispose();
                    return;
                }

                if (is32bit)
                {
                    var count = (int)tempAr.Length / 4;
                    Indices32 = tempAr.ReadArray <uint>(count);
                }
                else
                {
                    var count = (int)tempAr.Length / 2;
                    Indices16 = tempAr.ReadArray <ushort>(count);
                }
                tempAr.Dispose();
            }
        }
        public FRawStaticIndexBuffer(FArchive Ar) : this()
        {
            if (Ar.Ver < UE4Version.VER_UE4_SUPPORT_32BIT_STATIC_MESH_INDICES)
            {
                Indices16 = Ar.ReadBulkArray <ushort>();
            }
            else
            {
                var is32bit = Ar.ReadBoolean();
                var data    = Ar.ReadBulkArray <byte>();
                var tempAr  = new FByteArchive("IndicesReader", data, Ar.Versions);

                if (Ar.Game >= EGame.GAME_UE4_25)
                {
                    Ar.Position += 4;
                }

                if (tempAr.Length == 0)
                {
                    tempAr.Dispose();
                    return;
                }

                if (is32bit)
                {
                    var count = (int)tempAr.Length / 4;
                    Indices32 = tempAr.ReadArray <uint>(count);
                }
                else
                {
                    var count = (int)tempAr.Length / 2;
                    Indices16 = tempAr.ReadArray <ushort>(count);
                }
                tempAr.Dispose();
            }
        }
示例#6
0
        public IoGlobalData(IoStoreReader globalReader)
        {
            var nameHashesChunk = globalReader.ChunkIndex(new FIoChunkId(0, 0, EIoChunkType.LoaderGlobalNameHashes));
            var nameCount       = (int)(globalReader.TocResource.ChunkOffsetLengths[nameHashesChunk].Length / sizeof(ulong) - 1);

            var nameAr = new FByteArchive("LoaderGlobalNames", globalReader.Read(new FIoChunkId(0, 0, EIoChunkType.LoaderGlobalNames)));

            GlobalNameMap = FNameEntrySerialized.LoadNameBatch(nameAr, nameCount);

            var metaAr = new FByteArchive("LoaderInitialLoadMeta", globalReader.Read(new FIoChunkId(0, 0, EIoChunkType.LoaderInitialLoadMeta)));

            var numObjects    = metaAr.Read <int>();
            var scriptObjects = metaAr.ReadArray <FScriptObjectEntry>(numObjects);

            ObjectHashStore = new ObjectIndexHashEntry[numObjects];
            ObjectHashHeads = new ObjectIndexHashEntry[4096];
            for (int i = 0; i < ObjectHashHeads.Length; i++)
            {
                ObjectHashHeads[i] = new ObjectIndexHashEntry();
            }

            for (int i = 0; i < numObjects; i++)
            {
                ref var e = ref scriptObjects[i];

                var scriptName = GlobalNameMap[(int)e.ObjectName.NameIndex];

                var entry = new ObjectIndexHashEntry
                {
                    Name        = scriptName.Name,
                    ObjectIndex = e.GlobalIndex
                };
                ObjectHashStore[i] = entry;

                var hash = ObjectIndexToHash(e.GlobalIndex);
                entry.Next            = ObjectHashHeads[hash];
                ObjectHashHeads[hash] = entry;
            }
示例#7
0
        public FIoStoreTocResource(FArchive Ar, EIoStoreTocReadOptions readOptions = EIoStoreTocReadOptions.Default)
        {
            var streamBuffer = new byte[Ar.Length];

            Ar.Read(streamBuffer, 0, streamBuffer.Length);
            using var archive = new FByteArchive(Ar.Name, streamBuffer);

            // Header
            Header = new FIoStoreTocHeader(archive);

            if (Header.Version < EIoStoreTocVersion.PartitionSize)
            {
                Header.PartitionCount = 1;
                Header.PartitionSize  = uint.MaxValue;
            }

            // Chunk IDs
            ChunkIds = archive.ReadArray <FIoChunkId>((int)Header.TocEntryCount);

            // Chunk offsets
            ChunkOffsetLengths = new FIoOffsetAndLength[Header.TocEntryCount];
            for (int i = 0; i < Header.TocEntryCount; i++)
            {
                ChunkOffsetLengths[i] = new FIoOffsetAndLength(archive);
            }

            // Chunk perfect hash map
            uint perfectHashSeedsCount         = 0;
            uint chunksWithoutPerfectHashCount = 0;

            if (Header.Version >= EIoStoreTocVersion.PerfectHashWithOverflow)
            {
                perfectHashSeedsCount         = Header.TocChunkPerfectHashSeedsCount;
                chunksWithoutPerfectHashCount = Header.TocChunksWithoutPerfectHashCount;
            }
            else if (Header.Version >= EIoStoreTocVersion.PerfectHash)
            {
                perfectHashSeedsCount = Header.TocChunkPerfectHashSeedsCount;
            }
            if (perfectHashSeedsCount > 0)
            {
                ChunkPerfectHashSeeds = archive.ReadArray <int>((int)perfectHashSeedsCount);
            }
            if (chunksWithoutPerfectHashCount > 0)
            {
                ChunkIndicesWithoutPerfectHash = archive.ReadArray <int>((int)chunksWithoutPerfectHashCount);
            }

            // Compression blocks
            CompressionBlocks = new FIoStoreTocCompressedBlockEntry[Header.TocCompressedBlockEntryCount];
            for (int i = 0; i < Header.TocCompressedBlockEntryCount; i++)
            {
                CompressionBlocks[i] = new FIoStoreTocCompressedBlockEntry(archive);
            }

            // Compression methods
            unsafe
            {
                var bufferSize = (int)(Header.CompressionMethodNameLength * Header.CompressionMethodNameCount);
                var buffer     = stackalloc byte[bufferSize];
                archive.Serialize(buffer, bufferSize);
                CompressionMethods    = new CompressionMethod[Header.CompressionMethodNameCount + 1];
                CompressionMethods[0] = CompressionMethod.None;
                for (var i = 0; i < Header.CompressionMethodNameCount; i++)
                {
                    var name = new string((sbyte *)buffer + i * Header.CompressionMethodNameLength, 0, (int)Header.CompressionMethodNameLength).TrimEnd('\0');
                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }
                    if (!Enum.TryParse(name, true, out CompressionMethod method))
                    {
                        Log.Warning($"Unknown compression method '{name}' in {Ar.Name}");
                        method = CompressionMethod.Unknown;
                    }

                    CompressionMethods[i + 1] = method;
                }
            }

            // Chunk block signatures
            if (Header.ContainerFlags.HasFlag(EIoContainerFlags.Signed))
            {
                var hashSize = archive.Read <int>();
                // tocSignature and blockSignature both byte[hashSize]
                // and ChunkBlockSignature of FSHAHash[Header.TocCompressedBlockEntryCount]
                archive.Position += hashSize + hashSize + FSHAHash.SIZE * Header.TocCompressedBlockEntryCount;

                // You could verify hashes here but nah
            }

            // Directory index
            if (Header.Version >= EIoStoreTocVersion.DirectoryIndex &&
                readOptions.HasFlag(EIoStoreTocReadOptions.ReadDirectoryIndex) &&
                Header.ContainerFlags.HasFlag(EIoContainerFlags.Indexed) &&
                Header.DirectoryIndexSize > 0)
            {
                DirectoryIndexBuffer = archive.ReadBytes((int)Header.DirectoryIndexSize);
            }

            // Meta
            if (readOptions.HasFlag(EIoStoreTocReadOptions.ReadTocMeta))
            {
                ChunkMetas = new FIoStoreTocEntryMeta[Header.TocEntryCount];
                for (int i = 0; i < Header.TocEntryCount; i++)
                {
                    ChunkMetas[i] = new FIoStoreTocEntryMeta(archive);
                }
            }
        }