Restore direct-installation Classic baseline for OpenBMH 1.0 (by Codex)
This commit is contained in:
1 parent
c8f04d0099
commit
c3704878d6
255 files changed
+311
-21131
No files matched your search
+2
-10
@@ -1,6 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "formats/audio_layout.hpp"
|
||||
#include "launch/fltd.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -72,7 +71,7 @@ const OwnText kOwnTexts[] = {
|
||||
|
||||
} // namespace
|
||||
|
||||
LeImage translate_fltd(const fs::path& fltd_exe, bool apply_supported_rules) {
|
||||
LeImage translate_fltd(const fs::path& fltd_exe) {
|
||||
const Bytes raw = read_file(fltd_exe);
|
||||
if (raw.size() != kFltdSize || raw[0] != 'M' || raw[1] != 'Z')
|
||||
throw std::runtime_error(path_to_utf8(fltd_exe) + " is not the Football Limited FLTD.EXE");
|
||||
@@ -120,15 +119,8 @@ 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);
|
||||
apply_rule_base(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
namespace bmh::launch {
|
||||
|
||||
// The German-layout image of FLTD.EXE (throws std::runtime_error for another file).
|
||||
LeImage translate_fltd(const std::filesystem::path& fltd_exe, bool apply_supported_rules = true);
|
||||
LeImage translate_fltd(const std::filesystem::path& fltd_exe);
|
||||
|
||||
// Builds the German-layout data directory `target` from the English game in `source`.
|
||||
// Returns false with `error` set when a file cannot be read or written.
|
||||
|
||||
@@ -96,9 +96,6 @@
|
||||
{::bmh::layout::TeamStatistics_Render_ExecutableField, 2, Kind::copy, ::bmh::layout::EnglishLayoutTranslation72, {}},
|
||||
{::bmh::layout::DeskDrawers_Curve_ExecutableField, 24, Kind::copy, ::bmh::layout::EnglishLayoutTranslation160, {}},
|
||||
{::bmh::layout::DeskState_FormatError_RuntimeField, 4, Kind::copy, ::bmh::layout::EnglishLayoutTranslation161, {}},
|
||||
{::bmh::layout::Desktop_Render_RuntimeField, 2, Kind::copy, ::bmh::layout::EnglishDesktopBinSourceX, {}},
|
||||
{::bmh::layout::Desktop_Render_RuntimeField2, 2, Kind::copy, ::bmh::layout::EnglishDesktopBinSourceY, {}},
|
||||
{::bmh::layout::Desktop_Render_RuntimeField3, 2, Kind::copy, ::bmh::layout::EnglishDesktopSocketSourceX, {}},
|
||||
{::bmh::layout::Tactics_DrawSetting_RuntimeField, 4, Kind::copy, ::bmh::layout::EnglishLayoutTranslation224, {}},
|
||||
{::bmh::layout::Tactics_DrawSetting_RuntimeField2, 1, Kind::copy, ::bmh::layout::EnglishLayoutTranslation225, {}},
|
||||
{::bmh::layout::Tactics_DrawSetting_RuntimeField3, 7, Kind::copy, ::bmh::layout::EnglishLayoutTranslation226, {}},
|
||||
|
||||
@@ -379,8 +379,7 @@ 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 14"; // 14: bind native English OPL slots and note frequencies
|
||||
constexpr const char* kTranslation = "english translation 12"; // 12: contract warning ContractExpiryWarningText; 11: statistics windows, graph labels/count classes, streaks and national-badge banks
|
||||
std::string built;
|
||||
{
|
||||
std::ifstream in(marker);
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "launch/launcher.hpp"
|
||||
#include "launch/launcher_ui.hpp"
|
||||
#include "launch/process.hpp"
|
||||
#include "launch/game_data.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
#include <atomic>
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
namespace bmh::launch {
|
||||
int run_launcher(const std::filesystem::path &executable, const SaveMigrator &migrate) {
|
||||
auto ui = make_launcher_ui();
|
||||
ModLibrary library(executable.parent_path());
|
||||
for (;;)
|
||||
try {
|
||||
const auto mods = library.list();
|
||||
const auto action = ui->next(mods);
|
||||
if (action.action == LauncherAction::end)
|
||||
return 0;
|
||||
if (action.action == LauncherAction::add) {
|
||||
const auto source = ui->choose_folder("BMH-/Football-Limited-Installation wählen");
|
||||
if (!source)
|
||||
continue;
|
||||
const auto check = check_game_directory(*source);
|
||||
// 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;
|
||||
initial.name = check.family == GameFamily::english ? "FTDL-classic" : "BMH-classic";
|
||||
const auto request = ui->configure_add(initial);
|
||||
if (!request)
|
||||
continue;
|
||||
std::mutex mutex;
|
||||
std::string text = "Import wird vorbereitet …";
|
||||
std::atomic_bool cancelled = false;
|
||||
ui->progress(text, true);
|
||||
auto job = std::async(std::launch::async, [&] {
|
||||
return library.add(*request, migrate, [&](const std::string &s) {
|
||||
if (cancelled.load())
|
||||
throw FormatError("Import abgebrochen");
|
||||
std::lock_guard lock(mutex);
|
||||
text = s;
|
||||
});
|
||||
});
|
||||
while (job.wait_for(std::chrono::milliseconds(20)) != std::future_status::ready) {
|
||||
if (ui->pump())
|
||||
cancelled = true;
|
||||
std::lock_guard lock(mutex);
|
||||
ui->progress(text, true);
|
||||
}
|
||||
ui->finish_progress();
|
||||
const auto report = job.get();
|
||||
std::string summary =
|
||||
"Mod importiert: " + report.mod.name +
|
||||
"\nÜbernommene Spielstände/Einstellungen: " + std::to_string(report.migrated);
|
||||
for (const auto &error : report.errors)
|
||||
summary += "\n" + error;
|
||||
ui->message(summary, false);
|
||||
continue;
|
||||
}
|
||||
if (action.selection < 0 || size_t(action.selection) >= mods.size())
|
||||
continue;
|
||||
const auto &mod = mods[size_t(action.selection)];
|
||||
if (action.action == LauncherAction::remove) {
|
||||
if (ui->confirm_delete(mod.name))
|
||||
library.remove(mod);
|
||||
} else if (action.action == LauncherAction::rename) {
|
||||
if (const auto name = ui->rename(mod.name))
|
||||
library.rename(mod, *name);
|
||||
} else if (action.action == LauncherAction::start) {
|
||||
if (!mod.error.empty())
|
||||
throw FormatError(mod.error);
|
||||
(void)content::open(mod.directory / "content.obw");
|
||||
const auto userdata = library.user_directory(mod);
|
||||
ui->progress("Spiel läuft: " + mod.name, false);
|
||||
const int code = run_child(executable,
|
||||
{"--run-mod", path_to_utf8(mod.directory / "content.obw"),
|
||||
"--save-directory", path_to_utf8(userdata)},
|
||||
[&] { ui->pump(); });
|
||||
ui->finish_progress();
|
||||
if (code)
|
||||
ui->message("Das Spiel wurde mit Fehlercode " + std::to_string(code) + " beendet.", true);
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
ui->finish_progress();
|
||||
ui->message(e.what(), true);
|
||||
}
|
||||
}
|
||||
} // namespace bmh::launch
|
||||
@@ -1,6 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "launch/mods.hpp"
|
||||
namespace bmh::launch {
|
||||
int run_launcher(const std::filesystem::path &executable, const SaveMigrator &);
|
||||
} // namespace bmh::launch
|
||||
@@ -1,508 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "launch/archive.hpp"
|
||||
#include "launch/launcher_ui.hpp"
|
||||
#include "launch/process.hpp"
|
||||
#include "launch/rml_path.hpp"
|
||||
#include "launch/rml_video.hpp"
|
||||
#include "version.hpp"
|
||||
#include <RmlUi/Core.h>
|
||||
#include <RmlUi/Core/Elements/ElementFormControl.h>
|
||||
#include <RmlUi/Core/Elements/ElementFormControlInput.h>
|
||||
#include <RmlUi_Platform_SDL.h>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <nfd.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace bmh::launch {
|
||||
namespace {
|
||||
std::string escape(std::string_view value) {
|
||||
std::string result;
|
||||
for (char c : value)
|
||||
switch (c) {
|
||||
case '&':
|
||||
result += "&";
|
||||
break;
|
||||
case '<':
|
||||
result += "<";
|
||||
break;
|
||||
case '>':
|
||||
result += ">";
|
||||
break;
|
||||
case '"':
|
||||
result += """;
|
||||
break;
|
||||
case '\n':
|
||||
result += "<br/>";
|
||||
break;
|
||||
default:
|
||||
result += c;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
int modifiers(Uint16 state) {
|
||||
int result = 0;
|
||||
if (state & KMOD_CTRL)
|
||||
result |= Rml::Input::KM_CTRL;
|
||||
if (state & KMOD_SHIFT)
|
||||
result |= Rml::Input::KM_SHIFT;
|
||||
if (state & KMOD_ALT)
|
||||
result |= Rml::Input::KM_ALT;
|
||||
if (state & KMOD_GUI)
|
||||
result |= Rml::Input::KM_META;
|
||||
#ifdef __APPLE__
|
||||
// RmlUI text widgets use the Ctrl flag for editing shortcuts.
|
||||
if (state & KMOD_GUI)
|
||||
result |= Rml::Input::KM_CTRL;
|
||||
#endif
|
||||
if (state & KMOD_CAPS)
|
||||
result |= Rml::Input::KM_CAPSLOCK;
|
||||
if (state & KMOD_NUM)
|
||||
result |= Rml::Input::KM_NUMLOCK;
|
||||
return result;
|
||||
}
|
||||
class RmlLauncher final : public LauncherUI, public Rml::EventListener {
|
||||
rml::Video video_{"OpenBMH", 1100, 688, 800, 540};
|
||||
rml::AssetFiles files_;
|
||||
SystemInterface_SDL system_{video_.window};
|
||||
rml::Renderer renderer_{video_};
|
||||
TextInputMethodEditor_SDL ime_;
|
||||
Rml::Context *context_ = nullptr;
|
||||
Rml::ElementDocument *document_ = nullptr;
|
||||
bool initialized_ = false, closed_ = false, dirty_ = true;
|
||||
bool answered_ = false, accepted_ = false, busy_ = false, cancelled_ = false;
|
||||
bool cancellable_ = false, modal_visible_ = false;
|
||||
int selected_ = -1;
|
||||
std::string selected_name_;
|
||||
std::vector<ModEntry> mods_;
|
||||
std::optional<LauncherAction> action_;
|
||||
|
||||
Rml::Element *element(const char *id) const {
|
||||
auto *value = document_->GetElementById(id);
|
||||
if (!value)
|
||||
throw std::runtime_error(std::string("Launcher element missing: ") + id);
|
||||
return value;
|
||||
}
|
||||
void text(const char *id, const std::string &value) {
|
||||
element(id)->SetInnerRML(escape(value));
|
||||
dirty_ = true;
|
||||
}
|
||||
void display(const char *id, bool shown, const char *style = "block") {
|
||||
element(id)->SetProperty("display", shown ? style : "none");
|
||||
dirty_ = true;
|
||||
}
|
||||
void enabled(const char *id, bool active) {
|
||||
auto *button = element(id);
|
||||
if (active)
|
||||
button->RemoveAttribute("disabled");
|
||||
else
|
||||
button->SetAttribute("disabled", "disabled");
|
||||
button->SetPseudoClass("disabled", !active);
|
||||
button->SetProperty("focus", active ? "auto" : "none");
|
||||
dirty_ = true;
|
||||
}
|
||||
std::string value(const char *id) const {
|
||||
auto *input = dynamic_cast<Rml::ElementFormControl *>(element(id));
|
||||
if (!input)
|
||||
throw std::runtime_error("Launcher input has the wrong type");
|
||||
return input->GetValue();
|
||||
}
|
||||
void resize() {
|
||||
int w = 0, h = 0, pixels_w = 0, pixels_h = 0;
|
||||
SDL_GetWindowSize(video_.window, &w, &h);
|
||||
video_.drawable_size(pixels_w, pixels_h);
|
||||
if (w <= 0 || h <= 0 || pixels_w <= 0 || pixels_h <= 0)
|
||||
return;
|
||||
renderer_.SetViewport(pixels_w, pixels_h);
|
||||
context_->SetDimensions({pixels_w, pixels_h});
|
||||
const float scale = std::clamp(std::min(w / 1100.f, h / 688.f), .72f, 2.5f);
|
||||
context_->SetDensityIndependentPixelRatio(float(pixels_w) / w * scale);
|
||||
dirty_ = true;
|
||||
}
|
||||
void select(int index, bool focus = false) {
|
||||
if (index < 0 || size_t(index) >= mods_.size())
|
||||
index = -1;
|
||||
selected_ = index;
|
||||
selected_name_ = index >= 0 ? mods_[size_t(index)].name : std::string{};
|
||||
for (size_t i = 0; i < mods_.size(); ++i) {
|
||||
auto *row = document_->GetElementById("mod-" + std::to_string(i));
|
||||
row->SetClass("selected", int(i) == selected_);
|
||||
row->SetAttribute("aria-selected", int(i) == selected_ ? "true" : "false");
|
||||
if (focus && int(i) == selected_) {
|
||||
row->Focus(true);
|
||||
row->ScrollIntoView();
|
||||
}
|
||||
}
|
||||
enabled("start", selected_ >= 0);
|
||||
enabled("delete", selected_ >= 0);
|
||||
enabled("rename", selected_ >= 0);
|
||||
}
|
||||
bool modal_open() const { return modal_visible_; }
|
||||
void close_modal() {
|
||||
modal_visible_ = false;
|
||||
display("overlay", false);
|
||||
answered_ = false;
|
||||
busy_ = false;
|
||||
SDL_StopTextInput();
|
||||
if (selected_ >= 0)
|
||||
select(selected_, true);
|
||||
else
|
||||
element("add")->Focus(true);
|
||||
}
|
||||
void modal(const std::string &title, const std::string &body, const std::string &accept,
|
||||
bool cancel = true, bool danger = false) {
|
||||
text("modal-title", title);
|
||||
element("modal-body")->SetInnerRML(body);
|
||||
text("modal-error", "");
|
||||
text("accept", accept);
|
||||
element("accept")->SetClass("danger", danger);
|
||||
element("accept")->SetClass("primary", !danger);
|
||||
display("accept", !accept.empty(), "inline-block");
|
||||
display("cancel", cancel, "inline-block");
|
||||
answered_ = accepted_ = false;
|
||||
display("overlay", true);
|
||||
modal_visible_ = true;
|
||||
context_->Update();
|
||||
if (auto *input = document_->GetElementById("mod-name"))
|
||||
input->Focus(true);
|
||||
else
|
||||
element(cancel ? "cancel" : "accept")->Focus(true);
|
||||
context_->Update();
|
||||
dirty_ = true;
|
||||
}
|
||||
void dispatch(const std::string &command) {
|
||||
if (command == "cancel") {
|
||||
if (busy_) {
|
||||
if (cancellable_)
|
||||
cancelled_ = true;
|
||||
} else {
|
||||
answered_ = true;
|
||||
accepted_ = false;
|
||||
}
|
||||
} else if (command == "accept" && !busy_) {
|
||||
answered_ = accepted_ = true;
|
||||
} else if (command == "browse" && !busy_) {
|
||||
try {
|
||||
if (auto path =
|
||||
choose_folder("Spielstandsordner wählen", path_from_utf8(value("save-folder")))) {
|
||||
auto *input = dynamic_cast<Rml::ElementFormControl *>(element("save-folder"));
|
||||
input->SetValue(path_to_utf8(*path));
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
text("modal-error", e.what());
|
||||
}
|
||||
} else if (!modal_open()) {
|
||||
if (command == "add")
|
||||
action_ = LauncherAction::add;
|
||||
else if (command == "end")
|
||||
action_ = LauncherAction::end;
|
||||
else if (selected_ >= 0) {
|
||||
if (command == "start")
|
||||
action_ = LauncherAction::start;
|
||||
else if (command == "rename")
|
||||
action_ = LauncherAction::rename;
|
||||
else if (command == "delete")
|
||||
action_ = LauncherAction::remove;
|
||||
}
|
||||
}
|
||||
dirty_ = true;
|
||||
}
|
||||
void ProcessEvent(Rml::Event &event) override {
|
||||
const bool double_click = event.GetType() == "dblclick";
|
||||
if (event.GetType() != "click" && !double_click)
|
||||
return;
|
||||
for (auto *target = event.GetTargetElement(); target && target != document_;
|
||||
target = target->GetParentNode()) {
|
||||
if (target->HasAttribute("data-row") && !modal_open()) {
|
||||
select(target->GetAttribute<int>("data-row", -1));
|
||||
if (double_click)
|
||||
dispatch("start");
|
||||
return;
|
||||
}
|
||||
if (target->HasAttribute("data-action")) {
|
||||
if (double_click)
|
||||
return;
|
||||
if (!target->HasAttribute("disabled"))
|
||||
dispatch(target->GetAttribute<Rml::String>("data-action", ""));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void step(bool wait) {
|
||||
// Modal visibility and refreshed rows must be laid out before queued
|
||||
// pointer events are hit-tested against the new document state.
|
||||
if (dirty_) context_->Update();
|
||||
SDL_Event event;
|
||||
const int timeout = dirty_ ? 0 : int(std::clamp(context_->GetNextUpdateDelay(), 0.0, .2) * 1000);
|
||||
bool got = wait ? SDL_WaitEventTimeout(&event, timeout) != 0 : SDL_PollEvent(&event) != 0;
|
||||
bool redraw = dirty_ || got || context_->GetNextUpdateDelay() <= 0;
|
||||
while (got) {
|
||||
if (event.type == SDL_QUIT ||
|
||||
(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE)) {
|
||||
closed_ = answered_ = true;
|
||||
accepted_ = false;
|
||||
cancelled_ = true;
|
||||
action_ = LauncherAction::end;
|
||||
} else if (event.type == SDL_KEYDOWN && !event.key.repeat &&
|
||||
event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
if (modal_open())
|
||||
dispatch("cancel");
|
||||
else
|
||||
action_ = LauncherAction::end;
|
||||
} else if (event.type == SDL_KEYDOWN && modal_open() && event.key.keysym.sym == SDLK_TAB) {
|
||||
Rml::ElementList controls;
|
||||
element("modal")->QuerySelectorAll(controls, "input, button");
|
||||
std::erase_if(controls, [](auto *control) {
|
||||
return !control->IsVisible() || control->HasAttribute("disabled");
|
||||
});
|
||||
if (!controls.empty()) {
|
||||
const auto at = std::find(controls.begin(), controls.end(), context_->GetFocusElement());
|
||||
const int current = at == controls.end() ? -1 : int(at - controls.begin());
|
||||
const int step = event.key.keysym.mod & KMOD_SHIFT ? -1 : 1;
|
||||
const int next = (current + step + int(controls.size())) % int(controls.size());
|
||||
controls[size_t(next)]->Focus(true);
|
||||
}
|
||||
} else if (event.type == SDL_KEYDOWN && !modal_open() && !event.key.repeat &&
|
||||
(event.key.keysym.sym == SDLK_UP || event.key.keysym.sym == SDLK_DOWN)) {
|
||||
const int direction = event.key.keysym.sym == SDLK_UP ? -1 : 1;
|
||||
if (!mods_.empty())
|
||||
select(std::clamp(selected_ < 0 ? 0 : selected_ + direction, 0, int(mods_.size()) - 1),
|
||||
true);
|
||||
} else if (event.type == SDL_KEYDOWN && !event.key.repeat &&
|
||||
(event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_SPACE) &&
|
||||
context_->GetFocusElement() &&
|
||||
context_->GetFocusElement()->HasAttribute("data-action")) {
|
||||
auto *focused = context_->GetFocusElement();
|
||||
if (!focused->HasAttribute("disabled"))
|
||||
dispatch(focused->GetAttribute<Rml::String>("data-action", ""));
|
||||
} else if (event.type == SDL_KEYDOWN && !event.key.repeat &&
|
||||
event.key.keysym.sym == SDLK_RETURN) {
|
||||
if (modal_open() && !busy_)
|
||||
dispatch("accept");
|
||||
else if (!modal_open() && selected_ >= 0)
|
||||
dispatch("start");
|
||||
} else if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) {
|
||||
// Use the modifiers captured with this event, not SDL's final
|
||||
// state after pumping a batch containing the key releases.
|
||||
const auto key = RmlSDL::ConvertKey(event.key.keysym.sym);
|
||||
if (event.type == SDL_KEYDOWN)
|
||||
context_->ProcessKeyDown(key, modifiers(event.key.keysym.mod));
|
||||
else
|
||||
context_->ProcessKeyUp(key, modifiers(event.key.keysym.mod));
|
||||
} else {
|
||||
if (event.type == SDL_TEXTEDITING)
|
||||
ime_.HandleEdit(event.edit);
|
||||
// SDL2 reports mouse coordinates in window units on Retina/HiDPI.
|
||||
int w = 0, h = 0, pw = 0, ph = 0;
|
||||
SDL_GetWindowSize(video_.window, &w, &h);
|
||||
video_.drawable_size(pw, ph);
|
||||
if (w > 0 && h > 0) {
|
||||
if (event.type == SDL_MOUSEMOTION) {
|
||||
event.motion.x = int(double(event.motion.x) * pw / w);
|
||||
event.motion.y = int(double(event.motion.y) * ph / h);
|
||||
}
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) {
|
||||
event.button.x = int(double(event.button.x) * pw / w);
|
||||
event.button.y = int(double(event.button.y) * ph / h);
|
||||
// Repeated clicks need a fresh hover target even when
|
||||
// the pointer has not moved since a modal was closed.
|
||||
context_->ProcessMouseMove(event.button.x, event.button.y,
|
||||
RmlSDL::GetKeyModifierState());
|
||||
}
|
||||
}
|
||||
RmlSDL::InputEventHandler(context_, video_.window, event);
|
||||
}
|
||||
if (event.type == SDL_WINDOWEVENT)
|
||||
resize();
|
||||
got = SDL_PollEvent(&event) != 0;
|
||||
}
|
||||
if (redraw) {
|
||||
context_->Update();
|
||||
renderer_.BeginFrame();
|
||||
renderer_.Clear();
|
||||
context_->Render();
|
||||
renderer_.EndFrame();
|
||||
video_.present();
|
||||
dirty_ = false;
|
||||
}
|
||||
}
|
||||
bool wait_modal() {
|
||||
while (!answered_ && !closed_)
|
||||
step(true);
|
||||
answered_ = false;
|
||||
return accepted_ && !closed_;
|
||||
}
|
||||
|
||||
public:
|
||||
RmlLauncher() {
|
||||
SDL_StopTextInput();
|
||||
if (!renderer_)
|
||||
throw std::runtime_error("RmlUI could not create the graphics renderer");
|
||||
try {
|
||||
Rml::SetSystemInterface(&system_);
|
||||
Rml::SetFileInterface(&files_);
|
||||
Rml::SetRenderInterface(&renderer_);
|
||||
Rml::SetTextInputHandler(&ime_);
|
||||
initialized_ = Rml::Initialise();
|
||||
if (!initialized_)
|
||||
throw std::runtime_error("RmlUI initialization failed");
|
||||
const auto assets = executable_path({}).parent_path() / "assets" / "launcher";
|
||||
for (const char *weight : {"Regular", "Bold"})
|
||||
if (!Rml::LoadFontFace(rml::asset_path(assets / (std::string("LatoLatin-") + weight + ".ttf"))))
|
||||
throw std::runtime_error("Launcher font missing; extract the complete OpenBMH package");
|
||||
context_ = Rml::CreateContext("launcher", {1100, 688});
|
||||
if (!context_)
|
||||
throw std::runtime_error("RmlUI launcher context failed");
|
||||
document_ = context_->LoadDocument(rml::asset_path(assets / "launcher.rml"));
|
||||
if (!document_)
|
||||
throw std::runtime_error("Launcher layout missing; extract the complete OpenBMH package");
|
||||
document_->AddEventListener("click", this);
|
||||
document_->AddEventListener("dblclick", this);
|
||||
text("version", std::string("v") + bmh::kOpenBmhVersion);
|
||||
resize();
|
||||
document_->Show();
|
||||
SDL_ShowWindow(video_.window);
|
||||
element("add")->Focus(true);
|
||||
} catch (...) {
|
||||
if (initialized_)
|
||||
Rml::Shutdown();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
~RmlLauncher() override {
|
||||
if (initialized_)
|
||||
Rml::Shutdown();
|
||||
}
|
||||
LauncherChoice next(const std::vector<ModEntry> &mods) override {
|
||||
if (closed_)
|
||||
return {LauncherAction::end, -1};
|
||||
mods_ = mods;
|
||||
std::string rows;
|
||||
int selection = -1;
|
||||
for (size_t i = 0; i < mods.size(); ++i) {
|
||||
const auto &mod = mods[i];
|
||||
if (mod.name == selected_name_)
|
||||
selection = int(i);
|
||||
rows += "<button id=\"mod-" + std::to_string(i) + "\" class=\"mod-row" +
|
||||
(mod.error.empty() ? "" : " invalid") + "\" data-row=\"" + std::to_string(i) +
|
||||
"\" title=\"" + escape(mod.error) + "\"><span class=\"name\">" + escape(mod.name) +
|
||||
"</span><span class=\"type\">" + escape(mod.type) + "</span></button>";
|
||||
}
|
||||
if (mods.empty())
|
||||
rows = "<div class=\"empty\">Keine Mods vorhanden.<div class=\"empty-detail\">Über Add eine "
|
||||
"Installation hinzufügen.</div></div>";
|
||||
element("mod-list")->SetInnerRML(rows);
|
||||
text("mod-count", std::to_string(mods.size()) + (mods.size() == 1 ? " Mod" : " Mods"));
|
||||
select(selection);
|
||||
action_.reset();
|
||||
while (!action_ && !closed_)
|
||||
step(true);
|
||||
return {action_.value_or(LauncherAction::end), selected_};
|
||||
}
|
||||
std::optional<std::filesystem::path> choose_folder(const std::string &title,
|
||||
const std::filesystem::path &initial = {}) override {
|
||||
(void)title;
|
||||
NFD::Guard guard;
|
||||
NFD::UniquePathU8 result;
|
||||
const auto directory = path_to_utf8(initial.empty() ? executable_path({}).parent_path() : initial);
|
||||
const auto status = NFD::PickFolder(result, directory.c_str());
|
||||
SDL_RaiseWindow(video_.window);
|
||||
dirty_ = true;
|
||||
if (status == NFD_CANCEL)
|
||||
return {};
|
||||
if (status != NFD_OKAY)
|
||||
throw std::runtime_error(std::string("Ordnerauswahl: ") + NFD::GetError());
|
||||
return path_from_utf8(result.get());
|
||||
}
|
||||
std::optional<AddMod> configure_add(AddMod initial) override {
|
||||
modal("Classic-Mod hinzufügen",
|
||||
"<label>Bezeichnung</label><input id=\"mod-name\" type=\"text\" maxlength=\"100\" value=\"" +
|
||||
escape(initial.name) +
|
||||
"\"/><div class=\"fields\"><div class=\"year\"><label>Startjahr (nur "
|
||||
"Anzeige)</label><input id=\"start-year\" type=\"text\" maxlength=\"4\" value=\"" +
|
||||
std::to_string(initial.start_year) +
|
||||
"\"/></div></div><div class=\"check-row\"><input id=\"migrate\" class=\"checkbox\" "
|
||||
"type=\"checkbox\" " +
|
||||
(initial.migrate ? "checked=\"checked\"" : "") +
|
||||
"/><label for=\"migrate\">Spielstände/Einstellungen "
|
||||
"übernehmen</label></div><label>Spielstandsordner</label><div class=\"browse-row\"><input "
|
||||
"id=\"save-folder\" type=\"text\" value=\"" +
|
||||
escape(path_to_utf8(initial.saves)) +
|
||||
"\"/><button data-action=\"browse\">Auswählen …</button></div>",
|
||||
"Importieren");
|
||||
while (wait_modal()) {
|
||||
try {
|
||||
initial.name = value("mod-name");
|
||||
ModLibrary::validate_name(initial.name);
|
||||
const auto year = value("start-year");
|
||||
size_t end = 0;
|
||||
initial.start_year = std::stoi(year, &end);
|
||||
if (end != year.size() || initial.start_year < 1900 || initial.start_year > 9998)
|
||||
throw std::runtime_error("Startjahr muss zwischen 1900 und 9998 liegen.");
|
||||
initial.migrate = element("migrate")->HasAttribute("checked");
|
||||
initial.saves = path_from_utf8(value("save-folder"));
|
||||
close_modal();
|
||||
return initial;
|
||||
} catch (const std::exception &e) {
|
||||
text("modal-error", e.what());
|
||||
}
|
||||
}
|
||||
close_modal();
|
||||
return {};
|
||||
}
|
||||
std::optional<std::string> rename(const std::string &old) override {
|
||||
modal("Mod umbenennen",
|
||||
"<label>Bezeichnung</label><input id=\"mod-name\" type=\"text\" maxlength=\"100\" value=\"" +
|
||||
escape(old) + "\"/>",
|
||||
"Umbenennen");
|
||||
std::optional<std::string> result;
|
||||
while (wait_modal()) {
|
||||
try {
|
||||
auto name = value("mod-name");
|
||||
ModLibrary::validate_name(name);
|
||||
result = name;
|
||||
break;
|
||||
} catch (const std::exception &e) {
|
||||
text("modal-error", e.what());
|
||||
}
|
||||
}
|
||||
close_modal();
|
||||
return result;
|
||||
}
|
||||
bool confirm_delete(const std::string &name) override {
|
||||
modal("Mod löschen?",
|
||||
"„" + escape(name) + "“<br/><br/>Spielstände und persönliche Einstellungen bleiben erhalten.",
|
||||
"Löschen", true, true);
|
||||
const bool result = wait_modal();
|
||||
close_modal();
|
||||
return result;
|
||||
}
|
||||
void message(const std::string &value, bool error) override {
|
||||
if (closed_)
|
||||
return;
|
||||
modal(error ? "OpenBMH · Hinweis" : "OpenBMH", escape(value), "OK", false);
|
||||
wait_modal();
|
||||
close_modal();
|
||||
}
|
||||
void progress(const std::string &value, bool cancellable) override {
|
||||
if (!busy_) {
|
||||
modal(cancellable ? "Mod importieren" : "Spiel läuft", escape(value), "", cancellable);
|
||||
busy_ = true;
|
||||
cancelled_ = false;
|
||||
cancellable_ = cancellable;
|
||||
} else
|
||||
text("modal-body", value);
|
||||
}
|
||||
bool pump() override {
|
||||
step(false);
|
||||
return cancelled_ || closed_;
|
||||
}
|
||||
void finish_progress() override {
|
||||
if (busy_)
|
||||
close_modal();
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
std::unique_ptr<LauncherUI> make_launcher_ui() { return std::make_unique<RmlLauncher>(); }
|
||||
} // namespace bmh::launch
|
||||
@@ -1,27 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "launch/mods.hpp"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
namespace bmh::launch {
|
||||
enum class LauncherAction { start, add, remove, rename, end };
|
||||
struct LauncherChoice {
|
||||
LauncherAction action = LauncherAction::end;
|
||||
int selection = -1;
|
||||
};
|
||||
class LauncherUI {
|
||||
public:
|
||||
virtual ~LauncherUI() = default;
|
||||
virtual LauncherChoice next(const std::vector<ModEntry> &) = 0;
|
||||
virtual std::optional<std::filesystem::path> choose_folder(const std::string &title,
|
||||
const std::filesystem::path &initial = {}) = 0;
|
||||
virtual std::optional<AddMod> configure_add(AddMod defaults) = 0;
|
||||
virtual std::optional<std::string> rename(const std::string &) = 0;
|
||||
virtual bool confirm_delete(const std::string &) = 0;
|
||||
virtual void message(const std::string &, bool error) = 0;
|
||||
virtual void progress(const std::string &, bool cancellable) = 0;
|
||||
virtual bool pump() = 0; // cancellation requested
|
||||
virtual void finish_progress() = 0;
|
||||
};
|
||||
std::unique_ptr<LauncherUI> make_launcher_ui();
|
||||
} // namespace bmh::launch
|
||||
@@ -1,190 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "launch/mods.hpp"
|
||||
#include "content/save.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <chrono>
|
||||
#include <set>
|
||||
namespace bmh::launch {
|
||||
namespace fs = std::filesystem;
|
||||
namespace {
|
||||
std::string fold(std::string s) {
|
||||
for (auto &c : s)
|
||||
c = char(std::tolower(static_cast<unsigned char>(c)));
|
||||
return s;
|
||||
}
|
||||
std::string filename(const fs::path &p) { return path_to_utf8(p.filename()); }
|
||||
void safe_directory(const fs::path &path) {
|
||||
const auto status = fs::symlink_status(path);
|
||||
if (fs::is_symlink(status) || (fs::exists(status) && !fs::is_directory(status)))
|
||||
throw FormatError("Unsafe portable directory: " + path_to_utf8(path));
|
||||
fs::create_directories(path);
|
||||
}
|
||||
} // namespace
|
||||
ModLibrary::ModLibrary(fs::path root) : root_(fs::absolute(std::move(root)).lexically_normal()) {}
|
||||
void ModLibrary::validate_name(const std::string &name) {
|
||||
if (name.empty() || name.size() > 100 || name == "." || name == ".." || name.front() == '.' ||
|
||||
name.back() == '.' || name.back() == ' ')
|
||||
throw FormatError("Invalid mod name");
|
||||
for (unsigned char c : name)
|
||||
if (c < 32 || c == 127 || std::string("/\\:*?\"<>|").find(char(c)) != std::string::npos)
|
||||
throw FormatError("Invalid character in mod name");
|
||||
auto base = fold(name.substr(0, name.find('.')));
|
||||
const std::set<std::string> reserved{"con", "prn", "aux", "nul", "com1", "com2", "com3", "com4",
|
||||
"com5", "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3",
|
||||
"lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9"};
|
||||
if (reserved.contains(base))
|
||||
throw FormatError("Reserved mod name");
|
||||
}
|
||||
std::vector<ModEntry> ModLibrary::list() const {
|
||||
std::vector<ModEntry> out;
|
||||
const auto folder = root_ / "mods";
|
||||
if (!fs::exists(fs::symlink_status(folder)))
|
||||
return out;
|
||||
if (fs::is_symlink(fs::symlink_status(folder)) || !fs::is_directory(folder))
|
||||
throw FormatError("Unsafe mods directory");
|
||||
for (const auto &entry : fs::directory_iterator(folder)) {
|
||||
const auto name = filename(entry.path());
|
||||
if (name.starts_with('.'))
|
||||
continue;
|
||||
if (!entry.is_directory() && !entry.is_symlink())
|
||||
continue;
|
||||
ModEntry mod;
|
||||
mod.name = name;
|
||||
mod.directory = entry.path();
|
||||
try {
|
||||
validate_name(name);
|
||||
if (entry.is_symlink())
|
||||
throw FormatError("Linked mod directories are not supported");
|
||||
for (const auto &child : fs::directory_iterator(entry.path()))
|
||||
if (child.path().filename() != "content.obw")
|
||||
throw FormatError("Unexpected files in sealed Classic mod");
|
||||
const auto content = content::open(entry.path() / "content.obw");
|
||||
mod.content_id = content->content_id;
|
||||
} catch (const std::exception &e) {
|
||||
mod.error = e.what();
|
||||
}
|
||||
out.push_back(std::move(mod));
|
||||
}
|
||||
std::sort(out.begin(), out.end(),
|
||||
[](const auto &a, const auto &b) { return fold(a.name) < fold(b.name); });
|
||||
return out;
|
||||
}
|
||||
void ModLibrary::available(const std::string &name) const {
|
||||
validate_name(name);
|
||||
const auto folder = root_ / "mods";
|
||||
if (fs::exists(fs::symlink_status(folder))) {
|
||||
if (fs::is_symlink(fs::symlink_status(folder)) || !fs::is_directory(folder))
|
||||
throw FormatError("Unsafe mods directory");
|
||||
for (const auto &entry : fs::directory_iterator(folder))
|
||||
if (fold(filename(entry.path())) == fold(name))
|
||||
throw FormatError("A mod with this name already exists");
|
||||
}
|
||||
}
|
||||
void ModLibrary::owned(const ModEntry &mod) const {
|
||||
if (mod.directory.parent_path() != root_ / "mods" || filename(mod.directory) != mod.name ||
|
||||
fs::is_symlink(fs::symlink_status(mod.directory)))
|
||||
throw FormatError("Mod path is not owned by this library");
|
||||
}
|
||||
fs::path ModLibrary::user_directory(const ModEntry &mod) const {
|
||||
if (mod.content_id.size() != 64 ||
|
||||
mod.content_id.find_first_not_of("0123456789abcdef") != std::string::npos)
|
||||
throw FormatError("Invalid mod identity");
|
||||
safe_directory(root_ / "userdata");
|
||||
const auto directory = root_ / "userdata" / mod.content_id;
|
||||
safe_directory(directory);
|
||||
return directory;
|
||||
}
|
||||
ImportReport ModLibrary::add(const AddMod &request, const SaveMigrator &migrate,
|
||||
const ImportProgress &progress) {
|
||||
available(request.name);
|
||||
if (request.start_year < 1900 || request.start_year > 9998)
|
||||
throw FormatError("Start year must be 1900–9998");
|
||||
safe_directory(root_ / "mods");
|
||||
const auto update = [&](const std::string &s) {
|
||||
if (progress)
|
||||
progress(s);
|
||||
};
|
||||
update("Installation wird konvertiert …");
|
||||
obw::Options options;
|
||||
options.start_date = std::to_string(request.start_year) + "-07-01";
|
||||
options.title = "Classic installation";
|
||||
auto docs = obw::import_installation(request.source, options);
|
||||
const auto identity = content::seal(docs);
|
||||
update("Konvertierte Inhalte werden geprüft …");
|
||||
const auto staging =
|
||||
root_ / "mods" /
|
||||
(".import-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
||||
if (!fs::create_directory(staging))
|
||||
throw FormatError("Cannot reserve mod staging directory");
|
||||
struct Cleanup {
|
||||
fs::path p;
|
||||
~Cleanup() {
|
||||
std::error_code ec;
|
||||
fs::remove_all(p, ec);
|
||||
}
|
||||
} cleanup{staging};
|
||||
content::write_archive(docs, staging / "content.obw");
|
||||
(void)content::open(staging / "content.obw");
|
||||
ImportReport report;
|
||||
report.mod = {request.name, "Classic", identity, {}, root_ / "mods" / path_from_utf8(request.name)};
|
||||
const auto userdata = user_directory(report.mod);
|
||||
// User data is retained separately, and never overwrites a previous migration.
|
||||
if (request.migrate) {
|
||||
const auto source = request.saves.empty() ? request.source : request.saves;
|
||||
if (!fs::is_directory(source))
|
||||
report.errors.push_back("Spielstandsordner ist nicht verfügbar");
|
||||
else {
|
||||
std::vector<fs::path> files;
|
||||
for (const auto &entry : fs::directory_iterator(source))
|
||||
if (entry.is_regular_file() && !entry.is_symlink())
|
||||
files.push_back(entry.path());
|
||||
std::sort(files.begin(), files.end());
|
||||
for (const auto &input : files) {
|
||||
const auto ext = fold(path_to_utf8(input.extension()));
|
||||
if (ext != ".fbm" && ext != ".ein" && ext != ".men")
|
||||
continue;
|
||||
update("Übernahme: " + filename(input));
|
||||
try {
|
||||
auto destination = userdata / input.stem();
|
||||
destination += ext == ".fbm" ? ".obs" : ext == ".ein" ? ".obsettings" : ".oblayout";
|
||||
if (fs::exists(fs::symlink_status(destination)))
|
||||
throw FormatError("Destination already exists; retained existing file");
|
||||
if (ext == ".fbm") {
|
||||
if (!migrate)
|
||||
throw FormatError("Save migrator unavailable");
|
||||
migrate(staging / "content.obw", input, destination);
|
||||
} else {
|
||||
auto bytes = read_file(input);
|
||||
if (ext == ".ein" && bytes.size() != 180)
|
||||
throw FormatError("Invalid settings length");
|
||||
if (ext == ".men" && bytes.size() != 0x360)
|
||||
throw FormatError("Invalid desktop layout length");
|
||||
content::save_preferences(destination, ext == ".ein" ? "settings" : "layout", bytes,
|
||||
false);
|
||||
}
|
||||
++report.migrated;
|
||||
} catch (const std::exception &e) {
|
||||
report.errors.push_back(filename(input) + ": " + e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
update("Mod wird eingetragen …");
|
||||
available(request.name);
|
||||
fs::rename(staging, report.mod.directory);
|
||||
return report;
|
||||
}
|
||||
void ModLibrary::rename(const ModEntry &mod, const std::string &name) {
|
||||
owned(mod);
|
||||
if (name == mod.name)
|
||||
return;
|
||||
available(name);
|
||||
fs::rename(mod.directory, root_ / "mods" / path_from_utf8(name));
|
||||
}
|
||||
void ModLibrary::remove(const ModEntry &mod) {
|
||||
owned(mod);
|
||||
fs::remove_all(mod.directory);
|
||||
}
|
||||
} // namespace bmh::launch
|
||||
@@ -1,41 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "content/package.hpp"
|
||||
#include <functional>
|
||||
namespace bmh::launch {
|
||||
struct ModEntry {
|
||||
std::string name, type = "Classic", content_id, error;
|
||||
std::filesystem::path directory;
|
||||
};
|
||||
struct AddMod {
|
||||
std::filesystem::path source, saves;
|
||||
std::string name;
|
||||
int start_year = 2026;
|
||||
bool migrate = true;
|
||||
};
|
||||
using SaveMigrator =
|
||||
std::function<void(const std::filesystem::path &content, const std::filesystem::path &source,
|
||||
const std::filesystem::path &destination)>;
|
||||
using ImportProgress = std::function<void(const std::string &)>;
|
||||
struct ImportReport {
|
||||
ModEntry mod;
|
||||
size_t migrated = 0;
|
||||
std::vector<std::string> errors;
|
||||
};
|
||||
class ModLibrary {
|
||||
public:
|
||||
explicit ModLibrary(std::filesystem::path portable_root);
|
||||
std::vector<ModEntry> list() const;
|
||||
ImportReport add(const AddMod &, const SaveMigrator &, const ImportProgress &progress = {});
|
||||
void rename(const ModEntry &, const std::string &name);
|
||||
void remove(const ModEntry &);
|
||||
std::filesystem::path user_directory(const ModEntry &) const;
|
||||
const std::filesystem::path &root() const { return root_; }
|
||||
static void validate_name(const std::string &);
|
||||
|
||||
private:
|
||||
std::filesystem::path root_;
|
||||
void available(const std::string &) const;
|
||||
void owned(const ModEntry &) const;
|
||||
};
|
||||
} // namespace bmh::launch
|
||||
@@ -1,115 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "launch/process.hpp"
|
||||
#include "launch/archive.hpp"
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <stdexcept>
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <spawn.h>
|
||||
#include <sys/wait.h>
|
||||
#include <cerrno>
|
||||
#ifdef __APPLE__
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
extern char **environ;
|
||||
#endif
|
||||
namespace bmh::launch {
|
||||
std::filesystem::path executable_path(const std::filesystem::path &invocation) {
|
||||
#ifdef _WIN32
|
||||
std::vector<wchar_t> buffer(1024);
|
||||
for (;;) {
|
||||
const auto length = GetModuleFileNameW(nullptr, buffer.data(), DWORD(buffer.size()));
|
||||
if (!length)
|
||||
throw std::runtime_error("Cannot locate OpenBMH executable");
|
||||
if (length < buffer.size())
|
||||
return std::filesystem::path(std::wstring(buffer.data(), length));
|
||||
if (buffer.size() > 32768)
|
||||
throw std::runtime_error("Executable path is too long");
|
||||
buffer.resize(buffer.size() * 2);
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
uint32_t size = 0;
|
||||
_NSGetExecutablePath(nullptr, &size);
|
||||
std::vector<char> buffer(size);
|
||||
if (_NSGetExecutablePath(buffer.data(), &size) != 0)
|
||||
throw std::runtime_error("Cannot locate OpenBMH executable");
|
||||
return std::filesystem::canonical(path_from_utf8(buffer.data()));
|
||||
#else
|
||||
std::error_code error;
|
||||
const auto path = std::filesystem::read_symlink("/proc/self/exe", error);
|
||||
if (!error)
|
||||
return path;
|
||||
return std::filesystem::absolute(invocation).lexically_normal();
|
||||
#endif
|
||||
}
|
||||
int run_child(const std::filesystem::path &executable, const std::vector<std::string> &args,
|
||||
const std::function<void()> &pump) {
|
||||
#ifdef _WIN32
|
||||
const auto quote = [](const std::wstring &value) {
|
||||
std::wstring out = L"\"";
|
||||
size_t slashes = 0;
|
||||
for (wchar_t c : value) {
|
||||
if (c == L'\\') {
|
||||
++slashes;
|
||||
continue;
|
||||
}
|
||||
if (c == L'\"')
|
||||
out.append(slashes * 2 + 1, L'\\');
|
||||
else
|
||||
out.append(slashes, L'\\');
|
||||
out += c;
|
||||
slashes = 0;
|
||||
}
|
||||
out.append(slashes * 2, L'\\');
|
||||
out += L'\"';
|
||||
return out;
|
||||
};
|
||||
auto command = quote(executable.wstring());
|
||||
for (const auto &a : args) {
|
||||
command += L' ';
|
||||
command += quote(path_from_utf8(a).wstring());
|
||||
}
|
||||
STARTUPINFOW start{};
|
||||
start.cb = sizeof(start);
|
||||
PROCESS_INFORMATION process{};
|
||||
if (!CreateProcessW(executable.c_str(), command.data(), nullptr, nullptr, FALSE, 0, nullptr,
|
||||
executable.parent_path().c_str(), &start, &process))
|
||||
throw std::runtime_error("Cannot start OpenBMH game process");
|
||||
CloseHandle(process.hThread);
|
||||
while (WaitForSingleObject(process.hProcess, 20) == WAIT_TIMEOUT)
|
||||
if (pump)
|
||||
pump();
|
||||
DWORD code = 1;
|
||||
GetExitCodeProcess(process.hProcess, &code);
|
||||
CloseHandle(process.hProcess);
|
||||
return int(code);
|
||||
#else
|
||||
const auto binary = path_to_utf8(executable);
|
||||
std::vector<std::string> storage{binary};
|
||||
storage.insert(storage.end(), args.begin(), args.end());
|
||||
std::vector<char *> argv;
|
||||
for (auto &s : storage)
|
||||
argv.push_back(s.data());
|
||||
argv.push_back(nullptr);
|
||||
pid_t pid;
|
||||
const int error = posix_spawn(&pid, binary.c_str(), nullptr, nullptr, argv.data(), environ);
|
||||
if (error)
|
||||
throw std::runtime_error("Cannot start OpenBMH game process (" + std::to_string(error) + ")");
|
||||
int status = 0;
|
||||
for (;;) {
|
||||
const auto result = waitpid(pid, &status, WNOHANG);
|
||||
if (result == pid)
|
||||
break;
|
||||
if (result < 0 && errno != EINTR)
|
||||
throw std::runtime_error("Cannot wait for game process");
|
||||
if (pump)
|
||||
pump();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
}
|
||||
return WIFEXITED(status) ? WEXITSTATUS(status) : 128 + WTERMSIG(status);
|
||||
#endif
|
||||
}
|
||||
} // namespace bmh::launch
|
||||
@@ -1,11 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
namespace bmh::launch {
|
||||
std::filesystem::path executable_path(const std::filesystem::path &invocation);
|
||||
int run_child(const std::filesystem::path &, const std::vector<std::string> &,
|
||||
const std::function<void()> &pump);
|
||||
} // namespace bmh::launch
|
||||
@@ -1,35 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <RmlUi/Core/FileInterface.h>
|
||||
|
||||
namespace bmh::rml {
|
||||
// RmlUI parses document locations as URLs. Native Windows backslashes make
|
||||
// URL::GetPath() empty, so relative image sources lose their asset directory.
|
||||
inline std::string asset_path(const std::filesystem::path &path) {
|
||||
const auto utf8 = path.generic_u8string();
|
||||
return {utf8.begin(), utf8.end()};
|
||||
}
|
||||
// RmlUI paths are UTF-8. The Windows narrow fopen API uses the system code page.
|
||||
class AssetFiles : public Rml::FileInterface {
|
||||
public:
|
||||
Rml::FileHandle Open(const Rml::String &path) override {
|
||||
#ifdef _WIN32
|
||||
const std::u8string utf8(path.begin(), path.end());
|
||||
return reinterpret_cast<Rml::FileHandle>(_wfopen(std::filesystem::path(utf8).c_str(), L"rb"));
|
||||
#else
|
||||
return reinterpret_cast<Rml::FileHandle>(std::fopen(path.c_str(), "rb"));
|
||||
#endif
|
||||
}
|
||||
void Close(Rml::FileHandle file) override { std::fclose(reinterpret_cast<FILE *>(file)); }
|
||||
size_t Read(void *buffer, size_t size, Rml::FileHandle file) override {
|
||||
return std::fread(buffer, 1, size, reinterpret_cast<FILE *>(file));
|
||||
}
|
||||
bool Seek(Rml::FileHandle file, long offset, int origin) override {
|
||||
return std::fseek(reinterpret_cast<FILE *>(file), offset, origin) == 0;
|
||||
}
|
||||
size_t Tell(Rml::FileHandle file) override { return size_t(std::ftell(reinterpret_cast<FILE *>(file))); }
|
||||
};
|
||||
} // namespace bmh::rml
|
||||
@@ -1,236 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "launch/rml_video.hpp"
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <string_view>
|
||||
#ifdef _WIN32
|
||||
#include <SDL_syswm.h>
|
||||
#endif
|
||||
|
||||
namespace bmh::rml {
|
||||
namespace {
|
||||
[[noreturn]] void sdl_error(const char *operation) {
|
||||
throw std::runtime_error(std::string(operation) + ": " + SDL_GetError());
|
||||
}
|
||||
#ifdef _WIN32
|
||||
void check(HRESULT result, const char *operation) {
|
||||
if (FAILED(result)) {
|
||||
char code[24];
|
||||
std::snprintf(code, sizeof(code), "0x%08lX", static_cast<unsigned long>(result));
|
||||
throw std::runtime_error(std::string(operation) + ": " + code);
|
||||
}
|
||||
}
|
||||
std::wstring wide(const std::string &text) {
|
||||
const int length = MultiByteToWideChar(CP_UTF8, 0, text.data(), int(text.size()), nullptr, 0);
|
||||
std::wstring result(size_t(length), L' ');
|
||||
MultiByteToWideChar(CP_UTF8, 0, text.data(), int(text.size()), result.data(), length);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
Video::Video(const char *title, int width, int height, int minimum_width, int minimum_height) {
|
||||
try {
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
|
||||
sdl_error("Video initialization");
|
||||
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
|
||||
Uint32 flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN;
|
||||
#ifndef _WIN32
|
||||
flags |= SDL_WINDOW_OPENGL;
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
#ifdef __APPLE__
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
||||
#else
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
#endif
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
#endif
|
||||
window =
|
||||
SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags);
|
||||
if (!window)
|
||||
sdl_error("Window creation");
|
||||
SDL_SetWindowMinimumSize(window, minimum_width, minimum_height);
|
||||
#ifdef _WIN32
|
||||
SDL_SysWMinfo info{};
|
||||
SDL_VERSION(&info.version);
|
||||
if (!SDL_GetWindowWMInfo(window, &info))
|
||||
sdl_error("Native window handle");
|
||||
DXGI_SWAP_CHAIN_DESC desc{};
|
||||
desc.BufferCount = 2;
|
||||
desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
desc.OutputWindow = info.info.win.window;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Windowed = TRUE;
|
||||
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
|
||||
const D3D_FEATURE_LEVEL levels[] = {D3D_FEATURE_LEVEL_11_0};
|
||||
auto create = [&](D3D_DRIVER_TYPE driver) {
|
||||
return D3D11CreateDeviceAndSwapChain(nullptr, driver, nullptr, 0, levels, 1, D3D11_SDK_VERSION,
|
||||
&desc, swapchain_.ReleaseAndGetAddressOf(),
|
||||
device_.ReleaseAndGetAddressOf(), nullptr,
|
||||
context_.ReleaseAndGetAddressOf());
|
||||
};
|
||||
const auto mode = std::getenv("OPENBMH_RML_DRIVER");
|
||||
const bool force_warp = mode && std::string_view(mode) == "warp";
|
||||
HRESULT result = force_warp ? E_FAIL : create(D3D_DRIVER_TYPE_HARDWARE);
|
||||
bool software = false;
|
||||
if (FAILED(result)) {
|
||||
result = create(D3D_DRIVER_TYPE_WARP);
|
||||
software = true;
|
||||
}
|
||||
check(result, "Direct3D 11 initialization (hardware and WARP)");
|
||||
// Upstream's full-featured renderer requires the 11.1 runtime interfaces.
|
||||
Microsoft::WRL::ComPtr<ID3D11Device1> device1;
|
||||
Microsoft::WRL::ComPtr<ID3D11DeviceContext1> context1;
|
||||
check(device_.As(&device1), "Direct3D 11.1 device");
|
||||
check(context_.As(&context1), "Direct3D 11.1 context");
|
||||
std::fprintf(stderr, "RmlUI renderer: Direct3D 11 (%s)\n", software ? "WARP software" : "hardware");
|
||||
int pw, ph;
|
||||
drawable_size(pw, ph);
|
||||
resize(pw, ph);
|
||||
#else
|
||||
gl_ = SDL_GL_CreateContext(window);
|
||||
if (!gl_)
|
||||
sdl_error("OpenGL 3.3 initialization (macOS: 4.1)");
|
||||
if (SDL_GL_MakeCurrent(window, gl_) != 0)
|
||||
sdl_error("OpenGL context activation");
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
std::string error;
|
||||
if (!RmlGL3::Initialize(&error))
|
||||
throw std::runtime_error("OpenGL renderer initialization: " + error);
|
||||
loader_ = true;
|
||||
#endif
|
||||
} catch (...) {
|
||||
close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
Video::~Video() { close(); }
|
||||
void Video::close() noexcept {
|
||||
#ifdef _WIN32
|
||||
if (context_)
|
||||
context_->ClearState();
|
||||
target_.Reset();
|
||||
swapchain_.Reset();
|
||||
context_.Reset();
|
||||
device_.Reset();
|
||||
#else
|
||||
if (loader_)
|
||||
RmlGL3::Shutdown();
|
||||
if (gl_)
|
||||
SDL_GL_DeleteContext(gl_);
|
||||
#endif
|
||||
if (window)
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER);
|
||||
}
|
||||
void Video::drawable_size(int &width, int &height) const {
|
||||
#ifdef _WIN32
|
||||
SDL_GetWindowSizeInPixels(window, &width, &height);
|
||||
#else
|
||||
SDL_GL_GetDrawableSize(window, &width, &height);
|
||||
#endif
|
||||
}
|
||||
#ifdef _WIN32
|
||||
void Video::resize(int width, int height) {
|
||||
if (width < 1 || height < 1 || (width == width_ && height == height_ && target_))
|
||||
return;
|
||||
context_->OMSetRenderTargets(0, nullptr, nullptr);
|
||||
target_.Reset();
|
||||
check(swapchain_->ResizeBuffers(0, UINT(width), UINT(height), DXGI_FORMAT_UNKNOWN, 0),
|
||||
"Swapchain resize");
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> buffer;
|
||||
check(swapchain_->GetBuffer(0, IID_PPV_ARGS(&buffer)), "Swapchain buffer");
|
||||
check(device_->CreateRenderTargetView(buffer.Get(), nullptr, &target_), "Render target");
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
}
|
||||
#endif
|
||||
void Video::present() {
|
||||
#ifdef _WIN32
|
||||
check(swapchain_->Present(1, 0), "Direct3D presentation");
|
||||
#else
|
||||
SDL_GL_SwapWindow(window);
|
||||
#endif
|
||||
}
|
||||
std::vector<uint8_t> Video::capture(int &width, int &height) {
|
||||
#ifdef _WIN32
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> buffer, staging;
|
||||
check(swapchain_->GetBuffer(0, IID_PPV_ARGS(&buffer)), "Screenshot buffer");
|
||||
D3D11_TEXTURE2D_DESC desc{};
|
||||
buffer->GetDesc(&desc);
|
||||
width = static_cast<int>(desc.Width);
|
||||
height = static_cast<int>(desc.Height);
|
||||
std::vector<uint8_t> pixels(size_t(width) * size_t(height) * 4);
|
||||
desc.Usage = D3D11_USAGE_STAGING;
|
||||
desc.BindFlags = 0;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
desc.MiscFlags = 0;
|
||||
check(device_->CreateTexture2D(&desc, nullptr, &staging), "Screenshot staging texture");
|
||||
context_->CopyResource(staging.Get(), buffer.Get());
|
||||
D3D11_MAPPED_SUBRESOURCE data{};
|
||||
check(context_->Map(staging.Get(), 0, D3D11_MAP_READ, 0, &data), "Screenshot readback");
|
||||
for (int row = 0; row < height; ++row)
|
||||
std::memcpy(pixels.data() + size_t(row) * width * 4,
|
||||
static_cast<const uint8_t *>(data.pData) + size_t(row) * data.RowPitch,
|
||||
size_t(width) * 4);
|
||||
context_->Unmap(staging.Get(), 0);
|
||||
#else
|
||||
drawable_size(width, height);
|
||||
std::vector<uint8_t> pixels(size_t(width) * size_t(height) * 4);
|
||||
using ReadPixels = void (*)(int, int, int, int, unsigned, unsigned, void *);
|
||||
auto read = reinterpret_cast<ReadPixels>(SDL_GL_GetProcAddress("glReadPixels"));
|
||||
if (!read)
|
||||
sdl_error("Screenshot readback");
|
||||
read(0, 0, width, height, 0x1908, 0x1401, pixels.data());
|
||||
for (int row = 0; row < height / 2; ++row)
|
||||
for (int col = 0; col < width * 4; ++col)
|
||||
std::swap(pixels[size_t(row) * width * 4 + col],
|
||||
pixels[size_t(height - row - 1) * width * 4 + col]);
|
||||
#endif
|
||||
return pixels;
|
||||
}
|
||||
void report_start_error(const char *product, const std::string &message, bool dialog) noexcept {
|
||||
std::fprintf(stderr, "%s: %s\n", product, message.c_str());
|
||||
#ifdef _WIN32
|
||||
try {
|
||||
wchar_t directory[32768]{};
|
||||
const auto length = GetEnvironmentVariableW(L"LOCALAPPDATA", directory, 32768);
|
||||
auto root = (length > 0 && length < 32768 ? std::filesystem::path(directory)
|
||||
: std::filesystem::temp_directory_path()) /
|
||||
L"OpenBMH";
|
||||
std::filesystem::create_directories(root);
|
||||
std::ofstream log(root / (std::string(product) + "-startup.log"), std::ios::app);
|
||||
log << message << '\n';
|
||||
if (dialog && !std::getenv("OPENBMH_NO_ERROR_DIALOG"))
|
||||
MessageBoxW(nullptr, wide(message).c_str(), wide(product).c_str(), MB_OK | MB_ICONERROR);
|
||||
} catch (...) {
|
||||
if (dialog && !std::getenv("OPENBMH_NO_ERROR_DIALOG"))
|
||||
MessageBoxW(nullptr, L"The application could not start.", L"OpenBMH", MB_OK | MB_ICONERROR);
|
||||
}
|
||||
#else
|
||||
if (dialog && !std::getenv("OPENBMH_NO_ERROR_DIALOG"))
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, product, message.c_str(), nullptr);
|
||||
#endif
|
||||
}
|
||||
void attach_parent_console() noexcept {
|
||||
#ifdef _WIN32
|
||||
const bool out_free = _fileno(stdout) < 0, err_free = _fileno(stderr) < 0;
|
||||
if ((out_free || err_free) && AttachConsole(ATTACH_PARENT_PROCESS)) {
|
||||
FILE *stream = nullptr;
|
||||
if (out_free)
|
||||
freopen_s(&stream, "CONOUT$", "w", stdout);
|
||||
if (err_free)
|
||||
freopen_s(&stream, "CONOUT$", "w", stderr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} // namespace bmh::rml
|
||||
@@ -1,71 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "launch/startup_error.hpp"
|
||||
#include <SDL.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#ifdef _WIN32
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <RmlUi_Renderer_DX11.h>
|
||||
#include <wrl/client.h>
|
||||
#else
|
||||
#include <RmlUi_Renderer_GL3.h>
|
||||
#endif
|
||||
|
||||
namespace bmh::rml {
|
||||
// The native Windows renderer needs no OpenGL ICD in a Remote Desktop session.
|
||||
// The device falls back to Microsoft's built-in WARP when hardware is absent.
|
||||
class Video {
|
||||
public:
|
||||
SDL_Window *window = nullptr;
|
||||
Video(const char *title, int width, int height, int minimum_width, int minimum_height);
|
||||
~Video();
|
||||
Video(const Video &) = delete;
|
||||
Video &operator=(const Video &) = delete;
|
||||
void drawable_size(int &width, int &height) const;
|
||||
void present();
|
||||
// RGBA rows in top-to-bottom order, independent of the graphics API.
|
||||
std::vector<uint8_t> capture(int &width, int &height);
|
||||
#ifdef _WIN32
|
||||
ID3D11Device *device() const { return device_.Get(); }
|
||||
ID3D11RenderTargetView *target() const { return target_.Get(); }
|
||||
void resize(int width, int height);
|
||||
#endif
|
||||
private:
|
||||
void close() noexcept;
|
||||
#ifdef _WIN32
|
||||
Microsoft::WRL::ComPtr<ID3D11Device> device_;
|
||||
Microsoft::WRL::ComPtr<ID3D11DeviceContext> context_;
|
||||
Microsoft::WRL::ComPtr<IDXGISwapChain> swapchain_;
|
||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> target_;
|
||||
int width_ = 0, height_ = 0;
|
||||
#else
|
||||
SDL_GLContext gl_ = nullptr;
|
||||
bool loader_ = false;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
class Renderer : public RenderInterface_DX11 {
|
||||
Video &video_;
|
||||
|
||||
public:
|
||||
explicit Renderer(Video &video) : RenderInterface_DX11(video.device()), video_(video) {}
|
||||
void SetViewport(int width, int height) {
|
||||
video_.resize(width, height);
|
||||
RenderInterface_DX11::SetViewport(width, height);
|
||||
}
|
||||
void Clear() { RenderInterface_DX11::Clear(video_.target()); }
|
||||
void EndFrame() { RenderInterface_DX11::EndFrame(video_.target()); }
|
||||
explicit operator bool() const { return video_.device() != nullptr; }
|
||||
};
|
||||
#else
|
||||
class Renderer : public RenderInterface_GL3 {
|
||||
public:
|
||||
explicit Renderer(Video &) {}
|
||||
};
|
||||
#endif
|
||||
} // namespace bmh::rml
|
||||
@@ -1,49 +0,0 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
# A shared visual layer for the launcher and future modern screens.
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build dependencies statically" FORCE)
|
||||
foreach(feature IN ITEMS ZLIB BZIP2 PNG HARFBUZZ BROTLI)
|
||||
set(FT_DISABLE_${feature} ON CACHE BOOL "Keep the bundled font engine minimal" FORCE)
|
||||
endforeach()
|
||||
set(SKIP_INSTALL_ALL ON)
|
||||
FetchContent_Declare(freetype
|
||||
GIT_REPOSITORY https://github.com/freetype/freetype.git
|
||||
GIT_TAG VER-2-13-3 GIT_SHALLOW TRUE GIT_SUBMODULES "")
|
||||
FetchContent_MakeAvailable(freetype)
|
||||
if(NOT TARGET Freetype::Freetype)
|
||||
add_library(Freetype::Freetype ALIAS freetype)
|
||||
endif()
|
||||
set(RMLUI_SAMPLES OFF CACHE BOOL "" FORCE)
|
||||
set(RMLUI_LUA_BINDINGS OFF CACHE BOOL "" FORCE)
|
||||
set(RMLUI_SVG_PLUGIN OFF CACHE BOOL "" FORCE)
|
||||
set(RMLUI_LOTTIE_PLUGIN OFF CACHE BOOL "" FORCE)
|
||||
FetchContent_Declare(rmlui
|
||||
GIT_REPOSITORY https://github.com/mikke89/RmlUi.git
|
||||
GIT_TAG 6.3 GIT_SHALLOW TRUE)
|
||||
FetchContent_MakeAvailable(rmlui)
|
||||
add_library(bmh_rmlui STATIC
|
||||
${rmlui_SOURCE_DIR}/Backends/RmlUi_Platform_SDL.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/launch/rml_video.cpp)
|
||||
if(WIN32)
|
||||
target_sources(bmh_rmlui PRIVATE ${rmlui_SOURCE_DIR}/Backends/RmlUi_Renderer_DX11.cpp)
|
||||
target_link_libraries(bmh_rmlui PUBLIC d3d11 dxgi d3dcompiler)
|
||||
# Upstream resolves its multisampled UI layer into the swapchain every frame.
|
||||
target_compile_definitions(bmh_rmlui PUBLIC NUM_MSAA_SAMPLES=2 NOMINMAX)
|
||||
else()
|
||||
target_sources(bmh_rmlui PRIVATE ${rmlui_SOURCE_DIR}/Backends/RmlUi_Renderer_GL3.cpp)
|
||||
endif()
|
||||
target_include_directories(bmh_rmlui PUBLIC ${rmlui_SOURCE_DIR}/Backends ${CMAKE_SOURCE_DIR}/src)
|
||||
target_compile_definitions(bmh_rmlui PUBLIC RMLUI_SDL_VERSION_MAJOR=2 RMLUI_NUM_MSAA_SAMPLES=0)
|
||||
target_link_libraries(bmh_rmlui PUBLIC RmlUi::Core ${BMH_SDL_TARGET} PRIVATE ${CMAKE_DL_LIBS})
|
||||
|
||||
# The background is project artwork, and the unmodified fonts come from the
|
||||
# pinned dependency. All assets are located relative to the executable at runtime.
|
||||
set(launcher_assets "${CMAKE_BINARY_DIR}/assets/launcher")
|
||||
file(MAKE_DIRECTORY "${launcher_assets}")
|
||||
foreach(asset IN ITEMS launcher.rml theme.rcss stadium.tga)
|
||||
configure_file("${CMAKE_SOURCE_DIR}/assets/launcher/${asset}" "${launcher_assets}/${asset}" COPYONLY)
|
||||
endforeach()
|
||||
foreach(weight IN ITEMS Regular Bold)
|
||||
configure_file("${rmlui_SOURCE_DIR}/Samples/assets/LatoLatin-${weight}.ttf"
|
||||
"${launcher_assets}/LatoLatin-${weight}.ttf" COPYONLY)
|
||||
endforeach()
|
||||
install(DIRECTORY "${launcher_assets}/" DESTINATION assets/launcher COMPONENT Runtime)
|
||||
@@ -1,10 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace bmh::rml {
|
||||
// Safe before video initialization, including when no graphics driver is available.
|
||||
// No preferences or authentication tokens are logged.
|
||||
void report_start_error(const char *product, const std::string &message, bool dialog = true) noexcept;
|
||||
void attach_parent_console() noexcept;
|
||||
} // namespace bmh::rml
|
||||
Reference in new issue
Block a user