code wiki / (root) / nx_nif_lib.nx

nx_nif_lib.nx

buildroot/runtime/nx_nif_lib.nx

19011 B401 linesdepth 4pulls 4 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_nif_lib.nx -- NETIMMERSE/GAMEBRYO NIF STRUCTURAL FACTS CORE (the Bethesda mesh container; /compare/koikatsu KK12 contract, legs 1+2 2026-08-30). SCHEMA GROUND TRUTH is the mirrored niftools nif.xml (GPL-3.0, read as an ORACLE) plus REAL fixtures from the nifly test corpus, hex-measured the same day: magic line then u32 version 0x14020007, u8 endian, u32 user version, u32 num blocks, BSStreamHeader, u16 num block types, SizedString type table, u16 type index per block, u32 size per block, string table, groups. BSStreamHeader export-string rule, VERCONDS FROM nif.xml AND CONFIRMED ON REAL BYTES (SE bsver 100 and FO76 bsver 155): Author always; one u32 when BS > 130; Process Script when BS < 131; Export Script always; Max Filepath when BS >= 103. THREE-STATE HONESTY: is_nif = 0 not a NIF; 1 parsed (modern layout); 2 RECOGNIZED-UNSUPPORTED -- the magic line is real but the version or a bound refuses, so every count ABSTAINS at -1 rather than misparse into confident garbage. A bounds failure is a named abstention, never a guess. MEASURED COVERAGE: Skyrim SE (100), Skyrim LE (83) and FO76 (155) headers all parse. GEOMETRY LEG (nif_geom): per-TriShape vertex/triangle counts extracted at the SSE BSTriShape tuple (desc u64, tri u16, vert u16, datasize u32 behind the 100+4*extra NiAVObject prefix) and VERIFIED BY THE SCHEMA'S OWN ARITHMETIC -- nif.xml declares DataSize = (desc AND 0xF) * verts * 4 + tris * 6, so a tuple that satisfies it is self-proven and one that does not is counted UNVERIFIED by name (LE NiTriShape and FO76 layouts land there deliberately). Full vertex DATA extraction to .nxmesh remains the contract's declared final half. SCOPE DECLARED: the census counts blocks whose TYPE NAME contains TriShape; NiTriStrips is not counted -- stated imprecision, widen deliberately. Slots: [0] is_nif [1] version [2] bs_version [3] num_blocks [4] num_block_types [5] trishape_blocks [6] total_block_bytes [7] num_strings [8] header_bytes [9] endian license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 2 imports · 2 importers

nx_syscalls.nx nx_kkfacts_lib.nx nx_nif_lib.nx nx_nif_gate.nx nx_niffacts.nx

imports: nx_syscalls.nxnx_kkfacts_lib.nx

imported by: nx_nif_gate.nxnx_niffacts.nx

structs

none

consts

28const NF_N_SLOTS: i64 = 10
29const NF_MAGIC_SCAN: i64 = 64 // the magic line ends within the first 64 bytes on every known dialect
30const NF_VER_SSE: i64 = 335675399 // 0x14020007 = 20.2.0.7, the modern Bethesda layout this lib parses
31const NF_MAX_TYPES: i64 = 2048 // a type table beyond this refuses as UNSUPPORTED (bound, not a guess)
32const NF_MAX_TYPENAME: i64 = 64
33const NF_MAX_STRINGS: i64 = 65536
34const NF_MAX_STRLEN: i64 = 4096
35const NF_MAX_GROUPS: i64 = 65536
36const NF_BS_EXTRAINT_GT: i64 = 130 // BS Version above which the header carries one extra u32 (nif.xml)
37const NF_BS_PROCSCRIPT_LT: i64 = 131 // BS Version below which Process Script exists (nif.xml)
38const NF_BS_MAXPATH_GTE: i64 = 103 // BS Version at/above which Max Filepath exists (nif.xml)
39const NF_BS_SSE: i64 = 100 // the one BS version whose BSTriShape tuple the geometry leg verifies
40const NF_UV_BS: i64 = 12 // user version at/above which the BSStreamHeader exists
41const NF_CH_NL: i64 = 10
42const NF_GEOM_PREFIX_BASE: i64 = 100 // SSE NiAVObject fixed part 72 + NiBound 16 + skin/shader/alpha refs 12
43const NF_GEOM_TUPLE: i64 = 16 // desc u64 + tri u16 + vert u16 + datasize u32
44const NF_MAX_EXTRA: i64 = 64 // an extra-data list beyond this reads UNVERIFIED, never trusted
45const NF_DESC_LOW_MASK: i64 = 0xF // vertex-record size in dwords lives in the desc's low nibble
239const NF_GEOM_MAX_BLOCKS: i64 = 65536
311const NF_BOUND_OFF: i64 = 72 // NiBound (center xyz f32 + radius f32) after the 72-byte NiAVObject fixed part
312const NF_INSIDE_SLACK_NUM: i64 = 1051 // 5.1 percent radius slack for f32-to-permil rounding -- named imprecision
313const NF_INSIDE_SLACK_DEN: i64 = 1000

functions

47func nf_u8(buf: *u8, o: i64) -> i64 { return buf[o] as i64 & 0xff }
48func nf_u16(buf: *u8, o: i64) -> i64 { return nf_u8(buf, o) | (nf_u8(buf, o + 1) << 8) }
called by 3: nf_walknif_geomnif_verts calls 1: nf_u8
49func nf_u32(buf: *u8, o: i64) -> i64 { return nf_u8(buf, o) | (nf_u8(buf, o + 1) << 8) | (nf_u8(buf, o + 2) << 16) | (nf_u8(buf, o + 3) << 24) }
52func nf_starts(buf: *u8, at: i64, end: i64, pre: *u8) -> i64
62func nf_span_has(buf: *u8, off: i64, len: i64, needle: *u8) -> i64
called by 3: nf_walknif_geomnif_verts calls 1: kk_find
68func nf_export(buf: *u8, p: i64, n: i64) -> i64
called by 1: nf_walk calls 1: nf_u8
79func nf_walk(buf: *u8, n: i64, facts: *i64, toffs: *i64, tlens: *i64, tcounts: *i64, maxtypes: i64, bidx: *i64, bsz: *i64, bcap: i64) -> i64
186func nif_probe(buf: *u8, n: i64, file_size: i64, facts: *i64) -> i64
called by 2: mainmain calls 3: nf_startssys_mmapnf_walk
218func nif_types(buf: *u8, n: i64, file_size: i64, toffs: *i64, tlens: *i64, tcounts: *i64, maxtypes: i64, meta: *i64) -> i64
called by 2: mainmain calls 3: sys_mmapnf_startsnf_walk
247func nif_geom(buf: *u8, n: i64, file_size: i64, vouts: *i64, touts: *i64, vflags: *i64, cap: i64, meta: *i64) -> i64
316func nf_f32p(buf: *u8, o: i64) -> i64 { return kk_f32_permil(nf_u32(buf, o)) }
called by 1: nif_verts calls 2: kk_f32_permilnf_u32
324func nif_verts(buf: *u8, n: i64, file_size: i64, shape_sel: i64, pxs: *i64, pys: *i64, pzs: *i64, cap: i64, meta: *i64) -> i64