Implement Bubble controller, sprite and VR01 body behavior

This commit is contained in:
UnixNight committed 2026-11-02 16:57:54 -05:00
1 parent 9ea578492d
commit 1ae5f4251c
51 files changed
+2811 -54

No files matched your search

+224
View File
@@ -0,0 +1,224 @@
#!/usr/bin/env python3
"""Read-only Bubble body/VR01 coverage and bounded floor-policy projections.
Static evidence and source projections are distinct from the generated copied-code
probe. No original file is changed or executed in place.
"""
from __future__ import annotations
import argparse
from collections import Counter
from dataclasses import dataclass, replace
import hashlib
import json
import math
from pathlib import Path
import struct
import sys
from bubble import f32
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'))
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'levels'))
from omt import Database, read_material, read_shape
from gam import parse
BODIES = (
('vr01_ctor', 0x455ef0, 0x455fd8, '93c98d72b0c8f0da102068beff19f9b8ebb0da58fa6a4d524ae09415f814f088'),
('floor_game', 0x44e030, 0x44e444, '6ae67944afc53bd050279c1e2356c614e8cd534c7a94ef9628bf0bbfd028fe91'),
('base_floor', 0x462520, 0x462647, 'ba8f47f8b62db304821b751872db003d37605031c57423542f8040c9ef9d7e68'),
('lava_enter', 0x42ab00, 0x42ab2a, '06010f1d0ca453459062f8cb0f96caf3fd2c605cee88547315ddee43b051430a'),
('lava_damage', 0x42a8d0, 0x42a918, '88a303b3ae7cca7fc4c3935848077bbaf5393f83ed184b8e042e67803c3c4863'),
('lava_flash', 0x4257d6, 0x425864, '7f239b21895a710aa766c8d4b8213c70d931e785399c01f8ea1fbec66e19f65d'),
('polygon_setter', 0x472580, 0x47258d, 'e7fe0271b3f9cffbde6e23f64ff533a86042f4c063a804430921b7fe1e9e036b'),
('shape_setter', 0x4725c0, 0x4725cd, '4f7a906d71c1d56117bba8c9ccd2d757c1ed9ee09e40e2a3930388b650b4427d'),
)
SITES = (
('player_base_before_owner', 0x43796a, 'e8e166fdff'),
('animated_base_floor', 0x40e0eb, 'e830440500'),
('base_integrates', 0x46253d, 'ff9010020000'),
('base_polygon', 0x46254f, 'ff9238030000'),
('base_game130', 0x46258f, 'ff9530010000'),
('lava_low', 0x44e170, '83fd6e7c32'),
('lava_high', 0x44e175, '83fd777f2d'),
('lava_entry_callback', 0x44e18e, 'ff9098010000'),
('lava_latch_on', 0x44e194, 'c686021e000001'),
('lava_damage_callback', 0x44e19f, 'ff9264010000'),
('lava_leave_callback', 0x44e1bb, 'ff909c010000'),
('lava_latch_off', 0x44e1c1, '889e021e0000'),
('lava_sound35', 0x44e32c, 'c7824c05000023000000'),
('ordinary_sound5', 0x44e407, 'c7824c05000005000000'),
('floor_sound_changed', 0x44e426, 'ff92e4010000'),
('wrapper_flash_late', 0x424c88, 'ff92b4010000'),
('flash_duration4', 0x49d5e8, '00008040'),
('support_polygon_publish', 0x47bba1, 'ff923c030000'),
('support_shape_publish', 0x47bb91, 'ff904c030000'),
('landing_noop', 0x472970, 'c3'),
('grounded_radius160', 0x4246b4, '6800002043'),
('grounded_radius60', 0x4246dc, '6800007042'),
('factor_authored_live', 0x4711e0, '8b4424048b115089412cff9254020000'),
('game_filter_false', 0x475cd0, '32c0c21800'),
('nc_shape_skip', 0x44dd64, '83f86374078b178bcfff522c'),
('checkpoint_filter', 0x4791c7, '5355e8f202000083c40884'),
('game_filter', 0x4791d9, '5355e8c005000083c40884c0740c'),
)
TABLES = (
(0x4cd740, 0x134, 0x475cd0), (0x4cd740, 0x130, 0x44e030),
(0x4a373c, 0x338, 0x472570), (0x4a373c, 0x33c, 0x472580),
(0x4a373c, 0x34c, 0x4725c0), (0x4a373c, 0x37c, 0x472970),
(0x4a3bdc, 0x198, 0x42ab00), (0x4a3bdc, 0x19c, 0x472970),
(0x4a3bdc, 0x164, 0x42a8d0), (0x4a3bdc, 0x1e4, 0x42aec0),
)
def geometry(root, name):
db = Database(find_case(root, 'omt/' + name))
materials = {e.id: e.name for e in db.entries if e.type == '3DMa'}
textures = {e.id: read_material(db.payload(e))['texture'] for e in db.entries if e.type == '3DMa'}
shapes, records = [], []
for entry in sorted((e for e in db.entries if e.type == '3DSh'), key=lambda e: e.id):
shape = read_shape(db.payload(entry))
shapes.append(dict(id=entry.id, name=entry.name, payload_offset=entry.offset,
payload_sha256=hashlib.sha256(db.payload(entry)).hexdigest(),
vertices=len(shape['vertices']), polygons=len(shape['polygons'])))
for index, polygon in enumerate(shape['polygons']):
link = polygon['material']
identity = link['id'] if link and link['type'] == '3DMa' else None
material = materials.get(identity)
registered = not (entry.name or '').lower().startswith('nc') and not (
material and material.lower() in {'cstart', *(f'ccheck{i}' for i in range(1, 10))})
ny = polygon['normal'][1]
records.append(dict(shape=entry.id, polygon=index, corners=len(polygon['corners']),
material=identity, material_name=material, texture=textures.get(identity),
normal=polygon['normal'],
registered=registered, wall=registered and ny < f32(.7),
callback374=registered and f32(-.7) < ny < f32(.7)))
return dict(name=name, sha256=hashlib.sha256(db.data).hexdigest(), shapes=shapes,
polygon_count=len(records), registered=sum(p['registered'] for p in records),
walls=sum(p['wall'] for p in records), polygons=records)
def collect(root):
root = Path(root)
pe = PE(find_case(root, 'Neutron.exe'))
if hashlib.sha256(pe.data).hexdigest() != EXE_SHA256:
raise ValueError('Unsupported original executable')
bodies, sites, tables = [], [], []
for name, start, end, expected in BODIES:
if hashlib.sha256(read_va(pe, start, end-start)).hexdigest() != expected:
raise ValueError('Changed source body ' + name)
bodies.append(dict(name=name, va=hex(start), file_offset=hex(pe.offset(start-pe.base)),
length=end-start, sha256=expected))
for name, va, expected in SITES:
actual = read_va(pe, va, len(bytes.fromhex(expected))).hex()
if actual != expected:
raise ValueError(f'Changed {name} at {va:x}: {actual}')
sites.append(dict(name=name, va=hex(va), file_offset=hex(pe.offset(va-pe.base)), bytes=actual))
for table, slot, target in TABLES:
if struct.unpack('<I', read_va(pe, table+slot, 4))[0] != target:
raise ValueError('Changed virtual binding')
tables.append(dict(table=hex(table), slot=hex(slot), target=hex(target),
file_offset=hex(pe.offset(table+slot-pe.base))))
dll = PE(find_case(root, 'OMT2.dll'))
dll_hash = '3ec41ead011adf56387a6dbd4580e5b5a9721b5f8020c8a56420f42824354943'
if hashlib.sha256(dll.data).hexdigest() != dll_hash:
raise ValueError('Unsupported OMT DLL')
texture_set = '8b44240485c0898180000000'
if read_va(dll, 0x100013b5, len(bytes.fromhex(texture_set))).hex() != texture_set:
raise ValueError('Changed OMT material texture publication')
gam = find_case(root, 'gam/VR01.gam').read_bytes()
return dict(sha256=EXE_SHA256, bodies=bodies, sites=sites, tables=tables,
archives=[geometry(root, name) for name in ('VR01.omt', 'VR04.omt')],
vr01_gam_sha256=hashlib.sha256(gam).hexdigest(),
vr01_entities=dict(Counter(e.kind for e in parse(gam).entities)),
material_texture=dict(dll_sha256=dll_hash, exported_set_texture=hex(0x100013a0),
write_va=hex(0x100013b5), file_offset=hex(dll.offset(0x100013b5-dll.base)), bytes=texture_set),
scope='Static guarded source and bounded projections; isolated original probe is separate.')
@dataclass(frozen=True)
class LavaState:
entered: bool = False
flashing: bool = False
timer: float = 0
sound_selector: int = 5
def floor_phase(state, material, raw_mode, *, eligible=True, integration=True,
polygon_present=True, material_present=True, texture_present=True):
"""462520→44E030 restricted to actualVR01 IDs; excludes other damage flags.
This phase consumes retained338 even if current218=false. Caller preserves
that polygon until next successful support. Energy/score helpers own clamps
and tutorial exemption. Audio requests are distinct from playback evidence.
"""
if material not in (None, 0, 1, 2, 3, 4, 111):
raise ValueError('Outside VR01 floor-policy projection')
if not (eligible and integration and polygon_present and material_present and texture_present):
return state, ()
actions = []
lava = material == 111
if lava:
if not state.entered:
actions += ['sound39']
if raw_mode != 0:
actions += ['sound190']
state = replace(state, entered=True)
if not state.flashing and raw_mode != 0:
state = replace(state, flashing=True, timer=0)
actions += ['energy_minus5_common_helper', 'score_minus5_common_helper', 'cancel_mode1']
elif state.entered:
state = replace(state, entered=False)
selector = 35 if lava else 5
if selector != state.sound_selector:
actions += [f'retarget_existing_floor_loop_{selector}']
return replace(state, sound_selector=selector), tuple(actions)
def lava_flash(state, seconds):
"""4257D6 finite projection, assuming1DED/1E03 false; no x87/fsin parity."""
if not math.isfinite(seconds) or not 0 <= seconds < 1:
raise ValueError('Bounded finite timestep required')
if not state.flashing:
return state, None
#4257E8 compares the unrounded x87 sum before4257EE storesfloat; FSIN
#also consumes that retained sum. Python double models this bounded sum.
total = f32(state.timer) + f32(seconds)
timer = f32(total)
if total > 4:
return replace(state, flashing=False, timer=timer), (1., 1., 1., 1.)
pulse = f32((math.sin(total * 20) + 1) * .5)
return replace(state, timer=timer), (pulse, 1., pulse, 1.)
def generate_probe(output):
"""Reuse the isolated body's synthetic virtuals; no game actor/input/audio."""
source = Path(__file__).with_name('body_step_probe.c').read_text()
marker = ' puts("BODY_COMPONENT_COMPLETE:'
if source.count(marker) != 1:
raise ValueError('Unexpected body fixture source')
extra = ''' b=initial();b.radius=160;b.factor=.415f;b.position.y=66.4f;b.previous=b.position;run("bubble_floor",b,1);
b=initial();b.radius=160;b.factor=.415f;b.position.y=26;b.previous=b.position;run("bubble_spawn",b,1);
b=initial();b.radius=160;b.factor=.415f;run("bubble_equip_no_forced_lowering",b,1);
b=initial();b.position.y=66.4f;b.previous=b.position;run("bubble_cleanup_raise",b,1);
b=initial();b.radius=160;b.factor=.415f;b.position.y=66.4f;b.previous=b.position;b.supported=1;b.velocity.y=300;run("bubble_small_bounce",b,1);
b=initial();b.radius=160;b.factor=.415f;b.position.y=66.4f;b.previous=b.position;b.supported=1;b.velocity.y=900;run("bubble_held_bounce",b,1);
'''
output = Path(output).resolve()
project = Path(__file__).resolve().parents[2]
if output.is_relative_to(project.parent / 'Original'):
raise ValueError('Generated source must be outside originals')
output.write_text(source.replace(marker, extra + marker))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('original', type=Path)
parser.add_argument('--probe-source', type=Path)
args = parser.parse_args()
report = collect(args.original)
if args.probe_source:
generate_probe(args.probe_source)
print(json.dumps(report, indent=2))