111 lines
6.1 KiB
Python
111 lines
6.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Read-only 3DUD/defaults/oriented-cube collision evidence; executes no originals."""
|
|
from pathlib import Path
|
|
import hashlib
|
|
import json
|
|
import re
|
|
import struct
|
|
import sys
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
PROJECT = HERE.parent.parent
|
|
sys.path.insert(0, str(HERE))
|
|
sys.path.insert(0, str(PROJECT / 'tools/levels'))
|
|
from pe_inspect import PE
|
|
from rtti_map import rtti_map
|
|
from gam import parse
|
|
|
|
|
|
def main():
|
|
original = PROJECT.parent / 'Original'
|
|
pe = PE(original / 'Neutron.exe')
|
|
checks = {
|
|
'door_pair_collision_enable': (0x4175b0, '56e80a9b0500'),
|
|
'door_mode2_push': (0x4175c6, '6a02'),
|
|
'door_mode2_setter': (0x4175ca, 'e861a10500'),
|
|
'door_integration_disable': (0x4175cf, '578bcde8599a0500'),
|
|
'door_postload_radius40': (0x417cab, '6800002042'),
|
|
'door_postload_radius_setter': (0x417cb2, 'ff9210010000'),
|
|
'activation_has_collision_sentinel': (0x40e410, '83f8ff747c'),
|
|
'activation_enable_pairs': (0x40e427, 'ff90ac030000'),
|
|
'activation_disable_pairs': (0x40e44b, 'ff90a4030000'),
|
|
'pair_dispatch_box_mode': (0x47a4cf, 'ff9078010000'),
|
|
'pair_dispatch_box_first': (0x47a4dc, 'e8ff000000'),
|
|
'pair_dispatch_box_second': (0x47a4f4, 'e8e7000000'),
|
|
'box_query_other_geometry_gate': (0x47a5f5, 'ff90d0010000'),
|
|
'box_query_other_mode': (0x47a707, 'ff9278010000'),
|
|
'box_sphere_double_box_radius': (0x47a73f, 'd9842498000000dcc0d8842494000000'),
|
|
'box_min_bound_getter': (0x47a776, 'ff90e4020000'),
|
|
'box_max_bound_getter': (0x47a7a5, 'ff90dc020000'),
|
|
'box_corner_transform': (0x47a7ec, 'ff9084030000'),
|
|
'box_triangle_count12': (0x47ab67, 'c784240c0100000c000000'),
|
|
'box_triangle_narrowphase': (0x47b277, 'e8040b0000'),
|
|
'box_response_inhibition_gate': (0x47b2ef, 'ff90e0010000'),
|
|
'box_response_world_clip': (0x47b364, 'e847010000'),
|
|
'box_response_position_setter': (0x47b399, 'ff9014030000'),
|
|
'shape_change_cube_query': (0x4622d4, 'ff5044'),
|
|
'shape_change_min_bound_setter': (0x4622fb, 'ff90e8020000'),
|
|
'shape_change_max_bound_setter': (0x462325, 'ff90e0020000'),
|
|
}
|
|
for label, (va, expected) in checks.items():
|
|
offset = pe.offset(va - pe.base)
|
|
actual = pe.data[offset:offset + len(expected) // 2].hex()
|
|
if actual != expected:
|
|
raise ValueError(f'{label} at{va:#x}: {actual} != {expected}')
|
|
table = struct.unpack_from('<12I', pe.data, pe.offset(0x47b3ac - pe.base))
|
|
assert table == (0x47ab82, 0x47abf3, 0x47ac64, 0x47acd5, 0x47ad46, 0x47adb7,
|
|
0x47ae34, 0x47aeb1, 0x47af22, 0x47af93, 0x47aff8, 0x47b075)
|
|
# These bounded switch cases copy three source corners into the triangle
|
|
# scratch vectors. Decode their mov EAX/ECX/EDX,[ESP+disp] loads directly.
|
|
locals_to_corners = {0xdc: 0, 0x70: 1, 0x40: 2, 0xac: 3,
|
|
0x50: 4, 0x60: 5, 0xbc: 6, 0x9c: 7}
|
|
triangles = []
|
|
for start, end in zip(table, (*table[1:], 0x47b0ef)):
|
|
code = pe.data[pe.offset(start - pe.base):pe.offset(end - pe.base)]
|
|
offsets = [m[1][0] if m[1] else struct.unpack('<I', m[2])[0] for m in re.finditer(
|
|
rb'\x8b[\x44\x4c\x54]\x24(.)|\x8b[\x84\x8c\x94]\x24(.{4})', code)]
|
|
assert len(offsets) == 12
|
|
triangles.extend(locals_to_corners[offsets[i]] for i in (0, 4, 8))
|
|
assert triangles == [0,1,2,1,3,2,0,2,4,2,6,4,4,6,5,6,7,5,5,7,3,5,3,1,0,4,1,4,5,1,2,3,7,7,6,2]
|
|
interface = next(t for t in rtti_map(pe, 'C3DDoorUpDown')['vtables']
|
|
if t['object_displacement'] == '0xc0')
|
|
assert interface['va'] == '0x4993ac'
|
|
methods = {m['slot']: m['va'] for m in interface['methods']}
|
|
for slot, target in {'0x178': '0x471720', '0x384': '0x472980', '0x40c': '0x417c50'}.items():
|
|
assert methods[slot] == target
|
|
level_path = original / 'gam/level1b.gam'
|
|
level = parse(level_path.read_bytes())
|
|
bars_entity = next(e for e in level.entities if e.kind == '3DUD' and e.values().get('ObjectTag') == 'bars')
|
|
bars = bars_entity.values()
|
|
assert bars['HasCollision'] == -1 and bars['CanMove'] == 1
|
|
source = next(p for p in (original / 'ASE').iterdir() if p.name.casefold() == bars['ASEFile'].casefold())
|
|
text = source.read_text(encoding='latin-1')
|
|
count = int(re.search(r'\*MESH_NUMVERTEX\s+(\d+)', text)[1])
|
|
points = [(float(x), float(z), float(y)) for x, y, z in re.findall(
|
|
r'\*MESH_VERTEX\s+\d+\s+([-\d.]+)\s+([-\d.]+)\s+([-\d.]+)', text)[:count]]
|
|
assert count == len(points) == 42
|
|
low = [min(v[i] for v in points) for i in range(3)]
|
|
high = [max(v[i] for v in points) for i in range(3)]
|
|
print(json.dumps(dict(
|
|
executable_sha256=hashlib.sha256(pe.data).hexdigest(),
|
|
verified_instruction_sequences=len(checks), verified_jump_table_entries=len(table),
|
|
door_interface=interface['va'], mode=2, postload_radius=40,
|
|
constructor_defaults=dict(entity_pair_collision=True, integrate_own_physics=False,
|
|
has_collision_minus1='preserves both defaults'),
|
|
normal_sphere_broadphase='quick_magnitude(otherRoot-boxRoot) <=2*boxRadius+otherRadius',
|
|
second_mode2_broadphase='quick_magnitude(otherRoot-boxRoot) <=boxRadius+otherRadius; returns directly',
|
|
bounds_origin='OMT shape find_cube ->EXE462270 ->iface2E8(min),2E0(max)',
|
|
corners='bit4 selects maxX,bit2 maxY,bit1 maxZ; transform by current root/rotation viaiface384',
|
|
triangle_corners=triangles,
|
|
lab_bars=dict(gam_offset=hex(bars_entity.offset), gam_sha256=hashlib.sha256(level_path.read_bytes()).hexdigest(),
|
|
ase_source=source.relative_to(original).as_posix(), ase_sha256=hashlib.sha256(source.read_bytes()).hexdigest(),
|
|
source_vertices=count, local_min=low, local_max=high,
|
|
position=[bars['Position'+a] for a in 'XYZ'], rotation=[bars['Rotation'+a] for a in 'XYZ'],
|
|
has_collision=bars['HasCollision'], can_move=bars['CanMove'], open_amount=bars['OpenAmount']),
|
|
limitation='Static geometry/dispatch/default evidence.47BD80 narrowphase and original runtime door blocking remain unverified.'
|
|
), indent=2))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|