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
+1
-29
@@ -1,8 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "game/highscore.hpp"
|
||||
#include "formats/native_state.hpp"
|
||||
#include "formats/native_file.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <bit>
|
||||
@@ -188,25 +186,11 @@ HighscoreTable decode_highscore_table(const HighscoreBytes& bytes) {
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
std::filesystem::path highscore_file(const std::filesystem::path &base, uint16_t signature,
|
||||
const std::string &prefix, bool native) {
|
||||
std::filesystem::path highscore_file(const std::filesystem::path& base, uint16_t signature, const std::string& prefix) {
|
||||
if (!signature) throw std::invalid_argument("highscore: signature0 has no ranked file");
|
||||
if (native)
|
||||
return base / ("highscore-" + std::to_string(signature) + ".obscore");
|
||||
return base / (prefix + std::to_string(signature));
|
||||
}
|
||||
HighscoreTable load_highscore_table(const std::filesystem::path& file) {
|
||||
if (file.extension() == ".obscore") {
|
||||
const auto data = read_file(file);
|
||||
const auto j = cli::parse_json(std::string(data.begin(), data.end()));
|
||||
if (!j.object() || !j.object()->contains("schema") || !j.object()->at("schema").string() ||
|
||||
*j.object()->at("schema").string() != "classic-highscore@1.0" || !j.object()->contains("payload"))
|
||||
throw FormatError("Invalid native highscore");
|
||||
const auto raw = decode_native_bytes(j.object()->at("payload"), 360);
|
||||
HighscoreBytes bytes;
|
||||
std::copy(raw.begin(), raw.end(), bytes.begin());
|
||||
return decode_highscore_table(bytes);
|
||||
}
|
||||
std::ifstream in(file, std::ios::binary);
|
||||
if (!in) {
|
||||
HighscoreTable empty{};
|
||||
@@ -219,18 +203,6 @@ HighscoreTable load_highscore_table(const std::filesystem::path& file) {
|
||||
}
|
||||
bool save_highscore_table(const std::filesystem::path& file, const HighscoreTable& rows) {
|
||||
const auto bytes = encode_highscore_table(rows);
|
||||
if (file.extension() == ".obscore") {
|
||||
try {
|
||||
content::write_atomic(file,
|
||||
cli::dump_json(cli::Json::Object{
|
||||
{"schema", "classic-highscore@1.0"},
|
||||
{"payload", encode_native_bytes(Bytes(bytes.begin(), bytes.end()))}}),
|
||||
true);
|
||||
return true;
|
||||
} catch (const std::exception &) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
std::ofstream out(file, std::ios::binary | std::ios::trunc);
|
||||
if (!out) return false;
|
||||
out.write(reinterpret_cast<const char*>(bytes.data()), bytes.size());
|
||||
|
||||
Reference in new issue
Block a user