Fix save loading at the national desk, calendar colours, pointer size; add -debug

- Loading: a single-manager desk saved with DeskPosition == ManagerCount
  (the completed loop) is read as the first desk again instead of being
  refused as "not a savegame".
- Calendar: text takes the original's six-row colour gradient (the flat
  colours were too dark next to the original).
- Pointer: sized in window points, so it is not doubled on Retina screens.
- Settings: the page names OpenBMH and shows the build version below.
- Desk: the opponent's badge is shown whenever the data has one
  (documented difference); cup-only teams keep the computer portrait.
- Live overview tests: Tabelle/Stärken/Spiele handovers, also with the
  Spiele page opened first.
- New command line option -debug: timestamped log, stderr captured in a
  file, and a savegame after every match day in <saves>/debug.

Refs #63, #65, #67, #68, #71, #73.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-11-04 22:22:30 +01:00
1 parent 1e7df751a0
commit 38f69fa37b
15 files changed
+234 -13

No files matched your search

+8 -1
View File
@@ -374,8 +374,15 @@ void restore_saved_turn_cursor(TurnDriver& driver, GameState& state, const Datab
const int manager_count = int(state.manager_teams.size());
if (manager_count > 4 || !state.memory.has(::bmh::layout::ActiveManager) || !state.memory.has(::bmh::layout::DeskPosition))
throw std::runtime_error("saved turn cursor: manager continuation fields are missing");
const int position = int(state.memory.u8(::bmh::layout::DeskPosition));
int position = int(state.memory.u8(::bmh::layout::DeskPosition));
const int active = int(state.memory.u8(::bmh::layout::ActiveManager));
// A completed manager loop leaves DeskPosition == ManagerCount (the day's desks are done). A desk
// that was saved in that state is the first desk again for a single manager: nothing else can
// follow it. Reading the byte as 0 lets the day go on instead of refusing the whole save.
if (manager_count == 1 && position == 1 && active == 0) {
position = 0;
state.memory.set8(::bmh::layout::DeskPosition, 0);
}
if (position < 0 || position >= manager_count)
throw std::runtime_error("saved turn cursor: manager position is outside the saved roster");
if (manager_count == 1) {
+15
View File
@@ -2,6 +2,7 @@
#include "formats/badge_policy.hpp"
#include "formats/executable_layout.hpp"
#include "app/controller.hpp"
#include "app/debug_log.hpp"
#include "app/window_actions.hpp"
#include "app/desktop_actions.hpp"
#include "app/audio.hpp"
@@ -1866,6 +1867,20 @@ std::string serve_flow_request(ui::StartupFlow& flow, const ui::FlowResult& resu
});
const auto advanced = session->dispatch_kickoff(result.desk_action, revision, error);
start_original_desk_audio(playback, session->state(), music_enabled);
if (app::debug::enabled()) {
// -debug: one savegame after every match day, in the debug folder (DBG00001.FBM, ...).
app::debug::log("kickoff handled: " + std::string(advanced.kind == TurnDeskKind::Failed ? "failed" : "ok") +
", date counter " + std::to_string(session->state().date) + ", revision " + std::to_string(revision) +
(error.empty() ? std::string() : ", error " + error));
if (advanced.kind != TurnDeskKind::Failed) {
const auto path = app::debug::next_save_path();
std::string save_error;
const int slot = int(session->state().memory.u8(::bmh::layout::ActiveManager));
const bool saved = session->save_game(path, slot, true, save_error);
app::debug::log(saved ? "debug savegame " + path.filename().string()
: "debug savegame failed: " + save_error);
}
}
if (advanced.kind == TurnDeskKind::Failed || advanced.kind == TurnDeskKind::WaitingAtDesk) {
flow.reject_desk_action(error.empty() ? advanced.reason : error);
return {};
+77
View File
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <chrono>
#include <cstdio>
#include <ctime>
#include <filesystem>
#include <fstream>
#include <mutex>
#include <string>
#include <system_error>
namespace bmh::app::debug {
// The debug mode (command line -debug): a log with timestamps next to everything the game prints
// to stderr, and a savegame after every played match day, both in one sub folder of the save
// directory. Off by default; every function is a no-op until init() has run.
struct State {
bool enabled = false;
std::filesystem::path directory;
unsigned saves = 0;
std::mutex mutex;
};
inline State& state() { static State s; return s; }
inline bool enabled() { return state().enabled; }
inline const std::filesystem::path& directory() { return state().directory; }
inline std::string timestamp() {
const auto now = std::chrono::system_clock::now();
const std::time_t t = std::chrono::system_clock::to_time_t(now);
std::tm parts{};
#ifdef _WIN32
localtime_s(&parts, &t);
#else
localtime_r(&t, &parts);
#endif
const auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count() % 1000;
char text[40];
std::snprintf(text, sizeof text, "%04d-%02d-%02d %02d:%02d:%02d.%03d", parts.tm_year + 1900, parts.tm_mon + 1,
parts.tm_mday, parts.tm_hour, parts.tm_min, parts.tm_sec, int(ms));
return text;
}
// One line, flushed at once so that a crash or a hang loses nothing.
inline void log(const std::string& line) {
auto& s = state();
if (!s.enabled) return;
std::lock_guard<std::mutex> lock(s.mutex);
std::ofstream out(s.directory / "openbmh-debug.log", std::ios::app);
if (out) out << timestamp() << " " << line << '\n';
}
// Creates the folder and redirects stderr into the same folder, so the messages the game
// prints on its own (for example the live overview errors) are kept as well.
inline bool init(const std::filesystem::path& directory) {
std::error_code ec;
std::filesystem::create_directories(directory, ec);
if (ec || !std::filesystem::is_directory(directory)) return false;
auto& s = state();
s.directory = directory;
s.enabled = true;
const auto errors = (directory / "openbmh-stderr.log").string();
if (std::FILE* redirected = std::freopen(errors.c_str(), "a", stderr)) std::setvbuf(redirected, nullptr, _IONBF, 0);
log("debug mode on, folder " + directory.string());
return true;
}
// The file name of the next automatic savegame: DBG00001.FBM, DBG00002.FBM, ... (8.3 like the original).
inline std::filesystem::path next_save_path() {
auto& s = state();
char name[16];
std::snprintf(name, sizeof name, "DBG%05u.FBM", ++s.saves);
return s.directory / name;
}
} // namespace bmh::app::debug
+14 -2
View File
@@ -34,6 +34,7 @@
#include "version.hpp"
#include "app/video_session.hpp"
#include "app/live_matchday_events.hpp"
#include "app/debug_log.hpp"
#include "app/pitch_pointer.hpp"
#include "audio/playback.hpp"
#include "app/audio.hpp"
@@ -115,7 +116,7 @@ int main(int argc, char** argv) {
const std::vector<std::string> args = launch::utf8_arguments(argc, argv); // (file names beyond the code page)
fs::path data, save_directory;
uint32_t seed = uint32_t(std::chrono::system_clock::now().time_since_epoch().count());
bool muted = false, music_enabled = true;
bool muted = false, music_enabled = true, debug_mode = false;
int live_frame_ms = 0;
bool live_frame_ms_explicit = false;
if (const char* configured = std::getenv("BMH_LIVE_FRAME_MS")) {
@@ -139,6 +140,8 @@ int main(int argc, char** argv) {
data = launch::path_from_utf8(args[++i]);
} else if (is("--seed") && value) {
seed = uint32_t(std::strtoul(args[++i].c_str(), nullptr, 0));
} else if (is("-debug") || is("--debug")) {
debug_mode = true;
} else if (is("--save-directory") && value) {
save_directory = launch::path_from_utf8(args[++i]);
} else if (is("--volume") && value) {
@@ -148,7 +151,7 @@ int main(int argc, char** argv) {
return 0;
} else if (is("--help") || is("-h")) {
std::printf("usage: OpenBMH [<game directory | BMH.EXE | game.zip | game.7z>] [--seed <Watcom seed>] "
"[--save-directory <directory>] [--mute] [--volume <0..1>] [--no-music] [--live-frame-ms <0..1000>]\n");
"[--save-directory <directory>] [--mute] [--volume <0..1>] [--no-music] [--live-frame-ms <0..1000>] [-debug]\n");
return 0;
} else if (args[i].rfind("--", 0) != 0 && data.empty()) {
data = launch::path_from_utf8(args[i]);
@@ -195,6 +198,13 @@ int main(int argc, char** argv) {
data = game.check.directory;
}
if (save_directory.empty()) save_directory = data;
if (debug_mode) {
// -debug: log in <saves>/debug, with a savegame after every match day (app/debug_log.hpp).
if (!app::debug::init(save_directory / "debug")) std::fprintf(stderr, "debug folder cannot be created\n");
app::debug::log(std::string("OpenBMH ") + bmh::kOpenBmhVersion + ", data " + data.string() + ", saves " + save_directory.string() + ", seed " + std::to_string(seed));
SDL_version linked; SDL_GetVersion(&linked);
app::debug::log("SDL " + std::to_string(linked.major) + "." + std::to_string(linked.minor) + "." + std::to_string(linked.patch) + ", platform " + SDL_GetPlatform());
}
try {
const Palette palette = load_palette(ui::asset_path(data, "M3PC.COL"));
ui::StartupFlow flow(data, save_directory);
@@ -226,6 +236,7 @@ int main(int argc, char** argv) {
ui::SportschauEleven sportschau_eleven(data);
ui::SportschauTeamInfo sportschau_team_info(data);
ui::CompetitionWinnerScreen competition_winner(data);
ui::set_settings_product_version(bmh::kOpenBmhVersion);
const auto season_exe = load_le(ui::asset_path(data, "BMH.exe"));
english_game = english_game || season_exe.u8(layout::LeagueSizes) == 20;
{
@@ -3238,6 +3249,7 @@ int main(int argc, char** argv) {
}, &request);
if (!closed) throw FormatError("phase results: viewer stopped before Source ACK");
}, true);
if (app::debug::enabled()) app::debug::log("request " + std::to_string(int(r.request)) + (message.empty() ? std::string(" ok") : " -> " + message));
if (message == "career_complete") { running = false; return; }
if (!message.empty()) std::fprintf(stderr, "engine: %s\n", message.c_str());
if (session) {
+5 -1
View File
@@ -28,8 +28,12 @@ public:
void show(const std::optional<std::array<uint32_t,121>>& requested, SDL_Renderer* renderer) {
const auto& pixels = requested ? requested : default_;
if (!pixels) { SDL_SetCursor(SDL_GetDefaultCursor()); return; }
// Cursor bitmaps are sized in window points, not in pixels: on a high-DPI display (macOS
// Retina) the renderer's output is larger than the window, and a bitmap scaled to it would
// show twice as large. SDL_GetWindowSize gives the points.
int width = 320, height = 240;
SDL_GetRendererOutputSize(renderer, &width, &height);
if (SDL_Window* window = SDL_RenderGetWindow(renderer)) SDL_GetWindowSize(window, &width, &height);
else SDL_GetRendererOutputSize(renderer, &width, &height);
const int scale = std::max(1, std::min(width / 320, height / 240));
if (!cursor_ || pixels != pixels_ || scale != scale_) {
std::vector<uint32_t> enlarged(size_t(11 * scale) * size_t(11 * scale));
+23 -2
View File
@@ -77,9 +77,30 @@ CalendarScreen::CalendarScreen(const std::filesystem::path& data, CalendarState
void CalendarScreen::text(Image& out, int x, int baseline, std::string_view bytes, uint8_t color) const {
// TextWidth3 refuses text outside the original screen; no UTF-8 enters BMH3.
const int top = baseline - font_.baseline;
if (x >= 0 && top >= 0 && top + font_.height <= out.height &&
x + font_.text_width(bytes) <= out.width)
if (!(x >= 0 && top >= 0 && top + font_.height <= out.height &&
x + font_.text_width(bytes) <= out.width)) return;
// With the gradient on, every set pixel of a glyph takes the colour its row has in the original's
// table for this palette token (six rows per token); a token the table does not know stays flat.
unsigned slot = 0;
while (slot < 32 && exe_.u8(::bmh::layout::Advertising_Text_RuntimeField2 + slot) != color) ++slot;
if (!state_.gradient_text || slot == 32) {
font_.draw(out, x, top, bytes, color);
return;
}
int pen_x = x;
for (unsigned char ch : bytes) {
const auto& glyph = font_.glyph(ch);
for (int row = 0; row < font_.height; ++row) {
const uint8_t row_color = exe_.u8(::bmh::layout::Advertising_Text_RuntimeField + slot * 6 + std::min(row, 5));
if (row_color == 0) continue;
for (int col = 0; col < glyph.bit_width; ++col) {
const int bit = glyph.bit_offset + col;
if (!(font_.bitmap[size_t(row) * font_.modulo + bit / 8] & (0x80 >> (bit % 8)))) continue;
out.at(pen_x + col, top + row) = row_color;
}
}
pen_x += glyph.advance;
}
}
std::string CalendarScreen::information(const CalendarDayProjection& day) const {
+4
View File
@@ -105,6 +105,10 @@ CalendarState calendar_from_game(const GameState& game, const LeImage& executabl
if (current_display >= int(state.days.size()))
throw FormatError("calendar: current date is outside the season calendar");
state.current_day = current_display;
// TextGradientDisabled (a settings switch) clear and the edition's gradient mode 2: the text
// takes the original's six-row colour table, as on every other page.
state.gradient_text = !game.memory.has(::bmh::layout::TextGradientDisabled) ||
(game.memory.u8(::bmh::layout::TextGradientDisabled) == 0 && executable.u8(::bmh::layout::TextGradientMode) == 2);
return state;
}
+1
View File
@@ -47,6 +47,7 @@ struct CalendarState {
bool friendly_selection = false;
std::vector<RescheduleOption> reschedule_options;
std::vector<LeagueMatchRef> moved_matches;
bool gradient_text = true; // six-row colour table of the original instead of flat colours
};
// Projects the current saved season without preparing fixtures, advancing the date,
+4 -1
View File
@@ -621,7 +621,10 @@ DeskState desk_from_game(const GameState& g, const LeImage& exe, uint64_t revisi
*d.next_opponent < int(g.club_ids.size())) {
const int opponent = *d.next_opponent;
d.next_opponent_name = g.club_name(opponent);
const bool fallback = original_badge_fallback(opponent,&exe);
// OpenBMH deviates from the original: the desk shows the opponent's badge whenever the data has one.
// The original draws a computer icon for the clubs between its two gate values (the foreign league
// clubs); only the cup-only teams and the empty selector keep the icon.
const bool fallback = (opponent & 0xfff) == 0xfff || (opponent >= 168 && opponent < 357);
d.next_opponent_badge_fallback = fallback;
if (!fallback) {
const size_t badge_at = size_t(opponent) * 2;
+10 -3
View File
@@ -1123,12 +1123,19 @@ int main(int argc, char** argv) {
auto special=desk_from_game(special_game,exe,10,&prepared,34);
check(special.next_competition_label==desk_texts[(::bmh::layout::DeskState_FormatError_RuntimeField4-::bmh::layout::TextPointerTable)/4],
"Source calendar entry 4006 selects the special competition title");
MatchGroup fallback_badge_group=cup_fixture;fallback_badge_group.fixtures={12,100};
// OpenBMH shows a club badge for every league club; only the cup-only teams keep the computer portrait.
MatchGroup fallback_badge_group=cup_fixture;fallback_badge_group.fixtures={12,200};
std::vector<MatchGroup> fallback_badge_groups{fallback_badge_group};
auto fallback_badge=desk_from_game(match_game,exe,10,&fallback_badge_groups,34);
check(fallback_badge.next_opponent==100&&fallback_badge.next_opponent_badge_fallback&&
check(fallback_badge.next_opponent==200&&fallback_badge.next_opponent_badge_fallback&&
!fallback_badge.next_opponent_badge,
"legacy routine special team range uses its computer-portrait fallback");
"a cup-only team uses its computer-portrait fallback");
fallback_badge_group.fixtures={12,100};
fallback_badge_groups={fallback_badge_group};
auto foreign_badge=desk_from_game(match_game,exe,10,&fallback_badge_groups,34);
check(foreign_badge.next_opponent==100&&!foreign_badge.next_opponent_badge_fallback&&
foreign_badge.next_opponent_badge,
"a foreign league club shows its badge");
prepared.clear();
auto other_fixture = league_fixture; other_fixture.fixtures={13,14}; prepared.push_back(other_fixture);
auto unmatched = desk_from_game(match_game,exe,10,&prepared,34);
+12 -1
View File
@@ -51,6 +51,11 @@ std::string number(int value) {
}
}
namespace {
std::string& product_version() { static std::string version; return version; }
}
void set_settings_product_version(std::string version) { product_version() = std::move(version); }
std::array<uint8_t, 180> project_settings_availability(
const std::array<uint8_t, 180>& raw_cells, const SettingsAvailabilityInputs& in,
const LeImage& exe) {
@@ -210,7 +215,13 @@ Image SettingsScreen::render() const {
}
sprite_font_.draw(out, SpriteFont::centered_title_x(sprite_font_.text_width(state_.title)), 13, state_.title);
sprite_font_.draw(out, 5, 235, state_.footer);
text(out, 2, 41, utf8_to_original(state_.version), 0x5f, 58);
// OpenBMH deviates from the original: the settings page names the product and its build version instead of the original's version text.
if (product_version().empty()) {
text(out, 2, 41, utf8_to_original(state_.version), 0x5f, 58);
} else {
text(out, 2, 41, "OpenBMH", 0x5f, 58);
text(out, 2, 49, utf8_to_original(product_version()), 0x5f, 58);
}
for (int col = 0; col < 9; ++col) {
const auto label = std::to_string(col + 1);
// DrawnFirstBy uses x directly when right=-1 and shadow=0x40.
+4
View File
@@ -64,6 +64,10 @@ SettingsState settings_from_game(const GameState&, int manager, uint64_t revisio
std::optional<uint32_t> settings_source_refusal(const GameState& state,
const SettingsWriteRequest& request, uint64_t revision);
// The product line of the settings page: "OpenBMH" and, below it, this build's version. Set once by the
// application (the UI library does not include the generated version); empty keeps the original text.
void set_settings_product_version(std::string version);
class SettingsScreen {
public:
SettingsScreen(const std::filesystem::path& data, SettingsState state, int origin_item_id = -1);