diff --git a/src/mc/level.cpp b/src/mc/level.cpp index 132107ee..7bff488e 100644 --- a/src/mc/level.cpp +++ b/src/mc/level.cpp @@ -17,44 +17,15 @@ Compound() { Long(LastUpdate): 7446079 Int(xPos): -1 Int(zPos): -1 - List(TileEntities, TAG_Byte, 0): [ ] + List(TileEntities, TAG_Compound, 0): [ ] Byte(TerrainPopulated): 0x1 IntArray(HeightMap): (256 ints) - List(Sections, TAG_Compound, 5): [ + List(Sections, TAG_Compound, 1): [ Compound() { - ByteArray(Data): (2048 bytes) ByteArray(SkyLight): (2048 bytes) ByteArray(BlockLight): (2048 bytes) Byte(Y): 0x0 - ByteArray(Blocks): (4096 bytes) - } - Compound() { - ByteArray(Data): (2048 bytes) - ByteArray(SkyLight): (2048 bytes) - ByteArray(BlockLight): (2048 bytes) - Byte(Y): 0x1 - ByteArray(Blocks): (4096 bytes) - } - Compound() { - ByteArray(Data): (2048 bytes) - ByteArray(SkyLight): (2048 bytes) - ByteArray(BlockLight): (2048 bytes) - Byte(Y): 0x2 - ByteArray(Blocks): (4096 bytes) - } - Compound() { - ByteArray(Data): (2048 bytes) - ByteArray(SkyLight): (2048 bytes) - ByteArray(BlockLight): (2048 bytes) - Byte(Y): 0x3 - ByteArray(Blocks): (4096 bytes) - } - Compound() { - ByteArray(Data): (2048 bytes) - ByteArray(SkyLight): (2048 bytes) - ByteArray(BlockLight): (2048 bytes) - Byte(Y): 0x4 - ByteArray(Blocks): (4096 bytes) + ByteArray(BlockStates): (4096 bytes) } ] } @@ -193,6 +164,11 @@ namespace mc { delete byte_array; } + void register_long_array(level_context* C, nbt::String name, nbt::LongArray* long_array) { + + delete long_array; + } + void error_handler(level_context* C, size_t where, const char *why) { C->error = true; C->error_where = where; @@ -232,6 +208,7 @@ namespace mc { parser.register_byte_array = register_byte_array; parser.register_int_array = register_int_array; + parser.register_long_array = register_long_array; parser.register_byte = register_byte; parser.register_string = register_string; parser.register_int = register_int; diff --git a/src/mc/region_inspect.cpp b/src/mc/region_inspect.cpp index 8a097b9f..1418188c 100644 --- a/src/mc/region_inspect.cpp +++ b/src/mc/region_inspect.cpp @@ -86,6 +86,12 @@ void register_int_array(inspect_context* inspect, nbt::String name, nbt::IntArra delete value; } +void register_long_array(inspect_context* inspect, nbt::String name, nbt::LongArray* value) { + cout << setw(inspect->width) << "" + << "LongArray(" << name << "): " << "(" << dec << int(value->length) << " longs)" << endl; + delete value; +} + void error_handler(inspect_context* ctx, size_t where, const char* why) { std::cout << where << ":" << why << std::endl; } @@ -115,6 +121,7 @@ int main(int argc, char* argv[]) { parser.register_byte = register_byte; parser.register_byte_array = register_byte_array; parser.register_int_array = register_int_array; + parser.register_long_array = register_long_array; mc::region region(argv[1]); diff --git a/src/nbt/nbt.hpp b/src/nbt/nbt.hpp index 22530f2f..611d0041 100644 --- a/src/nbt/nbt.hpp +++ b/src/nbt/nbt.hpp @@ -236,6 +236,7 @@ namespace nbt { const Byte TAG_List = 0x9; const Byte TAG_Compound = 0xa; const Byte TAG_Int_Array = 0xb; + const Byte TAG_Long_Array = 0xc; const std::string TAG_End_str("TAG_End"); const std::string TAG_Byte_str("TAG_Byte"); @@ -249,6 +250,7 @@ namespace nbt { const std::string TAG_List_str("TAG_List"); const std::string TAG_Compound_str("TAG_Compound"); const std::string TAG_Int_Array_str("TAG_Int_Array"); + const std::string TAG_Long_Array_str("TAG_Long_Array"); const std::string tag_string_map[] = { TAG_End_str, @@ -262,7 +264,8 @@ namespace nbt { TAG_String_str, TAG_List_str, TAG_Compound_str, - TAG_Int_Array_str + TAG_Int_Array_str, + TAG_Long_Array_str }; bool is_big_endian(); @@ -408,7 +411,7 @@ namespace nbt { inline Byte read_tagType(input_buffer_ptr file) { Byte type = read_byte(file); - nbt_assert_error(exc_env, file, type >= 0 && type <= TAG_Int_Array, + nbt_assert_error(exc_env, file, type >= 0 && type <= TAG_Long_Array, "Not a valid tag type"); return type; @@ -454,6 +457,27 @@ namespace nbt { array->length = length; register_int_array(context, name, array); } + + inline void flush_long_array(input_buffer_ptr file) { + Int length = read_int(file); + + nbt_assert_error(exc_env, file, file->flush(length * sizeof(Long)) != -1, + "Buffer to short to flush LongArray"); + } + + inline void handle_long_array(String name, input_buffer_ptr file) { + Int length = read_int(file); + Long *values = new Long[length]; + + for (Int i = 0; i < length; i++) { + values[i] = read_long(file); + } + + LongArray *array = new LongArray(); + array->values = values; + array->length = length; + register_long_array(context, name, array); + } public: typedef void (*begin_compound_t)(C*, String name); typedef void (*end_compound_t)(C*, String name); @@ -470,6 +494,7 @@ namespace nbt { typedef void (*register_byte_t)(C*, String name, Byte b); typedef void (*register_byte_array_t)(C*, String name, ByteArray* array); typedef void (*register_int_array_t)(C*, String name, IntArray* array); + typedef void (*register_long_array_t)(C*, String name, LongArray* array); typedef void (*error_handler_t)(C*, size_t where, const char *why); register_long_t register_long; @@ -481,6 +506,7 @@ namespace nbt { register_byte_t register_byte; register_byte_array_t register_byte_array; register_int_array_t register_int_array; + register_long_array_t register_long_array; begin_compound_t begin_compound; end_compound_t end_compound; @@ -499,6 +525,7 @@ namespace nbt { register_byte(NULL), register_byte_array(NULL), register_int_array(NULL), + register_long_array(NULL), begin_compound(&default_begin_compound), end_compound(&default_end_compound), begin_list(&default_begin_list), @@ -518,6 +545,7 @@ namespace nbt { register_byte(NULL), register_byte_array(NULL), register_int_array(NULL), + register_long_array(NULL), begin_compound(&default_begin_compound), end_compound(&default_end_compound), begin_list(&default_begin_list), @@ -684,6 +712,13 @@ namespace nbt { handle_int_array(name, file); } break; + case TAG_Long_Array: + if (register_long_array == NULL) { + flush_long_array(file); + } else { + handle_long_array(name, file); + } + break; default: nbt_assert_error(exc_env, file, 0, "Encountered unknown type"); break; diff --git a/src/nbt/nbt_inspect.cpp b/src/nbt/nbt_inspect.cpp index 864e23f1..57427470 100644 --- a/src/nbt/nbt_inspect.cpp +++ b/src/nbt/nbt_inspect.cpp @@ -76,6 +76,12 @@ void register_byte_array(inspect_context* inspect, nbt::String name, nbt::ByteAr delete value; } +void register_long_array(inspect_context* inspect, nbt::String name, nbt::LongArray* value) { + cout << setw(inspect->width) << "" + << "LongArray(" << name << "): " << "(binary blob)" << endl; + delete value; +} + int main(int argc, char* argv[]) { if (argc < 2) { return 1; @@ -98,7 +104,8 @@ int main(int argc, char* argv[]) { parser.register_int = register_int; parser.register_byte = register_byte; parser.register_byte_array = register_byte_array; - + parser.register_long_array = register_long_array; + parser.parse_file(argv[1]); return 0; } diff --git a/src/nbt/types.hpp b/src/nbt/types.hpp index abb0aedb..12e85fcd 100644 --- a/src/nbt/types.hpp +++ b/src/nbt/types.hpp @@ -29,6 +29,15 @@ namespace nbt { } }; + + struct LongArray { + Int length; + Long *values; + ~LongArray() { + delete [] values; + } + }; + struct stack_entry { Byte type; String name;