Run from the asset files alone: built-in numbers and texts for BMH and FLTD

The game no longer needs BMH.EXE or FLTD.EXE. The numbers and the game texts of
the Diamond 3.7 executable and of the English Football Limited are generated into
formats/diamond_constants.inc and formats/fltd_constants.inc (tools/diamond_constants).
A missing BMH.exe loads the embedded German image, an English installation without
FLTD.EXE gets the embedded English image; an executable that is present is used as
before. The default manager name is OpenBMH. The launcher accepts directories and
archives that hold only the asset files. Replays of a recorded session give identical
output with and without BMH.EXE, and the English image equals the translated one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-11-08 14:04:34 +01:00
1 parent 6aa7c4f4a2
commit 524b9e4158
15 files changed
+4262 -23

No files matched your search

File diff suppressed because it is too large. Load diff
+46
View File
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: GPL-3.0-only
// Implementation of diamond_image.hpp: the images built from the embedded data of the generated .inc files.
#include "formats/diamond_image.hpp"
#include <algorithm>
#include <cctype>
#include <string>
namespace bmh {
namespace {
struct Chunk { uint32_t address; uint32_t size; const uint8_t* bytes; };
namespace german {
#include "formats/diamond_constants.inc"
} // namespace german
namespace english {
#include "formats/fltd_constants.inc"
} // namespace english
LeImage build(uint32_t base, uint32_t size, const Chunk* first, const Chunk* last) {
Bytes bytes(size, 0);
for (const Chunk* chunk = first; chunk != last; ++chunk)
std::copy(chunk->bytes, chunk->bytes + chunk->size, bytes.begin() + (chunk->address - base));
return LeImage::from_bytes(base, std::move(bytes));
}
std::string lower(std::string s) {
for (char& c : s) c = char(std::tolower(static_cast<unsigned char>(c)));
return s;
}
} // namespace
LeImage diamond_constants_image() {
return build(german::kImageBase, german::kImageSize, std::begin(german::kChunks), std::end(german::kChunks));
}
LeImage english_constants_image() {
return build(english::kImageBase, english::kImageSize, std::begin(english::kChunks), std::end(english::kChunks));
}
bool is_executable_name(const std::filesystem::path& file_name) { return lower(file_name.string()) == "bmh.exe"; }
} // namespace bmh
+29
View File
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-3.0-only
// The game without BMH.exe and FLTD.EXE: OpenBMH carries the numbers and texts of the Diamond 3.7 executable (tables,
// rates, positions, prices, live commentary, messages; the generated formats/diamond_constants.inc) and of the English
// Football Limited (formats/fltd_constants.inc) and needs only the asset files of the game.
//
// load_le() returns diamond_constants_image() for a BMH.exe that does not exist, so every reader of the executable image
// works unchanged. A BMH.exe that is there is used as before (it carries its own edition's numbers and texts). For an
// English installation the launcher (launch/fltd.cpp) writes english_constants_image() as the image of the game
// directory when FLTD.EXE is missing.
#pragma once
#include <filesystem>
#include "formats/binary.hpp"
#include "formats/le.hpp"
namespace bmh {
// The German (Diamond 3.7) image built from the embedded data.
LeImage diamond_constants_image();
// The English Football Limited image in the German address space, built from the embedded data (what
// launch::translate_fltd() makes from FLTD.EXE).
LeImage english_constants_image();
// Whether `file_name` is the name of the executable (BMH.exe in any case).
bool is_executable_name(const std::filesystem::path& file_name);
} // namespace bmh
File diff suppressed because it is too large. Load diff
+66 -1
View File
@@ -6,7 +6,11 @@
// LeImage::cstring() reads NUL-terminated strings from the image. No global state.
#include "formats/le.hpp"
#include "formats/diamond_image.hpp"
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <vector>
@@ -22,10 +26,63 @@ struct Object {
std::string LeImage::cstring(uint32_t address) const {
std::string s;
while (contains(address) && u8(address) != 0) s.push_back(char(u8(address++)));
const uint32_t first = address;
while (contains(address) && bytes_[address - base_] != 0) s.push_back(char(bytes_[address++ - base_]));
if (le_trace::hook) le_trace::hook(first, uint32_t(s.size()) + 1, 't');
return s;
}
namespace le_trace {
void (*hook)(uint32_t, uint32_t, char) = nullptr;
namespace {
// One flag byte per image address: 1 number read, 2 string read, 4 start of a bulk read.
std::vector<uint8_t>& marks() {
static std::vector<uint8_t> value(0x100000, 0);
return value;
}
std::string& trace_path() {
static std::string value;
return value;
}
void record(uint32_t address, uint32_t length, char kind) {
auto& m = marks();
const uint8_t flag = kind == 'n' ? 1 : kind == 't' ? 2 : 4;
if (address < 0x10000 || address - 0x10000 >= m.size()) return;
if (length == 0) length = 1;
for (uint32_t i = 0; i < length && address - 0x10000 + i < m.size(); ++i) m[address - 0x10000 + i] |= flag;
}
// Appends the marked ranges ("<flag> <start> <length>" in hex, one per line) to the trace file.
void flush() {
if (trace_path().empty()) return;
std::ofstream out(trace_path(), std::ios::app);
const auto& m = marks();
for (uint8_t flag : {uint8_t(1), uint8_t(2), uint8_t(4)}) {
size_t i = 0;
while (i < m.size()) {
if (!(m[i] & flag)) { ++i; continue; }
size_t j = i;
while (j < m.size() && (m[j] & flag)) ++j;
out << std::hex << unsigned(flag) << ' ' << (i + 0x10000) << ' ' << (j - i) << '\n';
i = j;
}
}
}
} // namespace
void enable_from_environment() {
static bool done = false;
if (done) return;
done = true;
if (const char* path = std::getenv("OPENBMH_LE_TRACE"); path && *path) {
trace_path() = path;
(void)marks(); // constructed before atexit(flush) is registered, so it is destroyed after flush has run
hook = record;
std::atexit(flush);
}
}
} // namespace le_trace
namespace {
constexpr char kImageMagic[14] = "OPENBMH-IMAGE"; // 13 characters and the NUL
}
@@ -41,6 +98,14 @@ void save_image(const LeImage& image, const std::filesystem::path& path) {
}
LeImage load_le(const std::filesystem::path& path) {
le_trace::enable_from_environment();
// The game runs from its asset files alone: for a BMH.exe that is not there the embedded numbers and texts of the
// Diamond 3.7 executable stand in for it.
{
std::error_code ec;
if (is_executable_name(path.filename()) && !std::filesystem::exists(path, ec))
return diamond_constants_image();
}
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; };
+16 -2
View File
@@ -16,19 +16,33 @@
namespace bmh {
// Read recording for building the embedded constants (formats/diamond_constants.inc): when the environment variable
// OPENBMH_LE_TRACE names a file, every image read is noted (numbers, strings, bulk pointers) and appended to that
// file when the program ends. Without the variable the hook is a null pointer and costs one branch per read.
namespace le_trace {
extern void (*hook)(uint32_t address, uint32_t length, char kind); // kind: 'n' number, 't' string, 'b' bulk pointer
void enable_from_environment();
} // namespace le_trace
class LeImage {
public:
uint32_t base() const { return base_; }
uint32_t size() const { return uint32_t(bytes_.size()); }
bool contains(uint32_t address) const { return address >= base_ && address - base_ < bytes_.size(); }
uint8_t u8(uint32_t address) const { return bytes_.at(address - base_); }
uint8_t u8(uint32_t address) const {
if (le_trace::hook) le_trace::hook(address, 1, 'n');
return bytes_.at(address - base_);
}
uint16_t u16(uint32_t address) const { return uint16_t(u8(address) | u8(address + 1) << 8); }
uint32_t u32(uint32_t address) const { return uint32_t(u16(address)) | uint32_t(u16(address + 2)) << 16; }
// A NUL terminated string at `address` (ISO 646-DE bytes, see textd.hpp).
std::string cstring(uint32_t address) const;
// The string a pointer variable at `address` points to (e.g. Weekly_AdvertisingOffers_TextPointer).
std::string string_at_pointer(uint32_t address) const { return cstring(u32(address)); }
const uint8_t* data(uint32_t address) const { return bytes_.data() + (address - base_); }
const uint8_t* data(uint32_t address) const {
if (le_trace::hook) le_trace::hook(address, 0, 'b');
return bytes_.data() + (address - base_);
}
// Overwrites bytes inside a prepared image for verified address translation.
void patch(uint32_t address, const uint8_t* bytes, size_t count) {
for (size_t i = 0; i < count; ++i) bytes_.at(address - base_ + i) = bytes[i];
+3 -2
View File
@@ -19,6 +19,7 @@
#include <vector>
#include "formats/binary.hpp"
#include "formats/diamond_image.hpp"
#include "launch/archive.hpp"
#include "launch/game_data.hpp"
@@ -169,9 +170,9 @@ bool prepare_english_game(const fs::path& source, const fs::path& target, std::s
}
if (auto f = find_file(source, "TEXTE.BLK")) copy(*f, target / "TEXTD.BLK");
if (auto f = find_file(source, "M3E.MAN")) copy(*f, target / "M3D.MAN");
// FLTD.EXE is optional: without it the numbers and texts built into OpenBMH stand in (formats/diamond_image.hpp)
const auto exe = find_file(source, "FLTD.EXE");
if (!exe) throw std::runtime_error("FLTD.EXE is missing");
save_image(translate_fltd(*exe), target / "BMH.exe");
save_image(exe ? translate_fltd(*exe) : english_constants_image(), target / "BMH.exe");
return true;
} catch (const std::exception& e) {
error = e.what();
+54 -13
View File
@@ -18,6 +18,7 @@
#include <system_error>
#include "formats/binary.hpp"
#include "formats/diamond_image.hpp"
#include "formats/le.hpp"
#include "formats/m3d.hpp"
#include "formats/textd.hpp"
@@ -71,6 +72,22 @@ std::optional<Family> family_of_exe(const std::string& file_name) {
return std::nullopt;
}
// Whether `directory` holds the asset files of the English game (FLTD.EXE is not needed: its numbers and texts are built in).
bool has_english_assets(const fs::path& directory) {
std::error_code ec;
if (!fs::is_directory(directory, ec)) return false;
const auto kb = find_file(directory, "KB");
return find_file(directory, "TEXTE.BLK") && find_file(directory, "M3E.MAN") && kb && fs::is_directory(*kb, ec);
}
// Whether `directory` holds the asset files of the German game (the executable is not needed: its numbers are built in).
bool has_german_assets(const fs::path& directory) {
std::error_code ec;
if (!fs::is_directory(directory, ec)) return false;
const auto kb = find_file(directory, "KB");
return find_file(directory, "TEXTD.BLK") && find_file(directory, "M3D.MAN") && kb && fs::is_directory(*kb, ec);
}
// Every game EXE directly in `directory`.
std::vector<std::pair<Family, fs::path>> game_exes(const fs::path& directory) {
std::vector<std::pair<Family, fs::path>> out;
@@ -150,24 +167,26 @@ std::string text_title(const std::string& raw) {
void check_german(GameCheck& c) {
// (a translated English game has BMH.exe in the OpenBMH image format, launch/fltd.hpp)
bool image = false;
if (const auto exe = find_file(c.directory, "BMH.EXE")) {
const auto exe = find_file(c.directory, "BMH.EXE");
if (exe) {
std::ifstream in(*exe, std::ios::binary);
char head[13] = {};
in.read(head, sizeof head);
image = std::string(head, sizeof head) == "OPENBMH-IMAGE";
require(c, c.directory, "BMH.EXE", image ? 0 : 602527, "BMH.EXE");
}
require(c, c.directory, "BMH.EXE", image ? 0 : 602527, "BMH.EXE");
require(c, c.directory, "TEXTD.BLK", 0, "TEXTD.BLK");
require(c, c.directory, "M3D.MAN", 0, "M3D.MAN");
for (const Required& r : kCommon) require(c, c.directory, r.name, r.size, r.name);
require_media(c);
if (!c.problems.empty()) return;
// the files must also load: the engine reads tables from the EXE, the texts and the
// database of clubs and players
// the files must also load: the engine reads tables from the EXE (or the built-in numbers and texts), the
// texts and the database of clubs and players
try {
load_le(*find_file(c.directory, "BMH.EXE"));
load_le(exe ? *exe : c.directory / "BMH.EXE");
} catch (const std::exception& e) {
c.problems.push_back(std::string("BMH.EXE cannot be read: ") + e.what());
c.problems.push_back(std::string("BMH.EXE") + " cannot be read: " + e.what());
}
try {
const TextDb texts = load_textd(*find_file(c.directory, "TEXTD.BLK"));
@@ -187,7 +206,8 @@ void check_german(GameCheck& c) {
}
void check_english(GameCheck& c) {
require(c, c.directory, "FLTD.EXE", 507925, "FLTD.EXE");
// (FLTD.EXE is optional: the numbers and texts of Football Limited are built into OpenBMH)
if (find_file(c.directory, "FLTD.EXE")) require(c, c.directory, "FLTD.EXE", 507925, "FLTD.EXE");
require(c, c.directory, "TEXTE.BLK", 0, "TEXTE.BLK");
require(c, c.directory, "M3E.MAN", 0, "M3E.MAN");
for (const Required& r : kCommon) require(c, c.directory, r.name, r.size, r.name);
@@ -258,11 +278,18 @@ ResolvedGame unpack(const fs::path& file, const fs::path& cache) {
if (is_archive_name(base)) nested = true;
if (upper(base) == "INSTALL.EXE") installer = true;
}
// no executable: the asset files are enough (the text block marks the game's folder)
if (exes.empty())
for (size_t i = 0; i < entries.size(); ++i) {
if (entries[i].directory) continue;
const std::string& n = entries[i].name;
{ const std::string leaf = upper(n.substr(n.find_last_of('/') + 1)); if (leaf == "TEXTD.BLK" || leaf == "TEXTE.BLK") exes.push_back(i); }
}
if (exes.empty()) {
if (installer) r.error = "The archive holds an installer (INSTALL.EXE), not an installed game.";
else if (nested) r.error = "The archive contains further archives (a box with several editions). "
"Please choose the archive of one edition.";
else r.error = "The archive contains no BMH.EXE or FLTD.EXE.";
else r.error = "The archive contains no BMH.EXE, FLTD.EXE or game asset files (TEXTD.BLK, TEXTE.BLK).";
return r;
}
if (exes.size() > 1) {
@@ -334,19 +361,32 @@ GameCheck check_game_directory(const fs::path& path) {
std::error_code ec;
fs::path dir = fs::is_directory(path, ec) ? path : path.parent_path();
auto exes = game_exes(dir);
if (exes.empty()) {
if (exes.empty() && !has_german_assets(dir) && !has_english_assets(dir)) {
// an edition folder with the game one level below (e.g. "BMH 2026-27 supported rule profile\BMH")
std::vector<fs::path> candidates;
for (const auto& e : fs::directory_iterator(dir, ec))
if (e.is_directory(ec) && !game_exes(e.path()).empty()) candidates.push_back(e.path());
if (e.is_directory(ec) && (!game_exes(e.path()).empty() || has_german_assets(e.path()) || has_english_assets(e.path()))) candidates.push_back(e.path());
if (candidates.size() == 1) {
dir = candidates[0];
exes = game_exes(dir);
}
}
c.directory = dir;
// The German game without BMH.EXE: the asset files are enough (the numbers of the executable are built in).
if (exes.empty() && has_german_assets(dir)) {
c.family = GameFamily::german;
check_german(c);
c.playable = c.problems.empty();
return c;
}
// The English game without FLTD.EXE: the asset files are enough as well.
if (exes.empty() && has_english_assets(dir)) {
c.family = GameFamily::english;
check_english(c);
return c;
}
if (exes.empty()) {
c.problems.push_back("no BMH.EXE or FLTD.EXE in " + path_to_utf8(dir));
c.problems.push_back("no BMH.EXE or FLTD.EXE in " + path_to_utf8(dir) + ", and no game asset files (TEXTD.BLK, M3D.MAN) or the English ones (TEXTE.BLK, M3E.MAN)");
return c;
}
// a named EXE decides; otherwise the German game before the English one
@@ -382,11 +422,11 @@ ResolvedGame resolve_game(const fs::path& input, const fs::path& cache) {
// The English Football Limited runs on the same engine through a German-layout data
// directory, built once in the cache (launch/fltd.hpp); its name follows FLTD.EXE.
if (game.error.empty() && game.check.family == GameFamily::english && game.check.problems.empty()) {
const fs::path prepared = cache / ("en-" + content_hash(game.check.exe));
const fs::path prepared = cache / ("en-" + (game.check.exe.empty() ? std::string("embedded") : content_hash(game.check.exe)));
const fs::path marker = prepared / ".openbmh-english";
// the version of the translation (launch/fltd.cpp, fltd_map.inc): a cache built
// by another version is built again
constexpr const char* kTranslation = "english translation 17"; // 17: English monthly environment tables (16: overwrite question)
constexpr const char* kTranslation = "english translation 18"; // 18: numbers and texts built in (no FLTD.EXE needed), 17: English monthly environment tables (16: overwrite question)
std::string built;
{
std::ifstream in(marker);
@@ -469,6 +509,7 @@ std::string describe(const ResolvedGame& game) {
if (!c.title.empty()) text += c.title + "\n";
text += path_to_utf8(c.directory) + "\n";
for (const auto& p : c.problems) text += "- " + p + "\n";
for (const auto& n : c.notes) text += "Note: " + n + "\n";
if (!c.unsupported.empty()) text += c.unsupported + "\n";
if (c.playable) text += "The game data is complete.\n";
return text;
+6
View File
@@ -10,6 +10,10 @@
// OpenBMH has one game and match engine (the supported rule profile rules); the original files are only
// data. The check therefore asks whether the data is complete and readable, not which
// edition it is. Fan extras next to the files (pictures, manuals) are ignored.
//
// The German game does not need BMH.EXE: the numbers of the executable are built into OpenBMH (formats/diamond_image.hpp).
// A directory with the asset files (TEXTD.BLK, M3D.MAN, the picture, font and sound folders) is a complete game; the
// texts of the executable are built in as well. The same holds for the English game (TEXTE.BLK, M3E.MAN; FLTD.EXE).
#include <cstdint>
#include <filesystem>
@@ -32,6 +36,8 @@ struct GameCheck {
std::filesystem::path exe; // the EXE as found (its case may differ)
std::string title; // e.g. "Bundesliga Manager Hattrick 2026-27 (supported rule profile)"
std::vector<std::string> problems; // missing or unreadable files; empty = data complete
// Hints that do not stop the game.
std::vector<std::string> notes;
// Data complete and the engine can run it. False also for complete data the engine does
// not run yet (`unsupported` says why).
bool playable = false;
+3 -1
View File
@@ -131,7 +131,9 @@ ManagerScreen::ManagerScreen(const std::filesystem::path& data, int slot, const
if (id < 0 || id >= int(db_.club_names.size()) || !unique.insert(id).second)
throw FormatError("manager selection: club order must contain unique valid master IDs");
choice_.slot = slot; choice_.roster_revision = context_.revision;
choice_.name = texts_[(::bmh::layout::Career_NewCareerMarketsAndMoods_ExecutableField - ::bmh::layout::TextPointerTable) / 4 + slot];
// The default name of a new manager: OpenBMH (the original text blocks offer "Nobody" for every slot). The player can still
// type another name; the name editor of the original keeps working on this string.
choice_.name = "OpenBMH";
while (club_locked(master_id(choice_.selection_club))) ++choice_.selection_club;
choice_.master_club = master_id(choice_.selection_club);
while (portrait_locked(choice_.portrait)) ++choice_.portrait;
+3
View File
@@ -38,6 +38,9 @@ std::filesystem::path asset_path(const std::filesystem::path& directory, const s
found = e.path();
}
}
// The game runs from its asset files alone: BMH.exe may be missing, load_le() then uses the embedded numbers of the
// Diamond executable (formats/diamond_image.hpp). The returned path simply does not exist.
if (found.empty() && folded(name) == "bmh.exe") return directory / "BMH.exe";
if (found.empty()) throw FormatError("missing original asset: " + (directory / name).string());
return found;
}