Anyone knowledge with reading binary file intro struct?
I got weird error..
The first line is correct but then its only trash..
http://s14.directupload.net/images/141003/nz6k6cd2.jpg
it starts 1,0,450
and then it should be
2,450,1200
3,1200,xxx
and so on.
Load file function:
bool CNtlFileSerializer::LoadFile(char* pszFullPathFileName, bool bCrypt /* = FALSE */, char* szCryptPassword /* = NULL */)
{
if(!pszFullPathFileName)
return false;
FILE *pFile = NULL;
printf("BUFFER BINARY\n");
if (0 != fopen_s(&pFile, pszFullPathFileName, "rb"))
{
return false;
}
long lSize = getFileSize(pFile);
if (0 == lSize)
{
fclose(pFile);
return false;
}
Refresh();
CheckInBuffer(lSize);
printf("BINARY IS NOT CRYPTED \n");
fread((void*)(GetData()), lSize, 1, pFile);
IncrementEndPointer(lSize);
fclose(pFile);
return true;
}
getFileSize function:
long getFileSize(FILE *file)
{
long lCurPos, lEndPos;
lCurPos = ftell(file);
fseek(file, 0, 2);
lEndPos = ftell(file);
fseek(file, lCurPos, 0);
return lEndPos;
}
Refresh function
void CNtlSerializer::Refresh(void)
{
m_iStartPointer = 0;
m_iEndPointer = 0;
}
checkinbuffer function
bool CNtlSerializer::CheckInBuffer(int iSize)
{
if(m_pBuffer == NULL)
return false;
if(0 == iSize)
{
return true;
}
if(m_iCurrSize <= m_iEndPointer + iSize)
{
m_iCurrSize = ((m_iEndPointer + iSize - 1) / m_iGlowSize + 1) * m_iGlowSize;
char *pTemp = new char [m_iCurrSize];
memset(pTemp, 0, m_iCurrSize);
memcpy(pTemp, m_pBuffer, m_iEndPointer);
if(m_pBuffer)
{
delete [] m_pBuffer;
m_pBuffer = NULL;
}
m_pBuffer = pTemp;
}
return true;
}
IncrementEndPointer function:
void CNtlSerializer::IncrementEndPointer(int nSize)
{
if(nSize <= 0)
return;
if(m_iEndPointer + nSize > m_iCurrSize)
{
printf("CNtlSerializer::IncrementEndPointer => overflow");
return;
}
m_iEndPointer += nSize;
}
struct:
#pragma pack(push, 4)
struct sEXP_TBLDAT : public sTBLDAT
{
public:
DWORD dwExp;
DWORD dwNeed_Exp;
public:
virtual int GetDataSize()
{
return sizeof(*this) - sizeof(void*);
}
};
#pragma pack(pop)
#pragma pack(push, 4)
struct sTBLDAT
{
public:
sTBLDAT()
:tblidx(INVALID_TBLIDX) {}
virtual ~sTBLDAT() {}
TBLIDX tblidx;
public:
bool LoadFromBinary(CNtlSerializer& serializer)
{
if (serializer.GetDataSize() < GetDataSize())
{
return false;
}
serializer.Out(GetDataAddress(), GetDataSize());
return true;
}
bool LoadFromChunk(CNtlSerializer& serializer)
{
if (serializer.GetDataSize() < GetDataSize())
{
return false;
}
serializer.Out(GetDataAddress(), GetDataSize());
return true;
}
void SaveToBinary(CNtlSerializer& serializer)
{
serializer.In(GetDataAddress(), GetDataSize());
}
void* GetDataAddress()
{
return (char*)this + sizeof(void*);
}
virtual int GetDataSize()
{
return sizeof(*this) - sizeof(void*);
}
};
#pragma pack(pop)
any idea whats wrong? I hope this is enough info. Just ask if you need something