@@ -84,6 +84,7 @@ NBT::NBT(const char *file, bool &success)
84
84
_blob = NULL ;
85
85
_filename = NULL ;
86
86
if (file == NULL || *file == ' \0 ' || !fileExists (file)) {
87
+ // fprintf(stderr, "File not found: %s\n", file);
87
88
success = false ;
88
89
return ;
89
90
}
@@ -97,14 +98,16 @@ NBT::NBT(const char *file, bool &success)
97
98
}
98
99
success = (fh != 0 );
99
100
if (!success) {
101
+ // fprintf(stderr, "Error opening file %s\n", file);
100
102
return ;
101
103
}
102
104
// File is open, read data
103
- int length = 150000 ; // I checked a few chunk files in their decompressed form, I think they can't really get any bigger than 80~90KiB, but just to be sure...
105
+ int length = 150000 * (CHUNKSIZE_Y / 128 ) ; // I checked a few chunk files in their decompressed form, I think they can't really get any bigger than 80~90KiB, but just to be sure...
104
106
_blob = new uint8_t [length];
105
107
int ret = gzread (fh, _blob, length);
106
108
gzclose (fh);
107
109
if (ret == -1 || _blob[0 ] != 10 ) { // Has to start with TAG_Compound
110
+ // fprintf(stderr, "Ret: %d/%d - start: %d\n", ret, length, (int)_blob[0]);
108
111
success = false ;
109
112
return ;
110
113
}
@@ -113,7 +116,7 @@ NBT::NBT(const char *file, bool &success)
113
116
_type = tagCompound;
114
117
NBT_Tag::parseData (position, end);
115
118
if (position == NULL ) {
116
- // printf( "Error parsing NBT from file\n");
119
+ // fprintf(stderr, "Error parsing NBT from file\n");
117
120
}
118
121
success = (position != NULL );
119
122
}
@@ -132,15 +135,15 @@ NBT::NBT(uint8_t * const file, const size_t len, const bool shared, bool &succes
132
135
_type = tagCompound;
133
136
NBT_Tag::parseData (position, end);
134
137
if (position == NULL ) {
135
- // printf( "Error parsing NBT from stream\n");
138
+ // fprintf(stderr, "Error parsing NBT from stream\n");
136
139
}
137
140
success = (position != NULL );
138
141
}
139
142
140
143
NBT::~NBT ()
141
144
{
142
145
if (_blob != NULL ) {
143
- // //printf( "DELETE BLOB\n");
146
+ // fprintf(stderr, "DELETE BLOB\n");
144
147
delete[] _blob;
145
148
}
146
149
if (_filename != NULL ) {
@@ -176,7 +179,7 @@ bool NBT::save()
176
179
}
177
180
//remove(tmpfile);
178
181
delete[] tmpfile;
179
- //printf( "Saved %s\n", _filename);
182
+ //fprintf(stderr, "Saved %s\n", _filename);
180
183
return true;
181
184
}
182
185
*/
@@ -195,7 +198,7 @@ NBT_Tag::NBT_Tag(uint8_t* &position, const uint8_t *end, string &name)
195
198
_elems = NULL ;
196
199
_data = NULL ;
197
200
_type = tagUnknown;
198
- if (*position < 1 || *position > 10 || end - position < 3 ) {
201
+ if (*position < 1 || *position > 11 || end - position < 3 ) {
199
202
position = NULL ;
200
203
return ;
201
204
}
@@ -207,7 +210,7 @@ NBT_Tag::NBT_Tag(uint8_t* &position, const uint8_t *end, string &name)
207
210
}
208
211
name = string ((char *)position+3 , len);
209
212
position += 3 + len;
210
- // printf( "Tag name is %s\n", name.c_str());
213
+ // fprintf(stderr, "Tag name is %s\n", name.c_str());
211
214
this ->parseData (position, end, &name);
212
215
}
213
216
@@ -224,41 +227,41 @@ NBT_Tag::NBT_Tag(uint8_t* &position, const uint8_t *end, TagType type)
224
227
void NBT_Tag::parseData (uint8_t * &position, const uint8_t *end, string *name)
225
228
{
226
229
// position should now point to start of data (for named tags, right after the name)
227
- // printf( "Have Tag of type %d\n", (int)_type);
230
+ // fprintf(stderr, "Have Tag of type %d\n", (int)_type);
228
231
switch (_type) {
229
232
case tagCompound:
230
233
_elems = new tagmap;
231
234
while (*position != 0 && position < end) { // No end tag, go on...
232
- // printf( "Having a child....*plopp*..\n");
235
+ // fprintf(stderr, "Having a child....*plopp*..\n");
233
236
string thisname;
234
237
NBT_Tag *tmp = new NBT_Tag (position, end, thisname);
235
238
if (position == NULL ) {
236
- // printf( "DELETE tmp in compound because of invalid\n");
239
+ // fprintf(stderr, "DELETE tmp in compound because of invalid\n");
237
240
delete tmp;
238
241
return ;
239
242
}
240
243
if (name != NULL ) {
241
- // printf( " ** Adding %s to %s\n", thisname.c_str(), name->c_str());
244
+ // fprintf(stderr, " ** Adding %s to %s\n", thisname.c_str(), name->c_str());
242
245
}
243
246
(*_elems)[thisname] = tmp;
244
247
}
245
248
++position;
246
249
break ;
247
250
case tagList: {
248
- if (*position < 1 || *position > 10 ) {
249
- // printf( "Invalid list type!\n");
251
+ if (*position < 1 || *position > 11 ) {
252
+ // fprintf(stderr, "Invalid list type!\n");
250
253
position = NULL ;
251
254
return ;
252
255
}
253
256
TagType type = (TagType)*position;
254
257
uint32_t count = _ntohl (position+1 );
255
258
position += 5 ;
256
259
_list = new list<NBT_Tag *>;
257
- // printf( "List contains %d elements of type %d\n", (int)count, (int)type);
260
+ // fprintf(stderr, "List contains %d elements of type %d\n", (int)count, (int)type);
258
261
while (count-- && position < end) { // No end tag, go on...
259
262
NBT_Tag *tmp = new NBT_Tag (position, end, type);
260
263
if (position == NULL ) {
261
- // printf( "DELETE tmp in list because of invalid\n");
264
+ // fprintf(stderr, "DELETE tmp in list because of invalid\n");
262
265
delete tmp;
263
266
return ;
264
267
}
@@ -292,9 +295,9 @@ void NBT_Tag::parseData(uint8_t* &position, const uint8_t *end, string *name)
292
295
break ;
293
296
case tagByteArray:
294
297
_len = _ntohl (position);
295
- // printf( "Array size is %d\n", (int)_len);
298
+ // fprintf(stderr, "Array size is %d\n", (int)_len);
296
299
if (position + _len + 4 >= end) {
297
- // printf("Too long b< %d bytes!\n", int((position + _len + 4) - end));
300
+ printf (" ByteArray too long by %d bytes!\n " , int ((position + _len + 4 ) - end));
298
301
position = NULL ;
299
302
return ;
300
303
}
@@ -303,36 +306,46 @@ void NBT_Tag::parseData(uint8_t* &position, const uint8_t *end, string *name)
303
306
break ;
304
307
case tagString:
305
308
_len = _ntohs (position);
306
- // printf( "Stringlen is %d\n", (int)_len);
309
+ // fprintf(stderr, "Stringlen is %d\n", (int)_len);
307
310
if (position + _len + 2 >= end) {
308
- // printf( "Too long!\n");
311
+ // fprintf(stderr, "Too long!\n");
309
312
position = NULL ;
310
313
return ;
311
314
}
312
315
_data = position;
313
316
position += 2 + _len;
314
317
break ;
318
+ case tagIntArray:
319
+ _len = _ntohl (position) * 4 ;
320
+ // fprintf(stderr, "Array size is %d\n", (int)_len);
321
+ if (position + _len + 4 >= end) {
322
+ printf (" IntArray too long by %d bytes!\n " , int ((position + _len + 4 ) - end));
323
+ position = NULL ;
324
+ return ;
325
+ }
326
+ _data = position + 4 ;
327
+ position += 4 + _len;
328
+ break ;
315
329
case tagUnknown:
316
330
default :
317
- // printf("UNKNOWN TAG !\n");
331
+ printf (" UNKNOWN TAG_ %d !\n " , ( int )_type );
318
332
position = NULL ;
319
333
break ;
320
334
}
321
335
}
322
336
323
337
NBT_Tag::~NBT_Tag ()
324
338
{
325
- // //printf("Tag Destructor for %p\n", this);
326
339
if (_elems) {
327
340
for (tagmap::iterator it = _elems->begin (); it != _elems->end (); it++) {
328
- // //printf( "_elems Deleting %p\n", (it->second));
341
+ // //fprintf(stderr, "_elems Deleting %p\n", (it->second));
329
342
delete (it->second );
330
343
}
331
344
delete _elems;
332
345
}
333
346
if (_list) {
334
347
for (list<NBT_Tag *>::iterator it = _list->begin (); it != _list->end (); it++) {
335
- // //printf( "_list Deleting %p\n", *it);
348
+ // //fprintf(stderr, "_list Deleting %p\n", *it);
336
349
delete *it;
337
350
}
338
351
delete _list;
0 commit comments