(by Codex) Preserve long-career player counts and title history

This commit is contained in:
Codex committed 2026-11-01 18:15:55 +01:00
1 parent 8e2f491d5e
commit 30843fc9f3
23 files changed
+491 -47

No files matched your search

+4
View File
@@ -232,6 +232,7 @@ add_library(bmhcore STATIC
src/game/reality_ball.cpp src/game/reality_ball.cpp
src/game/reality_duel.cpp src/game/reality_duel.cpp
src/game/reality_reporter.cpp src/game/reality_reporter.cpp
src/game/long_career.cpp
src/game/matchday.cpp src/game/matchday.cpp
src/game/sportschau_replay.cpp src/game/sportschau_replay.cpp
src/game/sportschau_rating.cpp src/game/sportschau_rating.cpp
@@ -1178,3 +1179,6 @@ bmh_add_data_test(NAME transfer_seller_app_tests REQUIRED_OPTIONS BMH_TEST_TRANS
add_executable(wide_number_unit_tests tests/wide_number_unit_tests.cpp) add_executable(wide_number_unit_tests tests/wide_number_unit_tests.cpp)
target_link_libraries(wide_number_unit_tests PRIVATE bmhcore) target_link_libraries(wide_number_unit_tests PRIVATE bmhcore)
add_test(NAME wide_number_unit_tests COMMAND wide_number_unit_tests) add_test(NAME wide_number_unit_tests COMMAND wide_number_unit_tests)
add_executable(long_career_tests tests/long_career_tests.cpp)
target_link_libraries(long_career_tests PRIVATE bmhcore)
add_test(NAME long_career_tests COMMAND long_career_tests)
+20
View File
@@ -112,3 +112,23 @@ boundaries. Post-match overview dismissal owns its full mouse gesture, including
release after pointer movement, before the following calendar decision can open. release after pointer movement, before the following calendar decision can open.
The pitch uses each edition's original position-distance tables, atlas swatches The pitch uses each edition's original position-distance tables, atlas swatches
and pointer bitmap for placement feedback; this display state is not serialized. and pointer bitmap for placement feedback; this display state is not serialized.
OpenBMH deviates from the original: cumulative human-club appearances, goals and
assists have optional 64-bit counters. Original byte/word fields keep their
modulo representation for gameplay/layout compatibility; roster projections use
the wider values. Tracking begins with the surviving legacy values, so high bits
already lost in an imported save cannot be recovered. A new arrival clears the
previous squad occupant's totals. Club promotion remaps counter ownership.
Title-holder and cup-winner lists retain all observed seasons in the same optional
OpenBMH save extension. The Original nine-by-fifty table remains a rolling window.
The archive captures that window before it shifts, and the title list can page
through the archived rows. Late legacy imports start with their surviving fifty
seasons; earlier winners are unknown and are not fabricated. Stored winner names
are historical snapshots, so later renaming and promotion cannot change them.
The separate manager-achievements graph retains its Original fifty-season view.
These records use a versioned `OBMHEXT1` extension after the Original name pools;
see [save format](formats/LONG_CAREER.md). Original programs and older OpenBMH
writers do not preserve this archive. Keep an OpenBMH backup when exchanging
careers with those writers. The native calendar still has its existing signed
16-bit season limit; this patch does not claim an unlimited calendar.
+34
View File
@@ -0,0 +1,34 @@
# Optional long-career statistics and title archive
The existing `OBMHEXT1` container can contain block `0x4f424c43` (OpenBMH-owned,
not a guest memory address). Original state blocks and all four name pools retain
their sizes and ordering. No extension is emitted until an archive is needed.
Payload integers use little-endian encoding:
| Field | Encoding |
|---|---|
| Payload version | u32, currently 1 |
| Player/club record count | u32 |
| Known season record count | u32 |
| Each player/club record | u32 key, then six u64 counters |
| Each season record | u32 absolute zero-based season, then nine names |
| Each name | u16 byte length followed by Original-encoding bytes |
The player key is `(runtime_club << 12) | player_id`. The six counters are league,
national-cup and European-cup appearances, total appearances, goals and assists.
Club swaps remap keys; fresh squad entry initialization resets the new player's
club record. The Original byte/word fields continue to update normally.
Season names follow the nine Original title categories. An empty name is a known
season with no holder for that category. Missing season records are unknown,
not an assertion that no competition was held. Names are owned snapshots at the
award/capture time, independent of future club-number and name-pool changes.
A legacy import contributes only its surviving window; no earlier information
is inferred. The title list uses the earliest known absolute season when paging
and compensates for the native rolling-window year offset.
The decoder rejects unknown versions, truncated payloads, invalid/duplicate
identities and seasons, duplicate blocks and trailing bytes before publishing
archive state. Season records remain within the native signed 16-bit calendar
range. The surrounding FBM checksum covers the extension. Older writers may
discard extensions; Original-game roundtrip preservation is not promised.
+2 -2
View File
@@ -622,7 +622,7 @@ void advance_cup(GameState& g, int id, WatcomRandom& rand, MinuteReport& report,
g.manager_records.at(at) = uint8_t(n + 1), g.manager_records.at(at + 1) = uint8_t((n + 1) >> 8); g.manager_records.at(at) = uint8_t(n + 1), g.manager_records.at(at + 1) = uint8_t((n + 1) >> 8);
} }
// ListTitleHoldersAf(winner, title): the list of title holders (Titles) // ListTitleHoldersAf(winner, title): the list of title holders (Titles)
mem.set16(::bmh::layout::Titles + uint32_t(title) * 100 + uint32_t(std::min<int>(g.season, 0x31)) * 2, winners[0]); record_title_holder(g, title, winners[0]);
} }
if (type == 0 && !winners.empty()) { if (type == 0 && !winners.empty()) {
// the national cup: winner (Cup_AdvanceCup_RuntimeField5) and the previous holder // the national cup: winner (Cup_AdvanceCup_RuntimeField5) and the previous holder
@@ -654,7 +654,7 @@ void advance_cup(GameState& g, int id, WatcomRandom& rand, MinuteReport& report,
if (mem.u8(::bmh::layout::Cup_AdvanceCup_RuntimeField) == 0 && winner_display) if (mem.u8(::bmh::layout::Cup_AdvanceCup_RuntimeField) == 0 && winner_display)
winner_display(g, {7, winner}); winner_display(g, {7, winner});
if (mem.u8(::bmh::layout::Cup_AdvanceCup_RuntimeField) == 0 && mem.has(::bmh::layout::CareerSession_BeginFriendlyOpponentTable_ExecutableField2)) mem.set8(::bmh::layout::CareerSession_BeginFriendlyOpponentTable_ExecutableField2, 0); if (mem.u8(::bmh::layout::Cup_AdvanceCup_RuntimeField) == 0 && mem.has(::bmh::layout::CareerSession_BeginFriendlyOpponentTable_ExecutableField2)) mem.set8(::bmh::layout::CareerSession_BeginFriendlyOpponentTable_ExecutableField2, 0);
mem.set16(::bmh::layout::Titles + 7 * 100 + uint32_t(std::min<int>(g.season, 0x31)) * 2, winner); record_title_holder(g, 7, winner);
if (mem.has(::bmh::layout::Cup_AdvanceCup_RuntimeField7)) mem.set16(::bmh::layout::Cup_AdvanceCup_RuntimeField7, winner); if (mem.has(::bmh::layout::Cup_AdvanceCup_RuntimeField7)) mem.set16(::bmh::layout::Cup_AdvanceCup_RuntimeField7, winner);
const int manager = g.manager_of(winner); const int manager = g.manager_of(winner);
if (manager >= 0) { if (manager >= 0) {
+149
View File
@@ -0,0 +1,149 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "game/long_career.hpp"
#include "game/state.hpp"
#include "formats/executable_layout.hpp"
#include <algorithm>
#include <limits>
#include <stdexcept>
namespace bmh {
namespace {
uint32_t key(int team, int player) {
if (team < 0 || team > 0xfff || player < 0 || player >= 0xfff)
throw FormatError("long career: invalid player/club identity");
return uint32_t(team) << 12 | uint32_t(player);
}
int manager_team(const GameState& g, int manager) {
if (manager >= 0 && size_t(manager) < g.manager_teams.size()) return g.manager_teams[size_t(manager)];
const size_t at = size_t(manager) * 0xb0c + 0x290;
if (manager < 0 || manager > 4 || at + 1 >= g.manager_records.size())
throw FormatError("long career: invalid manager");
return int(g.manager_records[at] | uint16_t(g.manager_records[at + 1]) << 8);
}
PlayerClubStatistics legacy(const std::array<uint8_t, 0x58>& b) {
auto word = [&](size_t at) { return uint64_t(b[at] | uint16_t(b[at + 1]) << 8); };
return {{b[7], b[8], b[9]}, word(0x48), word(0x4a), word(0x4c)};
}
void increment(uint64_t& n) {
if (n == std::numeric_limits<uint64_t>::max()) throw FormatError("long career: statistics counter exhausted");
++n;
}
void put(Bytes& b, uint64_t n, int width) { for (int i = 0; i < width; ++i) b.push_back(uint8_t(n >> (i * 8))); }
struct Reader {
const Bytes& bytes; size_t pos = 0;
uint64_t get(int width) {
if (size_t(width) > bytes.size() - pos) throw FormatError("long career: truncated extension");
uint64_t n = 0; for (int i = 0; i < width; ++i) n |= uint64_t(bytes[pos++]) << (i * 8); return n;
}
std::string string() {
const size_t size = size_t(get(2));
if (size > bytes.size() - pos) throw FormatError("long career: truncated title name");
std::string s(bytes.begin() + pos, bytes.begin() + pos + size); pos += size; return s;
}
};
}
PlayerClubStatistics player_club_statistics(const GameState& g, int team, int player,
const std::array<uint8_t, 0x58>& board) {
const auto found = g.player_statistics.find(key(team, player));
return found == g.player_statistics.end() ? legacy(board) : found->second;
}
void record_player_statistics(GameState& g, int manager, int row, int player, int cls, int kind) {
const size_t at = size_t(manager) * 0x840 + size_t(row) * 0x58;
if (manager < 0 || row < 0 || row >= 24 || at + 0x58 > g.tactics.size() || cls < 0 || cls > 3 || kind < 0 || kind > 2)
throw FormatError("long career: invalid statistics row/event");
std::array<uint8_t, 0x58> board; std::copy_n(g.tactics.begin() + at, board.size(), board.begin());
const auto identity = key(manager_team(g, manager), player);
auto [found, inserted] = g.player_statistics.try_emplace(identity, legacy(board));
auto next = found->second;
if (kind == 0) { if (cls < 3) increment(next.appearances[size_t(cls)]); increment(next.total); }
else if (kind == 1) increment(next.goals);
else increment(next.assists);
found->second = next;
}
void reset_player_statistics(GameState& g, int manager, int player) {
g.player_statistics.erase(key(manager_team(g, manager), player));
}
void swap_statistics_clubs(GameState& g, int first, int second) {
PlayerStatisticsArchive next;
for (const auto& [identity, value] : g.player_statistics) {
const int club = int(identity >> 12), player = int(identity & 0xfff);
next.emplace(key(club == first ? second : club == second ? first : club, player), value);
}
g.player_statistics = std::move(next);
}
TitleHistoryArchive title_history_rows(const GameState& g) {
if (g.season < 0) throw FormatError("long career: negative season index");
auto rows = g.title_history;
if (!g.memory.has(layout::Titles + 899)) return rows;
const int first = std::max(0, g.season - 49);
for (int slot = 0; slot < 50 && first + slot <= g.season; ++slot) {
const auto season = uint32_t(first + slot);
if (rows.contains(season)) continue;
std::array<std::string, 9> winners;
for (size_t category = 0; category < 9; ++category) {
const auto team = g.memory.u16(layout::Titles + uint32_t(category) * 100 + uint32_t(slot) * 2);
if (team != 0xffff) winners[category] = g.club_name(team);
}
rows.emplace(season, std::move(winners));
}
return rows;
}
void capture_title_history(GameState& g) { g.title_history = title_history_rows(g); }
void record_title_holder(GameState& g, int category, uint16_t winner) {
if (category < 0 || category >= 9 || g.season < 0 || winner >= g.club_ids.size())
throw FormatError("long career: invalid title award");
capture_title_history(g);
const auto name = g.club_name(winner);
g.memory.set16(layout::Titles + uint32_t(category) * 100 + uint32_t(std::min(g.season, 49)) * 2, winner);
g.title_history[uint32_t(g.season)][size_t(category)] = name;
}
void shift_legacy_title_history(GameState& g) {
if (g.season <= 49) return;
for (uint32_t category = 0; category < 9; ++category) {
for (uint32_t i = 0; i < 98; ++i)
g.memory.set8(layout::Titles + category * 100 + i,
g.memory.u8(layout::Season_SeasonEndSteps_RuntimeField + category * 100 + i));
g.memory.set16(layout::Season_SeasonEndSteps_RuntimeField2 + category * 100, 0xffff);
}
}
Bytes encode_long_career(const GameState& g) {
if (g.player_statistics.empty() && g.title_history.empty()) return {};
Bytes b; put(b, 1, 4); put(b, g.player_statistics.size(), 4); put(b, g.title_history.size(), 4);
for (const auto& [identity, s] : g.player_statistics) {
put(b, identity, 4); for (const auto n : s.appearances) put(b, n, 8);
for (const auto n : {s.total, s.goals, s.assists}) put(b, n, 8);
}
for (const auto& [season, names] : g.title_history) {
if (season > 32767) throw FormatError("long career: archived season exceeds native calendar range");
put(b, season, 4);
for (const auto& name : names) {
if (name.size() > UINT16_MAX) throw FormatError("long career: title name too long");
put(b, name.size(), 2); b.insert(b.end(), name.begin(), name.end());
}
}
return b;
}
void decode_long_career(GameState& g, const Bytes& bytes) {
Reader r{bytes};
if (r.get(4) != 1) throw FormatError("long career: unsupported extension version");
const auto players = r.get(4), seasons = r.get(4);
if (players > (bytes.size() - r.pos) / 52 || seasons > 32768)
throw FormatError("long career: invalid extension counts");
PlayerStatisticsArchive stats; TitleHistoryArchive history;
for (uint64_t i = 0; i < players; ++i) {
const auto identity = uint32_t(r.get(4));
if (identity > 0xffffff || (identity & 0xfff) == 0xfff) throw FormatError("long career: invalid archived identity");
PlayerClubStatistics s; for (auto& n : s.appearances) n = r.get(8);
s.total = r.get(8); s.goals = r.get(8); s.assists = r.get(8);
if (!stats.emplace(identity, s).second) throw FormatError("long career: duplicate archived identity");
}
for (uint64_t i = 0; i < seasons; ++i) {
const auto season = uint32_t(r.get(4));
if (season > 32767) throw FormatError("long career: invalid archived season");
std::array<std::string, 9> names; for (auto& name : names) name = r.string();
if (!history.emplace(season, std::move(names)).second) throw FormatError("long career: duplicate archived season");
}
if (r.pos != bytes.size()) throw FormatError("long career: trailing extension bytes");
g.player_statistics = std::move(stats); g.title_history = std::move(history);
}
}
+31
View File
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <array>
#include <cstdint>
#include <map>
#include <string>
#include "formats/binary.hpp"
namespace bmh {
struct GameState;
struct PlayerClubStatistics {
std::array<uint64_t, 3> appearances{};
uint64_t total = 0, goals = 0, assists = 0;
bool operator==(const PlayerClubStatistics&) const = default;
};
// Optional OBMHEXT1 block, outside the Original guest address space. Payload v1.
inline constexpr uint32_t kLongCareerExtension = 0x4f424c43;
using PlayerStatisticsArchive = std::map<uint32_t, PlayerClubStatistics>;
using TitleHistoryArchive = std::map<uint32_t, std::array<std::string, 9>>;
PlayerClubStatistics player_club_statistics(const GameState&, int team, int player,
const std::array<uint8_t, 0x58>& board);
void record_player_statistics(GameState&, int manager, int row, int player, int competition_class, int kind);
void reset_player_statistics(GameState&, int manager, int player);
void swap_statistics_clubs(GameState&, int first, int second);
TitleHistoryArchive title_history_rows(const GameState&);
void capture_title_history(GameState&);
void record_title_holder(GameState&, int category, uint16_t winner);
void shift_legacy_title_history(GameState&);
Bytes encode_long_career(const GameState&);
void decode_long_career(GameState&, const Bytes&);
}
+7 -2
View File
@@ -242,6 +242,7 @@ void player_statistic(GameState& g, int type, int player, int manager, int slot,
if (cls == 3 && (g.player_bonus.at(player) & 0x7F) < 0x7F) g.player_bonus.at(player)++; if (cls == 3 && (g.player_bonus.at(player) & 0x7F) < 0x7F) g.player_bonus.at(player)++;
if (manager >= 0) { if (manager >= 0) {
pay_bonus(g, manager, slot, 2, true); pay_bonus(g, manager, slot, 2, true);
record_player_statistics(g, manager, slot, player, cls, kind);
if (cls < 3) g.tactics.at(board + 7 + cls)++; if (cls < 3) g.tactics.at(board + 7 + cls)++;
wr16(g.tactics, board + 0x48, uint16_t(rd16(g.tactics, board + 0x48) + 1)); wr16(g.tactics, board + 0x48, uint16_t(rd16(g.tactics, board + 0x48) + 1));
} }
@@ -249,13 +250,17 @@ void player_statistic(GameState& g, int type, int player, int manager, int slot,
} else if (kind == 1) { // goal } else if (kind == 1) { // goal
if (manager >= 0) { if (manager >= 0) {
pay_bonus(g, manager, slot, 0, true); pay_bonus(g, manager, slot, 0, true);
record_player_statistics(g, manager, slot, player, cls, kind);
wr16(g.tactics, board + 0x4a, uint16_t(rd16(g.tactics, board + 0x4a) + 1)); wr16(g.tactics, board + 0x4a, uint16_t(rd16(g.tactics, board + 0x4a) + 1));
if (cls == 0) g.manager_records.at(size_t(manager) * kManagerRecord + 0x1ae + std::min(minute, 89) / 5)++; if (cls == 0) g.manager_records.at(size_t(manager) * kManagerRecord + 0x1ae + std::min(minute, 89) / 5)++;
} }
// league goals in bits 2-7 (a 64th goal carries into bit 8, as in the original) // league goals in bits 2-7 (a 64th goal carries into bit 8, as in the original)
if (cls == 0) p.w364 = (w364 & 0xFFFFFF03u) | ((((w364 >> 2) & 0x3F) << 2) + 4); if (cls == 0) p.w364 = (w364 & 0xFFFFFF03u) | ((((w364 >> 2) & 0x3F) << 2) + 4);
} else if (kind == 2) { // assist } else if (kind == 2) { // assist
if (manager >= 0) wr16(g.tactics, board + 0x4c, uint16_t(rd16(g.tactics, board + 0x4c) + 1)); if (manager >= 0) {
record_player_statistics(g, manager, slot, player, cls, kind);
wr16(g.tactics, board + 0x4c, uint16_t(rd16(g.tactics, board + 0x4c) + 1));
}
if (cls == 0) p.w368 = (p.w368 & 0xFF03FFFFu) | ((((p.w368 >> 18) & 0x3F) + 1) << 18); if (cls == 0) p.w368 = (p.w368 & 0xFF03FFFFu) | ((((p.w368 >> 18) & 0x3F) + 1) << 18);
} }
} }
@@ -776,7 +781,7 @@ void advance_league_rounds(GameState& g, uint32_t competitions, WatcomRandom& ra
if (g.memory.u8(::bmh::layout::Cup_AdvanceCup_RuntimeField) == 0 && winner) if (g.memory.u8(::bmh::layout::Cup_AdvanceCup_RuntimeField) == 0 && winner)
winner(g, {0, uint16_t(champion)}); winner(g, {0, uint16_t(champion)});
if (g.memory.u8(::bmh::layout::Cup_AdvanceCup_RuntimeField) == 0 && g.memory.has(::bmh::layout::CareerSession_BeginFriendlyOpponentTable_ExecutableField2)) g.memory.set8(::bmh::layout::CareerSession_BeginFriendlyOpponentTable_ExecutableField2, 0); if (g.memory.u8(::bmh::layout::Cup_AdvanceCup_RuntimeField) == 0 && g.memory.has(::bmh::layout::CareerSession_BeginFriendlyOpponentTable_ExecutableField2)) g.memory.set8(::bmh::layout::CareerSession_BeginFriendlyOpponentTable_ExecutableField2, 0);
g.memory.set16(::bmh::layout::Titles + uint32_t(std::min<int>(g.season, 0x31)) * 2, uint16_t(champion)); record_title_holder(g, 0, uint16_t(champion));
const int manager = g.manager_of(champion); const int manager = g.manager_of(champion);
if (manager >= 0) { if (manager >= 0) {
const size_t at = size_t(manager) * kManagerRecord + 0x8a4; const size_t at = size_t(manager) * kManagerRecord + 0x8a4;
+2
View File
@@ -77,6 +77,8 @@ void new_board_entry(GameState& g, int manager, int index, int slot, WatcomRando
// OpenBMH deviates from the original: a new arrival must not inherit the // OpenBMH deviates from the original: a new arrival must not inherit the
// previous occupant's retirement/refusal/month-processing flags. // previous occupant's retirement/refusal/month-processing flags.
e[0xb] = 0; e[0xb] = 0;
std::memset(e + 0x48, 0, 6); // Fresh arrivals do not inherit the previous player's totals.
reset_player_statistics(g, manager, g.squad_slots.at(size_t(slot)) & 0xfff);
e[10] = 2; e[10] = 2;
for (int k = 0; k < 4; k++) e[2 + k] = index < 2 ? 1 : uint8_t(rand.range(2, 0x27)); for (int k = 0; k < 4; k++) e[2 + k] = index < 2 ? 1 : uint8_t(rand.range(2, 0x27));
e[0x3f] = 0xff; e[0x3f] = 0xff;
+2
View File
@@ -126,6 +126,8 @@ Bytes save_stream(const GameState& live) {
for (uint32_t i = 0; i < size; ++i) bytes[i] = g.memory.u8(at + i); for (uint32_t i = 0; i < size; ++i) bytes[i] = g.memory.u8(at + i);
extension.push_back({at, std::move(bytes)}); extension.push_back({at, std::move(bytes)});
} }
auto history = encode_long_career(g);
if (!history.empty()) extension.push_back({kLongCareerExtension, std::move(history)});
append_save_extension(stream, extension); append_save_extension(stream, extension);
return stream; return stream;
} }
+3 -4
View File
@@ -787,6 +787,7 @@ void change_places(GameState& g, int a, int b) {
mem.set32(::bmh::layout::Career_RemoveJoinLoans_RuntimeField + k * 4, (e & 0xfff) | uint32_t(seller) << 12 | uint32_t(buyer) << 22); mem.set32(::bmh::layout::Career_RemoveJoinLoans_RuntimeField + k * 4, (e & 0xfff) | uint32_t(seller) << 12 | uint32_t(buyer) << 22);
} }
if (!g.club_table.empty() && a < 0xa8 && b < 0xa8) swap_bytes(g.club_table, size_t(a) * 0x4a, size_t(b) * 0x4a, 0x4a); if (!g.club_table.empty() && a < 0xa8 && b < 0xa8) swap_bytes(g.club_table, size_t(a) * 0x4a, size_t(b) * 0x4a, 0x4a);
swap_statistics_clubs(g, a, b);
std::swap(g.club_ids.at(size_t(a)), g.club_ids.at(size_t(b))); std::swap(g.club_ids.at(size_t(a)), g.club_ids.at(size_t(b)));
swap_bytes(g.club_heap_bc, size_t(a) * 2, size_t(b) * 2, 2); swap_bytes(g.club_heap_bc, size_t(a) * 2, size_t(b) * 2, 2);
std::swap(g.team_morale.at(size_t(a)), g.team_morale.at(size_t(b))); std::swap(g.team_morale.at(size_t(a)), g.team_morale.at(size_t(b)));
@@ -1284,10 +1285,7 @@ SeasonTransitionOutcome season_end_steps(GameState& g, GameRandom& game, WatcomR
TransferAllocatorContext allocator) { TransferAllocatorContext allocator) {
StaticMemory& mem = g.memory; StaticMemory& mem = g.memory;
if (g.season > 0x31) { // SeasonEndSteps if (g.season > 0x31) { // SeasonEndSteps
for (uint32_t k = 0; k < 9; k++) { shift_legacy_title_history(g);
for (uint32_t i = 0; i < 0x62; i++) mem.set8(::bmh::layout::Titles + k * 100 + i, mem.u8(::bmh::layout::Season_SeasonEndSteps_RuntimeField + k * 100 + i));
mem.set16(::bmh::layout::Season_SeasonEndSteps_RuntimeField2 + k * 100, 0xffff);
}
for (size_t m = 0; m < g.manager_teams.size(); m++) { for (size_t m = 0; m < g.manager_teams.size(); m++) {
for (size_t i = 0; i < 0x93; i++) rec8(g, int(m), 0xda + i) = rec8(g, int(m), 0xdd + i); for (size_t i = 0; i < 0x93; i++) rec8(g, int(m), 0xda + i) = rec8(g, int(m), 0xdd + i);
const size_t at = m * 0xB0C + 0x2aa; const size_t at = m * 0xB0C + 0x2aa;
@@ -1610,6 +1608,7 @@ SeasonTransitionOutcome season_transition(GameState& g, GameRandom& game, Watcom
} }
g.memory.set8(::bmh::layout::CareerSession_RuntimeError_RuntimeField4, 0); g.memory.set8(::bmh::layout::CareerSession_RuntimeError_RuntimeField4, 0);
if (g.memory.has(::bmh::layout::Season_SeasonTransition_RuntimeField)) g.memory.set8(::bmh::layout::Season_SeasonTransition_RuntimeField, 0); if (g.memory.has(::bmh::layout::Season_SeasonTransition_RuntimeField)) g.memory.set8(::bmh::layout::Season_SeasonTransition_RuntimeField, 0);
capture_title_history(g); // Preserve the current window before it advances/shifts.
g.season = int16_t(g.season + 1); // SeasonIndex g.season = int16_t(g.season + 1); // SeasonIndex
reset_club_moods(g, game, rand); reset_club_moods(g, game, rand);
european_setup(g, game, rand, cup_draw); european_setup(g, game, rand, cup_draw);
+7
View File
@@ -99,7 +99,12 @@ GameState GameState::from_save(const SaveState& save, const DbCounts& c) {
g.foreign_strength = bytes(::bmh::layout::ForeignClubStrength); g.foreign_strength = bytes(::bmh::layout::ForeignClubStrength);
g.memory = StaticMemory(save); g.memory = StaticMemory(save);
// memory OpenBMH saves behind the trailer (the English cup blocks, career.hpp) // memory OpenBMH saves behind the trailer (the English cup blocks, career.hpp)
bool long_career_seen = false;
for (const auto& b : save.extension()) { for (const auto& b : save.extension()) {
if (b.address == kLongCareerExtension) {
if (long_career_seen) throw FormatError("long career: duplicate extension block");
decode_long_career(g, b.bytes); long_career_seen = true; continue;
}
if (!g.memory.has(b.address)) g.memory.add_block(b.address, uint32_t(b.bytes.size())); if (!g.memory.has(b.address)) g.memory.add_block(b.address, uint32_t(b.bytes.size()));
for (size_t i = 0; i < b.bytes.size(); ++i) g.memory.set8(b.address + uint32_t(i), b.bytes[i]); for (size_t i = 0; i < b.bytes.size(); ++i) g.memory.set8(b.address + uint32_t(i), b.bytes[i]);
} }
@@ -110,6 +115,8 @@ GameState GameState::from_save(const SaveState& save, const DbCounts& c) {
g.stadium_names = save.pool(3); g.stadium_names = save.pool(3);
g.player_name_offsets = words16(::bmh::layout::PlayerNameOffsets); g.player_name_offsets = words16(::bmh::layout::PlayerNameOffsets);
g.season = int16_t(save.data(::bmh::layout::SeasonIndex)[0] | save.data(::bmh::layout::SeasonIndex)[1] << 8); g.season = int16_t(save.data(::bmh::layout::SeasonIndex)[0] | save.data(::bmh::layout::SeasonIndex)[1] << 8);
if (!g.title_history.empty() && (g.season < 0 || g.title_history.rbegin()->first > uint32_t(g.season)))
throw FormatError("long career: archived season is beyond the saved calendar");
return g; return g;
} }
+3
View File
@@ -17,6 +17,7 @@
#include "formats/textd.hpp" #include "formats/textd.hpp"
#include "game/memory.hpp" #include "game/memory.hpp"
#include "game/random.hpp" #include "game/random.hpp"
#include "game/long_career.hpp"
#include "game/reality_motion.hpp" #include "game/reality_motion.hpp"
namespace bmh { namespace bmh {
@@ -36,6 +37,8 @@ constexpr uint16_t kEmptySlot = 0x0FFF;
constexpr uint16_t kSlotInLineup = 0x8000; constexpr uint16_t kSlotInLineup = 0x8000;
struct GameState { struct GameState {
PlayerStatisticsArchive player_statistics;
TitleHistoryArchive title_history;
std::vector<uint16_t> squad_slots; // *SquadSlots, all squads back to back (see squad_range) std::vector<uint16_t> squad_slots; // *SquadSlots, all squads back to back (see squad_range)
std::vector<Player> players; // *PlayerConditionTechniqueForm / *PlayerSkillWords / *PlayerIdentityWords, names not filled std::vector<Player> players; // *PlayerConditionTechniqueForm / *PlayerSkillWords / *PlayerIdentityWords, names not filled
std::vector<uint8_t> team_morale; // *TeamMorale, per team: bits 0-5 morale / 2, bits 6-7 flags std::vector<uint8_t> team_morale; // *TeamMorale, per team: bits 0-5 morale / 2, bits 6-7 flags
+8 -5
View File
@@ -28,7 +28,7 @@ void rect(Image& out, int x, int y, int w, int h, uint8_t color) {
for (int yy = std::max(0, y); yy < std::min(out.height, y + h); ++yy) for (int yy = std::max(0, y); yy < std::min(out.height, y + h); ++yy)
for (int xx = std::max(0, x); xx < std::min(out.width, x + w); ++xx) out.at(xx, yy) = color; for (int xx = std::max(0, x); xx < std::min(out.width, x + w); ++xx) out.at(xx, yy) = color;
} }
std::string padded(int value, int width = 2) { std::string padded(uint64_t value, int width = 2) {
std::string s = std::to_string(value); std::string s = std::to_string(value);
if (int(s.size()) < width) s.insert(0, size_t(width - int(s.size())), '%'); if (int(s.size()) < width) s.insert(0, size_t(width - int(s.size())), '%');
return s; return s;
@@ -110,7 +110,10 @@ ClubInfoProjection club_info_from_game(const GameState& g, int team,
player.cards = g.player_cards[id]; player.cards = g.player_cards[id];
player.bonus = g.player_bonus[id]; player.bonus = g.player_bonus[id];
} }
if (board) player.manager_board = std::move(board); if (board) {
player.manager_board = std::move(board);
if (player.player_id >= 0) player.statistics = player_club_statistics(g, team, player.player_id, *player.manager_board);
}
if (!player.borrowed && player.player_id >= 0) { if (!player.borrowed && player.player_id >= 0) {
for (int loan = 0; loan < 200; ++loan) { for (int loan = 0; loan < 200; ++loan) {
const uint32_t address = ::bmh::layout::Career_RemoveJoinLoans_RuntimeField + uint32_t(loan) * 4; const uint32_t address = ::bmh::layout::Career_RemoveJoinLoans_RuntimeField + uint32_t(loan) * 4;
@@ -296,9 +299,9 @@ Image ClubInfoScreen::render() const {
std::string attrs = padded(p.bonus & 127, 3) + exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5); std::string attrs = padded(p.bonus & 127, 3) + exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5);
if (p.manager_board) { if (p.manager_board) {
const auto& b = *p.manager_board; const auto& b = *p.manager_board;
attrs += padded(b[7], 3) + exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5) + padded(b[9], 3) + exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5); attrs += padded(p.statistics ? p.statistics->appearances[0] : b[7], 3) + exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5) + padded(p.statistics ? p.statistics->appearances[2] : b[9], 3) + exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5);
Bytes raw(b.begin(), b.end()); attrs += padded(le16(raw, 0x48), 3) + exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2) + Bytes raw(b.begin(), b.end()); attrs += padded((p.statistics ? p.statistics->total : le16(raw, 0x48)), 3) + exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2) +
padded(le16(raw, 0x4a), 3) + exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2) + padded(le16(raw, 0x4c), 3) + exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField); padded((p.statistics ? p.statistics->goals : le16(raw, 0x4a)), 3) + exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2) + padded((p.statistics ? p.statistics->assists : le16(raw, 0x4c)), 3) + exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField);
} }
text(out, 165, baseline, attrs, 0x6c); text(out, 165, baseline, attrs, 0x6c);
} }
+1
View File
@@ -36,6 +36,7 @@ struct ClubInfoPlayer {
bool offer_name_color = false; bool offer_name_color = false;
// Present only when this runtime club belongs to a human manager. // Present only when this runtime club belongs to a human manager.
std::optional<std::array<uint8_t, 0x58>> manager_board; std::optional<std::array<uint8_t, 0x58>> manager_board;
std::optional<PlayerClubStatistics> statistics;
}; };
// Owned inputs for one render of ClubInfoFromGame / LineupScreen. Build this from the actual // Owned inputs for one render of ClubInfoFromGame / LineupScreen. Build this from the actual
+5 -3
View File
@@ -148,6 +148,7 @@ ContractsState contracts_from_game(const GameState& game, int manager_slot, uint
view.source.name = game.player_name(player); view.source.attributes = source; view.source.name = game.player_name(player); view.source.attributes = source;
view.source.cards = game.player_cards.at(size_t(player)); view.source.bonus = game.player_bonus.at(size_t(player)); view.source.cards = game.player_cards.at(size_t(player)); view.source.bonus = game.player_bonus.at(size_t(player));
std::copy_n(game.tactics.begin() + std::ptrdiff_t(at), 0x58, view.source.board.begin()); std::copy_n(game.tactics.begin() + std::ptrdiff_t(at), 0x58, view.source.board.begin());
view.source.statistics = player_club_statistics(game, team, player, view.source.board);
state.players.push_back(std::move(view)); state.players.push_back(std::move(view));
} }
if (!state.players.empty()) { if (!state.players.empty()) {
@@ -314,6 +315,7 @@ Image ContractsScreen::render_roster() const {
text(out, x, y, original_to_utf8(raw), color, -1); text(out, x, y, original_to_utf8(raw), color, -1);
}; };
const auto fixed = [](uint32_t value, int width, bool grouped = false) { return original_number(value, width, grouped); }; const auto fixed = [](uint32_t value, int width, bool grouped = false) { return original_number(value, width, grouped); };
const auto count = [](uint64_t value) { auto s = std::to_string(value); if(s.size()<3)s.insert(0,3-s.size(),'%'); return s; };
const auto title = original_to_utf8(texts_[(::bmh::layout::Contracts_RenderRoster_TextPointer2 - ::bmh::layout::TextPointerTable) / 4]); const auto title = original_to_utf8(texts_[(::bmh::layout::Contracts_RenderRoster_TextPointer2 - ::bmh::layout::TextPointerTable) / 4]);
sprite_font_.draw(out, SpriteFont::centered_title_x(sprite_font_.text_width(title)), 13, title, 5); sprite_font_.draw(out, SpriteFont::centered_title_x(sprite_font_.text_width(title)), 13, title, 5);
sprite_font_.draw(out, 5, 235, state_.club_name, 5); sprite_font_.draw(out, 5, 235, state_.club_name, 5);
@@ -374,9 +376,9 @@ Image ContractsScreen::render_roster() const {
original_text(65, baseline, fixed(a.age(), 2) + texts_[(::bmh::layout::ClubInfo_Render_TextPointer5 - ::bmh::layout::TextPointerTable) / 4], 0x6c); original_text(65, baseline, fixed(a.age(), 2) + texts_[(::bmh::layout::ClubInfo_Render_TextPointer5 - ::bmh::layout::TextPointerTable) / 4], 0x6c);
for (int skill = 0; skill < 7; ++skill) copy_region(out, atlas_, 256 + a.skill(Player::Skill(skill)) * 16, 32, 87 + skill * 10, baseline - 5, 16, 5, true); for (int skill = 0; skill < 7; ++skill) copy_region(out, atlas_, 256 + a.skill(Player::Skill(skill)) * 16, 32, 87 + skill * 10, baseline - 5, 16, 5, true);
auto word = [&](int at) { return uint16_t(s.board[at] | uint16_t(s.board[at + 1]) << 8); }; auto word = [&](int at) { return uint16_t(s.board[at] | uint16_t(s.board[at + 1]) << 8); };
original_text(165, baseline, fixed(s.bonus & 127, 3) + exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5) + fixed(s.board[7], 3) + exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5) + original_text(165, baseline, fixed(s.bonus & 127, 3) + exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5) + count(s.statistics ? s.statistics->appearances[0] : s.board[7]) + exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5) +
fixed(s.board[9], 3) + exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5) + fixed(word(0x48), 3) + exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2) + count(s.statistics ? s.statistics->appearances[2] : s.board[9]) + exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5) + count(s.statistics ? s.statistics->total : word(0x48)) + exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2) +
fixed(word(0x4a), 3) + exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2) + fixed(word(0x4c), 3) + exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField), 0x6c); count(s.statistics ? s.statistics->goals : word(0x4a)) + exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2) + count(s.statistics ? s.statistics->assists : word(0x4c)) + exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField), 0x6c);
} }
baseline += 7; baseline += 7;
} }
+11 -4
View File
@@ -83,7 +83,7 @@ void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int
if (c != transparent && x+xx>=0 && x+xx<out.width && y+yy>=0 && y+yy<out.height) out.at(x+xx,y+yy)=c; if (c != transparent && x+xx>=0 && x+xx<out.width && y+yy>=0 && y+yy<out.height) out.at(x+xx,y+yy)=c;
} }
} }
std::string number(int value, int width = 2) { std::string number(uint64_t value, int width = 2) {
auto s=std::to_string(value); auto s=std::to_string(value);
if (int(s.size())<width) s.insert(0,size_t(width-int(s.size())),'%'); if (int(s.size())<width) s.insert(0,size_t(width-int(s.size())),'%');
return s; return s;
@@ -110,11 +110,16 @@ LineupState lineup_from_save(const SaveState& s,const LeImage& exe,uint64_t revi
for(size_t at=0;at<w1.size();at+=4) players.push_back({{},le32(w1,at),le32(w2,at),le32(w3,at)}); for(size_t at=0;at<w1.size();at+=4) players.push_back({{},le32(w1,at),le32(w2,at),le32(w3,at)});
auto out=project(memory,exe,teams,words(block(s,::bmh::layout::SquadSlots)),players,block(s,::bmh::layout::TacticsBoards),block(s,::bmh::layout::ManagerAutomation), auto out=project(memory,exe,teams,words(block(s,::bmh::layout::SquadSlots)),players,block(s,::bmh::layout::TacticsBoards),block(s,::bmh::layout::ManagerAutomation),
words(block(s,::bmh::layout::PlayerCards)),block(s,::bmh::layout::PlayerBonuses),words(block(s,::bmh::layout::PlayerNameOffsets)),s.pool(1),words(block(s,::bmh::layout::ClubIdentities)),s.pool(0),revision); words(block(s,::bmh::layout::PlayerCards)),block(s,::bmh::layout::PlayerBonuses),words(block(s,::bmh::layout::PlayerNameOffsets)),s.pool(1),words(block(s,::bmh::layout::ClubIdentities)),s.pool(0),revision);
const auto g = GameState::from_save(s);
for (auto& p : out.players) if (p.player_id >= 0)
p.statistics = player_club_statistics(g, out.runtime_club, p.player_id, p.board);
out.source="original_save_read_only"; return out; out.source="original_save_read_only"; return out;
} }
LineupState lineup_from_game(const GameState& g,const LeImage& exe,uint64_t revision) { LineupState lineup_from_game(const GameState& g,const LeImage& exe,uint64_t revision) {
auto out=project(g.memory,exe,g.manager_teams,g.squad_slots,g.players,g.tactics,g.manager_options, auto out=project(g.memory,exe,g.manager_teams,g.squad_slots,g.players,g.tactics,g.manager_options,
g.player_cards,g.player_bonus,g.player_name_offsets,g.player_names,g.club_ids,g.club_names,revision); g.player_cards,g.player_bonus,g.player_name_offsets,g.player_names,g.club_ids,g.club_names,revision);
for (auto& p : out.players) if (p.player_id >= 0)
p.statistics = player_club_statistics(g, out.runtime_club, p.player_id, p.board);
out.source="engine_projection"; return out; out.source="engine_projection"; return out;
} }
@@ -224,9 +229,9 @@ Image LineupScreen::render() const {
} else { } else {
text(out,65,baseline,number(a.age())+texts_[(::bmh::layout::ClubInfo_Render_TextPointer5-::bmh::layout::TextPointerTable)/4],0x6c); text(out,65,baseline,number(a.age())+texts_[(::bmh::layout::ClubInfo_Render_TextPointer5-::bmh::layout::TextPointerTable)/4],0x6c);
for(int skill=0;skill<7;++skill)copy(out,atlas_,256+a.skill(Player::Skill(skill))*16,32,87+skill*10,baseline-5,16,5,0); for(int skill=0;skill<7;++skill)copy(out,atlas_,256+a.skill(Player::Skill(skill))*16,32,87+skill*10,baseline-5,16,5,0);
text(out,165,baseline,number(p.bonus&127,3)+exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5)+number(p.board[7],3)+exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5)+ text(out,165,baseline,number(p.bonus&127,3)+exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5)+number(p.statistics ? p.statistics->appearances[0] : p.board[7],3)+exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5)+
number(p.board[9],3)+exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5)+number(le16(Bytes(p.board.begin(),p.board.end()),0x48),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2)+ number(p.statistics ? p.statistics->appearances[2] : p.board[9],3)+exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5)+number((p.statistics ? p.statistics->total : le16(Bytes(p.board.begin(),p.board.end()),0x48)),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2)+
number(le16(Bytes(p.board.begin(),p.board.end()),0x4a),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2)+number(le16(Bytes(p.board.begin(),p.board.end()),0x4c),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField),0x6c); number((p.statistics ? p.statistics->goals : le16(Bytes(p.board.begin(),p.board.end()),0x4a)),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2)+number((p.statistics ? p.statistics->assists : le16(Bytes(p.board.begin(),p.board.end()),0x4c)),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField),0x6c);
} }
} }
button(out,1,215,texts_[(::bmh::layout::Lineup_Render_TextPointer-::bmh::layout::TextPointerTable)/4+(state_.view==LineupView::data_a?1:0)]); button(out,1,215,texts_[(::bmh::layout::Lineup_Render_TextPointer-::bmh::layout::TextPointerTable)/4+(state_.view==LineupView::data_a?1:0)]);
@@ -310,6 +315,8 @@ std::string LineupScreen::state_json() const {
if(p.player_id>=0)s<<",\"starting\":"<<((p.slot&0x8000)?"true":"false")<<",\"bench\":"<<((p.slot&0x4000)?"true":"false") if(p.player_id>=0)s<<",\"starting\":"<<((p.slot&0x8000)?"true":"false")<<",\"bench\":"<<((p.slot&0x4000)?"true":"false")
<<",\"position_type\":"<<p.attributes.position()<<",\"condition\":"<<p.attributes.condition()<<",\"technique\":"<<p.attributes.technique() <<",\"position_type\":"<<p.attributes.position()<<",\"condition\":"<<p.attributes.condition()<<",\"technique\":"<<p.attributes.technique()
<<",\"form\":"<<p.attributes.form()<<",\"strength\":"<<p.attributes.strength()<<",\"age\":"<<p.attributes.age()<<",\"exhaustion\":"<<int(p.board[0xf]); <<",\"form\":"<<p.attributes.form()<<",\"strength\":"<<p.attributes.strength()<<",\"age\":"<<p.attributes.age()<<",\"exhaustion\":"<<int(p.board[0xf]);
if (p.statistics) s << ",\"club_appearances\":[" << p.statistics->appearances[0] << ',' << p.statistics->appearances[1] << ',' << p.statistics->appearances[2]
<< "],\"total_appearances\":" << p.statistics->total << ",\"club_goals\":" << p.statistics->goals << ",\"club_assists\":" << p.statistics->assists;
s<<'}';} s<<'}';}
s<<"]}";return s.str(); s<<"]}";return s.str();
} }
+2
View File
@@ -6,6 +6,7 @@
#include <vector> #include <vector>
#include "formats/font.hpp" #include "formats/font.hpp"
#include "game/long_career.hpp"
#include "formats/m3d.hpp" #include "formats/m3d.hpp"
#include "formats/textd.hpp" #include "formats/textd.hpp"
#include "ui/setup.hpp" #include "ui/setup.hpp"
@@ -22,6 +23,7 @@ struct LineupPlayer {
uint16_t cards = 0; uint16_t cards = 0;
uint8_t bonus = 0; uint8_t bonus = 0;
std::array<uint8_t, 0x58> board{}; std::array<uint8_t, 0x58> board{};
std::optional<PlayerClubStatistics> statistics;
}; };
struct LineupState { struct LineupState {
int manager_slot = -1, runtime_club = -1; int manager_slot = -1, runtime_club = -1;
+39 -21
View File
@@ -59,7 +59,7 @@ StatisticsRankingState statistics_rankings_from_game(const GameState& game, cons
int manager_slot, int category, int first_season, int manager_slot, int category, int first_season,
const Image& underlay) { const Image& underlay) {
if (category < 0 || category >= int(kTitleCount)) throw FormatError("statistics rankings: category outside 0..8"); if (category < 0 || category >= int(kTitleCount)) throw FormatError("statistics rankings: category outside 0..8");
if (first_season < 0 || first_season >= int(kSeasonCount) || (first_season % 4) != 0) if (first_season < 0 || (first_season % 4) != 0)
throw FormatError("statistics rankings: Source page must start at a four-season boundary"); throw FormatError("statistics rankings: Source page must start at a four-season boundary");
if (!game.memory.has(kTitles + kTitleCount * kSeasonCount * 2 - 1)) if (!game.memory.has(kTitles + kTitleCount * kSeasonCount * 2 - 1))
throw FormatError("statistics rankings: save lacks the Original Titles title-holder block"); throw FormatError("statistics rankings: save lacks the Original Titles title-holder block");
@@ -76,7 +76,14 @@ StatisticsRankingState statistics_rankings_from_game(const GameState& game, cons
const uint32_t manager_year_at = uint32_t(manager_slot) * 0xb0c + 0x2aa; const uint32_t manager_year_at = uint32_t(manager_slot) * 0xb0c + 0x2aa;
out.season_number_base = int(exe.u16(::bmh::layout::Achievements_FormatError_RuntimeField2)) + out.season_number_base = int(exe.u16(::bmh::layout::Achievements_FormatError_RuntimeField2)) +
int(game.manager_records[manager_year_at] | (uint16_t(game.manager_records[manager_year_at + 1]) << 8)); int(game.manager_records[manager_year_at] | (uint16_t(game.manager_records[manager_year_at + 1]) << 8));
out.current_season = std::clamp(game.season, 0, int(kSeasonCount) - 1); const auto history = title_history_rows(game);
if (history.empty()) throw FormatError("statistics rankings: missing title history");
out.history_first_season = int(history.begin()->first);
out.current_season = game.season - out.history_first_season;
if (out.current_season < 0 || first_season > out.current_season)
throw FormatError("statistics rankings: history page outside known career");
out.season_number_base += out.history_first_season - std::max(0, game.season - 49);
out.season_known.assign(size_t(out.current_season) + 1, false);
out.underlay = underlay; out.underlay = underlay;
for (uint32_t index = 0; index < kTitleCount; ++index) { for (uint32_t index = 0; index < kTitleCount; ++index) {
const uint8_t title_id = exe.u8(::bmh::layout::StatisticsRankings_FormatError_RuntimeField + index); const uint8_t title_id = exe.u8(::bmh::layout::StatisticsRankings_FormatError_RuntimeField + index);
@@ -84,18 +91,23 @@ StatisticsRankingState statistics_rankings_from_game(const GameState& game, cons
if (title_id >= kTitleCount) throw FormatError("statistics rankings: Source title id outside nine stored lists"); if (title_id >= kTitleCount) throw FormatError("statistics rankings: Source title id outside nine stored lists");
out.categories[index] = StatisticsRankingCategory{title_id, alternate}; out.categories[index] = StatisticsRankingCategory{title_id, alternate};
} }
for (uint32_t category_index = 0; category_index < kTitleCount; ++category_index) { for (size_t category = 0; category < 9; ++category) {
for (uint32_t season = 0; season < kSeasonCount; ++season) { const auto count = size_t(out.current_season) + 1;
// StatisticsRankingsFromGame reads Titles by selected control index (local_14). out.title_holders[category].assign(count, 0xffff);
// title_id only chooses the Original label pointer above. out.club_names[category].resize(count);
const uint32_t at = kTitles + category_index * 100 + season * 2; out.club_name_colors[category].assign(count, 0x5f);
out.title_holders[category_index][season] = game.memory.u16(at); out.title_present[category].assign(count, false);
const uint16_t team = out.title_holders[category_index][season]; for (const auto& [season, names] : history) {
if (team != 0xffff) { if (int(season) > game.season) throw FormatError("statistics rankings: future archived season");
if (team >= game.club_ids.size()) const auto index = size_t(int(season) - out.history_first_season);
throw FormatError("statistics rankings: Source title holder has no club identity/name"); out.season_known[index] = true;
out.club_names[category_index][season] = game.club_name(team); out.club_names[category][index] = names[category];
out.club_name_colors[category_index][season] = original_name_color(game, team); out.title_present[category][index] = !names[category].empty();
const int native_index = int(season) - std::max(0, game.season - 49);
if (native_index >= 0 && native_index < 50) {
const auto team = game.memory.u16(kTitles + uint32_t(category) * 100 + uint32_t(native_index) * 2);
out.title_holders[category][index] = team;
if (team != 0xffff) out.club_name_colors[category][index] = original_name_color(game, team);
} }
} }
} }
@@ -109,11 +121,16 @@ StatisticsRankingsScreen::StatisticsRankingsScreen(const std::filesystem::path&
button_art_(load_vga(asset_path(data / "KB", "0.VGA"))), button_art_(load_vga(asset_path(data / "KB", "0.VGA"))),
texts_(load_textd(asset_path(data, "TEXTD.BLK"))) { texts_(load_textd(asset_path(data, "TEXTD.BLK"))) {
if (state_.category < 0 || state_.category >= int(kTitleCount) || state_.current_season < 0 || if (state_.category < 0 || state_.category >= int(kTitleCount) || state_.current_season < 0 ||
state_.current_season >= int(kSeasonCount) || state_.first_season < 0 || state_.first_season < 0 || state_.first_season > state_.current_season || state_.first_season % 4 != 0 ||
state_.first_season >= int(kSeasonCount) || state_.first_season % 4 != 0 ||
state_.underlay.width != 320 || state_.underlay.height != 240 || state_.underlay.width != 320 || state_.underlay.height != 240 ||
button_art_.width < 76 || button_art_.height < 84) button_art_.width < 76 || button_art_.height < 84)
throw FormatError("statistics rankings: incomplete Source projection"); throw FormatError("statistics rankings: incomplete Source projection");
for (size_t i = 0; i < 9; ++i)
if (state_.club_names[i].size() != size_t(state_.current_season) + 1 ||
state_.club_name_colors[i].size() != state_.club_names[i].size() ||
state_.title_present[i].size() != state_.club_names[i].size() ||
state_.season_known.size() != state_.club_names[i].size())
throw FormatError("statistics rankings: incomplete archived rows");
for (size_t i = 0; i < state_.categories.size(); ++i) { for (size_t i = 0; i < state_.categories.size(); ++i) {
const auto& category = state_.categories[i]; const auto& category = state_.categories[i];
if (category.title_id >= kTitleCount) if (category.title_id >= kTitleCount)
@@ -169,21 +186,22 @@ Image StatisticsRankingsScreen::render() const {
for (int season = state_.first_season; season <= end; ++season) { for (int season = state_.first_season; season <= end; ++season) {
const int visible = season - state_.first_season; const int visible = season - state_.first_season;
const int y = 0x31 + visible * 6; const int y = 0x31 + visible * 6;
const uint16_t team = state_.title_holders[size_t(state_.category)][size_t(season)]; const bool has_title = state_.title_present[size_t(state_.category)][size_t(season)];
if (season < state_.current_season || team != 0xffff) { if (season < state_.current_season || has_title) {
const int source_season_number = state_.season_number_base + season + 1; const int source_season_number = state_.season_number_base + season + 1;
std::string n = std::to_string(source_season_number); std::string n = std::to_string(source_season_number);
while (n.size() < 4) n.insert(n.begin(), '%'); while (n.size() < 4) n.insert(n.begin(), '%');
n += "%%"; // FormatNumber(...,0xc4,&StatisticsRankingsRuntimeField): width-four Source number and suffix. n += "%%"; // FormatNumber(...,0xc4,&StatisticsRankingsRuntimeField): width-four Source number and suffix.
const uint8_t year_color = team == 0xffff && const uint8_t year_color = !has_title &&
(state_.category == 5 || state_.category == 6) ? 0x67 : 0x6b; (state_.category == 5 || state_.category == 6) ? 0x67 : 0x6b;
font_.draw(out, 100, y - font_.baseline, n, year_color); font_.draw(out, 100, y - font_.baseline, n, year_color);
if (team != 0xffff) { if (has_title) {
font_.draw(out, 130, y - font_.baseline, font_.draw(out, 130, y - font_.baseline,
state_.club_names[size_t(state_.category)][size_t(season)], state_.club_names[size_t(state_.category)][size_t(season)],
state_.club_name_colors[size_t(state_.category)][size_t(season)]); state_.club_name_colors[size_t(state_.category)][size_t(season)]);
} else { } else {
font_.draw(out, 130, y - font_.baseline, empty_label_, 0x67); font_.draw(out, 130, y - font_.baseline,
state_.season_known[size_t(season)] ? empty_label_ : "Unbekannt", 0x67);
} }
} }
} }
+6 -3
View File
@@ -27,9 +27,12 @@ struct StatisticsRankingCategory {
struct StatisticsRankingState { struct StatisticsRankingState {
std::array<StatisticsRankingCategory, 9> categories{}; std::array<StatisticsRankingCategory, 9> categories{};
std::array<std::array<uint16_t, 50>, 9> title_holders{}; std::array<std::vector<uint16_t>, 9> title_holders{};
std::array<std::array<std::string, 50>, 9> club_names{}; std::array<std::vector<std::string>, 9> club_names{};
std::array<std::array<uint8_t, 50>, 9> club_name_colors{}; std::array<std::vector<uint8_t>, 9> club_name_colors{};
std::array<std::vector<bool>, 9> title_present{};
std::vector<bool> season_known;
int history_first_season = 0;
int current_season = 0; // SeasonIndex: latest history index; current empty slot is retained. int current_season = 0; // SeasonIndex: latest history index; current empty slot is retained.
int manager_slot = -1; int manager_slot = -1;
int season_number_base = 0; // AchievementsRuntimeField[manager] + Achievements_FormatError_RuntimeField2; StatisticsRankingsFromGame adds one. int season_number_base = 0; // AchievementsRuntimeField[manager] + Achievements_FormatError_RuntimeField2; StatisticsRankingsFromGame adds one.
+22
View File
@@ -97,6 +97,28 @@ int main(int argc, char** argv) {
screen.pending()->kind == StatisticsRankingsRequestKind::close, screen.pending()->kind == StatisticsRankingsRequestKind::close,
"right-click is the Source parent-return request"); "right-click is the Source parent-return request");
auto career = sample(); career.season = 300;
career.manager_records[0x2aa] = uint8_t(258); career.manager_records[0x2ab] = uint8_t(258 >> 8);
for (uint32_t season = 0; season <= 300; ++season) {
std::array<std::string,9> titles; titles[0] = "Bayer"; career.title_history.emplace(season, titles);
}
auto wide = statistics_rankings_from_game(career, exe, 0, 0, 0, underlay);
check(wide.current_season == 300 && wide.history_first_season == 0 && wide.club_names[0].size() == 301 &&
wide.club_names[0][0] == "Bayer" && wide.club_names[0][300] == "Bayer",
"archived title lists retain all 301 known seasons and original winner snapshots");
check(wide.season_number_base == int(exe.u16(::bmh::layout::Achievements_FormatError_RuntimeField2)) + 7,
"absolute archive year labels compensate for the native 50-row window shift");
StatisticsRankingsScreen long_screen(data, wide);
for (int n = 0; n < 100; ++n) long_screen.scroll(1);
check(long_screen.state().first_season == 288 && long_screen.render().width == 320,
"history paging reaches season 300 instead of stopping at the fiftieth row");
for (int n = 0; n < 100; ++n) long_screen.scroll(-1);
check(long_screen.state().first_season == 0, "oldest archived title rows remain reachable");
auto legacy = sample(); legacy.season = 300;
const auto imported = statistics_rankings_from_game(legacy, exe, 0, 0, 0, underlay);
check(imported.history_first_season == 251 && imported.current_season == 49,
"a legacy late-career save exposes only its surviving 50 seasons, without invented earlier winners");
GameState missing; GameState missing;
bool rejected = false; bool rejected = false;
try { (void)statistics_rankings_from_game(missing, exe, 0, 0, 0, underlay); } try { (void)statistics_rankings_from_game(missing, exe, 0, 0, 0, underlay); }
+5 -3
View File
@@ -32,7 +32,7 @@ void copy(Image& out,const Image& source,int sx,int sy,int x,int y,int w,int h,i
if(pixel!=key&&x+xx>=0&&x+xx<out.width&&y+yy>=0&&y+yy<out.height)out.at(x+xx,y+yy)=pixel; if(pixel!=key&&x+xx>=0&&x+xx<out.width&&y+yy>=0&&y+yy<out.height)out.at(x+xx,y+yy)=pixel;
} }
} }
std::string padded(int n,int width=2) { std::string padded(uint64_t n,int width=2) {
auto text=std::to_string(n);if(int(text.size())<width)text.insert(0,size_t(width-int(text.size())),'%');return text; auto text=std::to_string(n);if(int(text.size())<width)text.insert(0,size_t(width-int(text.size())),'%');return text;
} }
std::string money(int64_t value) { std::string money(int64_t value) {
@@ -191,6 +191,7 @@ TransferMarketState transfer_market_from_game(const GameState& g, uint64_t revis
if(int(word&31)==manager&&int(word>>10&0xfff)==id)p.offer_name_color=true; if(int(word&31)==manager&&int(word>>10&0xfff)==id)p.offer_name_color=true;
} }
} }
if (p.manager_board && p.player_id >= 0) p.statistics = player_club_statistics(g, state.runtime_club, p.player_id, *p.manager_board);
state.roster.players.push_back(std::move(p)); state.roster.players.push_back(std::move(p));
} }
for(size_t index=0;index<borrowed.size();++index) { for(size_t index=0;index<borrowed.size();++index) {
@@ -204,6 +205,7 @@ TransferMarketState transfer_market_from_game(const GameState& g, uint64_t revis
const uint32_t board=::bmh::layout::ClubInfo_FormatError_RuntimeField+uint32_t(loan)*0x58; const uint32_t board=::bmh::layout::ClubInfo_FormatError_RuntimeField+uint32_t(loan)*0x58;
if(!g.memory.has(board+0x57))throw FormatError("transfer market: borrowed board outside Native storage"); if(!g.memory.has(board+0x57))throw FormatError("transfer market: borrowed board outside Native storage");
p.manager_board.emplace();for(uint32_t n=0;n<0x58;++n)(*p.manager_board)[n]=g.memory.u8(board+n); p.manager_board.emplace();for(uint32_t n=0;n<0x58;++n)(*p.manager_board)[n]=g.memory.u8(board+n);
p.statistics = player_club_statistics(g, state.runtime_club, p.player_id, *p.manager_board);
state.roster.players.push_back(std::move(p)); state.roster.players.push_back(std::move(p));
} }
for (size_t row = 0; row < ordinary_count; ++row) { for (size_t row = 0; row < ordinary_count; ++row) {
@@ -448,8 +450,8 @@ void TransferMarketScreen::draw_roster(Image& out,bool full) const {
for(int skill=0;skill<7;++skill)copy(out,atlas_,256+a.skill(Player::Skill(skill))*16,32,87+skill*10,baseline-5,16,5,0); for(int skill=0;skill<7;++skill)copy(out,atlas_,256+a.skill(Player::Skill(skill))*16,32,87+skill*10,baseline-5,16,5,0);
std::string stats=padded(p.bonus&127,3)+exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5); std::string stats=padded(p.bonus&127,3)+exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5);
if(p.manager_board) { if(p.manager_board) {
const auto& b=*p.manager_board;stats+=padded(b[7],3)+exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5)+padded(b[9],3)+exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5); const auto& b=*p.manager_board;stats+=padded(p.statistics ? p.statistics->appearances[0] : b[7],3)+exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5)+padded(p.statistics ? p.statistics->appearances[2] : b[9],3)+exe_.cstring(::bmh::layout::ClubInfo_Render_ExecutableField5);
if(full){Bytes raw(b.begin(),b.end());stats+=padded(le16(raw,0x48),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2)+padded(le16(raw,0x4a),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2)+padded(le16(raw,0x4c),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField);} if(full){Bytes raw(b.begin(),b.end());stats+=padded((p.statistics ? p.statistics->total : le16(raw,0x48)),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2)+padded((p.statistics ? p.statistics->goals : le16(raw,0x4a)),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField2)+padded((p.statistics ? p.statistics->assists : le16(raw,0x4c)),3)+exe_.cstring(::bmh::layout::ClubInfo_Raw_ExecutableField);}
} }
original_text(out,165,baseline,stats,0x6c); original_text(out,165,baseline,stats,0x6c);
} }
+12
View File
@@ -100,6 +100,18 @@ int main(int argc,char** argv){
check(!transfer_market_from_game(expired,5).squad[0].already_listed, check(!transfer_market_from_game(expired,5).squad[0].already_listed,
"cleared rejected/expired pool entry immediately makes the player listable again"); "cleared rejected/expired pool entry immediately makes the player listable again");
auto wide_game=fixture();
wide_game.player_statistics.emplace(uint32_t(1)<<12, PlayerClubStatistics{{256,0,256},65536,0,0});
const auto wide_state=transfer_market_from_game(wide_game,4);
check(wide_state.roster.players[0].statistics&&wide_state.roster.players[0].statistics->appearances[0]==256&&
wide_state.roster.players[0].statistics->total==65536,
"roster projection owns widened counts instead of showing wrapped Native bytes");
TransferMarketScreen wide_screen(argv[1],wide_state),native_screen(argv[1],s);
wide_screen.click(65,219);native_screen.click(65,219);
wide_screen.click(10,219);native_screen.click(10,219);
check(wide_screen.render().pixels!=native_screen.render().pixels,
"actual transfer roster renderer visibly retains the 256th appearance");
auto all=s;all.items.clear();for(int n=0;n<40;++n){auto item=s.items[0];item.list_entry=n;item.source_slot=2928+n;item.player=100+n;item.name="P"+std::to_string(n);item.position=n%4;item.strength=60+n%7;all.items.push_back(item);} auto all=s;all.items.clear();for(int n=0;n<40;++n){auto item=s.items[0];item.list_entry=n;item.source_slot=2928+n;item.player=100+n;item.name="P"+std::to_string(n);item.position=n%4;item.strength=60+n%7;all.items.push_back(item);}
TransferMarketScreen pages(argv[1],all);const auto first=visible(pages);std::set<int> reached; TransferMarketScreen pages(argv[1],all);const auto first=visible(pages);std::set<int> reached;
for(int page=0;page<7;++page){const auto rows=visible(pages);check(rows.size()==size_t(page==6?4:6),"six original rows per page with final four");reached.insert(rows.begin(),rows.end());pages.click(210,45,true);} for(int page=0;page<7;++page){const auto rows=visible(pages);check(rows.size()==size_t(page==6?4:6),"six original rows per page with final four");reached.insert(rows.begin(),rows.end());pages.click(210,45,true);}
+116
View File
@@ -0,0 +1,116 @@
// SPDX-License-Identifier: GPL-3.0-only
#include <algorithm>
#include <array>
#include <iostream>
#include <stdexcept>
#include "formats/executable_layout.hpp"
#include "game/long_career.hpp"
#include "game/matchday.hpp"
#include "game/national.hpp"
#include "game/save.hpp"
using namespace bmh;
namespace {
void check(bool yes, const char* why) { if (!yes) throw std::runtime_error(why); }
GameState fixture() {
GameState g; g.season = 0; g.manager_teams = {0};
g.manager_records.resize(5 * 0xb0c); g.tactics.resize(5 * 0x840);
g.players = {{"Synthetic", 70u << 7 | 70u << 14 | 70u, 0, 6u << 21 | 1u}};
g.player_bonus.resize(1); g.squad_slots.resize(3072, 0xfff); g.squad_slots[0] = 0;
g.club_ids = {0, 5}; g.club_names = {'C','l','u','b',0,'R','i','v','a','l',0};
g.memory.add_block(layout::Titles, 900);
for (uint32_t n = 0; n < 900; ++n) g.memory.set8(layout::Titles + n, 0xff);
g.memory.add_block(layout::ManagerCount, 1); g.memory.set8(layout::ManagerCount, 1);
return g;
}
std::array<uint8_t, 0x58> board(const GameState& g) {
std::array<uint8_t, 0x58> b; std::copy_n(g.tactics.begin(), b.size(), b.begin()); return b;
}
void counters() {
auto g = fixture();
g.tactics[7] = g.tactics[8] = g.tactics[9] = 255;
for (size_t n = 0x48; n <= 0x4d; ++n) g.tactics[n] = 255;
player_statistic(g, 0, 0, 0, 0, 0, 0);
player_statistic(g, 1, 0, 0, 0, 0, 0);
player_statistic(g, 2, 0, 0, 0, 0, 0);
player_statistic(g, 0, 0, 0, 0, 1, 0);
player_statistic(g, 0, 0, 0, 0, 2, 0);
const auto stats = player_club_statistics(g, 0, 0, board(g));
check(stats.appearances == std::array<uint64_t,3>{256,256,256}, "all cumulative byte counters survive 255 -> 256");
check(stats.total == 65538 && stats.goals == 65536 && stats.assists == 65536, "word totals survive 65535 -> 65536");
check(g.tactics[7] == 0 && g.tactics[8] == 0 && g.tactics[9] == 0 && g.tactics[0x48] == 2,
"native byte/word fields retain compatible modulo representation");
const auto native = save_stream(g); const SaveState saved(native);
auto loaded = GameState::from_save(saved);
check(loaded.player_statistics == g.player_statistics && save_stream(loaded) == native,
"optional wide counters survive exact native-stream save/load/save roundtrip");
const auto payload = encode_long_career(g);
auto plain = g; plain.player_statistics.clear();
const auto original = save_stream(plain);
check(original.size() + payload.size() + 18 == native.size() &&
std::equal(original.begin(), original.end(), native.begin()), "extension leaves every Original block and name pool byte unchanged");
swap_statistics_clubs(g, 0, 1);
check(player_club_statistics(g, 1, 0, board(g)) == stats, "club promotion remapping retains the same player's counts");
swap_statistics_clubs(g, 0, 1);
WatcomRandom random(713);
new_board_entry(g, 0, 0, 0, random);
check(g.player_statistics.empty() && player_club_statistics(g, 0, 0, board(g)).total == 0,
"replacement player never inherits the previous occupant's wide/native totals");
auto exhausted = fixture();
exhausted.player_statistics.emplace(0, PlayerClubStatistics{{255,0,0}, UINT64_MAX,0,0});
const auto exhausted_before = save_stream(exhausted); bool refused = false;
try { player_statistic(exhausted, 0, 0, 0, 0, 0, 0); } catch (const FormatError&) { refused = true; }
check(refused && save_stream(exhausted) == exhausted_before, "uint64 exhaustion is explicit and inert, never a silent clamp");
auto wrapped = fixture(); // Already lost high bits cannot be reconstructed from a legacy import.
player_statistic(wrapped, 0, 0, 0, 0, 0, 0);
check(player_club_statistics(wrapped, 0, 0, board(wrapped)).total == 1, "legacy zero is a known lower bound, never fabricated prior appearances");
}
void history() {
auto g = fixture();
for (int season = 0; season <= 300; ++season) {
if (season) {
capture_title_history(g); ++g.season; shift_legacy_title_history(g);
}
record_title_holder(g, 0, uint16_t(season % 2));
record_title_holder(g, 1, uint16_t((season + 1) % 2));
}
check(g.title_history.size() == 301 && g.title_history.at(0)[0] == "Club" &&
g.title_history.at(49)[0] == "Rival" && g.title_history.at(50)[0] == "Club" &&
g.title_history.at(300)[1] == "Rival", "title and cup winners remain available across seasons 49/50/300");
check(g.memory.u16(layout::Titles) == 1 && g.memory.u16(layout::Titles + 98) == 0,
"Original block still contains exactly the latest 50 seasons");
const auto bytes = save_stream(g); const SaveState saved(bytes); auto loaded = GameState::from_save(saved);
check(loaded.title_history == g.title_history && save_stream(loaded) == bytes, "301 seasons persist in the optional save extension");
g.club_names[0] = 'X';
check(g.title_history.at(0)[0] == "Club", "winner names are owned snapshots, independent of later renaming/promotion");
auto imported = fixture(); imported.season = 300; imported.memory.set16(layout::Titles, 0);
capture_title_history(imported);
check(imported.title_history.size() == 50 && imported.title_history.begin()->first == 251 &&
!imported.title_history.contains(0), "old late-career imports retain only known rows and do not fabricate lost history");
}
void malformed() {
auto g = fixture(); record_title_holder(g, 0, 0); const auto original = encode_long_career(g);
for (size_t size = 0; size < original.size(); ++size) {
auto old = g; bool refused = false;
try { decode_long_career(old, Bytes(original.begin(), original.begin() + size)); }
catch (const FormatError&) { refused = true; }
check(refused && old.title_history == g.title_history, "truncated archive rejects atomically");
}
auto version = original; version[0] = 2; bool refused = false;
try { decode_long_career(g, version); } catch (const FormatError&) { refused = true; }
check(refused, "future archive versions are explicit unsupported outcomes");
auto future = g; future.title_history.emplace(1, std::array<std::string,9>{});
const auto future_bytes = save_stream(future); refused = false;
try { (void)GameState::from_save(SaveState(future_bytes)); } catch (const FormatError&) { refused = true; }
check(refused, "future season history cannot silently bind to a different saved calendar");
auto base = g; base.title_history.clear(); auto duplicate = save_stream(base);
append_save_extension(duplicate, {{kLongCareerExtension,original},{kLongCareerExtension,original}});
refused = false;
try { (void)GameState::from_save(SaveState(duplicate)); } catch (const FormatError&) { refused = true; }
check(refused, "duplicate archive containers reject rather than overwrite history");
}
}
int main() try {
counters(); history(); malformed();
std::cout << "PASS cumulative 256/65536 counters, 301 title seasons, legacy compatibility and archive roundtrip/validation\n";
return 0;
} catch (const std::exception& error) { std::cerr << error.what() << '\n'; return 1; }