Skip to content

Commit 8bc9a55

Browse files
committed
refactor
1 parent 7402284 commit 8bc9a55

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

FModel/ViewModels/ApiEndpoints/ValorantApiEndpoint.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ public async Task<byte[]> GetChunkBytes(VChunk chunk, CancellationToken cancella
116116

117117
return chunkBytes;
118118
}
119-
120-
public VPakStream GetPakStream(int index) => new VPakStream(this, index);
121119
}
122120

123121
public readonly struct VHeader
@@ -168,6 +166,7 @@ public VPak(FArchive Ar)
168166
}
169167

170168
public string GetFullName() => $"ValorantLive/ShooterGame/Content/Paks/{Name}";
169+
public VPakStream GetStream(VManifest manifest) => new(manifest, this);
171170
}
172171

173172
[StructLayout(LayoutKind.Sequential, Pack = 1)]
@@ -182,16 +181,15 @@ public readonly struct VChunk
182181
public class VPakStream : RandomAccessStream, ICloneable
183182
{
184183
private readonly VManifest _manifest;
185-
private readonly int _pakIndex;
184+
private readonly VPak _pak;
186185
private readonly VChunk[] _chunks;
187186

188-
public VPakStream(VManifest manifest, int pakIndex, long position = 0L)
187+
public VPakStream(VManifest manifest, in VPak pak, long position = 0L)
189188
{
190189
_manifest = manifest;
191-
_pakIndex = pakIndex;
190+
_pak = pak;
192191
_position = position;
193192

194-
var pak = manifest.Paks[pakIndex];
195193
_chunks = new VChunk[pak.ChunkIndices.Length];
196194
for (var i = 0; i < _chunks.Length; i++)
197195
{
@@ -201,7 +199,7 @@ public VPakStream(VManifest manifest, int pakIndex, long position = 0L)
201199
Length = pak.Size;
202200
}
203201

204-
public object Clone() => new VPakStream(_manifest, _pakIndex, _position);
202+
public object Clone() => new VPakStream(_manifest, _pak, _position);
205203

206204
public override int Read(byte[] buffer, int offset, int count) =>
207205
ReadAsync(buffer, offset, count, CancellationToken.None).GetAwaiter().GetResult();

FModel/ViewModels/CUE4ParseViewModel.cs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class CUE4ParseViewModel : ViewModel
8484
{
8585
private ThreadWorkerViewModel _threadWorkerView => ApplicationService.ThreadWorkerView;
8686
private ApiEndpointViewModel _apiEndpointView => ApplicationService.ApiEndpointView;
87-
private readonly Regex _fnLive = new(@"^FortniteGame[/\\]Content[/\\]Paks[/\\]",
87+
private readonly Regex _fnLiveRegex = new(@"^FortniteGame[/\\]Content[/\\]Paks[/\\]",
8888
RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
8989

9090
private string _internalGameName;
@@ -251,44 +251,38 @@ await _threadWorkerView.Begin(cancellationToken =>
251251
cancellationToken: cancellationToken,
252252
elementManifestPredicate: x => x.Uri.Host is ("epicgames-download1.akamaized.net" or "download.epicgames.com")
253253
).GetAwaiter().GetResult();
254-
var parseTime = Stopwatch.GetElapsedTime(startTs);
255254

256-
Parallel.ForEach(manifest.Files, fileManifest =>
255+
if (manifest.TryFindFile("Cloud/IoStoreOnDemand.ini", out var ioStoreOnDemandFile))
257256
{
258-
if (fileManifest.FileName.Equals("Cloud/IoStoreOnDemand.ini", StringComparison.OrdinalIgnoreCase))
259-
{
260-
IoStoreOnDemand.Read(new StreamReader(fileManifest.GetStream()));
261-
return;
262-
}
263-
264-
if (!_fnLive.IsMatch(fileManifest.FileName))
265-
{
266-
return;
267-
}
268-
269-
p.RegisterVfs(fileManifest.FileName, [fileManifest.GetStream()]
270-
, it => new FRandomAccessStreamArchive(it, manifest.Files.First(x => x.FileName.Equals(it)).GetStream(), p.Versions));
257+
IoStoreOnDemand.Read(new StreamReader(ioStoreOnDemandFile.GetStream()));
258+
}
259+
260+
Parallel.ForEach(manifest.Files.Where(x => _fnLiveRegex.IsMatch(x.FileName)), fileManifest =>
261+
{
262+
p.RegisterVfs(fileManifest.FileName, [fileManifest.GetStream()],
263+
it => new FRandomAccessStreamArchive(it, manifest.FindFile(it)!.GetStream(), p.Versions));
271264
});
272265

266+
var elapsedTime = Stopwatch.GetElapsedTime(startTs);
273267
FLogger.Append(ELog.Information, () =>
274-
FLogger.Text($"Fortnite [LIVE] has been loaded successfully in {parseTime.TotalMilliseconds}ms", Constants.WHITE, true));
268+
FLogger.Text($"Fortnite [LIVE] has been loaded successfully in {elapsedTime.TotalMilliseconds:F1}ms", Constants.WHITE, true));
275269
break;
276270
}
277271
case "ValorantLive":
278272
{
279-
var manifestInfo = _apiEndpointView.ValorantApi.GetManifest(cancellationToken);
280-
if (manifestInfo == null)
273+
var manifest = _apiEndpointView.ValorantApi.GetManifest(cancellationToken);
274+
if (manifest == null)
281275
{
282276
throw new Exception("Could not load latest Valorant manifest, you may have to switch to your local installation.");
283277
}
284278

285-
Parallel.For(0, manifestInfo.Paks.Length, i =>
279+
Parallel.ForEach(manifest.Paks, pak =>
286280
{
287-
p.RegisterVfs(manifestInfo.Paks[i].GetFullName(), [manifestInfo.GetPakStream(i)]);
281+
p.RegisterVfs(pak.GetFullName(), [pak.GetStream(manifest)]);
288282
});
289283

290284
FLogger.Append(ELog.Information, () =>
291-
FLogger.Text($"Valorant '{manifestInfo.Header.GameVersion}' has been loaded successfully", Constants.WHITE, true));
285+
FLogger.Text($"Valorant '{manifest.Header.GameVersion}' has been loaded successfully", Constants.WHITE, true));
292286
break;
293287
}
294288
}

0 commit comments

Comments
 (0)