upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tools/rpf9dump/Program.cs
diff options
context:
space:
mode:
authorcxchhh <35392417+cxchhh@users.noreply.github.com>2026-11-22 03:38:39 +0000
committercxchhh <35392417+cxchhh@users.noreply.github.com>2026-11-22 03:38:39 +0000
commit9e0d871d76eb0102cbc69d92262f9adfaf2eb9e5 (patch)
treef4713661bd29ed9de3b52e3a53386385df23745d /tools/rpf9dump/Program.cs
parentdedd75c1d1db4e042f559f0dd39e872313457bf4 (diff)
rpf9dump: record scan-level candidate and recovery counts
Candidates that RecoverAtOffsets rejects never reach the per-item loop, so ModelDecodeFailures stays empty even when candidates are missing. Write Scan { Candidates, Recovered, NotRecovered, Entries } into the manifest and print the shortfall. Recovered counts resources (distinct candidate offsets): since the 917e9b9 pin a drawable dictionary yields one entry per child, so Entries can exceed Candidates. On a cached run the candidate count comes from the index cache's coverage text, which rpf9dump now writes with invariant digits; older caches with grouped digits still parse. The count is null when another tool wrote the cache. Suggested by Kam471 in the review of #30; that follow-up commit was pushed after #30 had been merged, so it is resubmitted here on current main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/rpf9dump/Program.cs')
-rw-r--r--tools/rpf9dump/Program.cs18
1 files changed, 17 insertions, 1 deletions
diff --git a/tools/rpf9dump/Program.cs b/tools/rpf9dump/Program.cs
index 28b0ddef1..65e850b37 100644
--- a/tools/rpf9dump/Program.cs
+++ b/tools/rpf9dump/Program.cs
@@ -77,6 +77,7 @@ else if (mode is "models" or "textures")
77{ 77{
78 byte[] header; using (var f = File.OpenRead(src)) { header = new byte[64]; f.ReadExactly(header); } 78 byte[] header; using (var f = File.OpenRead(src)) { header = new byte[64]; f.ReadExactly(header); }
79 var cached = RecoveryIndexCache.Load(mode, src, length, header); 79 var cached = RecoveryIndexCache.Load(mode, src, length, header);
80 int? candidates = ScanCounts.Candidates(cached?.Coverage);
80 if (cached == null) 81 if (cached == null)
81 { 82 {
82 long last = -1; 83 long last = -1;
@@ -92,12 +93,17 @@ else if (mode is "models" or "textures")
92 if ((i / 32) % 200 == 0) Console.WriteLine($" validated {i + chunk.Length:N0}/{cands.Count:N0} -> {entries.Count:N0} ({sw.Elapsed.TotalSeconds:0}s)"); 93 if ((i / 32) % 200 == 0) Console.WriteLine($" validated {i + chunk.Length:N0}/{cands.Count:N0} -> {entries.Count:N0} ({sw.Elapsed.TotalSeconds:0}s)");
93 } 94 }
94 entries = entries.OrderBy(e => e.Offset).Select((e, k) => e with { Index = k }).ToList(); 95 entries = entries.OrderBy(e => e.Offset).Select((e, k) => e with { Index = k }).ToList();
95 RecoveryIndexCache.Save(mode, src, entries, $"rpf9dump full scan, {cands.Count:N0} candidates, {entries.Count:N0} recovered"); 96 RecoveryIndexCache.Save(mode, src, entries, ScanCounts.Coverage(cands.Count, entries.Select(e => e.Offset).Distinct().Count()));
97 candidates = cands.Count;
96 } 98 }
97 var doc = ArchiveReader.Open(src); 99 var doc = ArchiveReader.Open(src);
98 string want = mode == "models" ? "Recovered model" : "Recovered texture dictionary"; 100 string want = mode == "models" ? "Recovered model" : "Recovered texture dictionary";
99 var list = doc.Entries.Where(e => e.Compression == want).ToList(); 101 var list = doc.Entries.Where(e => e.Compression == want).ToList();
100 Console.WriteLine($" {list.Count:N0} {mode} entries ({sw.Elapsed.TotalSeconds:0}s)"); 102 Console.WriteLine($" {list.Count:N0} {mode} entries ({sw.Elapsed.TotalSeconds:0}s)");
103 // A drawable dictionary yields one entry per child, all with the candidate's offset: count resources by offset.
104 int recovered = list.Select(e => e.Offset).Distinct().Count();
105 if (candidates is int c && c > recovered)
106 Console.WriteLine($" {c - recovered:N0} of {c:N0} scan candidates were not recovered (rejected before decoding)");
101 string sub = Path.Combine(outDir, mode); Directory.CreateDirectory(sub); 107 string sub = Path.Combine(outDir, mode); Directory.CreateDirectory(sub);
102 // The manifest is streamed row by row: holding 150k rows (each capturing its decoded model through lazy 108 // The manifest is streamed row by row: holding 150k rows (each capturing its decoded model through lazy
103 // projections) ran out of memory on levels.rpf. Written to a .partial file and renamed when complete. 109 // projections) ran out of memory on levels.rpf. Written to a .partial file and renamed when complete.
@@ -107,6 +113,16 @@ else if (mode is "models" or "textures")
107 writer.WriteStartObject(); 113 writer.WriteStartObject();
108 writer.WriteString("src", src); 114 writer.WriteString("src", src);
109 writer.WriteNumber("Count", list.Count); 115 writer.WriteNumber("Count", list.Count);
116 // Scan-level counts. Candidates the recovery step rejects never reach the per-item loop or
117 // ModelDecodeFailures, so NotRecovered is the only place they show up. Recovered counts resources (candidate
118 // offsets); Entries counts manifest items (one per dictionary child). Null when a cached index does not record
119 // the candidate count.
120 writer.WriteStartObject("Scan");
121 if (candidates is int scanned) writer.WriteNumber("Candidates", scanned); else writer.WriteNull("Candidates");
122 writer.WriteNumber("Recovered", recovered);
123 if (candidates is int total) writer.WriteNumber("NotRecovered", total - recovered); else writer.WriteNull("NotRecovered");
124 writer.WriteNumber("Entries", list.Count);
125 writer.WriteEndObject();
110 writer.WriteStartArray("Items"); 126 writer.WriteStartArray("Items");
111 void Row(object row) => JsonSerializer.Serialize(writer, row, json); 127 void Row(object row) => JsonSerializer.Serialize(writer, row, json);
112 int embedded = 0; 128 int embedded = 0;