Introduce explicit Classic and expanded 1.1 data profile dimensions (by Codex)

This commit is contained in:
Codex committed 2026-10-31 09:48:45 +01:00
1 parent b2a6300aad
commit ff05d4f28a
12 files changed
+132 -8

No files matched your search

+5
View File
@@ -213,6 +213,7 @@ add_library(bmhcore STATIC
src/formats/textd.cpp
src/formats/fbm.cpp
src/formats/le.cpp
src/formats/data_profile.cpp
src/formats/m3d.cpp
src/formats/savestate.cpp
src/game/schedule.cpp
@@ -1152,3 +1153,7 @@ endif()
add_executable(desktop_feedback_tests tests/desktop_feedback_tests.cpp)
target_link_libraries(desktop_feedback_tests PRIVATE bmhui)
bmh_add_data_test(NAME desktop_feedback_tests COMMAND desktop_feedback_tests "${BMH_DATA}")
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)
+9
View File
@@ -0,0 +1,9 @@
# International-league POC
Working branch: poc/1.1-international, based on v1.0.2. The stable main line is separate.
The explicit `OBMHPROF.INI` profile marker selects classic-plus-1; missing metadata retains the original Classic mode. Unknown or inconsistent metadata is rejected. Profiles define database counts and roster boundaries, with tests for the existing layout, the expanded layout and packed-player limits.
Target: five German divisions unchanged, international sizes 18/20/18/18, 164 league clubs, 24 roster slots and normally 20 starting players per league club. The expanded runtime needs 4,158 roster and auxiliary slots. Player IDs remain below the 4,095 empty sentinel; absolute slot references must not be truncated to twelve bits.
This is a development status, not a claim of completed expanded gameplay. Next stages migrate semantic limits and index-dependent buffers, prepare the private dataset, distinguish extended save identity, and verify two complete seasons. No original data or rendered proprietary assets belong in this public tree. Classic readers retain their default counts and byte structure.
+41
View File
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/data_profile.hpp"
#include <fstream>
#include <numeric>
#include <set>
#include <sstream>
namespace bmh {
DataProfile DataProfile::international_11() {
DataProfile p;
p.id="classic-plus-1";
p.leagues={18,18,18,18,18,18,20,18,18};
p.counts={445,3334,194,4104,164,30};
p.big_squad_teams=164;
p.national_first=383;
return p;
}
void DataProfile::validate() const {
const auto total=std::accumulate(leagues.begin(),leagues.end(),uint32_t(0));
if(total!=counts.league_teams || big_squad_teams>total || counts.n42!=total+counts.cup_teams ||
counts.n66!=extra_slots_first() || counts.clubs!=national_first+62 ||
national_first!=total+counts.cup_teams+189 || counts.clubs>512 || counts.players>=4095 || total_slots()>65535)
throw FormatError("profile: inconsistent counts or packed identifier overflow");
for(auto size:leagues)if(size!=12 && size!=18 && size!=20)throw FormatError("profile: unsupported league size");
}
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");
std::string line,id;bool section=false,seen=false;
while(std::getline(input,line)) {
if(!line.empty()&&line.back()=='\r')line.pop_back();
const auto first=line.find_first_not_of(" \t");if(first==std::string::npos||line[first]==';'||line[first]=='#')continue;
const auto last=line.find_last_not_of(" \t");line=line.substr(first,last-first+1);
if(line=="[OpenBMH]"){if(section)throw FormatError("profile: duplicate section");section=true;continue;}
if(!section||line.rfind("profile=",0)!=0||seen)throw FormatError("profile: unknown or duplicate metadata key");
id=line.substr(8);seen=true;
}
if(id!="classic-plus-1")throw FormatError("profile: unsupported data profile");
auto p=DataProfile::international_11();p.validate();return p;
}
}
+24
View File
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <array>
#include <filesystem>
#include <string>
#include "formats/m3d.hpp"
namespace bmh {
// Installation metadata; original files retain their implicit Classic profile.
struct DataProfile {
std::string id = "classic";
std::array<uint8_t,9> leagues{18,18,18,18,18,12,12,12,12};
DbCounts counts{};
uint32_t big_squad_teams = 90;
uint32_t national_first = 357;
uint32_t pool_first() const { return big_squad_teams*24+(counts.league_teams-big_squad_teams)*16; }
uint32_t national_slots_first() const { return pool_first()+144; }
uint32_t extra_slots_first() const { return national_slots_first()+24; }
uint32_t total_slots() const { return extra_slots_first()+54; }
bool extended() const { return id != "classic"; }
void validate() const;
static DataProfile international_11();
};
DataProfile load_data_profile(const std::filesystem::path& directory);
}
+3 -3
View File
@@ -40,7 +40,7 @@ Database load_database(const std::filesystem::path& path, const DbCounts& c) {
Bytes lens = r.take(8);
size_t len_clubs = le16(lens, 0), len_players = le16(lens, 2), len_refs = le16(lens, 4), len_stadiums = le16(lens, 6);
Database db;
Database db; db.counts=c;
db.raw_player_bonus_values = r.take(c.n66 + 0x32);
Bytes club_pool = r.take(len_clubs);
Bytes player_pool = r.take(len_players);
@@ -57,8 +57,8 @@ Database load_database(const std::filesystem::path& path, const DbCounts& c) {
db.raw_foreign_club_strength = r.take(0xFB);
db.raw_league_auxiliary_bytes = r.take(0xBD);
db.raw_referee_properties = r.take(0x32);
db.raw_club_kit_selectors = r.take(0x1A3);
db.raw_club_short_name_offsets = r.take(0xA8);
db.raw_club_kit_selectors = r.take(c.clubs);
db.raw_club_short_name_offsets = r.take(c.n42);
db.squad_list = r.take((c.n66 - 4) * 2 + 0x6C);
Bytes w35c = r.take(c.players * 4), w368 = r.take(c.players * 4), w364 = r.take(c.players * 4);
if (r.pos != d.size()) throw FormatError("M3D: trailing data, table sizes do not match");
+3
View File
@@ -16,6 +16,8 @@ struct DbCounts {
uint32_t players = 2574;
uint32_t n42 = 168;
uint32_t n66 = 3096;
uint32_t league_teams = 138;
uint32_t cup_teams = 30;
};
// A player as stored in the three parallel u32 tables of the database/savegame
@@ -61,6 +63,7 @@ struct Player {
};
struct Database {
DbCounts counts{};
std::vector<std::string> club_names;
std::vector<std::string> referees;
std::vector<std::string> stadiums;
+2 -2
View File
@@ -106,7 +106,7 @@ constexpr BlockDef kBlocks[] = {
SaveState::SaveState(const Bytes& stream, const DbCounts& c) : stream_(stream) {
// Teams in league play and cup-only teams are not part of DbCounts yet;
// these are the V2.24 values (CareerSession_DispatchLineup_RuntimeField, CareerSession_InstallLeagueSizes_RuntimeField6).
constexpr uint32_t kTeams = 138, kCupTeams = 30;
const uint32_t kTeams = c.league_teams, kCupTeams = c.cup_teams;
size_t pos = 0;
uint32_t last_pointer = 0;
for (const BlockDef& d : kBlocks) {
@@ -177,7 +177,7 @@ const SaveBlock& SaveState::block(uint32_t address) const {
namespace bmh {
std::vector<SaveBlock> save_layout(const DbCounts& c, bool club_records) {
constexpr uint32_t kTeams = 138, kCupTeams = 30;
const uint32_t kTeams = c.league_teams, kCupTeams = c.cup_teams;
std::vector<SaveBlock> out;
size_t pos = 0;
for (const BlockDef& d : kBlocks) {
+1 -1
View File
@@ -101,7 +101,7 @@ void startup_players(GameState& g, GameRandom& game, WatcomRandom& rand) {
namespace bmh {
GameState startup_state(const LeImage& exe, const Database& db, const Bytes& m3_men, const Bytes& m3_dat) {
const DbCounts counts;
const DbCounts counts=db.counts;
const std::vector<SaveBlock> layout = save_layout(counts, true);
Bytes stream;
for (const SaveBlock& b : layout) {
+1 -1
View File
@@ -59,7 +59,7 @@ Bytes save_stream(const GameState& live) {
const GameState& g = coach ? swapped : live;
const bool records = g.memory.has(::bmh::layout::ClubSeasonRecords) && g.memory.u32(::bmh::layout::ClubSeasonRecords) != 0;
Bytes stream;
for (const SaveBlock& b : save_layout(DbCounts{}, records)) {
for (const SaveBlock& b : save_layout(g.counts, records)) {
Bytes d(b.size, 0);
if (b.heap) {
switch (b.address) {
+1 -1
View File
@@ -21,7 +21,7 @@ int div8(int x) { return x / 8; }
} // namespace
GameState GameState::from_save(const SaveState& save, const DbCounts& c) {
GameState g;
GameState g; g.counts=c;
const SaveBlock& squads = save.block(::bmh::layout::SquadSlots);
for (size_t i = 0; i + 1 < squads.size; i += 2)
g.squad_slots.push_back(uint16_t(save.data(::bmh::layout::SquadSlots)[i] | save.data(::bmh::layout::SquadSlots)[i + 1] << 8));
+1
View File
@@ -36,6 +36,7 @@ constexpr uint16_t kEmptySlot = 0x0FFF;
constexpr uint16_t kSlotInLineup = 0x8000;
struct GameState {
DbCounts counts{};
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<uint8_t> team_morale; // *TeamMorale, per team: bits 0-5 morale / 2, bits 6-7 flags
+41
View File
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/data_profile.hpp"
#include "formats/savestate.hpp"
#include "formats/executable_layout.hpp"
#include <filesystem>
#include <fstream>
#include <iostream>
#include <stdexcept>
void check(bool condition,const char* message){if(!condition)throw std::runtime_error(message);}
int main()try {
bmh::DataProfile classic;classic.validate();
check(classic.pool_first()==2928 && classic.national_slots_first()==3072 && classic.total_slots()==3150,"Classic roster boundaries changed");
auto expanded=bmh::DataProfile::international_11();expanded.validate();
check(expanded.counts.league_teams==164 && expanded.pool_first()==3936 && expanded.total_slots()==4158,"Expanded roster boundaries incorrect");
check(expanded.leagues[6]==20 && expanded.counts.players<4095 && expanded.counts.clubs<=512,"Expanded profile exceeds compact IDs");
for (const auto& profile : {classic, expanded}) {
const auto blocks = bmh::save_layout(profile.counts, true);
const auto& end = blocks.back();
bmh::Bytes stream(end.offset + end.size, 0);
for (const auto& block : blocks)
if (block.address == bmh::layout::ClubSeasonRecords && !block.heap) stream.at(block.offset) = 1;
stream.insert(stream.end(), 8, 0); // Four empty, independent synthetic string pools.
bmh::SaveState decoded(stream, profile.counts);
check(decoded.block(bmh::layout::SquadSlots).size == profile.total_slots() * 2,
"squad block ignored configured profile counts");
check(decoded.block(bmh::layout::PlayerConditionTechniqueForm).size == profile.counts.players * 4,
"player block ignored configured profile counts");
}
auto invalid=expanded;invalid.counts.players=4095;bool rejected=false;
try{invalid.validate();}catch(const bmh::FormatError&){rejected=true;}
check(rejected,"Player-ID sentinel collision accepted");
const auto dir=std::filesystem::temp_directory_path()/"openbmh-profile-synthetic-test";
std::filesystem::create_directories(dir);
check(!bmh::load_data_profile(dir).extended(),"Original installation did not select Classic");
{std::ofstream f(dir/"OBMHPROF.INI");f<<"[OpenBMH]\nprofile=classic-plus-1\n";}
check(bmh::load_data_profile(dir).counts.n66==4104,"Profile marker not recognized");
{std::ofstream f(dir/"OBMHPROF.INI");f<<"[OpenBMH]\nprofile=unknown\n";}
rejected=false;try{bmh::load_data_profile(dir);}catch(const bmh::FormatError&){rejected=true;}
std::filesystem::remove_all(dir);check(rejected,"Unknown profile silently became Classic");
std::cout<<"Classic and expanded profile dimensions, discovery and limits passed\n";return 0;
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}