Skip to content

Commit d7e5659

Browse files
authored
Add "support" for BYML v1, and check for MK8 path nodes (#27)
1 parent 1767210 commit d7e5659

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dist/
88
build/
99
.mypy_cache/
1010
.idea/
11+
.cache/
1112
.vscode/
1213
.benchmarks/
1314

@@ -22,6 +23,7 @@ build/
2223
perf.data
2324
perf.data.old
2425
.gdb_history
26+
compile_commands.json
2527

2628
test/files/TwnObj_HyruleCastle_A.Tex.sbfres
2729

Diff for: readme.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Features
1212
Currently, oead only handles very common formats that are extensively used in recent games such as *Breath of the Wild* and *Super Mario Odyssey*.
1313

1414
* `AAMP <https://zeldamods.org/wiki/AAMP>`_ (binary parameter archive): Only version 2 is supported.
15-
* `BYML <https://zeldamods.org/wiki/BYML>`_ (binary YAML): Versions 2, 3, and 4 are supported.
15+
* `BYML <https://zeldamods.org/wiki/BYML>`_ (binary YAML): Versions 1, 2, 3, and 4 are supported.
1616
* `SARC <https://zeldamods.org/wiki/SARC>`_ (archive)
1717
* `Yaz0 <https://zeldamods.org/wiki/Yaz0>`_ (compression algorithm)
1818

Diff for: src/byml.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace byml {
3939
struct ResHeader {
4040
/// “BY” (big endian) or “YB” (little endian).
4141
std::array<char, 2> magic;
42-
/// Format version (2 or 3).
42+
/// Format version (1-4).
4343
u16 version;
4444
/// Offset to the hash key table, relative to start (usually 0x010)
4545
/// May be 0 if no hash nodes are used. Must be a string table node (0xc2).
@@ -59,6 +59,7 @@ enum class NodeType : u8 {
5959
Array = 0xc0,
6060
Hash = 0xc1,
6161
StringTable = 0xc2,
62+
PathTable = 0xc3, // Unsupported
6263
Bool = 0xd0,
6364
Int = 0xd1,
6465
Float = 0xd2,
@@ -94,7 +95,7 @@ constexpr bool IsNonInlineType(T type) {
9495
}
9596

9697
constexpr bool IsValidVersion(int version) {
97-
return 2 <= version && version <= 4;
98+
return 1 <= version && version <= 4;
9899
}
99100

100101
class StringTableParser {
@@ -153,7 +154,19 @@ class Parser {
153154
m_reader, *m_reader.Read<u32>(offsetof(ResHeader, hash_key_table_offset)));
154155
m_string_table =
155156
StringTableParser(m_reader, *m_reader.Read<u32>(offsetof(ResHeader, string_table_offset)));
156-
m_root_node_offset = *m_reader.Read<u32>(offsetof(ResHeader, root_node_offset));
157+
158+
// In MK8 byamls, there is an extra offset to a path table here
159+
u32 root_node_offset = *m_reader.Read<u32>(offsetof(ResHeader, root_node_offset));
160+
size_t header_end = m_reader.Tell();
161+
if (root_node_offset != 0)
162+
{
163+
const auto type = m_reader.Read<NodeType>(root_node_offset);
164+
if (type == NodeType::PathTable)
165+
throw UnsupportedError("Path nodes unsupported");
166+
}
167+
168+
m_root_node_offset = root_node_offset;
169+
m_reader.Seek(header_end);
157170
}
158171

159172
Byml Parse() {

Diff for: src/include/oead/errors.h

+5
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ struct InvalidDataError : std::runtime_error {
3333
using std::runtime_error::runtime_error;
3434
};
3535

36+
/// Thrown when unsupported feature is detected.
37+
struct UnsupportedError : std::runtime_error {
38+
using std::runtime_error::runtime_error;
39+
};
40+
3641
} // namespace oead

0 commit comments

Comments
 (0)