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))
|
||||
@@ -0,0 +1,197 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only Invisible gadget source guards and bounded branch projections.
|
||||
|
||||
These projections are independently transcribed static contracts, not execution
|
||||
of original code or a replacement for the port's runtime checks.
|
||||
"""
|
||||
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 = (
|
||||
('invisible_tick', 0x424E80, 0x425114, 'b52f6f643c786206fa5a4089d58b311417439a203e0914a8a0243e319c52ebb3'),
|
||||
('invisible_equip', 0x428E51, 0x428F61, '9abaa12fb4625248564818695c6a7e6d27fccf15216c670e5321a3742aa99bc2'),
|
||||
('invisible_cleanup', 0x42810C, 0x4281B3, '92e9ffe9516cca33159b05d3509dc0e34d839e6c8d3deb7e1cd08adbfbfc2851'),
|
||||
('material_alpha', 0x40E4A0, 0x40E5D9, '741d94d5cf14efd99e5380239d7a1b4be7e7fb5f478590604e8bd76b8e5d1ead'),
|
||||
('indexed_blend', 0x40DD40, 0x40DD5D, 'b14a27765254aba1bb2e420019648ee0f05573567c1d1f79c6d8ab09cc59fdc5'),
|
||||
('meter', 0x4036C0, 0x40385B, '46f35e6db8030b96cd6a0bddaf59cf37d36b41f6b568143856db2184b360ca8b'),
|
||||
('enemy_target_flag', 0x409CC0, 0x409CF7, 'cf6e1c52f5801412ab7012465fd41d0278ddb9aef62002535c829f6e03af9252'),
|
||||
)
|
||||
SITES = (
|
||||
('tick_after_movement', 0x424C31, 20),
|
||||
('tick_control_pointer_not_identity', 0x424E80, 30),
|
||||
('tick_mode_two', 0x424E9E, 12),
|
||||
('tick_show_meter', 0x424EB4, 6),
|
||||
('primary_then_not_jump', 0x424EBA, 26),
|
||||
('primary_suppressor_returns', 0x424ED4, 13),
|
||||
('activation_remaining_exact_zero', 0x424EE1, 19),
|
||||
('activation_recharge_exact_seven_bits', 0x424EF4, 12),
|
||||
('activation_energy_strict_two_or_override', 0x424F00, 33),
|
||||
('activation_fixed_cost_minus_two', 0x424F21, 10),
|
||||
('activation_duration_seven', 0x424F32, 10),
|
||||
('activation_blend_source6_dest1', 0x424F3C, 12),
|
||||
('activation_material_alpha_point7', 0x424F48, 15),
|
||||
('activation_target_flag_false', 0x424F57, 7),
|
||||
('activation_recharge_zero', 0x424F5E, 10),
|
||||
('recharge_only_remaining_zero', 0x424F68, 23),
|
||||
('recharge_energy_positive_or_override', 0x424F7F, 29),
|
||||
('recharge_store_before_meter', 0x424F9C, 54),
|
||||
('recharge_seven_clamp_white', 0x424FD2, 47),
|
||||
('active_strict_positive_before_decrement', 0x425001, 23),
|
||||
('active_decrement_before_meter', 0x425018, 28),
|
||||
('active_expiry_less_or_equal_zero', 0x425064, 19),
|
||||
('expiry_material_reset', 0x425077, 38),
|
||||
('expiry_target_true_red_meter', 0x42509D, 25),
|
||||
('flash_last_three', 0x4250BA, 19),
|
||||
('flash_trunc_remaining_times_five', 0x4250CD, 19),
|
||||
('flash_odd_dest7_even_dest1', 0x4250EA, 38),
|
||||
('equip_energy_positive_or_override', 0x428E51, 40),
|
||||
('equip_mode_two_timers_target_flag', 0x428EB4, 36),
|
||||
('equip_display_before_branch', 0x428D95, 9),
|
||||
('cleanup_target_flag_true_recharge_zero', 0x428125, 21),
|
||||
('cleanup_companion_skip_flag', 0x428144, 20),
|
||||
('cleanup_material_opaque_mode_minus_one', 0x428194, 31),
|
||||
('constructor_timer_zero', 0x4227BE, 15),
|
||||
('constructor_override_false', 0x437650, 6),
|
||||
('postload_override_false', 0x4236C0, 7),
|
||||
('postload_vr_range_override_true', 0x423E44, 45),
|
||||
('enemy_chase_target_flag', 0x40847C, 34),
|
||||
('enemy_acquire_target_flag', 0x40877A, 28),
|
||||
('enemy_lost_target_flag', 0x4087F6, 51),
|
||||
('cam_optional_cleanup_flag', 0x4165B7, 43),
|
||||
('mca_optional_cleanup_flag', 0x43129A, 56),
|
||||
('jimmy438_cleanup', 0x42AE08, 18),
|
||||
('cam_interface_complete_plus_c8', 0x415A60, 6),
|
||||
('cam_property_default_one_register', 0x415C09, 5),
|
||||
('cam_property_default_one_store', 0x415CD5, 6),
|
||||
('cam_deactivateinv_property', 0x415F70, 26),
|
||||
('mca_interface_complete_plus_c8', 0x430930, 6),
|
||||
('mca_property_default_one', 0x430AA0, 10),
|
||||
('mca_deactivateinv_property', 0x430D7E, 26),
|
||||
)
|
||||
VTABLES = (
|
||||
(0x4A3BDC, 0x1C8, 0x424E80), (0x4A3BDC, 0x178, 0x427FF0),
|
||||
(0x4A3BDC, 0xFC, 0x40DD40), (0x4A3BDC, 0x114, 0x40E4A0),
|
||||
(0x48D414, 0x484, 0x4036C0), (0x48D414, 0x488, 0x403700),
|
||||
(0x48D414, 0x48C, 0x403730), (0x48D414, 0x490, 0x4037A0),
|
||||
)
|
||||
CONSTANTS = ((0x48D914, 0.0), (0x48D954, 2.0), (0x48D950, 5.0),
|
||||
(0x48E5A0, 3.0), (0x48E5B8, 7.0), (0x4A3E30, 1/7))
|
||||
|
||||
|
||||
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 original 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]
|
||||
tables = []
|
||||
for base, slot, expected in VTABLES:
|
||||
actual = struct.unpack('<I', read_va(pe, base+slot, 4))[0]
|
||||
if actual != expected:
|
||||
raise ValueError('Changed original virtual binding')
|
||||
tables.append(dict(table=hex(base), slot=hex(slot), target=hex(actual)))
|
||||
constants = []
|
||||
for va, expected in CONSTANTS:
|
||||
actual = struct.unpack('<f', read_va(pe, va, 4))[0]
|
||||
if abs(actual-expected) > 1e-7:
|
||||
raise ValueError('Changed original float constant')
|
||||
constants.append(dict(va=hex(va), file_offset=hex(pe.offset(va-pe.base)), value=actual))
|
||||
if read_va(pe, 0x4EDF10, 14) != b'DeactivateInv\0':
|
||||
raise ValueError('Changed cleanup property identity')
|
||||
return dict(sha256=digest, bodies=bodies, sites=sites, vtables=tables, constants=constants)
|
||||
|
||||
|
||||
def f32(value):
|
||||
return struct.unpack('<f', struct.pack('<f', value))[0]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class State:
|
||||
mode: int = 2
|
||||
remaining: float = 0
|
||||
recharge: float = 0
|
||||
alpha: float = 1
|
||||
blend: str = 'opaque'
|
||||
targetable: bool = True
|
||||
meter_visible: bool = True
|
||||
meter_red: bool = True
|
||||
|
||||
|
||||
def equip(state: State, energy: float, override: bool = False):
|
||||
"""After caller cleanup/UI display2; failed branch changes only raw mode."""
|
||||
if energy <= 0 and not override:
|
||||
return replace(state, mode=-1)
|
||||
return replace(state, mode=2, remaining=0, recharge=0, targetable=True,
|
||||
meter_visible=True, meter_red=True)
|
||||
|
||||
|
||||
def cleanup(state: State):
|
||||
"""Only Jimmy-owned scalar/material/meter leaves; companion cleanup separate."""
|
||||
return replace(state, mode=-1, remaining=7, recharge=0, alpha=1,
|
||||
blend='opaque', targetable=True, meter_visible=False)
|
||||
|
||||
|
||||
def step(state: State, seconds: float, energy: float, *, primary=False,
|
||||
jump=False, suppressed=False, control_present=True, override=False,
|
||||
graphics_alpha=False):
|
||||
"""Source424E80 partial-order projection; return (state, fixed energy delta).
|
||||
|
||||
Uses float stores but does not claim x87 extended-precision equivalence for
|
||||
every bin boundary or reproduce the UI's transient pre-clamp meter sample.
|
||||
"""
|
||||
if not math.isfinite(seconds) or not 0 <= seconds < 1:
|
||||
raise ValueError('seconds must be finite and bounded')
|
||||
if not control_present:
|
||||
return replace(state, meter_visible=False), 0
|
||||
if state.mode != 2:
|
||||
return state, 0
|
||||
state = replace(state, meter_visible=True)
|
||||
delta = 0
|
||||
if primary and not jump:
|
||||
if suppressed:
|
||||
return state, delta
|
||||
if state.remaining == 0 and struct.pack('<f', state.recharge) == b'\0\0\xe0@':
|
||||
if energy <= 2 and not override:
|
||||
return state, delta
|
||||
delta = -2
|
||||
energy = max(0, min(100, f32(energy-2)))
|
||||
state = replace(state, remaining=7, recharge=0, alpha=f32(.7),
|
||||
blend='alpha' if graphics_alpha else 'additive', targetable=False)
|
||||
if state.remaining == 0 and (energy > 0 or override):
|
||||
recharge = f32(state.recharge+seconds)
|
||||
state = replace(state, recharge=min(recharge, 7),
|
||||
meter_red=False if recharge >= 7 else state.meter_red)
|
||||
if state.remaining > 0:
|
||||
remaining = f32(state.remaining-seconds)
|
||||
if remaining <= 0:
|
||||
return replace(state, remaining=0, alpha=1, blend='opaque',
|
||||
targetable=True, meter_red=True), delta
|
||||
blend = state.blend
|
||||
if remaining <= 3:
|
||||
blend = 'alpha' if int(remaining*5) % 2 else 'additive'
|
||||
state = replace(state, remaining=remaining, blend=blend)
|
||||
return state, delta
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cli = argparse.ArgumentParser(description=__doc__)
|
||||
cli.add_argument('original', type=Path)
|
||||
print(json.dumps(collect(cli.parse_args().original), indent=2))
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only guards for shared42A920 energy/warning state; REA evidence is reused."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
|
||||
from checkpoint_script_state import find_case, read_va
|
||||
from pe_inspect import PE
|
||||
|
||||
EXE_SHA256 = 'f5281076e1a2492f2d61f87aae3f4544b6d0f535ebe33f9fbb6f78710fe1aea8'
|
||||
SITES = (
|
||||
('ctor_zero_register', 0x42217E, '33db'),
|
||||
('ctor_clear_warning', 0x422980, '881ddc834f00'),
|
||||
('tutorial_numeric_range', 0x42A92B, '3d313052567c0b3d383052560f8ed5000000'),
|
||||
('empty_sound_before_scalar', 0x42A967, '6a006a506affe80ee00200'),
|
||||
('scalar_store_before_extended_upper_test', 0x42A975, 'd905d4834f00d8442404d915d4834f00d81d6cd94800'),
|
||||
('upper_clamp_clears_warning', 0x42A992, 'c705d4834f000000c842c605dc834f0000'),
|
||||
('low_sound_before_latch', 0x42A9DF, '6a0068b60000006affe893df020083c40cc605dc834f0001'),
|
||||
('strict_rearm', 0x42A9F8, 'd905d4834f00d81d24534900dfe0f6c4417507c605dc834f0000'),
|
||||
('ray_adjust_caller', 0x426F5A, 'e8c1390000'),
|
||||
('invisible_adjust_caller', 0x424F26, 'e8f5590000'),
|
||||
)
|
||||
|
||||
|
||||
def collect(original):
|
||||
pe = PE(find_case(Path(original), 'Neutron.exe'))
|
||||
if hashlib.sha256(pe.data).hexdigest() != EXE_SHA256:
|
||||
raise ValueError('Original EXE identity changed')
|
||||
body = read_va(pe, 0x42A920, 0xF3)
|
||||
digest = hashlib.sha256(body).hexdigest()
|
||||
if digest != '6d6a880fb1b4e39addc588201b7d5bb86c768dbfa3778b35045fc10380c9c5e4':
|
||||
raise ValueError('Changed energy body')
|
||||
sites = []
|
||||
for name, va, expected in SITES:
|
||||
if read_va(pe, va, len(bytes.fromhex(expected))) != bytes.fromhex(expected):
|
||||
raise ValueError('Changed source site: ' + name)
|
||||
sites.append(dict(name=name, va=hex(va), file_offset=hex(pe.offset(va-pe.base)), bytes=expected))
|
||||
constants = {name: struct.unpack('<f', read_va(pe, va, 4))[0] for name, va in
|
||||
(('zero', 0x48D914), ('maximum', 0x48D96C), ('low', 0x4A3E90), ('rearm', 0x495324))}
|
||||
return dict(sha256=EXE_SHA256, body=dict(va='0x42a920', file_offset=hex(pe.offset(0x2A920)),
|
||||
size=len(body), sha256=digest), sites=sites, constants=constants,
|
||||
globals=dict(value='0x4f83d4', warning='0x4f83dc'),
|
||||
rea_evidence='ev_71897af12f4bfa1de946c6f17f3bbed34764fdc84258ce64516c8f1f904b465d')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('original', type=Path)
|
||||
args = parser.parse_args()
|
||||
print(json.dumps(collect(args.original), indent=2))
|
||||
@@ -0,0 +1,205 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only resource/tutorial inventory for Bubble and Invisible follow-up work.
|
||||
|
||||
Reports serialized data and pixel/topology observations, not activation or AI rules.
|
||||
Writes only a caller-selected generated JSON file outside the original tree.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from collections import Counter
|
||||
from dataclasses import asdict
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import sys
|
||||
|
||||
from ase import read_ase
|
||||
from entities import resolve_asset
|
||||
from gam import parse
|
||||
from omt import Database, FormatError, read_canvas, read_shape, write_png
|
||||
from png import read_png
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]/'binary'))
|
||||
from pe_inspect import PE
|
||||
from checkpoint_script_state import read_va
|
||||
|
||||
|
||||
METER_SPANS = (
|
||||
('Neutron.exe', 'meter_init', 0x40174D, 0x40189C, 'cfeb0003633ab684e0a0bc68faf39414ef946fea6a879e983b3277899286323f'),
|
||||
('Neutron.exe', 'sprite_place', 0x402D70, 0x402E2D, '448b8a739fa730ae9d46f4f952b7086e8fd383d6d4ac8c01f56caf0f82bb2704'),
|
||||
('Neutron.exe', 'meter_tint', 0x403730, 0x4037F0, 'cc3172e68a085d9fd2901e93c620002dfc2f9526d22999bbf05a25cc595057a6'),
|
||||
('Neutron.exe', 'meter_percent', 0x4037F0, 0x40385B, '434216bb132d7e1a69fc74fcfd68c9fe5953d1894098dd65aa1c91424926cd2e'),
|
||||
('OMT2.dll', 'canvas_render', 0x10029430, 0x1002959A, '041ce8342d11d4a3f553cdacc66b33381f1eff686b61311afb48bf3b1396c4bb'),
|
||||
('OMT2.dll', 'canvas_update_align', 0x10029870, 0x1002992A, 'cb833afae3132776df9fd123ccad03f713d73d58058f06698b57d8ffb3df0387'),
|
||||
('OMT2.dll', 'canvas_dimensions', 0x10029930, 0x1002998D, 'fb5be6cee77db2a3988a2b6e979dcc0083d48281686f7b855a2119f18783298a'),
|
||||
('OMT2.dll', 'draw_surface', 0x10037AC0, 0x1003818C, 'c76738fe3dfb7556283654a233071be1d68b08aecff277a46535e3a0913d30e3'),
|
||||
)
|
||||
|
||||
|
||||
def meter_code_contract(original: Path) -> dict:
|
||||
"""Guard REA-backed original code; no target code is executed."""
|
||||
expected = {'Neutron.exe': 'f5281076e1a2492f2d61f87aae3f4544b6d0f535ebe33f9fbb6f78710fe1aea8',
|
||||
'OMT2.dll': '3ec41ead011adf56387a6dbd4580e5b5a9721b5f8020c8a56420f42824354943'}
|
||||
images = {name: PE(resolve_asset(original, name)) for name in expected}
|
||||
for name, image in images.items():
|
||||
if digest(image.data) != expected[name]:
|
||||
raise FormatError(f'Unexpected meter source image: {name}')
|
||||
spans = []
|
||||
for name, label, start, end, sha256 in METER_SPANS:
|
||||
image = images[name]
|
||||
if digest(read_va(image, start, end-start)) != sha256:
|
||||
raise FormatError(f'Unexpected source meter span: {label}')
|
||||
spans.append(dict(image=name, label=label, start=hex(start), end=hex(end),
|
||||
fileOffset=image.offset(start-image.base), bytes=end-start, sha256=sha256))
|
||||
exe = images['Neutron.exe']
|
||||
multiplier = struct.unpack('<d', read_va(exe, 0x48D908, 8))[0]
|
||||
if multiplier != 1.04:
|
||||
raise FormatError('Unexpected meter percentage multiplier')
|
||||
return dict(images=expected, guardedSpans=spans, heightMultiplier=multiplier,
|
||||
width=27, backgroundCanvas=21, fillCanvas=22,
|
||||
rawBackgroundPosition=[320, 7], rawFillPosition=[322, 4],
|
||||
layoutPolicy='Modern logical rectangles from source coordinates; cached engine autoalignment scheduling remains open.')
|
||||
|
||||
|
||||
def digest(data: bytes) -> str:
|
||||
return hashlib.sha256(data).hexdigest()
|
||||
|
||||
|
||||
def resource(database: Database, kind: str, identity: int) -> dict:
|
||||
matches = [e for e in database.entries if e.type == kind and e.id == identity]
|
||||
if len(matches) != 1:
|
||||
raise FormatError(f'Expected one {database.path.name}:{kind}:{identity}')
|
||||
entry = matches[0]
|
||||
payload = database.payload(entry)
|
||||
result = dict(archive=database.path.name, archiveSha256=digest(database.data),
|
||||
**asdict(entry), payloadSha256=digest(payload))
|
||||
if kind == 'Canv':
|
||||
canvas = read_canvas(payload)
|
||||
rgba = canvas.pop('rgba')
|
||||
result.update(canvas=canvas, rgbaSha256=digest(rgba),
|
||||
alphaCounts=dict(sorted(Counter(rgba[3::4]).items())))
|
||||
return result
|
||||
|
||||
|
||||
def tutorial(original: Path, name: str) -> dict:
|
||||
source = resolve_asset(original, f'gam/{name}.gam')
|
||||
data = source.read_bytes()
|
||||
level = parse(data)
|
||||
database = Database(resolve_asset(original, f'omt/{name}.omt'))
|
||||
meshes = []
|
||||
for entry in database.entries:
|
||||
if entry.type != '3DSh':
|
||||
continue
|
||||
shape = read_shape(database.payload(entry))
|
||||
vertices = shape['vertices']
|
||||
meshes.append(dict(**asdict(entry), vertices=len(vertices),
|
||||
polygons=len(shape['polygons']),
|
||||
triangles=sum(max(0, len(p['corners'])-2) for p in shape['polygons']),
|
||||
bounds=dict(min=[min(v[i] for v in vertices) for i in range(3)],
|
||||
max=[max(v[i] for v in vertices) for i in range(3)])))
|
||||
# Preserve duplicate tags and literal patrol links; do not silently repair
|
||||
# malformed/missing references or identify distinct actors by tag alone.
|
||||
records = [dict(ordinal=index, kind=e.kind, offset=e.offset,
|
||||
tag=e.values().get('ObjectTag', ''),
|
||||
properties=[asdict(p) for p in e.properties])
|
||||
for index, e in enumerate(level.entities)]
|
||||
tags = Counter(str(r['tag']).casefold() for r in records)
|
||||
return dict(level=level.code, source=f'gam/{source.name}', bytes=len(data),
|
||||
sha256=digest(data), counts=dict(sorted(Counter(e.kind for e in level.entities).items())),
|
||||
duplicateTags={tag: count for tag, count in sorted(tags.items()) if count > 1},
|
||||
archive=database.path.name, archiveSha256=digest(database.data), meshes=meshes,
|
||||
entities=records)
|
||||
|
||||
|
||||
def inspect(original: Path) -> dict:
|
||||
original = original.resolve()
|
||||
screens = Database(resolve_asset(original, 'omt/screens.omt'))
|
||||
retained = Database(resolve_asset(original, 'omt/RetainedSprites.omt'))
|
||||
voice = Database(resolve_asset(original, 'omt/voicepractice.omt'))
|
||||
sounds = Database(resolve_asset(original, 'omt/soundeffects.omt'))
|
||||
texture_source = resolve_asset(original, 'png/jimycarl.png')
|
||||
texture = read_png(texture_source)
|
||||
rgba = texture.pop('rgba')
|
||||
clips = []
|
||||
for stem in ('jimstop', 'jimrun', 'jimbackpedal', 'jimjump', 'jimfall', 'jimfly', 'jimshoot'):
|
||||
source = resolve_asset(original, f'ASE/{stem}.ASE')
|
||||
clip = read_ase(source)
|
||||
clips.append({key: value for key, value in clip.items() if key != 'objects'} | dict(
|
||||
nodes=[dict(name=o['name'], samples=len(o['samples']),
|
||||
times=[s['time'] for s in o['samples']],
|
||||
vertices=len(o['samples'][0]['vertices']),
|
||||
faces=len(o['samples'][0]['faces']),
|
||||
uvs=len(o['samples'][0]['uvs']),
|
||||
textureFaces=len(o['samples'][0]['textureFaces'])) for o in clip['objects']]))
|
||||
return dict(schema=1,
|
||||
policy='Serialized source data and decoded pixels/topology only; no gameplay or AI inference.',
|
||||
resources=[resource(screens, 'Canv', i) for i in (11, 13, 21, 22, 47, 52, 88, 94, 109, 111)]
|
||||
+ [resource(retained, 'Canv', 1)]
|
||||
+ [resource(voice, 'Wave', i) for i in (20, 21, 22, 23, 24, 37, 38)]
|
||||
+ [resource(sounds, 'Wave', i) for i in (2, 3, 106)],
|
||||
jimmyTexture=dict(source=f'png/{texture_source.name}', sha256=digest(texture_source.read_bytes()),
|
||||
**texture, rgbaSha256=digest(rgba), alphaCounts=dict(sorted(Counter(rgba[3::4]).items()))),
|
||||
jimmyClips=clips, meterCode=meter_code_contract(original),
|
||||
levels=[tutorial(original, name) for name in ('VR01', 'VR03')])
|
||||
|
||||
|
||||
def write_report(original: Path, output: Path) -> dict:
|
||||
original, output = original.resolve(), output.resolve()
|
||||
if output.is_relative_to(original) or original.is_relative_to(output):
|
||||
raise ValueError('Output must be separate from the original installation')
|
||||
report = inspect(original)
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
output.write_text(json.dumps(report, indent=2, allow_nan=False)+'\n', encoding='utf-8')
|
||||
return report
|
||||
|
||||
|
||||
def export_meter(original: Path, output: Path) -> dict:
|
||||
"""Export only the two source-bound recharge meter canvases, without tinting.
|
||||
|
||||
Source 401430 binds 4F7CB0/4F8028 to screens.omt21/22. Gameplay controls
|
||||
visibility/percent/tint; output does not bake those changes into the pixels.
|
||||
"""
|
||||
original, output = original.resolve(), output.resolve()
|
||||
if output.is_relative_to(original) or original.is_relative_to(output):
|
||||
raise ValueError('Output must be separate from the original installation')
|
||||
database = Database(resolve_asset(original, 'omt/screens.omt'))
|
||||
recovered = []
|
||||
for identity, expected in ((21, 'meter'), (22, 'metercolor')):
|
||||
record = resource(database, 'Canv', identity)
|
||||
if record['name'] != expected or (record['canvas']['width'], record['canvas']['height']) != (30, 110):
|
||||
raise FormatError(f'Unexpected source meter canvas {identity}')
|
||||
entry = next(e for e in database.entries if e.type == 'Canv' and e.id == identity)
|
||||
canvas = read_canvas(database.payload(entry))
|
||||
recovered.append((record, canvas['rgba']))
|
||||
# Validate both identities before producing any generated files.
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
textures = []
|
||||
for record, rgba in recovered:
|
||||
name = f"canvas_{record['id']}"
|
||||
(output/(name+'.rgba')).write_bytes(rgba)
|
||||
write_png(output/(name+'.png'), 30, 110, rgba)
|
||||
textures.append(dict(id=record['id'], name=record['name'], width=30, height=110,
|
||||
path=name+'.rgba', png=name+'.png', sourceOffset=record['offset'],
|
||||
sourceBytes=record['size'], sourceSha256=record['payloadSha256'], rgbaSha256=record['rgbaSha256']))
|
||||
manifest = dict(schema=1, referenceWidth=640, referenceHeight=480,
|
||||
source=database.path.name, sourceSha256=digest(database.data), textures=textures)
|
||||
(output/'meter.json').write_text(json.dumps(manifest, indent=2)+'\n', encoding='utf-8')
|
||||
return manifest
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('original', type=Path)
|
||||
parser.add_argument('--output', type=Path, required=True)
|
||||
parser.add_argument('--meter-output', type=Path, help='Optional separate generated meter texture directory')
|
||||
args = parser.parse_args()
|
||||
report = write_report(args.original, args.output)
|
||||
if args.meter_output:
|
||||
export_meter(args.original, args.meter_output)
|
||||
print(f"{len(report['resources'])} resource identities, {len(report['jimmyClips'])} Jimmy clips, two tutorials: {args.output}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -11,6 +11,7 @@ from entities import prepare_entities
|
||||
from models import prepare_models
|
||||
from ui import export_ui
|
||||
from gadget_resources import export_gadget_resources
|
||||
from gadget_followup_assets import export_meter
|
||||
from sound_bank import export_sound_bank
|
||||
|
||||
|
||||
@@ -80,6 +81,7 @@ def main():
|
||||
(args.output/'scene-catalog.json').write_text(json.dumps(catalog, indent=2)+'\n')
|
||||
export_ui(Database(find_archive(args.original, 'screens')), args.output / 'ui', Database(args.original / 'alpha.omt'))
|
||||
export_gadget_resources(Database(find_archive(args.original, 'screens')), args.output / 'gadgets')
|
||||
export_meter(args.original, args.output / 'invisible-meter')
|
||||
effects = export_sound_bank(args.original, args.output / 'effects')
|
||||
print(f"SoundEffects.omt: {len(effects['resources'])} original sound identities")
|
||||
for name in args.audio:
|
||||
|
||||
Reference in new issue
Block a user