2011-10-29 17:19:06 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class cNBTList;
|
|
|
|
class cNBTData;
|
|
|
|
|
|
|
|
class cNBTCompound
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cNBTCompound( cNBTCompound* a_ParentCompound ) : m_ParentCompound( a_ParentCompound ), m_CurrentList(0) { }
|
|
|
|
virtual ~cNBTCompound() {}
|
|
|
|
public:
|
|
|
|
#ifdef _WIN32
|
|
|
|
enum ENUM_TAG : unsigned char
|
|
|
|
#else
|
|
|
|
enum ENUM_TAG
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
TAG_End = 0,
|
2011-10-30 07:41:18 -04:00
|
|
|
TAG_Byte = 1,
|
|
|
|
TAG_Short = 2,
|
|
|
|
TAG_Int = 3,
|
2011-10-30 14:15:44 -04:00
|
|
|
TAG_Long = 4,
|
|
|
|
TAG_Float = 5,
|
|
|
|
TAG_Double = 6,
|
2011-10-29 22:55:10 -04:00
|
|
|
TAG_ByteArray = 7,
|
2011-10-30 14:15:44 -04:00
|
|
|
TAG_String = 8,
|
2011-10-30 07:41:18 -04:00
|
|
|
TAG_List = 9,
|
|
|
|
TAG_Compound = 10,
|
2011-10-29 17:19:06 -04:00
|
|
|
TAG_NumTags // Not a real tag, but contains number of tags
|
|
|
|
};
|
|
|
|
|
|
|
|
void Clear();
|
|
|
|
|
2011-10-30 03:10:22 -04:00
|
|
|
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; }
|
2011-10-30 22:24:44 -04:00
|
|
|
void PutLong( std::string Name, long long Value ) { m_Longs[Name] = Value; }
|
|
|
|
void PutDouble( std::string Name, double Value ) { m_Doubles[Name] = Value; }
|
2011-10-31 01:12:21 -04:00
|
|
|
void PutFloat( std::string Name, float Value );
|
2011-10-30 03:10:22 -04:00
|
|
|
void PutString( std::string Name, std::string Value ) { m_Strings[Name] = Value; }
|
2011-10-30 04:04:40 -04:00
|
|
|
void PutByteArray( std::string Name, char* ByteArray ) { m_ByteArrays[Name] = ByteArray; }
|
2011-10-29 17:19:06 -04:00
|
|
|
void PutCompound( std::string Name );
|
|
|
|
void PutList( std::string Name, ENUM_TAG Type );
|
|
|
|
|
2011-10-30 04:04:40 -04:00
|
|
|
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]; }
|
2011-10-30 22:24:44 -04:00
|
|
|
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]; }
|
2011-10-30 04:04:40 -04:00
|
|
|
std::string GetString( std::string Name ) { return m_Strings[Name]; }
|
|
|
|
char* GetByteArray( std::string Name ) { return m_ByteArrays[Name]; }
|
2011-10-29 17:19:06 -04:00
|
|
|
cNBTCompound* GetCompound( std::string Name );
|
2011-10-30 04:04:40 -04:00
|
|
|
cNBTList* GetList( std::string Name ) { return m_Lists[Name]; }
|
2011-10-29 17:19:06 -04:00
|
|
|
|
2011-10-30 14:15:44 -04:00
|
|
|
cNBTList* GetCurrentList() { return m_CurrentList; }
|
|
|
|
cNBTCompound* GetParentCompound() { return m_ParentCompound; }
|
2011-10-29 17:19:06 -04:00
|
|
|
|
|
|
|
bool OpenList( std::string a_Name );
|
|
|
|
bool CloseList();
|
|
|
|
|
|
|
|
void Serialize(std::string & a_Buffer);
|
|
|
|
|
|
|
|
void PrintData( int a_Depth, std::string a_Name );
|
|
|
|
private:
|
|
|
|
void AppendShort( std::string & a_Buffer, short a_Value );
|
|
|
|
void AppendInteger( std::string & a_Buffer, int a_Value );
|
|
|
|
|
|
|
|
cNBTCompound* m_ParentCompound;
|
|
|
|
cNBTList* m_CurrentList;
|
|
|
|
|
2011-10-29 22:16:01 -04:00
|
|
|
typedef std::map<std::string, char> ByteMap;
|
2011-10-29 17:19:06 -04:00
|
|
|
typedef std::map<std::string, short> ShortMap;
|
2011-10-29 22:16:01 -04:00
|
|
|
typedef std::map<std::string, int> IntegerMap;
|
2011-10-30 22:24:44 -04:00
|
|
|
typedef std::map<std::string, long long> LongMap;
|
|
|
|
typedef std::map<std::string, double> DoubleMap;
|
|
|
|
typedef std::map<std::string, float> FloatMap;
|
2011-10-29 22:16:01 -04:00
|
|
|
typedef std::map<std::string, std::string> StringMap;
|
2011-10-30 04:04:40 -04:00
|
|
|
typedef std::map<std::string, char*> ByteArrayMap;
|
2011-10-29 17:19:06 -04:00
|
|
|
typedef std::map<std::string, cNBTCompound*> CompoundMap;
|
|
|
|
typedef std::map<std::string, cNBTList*> ListMap;
|
|
|
|
ByteMap m_Bytes;
|
2011-10-29 22:16:01 -04:00
|
|
|
ShortMap m_Shorts;
|
|
|
|
IntegerMap m_Integers;
|
2011-10-30 03:10:22 -04:00
|
|
|
LongMap m_Longs;
|
2011-10-30 22:24:44 -04:00
|
|
|
DoubleMap m_Doubles;
|
|
|
|
FloatMap m_Floats;
|
2011-10-29 22:16:01 -04:00
|
|
|
StringMap m_Strings;
|
|
|
|
ByteArrayMap m_ByteArrays;
|
2011-10-29 17:19:06 -04:00
|
|
|
CompoundMap m_Compounds;
|
|
|
|
ListMap m_Lists;
|
|
|
|
};
|
|
|
|
|
|
|
|
class cNBTList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cNBTList( cNBTList* a_ParentList, cNBTCompound::ENUM_TAG a_Type ) : m_ParentList( a_ParentList ), m_Type( a_Type ) {}
|
|
|
|
void AddToList( void* a_Item ) { m_List.push_back( a_Item ); }
|
|
|
|
void* GetLastElement() { return m_List.back(); }
|
|
|
|
cNBTCompound::ENUM_TAG GetType() { return m_Type; }
|
|
|
|
cNBTList* GetParentList() { return m_ParentList; }
|
|
|
|
|
|
|
|
unsigned int GetSize() { return m_List.size(); }
|
|
|
|
|
|
|
|
void Serialize(std::string & a_Buffer);
|
|
|
|
void PrintData(int a_Depth, std::string a_Name);
|
|
|
|
typedef std::list<void*> VoidList;
|
|
|
|
VoidList GetList() { return m_List; }
|
|
|
|
|
|
|
|
void Clear();
|
|
|
|
private:
|
|
|
|
cNBTList* m_ParentList;
|
|
|
|
cNBTCompound::ENUM_TAG m_Type;
|
|
|
|
VoidList m_List;
|
|
|
|
};
|
|
|
|
|
|
|
|
class cNBTData : public cNBTCompound
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cNBTData( char* a_Buffer, unsigned int a_BufferSize );
|
|
|
|
virtual ~cNBTData();
|
|
|
|
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
void PrintData();
|
|
|
|
|
|
|
|
void ParseData();
|
|
|
|
|
|
|
|
bool OpenCompound( std::string a_Name );
|
|
|
|
bool CloseCompound();
|
|
|
|
|
|
|
|
bool OpenList( std::string a_Name );
|
|
|
|
bool CloseList();
|
|
|
|
|
2011-10-30 02:48:10 -04:00
|
|
|
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 ); }
|
2011-10-30 22:24:44 -04:00
|
|
|
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 ); }
|
2011-10-30 04:04:40 -04:00
|
|
|
void PutByteArray( std::string Name, char* ByteArray ) { m_CurrentCompound->PutByteArray( Name, ByteArray ); }
|
2011-10-30 02:48:10 -04:00
|
|
|
void PutCompound( std::string Name ) { m_CurrentCompound->PutCompound( Name ); }
|
|
|
|
void PutList( std::string Name, ENUM_TAG Type ) { m_CurrentCompound->PutList( Name, Type ); }
|
2011-10-29 17:19:06 -04:00
|
|
|
|
2011-10-29 22:16:01 -04:00
|
|
|
int GetInteger( std::string Name ) { return m_CurrentCompound->GetInteger(Name); }
|
2011-10-30 22:24:44 -04:00
|
|
|
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); }
|
2011-10-29 22:16:01 -04:00
|
|
|
std::string GetString( std::string Name ) { return m_CurrentCompound->GetString(Name); }
|
2011-10-30 04:04:40 -04:00
|
|
|
char* GetByteArray( std::string Name ) { return m_CurrentCompound->GetByteArray(Name); }
|
2011-10-29 22:16:01 -04:00
|
|
|
cNBTCompound* GetCompound( std::string Name ) { return m_CurrentCompound->GetCompound(Name); }
|
|
|
|
cNBTList* GetList( std::string Name ) { return m_CurrentCompound->GetList(Name); }
|
2011-10-29 17:19:06 -04:00
|
|
|
|
|
|
|
char* GetBuffer() { return m_Buffer; }
|
|
|
|
unsigned int GetBufferSize() { return m_BufferSize; }
|
|
|
|
|
|
|
|
void Compress();
|
|
|
|
bool Decompress();
|
|
|
|
|
|
|
|
void Serialize();
|
|
|
|
private:
|
|
|
|
int m_NumUnnamedElements;
|
|
|
|
bool m_bDecompressed;
|
|
|
|
|
|
|
|
void ParseTags();
|
|
|
|
void ParseCompound( bool a_bNamed );
|
|
|
|
void ParseList( bool a_bNamed );
|
|
|
|
void ParseString( bool a_bNamed );
|
|
|
|
void ParseByte( bool a_bNamed );
|
2011-10-29 22:16:01 -04:00
|
|
|
void ParseByteArray( bool a_bNamed );
|
2011-10-29 17:19:06 -04:00
|
|
|
void ParseInt( bool a_bNamed );
|
2011-10-30 03:10:22 -04:00
|
|
|
void ParseLong( bool a_bNamed );
|
2011-10-30 22:24:44 -04:00
|
|
|
void ParseDouble( bool a_bNamed );
|
|
|
|
void ParseFloat( bool a_bNamed );
|
2011-10-29 17:19:06 -04:00
|
|
|
void ParseShort( bool a_bNamed );
|
|
|
|
|
|
|
|
short ReadShort();
|
|
|
|
std::string ReadName();
|
|
|
|
char ReadByte();
|
|
|
|
int ReadInt();
|
2011-10-30 07:41:18 -04:00
|
|
|
long long ReadLong();
|
2011-10-30 22:24:44 -04:00
|
|
|
double ReadDouble();
|
|
|
|
float ReadFloat();
|
2011-10-29 17:19:06 -04:00
|
|
|
|
|
|
|
cNBTCompound* m_CurrentCompound;
|
|
|
|
|
|
|
|
char* m_Buffer;
|
|
|
|
unsigned int m_BufferSize;
|
|
|
|
unsigned int m_Index;
|
2011-10-30 22:24:44 -04:00
|
|
|
bool tm;
|
2011-10-29 17:19:06 -04:00
|
|
|
|
|
|
|
void (cNBTData::*m_ParseFunctions[TAG_NumTags])(bool);
|
|
|
|
};
|