Bind original settings and automation to atomic native drafts (by Codex)

This commit is contained in:
Codex committed 2026-10-29 18:52:41 +01:00
1 parent 2ce563a4b9
commit 98cff2185d
23 files changed
+959 -189

No files matched your search

+75 -152
View File
@@ -4643,6 +4643,8 @@ bool ModernSession::acknowledge_mailbox_close(const ui::MailboxCloseRequest& req
return true;
}
#include "modern/app/settings_write.inc"
bool ModernSession::dispatch_settings(const ui::SettingsWriteRequest& request, uint64_t& revision,
std::string& error) {
if ((live_settings_owner_ && !live_settings_dispatch_active_) ||
@@ -4652,159 +4654,11 @@ bool ModernSession::dispatch_settings(const ui::SettingsWriteRequest& request, u
}
if (balance_draft_ || balance_dispatch_active_ || strengths_owner_ || strengths_dispatch_active_ ||
top_scorers_owner_ || top_scorers_dispatch_active_ || stadium_.block_expansion || other_games_owner_ || other_games_dispatch_active_) { error = "strengths_active"; return false; }
auto& mem = g_.memory;
if (request.manager_slot < 0 || request.manager_slot > 3 ||
size_t(request.manager_slot) >= g_.manager_teams.size() || !mem.has(::bmh::layout::ActiveManager) ||
int(mem.u8(::bmh::layout::ActiveManager)) != request.manager_slot || request.revision != revision ||
revision == std::numeric_limits<uint64_t>::max()) {
error = "Diese Einstellungsaktion gehört zu einem veralteten Manager oder Stand.";
return false;
}
if (request.row >= 20 || request.column >= 9 || !mem.has(::bmh::layout::LeaguePresentationOptions + 179) ||
!mem.has(::bmh::layout::GameMode) || !mem.has(::bmh::layout::CompetitionSelection)) {
error = "Der Einstellungszustand ist unvollständig.";
return false;
}
std::array<uint8_t, 180> raw{};
for (size_t i = 0; i < raw.size(); ++i) {
const uint32_t address = ::bmh::layout::LeaguePresentationOptions + uint32_t(i);
if (!mem.has(address)) { error = "Der Einstellungszustand ist unvollständig."; return false; }
raw[i] = mem.u8(address);
}
if (raw != request.expected_raw) {
error = "Die Einstellungen wurden inzwischen geändert.";
return false;
}
const size_t index = size_t(request.row) * 9 + request.column;
const uint32_t address = ::bmh::layout::LeaguePresentationOptions + uint32_t(index);
ui::SettingsAvailabilityInputs inputs{mem.u8(::bmh::layout::GameMode), mem.u32(::bmh::layout::CompetitionSelection),
uint8_t(sound_capabilities_ && !sound_capabilities_->music),
uint8_t(sound_capabilities_ && !sound_capabilities_->effects)};
auto availability = ui::project_settings_availability(raw, inputs, exe_);
// The host supplies the portable sound driver's capabilities. Headless
// callers without that provider retain the unknown Source latch boundary.
if (!sound_capabilities_) { availability[5] = raw[5]; availability[6] = raw[6]; }
const bool sound_cell = request.row == 0 && (request.column == 5 || request.column == 6);
if (sound_cell && !sound_capabilities_) {
error = "Diese Einstellung ist noch nicht verfügbar.";
return false;
}
const bool scoped_settings = (live_settings_owner_.has_value() && live_settings_dispatch_active_) ||
const bool scoped = (live_settings_owner_.has_value() && live_settings_dispatch_active_) ||
(desk_settings_owner_.has_value() && desk_settings_dispatch_active_);
if (((request.row == 8 && request.column == 7) && !scoped_settings) ||
(request.column == 7 && request.row >= 14 && request.row <= 19)) {
error = "Diese Einstellung ist noch nicht verfügbar.";
return false;
}
if ((request.operation != ui::SettingsEdit::toggle_binary &&
request.operation != ui::SettingsEdit::decrement && request.operation != ui::SettingsEdit::increment) ||
(request.column < 7 && request.operation != ui::SettingsEdit::toggle_binary) ||
(request.column >= 7 && request.operation == ui::SettingsEdit::toggle_binary)) {
error = "Die Aktion passt nicht zum Einstellungsfeld.";
return false;
}
const uint8_t shown = availability[index];
const uint8_t raw_value = sound_cell && sound_capabilities_ ? uint8_t(raw[index] & 0x7f) : raw[index];
if (request.column < 7 && ((shown & 0x80) || raw_value >= 2)) {
error = "Dieses Einstellungsfeld ist im aktuellen Modus gesperrt.";
return false;
}
const uint8_t old = raw_value;
uint8_t next = old;
if (request.operation == ui::SettingsEdit::toggle_binary) {
// Inventory of actual current consumers: direct match-engine buttons,
// matchday/season flags and the live-scene switch. Other cells are not
// made writable merely because the Original UI displayed a cell.
// Tie the write whitelist to the concrete consumer ranges. League
// remapping reads rows 0..4, columns 0..3; matchday display kinds 1/2
// map to columns 0..2 and rows 0..4 or 17..19.
const bool consumed = (sound_cell && sound_capabilities_.has_value()) ||
(request.row == 0 && request.column == 4) || // A5: match/Sportschau sound
((request.row <= 4 && request.column <= 3) ||
((request.row <= 4 || request.row >= 17) && request.column <= 2)) ||
((request.row == 5 || (request.row >= 9 && request.row <= 12)) && request.column == 0) ||
(request.row == 1 && request.column == 4) || // B5 live-scene option
(request.row == 2 && request.column == 4) || // C5: Reality player numbers (RealityMatch_FormatError_ExecutableField)
(request.row == 5 && request.column == 5) || // F6: Source manager-match desk gate (MatchdaySetup_MatchdayNeedsManagerDesks_RuntimeField)
(request.row == 6 && request.column == 5) || // G6: transfer confirmation wait (OutcomeDelayDisabled)
(request.row == 16 && request.column == 6) || // Q7: own-club Sportschau preference (MatchdaySetup_ConsiderSportschauFixture_RuntimeField)
(request.row == 13 && request.column == 6) || // N7: Source kickoff competition list (SportschauAwards_MatchdayIntroView_RuntimeField)
(request.row == 1 && request.column == 6) || // B7: SportschauIntro intro gate (Controller_FormatError_RuntimeField)
(request.row == 2 && request.column == 6) || // C7: SportschauIntro intro-animation gate (Controller_FormatError_RuntimeField2)
(request.row == 3 && request.column == 6) || // D7: selected report progression (ReplayProgressionMode)
(request.row == 4 && request.column == 6) || // E7: Source-owned Sportschau scenes (ReplayChanceMode)
(request.row == 5 && request.column == 6) || // F7: SportschauIntro fixture-report gate (Controller_FormatError_RuntimeField3)
(request.row == 6 && request.column == 6) || // G7: MatchdayIntro player/award rating (SportschauAwards_FinishSportschauAwards_RuntimeField)
(request.row == 7 && request.column == 6) || // H7: SportschauTeamInfo competition totals (SportschauAwards_SportschauTeamInfoView_RuntimeField)
(request.row == 2 && request.column == 5) || // C6 drawer-handle behavior (CareerSession_DispatchDesktopLayout_RuntimeField)
(request.row == 3 && request.column == 5) || // D6 native desktop drag raster (CareerSession_DispatchDesktopLayout_RuntimeField2)
(request.row == 4 && request.column == 5) || // E6 always-visible shortcut bar (DeskState_FormatError_RuntimeField3)
(request.row == 7 && request.column == 5) || // H6 transfer option
(request.row == 8 && (request.column == 5 || request.column == 6)) || // I6/I7
(request.row >= 10 && request.row <= 13 && request.column == 4) || // K5:N5 match buttons
(request.row >= 10 && request.row <= 12 && request.column == 6) || // K7:M7 presentation
(request.row == 9 && request.column == 6) || // J7 season-entrant visibility (SeasonEntrants_SeasonEntrantsFromGame_TextPointer)
(request.row == 15 && request.column == 4) || // P5
(request.row == 16 && request.column == 4) || // Q5
(request.row == 17 && request.column == 4); // R5: secondary leagues (CalendarState_FormatError_RuntimeField2)
if (!consumed || (old != 0 && old != 1)) {
error = "Diese Einstellung ist noch nicht verfügbar.";
return false;
}
if (request.row == 16 && request.column == 4 &&
g_.season_day() >= 110 && g_.season_day() <= 230) {
error = ui::original_to_utf8(message_text(g_, ::bmh::layout::CareerSession_DispatchSettings_TextPointer));
return false;
}
// SettingsSourceRefusal only permits re-enabling R5 while CareerSessionRuntimeField4 is zero.
// LeagueRoundCounters is the saved league_rounds block; CareerSessionRuntimeField4 is its sixth byte.
// Turning the leagues off remains possible after they have started.
if (request.row == 17 && request.column == 4 && old != 0 &&
(g_.league_rounds.size() <= 5 || g_.league_rounds[5] != 0)) {
error = ui::original_to_utf8(message_text(g_, ::bmh::layout::CareerSession_DispatchSettings_TextPointer2));
return false;
}
next = old ^ 1;
} else {
// Column8: existing presentation speeds B8:F8, H8 process budget,
// J8 postponed limit and K8 autosave. Column9 only exposes values
// already read by Main's Source live presenters or CupDrawScreen.
const bool consumed = (request.column == 7 &&
((request.row <= 6) || request.row == 7 || request.row == 9 || request.row == 10 ||
(scoped_settings && request.row == 8))) ||
// A9 match minutes; B9:C9 chance result; D9:E9 bookings; F9:G9 rolling ball;
// I9 cup draw; K9 Reality report; M9 preview/shootout; P9 shot.
(request.column == 8 && ((request.row >= 0 && request.row <= 6) ||
request.row == 7 || request.row == 8 || request.row == 10 || request.row == 12 || request.row == 15));
if (!consumed || old >= 200) {
error = "Diese Einstellung ist noch nicht verfügbar.";
return false;
}
if (request.column == 8) {
// SettingsSourceRefusal's ninth column is stored doubled for display. Its
// Source edit step is two raw units; decrement is enabled only
// above 1 and increment only below 0xc6 (198). Preserve odd raw
// values exactly, as the original does.
if (request.operation == ui::SettingsEdit::decrement) {
if (old <= 1) { error = "Der Zahlenwert ist bereits am Originalminimum."; return false; }
next = uint8_t(old - 2);
} else {
if (old >= 198) { error = "Der Zahlenwert ist bereits am Originalmaximum."; return false; }
next = uint8_t(old + 2);
}
} else if (request.column == 7) {
if (request.operation == ui::SettingsEdit::decrement) {
if (old == 0) { error = "Der Zahlenwert ist bereits am Originalminimum."; return false; }
next = uint8_t(old - 1);
} else {
const uint8_t limit = exe_.u8(::bmh::layout::CareerSession_DispatchSettings_RuntimeField + request.row);
if (old >= limit) { error = "Der Zahlenwert ist bereits am Originalmaximum."; return false; }
next = uint8_t(old + 1);
}
}
}
if (next == old) { error = "Die Einstellung hat sich nicht geändert."; return false; }
mem.set8(address, next);
const auto next = settings_next_value(g_, exe_, sound_capabilities_, request, revision, scoped, error);
if (!next) return false;
g_.memory.set8(::bmh::layout::LeaguePresentationOptions + uint32_t(request.row) * 9 + request.column, *next);
++revision;
return true;
}
@@ -8777,6 +8631,7 @@ std::string ui_text(const cli::Json& j, const char* key) {
}
#include "modern/app/ui_balance.inc"
#include "modern/app/ui_settings.inc"
// The original mailbox of a manager, each message with an id that stays the same while the
// mailbox shifts its entries (the entry index does not): "message:<day>-<text hash>", "-<n>"
@@ -8985,6 +8840,18 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
context.career_ended = career_complete();
const std::string kind = ui_text(request, "kind"), request_id = ui_text(request, "requestId");
const int manager = context.manager;
if (kind == "settings") {
if (manager < 0 || manager > 3 || size_t(manager) >= g_.manager_teams.size())
return modern::ui_error(request_id, "no_manager", "Kein aktiver Manager.", revision, false);
if (const auto wanted = ui_text(request, "managerId"); !wanted.empty() && wanted != modern::ui_manager_id(g_, manager))
return modern::ui_error(request_id, "manager_not_active", "Dieser Manager sitzt nicht am Schreibtisch.", revision, false);
DeskSettingIdentity identity{manager, g_.manager_teams[size_t(manager)], std::nullopt, revision};
if (identity.runtime_club >= 0 && size_t(identity.runtime_club) < g_.club_ids.size()) identity.stable_club_identity = int(g_.club_ids[size_t(identity.runtime_club)]);
std::string error;
const bool automation_available = validate_desk_setting_owner(identity, revision, error);
try { return modern::ui_snapshot(g_, context, request_id, ui_settings_data(g_, exe_, sound_capabilities_, manager, revision, automation_available)); }
catch (const std::exception &e) { return modern::ui_error(request_id, "settings_unavailable", e.what(), revision, false); }
}
if (kind == "indoor-standings") {
if (manager < 0 || manager > 3 || size_t(manager) >= g_.manager_teams.size() ||
g_.manager_teams[size_t(manager)] < 0 || g_.manager_teams[size_t(manager)] >= league_clubs())
@@ -10697,6 +10564,62 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
if (!dispatch_ticket_price(r, revision, error)) { restore(); return refuse("ticket_refused", error); }
if (revision != previous) revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision, {"stadium"}, "Eintrittspreis gesetzt.");
} else if (kind == "settings.commit") {
if (transfer_offer_editor_ || contract_quote_ || stadium_.block_expansion || desk_settings_owner_ || live_settings_owner_)
return refuse("decision_pending", "Bitte die offene Entscheidung zuerst abschließen.");
try {
const auto *edits = ui_field(*payload, "edits"), *automation = ui_field(*payload, "automation");
if ((edits && (!edits->array() || edits->array()->size() > 180)) ||
(automation && (!automation->array() || automation->array()->size() > 5)))
return refuse("invalid_payload", "Ungültige Einstellungsänderungen.");
std::set<int> seen;
if (edits) for (const auto &edit : *edits->array()) {
const auto code = ui_text(edit, "code");
const auto *value = ui_field(edit, "value");
const int index = ui_setting_index(code);
if (index < 0 || !seen.insert(index).second || !value || !value->integer() || *value->integer() < 0 || *value->integer() > 255)
throw FormatError("invalid_setting_edit");
const auto address = ::bmh::layout::LeaguePresentationOptions + uint32_t(index);
const int old = g_.memory.u8(address), column = index % 9;
if (column < 7 && ((old & 0x3f) > 1 || *value->integer() > 1)) throw FormatError("setting_not_boolean");
const int target = column < 7 ? 1 - int(*value->integer()) : int(*value->integer()) * (column == 8 ? 2 : 1) + (column == 8 ? old % 2 : 0);
if (target > 255) throw FormatError("invalid_setting_value");
if (column < 7 && (old & 0x3f) == target) continue; // No-op preserves availability flags.
for (int count = 0; g_.memory.u8(address) != target; ++count) {
if (count >= 200) throw FormatError("setting_step_limit");
ui::SettingsWriteRequest write;
write.manager_slot = manager; write.revision = revision;
write.row = uint8_t(index / 9); write.column = uint8_t(column);
for (size_t i = 0; i < write.expected_raw.size(); ++i) write.expected_raw[i] = g_.memory.u8(::bmh::layout::LeaguePresentationOptions + uint32_t(i));
write.operation = column < 7 ? ui::SettingsEdit::toggle_binary : g_.memory.u8(address) < target ? ui::SettingsEdit::increment : ui::SettingsEdit::decrement;
if (!dispatch_settings(write, revision, error)) throw FormatError(error);
}
}
seen.clear();
if (automation) for (const auto &edit : *automation->array()) {
const auto id = ui_text(edit, "id");
const int index = ui_automation_index(id);
const auto *enabled = ui_field(edit, "enabled");
if (index < 0 || !seen.insert(index).second || !enabled || !std::holds_alternative<bool>(enabled->value)) throw FormatError("invalid_automation_edit");
AutomationRequest write;
write.identity = {manager, g_.manager_teams[size_t(manager)], std::nullopt, revision};
if (write.identity.runtime_club >= 0 && size_t(write.identity.runtime_club) < g_.club_ids.size()) write.identity.stable_club_identity = int(g_.club_ids[size_t(write.identity.runtime_club)]);
write.automation = DeskAutomation(index); write.enabled = std::get<bool>(enabled->value);
if (const auto *formation = ui_field(edit, "formation")) {
if (!formation->integer() || *formation->integer() < 1 || *formation->integer() > 8) throw FormatError("invalid_formation");
write.formation = int(*formation->integer());
}
if (index == 0 && write.enabled != write.formation.has_value()) throw FormatError("formation_selection_required");
if (index != 0 && write.formation) throw FormatError("unexpected_formation");
const int current = g_.manager_options.at(size_t(manager) * 5 + size_t(index));
if (index == 0 ? current == write.formation.value_or(0) : bool(current & 1) == write.enabled) continue;
if (!dispatch_automation(write, revision, error)) throw FormatError(error);
}
const bool changed = revision != previous;
revision = changed ? previous + 1 : previous;
answer = modern::ui_command_result(request_id, previous, revision, {"settings", "desktop", "training", "lineup", "tactics"}, changed ? "Einstellungen übernommen." : "Einstellungen unverändert.");
if (!changed) std::get<cli::Json::Object>(answer.value)["outcome"] = "no_change";
} catch (const std::exception &e) { restore(); return refuse("settings_refused", e.what()); }
} else if (kind == "balance.commit") {
if (balance_active() || transfer_offer_editor_ || contract_quote_ || stadium_.block_expansion)
return refuse("decision_pending", "Bitte die offene Entscheidung zuerst abschließen.");
+252
View File
@@ -0,0 +1,252 @@
// SPDX-License-Identifier: GPL-3.0-only
// One source of truth for existing settings validation and read-only capability
// probes.
namespace {
std::optional<uint8_t>
settings_next_value(const ModernState &state, const LeImage &exe,
std::optional<ui::SettingsSoundCapabilities> sound,
const ui::SettingsWriteRequest &request, uint64_t revision,
bool scoped_settings, std::string &error) {
const auto &mem = state.memory;
if (request.manager_slot < 0 || request.manager_slot > 3 ||
size_t(request.manager_slot) >= state.manager_teams.size() ||
!mem.has(::bmh::layout::ActiveManager) ||
int(mem.u8(::bmh::layout::ActiveManager)) != request.manager_slot ||
request.revision != revision ||
revision == std::numeric_limits<uint64_t>::max()) {
error = "Diese Einstellungsaktion gehört zu einem veralteten Manager oder "
"Stand.";
return std::nullopt;
}
if (request.row >= 20 || request.column >= 9 ||
!mem.has(::bmh::layout::LeaguePresentationOptions + 179) ||
!mem.has(::bmh::layout::GameMode) ||
!mem.has(::bmh::layout::CompetitionSelection)) {
error = "Der Einstellungszustand ist unvollständig.";
return std::nullopt;
}
std::array<uint8_t, 180> raw{};
for (size_t i = 0; i < raw.size(); ++i) {
const uint32_t address =
::bmh::layout::LeaguePresentationOptions + uint32_t(i);
if (!mem.has(address)) {
error = "Der Einstellungszustand ist unvollständig.";
return std::nullopt;
}
raw[i] = mem.u8(address);
}
if (raw != request.expected_raw) {
error = "Die Einstellungen wurden inzwischen geändert.";
return std::nullopt;
}
const size_t index = size_t(request.row) * 9 + request.column;
const uint32_t address =
::bmh::layout::LeaguePresentationOptions + uint32_t(index);
ui::SettingsAvailabilityInputs inputs{
mem.u8(::bmh::layout::GameMode),
mem.u32(::bmh::layout::CompetitionSelection),
uint8_t(sound && !sound->music), uint8_t(sound && !sound->effects)};
auto availability = ui::project_settings_availability(raw, inputs, exe);
// The host supplies the portable sound driver's capabilities. Headless
// callers without that provider retain the unknown Source latch boundary.
if (!sound) {
availability[5] = raw[5];
availability[6] = raw[6];
}
const bool sound_cell =
request.row == 0 && (request.column == 5 || request.column == 6);
if (sound_cell && !sound) {
error = "Diese Einstellung ist noch nicht verfügbar.";
return std::nullopt;
}
if (((request.row == 8 && request.column == 7) && !scoped_settings) ||
(request.column == 7 && request.row >= 14 && request.row <= 19)) {
error = "Diese Einstellung ist noch nicht verfügbar.";
return std::nullopt;
}
if ((request.operation != ui::SettingsEdit::toggle_binary &&
request.operation != ui::SettingsEdit::decrement &&
request.operation != ui::SettingsEdit::increment) ||
(request.column < 7 &&
request.operation != ui::SettingsEdit::toggle_binary) ||
(request.column >= 7 &&
request.operation == ui::SettingsEdit::toggle_binary)) {
error = "Die Aktion passt nicht zum Einstellungsfeld.";
return std::nullopt;
}
const uint8_t shown = availability[index];
const uint8_t raw_value =
sound_cell && sound ? uint8_t(raw[index] & 0x7f) : raw[index];
if (request.column < 7 && ((shown & 0x80) || raw_value >= 2)) {
error = "Dieses Einstellungsfeld ist im aktuellen Modus gesperrt.";
return std::nullopt;
}
const uint8_t old = raw_value;
uint8_t next = old;
if (request.operation == ui::SettingsEdit::toggle_binary) {
// Inventory of actual current consumers: direct match-engine buttons,
// matchday/season flags and the live-scene switch. Other cells are not
// made writable merely because the Original UI displayed a cell.
// Tie the write whitelist to the concrete consumer ranges. League
// remapping reads rows 0..4, columns 0..3; matchday display kinds 1/2
// map to columns 0..2 and rows 0..4 or 17..19.
const bool consumed =
(sound_cell && sound.has_value()) ||
(request.row == 0 &&
request.column == 4) || // A5: match/Sportschau sound
((request.row <= 4 && request.column <= 3) ||
((request.row <= 4 || request.row >= 17) && request.column <= 2)) ||
((request.row == 5 || (request.row >= 9 && request.row <= 12)) &&
request.column == 0) ||
(request.row == 1 && request.column == 4) || // B5 live-scene option
(request.row == 2 &&
request.column == 4) || // C5: Reality player numbers
// (RealityMatch_FormatError_ExecutableField)
(request.row == 5 &&
request.column ==
5) || // F6: Source manager-match desk gate
// (MatchdaySetup_MatchdayNeedsManagerDesks_RuntimeField)
(request.row == 6 &&
request.column ==
5) || // G6: transfer confirmation wait (OutcomeDelayDisabled)
(request.row == 16 &&
request.column ==
6) || // Q7: own-club Sportschau preference
// (MatchdaySetup_ConsiderSportschauFixture_RuntimeField)
(request.row == 13 &&
request.column ==
6) || // N7: Source kickoff competition list
// (SportschauAwards_MatchdayIntroView_RuntimeField)
(request.row == 1 &&
request.column == 6) || // B7: SportschauIntro intro gate
// (Controller_FormatError_RuntimeField)
(request.row == 2 &&
request.column == 6) || // C7: SportschauIntro intro-animation gate
// (Controller_FormatError_RuntimeField2)
(request.row == 3 &&
request.column ==
6) || // D7: selected report progression (ReplayProgressionMode)
(request.row == 4 &&
request.column ==
6) || // E7: Source-owned Sportschau scenes (ReplayChanceMode)
(request.row == 5 &&
request.column == 6) || // F7: SportschauIntro fixture-report gate
// (Controller_FormatError_RuntimeField3)
(request.row == 6 &&
request.column ==
6) || // G7: MatchdayIntro player/award rating
// (SportschauAwards_FinishSportschauAwards_RuntimeField)
(request.row == 7 &&
request.column ==
6) || // H7: SportschauTeamInfo competition totals
// (SportschauAwards_SportschauTeamInfoView_RuntimeField)
(request.row == 2 &&
request.column ==
5) || // C6 drawer-handle behavior
// (CareerSession_DispatchDesktopLayout_RuntimeField)
(request.row == 3 &&
request.column ==
5) || // D6 native desktop drag raster
// (CareerSession_DispatchDesktopLayout_RuntimeField2)
(request.row == 4 &&
request.column == 5) || // E6 always-visible shortcut bar
// (DeskState_FormatError_RuntimeField3)
(request.row == 7 && request.column == 5) || // H6 transfer option
(request.row == 8 &&
(request.column == 5 || request.column == 6)) || // I6/I7
(request.row >= 10 && request.row <= 13 &&
request.column == 4) || // K5:N5 match buttons
(request.row >= 10 && request.row <= 12 &&
request.column == 6) || // K7:M7 presentation
(request.row == 9 &&
request.column ==
6) || // J7 season-entrant visibility
// (SeasonEntrants_SeasonEntrantsFromGame_TextPointer)
(request.row == 15 && request.column == 4) || // P5
(request.row == 16 && request.column == 4) || // Q5
(request.row == 17 &&
request.column == 4); // R5: secondary leagues
// (CalendarState_FormatError_RuntimeField2)
if (!consumed || (old != 0 && old != 1)) {
error = "Diese Einstellung ist noch nicht verfügbar.";
return std::nullopt;
}
if (request.row == 16 && request.column == 4 && state.season_day() >= 110 &&
state.season_day() <= 230) {
error = ui::original_to_utf8(message_text(
state, ::bmh::layout::CareerSession_DispatchSettings_TextPointer));
return std::nullopt;
}
// SettingsSourceRefusal only permits re-enabling R5 while
// CareerSessionRuntimeField4 is zero. LeagueRoundCounters is the saved
// league_rounds block; CareerSessionRuntimeField4 is its sixth byte.
// Turning the leagues off remains possible after they have started.
if (request.row == 17 && request.column == 4 && old != 0 &&
(state.league_rounds.size() <= 5 || state.league_rounds[5] != 0)) {
error = ui::original_to_utf8(message_text(
state, ::bmh::layout::CareerSession_DispatchSettings_TextPointer2));
return std::nullopt;
}
next = old ^ 1;
} else {
// Column8: existing presentation speeds B8:F8, H8 process budget,
// J8 postponed limit and K8 autosave. Column9 only exposes values
// already read by Main's Source live presenters or CupDrawScreen.
const bool consumed =
(request.column == 7 &&
((request.row <= 6) || request.row == 7 || request.row == 9 ||
request.row == 10 || (scoped_settings && request.row == 8))) ||
// A9 match minutes; B9:C9 chance result; D9:E9 bookings; F9:G9 rolling
// ball; I9 cup draw; K9 Reality report; M9 preview/shootout; P9 shot.
(request.column == 8 &&
((request.row >= 0 && request.row <= 6) || request.row == 7 ||
request.row == 8 || request.row == 10 || request.row == 12 ||
request.row == 15));
if (!consumed || old >= 200) {
error = "Diese Einstellung ist noch nicht verfügbar.";
return std::nullopt;
}
if (request.column == 8) {
// SettingsSourceRefusal's ninth column is stored doubled for display. Its
// Source edit step is two raw units; decrement is enabled only
// above 1 and increment only below 0xc6 (198). Preserve odd raw
// values exactly, as the original does.
if (request.operation == ui::SettingsEdit::decrement) {
if (old <= 1) {
error = "Der Zahlenwert ist bereits am Originalminimum.";
return std::nullopt;
}
next = uint8_t(old - 2);
} else {
if (old >= 198) {
error = "Der Zahlenwert ist bereits am Originalmaximum.";
return std::nullopt;
}
next = uint8_t(old + 2);
}
} else if (request.column == 7) {
if (request.operation == ui::SettingsEdit::decrement) {
if (old == 0) {
error = "Der Zahlenwert ist bereits am Originalminimum.";
return std::nullopt;
}
next = uint8_t(old - 1);
} else {
const uint8_t limit =
exe.u8(::bmh::layout::CareerSession_DispatchSettings_RuntimeField +
request.row);
if (old >= limit) {
error = "Der Zahlenwert ist bereits am Originalmaximum.";
return std::nullopt;
}
next = uint8_t(old + 1);
}
}
}
if (next == old) {
error = "Die Einstellung hat sich nicht geändert.";
return std::nullopt;
}
return next;
}
} // namespace
+97
View File
@@ -0,0 +1,97 @@
// SPDX-License-Identifier: GPL-3.0-only
int ui_setting_index(const std::string &code) {
if (code.size() != 2 || code[0] < 'A' || code[0] > 'T' || code[1] < '1' ||
code[1] > '9')
return -1;
return (code[0] - 'A') * 9 + code[1] - '1';
}
constexpr const char *ui_automation_ids[] = {"lineup", "substitutions",
"tactics", "marking", "training"};
int ui_automation_index(const std::string &id) {
for (int i = 0; i < 5; ++i)
if (id == ui_automation_ids[i])
return i;
return -1;
}
cli::Json ui_settings_data(const ModernState &state, const LeImage &exe,
std::optional<ui::SettingsSoundCapabilities> sound,
int manager, uint64_t revision,
bool automation_available) {
using J = cli::Json;
using O = J::Object;
using A = J::Array;
const auto view =
ui::settings_from_game(state, manager, revision, exe, sound);
A cells, automation, formations;
for (size_t i = 0; i < view.cells.size(); ++i) {
const int column = int(i % 9), row = int(i / 9), raw = view.cells[i];
ui::SettingsWriteRequest request;
request.manager_slot = manager;
request.revision = revision;
request.expected_raw = view.cells;
request.row = uint8_t(row);
request.column = uint8_t(column);
std::string error;
request.operation = column < 7 ? ui::SettingsEdit::toggle_binary
: ui::SettingsEdit::increment;
bool editable =
settings_next_value(state, exe, sound, request, revision, false, error)
.has_value();
if (column >= 7 && !editable) {
request.operation = ui::SettingsEdit::decrement;
editable = settings_next_value(state, exe, sound, request, revision,
false, error)
.has_value();
}
const int binary = raw & 0x3f;
const int shown = column < 7 ? 1 - binary : column == 8 ? raw / 2 : raw;
const int maximum =
column < 7 ? 1
: column == 8
? 99
: exe.u8(
::bmh::layout::CareerSession_DispatchSettings_RuntimeField +
uint32_t(row));
const bool known = column < 7 ? binary <= 1 : raw < 200;
const auto code = std::string(1, char('A' + row)) + char('1' + column);
cells.push_back(
O{{"code", code},
{"raw", raw},
{"displayRaw",
int(view.display_cells ? (*view.display_cells)[i] : view.cells[i])},
{"value", known ? J(shown) : J(nullptr)},
{"editable", editable},
{"min", 0},
{"max", maximum},
{"step", 1},
{"reason", editable ? std::string() : error}});
}
const size_t base = size_t(manager) * 5, record = size_t(manager) * 0xb0c;
const auto mask =
state.manager_records.at(record + 0x218 + size_t(state.indoor));
for (int i = 1; i <= 8; ++i)
if (mask & (1 << (i - 1)))
formations.push_back(
O{{"value", i}, {"label", "Aufstellung " + std::to_string(i)}});
const int selected = state.manager_options.at(base);
const int default_formation =
selected > 0 && selected <= 8 && (mask & (1 << (selected - 1))) ? selected
: formations.empty()
? 0
: int(*ui_field(formations.front(), "value")->integer());
for (int i = 0; i < 5; ++i) {
const int raw = state.manager_options.at(base + size_t(i));
const bool available =
automation_available && (i != 0 || (!formations.empty() && raw <= 8)) &&
(i != 4 || state.manager_teams.at(size_t(manager)) != no_team());
automation.push_back(O{{"id", ui_automation_ids[i]},
{"enabled", i == 0 ? raw != 0 : (raw & 1) != 0},
{"raw", raw},
{"editable", available}});
}
return O{{"kind", "settings"},
{"cells", std::move(cells)},
{"automation", std::move(automation)},
{"formations", std::move(formations)},
{"formation", default_formation}};
}