From 2e7781f7f0b92af1fd9bb8b297089137b0b16ad4 Mon Sep 17 00:00:00 2001 From: "admin@omencraft.com" Date: Mon, 31 Oct 2011 02:24:44 +0000 Subject: More changes to the denotch map converter. Added some tags. Still debugging some parsing issues. git-svn-id: http://mc-server.googlecode.com/svn/trunk@30 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- converter/cConvert.cpp | 10 +-- converter/cNBTData.cpp | 176 ++++++++++++++++++++++++++++++++++++++++++++----- converter/cNBTData.h | 29 ++++++-- converter/denotch | Bin 165672 -> 212251 bytes 4 files changed, 189 insertions(+), 26 deletions(-) diff --git a/converter/cConvert.cpp b/converter/cConvert.cpp index 445d38796..b84e93424 100644 --- a/converter/cConvert.cpp +++ b/converter/cConvert.cpp @@ -74,13 +74,13 @@ int main () { quicksort(toffarr, 0, 1023); //sort the array from smallest to larget offset locations so we only have to read through the file once. for ( short ia = 0; ia < 1024; ia++ ) {//a region file can hold a maximum of 1024 chunks (32*32) - if (ia == 31) { ia++; } + if (ia < 35 ) { //only run chunk # 3 if (toffarr[ia] < 8192) { //offsets of less than 8192 are impossible. 0 means there is no chunk in a particular location. if (toffarr[ia] > 0) { cout << "ERROR 2s31 IN COLLECTED CHUNK OFFSETS " << toffarr[ia]; fclose(f); return false; } //values between 0 and 8192 should be impossible. //This file does not contain the max 1024 chunks, skip until we get to the first } else { // found a chunk offset value //Chunk data begins with a (big-endian) four-byte length field which indicates the exact length of the remaining chunk data in bytes. The following byte indicates the compression scheme used for chunk data, and the remaining (length-1) bytes are the compressed chunk data. - printf("Working on chunk %i\n", ia); + printf("Working on chunk %i :: %i\n", ia, toffarr[ia]); if( fread( &byte1, sizeof(byte1), 1, f) != 1 ) { cout << "ERROR 2t32 READING FROM FILE " << SourceFile; fclose(f); return false; } if( fread( &byte2, sizeof(byte2), 1, f) != 1 ) { cout << "ERROR 2y51 READING FROM FILE " << SourceFile; fclose(f); return false; } if( fread( &byte3, sizeof(byte3), 1, f) != 1 ) { cout << "ERROR 3424 READING FROM FILE " << SourceFile; fclose(f); return false; } @@ -128,7 +128,7 @@ int main () { //testing of nbtparser. - cNBTData* NBTData = new cNBTData(BlockData, (testr)); + cNBTData* NBTData = new cNBTData(BlockData, (int)DestSize); NBTData->ParseData(); //NBTData->PrintData(); NBTData->OpenCompound(""); @@ -160,7 +160,8 @@ int main () { //printf("array Blocks: %i\n", NBTData->GetByteArray("Blocks")[i]); } - //printf("xPos: %i\n", NBTData->GetInteger("xPos") ); + printf("Coord(X,Z): %i,%i\n", NBTData->GetInteger("xPos"), NBTData->GetInteger("zPos") ); + NBTData->CloseCompound();// Close the compounds after you're done NBTData->CloseCompound(); @@ -174,6 +175,7 @@ int main () { } } + } //only run chunk # 3 //if (ia == 30) { break; } } //return 0; diff --git a/converter/cNBTData.cpp b/converter/cNBTData.cpp index c54f7d74e..ed655430b 100644 --- a/converter/cNBTData.cpp +++ b/converter/cNBTData.cpp @@ -3,6 +3,7 @@ #include #include "zlib.h" #include +#include #ifndef _WIN32 #include @@ -31,6 +32,8 @@ cNBTData::cNBTData( char* a_Buffer, unsigned int a_BufferSize ) m_ParseFunctions[TAG_Short] = &cNBTData::ParseShort; m_ParseFunctions[TAG_Int] = &cNBTData::ParseInt; m_ParseFunctions[TAG_Long] = &cNBTData::ParseLong; + m_ParseFunctions[TAG_Double] = &cNBTData::ParseDouble; + m_ParseFunctions[TAG_Float] = &cNBTData::ParseFloat; m_ParseFunctions[TAG_String] = &cNBTData::ParseString; m_ParseFunctions[TAG_List] = &cNBTData::ParseList; m_ParseFunctions[TAG_Compound] = &cNBTData::ParseCompound; @@ -41,6 +44,11 @@ cNBTData::cNBTData( char* a_Buffer, unsigned int a_BufferSize ) m_BufferSize = a_BufferSize; m_Index = 0; + tm = false; //tm to true will print more information for test mode + if (m_BufferSize == 82659) { + tm = true; + } + m_CurrentCompound = this; m_bDecompressed = true; @@ -309,6 +317,41 @@ void cNBTCompound::Serialize(std::string & a_Buffer) } a_Buffer.push_back( itr->second ); } + + for( DoubleMap::iterator itr = m_Doubles.begin(); itr != m_Doubles.end(); itr++ ) + { + a_Buffer.push_back( TAG_Double ); + AppendShort( a_Buffer, (short)itr->first.size() ); + if( itr->first.size() > 0 ) + { + a_Buffer.append( itr->first.c_str(), itr->first.size() ); + } + a_Buffer.push_back( itr->second ); + } + + for( FloatMap::iterator itr = m_Floats.begin(); itr != m_Floats.end(); itr++ ) + { + a_Buffer.push_back( TAG_Float ); + AppendShort( a_Buffer, (short)itr->first.size() ); + if( itr->first.size() > 0 ) + { + a_Buffer.append( itr->first.c_str(), itr->first.size() ); + } + a_Buffer.push_back( itr->second ); + } + + for( LongMap::iterator itr = m_Longs.begin(); itr != m_Longs.end(); itr++ ) + { + a_Buffer.push_back( TAG_Long ); + AppendShort( a_Buffer, (short)itr->first.size() ); + if( itr->first.size() > 0 ) + { + a_Buffer.append( itr->first.c_str(), itr->first.size() ); + } + a_Buffer.push_back( itr->second ); + } + + } void cNBTCompound::PrintData( int a_Depth, std::string a_Name ) @@ -352,6 +395,21 @@ void cNBTCompound::PrintData( int a_Depth, std::string a_Name ) printf("%s SHORT %s (%i)\n", Prefix, itr->first.c_str(), itr->second ); } + for( FloatMap::iterator itr = m_Floats.begin(); itr != m_Floats.end(); itr++ ) + { + printf("%s FLOAT %s (%f)\n", Prefix, itr->first.c_str(), itr->second ); + } + + for( LongMap::iterator itr = m_Longs.begin(); itr != m_Longs.end(); itr++ ) + { + printf("%s LONG %s (%lli)\n", Prefix, itr->first.c_str(), itr->second ); + } + + for( DoubleMap::iterator itr = m_Doubles.begin(); itr != m_Doubles.end(); itr++ ) + { + printf("%s Double %s (%f)\n", Prefix, itr->first.c_str(), itr->second ); + } + for( ByteMap::iterator itr = m_Bytes.begin(); itr != m_Bytes.end(); itr++ ) { printf("%s BYTE %s (%i)\n", Prefix, itr->first.c_str(), itr->second ); @@ -410,8 +468,10 @@ void cNBTData::ParseData() while( m_Index < m_BufferSize ) { - //printf("m_BufferSize3: %i\n", m_BufferSize); - //printf("m_Index: %i\n", m_Index); + if (tm) { + printf("m_BufferSize3: %i\n", m_BufferSize); + printf("m_Index: %i\n", m_Index); + } ParseTags(); } } @@ -428,12 +488,18 @@ void cNBTData::ParseTags() //printf("m_Index1: %i\n\n\n\n", m_Index); m_Index++; - //printf("Tag: %i\n", Tag); + if (tm) { + printf("Tag: %i\n", Tag); + } (*this.*m_ParseFunctions[ Tag ])(true); } else if( Tag == TAG_End ) { - //printf("Tag End"); + if (tm) { + printf("Tag End\n"); + int n; + std::cin >> n; + } m_Index++; } else @@ -478,6 +544,10 @@ void cNBTData::ParseList( bool a_bNamed ) //printf("%02i %02x %3i %c\n", i, (unsigned char)m_Buffer[i], (unsigned char)m_Buffer[i], m_Buffer[i] );//re //}//re + if (tm) { + printf("List Name, tag, length: %s, %i, %i\n", Name.c_str(), (int)TagType, Length); + } + PutList( Name, TagType ); OpenList( Name ); for(int i = 0; i < Length && m_Index < m_BufferSize; i++) @@ -499,8 +569,9 @@ void cNBTData::ParseByte( bool a_bNamed ) char Value = ReadByte(); PutByte( Name, Value ); - - //printf("BYTE: %s %i\n", Name.c_str(), Value );//re + if (tm) { + printf("BYTE: %s %i\n", Name.c_str(), Value );//re + } } void cNBTData::ParseShort( bool a_bNamed ) @@ -510,8 +581,9 @@ void cNBTData::ParseShort( bool a_bNamed ) short Value = ReadShort(); PutShort( Name, Value ); - - //printf("SHORT: %s %i\n", Name.c_str(), Value );//re + if (tm) { + printf("SHORT: %s %i\n", Name.c_str(), Value );//re + } } void cNBTData::ParseInt( bool a_bNamed ) @@ -521,19 +593,63 @@ void cNBTData::ParseInt( bool a_bNamed ) int Value = ReadInt(); PutInteger( Name, Value ); - - //printf("INT: %s %i\n", Name.c_str(), Value );//re + if (tm) { + printf("INT: %s %i\n", Name.c_str(), Value );//re + } } void cNBTData::ParseLong( bool a_bNamed ) { + if (tm) { + for(unsigned int i = (m_Index-10 > 0)?m_Index-10:0 ; i < m_Index+30 && i < m_BufferSize; i++) { + printf("%02i %02x %3i %c\n", i, (unsigned char)m_Buffer[i], (unsigned char)m_Buffer[i], m_Buffer[i] ); + } + } std::string Name; if( a_bNamed ) Name = ReadName(); long long Value = ReadLong(); - PutInteger( Name, (int)Value ); + //PutInteger( Name, (int)Value ); + PutLong( Name, Value ); + if (tm) { + printf("LONG: %s %lli\n", Name.c_str(), Value );//re + } +} + +void cNBTData::ParseDouble( bool a_bNamed ) +{ + if (tm) { + for(unsigned int i = (m_Index-10 > 0)?m_Index-10:0 ; i < m_Index+30 && i < m_BufferSize; i++) { + printf("%02i %02x %3i %c\n", i, (unsigned char)m_Buffer[i], (unsigned char)m_Buffer[i], m_Buffer[i] ); + } + } + std::string Name; + if( a_bNamed ) Name = ReadName(); + double Value = ReadDouble(); + + //PutInteger( Name, (int)Value ); + PutDouble( Name, Value ); + if (tm) { + printf("Double: %s %f\n", Name.c_str(), Value );//re + } +} + +void cNBTData::ParseFloat( bool a_bNamed ) +{ + if (tm) { + for(unsigned int i = (m_Index-10 > 0)?m_Index-10:0 ; i < m_Index+30 && i < m_BufferSize; i++) { + printf("%02i %02x %3i %c\n", i, (unsigned char)m_Buffer[i], (unsigned char)m_Buffer[i], m_Buffer[i] ); + } + } + std::string Name; + if( a_bNamed ) Name = ReadName(); + float Value = ReadFloat(); - //printf("LONG: %s %lli\n", Name.c_str(), Value );//re + //PutInteger( Name, (int)Value ); + PutFloat( Name, Value ); + if (tm) { + printf("Float: %s %f\n", Name.c_str(), Value );//re + } } void cNBTData::ParseString( bool a_bNamed ) @@ -543,8 +659,9 @@ void cNBTData::ParseString( bool a_bNamed ) std::string String = ReadName(); PutString( Name, String ); - - //printf("STRING: %s (%s)\n", Name.c_str(), String.c_str() );//re + if (tm) { + printf("STRING: %s (%s)\n", Name.c_str(), String.c_str() );//re + } } void cNBTData::ParseByteArray( bool a_bNamed ) @@ -565,7 +682,11 @@ void cNBTData::ParseByteArray( bool a_bNamed ) PutByteArray( Name, ByteArray ); - //printf("VALUE: %s First 5 Chars: (%i,%i,%i,%i,%i)\n", Name.c_str(), ByteArray[0],ByteArray[1],ByteArray[2],ByteArray[3],ByteArray[4] );//re + if (tm) { + for(unsigned int i = (m_Index-10 > 0)?m_Index-10:0 ; i < m_Index+10 && i < m_BufferSize; i++) { + printf("%02i %02x %3i %c\n", i, (unsigned char)m_Buffer[i], (unsigned char)m_Buffer[i], m_Buffer[i] ); + } + } } std::string cNBTData::ReadName() @@ -610,11 +731,34 @@ int cNBTData::ReadInt() long long cNBTData::ReadLong() { + if (tm) { + printf( "here1 : %i, m_Index: %i\n", (int)sizeof(long long), (int)m_Index ); + } long long Value = 0; memcpy( &Value, m_Buffer+m_Index, sizeof(long long) ); m_Index+=sizeof(long long); + if (tm) { + printf( "here2 : %i, m_Index: %i\n", (int)sizeof(long long), (int)m_Index ); + } + return Value; +} - return ntohl( Value ); +double cNBTData::ReadDouble() +{ + double Value = 0; + memcpy( &Value, m_Buffer+m_Index, sizeof(double) ); + m_Index+=sizeof(double); + + return Value; +} + +float cNBTData::ReadFloat() +{ + float Value = 0; + memcpy( &Value, m_Buffer+m_Index, sizeof(float) ); + m_Index+=sizeof(float); + + return Value; } void cNBTCompound::PutList( std::string Name, ENUM_TAG Type ) diff --git a/converter/cNBTData.h b/converter/cNBTData.h index 4d5ec0beb..d3e5e82b6 100644 --- a/converter/cNBTData.h +++ b/converter/cNBTData.h @@ -38,7 +38,9 @@ public: void PutByte( std::string Name, char Value ) { m_Bytes[Name] = Value; } void PutShort( std::string Name, short Value ) { m_Shorts[Name] = Value; } void PutInteger( std::string Name, int Value ) { m_Integers[Name] = Value; } - void PutLong( std::string Name, long Value ) { m_Longs[Name] = Value; } + void PutLong( std::string Name, long long Value ) { m_Longs[Name] = Value; } + void PutDouble( std::string Name, double Value ) { m_Doubles[Name] = Value; } + void PutFloat( std::string Name, float Value ) { m_Floats[Name] = Value; } void PutString( std::string Name, std::string Value ) { m_Strings[Name] = Value; } void PutByteArray( std::string Name, char* ByteArray ) { m_ByteArrays[Name] = ByteArray; } void PutCompound( std::string Name ); @@ -47,7 +49,9 @@ public: char GetByte( std::string Name ) { return m_Bytes[Name]; } short GetShort( std::string Name ) { return m_Shorts[Name]; } int GetInteger( std::string Name ) { return m_Integers[Name]; } - long GetLong( std::string Name ) { return m_Longs[Name]; } + long long GetLong( std::string Name ) { return m_Longs[Name]; } + double GetDouble( std::string Name ) { return m_Doubles[Name]; } + float GetFloat( std::string Name ) { return m_Floats[Name]; } std::string GetString( std::string Name ) { return m_Strings[Name]; } char* GetByteArray( std::string Name ) { return m_ByteArrays[Name]; } cNBTCompound* GetCompound( std::string Name ); @@ -72,7 +76,9 @@ private: typedef std::map ByteMap; typedef std::map ShortMap; typedef std::map IntegerMap; - typedef std::map LongMap; + typedef std::map LongMap; + typedef std::map DoubleMap; + typedef std::map FloatMap; typedef std::map StringMap; typedef std::map ByteArrayMap; typedef std::map CompoundMap; @@ -81,6 +87,8 @@ private: ShortMap m_Shorts; IntegerMap m_Integers; LongMap m_Longs; + DoubleMap m_Doubles; + FloatMap m_Floats; StringMap m_Strings; ByteArrayMap m_ByteArrays; CompoundMap m_Compounds; @@ -131,14 +139,18 @@ public: void PutByte( std::string Name, char Value ) { m_CurrentCompound->PutByte( Name, Value ); } void PutShort( std::string Name, short Value ) { m_CurrentCompound->PutShort( Name, Value ); } void PutInteger( std::string Name, int Value ) { m_CurrentCompound->PutInteger( Name, Value ); } - void PutLong( std::string Name, long Value ) { m_CurrentCompound->PutLong( Name, Value ); } - void PutString( std::string Name, std::string Value ) { m_CurrentCompound->PutString(Name, Value); } + void PutLong( std::string Name, long long Value ) { m_CurrentCompound->PutLong( Name, Value ); } + void PutDouble( std::string Name, double Value ) { m_CurrentCompound->PutDouble( Name, Value ); } + void PutFloat( std::string Name, float Value ) { m_CurrentCompound->PutFloat( Name, Value ); } + void PutString( std::string Name, std::string Value ) { m_CurrentCompound->PutString( Name, Value ); } void PutByteArray( std::string Name, char* ByteArray ) { m_CurrentCompound->PutByteArray( Name, ByteArray ); } void PutCompound( std::string Name ) { m_CurrentCompound->PutCompound( Name ); } void PutList( std::string Name, ENUM_TAG Type ) { m_CurrentCompound->PutList( Name, Type ); } int GetInteger( std::string Name ) { return m_CurrentCompound->GetInteger(Name); } - long GetLong( std::string Name ) { return m_CurrentCompound->GetLong(Name); } + long long GetLong( std::string Name ) { return m_CurrentCompound->GetLong(Name); } + double GetDouble( std::string Name ) { return m_CurrentCompound->GetDouble(Name); } + float GetFloat( std::string Name ) { return m_CurrentCompound->GetFloat(Name); } std::string GetString( std::string Name ) { return m_CurrentCompound->GetString(Name); } char* GetByteArray( std::string Name ) { return m_CurrentCompound->GetByteArray(Name); } cNBTCompound* GetCompound( std::string Name ) { return m_CurrentCompound->GetCompound(Name); } @@ -163,6 +175,8 @@ private: void ParseByteArray( bool a_bNamed ); void ParseInt( bool a_bNamed ); void ParseLong( bool a_bNamed ); + void ParseDouble( bool a_bNamed ); + void ParseFloat( bool a_bNamed ); void ParseShort( bool a_bNamed ); short ReadShort(); @@ -170,12 +184,15 @@ private: char ReadByte(); int ReadInt(); long long ReadLong(); + double ReadDouble(); + float ReadFloat(); cNBTCompound* m_CurrentCompound; char* m_Buffer; unsigned int m_BufferSize; unsigned int m_Index; + bool tm; void (cNBTData::*m_ParseFunctions[TAG_NumTags])(bool); }; diff --git a/converter/denotch b/converter/denotch index d222a8d27..4874c3c53 100755 Binary files a/converter/denotch and b/converter/denotch differ -- cgit v1.2.3