Exemple #1
0
        public async Task PrefetchChunk(ValorantChunkV2 chunk, CancellationToken cancellationToken)
        {
            var chunkPath = Path.Combine(_chunkDirectory.FullName, $"{chunk.Id}.valchunk");

            if (File.Exists(chunkPath))
            {
                return;
            }

            using var request  = new HttpRequestMessage(HttpMethod.Get, chunk.Url);
            using var response = await _client.SendAsync(request, cancellationToken).ConfigureAwait(false);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                var chunkBytes = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false);

                await using var fs = new FileStream(chunkPath, FileMode.Create, FileAccess.Write, FileShare.Read);
                await fs.WriteAsync(chunkBytes, 0, chunkBytes.Length, cancellationToken).ConfigureAwait(false);
            }
            #if DEBUG
            else
            {
                var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                Debugger.Break();
            }
            #endif
        }
Exemple #2
0
        public ValorantAPIManifestV2(BinaryReader reader, DirectoryInfo directoryInfo)
        {
            using (reader)
            {
                Header = new ValorantAPIManifestHeaderV2(reader);

                var compressedBuffer   = reader.ReadBytes((int)Header.CompressedSize);
                var uncompressedBuffer = ZlibStream.UncompressBuffer(compressedBuffer);

                if (uncompressedBuffer.Length != Header.UncompressedSize)
                {
                    throw new FileLoadException("invalid decompressed manifest body");
                }

                using var bodyMs     = new MemoryStream(uncompressedBuffer, false);
                using var bodyReader = new BinaryReader(bodyMs);

                Chunks = new ValorantChunkV2[Header.ChunkCount];

                for (var i = 0u; i < Header.ChunkCount; i++)
                {
                    Chunks[i] = new ValorantChunkV2(bodyReader);
                }

                Paks = new ValorantPakV2[Header.PakCount];

                for (var i = 0u; i < Header.PakCount; i++)
                {
                    Paks[i] = new ValorantPakV2(bodyReader);
                }
            }

            _client = new HttpClient(new HttpClientHandler
            {
                UseProxy                       = false,
                UseCookies                     = false,
                AutomaticDecompression         = DecompressionMethods.All,
                CheckCertificateRevocationList = false,
                PreAuthenticate                = false,
                MaxConnectionsPerServer        = 1337,
                UseDefaultCredentials          = false,
                AllowAutoRedirect              = false
            });
            _chunkDirectory = directoryInfo;
        }