Complete native GUI file flows and Football Limited audio data (by Codex)
This commit is contained in:
1 parent
978a014b87
commit
0b2354c979
12 files changed
+155
-26
No files matched your search
@@ -8,8 +8,9 @@ aliases and written as `FLTD-classic`.
|
||||
The output is an `.obw` ZIP, or an equivalent directory. It contains the complete
|
||||
**Classic installation content**, including graphics, portrait parts, fonts,
|
||||
audio and the original data tables. It contains no running career or executable.
|
||||
The existing 0.1 game does not read OBW. The new 0.2 adapter must implement the
|
||||
versioned [Classic contract](classic-v1.md); this is deliberately separate from
|
||||
The existing 0.1 game does not read OBW. The 0.2 development branch implements the
|
||||
versioned [Classic contract](classic-v1.md) through its
|
||||
[native runtime and launcher](runtime-0.2.md). This remains separate from
|
||||
migrating every engine rule to the future generic model.
|
||||
|
||||
## Build and use
|
||||
@@ -117,7 +118,9 @@ same initialization phase as in the Classic engine.
|
||||
`--validate` checks the profile, versions, safe paths, unique entity/asset IDs,
|
||||
core references, squad/stage counts, complete cup bindings, contract ownership,
|
||||
initialization contract, media shapes, portrait indices, resource files and the
|
||||
inventory before accepting a world. ZIP and directory readers enforce size
|
||||
inventory before accepting a world. Complete imports also carry a SHA-256 seal,
|
||||
verified by this tool when present and required by the 0.2 Classic runtime.
|
||||
ZIP and directory readers enforce size
|
||||
limits; directory symlinks and injected `state/` content are rejected. CRC32
|
||||
catches accidental damage; it is not a signature or proof of trustworthy content.
|
||||
This is the Classic profile validator, not a general competition engine or a full
|
||||
@@ -146,7 +149,10 @@ All imported content remains local and retains its original ownership. Do not
|
||||
publish generated worlds or assets without appropriate rights. Public tests and
|
||||
schemas contain only independently authored implementation and synthetic data.
|
||||
|
||||
There is **no savegame converter**. `.FBM`, personal `.EIN`, `SOUND.CFG`, high
|
||||
scores, backups, editor/program executables and manuals are not imported.
|
||||
Manager choices and career RNG state belong to a new game or later `.obs` save,
|
||||
not to this installation conversion.
|
||||
The standalone installation converter does not migrate careers or personal
|
||||
settings. The 0.2 launcher separately migrates supported `.FBM`, `.EIN` and `.MEN`
|
||||
files into native personal files; see its [migration contract](runtime-0.2.md).
|
||||
`SOUND.CFG`, high scores, backups, editor/program executables and external manuals
|
||||
are not imported. In-game readme content is retained when available. Manager
|
||||
choices and career RNG state belong to a new game or `.obs` save, not to this
|
||||
installation conversion.
|
||||
@@ -614,6 +614,20 @@ CareerSession::CareerSession(const std::filesystem::path &data, uint32_t watcom_
|
||||
exe_.u32(::bmh::layout::CareerSession_DataDirectory_RuntimeField4)};
|
||||
const auto stream = original_english_save ? obw::normalize_english_save(file, counts) : file.stream;
|
||||
const SaveState save(stream, counts);
|
||||
const auto manager_count = save.data(::bmh::layout::ManagerCount)[0];
|
||||
if (manager_count < 1 || manager_count > 4)
|
||||
throw FormatError("Invalid legacy manager count");
|
||||
if (importing_legacy) {
|
||||
size_t english_blocks = 0;
|
||||
for (const auto &[address, size] : kEnglishCompetitionBlocks)
|
||||
for (const auto &block : save.extension())
|
||||
if (block.address == address && block.bytes.size() == size)
|
||||
++english_blocks;
|
||||
if ((kEnglishCompetitions && english_blocks != std::size(kEnglishCompetitionBlocks)) ||
|
||||
(!kEnglishCompetitions && english_blocks != 0))
|
||||
throw FormatError(
|
||||
"Spielstand und Mod-Ausgabe passen nicht zusammen oder englische Pokaldaten fehlen.");
|
||||
}
|
||||
g_ = GameState::from_save(save, counts);
|
||||
if (importing_legacy && file.plain_header.size() >= 11) {
|
||||
const std::string year(file.plain_header.begin() + 7, file.plain_header.begin() + 11);
|
||||
|
||||
@@ -352,8 +352,8 @@ void start_original_desk_audio(openbmh::audio::Playback& playback, const GameSta
|
||||
original_audio_command(playback, 1); // SavePathInDirectory / CareerFirstSteps2, resume the same song.
|
||||
}
|
||||
|
||||
bool save_path_in_directory(const fs::path& path, const fs::path& directory,
|
||||
std::string_view expected_extension = ".fbm") {
|
||||
bool save_path_in_directory(const fs::path &path, const fs::path &directory,
|
||||
std::string_view expected_extension) {
|
||||
if (path.filename().empty()) return false;
|
||||
std::string ext = path.extension().string();
|
||||
std::transform(ext.begin(), ext.end(), ext.begin(), [](unsigned char c) { return char(std::tolower(c)); });
|
||||
@@ -1878,7 +1878,8 @@ std::string serve_flow_request(ui::StartupFlow& flow, const ui::FlowResult& resu
|
||||
result.settings_owner_sequence == flow.settings_owner_sequence() &&
|
||||
request.origin_item_id == desk_owner.item_id && request.manager_slot == desk_owner.manager_slot;
|
||||
if (!session || !same_pending || request.revision != revision ||
|
||||
!save_path_in_directory(request.path, save_directory, ".ein")) {
|
||||
!save_path_in_directory(request.path, save_directory,
|
||||
content::find(data) ? ".obsettings" : ".ein")) {
|
||||
flow.reject_settings_file("stale_request_or_invalid_settings_path");
|
||||
return {};
|
||||
}
|
||||
@@ -1909,7 +1910,8 @@ std::string serve_flow_request(ui::StartupFlow& flow, const ui::FlowResult& resu
|
||||
return {};
|
||||
}
|
||||
if (request.revision != revision ||
|
||||
!save_path_in_directory(request.path, save_directory, ".men")) {
|
||||
!save_path_in_directory(request.path, save_directory,
|
||||
content::find(data) ? ".oblayout" : ".men")) {
|
||||
flow.reject_file_action("stale_request_or_invalid_menu_layout_path");
|
||||
return {};
|
||||
}
|
||||
@@ -1927,7 +1929,8 @@ std::string serve_flow_request(ui::StartupFlow& flow, const ui::FlowResult& resu
|
||||
}
|
||||
} else if (result.request == ui::FlowRequest::file_action) {
|
||||
const auto& request = result.file_action;
|
||||
if (request.revision != revision || !save_path_in_directory(request.path, save_directory)) {
|
||||
if (request.revision != revision ||
|
||||
!save_path_in_directory(request.path, save_directory, content::find(data) ? ".obs" : ".fbm")) {
|
||||
flow.reject_file_action("stale_request_or_invalid_save_path");
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "content/package.hpp"
|
||||
#include "import/detail.hpp"
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
namespace bmh::content {
|
||||
@@ -113,6 +114,12 @@ std::shared_ptr<const Classic> open(const fs::path &path) {
|
||||
auto docs = read_archive(path);
|
||||
const auto id = verify(docs);
|
||||
auto value = std::make_shared<Classic>(obw::load_classic(docs));
|
||||
constexpr std::array<uint8_t, 9> german{18, 18, 18, 18, 18, 12, 12, 12, 12};
|
||||
constexpr std::array<uint8_t, 9> english{20, 20, 20, 20, 10, 12, 12, 12, 12};
|
||||
const auto &leagues = value->english ? english : german;
|
||||
for (size_t i = 0; i < leagues.size(); ++i)
|
||||
if (value->executable.u8(layout::LeagueSizes + uint32_t(i)) != leagues[i])
|
||||
fail("Classic supports only the original BMH and Football Limited league structures");
|
||||
value->content_id = id;
|
||||
const auto manifest = parse(docs, "manifest.json");
|
||||
value->start_year = std::stoi(str(get(manifest, "start_date")).substr(0, 4));
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "formats/executable_layout.hpp"
|
||||
|
||||
namespace bmh::layout {
|
||||
// Football Limited V2.20 data-segment locations of the OPL voice slots and
|
||||
// the 96-word key-on frequency table. Kept separate from simulation tables.
|
||||
inline constexpr auto EnglishAudioOperatorSlots = EnDataStart + 0x6a63;
|
||||
inline constexpr auto EnglishAudioNoteFrequencies = EnDataStart + 0xb310;
|
||||
} // namespace bmh::layout
|
||||
@@ -47,8 +47,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_SOURCE})
|
||||
target_link_libraries(native_runtime_tests PRIVATE bmhui bmh_launcher)
|
||||
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)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "formats/audio_layout.hpp"
|
||||
#include "launch/fltd.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -119,6 +120,13 @@ LeImage translate_fltd(const fs::path& fltd_exe, bool apply_supported_rules) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Bind the English audio driver's data explicitly; the general UI/table map
|
||||
// does not cover its OPL voice slots or key-on frequency table.
|
||||
for (uint32_t i = 0; i < 9; ++i)
|
||||
put(layout::Audio_OriginalAudioAssets_RuntimeField + i * 16,
|
||||
en(layout::EnglishAudioOperatorSlots + i * 16));
|
||||
for (uint32_t i = 0; i < 96 * 2; ++i)
|
||||
put(layout::Audio_OriginalAudioAssets_RuntimeField2 + i, en(layout::EnglishAudioNoteFrequencies + i));
|
||||
LeImage out = LeImage::from_bytes(kDeBase, std::move(image));
|
||||
if (apply_supported_rules) apply_rule_base(out);
|
||||
return out;
|
||||
|
||||
@@ -379,7 +379,8 @@ ResolvedGame resolve_game(const fs::path& input, const fs::path& cache) {
|
||||
const fs::path marker = prepared / ".openbmh-english";
|
||||
// the version of the translation (launch/fltd.cpp, fltd_map.inc): a cache built
|
||||
// by another version is built again
|
||||
constexpr const char* kTranslation = "english translation 13"; // 13: setup toggle rows, positive balance colour and desktop bar controls
|
||||
constexpr const char *kTranslation =
|
||||
"english translation 14"; // 14: bind native English OPL slots and note frequencies
|
||||
std::string built;
|
||||
{
|
||||
std::ifstream in(marker);
|
||||
|
||||
@@ -22,8 +22,15 @@ int run_launcher(const std::filesystem::path &executable, const SaveMigrator &mi
|
||||
if (!source)
|
||||
continue;
|
||||
const auto check = check_game_directory(*source);
|
||||
if (!check.playable)
|
||||
throw FormatError("Installation wird nicht unterstützt: " + check.unsupported);
|
||||
// Raw English installations are importable before legacy directory
|
||||
// normalisation, so their old runtime "playable" flag is irrelevant.
|
||||
if ((check.family != GameFamily::german && check.family != GameFamily::english) ||
|
||||
!check.problems.empty()) {
|
||||
std::string reason = check.unsupported;
|
||||
for (const auto &problem : check.problems)
|
||||
reason += "\n" + problem;
|
||||
throw FormatError("Installation wird nicht unterstützt: " + reason);
|
||||
}
|
||||
AddMod initial;
|
||||
initial.source = check.directory;
|
||||
initial.saves = check.directory;
|
||||
|
||||
@@ -81,6 +81,9 @@ struct Form {
|
||||
if (!window)
|
||||
throw std::runtime_error("Cannot create native launcher window");
|
||||
command = [this](int id) {
|
||||
// Edit controls also emit WM_COMMAND while the user types.
|
||||
if (id != IDOK && id != IDCANCEL)
|
||||
return;
|
||||
response = id;
|
||||
done = true;
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
constexpr uint32_t kTextBase = ::bmh::layout::TextPointerTable;
|
||||
constexpr size_t kFilenameBytes = 251; // Host filename limit, including the four-byte .FBM suffix.
|
||||
constexpr size_t kHostFilenameBytes = 255; // Includes the selected native or legacy extension.
|
||||
std::string path_to_utf8(const std::filesystem::path& path) {
|
||||
const auto value = path.u8string();
|
||||
return std::string(value.begin(), value.end());
|
||||
@@ -24,11 +24,10 @@ std::string path_to_utf8(const std::filesystem::path& path) {
|
||||
std::filesystem::path path_from_utf8(std::string_view value) {
|
||||
return std::filesystem::path(std::u8string(value.begin(), value.end()));
|
||||
}
|
||||
bool valid_filename(std::string_view value) {
|
||||
return !value.empty() && value.size() <= kFilenameBytes && value != "." && value != ".." &&
|
||||
std::all_of(value.begin(), value.end(), [](unsigned char c) {
|
||||
return c >= 32 && c != 127 && c != '/' && c != '\\';
|
||||
});
|
||||
bool valid_filename(std::string_view value, size_t maximum) {
|
||||
return !value.empty() && value.size() <= maximum && value != "." && value != ".." &&
|
||||
std::all_of(value.begin(), value.end(),
|
||||
[](unsigned char c) { return c >= 32 && c != 127 && c != '/' && c != '\\'; });
|
||||
}
|
||||
std::string_view text_at(const TextDb& texts, uint32_t address) {
|
||||
if (address < kTextBase || ((address - kTextBase) & 3u) != 0)
|
||||
@@ -319,7 +318,7 @@ void SaveLoadScreen::request_action() {
|
||||
entries_[size_t(selected_)].path, false, file_kind_, origin_item_id_};
|
||||
return;
|
||||
}
|
||||
if (!valid_filename(filename_)) {
|
||||
if (!valid_filename(filename_, kHostFilenameBytes - file_kind_extension(file_kind_, native_).size())) {
|
||||
feedback_ = "UNGUELTIGER DATEINAME"; return;
|
||||
}
|
||||
auto path =
|
||||
@@ -397,7 +396,8 @@ bool SaveLoadScreen::key(std::string_view value) {
|
||||
bool SaveLoadScreen::text(std::string_view value) {
|
||||
if (info_ || mode_ != SaveLoadMode::save || !filename_focus_ || pending_ || value.empty()) return false;
|
||||
const std::string next = (filename_selected_ ? std::string{} : filename_) + std::string(value);
|
||||
if (!valid_filename(next)) return false;
|
||||
if (!valid_filename(next, kHostFilenameBytes - file_kind_extension(file_kind_, native_).size()))
|
||||
return false;
|
||||
filename_ = next; filename_selected_ = false;
|
||||
overwrite_armed_ = false; feedback_.clear(); return true;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
// 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;
|
||||
@@ -32,17 +35,44 @@ int main(int argc, char **argv) try {
|
||||
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);
|
||||
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);
|
||||
app::CareerSession old(resolved.check.directory, 12345);
|
||||
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(),
|
||||
@@ -63,6 +93,8 @@ int main(int argc, char **argv) try {
|
||||
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();
|
||||
@@ -79,6 +111,44 @@ int main(int argc, char **argv) try {
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user