Example #1
0
        public async Task PrefetchChunk(ValorantChunkV1 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
        }
Example #2
0
        public ValorantAPIManifestV1(BinaryReader reader, DirectoryInfo directoryInfo)
        {
            using (reader)
            {
                Id = reader.ReadUInt64();
                var chunks = reader.ReadInt32();
                Chunks = new Dictionary <ulong, ValorantChunkV1>(chunks);

                for (var i = 0; i < chunks; i++)
                {
                    var chunk = new ValorantChunkV1(reader);
                    Chunks.Add(chunk.Id, chunk);
                }

                Paks = reader.ReadTArray(() => new ValorantPakV1(reader));
            }

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