Restore direct-installation Classic baseline for OpenBMH 1.0 (by Codex)

This commit is contained in:
Codex committed 2026-10-30 14:19:25 +01:00
1 parent c8f04d0099
commit c3704878d6
255 files changed
+311 -21131

No files matched your search

+1 -3
View File
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "formats/content.hpp"
#include "formats/executable_layout.hpp"
// Information windows of docs/CLI_CONCEPT/05-information.md that the engine can already
// project: TeamInfo (club information, from LeagueTable / Fixtures), HighScore (menu 26) and
@@ -187,8 +186,7 @@ void Console::register_info_commands() {
const uint16_t signature = g.memory.has(::bmh::layout::CareerSession_FormatError_RuntimeField7) ? g.memory.u16(::bmh::layout::CareerSession_FormatError_RuntimeField7) : 0;
if (signature != 0) {
// the ranked list of this game's level, stored next to the saved games
const auto file = highscore_file(save_directory(), signature, texts_.strings.at(kHighscorePrefix),
bool(content::find(options_.data)));
const auto file = highscore_file(save_directory(), signature, texts_.strings.at(kHighscorePrefix));
HighscoreTable rows{};
std::error_code ec;
if (std::filesystem::exists(file, ec)) rows = load_highscore_table(file);
+3 -7
View File
@@ -5,7 +5,6 @@
#include <algorithm>
#include "formats/content.hpp"
#include "cli/console/console.hpp"
#include "cli/console/detail.hpp"
#include "ui/cup_draw.hpp"
@@ -397,8 +396,7 @@ std::filesystem::path Console::browser_file(const std::string& name) const {
if (name == "." || name == ".." || name.find_first_of("/\\:") != std::string::npos)
fail("E_BAD_ARGUMENT", "not a file name: " + name + " (no directories; use ChangeDirectory)");
std::filesystem::path path = browse_directory_ / name;
if (!path.has_extension())
path += content::find(options_.data) ? ".obs" : ".FBM";
if (!path.has_extension()) path += ".FBM";
return path;
}
@@ -412,8 +410,7 @@ void Console::register_file_commands() {
std::error_code ec;
for (const auto& entry : std::filesystem::directory_iterator(browse_directory_, ec)) {
if (entry.is_directory(ec)) dirs.push_back({entry.path().filename().string(), "dir"});
else if (entry.is_regular_file(ec) && lower(entry.path().extension().string()) ==
(content::find(options_.data) ? ".obs" : ".fbm"))
else if (entry.is_regular_file(ec) && lower(entry.path().extension().string()) == ".fbm")
files.push_back({entry.path().stem().string(), "file"});
}
if (ec) fail("E_IO", "cannot read the directory " + shown_directory());
@@ -466,8 +463,7 @@ void Console::register_file_commands() {
void Console::load_game(const std::filesystem::path& requested) {
std::filesystem::path path = requested;
if (!path.has_extension())
path += content::find(options_.data) ? ".obs" : ".FBM";
if (!path.has_extension()) path += ".FBM";
std::error_code ec;
if (!std::filesystem::is_regular_file(path, ec)) fail("E_IO", "file not found: " + path.filename().string());
std::unique_ptr<app::CareerSession> loaded;
+23 -64
View File
@@ -32,9 +32,6 @@
#include "launch/archive.hpp"
#include "launch/game_data.hpp"
#include "content/package.hpp"
#include "launch/process.hpp"
#include "launch/mods.hpp"
#include "version.hpp"
namespace {
@@ -86,8 +83,7 @@ Arguments parse_args(int argc, char** argv) {
std::exit(0);
}
if (arg == "--help" || arg == "-h") args.help = true;
else if (arg == "--data" || arg == "--mod")
args.data = bmh::launch::path_from_utf8(next(arg));
else if (arg == "--data") args.data = bmh::launch::path_from_utf8(next(arg));
else if (arg == "--seed") { args.seed = parse_seed(next(arg)); args.seed_set = true; }
else if (arg == "--text") args.json = false;
else if (arg == "--json") args.json = true;
@@ -120,26 +116,21 @@ Arguments parse_args(int argc, char** argv) {
}
void print_usage() {
std::cout
<< "openbmh_cli --mod <content.obw> [--seed <n>] [--text|--json] [--log <jsonl>]\n"
"openbmh_cli --replay <jsonl> [--mod <content.obw>] [--text|--json]\n"
"openbmh_cli --console --mod <content.obw> [--saves <dir>] [--seed <n>] [--text|--json] [--echo]\n"
" [--log|--replay <jsonl> [--keep-going]] [--serve <dir> | --listen <port>] [--seats "
"N]\n"
" --listen: the console on 127.0.0.1:<port>, line protocol (SEAT k with --seats; a block ends\n"
" with go., the answer with a line \".\"); --json gives structured lines, State(view) "
"projections.\n"
" --seats N: one mailbox <dir>/seat<k> per manager; a request \"WaitTurn\" waits for k's turn.\n"
" --resume <jsonl>: with --seats, first play an earlier session log again, then go on.\n"
"openbmh_cli --send <dir> [--timeout <seconds>] (the block on stdin)\n"
" --serve: the session answers blocks dropped into <dir> (request-N.txt -> response-N.txt);\n"
" --send hands one block to it and prints the answer - for agents that work in steps.\n"
" console language (docs/CLI_CONCEPT): command lines, executed by a line \"go.\";\n"
" ListOptions shows what is possible, Help the reference, Quit ends.\n"
"Commands: help, new, load, save, status, desk, kickoff, camp.*, bank.*, stadium.*, toto.submit, "
"quit\n"
"Text: new <master_club> <manager_name> [strength], load/save <path>, kickoff, status, desk, "
"quit\n";
std::cout << "openbmh_cli --data <BMH directory> [--seed <n>] [--text|--json] [--log <jsonl>]\n"
"openbmh_cli --replay <jsonl> [--data <BMH directory>] [--text|--json]\n"
"openbmh_cli --console --data <BMH directory> [--saves <dir>] [--seed <n>] [--text|--json] [--echo]\n"
" [--log|--replay <jsonl> [--keep-going]] [--serve <dir> | --listen <port>] [--seats N]\n"
" --listen: the console on 127.0.0.1:<port>, line protocol (SEAT k with --seats; a block ends\n"
" with go., the answer with a line \".\"); --json gives structured lines, State(view) projections.\n"
" --seats N: one mailbox <dir>/seat<k> per manager; a request \"WaitTurn\" waits for k's turn.\n"
" --resume <jsonl>: with --seats, first play an earlier session log again, then go on.\n"
"openbmh_cli --send <dir> [--timeout <seconds>] (the block on stdin)\n"
" --serve: the session answers blocks dropped into <dir> (request-N.txt -> response-N.txt);\n"
" --send hands one block to it and prints the answer - for agents that work in steps.\n"
" console language (docs/CLI_CONCEPT): command lines, executed by a line \"go.\";\n"
" ListOptions shows what is possible, Help the reference, Quit ends.\n"
"Commands: help, new, load, save, status, desk, kickoff, camp.*, bank.*, stadium.*, toto.submit, quit\n"
"Text: new <master_club> <manager_name> [strength], load/save <path>, kickoff, status, desk, quit\n";
}
std::string command_line_response(const Json& response) {
@@ -719,46 +710,14 @@ int main(int argc, char** argv) {
Arguments args = parse_args(argc, argv);
if (args.help) { print_usage(); return 0; }
if (!args.send.empty()) return run_send(args);
// Replay and resumed sessions can supply their content/save paths in
// the log header. Resolve them before mounting or selecting defaults.
const auto &source_log = !args.replay.empty() ? args.replay : args.resume;
if (!source_log.empty()) {
std::ifstream input(source_log, std::ios::binary);
std::string line;
if (!input || !std::getline(input, line))
throw std::runtime_error("cannot_read_session_log_header");
const auto header = parse_json(line);
const auto *fields = header.object();
if (!fields || !fields->contains("type") || !fields->at("type").string() ||
*fields->at("type").string() != (args.console ? "openbmh_console_log" : "openbmh_cli_log"))
throw std::runtime_error("invalid_session_log_header");
if (args.data.empty()) {
if (!fields->contains("data") || !fields->at("data").string())
throw std::runtime_error("missing_session_content_path");
args.data = bmh::launch::path_from_utf8(*fields->at("data").string());
}
if (args.console && args.saves.empty() && fields->contains("saves") &&
fields->at("saves").string())
args.saves = bmh::launch::path_from_utf8(*fields->at("saves").string());
}
std::shared_ptr<const bmh::content::Classic> contents;
std::unique_ptr<bmh::content::Mount> mount;
// --data may also name BMH.EXE or a ZIP/7z archive with one game (src/launch); an
// archive is unpacked into the per-user cache and its copy is used
if (!args.data.empty()) {
if (std::filesystem::is_directory(args.data))
args.data /= "content.obw";
contents = bmh::content::open(args.data);
mount = std::make_unique<bmh::content::Mount>(args.data, contents);
args.data = mount->root();
if (args.saves.empty()) {
bmh::launch::ModLibrary library(
bmh::launch::executable_path(bmh::launch::path_from_utf8(argv[0])).parent_path());
bmh::launch::ModEntry mod;
mod.content_id = contents->content_id;
args.saves = library.user_directory(mod);
}
} else
throw std::runtime_error(
"0.2 requires --mod <content.obw>; import installations in OpenBMH first");
const auto game = bmh::launch::resolve_game(args.data, bmh::launch::default_cache_directory());
if (!game.error.empty() || !game.check.playable)
throw std::runtime_error("the game cannot be used:\n" + bmh::launch::describe(game));
args.data = game.check.directory;
}
if (args.console) {
if (!args.log.empty() && !args.replay.empty()) throw std::runtime_error("--log and --replay cannot be combined");
if (args.listen_port) return run_console_listen(args);