Read the original edition calendar for gameplay, desktop and saves (by Codex)
Prepare verified release / draft (push) Canceled after 0s

This commit is contained in:
Codex committed 2026-10-30 18:02:52 +01:00
1 parent f0ef79a119
commit d43d09a378
16 files changed
+130 -11

No files matched your search

+2
View File
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/badge_policy.hpp"
#include "game/calendar.hpp"
#include "formats/executable_layout.hpp"
#include "app/career_session.hpp"
@@ -544,6 +545,7 @@ static void install_league_sizes(const LeImage& exe) {
install_career_rules(exe);
install_environment_rules(exe);
install_original_badge_policy(exe);
install_calendar_rules(exe);
}
CareerSession::CareerSession(const std::filesystem::path& data, uint32_t watcom_seed)
+2
View File
@@ -1986,3 +1986,5 @@ inline constexpr auto EnvironmentVerifiedHookEnd = 0x7b020;
}
namespace bmh::layout { inline constexpr auto ForeignBadgeGateInstruction = 0x10070; }
namespace bmh::layout { inline constexpr auto CalendarDateSetup = 0x21270; }
+23
View File
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "game/calendar.hpp"
#include "formats/executable_layout.hpp"
#include "formats/le.hpp"
namespace bmh {
namespace { CalendarEpoch installed_epoch{2026, 2}; }
CalendarEpoch calendar_epoch_from_executable(const LeImage& exe) {
constexpr auto setup = layout::CalendarDateSetup;
constexpr uint8_t weekday_prefix[] = {0xc6,0x44,0x24,0x04};
constexpr uint8_t month_and_year_prefix[] = {0xc6,0x44,0x24,0x0c,0x07,0xc7,0x04,0x24};
if (!exe.contains(setup) || !exe.contains(setup + 16))
throw FormatError("calendar: missing original date setup");
for (uint32_t i=0;i<sizeof weekday_prefix;++i)
if(exe.u8(setup+i)!=weekday_prefix[i])throw FormatError("calendar: unverified weekday setup");
for (uint32_t i=0;i<sizeof month_and_year_prefix;++i)
if(exe.u8(setup+5+i)!=month_and_year_prefix[i])throw FormatError("calendar: unverified year setup");
const auto year=exe.u32(setup+13);const int weekday=exe.u8(setup+4);
if(year<1600||year>9999||weekday>6)throw FormatError("calendar: invalid original epoch");
return {int(year),weekday};
}
void install_calendar_rules(const LeImage& exe) { installed_epoch=calendar_epoch_from_executable(exe); }
CalendarEpoch calendar_epoch() { return installed_epoch; }
}
+11
View File
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
namespace bmh {
class LeImage;
struct CalendarEpoch { int year; int weekday; };
// Read verified original date-setup operands; unknown routines are rejected.
CalendarEpoch calendar_epoch_from_executable(const LeImage& exe);
void install_calendar_rules(const LeImage& exe);
// Isolated authored states default to the established synthetic calendar.
CalendarEpoch calendar_epoch();
}
+3 -2
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/executable_layout.hpp"
#include "game/save.hpp"
#include "game/calendar.hpp"
#include <cstdio>
#include <cstring>
@@ -25,7 +26,7 @@ void put32(Bytes& d, size_t at, uint32_t x) {
for (int i = 0; i < 4 && at + size_t(i) < d.size(); i++) d[at + size_t(i)] = uint8_t(x >> (8 * i));
}
// DeskDate2(date, buffer, 0): "TT.MM.JJJJ" of a day counter (day 0 = 1 July 2026; a
// DeskDate2(date, buffer, 0): "TT.MM.JJJJ" of a day counter (day 0 = 1 July of the supplied edition; a
// four-year leap cycle that starts with the third 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};
@@ -45,7 +46,7 @@ std::string date_text(uint32_t counter) {
if (++month == 13) month = 1, ++years;
}
char buf[16];
std::snprintf(buf, sizeof buf, "%02d.%02d.%04d", day, month, 2026 + years);
std::snprintf(buf, sizeof buf, "%02d.%02d.%04d", day, month, calendar_epoch().year + years);
return buf;
}
+2 -3
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/executable_layout.hpp"
#include "game/week.hpp"
#include "game/calendar.hpp"
#include "game/matchday.hpp"
#include "game/lineup.hpp"
@@ -93,9 +94,7 @@ int attribute(Player& p, int area, bool write, int delta, int max) {
} // namespace
int weekday_code(uint32_t date) {
int c = int(date % 7) + 2;
if (c > 6) c = int(date % 7) - 5;
return c;
return int((date % 7 + uint32_t(calendar_epoch().weekday)) % 7);
}
void familiarity_decay(GameState& g, GameRandom& game, WatcomRandom& rand) {
+7 -2
View File
@@ -2,6 +2,7 @@
#include "formats/badge_policy.hpp"
#include "formats/executable_layout.hpp"
#include "ui/desk_state.hpp"
#include "game/calendar.hpp"
#include <algorithm>
#include <set>
@@ -462,7 +463,11 @@ void validate_desk_state(const DeskState& d) {
DeskDate desk_date(uint32_t counter, const LeImage& exe) {
if (counter == 0xffff || counter > 3000000) throw FormatError("desk: unsupported date counter");
DeskDate d; d.weekday = int((counter + 2) % 7);
// Partial data-only images use the explicitly installed calendar. Full
// executable images must supply their verified original date setup.
const auto epoch = exe.contains(layout::CalendarDateSetup)
? calendar_epoch_from_executable(exe) : calendar_epoch();
DeskDate d; d.weekday = int((counter + uint32_t(epoch.weekday)) % 7);
int cycle = 3, years = 0;
while (counter > uint32_t(364 + (cycle == 4))) {
if (cycle == 4) { cycle = 0; --counter; }
@@ -479,7 +484,7 @@ DeskDate desk_date(uint32_t counter, const LeImage& exe) {
d.day -= month_days();
if (++d.month == 13) { d.month = 1; ++years; }
}
d.year = 2026 + years;
d.year = epoch.year + years;
return d;
}
+1 -1
View File
@@ -113,7 +113,7 @@ struct DeskState {
uint64_t revision = 0;
};
// Original DeskDate2, including its four-year leap cycle and Wednesday epoch.
// Original DeskDate2, including its four-year leap cycle and edition-specific epoch.
DeskDate desk_date(uint32_t day_counter, const LeImage& executable);
DeskState desk_from_save(const SaveState&, const LeImage&, uint64_t revision = 0);
// Uses authoritative typed fields where StaticMemory contains stale copies.
+8 -2
View File
@@ -601,11 +601,17 @@ int main(int argc, char** argv) {
const std::filesystem::path data = argv[1]; const auto exe = bmh::test::load_executable(asset_path(data,"BMH.exe"));
paired_selection_matrix(exe);
if(argc>3)paired_saved_projection(argv[3],exe);
// Gregorian dates are an independent oracle for the original's observed year range.
// The date arithmetic is checked against a controlled epoch aligned with
// the original leap cycle, independently of the installation's start year.
auto oracle_exe = exe;
const uint8_t oracle_year[] = {0xea,0x07,0,0};
const uint8_t oracle_weekday = 2;
oracle_exe.patch(layout::CalendarDateSetup+13,oracle_year,4);
oracle_exe.patch(layout::CalendarDateSetup+4,&oracle_weekday,1);
using namespace std::chrono;
const sys_days epoch = year{2026}/7/1;
for (uint32_t i = 0; i < 1461; ++i) {
const auto d = desk_date(i,exe); const year_month_day oracle(epoch + days{i});
const auto d = desk_date(i,oracle_exe); const year_month_day oracle(epoch + days{i});
check(d.year == int(oracle.year()) && d.month == int(unsigned(oracle.month())) &&
d.day == int(unsigned(oracle.day())),"calendar/leap boundary mismatch");
}