refactor
Some checks failed
FModel QA Builder / build (push) Has been cancelled

This commit is contained in:
Marlon 2024-12-04 02:21:24 +01:00
parent 7402284c80
commit 8bc9a5535e
No known key found for this signature in database
GPG Key ID: 5C65CA190C38792F
2 changed files with 20 additions and 28 deletions

View File

@ -116,8 +116,6 @@ public class VManifest
return chunkBytes;
}
public VPakStream GetPakStream(int index) => new VPakStream(this, index);
}
public readonly struct VHeader
@ -168,6 +166,7 @@ public readonly struct VPak
}
public string GetFullName() => $"ValorantLive/ShooterGame/Content/Paks/{Name}";
public VPakStream GetStream(VManifest manifest) => new(manifest, this);
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
@ -182,16 +181,15 @@ public readonly struct VChunk
public class VPakStream : RandomAccessStream, ICloneable
{
private readonly VManifest _manifest;
private readonly int _pakIndex;
private readonly VPak _pak;
private readonly VChunk[] _chunks;
public VPakStream(VManifest manifest, int pakIndex, long position = 0L)
public VPakStream(VManifest manifest, in VPak pak, long position = 0L)
{
_manifest = manifest;
_pakIndex = pakIndex;
_pak = pak;
_position = position;
var pak = manifest.Paks[pakIndex];
_chunks = new VChunk[pak.ChunkIndices.Length];
for (var i = 0; i < _chunks.Length; i++)
{
@ -201,7 +199,7 @@ public class VPakStream : RandomAccessStream, ICloneable
Length = pak.Size;
}
public object Clone() => new VPakStream(_manifest, _pakIndex, _position);
public object Clone() => new VPakStream(_manifest, _pak, _position);
public override int Read(byte[] buffer, int offset, int count) =>
ReadAsync(buffer, offset, count, CancellationToken.None).GetAwaiter().GetResult();

View File

@ -84,7 +84,7 @@ public class CUE4ParseViewModel : ViewModel
{
private ThreadWorkerViewModel _threadWorkerView => ApplicationService.ThreadWorkerView;
private ApiEndpointViewModel _apiEndpointView => ApplicationService.ApiEndpointView;
private readonly Regex _fnLive = new(@"^FortniteGame[/\\]Content[/\\]Paks[/\\]",
private readonly Regex _fnLiveRegex = new(@"^FortniteGame[/\\]Content[/\\]Paks[/\\]",
RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
private string _internalGameName;
@ -251,44 +251,38 @@ public class CUE4ParseViewModel : ViewModel
cancellationToken: cancellationToken,
elementManifestPredicate: x => x.Uri.Host is ("epicgames-download1.akamaized.net" or "download.epicgames.com")
).GetAwaiter().GetResult();
var parseTime = Stopwatch.GetElapsedTime(startTs);
Parallel.ForEach(manifest.Files, fileManifest =>
if (manifest.TryFindFile("Cloud/IoStoreOnDemand.ini", out var ioStoreOnDemandFile))
{
if (fileManifest.FileName.Equals("Cloud/IoStoreOnDemand.ini", StringComparison.OrdinalIgnoreCase))
{
IoStoreOnDemand.Read(new StreamReader(fileManifest.GetStream()));
return;
}
IoStoreOnDemand.Read(new StreamReader(ioStoreOnDemandFile.GetStream()));
}
if (!_fnLive.IsMatch(fileManifest.FileName))
{
return;
}
p.RegisterVfs(fileManifest.FileName, [fileManifest.GetStream()]
, it => new FRandomAccessStreamArchive(it, manifest.Files.First(x => x.FileName.Equals(it)).GetStream(), p.Versions));
Parallel.ForEach(manifest.Files.Where(x => _fnLiveRegex.IsMatch(x.FileName)), fileManifest =>
{
p.RegisterVfs(fileManifest.FileName, [fileManifest.GetStream()],
it => new FRandomAccessStreamArchive(it, manifest.FindFile(it)!.GetStream(), p.Versions));
});
var elapsedTime = Stopwatch.GetElapsedTime(startTs);
FLogger.Append(ELog.Information, () =>
FLogger.Text($"Fortnite [LIVE] has been loaded successfully in {parseTime.TotalMilliseconds}ms", Constants.WHITE, true));
FLogger.Text($"Fortnite [LIVE] has been loaded successfully in {elapsedTime.TotalMilliseconds:F1}ms", Constants.WHITE, true));
break;
}
case "ValorantLive":
{
var manifestInfo = _apiEndpointView.ValorantApi.GetManifest(cancellationToken);
if (manifestInfo == null)
var manifest = _apiEndpointView.ValorantApi.GetManifest(cancellationToken);
if (manifest == null)
{
throw new Exception("Could not load latest Valorant manifest, you may have to switch to your local installation.");
}
Parallel.For(0, manifestInfo.Paks.Length, i =>
Parallel.ForEach(manifest.Paks, pak =>
{
p.RegisterVfs(manifestInfo.Paks[i].GetFullName(), [manifestInfo.GetPakStream(i)]);
p.RegisterVfs(pak.GetFullName(), [pak.GetStream(manifest)]);
});
FLogger.Append(ELog.Information, () =>
FLogger.Text($"Valorant '{manifestInfo.Header.GameVersion}' has been loaded successfully", Constants.WHITE, true));
FLogger.Text($"Valorant '{manifest.Header.GameVersion}' has been loaded successfully", Constants.WHITE, true));
break;
}
}