-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.bt
65 lines (54 loc) · 2.18 KB
/
common.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
// Common
typedef struct (uint32 count, string magic) {
char data[count] <bgcolor=cLtRed, format=hex>;
Assert(data == magic);
} Magic <read=ReadMagic>;
string ReadMagic(Magic& value) { return value.data; }
typedef struct (uint32 value) {
uint32 data <bgcolor=cGray, format=hex>;
Assert(data == value);
} Fixed32 <read=ReadFixed32>;
string ReadFixed32(Fixed32& value) { string out; SPrintf(out, "%08Xh", value.data); return out; }
typedef struct (uint64 value) {
uint64 data <bgcolor=cGray, format=hex>;
Assert(data == value);
} Fixed64 <read=ReadFixed64>;
string ReadFixed64(Fixed64& value) { string out; SPrintf(out, "%016LXh", value.data); return out; }
typedef struct { string value; } String <bgcolor=cLtYellow, read=ReadStr>;
string ReadStr(String& data) { return data.value; }
typedef struct (uint32 size) { char value[size]; } PaddedString <bgcolor=cLtYellow, read=ReadPaddedString>;
string ReadPaddedString(PaddedString& data) { return data.value; }
typedef struct { uint32 size; char value[size]; } SizedString <bgcolor=cLtYellow, read=ReadSizedString>;
string ReadSizedString(SizedString& data) { return data.value; }
typedef struct { byte size; char value[size]; } Sized8String <bgcolor=cLtYellow, read=ReadSized8String>;
string ReadSized8String(Sized8String& data) { return data.value; }
typedef struct { uint32 count; uint32 data[count]; } UInt32Array;
typedef struct {
uint32 data <bgcolor=0x80a0ff, format=hex>;
} ResId <read=ReadResId>;
string ReadResId(ResId& value) { string out; SPrintf(out, "%08Xh", value.data); return out; }
typedef struct (uint32 width, uint32 height) {
local uint32 width = width;
local uint32 height = height;
float data[width * height] <bgcolor=cLtPurple, format=hex>;
} Matrix <read=ReadMatrix>;
string ReadMatrix(Matrix& value) {
local string out = "{", buf;
local uint32 x,y;
for (y = 0; y < value.height; ++y) {
if (y > 0) out += ",\n";
out += "{";
for (x = 0; x < value.width; ++x) {
if (x > 0) out += ",";
SPrintf(buf, "%f", value.data[x + y * value.width]);
out += buf;
}
out += "}";
}
out += "}";
return out;
}
struct Chunk {
uint32 size <bgcolor=cLtBlue>;
byte data[size] <bgcolor=cLtYellow>;
};