Integrate Classic 0.2 launcher and native runtime (by Codex)
# Conflicts: # tools/public_release/check_public_tree.py # tools/public_release/test_public_tree.py
This commit is contained in:
commit
b8183e4165
108 files changed
+6344
-257
No files matched your search
@@ -1,12 +1,12 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
add_library(bmh_obw STATIC obw.cpp classic.cpp assets.cpp ../cli/json.cpp ../audio/container.cpp)
|
||||
add_library(bmh_obw STATIC obw.cpp classic.cpp assets.cpp save.cpp ../audio/container.cpp)
|
||||
target_include_directories(bmh_obw PUBLIC ..)
|
||||
target_link_libraries(bmh_obw PUBLIC bmhlaunch PRIVATE bmh_miniz)
|
||||
add_executable(openbmh_import main.cpp)
|
||||
target_link_libraries(openbmh_import PRIVATE bmh_obw)
|
||||
target_link_libraries(openbmh_import PRIVATE bmh_content)
|
||||
set_target_properties(openbmh_import PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
add_executable(obw_import_tests ../../tests/obw_import_tests.cpp)
|
||||
target_link_libraries(obw_import_tests PRIVATE bmh_obw bmh_miniz)
|
||||
target_link_libraries(obw_import_tests PRIVATE bmh_content bmh_miniz)
|
||||
if(MSVC)
|
||||
target_compile_options(bmh_obw PRIVATE /W4 /utf-8)
|
||||
target_compile_options(openbmh_import PRIVATE /W4 /utf-8)
|
||||
@@ -22,3 +22,35 @@ if(MSVC)
|
||||
endif()
|
||||
bmh_add_data_test(NAME obw_classic_installation_tests COMMAND obw_classic_installation_tests "${BMH_DATA}")
|
||||
install(TARGETS openbmh_import RUNTIME DESTINATION . COMPONENT Runtime)
|
||||
|
||||
add_library(bmh_content STATIC ../content/digest.cpp ../content/package.cpp ../content/save.cpp)
|
||||
target_include_directories(bmh_content PUBLIC ..)
|
||||
target_link_libraries(bmh_content PUBLIC bmh_obw PRIVATE bmh_miniz)
|
||||
|
||||
add_library(bmh_launcher STATIC ../launch/mods.cpp ../launch/process.cpp ../launch/launcher.cpp)
|
||||
target_include_directories(bmh_launcher PUBLIC ..)
|
||||
target_link_libraries(bmh_launcher PUBLIC bmh_content)
|
||||
include(../launch/rmlui.cmake)
|
||||
target_sources(bmh_launcher PRIVATE ../launch/launcher_rmlui.cpp)
|
||||
target_link_libraries(bmh_launcher PRIVATE bmh_rmlui nfd)
|
||||
add_executable(launcher_document_tests ../../tests/launcher_document_tests.cpp)
|
||||
target_include_directories(launcher_document_tests PRIVATE ..)
|
||||
target_link_libraries(launcher_document_tests PRIVATE RmlUi::Core)
|
||||
add_test(NAME launcher_document_tests COMMAND launcher_document_tests "${launcher_assets}")
|
||||
add_test(NAME launcher_unicode_document_tests COMMAND launcher_document_tests "${launcher_assets}" unicode)
|
||||
if(MSVC)
|
||||
target_compile_options(launcher_document_tests PRIVATE /utf-8)
|
||||
endif()
|
||||
add_executable(native_content_tests ../../tests/native_content_tests.cpp)
|
||||
target_link_libraries(native_content_tests PRIVATE bmh_launcher)
|
||||
add_test(NAME native_content_tests COMMAND native_content_tests)
|
||||
add_executable(native_runtime_tests ../../tests/native_runtime_tests.cpp ${BMH_APP_SESSION_SDL_SOURCE} ${BMH_APP_CONTROLLER_SOURCE})
|
||||
target_link_libraries(native_runtime_tests PRIVATE bmhui bmh_launcher openbmh_audio)
|
||||
bmh_add_data_test(NAME native_runtime_tests COMMAND native_runtime_tests "${BMH_DATA}")
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(bmh_content PRIVATE /W4 /utf-8)
|
||||
target_compile_options(bmh_launcher PRIVATE /W4 /utf-8)
|
||||
target_compile_options(native_content_tests PRIVATE /utf-8)
|
||||
target_compile_options(native_runtime_tests PRIVATE /utf-8)
|
||||
endif()
|
||||
+60
-4
@@ -109,7 +109,7 @@ cli::Json portrait_recipe(const std::string& legacy_name, const LeImage& exe) {
|
||||
void import_assets(Documents& out, const std::filesystem::path& root, const Database& db, const LeImage& exe) {
|
||||
using namespace detail;
|
||||
const auto palette = load_palette(required(root, "M3PC.COL"));
|
||||
A colors, index, images, fonts, audio, animations;
|
||||
A colors, index, images, fonts, audio, animations, palettes, supplemental;
|
||||
for (const auto color : palette.argb) colors.emplace_back(int64_t(color));
|
||||
put(out, "assets/classic/palette.json", O{{"schema", "classic-palette@1.0"}, {"argb", std::move(colors)}});
|
||||
std::map<std::string, Image> atlases;
|
||||
@@ -129,7 +129,21 @@ void import_assets(Documents& out, const std::filesystem::path& root, const Data
|
||||
const auto name = lower(group) + '/' + launch::path_to_utf8(path.stem());
|
||||
if (atlases.contains(name)) fail("duplicate image resource: " + name);
|
||||
auto image = decode_vga(bytes);
|
||||
image_entry(out, images, index, "asset:classic/" + name, name, image, palette);
|
||||
const size_t end = 8 + size_t(le32(bytes, 4));
|
||||
if (end > bytes.size())
|
||||
fail("invalid indexed image stream length");
|
||||
Palette effective = palette;
|
||||
if (bytes.size() - end >= 768) {
|
||||
A entries;
|
||||
for (size_t i = 0; i < 256; ++i) {
|
||||
auto channel = [&](size_t c) { return uint32_t(vga_dac_rgb8(bytes[end + i * 3 + c])); };
|
||||
effective.argb[i] = 0xff000000u | channel(0) << 16 | channel(1) << 8 | channel(2);
|
||||
entries.emplace_back(int64_t(effective.argb[i]));
|
||||
}
|
||||
palettes.emplace_back(O{{"name", name}, {"argb", std::move(entries)}});
|
||||
} else if (end != bytes.size())
|
||||
fail("truncated embedded palette");
|
||||
image_entry(out, images, index, "asset:classic/" + name, name, image, effective);
|
||||
atlases.emplace(name, std::move(image));
|
||||
}
|
||||
}
|
||||
@@ -225,8 +239,29 @@ void import_assets(Documents& out, const std::filesystem::path& root, const Data
|
||||
animations.emplace_back(O{{"name", name}, {"path", path}});
|
||||
index.emplace_back(asset("asset:classic/optional/" + name, path, name, "legacy-artwork"));
|
||||
}
|
||||
put(out, "assets/classic/resources.json", O{{"schema", "classic-resources@1.0"},
|
||||
{"images", std::move(images)}, {"fonts", std::move(fonts)}, {"audio", std::move(audio)}, {"optional", std::move(animations)}});
|
||||
// The in-game readme is content too; preserve its original byte encoding locally.
|
||||
const bool english = str(get(parse(out, "manifest.json"), "provenance")) == "import:fltd";
|
||||
const auto texts = load_textd(required(root, english ? "TEXTE.BLK" : "TEXTD.BLK"));
|
||||
if (texts.strings.size() > 839) {
|
||||
const auto name = texts[839];
|
||||
if (!name.empty() && fs::path(name) == fs::path(name).filename()) {
|
||||
if (const auto source = launch::find_file(root, name); source && fs::is_regular_file(*source)) {
|
||||
if (fs::is_symlink(fs::symlink_status(*source)) || fs::file_size(*source) > 1024 * 1024)
|
||||
fail("unsafe readme input");
|
||||
const auto path = "assets/classic/documents/readme.bytes";
|
||||
out[path] = binary(read_file(*source));
|
||||
supplemental.emplace_back(O{{"name", lower(name)}, {"path", path}});
|
||||
}
|
||||
}
|
||||
}
|
||||
put(out, "assets/classic/resources.json",
|
||||
O{{"schema", "classic-resources@1.0"},
|
||||
{"images", std::move(images)},
|
||||
{"fonts", std::move(fonts)},
|
||||
{"audio", std::move(audio)},
|
||||
{"optional", std::move(animations)},
|
||||
{"palettes", std::move(palettes)},
|
||||
{"supplemental", std::move(supplemental)}});
|
||||
put(out, "assets/index.json", O{{"schema", "asset-index@1.0"}, {"items", std::move(index)}});
|
||||
}
|
||||
|
||||
@@ -274,6 +309,27 @@ void load_assets(const Documents& out, ClassicData& data) {
|
||||
if (!openbmh::audio::parse_container(bank, parsed, error)) fail("invalid audio container: " + error);
|
||||
if (!data.audio.emplace(str(get(row, "name")), std::move(bank)).second) fail("duplicate audio bank");
|
||||
}
|
||||
if (resources.object()->contains("palettes"))
|
||||
for (const auto &row : arr(get(resources, "palettes"))) {
|
||||
const auto &colors = arr(get(row, "argb"));
|
||||
if (colors.size() != 256)
|
||||
fail("invalid embedded palette");
|
||||
Palette palette;
|
||||
for (size_t i = 0; i < 256; ++i) {
|
||||
const auto n = num(colors[i]);
|
||||
if (n < 0 || n > UINT32_MAX)
|
||||
fail("invalid color");
|
||||
palette.argb[i] = uint32_t(n);
|
||||
}
|
||||
if (!data.image_palettes.emplace(str(get(row, "name")), palette).second)
|
||||
fail("duplicate embedded palette");
|
||||
}
|
||||
if (resources.object()->contains("supplemental"))
|
||||
for (const auto &row : arr(get(resources, "supplemental"))) {
|
||||
if (!data.supplemental.emplace(str(get(row, "name")), bytes(out.at(str(get(row, "path")))))
|
||||
.second)
|
||||
fail("duplicate supplemental content");
|
||||
}
|
||||
if (!data.images.contains("kb/29") || data.fonts.size() != 2 || data.audio.size() != 4) fail("incomplete classic media");
|
||||
}
|
||||
} // namespace bmh::obw
|
||||
+108
-23
@@ -276,7 +276,7 @@ void refresh_classic_inventory(Documents& out) {
|
||||
using namespace detail;
|
||||
A inventory;
|
||||
for (const auto& [path, contents] : out)
|
||||
if (path != "x-classic/inventory.json")
|
||||
if (path != "x-classic/inventory.json" && path != "x-classic/seal.json")
|
||||
inventory.emplace_back(O{{"path", path}, {"bytes", int64_t(contents.size())}, {"crc32", int64_t(crc(contents))}});
|
||||
put(out, "x-classic/inventory.json", O{{"schema", "classic-inventory@1.0"}, {"entries", std::move(inventory)}});
|
||||
}
|
||||
@@ -287,52 +287,136 @@ static ClassicData decode_classic(const Documents& out) {
|
||||
if (str(get(startup, "schema")) != "classic-startup@1.0" || str(get(startup, "layout")) != layout_id)
|
||||
fail("unsupported classic startup/layout version");
|
||||
ClassicData data;
|
||||
const auto* en = get(startup, "english").boolean();
|
||||
if (!en) fail("invalid edition flag");
|
||||
const auto *en = get(startup, "english").boolean();
|
||||
if (!en)
|
||||
fail("invalid edition flag");
|
||||
data.english = *en;
|
||||
data.executable = load_regions(out, get(startup, "data_regions"), get(startup, "embedded_literals"), data.english);
|
||||
data.source_tables = load_regions(out, get(startup, "source_regions"), get(startup, "source_literals"), data.english);
|
||||
const auto database = parse(out, "x-legacy/source-database.json");
|
||||
data.database = decode_database(unhex(str(get(database, "bytes"))));
|
||||
data.executable =
|
||||
load_regions(out, get(startup, "data_regions"), get(startup, "embedded_literals"), data.english);
|
||||
data.source_tables =
|
||||
load_regions(out, get(startup, "source_regions"), get(startup, "source_literals"), data.english);
|
||||
// Reconstruct the native Classic database fields directly. The original M3D
|
||||
// byte stream is retained as import provenance only, never parsed at runtime.
|
||||
const auto database = parse(out, "x-legacy/database.json");
|
||||
const auto &counts = get(database, "counts");
|
||||
if (num(get(counts, "clubs")) != 419 || num(get(counts, "players")) != 2574 ||
|
||||
num(get(counts, "n42")) != 168 || num(get(counts, "n66")) != 3096)
|
||||
fail("unsupported Classic database dimensions");
|
||||
auto &db = data.database;
|
||||
const auto &pools = arr(get(database, "pools"));
|
||||
if (pools.size() != 4)
|
||||
fail("invalid native name pools");
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
db.pools[i] = unhex(str(pools[i]));
|
||||
const auto &tables = get(database, "tables");
|
||||
const auto table = [&](const char *name, Bytes &target, size_t expected) {
|
||||
target = unhex(str(get(tables, name)));
|
||||
if (target.size() != expected)
|
||||
fail(std::string("invalid Classic table size: ") + name);
|
||||
};
|
||||
table("player_bonus_values", db.raw_player_bonus_values, 3096 + 0x32);
|
||||
table("database_metadata", db.raw_database_metadata, 100);
|
||||
table("club_auxiliary_words", db.raw_club_auxiliary_words, 168 * 2);
|
||||
table("club_badge_selectors", db.raw_club_badge_selectors, 419 * 2);
|
||||
table("foreign_club_strength", db.raw_foreign_club_strength, 0xfb);
|
||||
table("league_auxiliary_bytes", db.raw_league_auxiliary_bytes, 0xbd);
|
||||
table("referee_properties", db.raw_referee_properties, 50);
|
||||
table("club_kit_selectors", db.raw_club_kit_selectors, 419);
|
||||
table("club_short_name_offsets", db.raw_club_short_name_offsets, 168);
|
||||
table("club_name_offsets", db.raw_club_name_offsets, 419 * 2);
|
||||
table("player_name_offsets", db.raw_player_name_offsets, 2574 * 2);
|
||||
table("squad_list", db.squad_list, (3096 - 4) * 2 + 0x6c);
|
||||
const auto name = [&](size_t pool, size_t offset) {
|
||||
const auto &bytes = db.pools[pool];
|
||||
if (offset >= bytes.size())
|
||||
fail("native name offset outside pool");
|
||||
const auto end = std::find(bytes.begin() + offset, bytes.end(), 0);
|
||||
if (end == bytes.end())
|
||||
fail("unterminated native name");
|
||||
return std::string(bytes.begin() + offset, end);
|
||||
};
|
||||
for (size_t i = 0; i < 419; ++i)
|
||||
db.club_names.push_back(name(0, le16(db.raw_club_name_offsets, i * 2)));
|
||||
db.players.resize(2574);
|
||||
std::set<size_t> player_ids;
|
||||
for (const auto &player : items(out, "players")) {
|
||||
const auto &raw = get(player, "x-legacy");
|
||||
const auto id = num(get(raw, "player_index"));
|
||||
if (id < 0 || id >= 2574 || !player_ids.insert(size_t(id)).second)
|
||||
fail("invalid native player identity");
|
||||
auto &value = db.players[size_t(id)];
|
||||
value.name = name(1, le16(db.raw_player_name_offsets, size_t(id) * 2));
|
||||
const auto word = [&](const char *key) {
|
||||
const auto n = num(get(raw, key));
|
||||
if (n < 0 || n > UINT32_MAX)
|
||||
fail("invalid native player word");
|
||||
return uint32_t(n);
|
||||
};
|
||||
value.w35c = word("condition_technique_form_word");
|
||||
value.w368 = word("skill_word");
|
||||
value.w364 = word("identity_word");
|
||||
}
|
||||
if (player_ids.size() != 2574)
|
||||
fail("incomplete native player records");
|
||||
const auto split = [&](size_t pool, std::vector<std::string> &values) {
|
||||
size_t at = 0;
|
||||
while (at < db.pools[pool].size()) {
|
||||
auto value = name(pool, at);
|
||||
at += value.size() + 1;
|
||||
values.push_back(std::move(value));
|
||||
}
|
||||
};
|
||||
split(2, db.referees);
|
||||
split(3, db.stadiums);
|
||||
data.desktops = bytes(out.at(str(get(startup, "desktop_seed"))));
|
||||
data.formations = bytes(out.at(str(get(startup, "formation_seed"))));
|
||||
if (data.desktops.size() != 864 || data.formations.size() != 1408) fail("invalid startup seed sizes");
|
||||
if (data.desktops.size() != 864 || data.formations.size() != 1408)
|
||||
fail("invalid startup seed sizes");
|
||||
data.texts.blob = bytes(out.at(str(get(startup, "text_blob"))));
|
||||
const auto& header = arr(get(startup, "text_header"));
|
||||
if (header.size() != 7) fail("invalid source text header");
|
||||
for (const auto& byte : header) {
|
||||
if (num(byte) < 0 || num(byte) > 255) fail("invalid source text header byte");
|
||||
const auto &header = arr(get(startup, "text_header"));
|
||||
if (header.size() != 7)
|
||||
fail("invalid source text header");
|
||||
for (const auto &byte : header) {
|
||||
if (num(byte) < 0 || num(byte) > 255)
|
||||
fail("invalid source text header byte");
|
||||
data.text_header.push_back(uint8_t(num(byte)));
|
||||
}
|
||||
size_t position = 0;
|
||||
while (data.texts.strings.size() < TEXT_COUNT && position < data.texts.blob.size()) {
|
||||
const auto begin = position;
|
||||
while (position < data.texts.blob.size() && data.texts.blob[position]) ++position;
|
||||
if (position == data.texts.blob.size()) fail("unterminated classic text");
|
||||
while (position < data.texts.blob.size() && data.texts.blob[position])
|
||||
++position;
|
||||
if (position == data.texts.blob.size())
|
||||
fail("unterminated classic text");
|
||||
data.texts.offsets.push_back(begin);
|
||||
data.texts.strings.emplace_back(data.texts.blob.begin() + begin, data.texts.blob.begin() + position);
|
||||
++position;
|
||||
}
|
||||
if (data.texts.strings.size() != TEXT_COUNT) fail("incomplete classic texts");
|
||||
if (data.texts.strings.size() != TEXT_COUNT)
|
||||
fail("incomplete classic texts");
|
||||
load_assets(out, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
void validate_classic(const Documents& out) {
|
||||
void validate_classic(const Documents &out) {
|
||||
using namespace detail;
|
||||
const auto manifest = parse(out, "manifest.json");
|
||||
const auto& imported = get(manifest, "x-import");
|
||||
const auto &imported = get(manifest, "x-import");
|
||||
if (str(get(imported, "profile")) != profile || !get(imported, "content_complete").boolean() ||
|
||||
!*get(imported, "content_complete").boolean()) fail("incomplete classic profile");
|
||||
const auto& required_features = arr(get(manifest, "requires"));
|
||||
if (required_features.size() != 1 || str(required_features[0]) != feature) fail("missing classic runtime requirement");
|
||||
!*get(imported, "content_complete").boolean())
|
||||
fail("incomplete classic profile");
|
||||
const auto &required_features = arr(get(manifest, "requires"));
|
||||
if (required_features.size() != 1 || str(required_features[0]) != feature)
|
||||
fail("missing classic runtime requirement");
|
||||
const auto startup = parse(out, "x-classic/startup.json");
|
||||
const auto expected = str(get(manifest, "provenance")) == "import:fltd" ? "FLTD-classic" : "BMH-classic";
|
||||
if (str(get(manifest, "mod")) != expected || str(get(startup, "mod")) != expected) fail("mod/edition mismatch");
|
||||
if (str(get(manifest, "mod")) != expected || str(get(startup, "mod")) != expected)
|
||||
fail("mod/edition mismatch");
|
||||
if (str(get(imported, "rule_profile")) != "openbmh-supported@1" ||
|
||||
str(get(startup, "rule_profile")) != "openbmh-supported@1" ||
|
||||
cli::dump_json(get(startup, "initializers")) != cli::dump_json(initializers) ||
|
||||
cli::dump_json(get(startup, "runtime_inputs")) != cli::dump_json(runtime_inputs)) fail("unsupported classic initialization contract");
|
||||
cli::dump_json(get(startup, "runtime_inputs")) != cli::dump_json(runtime_inputs))
|
||||
fail("unsupported classic initialization contract");
|
||||
std::set<std::string> seen;
|
||||
const auto inventory = parse(out, "x-classic/inventory.json");
|
||||
for (const auto& entry : arr(get(inventory, "entries"))) {
|
||||
@@ -345,7 +429,8 @@ void validate_classic(const Documents& out) {
|
||||
for (char& ch : suffix) ch = char(std::tolower(static_cast<unsigned char>(ch)));
|
||||
if (suffix == ".exe" || suffix == ".fbm" || suffix == ".obs" || suffix == ".ein" || suffix == ".cfg") fail("non-content file in classic world");
|
||||
}
|
||||
if (seen.size() + 1 != out.size()) fail("unlisted archive entries");
|
||||
if (seen.size() + 1 + size_t(out.contains("x-classic/seal.json")) != out.size())
|
||||
fail("unlisted archive entries");
|
||||
auto data = decode_classic(out);
|
||||
if (data.english != (std::string(expected) == "FLTD-classic")) fail("startup edition mismatch");
|
||||
// Every fixture pointer must remain readable from the exported DATA view.
|
||||
|
||||
+2
-13
@@ -1,23 +1,12 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "import/obw.hpp"
|
||||
#include "formats/font.hpp"
|
||||
#include "formats/content.hpp"
|
||||
#include "formats/palette.hpp"
|
||||
|
||||
namespace bmh::obw {
|
||||
// Installation content only. No manager choices, career RNG or save state.
|
||||
struct ClassicData {
|
||||
bool english = false;
|
||||
Database database;
|
||||
TextDb texts;
|
||||
LeImage executable; // DATA regions and four bounded literals; no instructions
|
||||
LeImage source_tables;
|
||||
Bytes desktops, formations, text_header;
|
||||
Palette palette;
|
||||
std::map<std::string, Image> images;
|
||||
std::map<std::string, Font> fonts;
|
||||
std::map<std::string, Bytes> audio;
|
||||
};
|
||||
using ClassicData = content::Classic;
|
||||
|
||||
void complete_classic(Documents& out, const std::filesystem::path& root,
|
||||
const Database& database, const LeImage& executable,
|
||||
|
||||
+11
-3
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "import/obw.hpp"
|
||||
#include "content/package.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
@@ -53,6 +54,8 @@ int main(int argc, char** argv) {
|
||||
if (!source.empty() || !destination.empty() || !options.start_date.empty() || !options.mod.empty() || directory || options.database_only)
|
||||
throw std::runtime_error("--validate cannot be combined with conversion options");
|
||||
const auto documents = bmh::obw::read(validate_path);
|
||||
if (documents.contains("x-classic/seal.json"))
|
||||
bmh::content::verify(documents);
|
||||
std::cout << "Valid OBW content: " << documents.size() << " entries; no engine runtime test implied.\n";
|
||||
return 0;
|
||||
}
|
||||
@@ -60,13 +63,18 @@ int main(int argc, char** argv) {
|
||||
throw std::runtime_error("--data, --output and --start-date are required; see --help");
|
||||
if (!directory && destination.extension() != ".obw")
|
||||
throw std::runtime_error("archive output must use the .obw extension");
|
||||
const auto documents = bmh::obw::import_installation(source, options);
|
||||
auto documents = bmh::obw::import_installation(source, options);
|
||||
if (!options.database_only)
|
||||
bmh::content::seal(documents);
|
||||
bmh::obw::write(documents, destination, directory);
|
||||
std::cout << "Converted " << documents.size() << " documents to "
|
||||
<< bmh::launch::path_to_utf8(destination) << "\n"
|
||||
<< "Profile: " << (options.database_only ? "legacy-database-v1 (partial)" : "classic-installation-v1 (complete Classic content)")
|
||||
<< "Profile: "
|
||||
<< (options.database_only ? "legacy-database-v1 (partial)"
|
||||
: "classic-installation-v1 (complete Classic content)")
|
||||
<< "; content_license: local-import-only.\n"
|
||||
<< "See manifest.json and x-legacy/import-report.json. 0.2 runtime integration is separate.\n";
|
||||
<< "See manifest.json and x-legacy/import-report.json. Classic packages can be added to "
|
||||
"the 0.2 portable mods directory.\n";
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << "openbmh_import: " << error.what() << '\n';
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "import/save.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/career.hpp"
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
namespace bmh::obw {
|
||||
namespace {
|
||||
struct Record {
|
||||
int target;
|
||||
uint32_t native_address;
|
||||
size_t size;
|
||||
};
|
||||
} // namespace
|
||||
Bytes normalize_english_save(const Savegame &source, const DbCounts &counts) {
|
||||
if (source.version != "V2.20" || !source.checksum_ok)
|
||||
throw FormatError("Invalid Football Limited V2.20 save");
|
||||
const auto layout = save_layout(counts, true);
|
||||
const Record records[] = {
|
||||
{0, 0, 0}, // Cup_AdvanceCup_RuntimeField3
|
||||
{1, 0, 0}, // LiveMatchday_FormatError_RuntimeField14
|
||||
{2, 0, 0}, // ManagerRecords
|
||||
{3, 0, 0}, // Loans
|
||||
{4, 0, 0}, // ManagerMatchHistory
|
||||
{6, 0, 0}, // ManagerAutomation
|
||||
{7, 0, 0}, // Desktops
|
||||
{8, 0, 0}, // CareerSession_DispatchToto_RuntimeField
|
||||
{10, 0, 0}, // CalendarState_FormatError_RuntimeField3
|
||||
{11, 0, 0}, // ActiveManager
|
||||
{12, 0, 0}, // CareerSession_RuntimeError_RuntimeField4
|
||||
{13, 0, 0}, // LeaguePresentationOptions
|
||||
{14, 0, 0}, // FriendlyTeams
|
||||
{15, 0, 0}, // FriendlyDays
|
||||
{16, 0, 0}, // Cup_AdvanceCup_ExecutableField
|
||||
{17, 0, 0}, // MatchdaySetup_IndoorTournamentDraw_RuntimeField
|
||||
{18, 0, 0}, // Placements
|
||||
{19, 0, 0}, // ActiveSelectors
|
||||
{20, 0, 0}, // Career_CareerAddManager_RuntimeField2
|
||||
{21, 0, 0}, // DeskActions_SubmitPoolsCoupon_RuntimeField
|
||||
{22, 0, 0}, // NextDeskManager
|
||||
{23, 0, 0}, // Savestate_Layout_ExecutableField8
|
||||
{24, 0, 0}, // DeskPosition
|
||||
{25, 0, 0}, // DeskRecords_Teams_RuntimeField
|
||||
{26, 0, 0}, // CareerSession_FormatError_RuntimeField7
|
||||
{27, 0, 0}, // Cup_AdvanceCup_RuntimeField6
|
||||
{28, 0, 0}, // CurrentMatchday
|
||||
{29, 0, 0}, // ClubPlayerDetail_InvalidArgument_RuntimeField3
|
||||
{30, 0, 0}, // CoachActive
|
||||
{31, 0, 0}, // OriginalManagerCount
|
||||
{32, 0, 0}, // CareerSession_Invalid_RuntimeField2
|
||||
{33, 0, 0}, // CareerDuration
|
||||
{34, 0, 0}, // GameMode
|
||||
{35, 0, 0}, // CompetitionSelection
|
||||
{36, 0, 0}, // ManagerCount
|
||||
{37, 0, 0}, // SavedCompetition
|
||||
{38, 0, 0}, // Difficulty
|
||||
{39, 0, 0}, // StockExchange
|
||||
{40, 0, 0}, // FundBlock
|
||||
{41, 0, 0}, // Coupon
|
||||
{42, 0, 0}, // Savestate_Layout_ExecutableField2
|
||||
{43, 0, 0}, // Savestate_Layout_ExecutableField
|
||||
{44, 0, 0}, // AdGroupId
|
||||
{45, 0, 0}, // OfferSlots
|
||||
{46, 0, 0}, // ForeignClubStrength
|
||||
{47, 0, 0}, // Career_Put_ExecutableField3
|
||||
{48, 0, 0}, // ClubShortNameOffsets
|
||||
{49, 0, 0}, // ClubKitSelectors
|
||||
{50, 0, 0}, // Savestate_Layout_ExecutableField7
|
||||
{51, 0, 0}, // ClubInfo_FormatError_RuntimeField
|
||||
{52, 0, 0}, // Career_CareerManagersEnd_RuntimeField
|
||||
{53, 0, 0}, // ClubInfo_FormatError_RuntimeField2
|
||||
{54, 0, 0}, // DeskActions_Unsupported_RuntimeField
|
||||
{55, 0, 0}, // Career_RemoveJoinLoans_RuntimeField
|
||||
{56, 0, 0}, // ClubPlayerDetail_InvalidArgument_RuntimeField
|
||||
{57, 0, 0}, // ManagerRatings
|
||||
{58, 0, 0}, // DaysIntoSeason
|
||||
{-1, ::bmh::layout::EnglishFaCupResults, 0x86}, // fa_results
|
||||
{-1, ::bmh::layout::EnglishLeagueCupFirstRoundResults, 0x56}, // league_results
|
||||
{-1, ::bmh::layout::EnglishLeagueCupQuarterFinalOtherLegResults, 0x3c}, // league_return
|
||||
{-1, ::bmh::layout::EnglishLeagueCupField, 0xa4}, // league_field
|
||||
{-1, ::bmh::layout::EnglishFaCupField, 0x134}, // fa_field
|
||||
{61, 0, 0}, // CalendarDay
|
||||
{62, 0, 0}, // SeasonIndex
|
||||
{63, 0, 0}, // Savestate_Layout_ExecutableField5
|
||||
{64, 0, 0}, // CompetitionCalendar
|
||||
{65, 0, 0}, // Postponed
|
||||
{66, 0, 0}, // LeagueTableDisplayModes
|
||||
{67, 0, 0}, // CareerSession_FormatError_ExecutableField
|
||||
{68, 0, 0}, // ManagerSettings
|
||||
{69, 0, 0}, // CareerSession_DispatchOtherGames_RuntimeField
|
||||
{70, 0, 0}, // CareerSession_AnyOf_ExecutableField
|
||||
{71, 0, 0}, // Career_NewCareerMarketsAndMoods_RuntimeField2
|
||||
{72, 0, 0}, // ManagerMailbox
|
||||
{73, 0, 0}, // CareerSession_CloseLeagueFamily_ExecutableField
|
||||
{74, 0, 0}, // Savestate_Layout_ExecutableField3
|
||||
{75, 0, 0}, // Flags
|
||||
{76, 0, 0}, // Formations
|
||||
{77, 0, 0}, // PlayerDevelopmentBalance
|
||||
{78, 0, 0}, // PlayerBonuses
|
||||
{79, 0, 0}, // EditorList
|
||||
{80, 0, 0}, // Field0
|
||||
{81, 0, 0}, // Career_CompetitionPointersEnglish_RuntimeField13
|
||||
{82, 0, 0}, // Career_CompetitionPointersEnglish_ExecutableField25
|
||||
{83, 0, 0}, // Career_CompetitionPointersEnglish_ExecutableField22
|
||||
{84, 0, 0}, // Career_CompetitionPointersEnglish_ExecutableField23
|
||||
{85, 0, 0}, // Career_CompetitionPointersEnglish_ExecutableField19
|
||||
{86, 0, 0}, // Career_CompetitionPointersEnglish_ExecutableField26
|
||||
{87, 0, 0}, // Career_CompetitionPointersEnglish_ExecutableField21
|
||||
{88, 0, 0}, // Career_CompetitionPointersEnglish_RuntimeField14
|
||||
{89, 0, 0}, // Career_CompetitionPointersEnglish_RuntimeField17
|
||||
{90, 0, 0}, // Savestate_Layout_ExecutableField4
|
||||
{91, 0, 0}, // Career_CompetitionPointersEnglish_ExecutableField28
|
||||
{92, 0, 0}, // Career_CompetitionPointersEnglish_ExecutableField31
|
||||
{93, 0, 0}, // Teams
|
||||
{94, 0, 0}, // MatchdayGroupWorkspace
|
||||
{95, 0, 0}, // Savestate_Layout_ExecutableField6
|
||||
{96, 0, 0}, // EventPasses
|
||||
{97, 0, 0}, // LeagueResults
|
||||
{98, 0, 0}, // LeagueRoundCounters
|
||||
{99, 0, 0}, // TeamMorale
|
||||
{100, 0, 0}, // ClubBadgeSelectors
|
||||
{101, 0, 0}, // TeamFlags
|
||||
{102, 0, 0}, // ClubIdentities
|
||||
{103, 0, 0}, // PlayerNameOffsets
|
||||
{104, 0, 0}, // MasterDatabaseMetadata
|
||||
{105, 0, 0}, // ClubAuxiliaryWords
|
||||
{106, 0, 0}, // LeagueRankHistory
|
||||
{107, 0, 0}, // Titles
|
||||
{108, 0, 0}, // Cup_AdvanceCup_RuntimeField6
|
||||
{109, 0, 0}, // ClubAuxiliaryBytes
|
||||
{110, 0, 0}, // CupTable
|
||||
{111, 0, 0}, // SquadSlots
|
||||
{112, 0, 0}, // PlayerConditionTechniqueForm
|
||||
{113, 0, 0}, // PlayerCards
|
||||
{114, 0, 0}, // PlayerSkillWords
|
||||
{115, 0, 0}, // PlayerIdentityWords
|
||||
{116, 0, 0}, // TacticsBoards
|
||||
{117, 0, 0}, // TournamentName
|
||||
{118, 0, 0}, // Career_EuropeanClub_ExecutableField
|
||||
{119, 0, 0}, // Career_EuropeanClub_ExecutableField2
|
||||
{120, 0, 0}, // Career_EuropeanClub_ExecutableField3
|
||||
{121, 0, 0}, // Career_CompetitionPointersEnglish_ExecutableField24
|
||||
{122, 0, 0}, // Career_CompetitionPointersEnglish_ExecutableField29
|
||||
{123, 0, 0}, // ClubSeasonRecords
|
||||
{124, 0, 0}, // ClubSeasonRecords
|
||||
};
|
||||
std::map<int, Bytes> decoded;
|
||||
std::map<uint32_t, Bytes> native;
|
||||
for (const auto &[address, size] : kEnglishCompetitionBlocks)
|
||||
native[address] = Bytes(size, 0);
|
||||
size_t offset = 0;
|
||||
bool club_records = false;
|
||||
for (const auto &record : records) {
|
||||
if (record.target == 124 && !club_records)
|
||||
continue;
|
||||
const size_t size = record.target < 0 ? record.size : layout.at(size_t(record.target)).size;
|
||||
if (offset + size > source.stream.size())
|
||||
throw FormatError("V2.20 state is truncated");
|
||||
Bytes bytes(source.stream.begin() + offset, source.stream.begin() + offset + size);
|
||||
offset += size;
|
||||
if (record.target == 123) {
|
||||
if (size != 4)
|
||||
throw FormatError("Invalid club record pointer");
|
||||
club_records = le32(bytes, 0) != 0;
|
||||
}
|
||||
if (record.target >= 0)
|
||||
decoded[record.target] = bytes;
|
||||
uint32_t target = record.native_address;
|
||||
if (record.target == 93)
|
||||
target = ::bmh::layout::EnglishAdditionalCupField;
|
||||
if (record.target == 94)
|
||||
target = ::bmh::layout::EnglishAdditionalCupResults;
|
||||
if (target)
|
||||
for (auto &[at, block] : native)
|
||||
if (target >= at && uint64_t(target) + bytes.size() <= uint64_t(at) + block.size())
|
||||
std::copy(bytes.begin(), bytes.end(), block.begin() + (target - at));
|
||||
}
|
||||
Bytes normalized;
|
||||
for (size_t i = 0; i < layout.size(); ++i) {
|
||||
if (i == 124 && !club_records)
|
||||
continue;
|
||||
if (const auto it = decoded.find(int(i)); it != decoded.end())
|
||||
normalized.insert(normalized.end(), it->second.begin(), it->second.end());
|
||||
else
|
||||
normalized.insert(normalized.end(), layout[i].size, 0);
|
||||
}
|
||||
// Four length-prefixed name pools, shared by both original editions.
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
if (offset + 2 > source.stream.size())
|
||||
throw FormatError("V2.20 name pool missing");
|
||||
const size_t size = le16(source.stream, offset) + 2;
|
||||
if (offset + size > source.stream.size())
|
||||
throw FormatError("V2.20 name pool is truncated");
|
||||
normalized.insert(normalized.end(), source.stream.begin() + offset,
|
||||
source.stream.begin() + offset + size);
|
||||
offset += size;
|
||||
}
|
||||
if (offset != source.stream.size())
|
||||
throw FormatError("V2.20 state has unexpected trailing bytes");
|
||||
std::vector<SaveState::ExtensionBlock> extension;
|
||||
for (auto &[at, bytes] : native)
|
||||
extension.push_back({at, std::move(bytes)});
|
||||
append_save_extension(normalized, extension);
|
||||
(void)SaveState(normalized, counts);
|
||||
return normalized;
|
||||
}
|
||||
} // namespace bmh::obw
|
||||
@@ -0,0 +1,9 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "formats/fbm.hpp"
|
||||
#include "formats/savestate.hpp"
|
||||
namespace bmh::obw {
|
||||
// Translate the V2.20 state-block contract, including its native cup regions,
|
||||
// to the existing in-memory Classic layout. No executable or FBM file is emitted.
|
||||
Bytes normalize_english_save(const Savegame &, const DbCounts &counts = {});
|
||||
} // namespace bmh::obw
|
||||
Reference in new issue
Block a user