diff options
Diffstat (limited to 'Tools/BlockZapper')
-rw-r--r-- | Tools/BlockZapper/BlockZapper.cpp | 15 | ||||
-rw-r--r-- | Tools/BlockZapper/Globals.cpp | 4 | ||||
-rw-r--r-- | Tools/BlockZapper/Globals.h | 4 | ||||
-rw-r--r-- | Tools/BlockZapper/Regions.cpp | 20 | ||||
-rw-r--r-- | Tools/BlockZapper/Regions.h | 20 | ||||
-rw-r--r-- | Tools/BlockZapper/Zapper.cpp | 85 | ||||
-rw-r--r-- | Tools/BlockZapper/Zapper.h | 10 |
7 files changed, 94 insertions, 64 deletions
diff --git a/Tools/BlockZapper/BlockZapper.cpp b/Tools/BlockZapper/BlockZapper.cpp index 9db9e3c99..de47ccfeb 100644 --- a/Tools/BlockZapper/BlockZapper.cpp +++ b/Tools/BlockZapper/BlockZapper.cpp @@ -15,8 +15,8 @@ #ifdef _MSC_VER - // Under MSVC, link to WinSock2 (needed by FastNBT's byteswapping) - #pragma comment(lib, "ws2_32.lib") +// Under MSVC, link to WinSock2 (needed by FastNBT's byteswapping) +#pragma comment(lib, "ws2_32.lib") #endif @@ -62,13 +62,8 @@ int main(int argc, char * argv[]) } i++; } - else if ( - (strcmp(argv[i], "help") == 0) || - (strcmp(argv[i], "-?") == 0) || - (strcmp(argv[i], "/?") == 0) || - (strcmp(argv[i], "-h") == 0) || - (strcmp(argv[i], "--help") == 0) - ) + else if ((strcmp(argv[i], "help") == 0) || (strcmp(argv[i], "-?") == 0) || (strcmp(argv[i], "/?") == 0) || + (strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0)) { ShowHelp(argv[0]); return 0; @@ -90,4 +85,4 @@ int main(int argc, char * argv[]) LOGINFO("Done"); return 0; -} ; +}; diff --git a/Tools/BlockZapper/Globals.cpp b/Tools/BlockZapper/Globals.cpp index d73265a60..6d1b25cbc 100644 --- a/Tools/BlockZapper/Globals.cpp +++ b/Tools/BlockZapper/Globals.cpp @@ -4,7 +4,3 @@ // Used for precompiled header generation in MSVC #include "Globals.h" - - - - diff --git a/Tools/BlockZapper/Globals.h b/Tools/BlockZapper/Globals.h index 3826c72fa..9de3f032c 100644 --- a/Tools/BlockZapper/Globals.h +++ b/Tools/BlockZapper/Globals.h @@ -8,7 +8,3 @@ #include "../../src/Globals.h" - - - - diff --git a/Tools/BlockZapper/Regions.cpp b/Tools/BlockZapper/Regions.cpp index 7a205a138..ec6f98545 100644 --- a/Tools/BlockZapper/Regions.cpp +++ b/Tools/BlockZapper/Regions.cpp @@ -30,7 +30,16 @@ cRegion::cRegion(void) : -cRegion::cRegion(int a_MinX, int a_MaxX, int a_MinY, int a_MaxY, int a_MinZ, int a_MaxZ, bool a_ShouldZapBlocks, bool a_ShouldZapEntities) : +cRegion::cRegion( + int a_MinX, + int a_MaxX, + int a_MinY, + int a_MaxY, + int a_MinZ, + int a_MaxZ, + bool a_ShouldZapBlocks, + bool a_ShouldZapEntities +) : m_MinX(a_MinX), m_MaxX(a_MaxX), m_MinY(std::max(0, std::min(255, a_MinY))), @@ -52,10 +61,7 @@ bool cRegion::TouchesChunk(int a_ChunkX, int a_ChunkZ) const int ChunkEndX = a_ChunkX * 16 + 15; int ChunkBeginZ = a_ChunkZ * 16; int ChunkEndZ = a_ChunkZ * 16 + 15; - if ( - (m_MinX > ChunkEndX) || (m_MaxX < ChunkBeginX) || - (m_MinZ > ChunkEndZ) || (m_MaxZ < ChunkBeginZ) - ) + if ((m_MinX > ChunkEndX) || (m_MaxX < ChunkBeginX) || (m_MinZ > ChunkEndZ) || (m_MaxZ < ChunkBeginZ)) { return false; } @@ -159,5 +165,7 @@ void cRegions::AddRegion(const AStringVector & a_Split) } // Store the region - m_Regions.push_back(cRegion(Coords[0], Coords[1], Coords[2], Coords[3], Coords[4], Coords[5], ShouldZapBlocks, ShouldZapEntities)); + m_Regions.push_back( + cRegion(Coords[0], Coords[1], Coords[2], Coords[3], Coords[4], Coords[5], ShouldZapBlocks, ShouldZapEntities) + ); } diff --git a/Tools/BlockZapper/Regions.h b/Tools/BlockZapper/Regions.h index 2fe50a9b4..b740f62f6 100644 --- a/Tools/BlockZapper/Regions.h +++ b/Tools/BlockZapper/Regions.h @@ -25,10 +25,19 @@ struct cRegion bool m_ShouldZapEntities; cRegion(void); - cRegion(int a_MinX, int a_MaxX, int a_MinY, int a_MaxY, int a_MinZ, int a_MaxZ, bool a_ShouldZapBlocks, bool a_ShouldZapEntities); + cRegion( + int a_MinX, + int a_MaxX, + int a_MinY, + int a_MaxY, + int a_MinZ, + int a_MaxZ, + bool a_ShouldZapBlocks, + bool a_ShouldZapEntities + ); bool TouchesChunk(int a_ChunkX, int a_ChunkZ) const; -} ; +}; typedef std::vector<cRegion> cRegionVector; @@ -38,17 +47,16 @@ typedef std::vector<cRegion> cRegionVector; class cRegions { -public: + public: /** Reads the list of regions from the specified stream */ void Read(std::istream & a_Stream); /** Returns all regions in this container */ const cRegionVector & GetAll(void) const { return m_Regions; } -protected: + protected: cRegionVector m_Regions; /** Adds a new region based on the contents of the split line. The split must already be the correct size */ void AddRegion(const AStringVector & a_Split); - -} ; +}; diff --git a/Tools/BlockZapper/Zapper.cpp b/Tools/BlockZapper/Zapper.cpp index ae3916835..84a5dd3f0 100644 --- a/Tools/BlockZapper/Zapper.cpp +++ b/Tools/BlockZapper/Zapper.cpp @@ -89,7 +89,12 @@ void cZapper::ZapRegionInMCAFile(const cRegion & a_Region, int a_MCAX, int a_MCA AString FileNameOut = Printf("%s/r.%d.%d.zap", m_MCAFolder.c_str(), a_MCAX, a_MCAZ); if (!fOut.Open(FileNameOut, cFile::fmWrite)) { - fprintf(stderr, "Cannot open temporary file \"%s\" for writing, skipping file \"%s\".", FileNameOut.c_str(), FileNameIn.c_str()); + fprintf( + stderr, + "Cannot open temporary file \"%s\" for writing, skipping file \"%s\".", + FileNameOut.c_str(), + FileNameIn.c_str() + ); return; } @@ -124,16 +129,17 @@ void cZapper::ZapRegionInMCAFile(const cRegion & a_Region, int a_MCAX, int a_MCA size_t DataSize = ChunkData.size() + 1; ChunkHeader[0] = (DataSize >> 24) & 0xff; ChunkHeader[1] = (DataSize >> 16) & 0xff; - ChunkHeader[2] = (DataSize >> 8) & 0xff; + ChunkHeader[2] = (DataSize >> 8) & 0xff; ChunkHeader[3] = DataSize & 0xff; ChunkHeader[4] = 2; // zlib compression - size_t Alignment = 4096 - (ChunkData.size() + 5) % 4096; // 5 bytes of the header are appended outside of ChunkData + size_t Alignment = + 4096 - (ChunkData.size() + 5) % 4096; // 5 bytes of the header are appended outside of ChunkData if (Alignment > 0) { - ChunkData.append(Alignment, (char)0); + ChunkData.append(Alignment, (char) 0); } HeaderOut[i] = htonl(((DataOut.size() / 4096 + 2) << 8) | ((ChunkData.size() + 5) / 4096)); - DataOut.append((const char *)ChunkHeader, sizeof(ChunkHeader)); + DataOut.append((const char *) ChunkHeader, sizeof(ChunkHeader)); DataOut.append(ChunkData); } // for i - chunks in fIn for (int i = 1024; i < 2048; i++) @@ -162,13 +168,19 @@ void cZapper::LoadChunkData(cFile & a_InFile, int a_ChunkHeaderValue, AString & a_InFile.Read(ChunkHeader, sizeof(ChunkHeader)); if (ChunkHeader[4] != 2) { - fprintf(stderr, "Chunk [%d, %d] is compressed in an unknown scheme (%d), skipping", a_ChunkX, a_ChunkZ, ChunkHeader[4]); + fprintf( + stderr, + "Chunk [%d, %d] is compressed in an unknown scheme (%d), skipping", + a_ChunkX, + a_ChunkZ, + ChunkHeader[4] + ); return; } - int ActualSize = (ChunkHeader[0] << 24) | (ChunkHeader[1] << 16) | (ChunkHeader[2] << 8) | ChunkHeader[3]; + int ActualSize = (ChunkHeader[0] << 24) | (ChunkHeader[1] << 16) | (ChunkHeader[2] << 8) | ChunkHeader[3]; ActualSize -= 1; // Compression took 1 byte a_ChunkData.resize(ActualSize); - int BytesRead = a_InFile.Read((void *)(a_ChunkData.data()), ActualSize); + int BytesRead = a_InFile.Read((void *) (a_ChunkData.data()), ActualSize); if (BytesRead != ActualSize) { fprintf(stderr, "Chunk is truncated in file (%d bytes out of %d), skipping.", BytesRead, ActualSize); @@ -186,14 +198,14 @@ void cZapper::ZapRegionInRawChunkData(const cRegion & a_Region, AString & a_Chun // Decompress the data: char Uncompressed[CHUNK_INFLATE_MAX]; z_stream strm; - strm.zalloc = (alloc_func)NULL; - strm.zfree = (free_func)NULL; + strm.zalloc = (alloc_func) NULL; + strm.zfree = (free_func) NULL; strm.opaque = NULL; inflateInit(&strm); - strm.next_out = (Bytef *)Uncompressed; + strm.next_out = (Bytef *) Uncompressed; strm.avail_out = sizeof(Uncompressed); - strm.next_in = (Bytef *)a_ChunkData.data(); - strm.avail_in = a_ChunkData.size(); + strm.next_in = (Bytef *) a_ChunkData.data(); + strm.avail_in = a_ChunkData.size(); int res = inflate(&strm, Z_FINISH); inflateEnd(&strm); if (res != Z_STREAM_END) @@ -268,7 +280,13 @@ void cZapper::ZapRegionInNBTChunk(const cRegion & a_Region, cParsedNBT & a_NBT, int SectionsTag = a_NBT.FindChildByName(LevelTag, "Sections"); if (SectionsTag < 0) { - fprintf(stderr, "Cannot find the Sections tag in the Level tag in chunk [%d, %d]'s NBT. Skipping block-zapping in chunk.", a_ChunkX, a_ChunkZ); + fprintf( + stderr, + "Cannot find the Sections tag in the Level tag in chunk [%d, %d]'s NBT. Skipping block-zapping in " + "chunk.", + a_ChunkX, + a_ChunkZ + ); return; } ZapRegionBlocksInNBT(Local, a_NBT, SectionsTag); @@ -279,7 +297,13 @@ void cZapper::ZapRegionInNBTChunk(const cRegion & a_Region, cParsedNBT & a_NBT, int EntitiesTag = a_NBT.FindChildByName(LevelTag, "Entities"); if (EntitiesTag < 0) { - fprintf(stderr, "Cannot find the Entities tag in the Level tag in chunk [%d, %d]'s NBT. Skipping entity-zapping in chunk.", a_ChunkX, a_ChunkZ); + fprintf( + stderr, + "Cannot find the Entities tag in the Level tag in chunk [%d, %d]'s NBT. Skipping entity-zapping in " + "chunk.", + a_ChunkX, + a_ChunkZ + ); return; } ZapRegionEntitiesInNBT(Local, a_NBT, EntitiesTag); @@ -307,18 +331,18 @@ void cZapper::ZapRegionBlocksInNBT(const cRegion & a_Region, cParsedNBT & a_NBT, } int BlockDataTag = a_NBT.FindChildByName(Child, "Blocks"); int BlockMetaTag = a_NBT.FindChildByName(Child, "Data"); - int BlockAddTag = a_NBT.FindChildByName(Child, "Add"); + int BlockAddTag = a_NBT.FindChildByName(Child, "Add"); if (BlockDataTag > 0) { - ZapRegionInNBTSectionBytes(a_Region, y, (unsigned char *)(a_NBT.GetData(BlockDataTag))); + ZapRegionInNBTSectionBytes(a_Region, y, (unsigned char *) (a_NBT.GetData(BlockDataTag))); } if (BlockMetaTag > 0) { - ZapRegionInNBTSectionNibbles(a_Region, y, (unsigned char *)(a_NBT.GetData(BlockMetaTag))); + ZapRegionInNBTSectionNibbles(a_Region, y, (unsigned char *) (a_NBT.GetData(BlockMetaTag))); } if (BlockAddTag > 0) { - ZapRegionInNBTSectionNibbles(a_Region, y, (unsigned char *)(a_NBT.GetData(BlockAddTag))); + ZapRegionInNBTSectionNibbles(a_Region, y, (unsigned char *) (a_NBT.GetData(BlockAddTag))); } } // for Child - Level / Sections / [] } @@ -384,25 +408,28 @@ void cZapper::SerializeNBTTag(const cParsedNBT & a_NBT, int a_Tag, cFastNBTWrite { switch (a_NBT.GetType(a_Tag)) { - case TAG_Byte: a_Writer.AddByte (a_NBT.GetName(a_Tag), a_NBT.GetByte (a_Tag)); break; - case TAG_Short: a_Writer.AddShort (a_NBT.GetName(a_Tag), a_NBT.GetShort (a_Tag)); break; - case TAG_Int: a_Writer.AddInt (a_NBT.GetName(a_Tag), a_NBT.GetInt (a_Tag)); break; - case TAG_Long: a_Writer.AddLong (a_NBT.GetName(a_Tag), a_NBT.GetLong (a_Tag)); break; - case TAG_Float: a_Writer.AddFloat (a_NBT.GetName(a_Tag), a_NBT.GetFloat (a_Tag)); break; - case TAG_Double: a_Writer.AddDouble (a_NBT.GetName(a_Tag), a_NBT.GetDouble(a_Tag)); break; - case TAG_ByteArray: a_Writer.AddByteArray(a_NBT.GetName(a_Tag), a_NBT.GetData (a_Tag), a_NBT.GetDataLength(a_Tag)); break; - case TAG_String: a_Writer.AddString (a_NBT.GetName(a_Tag), a_NBT.GetString(a_Tag)); break; + case TAG_Byte: a_Writer.AddByte(a_NBT.GetName(a_Tag), a_NBT.GetByte(a_Tag)); break; + case TAG_Short: a_Writer.AddShort(a_NBT.GetName(a_Tag), a_NBT.GetShort(a_Tag)); break; + case TAG_Int: a_Writer.AddInt(a_NBT.GetName(a_Tag), a_NBT.GetInt(a_Tag)); break; + case TAG_Long: a_Writer.AddLong(a_NBT.GetName(a_Tag), a_NBT.GetLong(a_Tag)); break; + case TAG_Float: a_Writer.AddFloat(a_NBT.GetName(a_Tag), a_NBT.GetFloat(a_Tag)); break; + case TAG_Double: a_Writer.AddDouble(a_NBT.GetName(a_Tag), a_NBT.GetDouble(a_Tag)); break; + case TAG_ByteArray: + a_Writer.AddByteArray(a_NBT.GetName(a_Tag), a_NBT.GetData(a_Tag), a_NBT.GetDataLength(a_Tag)); + break; + case TAG_String: a_Writer.AddString(a_NBT.GetName(a_Tag), a_NBT.GetString(a_Tag)); break; case TAG_IntArray: { std::vector<int> Data; int NumInts = a_NBT.GetDataLength(a_Tag) / 4; Data.reserve(NumInts); - int * OrigData = (int *)(a_NBT.GetData(a_Tag)); + int * OrigData = (int *) (a_NBT.GetData(a_Tag)); for (int i = 0; i < NumInts; i++) { Data.push_back(ntohl(OrigData[i])); } - a_Writer.AddIntArray (a_NBT.GetName(a_Tag), &Data.front(), Data.size()); break; + a_Writer.AddIntArray(a_NBT.GetName(a_Tag), &Data.front(), Data.size()); + break; } case TAG_List: diff --git a/Tools/BlockZapper/Zapper.h b/Tools/BlockZapper/Zapper.h index e156848af..7daa07a59 100644 --- a/Tools/BlockZapper/Zapper.h +++ b/Tools/BlockZapper/Zapper.h @@ -25,13 +25,13 @@ class cFastNBTWriter; class cZapper { -public: + public: cZapper(const AString & a_MCAFolder); /** Zaps all the specified regions */ void ZapRegions(const cRegionVector & a_Regions); -protected: + protected: static const int BlocksPerChunkX = 16; static const int BlocksPerChunkZ = 16; static const int ChunksPerMCAX = 32; @@ -49,8 +49,8 @@ protected: void ZapRegionInMCAFile(const cRegion & a_Region, int a_MCAX, int a_MCAZ); /** Loads raw compressed chunk data from the specified file - * chunk is specified by ChunkHeaderValue, which is the int describing the chunk in file header. - */ + * chunk is specified by ChunkHeaderValue, which is the int describing the chunk in file header. + */ void LoadChunkData(cFile & a_InFile, int a_ChunkHeaderValue, AString & a_ChunkData, int a_ChunkX, int a_ChunkZ); /** Zaps the specified region in the raw (compressed) chunk data. */ @@ -73,4 +73,4 @@ protected: /** Serializes the NBT subtree into a writer */ void SerializeNBTTag(const cParsedNBT & a_NBT, int a_Tag, cFastNBTWriter & a_Writer); -} ; +}; |