#!/usr/bin/env python3 """Generates the embedded game data of OpenBMH, so that the game runs from the asset files alone (no BMH.exe, no FLTD.EXE): src/formats/diamond_constants.inc (German, Diamond 3.7) and src/formats/fltd_constants.inc (English Football Limited) hold every non-zero byte of the numbers the engine reads - tables, rates, positions, prices - as runs of bytes; zero runs are not stored. The game texts (live commentary, messages) are NOT in the source: they go into the data file data/openbmh.dat that ships with the release (formats/diamond_image.hpp); the .inc files only list where they are. After regenerating, put the new SHA-256 of data/openbmh.dat into REVIEWED_BINARY_FILES of tools/public_release/check_public_tree.py. German (a Diamond 3.7 BMH.exe, read here and never copied into the repository): python generate.py german --exe BMH.exe --trace trace1.txt [--trace trace2.txt ...] --out ../../src/formats/diamond_constants.inc The file backed part of the data object, plus the few bytes of the code object that the program reads as numbers or tables (instruction immediates such as the calendar setup). The code bytes come from the read traces of OPENBMH_LE_TRACE (formats/le.hpp: run the data dependent tests and scenarios with the variable set to a file; the lines are " " in hex, flag 1 = number read, 2 = string read, 4 = start of a bulk read) and from a window at every layout constant that names a place in the code objects. English (the German layout image of FLTD.EXE, the cached "BMH.exe" of an English game that translate_fltd() made): python generate.py english --image BMH.exe --out ../../src/formats/fltd_constants.inc Every non-zero byte of the image. """ import argparse import re import struct import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent)) import classify # noqa: E402 DATA_LO, DATA_PAGES = 0xA0000, 12 # the initialised pages of the data object (file backed) DATA_HI = DATA_LO + DATA_PAGES * 4096 CODE = (0x10000, 0x10000 + 438272) PATCH = (0x80000, 0x81000) EN_LO, EN_HI = 0x6B000, 0x776A8 # the English data segment, also placed at its own addresses def load_le(path): """The loaded image of a DOS/4GW LE executable (objects at their link addresses, internal fixups applied).""" raw = Path(path).read_bytes() u16 = lambda o: struct.unpack_from(" len(data): continue if ftype == 0x07: put(pos, "