-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
nbt.hexpat
79 lines (69 loc) · 1.66 KB
/
nbt.hexpat
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
#pragma author WerWolv
#pragma description Minecraft NBT
import std.sys;
#pragma endian big
enum Tag : u8 {
End = 0,
Byte = 1,
Short = 2,
Int = 3,
Long = 4,
Float = 5,
Double = 6,
ByteArray = 7,
String = 8,
List = 9,
Compound = 10,
IntArray = 11,
LongArray = 12
};
using Element;
struct Value {
if (parent.tag == Tag::Byte)
s8 value;
else if (parent.tag == Tag::Short)
s16 value;
else if (parent.tag == Tag::Int)
s32 value;
else if (parent.tag == Tag::Long)
s64 value;
else if (parent.tag == Tag::Float)
float value;
else if (parent.tag == Tag::Double)
double value;
else if (parent.tag == Tag::ByteArray) {
s32 arrayLength;
s8 value[arrayLength] [[sealed]];
} else if (parent.tag == Tag::String) {
u16 stringLength;
char value[stringLength];
} else if (parent.tag == Tag::List) {
Tag tag;
s32 listLength;
Value values[listLength] [[static]];
} else if (parent.tag == Tag::Compound) {
Element values[while(true)];
} else if (parent.tag == Tag::IntArray){
s32 arrayLength;
s32 value[arrayLength] [[sealed]];
} else if (parent.tag == Tag::LongArray) {
s32 arrayLength;
s64 value[arrayLength] [[sealed]];
} else {
std::error(std::format("Invalid tag {:02X}", TypeTag));
}
} [[inline]];
struct Element {
Tag tag;
if (tag == Tag::End)
break;
else {
u16 nameLength;
char name[nameLength];
Value value;
}
};
struct NBT {
Element element[while(true)] [[inline]];
};
NBT nbt @ 0x00;