(by Codex) Import verified Diamond 3.7 native save containers

This commit is contained in:
Codex committed 2026-11-01 19:39:08 +01:00
1 parent 8862bd4f89
commit c6341aa4f9
8 files changed
+128 -5

No files matched your search

+2 -1
View File
@@ -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);
+20
View File
@@ -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.
}
}
+2 -2
View File
@@ -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);
+2 -1
View File
@@ -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;
+3 -1
View File
@@ -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;