189 lines
8.1 KiB
Python
189 lines
8.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Guarded Grappler evidence and isolated scalar projections, no target execution.
|
|
|
|
The projections omit ray traversal, Euler/table precision, body dispatch and
|
|
camera scheduling. They are not a live gadget or original-runtime oracle.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
from dataclasses import dataclass
|
|
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 = (
|
|
('cursor_owner', 0x42255b, 0x4225a0, '86c2500c8105768c3568faacb4001b3713639806c68961e6af00411b4388789c'),
|
|
('rope_owner', 0x4227fc, 0x422831, '53178e76063eb6400f277b91a63a38ebd6d65f1e0e73af86bf5ca99e5f4b82d4'),
|
|
('constructor_globals', 0x422761, 0x4227be, 'e914d43a038f8f4e99996a58f9cb9041c691b6a412ef64ed2a7c7a0357d1a091'),
|
|
('update_gate', 0x426030, 0x4260a6, 'bf3bcca296c7fc5d3c7dd5e79bdd9311b5fcee7606842978346706dbdab9d1b7'),
|
|
('primary_order', 0x42668f, 0x4266e9, '7774c6cb2aa7d6784bb0c74490c6f67ac9b96c9724dca9f4f2856519103bf320'),
|
|
('fire_attach', 0x426a70, 0x426e35, 'b4f77baf95e5f3b2b9cb07c58b3fa771d064ac2720346e1e04c90bad7aea76ac'),
|
|
('cleanup', 0x4287ac, 0x42882f, 'e59ec9d7f88f250552ca090897899be125dbf4b3b6194106755646d7d4b689ca'),
|
|
('equip', 0x4297dd, 0x4298bf, '77ddf32d73f9b387f2d4375e4f7c16c893ae5452eef1f57fd24d4ff0b52e50a5'),
|
|
('detach', 0x429c10, 0x429cf7, 'aad9706ec19de0d162827fe957e91fb4a513423d6e6901de9a29e4c780f7df97'),
|
|
('swing', 0x429d00, 0x42a660, '9f4f17bafbca614ee64094df4d951c53cb122f8e15adb9fd7f8a58be589cc2f3'),
|
|
('collision', 0x42a660, 0x42a714, 'd52831057c35afbdb73babff81857a6a3cfb2466f639b8be0a80e6300d386b0c'),
|
|
('jump_predicate', 0x42a730, 0x42a7a0, '8a736de3111c9c803d0748e2d3a385fda2156894467a335a3e5e55df7fa046e2'),
|
|
)
|
|
CONSTANTS = (
|
|
(0x48d96c, 'f', 100.), (0x4a3e58, 'f', 250.),
|
|
(0x4a3e5c, 'f', 0.0016666667070239782),
|
|
(0x4a3e64, 'f', 0.9599999785423279),
|
|
(0x4a3e68, 'f', 450.), (0x4a3e6c, 'f', 0.20000000298023224),
|
|
(0x4a3e70, 'f', 0.9800000190734863),
|
|
(0x4a3e74, 'f', 0.949999988079071), (0x4a3e78, 'f', -50.),
|
|
(0x4a3e80, 'd', .17), (0x4a3e88, 'f', 950.),
|
|
(0x4a3e8c, 'f', 116.), (0x4a2ad0, 'd', .2),
|
|
(0x49fae4, 'f', 350.), (0x48d400, 'f', 50.),
|
|
(0x49d5b4, 'f', 60.),
|
|
)
|
|
|
|
|
|
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), end_va=hex(end),
|
|
file_offset=hex(pe.offset(start-pe.base)), sha256=actual))
|
|
virtuals = ((0x188, 0x429d00), (0x1c0, 0x426a70), (0x204, 0x429c10))
|
|
for slot, expected in virtuals:
|
|
if struct.unpack('<I', read_va(pe, 0x4a3bdc+slot, 4))[0] != expected:
|
|
raise ValueError(f'Changed Jimmy virtual {slot:x}')
|
|
for va, fmt, value in CONSTANTS:
|
|
if struct.unpack('<'+fmt, read_va(pe, va, struct.calcsize(fmt)))[0] != value:
|
|
raise ValueError(f'Changed constant {va:x}')
|
|
for va, expected in ((0x4298e8+8*4, 0x4297dd), (0x428844+7*4, 0x4287ac)):
|
|
if struct.unpack('<I', read_va(pe, va, 4))[0] != expected:
|
|
raise ValueError('Changed Grappler dispatcher')
|
|
for va, value in ((0x4ef010, b'C3DGraplingHook'), (0x4ef03c, b'C3DTargetCursor'),
|
|
(0x4ef3e8, b'FALL'), (0x4ef6d8, b'SWING')):
|
|
if read_va(pe, va, len(value)+1) != value+b'\0':
|
|
raise ValueError(f'Changed source string {va:x}')
|
|
return dict(sha256=digest, bodies=bodies,
|
|
virtuals=[dict(table='0x4a3bdc', slot=hex(s), target=hex(t)) for s,t in virtuals],
|
|
constants=[dict(va=hex(a), format=f, value=v) for a,f,v in CONSTANTS],
|
|
item=7, raw_mode=7, practice='vr08.gam',
|
|
aim_local_point=[0,2400,2400], anchor_global='0x4f8214',
|
|
attached_global='0x4f8210', index_global='0x4f82cc',
|
|
model_scope='isolated scalar projections; no live or original-runtime claim')
|
|
|
|
|
|
def f32(value):
|
|
return struct.unpack('<f', struct.pack('<f', value))[0]
|
|
|
|
|
|
def finite(*values):
|
|
if not all(math.isfinite(v) for v in values):
|
|
raise ValueError('Finite inputs required')
|
|
|
|
|
|
def material_blocks_aim(material_id: int, *, polygon=True,
|
|
material_present=True, definition_present=True):
|
|
"""42A497..42A4E7 after successful ray and distance>=450.
|
|
|
|
Missing selected polygon passes this material check; present polygon without
|
|
material blocks. A present material without definition passes. This predicate
|
|
does not reproduce ray admission or the enclosing helper's return value.
|
|
"""
|
|
if not polygon:
|
|
return False
|
|
if not material_present:
|
|
return True
|
|
if not definition_present:
|
|
return False
|
|
return (60 <= material_id <= 69 or 80 <= material_id <= 89 or
|
|
210 <= material_id <= 219 or material_id in (-1, 170))
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class AttachmentScalars:
|
|
length: float
|
|
initial_length: float
|
|
scale_z: float | None
|
|
reel_target: float
|
|
velocity: tuple[float, float, float]
|
|
|
|
|
|
def attach_scalars(root, hit, velocity=(0.,0.,0.), *, initial_length=0.):
|
|
"""426BE8..426D85 accepted hit; no clamping or negative-length repair.
|
|
|
|
Host sqrt and explicit float stores are a bounded arithmetic projection,
|
|
not a bit-exact x87 execution oracle. Initial scale is assigned only when
|
|
global4F82B4 is zero; unequip/detach do not clear that global.
|
|
"""
|
|
if len(root) != 3 or len(hit) != 3 or len(velocity) != 3:
|
|
raise ValueError('Three-vectors required')
|
|
finite(*root, *hit, *velocity, initial_length)
|
|
length = f32(math.sqrt(sum((a-b)**2 for a,b in zip(hit,root)))-100.)
|
|
scale = f32(length*f32(1/600)) if initial_length == 0. else None
|
|
return AttachmentScalars(length, length if initial_length == 0. else initial_length,
|
|
scale, f32(hit[1]-root[1]-200.),
|
|
(velocity[0],100.,velocity[2]))
|
|
|
|
|
|
def held_reel(length, dt):
|
|
"""426DAC..426DFD: strict old length>250, no final minimum clamp."""
|
|
finite(length, dt)
|
|
if dt < 0:
|
|
raise ValueError('Nonnegative dt required')
|
|
return f32(length-dt*250.) if length > 250. else length
|
|
|
|
|
|
def fast_reel(length, target, dt):
|
|
"""429DCB..429DE8: target<length, no final target clamp."""
|
|
finite(length, target, dt)
|
|
if dt < 0:
|
|
raise ValueError('Nonnegative dt required')
|
|
return f32(length-dt*950.) if target < length else length
|
|
|
|
|
|
def swing_scalars(x, z, timer, dt, rope_offset_x, rope_offset_z, length):
|
|
"""42A077..42A198 after body dispatch, no position/collision emulation.
|
|
|
|
Accumulate elapsed dt; subtract constrained rope offset*dt*.17; at elapsed>=double .2,
|
|
clamp50, multiply .95/.98, then subtract float .2 ONCE (not a loop).
|
|
"""
|
|
finite(x,z,timer,dt,rope_offset_x,rope_offset_z,length)
|
|
if dt < 0:
|
|
raise ValueError('Nonnegative dt required')
|
|
timer = f32(timer+dt)
|
|
x = f32(x-rope_offset_x*dt*.17)
|
|
z = f32(z-rope_offset_z*dt*.17)
|
|
if timer >= .2:
|
|
gain = f32(.95 if length < 350. else .98)
|
|
x = f32(max(-50., min(50., x))*gain)
|
|
z = f32(max(-50., min(50., z))*gain)
|
|
timer = f32(timer-f32(.2))
|
|
return x,z,timer
|
|
|
|
|
|
def jump_detaches(*, jump_held, fire_held, attached):
|
|
"""429DF9..429E2C uses independent jump/fire predicates."""
|
|
return bool(jump_held and attached and not fire_held)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
cli = argparse.ArgumentParser(description=__doc__)
|
|
cli.add_argument('original', type=Path)
|
|
cli.add_argument('--output', type=Path)
|
|
args = cli.parse_args()
|
|
result = json.dumps(collect(args.original), indent=2)+'\n'
|
|
if args.output:
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
args.output.write_text(result)
|
|
else:
|
|
print(result, end='')
|