Compare commits

...
Author SHA1 Message Date
Codex 1771cb5599 Load standalone community data without DOS programs and match Original crest backgrounds (by Codex)
Prepare verified release / draft (push) Waiting to run
2026-10-31 11:43:25 +01:00
22 changed files with 454 additions and 19 deletions

No files matched your search

+10 -1
View File
@@ -5,7 +5,7 @@ if(APPLE)
# Enable native languages before dependencies/subdirectories inherit rules.
enable_language(OBJC OBJCXX)
endif()
set(OPENBMH_PRERELEASE "poc.1" CACHE STRING "Prerelease identifier; empty for final release")
set(OPENBMH_PRERELEASE "poc.2" CACHE STRING "Prerelease identifier; empty for final release")
set(OPENBMH_PRODUCT_VERSION "${PROJECT_VERSION}")
if(OPENBMH_PRERELEASE)
string(APPEND OPENBMH_PRODUCT_VERSION "-${OPENBMH_PRERELEASE}")
@@ -207,6 +207,7 @@ bmh_add_data_test(NAME highscore_tests REQUIRED_OPTIONS BMH_TEST_HIGHSCORE_TESTS
# Engine core: file formats and game logic, no platform dependencies
add_library(bmhcore STATIC
src/formats/binary.cpp
src/formats/resource_bundle.cpp
src/formats/palette.cpp
src/formats/vga.cpp
src/formats/font.cpp
@@ -305,6 +306,7 @@ FetchContent_MakeAvailable(miniz lzma_sdk nfd)
add_library(bmh_miniz STATIC ${miniz_SOURCE_DIR}/miniz.c)
target_include_directories(bmh_miniz PUBLIC ${miniz_SOURCE_DIR})
target_link_libraries(bmhcore PRIVATE bmh_miniz)
set(BMH_LZMA_C ${lzma_sdk_SOURCE_DIR}/C)
add_library(bmh_7z STATIC
${BMH_LZMA_C}/7zAlloc.c ${BMH_LZMA_C}/7zArcIn.c ${BMH_LZMA_C}/7zBuf.c ${BMH_LZMA_C}/7zCrc.c
@@ -1158,3 +1160,10 @@ bmh_add_data_test(NAME desktop_feedback_tests COMMAND desktop_feedback_tests "${
add_executable(data_profile_tests tests/data_profile_tests.cpp)
target_link_libraries(data_profile_tests PRIVATE bmhcore)
add_test(NAME data_profile_tests COMMAND data_profile_tests)
# Offline private package preparation; never installs Original data.
add_executable(export_community_runtime tools/poc/export_runtime.cpp)
target_link_libraries(export_community_runtime PRIVATE bmhcore)
add_executable(resource_bundle_tests tests/resource_bundle_tests.cpp)
target_link_libraries(resource_bundle_tests PRIVATE bmhcore bmh_miniz)
add_test(NAME resource_bundle_tests COMMAND resource_bundle_tests)
+2
View File
@@ -1,5 +1,7 @@
# OpenBMH
This is the **1.1 community development branch**. A prepared community package starts directly from `COMMUNITY.OBD`, without BMH.exe or a DOS installation. Original loose Classic installations remain supported. The stable 1.0 line stays on main. See [standalone community data](docs/poc-1.1/STANDALONE.md).
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.
+21
View File
@@ -0,0 +1,21 @@
# Standalone community data
The 1.1 community edition can start from `COMMUNITY.OBD` without an installed DOS game. The stable main line and loose Classic installation support remain separate.
`COMMUNITY.OBD` is a compressed read-only resource bundle. It contains the master database, text, palette, formations, desktop layout, fonts, indexed pictures/crests and audio containers required by OpenBMH. These are game content, not application code. Saves, highscores and user layouts remain normal writable files outside the bundle.
The bundle's `RUNTIME.DAT` uses the `OBMHDAT1` schema: data-segment base/length, calendar epoch, resolved badge/environment policies, data-segment bytes and explicitly named auxiliary labels. The exporter discards the DOS header, DOS/4GW loader and machine-code objects. Calendar and verified edition policies are values, rather than retained code fingerprints. This is not a renamed or embedded BMH executable.
The Classic address-view adapter still supplies the existing engine/UI table readers. It reads resource entries directly from the compressed bundle, without unpacking original executables or a cached DOS installation. Bundle paths are case-insensitive and reject duplicate/path-traversal entries; compressed/uncompressed limits bound allocations. Original loose installations retain their loading path.
Offline preparation from privately supplied resources:
```sh
cmake --build build --target export_community_runtime
python3 tools/poc/bundle_community.py --source /path/to/prepared-data \
--exporter /path/to/build/export_community_runtime --out /path/to/new/community-data
```
Only required resource types are included. DOS programs, installers, editor executables, original saves, backup directories, manuals and unused picture formats are excluded. Import provenance stays in `IMPORT-REPORT.json`; `PACKAGE.json` records the hashes of the bundled resources. A bundled `OBMHPROF.INI` selects the expanded league profile, so no additional loose Original files are needed.
Generated foreign crests now use the supplied Original domestic crest background texture. Transparent edges are composited onto that bright texture before palette reduction; actual black logo details remain black. The previous black rectangles and the light-on-dark monochrome workaround are removed.
+3 -1
View File
@@ -15,6 +15,8 @@ Implemented:
Local integration evidence so far: the expanded career completed 180 turns with seed 1 (three season ends), and another 180 with seed 11 (two season ends). No simulator invariant violations or contract-policy errors were reported. These are automated manager-policy runs, not claims of complete human gameplay QA or validation of all editions/platforms.
The prepared private dataset has 445 club/country entries, 3,334 players and 263 individual foreign club crests. Original German rosters and all 2,574 Original player word records are preserved by assertions during preparation. The visual review identified 175 usable supplied foreign crests and 88 missing/shared Original placeholders. Those 88 now have explicit fictional club-specific monograms instead of the computer symbol; very dark monochrome crests receive a documented contrast variant. Donor fields retain their real/fictional provenance. No original game content is committed here.
The prepared private dataset has 445 club/country entries, 3,334 players and 263 individual foreign club crests. Original German rosters and all 2,574 Original player word records are preserved by assertions during preparation. The visual review identified 175 usable supplied foreign crests and 88 missing/shared Original placeholders. Those 88 now have explicit fictional club-specific monograms instead of the computer symbol; the updated crest preparation uses the bright Original background texture and preserves black logo details. Donor fields retain their real/fictional provenance. No original game content is committed here.
Validation: 37 configured synthetic tests executed successfully, with 158 external-input tests explicitly skipped; four offline preparation tests passed. Extended save/reload and both cross-profile rejection paths passed. Two separate season-end snapshots each contain every fixture in all nine leagues. A Classic 80-turn run produces a byte-identical save to stable 1.0.2. Screenshots and saves are archived privately. Native platform CI also builds and tests Windows x64, macOS ARM64 and Linux x64; release QA receipts identify the exact successful revision. See [FORMAT.md](FORMAT.md) for dimensions, preparation and distribution boundaries. A development commit is not a completed release claim.
The next community package uses a data-only `COMMUNITY.OBD` bundle and no DOS executables. See [STANDALONE.md](STANDALONE.md). The Windows community ZIP omits source archives and loose PNG/JPEG studies; corresponding sources remain available separately.
+1
View File
@@ -12,6 +12,7 @@ inline int original_foreign_badge_end = 138;
inline bool expanded_badges = false;
inline int original_badge_gate(const LeImage& exe) {
if(const auto* policy=exe.runtime_policy())return int(policy->badge_end);
constexpr auto instruction = layout::ForeignBadgeGateInstruction;
if (exe.contains(instruction) && exe.contains(instruction + 6) &&
exe.u8(instruction) == 0x66 && exe.u8(instruction + 1) == 0x81 &&
+3
View File
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/binary.hpp"
#include "formats/resource_bundle.hpp"
#include <fstream>
#include <iterator>
@@ -7,6 +8,8 @@
namespace bmh {
Bytes read_file(const std::filesystem::path& path) {
if (!std::filesystem::exists(path))
if (auto bytes=bundled_resource(path)) return std::move(*bytes);
std::ifstream in(path, std::ios::binary);
if (!in) throw FormatError("cannot open " + path.string());
return Bytes(std::istreambuf_iterator<char>(in), {});
+4 -2
View File
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/data_profile.hpp"
#include "formats/resource_bundle.hpp"
#include <fstream>
#include <numeric>
#include <set>
@@ -24,8 +25,9 @@ void DataProfile::validate() const {
}
DataProfile load_data_profile(const std::filesystem::path& directory) {
const auto file=directory/"OBMHPROF.INI";
if(!std::filesystem::exists(file))return {};
std::ifstream input(file);if(!input)throw FormatError("profile: cannot read metadata");
if(!resource_exists(file))return {};
const auto raw=read_file(file);
std::istringstream input(std::string(raw.begin(),raw.end()));
std::string line,id;bool section=false,seen=false;
while(std::getline(input,line)) {
if(!line.empty()&&line.back()=='\r')line.pop_back();
+43
View File
@@ -18,6 +18,10 @@ struct Object {
} // namespace
std::string LeImage::cstring(uint32_t address) const {
if (runtime_policy_) {
const auto label=runtime_policy_->labels.find(address);
if(label!=runtime_policy_->labels.end())return label->second;
}
std::string s;
while (contains(address) && u8(address) != 0) s.push_back(char(u8(address++)));
return s;
@@ -37,6 +41,25 @@ void save_image(const LeImage& image, const std::filesystem::path& path) {
if (!file) throw FormatError("cannot write the OpenBMH image");
}
void save_runtime_image(const LeImage& image, const RuntimePolicy& policy, const std::filesystem::path& path) {
constexpr uint32_t start=layout::GermanDataSegmentBegin;
if(!image.contains(start) || policy.year<1600 || policy.year>9999 || policy.weekday>6 ||
(policy.badge_end!=90 && policy.badge_end!=138) || policy.environment_verified>1 || policy.labels.size()>16)
throw FormatError("runtime data: unsupported source policies");
const uint32_t size=image.base()+image.size()-start;
if(size>1024*1024)throw FormatError("runtime data: data segment too large");
Bytes out{'O','B','M','H','D','A','T','1'};
const auto put=[&](uint32_t value){for(int b=0;b<4;++b)out.push_back(uint8_t(value>>(8*b)));};
for(uint32_t value:{start,size,policy.year,policy.weekday,policy.badge_end,policy.environment_verified,uint32_t(policy.labels.size())})put(value);
out.insert(out.end(),image.data(start),image.data(start)+size);
for(const auto& [address,text]:policy.labels) {
if(text.size()>1024)throw FormatError("runtime data: label too long");
put(address);put(uint32_t(text.size()));out.insert(out.end(),text.begin(),text.end());
}
std::ofstream file(path,std::ios::binary|std::ios::trunc);file.write(reinterpret_cast<const char*>(out.data()),std::streamsize(out.size()));
if(!file)throw FormatError("cannot write runtime data");
}
LeImage load_le(const std::filesystem::path& path) {
const auto profile = load_data_profile(path.parent_path());
const auto apply_profile = [&](LeImage img) {
@@ -89,6 +112,26 @@ LeImage load_le(const std::filesystem::path& path) {
return img;
};
const Bytes raw = read_file(path);
if(raw.size()>=8 && std::string(raw.begin(),raw.begin()+8)=="OBMHDAT1") {
if(raw.size()<36)throw FormatError("runtime data: truncated header");
const uint32_t base=le32(raw,8),size=le32(raw,12),labels=le32(raw,32);
RuntimePolicy policy{le32(raw,16),le32(raw,20),le32(raw,24),le32(raw,28),{}};
if(base!=layout::GermanDataSegmentBegin || size>1024*1024 || size_t(size)+36>raw.size() || labels>16 ||
policy.year<1600 || policy.year>9999 || policy.weekday>6 || (policy.badge_end!=90 && policy.badge_end!=138) || policy.environment_verified>1)
throw FormatError("runtime data: invalid dimensions or policies");
auto image=LeImage::from_bytes(base,Bytes(raw.begin()+36,raw.begin()+36+size));
size_t at=36+size;
for(uint32_t i=0;i<labels;++i) {
if(at+8>raw.size())throw FormatError("runtime data: truncated label");
const auto address=le32(raw,at),length=le32(raw,at+4);at+=8;
if(length>1024 || at+length>raw.size() || !policy.labels.emplace(address,std::string(raw.begin()+at,raw.begin()+at+length)).second)
throw FormatError("runtime data: invalid label");
at+=length;
}
if(at!=raw.size())throw FormatError("runtime data: trailing bytes");
image.runtime_policy_=std::move(policy);
return apply_profile(std::move(image));
}
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);
+11
View File
@@ -11,11 +11,18 @@
#include <cstdint>
#include <filesystem>
#include <string>
#include <map>
#include <optional>
#include "formats/binary.hpp"
namespace bmh {
// Resolved edition policies, not copied machine instructions.
struct RuntimePolicy {
uint32_t year=0, weekday=0, badge_end=0, environment_verified=0;
std::map<uint32_t,std::string> labels;
};
class LeImage {
public:
uint32_t base() const { return base_; }
@@ -44,10 +51,12 @@ public:
}
const Bytes& bytes() const { return bytes_; }
bool expanded_profile() const { return expanded_profile_; }
const RuntimePolicy* runtime_policy() const { return runtime_policy_ ? &*runtime_policy_ : nullptr; }
friend LeImage load_le(const std::filesystem::path& path);
private:
std::optional<RuntimePolicy> runtime_policy_;
bool expanded_profile_ = false;
uint32_t base_ = 0;
Bytes bytes_;
@@ -60,5 +69,7 @@ LeImage load_le(const std::filesystem::path& path);
// 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.
void save_image(const LeImage& image, const std::filesystem::path& path);
// Exports only the data segment and resolved policy values, never DOS/LE/code objects.
void save_runtime_image(const LeImage&, const RuntimePolicy&, const std::filesystem::path&);
} // namespace bmh
+92
View File
@@ -0,0 +1,92 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/resource_bundle.hpp"
#include "miniz.h"
#include <algorithm>
#include <cctype>
#include <fstream>
#include <iterator>
#include <map>
#include <memory>
#include <mutex>
namespace bmh {
namespace {
std::string folded(std::string name) {
std::transform(name.begin(),name.end(),name.begin(),[](unsigned char ch){return char(std::toupper(ch));});
return name;
}
struct Bundle {
Bytes file;
mz_zip_archive zip{};
std::map<std::string,mz_uint> entries;
explicit Bundle(const std::filesystem::path& path) {
const auto size=std::filesystem::file_size(path);
if(size>64*1024*1024)throw FormatError("community bundle exceeds size limit");
std::ifstream input(path,std::ios::binary);
file.assign(std::istreambuf_iterator<char>(input),{});
if(!input.is_open() || file.size()!=size || !mz_zip_reader_init_mem(&zip,file.data(),file.size(),0))
throw FormatError("cannot read community bundle");
try {
uint64_t total=0;
const auto count=mz_zip_reader_get_num_files(&zip);
if(count>4096)throw FormatError("community bundle has too many entries");
for(mz_uint i=0;i<count;++i) {
mz_zip_archive_file_stat st{};
if(!mz_zip_reader_file_stat(&zip,i,&st))throw FormatError("invalid community directory");
if(st.m_is_directory)continue;
const std::string name=st.m_filename;
const std::filesystem::path relative(name);
if(name.empty()||name.find('\\')!=std::string::npos||name.find(':')!=std::string::npos||relative.is_absolute())
throw FormatError("unsafe community resource name");
for(const auto& part:relative)if(part==".."||part==".")throw FormatError("unsafe community resource path");
total+=st.m_uncomp_size;
if(st.m_uncomp_size>32*1024*1024 || total>128*1024*1024 ||
!entries.emplace(folded(name),i).second)throw FormatError("ambiguous or oversized community resources");
}
}catch(...){mz_zip_reader_end(&zip);throw;}
}
~Bundle(){mz_zip_reader_end(&zip);}
};
std::mutex bundle_mutex;
struct Cached { std::filesystem::file_time_type modified; uintmax_t size; std::shared_ptr<Bundle> bundle; };
std::map<std::filesystem::path,Cached> cache;
std::pair<std::shared_ptr<Bundle>,std::string> locate(const std::filesystem::path& requested) {
auto path=std::filesystem::absolute(requested).lexically_normal();
auto root=path.parent_path();
for(int depth=0;depth<4 && !root.empty();++depth) {
const auto archive=root/kCommunityBundle;
std::error_code ec;
if(std::filesystem::is_regular_file(archive,ec)) {
const auto modified=std::filesystem::last_write_time(archive);
const auto size=std::filesystem::file_size(archive);
auto found=cache.find(archive);
if(found==cache.end()||found->second.modified!=modified||found->second.size!=size) {
auto bundle=std::make_shared<Bundle>(archive);
if(cache.size()>=4)cache.clear();
found=cache.insert_or_assign(archive,Cached{modified,size,std::move(bundle)}).first;
}
auto name=folded(path.lexically_relative(root).generic_string());
// Compatibility address-view API; the archive contains no EXE image.
if(name=="BMH.EXE")name="RUNTIME.DAT";
return {found->second.bundle,std::move(name)};
}
const auto parent=root.parent_path();if(parent==root)break;root=parent;
}
return {};
}
}
std::optional<Bytes> bundled_resource(const std::filesystem::path& path) {
std::lock_guard lock(bundle_mutex);
auto [bundle,name]=locate(path);if(!bundle)return std::nullopt;
const auto found=bundle->entries.find(name);if(found==bundle->entries.end())return std::nullopt;
mz_zip_archive_file_stat st{};mz_zip_reader_file_stat(&bundle->zip,found->second,&st);
Bytes result(size_t(st.m_uncomp_size));
if(!mz_zip_reader_extract_to_mem(&bundle->zip,found->second,result.data(),result.size(),0))
throw FormatError("damaged community resource: "+name);
return result;
}
bool resource_exists(const std::filesystem::path& path) {
std::error_code ec;if(std::filesystem::is_regular_file(path,ec))return true;
std::lock_guard lock(bundle_mutex);auto [bundle,name]=locate(path);
return bundle && bundle->entries.count(name)!=0;
}
}
+10
View File
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "formats/binary.hpp"
#include <optional>
namespace bmh {
inline constexpr const char* kCommunityBundle = "COMMUNITY.OBD";
// Read-only package lookup. Loose user saves always remain outside the bundle.
std::optional<Bytes> bundled_resource(const std::filesystem::path& path);
bool resource_exists(const std::filesystem::path& path);
}
+1
View File
@@ -5,6 +5,7 @@
namespace bmh {
namespace { CalendarEpoch installed_epoch{2026, 2}; }
CalendarEpoch calendar_epoch_from_executable(const LeImage& exe) {
if(const auto* policy=exe.runtime_policy())return {int(policy->year),int(policy->weekday)};
constexpr auto setup = layout::CalendarDateSetup;
constexpr uint8_t weekday_prefix[] = {0xc6,0x44,0x24,0x04};
constexpr uint8_t month_and_year_prefix[] = {0xc6,0x44,0x24,0x0c,0x07,0xc7,0x04,0x24};
+1
View File
@@ -38,6 +38,7 @@ void install_environment_rules(const LeImage& exe) {
if (!exe.contains(at) || exe.u8(at)==0) { supported_environment=false; return; }
kEnvironmentStep[i]=int32_t(exe.u8(at))*1000;
}
if(const auto* policy=exe.runtime_policy()) { supported_environment=policy->environment_verified!=0;return; }
uint64_t fingerprint = 14695981039346656037ull;
for (const auto [first,last] : {std::pair{layout::EnvironmentVerifiedCodeBegin,layout::EnvironmentVerifiedCodeEnd},std::pair{layout::EnvironmentVerifiedHookBegin,layout::EnvironmentVerifiedHookEnd}}) {
if (!exe.contains(first) || !exe.contains(last-1)) { supported_environment=false; return; }
+1 -1
View File
@@ -14,7 +14,7 @@ std::optional<std::filesystem::path> choose_game_file(const std::string& title)
NFD::Guard guard;
NFD::UniquePathU8 path;
// one filter with all accepted kinds; the check after the choice decides
const nfdu8filteritem_t filters[] = {{"BMH game (ZIP, 7z, BMH.EXE, FLTD.EXE)", "zip,7z,exe"}};
const nfdu8filteritem_t filters[] = {{"BMH game (ZIP, 7z, BMH.EXE, FLTD.EXE)", "zip,7z,exe,obd"}};
const nfdresult_t result = NFD::OpenDialog(path, filters, 1);
if (result == NFD_CANCEL) return std::nullopt;
if (result != NFD_OKAY) throw std::runtime_error(std::string("no file dialog: ") + NFD::GetError());
+13 -5
View File
@@ -11,6 +11,8 @@
#include <system_error>
#include "formats/binary.hpp"
#include "formats/resource_bundle.hpp"
#include "formats/data_profile.hpp"
#include "formats/le.hpp"
#include "formats/m3d.hpp"
#include "formats/textd.hpp"
@@ -52,6 +54,7 @@ struct Family {
const char* database;
};
constexpr Family kFamilies[] = {
{GameFamily::german, "COMMUNITY.OBD", 0, "TEXTD.BLK", "M3D.MAN"},
{GameFamily::german, "BMH.EXE", 602527, "TEXTD.BLK", "M3D.MAN"},
{GameFamily::english, "FLTD.EXE", 507925, "TEXTE.BLK", "M3E.MAN"},
{GameFamily::disk1994, "M3.EXE", 0, "", "M3PC.MAN"},
@@ -82,7 +85,7 @@ void require(GameCheck& c, const fs::path& dir, const std::string& name, uint64_
return;
}
std::error_code ec;
const uint64_t actual = fs::file_size(*p, ec);
const uint64_t actual = fs::exists(*p,ec) ? fs::file_size(*p, ec) : read_file(*p).size();
if (ec || actual == 0) c.problems.push_back(shown + " is empty or unreadable");
else if (size != 0 && actual != size)
c.problems.push_back(shown + " has " + std::to_string(actual) + " bytes instead of " + std::to_string(size));
@@ -90,7 +93,9 @@ void require(GameCheck& c, const fs::path& dir, const std::string& name, uint64_
// The shared picture/font/sound files of the sub directories KB, W, F and S.
void require_media(GameCheck& c) {
const bool bundled=fs::is_regular_file(c.directory/kCommunityBundle);
const auto sub = [&](const char* name) -> std::optional<fs::path> {
if(bundled)return c.directory/name;
auto p = find_file(c.directory, name);
if (!p || !fs::is_directory(*p)) {
c.problems.push_back(std::string("the directory ") + name + " is missing");
@@ -142,14 +147,15 @@ 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)
const bool bundled=fs::is_regular_file(c.directory/kCommunityBundle);
bool image = false;
if (const auto exe = find_file(c.directory, "BMH.EXE")) {
if (const auto exe = find_file(c.directory, "BMH.EXE"); exe && !bundled) {
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 || bundled) ? 0 : 602527, bundled ? "RUNTIME.DAT" : "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);
@@ -158,7 +164,8 @@ void check_german(GameCheck& c) {
// the files must also load: the engine reads tables from the EXE, the texts and the
// database of clubs and players
try {
load_le(*find_file(c.directory, "BMH.EXE"));
const auto runtime=load_le(*find_file(c.directory, "BMH.EXE"));
if(bundled && (!runtime.runtime_policy() || !runtime.expanded_profile()))throw FormatError("unsupported standalone runtime/profile");
} catch (const std::exception& e) {
c.problems.push_back(std::string("BMH.EXE cannot be read: ") + e.what());
}
@@ -212,7 +219,7 @@ bool is_game_file(const std::string& relative) {
const size_t dot = base.find_last_of('.');
if (dot == std::string::npos) return false;
const std::string ext = base.substr(dot + 1);
for (const char* e : {"EXE", "BLK", "MAN", "DAT", "MEN", "COL", "VGA", "FNT", "LBM", "EIN", "CFG", "FBM", "WAP"})
for (const char* e : {"EXE", "BLK", "MAN", "DAT", "MEN", "COL", "VGA", "FNT", "LBM", "EIN", "CFG", "FBM", "WAP", "OBD"})
if (ext == e) return true;
return false;
}
@@ -315,6 +322,7 @@ ResolvedGame resolve_game_unchecked(const fs::path& input, const fs::path& cache
std::optional<fs::path> find_file(const fs::path& directory, const std::string& name) {
std::error_code ec;
const fs::path exact = directory / path_from_utf8(name);
if(resource_exists(exact))return exact;
if (fs::exists(exact, ec)) return exact;
const std::string wanted = upper(name);
for (const auto& e : fs::directory_iterator(directory, ec))
+2
View File
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/executable_layout.hpp"
#include "formats/resource_bundle.hpp"
#include "ui/setup.hpp"
#include <algorithm>
@@ -30,6 +31,7 @@ void copy_rect(Image& dst, const Image& src, int sx, int sy, int dx, int dy,
} // namespace
std::filesystem::path asset_path(const std::filesystem::path& directory, const std::string& name) {
if (!std::filesystem::exists(directory / name) && resource_exists(directory / name)) return directory / name;
std::filesystem::path found;
for (const auto& e : std::filesystem::directory_iterator(directory)) {
if (e.is_regular_file() && folded(e.path().filename().string()) == folded(name)) {
+62
View File
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/resource_bundle.hpp"
#include "formats/le.hpp"
#include "formats/data_profile.hpp"
#include "formats/executable_layout.hpp"
#include "game/calendar.hpp"
#include "miniz.h"
#include <chrono>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <stdexcept>
using namespace bmh;
void check(bool ok,const char* what){if(!ok)throw std::runtime_error(what);}
void bundle(const std::filesystem::path& path,const std::vector<std::pair<std::string,Bytes>>& files) {
mz_zip_archive zip{};
check(mz_zip_writer_init_heap(&zip,0,0)!=0,"synthetic ZIP initialization");
for(const auto& [name,bytes]:files)check(mz_zip_writer_add_mem(&zip,name.c_str(),bytes.data(),bytes.size(),MZ_BEST_COMPRESSION)!=0,"synthetic ZIP entry");
void* data=nullptr;size_t size=0;
check(mz_zip_writer_finalize_heap_archive(&zip,&data,&size)!=0,"synthetic ZIP finalization");
std::ofstream out(path,std::ios::binary);out.write(static_cast<const char*>(data),std::streamsize(size));
mz_free(data);mz_zip_writer_end(&zip);check(bool(out),"synthetic ZIP write");
}
Bytes bytes(std::string text){return Bytes(text.begin(),text.end());}
int main()try {
const auto root=std::filesystem::temp_directory_path()/("openbmh-bundle-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
std::filesystem::create_directories(root);
Bytes data(0x20000,0);
const auto put=[&](uint32_t address,uint8_t value){data.at(address-layout::GermanDataSegmentBegin)=value;};
for(int league=0;league<9;++league)put(layout::LeagueSizes+uint32_t(league),league<5?18:12);
for(int day=24;day<24+34*8;day+=8)put(layout::CompetitionCalendar+uint32_t(day*2),1);
RuntimePolicy policy{2030,2,90,1,{{layout::FreeKickTakerLabel,"Test label"}}};
save_runtime_image(LeImage::from_bytes(layout::GermanDataSegmentBegin,data),policy,root/"source.dat");
const auto runtime=read_file(root/"source.dat");
bundle(root/kCommunityBundle,{{"RUNTIME.DAT",runtime},{"OBMHPROF.INI",bytes("[OpenBMH]\nprofile=classic-plus-1\n")},{"KB/20.VGA",bytes("synthetic picture")}});
std::filesystem::remove(root/"source.dat");
check(!std::filesystem::exists(root/"BMH.exe"),"synthetic bundle accidentally requires an executable");
check(resource_exists(root/"kb"/"20.vga") && read_file(root/"kb"/"20.vga")==bytes("synthetic picture"),"case-insensitive resource read");
check(load_data_profile(root).extended(),"bundled profile metadata not found");
const auto image=load_le(root/"BMH.exe");
check(image.expanded_profile() && image.runtime_policy(),"data-only image did not bind the extended profile");
check(!image.contains(layout::CalendarDateSetup) && !image.contains(layout::ForeignBadgeGateInstruction),"machine-code segment retained");
check(calendar_epoch_from_executable(image).year==2030,"calendar still depends on original instructions");
check(image.cstring(layout::FreeKickTakerLabel)=="Test label","resolved auxiliary label lost");
check(image.u16(layout::TeamsWithSquads)==164,"standalone runtime roster dimensions differ");
// Loose user-created files remain writable and are not replaced by bundle data.
{std::ofstream out(root/"user.FBM");out<<"user save";}
check(read_file(root/"user.FBM")==bytes("user save"),"bundle swallowed a loose user save");
for(int kind=0;kind<2;++kind) {
const auto bad=root/("bad-"+std::to_string(kind));std::filesystem::create_directory(bad);
bundle(bad/kCommunityBundle,kind==0?std::vector<std::pair<std::string,Bytes>>{{"../escape",{1}}}:
std::vector<std::pair<std::string,Bytes>>{{"DUP",{1}},{"dup",{2}}});
bool rejected=false;try{resource_exists(bad/"anything");}catch(const FormatError&){rejected=true;}
check(rejected,"unsafe or duplicate resource accepted");
}
auto broken=runtime;broken.pop_back();
{std::ofstream out(root/"broken.dat",std::ios::binary);out.write(reinterpret_cast<const char*>(broken.data()),std::streamsize(broken.size()));}
bool rejected=false;try{load_le(root/"broken.dat");}catch(const FormatError&){rejected=true;}
check(rejected,"truncated runtime labels accepted");
std::filesystem::remove_all(root);
std::cout<<"Standalone data policies, bundled resources, paths and loose saves passed\n";return 0;
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
"""Assemble a small local Windows community ZIP from a verified program and private data."""
import argparse
import hashlib
import json
from pathlib import Path
import re
import zipfile
def create(program, data, destination, version):
if not re.fullmatch(r'\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?',version):
raise ValueError('Invalid version')
bundle=data/'COMMUNITY.OBD'
with zipfile.ZipFile(bundle) as z:
for name in z.namelist():
if Path(name).suffix.lower() in ('.exe','.com','.dll','.png','.jpg','.jpeg'):
raise ValueError('Original executables or raster studies found in data bundle')
if z.read('RUNTIME.DAT')[:8]!=b'OBMHDAT1':
raise ValueError('Expected a data-only runtime')
receipt=json.loads(z.read('PACKAGE.json'))
for name,digest in receipt['files'].items():
if hashlib.sha256(z.read(name)).hexdigest()!=digest:
raise ValueError('Resource checksum mismatch: '+name)
files={}
with zipfile.ZipFile(program) as z:
for info in z.infolist():
if info.is_dir():continue
path=Path(info.filename)
if path.is_absolute() or '..' in path.parts or len(path.parts)<2:
raise ValueError('Invalid program archive path')
name=Path(*path.parts[1:]).as_posix()
if name=='openbmh_cli.exe':continue
if path.suffix.lower() in ('.zip','.cpp','.hpp','.c','.h','.png','.jpg','.jpeg'):
raise ValueError('Unexpected source/archive/image in program package')
files[name]=z.read(info)
for required in ('OpenBMH.exe','vcruntime140.dll','msvcp140.dll','LICENSE'):
if required not in files:raise ValueError('Missing runtime component: '+required)
files['COMMUNITY.OBD']=bundle.read_bytes()
report=data/'IMPORT-REPORT.json'
if report.exists():files[report.name]=report.read_bytes()
source_url=f'https://github.com/Weyoune/openbmh/releases/download/v{version}/OpenBMH-{version}-source.zip'
files['COMMUNITY_README.txt']=('OpenBMH '+version+' Community Edition\n\n'
'ZIP vollstaendig in einen eigenen Ordner entpacken und OpenBMH.exe starten.\n'
'Alle benoetigten Spieldaten, Grafiken und Sounds liegen in COMMUNITY.OBD.\n'
'Keine Original-DOS-Installation und kein Startskript erforderlich.\n'
'Eigene Spielstaende und Einstellungen bleiben ausserhalb des Datenarchivs.\n\n'
'263 auslaendische Vereinswappen: 175 echte und 88 fiktive Ersatzwappen.\n'
'Quellen und gekennzeichnete Ergaenzungen: IMPORT-REPORT.json.\n\n'
'Anwendung: GPL-3.0-only. Vollstaendiger korrespondierender Quellcode und\n'
'Abhaengigkeiten kostenlos und separat unter:\n'+source_url+'\n'
'Lizenzen der Abhaengigkeiten siehe THIRD_PARTY_NOTICES.md und docs/licenses.\n'
'Inhaltsrechte der Spieldaten und Wappen bleiben bei ihren jeweiligen Quellen.\n').encode('utf-8')
files['PACKAGE-SHA256SUMS']=''.join(hashlib.sha256(b).hexdigest()+' '+name+'\n' for name,b in sorted(files.items())).encode()
destination.parent.mkdir(parents=True,exist_ok=True)
with zipfile.ZipFile(destination,'w',zipfile.ZIP_DEFLATED,compresslevel=9) as z:
for name,content in files.items():z.writestr(name,content)
if destination.stat().st_size>=10_000_000:
destination.unlink()
raise ValueError('Community ZIP exceeds the 10 MB budget')
print(json.dumps({'file':str(destination),'bytes':destination.stat().st_size,'sha256':hashlib.sha256(destination.read_bytes()).hexdigest(),'source_included':False}))
if __name__=='__main__':
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--program',type=Path,required=True);p.add_argument('--data',type=Path,required=True);p.add_argument('--out',type=Path,required=True);p.add_argument('--version',required=True);a=p.parse_args();create(a.program,a.data,a.out,a.version)
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
"""Prepare a compact data-only community directory from private supplied content."""
import argparse
import hashlib
import json
from pathlib import Path
import subprocess
import zipfile
def build(source, destination, exporter):
if destination.exists():
raise ValueError('Destination must not exist')
source=source.resolve();destination.mkdir(parents=True)
runtime=destination/'RUNTIME.DAT'
try:
exe=next(p for p in source.iterdir() if p.name.upper()=='BMH.EXE')
subprocess.run([str(exporter.resolve()),str(exe),str(runtime)],check=True)
data=runtime.read_bytes()
if data[:8]!=b'OBMHDAT1':raise ValueError('Exporter did not produce a data-only runtime')
# Only resources actually used by OpenBMH; no DOS programs, manuals, backups or unused original graphics formats.
names=('M3D.MAN','TEXTD.BLK','M3.DAT','M3.MEN','M3PC.COL','OBMHPROF.INI')
entries={'RUNTIME.DAT':data}
for name in names:
file=next(p for p in source.iterdir() if p.name.upper()==name)
entries[name]=file.read_bytes()
for directory in ('KB','W','F','S'):
root=next(p for p in source.iterdir() if p.name.upper()==directory)
for file in sorted(root.iterdir()):
if not file.is_file():continue
if directory in ('KB','W') and file.suffix.upper()!='.VGA':continue
if directory=='F' and file.name.upper() not in ('BMH2.FNT','BMH3.FNT'):continue
if directory=='S' and file.name not in ('2000','2001','2002','2003'):continue
entries[directory+'/'+file.name.upper()]=file.read_bytes()
receipt={'format':'openbmh-community-1','files':{name:hashlib.sha256(value).hexdigest() for name,value in entries.items()},
'executable_code_included':False,'profile':'classic-plus-1'}
entries['PACKAGE.json']=(json.dumps(receipt,indent=2)+'\n').encode()
archive=destination/'COMMUNITY.OBD'
with zipfile.ZipFile(archive,'w',zipfile.ZIP_DEFLATED,compresslevel=9) as z:
for name,value in entries.items():z.writestr(name,value)
report=source/'IMPORT-REPORT.json'
if report.exists():(destination/report.name).write_bytes(report.read_bytes())
print(json.dumps({'bundle_bytes':archive.stat().st_size,'uncompressed_resource_bytes':sum(map(len,entries.values())),
'resource_count':len(entries),'runtime_bytes':len(data),'bundle_sha256':hashlib.sha256(archive.read_bytes()).hexdigest()}))
finally:runtime.unlink(missing_ok=True)
if __name__=='__main__':
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--source',type=Path,required=True);p.add_argument('--out',type=Path,required=True);p.add_argument('--exporter',type=Path,required=True);a=p.parse_args();build(a.source,a.out,a.exporter)
+18
View File
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/le.hpp"
#include "formats/executable_layout.hpp"
#include "formats/badge_policy.hpp"
#include "game/calendar.hpp"
#include "game/environment.hpp"
#include <iostream>
int main(int argc,char**argv)try {
if(argc!=3)throw std::runtime_error("usage: export_community_runtime <supplied executable> <output runtime.dat>");
const auto image=bmh::load_le(argv[1]);
const auto epoch=bmh::calendar_epoch_from_executable(image);
bmh::install_environment_rules(image);
bmh::RuntimePolicy policy{uint32_t(epoch.year),uint32_t(epoch.weekday),uint32_t(bmh::original_badge_gate(image)),uint32_t(bmh::environment_rules_supported()),{}};
for(auto address:{bmh::layout::FreeKickTakerLabel,bmh::layout::PenaltyTakerLabel,bmh::layout::CornerTakerLabel,bmh::layout::AutomaticTakersLabel})
policy.labels.emplace(address,image.cstring(address));
bmh::save_runtime_image(image,policy,argv[2]);
std::cout<<"Data-only runtime exported; no DOS header, loader or code objects\n";return 0;
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
+35 -8
View File
@@ -95,6 +95,33 @@ def encode_vga(width, height, pixels):
def find_file(root, name):
return next(p for p in root.iterdir() if p.name.upper() == name.upper())
def original_crest_background(source):
"""Recover the shared bright crest texture from the supplied domestic sheets."""
sheets = {}
samples = []
directory = find_file(source, 'W')
for cell in range(90):
page = cell // 8
if page not in sheets:
sheets[page] = decode_vga(find_file(directory, str(page) + '.VGA').read_bytes())
width, height, pixels = sheets[page]
if (width, height) != (304, 38):
raise ValueError('Unexpected Original crest-sheet dimensions')
samples.append(bytes(pixels[y*width+(cell%8)*38+x] for y in range(38) for x in range(38)))
return crest_background_from_samples(samples)
def crest_background_from_samples(samples):
if not samples or any(len(s) != 38*38 for s in samples):
raise ValueError('Invalid crest background samples')
# The Original bright paper texture uses these four adjacent palette entries.
background = bytearray()
for pos in range(38*38):
counts = collections.Counter(s[pos] for s in samples if 92 <= s[pos] <= 95)
background.append(counts.most_common(1)[0][0] if counts else 94)
return bytes(background)
def repeated_native_images(clubs, assets, read):
"""Detect shared Original fallback images without baking in game pixels/hashes."""
counts = collections.Counter()
@@ -214,6 +241,10 @@ def build(source, donor, output):
palette=find_file(source,'M3PC.COL').read_bytes()
rgb=[tuple(((v&63)*255+31)//63 for v in palette[i:i+3]) for i in range(0,768,3)]
sheets={}; crest_report=[]; cache={}
backdrop = original_crest_background(source)
backdrop_image = Image.frombytes('P',(38,38),backdrop)
backdrop_image.putpalette([value for color in rgb for value in color])
backdrop_image = backdrop_image.convert('RGBA')
w_dir=find_file(source,'W')
def sheet(n):
if n not in sheets:
@@ -250,22 +281,18 @@ def build(source, donor, output):
color = '#%02x%02x%02x' % rgb[64 + index % 16]
svg = f'<svg xmlns="http://www.w3.org/2000/svg" width="38" height="38"><path d="M5 3H33L31 24L19 35L7 24Z" fill="{color}" stroke="#f0f5f3" stroke-width="2"/><path d="M8 9H30" stroke="#f0f5f3"/><text x="19" y="23" text-anchor="middle" font-family="sans-serif" font-size="10" font-weight="bold" fill="white">{html.escape(initials)}</text></svg>'
image=Image.open(io.BytesIO(cairosvg.svg2png(bytestring=svg.encode()))).convert('RGBA')
foreground = [(r,g,b) for r,g,b,a in image.getdata() if a >= 128]
contrast_adjusted = bool(foreground) and sum(max(pixel) for pixel in foreground)/len(foreground) < 60
if contrast_adjusted:
alpha=image.getchannel('A');image=Image.new('RGBA',image.size,(238,244,240,0));image.putalpha(alpha)
contrast_adjusted = False # Black silhouettes remain readable on the Original bright background.
image=ImageOps.contain(image,(36,36),method=Image.Resampling.LANCZOS)
canvas=Image.new('RGBA',(38,38));canvas.alpha_composite(image,((38-image.width)//2,(38-image.height)//2))
canvas=backdrop_image.copy();canvas.alpha_composite(image,((38-image.width)//2,(38-image.height)//2))
pixels=bytearray()
for r,g,b,a in canvas.getdata():
if a<128:pixels.append(0);continue
key=(r,g,b)
if key not in cache:cache[key]=min(range(1,256),key=lambda n:sum((x-y)**2 for x,y in zip(rgb[n],key)))
if key not in cache:cache[key]=min(range(256),key=lambda n:sum((x-y)**2 for x,y in zip(rgb[n],key)))
pixels.append(cache[key])
dst=sheet(cell//8)
for y in range(38):dst[y*304+(cell%8)*38:y*304+(cell%8)*38+38]=pixels[y*38:(y+1)*38]
badges[index]=(badges[index]&~511)|cell
crest_report.append({'club':club['id'],'runtime_team':index,'cell':cell,'asset':club.get('crest'),'source':asset.get('source'),'license':asset.get('license'),'fictional':fictional,'contrast_adjusted':contrast_adjusted,'last_decode_error':error})
crest_report.append({'club':club['id'],'runtime_team':index,'cell':cell,'asset':club.get('crest'),'source':asset.get('source'),'license':asset.get('license'),'fictional':fictional,'contrast_adjusted':contrast_adjusted,'background':'original-crest-texture','last_decode_error':error})
db['badges']=words(badges)
# Every Original player word and all German starting rosters remain unchanged.
original_db = read_master(master)
+9 -1
View File
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-3.0-only
"""Synthetic encoder/reader tests; no Original game content required."""
import unittest
from prepare_international import decode_vga, encode_vga, legacy_name, read_master, write_master, words, repeated_native_images
from prepare_international import decode_vga, encode_vga, legacy_name, read_master, write_master, words, repeated_native_images, crest_background_from_samples
class ProfileDataTests(unittest.TestCase):
def test_master_identity_and_sizes(self):
@@ -37,6 +37,14 @@ class ProfileDataTests(unittest.TestCase):
found=repeated_native_images(clubs,assets,lambda path: {'shared':b'placeholder','real':b'individual-crest'}[path])
self.assertEqual(found,{hashlib.sha256(b'placeholder').hexdigest()})
def test_original_background_recovers_texture(self):
texture=bytes(92+(i%4) for i in range(38*38))
samples=[bytearray(texture) for _ in range(7)]
for j, sample in enumerate(samples):
for i in range(j*100,j*100+80):sample[i]=0
self.assertEqual(crest_background_from_samples(samples),texture)
self.assertNotIn(0,crest_background_from_samples(samples))
def test_original_encoding(self):
self.assertEqual(legacy_name('Müller'),b'M}LLER')
self.assertEqual(legacy_name('Sørloth'),b'SORLOTH')