Initial public OpenBMH 0.1 source (by Codex)
This commit is contained in:
commit
558fbf166b
613 files changed
+168029
No files matched your search
@@ -0,0 +1,26 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "formats/textd.hpp"
|
||||
|
||||
#include "formats/binary.hpp"
|
||||
|
||||
namespace bmh {
|
||||
|
||||
TextDb load_textd(const std::filesystem::path& path) {
|
||||
Bytes d = read_file(path);
|
||||
if (d.size() < 7) throw FormatError("TEXTD: file too short");
|
||||
// header: u8 id, u16 buffer size, u32 unknown; the buffer may be larger than the file rest
|
||||
TextDb db;
|
||||
size_t p = 7;
|
||||
db.blob.assign(d.begin() + 7, d.end());
|
||||
while (db.strings.size() < TEXT_COUNT && p < d.size()) {
|
||||
size_t start = p;
|
||||
db.offsets.push_back(start - 7);
|
||||
while (p < d.size() && d[p] != 0) p++;
|
||||
db.strings.emplace_back(reinterpret_cast<const char*>(d.data() + start), p - start);
|
||||
p++;
|
||||
}
|
||||
if (db.strings.size() != TEXT_COUNT) throw FormatError("TEXTD: expected 1382 strings");
|
||||
return db;
|
||||
}
|
||||
|
||||
} // namespace bmh
|
||||
Reference in new issue
Block a user