Manage real OBS careers in native save and load dialogs (by Codex)

This commit is contained in:
Codex committed 2026-10-29 02:57:32 +01:00
1 parent 693744a961
commit e3ea03a05d
25 files changed
+539 -39

No files matched your search

+32
View File
@@ -3,6 +3,7 @@
#include <algorithm>
#include <bit>
#include <cstdio>
#include <utility>
#include <variant>
#include <set>
@@ -13,6 +14,7 @@
#include "formats/native_state.hpp"
#include "import/detail.hpp"
#include "modern/game/save.hpp"
#include "formats/executable_layout.hpp"
namespace bmh::modern {
@@ -266,4 +268,34 @@ SavedWorldCareer load_world_career(const std::filesystem::path& path, const Worl
return out;
}
cli::Json world_career_metadata(const World& world,const ModernState& state) {
const bool coach=state.memory.has(::bmh::layout::CoachActive)&&state.memory.u8(::bmh::layout::CoachActive)!=0;
const int count=coach?state.memory.u8(::bmh::layout::OriginalManagerCount):int(state.manager_teams.size());
if(count<1||count>4)fail("unsupported saved manager count");
const int runtime=coach?0:state.memory.has(::bmh::layout::ActiveManager)?state.memory.u8(::bmh::layout::ActiveManager):0;
const int active=state.human_manager_slot(runtime);if(active<0||active>=count)fail("invalid saved active manager");
A managers;int active_team=-1;
for(int human=0;human<count;++human) {
const int record=state.manager_record_slot(human);const size_t at=size_t(record)*0xb0c;
if(at+0x292>state.manager_records.size())fail("saved manager record missing");
const int team=record>=0&&size_t(record)<state.manager_teams.size()?state.manager_teams[size_t(record)]:int(uint16_t(state.manager_records[at+0x290])|uint16_t(state.manager_records[at+0x291])<<8);
if(team<0||size_t(team)>=state.world_club_id.size())fail("saved manager team missing");
const auto* presentation=state.manager_presentation_for_human(human);std::string name;
if(presentation)name=presentation->name;else {for(size_t n=0;n<25&&state.manager_records[at+0xa8+n];++n)name.push_back(char(state.manager_records[at+0xa8+n]));name=almanac_utf8(name);}
const auto id=size_t(human)<state.manager_ids.size()&&!state.manager_ids[size_t(human)].empty()?state.manager_ids[size_t(human)]:"manager:slot-"+std::to_string(human);
managers.push_back(O{{"id",id},{"name",name},{"club",state.world_club_id[size_t(team)]},{"team_name",coach&&record==0?std::string("Deutschland"):size_t(team)<state.world_club_name.size()?state.world_club_name[size_t(team)]:std::string()},{"portrait",int(state.manager_records[at+0x221])},{"portrait_style",presentation?presentation->portrait_style:"photo"},{"national",coach&&record==0}});
if(human==active)active_team=team;
}
const auto date=almanac_date(state.date,state.display_start_year);char iso[16];std::snprintf(iso,sizeof iso,"%04d-%02d-%02d",date.year,date.month,date.day);
const int year=state.display_start_year+state.season,next=(year+1)%100;const auto season=std::to_string(year)+"/"+(next<10?"0":"")+std::to_string(next);std::string round="—";
if(!coach) {
std::vector<const WorldLeague*> leagues;for(const auto& l:world.leagues)if(l.index>=0)leagues.push_back(&l);std::sort(leagues.begin(),leagues.end(),[](auto* a,auto* b){return a->index<b->index;});
int first=0;for(const auto* l:leagues){const int size=int(l->members.size());if(active_team>=first&&active_team<first+size&&size>1&&size_t(l->index)<state.league_rounds.size())round=std::to_string(std::min(int(state.league_rounds[size_t(l->index)])+1,(size-1)*2))+". Spieltag";first+=size;}
}
return O{{"schema","modern-career-metadata@1"},{"career_id",state.career_id},{"world_id",world.id},{"world_revision",world.data_revision},{"date",iso},{"season",season},{"matchday",round},{"role",coach?"national":"club"},{"human_count",count},{"current_manager",managers.at(size_t(active))},{"managers",std::move(managers)}};
}
cli::Json read_world_career_metadata(const std::filesystem::path& path,const World& world) {
const auto saved=load_world_career(path,world);return world_career_metadata(world,saved.state);
}
} // namespace bmh::modern