Accept zero-radius drawables and compute bounds when declared bounds are empty #12

Manually merged
github merged 1 commit from gh-pr/12/head into gh-pr/12/base 2026-11-26 19:05:03 +00:00
Owner

@⁠LocranKing on GitHub · 2026-11-22 06:49 UTC · original
LocranKing:fix/zero-radius-drawables → main · +2 −2 · 1 files · 1 commits · merged 2026-11-22 09:44 UTC

Why

LooksLikeDrawableHeader (Core/RageModelDecoder.cs:124) requires radius > 0, which rejects valid drawables whose bounding-sphere radius is 0.0f:

  • 11 drawable dictionaries in pack/core_restofworld/core_restofworld.rpf: single-entry skinned drawable dictionaries (bones = true, 1 material, 3–4 vertices / 1–2 triangles each) with sub-millimeter non-empty declared bounds (~0.0001–0.0002 m) whose radius is 0. With #9 (LooksLikeDrawableDictionary calling LooksLikeDrawableHeader), these would also stop being scan candidates and disappear silently.
  • 53 standalone drawables in levels.rpf: 38 skinned and 15 static single-mesh drawables (100,022 vertices, 37,826 triangles — 37,826/37,826 non-degenerate, 0 non-finite positions, spanning up to 7.65 m) whose drawable header has both radius == 0 and empty declared bounds min == max == (0, 0, 0).

Additionally, for the 15 static (!dictionary && !hasBoneBindings) standalone drawables whose declared bounds are empty (min == max), ModelReader.Decode (:560) returned BoundsMin = BoundsMax = (0, 0, 0) instead of computing preview bounds from the decoded vertices.

Measurements across the 1.0.2.1 package

Archive Candidates 917e9b9 → this PR Recovered 917e9b9 → this PR Models 917e9b9 → this PR New meshes / verts / tris
pack/core_restofworld/core_restofworld.rpf 1,024 → 1,024 873 → 884 (+11) 885 → 896 (+11) +11 / +40 / +18
levels.rpf 206,981 → 207,034 (+53) 205,944 → 205,997 (+53) 314,000 → 314,053 (+53) +53 / +100,022 / +37,826
pack/story000/story000.rpf 4,195 → 4,195 4,194 → 4,194 7,460 → 7,460 0
packs.rpf 23,838 → 23,838 23,838 → 23,838 24,034 → 24,034 0
data.rpf 2,402 → 2,402 2,327 → 2,327 2,581 → 2,581 0
pack/shared_minigame000/shared_minigame000.rpf 1,070 → 1,070 1,052 → 1,052 1,288 → 1,288 0
pack/story000_restofworld/story000_restofworld.rpf 1 → 1 1 → 1 3 → 3 0
  • Every new scan candidate in levels.rpf (53/53) recovered and decoded cleanly (0 false positives, 0 decode failures).
  • Total recovered across the package: +64 models (+64 meshes, +100,062 vertices, +37,844 triangles).
  • All 15 static levels.rpf drawables now report non-empty BoundsMin/BoundsMax computed from their decoded geometry while keeping DeclaredBoundsMin/DeclaredBoundsMax as (0, 0, 0).

Change

  • Core/RageModelDecoder.cs:124: accept radius is >= 0 and < 1_000_000 (negative, NaN, infinite, and >= 1_000_000 radii stay rejected).
  • Core/RageModelDecoder.cs:560: fall back to computing previewMin/previewMax from mesh vertices when min == max (alongside dictionary || hasBoneBindings).

This PR does not touch any lines modified by #8, #9, #10 or #11.

Tests

main ignores Tests/, so the self-contained synthetic smoke test is below (zero game data):

  • Embedded drawable dictionary child with radius == 0 and non-empty sub-millimeter bounds passes ProbeRequiredExtents, DecodeModels, and full synthetic .rpf scan + recovery.
  • Standalone static drawable with radius == 0 and empty declared bounds min == max == (0, 0, 0) passes LooksLikeDrawable, ProbeRequiredExtents, Decode, and synthetic .rpf scan + recovery, with BoundsMin/BoundsMax falling back to the decoded triangle [0, 1]^3 while DeclaredBoundsMin/DeclaredBoundsMax stay (0, 0, 0).
  • Negative (-0.001, -1), NaN, ±Infinity, and 1_000_000 radii remain rejected for both standalone and dictionary drawables.

Negative controls verified before the full fix:

  • On 917e9b9: fails at probe accepts dictionary child with radius 0.
  • With only :124 applied: fails at BoundsMin/BoundsMax fall back to decoded mesh vertices when declared bounds are empty.
  • With both :124 and :560: ZeroRadiusSmoke: all checks passed.

Copy both files to Tests/ZeroRadiusSmoke/ and run dotnet run --project Tests/ZeroRadiusSmoke -c Release.

Tests/ZeroRadiusSmoke/ZeroRadiusSmoke.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\Core\RpfPreview.Core.csproj" />
  </ItemGroup>
</Project>
Tests/ZeroRadiusSmoke/Program.cs
using System.Buffers.Binary;
using System.IO.Compression;
using System.Numerics;
using System.Text;
using RpfPreview.Core;

// 1. Embedded drawable dictionary child with radius == 0 and non-empty sub-millimeter bounds (core_restofworld case).
{
    var (sys, gfx) = MakeDictionary(radius: 0f, maxBound: 0.0002f);
    var extent = RageModelDecoder.ProbeRequiredExtents(sys);
    Check(extent is { MetadataComplete: true, IsDrawableDictionary: true }, "probe accepts dictionary child with radius 0");
    var models = RageModelDecoder.DecodeModels(sys, gfx);
    Check(models.Count == 1 && models[0].Meshes.Count == 1 && models[0].Meshes[0].Positions.Count == 3,
        "DecodeModels decodes dictionary child with radius 0");
    Check(RecoverFromSyntheticArchive(sys, gfx) == 1, "scanner and recovery find dictionary child with radius 0");
}

// 2. Standalone static drawable with radius == 0 and empty declared bounds min == max == (0,0,0) (levels.rpf case).
{
    var (sys, gfx) = MakeStandalone(radius: 0f, maxBound: 0f);
    Check(RageModelDecoder.LooksLikeDrawable(sys), "LooksLikeDrawable accepts standalone drawable with radius 0");
    var extent = RageModelDecoder.ProbeRequiredExtents(sys);
    Check(extent is { MetadataComplete: true, IsDrawableDictionary: false, IsFragment: false },
        "probe accepts standalone drawable with radius 0 and empty declared bounds");
    var model = RageModelDecoder.Decode(sys, gfx);
    Check(model is not null && model.Meshes.Count == 1 && model.Meshes[0].Positions.Count == 3,
        "Decode decodes standalone drawable with radius 0");
    Check(model!.DeclaredBoundsMin == Vector3.Zero && model.DeclaredBoundsMax == Vector3.Zero,
        "declared bounds remain zero");
    Check(model.BoundsMin == Vector3.Zero && model.BoundsMax == Vector3.One,
        "BoundsMin/BoundsMax fall back to decoded mesh vertices when declared bounds are empty");
    Check(RecoverFromSyntheticArchive(sys, gfx) == 1, "scanner and recovery find standalone drawable with radius 0");
}

// 3. Negative, NaN, infinite, and out-of-range radii remain rejected.
foreach (float bad in new[] { -0.001f, -1f, float.NaN, float.PositiveInfinity, float.NegativeInfinity, 1_000_000f })
{
    var (sys, _) = MakeStandalone(radius: bad, maxBound: 1f);
    Check(!RageModelDecoder.LooksLikeDrawable(sys), $"LooksLikeDrawable rejects radius {bad}");
    Check(RageModelDecoder.ProbeRequiredExtents(sys) is null, $"probe rejects standalone radius {bad}");

    var (dsys, _) = MakeDictionary(radius: bad, maxBound: 1f);
    Check(RageModelDecoder.ProbeRequiredExtents(dsys) is null, $"probe rejects dictionary child radius {bad}");
}

Console.WriteLine("ZeroRadiusSmoke: all checks passed");
return 0;

static void Check(bool ok, string what) { if (!ok) throw new Exception("Failed: " + what); }

static int RecoverFromSyntheticArchive(byte[] sys, byte[] gfx)
{
    string tmp = Path.Combine(Path.GetTempPath(), $"zero_radius_smoke_{Guid.NewGuid():N}.rpf");
    try
    {
        byte[] sZ = Compress(sys), gZ = Compress(gfx);
        int gOff = (4096 + 16 + sZ.Length + 15) & ~15;
        int total = Align4096(gOff + gZ.Length);
        byte[] file = new byte[total];
        Encoding.ASCII.GetBytes("9FPR").CopyTo(file, 0);
        sZ.CopyTo(file, 4096 + 16);
        gZ.CopyTo(file, gOff);
        File.WriteAllBytes(tmp, file);
        var cands = Rpf9ModelRecovery.FindCandidateOffsets(tmp);
        if (cands.Count != 1) return 0;
        var entries = Rpf9ModelRecovery.RecoverAtOffsets(tmp, file.Length, cands, 0);
        return entries.Count;
    }
    finally { if (File.Exists(tmp)) File.Delete(tmp); }
}

static byte[] Compress(byte[] raw)
{
    using var ms = new MemoryStream();
    using (var zs = new ZLibStream(ms, CompressionLevel.Fastest, leaveOpen: true)) zs.Write(raw);
    return ms.ToArray();
}

static int Align4096(int v) => (v + 4095) & ~4095;

static (byte[] System, byte[] Graphics) MakeDictionary(float radius, float maxBound)
{
    const int Pages = 0x100, Hashes = 0x140, Values = 0x180, D = 0x400;
    byte[] system = new byte[0x1200], graphics = new byte[256];
    WriteS(system, 8, Pages); BinaryPrimitives.WriteUInt64LittleEndian(system.AsSpan(24), 1);
    WriteS(system, 32, Hashes); WriteU16(system, 40, 1); WriteU16(system, 42, 1);
    WriteS(system, 48, Values); WriteU16(system, 56, 1); WriteU16(system, 58, 1);
    system[Pages + 8] = system[Pages + 9] = 1;
    WriteU32(system, Hashes, 0x1234567); WriteS(system, Values, D);
    WriteDrawable(system, graphics, D, embedded: true, pagesAt: 0, radius, maxBound);
    return (system, graphics);
}

static (byte[] System, byte[] Graphics) MakeStandalone(float radius, float maxBound)
{
    const int Pages = 0x100, D = 0;
    byte[] system = new byte[0xE00], graphics = new byte[256];
    system[Pages + 8] = system[Pages + 9] = 1;
    WriteDrawable(system, graphics, D, embedded: false, pagesAt: Pages, radius, maxBound);
    return (system, graphics);
}

static void WriteDrawable(byte[] system, byte[] graphics, int D, bool embedded, int pagesAt, float radius, float maxBound)
{
    const int PositionOffset = 96, VertexCount = 3, IndexLength = 48;
    int name = D + 0x180, shader = D + 0x1C0, lod = D + 0x200, models = D + 0x220, part = D + 0x240;
    int pointers = D + 0x300, bounds = D + 0x320, geometry = D + 0x400;
    int vb = geometry + 0xA0, descriptor = geometry + 0x160, ib = geometry + 0x180, fvf = geometry + 0x200;
    int index = 160;

    if (!embedded) WriteS(system, D + 8, pagesAt);
    Encoding.ASCII.GetBytes("zr.#dr").CopyTo(system, name);
    WriteS(system, D + 16, shader); WriteS(system, D + 80, lod); WriteS(system, D + 168, name);
    WriteF32(system, D + 44, radius);
    WriteF32(system, D + 64, maxBound); WriteF32(system, D + 68, maxBound); WriteF32(system, D + 72, maxBound);

    WriteS(system, lod, models); WriteU16(system, lod + 8, 1); WriteU16(system, lod + 10, 1); WriteS(system, models, part);
    WriteS(system, part + 8, pointers); WriteU16(system, part + 16, 1); WriteU16(system, part + 18, 1); WriteU16(system, part + 54, 1);
    WriteS(system, part + 24, bounds);
    WriteF32(system, bounds + 16, 1f); WriteF32(system, bounds + 20, 1f); WriteF32(system, bounds + 24, 1f);

    WriteS(system, pointers, geometry); WriteS(system, geometry + 8, vb); WriteS(system, geometry + 64, descriptor);
    WriteU32(system, vb + 8, PositionOffset + VertexCount * 12); WriteU16(system, vb + 12, 1); WriteG(system, vb + 24, 0); WriteS(system, vb + 64, fvf);
    WriteU32(system, fvf, PositionOffset);
    system[fvf + 0xD0] = 12; system[fvf + 0x104] = 6;
    WriteU32(system, fvf + 0x138, (VertexCount << 10) | 1);
    WriteU32(graphics, 0, 0x63);
    WriteF32(graphics, PositionOffset + 12, 1f);
    WriteF32(graphics, PositionOffset + 24, 1f); WriteF32(graphics, PositionOffset + 28, 1f); WriteF32(graphics, PositionOffset + 32, 1f);

    WriteS(system, descriptor, ib); WriteU16(system, descriptor + 8, 1); WriteU16(system, descriptor + 10, 1);
    WriteU32(system, descriptor + 12, VertexCount << 8);
    WriteU32(system, ib + 8, IndexLength / 4); WriteU16(system, ib + 12, 4); WriteG(system, ib + 24, index);
    WriteU32(graphics, index, 0x80000001);
    WriteU32(graphics, index + 4, 1); WriteU32(graphics, index + 8, VertexCount); WriteU32(graphics, index + 12, VertexCount - 1);
    WriteU32(graphics, index + 28, (2u << 14) | (1u << 7));
    graphics[index + 34] = 1; graphics[index + 36] = 2;
}

static void WriteS(byte[] b, int at, int addr) => BinaryPrimitives.WriteUInt64LittleEndian(b.AsSpan(at), 0x50000000UL + (uint)addr);
static void WriteG(byte[] b, int at, int addr) => BinaryPrimitives.WriteUInt64LittleEndian(b.AsSpan(at), 0x60000000UL + (uint)addr);
static void WriteU16(byte[] b, int at, int v) => BinaryPrimitives.WriteUInt16LittleEndian(b.AsSpan(at), checked((ushort)v));
static void WriteU32(byte[] b, int at, uint v) => BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(at), v);
static void WriteF32(byte[] b, int at, float v) => BinaryPrimitives.WriteSingleLittleEndian(b.AsSpan(at), v);

Testing environment

Tested on Windows 11 Build 26200 x64 with .NET SDK 8.0.428 (CPU only). Core builds with /p:TreatWarningsAsErrors=true (0 warnings, 0 errors), and Leonida's rpf9dump builds cleanly against it.

AI-assisted. No game data is included here (counts and synthetic test fixture only). Related tracking item: ItsNotRexed/Leonida#1006 (ASSET-69).

**@⁠LocranKing** on GitHub · 2026-11-22 06:49 UTC · [original](https://github.com/breadbbbb/rpf9-explorer/pull/12) `LocranKing:fix/zero-radius-drawables` → `main` · +2 −2 · 1 files · 1 commits · merged 2026-11-22 09:44 UTC ## Why `LooksLikeDrawableHeader` (`Core/RageModelDecoder.cs:124`) requires `radius > 0`, which rejects valid drawables whose bounding-sphere radius is `0.0f`: - **11 drawable dictionaries in `pack/core_restofworld/core_restofworld.rpf`**: single-entry skinned drawable dictionaries (`bones = true`, 1 material, 3–4 vertices / 1–2 triangles each) with sub-millimeter non-empty declared bounds (~`0.0001–0.0002` m) whose radius is `0`. With #9 (`LooksLikeDrawableDictionary` calling `LooksLikeDrawableHeader`), these would also stop being scan candidates and disappear silently. - **53 standalone drawables in `levels.rpf`**: 38 skinned and 15 static single-mesh drawables (`100,022` vertices, `37,826` triangles — `37,826/37,826` non-degenerate, `0` non-finite positions, spanning up to `7.65` m) whose drawable header has both `radius == 0` and empty declared bounds `min == max == (0, 0, 0)`. Additionally, for the 15 static (`!dictionary && !hasBoneBindings`) standalone drawables whose declared bounds are empty (`min == max`), `ModelReader.Decode` (`:560`) returned `BoundsMin = BoundsMax = (0, 0, 0)` instead of computing preview bounds from the decoded vertices. ### Measurements across the 1.0.2.1 package | Archive | Candidates `917e9b9` → this PR | Recovered `917e9b9` → this PR | Models `917e9b9` → this PR | New meshes / verts / tris | |---|---:|---:|---:|---:| | `pack/core_restofworld/core_restofworld.rpf` | 1,024 → **1,024** | 873 → **884** (+11) | 885 → **896** (+11) | +11 / +40 / +18 | | `levels.rpf` | 206,981 → **207,034** (+53) | 205,944 → **205,997** (+53) | 314,000 → **314,053** (+53) | +53 / +100,022 / +37,826 | | `pack/story000/story000.rpf` | 4,195 → 4,195 | 4,194 → 4,194 | 7,460 → 7,460 | 0 | | `packs.rpf` | 23,838 → 23,838 | 23,838 → 23,838 | 24,034 → 24,034 | 0 | | `data.rpf` | 2,402 → 2,402 | 2,327 → 2,327 | 2,581 → 2,581 | 0 | | `pack/shared_minigame000/shared_minigame000.rpf` | 1,070 → 1,070 | 1,052 → 1,052 | 1,288 → 1,288 | 0 | | `pack/story000_restofworld/story000_restofworld.rpf` | 1 → 1 | 1 → 1 | 3 → 3 | 0 | - Every new scan candidate in `levels.rpf` (53/53) recovered and decoded cleanly (0 false positives, 0 decode failures). - Total recovered across the package: **+64 models** (+64 meshes, +100,062 vertices, +37,844 triangles). - All 15 static `levels.rpf` drawables now report non-empty `BoundsMin`/`BoundsMax` computed from their decoded geometry while keeping `DeclaredBoundsMin`/`DeclaredBoundsMax` as `(0, 0, 0)`. ## Change - `Core/RageModelDecoder.cs:124`: accept `radius is >= 0 and < 1_000_000` (negative, `NaN`, infinite, and `>= 1_000_000` radii stay rejected). - `Core/RageModelDecoder.cs:560`: fall back to computing `previewMin`/`previewMax` from mesh vertices when `min == max` (alongside `dictionary || hasBoneBindings`). This PR does not touch any lines modified by #8, #9, #10 or #11. ## Tests `main` ignores `Tests/`, so the self-contained synthetic smoke test is below (zero game data): - Embedded drawable dictionary child with `radius == 0` and non-empty sub-millimeter bounds passes `ProbeRequiredExtents`, `DecodeModels`, and full synthetic `.rpf` scan + recovery. - Standalone static drawable with `radius == 0` and empty declared bounds `min == max == (0, 0, 0)` passes `LooksLikeDrawable`, `ProbeRequiredExtents`, `Decode`, and synthetic `.rpf` scan + recovery, with `BoundsMin`/`BoundsMax` falling back to the decoded triangle `[0, 1]^3` while `DeclaredBoundsMin`/`DeclaredBoundsMax` stay `(0, 0, 0)`. - Negative (`-0.001`, `-1`), `NaN`, `±Infinity`, and `1_000_000` radii remain rejected for both standalone and dictionary drawables. Negative controls verified before the full fix: - On `917e9b9`: fails at `probe accepts dictionary child with radius 0`. - With only `:124` applied: fails at `BoundsMin/BoundsMax fall back to decoded mesh vertices when declared bounds are empty`. - With both `:124` and `:560`: `ZeroRadiusSmoke: all checks passed`. Copy both files to `Tests/ZeroRadiusSmoke/` and run `dotnet run --project Tests/ZeroRadiusSmoke -c Release`. <details><summary><code>Tests/ZeroRadiusSmoke/ZeroRadiusSmoke.csproj</code></summary> ```xml <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <TreatWarningsAsErrors>true</TreatWarningsAsErrors> </PropertyGroup> <ItemGroup> <ProjectReference Include="..\..\Core\RpfPreview.Core.csproj" /> </ItemGroup> </Project> ``` </details> <details><summary><code>Tests/ZeroRadiusSmoke/Program.cs</code></summary> ```csharp using System.Buffers.Binary; using System.IO.Compression; using System.Numerics; using System.Text; using RpfPreview.Core; // 1. Embedded drawable dictionary child with radius == 0 and non-empty sub-millimeter bounds (core_restofworld case). { var (sys, gfx) = MakeDictionary(radius: 0f, maxBound: 0.0002f); var extent = RageModelDecoder.ProbeRequiredExtents(sys); Check(extent is { MetadataComplete: true, IsDrawableDictionary: true }, "probe accepts dictionary child with radius 0"); var models = RageModelDecoder.DecodeModels(sys, gfx); Check(models.Count == 1 && models[0].Meshes.Count == 1 && models[0].Meshes[0].Positions.Count == 3, "DecodeModels decodes dictionary child with radius 0"); Check(RecoverFromSyntheticArchive(sys, gfx) == 1, "scanner and recovery find dictionary child with radius 0"); } // 2. Standalone static drawable with radius == 0 and empty declared bounds min == max == (0,0,0) (levels.rpf case). { var (sys, gfx) = MakeStandalone(radius: 0f, maxBound: 0f); Check(RageModelDecoder.LooksLikeDrawable(sys), "LooksLikeDrawable accepts standalone drawable with radius 0"); var extent = RageModelDecoder.ProbeRequiredExtents(sys); Check(extent is { MetadataComplete: true, IsDrawableDictionary: false, IsFragment: false }, "probe accepts standalone drawable with radius 0 and empty declared bounds"); var model = RageModelDecoder.Decode(sys, gfx); Check(model is not null && model.Meshes.Count == 1 && model.Meshes[0].Positions.Count == 3, "Decode decodes standalone drawable with radius 0"); Check(model!.DeclaredBoundsMin == Vector3.Zero && model.DeclaredBoundsMax == Vector3.Zero, "declared bounds remain zero"); Check(model.BoundsMin == Vector3.Zero && model.BoundsMax == Vector3.One, "BoundsMin/BoundsMax fall back to decoded mesh vertices when declared bounds are empty"); Check(RecoverFromSyntheticArchive(sys, gfx) == 1, "scanner and recovery find standalone drawable with radius 0"); } // 3. Negative, NaN, infinite, and out-of-range radii remain rejected. foreach (float bad in new[] { -0.001f, -1f, float.NaN, float.PositiveInfinity, float.NegativeInfinity, 1_000_000f }) { var (sys, _) = MakeStandalone(radius: bad, maxBound: 1f); Check(!RageModelDecoder.LooksLikeDrawable(sys), $"LooksLikeDrawable rejects radius {bad}"); Check(RageModelDecoder.ProbeRequiredExtents(sys) is null, $"probe rejects standalone radius {bad}"); var (dsys, _) = MakeDictionary(radius: bad, maxBound: 1f); Check(RageModelDecoder.ProbeRequiredExtents(dsys) is null, $"probe rejects dictionary child radius {bad}"); } Console.WriteLine("ZeroRadiusSmoke: all checks passed"); return 0; static void Check(bool ok, string what) { if (!ok) throw new Exception("Failed: " + what); } static int RecoverFromSyntheticArchive(byte[] sys, byte[] gfx) { string tmp = Path.Combine(Path.GetTempPath(), $"zero_radius_smoke_{Guid.NewGuid():N}.rpf"); try { byte[] sZ = Compress(sys), gZ = Compress(gfx); int gOff = (4096 + 16 + sZ.Length + 15) & ~15; int total = Align4096(gOff + gZ.Length); byte[] file = new byte[total]; Encoding.ASCII.GetBytes("9FPR").CopyTo(file, 0); sZ.CopyTo(file, 4096 + 16); gZ.CopyTo(file, gOff); File.WriteAllBytes(tmp, file); var cands = Rpf9ModelRecovery.FindCandidateOffsets(tmp); if (cands.Count != 1) return 0; var entries = Rpf9ModelRecovery.RecoverAtOffsets(tmp, file.Length, cands, 0); return entries.Count; } finally { if (File.Exists(tmp)) File.Delete(tmp); } } static byte[] Compress(byte[] raw) { using var ms = new MemoryStream(); using (var zs = new ZLibStream(ms, CompressionLevel.Fastest, leaveOpen: true)) zs.Write(raw); return ms.ToArray(); } static int Align4096(int v) => (v + 4095) & ~4095; static (byte[] System, byte[] Graphics) MakeDictionary(float radius, float maxBound) { const int Pages = 0x100, Hashes = 0x140, Values = 0x180, D = 0x400; byte[] system = new byte[0x1200], graphics = new byte[256]; WriteS(system, 8, Pages); BinaryPrimitives.WriteUInt64LittleEndian(system.AsSpan(24), 1); WriteS(system, 32, Hashes); WriteU16(system, 40, 1); WriteU16(system, 42, 1); WriteS(system, 48, Values); WriteU16(system, 56, 1); WriteU16(system, 58, 1); system[Pages + 8] = system[Pages + 9] = 1; WriteU32(system, Hashes, 0x1234567); WriteS(system, Values, D); WriteDrawable(system, graphics, D, embedded: true, pagesAt: 0, radius, maxBound); return (system, graphics); } static (byte[] System, byte[] Graphics) MakeStandalone(float radius, float maxBound) { const int Pages = 0x100, D = 0; byte[] system = new byte[0xE00], graphics = new byte[256]; system[Pages + 8] = system[Pages + 9] = 1; WriteDrawable(system, graphics, D, embedded: false, pagesAt: Pages, radius, maxBound); return (system, graphics); } static void WriteDrawable(byte[] system, byte[] graphics, int D, bool embedded, int pagesAt, float radius, float maxBound) { const int PositionOffset = 96, VertexCount = 3, IndexLength = 48; int name = D + 0x180, shader = D + 0x1C0, lod = D + 0x200, models = D + 0x220, part = D + 0x240; int pointers = D + 0x300, bounds = D + 0x320, geometry = D + 0x400; int vb = geometry + 0xA0, descriptor = geometry + 0x160, ib = geometry + 0x180, fvf = geometry + 0x200; int index = 160; if (!embedded) WriteS(system, D + 8, pagesAt); Encoding.ASCII.GetBytes("zr.#dr").CopyTo(system, name); WriteS(system, D + 16, shader); WriteS(system, D + 80, lod); WriteS(system, D + 168, name); WriteF32(system, D + 44, radius); WriteF32(system, D + 64, maxBound); WriteF32(system, D + 68, maxBound); WriteF32(system, D + 72, maxBound); WriteS(system, lod, models); WriteU16(system, lod + 8, 1); WriteU16(system, lod + 10, 1); WriteS(system, models, part); WriteS(system, part + 8, pointers); WriteU16(system, part + 16, 1); WriteU16(system, part + 18, 1); WriteU16(system, part + 54, 1); WriteS(system, part + 24, bounds); WriteF32(system, bounds + 16, 1f); WriteF32(system, bounds + 20, 1f); WriteF32(system, bounds + 24, 1f); WriteS(system, pointers, geometry); WriteS(system, geometry + 8, vb); WriteS(system, geometry + 64, descriptor); WriteU32(system, vb + 8, PositionOffset + VertexCount * 12); WriteU16(system, vb + 12, 1); WriteG(system, vb + 24, 0); WriteS(system, vb + 64, fvf); WriteU32(system, fvf, PositionOffset); system[fvf + 0xD0] = 12; system[fvf + 0x104] = 6; WriteU32(system, fvf + 0x138, (VertexCount << 10) | 1); WriteU32(graphics, 0, 0x63); WriteF32(graphics, PositionOffset + 12, 1f); WriteF32(graphics, PositionOffset + 24, 1f); WriteF32(graphics, PositionOffset + 28, 1f); WriteF32(graphics, PositionOffset + 32, 1f); WriteS(system, descriptor, ib); WriteU16(system, descriptor + 8, 1); WriteU16(system, descriptor + 10, 1); WriteU32(system, descriptor + 12, VertexCount << 8); WriteU32(system, ib + 8, IndexLength / 4); WriteU16(system, ib + 12, 4); WriteG(system, ib + 24, index); WriteU32(graphics, index, 0x80000001); WriteU32(graphics, index + 4, 1); WriteU32(graphics, index + 8, VertexCount); WriteU32(graphics, index + 12, VertexCount - 1); WriteU32(graphics, index + 28, (2u << 14) | (1u << 7)); graphics[index + 34] = 1; graphics[index + 36] = 2; } static void WriteS(byte[] b, int at, int addr) => BinaryPrimitives.WriteUInt64LittleEndian(b.AsSpan(at), 0x50000000UL + (uint)addr); static void WriteG(byte[] b, int at, int addr) => BinaryPrimitives.WriteUInt64LittleEndian(b.AsSpan(at), 0x60000000UL + (uint)addr); static void WriteU16(byte[] b, int at, int v) => BinaryPrimitives.WriteUInt16LittleEndian(b.AsSpan(at), checked((ushort)v)); static void WriteU32(byte[] b, int at, uint v) => BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(at), v); static void WriteF32(byte[] b, int at, float v) => BinaryPrimitives.WriteSingleLittleEndian(b.AsSpan(at), v); ``` </details> ## Testing environment Tested on Windows 11 Build 26200 x64 with .NET SDK 8.0.428 (CPU only). `Core` builds with `/p:TreatWarningsAsErrors=true` (0 warnings, 0 errors), and `Leonida`'s `rpf9dump` builds cleanly against it. AI-assisted. No game data is included here (counts and synthetic test fixture only). Related tracking item: ItsNotRexed/Leonida#1006 (`ASSET-69`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:05:01 +00:00
github manually merged commit 47434e0811 into gh-pr/12/base 2026-11-26 19:05:03 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.