Initial commit: ROW Client source code
Game client codebase including: - CharacterActionControl: Character and creature management - GlobalScript: Network, items, skills, quests, utilities - RYLClient: Main client application with GUI and event handlers - Engine: 3D rendering engine (RYLGL) - MemoryManager: Custom memory allocation - Library: Third-party dependencies (DirectX, boost, etc.) - Tools: Development utilities 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
136
Engine/Zalla3D Base Class/ByteDataObj.cpp
Normal file
136
Engine/Zalla3D Base Class/ByteDataObj.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "./ByteDataObj.h"
|
||||
|
||||
namespace CROSSM {
|
||||
|
||||
const long UINT_SIZE = (long)sizeof(unsigned char);
|
||||
|
||||
CByteDataObj::CByteDataObj(void)
|
||||
{
|
||||
m_pBytes = NULL;
|
||||
m_lSize = 0;
|
||||
m_lReadPos = 0;
|
||||
|
||||
}
|
||||
|
||||
CByteDataObj::~CByteDataObj(void)
|
||||
{
|
||||
if(m_pBytes)
|
||||
{
|
||||
delete[] m_pBytes;
|
||||
m_pBytes = NULL;
|
||||
m_lSize = 0;
|
||||
m_lReadPos = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
unsigned char *CByteDataObj::GetReadPtr()
|
||||
{
|
||||
if((m_lReadPos >= m_lSize) || (m_pBytes == NULL))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &(m_pBytes[m_lReadPos]);
|
||||
|
||||
}
|
||||
bool CByteDataObj::SaveByte(const char *strFileName,long lOffset )
|
||||
{
|
||||
FILE *fp = fopen(strFileName,"wb+");
|
||||
if(!fp)
|
||||
{
|
||||
//CLogMgr::_LogError("CByteDataObj::SaveByte fopen Failed.");
|
||||
return false;
|
||||
}
|
||||
if(lOffset > 0)
|
||||
{
|
||||
fseek(fp,lOffset,SEEK_SET);
|
||||
}
|
||||
if(fwrite((void *)m_pBytes,sizeof(unsigned char) * m_lSize,1,fp) != m_lSize)
|
||||
{
|
||||
//CLogMgr::_LogError("CByteDataObj::SaveByte fwrite Failed.");
|
||||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
fclose(fp);
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
bool CByteDataObj::LoadByte(const char *strFileName,long lOffset)
|
||||
{
|
||||
FILE *fp = fopen(strFileName,"rb");
|
||||
long lFileSize = 0;
|
||||
|
||||
if(fp == NULL)
|
||||
{
|
||||
//CLogMgr::_LogError("CByteDataObj::LoadByte() : %s file not exist\n",strFileName);
|
||||
return false;
|
||||
|
||||
}
|
||||
fseek(fp,0,SEEK_END);
|
||||
m_lSize = ftell(fp);
|
||||
if(m_lSize <= 0)
|
||||
{
|
||||
//CLogMgr::_LogError("CByteDataObj::LoadByte() : %s file size Wrong\n",strFileName);
|
||||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
// Offset <20><><EFBFBD><EFBFBD>
|
||||
if(m_lSize > lOffset)
|
||||
m_lSize -= lOffset;
|
||||
else
|
||||
{
|
||||
//CLogMgr::_LogError("CByteDataObj::LoadByte() : %s File Offset<65><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ѱ踦 <20>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ϴ<EFBFBD>.\n",strFileName);
|
||||
fclose(fp);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
m_pBytes = new unsigned char[m_lSize];
|
||||
if(m_pBytes == NULL)
|
||||
{
|
||||
//CLogMgr::_LogError("CByteDataObj::LoadByte() : File Load Buffer's New Fail.\n");
|
||||
fclose(fp);
|
||||
return false;
|
||||
|
||||
}
|
||||
fseek(fp,lOffset,SEEK_SET);
|
||||
if(fread((unsigned char *)m_pBytes,sizeof(unsigned char),m_lSize,fp) != m_lSize)
|
||||
{
|
||||
//CLogMgr::_LogError("CByteDataObj::LoadByte() : Load File Fail.\n");
|
||||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
fclose(fp);
|
||||
return true;
|
||||
|
||||
}
|
||||
long CByteDataObj::Write(void *ptr,size_t UnitSize,int iNum)
|
||||
{
|
||||
if(ptr == NULL)
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
}
|
||||
long CByteDataObj::Read(void *ptr,size_t UnitSize,int iNum)
|
||||
{
|
||||
if(ptr == NULL)
|
||||
return -1;
|
||||
long lCurrentReaded = ((long)(UnitSize) * iNum) / UINT_SIZE;
|
||||
if(m_lSize >= lCurrentReaded + m_lReadPos)
|
||||
{
|
||||
memcpy(ptr,&(m_pBytes[m_lReadPos]), (size_t)(UINT_SIZE * lCurrentReaded));
|
||||
m_lReadPos += lCurrentReaded;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
|
||||
}
|
||||
return m_lReadPos;
|
||||
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user