From b2fc37f9e7c6998c65f82ec313723902d199e45f Mon Sep 17 00:00:00 2001 From: Evildeeds Date: Wed, 9 Feb 2022 00:04:00 +0100 Subject: [PATCH] Enforced unsigned data-streams Fixed Y-index crash from empty section stack --- src/mc/level.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/mc/level.cpp b/src/mc/level.cpp index a46241ab..e70138b1 100644 --- a/src/mc/level.cpp +++ b/src/mc/level.cpp @@ -714,7 +714,7 @@ namespace mc { C->p[C->pos++] = section_name::None; - if (in_level_section(C)) { + if (in_level_section_a(C) || in_level_section_c(C)) { C->sections.emplace_back(); } else if(in_palette_section(C)) { C->sections.back().PaletteProperties.emplace_back(); @@ -914,7 +914,7 @@ namespace mc { * indice_bit_count is the number of bits in the slice and may not exceed 32 since the return type is int. */ template - inline boost::optional get_indice(int x, int z, int y, boost::shared_ptr> &arr) { + inline boost::optional get_indice(int x, int z, int y, boost::shared_ptr> &arr) { size_t indice_index = (y * 16 + z) * 16 + x; // Compiler should catch that this is static and pre-compute it, @@ -927,11 +927,11 @@ namespace mc { size_t element_index = (indice_index - index_in_element) / indice_count_in_element; if (arr->length < 0 || element_index >= static_cast(arr->length)) - return boost::optional(); + return boost::optional(); T element = arr->values[element_index]; - int out_bits = ~(0xFFFFFFFF << indice_bit_count); - return boost::optional((element >> (indice_bit_count * index_in_element)) & out_bits); + uint32_t out_bits = ~(0xFFFFFFFF << indice_bit_count); + return boost::optional((element >> (indice_bit_count * index_in_element)) & out_bits); } /** @@ -943,7 +943,7 @@ namespace mc { * indice_bit_count is the number of bits in the slice and may not exceed 32 since the return type is int. */ template - inline boost::optional get_stream_indice(int x, int z, int y, boost::shared_ptr> &arr) { + inline boost::optional get_stream_indice(int x, int z, int y, boost::shared_ptr> &arr) { size_t indice_index = (y * 16 + z) * 16 + x; size_t bits_into_stream = indice_index * indice_bit_count; @@ -953,26 +953,26 @@ namespace mc { size_t element_index = (bits_into_stream - bits_in_element) / element_bits; if (arr->length < 0 || element_index >= static_cast(arr->length)) - return boost::optional(); + return boost::optional(); T element = arr->values[element_index]; int result = element >> bits_in_element; size_t got = element_bits - bits_in_element; if (got < indice_bit_count) { if (element_index + 1 >= static_cast(arr->length)) - return boost::optional(); + return boost::optional(); element = arr->values[element_index + 1]; int got_bits = ~(0xFFFFFFFF << got); result = (result & got_bits) | (element << got); } - int out_bits = ~(0xFFFFFFFF << indice_bit_count); - return boost::optional(result & out_bits); + uint32_t out_bits = ~(0xFFFFFFFF << indice_bit_count); + return boost::optional(result & out_bits); } bool Modern_Section_Compound::get_block(BlockT& block, int x, int z, int y) { if (this->BlockStates) { - boost::optional block_data = boost::optional(); + boost::optional block_data = boost::optional(); // Static expansion of dynamic palette resolver; // each section (16**3) contains 4096 unique blocks wihch yields max 2**12 @@ -1036,11 +1036,11 @@ namespace mc { } bool Legacy_Section_Compound::get_block(BlockT& block, int x, int z, int y) { - boost::optional lower_block_type; - boost::optional block_type = get_indice(x, z, y, this->Blocks); + boost::optional lower_block_type; + boost::optional block_type = get_indice(x, z, y, this->Blocks); // Data values are packed two by two and the position LSB decides which // half-byte contains the requested block data value. - boost::optional block_data = get_indice(x, z, y, this->Data); + boost::optional block_data = get_indice(x, z, y, this->Data); if (block_type && block_data) { boost::optional material = get_material_legacy(block_type.get(), block_data.get());