Complete Classic BMH and FLTD installation imports (by Codex)
This commit is contained in:
1 parent
65b087c1d0
commit
3a021fc160
32 files changed
+2297
-203
No files matched your search
@@ -31,7 +31,7 @@ The graphical client and console share career management, matches, transfers, co
|
||||
|
||||
Version 0.1 establishes the playable engine and development interfaces. Later milestones introduce an open data format and typed model, configurable rules, a scalable interface and independently distributable content. These are goals rather than delivery dates; the [roadmap](docs/ROADMAP.md) describes their dependencies.
|
||||
|
||||
The source tree also provides an initial standalone [`openbmh_import` tool](docs/formats/obw/import.md) to convert BMH and Football Limited installation data into the planned OBW format. These intermediate worlds are for conversion/development only; the game will gain OBW support in a later version.
|
||||
The standalone [`openbmh_import` tool](docs/formats/obw/import.md) converts BMH and Football Limited installations into **BMH-classic** / **FLTD-classic** OBW worlds, including media and frozen player portrait recipes. The content targets the versioned Classic adapter planned for 0.2; the 0.1 game does not load OBW. Savegame conversion is separate future work. The importer is built from current source and included in subsequent CI packages; it is absent from the already published 0.1.2 packages.
|
||||
|
||||
## Build from source
|
||||
|
||||
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
# OBW: OpenBMH world, save and pack format (concept, format version 1.0)
|
||||
|
||||
Status: **concept with an initial standalone converter** for roadmap 0.2 (open data and typed state), with preparation for 0.4 (scalable interface, content packs). `openbmh_import` implements the guarded `legacy-database-v1` conversion profile described in [import.md](obw/import.md). Its intermediate files cannot yet start a career. The legacy formats remain authoritative for the current engine; an OBW engine adapter and save conversion are not implemented.
|
||||
Status: **format concept with a complete Classic installation-content converter** for roadmap 0.2, with preparation for 0.4. `openbmh_import` produces `BMH-classic` and `FLTD-classic` worlds under the guarded [`runtime:classic-v1` contract](obw/classic-v1.md), including all startup inputs and media. The [import guide](obw/import.md) distinguishes this from the explicitly partial `legacy-database-v1` development export. The 0.1 engine still reads legacy installations; OBW runtime integration and savegame conversion are separate work.
|
||||
|
||||
## 1. Goals and non-goals
|
||||
|
||||
@@ -23,7 +23,7 @@ Non-goals of version 1.0:
|
||||
|
||||
### 2.1 Container
|
||||
|
||||
Every OBW file is a ZIP archive (deflate or stored) containing UTF-8 JSON documents. The project already links miniz (`bmh_miniz`) and has a JSON reader/writer (`src/cli/json.cpp`), so the format needs no new dependency. JSON keeps worlds diffable and editable by hand or by script.
|
||||
Every OBW file is a ZIP archive (deflate or stored) containing UTF-8 JSON documents and referenced binary assets. The versioned Classic extension additionally permits data-only compatibility regions and startup input records; it does not permit executable code or save state in a world. The project already links miniz (`bmh_miniz`) and has a JSON reader/writer (`src/cli/json.cpp`), so the format needs no new dependency. JSON keeps worlds diffable and editable by hand or by script.
|
||||
|
||||
| Extension | `kind` | Contents |
|
||||
|---|---|---|
|
||||
@@ -50,7 +50,7 @@ world/calendar.json season calendar, §7
|
||||
world/rules.json rule values (training camps, interest rates, ...)
|
||||
state/... save only, §5.9
|
||||
locale/<lang>/*.po texts, §9.3
|
||||
assets/... packs and themes only, §9
|
||||
assets/... local Classic worlds, packs and themes, §9
|
||||
x-<name>/... extensions, §3.3
|
||||
```
|
||||
|
||||
@@ -112,7 +112,7 @@ Fields and directories whose name starts with `x-` belong to extensions (`x-matc
|
||||
|
||||
Each format version is published as JSON Schema (draft 2020-12) under `docs/formats/obw/schema/<major>.<minor>/`, one file per table. The schemas are the machine-readable specification and the basis of the validator (§10).
|
||||
|
||||
The initial schemas describe the `legacy-database-v1` intermediate conversion profile only; save, pack, theme and complete playable-world schemas are still planned. This profile uses `requires` to prevent a partial conversion being mistaken for a complete world. Optional fields and unknown extensions remain allowed.
|
||||
The schemas describe the intermediate `legacy-database-v1` profile and the completed `classic-installation-v1` content profile. The latter requires `runtime:classic-v1`: it contains initialization policies and data-region compatibility fields in addition to typed projections. A generic OBW reader cannot execute those fields without the Classic adapter. Save, pack, theme and fully generic playable-world schemas remain future work. Optional fields and unknown extensions remain allowed.
|
||||
|
||||
## 4. Identifiers and names
|
||||
|
||||
@@ -186,7 +186,7 @@ Teams without a squad (`foreign`, or `national` in a world that does not simulat
|
||||
- `set` names a portrait part set; it defines the number of backgrounds, the layers, the number of parts per layer and their placement. `bmh-classic@1` is the set of the original game.
|
||||
- The importer computes the recipe once from the legacy name and **freezes** it. A later rename (for example by a name pack) keeps the face; the legacy name-derived generator is never re-run.
|
||||
- Players created in OpenBMH (youth, generated players) receive a random recipe of the world's default set.
|
||||
- The recipe holds indices only. The part graphics come from the user's installation or from a pack that provides the same set, possibly in higher resolution (§9.2), so a world contains no original artwork.
|
||||
- The recipe holds indices only. The part graphics come from the user's installation or from a pack that provides the same set, possibly in higher resolution (§9.2), so a recipe does not embed a composed face. A local Classic import may include the original part set as local-only assets; distributable worlds need separately licensed artwork.
|
||||
|
||||
An attribute set is declared once in `world/rules.json` with its fields, scales and meaning, so a later, finer model can sit next to the classic one without breaking the format:
|
||||
|
||||
@@ -363,7 +363,7 @@ Edition detection is the one the launcher already performs (`src/launch/game_dat
|
||||
|
||||
### 8.2 Mapping per edition
|
||||
|
||||
The first standalone converter and its coverage are documented in [the edition mapping](obw/import.md). The full intended mapping is:
|
||||
The standalone converter and its Classic contract are documented in [the edition mapping](obw/import.md) and [Classic v1](obw/classic-v1.md). The core league mapping is:
|
||||
|
||||
| Legacy league | German editions | Football Limited | OBW |
|
||||
|---|---|---|---|
|
||||
@@ -378,7 +378,7 @@ Cups, European cups, the indoor tournament, the English FA Cup with its qualifyi
|
||||
|
||||
### 8.3 Fidelity
|
||||
|
||||
The initial `legacy-database-v1` converter preserves database seeds and source tables without starting a career. It does not yet satisfy the engine equivalence criteria below; those require the 0.2 adapter. Its manifest explicitly marks it non-playable, and its import report lists unresolved areas. Unmapped world data lives in `x-legacy/`; `state/x-legacy.json` is reserved for converted saves.
|
||||
The complete `classic-installation-v1` importer preserves all installation content without starting a career. Typed projections are complemented by the versioned `x-classic` startup contract and data-only regions, including original and effective rules. Installation tests reconstruct from OBW and compare first-season initialization bytes and both RNG streams with the existing loader. They do not establish a released OBW frontend or save continuation. The optional `--database-only` intermediate profile remains explicitly non-playable. `state/x-legacy.json` is reserved for converted saves.
|
||||
|
||||
- A new career imported from an installation must produce the same first season in the engine as the legacy start (same fixtures, same participants), verified by the regression runs.
|
||||
- A converted `.FBM` must continue with the same results as the legacy save for a fixed number of turns.
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
# Classic installation content contract, version 1
|
||||
|
||||
This contract completes the installation import for the two supported Classic
|
||||
mods without making the 0.1 engine consume OBW. It is an additive OBW 1.0
|
||||
extension, guarded by **`requires: ["runtime:classic-v1"]`**. Readers which do not
|
||||
implement it must reject it. The mod IDs are `BMH-classic` and `FLTD-classic`.
|
||||
|
||||
The contract is a bridge for the 0.2 adapter. Core JSON gives stable identities
|
||||
and useful typed projections; `x-classic` retains every remaining content byte
|
||||
and binds initialization semantics to a version. It does not make a legacy cup
|
||||
table into the generic competition engine planned for 0.4. Neither a DOS
|
||||
executable nor an installed game is needed to reconstruct the imported content.
|
||||
|
||||
## Content and precedence
|
||||
|
||||
| Path | Contract |
|
||||
|---|---|
|
||||
| `manifest.json` | Profile `classic-installation-v1`, canonical mod ID, content ownership, season reference and required runtime |
|
||||
| `world/*.json` | Core entities, source squad identities, initialization policies, league/cup projections and rule/calendar projections |
|
||||
| `x-legacy/source-database.json` | Exact master database as hex, with `legacy-source@1.0`; preserves spare slots and packed fields |
|
||||
| `x-legacy/database.json` | Named auxiliary tables and name pools |
|
||||
| `x-legacy/texts.json` | Original text indices, decoded strings and raw bytes |
|
||||
| `x-classic/startup.json` | `classic-startup@1.0`, edition, layout version, initializers, inputs and resource references |
|
||||
| `x-classic/{source,effective}/*.bin` | Original and supported-profile DATA regions, never program code |
|
||||
| `x-classic/{desktop,formation}-seed.bin` | The 864-byte desktop and 1,408-byte formation input records |
|
||||
| `x-classic/text-blob.bin` | Exact text block after its seven-byte source header, including following bytes used by bounded legacy text reads; startup metadata preserves the header |
|
||||
| `assets/classic/resources.json` | Image dimensions/indices/PNG paths, bitmap-font metrics, audio-container chunks and optional artwork |
|
||||
| `assets/classic/palette.json` | All 256 ARGB colors, using the existing verified VGA-DAC expansion |
|
||||
| `assets/index.json` | Logical keys, paths, kind, source and rights metadata |
|
||||
| `assets/portrait-sets/bmh-classic@1/set.json` | Four backgrounds, five ordered layers, individual part keys and placement |
|
||||
| `x-classic/inventory.json` | Every other entry's path, byte count and CRC32 |
|
||||
|
||||
`content_complete: true` means that all content needed by this particular runtime
|
||||
is present. It does not identify a running game, an OBW-capable released client,
|
||||
or a completely generic typed simulation. The adapter must preserve legacy
|
||||
fields it does not otherwise use. Names/appearance/assets in the core projection
|
||||
are the presentation values; original byte names and offsets remain available
|
||||
for Classic initialization and compatibility. An adapter which supports editing
|
||||
ratings, membership or competitions must explicitly apply those changes to its
|
||||
initialization model; blindly replaying the preserved database would ignore them.
|
||||
|
||||
## Data regions
|
||||
|
||||
`openbmh-classic-layout@1` fixes the address layout already documented in
|
||||
`src/formats/executable_layout.hpp` at the introduction of this contract:
|
||||
|
||||
- Common German-layout data: `[0xA0000, 0xC1000)`.
|
||||
- Football Limited only, native English data: `[0x6B000, 0x776A8)`.
|
||||
|
||||
Only these allowlisted regions and four bounded text literals can be reconstructed.
|
||||
The literals are the free-kick, penalty, corner and automatic-taker labels at
|
||||
`0x80CC9`, `0x80CD2`, `0x80CDB`, `0x80CE3`, with bounds 9/9/8/5 bytes including
|
||||
the terminator. They share a German LE code object, so they are extracted as
|
||||
individual strings, never as the containing object. English normalized images
|
||||
retain their existing values (empty where untranslated). All other locations of
|
||||
the compatibility image are zero. DOS headers, program instructions and relocation
|
||||
instructions are excluded. Pointer-valued data remain numbers; they are never executed.
|
||||
|
||||
`effective` is the existing loader's output with `openbmh-supported@1` rules.
|
||||
`source` is the same loaded/translated data before applying that rule profile.
|
||||
English translation still maps the edition's content into the common layout and
|
||||
also retains its native data region. The two copies prevent shared rule
|
||||
normalization from destroying source values. The current supported rule profile
|
||||
is the default for both Classic mods; selecting unpatched rules requires a
|
||||
separately versioned runtime/profile, not a silent behavioral change.
|
||||
|
||||
Raw regions include all content read through the current executable-data API:
|
||||
cup/qualification tables, ladder, prices, training and credit data, stadium
|
||||
configuration, player-generation settings, match parameters, embedded strings,
|
||||
interface atlases/coordinates and audio tables. Some of these remain byte-based
|
||||
compatibility fields rather than final generic rule objects. They are fully
|
||||
preserved, not left to a future re-import from the executable.
|
||||
|
||||
## New-game initialization
|
||||
|
||||
The importer does **not** choose a manager, start a career, simulate a season,
|
||||
consume either game RNG or import an FBM. The adapter receives two seeds, manager
|
||||
choices, level, mode and competition options when starting a new game. It applies
|
||||
these operations in order, retaining the existing engine's arithmetic, packed
|
||||
field behavior and draw sequence:
|
||||
|
||||
| Initializer | Existing semantic operation |
|
||||
|---|---|
|
||||
| `classic-load-seeds@1` | `startup_state`: database/pools, saved static blocks, desktop/formation input, competition pointers and nationality transforms |
|
||||
| `classic-player-ratings@1` | `startup_players`, with edition league structure and original extra-player slots |
|
||||
| `classic-pending-offers@1` | Clear the four pending-offer words to their empty sentinel, as `new_career_before_dialog` |
|
||||
| `classic-markets-and-moods@1` | `new_career_markets_and_moods`: funds/shares, provisional computer-manager names, market history and club moods |
|
||||
| `classic-free-agents@1` | `new_career_players`: ages/skills and release of extra players |
|
||||
| `classic-setup-options@1` | Apply level, mode, duration, manager count, competition/calendar masks, then `career_managers_begin` |
|
||||
| `classic-confirm-managers@1` | `career_add_manager`: name/portrait, identity swaps, ratings, financial/contractual, lineup, stadium and sponsor initialization; then `career_managers_end` |
|
||||
| `classic-season-setup@1` | `career_season_setup` and `career_first_steps`: entrants, international cycle, calendar, tickets, club accounts, player season and shuffled draw positions |
|
||||
|
||||
Extra runtime configuration mirrors `CareerSession`: currency suffix, training-camp
|
||||
data, credit tables/divisor, edition scheduling, message strings and runtime
|
||||
options all come from the imported content/current versioned Classic algorithm.
|
||||
|
||||
The adapter maps `manifest.start_date` to its calendar's season origin. The
|
||||
current 0.1 engine uses a 2026 date label internally; the importer does not change
|
||||
that engine. The installation equivalence test uses the same 2026 origin and
|
||||
identical options/seeds on both paths. Other requested start years are retained
|
||||
as world input for the 0.2 calendar adapter.
|
||||
|
||||
`classic-manager-finance@1`, `classic-player-contract@1` and
|
||||
`classic-stadium@1` are **initialization policies**, not existing contracts,
|
||||
balances or owned stadiums. Finance policies cover 138 league clubs; actual
|
||||
human-manager accounts are created when a manager is assigned. Contract seeds
|
||||
bind every assigned player to the source team with the packed source values.
|
||||
Referees are staff entities; managers and other generated staff get identities
|
||||
when a new game creates them. Stadium entities form the complete name pool.
|
||||
No invented birth date, contract term or zero-capacity stadium fills a gap.
|
||||
|
||||
## Competition and calendar projections
|
||||
|
||||
All nine leagues use the edition's sizes, members and fixture draw-position
|
||||
tables. German regional third divisions remain parallel. The English ten-club
|
||||
fifth tier remains unplayed, with no invented fixture generator.
|
||||
|
||||
All 36 source cup entries remain in the data regions. Entries with a valid
|
||||
competition ID 0–26 are also represented as stages grouped by competition ID;
|
||||
sentinel entries remain data only. Their Classic fields record source entry,
|
||||
flags, next/parallel links, round counts, qualification quota and group number.
|
||||
Slots with `resolver: classic-entry@1` are dynamic fields populated by
|
||||
`classic-season-entrants@1`, not explicit team lists. `teams` records the source
|
||||
stage size and can be zero before initialization. The resolver must implement
|
||||
the current edition's selection and qualification algorithm, including FA Cup
|
||||
qualifying/proper rounds and League Cup for English data, or indoor/Masters for
|
||||
German data. The generic `format` field alone is insufficient to execute a stage.
|
||||
|
||||
`classic-calendar@1` retains the complete source day table and bindings.
|
||||
`classic-season-calendar@1` applies options, season cycle, weekday alignment and
|
||||
leap-year behavior using the Classic calendar algorithm at runtime. Cup series
|
||||
bind calendar bit `competition_id + 5`; league series retain the edition's
|
||||
calendar-group binding. Dated fixtures cannot be exported before manager/options
|
||||
selection without changing the original start semantics.
|
||||
|
||||
## Artwork, portraits, fonts and audio
|
||||
|
||||
Every imported image has an indexed PNG for standard consumers plus a `.pixels`
|
||||
payload for the Classic adapter's exact palette-index operations. Dimensions and
|
||||
palette are explicit. The source VGA files themselves are not required. Crest
|
||||
keys bind stable club identities; the original generic crest is used where the
|
||||
Classic interface deliberately uses a fallback. Kit selectors and the complete
|
||||
relevant sprite sheets remain available.
|
||||
|
||||
`appearance` contains the source-name-derived result, computed with the same
|
||||
signed-byte/unsigned-seed arithmetic as `PlayerCardScreen::draw_portrait`, including
|
||||
its discarded initial draw. It never consumes the game's RNG streams. A rename
|
||||
changes the name, not the recipe. The set stores each part separately, preserving
|
||||
linear source-stride wrap at row edges, transparent index zero, layer order and
|
||||
offsets relative to the 38×38 background. It never stores composed faces.
|
||||
|
||||
Bitmap fonts store glyph locations, widths, advances, original alphabet bounds,
|
||||
baseline and exact bitmap bytes. The zero-width replacement glyph may point
|
||||
beyond the bitmap because it is never dereferenced. These fonts use the Classic
|
||||
byte encoding; new modern interface fonts remain a separate theme concern.
|
||||
|
||||
The four original ALPTRAUM audio containers are local binary assets with chunk
|
||||
metadata, consumed by the already implemented audio decoder. Music keeps its
|
||||
instrument/sequence data rather than being destructively flattened to a recording.
|
||||
Source frequency/operator tables remain in the Classic data regions. Optional
|
||||
FLI/FLC and editor artwork is retained as identified local artwork, without
|
||||
importing editor programs, user settings or saves.
|
||||
|
||||
## Reader, writer and checks
|
||||
|
||||
`bmh::obw::read` accepts ZIP/directory content and validates it. `load_classic`
|
||||
returns the read-only input model (`Database`, data-only `LeImage`, full `TextDb`,
|
||||
desktop/formation seeds, indexed images, palette, fonts and audio) independently
|
||||
of either game frontend. It does not create `GameState` or `CareerSession`.
|
||||
|
||||
Binary payloads are byte strings, not UTF-8 JSON strings. Paths are authored
|
||||
relative forward-slash paths. The reader rejects traversal, duplicate entries,
|
||||
symlinks in a directory, excessive sizes and unknown required profiles. The
|
||||
validator checks cross-references, complete stage/contract bindings, resource
|
||||
shapes, portrait indices and inventory. CRC32 detects accidental damage, not
|
||||
malicious modification. An editor deliberately changing a world must update its
|
||||
inventory (`refresh_classic_inventory`) and validate it before writing.
|
||||
|
||||
The installation test reconstructs from an OBW ZIP, then compares a complete
|
||||
first-season initialization in RAM against the existing legacy-load path:
|
||||
native state bytes and both RNG seeds/counts. It also compares every exported
|
||||
data-region byte and original atlas pixels, palette, fonts and audio. This proves
|
||||
content/startup preservation for the supplied installation and chosen test start;
|
||||
it does not claim an implemented 0.2 adapter, native-platform testing, a fully
|
||||
played season or savegame conversion.
|
||||
+123
-114
@@ -1,143 +1,152 @@
|
||||
# Legacy installation importer (first version)
|
||||
# BMH and Football Limited installation converter
|
||||
|
||||
`openbmh_import` converts a locally supplied German BMH installation or English
|
||||
Football Limited installation into an OBW ZIP, or an unpacked OBW directory.
|
||||
It is a separate tool: neither game frontend nor the engine reads OBW yet.
|
||||
Integration into the game belongs to version 0.2.
|
||||
`openbmh_import` imports the content of a supported, locally supplied installation
|
||||
as **BMH-classic** or **FLTD-classic**. Football Limited's executable is named
|
||||
`FLTD.EXE`; the spellings `FTDL-classic` and `FTLD-classic` are accepted as CLI
|
||||
aliases and written as `FLTD-classic`.
|
||||
|
||||
The output is an `.obw` ZIP, or an equivalent directory. It contains the complete
|
||||
**Classic installation content**, including graphics, portrait parts, fonts,
|
||||
audio and the original data tables. It contains no running career or executable.
|
||||
The existing 0.1 game does not read OBW. The new 0.2 adapter must implement the
|
||||
versioned [Classic contract](classic-v1.md); this is deliberately separate from
|
||||
migrating every engine rule to the future generic model.
|
||||
|
||||
## Build and use
|
||||
|
||||
Configure the project as described in [BUILDING](../../BUILDING.md), then build
|
||||
the additional target:
|
||||
Configure as described in [BUILDING](../../BUILDING.md), then:
|
||||
|
||||
```sh
|
||||
cmake --build build --config Release --target openbmh_import
|
||||
./build/openbmh_import --data "path/to/game" --output "season.obw" \
|
||||
--start-date 2026-07-01 --title "My imported season"
|
||||
./build/openbmh_import --data "path/to/BMH" --output "BMH-classic.obw" \
|
||||
--start-date 2026-07-01 --mod BMH-classic
|
||||
./build/openbmh_import --data "path/to/FLTD.EXE" --output "FLTD-classic.obw" \
|
||||
--start-date 1995-07-01 --mod FLTD-classic
|
||||
./build/openbmh_import --validate "BMH-classic.obw"
|
||||
```
|
||||
|
||||
With a Visual Studio multi-configuration build, use
|
||||
`build\Release\openbmh_import.exe`. On Linux and macOS, the executable is in
|
||||
`build/openbmh_import`. To inspect or edit the JSON directly:
|
||||
On a Visual Studio multi-configuration build use
|
||||
`build\Release\openbmh_import.exe`. `--mod` is optional: the tool detects the
|
||||
edition. A mismatching explicit mod is an error. `--title TEXT` changes the
|
||||
world's display title. `--directory` writes an unpacked world, which `--validate`
|
||||
can read too. The source may be an installation directory, its executable, or a
|
||||
parent with exactly one installation. File discovery ignores case. If both game
|
||||
executables exist, select the intended executable explicitly.
|
||||
|
||||
```sh
|
||||
./build/openbmh_import --data "path/to/FLTD.EXE" --output "season-directory" \
|
||||
--start-date 1995-07-01 --directory
|
||||
```
|
||||
A full import requires the same installation resources as the current launcher:
|
||||
master database, text database, executable, `M3.MEN`, `M3.DAT`, palette, required
|
||||
`KB`/`W` pictures, two fonts and four sound banks. A missing resource is an error.
|
||||
Supported inputs are the German CD-family editions and Football Limited; the
|
||||
1994 floppy `M3.EXE`/`M3PC.MAN` family and Amiga installations are not supported.
|
||||
Source ZIP/7z and `.FBM` files are not input formats for this tool.
|
||||
|
||||
`--data` accepts an installation directory, a parent containing exactly one
|
||||
installation, or its `BMH.EXE`/`FLTD.EXE`. File discovery ignores case. An
|
||||
installation containing both executables requires naming the executable.
|
||||
Only the executable, master database and text database are required; absent
|
||||
graphics, audio or desktop files do not prevent conversion. Source ZIP/7z
|
||||
archives and individual `.FBM` saves are not input formats for this first tool.
|
||||
The date must be July 1 of an explicit year (1900–9998). Master data contain
|
||||
ages without an unambiguous season year; the converter never uses today's date
|
||||
or invents birth dates. Player age is recorded as `age_at_start`. Calendar setup
|
||||
remains a Classic runtime operation using the selected season/options.
|
||||
|
||||
The reference date is explicit because a master database records ages without
|
||||
an unambiguous season year. It must be July 1, from 1900 through 9998. The tool
|
||||
does not use the computer's current date. It refuses existing output paths,
|
||||
including symlinks. Output is assembled in a sibling staging directory and
|
||||
published after validation; the output parent must already exist.
|
||||
Do not run competing writers against the same destination.
|
||||
Existing destinations, including symlinks, are refused. The parent directory
|
||||
must exist. The tool stages and validates output before publishing by rename;
|
||||
source files are read only. Do not run competing writers for one destination.
|
||||
|
||||
Runtime packages for 0.1 retain their existing products. The source build has
|
||||
the extra importer; `cmake --install build --component ImportTools` installs it
|
||||
separately. Installing it does not enable OBW in the game.
|
||||
## What a Classic world contains
|
||||
|
||||
## Conversion profile and coverage
|
||||
The manifest names `mod: BMH-classic` or `FLTD-classic`, profile
|
||||
`classic-installation-v1`, `requires: ["runtime:classic-v1"]` and
|
||||
`content_license: local-import-only`. `content_complete: true` means all inputs
|
||||
for that **specific Classic runtime** are present. It does not claim that the
|
||||
0.1 client can load OBW or that every rule has already been migrated to a generic
|
||||
0.2/0.4 schema. A reader without `runtime:classic-v1` must refuse the world.
|
||||
|
||||
The manifest declares format `1.0`, `kind: world`, provenance `import:bmh-de`
|
||||
or `import:fltd`, and `content_license: local-import-only`. Crucially,
|
||||
`requires: ["import:legacy-database-v1"]` and `x-import.playable: false`
|
||||
identify an **intermediate conversion**, not a fully initialized playable world.
|
||||
A reader which does not support this profile must refuse it. Future conversion
|
||||
passes can complete its mappings without needing to reopen the original database.
|
||||
|
||||
Every core table uses the `schema`/`items` envelope, including `rules` and
|
||||
`calendar`. The schemas under [schema/1.0](schema/1.0) describe this first
|
||||
conversion profile; complete save/pack/theme schemas and engine playability
|
||||
validation remain future work.
|
||||
|
||||
| Source | Exported data |
|
||||
| Area | Contents |
|
||||
|---|---|
|
||||
| `M3D.MAN` / `M3E.MAN` | Named clubs, national teams, nations, all 2,574 players, master squad assignments, stadium name pool |
|
||||
| Player words and bonus bytes | Position, age, nationality including the high bonus bit, form/technique/condition, seven skills, bonus and derived display strength |
|
||||
| Executable, through existing loaders | Nine league sizes/tiers/participants, original fixture pairings, promotion-ladder inputs, 366 source calendar words, training-camp prices/quality and credit factors |
|
||||
| `TEXTD.BLK` / `TEXTE.BLK` | Local `de-original` / `en-original` gettext layer and an indexed text table with raw bytes |
|
||||
| Unmapped master fields | Named hexadecimal tables, original name pools, original player words, badge/kit selectors, squad words and flags |
|
||||
| Source master database | Exact file bytes in `x-legacy/source-database.json`, hexadecimal, for lossless later re-mapping |
|
||||
| Nations and teams | All named clubs/national teams, nine leagues, amateur pool, foreign nation blocks, encoded strength band/style, crest and kit selectors |
|
||||
| Players | All 2,574 identities, squads, raw words/flags, attributes, age reference, nationality and frozen portrait recipe |
|
||||
| Staff | Referee names, properties and strictness; human/computer manager setup is a runtime initializer |
|
||||
| Contracts and finance | Contract seeds per assigned player and finance policies for all 138 league clubs; actual values are created by the same manager/season initialization as today |
|
||||
| Stadiums | Entire name pool and stadium initializer, with all building, capacity, price and facility tables retained in Classic data regions |
|
||||
| Competitions | Nine league definitions and fixture generators, plus every configured cup-table stage with links, flags, group/qualifying information and runtime participant resolvers |
|
||||
| Calendar and rules | Day table, league bindings, cup series, ladder, training camps, credit factors, initialization sequence and all remaining data-region content |
|
||||
| Text | UTF-8 original gettext layer, indexed strings, raw text blob and embedded executable-data texts |
|
||||
| Artwork | Every numeric `KB/*.VGA` and `W/*.VGA` decoded as indexed PNG plus exact pixel indices; crest crops, original palette, portrait parts, bitmap fonts |
|
||||
| Audio and optional art | Four original audio containers with chunk descriptors; optional FLI/FLC animation and WAPPEN.LBM when present |
|
||||
| Preservation | Exact master-database bytes, named auxiliary tables/pools, original and effective data regions, resource metadata and CRC32 inventory |
|
||||
|
||||
`x-legacy/import-report.json` records warnings and outstanding mappings. Staff,
|
||||
contracts and finance tables are empty: their initialized values are created
|
||||
by career setup, rather than supplied as complete records by the master database.
|
||||
Stadium names are exported without invented owners or capacities. Squad rows are
|
||||
preserved as legacy rows, not claimed to be shirt numbers. A source player name
|
||||
is kept whole in `name.last`; the importer does not guess first/last-name splits.
|
||||
A source database does **not** contain ready-made human-manager finances,
|
||||
contracts or stadium capacities. Those depend on the selected club, game level,
|
||||
mode and random seeds. The world specifies their initialization rather than
|
||||
inventing a balance, contract term or stadium owner. Imported player attributes
|
||||
are the master seeds; the existing Classic initialization changes ratings and
|
||||
ages and can shuffle club draw positions. This consumes no RNG during import.
|
||||
|
||||
Exact birth dates are unknown. A player instead carries
|
||||
`age_at_start: {"years": 22, "on": "2026-07-01"}`. This is an explicit alternative
|
||||
to `born`, not an assumed birthday. Attribute scales are the stored scales:
|
||||
form, technique, condition and bonus 0–127; skills 0–3; display strength 0–99.
|
||||
`bmh-classic@1` in `world/rules.json` declares those scales and marks strength as
|
||||
derived. These are master seeds, before career initialization varies ratings,
|
||||
rewrites nationality fields or shuffles league participants. No career is
|
||||
started and no random stream is consumed during import.
|
||||
Player `appearance` is computed from the **raw legacy byte name**, before Unicode
|
||||
conversion. It freezes the background and five layer indices once. Name overlays
|
||||
must retain this field. The imported set stores individual transparent parts and
|
||||
placement metadata; composed player faces are never stored. Packed atlas parts
|
||||
which cross a source row boundary retain their original pixels.
|
||||
|
||||
### Identifiers and edition mappings
|
||||
The effective data use OpenBMH's existing supported rule profile. Unpatched
|
||||
source data are preserved separately, including Football Limited's native data
|
||||
segment. Neither copy includes a DOS header, executable code or relocation
|
||||
instructions. `x-classic` is a documented compatibility bridge, not a claim that
|
||||
the current address-based engine has already been replaced.
|
||||
|
||||
Ids derive from source identity slots, not names: `club:00000`, `player:00000`,
|
||||
`stadium:00000`. National teams use `nt:<nation key>`. Recognized geographic
|
||||
aliases get ISO nation keys (England/Scotland/Wales/Northern Ireland use private
|
||||
football-association keys). Unrecognized or duplicate labels get
|
||||
`nation:x-legacy-<index>` with confederation `other` and a warning. Foreign clubs
|
||||
whose nation has not been decoded refer to `nation:x-legacy-unassigned`.
|
||||
The source index always remains in `x-legacy`.
|
||||
## Stable identities and original encodings
|
||||
|
||||
| Source leagues | German | Football Limited |
|
||||
|---|---|---|
|
||||
| 0, 1 | Tiers 1, 2; 18 clubs each | Tiers 1, 2; 20 clubs each |
|
||||
| 2, 3 | Parallel tier 3, ids ending `-3-a` / `-3-b`; 18 each | Tiers 3, 4; 20 each |
|
||||
| 4 | Tier 4; 18 clubs | Tier 5; 10 clubs, `played: false`, no fixture generator |
|
||||
| 5–8 | Four 12-club leagues, using nation slots 1–4 | Same, with the English database's nation-slot order |
|
||||
| 138–167 | Named amateur-pool slots | Only named slots become entities; unnamed slots remain in the source data |
|
||||
| 168–356 | Foreign teams without squads | Same |
|
||||
| 357–418 | National teams / nationality labels | Same |
|
||||
IDs derive from master identity slots: `club:00000`, `player:00000`,
|
||||
`stadium:00000`; national teams use `nt:<nation-key>`. Recognized countries get
|
||||
ISO keys, with private association keys for England/Scotland/Wales/Northern
|
||||
Ireland. Unrecognized/duplicate country labels retain `nation:x-legacy-<index>`
|
||||
and a report warning, preserving modded or historical identities.
|
||||
|
||||
Foreign strength bytes encode a band and style flags, not a 0–255 rating. They
|
||||
stay in `x-legacy.strength_code` until a typed interpretation is implemented.
|
||||
Fixture tables store home/away **draw-position pairs**, not final shuffled
|
||||
career fixtures. Calendar words remain source day offsets; competition options
|
||||
and weekday alignment have not run. Promotion and European-place bytes are
|
||||
retained as inputs, without pretending that cup qualifications have been mapped.
|
||||
Foreign club indices 168–356 form 27 blocks of seven teams corresponding to
|
||||
nation slots 5–31. The nine league ranges retain their edition-specific sizes:
|
||||
German 18/18/18/18/18 and four 12-team leagues; English 20/20/20/20/10 and four
|
||||
12-team leagues. The English fifth division is an unplayed pool; no ten-team
|
||||
fixture generator is invented. Unnamed English amateur slots remain in the
|
||||
preserved source rather than becoming fabricated clubs.
|
||||
|
||||
The existing executable loaders apply OpenBMH's supported rule profile, and the
|
||||
English loader translates FLTD data into the common address space. The manifest
|
||||
records `rule_profile: openbmh-supported`; this tool does **not** claim an
|
||||
unmodified dump of every original edition's rules. No executable is included in
|
||||
the OBW file.
|
||||
Text follows ISO 646-DE substitutions and preserves extended bytes as Latin-1
|
||||
Unicode code points; raw bytes remain available. Player names are kept whole in
|
||||
`name.last`, without guessing first/last-name splits. Fixture tables describe
|
||||
draw positions; qualified participants and final fixtures are resolved at the
|
||||
same initialization phase as in the Classic engine.
|
||||
|
||||
### Text and rights
|
||||
## Validation and verification
|
||||
|
||||
Text follows the existing ISO 646-DE substitutions. Extended bytes are preserved
|
||||
as Latin-1 Unicode code points and original hexadecimal bytes; control/layout
|
||||
codes remain available in the legacy text table. The local gettext catalogue
|
||||
uses stable `legacy.text.<index>` message ids with `legacy-text` context. It is
|
||||
a preservation layer, not a completed translation of the modern interface.
|
||||
`--validate` checks the profile, versions, safe paths, unique entity/asset IDs,
|
||||
core references, squad/stage counts, complete cup bindings, contract ownership,
|
||||
initialization contract, media shapes, portrait indices, resource files and the
|
||||
inventory before accepting a world. ZIP and directory readers enforce size
|
||||
limits; directory symlinks and injected `state/` content are rejected. CRC32
|
||||
catches accidental damage; it is not a signature or proof of trustworthy content.
|
||||
This is the Classic profile validator, not a general competition engine or a full
|
||||
JSON Schema implementation. Draft 2020-12 schemas are provided for external tools.
|
||||
|
||||
Imported names and texts retain their original ownership. Keep the resulting
|
||||
world on your machine; the importer does not grant permission to distribute it.
|
||||
The public repository contains only implementation, schemas and synthetic tests.
|
||||
`obw_import_tests` uses synthetic data to cover both editions, binary round trips,
|
||||
frozen appearances, malformed input and damaged payloads. With `BMH_DATA`,
|
||||
`obw_classic_installation_tests` imports an installation, writes/reopens its ZIP,
|
||||
reconstructs the startup inputs without reading the source again, and compares
|
||||
first-season initialization bytes and both RNG streams. It also compares data
|
||||
regions, atlas pixels, palette, fonts and audio against the source. The same test
|
||||
can be run with a Football Limited directory as its argument. It does not test
|
||||
OBW integration in a released client or a complete played season.
|
||||
|
||||
## Validation and remaining work
|
||||
## Partial development export
|
||||
|
||||
The tool checks required documents, table versions, duplicate identities,
|
||||
cross-table team/nation references, stage participant counts, fixture rows,
|
||||
source squad ownership and supported edition sizes before publishing output.
|
||||
Malformed/truncated input is an error; it does not substitute synthetic game
|
||||
content. `obw_import_tests` covers synthetic German/English mappings, legacy
|
||||
reader input, archive/directory round trips and rejected inputs.
|
||||
`--database-only` deliberately retains the previous `legacy-database-v1` export
|
||||
for database investigations without media. Its manifest remains
|
||||
`playable: false`, requires `import:legacy-database-v1`, and its report lists gaps.
|
||||
It is **not** one of the completed Classic mods. Default imports never silently
|
||||
fall back to this mode.
|
||||
|
||||
Still to implement: full cup definitions/qualification and dated calendars,
|
||||
complete rule mappings, initialized finances/contracts/staff/stadiums, asset
|
||||
conversion, `.FBM` to `.obs`, a general OBW reader/validator and the 0.2 engine
|
||||
adapter. First-season equivalence and save continuation regressions only become
|
||||
possible when that adapter exists; the first converter does not claim them.
|
||||
## Rights and excluded data
|
||||
|
||||
All imported content remains local and retains its original ownership. Do not
|
||||
publish generated worlds or assets without appropriate rights. Public tests and
|
||||
schemas contain only independently authored implementation and synthetic data.
|
||||
|
||||
There is **no savegame converter**. `.FBM`, personal `.EIN`, `SOUND.CFG`, high
|
||||
scores, backups, editor/program executables and manuals are not imported.
|
||||
Manager choices and career RNG state belong to a new game or later `.obs` save,
|
||||
not to this installation conversion.
|
||||
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"$id": "https://raw.githubusercontent.com/Weyoune/openbmh/main/docs/formats/obw/schema/1.0/asset-index.json",
|
||||
"properties": {
|
||||
"schema": {
|
||||
"const": "asset-index@1.0"
|
||||
},
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"key": {
|
||||
"type": "string",
|
||||
"pattern": "^asset:"
|
||||
},
|
||||
"files": {
|
||||
"type": "object",
|
||||
"minProperties": 1,
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"source": {
|
||||
"type": "string"
|
||||
},
|
||||
"author": {
|
||||
"type": "string"
|
||||
},
|
||||
"license": {
|
||||
"const": "local-import-only"
|
||||
},
|
||||
"kind": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"key",
|
||||
"files",
|
||||
"source",
|
||||
"author",
|
||||
"license",
|
||||
"kind"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"schema",
|
||||
"items"
|
||||
],
|
||||
"$comment": "SPDX-License-Identifier: GPL-3.0-only; legacy database and Classic installation profiles."
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"$id": "https://raw.githubusercontent.com/Weyoune/openbmh/main/docs/formats/obw/schema/1.0/classic-inventory.json",
|
||||
"properties": {
|
||||
"schema": {
|
||||
"const": "classic-inventory@1.0"
|
||||
},
|
||||
"entries": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string"
|
||||
},
|
||||
"bytes": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"crc32": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 4294967295
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"path",
|
||||
"bytes",
|
||||
"crc32"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"schema",
|
||||
"entries"
|
||||
],
|
||||
"$comment": "SPDX-License-Identifier: GPL-3.0-only; legacy database and Classic installation profiles."
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"$comment": "SPDX-License-Identifier: GPL-3.0-only; Classic installation content.",
|
||||
"$id": "https://raw.githubusercontent.com/Weyoune/openbmh/main/docs/formats/obw/schema/1.0/classic-palette.json",
|
||||
"properties": {
|
||||
"schema": {
|
||||
"const": "classic-palette@1.0"
|
||||
},
|
||||
"argb": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 4294967295
|
||||
},
|
||||
"minItems": 256,
|
||||
"maxItems": 256
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"schema",
|
||||
"argb"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"$comment": "SPDX-License-Identifier: GPL-3.0-only; Classic installation content.",
|
||||
"$id": "https://raw.githubusercontent.com/Weyoune/openbmh/main/docs/formats/obw/schema/1.0/classic-resources.json",
|
||||
"properties": {
|
||||
"schema": {
|
||||
"const": "classic-resources@1.0"
|
||||
},
|
||||
"images": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"width": {
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
"maximum": 65535
|
||||
},
|
||||
"height": {
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
"maximum": 65535
|
||||
},
|
||||
"pixels": {
|
||||
"type": "string"
|
||||
},
|
||||
"png": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"width",
|
||||
"height",
|
||||
"pixels",
|
||||
"png"
|
||||
]
|
||||
}
|
||||
},
|
||||
"fonts": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"height": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"baseline": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"nominal_width": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"flags": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"lo_char": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"hi_char": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"modulo": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"bitmap": {
|
||||
"type": "string"
|
||||
},
|
||||
"glyphs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"bit_offset": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"bit_width": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"advance": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"bit_offset",
|
||||
"bit_width",
|
||||
"advance"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"height",
|
||||
"baseline",
|
||||
"nominal_width",
|
||||
"flags",
|
||||
"lo_char",
|
||||
"hi_char",
|
||||
"modulo",
|
||||
"glyphs",
|
||||
"bitmap"
|
||||
]
|
||||
},
|
||||
"minItems": 2,
|
||||
"maxItems": 2
|
||||
},
|
||||
"audio": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"path": {
|
||||
"type": "string"
|
||||
},
|
||||
"codec": {
|
||||
"const": "original-alptraum@1"
|
||||
},
|
||||
"chunks": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"offset": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"size": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"offset",
|
||||
"size"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"path",
|
||||
"codec",
|
||||
"chunks"
|
||||
]
|
||||
},
|
||||
"minItems": 4,
|
||||
"maxItems": 4
|
||||
},
|
||||
"optional": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"path": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"path"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"schema",
|
||||
"images",
|
||||
"fonts",
|
||||
"audio",
|
||||
"optional"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"$id": "https://raw.githubusercontent.com/Weyoune/openbmh/main/docs/formats/obw/schema/1.0/classic-startup.json",
|
||||
"properties": {
|
||||
"schema": {
|
||||
"const": "classic-startup@1.0"
|
||||
},
|
||||
"layout": {
|
||||
"const": "openbmh-classic-layout@1"
|
||||
},
|
||||
"mod": {
|
||||
"enum": [
|
||||
"BMH-classic",
|
||||
"FLTD-classic"
|
||||
]
|
||||
},
|
||||
"english": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"rule_profile": {
|
||||
"const": "openbmh-supported@1"
|
||||
},
|
||||
"data_regions": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"base": {
|
||||
"type": "integer"
|
||||
},
|
||||
"size": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
},
|
||||
"path": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"base",
|
||||
"size",
|
||||
"path"
|
||||
]
|
||||
},
|
||||
"minItems": 1,
|
||||
"maxItems": 2
|
||||
},
|
||||
"source_regions": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"base": {
|
||||
"type": "integer"
|
||||
},
|
||||
"size": {
|
||||
"type": "integer",
|
||||
"minimum": 1
|
||||
},
|
||||
"path": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"base",
|
||||
"size",
|
||||
"path"
|
||||
]
|
||||
},
|
||||
"minItems": 1,
|
||||
"maxItems": 2
|
||||
},
|
||||
"desktop_seed": {
|
||||
"type": "string"
|
||||
},
|
||||
"formation_seed": {
|
||||
"type": "string"
|
||||
},
|
||||
"text_blob": {
|
||||
"type": "string"
|
||||
},
|
||||
"initializers": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"minItems": 8,
|
||||
"maxItems": 8
|
||||
},
|
||||
"runtime_inputs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"rng": {
|
||||
"type": "object"
|
||||
},
|
||||
"embedded_literals": {
|
||||
"type": "array",
|
||||
"minItems": 4,
|
||||
"maxItems": 4,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"address": {
|
||||
"type": "integer"
|
||||
},
|
||||
"bytes_hex": {
|
||||
"type": "string",
|
||||
"pattern": "^(?:[0-9a-f]{2})+$"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"address",
|
||||
"bytes_hex"
|
||||
]
|
||||
}
|
||||
},
|
||||
"source_literals": {
|
||||
"type": "array",
|
||||
"minItems": 4,
|
||||
"maxItems": 4,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"address": {
|
||||
"type": "integer"
|
||||
},
|
||||
"bytes_hex": {
|
||||
"type": "string",
|
||||
"pattern": "^(?:[0-9a-f]{2})+$"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"address",
|
||||
"bytes_hex"
|
||||
]
|
||||
}
|
||||
},
|
||||
"text_header": {
|
||||
"type": "array",
|
||||
"minItems": 7,
|
||||
"maxItems": 7,
|
||||
"items": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 255
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"schema",
|
||||
"layout",
|
||||
"mod",
|
||||
"english",
|
||||
"rule_profile",
|
||||
"data_regions",
|
||||
"source_regions",
|
||||
"desktop_seed",
|
||||
"formation_seed",
|
||||
"text_blob",
|
||||
"initializers",
|
||||
"runtime_inputs",
|
||||
"rng",
|
||||
"embedded_literals",
|
||||
"source_literals",
|
||||
"text_header"
|
||||
],
|
||||
"$comment": "SPDX-License-Identifier: GPL-3.0-only; legacy database and Classic installation profiles."
|
||||
}
|
||||
@@ -19,7 +19,14 @@
|
||||
"$ref": "common.json#/$defs/localized"
|
||||
},
|
||||
"type": {
|
||||
"const": "league"
|
||||
"enum": [
|
||||
"league",
|
||||
"cup",
|
||||
"club_international",
|
||||
"national_team",
|
||||
"friendly",
|
||||
"indoor"
|
||||
]
|
||||
},
|
||||
"nation": {
|
||||
"$ref": "common.json#/$defs/nation_id"
|
||||
@@ -40,12 +47,18 @@
|
||||
"type": "string"
|
||||
},
|
||||
"format": {
|
||||
"const": "league"
|
||||
"enum": [
|
||||
"league",
|
||||
"groups",
|
||||
"knockout",
|
||||
"final",
|
||||
"playoff"
|
||||
]
|
||||
},
|
||||
"teams": {
|
||||
"type": "integer",
|
||||
"minimum": 4,
|
||||
"maximum": 24
|
||||
"minimum": 0,
|
||||
"maximum": 255
|
||||
},
|
||||
"legs": {
|
||||
"type": "integer",
|
||||
@@ -60,20 +73,46 @@
|
||||
"slots": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"teams": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "common.json#/$defs/team_id"
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"teams": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "common.json#/$defs/team_id"
|
||||
},
|
||||
"uniqueItems": true
|
||||
}
|
||||
},
|
||||
"uniqueItems": true
|
||||
"required": [
|
||||
"teams"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"resolver": {
|
||||
"const": "classic-entry@1"
|
||||
},
|
||||
"entry": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 35
|
||||
},
|
||||
"count": {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 255
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"resolver",
|
||||
"entry",
|
||||
"count"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"teams"
|
||||
],
|
||||
"additionalProperties": true
|
||||
]
|
||||
},
|
||||
"minItems": 1
|
||||
}
|
||||
@@ -94,12 +133,27 @@
|
||||
"id",
|
||||
"name",
|
||||
"type",
|
||||
"nation",
|
||||
"tier",
|
||||
"played",
|
||||
"stages"
|
||||
],
|
||||
"additionalProperties": true
|
||||
"additionalProperties": true,
|
||||
"allOf": [
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "league"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"required": [
|
||||
"nation",
|
||||
"tier"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -108,5 +162,5 @@
|
||||
"items"
|
||||
],
|
||||
"additionalProperties": true,
|
||||
"$comment": "SPDX-License-Identifier: GPL-3.0-only; initial legacy-database-v1 conversion profile."
|
||||
"$comment": "SPDX-License-Identifier: GPL-3.0-only; legacy database and Classic installation profiles."
|
||||
}
|
||||
@@ -69,8 +69,17 @@
|
||||
"additionalProperties": true
|
||||
},
|
||||
"requires": {
|
||||
"const": [
|
||||
"import:legacy-database-v1"
|
||||
"oneOf": [
|
||||
{
|
||||
"const": [
|
||||
"import:legacy-database-v1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"const": [
|
||||
"runtime:classic-v1"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"extensions": {
|
||||
@@ -93,27 +102,76 @@
|
||||
}
|
||||
},
|
||||
"x-import": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"profile": {
|
||||
"const": "legacy-database-v1"
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"profile": {
|
||||
"const": "legacy-database-v1"
|
||||
},
|
||||
"playable": {
|
||||
"const": false
|
||||
},
|
||||
"rule_profile": {
|
||||
"const": "openbmh-supported"
|
||||
},
|
||||
"default_attribute_set": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"profile",
|
||||
"playable",
|
||||
"rule_profile"
|
||||
],
|
||||
"additionalProperties": true
|
||||
},
|
||||
"playable": {
|
||||
"const": false
|
||||
},
|
||||
"rule_profile": {
|
||||
"const": "openbmh-supported"
|
||||
},
|
||||
"default_attribute_set": {
|
||||
"type": "string"
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"profile": {
|
||||
"const": "classic-installation-v1"
|
||||
},
|
||||
"content_complete": {
|
||||
"const": true
|
||||
},
|
||||
"runtime": {
|
||||
"const": "runtime:classic-v1"
|
||||
},
|
||||
"rule_profile": {
|
||||
"const": "openbmh-supported@1"
|
||||
},
|
||||
"source_rules_preserved": {
|
||||
"const": true
|
||||
},
|
||||
"default_attribute_set": {
|
||||
"const": "bmh-classic@1"
|
||||
},
|
||||
"default_portrait_set": {
|
||||
"const": "bmh-classic@1"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"profile",
|
||||
"content_complete",
|
||||
"runtime",
|
||||
"rule_profile",
|
||||
"source_rules_preserved",
|
||||
"default_attribute_set",
|
||||
"default_portrait_set"
|
||||
],
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"profile",
|
||||
"playable",
|
||||
"rule_profile"
|
||||
],
|
||||
"additionalProperties": true
|
||||
]
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"mod": {
|
||||
"enum": [
|
||||
"BMH-classic",
|
||||
"FLTD-classic"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -134,5 +192,44 @@
|
||||
"x-import"
|
||||
],
|
||||
"additionalProperties": true,
|
||||
"$comment": "SPDX-License-Identifier: GPL-3.0-only; initial legacy-database-v1 conversion profile."
|
||||
"$comment": "SPDX-License-Identifier: GPL-3.0-only; legacy database and Classic installation profiles.",
|
||||
"allOf": [
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"requires": {
|
||||
"const": [
|
||||
"runtime:classic-v1"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"required": [
|
||||
"id",
|
||||
"mod"
|
||||
],
|
||||
"properties": {
|
||||
"x-import": {
|
||||
"properties": {
|
||||
"profile": {
|
||||
"const": "classic-installation-v1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"else": {
|
||||
"properties": {
|
||||
"x-import": {
|
||||
"properties": {
|
||||
"profile": {
|
||||
"const": "legacy-database-v1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"$id": "https://raw.githubusercontent.com/Weyoune/openbmh/main/docs/formats/obw/schema/1.0/portrait-set.json",
|
||||
"properties": {
|
||||
"schema": {
|
||||
"const": "portrait-set@1.0"
|
||||
},
|
||||
"id": {
|
||||
"const": "bmh-classic@1"
|
||||
},
|
||||
"width": {
|
||||
"const": 38
|
||||
},
|
||||
"height": {
|
||||
"const": 38
|
||||
},
|
||||
"transparent_index": {
|
||||
"const": 0
|
||||
},
|
||||
"backgrounds": {
|
||||
"type": "array",
|
||||
"minItems": 4,
|
||||
"maxItems": 4,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"asset": {
|
||||
"type": "string"
|
||||
},
|
||||
"x": {
|
||||
"type": "integer"
|
||||
},
|
||||
"y": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"asset",
|
||||
"x",
|
||||
"y"
|
||||
]
|
||||
}
|
||||
},
|
||||
"layers": {
|
||||
"type": "array",
|
||||
"minItems": 5,
|
||||
"maxItems": 5,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"x": {
|
||||
"type": "integer"
|
||||
},
|
||||
"y": {
|
||||
"type": "integer"
|
||||
},
|
||||
"parts": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"x",
|
||||
"y",
|
||||
"parts"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"schema",
|
||||
"id",
|
||||
"width",
|
||||
"height",
|
||||
"backgrounds",
|
||||
"layers",
|
||||
"transparent_index"
|
||||
],
|
||||
"$comment": "SPDX-License-Identifier: GPL-3.0-only; legacy database and Classic installation profiles."
|
||||
}
|
||||
@@ -19,9 +19,11 @@ OpenBMH reconstructs the Bundesliga Manager Hattrick engine in C++20. The graphi
|
||||
- Setup ignores mouse releases without a matching press on that screen, so
|
||||
window activation cannot toggle the initial league/national-team selection
|
||||
through that input path ([#10](https://github.com/Weyoune/openbmh/issues/10)).
|
||||
- Source builds include the standalone [OBW installation converter](../../formats/obw/import.md).
|
||||
It produces intermediate database conversions; game integration remains
|
||||
planned for 0.2.
|
||||
- The standalone [OBW installation converter](../../formats/obw/import.md) builds
|
||||
complete `BMH-classic` / `FLTD-classic` installation-content worlds, including
|
||||
graphics, fonts, audio, frozen player portrait recipes and versioned Classic
|
||||
startup data. Subsequent CI packages include `openbmh_import`. The 0.2 runtime
|
||||
adapter and savegame conversion remain separate work.
|
||||
|
||||
These changes require a build from the updated source. The tagged 0.1.2 package
|
||||
does not contain these subsequent corrections.
|
||||
|
||||
+3
-3
@@ -36,14 +36,14 @@ void save_image(const LeImage& image, const std::filesystem::path& path) {
|
||||
if (!file) throw FormatError("cannot write the OpenBMH image");
|
||||
}
|
||||
|
||||
LeImage load_le(const std::filesystem::path& path) {
|
||||
LeImage load_le(const std::filesystem::path& path, bool apply_supported_rules) {
|
||||
const Bytes raw = read_file(path);
|
||||
if (raw.size() >= sizeof kImageMagic + 8 && std::equal(kImageMagic, kImageMagic + sizeof kImageMagic, raw.begin())) {
|
||||
const auto word = [&](size_t at) { return uint32_t(raw[at] | raw[at + 1] << 8 | raw[at + 2] << 16) | uint32_t(raw[at + 3]) << 24; };
|
||||
const uint32_t base = word(sizeof kImageMagic), size = word(sizeof kImageMagic + 4);
|
||||
if (raw.size() != sizeof kImageMagic + 8 + size_t(size)) throw FormatError("OpenBMH image: wrong size");
|
||||
LeImage img = LeImage::from_bytes(base, Bytes(raw.begin() + sizeof kImageMagic + 8, raw.end()));
|
||||
apply_rule_base(img);
|
||||
if (apply_supported_rules) apply_rule_base(img);
|
||||
return img;
|
||||
}
|
||||
auto u8 = [&](size_t o) -> uint32_t {
|
||||
@@ -133,7 +133,7 @@ LeImage load_le(const std::filesystem::path& path) {
|
||||
}
|
||||
}
|
||||
}
|
||||
apply_rule_base(img);
|
||||
if (apply_supported_rules) apply_rule_base(img);
|
||||
return img;
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -44,7 +44,7 @@ public:
|
||||
}
|
||||
const Bytes& bytes() const { return bytes_; }
|
||||
|
||||
friend LeImage load_le(const std::filesystem::path& path);
|
||||
friend LeImage load_le(const std::filesystem::path& path, bool apply_supported_rules);
|
||||
|
||||
private:
|
||||
uint32_t base_ = 0;
|
||||
@@ -55,7 +55,9 @@ private:
|
||||
// Throws FormatError for files that are not LE executables or use external fixups.
|
||||
// A German BMH.EXE is loaded with the OpenBMH rule base applied (formats/rule_base.hpp):
|
||||
// every edition plays by the supported rule profile rule values.
|
||||
LeImage load_le(const std::filesystem::path& path);
|
||||
// The installation importer passes false to preserve source tables separately;
|
||||
// ordinary engine callers retain the default behavior.
|
||||
LeImage load_le(const std::filesystem::path& path, bool apply_supported_rules = true);
|
||||
|
||||
// The OpenBMH image format: "OPENBMH-IMAGE" NUL, u32 base, u32 size, the bytes. load_le()
|
||||
// reads it as well, so a translated image can stand in for BMH.exe in a data directory.
|
||||
|
||||
+4
-1
@@ -35,7 +35,10 @@ std::string pool_string(const Bytes& pool, size_t offset) {
|
||||
} // namespace
|
||||
|
||||
Database load_database(const std::filesystem::path& path, const DbCounts& c) {
|
||||
Bytes d = read_file(path);
|
||||
return decode_database(read_file(path), c);
|
||||
}
|
||||
|
||||
Database decode_database(const Bytes& d, const DbCounts& c) {
|
||||
Reader r{d};
|
||||
Bytes lens = r.take(8);
|
||||
size_t len_clubs = le16(lens, 0), len_players = le16(lens, 2), len_refs = le16(lens, 4), len_stadiums = le16(lens, 6);
|
||||
|
||||
@@ -74,5 +74,6 @@ struct Database {
|
||||
};
|
||||
|
||||
Database load_database(const std::filesystem::path& path, const DbCounts& counts = {});
|
||||
Database decode_database(const Bytes& data, const DbCounts& counts = {});
|
||||
|
||||
} // namespace bmh
|
||||
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
add_library(bmh_obw STATIC obw.cpp ../cli/json.cpp)
|
||||
add_library(bmh_obw STATIC obw.cpp classic.cpp assets.cpp ../cli/json.cpp ../audio/container.cpp)
|
||||
target_include_directories(bmh_obw PUBLIC ..)
|
||||
target_link_libraries(bmh_obw PUBLIC bmhlaunch PRIVATE bmh_miniz)
|
||||
add_executable(openbmh_import main.cpp)
|
||||
@@ -11,7 +11,14 @@ if(MSVC)
|
||||
target_compile_options(bmh_obw PRIVATE /W4 /utf-8)
|
||||
target_compile_options(openbmh_import PRIVATE /W4 /utf-8)
|
||||
target_compile_options(obw_import_tests PRIVATE /W4 /utf-8)
|
||||
else()
|
||||
target_compile_options(bmh_obw PRIVATE -Wall -Wextra)
|
||||
endif()
|
||||
add_test(NAME obw_import_tests COMMAND obw_import_tests)
|
||||
# A separate component: existing 0.1 runtime packages retain their two products.
|
||||
install(TARGETS openbmh_import RUNTIME DESTINATION . COMPONENT ImportTools)
|
||||
add_executable(obw_classic_installation_tests ../../tests/obw_classic_installation_tests.cpp)
|
||||
target_link_libraries(obw_classic_installation_tests PRIVATE bmh_obw)
|
||||
if(MSVC)
|
||||
target_compile_options(obw_classic_installation_tests PRIVATE /W4 /utf-8)
|
||||
endif()
|
||||
bmh_add_data_test(NAME obw_classic_installation_tests COMMAND obw_classic_installation_tests "${BMH_DATA}")
|
||||
install(TARGETS openbmh_import RUNTIME DESTINATION . COMPONENT Runtime)
|
||||
@@ -0,0 +1,279 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "import/assets.hpp"
|
||||
#include "import/detail.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "launch/game_data.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
#include "audio/container.hpp"
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <limits>
|
||||
|
||||
namespace bmh::obw {
|
||||
namespace {
|
||||
using namespace detail;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
void be32(std::string& out, uint32_t value) {
|
||||
for (int shift = 24; shift >= 0; shift -= 8) out += char(value >> shift);
|
||||
}
|
||||
void chunk(std::string& out, const char* name, const std::string& payload) {
|
||||
be32(out, uint32_t(payload.size()));
|
||||
const auto start = out.size();
|
||||
out.append(name, 4);
|
||||
out += payload;
|
||||
be32(out, crc(out.substr(start)));
|
||||
}
|
||||
std::string png(const Image& image, const Palette& palette, bool transparent) {
|
||||
std::string out("\x89PNG\r\n\x1a\n", 8), header;
|
||||
be32(header, uint32_t(image.width)); be32(header, uint32_t(image.height));
|
||||
header.append("\x08\x03\x00\x00\x00", 5); // indexed PNG, exact palette indices
|
||||
chunk(out, "IHDR", header);
|
||||
std::string colors;
|
||||
for (const uint32_t color : palette.argb)
|
||||
for (int shift : {16, 8, 0}) colors += char(color >> shift);
|
||||
chunk(out, "PLTE", colors);
|
||||
if (transparent) chunk(out, "tRNS", std::string(1, '\0'));
|
||||
std::string rows;
|
||||
for (int y = 0; y < image.height; ++y) {
|
||||
rows += '\0';
|
||||
rows.append(reinterpret_cast<const char*>(image.pixels.data() + size_t(y) * image.width), size_t(image.width));
|
||||
}
|
||||
mz_ulong size = mz_compressBound(static_cast<mz_ulong>(rows.size()));
|
||||
std::string compressed(size, '\0');
|
||||
if (mz_compress2(reinterpret_cast<unsigned char*>(compressed.data()), &size,
|
||||
reinterpret_cast<const unsigned char*>(rows.data()), static_cast<mz_ulong>(rows.size()), MZ_BEST_COMPRESSION) != MZ_OK)
|
||||
fail("cannot compress PNG");
|
||||
compressed.resize(size);
|
||||
chunk(out, "IDAT", compressed); chunk(out, "IEND", "");
|
||||
return out;
|
||||
}
|
||||
fs::path required(const fs::path& root, const std::string& name) {
|
||||
const auto path = launch::find_file(root, name);
|
||||
if (!path || !fs::is_regular_file(*path) || fs::is_symlink(fs::symlink_status(*path))) fail("missing regular resource: " + name);
|
||||
return *path;
|
||||
}
|
||||
std::string lower(std::string value) {
|
||||
for (char& c : value) c = char(std::tolower(static_cast<unsigned char>(c)));
|
||||
return value;
|
||||
}
|
||||
bool numeric(const std::string& name) {
|
||||
return !name.empty() && std::all_of(name.begin(), name.end(), [](unsigned char c) { return c >= '0' && c <= '9'; });
|
||||
}
|
||||
// Source sprites use a linear packed stride; a feature may cross a row edge.
|
||||
Image extract(const Image& atlas, int sx, int sy, int width, int height) {
|
||||
if (sx < 0 || sy < 0 || width <= 0 || height <= 0 || width > 1024 || height > 1024) fail("invalid sprite geometry");
|
||||
Image out(width, height);
|
||||
for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) {
|
||||
const auto at = size_t(sy + y) * size_t(atlas.width) + size_t(sx + x);
|
||||
if (at >= atlas.pixels.size()) fail("sprite exceeds its packed atlas");
|
||||
out.at(x, y) = atlas.pixels[at];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
J asset(const std::string& key, const std::string& path, const std::string& source, const std::string& kind) {
|
||||
return O{{"key", key}, {"files", O{{"native", path}}}, {"source", source},
|
||||
{"author", "Original installation rights holders"}, {"license", "local-import-only"}, {"kind", kind}};
|
||||
}
|
||||
void image_entry(Documents& out, A& resources, A& index, const std::string& key,
|
||||
const std::string& name, const Image& image, const Palette& palette, bool transparent = false) {
|
||||
const auto base = "assets/classic/images/" + name;
|
||||
out[base + ".png"] = png(image, palette, transparent);
|
||||
out[base + ".pixels"] = binary(image.pixels);
|
||||
resources.emplace_back(O{{"name", name}, {"width", image.width}, {"height", image.height},
|
||||
{"pixels", base + ".pixels"}, {"png", base + ".png"}});
|
||||
index.emplace_back(asset(key, base + ".png", name, "indexed-image"));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
cli::Json portrait_recipe(const std::string& legacy_name, const LeImage& exe) {
|
||||
using namespace detail;
|
||||
// Unsigned overflow and signed source characters deliberately match the UI.
|
||||
uint32_t seed = 0x14344;
|
||||
for (size_t i = 0; i < legacy_name.size(); ++i) seed += int(int8_t(legacy_name[i])) * uint32_t(i) * 10;
|
||||
const auto next = [&](uint32_t maximum) {
|
||||
seed = (seed * 16 + 0xa7) % 4000000;
|
||||
return int(seed * (maximum + 1) / 4000000);
|
||||
};
|
||||
next(100);
|
||||
const int background = next(3);
|
||||
A layers;
|
||||
for (uint32_t layer = 0; layer < 5; ++layer) {
|
||||
const auto count = exe.u8(layout::ClubPlayerDetail_ClubPlayerDetailRedraw_RuntimeField2 + layer);
|
||||
if (!count) fail("portrait layer has no parts");
|
||||
layers.emplace_back(next(uint32_t(count - 1)));
|
||||
}
|
||||
return O{{"set", "bmh-classic@1"}, {"background", background}, {"layers", std::move(layers)}};
|
||||
}
|
||||
|
||||
void import_assets(Documents& out, const std::filesystem::path& root, const Database& db, const LeImage& exe) {
|
||||
using namespace detail;
|
||||
const auto palette = load_palette(required(root, "M3PC.COL"));
|
||||
A colors, index, images, fonts, audio, animations;
|
||||
for (const auto color : palette.argb) colors.emplace_back(int64_t(color));
|
||||
put(out, "assets/classic/palette.json", O{{"schema", "classic-palette@1.0"}, {"argb", std::move(colors)}});
|
||||
std::map<std::string, Image> atlases;
|
||||
for (const char* group : {"KB", "W"}) {
|
||||
const auto folder = launch::find_file(root, group);
|
||||
if (!folder || !fs::is_directory(*folder)) fail(std::string("missing directory: ") + group);
|
||||
std::vector<fs::path> paths;
|
||||
for (const auto& entry : fs::directory_iterator(*folder))
|
||||
if (entry.is_regular_file() && lower(launch::path_to_utf8(entry.path().extension())) == ".vga" &&
|
||||
numeric(launch::path_to_utf8(entry.path().stem()))) paths.push_back(entry.path());
|
||||
std::sort(paths.begin(), paths.end());
|
||||
for (const auto& path : paths) {
|
||||
if (fs::is_symlink(fs::symlink_status(path)) || fs::file_size(path) > 16 * 1024 * 1024) fail("unsafe image input");
|
||||
const auto bytes = read_file(path);
|
||||
if (bytes.size() < 8 || le16(bytes, 0) == 0 || le16(bytes, 2) == 0 ||
|
||||
uint64_t(le16(bytes, 0)) * le16(bytes, 2) > 16 * 1024 * 1024) fail("invalid image dimensions");
|
||||
const auto name = lower(group) + '/' + launch::path_to_utf8(path.stem());
|
||||
if (atlases.contains(name)) fail("duplicate image resource: " + name);
|
||||
auto image = decode_vga(bytes);
|
||||
image_entry(out, images, index, "asset:classic/" + name, name, image, palette);
|
||||
atlases.emplace(name, std::move(image));
|
||||
}
|
||||
}
|
||||
// Crests reference their original database identity, independently of runtime draws.
|
||||
auto clubs = items(out, "clubs");
|
||||
for (auto& club : clubs) {
|
||||
const auto team = size_t(num(get(get(club, "x-legacy"), "team_index")));
|
||||
const int selector = le16(db.raw_club_badge_selectors, team * 2) & 511;
|
||||
const std::string sheet = "w/" + std::to_string(selector >> 3);
|
||||
const bool neutral = (team >= 90 && team < 138) || (team >= 168 && team < 357);
|
||||
const std::string atlas_name = neutral ? "kb/0" : sheet;
|
||||
if (!atlases.contains(atlas_name)) fail("missing crest sheet " + atlas_name);
|
||||
const auto name = "crests/" + std::to_string(team);
|
||||
const auto key = "asset:club/" + str(get(club, "id")).substr(str(get(club, "id")).find(':') + 1) + "/crest";
|
||||
image_entry(out, images, index, key, name, extract(atlases.at(atlas_name), neutral ? 8 : (selector & 7) * 38, 0, 38, 38), palette, true);
|
||||
(*club.object())["crest"] = key;
|
||||
}
|
||||
table(out, "clubs", std::move(clubs));
|
||||
|
||||
const auto portrait = atlases.find("kb/29");
|
||||
if (portrait == atlases.end()) fail("missing player portrait atlas KB/29.VGA");
|
||||
A backgrounds, layers;
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
const auto name = "portraits/background-" + std::to_string(i);
|
||||
const auto key = "asset:portrait/bmh-classic/background/" + std::to_string(i);
|
||||
image_entry(out, images, index, key, name, extract(portrait->second, 108 + i * 38, 168, 38, 38), palette);
|
||||
backgrounds.emplace_back(O{{"asset", key}, {"x", 0}, {"y", 0}});
|
||||
}
|
||||
for (uint32_t layer = 0; layer < 5; ++layer) {
|
||||
int sx = exe.u8(layout::ClubPlayerDetail_DrawPortrait_RuntimeField + layer);
|
||||
int sy = exe.u8(layout::ClubPlayerDetail_DrawPortrait_RuntimeField2 + layer);
|
||||
const int count = exe.u8(layout::ClubPlayerDetail_ClubPlayerDetailRedraw_RuntimeField2 + layer);
|
||||
const int width = exe.u8(layout::ClubPlayerDetail_DrawPortrait_RuntimeField3 + layer);
|
||||
const int height = exe.u8(layout::ClubPlayerDetail_DrawPortrait_RuntimeField4 + layer);
|
||||
if (!count) fail("empty portrait layer");
|
||||
A parts;
|
||||
for (int part = 0; part < count; ++part) {
|
||||
const auto name = "portraits/layer-" + std::to_string(layer) + '-' + std::to_string(part);
|
||||
const auto key = "asset:portrait/bmh-classic/layer/" + std::to_string(layer) + '/' + std::to_string(part);
|
||||
image_entry(out, images, index, key, name, extract(portrait->second, sx, sy, width, height), palette, true);
|
||||
parts.emplace_back(key);
|
||||
sx += width;
|
||||
if (sx > exe.u16(layout::ClubPlayerDetail_DrawPortrait_RuntimeField7 + layer * 2)) {
|
||||
sx = exe.u8(layout::ClubPlayerDetail_DrawPortrait_RuntimeField + layer); sy += height;
|
||||
}
|
||||
}
|
||||
// Destination relative to the 38x38 background at (181,109) in the legacy card.
|
||||
layers.emplace_back(O{{"x", 1 + int(exe.u8(layout::ClubPlayerDetail_DrawPortrait_RuntimeField5 + layer))},
|
||||
{"y", 5 + int(exe.u8(layout::ClubPlayerDetail_DrawPortrait_RuntimeField6 + layer))}, {"parts", std::move(parts)}});
|
||||
}
|
||||
put(out, "assets/portrait-sets/bmh-classic@1/set.json", O{{"schema", "portrait-set@1.0"},
|
||||
{"id", "bmh-classic@1"}, {"width", 38}, {"height", 38}, {"transparent_index", 0},
|
||||
{"backgrounds", std::move(backgrounds)}, {"layers", std::move(layers)}});
|
||||
|
||||
const auto font_dir = launch::find_file(root, "F");
|
||||
if (!font_dir) fail("missing F directory");
|
||||
for (const char* source : {"BMH2.FNT", "BMH3.FNT"}) {
|
||||
const auto font = load_font(required(*font_dir, source));
|
||||
const auto name = lower(source);
|
||||
A glyphs;
|
||||
for (const auto& glyph : font.glyphs) glyphs.emplace_back(O{{"bit_offset", int(glyph.bit_offset)},
|
||||
{"bit_width", int(glyph.bit_width)}, {"advance", int(glyph.advance)}});
|
||||
const auto bitmap = "assets/classic/fonts/" + name + ".bitmap";
|
||||
out[bitmap] = binary(font.bitmap);
|
||||
fonts.emplace_back(O{{"name", name}, {"height", font.height}, {"baseline", font.baseline},
|
||||
{"nominal_width", font.nominal_width}, {"flags", int(font.flags)}, {"lo_char", int(font.lo_char)},
|
||||
{"hi_char", int(font.hi_char)}, {"modulo", font.modulo}, {"glyphs", std::move(glyphs)}, {"bitmap", bitmap}});
|
||||
index.emplace_back(asset("asset:font/classic/" + name, bitmap, std::string("F/") + source, "bitmap-font"));
|
||||
}
|
||||
const auto sound_dir = launch::find_file(root, "S");
|
||||
if (!sound_dir) fail("missing S directory");
|
||||
for (int i = 2000; i <= 2003; ++i) {
|
||||
const auto name = std::to_string(i);
|
||||
const auto bank = read_file(required(*sound_dir, name));
|
||||
openbmh::audio::Container parsed;
|
||||
std::string error;
|
||||
if (!openbmh::audio::parse_container(bank, parsed, error)) fail("audio bank " + name + ": " + error);
|
||||
const auto path = "assets/classic/audio/" + name + ".bank";
|
||||
out[path] = binary(bank);
|
||||
A chunks;
|
||||
for (const auto& c : parsed.chunks) chunks.emplace_back(O{{"id", c.id}, {"offset", int64_t(c.payload_offset)}, {"size", int64_t(c.payload_size)}});
|
||||
audio.emplace_back(O{{"name", name}, {"path", path}, {"codec", "original-alptraum@1"}, {"chunks", std::move(chunks)}});
|
||||
index.emplace_back(asset("asset:audio/classic/" + name, path, "S/" + name, "audio-bank"));
|
||||
}
|
||||
// Preserve optional animation/editor artwork, but never personal options or saves.
|
||||
for (const auto& entry : fs::directory_iterator(root)) {
|
||||
const auto name = lower(launch::path_to_utf8(entry.path().filename()));
|
||||
const auto ext = lower(launch::path_to_utf8(entry.path().extension()));
|
||||
if (!entry.is_regular_file() || (ext != ".fli" && ext != ".flc" && name != "wappen.lbm")) continue;
|
||||
if (entry.is_symlink() || entry.file_size() > 32 * 1024 * 1024) fail("unsafe optional artwork");
|
||||
const auto path = "assets/classic/optional/" + name;
|
||||
out[path] = binary(read_file(entry.path()));
|
||||
animations.emplace_back(O{{"name", name}, {"path", path}});
|
||||
index.emplace_back(asset("asset:classic/optional/" + name, path, name, "legacy-artwork"));
|
||||
}
|
||||
put(out, "assets/classic/resources.json", O{{"schema", "classic-resources@1.0"},
|
||||
{"images", std::move(images)}, {"fonts", std::move(fonts)}, {"audio", std::move(audio)}, {"optional", std::move(animations)}});
|
||||
put(out, "assets/index.json", O{{"schema", "asset-index@1.0"}, {"items", std::move(index)}});
|
||||
}
|
||||
|
||||
void load_assets(const Documents& out, ClassicData& data) {
|
||||
using namespace detail;
|
||||
const auto palette = parse(out, "assets/classic/palette.json");
|
||||
const auto& colors = arr(get(palette, "argb"));
|
||||
if (colors.size() != 256) fail("palette must contain 256 colors");
|
||||
for (size_t i = 0; i < 256; ++i) {
|
||||
const auto color = num(colors[i]);
|
||||
if (color < 0 || color > UINT32_MAX) fail("invalid palette color");
|
||||
data.palette.argb[i] = uint32_t(color);
|
||||
}
|
||||
const auto resources = parse(out, "assets/classic/resources.json");
|
||||
for (const auto& row : arr(get(resources, "images"))) {
|
||||
const auto width = num(get(row, "width")), height = num(get(row, "height"));
|
||||
const auto& pixels = out.at(str(get(row, "pixels")));
|
||||
if (width <= 0 || height <= 0 || width > 65535 || height > 65535 || width * height != int64_t(pixels.size())) fail("image pixel count disagrees with dimensions");
|
||||
Image image(int(width), int(height), 0);
|
||||
image.pixels = bytes(pixels);
|
||||
if (!data.images.emplace(str(get(row, "name")), std::move(image)).second) fail("duplicate indexed image");
|
||||
}
|
||||
for (const auto& row : arr(get(resources, "fonts"))) {
|
||||
Font font;
|
||||
font.height = int(num(get(row, "height"))); font.baseline = int(num(get(row, "baseline")));
|
||||
font.nominal_width = int(num(get(row, "nominal_width"))); font.flags = uint8_t(num(get(row, "flags")));
|
||||
font.lo_char = uint8_t(num(get(row, "lo_char"))); font.hi_char = uint8_t(num(get(row, "hi_char")));
|
||||
font.modulo = int(num(get(row, "modulo"))); font.bitmap = bytes(out.at(str(get(row, "bitmap"))));
|
||||
if (font.height <= 0 || font.modulo <= 0 || int64_t(font.height) * font.modulo != int64_t(font.bitmap.size())) fail("invalid font bitmap");
|
||||
for (const auto& glyph : arr(get(row, "glyphs"))) {
|
||||
const auto offset = num(get(glyph, "bit_offset")), width = num(get(glyph, "bit_width")), advance = num(get(glyph, "advance"));
|
||||
// BMH2's zero-width replacement glyph points beyond the bitmap;
|
||||
// it never dereferences that offset when drawing.
|
||||
if (offset < 0 || offset > UINT16_MAX || width < 0 || width > UINT16_MAX ||
|
||||
(width && offset + width > int64_t(font.modulo) * 8) || advance < INT16_MIN || advance > INT16_MAX) fail("invalid font glyph");
|
||||
font.glyphs.push_back({uint16_t(offset), uint16_t(width), int16_t(advance)});
|
||||
}
|
||||
if (font.glyphs.size() != size_t(int(font.hi_char) - font.lo_char + 2)) fail("invalid font glyph count");
|
||||
if (!data.fonts.emplace(str(get(row, "name")), std::move(font)).second) fail("duplicate font");
|
||||
}
|
||||
for (const auto& row : arr(get(resources, "audio"))) {
|
||||
auto bank = bytes(out.at(str(get(row, "path"))));
|
||||
openbmh::audio::Container parsed;
|
||||
std::string error;
|
||||
if (!openbmh::audio::parse_container(bank, parsed, error)) fail("invalid audio container: " + error);
|
||||
if (!data.audio.emplace(str(get(row, "name")), std::move(bank)).second) fail("duplicate audio bank");
|
||||
}
|
||||
if (!data.images.contains("kb/29") || data.fonts.size() != 2 || data.audio.size() != 4) fail("incomplete classic media");
|
||||
}
|
||||
} // namespace bmh::obw
|
||||
@@ -0,0 +1,11 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "import/classic.hpp"
|
||||
|
||||
namespace bmh::obw {
|
||||
cli::Json portrait_recipe(const std::string& legacy_name, const LeImage& exe);
|
||||
// PNGs retain original resolution. Portrait PARTS are exported, never composed faces.
|
||||
void import_assets(Documents& out, const std::filesystem::path& root,
|
||||
const Database& db, const LeImage& exe);
|
||||
void load_assets(const Documents& out, ClassicData& data);
|
||||
} // namespace bmh::obw
|
||||
@@ -0,0 +1,446 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "import/classic.hpp"
|
||||
#include "import/assets.hpp"
|
||||
#include "import/detail.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "launch/game_data.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <iterator>
|
||||
#include <set>
|
||||
|
||||
namespace bmh::obw {
|
||||
namespace {
|
||||
using namespace detail;
|
||||
namespace fs = std::filesystem;
|
||||
constexpr const char* profile = "classic-installation-v1";
|
||||
constexpr const char* feature = "runtime:classic-v1";
|
||||
constexpr const char* layout_id = "openbmh-classic-layout@1";
|
||||
const A initializers{"classic-load-seeds@1", "classic-player-ratings@1", "classic-pending-offers@1",
|
||||
"classic-markets-and-moods@1", "classic-free-agents@1", "classic-setup-options@1",
|
||||
"classic-confirm-managers@1", "classic-season-setup@1"};
|
||||
const A runtime_inputs{"game_rng_seed", "watcom_rng_seed", "managers", "game_level", "mode", "duration", "competition_options"};
|
||||
struct Literal { const char* name; uint32_t address, size; };
|
||||
// These four read-only labels share an LE code object. Extract the bounded
|
||||
// strings individually, never the containing executable object/instructions.
|
||||
constexpr Literal literals[] = {
|
||||
{"free_kick_taker", layout::FreeKickTakerLabel, 9}, {"penalty_taker", layout::PenaltyTakerLabel, 9},
|
||||
{"corner_taker", layout::CornerTakerLabel, 8}, {"automatic_takers", layout::AutomaticTakersLabel, 5}};
|
||||
|
||||
A literal_data(const LeImage& exe) {
|
||||
constexpr char digits[] = "0123456789abcdef";
|
||||
A values;
|
||||
for (const auto& literal : literals) {
|
||||
std::string hex;
|
||||
bool terminated = false;
|
||||
for (uint32_t i = 0; i < literal.size; ++i) {
|
||||
const auto c = exe.u8(literal.address + i);
|
||||
hex += digits[c >> 4]; hex += digits[c & 15];
|
||||
if (c == 0) { terminated = true; break; }
|
||||
if (c < 32 || c > 126) fail("invalid bounded embedded text literal");
|
||||
}
|
||||
if (!terminated) fail("unterminated bounded embedded text literal");
|
||||
values.emplace_back(O{{"name", literal.name}, {"address", int(literal.address)}, {"bytes_hex", hex}});
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
Bytes required(const fs::path& root, const std::string& name, size_t size) {
|
||||
const auto file = launch::find_file(root, name);
|
||||
if (!file || !fs::is_regular_file(*file) || fs::is_symlink(fs::symlink_status(*file)) || fs::file_size(*file) != size)
|
||||
fail(name + ": missing or incorrect size (expected " + std::to_string(size) + ')');
|
||||
return read_file(*file);
|
||||
}
|
||||
A data_regions(Documents& out, const LeImage& exe, bool english, const std::string& variant) {
|
||||
A regions;
|
||||
const auto add = [&](const char* name, uint32_t begin, uint32_t end) {
|
||||
if (!exe.contains(begin) || !exe.contains(end - 1)) fail("incomplete executable data region");
|
||||
const std::string path = "x-classic/" + variant + '/' + name + ".bin";
|
||||
out[path] = std::string(reinterpret_cast<const char*>(exe.data(begin)), end - begin);
|
||||
regions.emplace_back(O{{"name", name}, {"base", int(begin)}, {"size", int(end - begin)}, {"path", path}});
|
||||
};
|
||||
add("common-data", layout::GermanDataSegmentBegin, layout::GermanImageEnd);
|
||||
if (english) add("english-data", layout::EnDataStart, layout::Career_CompetitionPointersEnglish_RuntimeField);
|
||||
return regions;
|
||||
}
|
||||
LeImage load_regions(const Documents& out, const J& value, const J& embedded, bool english) {
|
||||
const auto& regions = arr(value);
|
||||
if (regions.size() != size_t(english ? 2 : 1)) fail("incorrect data-region count");
|
||||
Bytes image(layout::GermanImageEnd - 0x10000, 0);
|
||||
std::set<uint32_t> seen;
|
||||
for (const auto& region : regions) {
|
||||
const auto base = num(get(region, "base")), size = num(get(region, "size"));
|
||||
const bool german = base == layout::GermanDataSegmentBegin && size == layout::GermanImageEnd - layout::GermanDataSegmentBegin;
|
||||
const bool en = english && base == layout::EnDataStart && size == layout::Career_CompetitionPointersEnglish_RuntimeField - layout::EnDataStart;
|
||||
if ((!german && !en) || !seen.insert(uint32_t(base)).second) fail("unsupported/duplicate data region (code is forbidden)");
|
||||
const auto& bytes = out.at(str(get(region, "path")));
|
||||
if (int64_t(bytes.size()) != size) fail("truncated data region");
|
||||
std::copy(bytes.begin(), bytes.end(), image.begin() + (base - 0x10000));
|
||||
}
|
||||
const auto& texts = arr(embedded);
|
||||
if (texts.size() != std::size(literals)) fail("incomplete embedded text literals");
|
||||
for (size_t i = 0; i < std::size(literals); ++i) {
|
||||
const auto& literal = literals[i];
|
||||
const auto data = unhex(str(get(texts[i], "bytes_hex")));
|
||||
if (num(get(texts[i], "address")) != literal.address || str(get(texts[i], "name")) != literal.name ||
|
||||
data.empty() || data.size() > literal.size || data.back() != 0) fail("invalid embedded text literal binding");
|
||||
for (size_t ch = 0; ch + 1 < data.size(); ++ch)
|
||||
if (data[ch] < 32 || data[ch] > 126) fail("invalid embedded text character");
|
||||
std::copy(data.begin(), data.end(), image.begin() + (literal.address - 0x10000));
|
||||
}
|
||||
return LeImage::from_bytes(0x10000, std::move(image));
|
||||
}
|
||||
J localized(const std::string& value) { return O{{"default", legacy_text(value)}}; }
|
||||
|
||||
void competitions(Documents& out, const LeImage& exe) {
|
||||
auto comps = items(out, "competitions");
|
||||
const auto texts = parse(out, "x-legacy/texts.json");
|
||||
const auto& strings = arr(get(texts, "items"));
|
||||
std::map<int, A> cups;
|
||||
for (uint32_t entry = 0; entry < 36; ++entry) {
|
||||
const uint32_t at = layout::CupTable + entry * 0x28;
|
||||
const int cup = int(int16_t(exe.u16(at + 0x18)));
|
||||
if (cup < 0 || cup > 26) continue; // reserved sentinel entries stay in data regions
|
||||
const int flags = exe.u8(at + 0x14), next = int(int8_t(exe.u8(at + 0x16)));
|
||||
const int parallel = int(int8_t(exe.u8(at + 0x17)));
|
||||
const int count = exe.u8(at + 0x1a);
|
||||
O stage{{"id", "entry-" + std::to_string(entry)}, {"format", (flags & 4) ? "knockout" : "groups"},
|
||||
{"teams", count}, {"legs", 1 + (flags & 1)}, {"matchdays", "calendar:classic-cup-" + std::to_string(cup)},
|
||||
{"slots", A{O{{"resolver", "classic-entry@1"}, {"entry", int(entry)}, {"count", count}}}},
|
||||
{"classic", O{{"entry", int(entry)}, {"flags", flags}, {"next_entry", next}, {"parallel_entry", parallel},
|
||||
{"rounds", int(exe.u8(at + 0x1b))}, {"qualifying_rounds", int(exe.u8(at + 0x1c))},
|
||||
{"groups", int(exe.u8(at + 0x1e) & 15)}, {"group_index", int(exe.u8(at + 0x1e) >> 4)},
|
||||
{"qualification_quota", int(int8_t(exe.u8(at + 0x1f)))},
|
||||
{"draw_each_round", bool(flags & 0x20)}, {"decide_on_day", bool(flags & 8)}}}};
|
||||
cups[cup].emplace_back(std::move(stage));
|
||||
}
|
||||
const auto english = str(get(parse(out, "manifest.json"), "provenance")) == "import:fltd";
|
||||
for (auto& [cup, stages] : cups) {
|
||||
const auto text_index = (layout::DeskState_FormatError_ExecutableField3 - layout::TextPointerTable) / 4 + uint32_t(cup + 1);
|
||||
const auto label = text_index < strings.size() ? get(strings[text_index], "text") : J("Classic competition " + std::to_string(cup));
|
||||
std::string type = cup == 0 ? "cup" : cup >= 1 && cup <= 3 ? "club_international" :
|
||||
cup >= 4 && cup <= 8 ? "national_team" : cup == 10 ? "friendly" : cup == 11 && !english ? "indoor" : "cup";
|
||||
comps.emplace_back(O{{"id", "comp:classic-cup-" + std::to_string(cup)}, {"name", O{{"default", label}}},
|
||||
{"type", type}, {"played", true}, {"stages", std::move(stages)},
|
||||
{"classic", O{{"competition_id", cup}, {"calendar_bit", cup + 5},
|
||||
{"qualification", "classic-season-entrants@1"}, {"runtime_participants", true}}}});
|
||||
}
|
||||
table(out, "competitions", std::move(comps));
|
||||
auto calendars = items(out, "calendar");
|
||||
auto& calendar = *calendars.at(0).object();
|
||||
auto series = arr(calendar.at("series"));
|
||||
for (const auto& [cup, unused] : cups) {
|
||||
(void)unused;
|
||||
series.emplace_back(O{{"id", "classic-cup-" + std::to_string(cup)}, {"legacy_calendar_bit", cup + 5}});
|
||||
}
|
||||
calendar["series"] = std::move(series);
|
||||
calendar["initialization"] = O{{"policy", "classic-calendar@1"},
|
||||
{"inputs", A{"start_date", "season_index", "competition_options"}},
|
||||
{"source_anchor", "07-01"}, {"weekday_alignment", "classic-season-calendar@1"}};
|
||||
table(out, "calendar", std::move(calendars));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void complete_classic(Documents& out, const fs::path& root, const Database& db,
|
||||
const LeImage& exe, const LeImage& source_tables, bool english, const Options& options) {
|
||||
using namespace detail;
|
||||
const auto mod = english ? "FLTD-classic" : "BMH-classic";
|
||||
if (!options.mod.empty() && options.mod != mod) fail("--mod does not match the source edition (expected " + std::string(mod) + ')');
|
||||
const auto desktop = required(root, "M3.MEN", 864);
|
||||
const auto formations = required(root, "M3.DAT", 1408);
|
||||
out["x-classic/desktop-seed.bin"] = binary(desktop);
|
||||
out["x-classic/formation-seed.bin"] = binary(formations);
|
||||
const auto source_text = launch::find_file(root, english ? "TEXTE.BLK" : "TEXTD.BLK");
|
||||
if (!source_text) fail("missing source text block");
|
||||
const auto raw_texts = read_file(*source_text);
|
||||
if (raw_texts.size() < 7) fail("truncated source text block");
|
||||
out["x-classic/text-blob.bin"] = std::string(raw_texts.begin() + 7, raw_texts.end());
|
||||
A text_header;
|
||||
for (size_t i = 0; i < 7; ++i) text_header.emplace_back(int(raw_texts[i]));
|
||||
|
||||
const auto effective_regions = data_regions(out, exe, english, "effective");
|
||||
const auto original_regions = data_regions(out, source_tables, english, "source");
|
||||
put(out, "x-classic/startup.json", O{{"schema", "classic-startup@1.0"}, {"layout", layout_id},
|
||||
{"mod", mod}, {"english", english}, {"rule_profile", "openbmh-supported@1"},
|
||||
{"data_regions", effective_regions}, {"source_regions", original_regions},
|
||||
{"embedded_literals", literal_data(exe)}, {"source_literals", literal_data(source_tables)},
|
||||
{"desktop_seed", "x-classic/desktop-seed.bin"}, {"formation_seed", "x-classic/formation-seed.bin"},
|
||||
{"text_blob", "x-classic/text-blob.bin"},
|
||||
{"text_header", std::move(text_header)},
|
||||
{"initializers", initializers}, {"runtime_inputs", runtime_inputs},
|
||||
{"rng", O{{"import_consumes_draws", false}, {"game", "bmh-game@1"}, {"secondary", "watcom@1"}}}});
|
||||
|
||||
auto manifest = parse(out, "manifest.json");
|
||||
auto& m = *manifest.object();
|
||||
m["id"] = std::string("world:") + mod;
|
||||
m["mod"] = mod;
|
||||
m["requires"] = A{feature};
|
||||
m["extensions"] = A{O{{"id", "x-legacy"}, {"version", "1.0"}}, O{{"id", "x-classic"}, {"version", "1.0"}}};
|
||||
m["x-import"] = O{{"profile", profile}, {"content_complete", true}, {"runtime", feature},
|
||||
{"rule_profile", "openbmh-supported@1"}, {"source_rules_preserved", true},
|
||||
{"default_attribute_set", "bmh-classic@1"}, {"default_portrait_set", "bmh-classic@1"}};
|
||||
put(out, "manifest.json", std::move(manifest));
|
||||
|
||||
auto players = items(out, "players");
|
||||
A contracts;
|
||||
for (size_t i = 0; i < players.size(); ++i) {
|
||||
auto& player = *players[i].object();
|
||||
player["appearance"] = portrait_recipe(db.players.at(i).name, exe);
|
||||
player["photo"] = "asset:player/" + str(player.at("id")).substr(7) + "/photo";
|
||||
if (player.contains("team")) contracts.emplace_back(O{{"id", id("contract", i)}, {"person", player.at("id")},
|
||||
{"team", player.at("team")}, {"initialization", O{{"policy", "classic-player-contract@1"},
|
||||
{"source_identity_word", int64_t(db.players.at(i).w364)}, {"source_skill_word", int64_t(db.players.at(i).w368)}}}});
|
||||
}
|
||||
table(out, "players", std::move(players));
|
||||
table(out, "contracts", std::move(contracts));
|
||||
|
||||
auto nations = items(out, "nations");
|
||||
auto clubs = items(out, "clubs");
|
||||
A finance;
|
||||
for (auto& club : clubs) {
|
||||
auto& row = *club.object();
|
||||
const auto team = size_t(num(get(row.at("x-legacy"), "team_index")));
|
||||
if (team >= 168 && team < 357) row["nation"] = get(nations.at(5 + (team - 168) / 7), "id");
|
||||
if (team >= 168) {
|
||||
constexpr int levels[] = {55, 61, 65, 67, 70, 73, 76, 80};
|
||||
const auto code = db.raw_foreign_club_strength.at(team - 168);
|
||||
row["classic_strength"] = O{{"band", int(code >> 5)}, {"base", levels[code >> 5]},
|
||||
{"style_flags", int(code & 31)}, {"policy", "classic-strength-only-team@1"}};
|
||||
}
|
||||
row["kit"] = O{{"set", "bmh-classic@1"}, {"selector", int(db.raw_club_kit_selectors.at(team))}};
|
||||
if (team < 138) {
|
||||
row["stadium_initialization"] = O{{"policy", "classic-stadium@1"}, {"name_pool", "stadiums"}};
|
||||
finance.emplace_back(O{{"id", id("finance", team)}, {"team", row.at("id")},
|
||||
{"initialization", O{{"policy", "classic-manager-finance@1"},
|
||||
{"when", "human_manager_assigned"}, {"inputs", A{"game_level", "mode", "start_league"}}}}});
|
||||
}
|
||||
}
|
||||
table(out, "clubs", std::move(clubs));
|
||||
nations.erase(std::remove_if(nations.begin(), nations.end(), [](const J& nation) {
|
||||
return str(get(nation, "id")) == "nation:x-legacy-unassigned";
|
||||
}), nations.end());
|
||||
table(out, "nations", std::move(nations));
|
||||
table(out, "finance", std::move(finance));
|
||||
A staff;
|
||||
for (size_t i = 0; i < db.referees.size(); ++i) {
|
||||
if (i >= db.raw_referee_properties.size()) fail("referee property count mismatch");
|
||||
const auto property = db.raw_referee_properties[i];
|
||||
staff.emplace_back(O{{"id", id("staff", i)}, {"name", localized(db.referees[i])}, {"role", "referee"},
|
||||
{"attributes", O{{"strictness", int((property >> 3) & 3)}}},
|
||||
{"x-legacy", O{{"referee_index", int(i)}, {"property", int(property)}}}});
|
||||
}
|
||||
table(out, "staff", std::move(staff));
|
||||
auto rules = items(out, "rules");
|
||||
rules.emplace_back(O{{"id", "rule:classic-runtime"}, {"type", "classic_runtime"}, {"version", 1},
|
||||
{"startup", "x-classic/startup.json"}, {"layout", layout_id},
|
||||
{"calendar", "classic-calendar@1"}, {"qualifications", "classic-season-entrants@1"},
|
||||
{"financial_initialization", "classic-manager-finance@1"}, {"stadium_initialization", "classic-stadium@1"},
|
||||
{"contract_initialization", "classic-player-contract@1"}, {"staff_initialization", "classic-confirm-managers@1"},
|
||||
{"default_portrait_set", "bmh-classic@1"}});
|
||||
rules.emplace_back(O{{"id", "rule:classic-data-tables"}, {"type", "classic_data_regions"},
|
||||
{"layout", layout_id}, {"effective", effective_regions}, {"source", original_regions},
|
||||
{"coverage", A{"competition_configuration", "qualification_and_movement", "calendar", "player_generation",
|
||||
"contracts", "finance", "sponsors", "training", "stadiums", "transfer_market", "national_teams",
|
||||
"match_parameters", "embedded_texts", "interface_tables", "audio_tables"}}});
|
||||
table(out, "rules", std::move(rules));
|
||||
competitions(out, exe);
|
||||
import_assets(out, root, db, exe);
|
||||
|
||||
auto report = parse(out, "x-legacy/import-report.json");
|
||||
auto& r = *report.object();
|
||||
r["profile"] = profile;
|
||||
r["unmapped"] = A{};
|
||||
auto warnings = arr(r.at("warnings"));
|
||||
warnings.erase(std::remove_if(warnings.begin(), warnings.end(), [](const J& warning) {
|
||||
return warning.string() && warning.string()->starts_with("foreign club nation assignments");
|
||||
}), warnings.end());
|
||||
r["warnings"] = std::move(warnings);
|
||||
r["coverage"] = O{{"core_entities", true}, {"all_classic_data_regions", true}, {"media", true},
|
||||
{"new_career_initialization", "runtime:classic-v1"}, {"savegame_conversion", false}};
|
||||
r["notes"] = A{"Complete installation content for the versioned Classic adapter, not a running career.",
|
||||
"Runtime-generated values are initialization policies, not fabricated initial contracts or stadiums.",
|
||||
"Generic competitions/rules are projections. Exact classic semantics use x-classic data and runtime:classic-v1.",
|
||||
"Both the supported effective tables and unpatched source data tables are retained; no executable code is exported.",
|
||||
"Player appearances are frozen from the original byte names; only portrait parts, never composed faces, are stored.",
|
||||
"No FBM, personal EIN, SOUND.CFG, high scores, or executable is copied.",
|
||||
"No 0.1 frontend reads OBW. The 0.2 runtime adapter is separate work."};
|
||||
put(out, "x-legacy/import-report.json", std::move(report));
|
||||
|
||||
// All payload entries, including binary assets, are checked before publication/load.
|
||||
refresh_classic_inventory(out);
|
||||
}
|
||||
|
||||
void refresh_classic_inventory(Documents& out) {
|
||||
using namespace detail;
|
||||
A inventory;
|
||||
for (const auto& [path, contents] : out)
|
||||
if (path != "x-classic/inventory.json")
|
||||
inventory.emplace_back(O{{"path", path}, {"bytes", int64_t(contents.size())}, {"crc32", int64_t(crc(contents))}});
|
||||
put(out, "x-classic/inventory.json", O{{"schema", "classic-inventory@1.0"}, {"entries", std::move(inventory)}});
|
||||
}
|
||||
|
||||
static ClassicData decode_classic(const Documents& out) {
|
||||
using namespace detail;
|
||||
const auto startup = parse(out, "x-classic/startup.json");
|
||||
if (str(get(startup, "schema")) != "classic-startup@1.0" || str(get(startup, "layout")) != layout_id)
|
||||
fail("unsupported classic startup/layout version");
|
||||
ClassicData data;
|
||||
const auto* en = get(startup, "english").boolean();
|
||||
if (!en) fail("invalid edition flag");
|
||||
data.english = *en;
|
||||
data.executable = load_regions(out, get(startup, "data_regions"), get(startup, "embedded_literals"), data.english);
|
||||
data.source_tables = load_regions(out, get(startup, "source_regions"), get(startup, "source_literals"), data.english);
|
||||
const auto database = parse(out, "x-legacy/source-database.json");
|
||||
data.database = decode_database(unhex(str(get(database, "bytes"))));
|
||||
data.desktops = bytes(out.at(str(get(startup, "desktop_seed"))));
|
||||
data.formations = bytes(out.at(str(get(startup, "formation_seed"))));
|
||||
if (data.desktops.size() != 864 || data.formations.size() != 1408) fail("invalid startup seed sizes");
|
||||
data.texts.blob = bytes(out.at(str(get(startup, "text_blob"))));
|
||||
const auto& header = arr(get(startup, "text_header"));
|
||||
if (header.size() != 7) fail("invalid source text header");
|
||||
for (const auto& byte : header) {
|
||||
if (num(byte) < 0 || num(byte) > 255) fail("invalid source text header byte");
|
||||
data.text_header.push_back(uint8_t(num(byte)));
|
||||
}
|
||||
size_t position = 0;
|
||||
while (data.texts.strings.size() < TEXT_COUNT && position < data.texts.blob.size()) {
|
||||
const auto begin = position;
|
||||
while (position < data.texts.blob.size() && data.texts.blob[position]) ++position;
|
||||
if (position == data.texts.blob.size()) fail("unterminated classic text");
|
||||
data.texts.offsets.push_back(begin);
|
||||
data.texts.strings.emplace_back(data.texts.blob.begin() + begin, data.texts.blob.begin() + position);
|
||||
++position;
|
||||
}
|
||||
if (data.texts.strings.size() != TEXT_COUNT) fail("incomplete classic texts");
|
||||
load_assets(out, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
void validate_classic(const Documents& out) {
|
||||
using namespace detail;
|
||||
const auto manifest = parse(out, "manifest.json");
|
||||
const auto& imported = get(manifest, "x-import");
|
||||
if (str(get(imported, "profile")) != profile || !get(imported, "content_complete").boolean() ||
|
||||
!*get(imported, "content_complete").boolean()) fail("incomplete classic profile");
|
||||
const auto& required_features = arr(get(manifest, "requires"));
|
||||
if (required_features.size() != 1 || str(required_features[0]) != feature) fail("missing classic runtime requirement");
|
||||
const auto startup = parse(out, "x-classic/startup.json");
|
||||
const auto expected = str(get(manifest, "provenance")) == "import:fltd" ? "FLTD-classic" : "BMH-classic";
|
||||
if (str(get(manifest, "mod")) != expected || str(get(startup, "mod")) != expected) fail("mod/edition mismatch");
|
||||
if (str(get(imported, "rule_profile")) != "openbmh-supported@1" ||
|
||||
str(get(startup, "rule_profile")) != "openbmh-supported@1" ||
|
||||
cli::dump_json(get(startup, "initializers")) != cli::dump_json(initializers) ||
|
||||
cli::dump_json(get(startup, "runtime_inputs")) != cli::dump_json(runtime_inputs)) fail("unsupported classic initialization contract");
|
||||
std::set<std::string> seen;
|
||||
const auto inventory = parse(out, "x-classic/inventory.json");
|
||||
for (const auto& entry : arr(get(inventory, "entries"))) {
|
||||
const auto path = str(get(entry, "path"));
|
||||
if (!safe_path(path) || path == "x-classic/inventory.json" || !seen.insert(path).second || !out.contains(path)) fail("invalid inventory entry: " + path);
|
||||
const auto& bytes = out.at(path);
|
||||
if (int64_t(bytes.size()) != num(get(entry, "bytes")) || int64_t(crc(bytes)) != num(get(entry, "crc32"))) fail("damaged entry: " + path);
|
||||
if (path.starts_with("state/")) fail("save state is forbidden in an installation mod");
|
||||
auto suffix = fs::path(path).extension().string();
|
||||
for (char& ch : suffix) ch = char(std::tolower(static_cast<unsigned char>(ch)));
|
||||
if (suffix == ".exe" || suffix == ".fbm" || suffix == ".obs" || suffix == ".ein" || suffix == ".cfg") fail("non-content file in classic world");
|
||||
}
|
||||
if (seen.size() + 1 != out.size()) fail("unlisted archive entries");
|
||||
auto data = decode_classic(out);
|
||||
if (data.english != (std::string(expected) == "FLTD-classic")) fail("startup edition mismatch");
|
||||
// Every fixture pointer must remain readable from the exported DATA view.
|
||||
const auto fixture_rules = items(out, "rules");
|
||||
const auto fixture = std::find_if(fixture_rules.begin(), fixture_rules.end(), [](const J& row) {
|
||||
return str(get(row, "id")) == "rule:legacy-fixtures";
|
||||
});
|
||||
if (fixture == fixture_rules.end()) fail("missing fixture generators");
|
||||
const std::map<int, uint32_t> bindings = data.english ?
|
||||
std::map<int, uint32_t>{{4, layout::EnglishFourTeamFixtureTable}, {6, layout::EnglishSixTeamFixtureTable},
|
||||
{12, layout::EnglishTwelveTeamFixtureTable}, {20, layout::EnglishTwentyTeamFixtureTable}} :
|
||||
std::map<int, uint32_t>{{4, layout::CareerSession_RuntimeError_RuntimeField}, {6, layout::CareerSession_RuntimeError_RuntimeField2},
|
||||
{12, layout::CareerSession_RuntimeError_RuntimeField3}, {16, layout::CareerSession_RuntimeError_ExecutableField3},
|
||||
{18, layout::CareerSession_RuntimeError_ExecutableField}, {20, layout::CareerSession_RuntimeError_ExecutableField2}};
|
||||
std::set<int> fixture_sizes;
|
||||
for (const auto& entry : arr(get(*fixture, "tables"))) {
|
||||
const int teams = int(num(get(entry, "teams")));
|
||||
if (!bindings.contains(teams) || !fixture_sizes.insert(teams).second) fail("invalid fixture generator size");
|
||||
if (str(get(entry, "id")) != "legacy:" + std::to_string(teams)) fail("invalid fixture generator identity");
|
||||
const auto& rounds = arr(get(entry, "rounds"));
|
||||
if (rounds.size() != size_t(teams - 1)) fail("invalid fixture round count");
|
||||
for (size_t round = 0; round < rounds.size(); ++round) {
|
||||
const auto row = data.executable.cstring(data.executable.u32(bindings.at(teams) + uint32_t(round + 1) * 4));
|
||||
if (row.size() != size_t(teams) || arr(rounds[round]).size() != size_t(teams / 2)) fail("incomplete fixture round data");
|
||||
std::set<char> seen;
|
||||
for (const char team : row)
|
||||
if (team < 'a' || team >= 'a' + teams || !seen.insert(team).second) fail("invalid fixture round participants");
|
||||
for (size_t match = 0; match < size_t(teams / 2); ++match) {
|
||||
const auto& pair = arr(arr(rounds[round])[match]);
|
||||
if (pair.size() != 2 || num(pair[0]) != row[match * 2] - 'a' || num(pair[1]) != row[match * 2 + 1] - 'a') fail("fixture projection disagrees with classic data");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fixture_sizes.size() != bindings.size()) fail("incomplete fixture generators");
|
||||
const auto portrait_set = parse(out, "assets/portrait-sets/bmh-classic@1/set.json");
|
||||
const auto& layers = arr(get(portrait_set, "layers"));
|
||||
if (layers.size() != 5 || arr(get(portrait_set, "backgrounds")).size() != 4) fail("invalid portrait set");
|
||||
std::set<std::string> assets;
|
||||
const auto index = parse(out, "assets/index.json");
|
||||
for (const auto& row : arr(get(index, "items"))) {
|
||||
const auto key = str(get(row, "key"));
|
||||
if (!key.starts_with("asset:") || !assets.insert(key).second || str(get(row, "license")) != "local-import-only") fail("invalid asset metadata");
|
||||
const auto* files = get(row, "files").object();
|
||||
if (!files || files->empty()) fail("missing asset files");
|
||||
for (const auto& [size, path] : *files) {
|
||||
(void)size;
|
||||
if (!out.contains(str(path))) fail("missing asset file: " + str(path));
|
||||
}
|
||||
}
|
||||
for (const auto& row : arr(get(portrait_set, "backgrounds")))
|
||||
if (!assets.contains(str(get(row, "asset")))) fail("missing portrait background asset");
|
||||
for (const auto& layer : layers) for (const auto& part : arr(get(layer, "parts")))
|
||||
if (!assets.contains(str(part))) fail("missing portrait part asset");
|
||||
const auto players = items(out, "players");
|
||||
if (players.size() != data.database.players.size()) fail("incomplete player projections");
|
||||
for (const auto& player : players) {
|
||||
const auto& appearance = get(player, "appearance");
|
||||
const auto background = num(get(appearance, "background"));
|
||||
const auto& parts = arr(get(appearance, "layers"));
|
||||
if (str(get(appearance, "set")) != "bmh-classic@1" || background < 0 || background > 3 || parts.size() != 5) fail("invalid frozen player appearance");
|
||||
for (size_t i = 0; i < 5; ++i)
|
||||
if (num(parts[i]) < 0 || num(parts[i]) >= int64_t(arr(get(layers[i], "parts")).size())) fail("portrait part index out of range");
|
||||
}
|
||||
const auto clubs = items(out, "clubs");
|
||||
for (const auto& club : clubs) if (!assets.contains(str(get(club, "crest")))) fail("missing club crest");
|
||||
if (items(out, "finance").size() != 138 || items(out, "staff").size() != data.database.referees.size()) fail("incomplete finance/staff seeds");
|
||||
std::map<std::string, std::string> owned;
|
||||
for (const auto& player : players)
|
||||
if (player.object()->contains("team")) owned.emplace(str(get(player, "id")), str(get(player, "team")));
|
||||
const auto contracts = items(out, "contracts");
|
||||
if (contracts.size() != owned.size()) fail("incomplete contract seeds");
|
||||
for (const auto& contract : contracts) {
|
||||
const auto who = str(get(contract, "person"));
|
||||
if (!owned.contains(who) || owned.at(who) != str(get(contract, "team"))) fail("contract does not match its player/team");
|
||||
owned.erase(who);
|
||||
}
|
||||
std::set<int> entries;
|
||||
size_t leagues = 0;
|
||||
for (const auto& competition : items(out, "competitions")) {
|
||||
if (str(get(competition, "type")) == "league") { ++leagues; continue; }
|
||||
const auto cup = num(get(get(competition, "classic"), "competition_id"));
|
||||
for (const auto& stage : arr(get(competition, "stages"))) {
|
||||
const auto entry = num(get(get(stage, "classic"), "entry"));
|
||||
if (entry < 0 || entry >= 36 || !entries.insert(int(entry)).second ||
|
||||
data.executable.u16(layout::CupTable + uint32_t(entry) * 0x28 + 0x18) != cup) fail("invalid classic cup stage binding");
|
||||
}
|
||||
}
|
||||
if (leagues != 9) fail("classic world requires nine league definitions");
|
||||
for (uint32_t entry = 0; entry < 36; ++entry) {
|
||||
const int cup = int(int16_t(data.executable.u16(layout::CupTable + entry * 0x28 + 0x18)));
|
||||
if (cup >= 0 && cup <= 26 && !entries.contains(int(entry))) fail("missing classic cup stage");
|
||||
}
|
||||
}
|
||||
|
||||
ClassicData load_classic(const Documents& out) {
|
||||
validate(out);
|
||||
return decode_classic(out);
|
||||
}
|
||||
} // namespace bmh::obw
|
||||
@@ -0,0 +1,29 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "import/obw.hpp"
|
||||
#include "formats/font.hpp"
|
||||
#include "formats/palette.hpp"
|
||||
|
||||
namespace bmh::obw {
|
||||
// Installation content only. No manager choices, career RNG or save state.
|
||||
struct ClassicData {
|
||||
bool english = false;
|
||||
Database database;
|
||||
TextDb texts;
|
||||
LeImage executable; // DATA regions and four bounded literals; no instructions
|
||||
LeImage source_tables;
|
||||
Bytes desktops, formations, text_header;
|
||||
Palette palette;
|
||||
std::map<std::string, Image> images;
|
||||
std::map<std::string, Font> fonts;
|
||||
std::map<std::string, Bytes> audio;
|
||||
};
|
||||
|
||||
void complete_classic(Documents& out, const std::filesystem::path& root,
|
||||
const Database& database, const LeImage& executable,
|
||||
const LeImage& source_tables, bool english, const Options& options);
|
||||
void validate_classic(const Documents& out);
|
||||
// For an editor after deliberate changes. CRC32 detects damage, not authenticity.
|
||||
void refresh_classic_inventory(Documents& out);
|
||||
ClassicData load_classic(const Documents& out);
|
||||
} // namespace bmh::obw
|
||||
@@ -0,0 +1,83 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "import/obw.hpp"
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string_view>
|
||||
#include "miniz.h"
|
||||
|
||||
namespace bmh::obw::detail {
|
||||
using J = cli::Json;
|
||||
using A = J::Array;
|
||||
using O = J::Object;
|
||||
[[noreturn]] inline void fail(const std::string& message) { throw FormatError("OBW: " + message); }
|
||||
inline const J& get(const J& value, std::string_view key) {
|
||||
if (!value.object()) fail("expected object for field: " + std::string(key));
|
||||
const auto found = value.object()->find(key);
|
||||
if (found == value.object()->end()) fail("missing field: " + std::string(key));
|
||||
return found->second;
|
||||
}
|
||||
inline std::string str(const J& value) {
|
||||
if (!value.string()) fail("expected string");
|
||||
return *value.string();
|
||||
}
|
||||
inline int64_t num(const J& value) {
|
||||
if (!value.integer()) fail("expected integer");
|
||||
return *value.integer();
|
||||
}
|
||||
inline const A& arr(const J& value) {
|
||||
if (!value.array()) fail("expected array");
|
||||
return *value.array();
|
||||
}
|
||||
inline J parse(const Documents& out, const std::string& path) {
|
||||
if (!out.contains(path)) fail("missing entry: " + path);
|
||||
return cli::parse_json(out.at(path));
|
||||
}
|
||||
inline void put(Documents& out, const std::string& path, J value) {
|
||||
out[path] = cli::dump_json(value) + '\n';
|
||||
}
|
||||
inline A items(const Documents& out, const std::string& table) {
|
||||
return arr(get(parse(out, "world/" + table + ".json"), "items"));
|
||||
}
|
||||
inline void table(Documents& out, const std::string& name, A values) {
|
||||
put(out, "world/" + name + ".json", O{{"schema", name + "@1.0"}, {"items", std::move(values)}});
|
||||
}
|
||||
inline std::string id(const std::string& prefix, size_t index) {
|
||||
std::ostringstream out;
|
||||
out << prefix << ':' << std::setfill('0') << std::setw(5) << index;
|
||||
return out.str();
|
||||
}
|
||||
inline std::string binary(const Bytes& bytes) { return std::string(bytes.begin(), bytes.end()); }
|
||||
inline Bytes bytes(const std::string& value) { return Bytes(value.begin(), value.end()); }
|
||||
inline std::string legacy_text(const std::string& raw) {
|
||||
std::string result;
|
||||
for (const unsigned char byte : raw) {
|
||||
if (byte >= 128) { result += char(0xc0 | (byte >> 6)); result += char(0x80 | (byte & 63)); }
|
||||
else { const char one[] = {char(byte), 0}; result += iso646de_to_utf8(one, 1); }
|
||||
}
|
||||
return result;
|
||||
}
|
||||
inline Bytes unhex(const std::string& hex) {
|
||||
if (hex.size() % 2) fail("odd hex length");
|
||||
const auto digit = [](char c) {
|
||||
if (c >= '0' && c <= '9') return c - '0';
|
||||
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
||||
fail("invalid hex digit");
|
||||
};
|
||||
Bytes result;
|
||||
result.reserve(hex.size() / 2);
|
||||
for (size_t i = 0; i < hex.size(); i += 2) result.push_back(uint8_t(digit(hex[i]) * 16 + digit(hex[i + 1])));
|
||||
return result;
|
||||
}
|
||||
inline uint32_t crc(const std::string& data) {
|
||||
return uint32_t(mz_crc32(MZ_CRC32_INIT, reinterpret_cast<const unsigned char*>(data.data()), data.size()));
|
||||
}
|
||||
inline bool safe_path(const std::string& path) {
|
||||
if (path.empty() || path.front() == '/' || path.back() == '/' || path.find('\\') != std::string::npos ||
|
||||
path.find(':') != std::string::npos || path.find('\0') != std::string::npos) return false;
|
||||
std::istringstream parts(path);
|
||||
std::string part;
|
||||
while (std::getline(parts, part, '/')) if (part.empty() || part == "." || part == "..") return false;
|
||||
return true;
|
||||
}
|
||||
} // namespace bmh::obw::detail
|
||||
+27
-7
@@ -9,7 +9,7 @@
|
||||
int main(int argc, char** argv) {
|
||||
try {
|
||||
const auto args = bmh::launch::utf8_arguments(argc, argv);
|
||||
std::filesystem::path source, destination;
|
||||
std::filesystem::path source, destination, validate_path;
|
||||
bmh::obw::Options options;
|
||||
bool directory = false;
|
||||
for (size_t i = 1; i < args.size(); ++i) {
|
||||
@@ -17,11 +17,14 @@ int main(int argc, char** argv) {
|
||||
if (arg == "--help" || arg == "-h") {
|
||||
std::cout << "OpenBMH installation-to-OBW converter\n"
|
||||
"Usage: openbmh_import --data DIR_OR_EXE --output WORLD.obw\n"
|
||||
" --start-date YYYY-07-01 [--title TEXT] [--directory]\n\n"
|
||||
"Reads BMH.EXE/M3D.MAN/TEXTD.BLK or FLTD.EXE/M3E.MAN/TEXTE.BLK.\n"
|
||||
" --start-date YYYY-07-01 [--mod BMH-classic|FLTD-classic]\n"
|
||||
" [--title TEXT] [--directory] [--database-only]\n"
|
||||
" openbmh_import --validate WORLD.obw_OR_DIRECTORY\n\n"
|
||||
"Imports a complete BMH or Football Limited installation, including media.\n"
|
||||
"--directory writes an unpacked world instead of a ZIP archive.\n"
|
||||
"Existing destinations are never overwritten. Imported content stays local.\n"
|
||||
"Conversion profile only: no game loading, FBM saves or graphics yet.\n";
|
||||
"--database-only explicitly selects the old partial development export.\n"
|
||||
"Classic content targets the 0.2 adapter; 0.1 cannot load OBW. No FBM conversion.\n";
|
||||
return 0;
|
||||
}
|
||||
if (arg == "--version") {
|
||||
@@ -29,13 +32,29 @@ int main(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
||||
if (arg == "--directory") { directory = true; continue; }
|
||||
if (arg != "--data" && arg != "--output" && arg != "--start-date" && arg != "--title")
|
||||
if (arg == "--database-only") { options.database_only = true; continue; }
|
||||
if (arg != "--data" && arg != "--output" && arg != "--start-date" && arg != "--title" &&
|
||||
arg != "--mod" && arg != "--validate")
|
||||
throw std::runtime_error("unknown option: " + arg);
|
||||
if (++i == args.size()) throw std::runtime_error("missing value for " + arg);
|
||||
if (arg == "--data") source = bmh::launch::path_from_utf8(args[i]);
|
||||
if (arg == "--output") destination = bmh::launch::path_from_utf8(args[i]);
|
||||
if (arg == "--start-date") options.start_date = args[i];
|
||||
if (arg == "--title") options.title = args[i];
|
||||
if (arg == "--mod") {
|
||||
options.mod = args[i];
|
||||
if (options.mod == "FTDL-classic" || options.mod == "FTLD-classic") options.mod = "FLTD-classic";
|
||||
if (options.mod != "BMH-classic" && options.mod != "FLTD-classic")
|
||||
throw std::runtime_error("--mod must be BMH-classic or FLTD-classic");
|
||||
}
|
||||
if (arg == "--validate") validate_path = bmh::launch::path_from_utf8(args[i]);
|
||||
}
|
||||
if (!validate_path.empty()) {
|
||||
if (!source.empty() || !destination.empty() || !options.start_date.empty() || !options.mod.empty() || directory || options.database_only)
|
||||
throw std::runtime_error("--validate cannot be combined with conversion options");
|
||||
const auto documents = bmh::obw::read(validate_path);
|
||||
std::cout << "Valid OBW content: " << documents.size() << " entries; no engine runtime test implied.\n";
|
||||
return 0;
|
||||
}
|
||||
if (source.empty() || destination.empty() || options.start_date.empty())
|
||||
throw std::runtime_error("--data, --output and --start-date are required; see --help");
|
||||
@@ -45,8 +64,9 @@ int main(int argc, char** argv) {
|
||||
bmh::obw::write(documents, destination, directory);
|
||||
std::cout << "Converted " << documents.size() << " documents to "
|
||||
<< bmh::launch::path_to_utf8(destination) << "\n"
|
||||
<< "Profile: legacy-database-v1; content_license: local-import-only.\n"
|
||||
<< "See x-legacy/import-report.json for coverage and remaining mappings.\n";
|
||||
<< "Profile: " << (options.database_only ? "legacy-database-v1 (partial)" : "classic-installation-v1 (complete Classic content)")
|
||||
<< "; content_license: local-import-only.\n"
|
||||
<< "See manifest.json and x-legacy/import-report.json. 0.2 runtime integration is separate.\n";
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << "openbmh_import: " << error.what() << '\n';
|
||||
|
||||
+75
-8
@@ -1,5 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "import/obw.hpp"
|
||||
#include "import/classic.hpp"
|
||||
#include "import/detail.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -165,10 +167,10 @@ std::string po_quote(const std::string& value) {
|
||||
return result + '"';
|
||||
}
|
||||
|
||||
const J& field(const J& value, const std::string& key, const std::string& path) {
|
||||
const J& field(const J& value, std::string_view key, std::string_view path) {
|
||||
const auto* object = value.object();
|
||||
if (!object || !object->contains(key)) fail(path + ": missing " + key);
|
||||
return object->at(key);
|
||||
if (!object || !object->contains(key)) fail(std::string(path) + ": missing " + std::string(key));
|
||||
return object->find(key)->second;
|
||||
}
|
||||
std::string string_field(const J& value, const std::string& key, const std::string& path) {
|
||||
const auto* result = field(value, key, path).string();
|
||||
@@ -466,6 +468,16 @@ Documents import_installation(const fs::path& source, const Options& options) {
|
||||
return *file;
|
||||
};
|
||||
const auto exe = english ? launch::translate_fltd(*english_exe) : load_le(*german);
|
||||
const std::string expected_mod = english ? "FLTD-classic" : "BMH-classic";
|
||||
if (!options.mod.empty() && options.mod != expected_mod) fail("--mod must be " + expected_mod + " for this installation");
|
||||
if (!options.database_only) {
|
||||
const auto checked = launch::check_game_directory(english ? *english_exe : *german);
|
||||
if (!checked.problems.empty()) {
|
||||
std::string problem = "incomplete installation";
|
||||
for (const auto& message : checked.problems) problem += "\n- " + message;
|
||||
fail(problem + "\nUse --database-only only for an explicitly partial development export.");
|
||||
}
|
||||
}
|
||||
const auto db_path = required(english ? "M3E.MAN" : "M3D.MAN");
|
||||
const auto text_path = required(english ? "TEXTE.BLK" : "TEXTD.BLK");
|
||||
const auto database = load_database(db_path);
|
||||
@@ -474,6 +486,11 @@ Documents import_installation(const fs::path& source, const Options& options) {
|
||||
// runnable legacy installation. No absolute developer paths enter the archive.
|
||||
put(out, "x-legacy/source-database.json", O{{"schema", "legacy-source@1.0"},
|
||||
{"name", english ? "M3E.MAN" : "M3D.MAN"}, {"encoding", "hex"}, {"bytes", hex(read_file(db_path))}});
|
||||
if (!options.database_only) {
|
||||
const auto source_tables = english ? launch::translate_fltd(*english_exe, false) : load_le(*german, false);
|
||||
complete_classic(out, root, database, exe, source_tables, english, options);
|
||||
}
|
||||
validate(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -488,13 +505,24 @@ void validate(const Documents& documents) {
|
||||
{"format", "openbmh-world"}, {"format_version", "1.0"}, {"kind", "world"}, {"content_license", "local-import-only"}})
|
||||
if (string_field(manifest, key, "manifest.json") != expected) fail("manifest.json: unsupported " + key);
|
||||
start_year(string_field(manifest, "start_date", "manifest.json"));
|
||||
uint64_t total = 0;
|
||||
if (documents.size() > 8192) fail("world has too many entries");
|
||||
for (const auto& [path, contents] : documents) {
|
||||
total += contents.size();
|
||||
if (contents.size() > 32 * 1024 * 1024 || total > 128ull * 1024 * 1024) fail("world exceeds import size limits");
|
||||
if (!detail::safe_path(path)) fail("unsafe archive path: " + path);
|
||||
}
|
||||
const auto& features = field(manifest, "requires", "manifest.json");
|
||||
if (!features.array() || features.array()->size() != 1 || !features.array()->front().string() ||
|
||||
*features.array()->front().string() != "import:legacy-database-v1") fail("manifest.json: missing conversion-only feature guard");
|
||||
const auto& profile = field(manifest, "x-import", "manifest.json");
|
||||
const auto* playable = field(profile, "playable", "manifest.json:x-import").boolean();
|
||||
if (!playable || *playable || string_field(profile, "profile", "manifest.json:x-import") != "legacy-database-v1")
|
||||
fail("manifest.json: conversion profile must remain non-playable");
|
||||
const bool classic = string_field(profile, "profile", "manifest.json:x-import") == "classic-installation-v1";
|
||||
if (classic) validate_classic(documents);
|
||||
else {
|
||||
if (!features.array() || features.array()->size() != 1 || !features.array()->front().string() ||
|
||||
*features.array()->front().string() != "import:legacy-database-v1") fail("manifest.json: missing conversion-only feature guard");
|
||||
const auto* playable = field(profile, "playable", "manifest.json:x-import").boolean();
|
||||
if (!playable || *playable || string_field(profile, "profile", "manifest.json:x-import") != "legacy-database-v1")
|
||||
fail("manifest.json: conversion profile must remain non-playable");
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> ids;
|
||||
struct Reference { std::string value, prefix, path; };
|
||||
@@ -521,6 +549,7 @@ void validate(const Documents& documents) {
|
||||
if (item.object()->contains(key)) references.push_back({string_field(item, key, at), prefix, at + '.' + key});
|
||||
};
|
||||
ref("nation", "nation:"); ref("team", "club:"); ref("stadium", "stadium:"); ref("national_team", "nt:");
|
||||
if (std::string(name) == "contracts") ref("person", "player:");
|
||||
if (std::string(name) == "players") {
|
||||
const auto* nats = field(item, "nationalities", at).array();
|
||||
if (!nats || nats->empty()) fail(at + ": nationalities must not be empty");
|
||||
@@ -547,6 +576,13 @@ void validate(const Documents& documents) {
|
||||
size_t participants = 0;
|
||||
std::set<std::string> unique_teams;
|
||||
for (const auto& slot : *slots) {
|
||||
if (classic && slot.object() && slot.object()->contains("resolver")) {
|
||||
if (string_field(slot, "resolver", at) != "classic-entry@1") fail(at + ": unknown slot resolver");
|
||||
const auto* count = field(slot, "count", at).integer();
|
||||
if (!count || *count < 0 || *count > 255) fail(at + ": invalid classic slot count");
|
||||
participants += size_t(*count);
|
||||
continue;
|
||||
}
|
||||
const auto* teams = field(slot, "teams", at).array();
|
||||
if (!teams) fail(at + ": slot teams must be an array");
|
||||
for (const auto& team : *teams) {
|
||||
@@ -566,6 +602,37 @@ void validate(const Documents& documents) {
|
||||
if (!ids.contains(ref.value) || !ref.value.starts_with(ref.prefix)) fail(ref.path + ": unknown or wrong-type id " + ref.value);
|
||||
}
|
||||
|
||||
Documents read(const fs::path& source) {
|
||||
Documents result;
|
||||
uint64_t total = 0;
|
||||
const auto add = [&](const std::string& name, const Bytes& bytes) {
|
||||
if (!detail::safe_path(name)) fail("unsafe archive entry: " + name);
|
||||
total += bytes.size();
|
||||
if (total > 128ull * 1024 * 1024 || result.size() >= 8192) fail("world exceeds import size limits");
|
||||
if (!result.emplace(name, detail::binary(bytes)).second) fail("duplicate archive entry: " + name);
|
||||
};
|
||||
if (fs::is_directory(source)) {
|
||||
for (const auto& entry : fs::recursive_directory_iterator(source)) {
|
||||
if (entry.is_symlink()) fail("symlinks are forbidden in an unpacked world");
|
||||
if (!entry.is_regular_file()) continue;
|
||||
if (entry.file_size() > 32 * 1024 * 1024 || total + entry.file_size() > 128ull * 1024 * 1024) fail("world exceeds import size limits");
|
||||
const auto name = entry.path().lexically_relative(source).generic_u8string();
|
||||
add(std::string(name.begin(), name.end()), read_file(entry.path()));
|
||||
}
|
||||
} else {
|
||||
if (fs::file_size(source) > 128ull * 1024 * 1024) fail("world archive is too large");
|
||||
auto archive = launch::Archive::open(source);
|
||||
for (size_t i = 0; i < archive.entries().size(); ++i) {
|
||||
const auto& entry = archive.entries()[i];
|
||||
if (entry.directory) continue;
|
||||
if (entry.size > 32 * 1024 * 1024 || total + entry.size > 128ull * 1024 * 1024) fail("world exceeds import size limits");
|
||||
add(entry.name, archive.read(i));
|
||||
}
|
||||
}
|
||||
validate(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void write(const Documents& documents, const fs::path& destination, bool directory) {
|
||||
validate(documents);
|
||||
if (fs::symlink_status(destination).type() != fs::file_type::not_found) fail("destination already exists");
|
||||
|
||||
+9
-4
@@ -12,22 +12,27 @@
|
||||
|
||||
namespace bmh::obw {
|
||||
|
||||
// A conversion document, deliberately independent of GameState and CareerSession.
|
||||
// Keys are relative, authored archive paths; values are UTF-8 text.
|
||||
// An archive entry, deliberately independent of GameState and CareerSession.
|
||||
// Keys are relative, authored paths; strings are binary-safe (including NUL).
|
||||
using Documents = std::map<std::string, std::string>;
|
||||
|
||||
struct Options {
|
||||
std::string start_date; // Required: legacy databases have ages, not birth dates.
|
||||
std::string title = "Imported legacy world";
|
||||
// Empty selects BMH-classic / FLTD-classic from the installation.
|
||||
std::string mod;
|
||||
// Explicit developer-only partial export; the default requires a complete installation.
|
||||
bool database_only = false;
|
||||
};
|
||||
|
||||
Documents convert_database(const Database& database, const TextDb& texts,
|
||||
const LeImage& executable, bool english, const Options& options);
|
||||
Documents import_installation(const std::filesystem::path& source, const Options& options);
|
||||
|
||||
// Checks the conversion profile and its cross-table references before any output.
|
||||
// This is not the future engine's competition/playability validator.
|
||||
// Checks the declared import profile, references and (for Classic) complete payload.
|
||||
// This is not a generic competition engine or a JSON Schema implementation.
|
||||
void validate(const Documents& documents);
|
||||
Documents read(const std::filesystem::path& source);
|
||||
|
||||
// Refuses existing destinations. Publishes a complete sibling staging path by rename.
|
||||
// No files in the installation are changed, copied back or executed.
|
||||
|
||||
+2
-2
@@ -71,7 +71,7 @@ const OwnText kOwnTexts[] = {
|
||||
|
||||
} // namespace
|
||||
|
||||
LeImage translate_fltd(const fs::path& fltd_exe) {
|
||||
LeImage translate_fltd(const fs::path& fltd_exe, bool apply_supported_rules) {
|
||||
const Bytes raw = read_file(fltd_exe);
|
||||
if (raw.size() != kFltdSize || raw[0] != 'M' || raw[1] != 'Z')
|
||||
throw std::runtime_error(path_to_utf8(fltd_exe) + " is not the Football Limited FLTD.EXE");
|
||||
@@ -120,7 +120,7 @@ LeImage translate_fltd(const fs::path& fltd_exe) {
|
||||
}
|
||||
}
|
||||
LeImage out = LeImage::from_bytes(kDeBase, std::move(image));
|
||||
apply_rule_base(out);
|
||||
if (apply_supported_rules) apply_rule_base(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
namespace bmh::launch {
|
||||
|
||||
// The German-layout image of FLTD.EXE (throws std::runtime_error for another file).
|
||||
LeImage translate_fltd(const std::filesystem::path& fltd_exe);
|
||||
LeImage translate_fltd(const std::filesystem::path& fltd_exe, bool apply_supported_rules = true);
|
||||
|
||||
// Builds the German-layout data directory `target` from the English game in `source`.
|
||||
// Returns false with `error` set when a file cannot be read or written.
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "import/classic.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "launch/game_data.hpp"
|
||||
#include "launch/fltd.hpp"
|
||||
#include "game/career.hpp"
|
||||
#include "game/season.hpp"
|
||||
#include "game/save.hpp"
|
||||
#include "game/schedule.hpp"
|
||||
#include "game/desk_actions.hpp"
|
||||
#include <bit>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
using namespace bmh;
|
||||
namespace fs = std::filesystem;
|
||||
namespace {
|
||||
void check(bool ok, const std::string& why) { if (!ok) throw std::runtime_error(why); }
|
||||
fs::path file(const fs::path& root, const std::string& name) {
|
||||
const auto value = launch::find_file(root, name);
|
||||
if (!value) throw std::runtime_error("missing " + name);
|
||||
return *value;
|
||||
}
|
||||
void install(const LeImage& exe) {
|
||||
install_fixture_tables(exe);
|
||||
uint8_t sizes[9], first[8], counts[8];
|
||||
for (uint32_t i = 0; i < 9; ++i) sizes[i] = exe.u8(layout::LeagueSizes + i);
|
||||
set_league_sizes(sizes); kEnglishCompetitions = sizes[0] == 20;
|
||||
for (uint32_t i = 0; i < 8; ++i) {
|
||||
first[i] = exe.u8(layout::CalendarFirstLeague + i); counts[i] = exe.u8(layout::CalendarLeagueCounts + i);
|
||||
kGroupBelow[i] = exe.u8(layout::CareerSession_InstallLeagueSizes_RuntimeField5 + i);
|
||||
kGroupBelowCount[i] = exe.u8(layout::CareerSession_InstallLeagueSizes_RuntimeField4 + i);
|
||||
}
|
||||
set_league_groups(first, counts);
|
||||
for (uint32_t i = 0; i < 9; ++i) {
|
||||
kLeagueRelegation[i] = exe.u8(layout::CareerSession_InstallLeagueSizes_RuntimeField2 + i);
|
||||
kLeagueEurope[i] = exe.u8(layout::CareerSession_InstallLeagueSizes_RuntimeField + i);
|
||||
kLeagueSuffix[i] = i < 5 ? char(exe.u8(layout::CareerSession_InstallLeagueSizes_RuntimeField3 + i * 2)) : 0;
|
||||
}
|
||||
kNewcomerFirst = exe.u16(layout::CareerSession_DispatchLineup_RuntimeField);
|
||||
kNewcomerCount = exe.u16(layout::CareerSession_InstallLeagueSizes_RuntimeField6);
|
||||
}
|
||||
struct Run { Bytes state; int32_t game; uint32_t watcom; uint64_t game_calls, watcom_calls; };
|
||||
Run start(const LeImage& exe, const Database& db, const TextDb& texts, const Bytes& men, const Bytes& dat) {
|
||||
install(exe);
|
||||
auto state = startup_state(exe, db, men, dat);
|
||||
state.texts = &texts;
|
||||
state.currency_suffix = exe.cstring(layout::CurrencySuffixText);
|
||||
configure_training_camp_data(state, exe);
|
||||
for (size_t i = 0; i < state.credit_rate_table.size(); ++i) state.credit_rate_table[i] = exe.u8(layout::BankCredit_BankCreditContext_RuntimeField3 + uint32_t(i));
|
||||
state.credit_divisor = std::bit_cast<double>(uint64_t(exe.u32(layout::BankCredit_BankCreditContext_RuntimeField)) |
|
||||
uint64_t(exe.u32(layout::BankCredit_BankCreditContext_RuntimeField2)) << 32);
|
||||
state.credit_rate_table_available = true;
|
||||
GameRandom game; WatcomRandom watcom(8128); MinuteReport report;
|
||||
startup_players(state, game, watcom);
|
||||
check(new_career_before_dialog(state, game, watcom, report), "pre-dialog initialization: " + report.reason);
|
||||
state.memory.set8(layout::CareerDuration, 20);
|
||||
state.memory.set8(layout::Difficulty, 1); state.level = 1;
|
||||
state.memory.set8(layout::ManagerCount, 1);
|
||||
state.memory.set8(layout::GameMode, 3);
|
||||
state.memory.set32(layout::CompetitionSelection, 3);
|
||||
state.manager_records.at(0x21c) = 1;
|
||||
career_managers_begin(state);
|
||||
check(career_add_manager(state, exe, 0, {"IMPORT QA", 0, 0, 1, 0}, false, game, watcom, report), "manager initialization: " + report.reason);
|
||||
career_managers_end(state, false);
|
||||
check(career_season_setup(state, game, watcom, report), "season setup: " + report.reason);
|
||||
check(career_first_steps(state, game, watcom, report), "first steps: " + report.reason);
|
||||
// Compare in RAM only: this is an installation test, never an FBM converter.
|
||||
return {save_stream(state), game.seed(), watcom.seed(), game.calls(), watcom.calls()};
|
||||
}
|
||||
} // namespace
|
||||
int main(int argc, char** argv) {
|
||||
fs::path temp;
|
||||
try {
|
||||
if (argc < 2 || std::string(argv[1]).empty()) return 77;
|
||||
const fs::path root = argv[1];
|
||||
const bool english = bool(launch::find_file(root, "FLTD.EXE")) && !launch::find_file(root, "BMH.EXE");
|
||||
const auto exe = english ? launch::translate_fltd(file(root, "FLTD.EXE")) : load_le(file(root, "BMH.EXE"));
|
||||
const auto source = english ? launch::translate_fltd(file(root, "FLTD.EXE"), false) : load_le(file(root, "BMH.EXE"), false);
|
||||
const auto db = load_database(file(root, english ? "M3E.MAN" : "M3D.MAN"));
|
||||
const auto texts = load_textd(file(root, english ? "TEXTE.BLK" : "TEXTD.BLK"));
|
||||
const auto men = read_file(file(root, "M3.MEN")), dat = read_file(file(root, "M3.DAT"));
|
||||
const auto original_run = start(exe, db, texts, men, dat);
|
||||
const auto converted = obw::import_installation(root, {"2026-07-01", "Private installation test"});
|
||||
temp = fs::temp_directory_path() / ("openbmh-classic-qa-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
||||
fs::create_directory(temp);
|
||||
obw::write(converted, temp / "world.obw", false);
|
||||
auto imported = obw::load_classic(obw::read(temp / "world.obw"));
|
||||
const auto imported_run = start(imported.executable, imported.database, imported.texts, imported.desktops, imported.formations);
|
||||
check(original_run.state == imported_run.state, "new-career first-season state differs after OBW round trip");
|
||||
check(original_run.game == imported_run.game && original_run.watcom == imported_run.watcom &&
|
||||
original_run.game_calls == imported_run.game_calls && original_run.watcom_calls == imported_run.watcom_calls,
|
||||
"initialization random sequence differs");
|
||||
for (uint32_t at = layout::GermanDataSegmentBegin; at < layout::GermanImageEnd; ++at) {
|
||||
check(exe.u8(at) == imported.executable.u8(at), "effective data-table byte changed");
|
||||
check(source.u8(at) == imported.source_tables.u8(at), "source data-table byte changed");
|
||||
}
|
||||
if (english) for (uint32_t at = layout::EnDataStart; at < layout::Career_CompetitionPointersEnglish_RuntimeField; ++at)
|
||||
check(exe.u8(at) == imported.executable.u8(at) && source.u8(at) == imported.source_tables.u8(at), "English data-table byte changed");
|
||||
for (const auto address : {layout::FreeKickTakerLabel, layout::PenaltyTakerLabel, layout::CornerTakerLabel, layout::AutomaticTakersLabel})
|
||||
check(exe.cstring(address) == imported.executable.cstring(address) && source.cstring(address) == imported.source_tables.cstring(address), "embedded literal changed");
|
||||
for (const auto& [name, image] : imported.images) {
|
||||
if (!name.starts_with("kb/") && !name.starts_with("w/")) continue;
|
||||
const auto folder = file(root, name.starts_with("kb/") ? "KB" : "W");
|
||||
const auto original = load_vga(file(folder, name.substr(name.find('/') + 1) + ".VGA"));
|
||||
check(original.width == image.width && original.height == image.height && original.pixels == image.pixels, "original atlas pixels changed");
|
||||
}
|
||||
const auto pal = load_palette(file(root, "M3PC.COL"));
|
||||
check(imported.palette.argb == pal.argb, "palette changed");
|
||||
for (const auto& [name, font] : imported.fonts) {
|
||||
const auto original = load_font(file(file(root, "F"), name));
|
||||
check(original.bitmap == font.bitmap && original.height == font.height && original.glyphs.size() == font.glyphs.size(), "font changed");
|
||||
}
|
||||
for (const auto& [name, bytes] : imported.audio) check(bytes == read_file(file(file(root, "S"), name)), "audio bytes changed");
|
||||
std::cout << (english ? "FLTD" : "BMH") << " Classic: " << converted.size() << " entries; " << original_run.state.size()
|
||||
<< " first-season bytes identical; RNG draws G=" << original_run.game_calls << " W=" << original_run.watcom_calls
|
||||
<< "; source/effective data regions, pixels, palette, fonts and audio retained\n";
|
||||
fs::remove_all(temp);
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
if (!temp.empty()) { std::error_code ec; fs::remove_all(temp, ec); }
|
||||
std::cerr << error.what() << '\n'; return 1;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "import/obw.hpp"
|
||||
#include "import/classic.hpp"
|
||||
#include "import/assets.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
|
||||
@@ -102,7 +104,7 @@ LeImage executable(bool english) {
|
||||
std::vector<std::pair<int, uint32_t>>{{4, layout::CareerSession_RuntimeError_RuntimeField}, {6, layout::CareerSession_RuntimeError_RuntimeField2},
|
||||
{12, layout::CareerSession_RuntimeError_RuntimeField3}, {16, layout::CareerSession_RuntimeError_ExecutableField3},
|
||||
{18, layout::CareerSession_RuntimeError_ExecutableField}, {20, layout::CareerSession_RuntimeError_ExecutableField2}};
|
||||
uint32_t cursor = base + 400000; // synthetic string storage, outside pointer tables
|
||||
uint32_t cursor = layout::GermanImageEnd - 4096; // synthetic data storage, outside pointer tables
|
||||
for (const auto& [teams, address] : bindings) {
|
||||
put(address, cursor, 4); ++cursor;
|
||||
std::vector<int> order;
|
||||
@@ -118,6 +120,18 @@ LeImage executable(bool english) {
|
||||
}
|
||||
}
|
||||
put(layout::Career_BuildStadium_RuntimeField4 - 1, 2);
|
||||
put(base, 0xdeadbeef, 4); // an executable instruction region must never be exported
|
||||
for (uint32_t i = 0; i < 5; ++i) {
|
||||
put(layout::ClubPlayerDetail_ClubPlayerDetailRedraw_RuntimeField2 + i, 4);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField + i, 2 + i);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField2 + i, 3 + i);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField3 + i, 3);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField4 + i, 2);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField7 + i * 2, 20, 2);
|
||||
}
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField, 253);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField3, 70);
|
||||
put(layout::ClubPlayerDetail_DrawPortrait_RuntimeField7, 319, 2);
|
||||
const std::string suffix = english ? " &" : " DM";
|
||||
for (size_t i = 0; i < suffix.size(); ++i) put(layout::CurrencySuffixText + uint32_t(i), uint8_t(suffix[i]));
|
||||
return LeImage::from_bytes(base, std::move(bytes));
|
||||
@@ -225,10 +239,70 @@ int main() {
|
||||
Bytes raw_texts(7);
|
||||
for (const auto& value : texts.strings) { raw_texts.insert(raw_texts.end(), value.begin(), value.end()); raw_texts.push_back(0); }
|
||||
save(input / "textd.blk", raw_texts);
|
||||
const auto converted = obw::import_installation(input, options);
|
||||
auto partial_options = options;
|
||||
partial_options.database_only = true;
|
||||
const auto converted = obw::import_installation(input, partial_options);
|
||||
check(converted.contains("x-legacy/source-database.json"), "retain exact database for future mappings");
|
||||
check(read_file(input / "m3d.man") == raw_database, "source database unchanged");
|
||||
check(obw::import_installation(root, options) == converted, "follow one nested installation");
|
||||
check(obw::import_installation(root, partial_options) == converted, "follow one nested installation");
|
||||
rejects([&] { obw::import_installation(input, options); }, "full mod requires its media and startup data");
|
||||
|
||||
// Complete synthetic content profile, including embedded NULs and media.
|
||||
for (const auto* dir : {"KB", "W", "F", "S"}) fs::create_directory(input / dir);
|
||||
save(input / "M3.MEN", Bytes(864, 7)); save(input / "M3.DAT", Bytes(1408, 9));
|
||||
save(input / "M3PC.COL", Bytes(768, 31));
|
||||
Bytes font(37, 0);
|
||||
word(font, 0, 1); font[3] = 2; word(font, 4, 1); font[8] = font[9] = 'A'; word(font, 16, 1);
|
||||
font[28] = 0x80; word(font, 31, 1); word(font, 35, 1);
|
||||
save(input / "F/BMH2.FNT", font); save(input / "F/BMH3.FNT", font);
|
||||
Bytes bank{'F','O','R','M',8,0,0,0,'A','L','P','T','R','A','U','M'};
|
||||
for (const char* name : {"2000", "2001", "2002", "2003"}) save(input / "S" / name, bank);
|
||||
const auto image = [&](const fs::path& path) {
|
||||
Bytes vga(8, 0), rle;
|
||||
constexpr int width = 320, height = 240;
|
||||
for (int i = 0; i < width * height; i += 128) {
|
||||
rle.push_back(127);
|
||||
for (int k = 0; k < 128; ++k) rle.push_back(uint8_t((i + k) % 251));
|
||||
}
|
||||
rle.push_back(0); word(vga, 0, width); word(vga, 2, height); word(vga, 4, uint32_t(rle.size()), 4);
|
||||
vga.insert(vga.end(), rle.begin(), rle.end()); save(path, vga);
|
||||
};
|
||||
image(input / "KB/0.VGA"); image(input / "KB/29.VGA"); image(input / "W/0.VGA");
|
||||
auto classic = converted;
|
||||
obw::complete_classic(classic, input, db, exe, exe, false, options);
|
||||
obw::validate(classic);
|
||||
const auto loaded = obw::load_classic(classic);
|
||||
check(loaded.desktops == Bytes(864, 7) && loaded.formations == Bytes(1408, 9), "all startup seed bytes survive");
|
||||
check(loaded.database.players[0].name == db.players[0].name && loaded.texts.blob == Bytes(raw_texts.begin() + 7, raw_texts.end()), "source records and text blob survive");
|
||||
check(loaded.images.at("kb/29").pixels.at(12 * 320 + 17) == uint8_t((12 * 320 + 17) % 251), "indexed media round trip");
|
||||
check(loaded.images.at("portraits/layer-0-0").pixels.at(67) == uint8_t((3 * 320 + 320) % 251), "portrait feature preserves packed row wrap");
|
||||
check(loaded.fonts.at("bmh2.fnt").glyph('A').bit_width == 1 && loaded.audio.at("2000") == bank, "font and audio round trip");
|
||||
check(loaded.executable.u32(0x10000) == 0, "no executable code in compatibility image");
|
||||
const auto portrait = obw::portrait_recipe("ABC", exe);
|
||||
check(*f(portrait, "background").integer() >= 0 && f(portrait, "layers").array()->size() == 5, "frozen part recipe");
|
||||
const auto classic_zip = root / "classic.obw";
|
||||
obw::write(classic, classic_zip, false);
|
||||
check(obw::read(classic_zip) == classic, "binary Classic ZIP round trip");
|
||||
auto damaged = classic;
|
||||
damaged.at("x-classic/desktop-seed.bin")[0] ^= 1;
|
||||
rejects([&] { obw::validate(damaged); }, "inventory catches binary corruption");
|
||||
damaged = classic; damaged["state/rng.json"] = "{}";
|
||||
rejects([&] { obw::validate(damaged); }, "reject injected save state");
|
||||
damaged = classic;
|
||||
auto renamed = document(damaged, "world/players.json");
|
||||
auto& renamed_rows = std::get<J::Array>(renamed.object()->at("items").value);
|
||||
const auto appearance = f(renamed_rows[0], "appearance");
|
||||
renamed_rows[0].object()->at("name").object()->at("last") = "Renamed";
|
||||
damaged["world/players.json"] = cli::dump_json(renamed);
|
||||
obw::refresh_classic_inventory(damaged);
|
||||
obw::validate(damaged);
|
||||
check(cli::dump_json(f(renamed_rows[0], "appearance")) == cli::dump_json(appearance), "rename keeps frozen face");
|
||||
renamed_rows[0].object()->at("appearance").object()->at("background") = 4;
|
||||
damaged["world/players.json"] = cli::dump_json(renamed);
|
||||
obw::refresh_classic_inventory(damaged);
|
||||
rejects([&] { obw::validate(damaged); }, "reject invalid appearance even with updated inventory");
|
||||
auto wrong_options = options; wrong_options.mod = "FLTD-classic";
|
||||
rejects([&] { obw::complete_classic(damaged, input, db, exe, exe, false, wrong_options); }, "mod/edition mismatch rejected");
|
||||
save(input / "m3d.man", Bytes{0, 1});
|
||||
rejects([&] { obw::import_installation(input, options); }, "reject truncated legacy database");
|
||||
fs::remove_all(root);
|
||||
|
||||
@@ -22,7 +22,7 @@ class PackageAllowlistTests(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
# Empty authored placeholders test names/structure, not executable behavior.
|
||||
for name in ['openbmh_play', 'openbmh_cli', 'README.md', 'LICENSE',
|
||||
for name in ['openbmh_play', 'openbmh_cli', 'openbmh_import', 'README.md', 'LICENSE',
|
||||
'THIRD_PARTY_NOTICES.md', 'ACKNOWLEDGEMENTS.md', 'CONTRIBUTING.md']:
|
||||
(root / name).write_text('synthetic')
|
||||
notes = root / 'docs/release/0.1/RELEASE_NOTES.md'
|
||||
|
||||
@@ -10,7 +10,7 @@ import zipfile
|
||||
|
||||
|
||||
def validate(directory, windows):
|
||||
products = {'openbmh_play.exe', 'openbmh_cli.exe'} if windows else {'openbmh_play', 'openbmh_cli'}
|
||||
products = {name + ('.exe' if windows else '') for name in ('openbmh_play', 'openbmh_cli', 'openbmh_import')}
|
||||
documents = {'README.md', 'LICENSE', 'THIRD_PARTY_NOTICES.md', 'ACKNOWLEDGEMENTS.md', 'CONTRIBUTING.md'}
|
||||
licenses = {'README.md', 'LGPL-2.1.txt', 'Nuked-OPL3-notices.txt', 'LZMA-SDK.txt', 'SDL2-HIDAPI-BSD.txt',
|
||||
'SDL2-HIDAPI-options.txt', 'SDL2-HIDAPI-original.txt', 'SDL2-yuv2rgb.txt',
|
||||
|
||||
Reference in new issue
Block a user