(by Codex) Import verified Diamond 3.7 native save containers
This commit is contained in:
1 parent
8862bd4f89
commit
c6341aa4f9
8 files changed
+128
-5
No files matched your search
@@ -1189,3 +1189,12 @@ add_test(NAME bank_robbery_month_tests COMMAND bank_robbery_month_tests)
|
||||
add_executable(monthly_dividend_tests tests/monthly_dividend_tests.cpp)
|
||||
target_link_libraries(monthly_dividend_tests PRIVATE bmhui)
|
||||
add_test(NAME monthly_dividend_tests COMMAND monthly_dividend_tests)
|
||||
|
||||
add_executable(native_save_version_tests tests/native_save_version_tests.cpp)
|
||||
target_link_libraries(native_save_version_tests PRIVATE bmhcore)
|
||||
add_test(NAME native_save_version_tests COMMAND native_save_version_tests)
|
||||
add_executable(native_save_import_tests tests/native_save_import_tests.cpp ${BMH_APP_CONTROLLER_SOURCE} ${BMH_APP_SESSION_SDL_SOURCE})
|
||||
target_link_libraries(native_save_import_tests PRIVATE bmhui openbmh_audio ${BMH_SDL_TARGET})
|
||||
set(BMH_TEST_NATIVE_SAVE_IMPORT_INPUT "" CACHE FILEPATH "External native save for import compatibility; not distributed")
|
||||
bmh_add_data_test(NAME native_save_import_tests REQUIRED_OPTIONS BMH_TEST_NATIVE_SAVE_IMPORT_INPUT
|
||||
COMMAND native_save_import_tests "${BMH_DATA}" "${BMH_TEST_NATIVE_SAVE_IMPORT_INPUT}")
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/native_save_version.hpp"
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "game/calendar.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
@@ -586,7 +587,7 @@ CareerSession::CareerSession(const std::filesystem::path& data, uint32_t watcom_
|
||||
session_id_ = next_session_id.fetch_add(1, std::memory_order_relaxed);
|
||||
initialize_club_modal_runtime();
|
||||
const Savegame file = load_savegame(save_path);
|
||||
if (!file.checksum_ok || file.version != "V2.24") throw std::runtime_error("savegame: unsupported or damaged FBM");
|
||||
require_native_savegame(file);
|
||||
const DbCounts counts{exe_.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField), exe_.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField3), exe_.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField2), exe_.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField4)};
|
||||
const SaveState save(file.stream, counts);
|
||||
g_ = GameState::from_save(save, counts);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "formats/fbm.hpp"
|
||||
#include <string_view>
|
||||
|
||||
namespace bmh {
|
||||
// Verified German V2.24 state layout: the supplied Diamond 3.7 changes its
|
||||
// container label, while retaining the same block order and database counts.
|
||||
// Expanded careers have their own layout and must not accept these markers.
|
||||
inline bool supported_native_save_version(std::string_view version, bool expanded = false) {
|
||||
return expanded ? version == "O1.1" : version == "V2.24" || version == "V3.7";
|
||||
}
|
||||
inline void require_native_savegame(const Savegame& save, bool expanded = false) {
|
||||
if (!save.checksum_ok) throw FormatError("savegame: FBM checksum mismatch");
|
||||
if (!supported_native_save_version(save.version, expanded))
|
||||
throw FormatError("savegame: unsupported FBM version " + save.version);
|
||||
// Callers still parse the complete state using the installed edition's
|
||||
// exact DbCounts; a recognized marker never bypasses layout validation.
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/native_save_version.hpp"
|
||||
#include "formats/badge_policy.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/desk_state.hpp"
|
||||
@@ -690,8 +691,7 @@ DeskState desk_from_game(const GameState& g, const LeImage& exe, uint64_t revisi
|
||||
|
||||
DeskState load_reference_desk(const std::filesystem::path& path, const LeImage& exe) {
|
||||
auto fbm = load_savegame(path);
|
||||
if (!fbm.checksum_ok) throw FormatError("desk: FBM checksum mismatch");
|
||||
if (fbm.version != "V2.24") throw FormatError("desk: unsupported FBM version");
|
||||
require_native_savegame(fbm);
|
||||
DbCounts counts{exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField3), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField2), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField4)};
|
||||
SaveState save(fbm.stream, counts);
|
||||
auto d = desk_from_save(save, exe);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/native_save_version.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/preparation.hpp"
|
||||
|
||||
@@ -93,7 +94,7 @@ PreparationState preparation_from_game(const GameState& game, const LeImage& exe
|
||||
|
||||
PreparationState load_preparation_reference(const std::filesystem::path& path, const LeImage& exe) {
|
||||
const auto fbm = load_savegame(path);
|
||||
if (!fbm.checksum_ok || fbm.version != "V2.24") throw FormatError("preparation: unsupported/damaged FBM");
|
||||
require_native_savegame(fbm);
|
||||
const DbCounts counts{exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField3), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField2), exe.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField4)};
|
||||
const SaveState save(fbm.stream, counts);
|
||||
PreparationState result;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/native_save_version.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/save_load.hpp"
|
||||
|
||||
@@ -185,7 +186,8 @@ bool SaveLoadScreen::info_press(int x, int y) {
|
||||
try {
|
||||
const auto saved = load_savegame(entries_.at(size_t(selected_)).path);
|
||||
const auto& h = saved.plain_header;
|
||||
if (!saved.checksum_ok || saved.version != "V2.24" || h.size() < 172 || h[0] < 1 || h[0] > 4)
|
||||
require_native_savegame(saved);
|
||||
if (h.size() < 172 || h[0] < 1 || h[0] > 4)
|
||||
throw FormatError("save/load: invalid native information header");
|
||||
const auto field = [&](size_t at, size_t count) {
|
||||
const auto end = h.begin() + at + count;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "app/controller.hpp"
|
||||
#include "formats/native_save_version.hpp"
|
||||
#include "game/save.hpp"
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace bmh;using namespace bmh::ui;
|
||||
namespace {void check(bool value,const char* why){if(!value)throw std::runtime_error(why);}}
|
||||
int main(int argc,char** argv)try {
|
||||
if(argc<3||!*argv[1]||!*argv[2])return 77;
|
||||
const std::filesystem::path data=argv[1],input=argv[2];const auto unchanged=read_file(input);
|
||||
const auto container=load_savegame(input);require_native_savegame(container);
|
||||
app::CareerSession imported(data,713,input);const auto desk=imported.desktop_projection(1);
|
||||
check(desk.manager_slot>=0&&!desk.manager_name.empty(),"unchanged external save did not produce an actual career desk");
|
||||
const auto exe=load_le(asset_path(data,"BMH.exe"));
|
||||
check(load_reference_desk(input,exe).manager_slot==desk.manager_slot,"read-only desktop importer rejects an accepted version");
|
||||
check(load_preparation_reference(input,exe).desktop.manager_slot==desk.manager_slot,"preparation importer rejects an accepted version");
|
||||
const auto directory=std::filesystem::temp_directory_path()/("openbmh-native-import-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
||||
std::filesystem::create_directories(directory);
|
||||
try {
|
||||
std::filesystem::copy_file(input,directory/"IMPORT.FBM");
|
||||
SaveLoadScreen browser(data,directory,SaveLoadMode::load,desk.manager_slot,1,Image(320,240));
|
||||
check(browser.info_press(80,45)&&browser.info_open(),"load-list information rejects the accepted original save");
|
||||
StartupFlow flow(data,directory);std::unique_ptr<app::CareerSession> session;uint64_t revision=0;
|
||||
openbmh::audio::Playback playback;std::optional<uint64_t> audio;
|
||||
flow.click(214,215);
|
||||
check(flow.screen_name()=="save_load","setup did not open the actual game browser");
|
||||
const auto request=flow.send_key("ENTER");check(request.request==FlowRequest::file_action,"browser did not emit the original save load request");
|
||||
const auto result=app::serve_flow_request(flow,request,session,data,directory,713,revision,playback,audio,false);
|
||||
check(result.empty()&&session&&flow.screen_name()=="desktop","shared production controller rejects the original version");
|
||||
const auto output=directory/"ROUNDTRIP.FBM";std::string error;
|
||||
check(imported.save_game(output,desk.manager_slot,false,error),"regular session save rejected the imported original career");
|
||||
const auto saved=load_savegame(output);require_native_savegame(saved);
|
||||
app::CareerSession reloaded(data,911,output);
|
||||
check(reloaded.desktop_projection(1).manager_slot==desk.manager_slot&&
|
||||
save_stream(reloaded.state())==save_stream(imported.state()),
|
||||
"ordinary save/reload changed the imported career's native state");
|
||||
check(read_file(input)==unchanged,"original input save was changed");
|
||||
std::filesystem::remove_all(directory);
|
||||
}catch(...){std::filesystem::remove_all(directory);throw;}
|
||||
std::cout<<"Unchanged external "<<container.version<<" imported through CareerSession, desktop/preparation and load-list/controller; ordinary session save/reload passed\n";return 0;
|
||||
}catch(const std::exception& error){std::cerr<<error.what()<<'\n';return 1;}
|
||||
@@ -0,0 +1,47 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/native_save_version.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "formats/savestate.hpp"
|
||||
#include "game/save.hpp"
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace bmh;
|
||||
namespace {
|
||||
void check(bool value,const char* why){if(!value)throw std::runtime_error(why);}
|
||||
template<class F>void rejects(F function,const char* message){bool rejected=false;try{function();}catch(const FormatError&){rejected=true;}check(rejected,message);}
|
||||
}
|
||||
int main()try {
|
||||
GameState state;state.manager_records.resize(5*0xb0c);state.manager_teams={0};state.club_ids={0};state.club_names={'Q',0};
|
||||
state.memory.add_block(layout::ManagerCount,1);state.memory.set8(layout::ManagerCount,1);
|
||||
WatcomRandom random(713);const auto original=make_savegame(state,random);
|
||||
for(const char* version:{"V2.24","V3.7"}) {
|
||||
auto saved=original;saved.version=version;require_native_savegame(saved);
|
||||
const SaveState parsed(saved.stream);check(!parsed.blocks().empty(),"recognized synthetic native layout does not parse");
|
||||
auto truncated=saved;truncated.stream.pop_back();
|
||||
rejects([&]{require_native_savegame(truncated);(void)SaveState(truncated.stream);},"recognized version bypassed strict state/trailer validation");
|
||||
auto counts=DbCounts{};++counts.players;
|
||||
rejects([&]{require_native_savegame(saved);(void)SaveState(saved.stream,counts);},"recognized version bypassed installed database dimensions");
|
||||
}
|
||||
for(const char* version:{"V2.20","V3.70","v3.7","V9.99","O1.1","O1.2",""}) {
|
||||
auto saved=original;saved.version=version;
|
||||
rejects([&]{require_native_savegame(saved);},"unknown/different-layout native version was accepted");
|
||||
}
|
||||
check(supported_native_save_version("O1.1",true)&&!supported_native_save_version("V2.24",true)&&
|
||||
!supported_native_save_version("V3.7",true)&&!supported_native_save_version("V2.20",true),
|
||||
"expanded layout accepted a classic/English marker or rejected its own version");
|
||||
auto damaged=original;damaged.checksum_ok=false;
|
||||
try{require_native_savegame(damaged);throw std::runtime_error("checksum failure was accepted");}
|
||||
catch(const FormatError& error){check(std::string(error.what()).find("checksum mismatch")!=std::string::npos,"checksum failure was confused with version support");}
|
||||
auto unsupported=original;unsupported.version="V2.20";
|
||||
try{require_native_savegame(unsupported);throw std::runtime_error("different-layout version was accepted");}
|
||||
catch(const FormatError& error){check(std::string(error.what()).find("unsupported FBM version V2.20")!=std::string::npos,"version rejection lost its actual marker");}
|
||||
const auto path=std::filesystem::temp_directory_path()/("openbmh-version-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count())+".FBM");
|
||||
auto version37=original;version37.version="V3.7";write_savegame(path,version37);const auto loaded=load_savegame(path);
|
||||
require_native_savegame(loaded);check(loaded.version=="V3.7"&&loaded.stream==original.stream,"synthetic V3.7 container roundtrip changed its state");
|
||||
auto bytes=read_file(path);bytes.back()^=1;{std::ofstream file(path,std::ios::binary|std::ios::trunc);file.write(reinterpret_cast<const char*>(bytes.data()),std::streamsize(bytes.size()));}
|
||||
const auto corrupt=load_savegame(path);std::filesystem::remove(path);
|
||||
rejects([&]{require_native_savegame(corrupt);},"actual corrupt container checksum was accepted");
|
||||
std::cout<<"Known native save versions, separate expanded layout, strict dimensions/trailers and checksum/version diagnostics passed\n";return 0;
|
||||
}catch(const std::exception& error){std::cerr<<error.what()<<'\n';return 1;}
|
||||
Reference in new issue
Block a user