Preserve human manager identity through national coach record swaps (by Codex)
This commit is contained in:
1 parent
ce1535fe2d
commit
693744a961
16 files changed
+203
-21
No files matched your search
@@ -0,0 +1,27 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Authored frozen coach records; no original data or simulated game decisions.
|
||||
#include "modern/content/ui_contract.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
using namespace bmh;
|
||||
namespace {using J=cli::Json;using O=J::Object;const J& at(const J& j,const char* k){return j.object()->at(k);}void check(bool ok,const char* why){if(!ok)throw std::runtime_error(why);}}
|
||||
int main() try {
|
||||
modern::ModernState g;g.manager_records.resize(5*0xb0c);g.manager_ids={"manager:1","manager:2","manager:3","manager:4"};g.manager_serial=4;g.manager_teams={no_team()};g.world_club_id.resize(no_team()+1);g.world_club_name.resize(no_team()+1);
|
||||
for(int i=0;i<4;++i){g.world_club_id[i]="club:"+std::to_string(i);g.world_club_name[i]="Club "+std::to_string(i);g.manager_presentations.push_back({g.manager_ids[i],"Human "+std::string(1,char('A'+i)),i%2?"photo":"painted"});}
|
||||
g.world_club_id[no_team()]="nation:de";g.world_club_name[no_team()]="Synthetic Nation";
|
||||
for(int r=0;r<5;++r){const auto team=r==0?no_team():r==4?0:r;const auto record=size_t(r)*0xb0c;g.manager_records[record+0x290]=team&255;g.manager_records[record+0x291]=(team>>8)&255;const std::string name=r==0?"Raw C":r==4?"Raw A":"Raw "+std::string(1,char('A'+r));for(size_t n=0;n<name.size();++n)g.manager_records[record+0xa8+n]=name[n];g.manager_records[record+0x221]=r==0?2:r==4?0:r;}
|
||||
g.manager_records[2*0xb0c+0x21c]=1;
|
||||
g.memory.add_block(layout::CoachActive,1);g.memory.set8(layout::CoachActive,1);g.memory.add_block(layout::OriginalManagerCount,1);g.memory.set8(layout::OriginalManagerCount,4);g.memory.add_block(layout::CompetitionSelection,4);g.memory.set32(layout::CompetitionSelection,3);
|
||||
check(g.human_manager_slot(0)==2&&g.manager_record_slot(2)==0&&g.manager_record_slot(0)==4&&g.human_manager_slot(4)==0,"coach/backup record mapping wrong");
|
||||
const auto bytes=g.manager_records;modern::UiContext c;c.manager=0;const auto session=modern::ui_read(g,c,O{{"kind","session"}});check(*at(at(session,"meta"),"scope").object()->at("managerId").string()=="manager:3","scope owns wrong human");
|
||||
const auto &people=*at(at(session,"data"),"managers").array();check(people.size()==4,"waiting humans disappeared");std::set<std::string> ids;
|
||||
for(int i=0;i<4;++i){const auto &m=people.at(size_t(i));check(*at(m,"id").string()==g.manager_ids[i],"human IDs reordered");ids.insert(*at(m,"id").string());check(*at(m,"teamId").string()==(i==2?"nation:de":"club:"+std::to_string(i)),"waiting human club lost");}
|
||||
check(ids.size()==4&&*at(people[0],"name").string()=="Human A"&&*at(people[2],"name").string()=="Human C","canonical coach names mixed");
|
||||
const auto desk=modern::ui_read(g,c,O{{"kind","desktop"},{"managerId","manager:3"}});const auto &manager=at(at(desk,"data"),"manager");check(*at(manager,"id").string()=="manager:3"&&*at(manager,"portraitGuiKey").string()=="gui:manager/painted/2","coach portrait/name belongs to wrong person");check(*at(manager,"slot").integer()==2&&*at(manager,"runtimeSlot").integer()==0,"human and runtime slot conflated");
|
||||
const auto wrong=modern::ui_read(g,c,O{{"kind","desktop"},{"managerId","manager:1"}});check(*at(wrong,"code").string()=="manager_not_active","displaced human may own coach request");
|
||||
g.manager_presentations.clear();const auto old=modern::ui_read(g,c,O{{"kind","desktop"}});check(*at(at(at(old,"data"),"manager"),"name").string()=="Raw C"&&*at(at(at(old,"data"),"manager"),"id").string()=="manager:3","older save fallback lost coach identity");check(bytes==g.manager_records,"projection changed original records");
|
||||
g.memory.set32(layout::CompetitionSelection,2);check(g.human_manager_slot(0)==0,"world-only source chooser is not first human");g.memory.set8(layout::CoachActive,0);g.manager_teams={0,1,2,3};check(g.human_manager_slot(2)==2&&g.manager_record_slot(0)==0,"normal club mapping changed");
|
||||
std::cout<<"coach stable identity, backup clubs, older metadata and read-only projection passed\n";return 0;
|
||||
} catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "modern/app/modern_session.hpp"
|
||||
#include "modern/content/world_package.hpp"
|
||||
#include "modern/ui/demo_opening.hpp"
|
||||
#include "modern/game/national.hpp"
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
@@ -12,7 +13,7 @@ using namespace bmh::modern_ui;
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
const std::string mode=argc>1?argv[1]:"";
|
||||
const std::set<std::string> modes{"prepare","prepare-two","prepare-national","prepare-almanac","inspect","inspect-friendlies","inspect-almanac","verify","verify-lineup","verify-sports","verify-bank","verify-commerce","verify-contracts","verify-calendar","verify-friendlies","verify-national","verify-almanac","verify-shootouts","verify-reports","verify-fixtures","verify-other","verify-rankings","prepare-rankings-archived","verify-create"};
|
||||
const std::set<std::string> modes{"prepare","prepare-two","prepare-national","prepare-almanac","inspect","inspect-friendlies","inspect-almanac","verify","verify-lineup","verify-sports","verify-bank","verify-commerce","verify-contracts","verify-calendar","verify-friendlies","verify-national","verify-almanac","verify-shootouts","verify-reports","verify-fixtures","verify-other","verify-rankings","prepare-rankings-archived","verify-create","inspect-coach-identity","prepare-coach-identity","verify-coach-almanac"};
|
||||
if(argc!=4||!modes.contains(mode))throw std::runtime_error("usage: modern_engine_bridge_probe <prepare[-two|-national|-almanac]|inspect[-friendlies|-almanac]|verify[-lineup|-sports|-bank|-commerce|-contracts|-calendar|-friendlies|-national|-almanac|-shootouts]> <world.obw> <new-output-directory>");
|
||||
const fs::path world = argv[2], out = argv[3]; fs::create_directories(out);
|
||||
const auto write = [&](const char *file, const Json &j) { editor::write_atomic(out / file, j.dump(2)); };
|
||||
@@ -85,6 +86,45 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
write("receipt.json",{{"status","passed"},{"cases",cases},{"invalidRequests",7},{"nationalOnly",true}});std::cout<<"real career creation, multiple managers, UTF-8, portrait styles and reload passed\n";return 0;
|
||||
}
|
||||
if(mode=="inspect-coach-identity") {
|
||||
auto package=modern::open_world_package(world);content::Mount mount(world,package.classic);modern::set_current_world(package.world);modern::app::ModernSession session(mount.root(),1u,out/"input.obs",false);
|
||||
auto &g=session.state();modern::UiContext context;context.manager=0;
|
||||
const auto before=Json::parse(cli::dump_json(modern::ui_read(g,context,cli::Json::Object{{"kind","session"}})));write("before.json",before);const auto expected=before.at("data").at("managers").at(2);
|
||||
for(int i=0;i<4;++i)g.manager_records[size_t(i)*0xb0c+0x21c]=i==2?1:0;
|
||||
modern::national_coach_take_over(g,0,2);
|
||||
const auto after=Json::parse(cli::dump_json(modern::ui_read(g,context,cli::Json::Object{{"kind","desktop"}})));write("after.json",after);
|
||||
const auto session_after=Json::parse(cli::dump_json(modern::ui_read(g,context,cli::Json::Object{{"kind","session"}})));write("session-after.json",session_after);
|
||||
write("observations.json",{{"qa_only_eligibility_flags",true},{"chosenHumanSlot",2},{"expected",expected},{"actual",after.at("data").at("manager")},{"ownerMatches",after.at("meta").at("scope").at("managerId")==expected.at("id")},{"nameMatches",after.at("data").at("manager").at("name")==expected.at("name")}});
|
||||
const auto records=g.manager_records;const auto repeated=Json::parse(cli::dump_json(modern::ui_read(g,context,cli::Json::Object{{"kind","desktop"}})));if(repeated!=after||g.manager_records!=records)throw std::runtime_error("coach projection changed records");
|
||||
modern::national_coach_hand_back(g);const auto returned=Json::parse(cli::dump_json(modern::ui_read(g,context,cli::Json::Object{{"kind","session"}})));write("returned.json",returned);
|
||||
if(after.at("meta").at("scope").at("managerId")!=expected.at("id")||after.at("data").at("manager").at("name")!=expected.at("name")||returned.at("data")!=before.at("data"))throw std::runtime_error("coach identity or handback changed humans");
|
||||
if(session_after.at("data").at("managers").size()!=4)throw std::runtime_error("waiting human managers disappeared");
|
||||
modern::set_current_world(nullptr);std::cout<<"coach identity and handback verified\n";return 0;
|
||||
}
|
||||
if(mode=="prepare-coach-identity") {
|
||||
{
|
||||
auto package=modern::open_world_package(world);content::Mount mount(world,package.classic);modern::set_current_world(package.world);modern::app::ModernSession session(mount.root(),1u,out/"input.obs",false);uint64_t revision=0;Json expiry=Json::object(),log=Json::array();bool found=false;
|
||||
for(int turn=0;turn<400;++turn) {
|
||||
auto &g=session.state();if(g.manager_teams.size()==4)for(int i=0;i<4;++i)g.manager_records[size_t(i)*0xb0c+0x21c]=i==2?1:0;
|
||||
const auto desk=Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind","desktop"}},revision)));
|
||||
if(desk.at("meta").at("scope").at("role")=="national") {write("national.json",desk);if(desk.at("data").at("manager").at("id")!="manager:3")throw std::runtime_error("unexpected coach in controlled career");found=true;break;}
|
||||
const auto &meta=desk.at("meta");const Json command={{"messageType","command"},{"contractVersion",meta.at("contractVersion")},{"requestId","request:coach-advance-"+std::to_string(turn)},{"careerId",meta.at("careerId")},{"expectedRevision",meta.at("stateRevision")},{"owner",{{"managerId",meta.at("scope").at("managerId")}}},{"kind","session.advance"},{"payload",{{"contractExpiry",expiry}}}};
|
||||
const auto reply=Json::parse(cli::dump_json(session.ui_command(cli::parse_json(command.dump()),revision)));log.push_back(reply);
|
||||
if(reply.value("messageType","")=="command_result")continue;if(reply.value("code","")=="decision_pending"){expiry[reply.at("message").at("args").at("playerId").get<std::string>()]={{"action","release"}};continue;}throw std::runtime_error(reply.dump());
|
||||
}
|
||||
write("advance.json",log);if(!found)throw std::runtime_error("controlled national desk not reached");std::string error;if(!session.save_game(out/"national.obs",0,false,error))throw std::runtime_error(error);
|
||||
const auto presentations=session.state().manager_presentations;session.state().manager_presentations.clear();if(!session.save_game(out/"national-legacy.obs",0,false,error))throw std::runtime_error(error);session.state().manager_presentations=presentations;
|
||||
}
|
||||
modern::set_current_world(nullptr);auto loaded=EngineBridge::open(world,out/"national.obs");const auto read=loaded->snapshot();write("loaded.json",read);if(read.at("desktop").at("data").at("manager").at("id")!="manager:3"||read.at("session").at("data").at("managers").size()!=4)throw std::runtime_error("coach identity lost on reload");std::cout<<"controlled real national desk with third human saved and reloaded\n";return 0;
|
||||
}
|
||||
if(mode=="verify-coach-almanac") {
|
||||
auto package=modern::open_world_package(world);content::Mount mount(world,package.classic);modern::set_current_world(package.world);modern::app::ModernSession session(mount.root(),1u,out/"input.obs",false);uint64_t revision=0;
|
||||
const auto initial=session.state().almanac.current.matches.size();const auto desk=Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind","desktop"}},revision)));const auto &meta=desk.at("meta");
|
||||
const Json command={{"messageType","command"},{"contractVersion",meta.at("contractVersion")},{"requestId","request:coach-match"},{"careerId",meta.at("careerId")},{"expectedRevision",meta.at("stateRevision")},{"owner",{{"managerId",meta.at("scope").at("managerId")}}},{"kind","session.advance"},{"payload",Json::object()}};
|
||||
const auto reply=Json::parse(cli::dump_json(session.ui_command(cli::parse_json(command.dump()),revision)));write("advance.json",reply);if(reply.value("messageType","")!="command_result")throw std::runtime_error(reply.dump());
|
||||
const auto &season=session.state().almanac.current;bool found=false;Json recorded=Json::array();for(size_t i=initial;i<season.matches.size();++i){const auto &match=season.matches[i];for(int manager:{int(match.home_manager),int(match.away_manager)})if(manager>=0){const auto &person=season.managers.at(size_t(manager));recorded.push_back({{"managerIndex",person.index},{"name",person.name},{"matchType",match.type}});if(match.type==7||match.type==8){if(person.index!=2||person.name!="Alex Berger")throw std::runtime_error("national archive used another human");found=true;}}}
|
||||
if(!found)throw std::runtime_error("no human national match recorded");write("recorded-managers.json",recorded);write("returned.json",Json::parse(cli::dump_json(session.ui_read(cli::Json::Object{{"kind","session"}},revision))));std::string error;const int active=session.state().memory.u8(::bmh::layout::ActiveManager);if(!session.save_game(out/"after-national.obs",active,false,error))throw std::runtime_error(error);modern::set_current_world(nullptr);std::cout<<"national archive attributed to third human\n";return 0;
|
||||
}
|
||||
auto link = EngineBridge::open(world, out / "input.obs");
|
||||
const auto before = link->snapshot(); write("before.json", before);
|
||||
if (before != link->snapshot()) throw std::runtime_error("reads changed the engine projection");
|
||||
|
||||
Reference in new issue
Block a user