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:
1 parent
6aa7c4f4a2
commit
524b9e4158
15 files changed
+4262
-23
No files matched your search
@@ -213,6 +213,7 @@ add_library(bmhcore STATIC
|
||||
src/formats/textd.cpp
|
||||
src/formats/fbm.cpp
|
||||
src/formats/le.cpp
|
||||
src/formats/diamond_image.cpp
|
||||
src/formats/m3d.cpp
|
||||
src/formats/savestate.cpp
|
||||
src/game/schedule.cpp
|
||||
@@ -1191,6 +1192,10 @@ add_test(NAME daily_interest_unit_tests COMMAND daily_interest_unit_tests)
|
||||
add_executable(transfer_seller_actions_tests tests/transfer_seller_actions_tests.cpp)
|
||||
target_link_libraries(transfer_seller_actions_tests PRIVATE bmhcore)
|
||||
add_test(NAME transfer_seller_actions_tests COMMAND transfer_seller_actions_tests)
|
||||
add_executable(diamond_image_tests tests/diamond_image_tests.cpp)
|
||||
target_link_libraries(diamond_image_tests PRIVATE bmhcore)
|
||||
add_test(NAME diamond_image_tests COMMAND diamond_image_tests)
|
||||
bmh_add_data_test(NAME diamond_image_data_tests COMMAND diamond_image_tests "${BMH_DATA}")
|
||||
add_executable(search_profile_tests tests/search_profile_tests.cpp)
|
||||
target_link_libraries(search_profile_tests PRIVATE bmhcore)
|
||||
add_test(NAME search_profile_tests COMMAND search_profile_tests)
|
||||
|
||||
@@ -7,7 +7,7 @@ werden separat als **[OpenBMH-Extended 1.0 Beta](https://github.com/Weyoune/Open
|
||||
|
||||
A faithful, standalone community reconstruction of *Bundesliga Manager Hattrick*, using the player's original installation and SDL2 interface.
|
||||
|
||||
OpenBMH 1.0 builds on v0.1.2 with reviewed bug fixes and starts directly with the original game data. Original game files, graphics, audio and manuals are not distributed. German CD-compatible BMH and verified Diamond editions are the primary release targets. Football Limited remains experimental; the older floppy executable is not supported.
|
||||
OpenBMH 1.0 builds on v0.1.2 with reviewed bug fixes and starts directly with the original game data. Original game files, graphics, audio, texts and manuals are not distributed. German CD-compatible BMH and verified Diamond editions are the primary release targets. Football Limited remains experimental; the older floppy executable is not supported.
|
||||
|
||||
This is an independent community project, with no affiliation with or endorsement by the original rights holders, the DFL or the Bundesliga. It is an engine implementation, not an official source release or a remaster.
|
||||
|
||||
@@ -15,9 +15,10 @@ This is an independent community project, with no affiliation with or endorsemen
|
||||
|
||||
Check the [releases page](https://github.com/Weyoune/openbmh/releases) for available packages and their platform notes. A Windows package uses the name `OpenBMH-<version>-windows-x64.zip`. Availability and native validation are stated for each release; source build instructions do not establish platform support on their own.
|
||||
|
||||
1. Have your own supported game installation available.
|
||||
1. Have your own supported game installation available. OpenBMH needs its asset files (texts, master database, pictures, fonts, sounds); neither `BMH.EXE` nor `FLTD.EXE` is required: the numbers and texts of the Diamond 3.7 executable and of the English Football Limited are built in.
|
||||
2. Extract the OpenBMH package into a separate directory, or alongside the game files.
|
||||
3. Start `OpenBMH` (`OpenBMH.exe` on Windows). Select the game directory or executable when prompted. A ZIP or 7z containing one game installation can also be selected.
|
||||
3. Start `OpenBMH` (`OpenBMH.exe` on Windows). Select the game directory (or `BMH.EXE`) when prompted. A ZIP or 7z containing one game installation can also be selected.
|
||||
4. A BMH.EXE (or FLTD.EXE) that stays in the game directory is used as before; it carries its own edition's numbers and texts.
|
||||
|
||||
From a terminal in the extracted package on Linux or macOS:
|
||||
|
||||
@@ -104,7 +105,7 @@ Reports with reproducible steps, documentation corrections and focused patches a
|
||||
|
||||
## How the project was developed
|
||||
|
||||
The implementation grew from study of file formats and behaviour of a legally obtained game installation. The public repository contains independently written implementation and format documentation. It does not contain the proprietary implementation or its extracted resources.
|
||||
The implementation grew from study of file formats and behaviour of a legally obtained game installation. The public repository contains independently written implementation and format documentation. It also contains the numeric tables and constants of the Diamond edition 3.7 executable (rates, positions, prices; `src/formats/diamond_constants.inc`, generated by `tools/diamond_constants`) so that the game runs from its asset files alone. It does not contain the executable's program code or any original game text, graphics, audio or master data.
|
||||
|
||||
## License and thanks
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -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
|
||||
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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;
|
||||
|
||||
@@ -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
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// The game without BMH.exe and FLTD.EXE (formats/diamond_image.*): the images built from the embedded numbers and texts
|
||||
// of the Diamond 3.7 executable and of the English Football Limited. Usage: diamond_image_tests [<BMH data dir>]
|
||||
// (with a data directory the embedded German image is also compared byte for byte with its BMH.exe).
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "formats/diamond_image.hpp"
|
||||
#include "formats/le.hpp"
|
||||
|
||||
using namespace bmh;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr uint32_t kImageStart = 0x10000, kMinimumSize = 0xB0000; // where the image begins and its least size
|
||||
int failures = 0;
|
||||
void require(bool ok, const char* what) {
|
||||
if (!ok) { std::cerr << "FAIL: " << what << "\n"; ++failures; }
|
||||
}
|
||||
|
||||
bool contains_text(const LeImage& image, const std::string& text) {
|
||||
const auto& b = image.bytes();
|
||||
return std::search(b.begin(), b.end(), text.begin(), text.end()) != b.end();
|
||||
}
|
||||
|
||||
void german() {
|
||||
const LeImage image = diamond_constants_image();
|
||||
require(image.size() > kMinimumSize && image.base() == kImageStart, "the German image has the layout of the Diamond data object");
|
||||
// the game texts are built in: a line of the live commentary
|
||||
require(contains_text(image, "DER LINIENRICHTER HAT DIE FAHNE OBEN"), "the German texts are embedded");
|
||||
// the letter tables of the cup draw and fixtures are numbers of the image
|
||||
require(contains_text(image, "abcdefghijklmnopqrst"), "the fixture letter tables are embedded");
|
||||
}
|
||||
|
||||
void english() {
|
||||
const LeImage image = english_constants_image();
|
||||
require(image.base() == kImageStart && image.size() > kMinimumSize, "the English image lies in the German address space");
|
||||
require(contains_text(image, "Competition closed"), "the English texts are embedded");
|
||||
}
|
||||
|
||||
void missing_executable() {
|
||||
// a BMH.exe that is not there stands for the embedded German image
|
||||
const fs::path nowhere = fs::temp_directory_path() / "openbmh-no-such-directory" / "BMH.exe";
|
||||
const LeImage loaded = load_le(nowhere);
|
||||
const LeImage embedded = diamond_constants_image();
|
||||
require(loaded.bytes() == embedded.bytes() && loaded.base() == embedded.base(), "a missing BMH.exe loads the embedded image");
|
||||
require(is_executable_name("bmh.EXE") && !is_executable_name("TEXTD.BLK"), "is_executable_name");
|
||||
}
|
||||
|
||||
void against_real_executable(const fs::path& directory) {
|
||||
fs::path exe;
|
||||
for (const auto& entry : fs::directory_iterator(directory))
|
||||
if (is_executable_name(entry.path().filename())) exe = entry.path();
|
||||
if (exe.empty()) return;
|
||||
const LeImage real = load_le(exe);
|
||||
const LeImage embedded = diamond_constants_image();
|
||||
// the embedded image is the Diamond 3.7 data object: every byte of it that is not zero equals the executable
|
||||
if (real.size() != embedded.size()) { std::cout << "(the executable is not Diamond 3.7: embedded numbers not compared)\n"; return; }
|
||||
size_t compared = 0, different = 0;
|
||||
for (uint32_t i = 0; i < embedded.size(); ++i) {
|
||||
const uint8_t value = embedded.bytes()[i];
|
||||
if (!value) continue;
|
||||
++compared;
|
||||
if (real.bytes()[i] != value) ++different;
|
||||
}
|
||||
if (different) std::cout << "(the executable differs from the embedded Diamond 3.7 in " << different << " of " << compared << " bytes)\n";
|
||||
else std::cout << "all " << compared << " embedded bytes equal BMH.exe\n";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) try {
|
||||
german();
|
||||
english();
|
||||
missing_executable();
|
||||
if (argc > 1) against_real_executable(argv[1]);
|
||||
if (failures) return 1;
|
||||
std::cout << "PASS embedded German and English images\n";
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "FAIL: " << e.what() << "\n";
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generates the embedded game images of OpenBMH, so that the game runs from the asset files alone (no BMH.exe, no
|
||||
FLTD.EXE): src/formats/diamond_constants.inc (German, Diamond 3.7) and src/formats/fltd_constants.inc (English
|
||||
Football Limited). Both hold every non-zero byte of the data the engine reads - tables, rates, positions, prices and the
|
||||
game texts - as runs of bytes; zero runs are not stored.
|
||||
|
||||
German (a Diamond 3.7 BMH.exe, read here and never copied into the repository):
|
||||
python generate.py german --exe BMH.exe --trace trace1.txt [--trace trace2.txt ...] --out ../../src/formats/diamond_constants.inc
|
||||
The file backed part of the data object, plus the few bytes of the code object that the program reads as numbers or
|
||||
tables (instruction immediates such as the calendar setup). The code bytes come from the read traces of OPENBMH_LE_TRACE
|
||||
(formats/le.hpp: run the data dependent tests and scenarios with the variable set to a file; the lines are
|
||||
"<flag> <start> <length>" in hex, flag 1 = number read, 2 = string read, 4 = start of a bulk read) and from a window
|
||||
at every layout constant that names a place in the code objects.
|
||||
|
||||
English (the German layout image of FLTD.EXE, the cached "BMH.exe" of an English game that translate_fltd() made):
|
||||
python generate.py english --image BMH.exe --out ../../src/formats/fltd_constants.inc
|
||||
Every non-zero byte of the image.
|
||||
"""
|
||||
import argparse
|
||||
import re
|
||||
import struct
|
||||
from pathlib import Path
|
||||
|
||||
DATA_LO, DATA_PAGES = 0xA0000, 12 # the initialised pages of the data object (file backed)
|
||||
DATA_HI = DATA_LO + DATA_PAGES * 4096
|
||||
CODE = (0x10000, 0x10000 + 438272)
|
||||
PATCH = (0x80000, 0x81000)
|
||||
|
||||
|
||||
def load_le(path):
|
||||
"""The loaded image of a DOS/4GW LE executable (objects at their link addresses, internal fixups applied)."""
|
||||
raw = Path(path).read_bytes()
|
||||
u16 = lambda o: struct.unpack_from("<H", raw, o)[0]
|
||||
u32 = lambda o: struct.unpack_from("<I", raw, o)[0]
|
||||
le = u32(0x3C)
|
||||
if u16(le) != 0x454C:
|
||||
raise SystemExit("no LE header")
|
||||
h = lambda off: u32(le + off)
|
||||
pages, page_size, last_page = h(0x14), h(0x28), h(0x2C)
|
||||
object_table, page_map = le + h(0x40), le + h(0x48)
|
||||
fixup_pages, fixup_records = le + h(0x68), le + h(0x6C)
|
||||
objects, data_pages = h(0x44), h(0x80)
|
||||
obj, lo, hi = [], 0xFFFFFFFF, 0
|
||||
for i in range(objects):
|
||||
o = object_table + i * 24
|
||||
ob = (u32(o), u32(o + 4), u32(o + 8), u32(o + 12), u32(o + 16)) # vsize, base, flags, page index, pages
|
||||
obj.append(ob)
|
||||
span = max(ob[0], ob[4] * page_size)
|
||||
lo, hi = min(lo, ob[1]), max(hi, ob[1] + (span + page_size - 1) // page_size * page_size)
|
||||
data = bytearray(hi - lo)
|
||||
page_address = [0] * (pages + 1)
|
||||
for vsize, base, flags, index, count in obj:
|
||||
for p in range(count):
|
||||
logical = index + p
|
||||
e = page_map + (logical - 1) * 4
|
||||
file_page = raw[e] << 16 | raw[e + 1] << 8 | raw[e + 2]
|
||||
va = base + p * page_size
|
||||
if logical <= pages:
|
||||
page_address[logical] = va
|
||||
if raw[e + 3] != 0:
|
||||
continue
|
||||
size = last_page if file_page == pages else page_size
|
||||
src = data_pages + (file_page - 1) * page_size
|
||||
size = min(size, len(raw) - src)
|
||||
data[va - lo:va - lo + size] = raw[src:src + size]
|
||||
|
||||
def put(pos, fmt, v):
|
||||
struct.pack_into(fmt, data, pos, v & ((1 << (8 * struct.calcsize(fmt))) - 1))
|
||||
|
||||
for pg in range(1, pages + 1):
|
||||
r = fixup_records + u32(fixup_pages + (pg - 1) * 4)
|
||||
end = fixup_records + u32(fixup_pages + pg * 4)
|
||||
while r < end:
|
||||
src, flags = raw[r], raw[r + 1]
|
||||
r += 2
|
||||
ftype, is_list = src & 0x0F, bool(src & 0x20)
|
||||
count, source_offset = 1, 0
|
||||
if is_list:
|
||||
count = raw[r]; r += 1
|
||||
else:
|
||||
source_offset = struct.unpack_from("<h", raw, r)[0]; r += 2
|
||||
if flags & 3:
|
||||
raise SystemExit("external fixup")
|
||||
if flags & 0x40:
|
||||
target_object = u16(r); r += 2
|
||||
else:
|
||||
target_object = raw[r]; r += 1
|
||||
target_offset = 0
|
||||
if ftype != 0x02:
|
||||
if flags & 0x10:
|
||||
target_offset = u32(r); r += 4
|
||||
else:
|
||||
target_offset = u16(r); r += 2
|
||||
offsets = []
|
||||
if is_list:
|
||||
for _ in range(count):
|
||||
offsets.append(struct.unpack_from("<h", raw, r)[0]); r += 2
|
||||
else:
|
||||
offsets.append(source_offset)
|
||||
target = obj[target_object - 1][1] + target_offset
|
||||
for so in offsets:
|
||||
sa = page_address[pg] + so
|
||||
pos = sa - lo
|
||||
if pos < 0 or pos + 4 > len(data):
|
||||
continue
|
||||
if ftype == 0x07: put(pos, "<I", target)
|
||||
elif ftype == 0x08: put(pos, "<I", target - (sa + 4))
|
||||
elif ftype == 0x05: put(pos, "<H", target)
|
||||
elif ftype == 0x02: put(pos, "<H", target_object)
|
||||
elif ftype == 0x06: put(pos, "<I", target); put(pos + 4, "<H", target_object)
|
||||
return lo, data
|
||||
|
||||
|
||||
def load_openbmh_image(path):
|
||||
raw = Path(path).read_bytes()
|
||||
if raw[:14] != b"OPENBMH-IMAGE\0":
|
||||
raise SystemExit("not an OPENBMH-IMAGE file")
|
||||
base, size = struct.unpack_from("<II", raw, 14)
|
||||
data = raw[22:]
|
||||
if len(data) != size:
|
||||
raise SystemExit("OPENBMH-IMAGE: wrong size")
|
||||
return base, bytearray(data)
|
||||
|
||||
|
||||
def read_traces(paths):
|
||||
numbers, bulk = [], []
|
||||
for path in paths:
|
||||
for line in Path(path).read_text().splitlines():
|
||||
flag, start, length = (int(x, 16) for x in line.split())
|
||||
if flag == 1:
|
||||
numbers.append((start, length))
|
||||
elif flag == 4:
|
||||
bulk.append((start, length))
|
||||
return numbers, bulk
|
||||
|
||||
|
||||
def merge(ranges, gap=0):
|
||||
out = []
|
||||
for start, end in sorted((s, s + l) for s, l in ranges):
|
||||
if out and start <= out[-1][1] + gap:
|
||||
out[-1][1] = max(out[-1][1], end)
|
||||
else:
|
||||
out.append([start, end])
|
||||
return out
|
||||
|
||||
|
||||
def nonzero_runs(data, base, lo, hi, gap=8):
|
||||
"""[start, end) runs that hold every non-zero byte of lo..hi; zero gaps up to `gap` bytes stay inside a run."""
|
||||
runs, cur = [], None
|
||||
for address in range(lo, hi):
|
||||
if data[address - base]:
|
||||
if cur and address - cur[1] <= gap:
|
||||
cur[1] = address + 1
|
||||
else:
|
||||
cur = [address, address + 1]
|
||||
runs.append(cur)
|
||||
return runs
|
||||
|
||||
|
||||
def write_inc(path, title, base, data, chunks):
|
||||
out = ["// SPDX-License-Identifier: GPL-3.0-only",
|
||||
f"// Generated by tools/diamond_constants/generate.py from {title} - do not edit.",
|
||||
"// Every non-zero byte of the data the engine reads (tables, rates, positions, prices, game texts), as runs.",
|
||||
"// Included inside a namespace by formats/diamond_image.cpp.",
|
||||
f"inline constexpr uint32_t kImageBase = {base}, kImageSize = {len(data)};"]
|
||||
total = 0
|
||||
for i, (start, end) in enumerate(chunks):
|
||||
body = data[start - base:end - base]
|
||||
total += len(body)
|
||||
rows = [", ".join(f"0x{b:02X}" for b in body[k:k + 24]) for k in range(0, len(body), 24)]
|
||||
out.append(f"inline constexpr uint8_t kChunk{i}[] = {{\n " + ",\n ".join(rows) + "};")
|
||||
out.append("inline constexpr Chunk kChunks[] = {")
|
||||
for i, (start, end) in enumerate(chunks):
|
||||
out.append(f" {{{start}, {end - start}, kChunk{i}}},")
|
||||
out.append("};")
|
||||
Path(path).write_text("\n".join(out) + "\n")
|
||||
print(f"{len(chunks)} chunks, {total} bytes")
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
sub = ap.add_subparsers(dest="mode", required=True)
|
||||
de = sub.add_parser("german")
|
||||
de.add_argument("--exe", required=True)
|
||||
de.add_argument("--trace", action="append", default=[])
|
||||
de.add_argument("--layout", default=str(Path(__file__).parents[2] / "src/formats/executable_layout.hpp"))
|
||||
de.add_argument("--out", required=True)
|
||||
en = sub.add_parser("english")
|
||||
en.add_argument("--image", required=True)
|
||||
en.add_argument("--out", required=True)
|
||||
args = ap.parse_args()
|
||||
|
||||
if args.mode == "english":
|
||||
base, data = load_openbmh_image(args.image)
|
||||
write_inc(args.out, "the German layout image of FLTD.EXE (Football Limited)", base, data,
|
||||
nonzero_runs(data, base, base, base + len(data)))
|
||||
return
|
||||
|
||||
base, data = load_le(args.exe)
|
||||
numbers, bulk = read_traces(args.trace)
|
||||
layout = Path(args.layout).read_text()
|
||||
# numbers read from the code or patch object: the bytes read, a margin, and a window after bulk pointers
|
||||
wanted = []
|
||||
for s, l in numbers:
|
||||
if CODE[0] <= s < CODE[1] or PATCH[0] <= s < PATCH[1]:
|
||||
wanted.append((max(s - 4, 0), l + 8))
|
||||
for s, l in bulk:
|
||||
if CODE[0] <= s < CODE[1] or PATCH[0] <= s < PATCH[1]:
|
||||
wanted.append((s, 256))
|
||||
# and, whatever the traces saw, a window at every layout constant that names a place in the code objects
|
||||
for name, address in re.findall(r"inline constexpr auto (\w+) = 0x([0-9a-fA-F]+);", layout):
|
||||
a = int(address, 16)
|
||||
if CODE[0] <= a < CODE[1] or PATCH[0] <= a < PATCH[1]:
|
||||
wanted.append((a, 16))
|
||||
chunks = sorted(nonzero_runs(data, base, DATA_LO, DATA_HI) + merge(wanted, 16))
|
||||
write_inc(args.out, "BMH 2026-27 Diamond edition 3.7", base, data, chunks)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user