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
@@ -0,0 +1,114 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include <RmlUi/Core.h>
|
||||
#include "launch/rml_path.hpp"
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace {
|
||||
struct System : Rml::SystemInterface {
|
||||
std::string errors;
|
||||
bool LogMessage(Rml::Log::Type type, const Rml::String &text) override {
|
||||
if (type <= Rml::Log::LT_WARNING)
|
||||
errors += text + "\n";
|
||||
return true;
|
||||
}
|
||||
};
|
||||
struct Renderer : Rml::RenderInterface {
|
||||
size_t rendered_vertices = 0;
|
||||
Rml::CompiledGeometryHandle CompileGeometry(Rml::Span<const Rml::Vertex> vertices,
|
||||
Rml::Span<const int>) override {
|
||||
return Rml::CompiledGeometryHandle(vertices.size());
|
||||
}
|
||||
void ReleaseGeometry(Rml::CompiledGeometryHandle) override {}
|
||||
void RenderGeometry(Rml::CompiledGeometryHandle geometry, Rml::Vector2f, Rml::TextureHandle) override {
|
||||
rendered_vertices += size_t(geometry);
|
||||
}
|
||||
void EnableScissorRegion(bool) override {}
|
||||
void SetScissorRegion(Rml::Rectanglei) override {}
|
||||
Rml::TextureHandle LoadTexture(Rml::Vector2i &dimensions, const Rml::String &name) override {
|
||||
auto *files = Rml::GetFileInterface();
|
||||
const auto input = files->Open(name);
|
||||
if (!input)
|
||||
throw std::runtime_error("Stadium asset unavailable: " + name);
|
||||
unsigned char header[18]{};
|
||||
const auto read = files->Read(header, sizeof(header), input);
|
||||
files->Close(input);
|
||||
if (read != sizeof(header) || header[2] != 2 || header[16] != 24)
|
||||
throw std::runtime_error("Invalid stadium asset: " + name);
|
||||
dimensions = {header[12] + 256 * header[13], header[14] + 256 * header[15]};
|
||||
return 1;
|
||||
}
|
||||
Rml::TextureHandle GenerateTexture(Rml::Span<const Rml::byte>, Rml::Vector2i) override { return 2; }
|
||||
void ReleaseTexture(Rml::TextureHandle) override {}
|
||||
};
|
||||
void require(bool value, const std::string &error) {
|
||||
if (!value)
|
||||
throw std::runtime_error(error);
|
||||
}
|
||||
} // namespace
|
||||
int main(int argc, char **argv) try {
|
||||
require(argc == 2 || (argc == 3 && std::string(argv[2]) == "unicode"), "launcher asset directory required");
|
||||
std::filesystem::path assets(argv[1]);
|
||||
struct Cleanup {
|
||||
std::filesystem::path path;
|
||||
~Cleanup() {
|
||||
if (!path.empty()) {
|
||||
std::error_code error;
|
||||
std::filesystem::remove_all(path, error);
|
||||
}
|
||||
}
|
||||
} cleanup;
|
||||
if (argc == 3) {
|
||||
cleanup.path = std::filesystem::temp_directory_path() /
|
||||
("openbmh-rml-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
||||
std::filesystem::create_directory(cleanup.path);
|
||||
const auto unicode = cleanup.path / std::filesystem::path(u8"Fußball 日本語") / "launcher";
|
||||
std::filesystem::create_directories(unicode);
|
||||
std::filesystem::copy(assets, unicode, std::filesystem::copy_options::recursive);
|
||||
assets = unicode;
|
||||
}
|
||||
System system;
|
||||
Renderer renderer;
|
||||
bmh::rml::AssetFiles files;
|
||||
Rml::SetSystemInterface(&system);
|
||||
Rml::SetRenderInterface(&renderer);
|
||||
Rml::SetFileInterface(&files);
|
||||
require(Rml::Initialise(), "RmlUI initialization");
|
||||
struct Shutdown {
|
||||
~Shutdown() { Rml::Shutdown(); }
|
||||
} shutdown;
|
||||
for (const auto *weight : {"Regular", "Bold"})
|
||||
require(Rml::LoadFontFace(bmh::rml::asset_path(assets / (std::string("LatoLatin-") + weight + ".ttf"))),
|
||||
"font load");
|
||||
auto *context = Rml::CreateContext("test", {1100, 688});
|
||||
auto *document = context->LoadDocument(bmh::rml::asset_path(assets / "launcher.rml"));
|
||||
require(document != nullptr, "launcher document load");
|
||||
document->Show();
|
||||
for (const auto size : {Rml::Vector2i(1100, 688), Rml::Vector2i(800, 540), Rml::Vector2i(2200, 1376)}) {
|
||||
context->SetDimensions(size);
|
||||
context->SetDensityIndependentPixelRatio(float(size.x) / 1100);
|
||||
context->Update();
|
||||
context->Render();
|
||||
for (const auto *id : {"start", "add", "delete", "rename", "end"}) {
|
||||
auto *button = document->GetElementById(id);
|
||||
require(button != nullptr, "missing launcher action");
|
||||
const auto origin = button->GetAbsoluteOffset(Rml::BoxArea::Border);
|
||||
const auto dimensions = button->GetBox().GetSize(Rml::BoxArea::Border);
|
||||
require(origin.x >= 0 && origin.y >= 0 && origin.x + dimensions.x <= size.x + 1 &&
|
||||
origin.y + dimensions.y <= size.y + 1 && dimensions.y >= 30,
|
||||
"action outside viewport or too small");
|
||||
require(button->GetNumChildren() >= 2, "action lost its visible text label");
|
||||
}
|
||||
require(!document->GetElementById("overlay")->IsVisible(), "modal unexpectedly visible");
|
||||
}
|
||||
require(renderer.rendered_vertices > 100, "launcher did not render");
|
||||
require(system.errors.empty(), system.errors);
|
||||
std::cout << "Launcher RML/RCSS, fonts, background, visible labels and responsive layout passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception &error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "content/package.hpp"
|
||||
#include "content/save.hpp"
|
||||
#include "launch/mods.hpp"
|
||||
#include "launch/process.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
#include "formats/content.hpp"
|
||||
#include "formats/native_state.hpp"
|
||||
#include "formats/vga.hpp"
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
using namespace bmh;
|
||||
namespace fs = std::filesystem;
|
||||
void check(bool value, const char *message) {
|
||||
if (!value)
|
||||
throw std::runtime_error(message);
|
||||
}
|
||||
template <class F> void rejects(F f, const char *message) {
|
||||
bool failed = false;
|
||||
try {
|
||||
f();
|
||||
} catch (const std::exception &) {
|
||||
failed = true;
|
||||
}
|
||||
check(failed, message);
|
||||
}
|
||||
int main(int argc, char **argv) try {
|
||||
const auto arguments = launch::utf8_arguments(argc, argv);
|
||||
if (arguments.size() > 1 && arguments[1] == "--child-check") {
|
||||
return arguments == std::vector<std::string>{arguments[0], "--child-check", "Grüße with spaces",
|
||||
"quote\" and trailing\\", ""}
|
||||
? 42
|
||||
: 43;
|
||||
}
|
||||
const auto executable = launch::executable_path("not-the-executable");
|
||||
check(fs::is_regular_file(executable),
|
||||
"portable root uses the actual process path rather than argv or current directory");
|
||||
check(launch::run_child(executable, {"--child-check", "Grüße with spaces", "quote\" and trailing\\", ""},
|
||||
{}) == 42,
|
||||
"child startup preserves Unicode, spaces, quotes, trailing slashes and empty arguments");
|
||||
check(content::sha256("") == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||
"SHA256 empty vector");
|
||||
check(content::sha256("abc") == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
|
||||
"SHA256 short vector");
|
||||
check(content::sha256(std::string(1000000, 'a')) ==
|
||||
"cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0",
|
||||
"SHA256 multi-block vector");
|
||||
const auto root = fs::temp_directory_path() /
|
||||
("openbmh-native-test-" +
|
||||
std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
||||
fs::create_directories(root);
|
||||
struct Cleanup {
|
||||
fs::path p;
|
||||
~Cleanup() {
|
||||
std::error_code ec;
|
||||
fs::remove_all(p, ec);
|
||||
}
|
||||
} cleanup{root};
|
||||
auto classic = std::make_shared<content::Classic>();
|
||||
classic->images.emplace("kb/7", Image(2, 2, 19));
|
||||
classic->audio["2000"] = {1, 2, 3};
|
||||
classic->desktops = {4, 5};
|
||||
classic->palette.argb[9] = 0xffabcdef;
|
||||
{
|
||||
content::Mount mount(root / "content.obw", classic);
|
||||
check(!fs::exists(mount.root()), "mounted contents need no materialized legacy files");
|
||||
check(load_vga(mount.root() / "KB/7.VGA").pixels == Bytes(4, 19),
|
||||
"indexed OBW image reaches existing renderer");
|
||||
check(read_file(mount.root() / "S/2000") == Bytes({1, 2, 3}),
|
||||
"audio bank comes from immutable store");
|
||||
check(read_file(mount.root() / "M3.MEN") == Bytes({4, 5}),
|
||||
"startup input comes from immutable store");
|
||||
check(load_palette(mount.root() / "M3PC.COL").argb[9] == 0xffabcdef,
|
||||
"palette keeps exact imported RGB8");
|
||||
rejects([&] { load_vga(mount.root() / "KB/999.VGA"); },
|
||||
"missing content must not fall through to disk");
|
||||
rejects([&] { content::Mount duplicate(mount.root(), classic); },
|
||||
"duplicate mounts must not replace live contents");
|
||||
}
|
||||
check(!content::find(root / "content.obw/KB/7.VGA"), "mount lifetime is bounded");
|
||||
GameState state;
|
||||
state.date = 99;
|
||||
state.season_start = 12;
|
||||
state.display_start_year = 1994;
|
||||
state.squad_slots = {0x8fff, 42};
|
||||
state.manager_teams = {-1, 12};
|
||||
state.manager_records = {1, 2, 3};
|
||||
state.player_names = {0, 0xff};
|
||||
state.memory.add_block(0x1000, 4);
|
||||
state.memory.set32(0x1000, 0xff123456);
|
||||
state.players.push_back({std::string("A\xff", 2), 0xdeadbeef, 0x12345678, 0xffffffff});
|
||||
state.autosave_month = 4;
|
||||
state.list_toggle = 1;
|
||||
state.sportschau_homes[9] = 41;
|
||||
state.reality.initialized = true;
|
||||
state.reality.grid.place(0, 5, 7, 0);
|
||||
state.reality.cue_actors[3] = 19;
|
||||
const auto encoded = encode_native_state(state);
|
||||
const auto restored = decode_native_state(cli::parse_json(cli::dump_json(encoded)));
|
||||
check(cli::dump_json(encoded) == cli::dump_json(encode_native_state(restored)),
|
||||
"all native fields round-trip without host padding/pointers");
|
||||
check(restored.reality == state.reality, "Reality residues survive exactly");
|
||||
auto damaged = encoded;
|
||||
damaged.object()->at("schema") = "classic-state@99.0";
|
||||
rejects([&] { decode_native_state(damaged); }, "unsupported checkpoint schema rejected");
|
||||
TurnDriver driver;
|
||||
driver.referees = {1, 0x81};
|
||||
driver.next_event_id = UINT64_MAX;
|
||||
TurnDriver copy;
|
||||
content::restore_driver(copy, content::driver_checkpoint(driver));
|
||||
check(copy.next_event_id == UINT64_MAX && copy.referees == driver.referees,
|
||||
"driver counters and referees round-trip");
|
||||
WatcomRandom random(7);
|
||||
random.rand();
|
||||
WatcomRandom continued;
|
||||
continued.restore(random.seed(), random.calls());
|
||||
check(continued.rand() == random.rand() && continued.calls() == random.calls(),
|
||||
"Watcom stream resumes including counter");
|
||||
content::Documents docs{{"manifest.json", "{}"}, {"assets/test.pixels", std::string("a\0b", 3)}};
|
||||
const auto archive = root / "sample.obs";
|
||||
content::write_archive(docs, archive);
|
||||
check(content::read_archive(archive) == docs, "binary native archive round-trip");
|
||||
{
|
||||
content::Mount mount(archive, std::make_shared<content::Classic>());
|
||||
check(content::read_archive(archive) == docs,
|
||||
"archive reads bypass the mounted virtual resource namespace");
|
||||
}
|
||||
rejects([&] { content::write_archive({{"../outside", "x"}}, root / "unsafe.obs"); },
|
||||
"archive traversal rejected");
|
||||
rejects([&] { content::write_archive({}, archive); }, "existing saves require explicit overwrite");
|
||||
check(content::read_archive(archive) == docs, "rejected overwrite retains existing save");
|
||||
content::write_archive({{"new", "value"}}, archive, true);
|
||||
check(content::read_archive(archive).contains("new"), "atomic replacement publishes complete archive");
|
||||
content::save_preferences(root / "test.obsettings", "settings", Bytes(180, 0x82), false);
|
||||
check(content::load_preferences(root / "test.obsettings", "settings", 180) == Bytes(180, 0x82),
|
||||
"native settings retain availability bits");
|
||||
rejects([&] { content::load_preferences(root / "test.obsettings", "layout", 180); },
|
||||
"preferences kinds cannot be confused");
|
||||
launch::ModLibrary library(root);
|
||||
check(library.list().empty(), "first launch has no implicit installation");
|
||||
for (const char *name : {"../escape", "CON", "lpt1.txt", "trailing.", "bad/name", ""})
|
||||
rejects([&] { launch::ModLibrary::validate_name(name); }, "portable mod name validation");
|
||||
fs::create_directories(root / "mods/BMH-classic");
|
||||
auto entries = library.list();
|
||||
check(entries.size() == 1 && !entries[0].error.empty(), "damaged mods remain visible with error");
|
||||
rejects([&] { library.rename(entries[0], "bmh-CLASSIC"); }, "case-insensitive duplicate name rejected");
|
||||
library.rename(entries[0], "Renamed");
|
||||
entries = library.list();
|
||||
check(entries[0].name == "Renamed", "rename changes directory name");
|
||||
entries[0].content_id = std::string(64, 'a');
|
||||
const auto personal = library.user_directory(entries[0]);
|
||||
content::write_atomic(personal / "keep.obs", "saved", false);
|
||||
library.remove(entries[0]);
|
||||
check(library.list().empty() && fs::exists(personal / "keep.obs"), "delete retains personal saves");
|
||||
std::cout << "native content, checkpoints and portable mod lifecycle passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "app/career_session.hpp"
|
||||
#include "app/controller.hpp"
|
||||
#include "content/save.hpp"
|
||||
#include "launch/mods.hpp"
|
||||
#include "launch/game_data.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/sportschau.hpp"
|
||||
#include "game/save.hpp"
|
||||
#include "audio/original.hpp"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
using namespace bmh;
|
||||
namespace fs = std::filesystem;
|
||||
void check(bool value, const std::string &text) {
|
||||
if (!value)
|
||||
throw std::runtime_error(text);
|
||||
}
|
||||
int main(int argc, char **argv) try {
|
||||
if (argc < 2)
|
||||
return 77;
|
||||
const auto root = fs::temp_directory_path() /
|
||||
("openbmh-native-career-" +
|
||||
std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
||||
fs::create_directories(root);
|
||||
struct Cleanup {
|
||||
fs::path p;
|
||||
~Cleanup() {
|
||||
std::error_code ec;
|
||||
fs::remove_all(p, ec);
|
||||
}
|
||||
} cleanup{root};
|
||||
launch::ModLibrary library(root);
|
||||
launch::AddMod request;
|
||||
request.source = argv[1];
|
||||
request.name = "Test Classic";
|
||||
request.start_year = 1994;
|
||||
request.migrate = false;
|
||||
const auto result = library.add(request, {});
|
||||
const auto package = result.mod.directory / "content.obw";
|
||||
auto content = content::open(package);
|
||||
content::Mount mount(package, content);
|
||||
check(content::open(package)->content_id == content->content_id,
|
||||
"mounted container can be reopened without resolving it as an asset");
|
||||
openbmh::audio::OriginalAssets sound;
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
sound.containers[i] = read_file(mount.root() / "S" / std::to_string(2000 + i));
|
||||
for (size_t i = 0; i < 96; ++i)
|
||||
sound.tables.frequencies[i] =
|
||||
content->executable.u16(layout::Audio_OriginalAudioAssets_RuntimeField2 + uint32_t(i) * 2);
|
||||
for (size_t i = 0; i < 9; ++i)
|
||||
sound.tables.operators[i] =
|
||||
content->executable.u8(layout::Audio_OriginalAudioAssets_RuntimeField + uint32_t(i) * 16);
|
||||
openbmh::audio::OriginalSynth synth;
|
||||
std::string sound_error;
|
||||
check(synth.load(std::move(sound), 22050, sound_error), sound_error);
|
||||
|
||||
// Exercise renderers through aliases while the mod contains only content.obw.
|
||||
check(ui::SetupScreen(mount.root()).render().pixels.size() == 320 * 240, "OBW-only setup renderer");
|
||||
(void)ui::SportschauIntro(mount.root()).render_frame(0);
|
||||
const auto resolved = launch::resolve_game(request.source, root / "legacy-test-cache");
|
||||
check(resolved.error.empty(), resolved.error);
|
||||
auto legacy_directory = resolved.check.directory;
|
||||
if (!fs::exists(legacy_directory / "BMH.exe")) {
|
||||
// The legacy oracle uses fixed filename casing. Only its private test
|
||||
// copy needs aliases on case-sensitive filesystems; OBW does not.
|
||||
const auto aliases = root / "legacy-case-reference";
|
||||
fs::create_directory(aliases);
|
||||
for (const char *name : {"BMH.exe", "M3D.MAN", "TEXTD.BLK", "M3.MEN", "M3.DAT"}) {
|
||||
const auto source = launch::find_file(legacy_directory, name);
|
||||
check(bool(source), "legacy reference file missing");
|
||||
fs::copy_file(*source, aliases / name);
|
||||
}
|
||||
legacy_directory = aliases;
|
||||
}
|
||||
app::CareerSession old(legacy_directory, 12345);
|
||||
app::CareerSession session(mount.root(), 12345);
|
||||
check(save_stream(old.state()) == save_stream(session.state()) &&
|
||||
old.rand().seed() == session.rand().seed() && old.game().seed() == session.game().seed(),
|
||||
"OBW bootstrap matches legacy state and RNG");
|
||||
ui::SetupOptions options;
|
||||
options.managers = 1;
|
||||
ui::ManagerChoice manager;
|
||||
manager.slot = 0;
|
||||
manager.master_club = 0;
|
||||
manager.start_league = 0;
|
||||
manager.strength = 1;
|
||||
manager.portrait = 0;
|
||||
manager.name = "Native QA";
|
||||
std::string error;
|
||||
check(session.confirm_manager(options, manager, error), error);
|
||||
const auto personal = library.user_directory(result.mod);
|
||||
session.configure_autosave_directory(personal);
|
||||
session.state().memory.set8(layout::Desk_EnterDesk_RuntimeField, 1);
|
||||
ui::CareerInitializationResult initial;
|
||||
check(session.finish(initial, error), error);
|
||||
check(initial.desktop.date.year == 1994 && initial.desktop.date.weekday == 2,
|
||||
"selected start year changes the year display while retaining the Classic Wednesday epoch");
|
||||
const auto before = cli::dump_json(encode_native_state(session.state()));
|
||||
const auto random = session.rand();
|
||||
const auto game = session.game();
|
||||
const auto save = library.user_directory(result.mod) / "QA.obs";
|
||||
check(session.save_game(save, 0, false, error), error);
|
||||
check(session.rand().seed() == random.seed() && session.rand().calls() == random.calls() &&
|
||||
session.game().seed() == game.seed() && session.game().calls() == game.calls(),
|
||||
"native saving is RNG-neutral");
|
||||
app::CareerSession loaded(mount.root(), 999, save);
|
||||
check(cli::dump_json(encode_native_state(loaded.state())) == before, "native career state round-trip");
|
||||
check(loaded.rand().seed() == random.seed() && loaded.rand().calls() == random.calls() &&
|
||||
loaded.game().seed() == game.seed() && loaded.game().calls() == game.calls(),
|
||||
"both RNG states and counters restored");
|
||||
check(cli::dump_json(content::driver_checkpoint(session.manager_join_checkpoint().driver)) ==
|
||||
cli::dump_json(content::driver_checkpoint(loaded.manager_join_checkpoint().driver)),
|
||||
"native turn cursor round-trip");
|
||||
{
|
||||
ui::StartupFlow flow(mount.root(), personal);
|
||||
check(flow.click(215, 220).request == ui::FlowRequest::submenu_opened,
|
||||
"GUI opens native load browser from setup");
|
||||
const auto request = flow.send_key("ENTER");
|
||||
check(request.request == ui::FlowRequest::file_action && request.file_action.path == save,
|
||||
"GUI selects native save from personal directory");
|
||||
std::unique_ptr<app::CareerSession> gui_session;
|
||||
uint64_t gui_revision = 0;
|
||||
openbmh::audio::Playback playback;
|
||||
std::optional<uint64_t> audio_session;
|
||||
check(app::serve_flow_request(flow, request, gui_session, mount.root(), personal, 999, gui_revision,
|
||||
playback, audio_session, false)
|
||||
.empty(),
|
||||
"GUI controller accepts native save path");
|
||||
check(gui_session && flow.screen_name() == "desktop" && gui_revision == 1,
|
||||
"GUI controller attaches loaded native desktop: " + flow.state_json());
|
||||
const auto save_item =
|
||||
std::find_if(flow.desktop()->state().items.begin(), flow.desktop()->state().items.end(),
|
||||
[](const ui::DeskItem &item) { return item.kind == 11 && !item.disabled; });
|
||||
check(save_item != flow.desktop()->state().items.end(), "native desktop exposes Save");
|
||||
const auto serve = [&](const ui::FlowResult &event) {
|
||||
check(app::serve_flow_request(flow, event, gui_session, mount.root(), personal, 999, gui_revision,
|
||||
playback, audio_session, false)
|
||||
.empty(),
|
||||
"native GUI file action dispatch");
|
||||
};
|
||||
serve(flow.click(save_item->x + save_item->width / 2, save_item->y + save_item->height / 2));
|
||||
check(flow.screen_name() == "save_load" && flow.text("GUI Roundtrip"),
|
||||
"native GUI Save accepts a new filename");
|
||||
const auto gui_random = gui_session->rand();
|
||||
serve(flow.send_key("ENTER"));
|
||||
check(flow.screen_name() == "desktop" && fs::exists(personal / "GUI Roundtrip.obs"),
|
||||
"native GUI Save publishes OBS and returns to desktop: " + flow.state_json());
|
||||
check(gui_session->rand().seed() == gui_random.seed() &&
|
||||
gui_session->rand().calls() == gui_random.calls(),
|
||||
"GUI saving preserves random state");
|
||||
}
|
||||
session.state().memory.set8(layout::Desk_EnterDesk_RuntimeField, 1);
|
||||
loaded.state().memory.set8(layout::Desk_EnterDesk_RuntimeField, 1);
|
||||
session.state().autosave_month = 0;
|
||||
loaded.state().autosave_month = 0;
|
||||
uint64_t first_revision = 1, second_revision = 1;
|
||||
for (int step = 0; step < 8; ++step) {
|
||||
const auto first_desk = session.desktop_projection(first_revision),
|
||||
second_desk = loaded.desktop_projection(second_revision);
|
||||
ui::DeskRequest first_request;
|
||||
first_request.kind = ui::DeskRequestKind::advance_turn;
|
||||
first_request.manager_slot = first_desk.manager_slot;
|
||||
first_request.revision = first_revision;
|
||||
auto second_request = first_request;
|
||||
second_request.manager_slot = second_desk.manager_slot;
|
||||
second_request.revision = second_revision;
|
||||
std::string first_error, second_error;
|
||||
const auto first = session.dispatch_kickoff(first_request, first_revision, first_error);
|
||||
const auto second = loaded.dispatch_kickoff(second_request, second_revision, second_error);
|
||||
check(first.kind == second.kind && first_error == second_error,
|
||||
"native continuation has identical outcome");
|
||||
check(cli::dump_json(encode_native_state(session.state())) ==
|
||||
cli::dump_json(encode_native_state(loaded.state())),
|
||||
"native continuation preserves every game-state field");
|
||||
check(session.rand().seed() == loaded.rand().seed() &&
|
||||
session.rand().calls() == loaded.rand().calls() &&
|
||||
session.game().seed() == loaded.game().seed() &&
|
||||
session.game().calls() == loaded.game().calls(),
|
||||
"native continuation preserves both random streams");
|
||||
if (first.kind == TurnDeskKind::Failed || first.kind == TurnDeskKind::WaitingAtDesk)
|
||||
break;
|
||||
if (step == 0) {
|
||||
const auto autosave_error = session.take_autosave_error();
|
||||
check(fs::exists(personal / "AUTOSAVE.obs"), "native autosave at stable desk: " + autosave_error);
|
||||
app::CareerSession autosaved(mount.root(), 0, personal / "AUTOSAVE.obs");
|
||||
check(cli::dump_json(encode_native_state(autosaved.state())) ==
|
||||
cli::dump_json(encode_native_state(session.state())),
|
||||
"autosave matches completed desk, including runtime flags");
|
||||
}
|
||||
check(session.save_game(save, first.manager_slot, true, error), error);
|
||||
auto fresh = std::make_unique<app::CareerSession>(mount.root(), 0, save);
|
||||
check(cli::dump_json(content::driver_checkpoint(session.manager_join_checkpoint().driver)) ==
|
||||
cli::dump_json(content::driver_checkpoint(fresh->manager_join_checkpoint().driver)),
|
||||
"prepared match groups and previous results survive saving");
|
||||
}
|
||||
// Original save migration must not require the original installation afterwards.
|
||||
auto old_save = make_savegame(session.state(), session.rand());
|
||||
write_savegame(root / "legacy.FBM", old_save);
|
||||
app::CareerSession migrated(mount.root(), 4321, root / "legacy.FBM", true);
|
||||
check(migrated.save_game(root / "migrated.obs", 0, false, error), error);
|
||||
app::CareerSession continued(mount.root(), 1, root / "migrated.obs");
|
||||
check(continued.state().players.size() == session.state().players.size(),
|
||||
"legacy save migrates to native continuation");
|
||||
if (argc > 2) {
|
||||
app::CareerSession original(mount.root(), 0x12345678, argv[2], true);
|
||||
check(original.save_game(root / "original-import.obs",
|
||||
original.state().memory.u8(layout::ActiveManager), false, error),
|
||||
error);
|
||||
app::CareerSession resumed(mount.root(), 0, root / "original-import.obs");
|
||||
check(cli::dump_json(encode_native_state(original.state())) ==
|
||||
cli::dump_json(encode_native_state(resumed.state())),
|
||||
"original edition save migration round-trip");
|
||||
}
|
||||
auto changed = content->documents;
|
||||
changed["assets/classic/images/kb/29.pixels"][0] ^= 1;
|
||||
bool rejected = false;
|
||||
try {
|
||||
content::verify(changed);
|
||||
} catch (const std::exception &) {
|
||||
rejected = true;
|
||||
}
|
||||
check(rejected, "modified Classic assets rejected");
|
||||
std::cout << "OBW-only GUI/bootstrap, career/RNG round-trip and migration passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "import/obw.hpp"
|
||||
#include "import/classic.hpp"
|
||||
#include "content/package.hpp"
|
||||
#include "import/assets.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
@@ -304,6 +305,23 @@ int main() {
|
||||
const auto classic_zip = root / "classic.obw";
|
||||
obw::write(classic, classic_zip, false);
|
||||
check(obw::read(classic_zip) == classic, "binary Classic ZIP round trip");
|
||||
auto sealed=classic;
|
||||
const auto identity=content::seal(sealed);
|
||||
const auto runtime_zip=root/"runtime.obw";
|
||||
content::write_archive(sealed,runtime_zip);
|
||||
const auto runtime=content::open(runtime_zip);
|
||||
check(runtime->content_id==identity&&runtime->database.squad_list==db.squad_list,
|
||||
"sealed native runtime reconstructs typed database without the source codec");
|
||||
auto changed_title=sealed;
|
||||
auto changed_manifest=cli::parse_json(changed_title.at("manifest.json"));
|
||||
(*changed_manifest.object())["generator"]="new importer version";
|
||||
(*changed_manifest.object())["title"]=J::Object{{"default","Renamed title"}};
|
||||
changed_title["manifest.json"]=cli::dump_json(changed_manifest)+"\n";
|
||||
obw::refresh_classic_inventory(changed_title);
|
||||
check(content::seal(changed_title)==identity,"reimport identity ignores presentation title and generator version");
|
||||
auto edited=sealed;edited.at("x-classic/desktop-seed.bin")[0]^=1;
|
||||
obw::refresh_classic_inventory(edited);
|
||||
rejects([&]{content::verify(edited);},"refreshing old CRC inventory cannot bypass the Classic seal");
|
||||
auto damaged = classic;
|
||||
damaged.at("x-classic/desktop-seed.bin")[0] ^= 1;
|
||||
rejects([&] { obw::validate(damaged); }, "inventory catches binary corruption");
|
||||
|
||||
+20
-2
@@ -22,12 +22,16 @@ class PackageAllowlistTests(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
# Empty authored placeholders test names/structure, not executable behavior.
|
||||
for name in ['openbmh_play', 'openbmh_cli', 'openbmh_import', 'README.md', 'LICENSE',
|
||||
for name in ['OpenBMH', 'openbmh_cli', 'openbmh_import', 'README.md', 'LICENSE',
|
||||
'THIRD_PARTY_NOTICES.md', 'ACKNOWLEDGEMENTS.md', 'CONTRIBUTING.md']:
|
||||
(root / name).write_text('synthetic')
|
||||
notes = root / 'docs/release/0.1/RELEASE_NOTES.md'
|
||||
notes = root / 'docs/release/0.2/RELEASE_NOTES.md'
|
||||
notes.parent.mkdir(parents=True)
|
||||
notes.write_text('synthetic release notes')
|
||||
for name in ['launcher.rml', 'theme.rcss', 'stadium.tga', 'LatoLatin-Regular.ttf', 'LatoLatin-Bold.ttf']:
|
||||
asset = root / 'assets' / 'launcher' / name
|
||||
asset.parent.mkdir(parents=True, exist_ok=True)
|
||||
asset.write_text('synthetic packaged UI asset')
|
||||
licenses = Path(__file__).resolve().parents[1] / 'docs' / 'licenses'
|
||||
for source in licenses.iterdir():
|
||||
if source.is_file():
|
||||
@@ -35,6 +39,11 @@ class PackageAllowlistTests(unittest.TestCase):
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_text('synthetic license placeholder')
|
||||
package.validate(root, False)
|
||||
missing = root / 'assets/launcher/LatoLatin-Bold.ttf'
|
||||
missing.unlink()
|
||||
with self.assertRaises(RuntimeError):
|
||||
package.validate(root, False)
|
||||
missing.write_text('synthetic font')
|
||||
schema = root / 'docs/formats/obw/schema/1.0/manifest.json'
|
||||
schema.parent.mkdir(parents=True)
|
||||
schema.write_text('{"type":"object"}')
|
||||
@@ -55,6 +64,15 @@ class PackageAllowlistTests(unittest.TestCase):
|
||||
|
||||
|
||||
class SourceInventoryTests(unittest.TestCase):
|
||||
def test_only_pinned_unused_freetype_logging_submodule_is_omitted(self):
|
||||
record = b'160000 72dfcc858c040c54a6a0b88fcb7e70ee186d3167 0\tsubprojects/dlg\0'
|
||||
self.assertEqual(source_package.unbuilt_submodules('freetype', record),
|
||||
{'subprojects/dlg': '72dfcc858c040c54a6a0b88fcb7e70ee186d3167'})
|
||||
for component, entry in [('SDL2', record), ('freetype', record.replace(b'subprojects/dlg', b'other')),
|
||||
('freetype', record.replace(b'72df', b'0000'))]:
|
||||
with self.assertRaises(RuntimeError):
|
||||
source_package.unbuilt_submodules(component, entry)
|
||||
|
||||
def setUp(self):
|
||||
self.temporary = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.temporary.cleanup)
|
||||
|
||||
Reference in new issue
Block a user