// SPDX-License-Identifier: GPL-3.0-only #include "formats/executable_layout.hpp" #pragma once #include #include #include "game/national.hpp" #include "game/pending_offer.hpp" // Explicit in-memory controls, never presented as untouched Original saves. // The base is a loaded national desk. Only its order prefix, a selected national // row (owner0 control), and one fully declared format field-shaped offer change. namespace national_pending_control { constexpr uint32_t offers=::bmh::layout::OfferSlots, list=::bmh::layout::EditorList+40*0x58; constexpr size_t pool=0xb70+40, record_size=0xb0c, board_size=0x840, row_size=0x58; inline int record_team(const bmh::GameState& g,int owner) { const size_t at=size_t(owner)*record_size+0x290; return int(g.manager_records.at(at)) | int(g.manager_records.at(at+1))<<8; } inline uint32_t read(const std::vector& v,size_t at) { uint32_t n=0;for(int i=0;i<4;++i)n|=uint32_t(v.at(at+size_t(i)))<<(8*i);return n; } inline void write(std::vector& v,size_t at,uint32_t n) { for(int i=0;i<4;++i)v.at(at+size_t(i))=uint8_t(n>>(8*i)); } inline bool contains(const bmh::GameState& g,int team,int player) { const auto r=bmh::squad_range(team); for(size_t i=r.first;i{bmh::kNoTeam} || !g.memory.u8(::bmh::layout::CoachActive) || owner<0 || owner>=g.memory.u8(::bmh::layout::OriginalManagerCount)) throw std::runtime_error("control requires a genuine national takeover and retained owner"); Offer o;o.owner=owner;o.seller=record_team(g,owner==0?4:owner); const auto seller=bmh::squad_range(o.seller); for(size_t row=0;row=g.players.size())continue; o.player=player;o.seller_row=int(row);break; } if(o.player<0)throw std::runtime_error("control seller has no actual player"); const int parked=record_team(g,4); for(int team=0;team<90;++team) { if(team==o.seller || team==parked || g.manager_of(team)>=0 || contains(g,team,o.player))continue; const auto r=bmh::squad_range(team); for(size_t at=r.first;at=0)break; } if(o.buyer<0)throw std::runtime_error("control has no genuine AI buyer with room"); const auto runtime=bmh::squad_range(owner==0?bmh::kNoTeam:o.seller); o.row=owner==0?2:o.seller_row;o.anchor=int(runtime.first)+o.row; if(owner==0)g.squad_slots.at(size_t(o.anchor))=uint16_t(o.player); const size_t board=size_t(owner)*board_size+size_t(o.row)*row_size; g.tactics.at(board+0x0c)=24; o.salary=std::max(100000u,read(g.tactics,board+0x50)+1000u); // NO also reads the seller's club row against param8's board, rather than // the national anchor row. Set both explicit controls above the old salary. o.salary=std::max(o.salary,read(g.tactics,size_t(owner)*board_size+size_t(o.seller_row)*row_size+0x50)+1000u); for(int raw=0;raw<4;++raw){g.memory.set32(offers+uint32_t(raw)*4,0xffffffffu);g.squad_slots.at(pool+size_t(raw))=0xfff;} for(uint32_t byte=0;byte<0x58;++byte)g.memory.set8(list+byte,0); for(uint32_t bid=0;bid<4;++bid)g.memory.set16(list+bid*2,0xffff); g.memory.set16(list,uint16_t(o.buyer));g.memory.set16(list+8,uint16_t(o.seller)|0x8000u); g.memory.set32(list+0x0c,o.salary);g.memory.set32(list+0x1c,o.fee);g.memory.set8(list+0x34,24); g.memory.set32(offers,uint32_t(o.player)*1024u+uint32_t(owner)+(salary?0x80000000u:0)); g.squad_slots.at(pool)=uint16_t(o.player); int position=-1; for(int i=0;i