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

+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