-
Notifications
You must be signed in to change notification settings - Fork 0
/
MinecraftNBT.bt
210 lines (167 loc) · 4 KB
/
MinecraftNBT.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//------------------------------------------------
//--- 010 Editor v10.0 Binary Template
//
// File: MinecraftNBT
// Authors: MrNikes, Andrew McRae
// Version: 0.3
// Purpose: Minecraft NBT file
// Category: Misc
// File Mask:
// ID Bytes:
// Sources: https://github.com/fesh0r/010editor/blob/master/010%20Templates/NBT.bt
// History:
// 0.3 2022-09-10 MrNikes: Added read IntArray, LongArray
// 0.2 2016-03-30 Andrew McRae: Updated header for repo
// 0.1 2012-06-01 Andrew McRae: Initial revision
//------------------------------------------------
enum <ubyte> TAG_TYPE {
TAG_End = 0,
TAG_Byte,
TAG_Short,
TAG_Int,
TAG_Long,
TAG_Float,
TAG_Double,
TAG_Byte_Array,
TAG_String,
TAG_List,
TAG_Compound,
TAG_IntArray,
TAG_LongArray,
};
typedef struct {
} TAG_End;
typedef byte TAG_Byte;
typedef short TAG_Short;
typedef int TAG_Int;
typedef int64 TAG_Long;
typedef float TAG_Float;
typedef double TAG_Double;
typedef struct {
TAG_Int length <hidden=true>;
if (length > 0) byte d[length];
} TAG_Byte_Array <read=read_TAG_Byte_Array>;
string read_TAG_Byte_Array(TAG_Byte_Array &in) {
string out;
SPrintf(out, "byte[%i]", in.length);
return out;
}
typedef struct {
TAG_Short length <hidden=true>;
if (length > 0) char d[length];
} TAG_String <read=read_TAG_String>;
string read_TAG_String(TAG_String &in) {
if (in.length > 0) {
return in.d;
}
return "";
}
typedef struct {
local int i;
TAG_TYPE tagType <hidden=true>;
TAG_Int length <hidden=true>;
for (i = 0; i < length; i++) {
TAG(tagType);
}
} TAG_List <read=read_TAG_LIST>;
string read_TAG_LIST(TAG_List &in) {
string out;
SPrintf(out, "%s[%i]", EnumToString(in.tagType), in.length);
return out;
}
typedef struct {
TAG_TYPE tagType <hidden=true>;
if (tagType != 0) {
TAG_String name <hidden=true>;
TAG(tagType);
}
} TAG_Named <read=read_TAG_Named>;
string read_TAG_Named(TAG_Named &in) {
string out;
SPrintf(out, "%s", EnumToString(in.tagType));
if (in.tagType != 0) {
SPrintf(out, "%s(\"%s\")", out, read_TAG_String(in.name));
}
return out;
}
typedef struct {
local int found_end = 0;
local int tag_count = 0;
while (!found_end) {
found_end = (ReadByte(FTell()) == 0);
TAG_Named d;
tag_count++;
}
} TAG_Compound <read=read_TAG_Compound>;
string read_TAG_Compound(TAG_Compound &in) {
string out;
SPrintf(out, "TAG_Named[%i]", in.tag_count - 1);
return out;
}
typedef struct {
local int i;
TAG_Int length <hidden=true>;
for (i = 0; i < length; i++) {
TAG_Int d;
}
} TAG_IntArray <read=read_TAG_IntArray>;
string read_TAG_IntArray(TAG_IntArray &in) {
string out;
SPrintf(out, "TAG_IntArray([%i]", in.length);
return out;
}
typedef struct {
local int i;
TAG_Int length <hidden=true>;
for (i = 0; i < length; i++) {
TAG_Long d;
}
} TAG_LongArray <read=read_TAG_LongArray>;
string read_TAG_LongArray(TAG_LongArray &in) {
string out;
SPrintf(out, "TAG_LongArray([%i]", in.length);
return out;
}
void TAG(TAG_TYPE tagType) {
switch (tagType) {
case 0:
TAG_End d;
break;
case 1:
TAG_Byte d;
break;
case 2:
TAG_Short d;
break;
case 3:
TAG_Int d;
break;
case 4:
TAG_Long d;
break;
case 5:
TAG_Float d;
break;
case 6:
TAG_Double d;
break;
case 7:
TAG_Byte_Array d;
break;
case 8:
TAG_String d;
break;
case 9:
TAG_List d;
break;
case 10:
TAG_Compound d;
break;
case 11:
TAG_IntArray d;
break;
case 12:
TAG_LongArray d;
break;
}
}