Skip to content

Commit

Permalink
RE CV: add PRS cache
Browse files Browse the repository at this point in the history
  • Loading branch information
IntelOrca committed Mar 24, 2024
1 parent 98808ee commit 54b7add
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions IntelOrca.Biohazard.BioRand/RECV/ReCvRandomiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public override void Generate(RandoConfig config, IRandoProgress progress, FileR

using (progress.BeginTask(null, "Compressing room files"))
{
_rdxAfs = WriteRdxAfs();
_rdxAfs = WriteRdxAfs(fileRepository);
}

using (progress.BeginTask(null, "Creating ISO file"))
Expand Down Expand Up @@ -466,7 +466,7 @@ private byte[] ReadFile(UdfEditor editor, FileIdentifier fileId)
return data;
}

private AfsFile WriteRdxAfs()
private AfsFile WriteRdxAfs(FileRepository fileRepository)
{
if (_rdxAfs == null)
throw new Exception();
Expand All @@ -482,13 +482,43 @@ private AfsFile WriteRdxAfs()
var rrdt = _rdts[i];
if (rrdt != null)
{
var prs = PrsFile.Compress(rrdt.RdtFile.Data);
var prs = CachePrs(fileRepository, rrdt.RdtId, rrdt.RdtFile.Data);
builder.Replace(i, prs.Data);
}
});
return builder.ToAfsFile();
}

private PrsFile CachePrs(FileRepository fileRepository, RdtId rtdId, ReadOnlyMemory<byte> uncompressed)
{
var cacheDir = Path.Combine(Path.GetDirectoryName(fileRepository.DataPath), "prs_cache");
var cacheFile = Path.Combine(cacheDir, rtdId + "_" + uncompressed.CalculateFnv1a().ToString("X8"));
if (File.Exists(cacheFile))
{
try
{
return new PrsFile(File.ReadAllBytes(cacheFile));
}
catch
{
}
}

var compressedData = PrsFile.Compress(uncompressed);
try
{
if (Directory.Exists(cacheDir))
{
Directory.CreateDirectory(cacheDir);
compressedData.Data.WriteToFile(cacheFile);
}
}
catch
{
}
return compressedData;
}

protected override string[] GetDefaultNPCs()
{
return new[] { "claire", "steve", "chris", "rodrigo", "alfred", "alexia" };
Expand Down

0 comments on commit 54b7add

Please sign in to comment.