#include "test_inputs.hpp" // SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include "formats/league_visibility.hpp" #include #include #include #include #include #include #include #include #include #include #include "app/controller.hpp" #include "app/window_actions.hpp" #include "ui/manager.hpp" #include "ui/pending_offer.hpp" #include "ui/contracts.hpp" #include "game/month.hpp" #include "game/desk_actions.hpp" #include "game/weekly.hpp" #include "ui/transfer_market.hpp" #include "ui/club_player_detail.hpp" #include "ui/league_table.hpp" #include "ui/live_matchday.hpp" #include "ui/live_set_piece.hpp" #include "ui/desk_records.hpp" #include "ui/game_end_alternate.hpp" #include "ui/desktop.hpp" #include "ui/settings.hpp" #include "ui/environment.hpp" #include "ui/season_entrants.hpp" #include "formats/textd.hpp" #include "game/messages.hpp" #include "game/lineup.hpp" #include "game/save.hpp" #include "game/schedule.hpp" #include "game/national.hpp" #include "game/matchday.hpp" #include "game/matchday_setup.hpp" #include "game/reschedule.hpp" #include "game/highscore.hpp" using namespace bmh; using namespace bmh::ui; namespace { void check(bool value, const char* message) { if (!value) throw std::runtime_error(message); } uint8_t session_runtime_byte(const GameState& state,const std::map& runtime,uint32_t address) { if(state.memory.has(address))return state.memory.u8(address); const auto found=runtime.find(address); if(found==runtime.end())throw std::runtime_error("expected live Source runtime byte is absent"); return found->second; } int32_t signed_u32(const std::vector& bytes, size_t at) { return int32_t(uint32_t(bytes.at(at)) | uint32_t(bytes.at(at + 1)) << 8 | uint32_t(bytes.at(at + 2)) << 16 | uint32_t(bytes.at(at + 3)) << 24); } void check_poach_ui_components(const std::filesystem::path& data) { StartupFlow flow(data); flow.click(150,215);flow.click(5,225,true);flow.click(5,225,true); std::unique_ptr session; uint64_t revision=0; openbmh::audio::Playback playback; std::optional audio_session; app::CareerSession::PoachPlayerSelector selector; const auto serve=[&](const FlowResult& result) { check(app::serve_flow_request(flow,result,session,data,data,0x1789abcd,revision,playback,audio_session,false, {},{},{},{},{},{},{},{},{},app::PendingOfferEntryPolicy::legacy_unpresented,{}, app::HumanBuyerMarketEntryPolicy::normal_interactive,{},{},{},{},{},{},selector).empty(), "poach uses the production controller"); }; serve(flow.click(90,169)); check(session && flow.screen_name()=="desktop","poach starts in an actual career"); auto& state=session->state(); state.memory.set16(::bmh::layout::Savestate_Layout_ExecutableField3,0x1f0); check(state.memory.has(::bmh::layout::GameMode)&&state.memory.u8(::bmh::layout::GameMode)==3,"actual Mode III exposes Original Abwerben"); flow.attach_preparation_context(session->preparation_projection(revision)); const auto& menu=*std::find_if(flow.desktop()->state().items.begin(),flow.desktop()->state().items.end(), [](const DeskItem& item){return item.kind==17&&!item.disabled;}); serve(flow.click(menu.x+menu.width/2,menu.y+menu.height/2)); const auto exe=load_le(asset_path(data,"BMH.exe")); const auto texts=load_textd(asset_path(data,"TEXTD.BLK")); const int px=exe.u16(::bmh::layout::TransferMarket_Click_RuntimeField + 3*6)+2,py=exe.u16(::bmh::layout::TransferMarket_Click_RuntimeField2+3*6)+2; const auto open=[&] { auto result=flow.click(px,py); check(result.request==FlowRequest::submenu_action && std::get(result.submenu_action).kind==TransferMarketRequestKind::open_poach, "Original EXE Abwerben button emits its typed selection request"); return result; }; auto pending=open(); const auto native=save_stream(state);const auto old_g=session->game();const auto old_w=session->rand(); const auto old_runtime=session->club_modal_runtime_checkpoint();const auto old_rev=revision; selector=[&](app::CareerSession&,app::ClubModalServices& staged,int,uint64_t&,const Image&) -> std::optional { staged.state().date++; state.date++; return std::nullopt; }; serve(pending); check(save_stream(state)==native && state.date==flow.desktop()->state().day_counter && revision==old_rev && session->game().seed()==old_g.seed()&&session->game().calls()==old_g.calls()&& session->rand().seed()==old_w.seed()&&session->rand().calls()==old_w.calls()&& session->club_modal_runtime_checkpoint()==old_runtime&&!session->transfer_offer_owner(), "reentrant selection/cancel restores session Native, date, G/W, runtime and revision"); int selected_team=-1,selected_player=-1,physical=-1; for(int team=0;team<138&&selected_team<0;++team) { if(team==state.manager_teams[0])continue; const auto range=squad_range(team); for(size_t row=0;rowrand(); if(start_poach(trial,0,int(range.first+row),w).status==PoachStatus::ready) { selected_team=team;selected_player=id;physical=int(row);break; } } } check(selected_team>=0,"actual career has a Source-poachable ordinary forward"); selector=[&](app::CareerSession& selector_session,app::ClubModalServices&,int manager,uint64_t& selector_revision,const Image& backdrop) -> std::optional { check(manager==0&&backdrop.width==320,"poach owns its actual Transfer backdrop"); const auto entry_g=selector_session.game(),live_g=session->game(); const auto entry_w=selector_session.rand(),live_w=session->rand(); check(entry_g.seed()==live_g.seed()&&entry_g.calls()==live_g.calls()&& entry_w.seed()==live_w.seed()&&entry_w.calls()==live_w.calls()&& selector_session.state().memory.u16(::bmh::layout::ManagerSettings)==state.memory.u16(::bmh::layout::ManagerSettings), "standalone50775 entry does not invoke53435 entry writes or family-close RNG"); std::string error; auto page=selector_session.current_league_table_dispatch(error);check(bool(page),"selection owns the reused Table controls"); if(page->identity.league!=team_league(selected_team)) { LeagueFamilyRequest map;map.identity=page->identity;map.from_child=1; map.kind=LeagueFamilyRequestKind::select_league;map.league_id=team_league(selected_team); check(selector_session.select_league_family_page(map,selector_revision,error),"Source map changes selection league"); page=selector_session.current_league_table_dispatch(error);check(bool(page),"selected league has an owned page"); } if(page->page.source_normal_mode==0) { LeagueFamilyRequest toggle;toggle.identity=page->identity;toggle.from_child=1; toggle.kind=LeagueFamilyRequestKind::control;toggle.control_index=7; page=selector_session.dispatch_league_table_control(toggle,selector_revision,error); check(bool(page),"selection reuses the real Source normal-mode control"); } auto tables=league_tables_from_game(selector_session.state(),manager); tables[size_t(page->identity.league)]=page->page; LeagueTableScreen table(data,std::move(tables),page->identity.league,LeagueTableScreen::FamilyMode{page->identity,1}); const auto row=std::find_if(page->page.rows.begin(),page->page.rows.end(),[&](const auto& r){return r.runtime_team_id==selected_team;}); check(row!=page->page.rows.end(),"chosen club belongs to actual visible Source league"); check(table.pointer_down(30,29+int(row-page->page.rows.begin())*7+3)&&table.pending_family_action(), "physical Table row DOWN requests the owned club"); std::optional chosen; const auto returned=selector_session.dispatch_family_table_team_info(*table.pending_family_action(),selector_revision,error, [&](app::ClubModalServices& staged,int team,const Image& table_backdrop) { check(team==selected_team&&staged.runtime_byte(::bmh::layout::CareerSession_DispatchPoachUi_ExecutableField)==2,"selected Source rank resolves actual club in poach mode"); const auto entry=staged.enter_club(team); const auto info=club_info_from_game(staged.state(),team,entry,exe,texts); const auto player=std::find_if(info.players.begin(),info.players.end(),[&](const auto& p){return p.physical_row==physical&&p.player_id==selected_player;}); check(player!=info.players.end(),"selected identity belongs to the actual Source club list"); ClubPlayerDetailSelection selection{team,selected_player,player->rendered_row,physical,-1}; auto redraw=staged.redraw_player(selection); const int slot=redraw.context.source_slot; ClubPlayerDetailScreen card(data,club_player_detail_from_game(staged.state(),std::move(redraw),exe),table_backdrop); check(!card.held_left_ticks(25)&&card.held_left_ticks(26),"Original long press requires more than25 ticks"); const auto request=card.take_request(); check(request.kind==ClubPlayerDetailRequestKind::close&&request.source_return==slot+1, "Source card returns the concrete absolute squad slot plus one"); chosen=request.selection;return true; },&chosen); if(!returned) throw std::runtime_error(error); check(chosen&&(selector_session.state().memory.u16(::bmh::layout::LeagueTableDisplayModes)&0x80), "valid50775 player selection preserves common low80 without an extra Table redraw"); return chosen; }; pending=open(); const auto before_offer=save_stream(state);const auto before_offer_g=session->game(); const auto before_offer_w=session->rand();const auto before_offer_runtime=session->club_modal_runtime_checkpoint(); const auto before_offer_rev=revision; std::string reject_error; check(!session->dispatch_poach_ui(std::get(pending.submenu_action),flow.render(),selector, [](const app::CareerSession::PoachDispatch& result,PreparationState) { check(bool(result.editor),"rollback test reached the real prepared poach editor"); throw FormatError("controlled UI acknowledgement rejection"); },revision,reject_error),"failed UI acknowledgement rejects prepared poach"); check(save_stream(state)==before_offer&&revision==before_offer_rev&&!session->transfer_offer_owner()&& poach_attempts_left(state,0)==5&&session->game().seed()==before_offer_g.seed()&& session->game().calls()==before_offer_g.calls()&&session->rand().seed()==before_offer_w.seed()&& session->rand().calls()==before_offer_w.calls()&&session->club_modal_runtime_checkpoint()==before_offer_runtime&& flow.pending_transfer_market(),"failed UI ACK restores special rows, owner, attempts, revision, runtime and G/W"); serve(pending); check(flow.screen_name()=="outgoing_transfer"&&session->transfer_offer_owner()&& session->transfer_offer_owner()->request.poach&&session->transfer_offer_owner()->request.list_entry>=40&& session->transfer_offer_owner()->request.list_entry<=43&&revision==old_rev+1, "typed player selection opens the actual special-row Original offer owner"); check(poach_attempts_left(state,0)==5,"opening the editor does not prematurely count the attempt"); const auto cancel_offer=flow.click(260,219); { const auto native=save_stream(state);const auto g=session->game();const auto w=session->rand(); const auto rev=revision;bool acknowledged=false;std::string error; try { app::TransferActions(*session).offer(std::get(cancel_offer.submenu_action), {},revision,error,{},{},[&](app::CareerSession::TransferOfferEditorDispatch& result) { acknowledged=result.editor.closed; session->game().range(0,10);session->rand().rand(); throw std::runtime_error("rejected poach cancel ACK"); }); } catch(const std::runtime_error&) {} check(acknowledged && save_stream(state)==native && revision==rev && session->transfer_offer_owner() && session->game().seed()==g.seed() && session->game().calls()==g.calls() && session->rand().seed()==w.seed() && session->rand().calls()==w.calls(), "shared offer rollback restores the suspended poach after a closing ACK fails"); } serve(cancel_offer); check(flow.screen_name()=="transfer_market"&&!session->transfer_offer_owner()&&poach_attempts_left(state,0)==4, "physical Original editor cancel returns to Transfer and counts/frees the poach attempt"); const auto completed_rev=revision;serve(pending); check(revision==completed_rev&&poach_attempts_left(state,0)==4,"consumed selection cannot reopen or count twice"); selector=[&](app::CareerSession& staged,app::ClubModalServices&,int,uint64_t&,const Image&) -> std::optional { std::string error;const auto page=staged.current_league_table_dispatch(error); check(bool(page),"cancel owns the real selection Table"); auto tables=league_tables_from_game(staged.state(),0);tables[size_t(page->identity.league)]=page->page; LeagueTableScreen table(data,std::move(tables),page->identity.league,LeagueTableScreen::FamilyMode{page->identity,1}); check(table.pointer_down(1,1,true)&&table.pending_family_action(),"selection right-DOWN posts Source close"); check(staged.close_poach_table_selection(*table.pending_family_action(),error),"standalone selection close accepts its owner"); return std::nullopt; }; const auto cancel_g=session->game();const auto cancel_w=session->rand(); serve(open()); check(flow.screen_name()=="transfer_market"&&revision==completed_rev+1&&!session->transfer_offer_owner()&& poach_attempts_left(state,0)==4&&session->game().seed()==cancel_g.seed()&&session->game().calls()==cancel_g.calls()&& session->rand().seed()==cancel_w.seed()&&session->rand().calls()==cancel_w.calls(), "Source selection cancel returns to Transfer without an attempt or family-close W/G stir"); const auto cancelled_revision=revision; // Source loan mode rejects before asking the player selector to run. flow.click(200,207); // no marks: toggle quote loan mode bool selected_again=false; selector=[&](app::CareerSession&,app::ClubModalServices&,int,uint64_t&,const Image&) -> std::optional {selected_again=true;return std::nullopt;}; const auto before_loan=save_stream(state);const auto loan_w=session->rand(); serve(open()); check(!selected_again&&revision==cancelled_revision&&save_stream(state)==before_loan&&session->rand().calls()==loan_w.calls(), "loan-mode prohibition precedes Table selection and preserves attempts/Native/W"); } void check_transfer_market_controller(const std::filesystem::path& data) { StartupFlow flow(data); flow.click(150, 215); flow.click(5, 225, true); flow.click(5, 225, true); auto started = flow.click(90, 169); std::unique_ptr session; uint64_t revision = 0; openbmh::audio::Playback playback; std::optional audio_session; const auto serve = [&](const FlowResult& result) { check(app::serve_flow_request(flow, result, session, data, data, 0x1789abcd, revision, playback, audio_session, false).empty(), "transfer flow uses production App controller"); }; serve(started); check(session && flow.screen_name() == "desktop", "transfer test begins in an actual initialized career"); auto& game = session->state(); MinuteReport market_report; new_transfer_list_entries(game, session->rand(), market_report); check(!market_report.unsupported, "real transfer pool is initialized by the engine API"); // Declared saved view control: Source position classes enabled and ordinary // market/roster split, rather than the removed free-form sell screen. game.memory.set16(::bmh::layout::Savestate_Layout_ExecutableField3, 0x1f0); flow.attach_preparation_context(session->preparation_projection(revision)); const auto menu = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(), [](const DeskItem& item) { return item.kind == 17 && !item.disabled; }); check(menu != flow.desktop()->state().items.end(), "actual desktop offers menu 17"); const auto opened = flow.click(menu->x + menu->width / 2, menu->y + menu->height / 2); check(opened.request == FlowRequest::submenu_opened && flow.screen_name() == "transfer_market", "menu 17 opens the real transfer screen"); serve(opened); const auto initial = transfer_market_from_game(game, revision); { app::TransferActions common(*session); const auto native=save_stream(game);const auto g=session->game();const auto w=session->rand(); const auto rev=revision;const auto runtime=session->club_modal_runtime_checkpoint(); auto observed=initial;++observed.revision; std::string error; check(!common.market(app::TransferActions::listing(observed,observed.squad.front(),false),{},revision,error), "shared transfer boundary rejects a stale observed listing"); check(!common.market(app::TransferActions::listing(observed,observed.squad.front(),false),{},revision,error, app::HumanBuyerMarketEntryPolicy::legacy_unpresented), "shared legacy transfer path rejects the same stale identity before an engine draw"); check(!common.apply(revision,[&] { game.date++;session->rand().rand();session->game().range(0,10);++revision; auto changed=runtime;changed[::bmh::layout::CareerSession_DispatchPoachUi_ExecutableField]=1; session->restore_club_modal_runtime(std::move(changed)); return false; }) && save_stream(game)==native && revision==rev && session->game().seed()==g.seed() && session->game().calls()==g.calls() && session->rand().seed()==w.seed() && session->rand().calls()==w.calls() && session->club_modal_runtime_checkpoint()==runtime && !session->transfer_offer_owner(), "shared transfer rejection restores Native, both RNGs, revision, runtime and owner"); } int listing_row = -1; TransferActionResult expected_listing; for (int row = std::min(17, int(initial.squad.size()) - 1); row >= 11; --row) { const auto& player = initial.squad[size_t(row)]; if (player.player < 0 || player.already_listed) continue; auto trial_state = game; auto trial_rand = session->rand(); MinuteReport trial_report; const auto trial = list_manager_player(trial_state, initial.manager_slot, player.row, trial_rand, trial_report); if (trial.status == TransferActionStatus::accepted && !trial_report.unsupported) { listing_row = player.row; expected_listing = trial; break; } } check(listing_row >= 0, "live manager roster has a listable reserve player"); int list_y = -1, baseline = 36; for (size_t n = 0; n < initial.roster.players.size(); ++n) { const auto& player = initial.roster.players[n]; if (player.borrowed) continue; if (n && (player.displayed_slot & 0xc000) != (initial.roster.players[n-1].displayed_slot & 0xc000)) baseline += 2; if (player.player_id < 0) continue; if (player.physical_row == listing_row) { list_y = baseline - 3; break; } baseline += 7; } check(list_y >= 29 && list_y < 215, "listable player is visible at its Original roster coordinate"); const auto roster_preview = flow.move_action(20, list_y); check(roster_preview.request == FlowRequest::submenu_action && std::get(roster_preview.submenu_action).kind == TransferMarketRequestKind::preview_quote, "Source roster hover sends its owned outgoing value preview"); // Hover belongs to the normal Source owner even while the compatibility // controller below retains the already-published listing path. check(app::serve_flow_request(flow, roster_preview, session, data, data, 0x1789abcd, revision, playback, audio_session, false, {}, {}, {}, {}, {}, {}, {}, {}, {}, app::PendingOfferEntryPolicy::legacy_unpresented, {}, app::HumanBuyerMarketEntryPolicy::normal_interactive).empty(), "real roster preview uses the production controller"); check(!flow.pending_transfer_market(), "Source roster preview acknowledged before mark/action"); flow.click(20, list_y); auto listing_request = flow.click(200, 207); check(listing_request.request == FlowRequest::submenu_action && std::holds_alternative(listing_request.submenu_action) && std::get(listing_request.submenu_action).kind == TransferMarketRequestKind::list_player && std::get(listing_request.submenu_action).squad_row == listing_row && std::get(listing_request.submenu_action).selected_players.size() == 1, "selecting a roster player sends a typed list-player request"); const auto list_action = std::get(listing_request.submenu_action); const size_t squad_slot = squad_range(list_action.runtime_club).first + size_t(list_action.squad_row); const uint16_t listed_player = game.squad_slots.at(squad_slot) & 0x0fff; const auto before_forgery = save_stream(game); const auto rand_seed = session->rand().seed(); const auto rand_calls = session->rand().calls(); const uint64_t before_listing_revision = revision; auto forged_revision = listing_request; std::get(forged_revision.submenu_action).revision--; serve(forged_revision); check(save_stream(game) == before_forgery && revision == before_listing_revision && session->rand().seed() == rand_seed && session->rand().calls() == rand_calls && flow.pending_transfer_market(), "stale list envelope is inert and leaves the valid pending request available"); auto altered_manager_list = list_action; altered_manager_list.manager_slot++; auto forged_manager_list = listing_request; forged_manager_list.submenu_action = altered_manager_list; serve(forged_manager_list); check(save_stream(game) == before_forgery && revision == before_listing_revision && session->rand().seed() == rand_seed && session->rand().calls() == rand_calls && flow.pending_transfer_market(), "forged list manager is inert"); const uint16_t old_slot = game.squad_slots.at(squad_slot); const int replacement = (listed_player + 1) % int(game.players.size()); game.squad_slots.at(squad_slot) = uint16_t((old_slot & 0xf000) | uint16_t(replacement)); const auto stale_player_state = save_stream(game); serve(listing_request); check(save_stream(game) == stale_player_state && revision == before_listing_revision && session->rand().seed() == rand_seed && session->rand().calls() == rand_calls && !flow.pending_transfer_market(), "stale roster player is rejected before engine/RNG mutation"); game.squad_slots.at(squad_slot) = old_slot; auto retry_listing = flow.click(200, 207); check(retry_listing.request == FlowRequest::submenu_action, "rejected listing can be resubmitted from current roster"); auto expected_state = game; auto expected_rand = session->rand(); MinuteReport expected_report; expected_listing = list_manager_player(expected_state, list_action.manager_slot, list_action.squad_row, expected_rand, expected_report); check(expected_listing.status == TransferActionStatus::accepted && !expected_report.unsupported, "independent reference listing succeeds"); const auto expected_list_bytes = save_stream(expected_state); serve(retry_listing); check(revision == before_listing_revision + 1 && save_stream(game) == expected_list_bytes && session->rand().seed() == expected_rand.seed() && session->rand().calls() == expected_rand.calls() && !flow.pending_transfer_market() && flow.screen_name() == "transfer_market", "App ACK matches independent list-manager engine state and consumes one revision"); const auto listed_projection = transfer_market_from_game(game, revision); check(std::any_of(listed_projection.items.begin(), listed_projection.items.end(), [&](const auto& item) { return item.player == listed_player && item.own_listing; }) && flow.state_json().find("Der Spieler steht jetzt auf der Transferliste.") != std::string::npos, "listing returns owned listing and visible confirmation to the UI"); const auto listed_snapshot = save_stream(game); const auto listed_seed = session->rand().seed(); const auto listed_calls = session->rand().calls(); const uint64_t listed_revision = revision; serve(retry_listing); check(save_stream(game) == listed_snapshot && revision == listed_revision && session->rand().seed() == listed_seed && session->rand().calls() == listed_calls, "consumed list request replay is inert"); { // GUI route: the offers on an own listing are reviewed from the roster and accepted before the listing expires int entry = -1; for (int e = 0; e < 40; ++e) if ((game.squad_slots.at(0xb70 + size_t(e)) & 0xfff) == listed_player) entry = e; check(entry >= 0, "the own listing has a transfer-list entry"); const uint32_t list = ::bmh::layout::EditorList + uint32_t(entry) * 0x58; MinuteReport bid_report; for (int tries = 0; tries < 400 && int16_t(game.memory.u16(list)) == -1; ++tries) transfer_bid(game, 0xb70 + entry, list, false, -1, session->game(), session->rand(), bid_report); check(!bid_report.unsupported && int16_t(game.memory.u16(list)) != -1, "the engine places a bid on the own listing"); flow.send_key("ESC"); flow.attach_preparation_context(session->preparation_projection(revision)); const auto menu17 = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(), [](const DeskItem& item) { return item.kind == 17 && !item.disabled; }); check(menu17 != flow.desktop()->state().items.end(), "the desktop still offers the market"); flow.click(menu17->x + menu17->width / 2, menu17->y + menu17->height / 2); const auto marked = flow.click(20, list_y); // marking a roster player first asks for the value preview if (marked.request == FlowRequest::submenu_action) check(app::serve_flow_request(flow, marked, session, data, data, 0x1789abcd, revision, playback, audio_session, false, {}, {}, {}, {}, {}, {}, {}, {}, {}, app::PendingOfferEntryPolicy::legacy_unpresented, {}, app::HumanBuyerMarketEntryPolicy::normal_interactive).empty(), "the roster preview is served"); const auto review_request = flow.click(200, 207); check(review_request.request == FlowRequest::submenu_action && std::holds_alternative(review_request.submenu_action) && std::get(review_request.submenu_action).kind == TransferMarketRequestKind::review_offers, "an already listed player opens the review of his offers"); int offers_shown = 0; HumanBuyerSaleHooks hooks; hooks.allocator_gate = HumanBuyerSaleAllocatorGate::zero; hooks.direct_mode = HumanBuyerSaleDirectMode::ordinary_ai_purchase; hooks.notice = [](const GameState&, const HumanBuyerSaleNotice&) {}; const app::TransferOfferPresenter review = [&](const GameState&, const TransferOfferListView& view) { offers_shown = view.offer_count; return 0; // accept the first bid }; const auto error = app::serve_flow_request(flow, review_request, session, data, data, 0x1789abcd, revision, playback, audio_session, false, {}, review, {}, {}, {}, {}, {}, {}, {}, app::PendingOfferEntryPolicy::legacy_unpresented, hooks, app::HumanBuyerMarketEntryPolicy::normal_interactive); check(error.empty() && offers_shown > 0, "the review presents the offers"); check((game.squad_slots.at(0xb70 + size_t(entry)) & 0xfff) != listed_player && !flow.pending_transfer_market(), "accepting a bid in the review sells the player and settles the request"); } { // a declined listing: at expiry the player leaves the list (the seller declines every offer) and can be listed again const auto before = transfer_market_from_game(game, revision); int row2 = -1; for (int row = std::min(17, int(before.squad.size()) - 1); row >= 11 && row2 < 0; --row) { const auto& player = before.squad[size_t(row)]; if (player.player < 0 || player.already_listed || player.row == listing_row) continue; auto trial_state = game; auto trial_rand = session->rand(); MinuteReport trial_report; if (list_manager_player(trial_state, before.manager_slot, player.row, trial_rand, trial_report).status == TransferActionStatus::accepted && !trial_report.unsupported) row2 = player.row; } check(row2 >= 0, "another listable reserve player exists"); MinuteReport report; const auto listed = list_manager_player(game, before.manager_slot, row2, session->rand(), report); check(listed.status == TransferActionStatus::accepted && listed.list_entry >= 0, "the second player is listed"); const int entry = listed.list_entry; const uint32_t list = ::bmh::layout::EditorList + uint32_t(entry) * 0x58; for (int tries = 0; tries < 400 && int16_t(game.memory.u16(list)) == -1; ++tries) transfer_bid(game, 0xb70 + entry, list, false, -1, session->game(), session->rand(), report); check(int16_t(game.memory.u16(list)) != -1, "a bid arrives on the second listing"); game.memory.set8(list + 0x56, 1); // expires with this countdown int declined = 0; game.transfer_offer_selector = [&](const GameState&, const TransferOfferListView&) { ++declined; return -1; }; transfer_list_countdown(game, session->game(), session->rand(), report, false, TransferAllocatorContext::zero); game.transfer_offer_selector = {}; check(!report.unsupported && declined > 0, "the seller was asked and declined"); check((game.squad_slots.at(0xb70 + size_t(entry)) & 0xfff) == 0xfff, "after the decline the player has left the transfer list"); const auto fresh = transfer_market_from_game(game, revision); int y2 = -1, line = 36; for (size_t n = 0; n < fresh.roster.players.size(); ++n) { const auto& player = fresh.roster.players[n]; if (player.borrowed) continue; if (n && (player.displayed_slot & 0xc000) != (fresh.roster.players[n-1].displayed_slot & 0xc000)) line += 2; if (player.player_id < 0) continue; if (player.physical_row == row2) { y2 = line - 3; break; } line += 7; } check(y2 >= 29 && y2 < 215, "the declined player is visible in the roster"); flow.send_key("ESC"); flow.attach_preparation_context(session->preparation_projection(revision)); const auto menu = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(), [](const DeskItem& item) { return item.kind == 17 && !item.disabled; }); check(menu != flow.desktop()->state().items.end(), "the desktop offers the market again"); flow.click(menu->x + menu->width / 2, menu->y + menu->height / 2); HumanBuyerSaleHooks relist_hooks; relist_hooks.allocator_gate = HumanBuyerSaleAllocatorGate::zero; relist_hooks.direct_mode = HumanBuyerSaleDirectMode::ordinary_ai_purchase; relist_hooks.notice = [](const GameState&, const HumanBuyerSaleNotice&) {}; const auto serve_relist = [&](const FlowResult& result) { return app::serve_flow_request(flow, result, session, data, data, 0x1789abcd, revision, playback, audio_session, false, {}, {}, {}, {}, {}, {}, {}, {}, {}, app::PendingOfferEntryPolicy::legacy_unpresented, relist_hooks, app::HumanBuyerMarketEntryPolicy::normal_interactive); }; const auto marked_again = flow.click(20, y2); if (marked_again.request == FlowRequest::submenu_action) check(serve_relist(marked_again).empty(), "the roster preview is served"); const auto relist = flow.click(200, 207); check(relist.request == FlowRequest::submenu_action && std::holds_alternative(relist.submenu_action) && std::get(relist.submenu_action).kind == TransferMarketRequestKind::list_player, "a player who left the list after a decline can be listed again from the roster"); check(serve_relist(relist).empty(), "the second listing is served"); bool listed_again = false; for (int e = 0; e < 40; ++e) listed_again |= (game.squad_slots.at(0xb70 + size_t(e)) & 0xfff) == (game.squad_slots.at(squad_range(before.runtime_club).first + size_t(row2)) & 0xfff); check(listed_again, "the declined player stands on the transfer list again"); // VERKAUFEN on a listed player asks "Wollen Sie ... vom Transfermarkt holen?"; no keeps the listing, yes takes him off const auto player_id = game.squad_slots.at(squad_range(before.runtime_club).first + size_t(row2)) & 0xfff; const auto on_list = [&] { for (int e = 0; e < 40; ++e) if ((game.squad_slots.at(0xb70 + size_t(e)) & 0xfff) == player_id) return true; return false; }; std::string asked; bool answer = false; relist_hooks.confirm = [&](const GameState&, int, const std::string& text) { asked = text; return answer; }; for (const bool yes : {false, true}) { answer = yes; asked.clear(); auto selected = FlowResult{}; auto sell_again = flow.click(200, 207); // after a "no" the player is still selected if (sell_again.request != FlowRequest::submenu_action) { selected = flow.click(20, y2); if (selected.request == FlowRequest::submenu_action) check(serve_relist(selected).empty(), "the listed player's preview is served"); sell_again = flow.click(200, 207); } check(sell_again.request == FlowRequest::submenu_action && std::holds_alternative(sell_again.submenu_action) && std::get(sell_again.submenu_action).kind == TransferMarketRequestKind::review_offers && std::get(sell_again.submenu_action).ask_withdraw, "selling a listed player starts the withdraw question even without offers"); const app::TransferOfferPresenter no_bid = [](const GameState&, const TransferOfferListView&) { return -1; }; check(app::serve_flow_request(flow, sell_again, session, data, data, 0x1789abcd, revision, playback, audio_session, false, {}, no_bid, {}, {}, {}, {}, {}, {}, {}, app::PendingOfferEntryPolicy::legacy_unpresented, relist_hooks, app::HumanBuyerMarketEntryPolicy::normal_interactive).empty(), "the withdraw question is served"); check(!asked.empty(), "the question 'vom Transfermarkt holen' was asked"); check(on_list() == !yes, yes ? "answering yes takes the player off the transfer list" : "answering no keeps the player on the list"); } } { // the search dialog behind the buttons Suchen and Vorschlag (Source sub_19409) flow.send_key("ESC"); flow.attach_preparation_context(session->preparation_projection(revision)); const auto menu = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(), [](const DeskItem& item) { return item.kind == 17 && !item.disabled; }); check(menu != flow.desktop()->state().items.end(), "the desktop offers the market for the search dialog"); flow.click(menu->x + menu->width / 2, menu->y + menu->height / 2); const auto exe = load_le(asset_path(data, "BMH.exe")); const auto button_at = [&](int n) { return std::pair{exe.u16(::bmh::layout::TransferMarket_Click_RuntimeField + uint32_t(n) * 6) + 2, exe.u16(::bmh::layout::TransferMarket_Click_RuntimeField2 + uint32_t(n) * 6) + 2}; }; HumanBuyerSaleHooks hooks; hooks.allocator_gate = HumanBuyerSaleAllocatorGate::zero; hooks.direct_mode = HumanBuyerSaleDirectMode::ordinary_ai_purchase; std::vector boxes; // Like the graphical client, every notice is turned into its dialog (an unknown notice there refuses the whole action). hooks.notice = [&](const GameState& state, const HumanBuyerSaleNotice& notice) { (void)pending_offer_notice_dialog(state, PendingOfferNotice{notice.manager, notice.raw_offer_slot, notice.source_text_address, notice.original_message}); boxes.push_back(notice.original_message); }; // All notices the transfer routes can raise have a dialog (the poached player's agreement and the scouting boxes included). for (const uint32_t address : {::bmh::layout::DeskActions_SubmitTransferOfferEditorSource_TextPointer, ::bmh::layout::DeskActions_SubmitTransferOfferEditorSource_RuntimeField, ::bmh::layout::DeskActions_SubmitTransferOfferEditorSource_ExecutableField, ::bmh::layout::DeskActions_SubmitTransferBidImpl_ExecutableField, ::bmh::layout::DeskActions_Unsupported_ExecutableField, ::bmh::layout::DeskActions_Unsupported_ExecutableField2, ::bmh::layout::DeskActions_Unsupported_ExecutableField3, ::bmh::layout::DeskActions_Unsupported_TextPointer3, ::bmh::layout::Month_SearchProfileNews_TextPointer3, ::bmh::layout::Month_SearchProfileNews_TextPointer4}) (void)pending_offer_notice_dialog(game, PendingOfferNotice{initial.manager_slot, -1, address, "x"}); const auto serve_search = [&](const FlowResult& result) { return app::serve_flow_request(flow, result, session, data, data, 0x1789abcd, revision, playback, audio_session, false, {}, {}, {}, {}, {}, {}, {}, {}, {}, app::PendingOfferEntryPolicy::legacy_unpresented, hooks, app::HumanBuyerMarketEntryPolicy::normal_interactive); }; const int manager = initial.manager_slot; // Suchen: opens locally with the stored profile (the career starts with an inactive one: every value 1) const auto [search_x, search_y] = button_at(1); check(flow.click(search_x, search_y).request == FlowRequest::none && flow.state_json().find("\"search_open\":true") != std::string::npos, "Suchen opens the dialog without a request"); check(flow.state_json().find("\"search_edit\":[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]") != std::string::npos, "the dialog shows the stored profile (a new career: off bit, otherwise all 1) without its off bit"); flow.click(272, 25); // switch the midfielder cell off (row y 25, 25 px cells) flow.click(316, 42); // age slider: the upper end to the right edge flow.click(316, 58); // strength slider: the upper end to 99 check(flow.render().width == 320, "the market with the open search dialog renders"); flow.move_action(200, 100); // the pointer moves under an open dialog are ignored const auto confirm = flow.click(285, 145); // the confirm button check(confirm.request == FlowRequest::submenu_action && std::holds_alternative(confirm.submenu_action) && std::get(confirm.submenu_action).kind == TransferMarketRequestKind::store_search_profile, "the confirm button posts the profile"); const auto& stored_request = std::get(confirm.submenu_action); check(stored_request.search_apply && !stored_request.search_cancelled && stored_request.search_profile[2] == 0 && stored_request.search_profile[5] == 24 && stored_request.search_profile[7] == 99, "the posted profile carries the edits"); const uint64_t before_store = revision; check(serve_search(confirm).empty(), "the profile is stored by the production controller"); const auto stored = search_profile(game, manager); check(revision == before_store + 1 && !(stored[0] & kSearchProfileOff) && stored[2] == 0 && stored[5] == 24 && stored[7] == 99, "the stored profile is active and has the edits"); check(boxes.size() == search_profile_hits(game, manager).size() + 1 && boxes.size() > 1, "the scouting department reports first, then every listing that fits gets its message box"); check(flow.state_json().find("\"search_open\":false") != std::string::npos && !flow.pending_transfer_market(), "the dialog is closed and the request settled"); // Vorschlag opens with the profile the squad asks for; leaving by right click keeps it but switches the search off const auto [suggest_x, suggest_y] = button_at(2); check(flow.click(suggest_x, suggest_y).request == FlowRequest::none && flow.state_json().find("\"search_open\":true") != std::string::npos, "Vorschlag opens the dialog"); const auto expected = suggest_search_profile(game, manager, false); std::string expected_json = "\"search_edit\":["; for (size_t i = 0; i < expected.size(); ++i) expected_json += (i ? "," : "") + std::to_string(i == 0 ? expected[i] & 0x3f : expected[i]); check(flow.state_json().find(expected_json) != std::string::npos, "the dialog shows the suggestion of the squad"); boxes.clear(); const auto leave = flow.click(100, 100, true); check(leave.request == FlowRequest::submenu_action && std::get(leave.submenu_action).search_cancelled && !std::get(leave.submenu_action).search_apply, "the right button posts a cancelled profile"); check(serve_search(leave).empty(), "the cancelled profile is stored"); const auto switched_off = search_profile(game, manager); check((switched_off[0] & kSearchProfileOff) && switched_off[1] == expected[1] && boxes.empty(), "the suggestion is kept, switched off, and nothing is announced"); } // The old KB23 editor/legacy heuristic is no longer the ordinary GUI route. // Keep its controller capability checks on real Source KB31 events, with // the Core owner as the integration reference (not an independent EXE oracle). check(game.memory.u8(::bmh::layout::GameMode) == 3, "actual startup creates saved Source Mode III for qualification"); flow.send_key("ESC"); flow.attach_preparation_context(session->preparation_projection(revision)); const auto market_menu = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(), [](const DeskItem& item) { return item.kind == 17 && !item.disabled; }); check(market_menu != flow.desktop()->state().items.end(), "refreshed desktop retains market capability"); flow.click(market_menu->x + market_menu->width/2, market_menu->y + market_menu->height/2); std::vector presented; HumanBuyerSaleHooks presenters; presenters.allocator_gate = HumanBuyerSaleAllocatorGate::zero; presenters.direct_mode = HumanBuyerSaleDirectMode::ordinary_ai_purchase; presenters.notice = [&](const GameState&, const HumanBuyerSaleNotice& notice) { presented.push_back(notice.source_text_address); }; const auto serve_source = [&](const FlowResult& result) { check(app::serve_flow_request(flow, result, session, data, data, 0x1789abcd, revision, playback, audio_session, false, {}, {}, {}, {}, {}, {}, {}, {}, {}, app::PendingOfferEntryPolicy::legacy_unpresented, presenters, app::HumanBuyerMarketEntryPolicy::normal_interactive).empty(), "KB31 events use the production controller"); }; const auto visible_entries = [&] { std::vector out; const auto text = flow.state_json(); const auto at = text.find("\"visible_market_entries\":["); check(at != std::string::npos, "Source market exposes its exact visible list identities"); const auto end = text.find(']', at); size_t cursor = at + std::string("\"visible_market_entries\":[").size(); while (cursor < end) { if (text[cursor] == ',' || text[cursor] == ' ') { ++cursor; continue; } size_t used = 0; out.push_back(std::stoi(text.substr(cursor,end-cursor), &used)); cursor += used; } return out; }; const auto source_input = [&](const TransferMarketItem& item, const GameState& state) { const uint32_t list = ::bmh::layout::EditorList + uint32_t(item.list_entry)*0x58; int bid = -1; for (int n = 0; n < 4; ++n) if (state.memory.u16(list+uint32_t(n)*2) == 0xffff || state.memory.u16(list+uint32_t(n)*2) == initial.runtime_club) { bid=n; break; } return TransferOfferEditorRequest{initial.manager_slot,initial.runtime_club,item.list_entry, item.source_slot,item.player,state.memory.u16(list+8),bid,false}; }; struct OfferChoice { TransferMarketItem item; uint32_t fee=0, salary=0; uint32_t expected_notice=0; }; const auto choose_offer = [&](uint32_t wanted_notice) { const auto market = transfer_market_from_game(game,revision); for (const auto& item : market.items) { if (item.own_listing || item.own_bid_pending || item.asking_fee <= 0 || !item.salary_reference) continue; for (unsigned pct : {1u,100u,150u,200u}) { auto trial = game; auto trial_g = session->game(); auto trial_w = session->rand(); auto owner = open_transfer_offer_editor_source(trial,source_input(item,trial),trial_g,trial_w); if (!owner.supported || !owner.editable) continue; const uint32_t fee = wanted_notice == ::bmh::layout::DeskActions_SubmitTransferBidImpl_ExecutableField ? std::min(owner.money_profiles[0].maximum, uint32_t(item.asking_fee)*pct/100u) : 1u; const uint32_t salary = wanted_notice == ::bmh::layout::DeskActions_Unsupported_ExecutableField3 ? 1u : owner.money_profiles[1].maximum; owner=edit_transfer_offer_editor_source(trial,owner,{TransferOfferEditorField::fee,fee},trial_g,trial_w); owner=edit_transfer_offer_editor_source(trial,owner,{TransferOfferEditorField::salary,salary},trial_g,trial_w); if (!owner.supported) continue; MinuteReport report; std::vector notices; auto hooks=presenters; hooks.notice=[&](const GameState&,const HumanBuyerSaleNotice& n){notices.push_back(n.source_text_address);}; const auto result=submit_transfer_offer_editor_source(trial,owner,trial_w,hooks,report); if (report.unsupported || notices.empty()) continue; if (wanted_notice == ::bmh::layout::DeskActions_SubmitTransferBidImpl_ExecutableField && (notices.front()!=::bmh::layout::DeskActions_SubmitTransferBidImpl_ExecutableField || result.action.status!=TransferActionStatus::accepted)) continue; if (wanted_notice != ::bmh::layout::DeskActions_SubmitTransferBidImpl_ExecutableField && notices.front()!=wanted_notice) continue; return OfferChoice{item,fee,salary,wanted_notice}; } } throw std::runtime_error("no genuine Source market candidate has requested qualification outcome"); }; const auto request_bid = [&](const OfferChoice& choice) { check(flow.screen_name()=="transfer_market", "real Source parent available before opening"); int row=-1; for (int page=0;page<7 && row<0;++page) { const auto entries=visible_entries(); const auto found=std::find(entries.begin(),entries.end(),choice.item.list_entry); if (found!=entries.end()) row=int(found-entries.begin()); else flow.click(250,40,true); } check(row>=0,"purchase reaches its Source six-row page through actual navigation"); const int y=32+row*15; serve_source(flow.move_action(220,y)); flow.click(220,y); // mark only after the Source preview is acknowledged. const auto opened=flow.click(200,207); check(opened.request==FlowRequest::submenu_action && std::get(opened.submenu_action).kind==TransferMarketRequestKind::open_offer, "Source market action emits typed KB31 opening"); const auto& open=std::get(opened.submenu_action); check(open.bid.player==choice.item.player && open.bid.list_entry==choice.item.list_entry && open.bid.source_slot==choice.item.source_slot && open.selected_players.size()==1, "physical opening preserves selected player/slot/manager identity"); { const auto native=save_stream(game);const auto g=session->game();const auto w=session->rand(); const auto rev=revision;const auto runtime=session->club_modal_runtime_checkpoint(); bool acknowledged=false;std::string error; try { app::TransferActions(*session).open_offer(open,revision,error, [&](app::CareerSession::TransferOfferEditorDispatch&) { acknowledged=bool(session->transfer_offer_owner()); game.date++;session->rand().rand();session->game().range(0,10); throw std::runtime_error("rejected transfer frontend ACK"); }); } catch(const std::runtime_error&) {} check(acknowledged && save_stream(game)==native && revision==rev && session->game().seed()==g.seed() && session->game().calls()==g.calls() && session->rand().seed()==w.seed() && session->rand().calls()==w.calls() && session->club_modal_runtime_checkpoint()==runtime && !session->transfer_offer_owner(), "shared transfer opening restores complete state when the frontend ACK throws"); } serve_source(opened); check(flow.screen_name()=="outgoing_transfer" && session->transfer_offer_owner(),"controller opens actual KB31 owner"); const auto field=[&](int x,uint32_t value) { flow.click(x,123); check(flow.text(std::to_string(value)),"actual KB6 accepts entered offer value"); const auto edit=flow.send_key("ENTER"); check(edit.request==FlowRequest::submenu_action && std::get(edit.submenu_action).kind==OutgoingTransferRequestKind::quote_change, "calculator emits a typed single-field Source commit"); serve_source(edit); }; field(40,choice.fee); field(200,choice.salary); const auto submit=flow.click(180,219); check(submit.request==FlowRequest::submenu_action && std::holds_alternative(submit.submenu_action), "live KB31 Angebot emits the typed submit request"); const auto& event=std::get(submit.submenu_action); check(event.identity.manager_slot==initial.manager_slot && event.identity.player==choice.item.player && event.identity.list_entry==choice.item.list_entry && event.identity.source_slot==choice.item.source_slot && event.fee==choice.fee && event.monthly_salary==choice.salary, "KB31 submit preserves Native identity and entered fee/salary"); return submit; }; const auto retry_submit=[&] { const auto r=flow.click(180,219); check(r.request==FlowRequest::submenu_action && flow.pending_transfer_offer(),"rejected KB31 submit remains physically retryable");return r; }; const auto stable=[&](const std::vector& bytes,const GameRandom& g,const WatcomRandom& w,uint64_t rev) { return save_stream(game)==bytes && revision==rev && session->game().seed()==g.seed() && session->game().calls()==g.calls() && session->rand().seed()==w.seed() && session->rand().calls()==w.calls(); }; const auto check_submit=[&](const FlowResult& submitted,const OfferChoice& choice) { auto expected=game;auto expected_g=session->game();auto expected_w=session->rand(); MinuteReport report;std::vector notices;auto hooks=presenters; hooks.notice=[&](const GameState&,const HumanBuyerSaleNotice& n){notices.push_back(n.source_text_address);}; const auto reference=submit_transfer_offer_editor_source(expected,*session->transfer_offer_owner(),expected_w,hooks,report); check(!report.unsupported && !notices.empty() && notices.front()==choice.expected_notice, "current Source owner reference retains the meaningful qualification outcome"); const auto rev=revision;const auto balance=signed_u32(game.manager_records,0x314);presented.clear(); serve_source(submitted); check(save_stream(game)==save_stream(expected) && session->game().seed()==expected_g.seed() && session->game().calls()==expected_g.calls() && session->rand().seed()==expected_w.seed() && session->rand().calls()==expected_w.calls() && revision==rev+1 && presented==notices && !flow.pending_transfer_offer(), "actual controller submit matches complete Core Native/G/W/notice sequence once"); const auto after=save_stream(game);const auto after_g=session->game();const auto after_w=session->rand();const auto after_rev=revision; serve_source(submitted); check(stable(after,after_g,after_w,after_rev),"consumed offer request replay cannot consume a second draw or commit"); const auto projection=transfer_market_from_game(game,revision); if (reference.action.status==TransferActionStatus::accepted) { const auto range=squad_range(initial.runtime_club);bool bought=false; for(size_t n=0;n(forged.submenu_action).identity.manager_slot++; const auto before=save_stream(game);const auto before_g=session->game();const auto before_w=session->rand();const auto before_rev=revision; serve_source(forged); check(stable(before,before_g,before_w,before_rev)&&flow.pending_transfer_offer(),"forged bid manager envelope is inert before Native/RNG"); auto forged_offer_revision=low_request;std::get(forged_offer_revision.submenu_action).identity.revision--; serve_source(forged_offer_revision); check(stable(before,before_g,before_w,before_rev)&&flow.pending_transfer_offer(),"stale bid revision envelope preserves valid physical pending request"); game.memory.set8(::bmh::layout::ActiveManager,1);const auto stale_manager=save_stream(game); serve_source(low_request); check(stable(stale_manager,before_g,before_w,before_rev)&&!flow.pending_transfer_offer(),"stale actual active manager rejects before Native/G/W mutation"); game.memory.set8(::bmh::layout::ActiveManager,0); low_request=retry_submit(); const size_t pool=size_t(low.item.source_slot);const uint16_t pool_before=game.squad_slots.at(pool); int replacement_player=-1;for(uint16_t slot:game.squad_slots){const int id=slot&0xfff;if(id!=0xfff&&id!=low.item.player&&size_t(id)=0,"genuine career contains a distinct replacement player"); game.squad_slots[pool]=uint16_t((pool_before&0xf000)|replacement_player);const auto stale_player=save_stream(game); serve_source(low_request); check(stable(stale_player,before_g,before_w,before_rev)&&!flow.pending_transfer_offer(),"recycled market identity rejects before Native/RNG/revision"); game.squad_slots[pool]=pool_before; check_submit(retry_submit(),low); // A high salary plus a negligible fee reaches the ordinary auction refusal, // distinct from the preceding low-salary short circuit; both retain a bid. OfferChoice pending; try { pending=choose_offer(::bmh::layout::DeskActions_Unsupported_ExecutableField2); } catch(const std::runtime_error&) { pending=choose_offer(::bmh::layout::DeskActions_Unsupported_TextPointer3); } check_submit(request_bid(pending),pending); const auto accepted=choose_offer(::bmh::layout::DeskActions_SubmitTransferBidImpl_ExecutableField); check_submit(request_bid(accepted),accepted); } void check_mailbox_actions(const std::filesystem::path& data) { StartupFlow flow(data); flow.click(150, 215); flow.click(5, 225, true); flow.click(5, 225, true); const auto career = flow.click(90, 169); std::unique_ptr session; uint64_t revision = 0; openbmh::audio::Playback playback; std::optional audio_session; const auto serve = [&](const FlowResult& result) { check(app::serve_flow_request(flow, result, session, data, data, 0x12345678, revision, playback, audio_session, false).empty(), "mailbox actions use production controller"); }; serve(career); check(bool(session), "mailbox fixture creates a career"); auto& game = session->state(); check(game.memory.has(::bmh::layout::MailboxRecipientMask) && (game.memory.u32(::bmh::layout::MailboxRecipientMask) & (uint32_t(1) << flow.desktop()->state().manager_slot)), "Source message posting sets the active manager format field latch"); const auto notification_mask = game.memory.u32(::bmh::layout::MailboxRecipientMask); const auto notification_save = save_stream(game); const auto quickbar_revision = revision; const auto quickbar_game_calls = session->game().calls(), quickbar_watcom_calls = session->rand().calls(); const auto edge_motion = flow.move_action(100, 239); check(edge_motion.request == FlowRequest::none && flow.desktop()->state_json().find("\"shortcut_bar_visible\":true") != std::string::npos && save_stream(game) == notification_save && revision == quickbar_revision && session->game().calls() == quickbar_game_calls && session->rand().calls() == quickbar_watcom_calls, "production Flow lower-edge motion shows quickbar without controller, save or RNG changes"); if (!flow.desktop()->state().shortcut_bar_always) check(edge_motion.changed, "physical lower-edge motion requests the hidden quickbar SDL redraw"); check(!flow.move_action(120, 239).changed, "production Flow consecutive bottom-edge samples preserve the shown bar"); flow.click(120, 239); check(flow.desktop()->state_json().find("\"shortcut_bar_visible\":true") != std::string::npos, "physical click after lower-edge motion does not retoggle the quickbar"); flow.click(10, 215); // Toggle legacy routine's presentation-local bin mode. check(flow.desktop()->state_json().find("\"bin_mode\":true") != std::string::npos, "mailbox parent fixture enters the local bin mode without a Native write"); auto notification = session->pending_mailbox_notification(revision); check(notification && notification->manager_slot == flow.desktop()->state().manager_slot, "only the active ordinary manager receives a pending automatic mailbox projection"); flow.show_notified_mailbox(std::move(*notification)); check(flow.screen_name() == "mailbox" && !flow.desktop()->pending(), "format field auto-opens the reader without fabricating a desk click"); const auto close_notification = flow.send_key("ESC"); check(close_notification.request == FlowRequest::mailbox_closed && close_notification.mailbox_close.revision == revision, "mailbox close returns an owner-bound notification acknowledgement"); serve(close_notification); const uint32_t active_bit = uint32_t(1) << flow.desktop()->state().manager_slot; check(!session->pending_mailbox_notification(revision) && game.memory.u32(::bmh::layout::MailboxRecipientMask) == (notification_mask & ~active_bit) && revision == close_notification.mailbox_close.revision && save_stream(game) == notification_save, "reader close clears only the active transient bit without revision or FBM writes"); check(flow.desktop()->state_json().find("\"bin_mode\":true") != std::string::npos, "returning from the reader preserves the desk's local bin mode"); flow.click(10, 215); game.memory.set8(::bmh::layout::DeskState_FormatError_RuntimeField3, 0); game.mailbox.assign(kMailboxEntries * kMailboxEntry, 0); post_composed(game, 0, "Gemeinsame Nachricht"); game.mailbox[0] = 3; game.mailbox[3] = 0x80; // Manager 0+1 and Original broadcast marker. post_composed(game, 0, "Private Nachricht"); const auto price = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(), [](const DeskItem& i) { return i.kind == 55 && i.open; }); check(price != flow.desktop()->state().items.end(), "mailbox fixture has price widget"); serve(flow.click(price->x + 39, price->y + 10)); serve(flow.click(183, 220)); check(flow.screen_name() == "mailbox", "mailbox opens in production App"); const auto date = game.date; const auto gs = session->game().seed(); const auto ws = session->rand().seed(); const auto gc = session->game().calls(), wc = session->rand().calls(); const auto stable = [&] { check(game.date == date && session->game().seed() == gs && session->rand().seed() == ws && session->game().calls() == gc && session->rand().calls() == wc, "article actions preserve calendar and both RNG streams"); }; auto expected = game; const auto before = revision; serve(flow.click(85, 205)); // Merken mode. const auto keep = flow.click(60, 70); check(keep.request == FlowRequest::mailbox_action && keep.mailbox_action.entry_index == 0 && flow.pending_mailbox() && !flow.send_key("ESC").changed, "article request is bound to modal revision and owns input until ACK"); auto wrong_context = session->preparation_projection(revision + 1); ++wrong_context.desktop.season_index; bool context_rejected = false; try { flow.acknowledge_mailbox(mailbox_state_from_game(game, 0, revision + 1), wrong_context); } catch (const FormatError&) { context_rejected = true; } check(context_rejected && flow.pending_mailbox() && flow.desktop()->state().revision == revision, "mailbox acknowledgement cannot advance calendar or replace another context"); auto forged = keep; forged.mailbox_action.kind = MailboxActionKind::delete_for_manager; serve(forged); check(revision == before && save_stream(game) == save_stream(expected) && flow.pending_mailbox(), "forged event neither writes nor consumes the valid pending article action"); serve(keep); expected.mailbox[4] ^= 1; check(revision == before + 1 && save_stream(game) == save_stream(expected) && !flow.pending_mailbox() && flow.desktop()->state().revision == revision && flow.screen_name() == "mailbox", "keep changes only active manager bit and refreshes all modal/parent context"); serve(keep); check(revision == before + 1 && save_stream(game) == save_stream(expected), "consumed action replay is inert"); serve(flow.click(110, 205)); serve(flow.click(60, 70)); check(revision == before + 1 && save_stream(game) == save_stream(expected) && !flow.pending_mailbox(), "kept message cannot be deleted and rejection restores usable input"); serve(flow.click(85, 205)); serve(flow.click(60, 70)); expected.mailbox[4] ^= 1; check(revision == before + 2 && save_stream(game) == save_stream(expected), "unkeep toggles only manager keep bit"); serve(flow.click(110, 205)); serve(flow.click(60, 70)); expected.mailbox[0] = 2; check(revision == before + 3 && save_stream(game) == save_stream(expected) && mailbox_state_from_game(game, 0).messages.size() == 1, "delete removes only this manager recipient and preserves other manager, broadcast, text and date"); // Physical entries can be recycled without an App revision change. Compare all 160 bytes. const auto stale = flow.click(60, 70); check(stale.request == FlowRequest::mailbox_action && stale.mailbox_action.entry_index == 1, "remaining article retains physical entry identity"); game.mailbox[kMailboxEntry + 159] ^= 1; expected = game; serve(stale); check(revision == before + 3 && save_stream(game) == save_stream(expected) && !flow.pending_mailbox(), "recycled or changed entry is rejected even when only an unused tail byte changed"); serve(flow.send_key("ESC")); check(flow.screen_name() == "desktop" && flow.desktop()->state().revision == revision, "mailbox closes to usable authoritative parent"); serve(flow.click(183, 220)); serve(flow.click(110, 205)); serve(flow.click(60, 70)); expected.mailbox[kMailboxEntry] = 0; check(revision == before + 4 && save_stream(game) == save_stream(expected) && flow.state_json().find("\"message_count\":0") != std::string::npos && flow.state_json().find("\"page_count\":1") != std::string::npos, "last deletion shows an explicit empty owned page without synthetic messages"); stable(); serve(flow.send_key("ESC")); // Exercise the Original's asymmetric recipient-word + 1 five-entry guard. game.mailbox.assign(kMailboxEntries * kMailboxEntry, 0); for (int i = 0; i < 6; ++i) post_composed(game, 0, "Grenze"); for (int i = 0; i < 5; ++i) game.mailbox[size_t(i) * kMailboxEntry + 4] = 1; auto request = [&](int slot, int manager, MailboxActionKind kind) { MailboxActionRequest r{kind, manager, revision, slot}; std::copy_n(game.mailbox.begin() + size_t(slot) * kMailboxEntry, kMailboxEntry, r.expected_entry.begin()); return r; }; expected = game; std::string error; const auto cap_revision = revision; check(!session->dispatch_mailbox(request(5, 0, MailboxActionKind::toggle_keep), revision, error) && !session->dispatch_mailbox(request(0, 0, MailboxActionKind::toggle_keep), revision, error) && revision == cap_revision && save_stream(game) == save_stream(expected), "Original manager-zero five-kept guard blocks both new keep and unkeep without writes"); auto stale_rev = request(5, 0, MailboxActionKind::delete_for_manager); --stale_rev.revision; check(!session->dispatch_mailbox(stale_rev, revision, error), "stale revision is rejected"); auto wrong_manager = request(5, 1, MailboxActionKind::delete_for_manager); check(!session->dispatch_mailbox(wrong_manager, revision, error), "inactive manager request is rejected"); game.manager_teams.push_back(game.manager_teams.front()); game.memory.set8(::bmh::layout::ActiveManager, 1); for (int i = 0; i < 6; ++i) game.mailbox[size_t(i) * kMailboxEntry] = 2; for (int i = 0; i < 5; ++i) game.mailbox[size_t(i) * kMailboxEntry + 4] = 2; expected = game; expected.mailbox[5 * kMailboxEntry + 4] = 2; check(session->dispatch_mailbox(request(5, 1, MailboxActionKind::toggle_keep), revision, error) && revision == cap_revision + 1 && save_stream(game) == save_stream(expected), "Original manager-one recipient-plus-one exception permits a sixth kept entry"); game.mailbox[5 * kMailboxEntry + 4] = 0; game.mailbox[5 * kMailboxEntry + 3] = 0x80; expected = game; expected.mailbox[5 * kMailboxEntry] = 0; expected.mailbox[5 * kMailboxEntry + 3] = 0; check(session->dispatch_mailbox(request(5, 1, MailboxActionKind::delete_for_manager), revision, error) && save_stream(game) == save_stream(expected), "last manager deletion clears an orphaned broadcast marker"); stable(); } void check_strengths_semantic_and_controller(const std::filesystem::path& data) { const auto exe=load_le(asset_path(data,"BMH.exe")); StartupFlow flow(data); flow.click(150,215);flow.click(5,225,true);flow.click(5,225,true); std::unique_ptr session;uint64_t revision=0; openbmh::audio::Playback playback;std::optional audio_session; const auto serve=[&](const FlowResult& result) { return app::serve_flow_request(flow,result,session,data,data,0x1789abcd,revision,playback,audio_session,false); }; check(serve(flow.click(90,169)).empty()&&session,"strengths starts a genuine career"); const auto w=session->rand();const auto g=session->game(); const auto rng_neutral=[&] {check(session->rand().seed()==w.seed()&&session->rand().calls()==w.calls()&& session->game().seed()==g.seed()&&session->game().calls()==g.calls(),"strengths never draws either RNG");}; const int manager=session->state().memory.u8(::bmh::layout::ActiveManager); const uint32_t settings=::bmh::layout::ManagerSettings+uint32_t(manager)*2,family=::bmh::layout::LeagueTableDisplayModes+uint32_t(manager)*2; // Source entry uses bit10 before it is cleared by render normalization. session->state().memory.set16(settings,0x0400);session->state().memory.set16(family,0xaabe); const auto open=session->strengths_open_request(revision); check(bool(open),"semantic strengths fixture has an active manager"); const int team_info_fixture_team=league_first_team(open->identity.league); const auto injured_range=squad_range(team_info_fixture_team); const int injured_player=session->state().squad_slots.at(injured_range.first)&0x0fff; check(injured_player!=kEmptySlot,"nested TeamInfo fixture has a first-row player"); session->state().squad_slots.at(injured_range.first)|=kSlotInLineup; session->state().players.at(size_t(injured_player)).w364|=1u<<16; const GameState baseline=session->state(); check(bool(open)&&!flow.in_strengths(),"semantic strengths entry has no UI/MEN owner requirement"); const auto neutral=[&](StrengthsRequest request) { const auto native=save_stream(session->state());const auto rev=revision;std::string error; check(!session->dispatch_strengths(request,revision,error)&&!error.empty()&&revision==rev&& save_stream(session->state())==native,"forged strengths identity rejects with whole Native/revision neutral");rng_neutral(); }; auto wrong=*open;++wrong.identity.manager;neutral(wrong); wrong=*open;++wrong.identity.runtime_club;neutral(wrong); wrong=*open;++wrong.identity.club_identity;neutral(wrong); wrong=*open;++wrong.identity.day_counter;neutral(wrong); wrong=*open;++wrong.identity.revision;neutral(wrong); wrong=*open;++wrong.identity.expected_settings_word;neutral(wrong); wrong=*open;++wrong.identity.expected_family_word;neutral(wrong); std::string error;const auto before_revision=revision; auto page=session->dispatch_strengths(*open,revision,error); check(page&&revision==before_revision+1&&page->page.identity.sequence==0&&page->page.identity.scope, "semantic opening commits exactly one ownership revision and establishes private scope"); auto expected=baseline;expected.memory.set16(settings,0x01ff); expected.memory.set16(family,uint16_t(0xa97e|(exe.u8(::bmh::layout::CareerSession_BeginFriendlyOpponentTable_RuntimeField+uint32_t(open->identity.league))?0x80:0))); check(save_stream(session->state())==save_stream(expected),"opening changes exactly format field and b602c words"); check(page->page.projection.words.raw_settings_word==0x0400&&page->page.projection.age_scratch.lineup_only&& page->page.projection.age_scratch.basis==StrengthsAgeBasis::entry_or_league_change_bit10, "Source opening keeps bit10-derived age despite persisted bit10 clearing");rng_neutral();neutral(*open); auto id=page->page.identity; // A valid public Bank transaction used to bypass the Strengths owner. It // must refuse before touching cash/deposit, and become usable after close. BankRequest deposit;deposit.kind=BankRequestKind::move_to_deposit; deposit.manager_slot=manager;deposit.runtime_club=id.runtime_club; deposit.revision=revision;deposit.amount=1; const auto owned_native=save_stream(session->state());const auto owned_revision=revision; check(!session->dispatch_bank(deposit,revision,error)&&error=="strengths_active"&& revision==owned_revision&&save_stream(session->state())==owned_native, "valid direct Bank request cannot invalidate active Strengths owner");rng_neutral(); bool facade_refused=false; try {(void)session->live_club_modal_services(revision);}catch(const FormatError&){facade_refused=true;} check(facade_refused&&save_stream(session->state())==owned_native, "new live mutable modal capability is unavailable during Strengths ownership"); // Mutable state() is a trusted Engine/fixture escape hatch. Its unexpected // Native mutation must be detected before the next owned view transition. const size_t cash_byte=size_t(manager)*0xb0c+0x314; const auto cash=session->state().manager_records.at(cash_byte); session->state().manager_records.at(cash_byte)^=1; neutral({id,StrengthsAction::control}); session->state().manager_records.at(cash_byte)=cash; wrong={id,StrengthsAction::control};++wrong.identity.scope;neutral(wrong); wrong={id,StrengthsAction::control};++wrong.identity.sequence;neutral(wrong); wrong={id,StrengthsAction::control,static_cast(255),-1};neutral(wrong); const auto action=[&](StrengthsAction kind,StrengthsControl control=StrengthsControl::condition,int value=-1) { const auto old_revision=revision; auto result=session->dispatch_strengths({id,kind,control,value},revision,error); check(result&&revision==old_revision+1,"owned semantic strengths action commits exactly once"); id=result->page.identity;rng_neutral();return *result; }; const auto age=page->page.projection.age_scratch.tenths; const auto filter=action(StrengthsAction::control); expected.memory.set16(settings,0x00fe); check(save_stream(session->state())==save_stream(expected)&&filter.page.projection.age_scratch.tenths==age&& filter.page.projection.age_scratch.lineup_only,"filter retains owned ages and only writes Source settings"); const auto lineup=action(StrengthsAction::control,StrengthsControl::lineup); expected.memory.set16(settings,0x80fe); check(save_stream(session->state())==save_stream(expected)&&lineup.page.projection.words.raw_settings_word&0x8000&& lineup.page.projection.age_scratch.basis==StrengthsAgeBasis::header_toggle_bit15, "header toggles saved bit15 and refreshes age with its own Source basis"); const auto header_frame=StrengthsScreen(data,lineup.page).render().pixels; const auto reset=action(StrengthsAction::control,StrengthsControl::reset); expected.memory.set16(settings,0x01ff); check(save_stream(session->state())==save_stream(expected)&&reset.page.projection.age_scratch.lineup_only&& reset.page.projection.age_scratch.basis==StrengthsAgeBasis::header_toggle_bit15&& StrengthsScreen(data,reset.page).render().pixels!=header_frame, "reset removes bit15 yet retains header ages and changes Original header/button drawing"); action(StrengthsAction::control,StrengthsControl::age); expected.memory.set16(settings,0x0200); check(save_stream(session->state())==save_stream(expected),"age sort Source transition clears only the specified word bits"); neutral({id,StrengthsAction::control,StrengthsControl::condition,-1}); action(StrengthsAction::control,StrengthsControl::age);expected.memory.set16(settings,0x01ff); const int first_navigation=id.league; for(int n=0;n<9;++n) { const int league=(first_navigation+1+n)%9; page=action(StrengthsAction::select_league,StrengthsControl::condition,league); check(page&&page->page.projection.rows.size()==size_t(kLeagueSizes[league])&& page->page.projection.age_scratch.basis==StrengthsAgeBasis::entry_or_league_change_bit10&& !page->page.projection.age_scratch.lineup_only,"all nine ordinary leagues refresh age from current bit10"); if(league>=5)check(page->page.projection.league_name==original_to_utf8(session->state().club_name(0x165+league-4)), "foreign ordinary leagues use actual country names without domestic suffix-table lookup"); for(const auto& row:page->page.projection.rows)check(row.runtime_team>=league_first_team(league)&& row.runtime_teampage.projection.rows.begin(),page->page.projection.rows.end(), [&](const auto& row){return row.runtime_team==team;}); check(visible!=page->page.projection.rows.end(),"TeamInfo fixture targets a visible runtime-team row"); const auto team_action=StrengthsRequest{id,StrengthsAction::team_info,StrengthsControl::condition,team}; const auto team_native=save_stream(session->state());const auto team_rev=revision; bool presenter_called=false; const app::TransferOfferTeamInfoPresenter stopped=[&](app::ClubModalServices&,int target,const Image& underlay) { presenter_called=true;check(target==team&&underlay.width==320&&underlay.height==240, "Strengths TeamInfo receives selected runtime club and exact parent frame");return false; }; check(!session->dispatch_strengths(team_action,revision,error,stopped)&&presenter_called&& revision==team_rev&&save_stream(session->state())==team_native&&session->strengths_owner()->page.identity==id, "stopped nested TeamInfo rolls back staged state and retains the exact Strengths owner");rng_neutral(); bool nested_rejected=false; const app::TransferOfferTeamInfoPresenter reentrant=[&](app::ClubModalServices&,int,const Image&) { std::string nested_error;auto nested=session->dispatch_strengths({id,StrengthsAction::close},revision,nested_error); nested_rejected=!nested&&!nested_error.empty();return true; }; auto team_return=session->dispatch_strengths(team_action,revision,error,reentrant); check(team_return&&nested_rejected&&revision==team_rev+1&&save_stream(session->state())==team_native, "reentrant nested dispatch is refused while the valid outer TeamInfo transaction succeeds"); id=team_return->page.identity;page=team_return;rng_neutral(); const app::TransferOfferTeamInfoPresenter accepted=[&](app::ClubModalServices& services,int target,const Image&) { check(target==team,"accepted TeamInfo keeps the selected runtime-team identity"); const auto entry=services.enter_club(target); check(!entry.displayed_slots.empty(),"TeamInfo fixture executes the original club-entry cleanup/projection"); return true; }; const auto source_effect_request=StrengthsRequest{id,StrengthsAction::team_info,StrengthsControl::condition,team}; const auto source_effect_before=save_stream(session->state());const auto source_effect_revision=revision; team_return=session->dispatch_strengths(source_effect_request,revision,error,accepted); GameState expected_team_info=session->state(); const auto expected_team_entry=prepare_club_info_entry(expected_team_info,team); check(!expected_team_entry.displayed_slots.empty(),"TeamInfo fixture executes known Original injury cleanup"); const bool returned_team_visible=team_return&&std::any_of(team_return->page.projection.rows.begin(), team_return->page.projection.rows.end(),[&](const auto& row){return row.runtime_team==team;}); check(team_return&&revision==source_effect_revision+1&&team_return->page.identity.manager==id.manager&& team_return->page.identity.runtime_club==id.runtime_club&&team_return->page.identity.league==id.league&& team_return->page.identity.scope==id.scope&&team_return->page.identity.sequence==id.sequence+1&& returned_team_visible&& team_return->page.projection.age_scratch==lineup_for_team.page.projection.age_scratch, "TeamInfo returns through a fresh projection to the same Strengths league and manager"); check(save_stream(session->state())==save_stream(expected_team_info)&& session->state().squad_slots.at(injured_range.first)!=uint16_t(baseline.squad_slots.at(injured_range.first)|kSlotInLineup), "successful nested TeamInfo commits the real injury cleanup and retains source age cache"); id=team_return->page.identity;page=team_return;rng_neutral(); const auto close_native=save_stream(session->state());action(StrengthsAction::close); check(!session->strengths_owner()&&save_stream(session->state())==close_native, "semantic close abandons scope without Source normalization/family writes"); neutral({id,StrengthsAction::close}); deposit.revision=revision;auto deposit_expected=session->state(); move_to_deposit(deposit_expected,manager,deposit.amount); const auto deposit_revision=revision; check(session->dispatch_bank(deposit,revision,error)&&revision==deposit_revision+1&& save_stream(session->state())==save_stream(deposit_expected), "same genuine direct Bank request resumes after accepted Strengths close");rng_neutral(); // Restore the real desktop at the advanced ownership revision, then exercise // actual controller pending equality and physical down/held-release routes. flow=StartupFlow(data);session.reset();revision=0;audio_session.reset(); flow.click(150,215);flow.click(5,225,true);flow.click(5,225,true); check(serve(flow.click(90,169)).empty()&&session,"physical strengths fixture starts a separate genuine career"); const auto item=std::find_if(flow.desktop()->state().items.begin(),flow.desktop()->state().items.end(), [](const DeskItem& item){return item.kind==2&&!item.disabled;}); check(item!=flow.desktop()->state().items.end(),"real desktop has enabled Strengths menu2"); const int x=item->x+item->width/2,y=item->y+item->height/2; const auto opened=flow.click(x,y);auto forged=opened;++forged.desk_action.item_id; const auto native_before=save_stream(session->state());const auto rev_before=revision; check(serve(forged).empty()&&!flow.in_strengths()&&flow.desktop()->pending()&& save_stream(session->state())==native_before&&revision==rev_before,"forged menu2 result cannot consume real UI owner"); check(serve(opened).empty()&&flow.in_strengths()&&revision==rev_before+1,"production controller opens acknowledged Strengths screen"); check(serve(opened).empty()&&revision==rev_before+1,"opening replay cannot allocate another scope"); const auto down=flow.pointer_down(205,218); check(down.changed&&down.request==FlowRequest::none&&flow.strengths()->state().identity.revision==revision, "Source button down presents held state without Native/revision commit"); const auto held=flow.render().pixels; check(flow.move(319,239)&&flow.click(205,218).request==FlowRequest::none&&flow.render().pixels!=held, "leaving held button cancels its release action"); flow.pointer_down(5,178);const auto request=flow.hold(5,178,2200); check(request.request==FlowRequest::strengths_action&&flow.pending_strengths(),"long hold follows same single release route"); forged=request;++forged.strengths_action.identity.scope; const auto pending_native=save_stream(session->state());const auto pending_revision=revision; check(serve(forged).empty()&&flow.pending_strengths()&&revision==pending_revision&& save_stream(session->state())==pending_native,"forged external action cannot dispatch another UI pending request"); auto bad_ack=flow.strengths()->state();++bad_ack.identity.revision;++bad_ack.identity.sequence;++bad_ack.identity.scope; bool thrown=false;try {flow.acknowledge_strengths(bad_ack,session->preparation_projection(revision+1));} catch(const FormatError&) {thrown=true;} check(thrown&&flow.pending_strengths()&&revision==pending_revision,"wrong ACK scope leaves pending UI and live session untouched"); check(serve(request).empty()&&revision==pending_revision+1&&!flow.pending_strengths(),"owned release receives strict ACK exactly once"); const auto accepted_native=save_stream(session->state()); const auto close_revision=revision;auto close_game=session->game();auto close_rand=session->rand(); stir_random(close_game,close_rand); check(serve(request).empty()&&revision==pending_revision+1&&save_stream(session->state())==accepted_native, "accepted physical request replay cannot write twice"); const auto close=flow.pointer_down(0,0,true); check(close.request==FlowRequest::league_family_action&& close.league_family_action.kind==LeagueFamilyRequestKind::close&&serve(close).empty()&&!flow.in_strengths()&& flow.screen_name()=="desktop","rightDOWN family close returns to desktop"); check(revision==close_revision+1,"family close commits one revision"); check(save_stream(session->state())==accepted_native,"family close keeps Native bytes"); check(session->game().seed()==close_game.seed()&&session->game().calls()==close_game.calls()&& session->rand().seed()==close_rand.seed()&&session->rand().calls()==close_rand.calls(), "family close matches exactly one Source stir"); check(flow.click(0,0,true).request==FlowRequest::none,"orphan rightUP does not reopen an action"); const auto save_dir=std::filesystem::temp_directory_path()/"openbmh-strengths-save-app-test"; std::filesystem::create_directories(save_dir);const auto save=save_dir/"STRENGTH.FBM"; std::filesystem::remove(save); check(session->save_game(save,manager,false,error),"changed Source criteria save through actual CareerSession"); app::CareerSession reload(data,0x1789abcd,save); check(reload.state().memory.u16(settings)==session->state().memory.u16(settings)&& reload.state().memory.u16(family)==session->state().memory.u16(family)&& reload.rand().calls()==0&&reload.game().calls()==0,"fresh actual Native load retains both settings without W/G"); std::filesystem::remove_all(save_dir); } void check_strengths_controller_ack_rollback(const std::filesystem::path& data) { const auto temp=std::filesystem::temp_directory_path()/"openbmh-strengths-ack-assets"; std::filesystem::remove_all(temp);std::filesystem::create_directories(temp/"KB"); for(const auto& entry:std::filesystem::directory_iterator(data)) { if(entry.path().filename()=="KB")continue; if(entry.is_regular_file()) std::filesystem::copy_file(entry.path(),temp/entry.path().filename()); } // Regular copies keep the ACK fault isolated without Windows symlink privileges. // Startup, desktop and eagerly projected submenus also need fonts and badges. for(const char* directory : {"KB","F","W"}) { std::filesystem::create_directories(temp/directory); for(const auto& entry:std::filesystem::directory_iterator(data/directory)) { if(!entry.is_regular_file())continue; std::filesystem::copy_file(entry.path(),temp/directory/entry.path().filename()); } } StartupFlow flow(temp);flow.click(150,215);flow.click(5,225,true);flow.click(5,225,true); std::unique_ptr session;uint64_t revision=0; openbmh::audio::Playback playback;std::optional audio_session; const auto serve=[&](const FlowResult& result) {return app::serve_flow_request(flow,result,session,data,data, 0x1789abcd,revision,playback,audio_session,false);}; check(serve(flow.click(90,169)).empty()&&session,"ACK rollback fixture uses genuine career and separate UI asset path"); const int manager=session->state().memory.u8(::bmh::layout::ActiveManager);session->state().memory.set16(::bmh::layout::ManagerSettings+uint32_t(manager)*2,0x0400); const auto before=session->strengths_checkpoint();const auto native=save_stream(session->state());const auto rev=revision; const auto item=std::find_if(flow.desktop()->state().items.begin(),flow.desktop()->state().items.end(), [](const DeskItem& item){return item.kind==2&&!item.disabled;}); check(item!=flow.desktop()->state().items.end(),"ACK fixture has genuine menu2"); const auto request=flow.click(item->x+item->width/2,item->y+item->height/2); // Session projection validates authentic assets; only the separate Flow ACK // renderer fails after the semantic transaction has accepted its settings. const auto original=read_file(temp/"KB"/"56.VGA"); const auto write_asset=[&](const Bytes& bytes) { std::ofstream out(temp/"KB"/"56.VGA",std::ios::binary|std::ios::trunc); out.write(reinterpret_cast(bytes.data()),std::streamsize(bytes.size())); check(bool(out),"bounded test asset write succeeds"); }; write_asset(Bytes{}); check(!serve(request).empty()&&!flow.in_strengths()&&!session->strengths_owner()&&revision==rev&& save_stream(session->state())==native&&session->rand().seed()==before.rand.seed()&& session->rand().calls()==before.rand.calls()&&session->game().seed()==before.game.seed()&& session->game().calls()==before.game.calls()&&session->strengths_checkpoint().next_scope==before.next_scope&& session->club_modal_runtime_checkpoint()==before.runtime, "postcommit UI ACK renderer exception rolls back settings, scope/cache/revision/runtime and both RNGs"); write_asset(original); const auto retry=flow.click(item->x+item->width/2,item->y+item->height/2); check(serve(retry).empty()&&flow.in_strengths()&&flow.strengths()->state().identity.scope==before.next_scope, "retry after ACK failure receives the original unconsumed scope"); check(serve(flow.pointer_down(0,0,true)).empty(),"rollback fixture closes owned scope"); std::filesystem::remove_all(temp); } void check_indoor_standings_controller(const std::filesystem::path& data) { StartupFlow flow(data); flow.click(150, 215); flow.click(5, 225, true); flow.click(5, 225, true); std::unique_ptr session; uint64_t revision = 0; openbmh::audio::Playback playback; std::optional audio_session; const auto serve = [&](const FlowResult& result) { check(app::serve_flow_request(flow, result, session, data, data, 0x12345678, revision, playback, audio_session, false).empty(), "indoor standings use the production controller"); }; serve(flow.click(90, 169)); check(session && flow.screen_name() == "desktop", "indoor standings start at a real career desk"); auto& game = session->state(); game.memory.set8(::bmh::layout::Cup_AdvanceCup_RuntimeField4, 1); for (int team = 0; team < 40; ++team) game.memory.set16(::bmh::layout::Cup_AdvanceCup_ExecutableField + uint32_t(team * 2), uint16_t(40 - team)); game.memory.set16(::bmh::layout::Cup_AdvanceCup_RuntimeField6, 0); game.memory.set16(::bmh::layout::Season_CareerSeasonSetup_RuntimeField7, 0); game.memory.set16(::bmh::layout::Cup_AdvanceCup_RuntimeField7, 1); const auto native = save_stream(game); const auto w = session->rand(); const auto g = session->game(); const auto rev = revision; const auto menu = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(), [](const DeskItem& item) { return item.kind == 9 && !item.disabled; }); check(menu != flow.desktop()->state().items.end(), "ordinary desk exposes its Hallenwertung item"); const int x = menu->x + menu->width / 2, y = menu->y + menu->height / 2; const auto open = flow.click(x, y); check(open.request == FlowRequest::desk_action && open.desk_action.menu_kind == 9, "indoor table retains its exact pending desk owner"); serve(open); check(flow.screen_name() == "indoor_standings" && flow.indoor_standings() && !flow.desktop()->pending(), "menu 9 opens the actual Source ranking rather than the unavailable-menu fallback"); const auto& rows = flow.indoor_standings()->state().rows; check(rows.size() == 16 && rows[0].team == 0 && rows[0].points == 40 && rows[15].team == 15, "Source ranks the forty saved Masters totals and presents the top sixteen"); check(rows[7].rank_color == 0x51 && rows[8].rank_color == 0xf7, "duplicate title holders do not consume an extra qualification place"); (void)flow.render(); check(!flow.send_key("ESC").changed && flow.screen_name() == "indoor_standings", "Source mouse wait does not invent an ESC binding"); serve(open); // Replayed owner has already been consumed. check(flow.screen_name() == "indoor_standings", "replayed navigation cannot reopen the owned table"); check(flow.pointer_down(x, y, true).request == FlowRequest::submenu_closed && flow.screen_name() == "desktop", "Original mouse DOWN returns to the retained desk"); check(!flow.click(x, y, true).changed && !flow.desktop()->pending(), "the matching mouse UP is consumed and cannot act on the underlying desk"); check(save_stream(game) == native && revision == rev && session->rand().seed() == w.seed() && session->rand().calls() == w.calls() && session->game().seed() == g.seed() && session->game().calls() == g.calls(), "ranking/render/close preserve Native, revision and both RNGs"); game.memory.set8(::bmh::layout::Cup_AdvanceCup_RuntimeField4, 0); game.indoor = true; const auto empty = indoor_standings_from_game(game, load_le(asset_path(data, "BMH.exe")), load_textd(asset_path(data, "TEXTD.BLK")), open.desk_action); check(empty.rows.empty() && empty.footer.empty() && !empty.strength_text.empty() && !empty.prize_text[0].empty(), "before the first tournament no ranking is fabricated; indoor prize information remains available"); } void check_calendar_readonly_controller(const std::filesystem::path& data) { StartupFlow flow(data); flow.click(150,215); flow.click(5,225,true); flow.click(5,225,true); const auto career = flow.click(90,169); std::unique_ptr session; uint64_t revision = 0; openbmh::audio::Playback playback; std::optional audio_session; const auto serve = [&](const FlowResult& result) { check(app::serve_flow_request(flow,result,session,data,data,0x12345678, revision,playback,audio_session,false).empty(), "calendar uses the production App controller"); }; serve(career); check(session && flow.screen_name() == "desktop", "calendar fixture begins on the actual career desk"); auto& game = session->state(); const auto native = save_stream(game); const auto rev = revision; const auto w = session->rand(); const auto g = session->game(); const auto unchanged = [&] { check(save_stream(game) == native && revision == rev && session->rand().seed() == w.seed() && session->rand().calls() == w.calls() && session->game().seed() == g.seed() && session->game().calls() == g.calls(), "calendar open/hover/select/redraw/close/replay preserve full Native, revision and both RNGs"); }; const auto calendar_item = std::find_if(flow.desktop()->state().items.begin(),flow.desktop()->state().items.end(), [](const DeskItem& item) { return item.kind == 8 && !item.disabled; }); check(calendar_item != flow.desktop()->state().items.end(), "actual desktop has an enabled Original calendar item"); const int x = calendar_item->x + calendar_item->width / 2; const int y = calendar_item->y + calendar_item->height / 2; const auto open = [&] { return flow.click(x,y); }; const auto request = open(); check(request.request == FlowRequest::desk_action && request.desk_action.menu_kind == 8 && flow.desktop()->pending() && !flow.calendar(), "menu8 awaits actual controller acknowledgement"); auto forged = request; ++forged.desk_action.item_id; serve(forged); check(!flow.calendar() && !flow.desktop()->pending(), "forged calendar request does not consume a different menu owner"); unchanged(); serve(request); check(!flow.calendar(), "replayed rejected calendar navigation has no pending owner"); unchanged(); auto stale = open(); ++stale.desk_action.revision; serve(stale); check(!flow.calendar(), "stale calendar revision rejects before projection"); unchanged(); auto wrong_manager = open(); ++wrong_manager.desk_action.manager_slot; serve(wrong_manager); check(!flow.calendar(), "calendar navigation binds the exact active manager"); unchanged(); // Keep the pending UI request genuine but alter only the live stable identity. const auto identity_request = open(); const int club = flow.desktop()->state().runtime_club; const auto identity = game.club_ids.at(size_t(club)); game.club_ids.at(size_t(club)) = uint16_t(identity + 1); const auto stale_identity_native = save_stream(game); serve(identity_request); check(!flow.calendar() && save_stream(game) == stale_identity_native && revision == rev && session->rand().calls() == w.calls() && session->game().calls() == g.calls(), "a pending calendar request cannot cross live stable-club identity replacement"); game.club_ids.at(size_t(club)) = identity; unchanged(); const auto opening = open(); auto desk_pixels = flow.render().pixels; serve(opening); check(flow.calendar() && flow.screen_name() == "calendar" && flow.in_readonly_view() && !flow.desktop()->pending(), "menu8 opens a real calendar instead of the parent unsupported route"); unchanged(); const auto state = flow.calendar()->state(); check((state.days.size() == 365 || state.days.size() == 366) && state.days.front().date.month == 7 && state.days.front().date.day == 1 && state.days.back().date.month == 6 && state.days.back().date.day == 30, "calendar screen owns the complete projected July-June year"); const auto first = calendar_cell(state.days.front()); check(first.x == 28 && first.y == 29 + state.days.front().date.weekday * 8 && first.width == 11 && first.height == 8, "Source July1 hitbox uses vertical weekdays and eleven by eight pixels"); const auto current = calendar_cell(state.days[size_t(state.current_day)]); check(flow.move(current.x + 2,current.y + 2) && flow.calendar()->selected_day() == state.current_day && flow.render().pixels.size() == 320 * 240 && !flow.move(current.x + 2,current.y + 2), "physical hover selects current day locally and duplicate motion is inert"); check(!flow.text("ignored") && !flow.send_key("RIGHT").changed, "calendar owns text and arrow input without advancing the career"); check(flow.move(0,0) && flow.calendar()->selected_day() == -1, "leaving Original day cells restores the unhighlighted calendar"); const auto free = std::find_if(state.days.begin(),state.days.end(),[](const CalendarDayProjection& day) { return day.competitions == 0; }); check(free != state.days.end(), "genuine calendar contains a free day"); const auto free_cell = calendar_cell(*free); serve(flow.click(free_cell.x + 2,free_cell.y + 2)); check(flow.calendar() && flow.calendar()->selected_day() == free->season_day, "a free day click remains read-only and does not book or advance"); const auto redraw = flow.render().pixels; check(flow.render().pixels == redraw, "calendar redraw is deterministic"); unchanged(); serve(opening); check(flow.calendar(), "consumed open replay cannot replace a live calendar"); unchanged(); serve(flow.click(0,0,true)); check(!flow.calendar() && flow.screen_name() == "desktop" && flow.render().pixels == desk_pixels, "right event8 returns to the exact parent desk without an engine revision"); unchanged(); // Source local30 selects only the manager's domestic class (plus bit14). int active_class = flow.desktop()->state().league; if (active_class > 2) --active_class; serve(open()); const auto own_state = flow.calendar()->state(); const auto own = std::find_if(own_state.days.begin(),own_state.days.end(),[&](const CalendarDayProjection& day) { return active_class >= 0 && active_class < 4 && (day.competitions & (uint32_t(1) << active_class)); }); check(own != own_state.days.end(), "genuine calendar contains an active domestic league day"); const auto own_cell = calendar_cell(*own); flow.move(own_cell.x + 2,own_cell.y + 2); const auto close = flow.click(own_cell.x + 2,own_cell.y + 2); check(close.request == FlowRequest::submenu_closed && !flow.calendar(), "Original own-league left event2 closes only the view, without kickoff or rescheduling"); serve(close); unchanged(); serve(open()); serve(flow.send_key("ESC")); check(!flow.calendar() && flow.screen_name() == "desktop", "calendar escape returns to the same desk"); unchanged(); const auto move_menu = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(), [](const DeskItem& item) { return item.kind == 7 && !item.disabled; }); check(move_menu != flow.desktop()->state().items.end(), "the real desk exposes enabled Original menu 7"); serve(flow.click(move_menu->x + move_menu->width / 2, move_menu->y + move_menu->height / 2)); check(flow.screen_name() == "reschedule_calendar" && flow.calendar() && !flow.calendar()->state().reschedule_options.empty(), "menu 7 opens its Source mode-2 calendar with actual reschedulable home fixtures"); const auto option = flow.calendar()->state().reschedule_options.front(); check(!option.target_days.empty(), "selected Original home fixture has at least one legal target"); const auto source_cell = calendar_cell(flow.calendar()->state().days[size_t(option.match.day)]); const auto select = flow.pointer_down(source_cell.x + 2, source_cell.y + 2); check(select.request == FlowRequest::none && flow.calendar()->state().reschedule_options.size() > 0, "first date click selects a fixture without changing Native state"); check(flow.click(source_cell.x + 2, source_cell.y + 2).request == FlowRequest::none, "matching physical release is consumed after Source date selection"); const int target_day = option.target_days.front(); const auto target_cell = calendar_cell(flow.calendar()->state().days[size_t(target_day)]); const auto move = flow.pointer_down(target_cell.x + 2, target_cell.y + 2); check(move.request == FlowRequest::reschedule_action && move.reschedule_action.kind == RescheduleActionKind::move, "second date click emits a typed move request for the selected Source fixture"); const size_t result_at = size_t(option.match.match) + size_t(option.match.round) * 10 + size_t(option.match.league) * 0x17c; const auto before_move_revision = revision; serve(move); check(flow.click(target_cell.x + 2, target_cell.y + 2).request == FlowRequest::none, "matching release cannot act a second time after the move acknowledgement"); check(revision == before_move_revision + 1 && flow.calendar()->state().moved_matches.size() == 1 && game.results.at(result_at) == 0xce, "controller applies the existing Engine reschedule transaction and acknowledges the moved fixture"); const auto target_again = calendar_cell(flow.calendar()->state().days[size_t(target_day)]); const auto undo = flow.pointer_down(target_again.x + 2, target_again.y + 2); check(undo.request == FlowRequest::reschedule_action && undo.reschedule_action.kind == RescheduleActionKind::undo, "clicking a moved match date emits the Source take-back action"); serve(undo); check(flow.click(target_again.x + 2, target_again.y + 2).request == FlowRequest::none, "matching release after take-back is consumed"); check(revision == before_move_revision + 2 && game.results.at(result_at) == 0xcc && flow.calendar()->state().moved_matches.empty(), "take-back restores the original unplayed fixture and removes its postponed entry"); serve(flow.pointer_down(0, 0, true)); check(flow.click(0, 0, true).request == FlowRequest::none, "menu 7 close release is consumed"); check(!flow.calendar() && flow.screen_name() == "desktop", "right event8 closes menu 7 and returns to the refreshed desk"); // After a kickoff the memory copy of the season day is only the day the game was loaded: the // calendar follows the live day (it was refused from the first kickoff on). ui::DeskRequest kickoff; kickoff.kind = ui::DeskRequestKind::advance_turn; kickoff.manager_slot = int(game.memory.u8(::bmh::layout::ActiveManager)); kickoff.revision = revision; std::string kickoff_error; const auto advanced = session->dispatch_kickoff(kickoff, revision, kickoff_error); check(advanced.kind != TurnDeskKind::Failed, "the fixture's first kickoff is played"); const auto after_kickoff = ui::calendar_from_game(game, load_le(asset_path(data, "BMH.exe"))); check(after_kickoff.current_day == game.season_day() + after_kickoff.leading_days, "the calendar after a kickoff shows the live day of the season"); } void check_readonly_views(const std::filesystem::path& data) { StartupFlow flow(data); flow.click(150, 215); flow.click(5, 225, true); flow.click(5, 225, true); const auto career = flow.click(90, 169); std::unique_ptr session; uint64_t revision = 0; openbmh::audio::Playback playback; std::optional audio_session; const auto serve = [&](const FlowResult& result) { const auto error=app::serve_flow_request(flow, result, session, data, data, 0x12345678, revision, playback, audio_session, false); if(!error.empty())throw std::runtime_error("read-only navigation uses the production App controller: "+error); }; serve(career); check(session && flow.screen_name() == "desktop", "read-only fixture reaches an actual career desk"); auto& game = session->state(); // Use a valid saved option which always displays the Original compact drawer bar. game.memory.set8(::bmh::layout::DeskState_FormatError_RuntimeField3, 0); for (int i = 0; i < 4; ++i) post_composed(game, 0, "Neue Nachricht " + std::to_string(i)); const auto current = flow.desktop()->state(); // A real acknowledged widget change refreshes the projected saved option and mailbox shortcut. const auto& items = current.items; const auto price = std::find_if(items.begin(), items.end(), [](const DeskItem& i) { return i.kind == 55 && i.open; }); check(price != items.end(), "fixture has the Original open admission drawer"); serve(flow.click(price->x + 4 + 35, price->y + 10)); check(flow.desktop()->state().mailbox_shortcut && flow.desktop()->state().mailbox_shortcut->id == 44 && flow.desktop()->state().mailbox_shortcut->kind == 63, "Original mailbox shortcut projects layout item 44 as drawer kind 63"); auto saved = save_stream(game); auto date = game.date; auto rev = revision; auto gs = session->game().seed(); auto ws = session->rand().seed(); auto gc = session->game().calls(), wc = session->rand().calls(); auto desk_pixels = flow.render().pixels; const auto unchanged = [&] { check(save_stream(game) == saved && revision == rev && game.date == date && session->game().seed() == gs && session->rand().seed() == ws && session->game().calls() == gc && session->rand().calls() == wc, "view opening, paging, rendering and closing preserve every saved byte, revision, date and both RNG streams"); }; const auto table = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(), [](const DeskItem& i) { return i.kind == 0 && !i.disabled; }); check(table != flow.desktop()->state().items.end(), "table is enabled on the real desk"); auto expected_table_entry=game; const int table_manager=flow.desktop()->state().manager_slot; const uint16_t table_family_before=game.memory.u16(::bmh::layout::LeagueTableDisplayModes+uint32_t(table_manager)*2); // legacy routine establishes the family bits; legacy routine clears the low mode bit // at its first draw. Runtime selector context is checked below separately. const uint16_t expected_table_word=uint16_t(((table_family_before&0xfc0f)|0x0170)&0xff7f); expected_table_entry.memory.set16(::bmh::layout::LeagueTableDisplayModes+uint32_t(table_manager)*2,expected_table_word); serve(flow.click(table->x + 10, table->y + 10)); check(flow.screen_name() == "league_table" && flow.in_readonly_view() && !flow.desktop()->pending(), "table menu opens the Source control view through the engine ACK"); std::string table_dispatch_error; const auto table_dispatch=session->current_league_table_dispatch(table_dispatch_error); check(save_stream(game)==save_stream(expected_table_entry)&& game.memory.u16(::bmh::layout::LeagueTableDisplayModes+uint32_t(table_manager)*2)==expected_table_word&& table_dispatch&&table_dispatch_error.empty()&&table_dispatch->page.source_controls_projection&& session->club_modal_runtime_checkpoint().at(::bmh::layout::CareerSession_BeginFriendlyOpponentTable_ExecutableField)==0, "Table entry changes only the Source family word and binds the Table selector context"); saved=save_stream(game);date=game.date;rev=revision;gs=session->game().seed();ws=session->rand().seed(); gc=session->game().calls();wc=session->rand().calls(); check(flow.render().pixels.size() == 320 * 240 && !flow.text("x") && !flow.move(15, 15), "read-only view renders and owns all input"); serve(flow.send_key("LEFT")); serve(flow.send_key("RIGHT")); const auto behind = flow.click(290, 100); check(behind.request == FlowRequest::none && flow.screen_name() == "league_table", "modal table input cannot trigger the underlying kickoff icon"); unchanged(); serve(flow.pointer_down(5,225,true)); check(flow.screen_name() == "desktop" && flow.render().pixels.size()==320*240, "Table right-click performs the Original family close and returns to a usable desk"); check(revision==rev+1,"Table family close commits one final Source return revision"); saved=save_stream(game);date=game.date;rev=revision;gs=session->game().seed();ws=session->rand().seed(); gc=session->game().calls();wc=session->rand().calls(); desk_pixels=flow.render().pixels; const auto mailbox = flow.click(183, 220); check(mailbox.request == FlowRequest::desk_action && mailbox.desk_action.item_id == 44 && mailbox.desk_action.menu_kind == 63, "Original compact-bar message hitbox resolves item ID rather than menu kind 44"); serve(mailbox); check(flow.screen_name() == "mailbox" && flow.in_readonly_view() && !flow.desktop()->pending(), "messages open through the actual App controller"); check(flow.render().pixels.size() == 320 * 240 && flow.state_json().find("\"read_only\":false") != std::string::npos, "message view exposes its action scope"); serve(flow.click(60, 205)); serve(flow.click(260, 205)); serve(flow.click(85, 205)); // Selecting an action mode alone is local. serve(flow.click(110, 205)); // No article was selected. serve(flow.hold(290, 100, 2000)); unchanged(); serve(flow.click(0, 0, true)); check(flow.screen_name() == "desktop" && flow.render().pixels == desk_pixels, "right-click closes the mailbox without changing or clicking the parent desk"); unchanged(); const auto settings = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(), [](const DeskItem& i) { return i.kind == 19 && !i.disabled; }); check(settings != flow.desktop()->state().items.end(), "Original settings icon is enabled"); const auto open_settings = flow.click(settings->x + 10, settings->y + 10); serve(open_settings); check(flow.screen_name() == "settings" && flow.in_readonly_view() && !flow.desktop()->pending(), "settings opens through production controller with owned raw settings"); saved=save_stream(game);date=game.date;rev=revision;gs=session->game().seed();ws=session->rand().seed(); gc=session->game().calls();wc=session->rand().calls(); check(flow.render().pixels.size() == 320 * 240 && !flow.text("x") && !flow.move(70, 27), "settings view owns all input"); serve(flow.click(64, 27)); serve(flow.click(27, 206)); // Original button 1 opens the .EIN load picker. check(flow.screen_name() == "save_load" && flow.state_json().find("\"file_kind\":\"settings\"") != std::string::npos, "settings Load opens the existing picker with the Original .EIN filter"); serve(flow.send_key("ESC")); check(flow.screen_name() == "settings", "cancelling the settings picker restores its parent settings page"); serve(flow.click(27, 219)); // Original button 2 opens the .EIN save picker. check(flow.screen_name() == "save_load" && flow.state_json().find("\"mode\":\"save\"") != std::string::npos && flow.state_json().find("\"file_kind\":\"settings\"") != std::string::npos, "settings Save opens the same picker in save mode with the .EIN filter"); serve(flow.click(120, 214)); check(flow.text("EIN-CHECK") && flow.state_json().find("EIN-CHECK") != std::string::npos, "retained settings parent permits typing into the active EIN filename field"); serve(flow.send_key("ESC")); check(flow.screen_name() == "settings", "cancelling the save picker preserves the settings parent"); serve(flow.hold(290, 100, 2000)); serve(flow.send_key("RIGHT")); unchanged(); const auto settings_pixels = flow.render().pixels; const auto ignored_escape = flow.send_key("ESC"); check(!ignored_escape.changed && ignored_escape.request == FlowRequest::none && flow.screen_name() == "settings" && flow.render().pixels == settings_pixels, "Source settings ignores ESC and retains the exact settings view"); unchanged(); serve(flow.pointer_down(310, 230, true)); check(flow.screen_name() == "desktop" && flow.render().pixels == desk_pixels, "Source right-button press returns settings to the exact parent pixels"); saved=save_stream(game);date=game.date;rev=revision;gs=session->game().seed();ws=session->rand().seed(); gc=session->game().calls();wc=session->rand().calls(); serve(open_settings); check(flow.screen_name() == "desktop" && !flow.desktop()->pending(), "replayed consumed settings navigation is inert"); unchanged(); const auto ad = std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(), [](const DeskItem& i) { return i.kind == 21 && !i.disabled; }); check(ad != flow.desktop()->state().items.end(), "Original advertising icon is enabled"); serve(flow.click(ad->x + 10, ad->y + 10)); check(flow.screen_name() == "advertising" && flow.in_readonly_view() && !flow.desktop()->pending(), "advertising opens through production controller"); check(flow.render().pixels.size() == 320 * 240 && !flow.text("x") && !flow.move(1, 1), "advertising owns modal input"); serve(flow.click(15, 30)); serve(flow.hold(290, 100, 2000)); unchanged(); serve(flow.click(0, 0, true)); check(flow.screen_name() == "advertising", "right-click cancels the nested spending calculator first"); unchanged(); serve(flow.click(0, 0, true)); check(flow.screen_name() == "desktop" && flow.render().pixels == desk_pixels, "advertising right-click closes only its modal"); unchanged(); } void check_desk_records_controller(const std::filesystem::path& data) { const auto save_dir=std::filesystem::temp_directory_path()/ ("openbmh-desk-records-controller-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count())); std::filesystem::create_directories(save_dir); StartupFlow flow(data,save_dir); flow.click(150,215);flow.click(5,225,true);flow.click(5,225,true); std::unique_ptr session;uint64_t revision=0; openbmh::audio::Playback playback;std::optional audio_session; const auto serve=[&](const FlowResult& result) { return app::serve_flow_request(flow,result,session,data,save_dir,0x44524543,revision,playback,audio_session,false); }; check(serve(flow.click(90,169)).empty()&&session&&flow.screen_name()=="desktop", "menu 26 verification starts through a real App career/controller"); auto& game=session->state(); const auto menu26=[&]() { const auto found=std::find_if(flow.desktop()->state().items.begin(),flow.desktop()->state().items.end(), [](const DeskItem& item){return item.kind==26&&!item.disabled;}); check(found!=flow.desktop()->state().items.end(),"Source menu 26 is enabled on the active desktop"); return flow.click(found->x+found->width/2,found->y+found->height/2); }; game.memory.set16(::bmh::layout::CareerSession_FormatError_RuntimeField7,0); check(serve(menu26()).empty()&&flow.screen_name()=="highscore"&&flow.desk_records()&& flow.desk_records()->is_alternate_calculator()&&std::filesystem::is_empty(save_dir), "zero signature dispatches menu 26 into the actual alternate score calculator"); const auto calculator=flow.render().pixels; check(serve(flow.send_key("ENTER")).empty()&&flow.desk_records_points_active(), "accepted calculator enters the Source point presentation phase"); unsigned frames=0;while(flow.advance_desk_records_point())++frames; check(frames==ui::GameEndAlternateScoreScreen::initial&&flow.finish_desk_records_points()&& flow.render().pixels!=calculator, "controller-owned calculator presents every point and retains the completed points image"); check(serve(flow.pointer_down(1,1)).empty()&&flow.screen_name()=="desktop", "the points result waits for a distinct mouse-down and returns to its desk"); serve(flow.click(1,1)); // Consume the paired UP release barrier. constexpr uint16_t signature=0x4938; game.memory.set16(::bmh::layout::CareerSession_FormatError_RuntimeField7,signature); const auto exe=load_le(asset_path(data,"BMH.exe")); const auto texts=load_textd(asset_path(data,"TEXTD.BLK")); const auto ranked_path=highscore_file(save_dir,signature,texts.strings.at(889)); const auto owner_slot=flow.desktop()->state().manager_slot; check(owner_slot>=0&&size_t(owner_slot)1 ? int((size_t(owner_slot)+1)%game.manager_teams.size()) : (owner_slot==0?1:0); check(foreign_slot!=owner_slot,"controller fixture can select a distinct foreign manager slot"); game.memory.set8(::bmh::layout::ActiveManager,uint8_t(foreign_slot)); const auto stale_request=menu26(); const auto rejected=serve(stale_request); check(!rejected.empty()&&!std::filesystem::exists(ranked_path)&&flow.screen_name()=="desktop", "wrong active-manager ownership is rejected before ranked highscore file persistence"); game.memory.set8(::bmh::layout::ActiveManager,uint8_t(owner_slot)); check(serve(menu26()).empty()&&flow.screen_name()=="highscore"&&flow.desk_records()&& !flow.desk_records()->is_alternate_calculator()&&std::filesystem::exists(ranked_path)&& std::filesystem::file_size(ranked_path)==360, "ranked highscore constructs its Original screen before writing the 360-byte table"); std::filesystem::remove_all(save_dir); } void check_advertising_controller(const std::filesystem::path& data) { StartupFlow flow(data); flow.click(150, 215); flow.click(5, 225, true); flow.click(5, 225, true); const auto started = flow.click(90, 169); std::unique_ptr session; uint64_t revision = 0; openbmh::audio::Playback playback; std::optional audio_session; const auto serve = [&](const FlowResult& request) { check(app::serve_flow_request(flow, request, session, data, data, 0x1789abcd, revision, playback, audio_session, false).empty(), "advertising uses the production App controller"); }; serve(started); check(session && flow.screen_name() == "desktop", "advertising test initializes an actual career"); auto& game = session->state(); const int manager = int(game.memory.u8(::bmh::layout::ActiveManager)); const size_t record = size_t(manager) * 0xb0c; std::fill_n(game.manager_records.begin() + std::ptrdiff_t(record + 0x8cc), 3 * 0x78, 0); std::fill_n(game.manager_records.begin() + std::ptrdiff_t(record + 0xa34), 16 * 12, 0); const size_t pool = record + 0x8cc + 3 * 12; const uint32_t amount = 10904; for (int i = 0; i < 4; ++i) game.manager_records[pool + size_t(i)] = uint8_t(amount >> (8 * i)); game.manager_records[pool + 4] = 2; game.manager_records[pool + 5] = 24; game.manager_records[pool + 7] = 3; game.memory.set8(::bmh::layout::AdGroupId, 31); const auto original_bytes = save_stream(game); const auto original_watcom = session->rand(); const auto original_game_rng = session->game(); const auto original_revision = revision; const auto unchanged = [&] { check(save_stream(game) == original_bytes && revision == original_revision && session->rand().seed() == original_watcom.seed() && session->rand().calls() == original_watcom.calls() && session->game().seed() == original_game_rng.seed() && session->game().calls() == original_game_rng.calls(), "advertising navigation, cancel and rejected requests do not mutate state or either RNG"); }; serve(flow.send_key("W")); check(flow.screen_name() == "advertising", "Original W opens advertising through the controller"); const auto unhovered_pixels = flow.render().pixels; const auto moved = flow.move_action(40, 30); check(moved.changed && moved.request == FlowRequest::none && flow.state_json().find("\"hovered_target\":") != std::string::npos && flow.render().pixels != unhovered_pixels && !flow.pending_advertising_action(), "production flow routes advertising motion into the original hover and help view"); check(!flow.pointer_down(40, 30).changed && !flow.pending_advertising_action(), "advertising DOWN does not duplicate the release-owned offer action"); unchanged(); check(flow.move_action(-1, -1).changed && flow.render().pixels == unhovered_pixels, "production flow restores the advertising view when the pointer leaves"); unchanged(); serve(flow.click(40, 30)); (void)flow.render(); unchanged(); serve(flow.click(110, 195)); check(!flow.pending_advertising_action() && flow.screen_name() == "advertising", "ABBRECHEN closes only the offer browser without an engine request"); unchanged(); serve(flow.click(40, 30)); const auto accept = [&] { auto action = flow.click(190, 195); check(action.request == FlowRequest::advertising_action && flow.pending_advertising_action(), "Original ANNEHMEN emits one manager/revision-bound offer request"); return action; }; for (int kind = 0; kind < 6; ++kind) { auto action = accept(); auto forged = action; auto& r = forged.advertising_action; if (kind == 0) ++r.manager_slot; if (kind == 1) ++r.runtime_club; if (kind == 2) ++r.revision; if (kind == 3) ++r.request_id; if (kind == 4) r.offer.expected_offer[11] ^= 1; if (kind == 5) r.offer.expected_contract[10] ^= 1; serve(forged); check(!flow.pending_advertising_action(), "forged advertising envelope is rejected"); unchanged(); } auto stale = accept(); game.manager_records[pool + 11] ^= 1; const auto stale_bytes = save_stream(game); serve(stale); check(save_stream(game) == stale_bytes && revision == original_revision && !flow.pending_advertising_action(), "changed native offer is rejected atomically before acceptance"); game.manager_records[pool + 11] ^= 1; unchanged(); // Both frontends use this application boundary. It must keep the observed // offer's identity, not silently refresh a stale selection from live state. auto observed = advertising_from_game(game, manager, revision); ++observed.revision; std::string shared_error; check(!session->accept_advertising_selection(observed, 0, 3, 0x700000001ULL, revision, shared_error) && !shared_error.empty(), "shared advertising selection rejects a stale observed revision"); unchanged(); const auto interrupted = accept(); const auto shared_last_id = session->advertising_checkpoint().last_request_id; bool acknowledgement_failed = false; try { session->apply_advertising(interrupted.advertising_action, revision, shared_error, [&](const app::CareerSession::AdvertisingActionResult&) { session->rand().rand(); session->game().range(0, 10); throw std::runtime_error("shared advertising acknowledgement rejected"); }); } catch (const std::runtime_error&) { acknowledgement_failed = true; } check(acknowledgement_failed && session->advertising_checkpoint().last_request_id == shared_last_id, "shared advertising rollback restores the consumed request id after failed acknowledgement"); unchanged(); flow.reject_advertising_action("shared acknowledgement test"); // Force the authoritative desk ACK to fail after the Core acceptance has succeeded. const auto failed_ack = accept(); const size_t name_byte = record + 0xa8; const auto old_name = game.manager_records[name_byte]; game.manager_records[name_byte] = old_name == 'X' ? 'Y' : 'X'; const auto rollback_bytes = save_stream(game); const auto last_id = session->advertising_checkpoint().last_request_id; serve(failed_ack); check(save_stream(game) == rollback_bytes && revision == original_revision && session->advertising_checkpoint().last_request_id == last_id && session->rand().calls() == original_watcom.calls() && session->game().calls() == original_game_rng.calls(), "failed advertising ACK restores native state, revision and consumed request id"); game.manager_records[name_byte] = old_name; unchanged(); auto action = accept(); auto expected = game; check(accept_advertising_offer(expected, action.advertising_action.offer).status == AdvertisingOfferStatus::accepted, "independent source commit accepts the two-board offer"); const auto expected_bytes = save_stream(expected); const int32_t cash_before = signed_u32(game.manager_records, record + 0x314); const auto advertising_exe = load_le(asset_path(data, "BMH.exe")); check(!flow.move_action( advertising_exe.u16(::bmh::layout::Advertising_Click_RuntimeField3 + 18 * 2) + 2, advertising_exe.u16(::bmh::layout::Advertising_Click_RuntimeField4 + 18 * 2) + 2).changed, "accepted offer remembers a moved pointer while its pending browser stays frozen"); serve(action); check(flow.state_json().find("\"hovered_target\":18") != std::string::npos, "accepted final offer resumes current hover outside its original contract target"); check(save_stream(game) == expected_bytes && revision == original_revision + 1 && !flow.pending_advertising_action() && flow.screen_name() == "advertising" && flow.desktop()->state().revision == revision && signed_u32(game.manager_records, record + 0x314) == cash_before && session->rand().seed() == original_watcom.seed() && session->rand().calls() == original_watcom.calls() && session->game().seed() == original_game_rng.seed() && session->game().calls() == original_game_rng.calls(), "accepted advertisement matches Core bytes, refreshes desk once, and draws neither RNG nor immediate cash"); const auto projection = advertising_from_game(game, manager, revision); check(projection.finance_preview.income == advertising_from_game(expected, manager, revision).finance_preview.income, "accepted advertising finance preview is coherent with the committed contracts"); const auto committed_bytes = save_stream(game); const auto committed_revision = revision; serve(action); std::string error; check(!session->dispatch_advertising(action.advertising_action, revision, error) && save_stream(game) == committed_bytes && revision == committed_revision, "replayed accepted advertisement cannot consume a second revision or another offer"); } void check_player_league_visibility_controller(const std::filesystem::path& data) { const auto exe=load_le(asset_path(data,"BMH.exe"));const auto visible=player_league_count(exe); if(visible==5)return; app::CareerSession session(data,0x1789abcd);const auto before=save_stream(session.state()); const auto game=session.game();const auto random=session.rand();SetupOptions options;options.world=false;options.league=true;options.managers=1; const auto context=session.selection_context(0);ManagerChoice choice;choice.master_club=context.club_order[0];choice.name="Visibility";choice.start_league=visible; std::string error; check(!session.confirm_manager(options,choice,error)&&!error.empty()&&save_stream(session.state())==before&&session.game().calls()==game.calls()&&session.rand().calls()==random.calls(),"hidden target league changed initial options/state/RNG"); int first=0;for(int league=0;league