Skip to content

Accept bone-palette hint 2 when vertex bone indices are 16-bit - #10

Merged
breadbbbb merged 1 commit into
breadbbbb:mainfrom
cxchhh:codex/bone-palette-wide-indices
Nov 22, 2026
Merged

breadbbbb merged 1 commit into
breadbbbb:mainfrom
cxchhh:codex/bone-palette-wide-indices

Conversation

@cxchhh

@cxchhh cxchhh commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Why

In a bone-palette index header (0x40000000 set), ReadMesh reads the hint field at bits 16..28. With the constant-binding flag (0x20000000), hint / 2 is the one bone. Without that flag, ReadMesh requires hint == 0. In levels.rpf of the 1.0.2.1 package, 504 fragments fail only on that check.

A census of all 74,335 bone-palette geometries in levels.rpf shows that a non-constant hint is either 0 or 2, and that the value follows the per-vertex bone index format in vertex slot 20:

Non-constant hint Slot 20 (size, DXGI format) Geometries
0 1 byte, R8_UINT (62) 9,328
0 4 bytes, R8G8B8A8_UINT (30) 310
0 8 bytes, R16G16B16A16_UINT (12) 198
2 2 bytes, R16_UINT (57) 822

Hint 2 occurs with a single R16_UINT index in 822 of 822 cases, and with nothing else. Every one of those 822 geometries belongs to a model with 257–425 bones, more than an 8-bit index can address. Constant-binding geometries (63,677) have no slot 20.

Change

Without the constant-binding flag, accept hint 2 when slot 20 is a single R16_UINT. Hint 0 still works for every format, and any other value is still rejected. Constant binding is unchanged, and every palette entry is still checked against the model's bone count.

Results

Measured on the 1.0.2.1 package, each decoder using its own scanner, over the ten archives that Leonida scans:

Decoder Change in recovered resources Decoded models Vertices Triangles
main (917e9b9) + this PR 0 0 0 0
main + #8 + this PR, compared with main + #8 +491 (all in levels.rpf) +491 +38.2M +39.0M

All 504 affected meshes are fragments whose headers the current LooksLikeFragment rejects, so on main they never reach ReadMesh, and this PR changes nothing there. Together with #8, 491 of the 504 decode. The other 13 still fail other ReadMesh checks, and this PR does not change them. No archive loses a resource, model, vertex or triangle in either configuration. The two changes do not conflict.

Tests

main ignores Tests/, so there is no test project in this PR. The census above is the evidence. The geometry checks in ReadMesh still apply to the newly accepted meshes: vertex references, cluster tables, and part bounds within tolerance.

Testing environment

Tested on Linux x64 with .NET SDK 8.0.428, CPU only. Core builds with warnings as errors. I could not build the Windows app on this machine, and the app code is unchanged.

AI-assisted: an AI agent (Claude, Anthropic) did the investigation, code and measurements on the author's behalf. No game data is included here.

🤖 Generated with Claude Code

ReadMesh required hint 0 for every bone palette without the constant-
binding flag. A non-constant hint is 2 exactly when the vertex bone index
(slot 20) is a single R16_UINT, which models with more than 256 bones
use: 822 of 822 such meshes in levels.rpf, with no other combination.
Hint 0 goes with R8_UINT, R8G8B8A8_UINT and R16G16B16A16_UINT (9,836).
Accept hint 2 in that case only; constant binding keeps hint / 2 as the
bone, and every palette entry is still checked against the bone count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cxchhh

cxchhh commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Same downstream measurement as on #8 (#8): in a 700 m downtown box, the share of levels.rpf HD placements that find a recovered model goes from 36.7% at 917e9b9 to 99.9% with #8 and this PR applied. This PR's part is the 491 large-rig fragments (257–425 bones), mostly vehicles, that #8 alone still rejects at the bone-palette check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants