Reconstruct lab story, interactions, patrol and jet pack practice flow

This commit is contained in:
UnixNight committed 2026-10-24 20:33:03 -04:00
1 parent 58424120bb
commit c929f942e1
84 files changed
+7957 -305

No files matched your search

+173
View File
@@ -0,0 +1,173 @@
#!/usr/bin/env python3
"""Read-only original collision/pivot evidence checks; executes no original code.
Run from GamePort: python3 tools/binary/collision_evidence.py
Outputs bounded JSON facts from the original PE, GAM, OMT and standing ASE bytes.
"""
from pathlib import Path
import collections
import hashlib
import json
import math
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'))
sys.path.insert(0, str(PROJECT / 'tools/extractors'))
from pe_inspect import PE
from rtti_map import rtti_map
from gam import parse
from omt import Database, read_shape
def f32(value):
return struct.unpack('<f', struct.pack('<f', value))[0]
def fingerprint(data):
value = 2166136261
for byte in data:
value = ((value ^ byte) * 16777619) & 0xffffffff
return f'{value:08x}'
def main():
originals = PROJECT.parent / 'Original'
pe = PE(originals / 'Neutron.exe')
omt_pe = PE(originals / 'OMT2.dll')
# These assertions guard the decisive instructions against source mismatch.
sequences = {
'jimmy_postload_radius60_push': (0x4236a3, '6800007042'),
'jimmy_postload_support_factor_push': (0x4236b3, '6885eba13f'),
'grounded_gadget0_radius160_push': (0x4246b4, '6800002043'),
'grounded_other_radius60_push': (0x4246dc, '6800007042'),
'support_radius_getter': (0x47b8b0, 'ff9060020000'),
'support_factor_getter': (0x47b8be, 'ff9250020000'),
'support_radius_factor_multiply': (0x47b8c8, 'd84c2420'),
'support_hit_height_plus_clearance': (0x47bae1, 'd90564fc5c00d8442408'),
'support_set_grounded': (0x47bb7c, '6a018bceff921c020000'),
'null_polygon_material_returns_false': (0x4794e8, '8b460485c00f8495020000'),
'ai_support_factor_point3_push': (0x407b2b, '689a99993e'),
'goddard_postload_radius130_push': (0x41e64a, '6800000243'),
'support_clearance_threshold_reference': (0x47ba48, 'd81d20d94800'),
'support_prevent_lowering_root_compare': (0x47bafd, 'd9442410d85c2408'),
'support_prevent_lowering_reject_above': (0x47bb0a, '0f8497000000'),
'ray_one_sided_flag': (0x469c7e, '8a842480000000'),
'ray_one_sided_reject': (0x469c85, '84c00f8491010000'),
'ray_negative_distance_reject': (0x469ddd, '753f'),
'ray_strict_endpoint_reject': (0x469dee, '752e'),
'physics_capture_previous_grounded': (0x479d2e, 'ff9018020000'),
'physics_clear_current_grounded': (0x479d4e, 'ff901c020000'),
'physics_support_after_motion_call': (0x47a235, 'e856160000'),
}
for label, (va, expected) in sequences.items():
offset = pe.offset(va - pe.base)
actual = pe.data[offset:offset + len(expected) // 2].hex()
if actual != expected:
raise ValueError(f'{label} instruction mismatch at {va:#x}: {actual}')
dll_sequences = {
'quick_magnitude_ratio_scale': (0x10020027, 'd80d54481110'),
'quick_magnitude_angle_lookup': (0x10020041, '668b1445381e1610'),
'quick_magnitude_sine_lookup': (0x1002004f, 'd83495301e1410'),
'sine_initializer_step': (0x100edc21, 'dc0dc0661110'),
'angle_initializer_step': (0x100edc90, 'dc0d88451110'),
}
for label, (va, expected) in dll_sequences.items():
offset = omt_pe.offset(va - omt_pe.base)
actual = omt_pe.data[offset:offset + len(expected) // 2].hex()
if actual != expected:
raise ValueError(f'{label} instruction mismatch at {va:#x}: {actual}')
threshold = struct.unpack_from('<f', pe.data, pe.offset(0x48d920 - pe.base))[0]
assert threshold == f32(0.1)
sine = [struct.pack('<f', math.sin(i * 0.0003834951969604492)) for i in range(16384)]
for index, value in [(0, 0), (8192, 0), (4096, 1), (12288, -1)]:
sine[index] = struct.pack('<f', value)
angles = [struct.pack('<H', int(math.acos(i * 0.0001220703125 - 1) * 2607.5945876921437 * 0.5))
for i in range(16384)]
sine_hash, angle_hash = fingerprint(b''.join(sine)), fingerprint(b''.join(angles))
# Actual original-DLL tables observed in copied-install mode2 probe2026-10-24.
assert (sine_hash, angle_hash) == ('431383b5', '4f800433')
slot_offsets = [0x100, 0x110, 0x208, 0x210, 0x250, 0x254, 0x260, 0x264,
0x2e0, 0x2e8, 0x310, 0x318, 0x40c]
interface_vtable = 0x4a373c
slots = {hex(slot): hex(pe.u32(pe.offset(interface_vtable + slot - pe.base)))
for slot in slot_offsets}
game_acceptance = {}
for cls in ['CJimmyGame', 'CLevel01BGame']:
tables = rtti_map(pe, cls)['vtables']
complete = next(t for t in tables if t['object_displacement'] == '0x0')
game_acceptance[cls] = next(m['va'] for m in complete['methods'] if m['slot'] == '0x134')
# Object conversion mode references are only collected, not executed.
mode_va = 0x1013d6cc
mode_refs = [hex(omt_pe.va(m.start())) for m in re.finditer(
re.escape(struct.pack('<I', mode_va)), omt_pe.data)]
source = (originals / 'ASE/jimstop.ase').read_text(encoding='latin-1')
count = int(re.search(r'\*MESH_NUMVERTEX\s+(\d+)', source)[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.]+)', source)[:count]]
low = [min(p[i] for p in points) for i in range(3)]
high = [max(p[i] for p in points) for i in range(3)]
level = parse((originals / 'gam/level1b.gam').read_bytes())
start = next(e.values() for e in level.entities if e.kind == '3JIM')
x, z = start['PositionX'], start['PositionZ']
scene = Database(originals / 'omt/level1b.omt')
materials = {e.id: e.name for e in scene.entries if e.type == '3DMa'}
triangles = unresolved = excluded = 0
hits = []
checkpoint_names = {'cstart', *(f'ccheck{i}' for i in range(1, 10))}
for entry in scene.entries:
if entry.type != '3DSh':
continue
shape = read_shape(scene.payload(entry))
for index, polygon in enumerate(shape['polygons']):
triangles += len(polygon['corners']) - 2
material_id = polygon['material']['id'] if polygon['material'] else None
unresolved += int(material_id not in materials) * (len(polygon['corners']) - 2)
excluded += int(materials.get(material_id) in checkpoint_names) * (len(polygon['corners']) - 2)
a, b, c = (shape['vertices'][p['vertex']] for p in polygon['corners'][:3])
denominator = (b[2]-c[2])*(a[0]-c[0]) + (c[0]-b[0])*(a[2]-c[2])
if abs(denominator) < 1e-8:
continue
u = ((b[2]-c[2])*(x-c[0]) + (c[0]-b[0])*(z-c[2])) / denominator
v = ((c[2]-a[2])*(x-c[0]) + (a[0]-c[0])*(z-c[2])) / denominator
if min(u, v, 1-u-v) < -1e-5:
continue
hits.append(dict(y=u*a[1]+v*b[1]+(1-u-v)*c[1], shape=entry.name,
shape_id=entry.id, polygon=index, normal=polygon['normal'],
material=material_id))
factor = struct.unpack('<f', bytes.fromhex('85eba13f'))[0]
clearance = f32(60 * factor)
floor = max(h['y'] for h in hits if h['y'] <= start['PositionY'])
result = dict(
source_sha256=hashlib.sha256(pe.data).hexdigest(),
verified_instruction_sequences=len(sequences) + len(dll_sequences),
jimmy_interface_vtable=hex(interface_vtable), interface_slots=slots,
scene_acceptance_slot134=game_acceptance,
jimmy_postload=dict(radius=60, support_factor=factor,
flat_floor_clearance=clearance,
predicted_flat_root_y=floor+clearance,
raw_sole_above_flat_floor=clearance+low[1]),
goddard_postload=dict(radius=130, inherited_ai_support_factor=f32(0.3), flat_floor_clearance=f32(130 * f32(0.3))),
support_ray_factor_threshold=threshold,
regenerated_math_table_fingerprints=dict(sine=sine_hash, half_acos=angle_hash,
reference='Recorded isolated copied-DLL execution2026-10-24; no original code executed by this script'),
standing_ase=dict(vertex_count=count, min=low, max=high,
geomobjects=len(re.findall(r'\*GEOMOBJECT\s*\{', source)),
groups=len(re.findall(r'\*GROUP\s', source)),
tm_animation='*TM_ANIMATION' in source),
object_conversion_mode_address=hex(mode_va), object_mode_references=mode_refs,
lab=dict(triangles=triangles, unresolved_material_triangles=unresolved,
checkpoint_material_triangles=excluded,
has_collision_counts=dict(collections.Counter(
str(e.values()['HasCollision']) for e in level.entities if 'HasCollision' in e.values())),
spawn_vertical_hits=sorted(hits, key=lambda h: h['y'])),
limitation='Static arithmetic/data evidence; no original code executed; model pivot and full solver fidelity remain unverified.')
print(json.dumps(result, indent=2))
if __name__ == '__main__':
main()