80 lines
3.7 KiB
Python
80 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Read-only evidence for NC-named static shape registration exclusions.
|
|
|
|
Run from GamePort. Checks original instruction bytes/vtable slots, then counts
|
|
source polygons. No original instructions are executed or modified.
|
|
"""
|
|
from pathlib import Path
|
|
import hashlib
|
|
import json
|
|
import sys
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
PROJECT = HERE.parent.parent
|
|
sys.path.insert(0, str(HERE))
|
|
sys.path.insert(0, str(PROJECT / 'tools/extractors'))
|
|
from pe_inspect import PE
|
|
from omt import Database, read_shape
|
|
|
|
|
|
def static_shape_enabled(name):
|
|
"""44DD2F..44DD6D: ASCII case-insensitive NC prefix omits InitPhysics."""
|
|
return name[:2].lower() != 'nc'
|
|
|
|
|
|
def evidence(originals=None):
|
|
originals = Path(originals) if originals else PROJECT.parent / 'Original'
|
|
pe = PE(originals / 'Neutron.exe')
|
|
sequences = {
|
|
'lab_initializer_calls_colour_shape_loader': (0x44f569, 'ff9058010000'),
|
|
'shape_loader_lowercase_first': (0x44dd27, 'e88d1c0300'),
|
|
'shape_loader_first_is_n': (0x44dd2f, '83f86e7535'),
|
|
'shape_loader_lowercase_second': (0x44dd5c, 'e8581c0300'),
|
|
'shape_loader_second_is_c_skips_initphysics': (0x44dd64, '83f8637407'),
|
|
'shape_loader_ordinary_initphysics': (0x44dd69, '8b178bcfff522c'),
|
|
'terrain_initphysics_register_shape': (0x464b11, '8b8e1404000051e823460100'),
|
|
'resource_lookup_is_3dsh': (0x477bc2, '6868534433'),
|
|
'ascii_lowercase_bounds': (0x47f9cc, '83f8410f8caa00000083f85a0f8fa100000083c020'),
|
|
}
|
|
for label, (va, hex_bytes) in sequences.items():
|
|
offset = pe.offset(va - pe.base)
|
|
actual = pe.data[offset:offset + len(hex_bytes) // 2].hex()
|
|
if actual != hex_bytes:
|
|
raise ValueError(f'{label} source bytes differ at {va:#x}: {actual}')
|
|
slots = {'lab_game_slot158': (0x4c3cd0 + 0x158, 0x44dbf0),
|
|
'terrain_interface_slot2c': (0x4d4ccc + 0x2c, 0x464b00)}
|
|
for label, (va, expected) in slots.items():
|
|
actual = pe.u32(pe.offset(va - pe.base))
|
|
if actual != expected:
|
|
raise ValueError(f'{label} differs: {actual:#x}')
|
|
scenes = {}
|
|
for level in ('level1b', 'level1', 'VR04'):
|
|
db = Database(originals / 'omt' / f'{level}.omt')
|
|
material_names = {e.id: e.name for e in db.entries if e.type == '3DMa'}
|
|
excluded, included = [], []
|
|
null_triangles = 0
|
|
for entry in db.entries:
|
|
if entry.type != '3DSh':
|
|
continue
|
|
shape = read_shape(db.payload(entry))
|
|
triangles = sum(len(p['corners']) - 2 for p in shape['polygons'])
|
|
fact = {'id': entry.id, 'name': entry.name, 'triangles': triangles}
|
|
if static_shape_enabled(entry.name):
|
|
included.append(fact)
|
|
null_triangles += sum(len(p['corners']) - 2 for p in shape['polygons']
|
|
if not p['material'] or p['material']['id'] not in material_names)
|
|
else:
|
|
excluded.append(fact)
|
|
scenes[level] = dict(excluded_shapes=excluded,
|
|
source_triangles=sum(e['triangles'] for e in included + excluded),
|
|
registered_triangles=sum(e['triangles'] for e in included),
|
|
registered_null_material_triangles=null_triangles)
|
|
return dict(source_sha256=hashlib.sha256(pe.data).hexdigest(),
|
|
instruction_checks=len(sequences), vtable_checks=len(slots), scenes=scenes,
|
|
rule='Case-insensitive shape name starts NC: skip static collision registration; retain render geometry.',
|
|
limitation='Static source/data proof. No original runtime comparison; water/hazard behavior and full solver remain incomplete.')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
print(json.dumps(evidence(), indent=2))
|