Restore direct-installation Classic baseline for OpenBMH 1.0 (by Codex)
This commit is contained in:
1 parent
c8f04d0099
commit
c3704878d6
255 files changed
+311
-21131
No files matched your search
+1
-29
@@ -1,8 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/highscore.hpp"
|
||||
#include "formats/native_state.hpp"
|
||||
#include "formats/native_file.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <bit>
|
||||
@@ -188,25 +186,11 @@ HighscoreTable decode_highscore_table(const HighscoreBytes& bytes) {
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
std::filesystem::path highscore_file(const std::filesystem::path &base, uint16_t signature,
|
||||
const std::string &prefix, bool native) {
|
||||
std::filesystem::path highscore_file(const std::filesystem::path& base, uint16_t signature, const std::string& prefix) {
|
||||
if (!signature) throw std::invalid_argument("highscore: signature0 has no ranked file");
|
||||
if (native)
|
||||
return base / ("highscore-" + std::to_string(signature) + ".obscore");
|
||||
return base / (prefix + std::to_string(signature));
|
||||
}
|
||||
HighscoreTable load_highscore_table(const std::filesystem::path& file) {
|
||||
if (file.extension() == ".obscore") {
|
||||
const auto data = read_file(file);
|
||||
const auto j = cli::parse_json(std::string(data.begin(), data.end()));
|
||||
if (!j.object() || !j.object()->contains("schema") || !j.object()->at("schema").string() ||
|
||||
*j.object()->at("schema").string() != "classic-highscore@1.0" || !j.object()->contains("payload"))
|
||||
throw FormatError("Invalid native highscore");
|
||||
const auto raw = decode_native_bytes(j.object()->at("payload"), 360);
|
||||
HighscoreBytes bytes;
|
||||
std::copy(raw.begin(), raw.end(), bytes.begin());
|
||||
return decode_highscore_table(bytes);
|
||||
}
|
||||
std::ifstream in(file, std::ios::binary);
|
||||
if (!in) {
|
||||
HighscoreTable empty{};
|
||||
@@ -219,18 +203,6 @@ HighscoreTable load_highscore_table(const std::filesystem::path& file) {
|
||||
}
|
||||
bool save_highscore_table(const std::filesystem::path& file, const HighscoreTable& rows) {
|
||||
const auto bytes = encode_highscore_table(rows);
|
||||
if (file.extension() == ".obscore") {
|
||||
try {
|
||||
content::write_atomic(file,
|
||||
cli::dump_json(cli::Json::Object{
|
||||
{"schema", "classic-highscore@1.0"},
|
||||
{"payload", encode_native_bytes(Bytes(bytes.begin(), bytes.end()))}}),
|
||||
true);
|
||||
return true;
|
||||
} catch (const std::exception &) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
std::ofstream out(file, std::ios::binary | std::ios::trunc);
|
||||
if (!out) return false;
|
||||
out.write(reinterpret_cast<const char*>(bytes.data()), bytes.size());
|
||||
|
||||
@@ -53,8 +53,8 @@ HighscoreProjection make_highscore_projection(const GameState& g, HighscoreTable
|
||||
HighscoreBytes encode_highscore_table(const HighscoreTable& rows);
|
||||
HighscoreTable decode_highscore_table(const HighscoreBytes& bytes);
|
||||
// The caller supplies the configured installation base and Original TEXTD889 prefix.
|
||||
std::filesystem::path highscore_file(const std::filesystem::path &base, uint16_t signature,
|
||||
const std::string &prefix = "high/h.", bool native = false);
|
||||
std::filesystem::path highscore_file(const std::filesystem::path& base,
|
||||
uint16_t signature, const std::string& prefix = "high/h.");
|
||||
HighscoreTable load_highscore_table(const std::filesystem::path& file);
|
||||
bool save_highscore_table(const std::filesystem::path& file, const HighscoreTable& rows);
|
||||
|
||||
|
||||
@@ -70,13 +70,6 @@ public:
|
||||
}
|
||||
void set_pointer(uint32_t a, uint32_t address) { set32(a, address == 0 ? 0 : address + kGuestDataBase); }
|
||||
|
||||
const std::map<uint32_t, Bytes> &blocks() const { return blocks_; }
|
||||
static StaticMemory from_blocks(std::map<uint32_t, Bytes> blocks) {
|
||||
StaticMemory memory;
|
||||
memory.blocks_ = std::move(blocks);
|
||||
return memory;
|
||||
}
|
||||
|
||||
private:
|
||||
static std::string hex(uint32_t v) {
|
||||
char b[16];
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/messages.hpp"
|
||||
#include "game/schedule.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
@@ -151,13 +150,4 @@ std::string format_number(const GameState& g, int32_t value, int flags) {
|
||||
|
||||
std::string format_amount(const GameState& g, int32_t value) { return format_number(g, value, 0x101); }
|
||||
|
||||
void install_message_texts(const LeImage& exe) {
|
||||
kContractEndsSoonText = exe.cstring(kEnglishCompetitions ? ::bmh::layout::EnglishContractExpiryWarningText : ::bmh::layout::ContractExpiryWarningText);
|
||||
kMastersQualificationText = kEnglishCompetitions ? "Masters entry confirmed. Your participation bonus has been credited." : exe.cstring(::bmh::layout::MastersQualificationText);
|
||||
kMastersWinnerText = kEnglishCompetitions ? "Masters title won. Your prize money has been credited." : exe.cstring(::bmh::layout::MastersWinnerText);
|
||||
kIndoorInvitationText = kEnglishCompetitions ? "Indoor event entry bonus credited for " : exe.cstring(::bmh::layout::IndoorInvitationText);
|
||||
kChampionshipBonusText = kEnglishCompetitions ? "League title bonus credited." : exe.cstring(::bmh::layout::ChampionshipBonusText);
|
||||
kFriendlyPayerPrefixText = kEnglishCompetitions ? "Your share: " : exe.cstring(::bmh::layout::NationalFriendlyPayerPrefixText);
|
||||
}
|
||||
|
||||
} // namespace bmh
|
||||
@@ -16,7 +16,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "formats/le.hpp"
|
||||
#include "game/state.hpp"
|
||||
|
||||
namespace bmh {
|
||||
@@ -60,11 +59,6 @@ inline std::string kIndoorInvitationText;
|
||||
inline std::string kChampionshipBonusText;
|
||||
inline std::string kFriendlyPayerPrefixText;
|
||||
|
||||
// Installs the six texts above from the game image (the English game uses its own wording).
|
||||
// Both career sessions call it at start; standalone engine tools (week_check, the season sims)
|
||||
// must call it too, or these messages lose their text (#14: the indoor entry bonus mail).
|
||||
void install_message_texts(const LeImage& exe);
|
||||
|
||||
// FormatNumber(buf, value, 0x101, ""): an amount of money as the messages show it: the
|
||||
// value converted with CurrencyMultiplier / CurrencyDivisor, digits grouped by dots, then " EU".
|
||||
std::string format_amount(const GameState& g, int32_t value);
|
||||
|
||||
@@ -20,10 +20,6 @@ public:
|
||||
void srand(uint32_t seed) { seed_ = seed; }
|
||||
uint32_t seed() const { return seed_; }
|
||||
uint64_t calls() const { return calls_; }
|
||||
void restore(uint32_t seed, uint64_t calls) {
|
||||
seed_ = seed;
|
||||
calls_ = calls;
|
||||
}
|
||||
int rand() {
|
||||
calls_++;
|
||||
if (draw_hook) draw_hook(1);
|
||||
@@ -51,10 +47,6 @@ public:
|
||||
int32_t seed() const { return seed_; }
|
||||
void set_seed(int32_t seed) { seed_ = seed; }
|
||||
uint64_t calls() const { return calls_; }
|
||||
void restore(int32_t seed, uint64_t calls) {
|
||||
seed_ = seed;
|
||||
calls_ = calls;
|
||||
}
|
||||
int32_t range(int32_t lo, int32_t hi) {
|
||||
calls_++;
|
||||
if (draw_hook) draw_hook(0);
|
||||
|
||||
@@ -166,60 +166,3 @@ std::pair<int,int> RealityGrid::position(int figure) const {
|
||||
}
|
||||
|
||||
} // namespace bmh
|
||||
|
||||
namespace bmh {
|
||||
cli::Json RealityGrid::checkpoint() const {
|
||||
cli::Json::Array planes, positions;
|
||||
for (const auto &plane : occupied_) {
|
||||
cli::Json::Array cells;
|
||||
for (auto b : plane)
|
||||
cells.emplace_back(int(b));
|
||||
planes.emplace_back(std::move(cells));
|
||||
}
|
||||
for (const auto &[x, y] : positions_)
|
||||
positions.emplace_back(cli::Json::Array{x, y});
|
||||
return cli::Json::Object{
|
||||
{"planes", std::move(planes)},
|
||||
{"positions", std::move(positions)},
|
||||
{"ball", cli::Json::Array{ball_.first, ball_.second}},
|
||||
{"previous_ball", cli::Json::Array{previous_ball_.first, previous_ball_.second}}};
|
||||
}
|
||||
void RealityGrid::restore_checkpoint(const cli::Json &value) {
|
||||
const auto field = [&](const char *name) -> const cli::Json & {
|
||||
if (!value.object() || !value.object()->contains(name))
|
||||
throw FormatError("native Reality grid field missing");
|
||||
return value.object()->at(name);
|
||||
};
|
||||
const auto array = [](const cli::Json &j, size_t size) -> const cli::Json::Array & {
|
||||
if (!j.array() || j.array()->size() != size)
|
||||
throw FormatError("invalid native Reality grid dimensions");
|
||||
return *j.array();
|
||||
};
|
||||
const auto integer = [](const cli::Json &j) -> int {
|
||||
if (!j.integer() || *j.integer() < INT32_MIN || *j.integer() > INT32_MAX)
|
||||
throw FormatError("invalid native Reality coordinate");
|
||||
return int(*j.integer());
|
||||
};
|
||||
RealityGrid restored;
|
||||
const auto &planes = array(field("planes"), 2);
|
||||
for (size_t p = 0; p < 2; ++p) {
|
||||
const auto &cells = array(planes[p], 0x478);
|
||||
for (size_t i = 0; i < cells.size(); ++i) {
|
||||
const int n = integer(cells[i]);
|
||||
if (n < 0 || n > 255)
|
||||
throw FormatError("invalid native Reality cell");
|
||||
restored.occupied_[p][i] = uint8_t(n);
|
||||
}
|
||||
}
|
||||
const auto pair = [&](const cli::Json &j) {
|
||||
const auto &xy = array(j, 2);
|
||||
return std::pair<int, int>{integer(xy[0]), integer(xy[1])};
|
||||
};
|
||||
const auto &positions = array(field("positions"), 24);
|
||||
for (size_t i = 0; i < 24; ++i)
|
||||
restored.positions_[i] = pair(positions[i]);
|
||||
restored.ball_ = pair(field("ball"));
|
||||
restored.previous_ball_ = pair(field("previous_ball"));
|
||||
*this = std::move(restored);
|
||||
}
|
||||
} // namespace bmh
|
||||
@@ -6,7 +6,6 @@
|
||||
#include <utility>
|
||||
|
||||
#include "formats/le.hpp"
|
||||
#include "cli/json.hpp"
|
||||
|
||||
namespace bmh {
|
||||
|
||||
@@ -60,17 +59,15 @@ RealityPath reality_goal_path(int x, int y, int goal_x);
|
||||
// either player plane. This is runtime scene state, not a Native save extension.
|
||||
class RealityGrid {
|
||||
public:
|
||||
cli::Json checkpoint() const;
|
||||
void restore_checkpoint(const cli::Json &);
|
||||
bool place(int figure, int x, int y, int side);
|
||||
void clear(int x, int y, int side); // caller clears old occupancy before a move
|
||||
void reset_occupancy(); // Source initialization preserves old figure/ball data
|
||||
bool operator==(const RealityGrid &) const = default;
|
||||
void stage_position(int figure, int x, int y); // afb0c/afb23 before occupancy is committed
|
||||
uint8_t occupant(int x, int y, int side) const;
|
||||
std::pair<int, int> position(int figure) const;
|
||||
std::pair<int, int> ball() const { return ball_; }
|
||||
std::pair<int, int> previous_ball() const { return previous_ball_; }
|
||||
bool place(int figure, int x, int y, int side);
|
||||
void clear(int x, int y, int side); // caller clears old occupancy before a move
|
||||
void reset_occupancy(); // Source initialization preserves old figure/ball data
|
||||
bool operator==(const RealityGrid&) const = default;
|
||||
void stage_position(int figure, int x, int y); // afb0c/afb23 before occupancy is committed
|
||||
uint8_t occupant(int x, int y, int side) const;
|
||||
std::pair<int, int> position(int figure) const;
|
||||
std::pair<int, int> ball() const { return ball_; }
|
||||
std::pair<int, int> previous_ball() const { return previous_ball_; }
|
||||
private:
|
||||
std::array<std::array<uint8_t, 0x478>, 2> occupied_{};
|
||||
std::array<std::pair<int, int>, 24> positions_{};
|
||||
|
||||
@@ -228,22 +228,15 @@ bool undo_reschedule(GameState& g, int manager, int day) {
|
||||
if (std::none_of(moved.begin(), moved.end(), [&](const LeagueMatchRef& m) { return m.day == day; })) return false;
|
||||
const int team = manager_team(g, manager);
|
||||
// UndoReschedule(day, 1, team): every replay of the club on that day, whatever its league
|
||||
int kept = 0; // local_18: the replays of other clubs that stay on the day
|
||||
for (int e = 0; e < kPostponedEntries; e++) {
|
||||
const uint32_t at = kPostponed + uint32_t(e) * 6;
|
||||
if (g.memory.u16(at) != uint16_t(day)) continue;
|
||||
const int league = g.memory.u8(at + 3), round = g.memory.u8(at + 2), m = g.memory.u8(at + 4);
|
||||
const Fixture f = round_fixtures(league, round).at(size_t(m));
|
||||
if (f.home != team && f.away != team) { ++kept; continue; }
|
||||
if (f.home != team && f.away != team) continue;
|
||||
g.results.at(result_at(league, round, m)) = kNotPlayed;
|
||||
g.memory.set16(at, 0);
|
||||
}
|
||||
// with no replay left the day loses its replay bit 0x4000 again (calendar high byte & 0xbf),
|
||||
// so it can be a target once more
|
||||
if (kept == 0) {
|
||||
const uint32_t high = kCalendar + uint32_t(day) * 2 + 1;
|
||||
g.memory.set8(high, uint8_t(g.memory.u8(high) & 0xbf));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
// matchday the 0xCE turns into 0xCD (matchday_setup) and the match is played on the
|
||||
// new day like a winter postponement.
|
||||
// 4. A click on the new day of a moved match takes the move back (UndoReschedule(day, 1,
|
||||
// team)): the entry is freed and the result byte is 0xCC again. When no replay of another
|
||||
// club stays on that day, the day loses bit 0x4000 again and can be a target once more.
|
||||
// team)): the entry is freed and the result byte is 0xCC again. The calendar keeps bit
|
||||
// 0x4000, as in the original.
|
||||
//
|
||||
// Everything here works on the saved GameState only: no random numbers are drawn, so a
|
||||
// rescheduled career stays deterministic.
|
||||
|
||||
+3
-3
@@ -27,7 +27,7 @@ void put32(Bytes& d, size_t at, uint32_t x) {
|
||||
|
||||
// DeskDate2(date, buffer, 0): "TT.MM.JJJJ" of a day counter (day 0 = 1 July 2026; a
|
||||
// four-year leap cycle that starts with the third year).
|
||||
std::string date_text(uint32_t counter, int start_year) {
|
||||
std::string date_text(uint32_t counter) {
|
||||
static const int kDays[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
int cycle = 3, years = 0, month = 7;
|
||||
while (counter > uint32_t(364 + (cycle == 4))) {
|
||||
@@ -45,7 +45,7 @@ std::string date_text(uint32_t counter, int start_year) {
|
||||
if (++month == 13) month = 1, ++years;
|
||||
}
|
||||
char buf[16];
|
||||
std::snprintf(buf, sizeof buf, "%02d.%02d.%04d", day, month, start_year + years);
|
||||
std::snprintf(buf, sizeof buf, "%02d.%02d.%04d", day, month, 2026 + years);
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ Bytes save_header(const GameState& g) {
|
||||
const int managers = g.memory.u8(::bmh::layout::ManagerCount);
|
||||
Bytes h;
|
||||
h.push_back(uint8_t(managers));
|
||||
const std::string date = date_text(g.date, g.display_start_year);
|
||||
const std::string date = date_text(g.date);
|
||||
for (size_t i = 0; i < 11; i++) h.push_back(i < date.size() ? uint8_t(date[i]) : 0);
|
||||
Bytes list(0xa0, 0);
|
||||
for (int m = 0; m < managers && m < 4; m++) {
|
||||
|
||||
@@ -174,7 +174,6 @@ struct GameState {
|
||||
// 3 (stadiums, *ba360): not used by the engine, kept for writing savegames.
|
||||
std::vector<uint8_t> master_database_metadata, referee_names, stadium_names;
|
||||
std::vector<uint16_t> player_cards; // *PlayerCards, per player: card counters per competition
|
||||
int display_start_year = 2026; // Cosmetic Classic origin; does not alter scheduling.
|
||||
uint32_t date = 0; // CalendarDay: day counter
|
||||
// DaysIntoSeason (day of the season, the calendar index) moves with the day counter within
|
||||
// a season: season_day() = date - season_start.
|
||||
|
||||
Reference in new issue
Block a user