bool cBlockArea::LoadFromSchematicFile(const AString & a_FileName) { // Un-GZip the contents: AString Contents; cGZipFile File; if (!File.Open(a_FileName, cGZipFile::fmRead)) { LOG("Cannot open the schematic file \"%s\".", a_FileName.c_str()); return false; } int NumBytesRead = File.ReadRestOfFile(Contents); if (NumBytesRead < 0) { LOG("Cannot read GZipped data in the schematic file \"%s\", error %d", a_FileName.c_str(), NumBytesRead); return false; } File.Close(); // Parse the NBT: cParsedNBT NBT(Contents.data(), Contents.size()); if (!NBT.IsValid()) { LOG("Cannot parse the NBT in the schematic file \"%s\".", a_FileName.c_str()); return false; } return LoadFromSchematicNBT(NBT); }
bool cMapSerializer::Load(void) { AString Data = cFile::ReadWholeFile(FILE_IO_PREFIX + m_Path); if (Data.empty()) { return false; } AString Uncompressed; int res = UncompressStringGZIP(Data.data(), Data.size(), Uncompressed); if (res != Z_OK) { return false; } // Parse the NBT data: cParsedNBT NBT(Uncompressed.data(), Uncompressed.size()); if (!NBT.IsValid()) { // NBT Parsing failed return false; } return LoadMapFromNBT(NBT); }
bool cIDCountSerializer::Load(void) { AString Data = cFile::ReadWholeFile(FILE_IO_PREFIX + m_Path); if (Data.empty()) { return false; } // NOTE: idcounts.dat is not compressed (raw format) // Parse the NBT data: cParsedNBT NBT(Data.data(), Data.size()); if (!NBT.IsValid()) { // NBT Parsing failed return false; } int CurrLine = NBT.FindChildByName(0, "map"); if (CurrLine >= 0) { m_MapCount = (int)NBT.GetShort(CurrLine) + 1; } else { m_MapCount = 0; } return true; }
bool cWSSAnvil::LoadChunkFromData(const cChunkCoords & a_Chunk, const AString & a_Data) { // Decompress the data: char Uncompressed[CHUNK_INFLATE_MAX]; z_stream strm; strm.zalloc = (alloc_func)NULL; strm.zfree = (free_func)NULL; strm.opaque = NULL; inflateInit(&strm); strm.next_out = (Bytef *)Uncompressed; strm.avail_out = sizeof(Uncompressed); strm.next_in = (Bytef *)a_Data.data(); strm.avail_in = a_Data.size(); int res = inflate(&strm, Z_FINISH); inflateEnd(&strm); if (res != Z_STREAM_END) { return false; } // Parse the NBT data: cParsedNBT NBT(Uncompressed, strm.total_out); if (!NBT.IsValid()) { // NBT Parsing failed return false; } // Load the data from NBT: return LoadChunkFromNBT(a_Chunk, NBT); }
bool cSchematicFileSerializer::LoadFromSchematicString(cBlockArea & a_BlockArea, const AString & a_SchematicData) { // Uncompress the data: AString UngzippedData; if (UncompressStringGZIP(a_SchematicData.data(), a_SchematicData.size(), UngzippedData) != Z_OK) { LOG("%s: Cannot unGZip the schematic data.", __FUNCTION__); return false; } // Parse the NBT: cParsedNBT NBT(UngzippedData.data(), UngzippedData.size()); if (!NBT.IsValid()) { LOG("%s: Cannot parse the NBT in the schematic data.", __FUNCTION__); return false; } return LoadFromSchematicNBT(a_BlockArea, NBT); }
int cProtocol132::ParseItemMetadata(cItem & a_Item, const AString & a_Metadata) { // Uncompress the GZIPped data: AString Uncompressed; if (UncompressStringGZIP(a_Metadata.data(), a_Metadata.size(), Uncompressed) != Z_OK) { AString HexDump; CreateHexDump(HexDump, a_Metadata.data(), a_Metadata.size(), 16); LOG("Cannot unGZIP item metadata:\n%s", HexDump.c_str()); return PARSE_ERROR; } // Parse into NBT: cParsedNBT NBT(Uncompressed.data(), Uncompressed.size()); if (!NBT.IsValid()) { AString HexDump; CreateHexDump(HexDump, Uncompressed.data(), Uncompressed.size(), 16); LOG("Cannot parse NBT item metadata:\n%s", HexDump.c_str()); return PARSE_ERROR; } // Load enchantments from the NBT: for (int tag = NBT.GetFirstChild(NBT.GetRoot()); tag >= 0; tag = NBT.GetNextSibling(tag)) { if ( (NBT.GetType(tag) == TAG_List) && ( (NBT.GetName(tag) == "ench") || (NBT.GetName(tag) == "StoredEnchantments") ) ) { EnchantmentSerializer::ParseFromNBT(a_Item.m_Enchantments, NBT, tag); } } return PARSE_OK; }