FO4-D1-H1: Next-Gen Patch NIFs Misalign Silently
FO4-D1-H1: Next-Gen Patch NIFs Misalign Silently at BSVER 131
Hey guys, let's dive into an interesting issue with FO4's Next-Gen patch NIFs. We've found a gap in the BSVER 131 flag-pair and CRC-count readings, which can cause some serious misalignments in your shaders. Let's fix that!
The Issue
In the crates/nif/src/blocks/shader.rs file, we've got two BSVER gates in the BSLightingShaderProperty::parse function that disagree on the FO4 / Next-Gen boundary. Here's what's happening:
- Flag-pair read: Lines 411-415 read the flag-pair only if
bsver <= 130. This means BSVER 131 reads neither the u32 pair nor the CRC counts, leaving a 4-byte or 8-byte gap depending on the wire layout.
nif.xml Reference
The nif.xml #BS_FO4_2# covers BSVER 130 to 139, suggesting the pair-drop happens at 131, not 132. To confirm, we need a canonical BSVER 131 NIF from the Next-Gen patch content.
Impact
Any FO4 Next-Gen patch mesh at BSVER 131 will misalign at the shader block. This can cause materials to render as black or purple due to incorrect flag readings or emissive color offsets.
The Fix
To resolve this issue, we need to:
- Inspect a canonical BSVER 131 NIF from the Next-Gen patch content to determine the correct boundary.
- Align both gates on the correct boundary, like this:
let (shader_flags_1, shader_flags_2) = if bsver <= 130 {
(stream.read_u32_le()?, stream.read_u32_le()?)
} else {
(0, 0)
};
if bsver >= 131 {
num_sf1 = stream.read_u32_le()?;
num_sf2 = stream.read_u32_le()?;
...
}
- Add fixture tests at BSVER 130, 131, 132, and 139 to lock the boundaries.
Completeness Checks
- UNSAFE: N/A
- SIBLING: Related to FO4-D1-C1. Verify every BSVER gate in
shader.rsagainstnif.xml. - DROP: N/A
- LOCK_ORDER: N/A
- FFI: N/A
- TESTS: Add per-BSVER fixture tests mirroring the existing FO4/FO76 harness.
Stay tuned for more updates, and happy modding!