Implement original gadget panel and playable shrink ray
This commit is contained in:
1 parent
0272f7bef7
commit
7b5230ceb8
57 files changed
+3545
-48
No files matched your search
@@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only gadget panel contracts from retained REA and guarded EXE spans."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
|
||||
from checkpoint_script_state import EXE_SHA256, find_case, read_va
|
||||
from pe_inspect import PE
|
||||
|
||||
BODIES = (
|
||||
('menu_keys', 0x425870, 0x425B20, 'd06e437c3b858d187a094306891333ce735445c412e35ef8ccb33c37d8ce7735'),
|
||||
('menu_close', 0x425B20, 0x425C32, '8e80202c37b31235630e097297395c3c196959dfa11fdc5582cf6acc7b7a74c4'),
|
||||
('menu_open', 0x425EF0, 0x426027, '472c5356cc85c9d3e79f053e63114fb03d7b81d79b51a653fc56c7ae1fee1008'),
|
||||
('menu_tick', 0x427370, 0x427F6F, 'c0a95b31c9d2c0563c132fd2a8b04fd1710c2b77a17e0746722b407909f10b45'),
|
||||
('hit', 0x403A30, 0x403BCE, 'fd20747d496832e9582deea8daa1c41c1400e9de35d07656ca622a61614ed2ce'),
|
||||
('initialize', 0x404DE0, 0x405F70, 'd3505b89b02f229976a47566c1e1a5897489fc52bc21b55ee234b1c552c2057c'),
|
||||
('select', 0x428D50, 0x4298E8, 'e86e6ad89c80b6d1656c3f4697d8f2cb06f79c4d2bc1c403f5449ad391aec9ff'),
|
||||
('render', 0x402F60, 0x4032C0, '74653924b0988d391478ef1f3cbf96eda8cda0283b5665e22f295b41b9abd462'),
|
||||
('description_init', 0x4018B4, 0x401A37, '1debbfc78bf08053a878fff43c54c7d38362920fa87d8393f02d86144369d5d7'),
|
||||
)
|
||||
# Slices are protected by the full EXE identity and the applicable spans above.
|
||||
# Retain offsets/bytes for individual review rather than inferred signatures.
|
||||
SITES = (
|
||||
('tab_byte', 0x4258EB, 5), ('space_byte', 0x4258F8, 5),
|
||||
('shared_key_latch', 0x425A7C, 6), ('open_flag_before_toggle', 0x425A99, 5),
|
||||
('selected_mode_test', 0x425AAE, 8), ('cleanup_before_unequip', 0x425ABC, 6),
|
||||
('unequip_global', 0x425AC2, 9), ('open_mode_zero', 0x425AE1, 4),
|
||||
('open_mode_call', 0x425AF1, 6), ('open_game_pause', 0x425F8D, 6),
|
||||
('open_flag_write', 0x425F9D, 7), ('open_physics_disable', 0x425FE9, 8),
|
||||
('open_sound_gate_false', 0x426004, 7), ('close_flag_false', 0x425B4C, 6),
|
||||
('close_game_resume', 0x425BAB, 6), ('close_sound_gate_true', 0x425BFE, 7),
|
||||
('close_physics_enable', 0x425C05, 8), ('hit_state_skip_zero', 0x403A69, 9),
|
||||
('hit_state_skip_four', 0x403A72, 10), ('hit_x_lower_strict', 0x403AD1, 9),
|
||||
('hit_y_lower_strict', 0x403B04, 5), ('hit_state_three', 0x403B2E, 6),
|
||||
('hit_return_last', 0x403BBF, 5), ('practice_scene500', 0x427794, 7),
|
||||
('practice_vr_range', 0x4277B5, 20), ('practice_old_state_two', 0x4277DF, 6),
|
||||
('practice_disarm_three', 0x4277E5, 11), ('practice_arm_two', 0x4277FC, 11),
|
||||
('return_slot10', 0x427866, 10), ('select_close_before_cleanup', 0x4278DB, 6),
|
||||
('select_cleanup', 0x4278E5, 6), ('select_from_menu4c8', 0x4278F3, 16),
|
||||
('select_body_enable_after', 0x42791C, 7), ('select_ui_prelude', 0x428D8F, 15),
|
||||
('select_table', 0x428DCD, 19), ('default_device_practice_state', 0x428DE0, 19),
|
||||
('default_device_practice_load', 0x428E26, 44),
|
||||
('initial_practice_return_state1', 0x4223BE, 20),
|
||||
('escape_closes_open_panel', 0x42AB6D, 19),
|
||||
('initial_display_highlight3', 0x401F93, 10),
|
||||
)
|
||||
VTABLES = (
|
||||
(0x4A3BDC, 0x184, 0x425870), (0x4A3BDC, 0x1AC, 0x427370),
|
||||
(0x4A3BDC, 0x1F8, 0x425EF0), (0x4A3BDC, 0x1FC, 0x425B20),
|
||||
(0x4A3BDC, 0x174, 0x428D50), (0x48D414, 0x4A4, 0x403A30),
|
||||
(0x48D414, 0x4A8, 0x403A10), (0x48D414, 0x4B0, 0x405FB0),
|
||||
(0x48D414, 0x498, 0x406240), (0x48D414, 0x4C4, 0x406590),
|
||||
)
|
||||
TILES = ((12, 182), (158, 182), (12, 327), (157, 327),
|
||||
(342, 182), (487, 182), (342, 327), (487, 327))
|
||||
IDLE_CANVASES = (52, 46, 47, 48, 49, 50, 51, 45)
|
||||
DESCRIPTION_CANVASES = (109, 115, 111, 113, 116, 114, 118, 110)
|
||||
PRACTICE = (
|
||||
(0, 0x428FCA, 0x4EF650, 'vr01.gam'), (1, 0x4296E8, 0x4EF58C, 'vr02.gam'),
|
||||
(2, 0x428F51, 0x4EF678, 'vr03.gam'), (3, 0x428E41, 0x4EF6A0, 'vr04.gam'),
|
||||
(4, 0x429348, 0x4EF628, 'vr05.gam'), (5, 0x42943D, 0x4EF5D8, 'vr06.gam'),
|
||||
(6, 0x4297CD, 0x4EF564, 'vr07.gam'), (7, 0x4298B2, 0x4EF53C, 'vr08.gam'),
|
||||
)
|
||||
|
||||
|
||||
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]
|
||||
tables = []
|
||||
for base, slot, expected in VTABLES:
|
||||
target = struct.unpack('<I', read_va(pe, base + slot, 4))[0]
|
||||
if target != expected:
|
||||
raise ValueError(f'Changed virtual {base:x}+{slot:x}')
|
||||
tables.append(dict(table=hex(base), slot=hex(slot), target=hex(target)))
|
||||
practice = []
|
||||
for item, call, string, name in PRACTICE:
|
||||
if read_va(pe, call, 5) != b'\x68' + struct.pack('<I', string) or read_va(pe, string, len(name)+1) != name.encode()+b'\0':
|
||||
raise ValueError('Changed practice destination')
|
||||
practice.append(dict(item=item, push_va=hex(call), push_offset=hex(pe.offset(call-pe.base)),
|
||||
string_va=hex(string), level=name))
|
||||
return dict(sha256=digest, bodies=bodies, sites=sites, vtables=tables, practice=practice,
|
||||
selection_table=[hex(v) for v in struct.unpack('<10I', read_va(pe, 0x4298E8, 40))],
|
||||
tiles=[dict(item=i, x=x, y=y, hover_canvas=11+i, idle_canvas=IDLE_CANVASES[i],
|
||||
description_canvas=DESCRIPTION_CANVASES[i]) for i, (x, y) in enumerate(TILES)])
|
||||
|
||||
|
||||
def tab_action(panel_open: bool, equipped_mode: int, latched: bool = False):
|
||||
"""Bounded425870 branch; caller/game/other-key preconditions are separate."""
|
||||
if latched:
|
||||
return 'none'
|
||||
if panel_open:
|
||||
return 'close'
|
||||
return 'unequip' if equipped_mode != -1 else 'open_gadgets'
|
||||
|
||||
|
||||
def hit_gadgets(states, x: float, y: float):
|
||||
if len(states) != 8:
|
||||
raise ValueError('Eight group0 gadget states required')
|
||||
result = None
|
||||
for item, ((left, top), state) in enumerate(zip(TILES, states)):
|
||||
if state not in (0, 4) and left < x < left + 141 and top < y < top + 141:
|
||||
result = item
|
||||
return result
|
||||
|
||||
|
||||
def practice_toggle(current: int, level: str, scene_task: int):
|
||||
if scene_task >= 500 or 'VR01' <= level <= 'VR08':
|
||||
return current
|
||||
return 3 if current == 2 else 2
|
||||
|
||||
|
||||
def default_device_selection(practice_state: int):
|
||||
"""After ordinary cleanup, item3 keeps source mode−1; UI highlight is3."""
|
||||
return dict(highlight=3, equipped_mode=-1,
|
||||
practice_level='VR04' if practice_state == 2 else None,
|
||||
practice_state=1 if practice_state == 2 else practice_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,178 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only heading evidence and bounded projection of OMT2 vector::angles.
|
||||
|
||||
This module executes no original code. --emit-probe emits a separate component
|
||||
probe for the existing isolated copied-DLL reference-capture harness.
|
||||
"""
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
import struct
|
||||
|
||||
from pe_inspect import PE
|
||||
|
||||
EXE_SHA256 = 'f5281076e1a2492f2d61f87aae3f4544b6d0f535ebe33f9fbb6f78710fe1aea8'
|
||||
DLL_SHA256 = '3ec41ead011adf56387a6dbd4580e5b5a9721b5f8020c8a56420f42824354943'
|
||||
ANGLE_EXPORT = '?angles@OMedia3DVector@@QAEXAAF0@Z'
|
||||
UNITS_TO_DEGREES = 0.02197265625
|
||||
|
||||
|
||||
def f32(value):
|
||||
return struct.unpack('<f', struct.pack('<f', value))[0]
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def half_acos_table():
|
||||
# OMT2 init_table100EDC8C..100EDCD0; the final endpoint is explicitly zero.
|
||||
return tuple(int(math.acos(i * 0.0001220703125 - 1.0)
|
||||
* 2607.5945876921437 * 0.5) for i in range(16384)) + (0,)
|
||||
|
||||
|
||||
def heading_units(x, z):
|
||||
"""Second output of original vector::angles, finite float32 horizontal input.
|
||||
|
||||
Products/division deliberately use Python double, approximating the original
|
||||
x87 extended intermediates. Values at a ratio integer boundary can need a
|
||||
copied-DLL check; do not claim arbitrary-input bit equivalence.
|
||||
"""
|
||||
x, z = f32(x), f32(z)
|
||||
if not (math.isfinite(x) and math.isfinite(z)):
|
||||
raise ValueError('finite float32 components required')
|
||||
if x == 0 and z == 0:
|
||||
return 0
|
||||
index = int(16384.0 * z * z / (x * x + z * z))
|
||||
angle = half_acos_table()[index]
|
||||
if z < 0:
|
||||
angle = 8192 + angle if x < 0 else 8192 - angle
|
||||
elif x < 0:
|
||||
angle = 16384 - angle
|
||||
return (-angle) & 0x3fff
|
||||
|
||||
|
||||
def within_heading_window(x, z, jimmy_yaw):
|
||||
"""Source426E40's strict comparisons; deliberately no seam wrapping."""
|
||||
heading = heading_units(x, z) * UNITS_TO_DEGREES
|
||||
yaw = f32(jimmy_yaw)
|
||||
return yaw - 5 < heading < yaw + 5
|
||||
|
||||
|
||||
def _read(pe, va, length):
|
||||
offset = pe.offset(va - pe.base)
|
||||
if offset < 0 or offset + length > len(pe.data):
|
||||
raise ValueError('source range outside file')
|
||||
return pe.data[offset:offset + length]
|
||||
|
||||
|
||||
def evidence(executable, dll):
|
||||
pe, omt = PE(executable), PE(dll)
|
||||
for binary, expected in [(pe, EXE_SHA256), (omt, DLL_SHA256)]:
|
||||
if hashlib.sha256(binary.data).hexdigest() != expected:
|
||||
raise ValueError('source hash mismatch')
|
||||
imported = next(i for i in pe.imports() if int(i['iat'], 16) == 0x48d108)
|
||||
exported = next(e for e in omt.exports() if e['name'] == ANGLE_EXPORT)
|
||||
if imported['name'] != ANGLE_EXPORT or int(exported['va'], 16) != 0x1001fda0:
|
||||
raise ValueError('heading import/export mismatch')
|
||||
guards = [
|
||||
(pe, 0x4270bf, 'ff1508d14800'),
|
||||
(pe, 0x4270d7, '0fbf542416'),
|
||||
(pe, 0x4270df, 'd82550d94800'),
|
||||
(pe, 0x4270ed, 'd80db4e54800'),
|
||||
(pe, 0x4270f7, 'f6c4410f8510020000'),
|
||||
(pe, 0x42711a, 'd80550d94800'),
|
||||
(pe, 0x427132, 'f6c4010f84d5010000'),
|
||||
(omt, 0x1001fdf5, '668b0c4d301e1410'),
|
||||
(omt, 0x1001fe32, '8b542414f7d825ff3f0000668902'),
|
||||
(omt, 0x10104e13, '80cc0c'),
|
||||
(omt, 0x10104e1d, 'df7df4'),
|
||||
(omt, 0x100edcaf, 'e850710100'),
|
||||
(omt, 0x100edd0d, '6689ae08800200'),
|
||||
]
|
||||
for binary, va, pattern in guards:
|
||||
if _read(binary, va, len(pattern) // 2).hex() != pattern:
|
||||
raise ValueError(f'instruction mismatch at {va:#x}')
|
||||
for binary, va, fmt, expected in [
|
||||
(pe, 0x48d950, '<f', 5.0),
|
||||
(pe, 0x48e5b4, '<f', UNITS_TO_DEGREES),
|
||||
(omt, 0x10114850, '<f', -16384.0),
|
||||
(omt, 0x10114588, '<d', 0.0001220703125),
|
||||
(omt, 0x101166b8, '<d', 2607.5945876921437),
|
||||
(omt, 0x10115448, '<d', 0.5)]:
|
||||
if struct.unpack(fmt, _read(binary, va, struct.calcsize(fmt)))[0] != expected:
|
||||
raise ValueError(f'constant mismatch at {va:#x}')
|
||||
table_bytes = b''.join(struct.pack('<H', n) for n in half_acos_table())
|
||||
fnv = 2166136261
|
||||
for byte in table_bytes[:-2]:
|
||||
fnv = ((fnv ^ byte) * 16777619) & 0xffffffff
|
||||
if fnv != 0x4f800433:
|
||||
raise ValueError('regenerated half-acos table fingerprint mismatch')
|
||||
bodies = [(omt, 0x1001fda0, 0x1001ff6e),
|
||||
(omt, 0x100edc00, 0x100edd2a),
|
||||
(omt, 0x10104e04, 0x10104e2b),
|
||||
(pe, 0x4270b1, 0x42713b)]
|
||||
return dict(imported=imported, exported=exported,
|
||||
sources=[dict(sha256=EXE_SHA256), dict(sha256=DLL_SHA256)],
|
||||
bodies=[dict(va=hex(start), end_exclusive=hex(end),
|
||||
file_offset=hex(binary.offset(start - binary.base)),
|
||||
sha256=hashlib.sha256(_read(binary, start, end - start)).hexdigest())
|
||||
for binary, start, end in bodies],
|
||||
instruction_guards=len(guards), table_fnv32=f'{fnv:08x}',
|
||||
table_sha256=hashlib.sha256(table_bytes).hexdigest())
|
||||
|
||||
|
||||
PROBE = r'''/* Generated by shrink_heading.py; copied DLL only, isolated harness. */
|
||||
#include <windows.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
typedef void (__attribute__((thiscall)) *Angles)(const float*,short*,short*);
|
||||
int main(void) {
|
||||
setbuf(stdout,NULL);
|
||||
HMODULE h=LoadLibraryA("Z:\\work\\game\\OMT2.dll");
|
||||
if(!h){fprintf(stderr,"LoadLibrary failed %lu\n",GetLastError());return 2;}
|
||||
Angles angles=(Angles)GetProcAddress(h,"?angles@OMedia3DVector@@QAEXAAF0@Z");
|
||||
if(!angles)return 3;
|
||||
float vectors[][4]={{0,0,0,0},{0,0,1,0},{-1,0,0,0},{0,0,-1,0},{1,0,0,0},
|
||||
{-1,0,1,0},{-1,0,-1,0},{1,0,-1,0},{1,0,1,0},
|
||||
{1,100,1000,0},{-1,-100,1000,0},{1000,0,1,0},{-1000,0,1,0},
|
||||
{.1234567f,88,.7654321f,0},{-99.1f,-20,15.7f,0}};
|
||||
for(unsigned i=0;i<sizeof(vectors)/sizeof(vectors[0]);i++) {
|
||||
short pitch=-123,yaw=-123;angles(vectors[i],&pitch,&yaw);
|
||||
printf("ANGLE %.9g %.9g %.9g pitch=%d yaw=%d\n",vectors[i][0],vectors[i][1],vectors[i][2],pitch,yaw);
|
||||
}
|
||||
/* Cover all lookup-bin interiors/quadrants with synthetic finite vectors. */
|
||||
unsigned cases=0;uint32_t hash=2166136261u;
|
||||
for(unsigned i=0;i<=16384;i++)for(unsigned quadrant=0;quadrant<4;quadrant++) {
|
||||
float a=(float)sqrt((i+.25)/16384.5),b=(float)sqrt(1.-(i+.25)/16384.5);
|
||||
float v[4]={quadrant&1?-b:b,0,quadrant&2?-a:a,0};
|
||||
short pitch,yaw;angles(v,&pitch,&yaw);
|
||||
hash=(hash^(uint16_t)yaw)*16777619u;cases++;
|
||||
}
|
||||
printf("HEADING_SWEEP cases=%u fnv_words=%08lx\n",cases,(unsigned long)hash);
|
||||
puts("SHRINK_HEADING_COMPLETE: isolated copied DLL component, no game entry point");
|
||||
FreeLibrary(h);return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
def main():
|
||||
cli = argparse.ArgumentParser(description=__doc__)
|
||||
cli.add_argument('--exe', type=Path, default=Path('artifacts/uncontrolled-phases/rea/Neutron.exe'))
|
||||
cli.add_argument('--dll', type=Path, default=Path('artifacts/asset-probe/game/OMT2.dll'))
|
||||
cli.add_argument('--emit-probe', type=Path)
|
||||
args = cli.parse_args()
|
||||
report = evidence(args.exe, args.dll)
|
||||
if args.emit_probe:
|
||||
originals = Path(__file__).resolve().parents[3] / 'Original'
|
||||
if args.emit_probe.resolve().is_relative_to(originals.resolve()):
|
||||
cli.error('probe output must be separate from originals')
|
||||
args.emit_probe.parent.mkdir(parents=True, exist_ok=True)
|
||||
args.emit_probe.write_text(PROBE)
|
||||
print(json.dumps(report, indent=2))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only ordinary shrink-ray/input/effect source guards and bounded projections."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
import struct
|
||||
|
||||
from checkpoint_script_state import find_case, read_va
|
||||
from pe_inspect import PE
|
||||
|
||||
EXE_SHA256 = 'f5281076e1a2492f2d61f87aae3f4544b6d0f535ebe33f9fbb6f78710fe1aea8'
|
||||
DLL_SHA256 = '3ec41ead011adf56387a6dbd4580e5b5a9721b5f8020c8a56420f42824354943'
|
||||
BODIES = (
|
||||
('primary_hold', 0x426030, 0x4269CD, 'ec176370191f7c77152e1a69ee9787485f013c6b144b4642a4b40a99271dd438'),
|
||||
('shrink_scan', 0x426E40, 0x427335, '41d4bdb4c1f5b8254e6590633bcf7235939a26653ef1ade22b62cc2f3658f268'),
|
||||
('shrink_target', 0x42AC10, 0x42ADB5, '3b89f0e92d4ab6c6cf8c1e6b31021f977b62171d49111a6da78a30a9ec932973'),
|
||||
('energy', 0x42A920, 0x42AA13, '6d6a880fb1b4e39addc588201b7d5bb86c768dbfa3778b35045fc10380c9c5e4'),
|
||||
('primary_keys', 0x42A7A0, 0x42A7D6, 'c8fa10f42eefe68a195d9980f1a57558a240cd7877bfeab567e7868c0ddf419f'),
|
||||
('ray_init', 0x440000, 0x440176, '56e73181c84e439f2030b5f44162910128cdee5def560fcc1e4e7e86e2fff806'),
|
||||
('ray_tick', 0x440180, 0x44021E, '998f8db1294b5b034611e20535e64424192ff805f62e121f560319ad21d2b438'),
|
||||
('ray_ctor', 0x43FE20, 0x43FF40, 'd8d9814d90c9095afc8fcbe12439e63c50e2830c122f6eded690f5583cc0d785'),
|
||||
)
|
||||
SITES = (
|
||||
('primary_control_owner', 0x426053, 'a1e4995000'),
|
||||
('primary_sample', 0x426566, 'e835420000'),
|
||||
('enter_alternative', 0x426573, '6a0d'),
|
||||
('zero_controller_speed', 0x4266BD, '89ae08060000'),
|
||||
('shoot_animation', 0x42671A, '6a016848f44e00'),
|
||||
('owned_slot3_for_sound', 0x4268BE, '6a0355e88ad0fdff'),
|
||||
('loop_sound0', 0x4268E0, '6a01556affe896200300'),
|
||||
('release_hides_ray', 0x42666E, '8bb650090000'),
|
||||
('invoke_shrink_scan', 0x4269BD, 'ff90b8010000'),
|
||||
('scan_owned_slot3', 0x426E4C, '6a036a00'),
|
||||
('scan_owned_exact1', 0x426E5C, '663d0100'),
|
||||
('scan_mode_minus1', 0x426E66, '66833d88054f00ff'),
|
||||
('ray_position_copy', 0x426EF1, 'ff9318030000'),
|
||||
('ray_rotation_copy', 0x426F47, 'ff9330030000'),
|
||||
('energy_minus_dt', 0x426F4D, 'd984240001000051d9e0'),
|
||||
('registry', 0x426F5F, '8b0d9c995000'),
|
||||
('target_body_gate', 0x426F85, '8a853e010000'),
|
||||
('target_class_name', 0x426F96, '6844e34e00'),
|
||||
('target_enabled', 0x426FA8, '8a8598080000'),
|
||||
('target_already_shrunk', 0x42713B, '8a85b0080000'),
|
||||
('wall_query', 0x4271F5, 'e816500500'),
|
||||
('wall_hit_rejects', 0x4271FD, '84c00f850b010000'),
|
||||
('target_callback', 0x42720A, 'ff92dc010000'),
|
||||
('target_shrink_animation', 0x42AC33, '6a00681cf74e00'),
|
||||
('target_mode5', 0x42AC50, '6a05ff9224010000'),
|
||||
('target_timer30', 0x42AC68, 'c780740900000000f041'),
|
||||
('target_shrunk_flag', 0x42AC8A, 'c6807009000001'),
|
||||
('ray_ctor_owned', 0x4222C9, 'e852db0100'),
|
||||
('ray_publish_owned', 0x4222D9, '8985100a0000'),
|
||||
('ray_ctor_phase0', 0x43FF0F, '66899ebc060000'),
|
||||
('ray_bind_mesh', 0x440037, '68780b4f00683ce34e00'),
|
||||
('ray_bind_texture0', 0x44004B, '6a00686c0b4f00'),
|
||||
('ray_bind_texture1', 0x44006C, '6a0168600b4f00'),
|
||||
('ray_bind_texture2', 0x44008D, '6a0268540b4f00'),
|
||||
('ray_opacity_half', 0x440121, '680000003f'),
|
||||
('ray_timer0', 0x44015F, 'c7870006000000000000'),
|
||||
('ray_timer_gt_double_point1', 0x4401B5, 'dc1db8cf4900'),
|
||||
('ray_phase_increment', 0x4401C2, '66ff86fc050000'),
|
||||
('ray_phase_gt2', 0x4401E3, '6683befc05000002'),
|
||||
('ray_tick_discards_remainder', 0x44020F, 'c7860006000000000000'),
|
||||
('alpha_material_pointer', 0x40E503, '8d584c'),
|
||||
('alpha_not_scale', 0x40E52A, '896b0c'),
|
||||
('blend_src6', 0x40E535, '897830'),
|
||||
('blend_dst7_or1', 0x40E53A, 'c7403407000000eb03897034'),
|
||||
)
|
||||
|
||||
|
||||
def collect(original):
|
||||
pe = PE(find_case(Path(original), 'Neutron.exe'))
|
||||
digest = hashlib.sha256(pe.data).hexdigest()
|
||||
if digest != EXE_SHA256:
|
||||
raise ValueError('Original EXE identity changed')
|
||||
bodies = []
|
||||
for name, begin, end, expected in BODIES:
|
||||
actual = hashlib.sha256(read_va(pe, begin, end-begin)).hexdigest()
|
||||
if actual != expected:
|
||||
raise ValueError(f'Changed function body: {name}')
|
||||
bodies.append(dict(name=name, va=hex(begin), file_offset=hex(pe.offset(begin-pe.base)),
|
||||
size=end-begin, sha256=actual))
|
||||
sites = []
|
||||
for name, va, expected in SITES:
|
||||
data = bytes.fromhex(expected)
|
||||
if read_va(pe, va, len(data)) != data:
|
||||
raise ValueError(f'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 (
|
||||
('lower_y', 0x4A3E34), ('upper_y', 0x49D5B4), ('range', 0x495318),
|
||||
('yaw_half_angle', 0x48D950), ('angle_unit_degrees', 0x48E5B4))}
|
||||
constants['texture_period'] = struct.unpack('<d', read_va(pe, 0x49CFB8, 8))[0]
|
||||
strings = {hex(va): read_va(pe, va, 48).split(b'\0')[0].decode('ascii') for va in (
|
||||
0x4EE344, 0x4EF71C, 0x4F0B78, 0x4F0B6C, 0x4F0B60, 0x4F0B54)}
|
||||
dll = PE(find_case(Path(original), 'OMT2.dll'))
|
||||
if hashlib.sha256(dll.data).hexdigest() != DLL_SHA256:
|
||||
raise ValueError('Original DLL identity changed')
|
||||
blend = read_va(dll, 0x10036AB0, 0x35)
|
||||
if hashlib.sha256(blend).hexdigest() != '5869d3ab07f2797d6b83a60634c95e5faf56e8c806918cb07b4c205210b207eb':
|
||||
raise ValueError('Changed engine blend adapter')
|
||||
table = read_va(dll, 0x1013667C, 44)
|
||||
expected_table = (1, 2, 9, 3, 10, 4, 5, 6, 7, 8, 11)
|
||||
if struct.unpack('<11I', table) != expected_table:
|
||||
raise ValueError('Changed engine blend factor table')
|
||||
return dict(sha256=digest, bodies=bodies, sites=sites, constants=constants, strings=strings,
|
||||
blend=dict(dll_sha256=DLL_SHA256, body_va='0x10036ab0', body_file_offset=hex(dll.offset(0x36AB0)),
|
||||
table_va='0x1013667c', table_file_offset=hex(dll.offset(0x13667C)), d3d_table=expected_table,
|
||||
source_alpha=expected_table[6], additive_destination=expected_table[1], alpha_destination=expected_table[7]))
|
||||
|
||||
|
||||
def target_eligible(player, target, yaw, target_degrees, *, owned_state=1, equipped_mode=-1,
|
||||
integrates=True, enemy=True, enabled=True, shrunk=False, wall_hit=False):
|
||||
"""Projection of source gates; caller supplies original quantized target heading."""
|
||||
return (owned_state == 1 and equipped_mode == -1 and integrates and enemy and enabled and not shrunk
|
||||
and player[1]-150 < target[1] < player[1]+60 and math.dist(player, target) < 1500
|
||||
and yaw-5 < target_degrees < yaw+5 and not wall_hit)
|
||||
|
||||
|
||||
def f32(value):
|
||||
return struct.unpack('<f', struct.pack('<f', value))[0]
|
||||
|
||||
|
||||
def texture_step(phase, elapsed, seconds):
|
||||
"""440180 float accumulator/double strict threshold, one advance/no carry."""
|
||||
elapsed = f32(elapsed + seconds)
|
||||
if elapsed > .1:
|
||||
return (phase+1) % 3, 0.0
|
||||
return phase, elapsed
|
||||
|
||||
|
||||
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,184 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Read-only, byte-guarded 3SOL visual/shrink source contract.
|
||||
|
||||
REA findings are recorded in docs/gameplay/shrink-targets.md. This utility
|
||||
rechecks their byte/asset provenance; it neither executes the game nor recovers
|
||||
the full soldier AI or collision system. Addresses use preferred image bases.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import sys
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
sys.path.insert(0, str(HERE))
|
||||
sys.path.insert(0, str(HERE.parent / 'extractors'))
|
||||
sys.path.insert(0, str(HERE.parent / 'levels'))
|
||||
from checkpoint_script_state import EXE_SHA256, find_case, read_va
|
||||
from pe_inspect import PE
|
||||
from ase import read_ase
|
||||
import gam
|
||||
|
||||
DLL_SHA256 = '3ec41ead011adf56387a6dbd4580e5b5a9721b5f8020c8a56420f42824354943'
|
||||
BODIES = (
|
||||
('Neutron.exe', 'enemy_mode_setter', 0x4089B0, 0x408B93, '0f8a8d6894ff1d246abbf5d8493330c4c9d5508bb5f027deaff0c38dcc969695'),
|
||||
('Neutron.exe', 'shared_yokian_constructor', 0x44A730, 0x44A97C, '4654b058e18f96c88a081878d432cd11e94ba3165529be6486b5e79d0dd321ed'),
|
||||
('Neutron.exe', 'soldier_constructor', 0x44BEE0, 0x44C028, 'e4ad6ea59b4d5f4e0c30b08f0161ec677da08b9f3a06efe28f4dd9009c472ddc'),
|
||||
('Neutron.exe', 'soldier_model_loader', 0x44C0B0, 0x44C1BB, '538a3dbf346547fd7ddfea85a8348acd91ddcb2006f2d9ed1ede594f9b9a367d'),
|
||||
('Neutron.exe', 'shared_yokian_update_range', 0x44AA00, 0x44AF9B, 'bcc710da864a6954cfa2f61ca39a50aff2244c0965ee28882a62dd942309f8c2'),
|
||||
('Neutron.exe', 'game_animation_selector', 0x40DA30, 0x40DAAD, 'f5c8baa1dd35b9920da657dbefcdd7bf3e927fcc764ea395bb50269f49dd4738'),
|
||||
('OMT2.dll', 'engine_sequence_selector', 0x100209F0, 0x10020A9A, 'c430ff3c7036e6415f167579cab749db5811eabc296fbcee5e91bbf43f72173c'),
|
||||
('OMT2.dll', 'engine_next_frame', 0x10021000, 0x100210B8, '4d39ade2bd9cd9456301146096e493a0b9dcec49e00e4e8fd8d94ecbc86eff72'),
|
||||
)
|
||||
SITES = (
|
||||
('Neutron.exe', 'mode_setter_previous_current_fields', 0x4089E5, '8b8ec80600008dbe60040000505768dccb4e00898ecc0600008986c8060000'),
|
||||
('Neutron.exe', 'mode5_no_additional_dispatch', 0x408BA8, '8e8b4000'),
|
||||
('Neutron.exe', 'authored_aistate_property', 0x407F67, '8d867c0800006a06506890ca4e008bceff92fc030000'),
|
||||
('Neutron.exe', 'yokian_initial_mode_two', 0x44A7D3, 'b802000000'),
|
||||
('Neutron.exe', 'yokian_current_and_authored_mode', 0x44A7F7, '8986c806000089863c090000'),
|
||||
('Neutron.exe', 'postload_restores_authored_mode', 0x409503, '8b96080600008d8e40ffffff89967c0800008b96080600008b0152ff9024010000'),
|
||||
('Neutron.exe', 'capture_authored_reset_mode', 0x409460, '8b817c0800008981080600008b11ffa20c040000'),
|
||||
('Neutron.exe', 'soldier_calls_yokian_constructor', 0x44BF32, 'e8f9e7ffff'),
|
||||
('Neutron.exe', 'soldier_class_fourcc', 0x44BFF5, '684c4f5333'),
|
||||
('Neutron.exe', 'walk_asset', 0x44C0C3, '6884194f00'),
|
||||
('Neutron.exe', 'walk_action', 0x44C0C8, '6808d84e00'),
|
||||
('Neutron.exe', 'shrink_asset', 0x44C0DC, '6874194f00'),
|
||||
('Neutron.exe', 'shrink_action', 0x44C0E1, '685ce14e00'),
|
||||
('Neutron.exe', 'talk_asset', 0x44C0F0, '6864194f00'),
|
||||
('Neutron.exe', 'talk_action', 0x44C0F5, '68f0d74e00'),
|
||||
('Neutron.exe', 'stop_asset', 0x44C104, '6864194f00'),
|
||||
('Neutron.exe', 'stop_action', 0x44C109, '68f4c94e00'),
|
||||
('Neutron.exe', 'vr_range_low', 0x44C121, '3d31305256'),
|
||||
('Neutron.exe', 'vr_range_high', 0x44C128, '3d38305256'),
|
||||
('Neutron.exe', 'vr_texture_0', 0x44C133, '6850194f00'),
|
||||
('Neutron.exe', 'vr_texture_1', 0x44C144, '6850194f00'),
|
||||
('Neutron.exe', 'regular_texture_0', 0x44C14F, '6844194f00'),
|
||||
('Neutron.exe', 'regular_texture_1', 0x44C160, '6834194f00'),
|
||||
('Neutron.exe', 'initial_walk', 0x44C184, '6854ca4e00'),
|
||||
('Neutron.exe', 'body_radius_90', 0x44C19D, '680000b442'),
|
||||
('Neutron.exe', 'body_radius_setter', 0x44C1A4, 'ff9010010000'),
|
||||
('Neutron.exe', 'body_factor_1', 0x44C1AC, '680000803f'),
|
||||
('Neutron.exe', 'body_factor_setter', 0x44C1B3, 'ff9200010000'),
|
||||
('Neutron.exe', 'soldier_calls_yokian_update', 0x44C1C9, 'e832e8ffff'),
|
||||
('Neutron.exe', 'initial_shrunk_flag_false', 0x44A905, '889e70090000'),
|
||||
('Neutron.exe', 'timer_skip_unless_positive', 0x44AE6F, '0f85a4000000'),
|
||||
('Neutron.exe', 'timer_subtract_delta', 0x44AE75, 'd986b4080000d8642468d996b4080000'),
|
||||
('Neutron.exe', 'expiry_skip_unless_negative', 0x44AE90, '0f8483000000'),
|
||||
('Neutron.exe', 'expiry_zero_timer', 0x44AE96, '899eb4080000'),
|
||||
('Neutron.exe', 'expiry_clear_shrunk', 0x44AE9C, '889eb0080000'),
|
||||
('Neutron.exe', 'expiry_saved_mode', 0x44AEA8, '8b8e7c080000'),
|
||||
('Neutron.exe', 'expiry_mode_callback', 0x44AEBD, 'ff9024010000'),
|
||||
('Neutron.exe', 'expiry_walk', 0x44AEC6, '6854ca4e00'),
|
||||
('Neutron.exe', 'engine_sequence_call', 0x40DA61, 'ff5210'),
|
||||
('Neutron.exe', 'game_copy_loop_flag', 0x40DA64, '889fad000000'),
|
||||
('OMT2.dll', 'engine_restart_or_preserve_ordinal', 0x10020A3A, '8a44241484c07536'),
|
||||
('OMT2.dll', 'engine_loop_gate', 0x10021079, '8a591d84db7434'),
|
||||
('OMT2.dll', 'engine_wrap_first_frame', 0x10021080, '8b12'),
|
||||
('OMT2.dll', 'engine_hold_current_frame', 0x100210B4, '5f5e5bc3'),
|
||||
)
|
||||
VTABLES = (
|
||||
('soldier_complete_mode_setter', 0x4C1E64, 0x124, 0x4089B0),
|
||||
('soldier_complete_load', 0x4C1E64, 0x10C, 0x44C0B0),
|
||||
('soldier_complete_select_action', 0x4C1E64, 0xE0, 0x40DD90),
|
||||
('soldier_complete_select_sequence', 0x4C1E64, 0xE4, 0x40DA30),
|
||||
('soldier_interface_radius_set', 0x4C19C4, 0x110, 0x471240),
|
||||
('soldier_interface_factor_set', 0x4C19C4, 0x100, 0x4711E0),
|
||||
('soldier_interface_update', 0x4C19C4, 0x3C4, 0x44C1C0),
|
||||
)
|
||||
STRINGS = {
|
||||
0x4ECA90: 'AIState',
|
||||
0x4F1984: 'soldwalk.ase', 0x4F1974: 'soldshrink.ASE',
|
||||
0x4F1964: 'soldatak.ASE', 0x4ED808: 'HIWALK', 0x4EE15C: 'HISHRINK',
|
||||
0x4ED7F0: 'HITALK', 0x4EC9F4: 'HISTOP', 0x4F1950: 'vryoksoldier.png',
|
||||
0x4F1944: 'yoksold.png', 0x4F1934: 'yoksoldtalk.png', 0x4ECA54: 'WALK',
|
||||
}
|
||||
ASSETS = {
|
||||
'soldwalk.ASE': '98b16d95899a9d6f201d48b8f46183314c9570def076c8a038e0f706eda55a19',
|
||||
'soldshrink.ASE': 'bd79795a878557cd979a97719653aa669130ad778e922f0b78aa2160eddeb59f',
|
||||
'soldatak.ASE': 'b759a087dc5ab6621e8b9745b5e62bf24b2f131b6bd0e509f2f5392d94d496a1',
|
||||
}
|
||||
|
||||
|
||||
def timer_step(timer: float, delta: float, shrunk: bool = True) -> tuple[float, bool, bool]:
|
||||
"""Bounded control-flow projection, not original x87/runtime emulation.
|
||||
|
||||
Deliberately retains the source's equality edge case. The caller supplies
|
||||
original nonnegative game time; this does not model unrelated AI updates.
|
||||
"""
|
||||
if timer > 0:
|
||||
timer -= delta
|
||||
if timer < 0:
|
||||
return 0, False, True
|
||||
return timer, shrunk, False
|
||||
|
||||
|
||||
def collect(root: Path) -> dict:
|
||||
modules = {name: PE(find_case(root, name)) for name in ('Neutron.exe', 'OMT2.dll')}
|
||||
identities = {name: hashlib.sha256(pe.data).hexdigest() for name, pe in modules.items()}
|
||||
bodies, sites, vtables = [], [], []
|
||||
for module, name, start, end, expected in BODIES:
|
||||
pe = modules[module]
|
||||
actual = hashlib.sha256(read_va(pe, start, end-start)).hexdigest()
|
||||
bodies.append(dict(module=module, name=name, va=hex(start), end_exclusive=hex(end),
|
||||
file_offset=hex(pe.offset(start-pe.base)), sha256=actual, matches=actual == expected))
|
||||
for module, name, va, expected in SITES:
|
||||
pe = modules[module]
|
||||
actual = read_va(pe, va, len(bytes.fromhex(expected))).hex()
|
||||
sites.append(dict(module=module, name=name, va=hex(va),
|
||||
file_offset=hex(pe.offset(va-pe.base)), bytes=actual, matches=actual == expected))
|
||||
pe = modules['Neutron.exe']
|
||||
for name, table, slot, expected in VTABLES:
|
||||
target = struct.unpack('<I', read_va(pe, table+slot, 4))[0]
|
||||
vtables.append(dict(name=name, table=hex(table), slot=hex(slot), target=hex(target),
|
||||
file_offset=hex(pe.offset(table+slot-pe.base)), matches=target == expected))
|
||||
strings = []
|
||||
for va, expected in STRINGS.items():
|
||||
actual = pe.cstr(pe.offset(va-pe.base))
|
||||
strings.append(dict(va=hex(va), file_offset=hex(pe.offset(va-pe.base)),
|
||||
value=actual, matches=actual == expected))
|
||||
clips = []
|
||||
for name, expected in ASSETS.items():
|
||||
path = find_case(root, 'ASE/'+name)
|
||||
asset = read_ase(path)
|
||||
samples = [sample for obj in asset['objects'] for sample in obj['samples']]
|
||||
clips.append(dict(name=path.name, sha256=asset['sha256'], matches=asset['sha256'] == expected,
|
||||
frames_per_second=asset['framesPerSecond'], ticks_per_frame=asset['ticksPerFrame'],
|
||||
sample_count=len(samples), vertex_counts=[len(s['vertices']) for s in samples],
|
||||
face_counts=[len(s['faces']) for s in samples], times=[s['time'] for s in samples],
|
||||
y_bounds=[[min(v[1] for v in s['vertices']), max(v[1] for v in s['vertices'])] for s in samples]))
|
||||
textures = []
|
||||
for name in ('vryoksoldier.png', 'yoksold.png', 'yoksoldtalk.png'):
|
||||
path = find_case(root, 'png/'+name)
|
||||
textures.append(dict(name=path.name, sha256=hashlib.sha256(path.read_bytes()).hexdigest()))
|
||||
level_path = find_case(root, 'gam/VR04.gam')
|
||||
level_data = level_path.read_bytes()
|
||||
targets = [dict(kind=e.kind, file_offset=hex(e.offset), fields=e.values())
|
||||
for e in gam.parse(level_data).entities if e.kind == '3SOL']
|
||||
return dict(scope='Static source and original asset data only; no original runtime execution.',
|
||||
modules=identities, known_binary=identities == {'Neutron.exe': EXE_SHA256, 'OMT2.dll': DLL_SHA256},
|
||||
bodies=bodies, sites=sites, vtables=vtables, strings=strings, clips=clips, textures=textures,
|
||||
radius=90, factor=1,
|
||||
modes=dict(current_complete='0x6c8', previous_complete='0x6cc',
|
||||
authored_complete='0x93c', authored_interface='0x87c',
|
||||
authored_property='AIState', initial_authored=2,
|
||||
shrink_snapshots_authored=False, expiry_restores='authored'),
|
||||
vr04=dict(sha256=hashlib.sha256(level_data).hexdigest(), targets=targets))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('original', type=Path)
|
||||
args = parser.parse_args()
|
||||
result = collect(args.original)
|
||||
print(json.dumps(result, indent=2, allow_nan=False))
|
||||
guards = result['bodies'] + result['sites'] + result['vtables'] + result['strings'] + result['clips']
|
||||
if not result['known_binary'] or not all(item['matches'] for item in guards):
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Export original gadget-screen canvases; resource identity is not gameplay policy."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from dataclasses import dataclass
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from omt import Database, FormatError, read_canvas, validate_output, write_png
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class CanvasSpec:
|
||||
id: int
|
||||
name: str
|
||||
width: int
|
||||
height: int
|
||||
role: str
|
||||
|
||||
|
||||
TILE_LABELS = ('BUBBLE', 'ROCKETSHIP', 'INVISIBLE', 'SHRINK RAY',
|
||||
'SCOOTER', 'REMOTE', 'BASEBALL', 'GRAPPLER')
|
||||
TILE_IDS = tuple(range(11, 19))
|
||||
TILE_B_IDS = (52, 46, 47, 48, 49, 50, 51, 45)
|
||||
TILE_C_IDS = (178, 171, 172, 173, 174, 175, 176, 177)
|
||||
|
||||
|
||||
def specifications() -> tuple[CanvasSpec, ...]:
|
||||
specs = [CanvasSpec(20, 'menu', 640, 480, 'background')]
|
||||
for index, (plain, alternate_b, alternate_c) in enumerate(zip(TILE_IDS, TILE_B_IDS, TILE_C_IDS), 1):
|
||||
for identity, suffix in ((plain, ''), (alternate_b, 'b'), (alternate_c, 'c')):
|
||||
specs.append(CanvasSpec(identity, f'item{index:02d}{suffix}', 141, 141, f'tile{suffix}'))
|
||||
for identity, name in ((109, 'Bubble'), (110, 'Grappler'), (111, 'Invisible'),
|
||||
(112, 'JetPack'), (113, 'RayGun'), (114, 'Remote'),
|
||||
(115, 'Rocketship'), (116, 'Scooter'), (118, 'Baseball')):
|
||||
specs.append(CanvasSpec(identity, 'BmenuL'+name, 393, 69, 'controls-left'))
|
||||
for identity, name in ((108, 'BmenuR2'), (117, 'BmenuR1')):
|
||||
specs.append(CanvasSpec(identity, name, 247, 69, 'controls-right'))
|
||||
for identity, name in ((24, 'return'), (181, 'return2'), (182, 'return3'),
|
||||
(170, 'practice'), (179, 'practice2'), (180, 'practice3')):
|
||||
specs.append(CanvasSpec(identity, name, 141, 78, 'button'))
|
||||
for identity, name in ((94, '1bubble'), (87, '2rocket'), (88, '3invisible'),
|
||||
(89, '4raygun'), (90, '5scooter'), (91, '6remote'),
|
||||
(92, '7baseball'), (93, '8grappler'), (119, '9jetpack')):
|
||||
specs.append(CanvasSpec(identity, name, 80, 70, 'hud'))
|
||||
for identity, name in ((84, 'backpack'), (85, 'backpack2')):
|
||||
specs.append(CanvasSpec(identity, name, 141, 141, 'backpack'))
|
||||
specs.append(CanvasSpec(253, 'CrossHairs', 15, 210, 'crosshairs-strip'))
|
||||
return tuple(specs)
|
||||
|
||||
|
||||
CANVASES = specifications()
|
||||
|
||||
|
||||
def export_gadget_resources(database: Database, output: Path) -> dict:
|
||||
"""Copy exact decoded pixels and metadata to a separate generated directory.
|
||||
|
||||
Tile roles preserve original resource suffixes. Which suffix means selected,
|
||||
hovered, unavailable or enabled must come from the original dispatcher.
|
||||
"""
|
||||
validate_output(database, output)
|
||||
# Supplied archives live beneath Original/omt. Protect that entire source
|
||||
# tree, including sibling ASE/png/gam directories, rather than only omt/.
|
||||
source_directory = database.path.parent.resolve()
|
||||
source_root = source_directory.parent if source_directory.name.casefold() == 'omt' else source_directory
|
||||
if output.resolve().is_relative_to(source_root):
|
||||
raise ValueError('Gadget output must be separate from the source asset tree')
|
||||
entries = {entry.id: entry for entry in database.entries if entry.type == 'Canv'}
|
||||
recovered = []
|
||||
for spec in CANVASES:
|
||||
entry = entries.get(spec.id)
|
||||
if entry is None or entry.name != spec.name:
|
||||
raise FormatError(f'Missing or changed gadget canvas {spec.id}:{spec.name}')
|
||||
canvas = read_canvas(database.payload(entry))
|
||||
if (canvas['width'], canvas['height']) != (spec.width, spec.height):
|
||||
raise FormatError(f'Unexpected gadget canvas dimensions {spec.id}')
|
||||
recovered.append((spec, entry, canvas))
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
textures = []
|
||||
for spec, entry, canvas in recovered:
|
||||
name = f'canvas_{spec.id}'
|
||||
rgba = canvas['rgba']
|
||||
(output/(name+'.rgba')).write_bytes(rgba)
|
||||
write_png(output/(name+'.png'), spec.width, spec.height, rgba)
|
||||
textures.append(dict(id=spec.id, name=entry.name, role=spec.role,
|
||||
width=spec.width, height=spec.height, path=name+'.rgba', png=name+'.png',
|
||||
sourceOffset=entry.offset, sourceBytes=entry.size,
|
||||
sourceSha256=hashlib.sha256(database.payload(entry)).hexdigest(),
|
||||
rgbaSha256=hashlib.sha256(rgba).hexdigest()))
|
||||
manifest = dict(schema=1, source=database.path.name,
|
||||
sourceSha256=hashlib.sha256(database.data).hexdigest(),
|
||||
referenceWidth=640, referenceHeight=480, textures=textures,
|
||||
tiles=[dict(artItem=index+1, label=TILE_LABELS[index], canvas=plain,
|
||||
alternateB=alternate_b, alternateC=alternate_c)
|
||||
for index, (plain, alternate_b, alternate_c) in enumerate(zip(TILE_IDS, TILE_B_IDS, TILE_C_IDS))])
|
||||
(output/'gadgets.json').write_text(json.dumps(manifest, indent=2)+'\n', encoding='utf-8')
|
||||
return manifest
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('database', type=Path)
|
||||
parser.add_argument('--output', type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
manifest = export_gadget_resources(Database(args.database), args.output)
|
||||
print(f"{len(manifest['textures'])} original gadget canvases exported to {args.output}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -10,6 +10,7 @@ from png import read_png
|
||||
from entities import prepare_entities
|
||||
from models import prepare_models
|
||||
from ui import export_ui
|
||||
from gadget_resources import export_gadget_resources
|
||||
from sound_bank import export_sound_bank
|
||||
|
||||
|
||||
@@ -48,7 +49,7 @@ def main():
|
||||
parser.add_argument('--scenes', nargs='+', default=['level1b', 'VR01'])
|
||||
parser.add_argument('--all-scenes', action='store_true', help='Prepare every supplied GAM/OMT scene pair')
|
||||
parser.add_argument('--audio', nargs='*', default=['sounds', 'musicjimmyshouse', 'musicneighborhood'])
|
||||
parser.add_argument('--animations', nargs='*', default=['jimstop', 'jimrun', 'jimjump', 'jimscratch', 'jimbackpedal', 'jimfall', 'jimtalk', 'jimfly'])
|
||||
parser.add_argument('--animations', nargs='*', default=['jimstop', 'jimrun', 'jimjump', 'jimscratch', 'jimbackpedal', 'jimfall', 'jimtalk', 'jimfly', 'jimshoot'])
|
||||
args = parser.parse_args()
|
||||
if args.output.resolve().is_relative_to(args.original.resolve()):
|
||||
parser.error('Output must be outside the original installation')
|
||||
@@ -78,6 +79,7 @@ def main():
|
||||
catalog['prepared'].append({'level': name+'.gam', 'archive': source.name, 'scene': source.stem+'/scene.json'})
|
||||
(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')
|
||||
effects = export_sound_bank(args.original, args.output / 'effects')
|
||||
print(f"SoundEffects.omt: {len(effects['resources'])} original sound identities")
|
||||
for name in args.audio:
|
||||
@@ -109,6 +111,10 @@ def main():
|
||||
prepare_actor(args.original, args.output, 'trophy', 'trophy.png', {'STOP': 'trophy'})
|
||||
# C3DJetpackFire421F30..96: DEFAULT fire.ase, HINONE fire2.ase, fire.png.
|
||||
prepare_actor(args.original, args.output, 'jetpack', 'fire.png', {'DEFAULT': 'fire', 'NONE': 'fire2'}, 'fire')
|
||||
#Recovered C3DShrinkRay440000 and3SOL44C0B0 bindings; see docs/gameplay/.
|
||||
prepare_actor(args.original, args.output, 'shrink-ray', 'ray0000.png', {'RAY': 'ray'})
|
||||
prepare_actor(args.original, args.output, 'soldier', 'yoksold.png', {'WALK': 'soldwalk', 'SHRINK': 'soldshrink'}, 'soldatak')
|
||||
prepare_actor(args.original, args.output, 'soldier-vr', 'vryoksoldier.png', {'WALK': 'soldwalk', 'SHRINK': 'soldshrink'}, 'soldatak')
|
||||
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
Reference in new issue
Block a user