diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e102c3..a0bd001 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/docs/poc-1.1/STATUS.md b/docs/poc-1.1/STATUS.md new file mode 100644 index 0000000..232b0d5 --- /dev/null +++ b/docs/poc-1.1/STATUS.md @@ -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. diff --git a/src/formats/data_profile.cpp b/src/formats/data_profile.cpp new file mode 100644 index 0000000..6779e2a --- /dev/null +++ b/src/formats/data_profile.cpp @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-3.0-only +#include "formats/data_profile.hpp" +#include +#include +#include +#include +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; +} +} diff --git a/src/formats/data_profile.hpp b/src/formats/data_profile.hpp new file mode 100644 index 0000000..59414eb --- /dev/null +++ b/src/formats/data_profile.hpp @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-3.0-only +#pragma once +#include +#include +#include +#include "formats/m3d.hpp" +namespace bmh { +// Installation metadata; original files retain their implicit Classic profile. +struct DataProfile { + std::string id = "classic"; + std::array 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); +} diff --git a/src/formats/m3d.cpp b/src/formats/m3d.cpp index 402150a..49e53db 100644 --- a/src/formats/m3d.cpp +++ b/src/formats/m3d.cpp @@ -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"); diff --git a/src/formats/m3d.hpp b/src/formats/m3d.hpp index 3e59423..f3a72cf 100644 --- a/src/formats/m3d.hpp +++ b/src/formats/m3d.hpp @@ -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 club_names; std::vector referees; std::vector stadiums; diff --git a/src/formats/savestate.cpp b/src/formats/savestate.cpp index 47a0c61..43c2f37 100644 --- a/src/formats/savestate.cpp +++ b/src/formats/savestate.cpp @@ -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 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 out; size_t pos = 0; for (const BlockDef& d : kBlocks) { diff --git a/src/game/career.cpp b/src/game/career.cpp index 00f622d..821368d 100644 --- a/src/game/career.cpp +++ b/src/game/career.cpp @@ -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 layout = save_layout(counts, true); Bytes stream; for (const SaveBlock& b : layout) { diff --git a/src/game/save.cpp b/src/game/save.cpp index cd27944..bb88d41 100644 --- a/src/game/save.cpp +++ b/src/game/save.cpp @@ -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) { diff --git a/src/game/state.cpp b/src/game/state.cpp index 7e12be8..c102de5 100644 --- a/src/game/state.cpp +++ b/src/game/state.cpp @@ -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)); diff --git a/src/game/state.hpp b/src/game/state.hpp index 6369a41..a5a3423 100644 --- a/src/game/state.hpp +++ b/src/game/state.hpp @@ -36,6 +36,7 @@ constexpr uint16_t kEmptySlot = 0x0FFF; constexpr uint16_t kSlotInLineup = 0x8000; struct GameState { + DbCounts counts{}; std::vector squad_slots; // *SquadSlots, all squads back to back (see squad_range) std::vector players; // *PlayerConditionTechniqueForm / *PlayerSkillWords / *PlayerIdentityWords, names not filled std::vector team_morale; // *TeamMorale, per team: bits 0-5 morale / 2, bits 6-7 flags diff --git a/tests/data_profile_tests.cpp b/tests/data_profile_tests.cpp new file mode 100644 index 0000000..c9b73be --- /dev/null +++ b/tests/data_profile_tests.cpp @@ -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 +#include +#include +#include +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<