// SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #include #include #include #include #include "app/career_session.hpp" #include "game/save.hpp" #include "national_coach_desk_pending_fixture.hpp" using namespace bmh; namespace { void check(bool ok,const char* why){if(!ok)throw std::runtime_error(why);} auto request(const GameState& g){return PendingOfferDeskRequest{ PendingOfferDeskRuntimeMode::normal_interactive,int(g.manager_teams.size()),int(g.memory.u8(::bmh::layout::DeskPosition))};} TurnAdvanceResult advance(app::CareerSession& s,uint64_t& revision){ std::string error; return s.dispatch_kickoff({ui::DeskRequestKind::advance_turn,int(s.state().memory.u8(::bmh::layout::ActiveManager)), -1,-1,-1,revision},revision,error); } void test(const std::filesystem::path& data,const std::filesystem::path& input){ app::CareerSession session(data,8128,input); // Explicit test decision policy for the June->July contract boundary reached // after this match. Production still owns the actual contract screen. session.set_contract_expiry_presenter([](GameState&,WatcomRandom&,int,int){return 0;}); session.set_pending_offer_entry_policy(app::PendingOfferEntryPolicy::normal_interactive); const auto checkpoint=session.manager_join_checkpoint();const auto& original=checkpoint.state; check(original.date==1453 && original.manager_teams==std::vector{kNoTeam} && original.memory.u8(::bmh::layout::CoachActive)==1,"normal fixture must be the genuine Germany-Italy takeover"); // The Original searches these club players in the national squad and // displays error58. OpenBMH deliberately keeps its final cleanup/state, // without requiring the user to acknowledge this known context mismatch. const auto range=squad_range(kNoTeam); int owned=0; for(int raw=0;raw<4;++raw){const auto word=original.memory.u32(::bmh::layout::OfferSlots+raw*4); if(word==0xffffffffu)continue; check((word&31)==0,"fixture offer belongs to inherited manager0");++owned; for(size_t i=range.first;i>10)&0xfff),"fixture offer must be absent from national squad"); } check(owned==3,"fixture has three actual club offers, not an empty batch"); auto actual=original,oracle=original;auto game=checkpoint.game;auto random=checkpoint.rand; int acknowledgements=0;PendingOfferHooks hooks; hooks.program_error=[&](const GameState&,uint16_t){++acknowledgements;}; hooks.answer=[](const auto&,const auto&)->PendingOfferAnswer{throw std::runtime_error("club salary must not resolve in spare record4");}; MinuteReport report;const auto result=process_natural_pending_offers_after_desk(actual,request(actual),game,random,hooks,report); check(result.completed && !report.unsupported && result.processed==0 && acknowledgements==0, "verified club offers in national context clean up without error58"); for(int raw=0;raw<4;++raw){oracle.memory.set32(::bmh::layout::OfferSlots+raw*4,0xffffffffu);oracle.squad_slots.at(0xb70+40+raw)=0xfff;} oracle.memory.set8(::bmh::layout::DeskPosition,1); check(save_stream(actual)==save_stream(oracle) && game.seed()==checkpoint.game.seed() && game.calls()==checkpoint.game.calls() && random.seed()==checkpoint.rand.seed() && random.calls()==checkpoint.rand.calls(),"Source oracle matches entire Native and both RNGs"); // Evidence guards: no blanket suppression for damaged pool/owner/club data. for(int variant=0;variant<4;++variant){ auto damaged=original; if(variant==0)damaged.squad_slots.at(0xb70+40)=0xfff; if(variant==1)damaged.memory.set8(::bmh::layout::OriginalManagerCount,0); if(variant==2){damaged.manager_records.at(4*0xb0c+0x290)=0x65;damaged.manager_records.at(4*0xb0c+0x291)=1;} if(variant==3){const auto club=squad_range(29);for(size_t i=club.first;i{kNoTeam} && g.memory.u8(::bmh::layout::CoachActive)==1 && g.memory.u8(::bmh::layout::OriginalManagerCount)==2 && g.memory.u8(::bmh::layout::ActiveManager)==0 && g.memory.u16(::bmh::layout::NextDeskManager)==1 && !checkpoint.driver.groups.empty() && !checkpoint.driver.national_nomination_desk, "GUI checkpoint is an actual national match with retained owner1, not a nomination-only desk"); for(int variant=0;variant<2;++variant){ auto invalid=checkpoint; if(variant==0)invalid.state.memory.set16(::bmh::layout::NextDeskManager,2); // Outside the retained two-manager roster. session.restore_manager_join_checkpoint(invalid); const auto before=save_stream(session.state());const auto game=session.game();const auto random=session.rand(); uint64_t revision=1;std::string error; const auto rejected=session.dispatch_kickoff({ui::DeskRequestKind::advance_turn, variant==1?1:0,-1,12,-1,revision},revision,error); check((rejected.kind==TurnDeskKind::Failed || rejected.kind==TurnDeskKind::WaitingAtDesk) && revision==1 && save_stream(session.state())==before && session.game().seed()==game.seed() && session.game().calls()==game.calls() && session.rand().seed()==random.seed() && session.rand().calls()==random.calls(), "invalid retained owner or runtime request remains rejected without Native/G/W/revision effects"); } session.restore_manager_join_checkpoint(checkpoint);uint64_t revision=1; const auto next=advance(session,revision); check(next.kind==TurnDeskKind::NextDesk && session.state().date>g.date, "retained owner1 no longer rejects a valid national kickoff after pending cleanup"); const auto completed=session.manager_join_checkpoint().driver; check(completed.last_results.valid && completed.last_results.date==g.date && !completed.last_results.groups.empty(), "actual national match is simulated and recorded, never skipped as a nomination day"); const auto file=std::filesystem::temp_directory_path()/ ("openbmh-national-retained-owner-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count())+".FBM"); std::string error;check(session.save_game(file,session.state().memory.u8(::bmh::layout::ActiveManager),false,error),error.c_str()); app::CareerSession fresh(data,8128,file); check(load_savegame(file).checksum_ok && save_stream(fresh.state())==save_stream(session.state()), "post-match ordinary save reloads the complete Native state"); std::filesystem::remove(file); } } int main(int argc,char**argv){try{if(argc!=4)return 2;if(!*argv[1])return 0;test(argv[1],argv[2]); retained_owner_match(argv[1],argv[3]); std::cout<<"National club-context cleanup: no spurious ACKs; real diagnostic rollback, kickoff and normal save/reload passed\n";return 0; }catch(const std::exception& e){std::cerr<