Implement timed Invisible gadget and shared energy warnings
This commit is contained in:
1 parent
3527d33810
commit
1897dd2b90
44 files changed
+2466
-39
No files matched your search
@@ -0,0 +1,156 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only Bubble gadget contract and bounded source-state projections.
|
||||
|
||||
REA inspected generated EXE copies; these projections are not original execution.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import argparse
|
||||
from dataclasses import dataclass, replace
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
import struct
|
||||
|
||||
from checkpoint_script_state import EXE_SHA256, find_case, read_va
|
||||
from pe_inspect import PE
|
||||
|
||||
BODIES = (
|
||||
('constructor', 0x410840, 0x410a0f, '60f84d3037031e7bdb4eff676c99b8f14337114086812d90f9cdf6cc512e3c52'),
|
||||
('bind', 0x410a80, 0x410ad1, '568468bd5cbd82fe5f4c3d54919b27c3cf6f4c472467102bcd0aae4f97f33f92'),
|
||||
('animate', 0x410ae0, 0x410c9e, '2d2fce6259a34254dec6b9e6a6302150f58c79d19771861fcadb26e8eda38c60'),
|
||||
('start', 0x410ca0, 0x410cf3, '238c7652a9d6237c6897a74e1c9757b15a063abf017f6e5225d25a75798b0fa3'),
|
||||
('stop', 0x410d00, 0x410d16, 'a551ba8c995dfd11db00c5d25f8502101a7bd05928a22781b0fd9f45e0d799c8'),
|
||||
('equip', 0x428f61, 0x4290b7, '0d56551646c616094d7550de24600475b2593160234111bb76fe2a434893862c'),
|
||||
('cleanup', 0x427ff0, 0x4280cc, 'd81b941f45247d8fc3c7652bc64d06e9c503d699d1a1820c5fab4ffad4e56bf9'),
|
||||
('active_input', 0x426264, 0x4263ef, '77de32b45f3808ccd7ec76304d74c82b09cc7ee831a6b7553e3fe68c72296715'),
|
||||
('ordinary_fire_gate', 0x42668f, 0x4266b9, 'd88cb837b49acc11f3a779f71b3f361ed27c634532aa3808081cf4a2438ee6b3'),
|
||||
('effect_callbacks', 0x42a870, 0x42a91a, 'eb20ec6524bf2a54bf45ea781f0cb0d6bc03f3c729f5dbd4097810d5c9b21fa2'),
|
||||
('supported_radius', 0x42469b, 0x4246e9, '40e025e4bdc8bcdbcb24651e3d81908a5b7a9e2cc8de81d733da7490ea76c1d4'),
|
||||
('movement_dispatch', 0x438b1e, 0x438ba4, 'a18e41a473e0975ae79c2d328ec323d7c87d77722a6a43a785bbc3fe92a58743'),
|
||||
)
|
||||
SITES = (
|
||||
('owned_bubble_ctor', 0x42232c, 5), ('owned_bubble_field', 0x42233c, 6),
|
||||
('sprite_archive', 0x410919, 5), ('sprite_canvas1', 0x41094a, 7),
|
||||
('radius160', 0x429049, 13), ('factor0415', 0x429058, 13),
|
||||
('mode0', 0x429065, 7), ('movement2', 0x429072, 9), ('max1350', 0x42907b, 10),
|
||||
('start_effect', 0x429085, 5), ('loop_sound2', 0x429093, 11),
|
||||
('practice_vr01', 0x428fca, 5), ('energy_gate', 0x428fda, 25),
|
||||
('exempt_flag', 0x428fed, 8), ('active_guard', 0x429013, 14),
|
||||
('collapse_guard', 0x429021, 14), ('expand_guard', 0x42902f, 14),
|
||||
('cleanup_mode0', 0x428030, 7), ('cleanup_timer05', 0x428045, 10),
|
||||
('cleanup_movement0', 0x42804f, 7), ('cleanup_max650', 0x428056, 10),
|
||||
('cleanup_stop', 0x428060, 5), ('cleanup_clear_expand', 0x42806b, 6),
|
||||
('cleanup_stop_loop', 0x42807c, 7), ('cleanup_radius60', 0x42809c, 13),
|
||||
('cleanup_factor1265', 0x4280ab, 13), ('cleanup_mode_minus1', 0x4280bb, 9),
|
||||
('input_mode2', 0x426264, 14), ('input_drain', 0x426272, 19),
|
||||
('input_empty_cleanup', 0x426285, 32), ('position_y100', 0x4262f2, 6),
|
||||
('position_distance80', 0x42637a, 6), ('position_y50', 0x426399, 6),
|
||||
('fire_mode0_reject', 0x4266ac, 13), ('effect_pulse30', 0x410b5a, 6),
|
||||
('expand_strict1', 0x410b95, 29), ('collapse_strict0', 0x410c1e, 13),
|
||||
)
|
||||
VTABLES = ((0x4a3bdc, 0x174, 0x428d50), (0x4a3bdc, 0x178, 0x427ff0),
|
||||
(0x49250c, 0x3c4, 0x410ae0), (0x49250c, 0x110, 0x471240),
|
||||
(0x49250c, 0x100, 0x4711e0), (0x4a3bdc, 0x128, 0x439900))
|
||||
|
||||
|
||||
def collect(original: Path | str):
|
||||
pe = PE(find_case(Path(original), 'Neutron.exe'))
|
||||
digest = hashlib.sha256(pe.data).hexdigest()
|
||||
if digest != EXE_SHA256:
|
||||
raise ValueError('Unexpected original EXE identity')
|
||||
bodies = []
|
||||
for name, start, end, expected in BODIES:
|
||||
actual = hashlib.sha256(read_va(pe, start, end-start)).hexdigest()
|
||||
if actual != expected:
|
||||
raise ValueError(f'Changed source span {name}')
|
||||
bodies.append(dict(name=name, va=hex(start), file_offset=hex(pe.offset(start-pe.base)),
|
||||
length=end-start, sha256=actual))
|
||||
sites = [dict(name=name, va=hex(va), file_offset=hex(pe.offset(va-pe.base)),
|
||||
bytes=read_va(pe, va, length).hex()) for name, va, length in SITES]
|
||||
for base, slot, expected in VTABLES:
|
||||
if struct.unpack('<I', read_va(pe,base+slot,4))[0] != expected:
|
||||
raise ValueError(f'Changed virtual {base:x}+{slot:x}')
|
||||
if read_va(pe,0x4ed838,len(b'RetainedSprites.omt\0')) != b'RetainedSprites.omt\0':
|
||||
raise ValueError('Changed Bubble archive identity')
|
||||
return dict(sha256=digest,bodies=bodies,sites=sites,
|
||||
vtables=[dict(table=hex(b),slot=hex(s),target=hex(t)) for b,s,t in VTABLES],
|
||||
archive='RetainedSprites.omt',canvas=1,
|
||||
equip=dict(raw_mode=0,movement_mode=2,radius=160,factor=f32(.415),max_speed=1350,loop_sound=2),
|
||||
cleanup=dict(raw_mode=-1,movement_mode=0,radius=60,factor=f32(1.265),max_speed=650))
|
||||
|
||||
|
||||
def f32(value):
|
||||
return struct.unpack('<f',struct.pack('<f',value))[0]
|
||||
|
||||
|
||||
def equip_result(energy: float, *, exists=True, practice=False, exempt=False,
|
||||
active=False, expanding=False, collapsing=False):
|
||||
"""428F61 branch after the panel's eligibility/cleanup caller, not full equip."""
|
||||
if not math.isfinite(energy):
|
||||
raise ValueError('Finite source energy required')
|
||||
if not exists:
|
||||
return 'no_effect'
|
||||
if practice:
|
||||
return 'practice_VR01'
|
||||
if energy <= 0 and not exempt:
|
||||
return 'mode_minus1'
|
||||
if active or expanding or collapsing:
|
||||
return 'unchanged'
|
||||
return 'equip_mode0_movement2'
|
||||
|
||||
|
||||
def energy_delta(movement_mode: int, seconds: float):
|
||||
"""426264..426280; common42A920 owns VR exemptions/clamp/warning audio."""
|
||||
if not math.isfinite(seconds) or not 0 <= seconds < 1:
|
||||
raise ValueError('Bounded finite timestep required')
|
||||
return f32(f32(seconds) * f32(-.5)) if movement_mode == 2 else 0.0
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class BubbleVisual:
|
||||
timer: float = 0.0
|
||||
scalar: float = 0.0
|
||||
active: bool = False
|
||||
expanding: bool = False
|
||||
collapsing: bool = False
|
||||
hidden: bool = True
|
||||
rgba: tuple = (1.0,1.0,1.0,1.0)
|
||||
width: float = 200.0
|
||||
height: float = 200.0
|
||||
|
||||
|
||||
def start(state: BubbleVisual):
|
||||
#410CA0 does not clear active/collapsing; equip explicitly guards those states.
|
||||
return replace(state,timer=0,expanding=True,hidden=False)
|
||||
|
||||
|
||||
def stop(state: BubbleVisual, *, through_jimmy_cleanup=True):
|
||||
#410D00 alone leaves expanding unchanged;427FF0 separately clears it.
|
||||
return replace(state,timer=0,active=False,collapsing=True,
|
||||
expanding=False if through_jimmy_cleanup else state.expanding)
|
||||
|
||||
|
||||
def visual_step(state: BubbleVisual, seconds: float, *, graphics_alpha=False):
|
||||
"""Bounded410AE0 projection, not x87/fsin bit parity or an original runtime probe."""
|
||||
if not math.isfinite(seconds) or not 0 <= seconds < 1:
|
||||
raise ValueError('Bounded finite timestep required')
|
||||
timer=f32(state.timer+f32(seconds))
|
||||
state=replace(state,timer=timer)
|
||||
if state.active:
|
||||
rgba=(1.,1.,1.,.5) if graphics_alpha else state.rgba
|
||||
return replace(state,width=240.,height=f32(240+math.sin(timer*10)*30),rgba=rgba)
|
||||
if state.expanding:
|
||||
scalar=1. if timer>1. else timer
|
||||
return replace(state,scalar=scalar,active=timer>1.,expanding=timer<=1.,rgba=(scalar,)*4)
|
||||
if state.collapsing:
|
||||
scalar=f32(1.-timer)
|
||||
return replace(state,scalar=max(0.,scalar),collapsing=scalar>=0.,
|
||||
hidden=state.hidden or scalar<0.,rgba=(max(0.,scalar),)*4)
|
||||
return state
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cli=argparse.ArgumentParser(description=__doc__)
|
||||
cli.add_argument('original',type=Path)
|
||||
print(json.dumps(collect(cli.parse_args().original),indent=2))
|
||||
Reference in new issue
Block a user