Complete Classic BMH and FLTD installation imports (by Codex)
This commit is contained in:
1 parent
65b087c1d0
commit
3a021fc160
32 files changed
+2297
-203
No files matched your search
+3
-3
@@ -36,14 +36,14 @@ void save_image(const LeImage& image, const std::filesystem::path& path) {
|
||||
if (!file) throw FormatError("cannot write the OpenBMH image");
|
||||
}
|
||||
|
||||
LeImage load_le(const std::filesystem::path& path) {
|
||||
LeImage load_le(const std::filesystem::path& path, bool apply_supported_rules) {
|
||||
const Bytes raw = read_file(path);
|
||||
if (raw.size() >= sizeof kImageMagic + 8 && std::equal(kImageMagic, kImageMagic + sizeof kImageMagic, raw.begin())) {
|
||||
const auto word = [&](size_t at) { return uint32_t(raw[at] | raw[at + 1] << 8 | raw[at + 2] << 16) | uint32_t(raw[at + 3]) << 24; };
|
||||
const uint32_t base = word(sizeof kImageMagic), size = word(sizeof kImageMagic + 4);
|
||||
if (raw.size() != sizeof kImageMagic + 8 + size_t(size)) throw FormatError("OpenBMH image: wrong size");
|
||||
LeImage img = LeImage::from_bytes(base, Bytes(raw.begin() + sizeof kImageMagic + 8, raw.end()));
|
||||
apply_rule_base(img);
|
||||
if (apply_supported_rules) apply_rule_base(img);
|
||||
return img;
|
||||
}
|
||||
auto u8 = [&](size_t o) -> uint32_t {
|
||||
@@ -133,7 +133,7 @@ LeImage load_le(const std::filesystem::path& path) {
|
||||
}
|
||||
}
|
||||
}
|
||||
apply_rule_base(img);
|
||||
if (apply_supported_rules) apply_rule_base(img);
|
||||
return img;
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -44,7 +44,7 @@ public:
|
||||
}
|
||||
const Bytes& bytes() const { return bytes_; }
|
||||
|
||||
friend LeImage load_le(const std::filesystem::path& path);
|
||||
friend LeImage load_le(const std::filesystem::path& path, bool apply_supported_rules);
|
||||
|
||||
private:
|
||||
uint32_t base_ = 0;
|
||||
@@ -55,7 +55,9 @@ private:
|
||||
// Throws FormatError for files that are not LE executables or use external fixups.
|
||||
// A German BMH.EXE is loaded with the OpenBMH rule base applied (formats/rule_base.hpp):
|
||||
// every edition plays by the supported rule profile rule values.
|
||||
LeImage load_le(const std::filesystem::path& path);
|
||||
// The installation importer passes false to preserve source tables separately;
|
||||
// ordinary engine callers retain the default behavior.
|
||||
LeImage load_le(const std::filesystem::path& path, bool apply_supported_rules = true);
|
||||
|
||||
// The OpenBMH image format: "OPENBMH-IMAGE" NUL, u32 base, u32 size, the bytes. load_le()
|
||||
// reads it as well, so a translated image can stand in for BMH.exe in a data directory.
|
||||
|
||||
+4
-1
@@ -35,7 +35,10 @@ std::string pool_string(const Bytes& pool, size_t offset) {
|
||||
} // namespace
|
||||
|
||||
Database load_database(const std::filesystem::path& path, const DbCounts& c) {
|
||||
Bytes d = read_file(path);
|
||||
return decode_database(read_file(path), c);
|
||||
}
|
||||
|
||||
Database decode_database(const Bytes& d, const DbCounts& c) {
|
||||
Reader r{d};
|
||||
Bytes lens = r.take(8);
|
||||
size_t len_clubs = le16(lens, 0), len_players = le16(lens, 2), len_refs = le16(lens, 4), len_stadiums = le16(lens, 6);
|
||||
|
||||
@@ -74,5 +74,6 @@ struct Database {
|
||||
};
|
||||
|
||||
Database load_database(const std::filesystem::path& path, const DbCounts& counts = {});
|
||||
Database decode_database(const Bytes& data, const DbCounts& counts = {});
|
||||
|
||||
} // namespace bmh
|
||||
Reference in new issue
Block a user