From 5bdd368b99c7d49cf10d69c15b5a90d8198fd1a7 Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 09:41:46 +0200 Subject: [PATCH 01/18] LongArray definition --- src/nbt/types.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) 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; From 8c427272366338aea820c93f2dc7a77db73608d3 Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 09:47:49 +0200 Subject: [PATCH 02/18] Update nbt_inspect.cpp --- src/nbt/nbt_inspect.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/nbt/nbt_inspect.cpp b/src/nbt/nbt_inspect.cpp index 864e23f1..8c10256d 100644 --- a/src/nbt/nbt_inspect.cpp +++ b/src/nbt/nbt_inspect.cpp @@ -76,6 +76,13 @@ 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 +105,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; } From ede1f0c8ae2799e0681444d4aec899b86cacdd02 Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 09:49:01 +0200 Subject: [PATCH 03/18] Update nbt_inspect.cpp --- src/nbt/nbt_inspect.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/nbt/nbt_inspect.cpp b/src/nbt/nbt_inspect.cpp index 8c10256d..57427470 100644 --- a/src/nbt/nbt_inspect.cpp +++ b/src/nbt/nbt_inspect.cpp @@ -76,7 +76,6 @@ 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; From 4576d2a4d3cf60d076881c0b65a8e062ea7925f2 Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 11:41:51 +0200 Subject: [PATCH 04/18] Updating nbt.hpp with long_array definition --- src/nbt/nbt.hpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/nbt/nbt.hpp b/src/nbt/nbt.hpp index 22530f2f..b80948c9 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(); @@ -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_long(file); + + nbt_assert_error(exc_env, file, file->flush(length * sizeof(Int)) != -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_int_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; From 741552a5c9603ea98f7432a7dc37330f7ca6338d Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 11:46:25 +0200 Subject: [PATCH 05/18] Updating nbt.hpp with long_array definition - 2 Forgot to modify one text --- src/nbt/nbt.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nbt/nbt.hpp b/src/nbt/nbt.hpp index b80948c9..7a1fc1a5 100644 --- a/src/nbt/nbt.hpp +++ b/src/nbt/nbt.hpp @@ -506,7 +506,7 @@ namespace nbt { register_byte_t register_byte; register_byte_array_t register_byte_array; register_int_array_t register_int_array; - register_int_array_t register_long_array; + register_long_array_t register_long_array; begin_compound_t begin_compound; end_compound_t end_compound; From e414a1771a1e38f2c9af15e7fedd29fcfc749b48 Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 12:00:23 +0200 Subject: [PATCH 06/18] Updating level.cpp with long_array definition --- src/mc/level.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/mc/level.cpp b/src/mc/level.cpp index 132107ee..0411ebb3 100644 --- a/src/mc/level.cpp +++ b/src/mc/level.cpp @@ -193,6 +193,33 @@ namespace mc { delete byte_array; } + void register_long_array(level_context* C, nbt::String name, nbt::LongArray* long_array) { + if (in_level_section(C)) + { + if (name.compare("Data") == 0) { + C->tmp_Section->Data.reset(long_array); + return; + } + + if (name.compare("SkyLight") == 0) { + C->tmp_Section->SkyLight.reset(long_array); + return; + } + + if (name.compare("BlockLight") == 0) { + C->tmp_Section->BlockLight.reset(long_array); + return; + } + + if (name.compare("Blocks") == 0) { + C->tmp_Section->Blocks.reset(long_array); + return; + } + } + + delete long_array; + } + void error_handler(level_context* C, size_t where, const char *why) { C->error = true; C->error_where = where; @@ -232,6 +259,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; From 8c226379cd2f876276c3c8c51917c29424b3b292 Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 20:20:57 +0200 Subject: [PATCH 07/18] Update level.cpp --- src/mc/level.cpp | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/mc/level.cpp b/src/mc/level.cpp index 0411ebb3..a3781753 100644 --- a/src/mc/level.cpp +++ b/src/mc/level.cpp @@ -194,30 +194,6 @@ namespace mc { } void register_long_array(level_context* C, nbt::String name, nbt::LongArray* long_array) { - if (in_level_section(C)) - { - if (name.compare("Data") == 0) { - C->tmp_Section->Data.reset(long_array); - return; - } - - if (name.compare("SkyLight") == 0) { - C->tmp_Section->SkyLight.reset(long_array); - return; - } - - if (name.compare("BlockLight") == 0) { - C->tmp_Section->BlockLight.reset(long_array); - return; - } - - if (name.compare("Blocks") == 0) { - C->tmp_Section->Blocks.reset(long_array); - return; - } - } - - delete long_array; } void error_handler(level_context* C, size_t where, const char *why) { From ecbd4e875c2e60a06ce72f3032ed1e35cb08b884 Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 20:35:57 +0200 Subject: [PATCH 08/18] Update nbt.hpp --- src/nbt/nbt.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nbt/nbt.hpp b/src/nbt/nbt.hpp index 7a1fc1a5..977f61e8 100644 --- a/src/nbt/nbt.hpp +++ b/src/nbt/nbt.hpp @@ -459,8 +459,8 @@ namespace nbt { } inline void flush_long_array(input_buffer_ptr file) { - Int length = read_long(file); - + Int length = read_int(file); + nbt_assert_error(exc_env, file, file->flush(length * sizeof(Int)) != -1, "Buffer to short to flush LongArray"); } From 26c23edc9ad171045d5213d3bbedf680acf32964 Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 20:39:51 +0200 Subject: [PATCH 09/18] Update region_inspect.cpp --- src/mc/region_inspect.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mc/region_inspect.cpp b/src/mc/region_inspect.cpp index 8a097b9f..1b09b868 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) << " ints)" << 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]); From bdb8d961be70d30e350da2e77e903de0b484505e Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 20:44:11 +0200 Subject: [PATCH 10/18] Update generate_map.cpp --- src/generate_map.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/generate_map.cpp b/src/generate_map.cpp index 0fb15ac4..97e8bb73 100644 --- a/src/generate_map.cpp +++ b/src/generate_map.cpp @@ -575,10 +575,6 @@ bool generate_map( return false; } - typedef void (*hello_f)(); - - //hello_f hello = (hello_f)dl_sym(dl, "hello"); - //hello(); return true; } else { From f35a97dfddb675d936786742d7f7d1f02e582a56 Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 20:45:56 +0200 Subject: [PATCH 11/18] Update json.hpp --- src/json.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/json.hpp b/src/json.hpp index 48797abe..1657d53a 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -50,6 +50,7 @@ namespace json { class basic_json { public: + virtual ~basic_json() {}; virtual void write(std::ostream& os) = 0; virtual json_type get_type() = 0; }; From 27303b7a7cc61489707bd13f4573431084942dc4 Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 21:09:22 +0200 Subject: [PATCH 12/18] Update level.cpp --- src/mc/level.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mc/level.cpp b/src/mc/level.cpp index a3781753..05a6a71c 100644 --- a/src/mc/level.cpp +++ b/src/mc/level.cpp @@ -194,6 +194,8 @@ namespace mc { } 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) { From 42f0924e89a753cb448e6e5d07f555faf8d5febc Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 21:10:51 +0200 Subject: [PATCH 13/18] Update region_inspect.cpp --- src/mc/region_inspect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mc/region_inspect.cpp b/src/mc/region_inspect.cpp index 1b09b868..1418188c 100644 --- a/src/mc/region_inspect.cpp +++ b/src/mc/region_inspect.cpp @@ -88,7 +88,7 @@ void register_int_array(inspect_context* inspect, nbt::String name, nbt::IntArra void register_long_array(inspect_context* inspect, nbt::String name, nbt::LongArray* value) { cout << setw(inspect->width) << "" - << "LongArray(" << name << "): " << "(" << dec << int(value->length) << " ints)" << endl; + << "LongArray(" << name << "): " << "(" << dec << int(value->length) << " longs)" << endl; delete value; } From 2688305adac1a684a493c7035053e29f21a27d3a Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 21:11:59 +0200 Subject: [PATCH 14/18] Update nbt.hpp --- src/nbt/nbt.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nbt/nbt.hpp b/src/nbt/nbt.hpp index 977f61e8..885e00d1 100644 --- a/src/nbt/nbt.hpp +++ b/src/nbt/nbt.hpp @@ -461,7 +461,7 @@ namespace nbt { inline void flush_long_array(input_buffer_ptr file) { Int length = read_int(file); - nbt_assert_error(exc_env, file, file->flush(length * sizeof(Int)) != -1, + nbt_assert_error(exc_env, file, file->flush(length * sizeof(Long)) != -1, "Buffer to short to flush LongArray"); } From 16223400086f8594f119e455ddb4335c722c2f92 Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Fri, 16 Aug 2019 21:49:35 +0200 Subject: [PATCH 15/18] Update nbt.hpp --- src/nbt/nbt.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nbt/nbt.hpp b/src/nbt/nbt.hpp index 885e00d1..611d0041 100644 --- a/src/nbt/nbt.hpp +++ b/src/nbt/nbt.hpp @@ -411,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; From 9762a3b601f2f2cf772830302e2070055c7b70f7 Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Sat, 17 Aug 2019 02:03:21 +0200 Subject: [PATCH 16/18] Update level.cpp --- src/mc/level.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mc/level.cpp b/src/mc/level.cpp index 05a6a71c..f819c93b 100644 --- a/src/mc/level.cpp +++ b/src/mc/level.cpp @@ -17,7 +17,7 @@ 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): [ From e94a55cf5a2d19aff416b82fd96d97b43eb36e53 Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Sat, 17 Aug 2019 02:29:43 +0200 Subject: [PATCH 17/18] Update level.cpp --- src/mc/level.cpp | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/src/mc/level.cpp b/src/mc/level.cpp index f819c93b..1b5b05a9 100644 --- a/src/mc/level.cpp +++ b/src/mc/level.cpp @@ -20,41 +20,14 @@ Compound() { 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) } ] } From 370f63a0200f12ac3b1f809cbab17a5e6ec40c0b Mon Sep 17 00:00:00 2001 From: tanaka141 Date: Sat, 17 Aug 2019 02:31:15 +0200 Subject: [PATCH 18/18] Update level.cpp --- src/mc/level.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mc/level.cpp b/src/mc/level.cpp index 1b5b05a9..7bff488e 100644 --- a/src/mc/level.cpp +++ b/src/mc/level.cpp @@ -22,11 +22,9 @@ Compound() { IntArray(HeightMap): (256 ints) 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) ByteArray(BlockStates): (4096 bytes) } ]