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:
authorjaybeebabageyus <jaybeebabageyus@users.noreply.github.com>2026-11-22 20:15:40 +0100
committerjaybeebabageyus <jaybeebabageyus@users.noreply.github.com>2026-11-22 20:15:40 +0100
commit01e27846e4a7fecdeba421df2e26afaec4261732 (patch)
tree0ea14a3e3a8396bf924fa4093c28868cb34143af /tools/rpf9dump/Program.cs
parent162821017ea3c286c8bec860f3ff94f037912061 (diff)
rpf9dump: a per-item write failure in models/textures must fail the run and withhold manifest.json
Diffstat (limited to 'tools/rpf9dump/Program.cs')
-rw-r--r--tools/rpf9dump/Program.cs49
1 files changed, 36 insertions, 13 deletions
diff --git a/tools/rpf9dump/Program.cs b/tools/rpf9dump/Program.cs
index 8c2453a83..f36edae29 100644
--- a/tools/rpf9dump/Program.cs
+++ b/tools/rpf9dump/Program.cs
@@ -11,7 +11,7 @@ var sw = Stopwatch.StartNew();
11string baseName = Path.GetFileNameWithoutExtension(src); 11string baseName = Path.GetFileNameWithoutExtension(src);
12string outDir = Path.Combine(outRoot, baseName); Directory.CreateDirectory(outDir); 12string outDir = Path.Combine(outRoot, baseName); Directory.CreateDirectory(outDir);
13long length = new FileInfo(src).Length; 13long length = new FileInfo(src).Length;
14int ok = 0, fail = 0, skip = 0; 14int ok = 0, fail = 0, skip = 0, writeFail = 0;
15// Every mode below works on all cores. Core's readers open their own read handle per call, entry and file names 15// Every mode below works on all cores. Core's readers open their own read handle per call, entry and file names
16// come from offsets and indexes, and results are put back in source order, so outputs match a one-thread run. 16// come from offsets and indexes, and results are put back in source order, so outputs match a one-thread run.
17// ponytail: every core, no flag; add --jobs if someone needs the machine during a build. 17// ponytail: every core, no flag; add --jobs if someone needs the machine during a build.
@@ -170,7 +170,7 @@ else if (mode is "models" or "textures")
170 for (int i = 0; i < n; i++) 170 for (int i = 0; i < n; i++)
171 { 171 {
172 var r = results[i]; results[i] = default; 172 var r = results[i]; results[i] = default;
173 ok += r.Ok; fail += r.Fail; embedded += r.Embedded; 173 ok += r.Ok; fail += r.Fail; embedded += r.Embedded; writeFail += r.WriteFail;
174 if (r.DecodeFailure is { } reason) 174 if (r.DecodeFailure is { } reason)
175 { 175 {
176 int count = modelDecodeFailures.GetValueOrDefault(reason.Code) + 1; 176 int count = modelDecodeFailures.GetValueOrDefault(reason.Code) + 1;
@@ -197,9 +197,13 @@ else if (mode is "models" or "textures")
197 { 197 {
198 var m = RageModelDecoder.Decode(sys, gfx, e.ResourceDrawableOffset); 198 var m = RageModelDecoder.Decode(sys, gfx, e.ResourceDrawableOffset);
199 if (m == null) 199 if (m == null)
200 return new Result(null, 0, 1, 0, ModelDecodeFailure.Explain(sys, gfx.Length), null); 200 return new Result(null, 0, 1, 0, ModelDecodeFailure.Explain(sys, gfx.Length), null, 0);
201 string obj = Path.Combine(sub, stem + ".obj"); 201 string obj = Path.Combine(sub, stem + ".obj");
202 if (!File.Exists(obj)) Util.WriteAllText(obj, RageModelDecoder.CreateObj(m)); 202 string objText = RageModelDecoder.CreateObj(m);
203 // A failed obj write means the model is missing from disk: fatal for the run (retryable),
204 // unlike the decode failures above, which no rerun would change.
205 try { if (!File.Exists(obj)) Util.WriteAllText(obj, objText); }
206 catch (Exception wex) { return new Result(null, 0, 1, 0, null, $" fail {e.Name}: {wex.GetType().Name} {wex.Message}", 1); }
203 if (m.EmbeddedTextures != null && m.EmbeddedTextureDictionaryOffset is int dOff) 207 if (m.EmbeddedTextures != null && m.EmbeddedTextureDictionaryOffset is int dOff)
204 { 208 {
205 string td = Path.Combine(sub, stem + "_tex"); Directory.CreateDirectory(td); 209 string td = Path.Combine(sub, stem + "_tex"); Directory.CreateDirectory(td);
@@ -216,23 +220,31 @@ else if (mode is "models" or "textures")
216 Embedded = m.EmbeddedTextures?.Select(t => new { t.Index, t.Name, t.Width, t.Height, t.Format, Hash = t.NameHash.ToString("X8"), Key = t.AssetKey?.ToString("X16") }).ToArray(), 220 Embedded = m.EmbeddedTextures?.Select(t => new { t.Index, t.Name, t.Width, t.Height, t.Format, Hash = t.NameHash.ToString("X8"), Key = t.AssetKey?.ToString("X16") }).ToArray(),
217 Materials = m.Materials?.Select(x => new { x.ShaderIndex, Shader = x.ShaderHash.ToString("X8"), Preset = x.PresetHash.ToString("X8"), x.RenderBucket, 221 Materials = m.Materials?.Select(x => new { x.ShaderIndex, Shader = x.ShaderHash.ToString("X8"), Preset = x.PresetHash.ToString("X8"), x.RenderBucket,
218 Textures = x.Textures.Select(r => new { Param = r.ParameterHash.ToString("X8"), r.TextureIndex, Name = r.NameHash.ToString("X8"), Id64 = r.OpaqueId64.ToString("X16"), Tag = r.Tag.ToString("X8") }).ToArray() }).ToArray() }, 222 Textures = x.Textures.Select(r => new { Param = r.ParameterHash.ToString("X8"), r.TextureIndex, Name = r.NameHash.ToString("X8"), Id64 = r.OpaqueId64.ToString("X16"), Tag = r.Tag.ToString("X8") }).ToArray() }).ToArray() },
219 1, 0, embedded, null, null); 223 1, 0, embedded, null, null, 0);
220 } 224 }
221 else 225 else
222 { 226 {
223 var dict = RageTextureDecoder.Inspect(sys, gfx); 227 var dict = RageTextureDecoder.Inspect(sys, gfx);
224 if (dict == null) return new Result(null, 0, 1, 0, null, null); 228 if (dict == null) return new Result(null, 0, 1, 0, null, null, 0);
225 string td = Path.Combine(sub, stem); Directory.CreateDirectory(td); 229 string td = Path.Combine(sub, stem); Directory.CreateDirectory(td);
230 int wfail = 0;
226 foreach (var t in dict.Textures) 231 foreach (var t in dict.Textures)
227 { 232 {
228 string p = Path.Combine(td, $"{t.Index:D3}_{Util.Safe(t.Name)}.dds"); 233 string p = Path.Combine(td, $"{t.Index:D3}_{Util.Safe(t.Name)}.dds");
229 try { if (!File.Exists(p)) Util.WriteAllBytes(p, RageTextureDecoder.CreateDds(sys, gfx, t.Index)); ok++; } catch { fail++; } 234 if (File.Exists(p)) { ok++; continue; }
235 // A decoder problem is counted like today and no rerun would change it; a failed DDS write
236 // is retryable, so it additionally counts as a write failure and fails the run.
237 byte[] dds;
238 try { dds = RageTextureDecoder.CreateDds(sys, gfx, t.Index); }
239 catch { fail++; continue; }
240 try { Util.WriteAllBytes(p, dds); ok++; }
241 catch { fail++; wfail++; }
230 } 242 }
231 return new Result(new { e.Offset, Dir = stem, Textures = dict.Textures.Select(t => new { t.Index, t.Name, t.Width, t.Height, t.Format, t.MipCount, Hash = t.NameHash.ToString("X8"), Key = t.AssetKey?.ToString("X16") }).ToArray() }, 243 return new Result(new { e.Offset, Dir = stem, Textures = dict.Textures.Select(t => new { t.Index, t.Name, t.Width, t.Height, t.Format, t.MipCount, Hash = t.NameHash.ToString("X8"), Key = t.AssetKey?.ToString("X16") }).ToArray() },
232 ok, fail, 0, null, null); 244 ok, fail, 0, null, null, wfail);
233 } 245 }
234 } 246 }
235 catch (Exception ex) { return new Result(null, ok, fail + 1, embedded, null, $" fail {e.Name}: {ex.GetType().Name} {ex.Message}"); } 247 catch (Exception ex) { return new Result(null, ok, fail + 1, embedded, null, $" fail {e.Name}: {ex.GetType().Name} {ex.Message}", 0); }
236 } 248 }
237 if (mode == "models") Console.WriteLine($" embedded textures {embedded:N0}"); 249 if (mode == "models") Console.WriteLine($" embedded textures {embedded:N0}");
238 writer.WriteEndArray(); 250 writer.WriteEndArray();
@@ -246,10 +258,21 @@ else if (mode is "models" or "textures")
246 writer.WriteEndObject(); 258 writer.WriteEndObject();
247 writer.Dispose(); // flushes; the later using-dispose is a no-op 259 writer.Dispose(); // flushes; the later using-dispose is a no-op
248 mstream.Dispose(); 260 mstream.Dispose();
249 File.Move(partial, manifestPath, true); 261 // The manifest is the completion marker make_game resumes on. Like ttpf, keep the successful exports for
262 // a retry, but a run with write failures must not mark the stage finished: withdraw a stale marker and
263 // drop the partial instead of publishing it.
264 if (writeFail == 0)
265 File.Move(partial, manifestPath, true);
266 else
267 {
268 Console.WriteLine($" {writeFail} write failure(s): manifest withheld; rerun retries the missing files");
269 File.Delete(manifestPath);
270 File.Delete(partial);
271 }
250} 272}
251Console.WriteLine($"{mode} {baseName}: ok={ok} fail={fail} skip={skip} in {sw.Elapsed.TotalSeconds:0}s"); 273Console.WriteLine($"{mode} {baseName}: ok={ok} fail={fail} skip={skip} in {sw.Elapsed.TotalSeconds:0}s");
252return mode == "ttpf" && fail != 0 ? 1 : 0; 274return (mode == "ttpf" && fail != 0) || writeFail != 0 ? 1 : 0;
253 275
254// One exported entry: its manifest row (null when nothing was written), counts, and a failure to report in order. 276// One exported entry: its manifest row (null when nothing was written), counts, a failure to report in order,
255readonly record struct Result(object? Row, int Ok, int Fail, int Embedded, ModelDecodeFailure? DecodeFailure, string? Error); 277// and how many of its failures were output-write failures (the ones a retry can fix; decode failures are not).
278readonly record struct Result(object? Row, int Ok, int Fail, int Embedded, ModelDecodeFailure? DecodeFailure, string? Error, int WriteFail);