276 lines
13 KiB
Python
276 lines
13 KiB
Python
#!/usr/bin/env python3
|
|
"""Read-only contact callback, friction and publication evidence; bounded projections."""
|
|
from __future__ import annotations
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import struct
|
|
import sys
|
|
from checkpoint_script_state import EXE_SHA256, find_case, read_va
|
|
from pe_inspect import PE
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'extractors'))
|
|
from omt import Database, Reader, read_material, read_shape
|
|
|
|
DLL_SHA256 = '3ec41ead011adf56387a6dbd4580e5b5a9721b5f8020c8a56420f42824354943'
|
|
DLL_SITES = (
|
|
('db_link_chunk', 0x10030070, '8b4424048b54240c89411c8b44240889410c89511089480c8b410c668b502066895122c20c00'),
|
|
('header_id_offset_size', 0x1004659f, '8b4b288d54245852e8f4d302008b4b288d44245050e837d402008d4c2454518b4b28e82ad40200'),
|
|
('header_record_insert', 0x10046635, '8b4e148d542450528b4104508d44243450e865190000'),
|
|
('chunk_id_lookup', 0x10045b98, '8b4c24108b500c3bca7c068d44240ceb08897424048d4424048b003bc65e740a8b401083c00859'),
|
|
('object_lookup_chunk', 0x1002df43, '55538bceff50488b3e55538bceff576c508bceff5774538be8'),
|
|
('object_db_link_call', 0x1002e0a5, '8b4c24108b075355518bcfff5018'),
|
|
('link_reads_fourcc_id', 0x100302ac, '8d4c2410518bcee8383704008d5424148bce52e8dc3604008b5c24108b6c2414'),
|
|
('link_get_object', 0x100302e8, '8b0755538bcfff50148b4c2418894104'),
|
|
('polygon_link_read', 0x10003f4f, '8d4424388bce50e8a5fe06008b4c243c51e910030000'),
|
|
('polygon_material_set', 0x10004275, '8bcbe874010000'),
|
|
('material_pointer_publish', 0x10004402, '8b44240485c08941047403ff4014c20400'),
|
|
)
|
|
|
|
# Fixed signatures from independently reviewed original instructions.
|
|
SITES = (
|
|
('root_before_normal', 0x47b7b1, '89038b442440894b048953088943'),
|
|
('normal_threshold', 0x47b7e3, 'd81d48314a00'),
|
|
('normal_strict_positive_side', 0x47b7f9, 'f6c441751f'),
|
|
('wall374', 0x47b80f, 'ff9774030000'),
|
|
('ceiling370', 0x47b82e, 'ff9770030000'),
|
|
('ceiling_velocity_read', 0x47269f, 'ff90bc020000'),
|
|
('ceiling_velocity_strict', 0x4726c0, 'f6c4417526'),
|
|
('ceiling_velocity_write', 0x4726e3, 'ff90c0020000'),
|
|
('ceiling_accel_read', 0x4726f6, 'ff9270020000'),
|
|
('ceiling_accel_strict', 0x472717, 'f6c4417525'),
|
|
('ceiling_accel_write', 0x472734, 'ff9074020000'),
|
|
('jimmy_gadget', 0x42a660, '66833d88054f0007'),
|
|
('jimmy_common_player_forward', 0x42a70b, 'e830030100'),
|
|
('base_guard', 0x458895, 'ff90d801000084c0742a8b4c'),
|
|
('base378', 0x4588c3, 'ff9078030000'),
|
|
('player_elapsed', 0x43aa4a, 'd98674070000d81da0e54800'),
|
|
('player_metadata', 0x43aa69, '8b400485c074658b400c85c00f84520200008b'),
|
|
('player_mode', 0x43aad5, '6683be04070000000f85f8040000'),
|
|
('landing_root', 0x47bb32, 'ff9018030000'),
|
|
('landing_acceleration', 0x47bb4b, 'ff9078020000'),
|
|
('landing_previous_ground', 0x47bb51, 'a0495d690084c0750a'),
|
|
('landing37c', 0x47bb5e, 'ff907c030000'),
|
|
('landing_velocity', 0x47bb74, 'ff92c4020000'),
|
|
('landing_support', 0x47bb7c, '6a018bceff921c020000'),
|
|
('landing_shape', 0x47bb91, 'ff904c030000'),
|
|
('landing_polygon', 0x47bba1, 'ff923c030000'),
|
|
('friction_speed_read', 0x47a241, 'ff9268020000'),
|
|
('friction_equal_zero', 0x47a24f, 'f6c4407440'),
|
|
('friction_call', 0x47a25a, 'e8d1000000'),
|
|
('friction_support', 0x47a344, 'ff901802000084c00f84ca000000'),
|
|
('friction_coefficient', 0x47a356, 'ff9248020000'),
|
|
('friction_magnitude', 0x47a38e, 'ff1504d14800d81d14d94800dfe0f6c441757b'),
|
|
('friction_linear_add', 0x47a3cb, 'ff92cc020000'),
|
|
('friction_angular_add', 0x47a416, 'ff92b8020000'),
|
|
('speed_getter', 0x471b50, 'd98160010000c3'),
|
|
('speed_setter', 0x471b60, '8b442404898160010000c20400'),
|
|
('speed_publication', 0x437c22, '8b86080600008b16508bceff926c020000'),
|
|
('small_motion_scale', 0x471a70, 'd98144010000c3'),
|
|
('threshold_minus07', 0x4a3148, '333333bf'),
|
|
('threshold_zero', 0x48d914, '00000000'),
|
|
('threshold_point1', 0x48d920, 'cdcccc3d'),
|
|
('threshold_3', 0x48e5a0, '00004040'),
|
|
('ctor_ebx_zero', 0x46fc08, '33db'),
|
|
('ctor208_false', 0x46fdbc, '538bcde8ac110000'),
|
|
('ctor1c8_true', 0x46fdc4, '6a018bcde8d3110000'),
|
|
('ctor1d0_true', 0x46fdcd, '6a018bcde8fa110000'),
|
|
('ctor220_true', 0x46fdf0, '6a018bcde8c7120000'),
|
|
('ctor228_false', 0x46fdf9, '538bcde8ef120000'),
|
|
('ctor42c_false', 0x46ffb1, '889d2c040000'),
|
|
('player208_true', 0x43740a, '578bcee85e9b0300'),
|
|
)
|
|
|
|
BODY_HASHES = (
|
|
('ceiling370', 0x472690, 0xba, 'febfe9381b19074c41b229b314307c85f95710a35c7907935f76519052d4b50c'),
|
|
('jimmy374', 0x42a660, 0xb4, 'd52831057c35afbdb73babff81857a6a3cfb2466f639b8be0a80e6300d386b0c'),
|
|
('player374', 0x43aa40, 0x5a3, '2acd114eb62fe67490d9301bc8e68f196830be74eb9076f52f79111467344a78'),
|
|
('base374', 0x458890, 0x3d, '250d34ac046749aa9e6d6e22968b1139a98be46d8f31cb2dda287ddc5c2c4b6f'),
|
|
('friction', 0x47a330, 0xf1, '3ac4d0268edb5fa4f5689a87fdc36759c12589caf76b2286b1817f2204a91155'),
|
|
('landing37c', 0x472970, 0x1, 'ae3f4619b0413d70d3004b9131c3752153074e45725be13b9a148978895e359e'),
|
|
)
|
|
|
|
TABLES = (
|
|
('Object', 0x4d3154, 0x370, 0x472690),
|
|
('Object', 0x4d3154, 0x374, 0x458890),
|
|
('Object', 0x4d3154, 0x378, 0x472750),
|
|
('Object', 0x4d3154, 0x37c, 0x472970),
|
|
('Object', 0x4d3154, 0x230, 0x471a70),
|
|
('Animated', 0x48fe1c, 0x370, 0x472690),
|
|
('Animated', 0x48fe1c, 0x374, 0x458890),
|
|
('Animated', 0x48fe1c, 0x378, 0x472750),
|
|
('Animated', 0x48fe1c, 0x37c, 0x472970),
|
|
('Animated', 0x48fe1c, 0x230, 0x471a70),
|
|
('Player', 0x4af6c4, 0x370, 0x472690),
|
|
('Player', 0x4af6c4, 0x374, 0x43aa40),
|
|
('Player', 0x4af6c4, 0x378, 0x472750),
|
|
('Player', 0x4af6c4, 0x37c, 0x472970),
|
|
('Player', 0x4af6c4, 0x230, 0x471a70),
|
|
('Jimmy', 0x4a373c, 0x370, 0x472690),
|
|
('Jimmy', 0x4a373c, 0x374, 0x42a660),
|
|
('Jimmy', 0x4a373c, 0x378, 0x472750),
|
|
('Jimmy', 0x4a373c, 0x37c, 0x472970),
|
|
('Jimmy', 0x4a373c, 0x230, 0x471a70),
|
|
)
|
|
|
|
NORMAL_Y_THRESHOLD = struct.unpack('<f', bytes.fromhex('333333bf'))[0]
|
|
|
|
|
|
def normal_callback(normal_y):
|
|
"""Finite-input dispatch only; caller already publishes candidate root."""
|
|
return 0x374 if normal_y > NORMAL_Y_THRESHOLD else 0x370
|
|
|
|
|
|
def ceiling_projection(velocity, acceleration):
|
|
"""472690 changes strictly positive Y only, retaining fourth components."""
|
|
def clear_positive_y(v):
|
|
return (v[0], 0 if v[1] > 0 else v[1], *v[2:])
|
|
return clear_positive_y(velocity), clear_positive_y(acceleration)
|
|
|
|
|
|
def player_material_actions(material_id, elapsed, mode):
|
|
"""Classify bounded branches, without inventing unresolved class callbacks."""
|
|
if elapsed <= 3:
|
|
return ()
|
|
actions = []
|
|
if 120 <= material_id <= 129:
|
|
actions.append('complete160')
|
|
if 110 <= material_id <= 119:
|
|
actions.append('complete164')
|
|
if mode == 0:
|
|
if 60 <= material_id <= 69:
|
|
actions.append('fence_query')
|
|
if material_id == 180:
|
|
actions.append('ladder_query')
|
|
return tuple(actions)
|
|
|
|
|
|
def jimmy_contact_actions(selected, material_id, elapsed, mode, *, gadget7_active=False):
|
|
"""42A660 branch contract; selected -1/3 have no extra gadget behavior."""
|
|
actions = player_material_actions(material_id, elapsed, mode)
|
|
if selected == 7 and gadget7_active:
|
|
actions += ('gadget7_unresolved',)
|
|
return actions
|
|
|
|
|
|
def friction_projection(velocity, angular, coefficient, delta, *,
|
|
support=True, published_speed=0):
|
|
"""47A330 with caller's268 gate; excludes later small-motion suppression.
|
|
|
|
Finite vectors only. Nonzero quick_magnitude gate is represented by any
|
|
nonzero component, not a substitute implementation of imported magnitude.
|
|
Python arithmetic is not an x87 bit-identity oracle. No clamp is added.
|
|
"""
|
|
if published_speed != 0 or not support or not any(velocity[:3]):
|
|
return tuple(velocity), tuple(angular)
|
|
k = coefficient * delta
|
|
return ((velocity[0] - velocity[0]*k, velocity[1],
|
|
velocity[2] - velocity[2]*k, *velocity[3:]),
|
|
tuple(x-x*k for x in angular[:3]) + tuple(angular[3:]))
|
|
|
|
|
|
def landing_phases(previous_support):
|
|
phases = ['root318', 'acceleration278_Y0']
|
|
if not previous_support:
|
|
phases.append('landing37C_noop_for_Jimmy')
|
|
return phases + ['velocity2C4_Y0', 'support21C_true', 'shape34C', 'polygon33C']
|
|
|
|
|
|
def material_identity_report(root):
|
|
"""Original table IDs linked by source chunk metadata, not payload flags.
|
|
|
|
Eligibility is registration+normal only, not evidence a gameplay trajectory
|
|
actually contacts a polygon. Preserve explicit source shape/polygon identity.
|
|
"""
|
|
root = Path(root)
|
|
dll = PE(find_case(root, 'OMT2.dll'))
|
|
if hashlib.sha256(dll.data).hexdigest() != DLL_SHA256:
|
|
raise ValueError('Unsupported original OMT2.dll')
|
|
anchors = []
|
|
for name, va, expected in DLL_SITES:
|
|
if read_va(dll, va, len(bytes.fromhex(expected))).hex() != expected:
|
|
raise ValueError(f'Changed DLL instruction {name}')
|
|
anchors.append(dict(name=name, va=hex(va), file_offset=hex(dll.offset(va-dll.base)), bytes=expected))
|
|
archives = []
|
|
for filename in ('level1b.omt', 'VR04.omt', 'level1.omt'):
|
|
db = Database(find_case(root, 'omt/' + filename))
|
|
# Record the identity's actual table byte offset, separate from payload.
|
|
r = Reader(db.data, db.table_offset)
|
|
id_offsets = {}
|
|
for _ in range(r.count(8)):
|
|
kind = r.take(4).decode('latin1')
|
|
for _ in range(r.count(13)):
|
|
offset = r.position
|
|
identity = r.u32()
|
|
r.take(8)
|
|
r.string()
|
|
id_offsets[kind, identity] = offset
|
|
materials = {e.id: e for e in db.entries if e.type == '3DMa'}
|
|
summaries = {}
|
|
special = []
|
|
for entry in db.entries:
|
|
if entry.type != '3DSh':
|
|
continue
|
|
shape = read_shape(db.payload(entry))
|
|
registered = not entry.name.lower().startswith('nc')
|
|
for index, polygon in enumerate(shape['polygons']):
|
|
link = polygon['material']
|
|
if link is None or link['type'] != '3DMa' or link['id'] not in materials:
|
|
continue
|
|
identity = link['id']
|
|
material = materials[identity]
|
|
item = summaries.setdefault(identity, dict(id=identity, name=material.name,
|
|
table_id_offset=id_offsets['3DMa', identity], payload_offset=material.offset,
|
|
payload_size=material.size, payload_sha256=hashlib.sha256(db.payload(material)).hexdigest(),
|
|
payload_trailing=read_material(db.payload(material))['trailing'],
|
|
polygons=0, registered_polygons=0, potential374_wall_polygons=0))
|
|
item['polygons'] += 1
|
|
item['registered_polygons'] += int(registered)
|
|
wall374 = registered and NORMAL_Y_THRESHOLD < polygon['normal'][1] < -NORMAL_Y_THRESHOLD
|
|
item['potential374_wall_polygons'] += int(wall374)
|
|
if player_material_actions(identity, 4, 0):
|
|
special.append(dict(shape_id=entry.id, shape_name=entry.name,
|
|
shape_payload_offset=entry.offset, polygon_index=index,
|
|
material_id=identity, normal=polygon['normal'], registered=registered,
|
|
potential374_wall=wall374))
|
|
archives.append(dict(name=filename, sha256=hashlib.sha256(db.data).hexdigest(),
|
|
materials=list(summaries.values()), special_polygons=special))
|
|
return dict(dll_sha256=DLL_SHA256, dll_sites=anchors, archives=archives,
|
|
discriminator='signed 3DMa database chunk ID at material+0C->chunk+8; not payload trailing')
|
|
|
|
|
|
def collect(root):
|
|
pe = PE(find_case(Path(root), 'Neutron.exe'))
|
|
if hashlib.sha256(pe.data).hexdigest() != EXE_SHA256:
|
|
raise ValueError('Unsupported original EXE')
|
|
sites = []
|
|
for name, va, expected in SITES:
|
|
actual = read_va(pe, va, len(bytes.fromhex(expected))).hex()
|
|
if actual != expected:
|
|
raise ValueError(f'Changed instruction {name} at {va:#x}')
|
|
sites.append(dict(name=name, va=hex(va), file_offset=hex(pe.offset(va-pe.base)), bytes=actual))
|
|
tables = []
|
|
for owner, table, slot, target in TABLES:
|
|
if struct.unpack('<I', read_va(pe, table+slot, 4))[0] != target:
|
|
raise ValueError(f'Changed {owner} slot{slot:x}')
|
|
tables.append(dict(owner=owner, table=hex(table), slot=hex(slot), target=hex(target),
|
|
file_offset=hex(pe.offset(table+slot-pe.base))))
|
|
bodies = []
|
|
for name, va, length, expected in BODY_HASHES:
|
|
raw = read_va(pe, va, length)
|
|
if hashlib.sha256(raw).hexdigest() != expected:
|
|
raise ValueError(f'Changed callback {name}')
|
|
bodies.append(dict(name=name, va=hex(va), file_offset=hex(pe.offset(va-pe.base)),
|
|
length=length, sha256=expected,
|
|
raw_control_reference=struct.pack('<I', 0x5099E4) in raw))
|
|
return dict(sha256=EXE_SHA256, sites=sites, tables=tables, bodies=bodies,
|
|
material_identity=material_identity_report(root),
|
|
scope='Static guarded source and bounded state fixtures; no original execution.')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('original', type=Path)
|
|
print(json.dumps(collect(parser.parse_args().original), indent=2))
|