Fix garbage prop-batch instances (pool refs first, separate graphics page stream) #48
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/holdmysocks--SixNG!48
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/48/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@holdmysocks on GitHub · 2026-11-23 13:57 UTC · original
holdmysocks:fix/prop-batch-decode→master· +258 −8 · 6 files · 1 commits · merged 2026-11-23 14:02 UTCAbout 0.5% of prop-batch instances in
levelsand 10% inpack/shared_minigame000decoded with garbage transforms: position 0,0,0 or 1e10–1e35, and scale 0, 1e3–1e18 or inf. This had two causes.1. Pool references read as real pointers (
meta7a.rs)Meta::ptrtried the real sys/gfx pointer reading first. A pool reference whose byte offset is 0x500–0x5FF or 0x600–0x6FF, with a zero low byte, also looks like a pointer. For example,0x5000_0003is block 3, offset 0x500, but it reads as sys offset 3. Pool references now resolve first, and the real-pointer reading is only the fallback.Census of every pointer, array and map member in every
levelsmeta resource: no value needs the real reading. All 14,471 ambiguous values point into a block of the expected struct, and none of them lands on a block start as a real pointer. Besides prop batches (8,617 arrays), this also fixes about 950CEntityDefextension arrays and about 4,500 other arrays.sixng lights levels: 136,548 → 139,291 light sets and 775,132 → 778,985 placed lights, with 0 implausible positions before or after.2. Graphics page in its own stream (
resource.rs)In 105 map files in
levelsand 2 in the minigame pack, the last stream fills whole 64 KiB chunks (64 K, 128 K or 448 K). In those files the graphics page isn't stored uncompressed right after that stream. It is a separate zlib stream a few KiB further on, which the index lists as a separatebinentry. Its length is exactly the instance block extent, or that rounded up to 64 KiB.load_metanow searches 256 KiB past the last stream, at 16-byte alignment, for such a stream. It only searches in the full-chunk case: without that limit, tiny 64-byte pages matched unrelated streams.Numbers (
sixng placements --batches-only,batch_props.bin)Bad means a non-finite value, |pos| ≥ 1e10, pos all zero, or a scale axis of 0, ≥ 1e3 or inf.
A stricter research check (
examples/propbad.rs, which also flags any scale axis below 1e-4) still flags 6 records. All 6 are real data: flat props with a z scale of exactly 1e-5, inside their batch bbox, with a sensible rotation.Tests
batches::tests: a synthetic batch at the ambiguous pool reference0x5000_0003, with decoy bytes where the real-pointer reading lands. Also checks the gfx-offset variant and the fallback to a real pointer.resource::page_stream_tests: a page stream behind junk and an unrelated stream, a page padded to 64 KiB, and lengths that are too small or too large.The README batch section notes the fix and that
batch_props.binexports from before it should be redone.