Implement Baseball aiming, pooled projectiles and VR07 targets
This commit is contained in:
1 parent
50fcb87d90
commit
d6ca417e9e
50 files changed
+3149
-32
No files matched your search
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Export exact Baseball canvases and authored VR07 data without timing guesses."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from dataclasses import asdict
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from entities import resolve_asset
|
||||
from gam import parse
|
||||
from omt import Database, FormatError, read_canvas, write_png
|
||||
|
||||
ARCHIVE_SHA256 = 'b584ffa4a38f4bc809b3ea8f4321e0c08f2719e22df41a3fb4cd143ed89b3bef'
|
||||
VR07_SHA256 = '1260b75d82ec794f9375ada30e186424746bc1dd4e4b0540c9b69bb7ad12d0b1'
|
||||
# Identity, source name, offset, bytes, width, height, decoded RGBA SHA256.
|
||||
CANVASES = (
|
||||
(2, 'ball0000', 72372, 3786, 32, 32, '68904b758e69139de0b01329b2a9844ecd2a466f31598c24324affaccfa2cab9'),
|
||||
(3, 'ball0001', 68582, 3790, 32, 32, '005def070e18111fbdb067e75285dad8ec677c1608020f55c3db7a4b9745205c'),
|
||||
(4, 'ball0002', 64788, 3794, 32, 32, 'c368a59d5d7a57824c1c6b56b617cf058f5d5d53e18e5e48989710413490c536'),
|
||||
(5, 'ball0003', 58830, 3794, 32, 32, 'e5da21c359d3215759e5c3c238107f526f7109203c0ff9fa391a3c8bc40c17ed'),
|
||||
(8, 'target', 48796, 10034, 64, 64, '8d31014cb9b9661ebed902c864bf740f562460e74da3f6b86ed3d2be4d10f0ec'),
|
||||
)
|
||||
AIM_ARCHIVES = {
|
||||
'omt/screens.omt': 'e8e95231f5d302b41f4fbf33df1c5a08ce4645370f9f519527ff1727b73b7a5e',
|
||||
'alpha.omt': '53cb9f47a588b1f19eb0adc4d43c8066a8b78aedd764b9e9314c81e287991126',
|
||||
}
|
||||
AIM_CANVASES = (
|
||||
('omt/screens.omt', 253, 15, 210, '2e16e11b151c8474ba68fd5017d1a3a6304a594a7f34c3b423f3417c7edfb453'),
|
||||
('alpha.omt', 118, 16, 16, 'edc60e65dcf7320813a80d4312e3c45951ccfc566ea79dfabf7a22ebc4b96049'),
|
||||
('alpha.omt', 127, 16, 16, '1fd058ad5bdc0f8a064ef7d2d52b2b036df3f35515691a366799d7e8aab5297f'),
|
||||
('alpha.omt', 120, 16, 16, '62aaeaaf107300a6f4f7ff52e98106c1520a9edbe2137626ee41091cf243e5c5'),
|
||||
('alpha.omt', 121, 16, 16, 'd78bf1895f5838b9eb8c6a22565a9588dae4fc8f7106697df373f4408aae634c'),
|
||||
('alpha.omt', 122, 16, 16, 'f6d628639de4e40005f62f63a49308ff9ee0656a36bb6eb7787230b4830a5ed9'),
|
||||
('alpha.omt', 123, 16, 16, '9f58cad5621d89b7a7012036daa8532b2397b0d9d267ab7d1aa5a7cd10d7ae87'),
|
||||
('alpha.omt', 124, 16, 16, '49cdc9ec812f4ef3826011d542c30afbb10229c4b4ce549e7820233bbaa53dd9'),
|
||||
('alpha.omt', 125, 16, 16, 'aaef2d59c2636c059b446bed643985ca55d15b2d070b0582b2d8994b3bf74f1e'),
|
||||
('alpha.omt', 126, 16, 16, 'bade574a4624a3f763ddd9c87fa2f102562b00d8d604e9faf32a43b372de64e0'),
|
||||
('alpha.omt', 119, 16, 16, '0a663ddf2df9f1065f5e4ffe27b4d1fa96edd5f19b6323217bad4148f8d2f3d7'),
|
||||
)
|
||||
TIME_DIGITS = (118, 127, 120, 121, 122, 123, 124, 125, 126, 119)
|
||||
|
||||
|
||||
def digest(data: bytes) -> str:
|
||||
return hashlib.sha256(data).hexdigest()
|
||||
|
||||
|
||||
def export_baseball(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')
|
||||
if output.exists() and any(p.is_symlink() for p in output.rglob('*')):
|
||||
raise ValueError('Generated Baseball paths must not contain symlinks')
|
||||
database = Database(resolve_asset(original, 'omt/RetainedSprites.omt'))
|
||||
if digest(database.data) != ARCHIVE_SHA256:
|
||||
raise FormatError('Unexpected original Baseball archive identity')
|
||||
textures, pixels = [], []
|
||||
for identity, name, offset, size, width, height, rgba_sha in CANVASES:
|
||||
matches = [e for e in database.entries if e.type == 'Canv' and e.id == identity]
|
||||
if len(matches) != 1:
|
||||
raise FormatError('Missing original Baseball canvas')
|
||||
entry = matches[0]
|
||||
if (entry.name, entry.offset, entry.size) != (name, offset, size):
|
||||
raise FormatError('Unexpected original Baseball canvas metadata')
|
||||
payload = database.payload(entry)
|
||||
canvas = read_canvas(payload)
|
||||
rgba = canvas['rgba']
|
||||
if (canvas['width'], canvas['height'], len(rgba), digest(rgba)) != (width, height, width*height*4, rgba_sha):
|
||||
raise FormatError('Unexpected original Baseball decoded pixels')
|
||||
textures.append(dict(id=identity, name=name, width=width, height=height,
|
||||
path=f'canvas_{identity}.rgba', png=f'canvas_{identity}.png',
|
||||
sourceOffset=offset, sourceBytes=size, sourceSha256=digest(payload), rgbaSha256=rgba_sha))
|
||||
pixels.append(rgba)
|
||||
aim_databases = {name: Database(resolve_asset(original, name)) for name in AIM_ARCHIVES}
|
||||
for name, expected in AIM_ARCHIVES.items():
|
||||
if digest(aim_databases[name].data) != expected:
|
||||
raise FormatError('Unexpected Baseball aim archive identity')
|
||||
aim_textures, aim_pixels = [], []
|
||||
for archive, identity, width, height, rgba_sha in AIM_CANVASES:
|
||||
aim_database = aim_databases[archive]
|
||||
entry = next(e for e in aim_database.entries if e.type == 'Canv' and e.id == identity)
|
||||
payload = aim_database.payload(entry)
|
||||
canvas = read_canvas(payload)
|
||||
rgba = canvas['rgba']
|
||||
if (canvas['width'], canvas['height'], len(rgba), digest(rgba)) != (width, height, width*height*4, rgba_sha):
|
||||
raise FormatError('Unexpected Baseball aim decoded pixels')
|
||||
aim_textures.append(dict(id=identity, name=entry.name, database=archive,
|
||||
width=width, height=height, path=f'aim_{identity}.rgba', png=f'aim_{identity}.png',
|
||||
sourceOffset=entry.offset, sourceBytes=entry.size, sourceSha256=digest(payload), rgbaSha256=rgba_sha))
|
||||
aim_pixels.append(rgba)
|
||||
source = resolve_asset(original, 'gam/VR07.gam')
|
||||
source_data = source.read_bytes()
|
||||
if digest(source_data) != VR07_SHA256:
|
||||
raise FormatError('Unexpected original Baseball tutorial identity')
|
||||
level = parse(source_data)
|
||||
records = [dict(ordinal=index, **asdict(entity)) for index, entity in enumerate(level.entities)
|
||||
if entity.kind in ('STRT', '3TAR', '3MCA')]
|
||||
targets = [r for r in records if r['kind'] == '3TAR']
|
||||
if len(targets) != 6:
|
||||
raise FormatError('Unexpected original Baseball tutorial target count')
|
||||
manifest = dict(schema=1, source=database.path.name, sourceSha256=ARCHIVE_SHA256,
|
||||
textures=textures, ballCanvasIds=[2, 3, 4, 5], retainedTargetCanvasId=8,
|
||||
aimTextures=aim_textures, aimArchiveSha256=AIM_ARCHIVES.copy(),
|
||||
aimFontPolicy='Original TIME set5; null space has zero advance;16-unit digits',
|
||||
aimDigitIds=list(TIME_DIGITS),
|
||||
tutorial=dict(source=source.name, sha256=VR07_SHA256, entities=records),
|
||||
bindingPolicy='Exact resource identities; caller owns source timing, dimensions, billboarding and attachments')
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
for entry, rgba in zip(textures+aim_textures, pixels+aim_pixels):
|
||||
(output/entry['path']).write_bytes(rgba)
|
||||
write_png(output/entry['png'], entry['width'], entry['height'], rgba)
|
||||
(output/'baseball.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)
|
||||
args = parser.parse_args()
|
||||
export_baseball(args.original, args.output)
|
||||
print(f'Original Baseball resources exported: {args.output}/baseball.json')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user