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
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user