-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMessageTable.bt
172 lines (155 loc) · 4.48 KB
/
MessageTable.bt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#ifndef _MESSAGESTUDIOBINARYTEXT
#define _MESSAGESTUDIOBINARYTEXT
struct MSBTHeader {
char magic[8];
Assert(magic == "MsgStdBn");
ushort bom <format=hex>;
//Assert(bom == 0xFEFF); // Big-Endian byte order
//Let's check
if (bom == 0xFFFE && isDKCTF)
{
LittleEndian();
}
ushort unk1;
ubyte maybeMajorVersion;
ubyte maybeMinorVersion;
ushort sectionCount;
ushort unk3;
uint fileSize;
byte padding[10]<hidden=true>;
};
struct TableHeader(string expectedMagic) {
char magic[4];
Assert(magic == expectedMagic);
uint tableSize;
byte padding[8]<hidden=true>;
};
struct LabelOffset {
uint stringCount;
uint stringOffset;
};
struct LabelEntry {
ubyte stringLength;
char str[stringLength];
uint stringTableIndex;
};
wstring LabelEntryRead(LabelEntry &le) {
return le.str;
}
struct LabelsSection {
TableHeader header("LBL1");
local int64 tableStart = FTell();
uint offsetCount;
LabelOffset offset[offsetCount];
local uint i;
for (i = 0; i < offsetCount; i++) {
Assert(FTell() == tableStart + offset[i].stringOffset);
if (offset[i].stringCount) {
LabelEntry label[offset[i].stringCount]<optimize=false,read=LabelEntryRead>;
}
}
while (ReadUByte(FTell()) == 0xAB) {
byte padding<hidden=true>;
}
};
struct AttributeEntry {
wstring str;
};
wstring AttributeEntryRead(AttributeEntry &ae) {
return ae.str;
}
struct AttributesSection {
TableHeader header("ATR1");
local int64 tableStart = FTell();
uint offsetCount;
uint entrySize; // should always be 4
if (isDKCTF == 0)
{
uint offset[offsetCount];
local uint i;
for (i = 0; i < offsetCount; i++) {
Assert(FTell() == tableStart + offset[i]);
AttributeEntry attribute<optimize=false,read=AttributeEntryRead>;
}
}
while (ReadUByte(FTell()) == 0xAB) {
byte padding<hidden=true>;
}
};
struct TextsEntry(int64 size) {
wchar_t str[size / 2];
};
wstring TextsEntryRead(TextsEntry &te) {
local wstring out;
local uint i;
for (i = 0; i < (sizeof te.str / 2); i++) {
// MSBT includes "text commands" in strings, which are sections of binary
// data with varying lengths. Parsing them is complicated, so for now we
// just skip all characters below the printable range. Some random bytes
// will still slip through.
if (te.str[i] >= 0x20) {
out += te.str[i];
}
}
return out;
}
struct TextsSection {
TableHeader header("TXT2");
local int64 tableStart = FTell();
uint offsetCount;
uint offset[offsetCount];
local uint i;
// This is kind of hacky- these strings may contain null characters, so
// we need to read between the offsets and stop at the end of the table.
for (i = 0; i < offsetCount - 1; i++) {
TextsEntry text(offset[i + 1] - offset[i])<optimize=false,read=TextsEntryRead>;
}
TextsEntry text(header.tableSize - offset[i])<optimize=false,read=TextsEntryRead>;
while (ReadUByte(FTell()) == 0xAB) {
byte padding<hidden=true>;
}
};
struct Language (string expectedLanguage) {
ChunkDescriptor languageChunkHeader;
// Each section here is heavily referenced from https://zeldamods.org/wiki/Msbt
struct MSBTContents {
MSBTHeader header;
LabelsSection labels;
AttributesSection attributes;
TextsSection texts;
if (isDKCTF) //Swap back
{
BigEndian();
}
} contents;
};
struct MessageStudioBinaryText
{
if (isDKCTF == 1)
{
Language us_english("USEN");
Language us_french("USFR");
Language us_spanish("USSP");
Language eu_english("EUEN");
Language eu_french("EUFR");
Language eu_spanish("EUSP");
Language eu_german("EUGE");
Language eu_italian("EUIT");
Language jp_japanese("JPJP");
} else {
Language us_english("USEN");
Language eu_english("EUEN");
Language eu_french("EUFR");
Language us_french("USFR");
Language eu_spanish("EUSP");
Language eu_german("EUGE");
Language eu_italian("EUIT");
Language eu_dutch("EUDU");
Language jp_japanese("JPJP");
Language ko_korean("KOKO");
Language ch_traditionalchinese("CHTC");
Language ch_simplifiedchinese("CHSC");
Language us_spanish("USSP");
}
};
#endif// _MESSAGESTUDIOBINARYTEXT