forked from metin-server/m2dev-client-src
new pack system
This commit is contained in:
@@ -3,7 +3,8 @@ file(GLOB_RECURSE FILE_SOURCES "*.h" "*.c" "*.cpp")
|
||||
add_library(AudioLib STATIC ${FILE_SOURCES})
|
||||
|
||||
target_link_libraries(AudioLib
|
||||
lzo2
|
||||
cryptopp-static
|
||||
mio
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(AudioLib)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "EterBase/Random.h"
|
||||
#include "EterBase/Timer.h"
|
||||
#include "Eterpack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
SoundEngine::SoundEngine()
|
||||
{
|
||||
@@ -246,17 +246,16 @@ bool SoundEngine::Internal_LoadSoundFromPack(const std::string& name)
|
||||
{
|
||||
if (m_Files.find(name) == m_Files.end())
|
||||
{
|
||||
LPCVOID soundData;
|
||||
CMappedFile soundFile;
|
||||
if (!CEterPackManager::Instance().Get(soundFile, name.c_str(), &soundData))
|
||||
TPackFile soundFile;
|
||||
if (!CPackManager::Instance().GetFile(name, soundFile))
|
||||
{
|
||||
TraceError("Internal_LoadSoundFromPack: SoundEngine: Failed to register file '%s' - not found.", name.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& buffer = m_Files[name];
|
||||
buffer.resize(soundFile.Size());
|
||||
memcpy(buffer.data(), soundData, soundFile.Size());
|
||||
buffer.resize(soundFile.size());
|
||||
memcpy(buffer.data(), soundFile.data(), soundFile.size());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ add_subdirectory(EterGrnLib)
|
||||
add_subdirectory(EterImageLib)
|
||||
add_subdirectory(EterLib)
|
||||
add_subdirectory(EterLocale)
|
||||
add_subdirectory(EterPack)
|
||||
add_subdirectory(EterPythonLib)
|
||||
add_subdirectory(GameLib)
|
||||
add_subdirectory(PRTerrainLib)
|
||||
@@ -15,3 +14,4 @@ add_subdirectory(SpeedTreeLib)
|
||||
add_subdirectory(SphereLib)
|
||||
add_subdirectory(UserInterface)
|
||||
add_subdirectory(PackMaker)
|
||||
add_subdirectory(PackLib)
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
add_library(EffectLib STATIC ${FILE_SOURCES})
|
||||
|
||||
target_link_libraries(EffectLib
|
||||
lzo2
|
||||
cryptopp-static
|
||||
mio
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(EffectLib)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "StdAfx.h"
|
||||
#include "Eterlib/StateManager.h"
|
||||
#include "Eterlib/ResourceManager.h"
|
||||
#include "Eterpack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
#include "EffectMesh.h"
|
||||
|
||||
CDynamicPool<CEffectMesh::SEffectMeshData> CEffectMesh::SEffectMeshData::ms_kPool;
|
||||
@@ -192,15 +192,14 @@ BOOL CEffectMesh::__LoadData_Ver002(int iSize, const BYTE * c_pbBuf)
|
||||
|
||||
if (0 == strExtension.compare("ifl"))
|
||||
{
|
||||
LPCVOID pMotionData;
|
||||
CMappedFile File;
|
||||
TPackFile File;
|
||||
|
||||
if (CEterPackManager::Instance().Get(File, pMeshData->szDiffuseMapFileName, &pMotionData))
|
||||
if (CPackManager::Instance().GetFile(pMeshData->szDiffuseMapFileName, File))
|
||||
{
|
||||
CMemoryTextFileLoader textFileLoader;
|
||||
std::vector<std::string> stTokenVector;
|
||||
|
||||
textFileLoader.Bind(File.Size(), pMotionData);
|
||||
textFileLoader.Bind(File.size(), File.data());
|
||||
|
||||
std::string strPathName;
|
||||
GetOnlyPathName(pMeshData->szDiffuseMapFileName, strPathName);
|
||||
@@ -337,15 +336,14 @@ BOOL CEffectMesh::__LoadData_Ver001(int iSize, const BYTE * c_pbBuf)
|
||||
|
||||
if (0 == strExtension.compare("ifl"))
|
||||
{
|
||||
LPCVOID pMotionData;
|
||||
CMappedFile File;
|
||||
TPackFile File;
|
||||
|
||||
if (CEterPackManager::Instance().Get(File, pMeshData->szDiffuseMapFileName, &pMotionData))
|
||||
if (CPackManager::Instance().GetFile(pMeshData->szDiffuseMapFileName, File))
|
||||
{
|
||||
CMemoryTextFileLoader textFileLoader;
|
||||
std::vector<std::string> stTokenVector;
|
||||
|
||||
textFileLoader.Bind(File.Size(), pMotionData);
|
||||
textFileLoader.Bind(File.size(), File.data());
|
||||
|
||||
std::string strPathName;
|
||||
GetOnlyPathName(pMeshData->szDiffuseMapFileName, strPathName);
|
||||
|
||||
@@ -5,6 +5,7 @@ add_library(EterBase STATIC ${FILE_SOURCES})
|
||||
target_link_libraries(EterBase
|
||||
lzo2
|
||||
cryptopp-static
|
||||
mio
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(EterBase)
|
||||
|
||||
@@ -1,259 +0,0 @@
|
||||
#include "StdAfx.h"
|
||||
#include "MappedFile.h"
|
||||
#include "Debug.h"
|
||||
|
||||
CMappedFile::CMappedFile() :
|
||||
m_hFM(NULL),
|
||||
m_lpMapData(NULL),
|
||||
m_dataOffset(0),
|
||||
m_mapSize(0),
|
||||
m_seekPosition(0),
|
||||
m_pLZObj(NULL),
|
||||
m_pbBufLinkData(NULL),
|
||||
m_dwBufLinkSize(0),
|
||||
m_pbAppendResultDataBlock(NULL),
|
||||
m_dwAppendResultDataSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
CMappedFile::~CMappedFile()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
BOOL CMappedFile::Create(const char * filename)
|
||||
{
|
||||
Destroy();
|
||||
return CFileBase::Create(filename, FILEMODE_READ);
|
||||
}
|
||||
|
||||
BOOL CMappedFile::Create(const char * filename, const void** dest, int offset, int size)
|
||||
{
|
||||
if (!CMappedFile::Create(filename))
|
||||
return NULL;
|
||||
|
||||
int ret = Map(dest, offset, size);
|
||||
return (ret) > 0;
|
||||
}
|
||||
|
||||
LPCVOID CMappedFile::Get()
|
||||
{
|
||||
return m_lpData;
|
||||
}
|
||||
|
||||
void CMappedFile::Link(DWORD dwBufSize, const void* c_pvBufData)
|
||||
{
|
||||
m_dwBufLinkSize=dwBufSize;
|
||||
m_pbBufLinkData=(BYTE*)c_pvBufData;
|
||||
}
|
||||
|
||||
void CMappedFile::BindLZObject(CLZObject * pLZObj)
|
||||
{
|
||||
assert(m_pLZObj == NULL);
|
||||
m_pLZObj = pLZObj;
|
||||
|
||||
Link(m_pLZObj->GetSize(), m_pLZObj->GetBuffer());
|
||||
}
|
||||
|
||||
void CMappedFile::BindLZObjectWithBufferedSize(CLZObject * pLZObj)
|
||||
{
|
||||
assert(m_pLZObj == NULL);
|
||||
m_pLZObj = pLZObj;
|
||||
|
||||
Link(m_pLZObj->GetBufferSize(), m_pLZObj->GetBuffer());
|
||||
}
|
||||
|
||||
BYTE* CMappedFile::AppendDataBlock( const void* pBlock, DWORD dwBlockSize )
|
||||
{
|
||||
if( m_pbAppendResultDataBlock )
|
||||
{
|
||||
delete []m_pbAppendResultDataBlock;
|
||||
}
|
||||
|
||||
//realloc
|
||||
m_dwAppendResultDataSize = m_dwBufLinkSize+dwBlockSize;
|
||||
m_pbAppendResultDataBlock = new BYTE[m_dwAppendResultDataSize];
|
||||
|
||||
memcpy(m_pbAppendResultDataBlock, m_pbBufLinkData, m_dwBufLinkSize );
|
||||
memcpy(m_pbAppendResultDataBlock + m_dwBufLinkSize, pBlock, dwBlockSize );
|
||||
|
||||
//redirect
|
||||
Link(m_dwAppendResultDataSize, m_pbAppendResultDataBlock);
|
||||
|
||||
return m_pbAppendResultDataBlock;
|
||||
}
|
||||
|
||||
void CMappedFile::Destroy()
|
||||
{
|
||||
if (m_pLZObj) // 압축된 데이터가 이 포인터로 연결 된다
|
||||
{
|
||||
delete m_pLZObj;
|
||||
m_pLZObj = NULL;
|
||||
}
|
||||
|
||||
if (NULL != m_lpMapData)
|
||||
{
|
||||
Unmap(m_lpMapData);
|
||||
m_lpMapData = NULL;
|
||||
}
|
||||
|
||||
if (NULL != m_hFM)
|
||||
{
|
||||
CloseHandle(m_hFM);
|
||||
m_hFM = NULL;
|
||||
}
|
||||
|
||||
if( m_pbAppendResultDataBlock )
|
||||
{
|
||||
delete []m_pbAppendResultDataBlock;
|
||||
m_pbAppendResultDataBlock = NULL;
|
||||
}
|
||||
|
||||
m_dwAppendResultDataSize = 0;
|
||||
|
||||
m_pbBufLinkData = NULL;
|
||||
m_dwBufLinkSize = 0;
|
||||
|
||||
m_seekPosition = 0;
|
||||
m_dataOffset = 0;
|
||||
m_mapSize = 0;
|
||||
|
||||
CFileBase::Destroy();
|
||||
}
|
||||
|
||||
int CMappedFile::Seek(DWORD offset, int iSeekType)
|
||||
{
|
||||
switch (iSeekType)
|
||||
{
|
||||
case SEEK_TYPE_BEGIN:
|
||||
if (offset > m_dwSize)
|
||||
offset = m_dwSize;
|
||||
|
||||
m_seekPosition = offset;
|
||||
break;
|
||||
|
||||
case SEEK_TYPE_CURRENT:
|
||||
m_seekPosition = std::min(m_seekPosition + offset, Size());
|
||||
break;
|
||||
|
||||
case SEEK_TYPE_END:
|
||||
m_seekPosition = std::max(0ul, Size() - offset);
|
||||
break;
|
||||
}
|
||||
|
||||
return m_seekPosition;
|
||||
}
|
||||
|
||||
// 2004.09.16.myevan.MemoryMappedFile 98/ME 개수 제한 문제 체크
|
||||
//DWORD g_dwCount=0;
|
||||
|
||||
int CMappedFile::Map(const void **dest, int offset, int size)
|
||||
{
|
||||
m_dataOffset = offset;
|
||||
|
||||
if (size == 0)
|
||||
m_mapSize = m_dwSize;
|
||||
else
|
||||
m_mapSize = size;
|
||||
|
||||
if (m_dataOffset + m_mapSize > m_dwSize)
|
||||
return NULL;
|
||||
|
||||
SYSTEM_INFO SysInfo;
|
||||
GetSystemInfo(&SysInfo);
|
||||
DWORD dwSysGran = SysInfo.dwAllocationGranularity;
|
||||
DWORD dwFileMapStart = (m_dataOffset / dwSysGran) * dwSysGran;
|
||||
DWORD dwMapViewSize = (m_dataOffset % dwSysGran) + m_mapSize;
|
||||
INT iViewDelta = m_dataOffset - dwFileMapStart;
|
||||
|
||||
|
||||
m_hFM = CreateFileMapping(m_hFile, // handle
|
||||
NULL, // security
|
||||
PAGE_READONLY, // flProtect
|
||||
0, // high
|
||||
m_dataOffset + m_mapSize, // low
|
||||
NULL); // name
|
||||
|
||||
if (!m_hFM)
|
||||
{
|
||||
OutputDebugString("CMappedFile::Map !m_hFM\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
m_lpMapData = MapViewOfFile(m_hFM,
|
||||
FILE_MAP_READ,
|
||||
0,
|
||||
dwFileMapStart,
|
||||
dwMapViewSize);
|
||||
|
||||
if (!m_lpMapData) // Success
|
||||
{
|
||||
TraceError("CMappedFile::Map !m_lpMapData %lu", GetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 2004.09.16.myevan.MemoryMappedFile 98/ME 개수 제한 문제 체크
|
||||
//g_dwCount++;
|
||||
//Tracenf("MAPFILE %d", g_dwCount);
|
||||
|
||||
m_lpData = (char*) m_lpMapData + iViewDelta;
|
||||
*dest = (char*) m_lpData;
|
||||
m_seekPosition = 0;
|
||||
|
||||
Link(m_mapSize, m_lpData);
|
||||
|
||||
return (m_mapSize);
|
||||
}
|
||||
|
||||
BYTE * CMappedFile::GetCurrentSeekPoint()
|
||||
{
|
||||
return m_pbBufLinkData+m_seekPosition;
|
||||
//return m_pLZObj ? m_pLZObj->GetBuffer() + m_seekPosition : (BYTE *) m_lpData + m_seekPosition;
|
||||
}
|
||||
|
||||
|
||||
DWORD CMappedFile::Size()
|
||||
{
|
||||
return m_dwBufLinkSize;
|
||||
/*
|
||||
if (m_pLZObj)
|
||||
return m_pLZObj->GetSize();
|
||||
|
||||
return (m_mapSize);
|
||||
*/
|
||||
}
|
||||
|
||||
DWORD CMappedFile::GetPosition()
|
||||
{
|
||||
return m_dataOffset;
|
||||
}
|
||||
|
||||
BOOL CMappedFile::Read(void * dest, int bytes)
|
||||
{
|
||||
if (m_seekPosition + bytes > Size())
|
||||
return FALSE;
|
||||
|
||||
memcpy(dest, GetCurrentSeekPoint(), bytes);
|
||||
m_seekPosition += bytes;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
DWORD CMappedFile::GetSeekPosition(void)
|
||||
{
|
||||
return m_seekPosition;
|
||||
}
|
||||
|
||||
void CMappedFile::Unmap(LPCVOID data)
|
||||
{
|
||||
if (UnmapViewOfFile(data))
|
||||
{
|
||||
// 2004.09.16.myevan.MemoryMappedFile 98/ME 개수 제한 문제 체크
|
||||
//g_dwCount--;
|
||||
//Tracenf("UNMAPFILE %d", g_dwCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
TraceError("CMappedFile::Unmap - Error");
|
||||
}
|
||||
m_lpData = NULL;
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
#ifndef __INC_MAPPEDFILE_H__
|
||||
#define __INC_MAPPEDFILE_H__
|
||||
|
||||
#include "lzo.h"
|
||||
#include "FileBase.h"
|
||||
|
||||
class CMappedFile : public CFileBase
|
||||
{
|
||||
public:
|
||||
enum ESeekType
|
||||
{
|
||||
SEEK_TYPE_BEGIN,
|
||||
SEEK_TYPE_CURRENT,
|
||||
SEEK_TYPE_END
|
||||
};
|
||||
|
||||
public:
|
||||
CMappedFile();
|
||||
virtual ~CMappedFile();
|
||||
|
||||
void Link(DWORD dwBufSize, const void* c_pvBufData);
|
||||
|
||||
BOOL Create(const char* filename);
|
||||
BOOL Create(const char* filename, const void** dest, int offset, int size);
|
||||
LPCVOID Get();
|
||||
void Destroy();
|
||||
int Seek(DWORD offset, int iSeekType = SEEK_TYPE_BEGIN);
|
||||
int Map(const void **dest, int offset=0, int size=0);
|
||||
DWORD Size();
|
||||
DWORD GetPosition();
|
||||
BOOL Read(void* dest, int bytes);
|
||||
DWORD GetSeekPosition();
|
||||
void BindLZObject(CLZObject * pLZObj);
|
||||
void BindLZObjectWithBufferedSize(CLZObject * pLZObj);
|
||||
BYTE* AppendDataBlock( const void* pBlock, DWORD dwBlockSize );
|
||||
|
||||
BYTE * GetCurrentSeekPoint();
|
||||
|
||||
private:
|
||||
void Unmap(LPCVOID data);
|
||||
|
||||
private:
|
||||
BYTE* m_pbBufLinkData;
|
||||
DWORD m_dwBufLinkSize;
|
||||
|
||||
BYTE* m_pbAppendResultDataBlock;
|
||||
DWORD m_dwAppendResultDataSize;
|
||||
|
||||
DWORD m_seekPosition;
|
||||
HANDLE m_hFM;
|
||||
DWORD m_dataOffset;
|
||||
DWORD m_mapSize;
|
||||
LPVOID m_lpMapData;
|
||||
LPVOID m_lpData;
|
||||
|
||||
CLZObject * m_pLZObj;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3,7 +3,8 @@
|
||||
add_library(EterGrnLib STATIC ${FILE_SOURCES})
|
||||
|
||||
target_link_libraries(EterGrnLib
|
||||
lzo2
|
||||
cryptopp-static
|
||||
mio
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(EterGrnLib)
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
add_library(EterImageLib STATIC ${FILE_SOURCES})
|
||||
|
||||
target_link_libraries(EterImageLib
|
||||
lzo2
|
||||
cryptopp-static
|
||||
mio
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(EterImageLib)
|
||||
|
||||
@@ -1,364 +0,0 @@
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "EterBase/MappedFile.h"
|
||||
#include "TGAImage.h"
|
||||
|
||||
CTGAImage::CTGAImage() : m_dwFlag(0)
|
||||
{
|
||||
}
|
||||
|
||||
CTGAImage::~CTGAImage()
|
||||
{
|
||||
}
|
||||
|
||||
CTGAImage::CTGAImage(CImage &image) : m_dwFlag(0)
|
||||
{
|
||||
int w = image.GetWidth();
|
||||
int h = image.GetHeight();
|
||||
|
||||
Create(w, h);
|
||||
|
||||
DWORD * pdwDest = GetBasePointer();
|
||||
memcpy(pdwDest, image.GetBasePointer(), w * h * sizeof(DWORD));
|
||||
FlipTopToBottom();
|
||||
}
|
||||
|
||||
void CTGAImage::Create(int width, int height)
|
||||
{
|
||||
memset(&m_Header, 0, sizeof(m_Header));
|
||||
|
||||
m_Header.imgType = 2;
|
||||
m_Header.width = (short) width;
|
||||
m_Header.height = (short) height;
|
||||
m_Header.colorBits = 32;
|
||||
m_Header.desc = 0x08; // alpha channel 있음
|
||||
|
||||
CImage::Create(width, height);
|
||||
}
|
||||
|
||||
bool CTGAImage::LoadFromMemory(int iSize, const BYTE * c_pbMem)
|
||||
{
|
||||
memcpy(&m_Header, c_pbMem, 18);
|
||||
c_pbMem += 18;
|
||||
iSize -= 18;
|
||||
|
||||
CImage::Create(m_Header.width, m_Header.height);
|
||||
|
||||
UINT hxw = m_Header.width * m_Header.height;
|
||||
BYTE r, g, b, a;
|
||||
DWORD i;
|
||||
|
||||
DWORD * pdwDest = GetBasePointer();
|
||||
|
||||
switch (m_Header.imgType)
|
||||
{
|
||||
case 3: // 알파만 있는 것 (1bytes per pixel, 거의 안쓰임)
|
||||
{
|
||||
for (i = 0; i < hxw; ++i)
|
||||
{
|
||||
a = (char) *(c_pbMem++);
|
||||
pdwDest[i] = (a << 24) | (a << 16) | (a << 8) | a;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 2: // 압축 안된 TGA
|
||||
{
|
||||
if (m_Header.colorBits == 16) // 16bit
|
||||
{
|
||||
for (i = 0; i < hxw; ++i)
|
||||
{
|
||||
WORD w;
|
||||
|
||||
memcpy(&w, c_pbMem, sizeof(WORD));
|
||||
c_pbMem += sizeof(WORD);
|
||||
iSize -= sizeof(WORD);
|
||||
|
||||
b = (BYTE) (w & 0x1F);
|
||||
g = (BYTE) ((w >> 5) & 0x1F);
|
||||
r = (BYTE) ((w >> 10) & 0x1F);
|
||||
|
||||
b <<= 3;
|
||||
g <<= 3;
|
||||
r <<= 3;
|
||||
a = 0xff;
|
||||
|
||||
pdwDest[i] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
}
|
||||
else if (m_Header.colorBits == 24) // 24bit
|
||||
{
|
||||
for (i = 0; i < hxw; ++i)
|
||||
{
|
||||
r = (BYTE) *(c_pbMem++); --iSize;
|
||||
g = (BYTE) *(c_pbMem++); --iSize;
|
||||
b = (BYTE) *(c_pbMem++); --iSize;
|
||||
a = 0xff;
|
||||
|
||||
pdwDest[i] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
}
|
||||
else if (m_Header.colorBits == 32) // 32bit
|
||||
{
|
||||
int size = GetWidth();
|
||||
size *= GetHeight() * 4;
|
||||
|
||||
memcpy(pdwDest, c_pbMem, size);
|
||||
c_pbMem += size;
|
||||
iSize -= size;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 10: // 압축 된 TGA (RLE)
|
||||
{
|
||||
BYTE rle;
|
||||
|
||||
if (m_Header.colorBits == 24)
|
||||
{
|
||||
i = 0;
|
||||
while (i < hxw)
|
||||
{
|
||||
rle = (BYTE) *(c_pbMem++); --iSize;
|
||||
|
||||
if (rle < 0x80) // 압축 안된 곳
|
||||
{
|
||||
rle++;
|
||||
|
||||
while (rle)
|
||||
{
|
||||
b = (BYTE) *(c_pbMem++); --iSize;
|
||||
g = (BYTE) *(c_pbMem++); --iSize;
|
||||
r = (BYTE) *(c_pbMem++); --iSize;
|
||||
a = 0xff;
|
||||
pdwDest[i++] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
|
||||
if (i > hxw)
|
||||
{
|
||||
assert(!"RLE overflow");
|
||||
printf("RLE overflow");
|
||||
return false;
|
||||
}
|
||||
--rle;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 압축 된 곳
|
||||
rle -= 127;
|
||||
|
||||
b = (BYTE) *(c_pbMem++); --iSize;
|
||||
g = (BYTE) *(c_pbMem++); --iSize;
|
||||
r = (BYTE) *(c_pbMem++); --iSize;
|
||||
a = 0xff;
|
||||
|
||||
while (rle)
|
||||
{
|
||||
pdwDest[i++] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
|
||||
if (i > hxw)
|
||||
{
|
||||
assert(!"RLE overflow");
|
||||
printf("RLE overflow");
|
||||
return false;
|
||||
}
|
||||
--rle;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_Header.colorBits == 32)
|
||||
{
|
||||
i = 0;
|
||||
while (i < hxw)
|
||||
{
|
||||
rle = (BYTE) *(c_pbMem++); --iSize;
|
||||
|
||||
if (rle < 0x80)
|
||||
{
|
||||
rle++;
|
||||
|
||||
while (rle)
|
||||
{
|
||||
b = (BYTE) *(c_pbMem++); --iSize;
|
||||
g = (BYTE) *(c_pbMem++); --iSize;
|
||||
r = (BYTE) *(c_pbMem++); --iSize;
|
||||
a = (BYTE) *(c_pbMem++); --iSize;
|
||||
pdwDest[i++] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
|
||||
if (i > hxw)
|
||||
{
|
||||
assert(!"RLE overflow");
|
||||
printf("RLE overflow");
|
||||
return false;
|
||||
}
|
||||
--rle;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rle -= 127;
|
||||
|
||||
b = (BYTE) *(c_pbMem++); --iSize;
|
||||
g = (BYTE) *(c_pbMem++); --iSize;
|
||||
r = (BYTE) *(c_pbMem++); --iSize;
|
||||
a = (BYTE) *(c_pbMem++); --iSize;
|
||||
|
||||
while (rle)
|
||||
{
|
||||
pdwDest[i++] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
|
||||
if (i > hxw)
|
||||
{
|
||||
assert(!"RLE overflow");
|
||||
printf("RLE overflow");
|
||||
return false;
|
||||
}
|
||||
|
||||
--rle;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(m_Header.desc & 0x20))
|
||||
{
|
||||
FlipTopToBottom();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CTGAImage::LoadFromDiskFile(const char * c_szFileName)
|
||||
{
|
||||
CMappedFile file;
|
||||
|
||||
const BYTE * c_pbMap;
|
||||
|
||||
if (!file.Create(c_szFileName, (const void **) &c_pbMap, 0, 0))
|
||||
return false;
|
||||
|
||||
return LoadFromMemory(file.Size(), c_pbMap);
|
||||
}
|
||||
|
||||
int CTGAImage::GetRLEPixelCount(const DWORD * data)
|
||||
{
|
||||
int r = 0;
|
||||
DWORD pixel;
|
||||
|
||||
r = 1;
|
||||
|
||||
if (data >= m_pdwEndPtr)
|
||||
return 0;
|
||||
|
||||
pixel = *data;
|
||||
|
||||
while ((r < 127) && (data < m_pdwEndPtr))
|
||||
{
|
||||
if (pixel != *(++data))
|
||||
return r;
|
||||
|
||||
r++;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int CTGAImage::GetRawPixelCount(const DWORD * data)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if (data >= m_pdwEndPtr)
|
||||
return 0;
|
||||
|
||||
while ((data < m_pdwEndPtr) && (i < 127))
|
||||
{
|
||||
int rle = GetRLEPixelCount(data);
|
||||
|
||||
if (rle >= 4)
|
||||
break;
|
||||
|
||||
data++;
|
||||
i++;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void CTGAImage::SetCompressed(bool isCompress)
|
||||
{
|
||||
if (isCompress)
|
||||
m_Header.imgType = 10;
|
||||
else
|
||||
m_Header.imgType = 2;
|
||||
}
|
||||
|
||||
void CTGAImage::SetAlphaChannel(bool isExist)
|
||||
{
|
||||
if (isExist)
|
||||
m_Header.desc |= 0x08;
|
||||
else
|
||||
m_Header.desc &= ~0x08;
|
||||
}
|
||||
|
||||
bool CTGAImage::SaveToDiskFile(const char* c_szFileName)
|
||||
{
|
||||
FILE * fp = fopen(c_szFileName, "wb");
|
||||
|
||||
if (!fp)
|
||||
return false;
|
||||
|
||||
fwrite(&m_Header, 18, 1, fp);
|
||||
|
||||
if (m_Header.imgType == 10) // RLE 압축으로 저장
|
||||
{
|
||||
DWORD * data = GetBasePointer();
|
||||
|
||||
while (data < m_pdwEndPtr)
|
||||
{
|
||||
int rle = GetRLEPixelCount(data);
|
||||
|
||||
if (rle < 4)
|
||||
{
|
||||
int raw = GetRawPixelCount(data);
|
||||
|
||||
if (raw == 0)
|
||||
break;
|
||||
|
||||
fputc(raw - 1, fp);
|
||||
|
||||
while (raw)
|
||||
{
|
||||
fwrite(data, sizeof(DWORD), 1, fp);
|
||||
data++;
|
||||
raw--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fputc((rle - 1) | 0x80, fp);
|
||||
fwrite(data, sizeof(DWORD), 1, fp);
|
||||
data += rle;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int size = GetWidth();
|
||||
size *= GetHeight() * 4;
|
||||
fwrite(GetBasePointer(), size, 1, fp);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
TGA_HEADER & CTGAImage::GetHeader()
|
||||
{
|
||||
return m_Header;
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
#ifndef __INC_ETERIMAGELIB_TGAIMAGE_H__
|
||||
#define __INC_ETERIMAGELIB_TGAIMAGE_H__
|
||||
|
||||
#include "Image.h"
|
||||
|
||||
class CTGAImage : public CImage
|
||||
{
|
||||
public:
|
||||
enum ETGAImageFlags
|
||||
{
|
||||
FLAG_RLE_COMPRESS = (1 << 0)
|
||||
};
|
||||
|
||||
CTGAImage();
|
||||
CTGAImage(CImage &image);
|
||||
virtual ~CTGAImage();
|
||||
|
||||
virtual void Create(int width, int height);
|
||||
virtual bool LoadFromMemory(int iSize, const BYTE * c_pbMem);
|
||||
virtual bool LoadFromDiskFile(const char * c_szFileName);
|
||||
virtual bool SaveToDiskFile(const char* c_szFileName);
|
||||
|
||||
void SetCompressed(bool isCompress = true);
|
||||
void SetAlphaChannel(bool isExist = true);
|
||||
|
||||
TGA_HEADER & GetHeader();
|
||||
protected:
|
||||
int GetRawPixelCount(const DWORD * data);
|
||||
int GetRLEPixelCount(const DWORD * data);
|
||||
|
||||
protected:
|
||||
TGA_HEADER m_Header;
|
||||
DWORD m_dwFlag;
|
||||
DWORD * m_pdwEndPtr;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3,8 +3,8 @@
|
||||
add_library(EterLib STATIC ${FILE_SOURCES})
|
||||
|
||||
target_link_libraries(EterLib
|
||||
lzo2
|
||||
cryptopp-static
|
||||
mio
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(EterLib)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "StdAfx.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "EterBase/Stl.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
#include "FileLoaderThread.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
@@ -115,8 +116,7 @@ void CFileLoaderThread::Request(std::string & c_rstFileName) // called in main t
|
||||
{
|
||||
TData * pData = new TData;
|
||||
|
||||
pData->dwSize = 0;
|
||||
pData->pvBuf = NULL;
|
||||
pData->File.clear();
|
||||
pData->stFileName = c_rstFileName;
|
||||
|
||||
m_RequestMutex.Lock();
|
||||
@@ -163,14 +163,7 @@ void CFileLoaderThread::Process() // called in loader thread
|
||||
|
||||
m_RequestMutex.Unlock();
|
||||
|
||||
LPCVOID pvBuf;
|
||||
|
||||
if (CEterPackManager::Instance().Get(pData->File, pData->stFileName.c_str(), &pvBuf))
|
||||
{
|
||||
pData->dwSize = pData->File.Size();
|
||||
pData->pvBuf = new char [pData->dwSize];
|
||||
memcpy(pData->pvBuf, pvBuf, pData->dwSize);
|
||||
}
|
||||
CPackManager::instance().GetFile(pData->stFileName, pData->File);
|
||||
|
||||
m_CompleteMutex.Lock();
|
||||
m_pCompleteDeque.push_back(pData);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <deque>
|
||||
#include "Thread.h"
|
||||
#include "Mutex.h"
|
||||
#include "EterBase/MappedFile.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
class CFileLoaderThread
|
||||
{
|
||||
@@ -12,10 +12,7 @@ class CFileLoaderThread
|
||||
typedef struct SData
|
||||
{
|
||||
std::string stFileName;
|
||||
|
||||
CMappedFile File;
|
||||
LPVOID pvBuf;
|
||||
DWORD dwSize;
|
||||
TPackFile File;
|
||||
} TData;
|
||||
|
||||
public:
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "StdAfx.h"
|
||||
#include "EterBase/MappedFile.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
#include "GrpImageTexture.h"
|
||||
#include "EterImageLib/DDSTextureLoader9.h"
|
||||
|
||||
@@ -53,13 +52,11 @@ bool CGraphicImageTexture::CreateDeviceObjects()
|
||||
}
|
||||
else
|
||||
{
|
||||
CMappedFile mappedFile;
|
||||
LPCVOID c_pvMap;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(mappedFile, m_stFileName.c_str(), &c_pvMap))
|
||||
TPackFile mappedFile;
|
||||
if (!CPackManager::Instance().GetFile(m_stFileName, mappedFile))
|
||||
return false;
|
||||
|
||||
return CreateFromMemoryFile(mappedFile.Size(), c_pvMap, m_d3dFmt, m_dwFilter);
|
||||
return CreateFromMemoryFile(mappedFile.size(), mappedFile.data(), m_d3dFmt, m_dwFilter);
|
||||
}
|
||||
|
||||
m_bEmpty = false;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "StdAfx.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
#include "EterBase/Stl.h"
|
||||
#include "EterBase/CRC32.h"
|
||||
#include "EterBase/Timer.h"
|
||||
|
||||
@@ -43,17 +44,16 @@ void CResource::Load()
|
||||
const char * c_szFileName = GetFileName();
|
||||
|
||||
DWORD dwStart = ELTimer_GetMSec();
|
||||
CMappedFile file;
|
||||
LPCVOID fileData;
|
||||
TPackFile file;
|
||||
|
||||
//Tracenf("Load %s", c_szFileName);
|
||||
|
||||
if (CEterPackManager::Instance().Get(file, c_szFileName, &fileData))
|
||||
if (CPackManager::Instance().GetFile(c_szFileName, file))
|
||||
{
|
||||
m_dwLoadCostMiliiSecond = ELTimer_GetMSec() - dwStart;
|
||||
//Tracef("CResource::Load %s (%d bytes) in %d ms\n", c_szFileName, file.Size(), m_dwLoadCostMiliiSecond);
|
||||
|
||||
if (OnLoad(file.Size(), fileData))
|
||||
if (OnLoad(file.size(), file.data()))
|
||||
{
|
||||
me_state = STATE_EXIST;
|
||||
}
|
||||
@@ -81,12 +81,10 @@ void CResource::Reload()
|
||||
Clear();
|
||||
Tracef("CResource::Reload %s\n", GetFileName());
|
||||
|
||||
CMappedFile file;
|
||||
LPCVOID fileData;
|
||||
|
||||
if (CEterPackManager::Instance().Get(file, GetFileName(), &fileData))
|
||||
TPackFile file;
|
||||
if (CPackManager::Instance().GetFile(GetFileName(), file))
|
||||
{
|
||||
if (OnLoad(file.Size(), fileData))
|
||||
if (OnLoad(file.size(), file.data()))
|
||||
{
|
||||
me_state = STATE_EXIST;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "EterBase/CRC32.h"
|
||||
#include "EterBase/Timer.h"
|
||||
#include "EterBase/Stl.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
#include "ResourceManager.h"
|
||||
#include "GrpImage.h"
|
||||
@@ -71,7 +71,7 @@ void CResourceManager::ProcessBackgroundLoading()
|
||||
{
|
||||
if (pResource->IsEmpty())
|
||||
{
|
||||
pResource->OnLoad(pData->dwSize, pData->pvBuf);
|
||||
pResource->OnLoad(pData->File.size(), pData->File.data());
|
||||
pResource->AddReferenceOnly();
|
||||
|
||||
// 여기서 올라간 레퍼런스 카운트를 일정 시간이 지난 뒤에 풀어주기 위하여
|
||||
@@ -81,7 +81,6 @@ void CResourceManager::ProcessBackgroundLoading()
|
||||
|
||||
m_WaitingMap.erase(GetCRC32(pData->stFileName.c_str(), pData->stFileName.size()));
|
||||
|
||||
delete [] ((char *) pData->pvBuf);
|
||||
delete pData;
|
||||
}
|
||||
|
||||
@@ -472,7 +471,7 @@ void CResourceManager::DumpFileListToTextFile(const char* c_szFileName)
|
||||
|
||||
bool CResourceManager::IsFileExist(const char * c_szFileName)
|
||||
{
|
||||
return CEterPackManager::Instance().isExist(c_szFileName);
|
||||
return CPackManager::Instance().IsExist(c_szFileName);
|
||||
}
|
||||
|
||||
void CResourceManager::Update()
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
#include "StdAfx.h"
|
||||
#include "TargaResource.h"
|
||||
|
||||
CTargaResource::CTargaResource(const char * c_pszFileName) : CResource(c_pszFileName)
|
||||
{
|
||||
}
|
||||
|
||||
CTargaResource::~CTargaResource()
|
||||
{
|
||||
}
|
||||
|
||||
CTargaResource::TType CTargaResource::Type()
|
||||
{
|
||||
static TType s_type = StringToType("CTargaResource");
|
||||
return s_type;
|
||||
}
|
||||
|
||||
bool CTargaResource::OnIsType(TType type)
|
||||
{
|
||||
if (CTargaResource::Type() == type)
|
||||
return true;
|
||||
|
||||
return CResource::OnIsType(type);
|
||||
}
|
||||
|
||||
bool CTargaResource::OnLoad(int iSize, const void * c_pvBuf)
|
||||
{
|
||||
return image.LoadFromMemory(iSize, static_cast<const BYTE *>(c_pvBuf));
|
||||
}
|
||||
|
||||
void CTargaResource::OnClear()
|
||||
{
|
||||
image.Clear();
|
||||
}
|
||||
|
||||
bool CTargaResource::OnIsEmpty() const
|
||||
{
|
||||
return image.IsEmpty();
|
||||
}
|
||||
|
||||
void CTargaResource::GetRect(DWORD & w, DWORD & h)
|
||||
{
|
||||
w = image.GetWidth();
|
||||
h = image.GetHeight();
|
||||
}
|
||||
|
||||
DWORD * CTargaResource::GetMemPtr()
|
||||
{
|
||||
return image.GetBasePointer();
|
||||
}
|
||||
|
||||
TGA_HEADER & CTargaResource::GetTgaHeader()
|
||||
{
|
||||
return image.GetHeader();
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Ref.h"
|
||||
#include "Resource.h"
|
||||
#include "EterImageLib/TGAImage.h"
|
||||
|
||||
class CTargaResource : public CResource
|
||||
{
|
||||
public:
|
||||
typedef CRef<CTargaResource> TRef;
|
||||
|
||||
public:
|
||||
static TType Type();
|
||||
|
||||
public:
|
||||
CTargaResource(const char * c_pszFileName);
|
||||
virtual ~CTargaResource();
|
||||
|
||||
DWORD * GetMemPtr();
|
||||
void GetRect(DWORD & w, DWORD & h);
|
||||
|
||||
TGA_HEADER & GetTgaHeader();
|
||||
|
||||
protected:
|
||||
virtual bool OnLoad(int iSize, const void * c_pvBuf);
|
||||
virtual void OnClear();
|
||||
virtual bool OnIsEmpty() const;
|
||||
virtual bool OnIsType(TType type);
|
||||
|
||||
protected:
|
||||
CTGAImage image;
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "StdAfx.h"
|
||||
#include "EterBase/CRC32.h"
|
||||
#include <string>
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
#include "Pool.h"
|
||||
#include "TextFileLoader.h"
|
||||
@@ -179,14 +179,13 @@ bool CTextFileLoader::Load(const char * c_szFileName)
|
||||
{
|
||||
m_strFileName = "";
|
||||
|
||||
const VOID* pvData;
|
||||
CMappedFile kFile;
|
||||
if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData))
|
||||
TPackFile kFile;
|
||||
if (!CPackManager::Instance().GetFile( c_szFileName, kFile))
|
||||
return false;
|
||||
|
||||
if (m_dwBufCapacity<kFile.Size())
|
||||
if (m_dwBufCapacity<kFile.size())
|
||||
{
|
||||
m_dwBufCapacity=kFile.Size();
|
||||
m_dwBufCapacity=kFile.size();
|
||||
|
||||
if (m_acBufData)
|
||||
delete [] m_acBufData;
|
||||
@@ -194,8 +193,8 @@ bool CTextFileLoader::Load(const char * c_szFileName)
|
||||
m_acBufData=new char[m_dwBufCapacity];
|
||||
}
|
||||
|
||||
m_dwBufSize=kFile.Size();
|
||||
memcpy(m_acBufData, pvData, m_dwBufSize);
|
||||
m_dwBufSize=kFile.size();
|
||||
memcpy(m_acBufData, kFile.data(), m_dwBufSize);
|
||||
|
||||
m_strFileName = c_szFileName;
|
||||
m_dwcurLineIndex = 0;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define __INC_METIN_II_TEXTFILELOADER_H__
|
||||
|
||||
#include "EterBase/FileLoader.h"
|
||||
#include "EterBase/MappedFile.h"
|
||||
#include "EterLib/Util.h"
|
||||
#include "EterLib/Pool.h"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "StdAfx.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
|
||||
#include "TextFileLoader.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
void PrintfTabs(FILE * File, int iTabCount, const char * c_szString, ...)
|
||||
{
|
||||
@@ -20,16 +19,15 @@ void PrintfTabs(FILE * File, int iTabCount, const char * c_szString, ...)
|
||||
|
||||
bool LoadTextData(const char * c_szFileName, CTokenMap & rstTokenMap)
|
||||
{
|
||||
LPCVOID pMotionData;
|
||||
CMappedFile File;
|
||||
TPackFile File;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(File, c_szFileName, &pMotionData))
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, File))
|
||||
return false;
|
||||
|
||||
CMemoryTextFileLoader textFileLoader;
|
||||
CTokenVector stTokenVector;
|
||||
|
||||
textFileLoader.Bind(File.Size(), pMotionData);
|
||||
textFileLoader.Bind(File.size(), File.data());
|
||||
|
||||
for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i)
|
||||
{
|
||||
@@ -50,10 +48,9 @@ bool LoadTextData(const char * c_szFileName, CTokenMap & rstTokenMap)
|
||||
|
||||
bool LoadMultipleTextData(const char * c_szFileName, CTokenVectorMap & rstTokenVectorMap)
|
||||
{
|
||||
LPCVOID pModelData;
|
||||
CMappedFile File;
|
||||
TPackFile File;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(File, c_szFileName, &pModelData))
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, File))
|
||||
return false;
|
||||
|
||||
DWORD i;
|
||||
@@ -61,7 +58,7 @@ bool LoadMultipleTextData(const char * c_szFileName, CTokenVectorMap & rstTokenV
|
||||
CMemoryTextFileLoader textFileLoader;
|
||||
CTokenVector stTokenVector;
|
||||
|
||||
textFileLoader.Bind(File.Size(), pModelData);
|
||||
textFileLoader.Bind(File.size(), File.data());
|
||||
|
||||
for (i = 0; i < textFileLoader.GetLineCount(); ++i)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
add_library(EterLocale STATIC ${FILE_SOURCES})
|
||||
|
||||
# target_link_libraries(EterLocale
|
||||
# )
|
||||
target_link_libraries(EterLocale
|
||||
cryptopp-static
|
||||
mio
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(EterLocale)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
file(GLOB_RECURSE FILE_SOURCES "*.h" "*.c" "*.cpp")
|
||||
|
||||
add_library(EterPack STATIC ${FILE_SOURCES})
|
||||
|
||||
target_link_libraries(EterPack
|
||||
lzo2
|
||||
cryptopp-static
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(EterPack)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,245 +0,0 @@
|
||||
#ifndef __INC_ETERPACKLIB_ETERPACK_H__
|
||||
#define __INC_ETERPACKLIB_ETERPACK_H__
|
||||
|
||||
#ifndef MAKEFOURCC
|
||||
#include <mmsyscom.h>
|
||||
#endif
|
||||
|
||||
#include <list>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "EterBase/MappedFile.h"
|
||||
|
||||
//#define CHECKSUM_CHECK_MD5
|
||||
#include "md5.h"
|
||||
|
||||
|
||||
namespace eterpack
|
||||
{
|
||||
const DWORD c_PackCC = MAKEFOURCC('E', 'P', 'K', 'D');
|
||||
const DWORD c_IndexCC = MAKEFOURCC('E', 'P', 'K', 'D');
|
||||
const DWORD c_Version = 2;
|
||||
// FourCC + Version + m_indexCount
|
||||
const DWORD c_HeaderSize = sizeof(DWORD) + sizeof(DWORD) + sizeof(long);
|
||||
};
|
||||
|
||||
enum EEterPackTypes
|
||||
{
|
||||
DBNAME_MAX_LEN = 255,
|
||||
FILENAME_MAX_LEN = 160,
|
||||
FREE_INDEX_BLOCK_SIZE = 32768,
|
||||
FREE_INDEX_MAX_SIZE = 512,
|
||||
DATA_BLOCK_SIZE = 256,
|
||||
|
||||
COMPRESSED_TYPE_NONE = 0,
|
||||
COMPRESSED_TYPE_COMPRESS = 1,
|
||||
COMPRESSED_TYPE_SECURITY = 2,
|
||||
COMPRESSED_TYPE_PANAMA = 3,
|
||||
COMPRESSED_TYPE_HYBRIDCRYPT = 4,
|
||||
COMPRESSED_TYPE_HYBRIDCRYPT_WITHSDB = 5,
|
||||
COMPRESSED_TYPE_COUNT = 6,
|
||||
};
|
||||
|
||||
#pragma pack(push, 4)
|
||||
typedef struct SEterPackIndex
|
||||
{
|
||||
long id;
|
||||
char filename[FILENAME_MAX_LEN + 1];
|
||||
DWORD filename_crc;
|
||||
long real_data_size;
|
||||
long data_size;
|
||||
#ifdef CHECKSUM_CHECK_MD5
|
||||
BYTE MD5Digest[16];
|
||||
#else
|
||||
DWORD data_crc;
|
||||
#endif
|
||||
long data_position;
|
||||
char compressed_type;
|
||||
} TEterPackIndex;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef std::unordered_map<DWORD, TEterPackIndex *> TDataPositionMap;
|
||||
typedef std::list<TEterPackIndex *> TFreeIndexList;
|
||||
|
||||
|
||||
class CEterPack;
|
||||
|
||||
class CEterFileDict
|
||||
{
|
||||
public:
|
||||
struct Item
|
||||
{
|
||||
Item() : pkPack(NULL), pkInfo(NULL) {}
|
||||
|
||||
CEterPack* pkPack;
|
||||
TEterPackIndex* pkInfo;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
BUCKET_SIZE = 16,
|
||||
};
|
||||
|
||||
typedef std::unordered_multimap<DWORD, Item> TDict;
|
||||
|
||||
public:
|
||||
void InsertItem(CEterPack* pkPack, TEterPackIndex* pkInfo);
|
||||
void UpdateItem(CEterPack* pkPack, TEterPackIndex* pkInfo);
|
||||
|
||||
Item* GetItem(DWORD dwFileNameHash, const char* c_pszFileName);
|
||||
|
||||
const TDict& GetDict() const
|
||||
{
|
||||
return m_dict;
|
||||
}
|
||||
|
||||
private:
|
||||
TDict m_dict;
|
||||
};
|
||||
|
||||
class EterPackPolicy_CSHybridCrypt;
|
||||
|
||||
class CEterPack
|
||||
{
|
||||
public:
|
||||
CEterPack();
|
||||
virtual ~CEterPack();
|
||||
|
||||
void Destroy();
|
||||
bool Create(CEterFileDict& rkFileDict, const char * dbname, const char * pathName, bool bReadOnly = true, const BYTE* iv = NULL);
|
||||
bool DecryptIV(DWORD dwPanamaKey);
|
||||
|
||||
const std::string& GetPathName();
|
||||
const char * GetDBName();
|
||||
|
||||
//THEMIDA
|
||||
bool Get(CMappedFile & mappedFile, const char * filename, LPCVOID * data);
|
||||
//THEMIDA
|
||||
bool Get2(CMappedFile & mappedFile, const char * filename, TEterPackIndex* index, LPCVOID * data);
|
||||
|
||||
|
||||
//THEMIDA
|
||||
bool Put(const char * filename, const char * sourceFilename, BYTE packType, const std::string& strRelateMapName);
|
||||
//THEMIDA
|
||||
bool Put(const char * filename, LPCVOID data, long len, BYTE packType);
|
||||
|
||||
bool Delete(const char * filename);
|
||||
|
||||
bool Extract();
|
||||
|
||||
long GetFragmentSize();
|
||||
|
||||
bool IsExist(const char * filename);
|
||||
|
||||
TDataPositionMap & GetIndexMap();
|
||||
|
||||
bool EncryptIndexFile();
|
||||
bool DecryptIndexFile();
|
||||
|
||||
DWORD DeleteUnreferencedData(); // 몇개가 삭제 되었는지 리턴 한다.
|
||||
|
||||
bool GetNames(std::vector<std::string>* retNames);
|
||||
|
||||
EterPackPolicy_CSHybridCrypt* GetPackPolicy_HybridCrypt() const;
|
||||
|
||||
private:
|
||||
bool __BuildIndex(CEterFileDict& rkFileDict, bool bOverwirte=false);
|
||||
|
||||
bool CreateIndexFile();
|
||||
TEterPackIndex * FindIndex(const char * filename);
|
||||
long GetNewIndexPosition(CFileBase& file);
|
||||
TEterPackIndex * NewIndex(CFileBase& file, const char * filename, long size);
|
||||
void WriteIndex(CFileBase& file, TEterPackIndex * index);
|
||||
int GetFreeBlockIndex(long size);
|
||||
void PushFreeIndex(TEterPackIndex * index);
|
||||
|
||||
bool CreateDataFile();
|
||||
long GetNewDataPosition(CFileBase& file);
|
||||
bool ReadData(CFileBase& file, TEterPackIndex * index, LPVOID data, long maxsize);
|
||||
bool WriteData(CFileBase& file, TEterPackIndex * index, LPCVOID data);
|
||||
bool WriteNewData(CFileBase& file, TEterPackIndex * index, LPCVOID data);
|
||||
|
||||
bool Delete(TEterPackIndex * pIndex);
|
||||
|
||||
protected:
|
||||
CMappedFile m_file;
|
||||
|
||||
char* m_file_data;
|
||||
unsigned m_file_size;
|
||||
|
||||
long m_indexCount;
|
||||
bool m_bEncrypted;
|
||||
|
||||
char m_dbName[DBNAME_MAX_LEN+1];
|
||||
char m_indexFileName[MAX_PATH+1];
|
||||
TEterPackIndex * m_indexData;
|
||||
long m_FragmentSize;
|
||||
bool m_bReadOnly;
|
||||
bool m_bDecrypedIV;
|
||||
|
||||
std::unordered_map<DWORD, DWORD> m_map_indexRefCount;
|
||||
TDataPositionMap m_DataPositionMap;
|
||||
TFreeIndexList m_FreeIndexList[FREE_INDEX_MAX_SIZE + 1]; // MAX 도 억세스 하므로 + 1 크기만큼 만든다.
|
||||
|
||||
std::string m_stDataFileName;
|
||||
std::string m_stPathName;
|
||||
|
||||
|
||||
EterPackPolicy_CSHybridCrypt* m_pCSHybridCryptPolicy;
|
||||
|
||||
private:
|
||||
void __CreateFileNameKey_Panama(const char * filename, BYTE * key, unsigned int keySize);
|
||||
bool __Decrypt_Panama(const char* filename, const BYTE* data, SIZE_T dataSize, CLZObject& zObj);
|
||||
bool __Encrypt_Panama(const char* filename, const BYTE* data, SIZE_T dataSize, CLZObject& zObj);
|
||||
std::string m_stIV_Panama;
|
||||
|
||||
//private:
|
||||
// bool m_bIsDataLoaded;
|
||||
// // 그냥 time_t를 쓰면, 32bit time_t를 사용하는 소스에서는,
|
||||
// // CEterPack의 size를 실제 size - 4로 인식하기 때문에 문제가 발생할 수 있다.
|
||||
// __time64_t m_tLastAccessTime;
|
||||
//public:
|
||||
// __time64_t GetLastAccessTime() { return m_tLastAccessTime; }
|
||||
// void UpdateLastAccessTime();
|
||||
// void ClearDataMemoryMap();
|
||||
|
||||
#ifdef CHECKSUM_CHECK_MD5
|
||||
void GenerateMD5Hash( BYTE* pData, int nLength, IN OUT MD5_CTX& context );
|
||||
#endif
|
||||
};
|
||||
|
||||
class CMakePackLog
|
||||
{
|
||||
public:
|
||||
static CMakePackLog& GetSingleton();
|
||||
|
||||
public:
|
||||
CMakePackLog();
|
||||
~CMakePackLog();
|
||||
|
||||
void SetFileName(const char* c_szFileName);
|
||||
|
||||
void Writef(const char* c_szFormat, ...);
|
||||
void Writenf(const char* c_szFormat, ...);
|
||||
void Write(const char* c_szBuf);
|
||||
|
||||
void WriteErrorf(const char* c_szFormat, ...);
|
||||
void WriteErrornf(const char* c_szFormat, ...);
|
||||
void WriteError(const char* c_szBuf);
|
||||
|
||||
void FlushError();
|
||||
|
||||
private:
|
||||
void __Write(const char* c_szBuf, int nBufLen);
|
||||
void __WriteError(const char* c_szBuf, int nBufLen);
|
||||
bool __IsLogMode();
|
||||
|
||||
private:
|
||||
FILE* m_fp;
|
||||
FILE* m_fp_err;
|
||||
|
||||
std::string m_stFileName;
|
||||
std::string m_stErrorFileName;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,59 +0,0 @@
|
||||
#include "StdAfx.h"
|
||||
#include "EterPackCursor.h"
|
||||
#include "Inline.h"
|
||||
|
||||
CEterPackCursor::CEterPackCursor(CEterPack* pack) : m_pPack(pack), m_pData(NULL), m_ReadPoint(0)
|
||||
{
|
||||
}
|
||||
|
||||
CEterPackCursor::~CEterPackCursor()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
bool CEterPackCursor::Open(const char* filename)
|
||||
{
|
||||
assert(m_pPack != NULL);
|
||||
|
||||
char tmpFilename[MAX_PATH + 1];
|
||||
strncpy(tmpFilename, filename, MAX_PATH);
|
||||
inlineConvertPackFilename(tmpFilename);
|
||||
|
||||
if (!m_pPack->Get(m_file, tmpFilename, &m_pData))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CEterPackCursor::Close()
|
||||
{
|
||||
m_file.Destroy();
|
||||
m_pData = NULL;
|
||||
m_ReadPoint = 0;
|
||||
}
|
||||
|
||||
void CEterPackCursor::Seek(long offset)
|
||||
{
|
||||
m_ReadPoint = std::max(0l, std::min(Size(), offset));
|
||||
}
|
||||
|
||||
bool CEterPackCursor::Read(LPVOID data, long size)
|
||||
{
|
||||
if (m_file.IsNull())
|
||||
return false;
|
||||
|
||||
if (m_ReadPoint + size > Size())
|
||||
return false;
|
||||
|
||||
memcpy(data, (char*) m_pData + m_ReadPoint, size);
|
||||
m_ReadPoint += size;
|
||||
return true;
|
||||
}
|
||||
|
||||
long CEterPackCursor::Size()
|
||||
{
|
||||
if (m_file.IsNull())
|
||||
return 0;
|
||||
|
||||
return m_file.Size();
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef __INC_ETERPACKCURSOR_H__
|
||||
#define __INC_ETERPACKCURSOR_H__
|
||||
|
||||
#include "EterPack.h"
|
||||
|
||||
class CEterPackCursor
|
||||
{
|
||||
public:
|
||||
CEterPackCursor(CEterPack * pack);
|
||||
~CEterPackCursor();
|
||||
|
||||
bool Open(const char* filename);
|
||||
void Close();
|
||||
void Seek(long offset);
|
||||
bool Read(LPVOID data, long size);
|
||||
long Size();
|
||||
|
||||
private:
|
||||
CEterPack * m_pPack;
|
||||
CMappedFile m_file;
|
||||
LPCVOID m_pData;
|
||||
long m_ReadPoint;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,621 +0,0 @@
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include <io.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "EterPackManager.h"
|
||||
#include "EterPackPolicy_CSHybridCrypt.h"
|
||||
|
||||
#include "EterBase/Debug.h"
|
||||
#include "EterBase/CRC32.h"
|
||||
|
||||
#define PATH_ABSOLUTE_YMIRWORK1 "d:/ymir work/"
|
||||
#define PATH_ABSOLUTE_YMIRWORK2 "d:\\ymir work\\"
|
||||
|
||||
#ifdef __THEMIDA__
|
||||
#include <ThemidaSDK.h>
|
||||
#endif
|
||||
|
||||
|
||||
CEterPack* CEterPackManager::FindPack(const char* c_szPathName)
|
||||
{
|
||||
std::string strFileName;
|
||||
|
||||
if (0 == ConvertFileName(c_szPathName, strFileName))
|
||||
{
|
||||
return &m_RootPack;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (TEterPackMap::iterator itor = m_DirPackMap.begin(); itor != m_DirPackMap.end(); ++itor)
|
||||
{
|
||||
const std::string & c_rstrName = itor->first;
|
||||
CEterPack * pEterPack = itor->second;
|
||||
|
||||
if (CompareName(c_rstrName.c_str(), c_rstrName.length(), strFileName.c_str()))
|
||||
{
|
||||
return pEterPack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CEterPackManager::SetCacheMode()
|
||||
{
|
||||
m_isCacheMode=true;
|
||||
}
|
||||
|
||||
void CEterPackManager::SetRelativePathMode()
|
||||
{
|
||||
m_bTryRelativePath = true;
|
||||
}
|
||||
|
||||
|
||||
// StringPath std::string 버전
|
||||
int CEterPackManager::ConvertFileName(const char * c_szFileName, std::string & rstrFileName)
|
||||
{
|
||||
rstrFileName = c_szFileName;
|
||||
stl_lowers(rstrFileName);
|
||||
|
||||
int iCount = 0;
|
||||
|
||||
for (DWORD i = 0; i < rstrFileName.length(); ++i)
|
||||
{
|
||||
if (rstrFileName[i] == '/')
|
||||
++iCount;
|
||||
else if (rstrFileName[i] == '\\')
|
||||
{
|
||||
rstrFileName[i] = '/';
|
||||
++iCount;
|
||||
}
|
||||
}
|
||||
|
||||
return iCount;
|
||||
}
|
||||
|
||||
bool CEterPackManager::CompareName(const char * c_szDirectoryName, DWORD /*dwLength*/, const char * c_szFileName)
|
||||
{
|
||||
const char * c_pszSrc = c_szDirectoryName;
|
||||
const char * c_pszCmp = c_szFileName;
|
||||
|
||||
while (*c_pszSrc)
|
||||
{
|
||||
if (*(c_pszSrc++) != *(c_pszCmp++))
|
||||
return false;
|
||||
|
||||
if (!*c_pszCmp)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CEterPackManager::LoadStaticCache(const char* c_szFileName)
|
||||
{
|
||||
if (!m_isCacheMode)
|
||||
return;
|
||||
|
||||
std::string strFileName;
|
||||
if (0 == ConvertFileName(c_szFileName, strFileName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD dwFileNameHash = GetCRC32(strFileName.c_str(), strFileName.length());
|
||||
|
||||
std::unordered_map<DWORD, SCache>::iterator f = m_kMap_dwNameKey_kCache.find(dwFileNameHash);
|
||||
if (m_kMap_dwNameKey_kCache.end() != f)
|
||||
return;
|
||||
|
||||
CMappedFile kMapFile;
|
||||
const void* c_pvData;
|
||||
if (!Get(kMapFile, c_szFileName, &c_pvData))
|
||||
return;
|
||||
|
||||
SCache kNewCache;
|
||||
kNewCache.m_dwBufSize = kMapFile.Size();
|
||||
kNewCache.m_abBufData = new BYTE[kNewCache.m_dwBufSize];
|
||||
memcpy(kNewCache.m_abBufData, c_pvData, kNewCache.m_dwBufSize);
|
||||
m_kMap_dwNameKey_kCache.insert(std::unordered_map<DWORD, SCache>::value_type(dwFileNameHash, kNewCache));
|
||||
}
|
||||
|
||||
CEterPackManager::SCache* CEterPackManager::__FindCache(DWORD dwFileNameHash)
|
||||
{
|
||||
std::unordered_map<DWORD, SCache>::iterator f=m_kMap_dwNameKey_kCache.find(dwFileNameHash);
|
||||
if (m_kMap_dwNameKey_kCache.end()==f)
|
||||
return NULL;
|
||||
|
||||
return &f->second;
|
||||
}
|
||||
|
||||
void CEterPackManager::__ClearCacheMap()
|
||||
{
|
||||
std::unordered_map<DWORD, SCache>::iterator i;
|
||||
|
||||
for (i = m_kMap_dwNameKey_kCache.begin(); i != m_kMap_dwNameKey_kCache.end(); ++i)
|
||||
delete [] i->second.m_abBufData;
|
||||
|
||||
m_kMap_dwNameKey_kCache.clear();
|
||||
}
|
||||
|
||||
struct TimeChecker
|
||||
{
|
||||
TimeChecker(const char* name) : name(name)
|
||||
{
|
||||
baseTime = timeGetTime();
|
||||
}
|
||||
~TimeChecker()
|
||||
{
|
||||
printf("load %s (%d)\n", name, timeGetTime() - baseTime);
|
||||
}
|
||||
|
||||
const char* name;
|
||||
DWORD baseTime;
|
||||
};
|
||||
|
||||
bool CEterPackManager::Get(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData)
|
||||
{
|
||||
//TimeChecker timeChecker(c_szFileName);
|
||||
//Logf(1, "Load %s\n", c_szFileName);
|
||||
|
||||
if (m_iSearchMode == SEARCH_FILE_FIRST)
|
||||
{
|
||||
if (GetFromFile(rMappedFile, c_szFileName, pData))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return GetFromPack(rMappedFile, c_szFileName, pData);
|
||||
}
|
||||
|
||||
if (GetFromPack(rMappedFile, c_szFileName, pData))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return GetFromFile(rMappedFile, c_szFileName, pData);
|
||||
}
|
||||
|
||||
struct FinderLock
|
||||
{
|
||||
FinderLock(CRITICAL_SECTION& cs) : p_cs(&cs)
|
||||
{
|
||||
EnterCriticalSection(p_cs);
|
||||
}
|
||||
|
||||
~FinderLock()
|
||||
{
|
||||
LeaveCriticalSection(p_cs);
|
||||
}
|
||||
|
||||
CRITICAL_SECTION* p_cs;
|
||||
};
|
||||
|
||||
bool CEterPackManager::GetFromPack(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData)
|
||||
{
|
||||
FinderLock lock(m_csFinder);
|
||||
|
||||
static std::string strFileName;
|
||||
|
||||
if (0 == ConvertFileName(c_szFileName, strFileName))
|
||||
{
|
||||
return m_RootPack.Get(rMappedFile, strFileName.c_str(), pData);
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD dwFileNameHash = GetCRC32(strFileName.c_str(), strFileName.length());
|
||||
SCache* pkCache = __FindCache(dwFileNameHash);
|
||||
|
||||
if (pkCache)
|
||||
{
|
||||
rMappedFile.Link(pkCache->m_dwBufSize, pkCache->m_abBufData);
|
||||
return true;
|
||||
}
|
||||
|
||||
CEterFileDict::Item* pkFileItem = m_FileDict.GetItem(dwFileNameHash, strFileName.c_str());
|
||||
|
||||
if (pkFileItem)
|
||||
if (pkFileItem->pkPack)
|
||||
{
|
||||
bool r = pkFileItem->pkPack->Get2(rMappedFile, strFileName.c_str(), pkFileItem->pkInfo, pData);
|
||||
//pkFileItem->pkPack->ClearDataMemoryMap();
|
||||
return r;
|
||||
}
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
TraceError("CANNOT_FIND_PACK_FILE [%s]", strFileName.c_str());
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const time_t g_tCachingInterval = 10; // 10초
|
||||
void CEterPackManager::ArrangeMemoryMappedPack()
|
||||
{
|
||||
//time_t curTime = time(NULL);
|
||||
//CEterFileDict::TDict dict = m_FileDict.GetDict();
|
||||
//for (CEterFileDict::TDict::iterator it = dict.begin(); it != dict.end(); ++it)
|
||||
//{
|
||||
// CEterFileDict::Item &rFileItem = it->second;
|
||||
// CEterPack* pkPack = rFileItem.pkPack;
|
||||
// if (pkPack)
|
||||
// {
|
||||
// if (curTime - pkPack->GetLastAccessTime() > g_tCachingInterval)
|
||||
// {
|
||||
// pkPack->ClearDataMemoryMap();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
bool CEterPackManager::GetFromFile(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData)
|
||||
{
|
||||
#ifndef _DEBUG
|
||||
//const char *pcExt = strchr(c_szFileName, '.');
|
||||
//if (pcExt &&
|
||||
// _strnicmp(pcExt, ".py", 3) == 0 && // python 스크립트 중
|
||||
// stricmp(c_szFileName, "logininfo.py") != 0 && // 로그인 정보 파일이 아니고
|
||||
// strnicmp(c_szFileName, "locale", 6) != 0
|
||||
// )
|
||||
//{
|
||||
// return false;
|
||||
//}
|
||||
#endif
|
||||
|
||||
//if(m_bTryRelativePath) {
|
||||
// if (strnicmp(c_szFileName, PATH_ABSOLUTE_YMIRWORK1, strlen(PATH_ABSOLUTE_YMIRWORK1)) == 0 || strnicmp(c_szFileName, PATH_ABSOLUTE_YMIRWORK2, strlen(PATH_ABSOLUTE_YMIRWORK2)) == 0) {
|
||||
// if(rMappedFile.Create(c_szFileName+strlen(PATH_ABSOLUTE_YMIRWORK1), pData, 0, 0))
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
return rMappedFile.Create(c_szFileName, pData, 0, 0) ? true : false;
|
||||
}
|
||||
|
||||
bool CEterPackManager::isExistInPack(const char * c_szFileName)
|
||||
{
|
||||
std::string strFileName;
|
||||
|
||||
if (0 == ConvertFileName(c_szFileName, strFileName))
|
||||
{
|
||||
return m_RootPack.IsExist(strFileName.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD dwFileNameHash = GetCRC32(strFileName.c_str(), strFileName.length());
|
||||
CEterFileDict::Item* pkFileItem = m_FileDict.GetItem(dwFileNameHash, strFileName.c_str());
|
||||
|
||||
if (pkFileItem)
|
||||
if (pkFileItem->pkPack)
|
||||
return pkFileItem->pkPack->IsExist(strFileName.c_str());
|
||||
}
|
||||
|
||||
// NOTE : 매치 되는 팩이 없다면 false - [levites]
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CEterPackManager::isExist(const char * c_szFileName)
|
||||
{
|
||||
if (m_iSearchMode == SEARCH_PACK_FIRST)
|
||||
{
|
||||
if (isExistInPack(c_szFileName))
|
||||
return true;
|
||||
|
||||
return _access(c_szFileName, 0) == 0 ? true : false;
|
||||
}
|
||||
|
||||
//if(m_bTryRelativePath) {
|
||||
// if (strnicmp(c_szFileName, PATH_ABSOLUTE_YMIRWORK1, strlen(PATH_ABSOLUTE_YMIRWORK1)) == 0 || strnicmp(c_szFileName, PATH_ABSOLUTE_YMIRWORK2, strlen(PATH_ABSOLUTE_YMIRWORK2)) == 0) {
|
||||
// if(access(c_szFileName+strlen(PATH_ABSOLUTE_YMIRWORK1), 0) == 0)
|
||||
// return true;
|
||||
// }
|
||||
//}
|
||||
|
||||
if (_access(c_szFileName, 0) == 0)
|
||||
return true;
|
||||
|
||||
return isExistInPack(c_szFileName);
|
||||
}
|
||||
|
||||
|
||||
void CEterPackManager::RegisterRootPack(const char * c_szName)
|
||||
{
|
||||
if (!m_RootPack.Create(m_FileDict, c_szName, ""))
|
||||
{
|
||||
TraceError("%s: Pack file does not exist", c_szName);
|
||||
}
|
||||
}
|
||||
|
||||
const char * CEterPackManager::GetRootPackFileName()
|
||||
{
|
||||
return m_RootPack.GetDBName();
|
||||
}
|
||||
|
||||
bool CEterPackManager::DecryptPackIV(DWORD dwPanamaKey)
|
||||
{
|
||||
TEterPackMap::iterator itor = m_PackMap.begin();
|
||||
while (itor != m_PackMap.end())
|
||||
{
|
||||
itor->second->DecryptIV(dwPanamaKey);
|
||||
itor++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CEterPackManager::RegisterPackWhenPackMaking(const char * c_szName, const char * c_szDirectory, CEterPack* pPack)
|
||||
{
|
||||
m_PackMap.insert(TEterPackMap::value_type(c_szName, pPack));
|
||||
m_PackList.push_front(pPack);
|
||||
|
||||
m_DirPackMap.insert(TEterPackMap::value_type(c_szDirectory, pPack));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CEterPackManager::RegisterPack(const char * c_szName, const char * c_szDirectory, const BYTE* c_pbIV)
|
||||
{
|
||||
CEterPack * pEterPack = NULL;
|
||||
{
|
||||
TEterPackMap::iterator itor = m_PackMap.find(c_szName);
|
||||
|
||||
if (m_PackMap.end() == itor)
|
||||
{
|
||||
bool bReadOnly = true;
|
||||
|
||||
pEterPack = new CEterPack;
|
||||
if (pEterPack->Create(m_FileDict, c_szName, c_szDirectory, bReadOnly, c_pbIV))
|
||||
{
|
||||
m_PackMap.insert(TEterPackMap::value_type(c_szName, pEterPack));
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
Tracef("The eterpack doesn't exist [%s]\n", c_szName);
|
||||
#endif
|
||||
delete pEterPack;
|
||||
pEterPack = NULL;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pEterPack = itor->second;
|
||||
}
|
||||
}
|
||||
|
||||
if (c_szDirectory && c_szDirectory[0] != '*')
|
||||
{
|
||||
TEterPackMap::iterator itor = m_DirPackMap.find(c_szDirectory);
|
||||
if (m_DirPackMap.end() == itor)
|
||||
{
|
||||
m_PackList.push_front(pEterPack);
|
||||
m_DirPackMap.insert(TEterPackMap::value_type(c_szDirectory, pEterPack));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CEterPackManager::SetSearchMode(bool bPackFirst)
|
||||
{
|
||||
m_iSearchMode = bPackFirst ? SEARCH_PACK_FIRST : SEARCH_FILE_FIRST;
|
||||
}
|
||||
|
||||
int CEterPackManager::GetSearchMode()
|
||||
{
|
||||
return m_iSearchMode;
|
||||
}
|
||||
|
||||
CEterPackManager::CEterPackManager() : m_bTryRelativePath(false), m_iSearchMode(SEARCH_FILE_FIRST), m_isCacheMode(false)
|
||||
{
|
||||
InitializeCriticalSection(&m_csFinder);
|
||||
}
|
||||
|
||||
CEterPackManager::~CEterPackManager()
|
||||
{
|
||||
__ClearCacheMap();
|
||||
|
||||
TEterPackMap::iterator i = m_PackMap.begin();
|
||||
TEterPackMap::iterator e = m_PackMap.end();
|
||||
while (i != e)
|
||||
{
|
||||
delete i->second;
|
||||
i++;
|
||||
}
|
||||
DeleteCriticalSection(&m_csFinder);
|
||||
}
|
||||
|
||||
void CEterPackManager::RetrieveHybridCryptPackKeys(const BYTE *pStream)
|
||||
{
|
||||
////dump file format
|
||||
//total packagecnt (4byte)
|
||||
// for packagecntpackage
|
||||
// db name hash ( stl.h stringhash )
|
||||
// extension cnt( 4byte)
|
||||
// for extension cnt
|
||||
// ext hash ( stl.h stringhash )
|
||||
// key-16byte
|
||||
// iv-16byte
|
||||
int iMemOffset = 0;
|
||||
|
||||
int iPackageCnt;
|
||||
DWORD dwPackageNameHash;
|
||||
|
||||
memcpy( &iPackageCnt, pStream + iMemOffset, sizeof(int) );
|
||||
iMemOffset += sizeof(iPackageCnt);
|
||||
|
||||
for( int i = 0; i < iPackageCnt; ++i )
|
||||
{
|
||||
int iRecvedCryptKeySize = 0;
|
||||
memcpy( &iRecvedCryptKeySize, pStream + iMemOffset, sizeof(iRecvedCryptKeySize) );
|
||||
iRecvedCryptKeySize -= sizeof(dwPackageNameHash); // 서버에서 받은 key stream에는 filename hash가 포함되어 있으므로, hash 사이즈 만큼 배줌.
|
||||
iMemOffset += sizeof(iRecvedCryptKeySize);
|
||||
|
||||
memcpy( &dwPackageNameHash, pStream + iMemOffset, sizeof(dwPackageNameHash) );
|
||||
iMemOffset += sizeof(dwPackageNameHash);
|
||||
|
||||
TEterPackMap::const_iterator cit;
|
||||
for( cit = m_PackMap.begin(); cit != m_PackMap.end(); ++cit )
|
||||
{
|
||||
auto ssvv = std::string(cit->first);
|
||||
std::string noPathName = CFileNameHelper::NoPath(ssvv);
|
||||
if( dwPackageNameHash == stringhash().GetHash(noPathName) )
|
||||
{
|
||||
EterPackPolicy_CSHybridCrypt* pCryptPolicy = cit->second->GetPackPolicy_HybridCrypt();
|
||||
int iHavedCryptKeySize = pCryptPolicy->ReadCryptKeyInfoFromStream( pStream + iMemOffset );
|
||||
if (iRecvedCryptKeySize != iHavedCryptKeySize)
|
||||
{
|
||||
TraceError("CEterPackManager::RetrieveHybridCryptPackKeys cryptokey length of file(%s) is not matched. received(%d) != haved(%d)", noPathName.c_str(), iRecvedCryptKeySize, iHavedCryptKeySize);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
iMemOffset += iRecvedCryptKeySize;
|
||||
}
|
||||
}
|
||||
|
||||
void CEterPackManager::RetrieveHybridCryptPackSDB( const BYTE* pStream )
|
||||
{
|
||||
//cnt
|
||||
//for cnt
|
||||
//DWORD dwPackageIdentifier;
|
||||
//DWORD dwFileIdentifier;
|
||||
//std::vector<BYTE> vecSDBStream;
|
||||
int iReadOffset = 0;
|
||||
int iSDBInfoCount = 0;
|
||||
|
||||
memcpy( &iSDBInfoCount, pStream+iReadOffset, sizeof(int) );
|
||||
iReadOffset += sizeof(int);
|
||||
|
||||
for( int i = 0; i < iSDBInfoCount; ++i )
|
||||
{
|
||||
DWORD dwPackgeIdentifier;
|
||||
memcpy( &dwPackgeIdentifier, pStream+iReadOffset, sizeof(DWORD) );
|
||||
iReadOffset += sizeof(DWORD);
|
||||
|
||||
TEterPackMap::const_iterator cit;
|
||||
for( cit = m_PackMap.begin(); cit != m_PackMap.end(); ++cit )
|
||||
{
|
||||
auto ssvv = std::string(cit->first);
|
||||
std::string noPathName = CFileNameHelper::NoPath(ssvv);
|
||||
if( dwPackgeIdentifier == stringhash().GetHash(noPathName) )
|
||||
{
|
||||
EterPackPolicy_CSHybridCrypt* pCryptPolicy = cit->second->GetPackPolicy_HybridCrypt();
|
||||
iReadOffset += pCryptPolicy->ReadSupplementatyDataBlockFromStream( pStream+iReadOffset );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CEterPackManager::WriteHybridCryptPackInfo(const char* pFileName)
|
||||
{
|
||||
//NOTE : this file format contains a little bit of redundant data.
|
||||
//however it`s better for seperating cryptkey & supplementary data block.
|
||||
|
||||
//dump file format
|
||||
|
||||
//SDB data offset(4)
|
||||
|
||||
// about cryptkey
|
||||
//total packagecnt (4byte)
|
||||
// for packagecnt
|
||||
// db name hash 4byte( stl.h stringhash )
|
||||
// extension cnt( 4byte)
|
||||
// for extension cnt
|
||||
// ext hash ( stl.h stringhash )
|
||||
// key-16byte
|
||||
// iv-16byte
|
||||
|
||||
//about SDB data
|
||||
//total packagecnt (4byte)
|
||||
// for packagecnt
|
||||
// db name hash 4byte( stl.h stringhash ) +child node size(4byte)
|
||||
// sdb file cnt( 4byte )
|
||||
// for sdb file cnt
|
||||
// filename hash ( stl.h stringhash )
|
||||
// related map name size(4), relate map name
|
||||
// sdb block size( 1byte )
|
||||
// sdb blocks
|
||||
|
||||
CFileBase keyFile;
|
||||
|
||||
if( !keyFile.Create( pFileName, CFileBase::FILEMODE_WRITE) )
|
||||
{
|
||||
//TODO : write log
|
||||
return;
|
||||
}
|
||||
|
||||
int iKeyPackageCount = 0;
|
||||
|
||||
//write later ( SDB Offset & PackageCnt for Key )
|
||||
keyFile.SeekCur(2*sizeof(int));
|
||||
|
||||
TEterPackMap::const_iterator cit;
|
||||
for( cit = m_PackMap.begin(); cit != m_PackMap.end(); ++cit )
|
||||
{
|
||||
EterPackPolicy_CSHybridCrypt* pPolicy = cit->second->GetPackPolicy_HybridCrypt();
|
||||
if( !pPolicy || !pPolicy->IsContainingCryptKey() )
|
||||
continue;
|
||||
|
||||
iKeyPackageCount++;
|
||||
auto ssvv = std::string(cit->first);
|
||||
std::string noPathName = CFileNameHelper::NoPath(ssvv);
|
||||
|
||||
DWORD dwPackNamehash = stringhash().GetHash(noPathName);
|
||||
|
||||
CMakePackLog::GetSingleton().Writef("CEterPackManager::WriteHybridCryptPackInfo PackName : %s, Hash : %x", noPathName.c_str(), dwPackNamehash);
|
||||
keyFile.Write( &dwPackNamehash, sizeof(DWORD) );
|
||||
|
||||
pPolicy->WriteCryptKeyToFile( keyFile );
|
||||
}
|
||||
|
||||
//Write SDB Data
|
||||
int iSDBDataOffset = keyFile.GetPosition();
|
||||
int iSDBPackageCnt = 0;
|
||||
|
||||
//Write SDB PackageCnt Later
|
||||
keyFile.SeekCur(sizeof(int));
|
||||
for( cit = m_PackMap.begin(); cit != m_PackMap.end(); ++cit )
|
||||
{
|
||||
EterPackPolicy_CSHybridCrypt* pPolicy = cit->second->GetPackPolicy_HybridCrypt();
|
||||
if( !pPolicy || !pPolicy->IsContainingSDBFile() )
|
||||
continue;
|
||||
|
||||
iSDBPackageCnt++;
|
||||
|
||||
auto ssvv1 = std::string(cit->first);
|
||||
auto noPathName = CFileNameHelper::NoPath(ssvv1);
|
||||
|
||||
DWORD dwPackNamehash = stringhash().GetHash(noPathName);
|
||||
keyFile.Write( &dwPackNamehash, sizeof(DWORD) );
|
||||
|
||||
int iSDBSizeWriteOffset = keyFile.GetPosition();
|
||||
keyFile.SeekCur(sizeof(int));
|
||||
|
||||
pPolicy->WriteSupplementaryDataBlockToFile( keyFile );
|
||||
int iSDBSizeAfterWrite = keyFile.GetPosition();
|
||||
|
||||
keyFile.Seek(iSDBSizeWriteOffset);
|
||||
|
||||
int iSDBSize = iSDBSizeAfterWrite-(iSDBSizeWriteOffset+4);
|
||||
keyFile.Write( &iSDBSize, sizeof(int) );
|
||||
|
||||
keyFile.Seek(iSDBSizeAfterWrite);
|
||||
}
|
||||
|
||||
//write sdb data start offset & package cnt
|
||||
keyFile.Seek(0);
|
||||
keyFile.Write( &iSDBDataOffset, sizeof(int));
|
||||
keyFile.Write( &iKeyPackageCount, sizeof(int));
|
||||
|
||||
keyFile.Seek(iSDBDataOffset);
|
||||
keyFile.Write( &iSDBPackageCnt, sizeof(int));
|
||||
|
||||
keyFile.Close();
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <unordered_map>
|
||||
#include "EterBase/Singleton.h"
|
||||
#include "EterBase/Stl.h"
|
||||
|
||||
#include "EterPack.h"
|
||||
|
||||
class CEterPackManager : public CSingleton<CEterPackManager>
|
||||
{
|
||||
public:
|
||||
struct SCache
|
||||
{
|
||||
BYTE* m_abBufData;
|
||||
DWORD m_dwBufSize;
|
||||
};
|
||||
public:
|
||||
enum ESearchModes
|
||||
{
|
||||
SEARCH_FILE_FIRST,
|
||||
SEARCH_PACK_FIRST
|
||||
};
|
||||
|
||||
typedef std::list<CEterPack*> TEterPackList;
|
||||
typedef std::unordered_map<std::string, CEterPack*, stringhash> TEterPackMap;
|
||||
|
||||
public:
|
||||
CEterPackManager();
|
||||
virtual ~CEterPackManager();
|
||||
|
||||
void SetCacheMode();
|
||||
void SetRelativePathMode();
|
||||
|
||||
void LoadStaticCache(const char* c_szFileName);
|
||||
|
||||
void SetSearchMode(bool bPackFirst);
|
||||
int GetSearchMode();
|
||||
|
||||
//THEMIDA
|
||||
bool Get(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData);
|
||||
|
||||
//THEMIDA
|
||||
bool GetFromPack(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData);
|
||||
|
||||
//THEMIDA
|
||||
bool GetFromFile(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData);
|
||||
bool isExist(const char * c_szFileName);
|
||||
bool isExistInPack(const char * c_szFileName);
|
||||
|
||||
bool RegisterPack(const char * c_szName, const char * c_szDirectory, const BYTE* c_pbIV = NULL);
|
||||
void RegisterRootPack(const char * c_szName);
|
||||
bool RegisterPackWhenPackMaking(const char * c_szName, const char * c_szDirectory, CEterPack* pPack);
|
||||
|
||||
|
||||
bool DecryptPackIV(DWORD key);
|
||||
|
||||
const char * GetRootPackFileName();
|
||||
|
||||
//for hybridcrypt
|
||||
//THEMIDA
|
||||
void WriteHybridCryptPackInfo(const char* pFileName);
|
||||
|
||||
//THEMIDA
|
||||
void RetrieveHybridCryptPackKeys( const BYTE* pStream );
|
||||
//THEMIDA
|
||||
void RetrieveHybridCryptPackSDB( const BYTE* pStream );
|
||||
|
||||
// 메모리에 매핑된 팩들 가운데, 정리해야할 것들 정리.
|
||||
public:
|
||||
void ArrangeMemoryMappedPack();
|
||||
|
||||
protected:
|
||||
int ConvertFileName(const char * c_szFileName, std::string & rstrFileName); // StringPath std::string 버전
|
||||
bool CompareName(const char * c_szDirectoryName, DWORD iLength, const char * c_szFileName);
|
||||
|
||||
CEterPack* FindPack(const char* c_szPathName);
|
||||
|
||||
SCache* __FindCache(DWORD dwFileNameHash);
|
||||
void __ClearCacheMap();
|
||||
|
||||
protected:
|
||||
bool m_bTryRelativePath;
|
||||
bool m_isCacheMode;
|
||||
int m_iSearchMode;
|
||||
|
||||
CEterFileDict m_FileDict;
|
||||
CEterPack m_RootPack;
|
||||
TEterPackList m_PackList;
|
||||
TEterPackMap m_PackMap;
|
||||
TEterPackMap m_DirPackMap;
|
||||
|
||||
std::unordered_map<DWORD, SCache> m_kMap_dwNameKey_kCache;
|
||||
|
||||
CRITICAL_SECTION m_csFinder;
|
||||
};
|
||||
@@ -1,503 +0,0 @@
|
||||
#include "Stdafx.h"
|
||||
#include "EterPackPolicy_CSHybridCrypt.h"
|
||||
#include "EterBase/Stl.h"
|
||||
#include "EterBase/FileName.h"
|
||||
#include "EterBase/FileBase.h"
|
||||
#include "EterBase/Crc32.h"
|
||||
#include "EterBase/lzo.h"
|
||||
#include "EterBase/Random.h"
|
||||
#include <modes.h>
|
||||
#include <osrng.h>
|
||||
|
||||
using namespace CryptoPP;
|
||||
|
||||
#define CIPHER_MODE CTR_Mode
|
||||
|
||||
#ifdef __THEMIDA__
|
||||
#include <ThemidaSDK.h>
|
||||
#endif
|
||||
//Cipher
|
||||
//Block Size
|
||||
//Key Length
|
||||
//
|
||||
//Default Minimum Maximum
|
||||
//AES(Rijndael) 16 16 16 32
|
||||
//Blowfish 8 16 0 56
|
||||
//Camellia 16 16 16 32
|
||||
//CAST-128 8 16 5 16
|
||||
//CAST-256 16 16 16 32
|
||||
//DES 8 8 8 8
|
||||
//DES-EDE2 8 16 16 16
|
||||
//DES-EDE3 8 24 24 24
|
||||
//DES-XEX3 8 24 24 24
|
||||
//GOST 8 32 32 32
|
||||
//IDEA 8 16 16 16
|
||||
//MARS 16 16 16 56
|
||||
//RC2 8 16 1 128
|
||||
//RC5 8 16 0 255
|
||||
//RC6 16 16 0 255
|
||||
//SAFER-K 8 16 8 16
|
||||
//SAFER-SK 8 16 8 16
|
||||
//Serpent 16 16 1 32
|
||||
//SHACAL-2 32 16 1 64
|
||||
//SHARK-E 8 16 1 16
|
||||
//SKIPJACK 8 10 1 10
|
||||
//3-Way 12 12 1 12
|
||||
//Twofish 16 16 0 32
|
||||
//XTEA 8 16 1 16
|
||||
|
||||
inline std::string GetFileExt( std::string& rfileName )
|
||||
{
|
||||
stl_lowers(rfileName);
|
||||
return CFileNameHelper::GetExtension(rfileName);
|
||||
}
|
||||
|
||||
EterPackPolicy_CSHybridCrypt::~EterPackPolicy_CSHybridCrypt()
|
||||
{
|
||||
m_mapHybridCryptKey.clear();
|
||||
m_mapSDBMap.clear();
|
||||
}
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::IsContainingCryptKey() const
|
||||
{
|
||||
return (m_mapHybridCryptKey.size() > 0) ? true : false;
|
||||
}
|
||||
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::GenerateCryptKey( std::string& rfileName )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
//make lower & extract ext
|
||||
std::string extName = GetFileExt(rfileName);
|
||||
stl_lowers(extName);
|
||||
|
||||
DWORD dwExtHash = stringhash().GetHash(extName);
|
||||
|
||||
TCSHybridCryptKeyMap::const_iterator cit = m_mapHybridCryptKey.find( dwExtHash );
|
||||
|
||||
if( cit != m_mapHybridCryptKey.end() )
|
||||
{
|
||||
//TODO : log already registered
|
||||
return false;
|
||||
}
|
||||
|
||||
static AutoSeededRandomPool rnd;
|
||||
|
||||
TCSHybridCryptKey info;
|
||||
{
|
||||
rnd.GenerateBlock( &(info.uEncryptKey.key[0]), sizeof(info.uEncryptKey) );
|
||||
rnd.GenerateBlock( &(info.uEncryptIV.iv[0]), sizeof(info.uEncryptIV) );
|
||||
|
||||
//for test
|
||||
/* memset( &info.uEncryptKey.key, 0x10, sizeof(info.uEncryptKey) );
|
||||
memset( &info.uEncryptIV.iv, 0x10, sizeof(info.uEncryptIV) ); */
|
||||
}
|
||||
m_mapHybridCryptKey[dwExtHash] = info;
|
||||
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::GetPerFileCryptKey( std::string& rfileName, eHybridCipherAlgorithm& eAlgorithm, TEncryptKey& key, TEncryptIV& iv )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
std::string fileNamelower = rfileName;
|
||||
stl_lowers(fileNamelower);
|
||||
|
||||
std::string extName = GetFileExt(fileNamelower);
|
||||
|
||||
TCSHybridCryptKeyMap::const_iterator cit = m_mapHybridCryptKey.find( stringhash().GetHash(extName));
|
||||
|
||||
if( cit == m_mapHybridCryptKey.end() )
|
||||
{
|
||||
//TODO : log no file ext info
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD dwfileNameCrc = GetCRC32(fileNamelower.c_str(), fileNamelower.size());
|
||||
|
||||
//make file specific algorithm & key & iv
|
||||
eAlgorithm = (eHybridCipherAlgorithm)(dwfileNameCrc % Num_Of_Ciphers);
|
||||
|
||||
::memcpy(key.key, cit->second.uEncryptKey.key, sizeof(key) );
|
||||
::memcpy(iv.iv, cit->second.uEncryptIV.iv, sizeof(iv) );
|
||||
|
||||
|
||||
//Themida Warning
|
||||
for( int i = 0; i < (sizeof(key)/sizeof(dwfileNameCrc)); ++i)
|
||||
{
|
||||
*((DWORD*)key.key + i) ^= dwfileNameCrc;
|
||||
}
|
||||
for( int i = 0; i < (sizeof(iv)/sizeof(dwfileNameCrc)); ++i)
|
||||
{
|
||||
*((DWORD*)iv.iv + i) ^= dwfileNameCrc;
|
||||
}
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::EncryptMemory( std::string& rfileName, IN const BYTE* pSrcData, IN int iSrcLen, OUT CLZObject& zObj )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
eHybridCipherAlgorithm eAlgorithm;
|
||||
TEncryptKey key;
|
||||
TEncryptIV iv;
|
||||
|
||||
if( !GetPerFileCryptKey( rfileName, eAlgorithm, key, iv ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// start cipher
|
||||
std::string strCipher;
|
||||
//NOTE : ciphered stream size could be different from original size if you choose diffrent cipher mode & algorithm
|
||||
//( i.e ECB or CBC mode )
|
||||
strCipher.reserve(iSrcLen);
|
||||
|
||||
if( eAlgorithm == e_Cipher_Camellia )
|
||||
{
|
||||
// Encryptor
|
||||
CIPHER_MODE<Camellia>::Encryption Encryptor;
|
||||
Encryptor.SetKeyWithIV(key.keyCamellia, sizeof(key.keyCamellia), iv.ivCamellia, sizeof(iv.ivCamellia));
|
||||
|
||||
ArraySource(pSrcData, iSrcLen, true,
|
||||
new StreamTransformationFilter(Encryptor, new CryptoPP::StringSink(strCipher)));
|
||||
}
|
||||
else if( eAlgorithm == e_Cipher_Twofish )
|
||||
{
|
||||
// Encryptor
|
||||
CIPHER_MODE<Twofish>::Encryption Encryptor;
|
||||
Encryptor.SetKeyWithIV(key.keyTwofish, sizeof(key.keyTwofish), iv.ivTwofish, sizeof(iv.ivTwofish));
|
||||
|
||||
ArraySource(pSrcData, iSrcLen, true,
|
||||
new StreamTransformationFilter(Encryptor, new CryptoPP::StringSink(strCipher)));
|
||||
}
|
||||
else if( eAlgorithm == e_Cipher_XTEA )
|
||||
{
|
||||
// Encryptor
|
||||
CIPHER_MODE<XTEA>::Encryption Encryptor;
|
||||
Encryptor.SetKeyWithIV(key.keyXTEA, sizeof(key.keyXTEA), iv.ivXTEA, sizeof(iv.ivXTEA));
|
||||
|
||||
ArraySource(pSrcData, iSrcLen, true,
|
||||
new StreamTransformationFilter(Encryptor, new CryptoPP::StringSink(strCipher)));
|
||||
}
|
||||
|
||||
if (strCipher.length() != iSrcLen)
|
||||
{
|
||||
//TODO: size error log
|
||||
return false;
|
||||
}
|
||||
|
||||
zObj.AllocBuffer(iSrcLen);
|
||||
memcpy(zObj.GetBuffer(), strCipher.c_str(), strCipher.length() );
|
||||
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::DecryptMemory( std::string& rfilename, IN const BYTE* pEncryptedData, IN int iEncryptedLen, OUT CLZObject& zObj )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
eHybridCipherAlgorithm eAlgorithm;
|
||||
TEncryptKey key;
|
||||
TEncryptIV iv;
|
||||
|
||||
if( !GetPerFileCryptKey( rfilename, eAlgorithm, key, iv ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// start decipher
|
||||
std::string strDecipher;
|
||||
//NOTE : ciphered stream size could be different from original size if you choose diffrent cipher mode & algorithm
|
||||
//( i.e ECB or CBC mode )
|
||||
strDecipher.reserve(iEncryptedLen);
|
||||
|
||||
if( eAlgorithm == e_Cipher_Camellia )
|
||||
{
|
||||
// Decryptor
|
||||
CIPHER_MODE<Camellia>::Decryption Decryptor;
|
||||
Decryptor.SetKeyWithIV(key.keyCamellia, sizeof(key.keyCamellia), iv.ivCamellia, sizeof(iv.ivCamellia));
|
||||
|
||||
ArraySource(pEncryptedData, iEncryptedLen, true,
|
||||
new StreamTransformationFilter(Decryptor, new CryptoPP::StringSink(strDecipher)));
|
||||
}
|
||||
else if( eAlgorithm == e_Cipher_Twofish )
|
||||
{
|
||||
// Decryptor
|
||||
CIPHER_MODE<Twofish>::Decryption Decryptor;
|
||||
Decryptor.SetKeyWithIV(key.keyTwofish, sizeof(key.keyTwofish), iv.ivTwofish, sizeof(iv.ivTwofish));
|
||||
|
||||
ArraySource(pEncryptedData, iEncryptedLen, true,
|
||||
new StreamTransformationFilter(Decryptor, new CryptoPP::StringSink(strDecipher)));
|
||||
}
|
||||
else if( eAlgorithm == e_Cipher_XTEA )
|
||||
{
|
||||
// Decryptor
|
||||
CIPHER_MODE<XTEA>::Decryption Decryptor;
|
||||
Decryptor.SetKeyWithIV(key.keyXTEA, sizeof(key.keyXTEA), iv.ivXTEA, sizeof(iv.ivXTEA));
|
||||
|
||||
ArraySource(pEncryptedData, iEncryptedLen, true,
|
||||
new StreamTransformationFilter(Decryptor, new CryptoPP::StringSink(strDecipher)));
|
||||
}
|
||||
|
||||
|
||||
if (strDecipher.length() != iEncryptedLen)
|
||||
{
|
||||
//TODO: size error log
|
||||
return false;
|
||||
}
|
||||
|
||||
zObj.AllocBuffer(iEncryptedLen);
|
||||
memcpy(zObj.GetBuffer(), strDecipher.c_str(), strDecipher.length() );
|
||||
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EterPackPolicy_CSHybridCrypt::WriteCryptKeyToFile( CFileBase& rFile )
|
||||
{
|
||||
// ext cnt 4byte
|
||||
// for ext hash ( crc32 )
|
||||
// key-16byte
|
||||
// iv-16byte
|
||||
|
||||
DWORD dwCryptKeySize = m_mapHybridCryptKey.size();
|
||||
rFile.Write( &dwCryptKeySize, sizeof(DWORD) );
|
||||
|
||||
TCSHybridCryptKeyMap::const_iterator cit;
|
||||
for( cit = m_mapHybridCryptKey.begin(); cit != m_mapHybridCryptKey.end(); ++cit )
|
||||
{
|
||||
DWORD extNamehash = cit->first;
|
||||
const TCSHybridCryptKey& CryptKey = cit->second;
|
||||
|
||||
rFile.Write( &extNamehash, sizeof(DWORD) );
|
||||
rFile.Write( CryptKey.uEncryptKey.key, sizeof(TEncryptKey) );
|
||||
rFile.Write( CryptKey.uEncryptIV.iv, sizeof(TEncryptIV) );
|
||||
}
|
||||
}
|
||||
|
||||
int EterPackPolicy_CSHybridCrypt::ReadCryptKeyInfoFromStream( IN const BYTE* pStream )
|
||||
{
|
||||
int iStreamOffset = 0;
|
||||
|
||||
DWORD dwCryptoInfoSize;
|
||||
memcpy(&dwCryptoInfoSize, pStream, sizeof(DWORD) );
|
||||
iStreamOffset += sizeof(DWORD);
|
||||
|
||||
DWORD dwExtHash;
|
||||
|
||||
m_mapHybridCryptKey.clear();
|
||||
|
||||
for( int i = 0; i < dwCryptoInfoSize; ++i )
|
||||
{
|
||||
memcpy(&dwExtHash, pStream + iStreamOffset, sizeof(DWORD) );
|
||||
iStreamOffset += sizeof(DWORD);
|
||||
|
||||
TCSHybridCryptKey info;
|
||||
{
|
||||
memcpy(info.uEncryptKey.key, pStream + iStreamOffset, sizeof(TEncryptKey) );
|
||||
iStreamOffset += sizeof(TEncryptKey);
|
||||
|
||||
memcpy(info.uEncryptIV.iv, pStream + iStreamOffset, sizeof(TEncryptIV) );
|
||||
iStreamOffset += sizeof(TEncryptIV);
|
||||
}
|
||||
|
||||
m_mapHybridCryptKey[dwExtHash] = info;
|
||||
}
|
||||
|
||||
return iStreamOffset;
|
||||
}
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::GenerateSupplementaryDataBlock(std::string& rfilename, const std::string& strMapName, IN const BYTE* pSrcData, IN int iSrcLen, OUT LPBYTE& pDestData, OUT int& iDestLen )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
std::string fileNamelower = rfilename;
|
||||
stl_lowers( fileNamelower );
|
||||
|
||||
DWORD dwFileNameHash = stringhash().GetHash(fileNamelower);
|
||||
TSupplementaryDataBlockMap::const_iterator cit = m_mapSDBMap.find( dwFileNameHash );
|
||||
|
||||
if( cit != m_mapSDBMap.end() )
|
||||
{
|
||||
//TODO : log already registered
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO : Find Better Method for deciding SDB Postion & Size
|
||||
|
||||
//prevent stream copy duplication
|
||||
TSupplementaryDataBlockInfo info;
|
||||
m_mapSDBMap[dwFileNameHash] = info;
|
||||
|
||||
std::string& strRelatedMapName = m_mapSDBMap[dwFileNameHash].strRelatedMapName;
|
||||
std::vector<BYTE>& sdbVector = m_mapSDBMap[dwFileNameHash].vecStream;
|
||||
|
||||
|
||||
//fill the data!!
|
||||
{
|
||||
strRelatedMapName = strMapName;
|
||||
|
||||
int iSDBSize = random_range( 64, 128 );
|
||||
|
||||
if( iSrcLen < iSDBSize )
|
||||
{
|
||||
iSDBSize = iSrcLen - 1;
|
||||
if( iSDBSize <= 0 )
|
||||
{
|
||||
//TODO : is there 1byte file exist???
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
sdbVector.resize( iSDBSize );
|
||||
|
||||
iDestLen = iSrcLen - iSDBSize;
|
||||
pDestData = (LPBYTE)pSrcData;
|
||||
|
||||
memcpy( &sdbVector[0], pDestData + iDestLen, iSDBSize );
|
||||
}
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::GetSupplementaryDataBlock( std::string& rfilename, OUT LPBYTE& pSDB, OUT int& iSDBSize )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
std::string fileNamelower = rfilename;
|
||||
stl_lowers( fileNamelower );
|
||||
|
||||
DWORD dwFileNameHash = stringhash().GetHash(fileNamelower);
|
||||
TSupplementaryDataBlockMap::const_iterator cit = m_mapSDBMap.find( dwFileNameHash );
|
||||
|
||||
if( cit == m_mapSDBMap.end() )
|
||||
{
|
||||
//TODO : log already registered
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::vector<BYTE>& vecSDB = cit->second.vecStream;
|
||||
|
||||
iSDBSize = vecSDB.size();
|
||||
|
||||
if(iSDBSize <= 0)
|
||||
{
|
||||
pSDB = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
pSDB = (BYTE*)&vecSDB[0];
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EterPackPolicy_CSHybridCrypt::IsContainingSDBFile() const
|
||||
{
|
||||
return m_mapSDBMap.size() > 0 ? true : false;
|
||||
}
|
||||
|
||||
void EterPackPolicy_CSHybridCrypt::WriteSupplementaryDataBlockToFile( CFileBase& rFile )
|
||||
{
|
||||
//about SDB data
|
||||
// sdb file cnt( 4byte )
|
||||
// for sdb file cnt
|
||||
// filename hash ( stl.h stringhash )
|
||||
// related map name size(4), relate map name
|
||||
// sdb block size( 1byte )
|
||||
// sdb blocks
|
||||
|
||||
DWORD dwSDBMapSize = m_mapSDBMap.size();
|
||||
rFile.Write( &dwSDBMapSize, sizeof(DWORD) );
|
||||
|
||||
TSupplementaryDataBlockMap::const_iterator cit;
|
||||
for( cit = m_mapSDBMap.begin(); cit != m_mapSDBMap.end(); ++cit )
|
||||
{
|
||||
DWORD dwFileNamehash = cit->first;
|
||||
rFile.Write( &dwFileNamehash, sizeof(DWORD) );
|
||||
|
||||
const std::string strRelatedMapName = cit->second.strRelatedMapName;
|
||||
DWORD dwMapNameSize = strRelatedMapName.size();
|
||||
rFile.Write( &dwMapNameSize, sizeof(DWORD) );
|
||||
rFile.Write( strRelatedMapName.c_str(), dwMapNameSize );
|
||||
|
||||
const std::vector<BYTE>& sdbVector = cit->second.vecStream;
|
||||
BYTE bSDBSize = (BYTE)(sdbVector.size());
|
||||
|
||||
rFile.Write( &bSDBSize, sizeof(bSDBSize) );
|
||||
if( bSDBSize > 0 )
|
||||
rFile.Write( &sdbVector[0], bSDBSize );
|
||||
}
|
||||
}
|
||||
|
||||
int EterPackPolicy_CSHybridCrypt::ReadSupplementatyDataBlockFromStream( IN const BYTE* pStream )
|
||||
{
|
||||
#ifdef __THEMIDA__
|
||||
VM_START
|
||||
#endif
|
||||
|
||||
//DWORD dwFileIdentifier;
|
||||
//std::vector<BYTE> vecSDBStream;
|
||||
|
||||
DWORD dwFileNameHash;
|
||||
BYTE bSDBSize;
|
||||
int iStreamOffset = 0;
|
||||
|
||||
memcpy(&dwFileNameHash, pStream + iStreamOffset, sizeof(DWORD) );
|
||||
iStreamOffset += sizeof(DWORD);
|
||||
|
||||
memcpy(&bSDBSize, pStream + iStreamOffset, sizeof(BYTE) );
|
||||
iStreamOffset += sizeof(BYTE);
|
||||
|
||||
// NOTE : related map name isn`t required in client. so we don`t recv it from stream to reduce packet size.
|
||||
TSupplementaryDataBlockInfo info;
|
||||
{
|
||||
info.vecStream.resize( bSDBSize );
|
||||
memcpy(&info.vecStream[0], pStream + iStreamOffset, bSDBSize );
|
||||
iStreamOffset += bSDBSize;
|
||||
|
||||
m_mapSDBMap[dwFileNameHash] = info;
|
||||
}
|
||||
|
||||
#ifdef __THEMIDA__
|
||||
VM_END
|
||||
#endif
|
||||
|
||||
return iStreamOffset;
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
#ifndef __INC_ETERPACKLIB_ETERPACKPOLICY_CSHYBRIDCRYPT_H__
|
||||
#define __INC_ETERPACKLIB_ETERPACKPOLICY_CSHYBRIDCRYPT_H__
|
||||
|
||||
#include <unordered_map>
|
||||
#include <cryptlib.h>
|
||||
#include <camellia.h>
|
||||
#include <twofish.h>
|
||||
#include <tea.h>
|
||||
|
||||
enum eHybridCipherAlgorithm
|
||||
{
|
||||
e_Cipher_Camellia,
|
||||
e_Cipher_Twofish,
|
||||
e_Cipher_XTEA,
|
||||
Num_Of_Ciphers
|
||||
};
|
||||
|
||||
|
||||
class CFileBase;
|
||||
class CLZObject;
|
||||
|
||||
//THEMIDA
|
||||
class EterPackPolicy_CSHybridCrypt
|
||||
{
|
||||
public:
|
||||
~EterPackPolicy_CSHybridCrypt();
|
||||
|
||||
bool GenerateCryptKey( std::string& rfileName );
|
||||
bool EncryptMemory( std::string& rfilename, IN const BYTE* pSrcData, IN int iSrcLen, OUT CLZObject& zObj );
|
||||
bool DecryptMemory( std::string& rfilename, IN const BYTE* pSrcData, IN int iSrcLen, OUT CLZObject& zObj );
|
||||
bool IsContainingCryptKey() const;
|
||||
|
||||
//Supplementary Data Block (SDB)
|
||||
bool GenerateSupplementaryDataBlock(std::string& rfilename, const std::string& strMapName, IN const BYTE* pSrcData, IN int iSrcLen, OUT LPBYTE& pDestData, OUT int& iDestLen );
|
||||
bool GetSupplementaryDataBlock( std::string& rfilename, OUT LPBYTE& pSDB, OUT int& iSDBSize );
|
||||
bool IsContainingSDBFile() const;
|
||||
|
||||
// Read/Write IO
|
||||
void WriteCryptKeyToFile( CFileBase& rFile );
|
||||
int ReadCryptKeyInfoFromStream( IN const BYTE* pStream );
|
||||
|
||||
void WriteSupplementaryDataBlockToFile( CFileBase& rFile );
|
||||
int ReadSupplementatyDataBlockFromStream( IN const BYTE* pStream );
|
||||
|
||||
protected:
|
||||
|
||||
typedef union UEncryptKey
|
||||
{
|
||||
BYTE key[16];
|
||||
BYTE keyCamellia[ CryptoPP::Camellia::DEFAULT_KEYLENGTH];
|
||||
BYTE keyTwofish [ CryptoPP::Twofish::DEFAULT_KEYLENGTH];
|
||||
BYTE keyXTEA [ CryptoPP::XTEA::DEFAULT_KEYLENGTH];
|
||||
|
||||
} TEncryptKey;
|
||||
|
||||
typedef union UEncryptIV
|
||||
{
|
||||
BYTE iv[16];
|
||||
BYTE ivCamellia [ CryptoPP::Camellia::BLOCKSIZE];
|
||||
BYTE ivTwofish [ CryptoPP::Twofish::BLOCKSIZE];
|
||||
BYTE ivXTEA [ CryptoPP::XTEA::BLOCKSIZE];
|
||||
|
||||
} TEncryptIV;
|
||||
|
||||
|
||||
typedef struct SCSHybridCryptKey
|
||||
{
|
||||
TEncryptKey uEncryptKey;
|
||||
TEncryptIV uEncryptIV;
|
||||
|
||||
} TCSHybridCryptKey;
|
||||
|
||||
typedef std::unordered_map<DWORD, TCSHybridCryptKey> TCSHybridCryptKeyMap;
|
||||
TCSHybridCryptKeyMap m_mapHybridCryptKey;
|
||||
|
||||
typedef struct SSupplementaryDataBlockInfo
|
||||
{
|
||||
std::string strRelatedMapName;
|
||||
std::vector<BYTE> vecStream;
|
||||
|
||||
} TSupplementaryDataBlockInfo;
|
||||
|
||||
typedef std::unordered_map<DWORD, TSupplementaryDataBlockInfo> TSupplementaryDataBlockMap; //key filename hash
|
||||
TSupplementaryDataBlockMap m_mapSDBMap;
|
||||
|
||||
private:
|
||||
bool GetPerFileCryptKey( std::string& rfileName, eHybridCipherAlgorithm& eAlgorithm, TEncryptKey& key, TEncryptIV& iv );
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // __INC_ETERPACKLIB_ETERPACKPOLICY_CSHYBRIDCRYPT_H__
|
||||
@@ -1,34 +0,0 @@
|
||||
#ifndef __INC_ETERPACK_INLINE_H__
|
||||
#define __INC_ETERPACK_INLINE_H__
|
||||
|
||||
inline void inlinePathCreate(const char* path)
|
||||
{
|
||||
char dir[64];
|
||||
const char* p, *k;
|
||||
|
||||
p = path + 3;
|
||||
|
||||
while (NULL != (k = strchr(p, '/')))
|
||||
{
|
||||
memset(dir, 0, sizeof(dir));
|
||||
strncpy(dir, path, k - path);
|
||||
CreateDirectory(dir, NULL);
|
||||
p = k + 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline void inlineConvertPackFilename(char* name)
|
||||
{
|
||||
char * p = name;
|
||||
|
||||
while (*p)
|
||||
{
|
||||
if (*p == '\\')
|
||||
*p = '/';
|
||||
else
|
||||
*p = (int) tolower(*p);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
//#include <crtdbg.h>
|
||||
#include <windows.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "EterBase/StdAfx.h"
|
||||
1033
src/EterPack/md5.c
1033
src/EterPack/md5.c
File diff suppressed because it is too large
Load Diff
@@ -1,128 +0,0 @@
|
||||
#ifndef __INC_ETERPACKLIB_MD5_H__
|
||||
#define __INC_ETERPACKLIB_MD5_H__
|
||||
|
||||
/*
|
||||
|
||||
***********************************************************************
|
||||
|
||||
** md5.h -- header file for implementation of MD5 **
|
||||
|
||||
** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
|
||||
|
||||
** Created: 2/17/90 RLR **
|
||||
|
||||
** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version **
|
||||
|
||||
** Revised (for MD5): RLR 4/27/91 **
|
||||
|
||||
** -- G modified to have y&~z instead of y&z **
|
||||
|
||||
** -- FF, GG, HH modified to add in last register done **
|
||||
|
||||
** -- Access pattern: round 2 works mod 5, round 3 works mod 3 **
|
||||
|
||||
** -- distinct additive constant for each step **
|
||||
|
||||
** -- round 4 added, working mod 7 **
|
||||
|
||||
***********************************************************************
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
***********************************************************************
|
||||
|
||||
** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
|
||||
|
||||
** **
|
||||
|
||||
** License to copy and use this software is granted provided that **
|
||||
|
||||
** it is identified as the "RSA Data Security, Inc. MD5 Message- **
|
||||
|
||||
** Digest Algorithm" in all material mentioning or referencing this **
|
||||
|
||||
** software or this function. **
|
||||
|
||||
** **
|
||||
|
||||
** License is also granted to make and use derivative works **
|
||||
|
||||
** provided that such works are identified as "derived from the RSA **
|
||||
|
||||
** Data Security, Inc. MD5 Message-Digest Algorithm" in all **
|
||||
|
||||
** material mentioning or referencing the derived work. **
|
||||
|
||||
** **
|
||||
|
||||
** RSA Data Security, Inc. makes no representations concerning **
|
||||
|
||||
** either the merchantability of this software or the suitability **
|
||||
|
||||
** of this software for any particular purpose. It is provided "as **
|
||||
|
||||
** is" without express or implied warranty of any kind. **
|
||||
|
||||
** **
|
||||
|
||||
** These notices must be retained in any copies of any part of this **
|
||||
|
||||
** documentation and/or software. **
|
||||
|
||||
***********************************************************************
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* typedef a 32-bit type */
|
||||
|
||||
typedef unsigned long int UINT4;
|
||||
|
||||
|
||||
|
||||
/* Data structure for MD5 (Message-Digest) computation */
|
||||
|
||||
typedef struct {
|
||||
|
||||
UINT4 i[2]; /* number of _bits_ handled mod 2^64 */
|
||||
|
||||
UINT4 buf[4]; /* scratch buffer */
|
||||
|
||||
unsigned char in[64]; /* input buffer */
|
||||
|
||||
unsigned char digest[16]; /* actual digest after MD5Final call */
|
||||
|
||||
} MD5_CTX;
|
||||
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void MD5Init (MD5_CTX *);
|
||||
|
||||
void MD5Update (MD5_CTX *,unsigned char *,unsigned int);
|
||||
|
||||
void MD5Final (MD5_CTX *);
|
||||
|
||||
void MD5Transform(UINT4 *,UINT4 *);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
***********************************************************************
|
||||
|
||||
** End of md5.h **
|
||||
|
||||
******************************** (cut) ********************************
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#endif
|
||||
@@ -3,8 +3,8 @@
|
||||
add_library(EterPythonLib STATIC ${FILE_SOURCES})
|
||||
|
||||
target_link_libraries(EterPythonLib
|
||||
lzo2
|
||||
cryptopp-static
|
||||
mio
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(EterPythonLib)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "EterLib/ResourceManager.h"
|
||||
#include "EterLib/StateManager.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
#include "AreaTerrain.h"
|
||||
#include "MapOutdoor.h"
|
||||
@@ -106,10 +106,9 @@ bool CTerrain::LoadShadowMap(const char * c_pszFileName)
|
||||
DWORD dwStart = ELTimer_GetMSec();
|
||||
Tracef("LoadShadowMap %s ", c_pszFileName);
|
||||
|
||||
CMappedFile file;
|
||||
LPCVOID c_pvData;
|
||||
TPackFile file;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData))
|
||||
if (!CPackManager::Instance().GetFile(c_pszFileName, file))
|
||||
{
|
||||
TraceError(" CTerrain::LoadShadowMap - %s OPEN ERROR", c_pszFileName);
|
||||
return false;
|
||||
@@ -117,13 +116,13 @@ bool CTerrain::LoadShadowMap(const char * c_pszFileName)
|
||||
|
||||
DWORD dwShadowMapSize = sizeof(WORD) * 256 * 256;
|
||||
|
||||
if (file.Size() != dwShadowMapSize)
|
||||
if (file.size() != dwShadowMapSize)
|
||||
{
|
||||
TraceError(" CTerrain::LoadShadowMap - %s SIZE ERROR", c_pszFileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(m_awShadowMap, c_pvData, dwShadowMapSize);
|
||||
memcpy(m_awShadowMap, file.data(), dwShadowMapSize);
|
||||
|
||||
Tracef("%d ms\n", ELTimer_GetMSec() - dwStart);
|
||||
return true;
|
||||
|
||||
@@ -4,6 +4,8 @@ add_library(GameLib STATIC ${FILE_SOURCES})
|
||||
|
||||
target_link_libraries(GameLib
|
||||
lzo2
|
||||
cryptopp-static
|
||||
mio
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(GameLib)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "StdAfx.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
#include "EterLib/ResourceManager.h"
|
||||
#include "EterBase/lzo.h"
|
||||
|
||||
#include "ItemManager.h"
|
||||
|
||||
@@ -95,14 +96,13 @@ CItemData * CItemManager::MakeItemData(DWORD dwIndex)
|
||||
|
||||
bool CItemManager::LoadItemList(const char * c_szFileName)
|
||||
{
|
||||
CMappedFile File;
|
||||
LPCVOID pData;
|
||||
TPackFile File;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(File, c_szFileName, &pData))
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, File))
|
||||
return false;
|
||||
|
||||
CMemoryTextFileLoader textFileLoader;
|
||||
textFileLoader.Bind(File.Size(), pData);
|
||||
textFileLoader.Bind(File.size(), File.data());
|
||||
|
||||
CTokenVector TokenVector;
|
||||
for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i)
|
||||
@@ -196,16 +196,15 @@ const std::string& __SnapString(const std::string& c_rstSrc, std::string& rstTem
|
||||
|
||||
bool CItemManager::LoadItemDesc(const char* c_szFileName)
|
||||
{
|
||||
const VOID* pvData;
|
||||
CMappedFile kFile;
|
||||
if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData))
|
||||
TPackFile kFile;
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, kFile))
|
||||
{
|
||||
Tracenf("CItemManager::LoadItemDesc(c_szFileName=%s) - Load Error", c_szFileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
CMemoryTextFileLoader kTextFileLoader;
|
||||
kTextFileLoader.Bind(kFile.Size(), pvData);
|
||||
kTextFileLoader.Bind(kFile.size(), kFile.data());
|
||||
|
||||
std::string stTemp;
|
||||
|
||||
@@ -254,22 +253,27 @@ DWORD GetHashCode( const char* pString )
|
||||
|
||||
bool CItemManager::LoadItemTable(const char* c_szFileName)
|
||||
{
|
||||
CMappedFile file;
|
||||
TPackFile file;
|
||||
LPCVOID pvData;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(file, c_szFileName, &pvData))
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, file))
|
||||
return false;
|
||||
|
||||
DWORD dwFourCC, dwElements, dwDataSize;
|
||||
DWORD dwVersion=0;
|
||||
DWORD dwStride=0;
|
||||
|
||||
file.Read(&dwFourCC, sizeof(DWORD));
|
||||
uint8_t* p = file.data();
|
||||
memcpy(&dwFourCC, p, sizeof(DWORD));
|
||||
p += sizeof(DWORD);
|
||||
|
||||
if (dwFourCC == MAKEFOURCC('M', 'I', 'P', 'X'))
|
||||
{
|
||||
file.Read(&dwVersion, sizeof(DWORD));
|
||||
file.Read(&dwStride, sizeof(DWORD));
|
||||
memcpy(&dwVersion, p, sizeof(DWORD));
|
||||
p += sizeof(DWORD);
|
||||
|
||||
memcpy(&dwStride, p, sizeof(DWORD));
|
||||
p += sizeof(DWORD);
|
||||
|
||||
if (dwVersion != 1)
|
||||
{
|
||||
@@ -289,11 +293,14 @@ bool CItemManager::LoadItemTable(const char* c_szFileName)
|
||||
return false;
|
||||
}
|
||||
|
||||
file.Read(&dwElements, sizeof(DWORD));
|
||||
file.Read(&dwDataSize, sizeof(DWORD));
|
||||
memcpy(&dwElements, p, sizeof(DWORD));
|
||||
p += sizeof(DWORD);
|
||||
|
||||
memcpy(&dwDataSize, p, sizeof(DWORD));
|
||||
p += sizeof(DWORD);
|
||||
|
||||
BYTE * pbData = new BYTE[dwDataSize];
|
||||
file.Read(pbData, dwDataSize);
|
||||
memcpy(pbData, p, dwDataSize);
|
||||
|
||||
/////
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "StdAfx.h"
|
||||
#include "EterLib/StateManager.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
#include "MapManager.h"
|
||||
#include "MapOutdoor.h"
|
||||
@@ -597,14 +597,13 @@ void CMapManager::GetBaseXY(DWORD * pdwBaseX, DWORD * pdwBaseY)
|
||||
|
||||
void CMapManager::__LoadMapInfoVector()
|
||||
{
|
||||
CMappedFile kFile;
|
||||
LPCVOID pData;
|
||||
if (!CEterPackManager::Instance().Get(kFile, m_stAtlasInfoFileName.c_str(), &pData))
|
||||
if (!CEterPackManager::Instance().Get(kFile, "AtlasInfo.txt", &pData))
|
||||
TPackFile kFile;
|
||||
if (!CPackManager::Instance().GetFile(m_stAtlasInfoFileName, kFile))
|
||||
if (!CPackManager::Instance().GetFile("AtlasInfo.txt", kFile))
|
||||
return;
|
||||
|
||||
CMemoryTextFileLoader textFileLoader;
|
||||
textFileLoader.Bind(kFile.Size(), pData);
|
||||
textFileLoader.Bind(kFile.size(), kFile.data());
|
||||
|
||||
char szMapName[256];
|
||||
int x, y;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "AreaTerrain.h"
|
||||
#include "AreaLoaderThread.h"
|
||||
#include "EterLib/ResourceManager.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
//CAreaLoaderThread CMapOutdoor::ms_AreaLoaderThread;
|
||||
|
||||
@@ -11,7 +11,6 @@ bool CMapOutdoor::Load(float x, float y, float z)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
CEterPackManager& rkPackMgr=CEterPackManager::Instance();
|
||||
{
|
||||
static std::string s_strOldPathName="";
|
||||
|
||||
@@ -42,7 +41,7 @@ bool CMapOutdoor::Load(float x, float y, float z)
|
||||
|
||||
// LOCAL_ENVIRONMENT_DATA
|
||||
std::string local_envDataName = GetMapDataDirectory() + "\\" + m_settings_envDataName;
|
||||
if (rkPackMgr.isExist(local_envDataName.c_str()))
|
||||
if (CPackManager::instance().IsExist(local_envDataName.c_str()))
|
||||
{
|
||||
m_envDataName = local_envDataName;
|
||||
}
|
||||
@@ -440,10 +439,9 @@ bool CMapOutdoor::LoadMonsterAreaInfo()
|
||||
char c_szFileName[256];
|
||||
sprintf(c_szFileName, "%s\\regen.txt", GetMapDataDirectory().c_str());
|
||||
|
||||
LPCVOID pModelData;
|
||||
CMappedFile File;
|
||||
TPackFile File;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(File, c_szFileName, &pModelData))
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, File))
|
||||
{
|
||||
//TraceError(" CMapOutdoorAccessor::LoadMonsterAreaInfo Load File %s ERROR", c_szFileName);
|
||||
return false;
|
||||
@@ -452,7 +450,7 @@ bool CMapOutdoor::LoadMonsterAreaInfo()
|
||||
CMemoryTextFileLoader textFileLoader;
|
||||
CTokenVector stTokenVector;
|
||||
|
||||
textFileLoader.Bind(File.Size(), pModelData);
|
||||
textFileLoader.Bind(File.size(), File.data());
|
||||
|
||||
for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i)
|
||||
{
|
||||
|
||||
@@ -136,54 +136,6 @@ void GetTimeString(char * str, time_t ct)
|
||||
tm.tm_sec);
|
||||
}
|
||||
|
||||
bool CProperty::Save(const char * c_pszFileName)
|
||||
{
|
||||
CTempFile file;
|
||||
|
||||
DWORD fourcc = MAKEFOURCC('Y', 'P', 'R', 'T');
|
||||
file.Write(&fourcc, sizeof(DWORD));
|
||||
file.Write("\r\n", 2);
|
||||
|
||||
if (0 == m_stCRC.length())
|
||||
{
|
||||
char szCRC[MAX_PATH + 16 + 1];
|
||||
|
||||
GetTimeString(szCRC, time(0));
|
||||
strcpy(szCRC + strlen(szCRC), c_pszFileName);
|
||||
|
||||
m_dwCRC = CPropertyManager::Instance().GetUniqueCRC(szCRC);
|
||||
_snprintf(szCRC, sizeof(szCRC), "%u", m_dwCRC);
|
||||
|
||||
m_stCRC.assign(szCRC);
|
||||
}
|
||||
|
||||
file.Write(m_stCRC.c_str(), m_stCRC.length());
|
||||
file.Write("\r\n", 2);
|
||||
|
||||
CTokenVectorMap::iterator itor = m_stTokenMap.begin();
|
||||
char buf[4096 + 1];
|
||||
|
||||
while (itor != m_stTokenMap.end())
|
||||
{
|
||||
CTokenVector & tokenVector = itor->second;
|
||||
|
||||
int len = _snprintf(buf, sizeof(buf), "%s\t", itor->first.c_str());
|
||||
file.Write(buf, len);
|
||||
|
||||
for (DWORD i = 0; i < tokenVector.size(); ++i)
|
||||
{
|
||||
len = _snprintf(buf, sizeof(buf), "\t\"%s\"", tokenVector[i].c_str());
|
||||
file.Write(buf, len);
|
||||
}
|
||||
|
||||
file.Write("\r\n", 2);
|
||||
++itor;
|
||||
}
|
||||
|
||||
file.Close();
|
||||
return CPropertyManager::Instance().Put(c_pszFileName, file.GetFileName());
|
||||
}
|
||||
|
||||
bool CProperty::ReadFromMemory(const void * c_pvData, int iLen, const char * c_pszFileName)
|
||||
{
|
||||
const char * pcData = (const char *) c_pvData;
|
||||
|
||||
@@ -19,8 +19,6 @@ class CProperty
|
||||
void PutVector(const char * c_pszKey, const CTokenVector & c_rTokenVector);
|
||||
void PutString(const char * c_pszKey, const char * c_pszString);
|
||||
|
||||
bool Save(const char * c_pszFileName);
|
||||
|
||||
DWORD GetSize();
|
||||
DWORD GetCRC();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "StdAfx.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
#include "PropertyManager.h"
|
||||
#include "Property.h"
|
||||
@@ -17,37 +17,22 @@ bool CPropertyManager::Initialize(const char * c_pszPackFileName)
|
||||
{
|
||||
if (c_pszPackFileName)
|
||||
{
|
||||
if (!m_pack.Create(m_fileDict, c_pszPackFileName, "", true))
|
||||
{
|
||||
m_pack = std::make_shared<CPack>();
|
||||
if (!m_pack->Open(c_pszPackFileName, m_fileDict)) {
|
||||
LogBoxf("Cannot open property pack file (filename %s)", c_pszPackFileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_isFileMode = false;
|
||||
|
||||
TDataPositionMap & indexMap = m_pack.GetIndexMap();
|
||||
|
||||
TDataPositionMap::iterator itor = indexMap.begin();
|
||||
|
||||
typedef std::map<DWORD, TEterPackIndex *> TDataPositionMap;
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (indexMap.end() != itor)
|
||||
{
|
||||
TEterPackIndex * pIndex = itor->second;
|
||||
++itor;
|
||||
|
||||
if (!stricmp("property/reserve", pIndex->filename))
|
||||
{
|
||||
LoadReservedCRC(pIndex->filename);
|
||||
continue;
|
||||
for (auto it = m_fileDict.begin(); it != m_fileDict.end(); ++it) {
|
||||
std::string stFileName = it->second.second.file_name;
|
||||
if (!stricmp("property/reserve", stFileName.c_str())) {
|
||||
LoadReservedCRC(stFileName.c_str());
|
||||
}
|
||||
else {
|
||||
Register(stFileName.c_str());
|
||||
}
|
||||
|
||||
if (!Register(pIndex->filename))
|
||||
continue;
|
||||
|
||||
++i;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -60,43 +45,15 @@ bool CPropertyManager::Initialize(const char * c_pszPackFileName)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPropertyManager::BuildPack()
|
||||
{
|
||||
if (!m_pack.Create(m_fileDict, "property", ""))
|
||||
return false;
|
||||
|
||||
WIN32_FIND_DATA fdata;
|
||||
HANDLE hFind = FindFirstFile("property\\*", &fdata);
|
||||
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
do
|
||||
{
|
||||
if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||
continue;
|
||||
|
||||
char szSourceFileName[256 + 1];
|
||||
_snprintf(szSourceFileName, sizeof(szSourceFileName), "property\\%s", fdata.cFileName);
|
||||
|
||||
m_pack.Put(fdata.cFileName, szSourceFileName,COMPRESSED_TYPE_NONE,"");
|
||||
}
|
||||
while (FindNextFile(hFind, &fdata));
|
||||
|
||||
FindClose(hFind);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPropertyManager::LoadReservedCRC(const char * c_pszFileName)
|
||||
{
|
||||
CMappedFile file;
|
||||
LPCVOID c_pvData;
|
||||
TPackFile file;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData))
|
||||
if (!CPackManager::Instance().GetFile(c_pszFileName, file))
|
||||
return false;
|
||||
|
||||
CMemoryTextFileLoader textFileLoader;
|
||||
textFileLoader.Bind(file.Size(), c_pvData);
|
||||
textFileLoader.Bind(file.size(), file.data());
|
||||
|
||||
for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i)
|
||||
{
|
||||
@@ -136,15 +93,14 @@ DWORD CPropertyManager::GetUniqueCRC(const char * c_szSeed)
|
||||
|
||||
bool CPropertyManager::Register(const char * c_pszFileName, CProperty ** ppProperty)
|
||||
{
|
||||
CMappedFile file;
|
||||
LPCVOID c_pvData;
|
||||
TPackFile file;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData))
|
||||
if (!CPackManager::Instance().GetFile(c_pszFileName, file))
|
||||
return false;
|
||||
|
||||
CProperty * pProperty = new CProperty(c_pszFileName);
|
||||
|
||||
if (!pProperty->ReadFromMemory(c_pvData, file.Size(), c_pszFileName))
|
||||
if (!pProperty->ReadFromMemory(file.data(), file.size(), c_pszFileName))
|
||||
{
|
||||
delete pProperty;
|
||||
return false;
|
||||
@@ -188,67 +144,6 @@ bool CPropertyManager::Get(DWORD dwCRC, CProperty ** ppProperty)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPropertyManager::Put(const char * c_pszFileName, const char * c_pszSourceFileName)
|
||||
{
|
||||
if (!CopyFile(c_pszSourceFileName, c_pszFileName, FALSE))
|
||||
return false;
|
||||
|
||||
if (!m_isFileMode) // 팩 파일에도 넣음
|
||||
{
|
||||
if (!m_pack.Put(c_pszFileName, NULL, COMPRESSED_TYPE_NONE,""))
|
||||
{
|
||||
assert(!"CPropertyManager::Put cannot write to pack file");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Register(c_pszFileName);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPropertyManager::Erase(DWORD dwCRC)
|
||||
{
|
||||
TPropertyCRCMap::iterator itor = m_PropertyByCRCMap.find(dwCRC);
|
||||
|
||||
if (m_PropertyByCRCMap.end() == itor)
|
||||
return false;
|
||||
|
||||
CProperty * pProperty = itor->second;
|
||||
m_PropertyByCRCMap.erase(itor);
|
||||
|
||||
DeleteFile(pProperty->GetFileName());
|
||||
ReserveCRC(pProperty->GetCRC());
|
||||
|
||||
if (!m_isFileMode) // 파일 모드가 아니면 팩에서도 지움
|
||||
m_pack.Delete(pProperty->GetFileName());
|
||||
|
||||
FILE * fp = fopen("property/reserve", "a+");
|
||||
|
||||
if (!fp)
|
||||
LogBox("예약 CRC 파일을 열 수 없습니다.");
|
||||
else
|
||||
{
|
||||
char szCRC[64 + 1];
|
||||
_snprintf(szCRC, sizeof(szCRC), "%u\r\n", pProperty->GetCRC());
|
||||
|
||||
fputs(szCRC, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
delete pProperty;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPropertyManager::Erase(const char * c_pszFileName)
|
||||
{
|
||||
CProperty * pProperty = NULL;
|
||||
|
||||
if (Get(c_pszFileName, &pProperty))
|
||||
return Erase(pProperty->GetCRC());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CPropertyManager::Clear()
|
||||
{
|
||||
stl_wipe_second(m_PropertyByCRCMap);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "EterPack/EterPack.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
class CPropertyManager : public CSingleton<CPropertyManager>
|
||||
{
|
||||
@@ -10,9 +10,6 @@ class CPropertyManager : public CSingleton<CPropertyManager>
|
||||
|
||||
void Clear();
|
||||
|
||||
void SetPack(CEterPack * pPack);
|
||||
bool BuildPack();
|
||||
|
||||
bool LoadReservedCRC(const char * c_pszFileName);
|
||||
void ReserveCRC(DWORD dwCRC);
|
||||
DWORD GetUniqueCRC(const char * c_szSeed);
|
||||
@@ -23,14 +20,6 @@ class CPropertyManager : public CSingleton<CPropertyManager>
|
||||
bool Get(DWORD dwCRC, CProperty ** ppProperty);
|
||||
bool Get(const char * c_pszFileName, CProperty ** ppProperty);
|
||||
|
||||
// bool Add(const char * c_pszFileName);
|
||||
// bool Remove(DWORD dwCRC);
|
||||
|
||||
bool Put(const char * c_pszFileName, const char * c_pszSourceFileName);
|
||||
|
||||
bool Erase(DWORD dwCRC);
|
||||
bool Erase(const char * c_pszFileName);
|
||||
|
||||
protected:
|
||||
typedef std::map<DWORD, CProperty *> TPropertyCRCMap;
|
||||
typedef std::set<DWORD> TCRCSet;
|
||||
@@ -38,6 +27,6 @@ class CPropertyManager : public CSingleton<CPropertyManager>
|
||||
bool m_isFileMode;
|
||||
TPropertyCRCMap m_PropertyByCRCMap;
|
||||
TCRCSet m_ReservedCRCSet;
|
||||
CEterPack m_pack;
|
||||
CEterFileDict m_fileDict;
|
||||
std::shared_ptr<CPack> m_pack;
|
||||
TPackFileMap m_fileDict;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "StdAfx.h"
|
||||
#include "RaceManager.h"
|
||||
#include "RaceMotionData.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
bool __IsGuildRace(unsigned race)
|
||||
{
|
||||
@@ -237,14 +237,13 @@ bool CRaceManager::__LoadRaceMotionList(CRaceData& rkRaceData, const char* pathN
|
||||
s_kMap_stType_dwIndex.insert(std::map<std::string, DWORD>::value_type("SKILL5", CRaceMotionData::NAME_SKILL+125));
|
||||
}
|
||||
|
||||
const void* pvData;
|
||||
CMappedFile kMappedFile;
|
||||
if (!CEterPackManager::Instance().Get(kMappedFile, motionListFileName, &pvData))
|
||||
TPackFile kMappedFile;
|
||||
if (!CPackManager::Instance().GetFile(motionListFileName, kMappedFile))
|
||||
return false;
|
||||
|
||||
|
||||
CMemoryTextFileLoader kTextFileLoader;
|
||||
kTextFileLoader.Bind(kMappedFile.Size(), pvData);
|
||||
kTextFileLoader.Bind(kMappedFile.size(), kMappedFile.data());
|
||||
|
||||
rkRaceData.RegisterMotionMode(CRaceMotionData::MODE_GENERAL);
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
add_library(PRTerrainLib STATIC ${FILE_SOURCES})
|
||||
|
||||
target_link_libraries(PRTerrainLib
|
||||
lzo2
|
||||
cryptopp-static
|
||||
mio
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(PRTerrainLib)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "Stdafx.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
#include "terrain.h"
|
||||
#include <math.h>
|
||||
@@ -42,7 +42,6 @@ void CTerrainImpl::Initialize()
|
||||
memset(m_lWaterHeight, -1, sizeof(m_lWaterHeight));
|
||||
|
||||
m_byNumWater = 0;
|
||||
memset(&m_HeightMapHeader, 0, sizeof(TGA_HEADER));
|
||||
memset(&m_awShadowMap, 0xFFFF, sizeof(m_awShadowMap));
|
||||
memset(&m_lpAlphaTexture, NULL, sizeof(m_lpAlphaTexture));
|
||||
|
||||
@@ -76,17 +75,16 @@ bool CTerrainImpl::LoadHeightMap(const char*c_szFileName)
|
||||
{
|
||||
Tracef("LoadRawHeightMapFile %s ", c_szFileName);
|
||||
|
||||
CMappedFile kMappedFile;
|
||||
LPCVOID lpcvFileData;
|
||||
TPackFile kMappedFile;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(kMappedFile, c_szFileName, &lpcvFileData))
|
||||
if (!CPackManager::Instance().GetFile( c_szFileName, kMappedFile))
|
||||
{
|
||||
Tracen("Error");
|
||||
TraceError("CTerrainImpl::LoadHeightMap - %s OPEN ERROR", c_szFileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(m_awRawHeightMap, lpcvFileData, sizeof(WORD)*HEIGHTMAP_RAW_XSIZE*HEIGHTMAP_RAW_YSIZE);
|
||||
memcpy(m_awRawHeightMap, kMappedFile.data(), sizeof(WORD) * HEIGHTMAP_RAW_XSIZE * HEIGHTMAP_RAW_YSIZE);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -96,17 +94,16 @@ bool CTerrainImpl::LoadAttrMap(const char *c_szFileName)
|
||||
DWORD dwStart = ELTimer_GetMSec();
|
||||
Tracef("LoadAttrMapFile %s ", c_szFileName);
|
||||
|
||||
CMappedFile kMappedFile;
|
||||
LPCVOID lpcvFileData;
|
||||
TPackFile kMappedFile;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(kMappedFile, c_szFileName, &lpcvFileData))
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, kMappedFile))
|
||||
{
|
||||
TraceError("CTerrainImpl::LoadAttrMap - %s OPEN ERROR", c_szFileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD dwFileSize = kMappedFile.Size();
|
||||
BYTE * abFileData = (BYTE *) lpcvFileData;
|
||||
DWORD dwFileSize = kMappedFile.size();
|
||||
BYTE * abFileData = kMappedFile.data();
|
||||
|
||||
// LoadAttrMap
|
||||
{
|
||||
@@ -168,17 +165,16 @@ bool CTerrainImpl::RAW_LoadTileMap(const char * c_szFileName)
|
||||
{
|
||||
Tracef("LoadSplatFile %s ", c_szFileName);
|
||||
|
||||
CMappedFile kMappedFile;
|
||||
LPCVOID lpcvFileData;
|
||||
TPackFile kMappedFile;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(kMappedFile, c_szFileName, &lpcvFileData))
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, kMappedFile))
|
||||
{
|
||||
Tracen("Error");
|
||||
TraceError("CTerrainImpl::RAW_LoadTileMap - %s OPEN ERROR", c_szFileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(m_abyTileMap, lpcvFileData, sizeof(BYTE)*(TILEMAP_RAW_XSIZE)*(TILEMAP_RAW_YSIZE));
|
||||
memcpy(m_abyTileMap, kMappedFile.data(), sizeof(BYTE) * (TILEMAP_RAW_XSIZE) * (TILEMAP_RAW_YSIZE));
|
||||
|
||||
return true;
|
||||
|
||||
@@ -206,18 +202,17 @@ bool CTerrainImpl::LoadWaterMap(const char * c_szFileName)
|
||||
|
||||
bool CTerrainImpl::LoadWaterMapFile(const char * c_szFileName)
|
||||
{
|
||||
CMappedFile kMappedFile;
|
||||
LPCVOID lpcvFileData;
|
||||
TPackFile kMappedFile;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(kMappedFile, c_szFileName, &lpcvFileData))
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, kMappedFile))
|
||||
{
|
||||
Tracen("Error");
|
||||
TraceError("CTerrainImpl::LoadWaterMap - %s OPEN ERROR", c_szFileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD dwFileSize = kMappedFile.Size();
|
||||
BYTE* abFileData = (BYTE*)lpcvFileData;
|
||||
DWORD dwFileSize = kMappedFile.size();
|
||||
BYTE* abFileData = kMappedFile.data();
|
||||
|
||||
{
|
||||
#pragma pack(push)
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "EterImageLib/TGAImage.h"
|
||||
|
||||
#include "TextureSet.h"
|
||||
#include "TerrainType.h"
|
||||
|
||||
@@ -116,8 +114,6 @@ class CTerrainImpl
|
||||
BYTE m_abyWaterMap[WATERMAP_YSIZE*WATERMAP_XSIZE];
|
||||
CHAR m_acNormalMap[NORMALMAP_YSIZE*NORMALMAP_XSIZE*3];
|
||||
|
||||
TGA_HEADER m_HeightMapHeader;
|
||||
|
||||
WORD m_wTileMapVersion;
|
||||
|
||||
long m_lViewRadius;
|
||||
|
||||
11
src/PackLib/CMakeLists.txt
Normal file
11
src/PackLib/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
file(GLOB_RECURSE FILE_SOURCES "*.h" "*.c" "*.cpp")
|
||||
|
||||
add_library(PackLib STATIC ${FILE_SOURCES})
|
||||
|
||||
target_link_libraries(PackLib
|
||||
libzstd_static
|
||||
cryptopp-static
|
||||
mio
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(PackLib)
|
||||
71
src/PackLib/Pack.cpp
Normal file
71
src/PackLib/Pack.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "Pack.h"
|
||||
#include <zstd.h>
|
||||
|
||||
bool CPack::Open(const std::string& path, TPackFileMap& entries)
|
||||
{
|
||||
std::error_code ec;
|
||||
m_file.map(path, ec);
|
||||
|
||||
if (ec) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t file_size = m_file.size();
|
||||
if (file_size < sizeof(TPackFileHeader)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(&m_header, m_file.data(), sizeof(TPackFileHeader));
|
||||
m_decryption.SetKeyWithIV(PACK_KEY.data(), PACK_KEY.size(), m_header.iv, CryptoPP::Camellia::BLOCKSIZE);
|
||||
|
||||
if (file_size < sizeof(TPackFileHeader) + m_header.entry_num * sizeof(TPackFileEntry)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_header.entry_num; i++) {
|
||||
TPackFileEntry entry;
|
||||
memcpy(&entry, m_file.data() + sizeof(TPackFileHeader) + i * sizeof(TPackFileEntry), sizeof(TPackFileEntry));
|
||||
m_decryption.ProcessData((CryptoPP::byte*)&entry, (CryptoPP::byte*)&entry, sizeof(TPackFileEntry));
|
||||
|
||||
entries[entry.file_name] = std::make_pair(shared_from_this(), entry);
|
||||
|
||||
if (file_size < m_header.data_begin + entry.offset + entry.compressed_size) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPack::GetFile(const TPackFileEntry& entry, TPackFile& result)
|
||||
{
|
||||
result.resize(entry.file_size);
|
||||
|
||||
size_t offset = m_header.data_begin + entry.offset;
|
||||
switch (entry.encryption)
|
||||
{
|
||||
case 0: {
|
||||
size_t decompressed_size = ZSTD_decompress(result.data(), result.size(), m_file.data() + offset, entry.compressed_size);
|
||||
if (decompressed_size != entry.file_size) {
|
||||
return false;
|
||||
}
|
||||
} break;
|
||||
|
||||
case 1: {
|
||||
std::vector<uint8_t> compressed_data(entry.compressed_size);
|
||||
memcpy(compressed_data.data(), m_file.data() + offset, entry.compressed_size);
|
||||
|
||||
m_decryption.Resynchronize(entry.iv, sizeof(entry.iv));
|
||||
m_decryption.ProcessData(compressed_data.data(), compressed_data.data(), entry.compressed_size);
|
||||
|
||||
size_t decompressed_size = ZSTD_decompress(result.data(), result.size(), compressed_data.data(), compressed_data.size());
|
||||
if (decompressed_size != entry.file_size) {
|
||||
return false;
|
||||
}
|
||||
} break;
|
||||
|
||||
default: return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
21
src/PackLib/Pack.h
Normal file
21
src/PackLib/Pack.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <mio/mmap.hpp>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
class CPack : public std::enable_shared_from_this<CPack>
|
||||
{
|
||||
public:
|
||||
CPack() = default;
|
||||
~CPack() = default;
|
||||
|
||||
bool Open(const std::string& path, TPackFileMap& entries);
|
||||
bool GetFile(const TPackFileEntry& entry, TPackFile& result);
|
||||
|
||||
private:
|
||||
TPackFileHeader m_header;
|
||||
mio::mmap_source m_file;
|
||||
|
||||
CryptoPP::CTR_Mode<CryptoPP::Camellia>::Decryption m_decryption;
|
||||
};
|
||||
40
src/PackLib/PackManager.cpp
Normal file
40
src/PackLib/PackManager.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "PackManager.h"
|
||||
|
||||
bool CPackManager::AddPack(const std::string& path)
|
||||
{
|
||||
std::shared_ptr<CPack> pack = std::make_shared<CPack>();
|
||||
return pack->Open(path, m_entries);
|
||||
}
|
||||
|
||||
bool CPackManager::GetFile(std::string_view path, TPackFile& result)
|
||||
{
|
||||
thread_local std::string buf;
|
||||
NormalizePath(path, buf);
|
||||
|
||||
auto it = m_entries.find(buf);
|
||||
if (it != m_entries.end()) {
|
||||
return it->second.first->GetFile(it->second.second, result);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPackManager::IsExist(std::string_view path) const
|
||||
{
|
||||
thread_local std::string buf;
|
||||
NormalizePath(path, buf);
|
||||
|
||||
auto it = m_entries.find(buf);
|
||||
return it != m_entries.end();
|
||||
}
|
||||
|
||||
void CPackManager::NormalizePath(std::string_view in, std::string& out) const
|
||||
{
|
||||
out.resize(in.size());
|
||||
for (std::size_t i = 0; i < out.size(); ++i) {
|
||||
if (in[i] == '\\')
|
||||
out[i] = '/';
|
||||
else
|
||||
out[i] = static_cast<char>(std::tolower(in[i]));
|
||||
}
|
||||
}
|
||||
22
src/PackLib/PackManager.h
Normal file
22
src/PackLib/PackManager.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <unordered_map>
|
||||
|
||||
#include "EterBase/Singleton.h"
|
||||
#include "Pack.h"
|
||||
|
||||
class CPackManager : public CSingleton<CPackManager>
|
||||
{
|
||||
public:
|
||||
CPackManager() = default;
|
||||
virtual ~CPackManager() = default;
|
||||
|
||||
bool AddPack(const std::string& path);
|
||||
bool GetFile(std::string_view path, TPackFile& result);
|
||||
bool IsExist(std::string_view path) const;
|
||||
|
||||
private:
|
||||
void NormalizePath(std::string_view in, std::string& out) const;
|
||||
|
||||
private:
|
||||
TPackFileMap m_entries;
|
||||
};
|
||||
43
src/PackLib/config.h
Normal file
43
src/PackLib/config.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <gcm.h>
|
||||
#include <modes.h>
|
||||
#include <osrng.h>
|
||||
#include <secblock.h>
|
||||
#include <camellia.h>
|
||||
|
||||
constexpr std::array<uint8_t, 32> PACK_KEY = {
|
||||
0x00,0x11,0x22,0x33, 0x44,0x55,0x66,0x77,
|
||||
0x88,0x99,0xAA,0xBB, 0xCC,0xDD,0xEE,0xFF,
|
||||
0x01,0x23,0x45,0x67, 0x89,0xAB,0xCD,0xEF,
|
||||
0xFE,0xDC,0xBA,0x98, 0x76,0x54,0x32,0x10
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct TPackFileHeader
|
||||
{
|
||||
uint64_t entry_num;
|
||||
uint64_t data_begin;
|
||||
uint8_t iv[CryptoPP::Camellia::BLOCKSIZE];
|
||||
};
|
||||
struct TPackFileEntry
|
||||
{
|
||||
char file_name[FILENAME_MAX+1];
|
||||
uint64_t offset;
|
||||
uint64_t file_size;
|
||||
uint64_t compressed_size;
|
||||
uint8_t encryption;
|
||||
uint8_t iv[CryptoPP::Camellia::BLOCKSIZE];
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
class CPack;
|
||||
using TPackFile = std::vector<uint8_t>;
|
||||
using TPackFileMapEntry = std::pair<std::shared_ptr<CPack>, TPackFileEntry>;
|
||||
using TPackFileMap = std::unordered_map<std::string, TPackFileMapEntry>;
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -7,36 +6,7 @@
|
||||
#include <zstd.h>
|
||||
#include <argparse.hpp>
|
||||
|
||||
#include <gcm.h>
|
||||
#include <modes.h>
|
||||
#include <osrng.h>
|
||||
#include <secblock.h>
|
||||
#include <camellia.h>
|
||||
|
||||
constexpr std::array<uint8_t, 32> PACK_KEY = {
|
||||
0x00,0x11,0x22,0x33, 0x44,0x55,0x66,0x77,
|
||||
0x88,0x99,0xAA,0xBB, 0xCC,0xDD,0xEE,0xFF,
|
||||
0x01,0x23,0x45,0x67, 0x89,0xAB,0xCD,0xEF,
|
||||
0xFE,0xDC,0xBA,0x98, 0x76,0x54,0x32,0x10
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct TPackFileHeader
|
||||
{
|
||||
uint64_t entry_num;
|
||||
uint64_t data_begin;
|
||||
uint8_t iv[CryptoPP::Camellia::BLOCKSIZE];
|
||||
};
|
||||
struct TPackFileEntry
|
||||
{
|
||||
char file_name[FILENAME_MAX];
|
||||
uint64_t offset;
|
||||
uint64_t file_size;
|
||||
uint64_t compressed_size;
|
||||
uint8_t encryption;
|
||||
uint8_t iv[CryptoPP::Camellia::BLOCKSIZE];
|
||||
};
|
||||
#pragma pack(pop)
|
||||
#include "PackLib/config.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
@@ -110,7 +80,7 @@ int main(int argc, char* argv[])
|
||||
CryptoPP::CTR_Mode<CryptoPP::Camellia>::Encryption encryption;
|
||||
encryption.SetKeyWithIV(PACK_KEY.data(), PACK_KEY.size(), header.iv, CryptoPP::Camellia::BLOCKSIZE);
|
||||
|
||||
uint64_t offset = header.data_begin;
|
||||
uint64_t offset = 0;
|
||||
for (auto& [path, entry] : entries) {
|
||||
std::ifstream ifs(input / path, std::ios::binary);
|
||||
if (!ifs.is_open()) {
|
||||
@@ -151,18 +121,14 @@ int main(int argc, char* argv[])
|
||||
offset += entry.compressed_size;
|
||||
}
|
||||
|
||||
std::vector<char> entry_buffer(sizeof(TPackFileEntry) * entries.size());
|
||||
char* ptr = entry_buffer.data();
|
||||
ofs.seekp(sizeof(TPackFileHeader), std::ios::beg);
|
||||
encryption.Resynchronize(header.iv, sizeof(header.iv));
|
||||
|
||||
for (auto& [path, entry] : entries) {
|
||||
memcpy(ptr, &entry, sizeof(entry));
|
||||
ptr += sizeof(entry);
|
||||
TPackFileEntry tmp = entry;
|
||||
encryption.ProcessData((uint8_t*)&tmp, (uint8_t*)&tmp, sizeof(TPackFileEntry));
|
||||
ofs.write((const char*)&tmp, sizeof(TPackFileEntry));
|
||||
}
|
||||
|
||||
encryption.Resynchronize(header.iv, sizeof(header.iv));
|
||||
encryption.ProcessData((uint8_t*)entry_buffer.data(), (uint8_t*)entry_buffer.data(), entry_buffer.size());
|
||||
|
||||
ofs.seekp(sizeof(TPackFileHeader), std::ios::beg);
|
||||
ofs.write(entry_buffer.data(), entry_buffer.size());
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
add_library(ScriptLib STATIC ${FILE_SOURCES})
|
||||
|
||||
target_link_libraries(ScriptLib
|
||||
lzo2
|
||||
cryptopp-static
|
||||
mio
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(ScriptLib)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#undef BYTE
|
||||
#endif
|
||||
|
||||
#include "eterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
#include "PythonLauncher.h"
|
||||
|
||||
@@ -232,29 +232,13 @@ bool CPythonLauncher::RunMemoryTextFile(const char* c_szFileName, UINT uFileSize
|
||||
|
||||
bool CPythonLauncher::RunFile(const char* c_szFileName)
|
||||
{
|
||||
char* acBufData=NULL;
|
||||
DWORD dwBufSize=0;
|
||||
|
||||
{
|
||||
CMappedFile file;
|
||||
const VOID* pvData;
|
||||
CEterPackManager::Instance().Get(file, c_szFileName, &pvData);
|
||||
TPackFile file;
|
||||
CPackManager::Instance().GetFile(c_szFileName, file);
|
||||
|
||||
dwBufSize=file.Size();
|
||||
if (dwBufSize==0)
|
||||
return false;
|
||||
if (file.empty())
|
||||
return false;
|
||||
|
||||
acBufData=new char[dwBufSize];
|
||||
memcpy(acBufData, pvData, dwBufSize);
|
||||
}
|
||||
|
||||
bool ret=false;
|
||||
|
||||
ret=RunMemoryTextFile(c_szFileName, dwBufSize, acBufData);
|
||||
|
||||
delete [] acBufData;
|
||||
|
||||
return ret;
|
||||
return RunMemoryTextFile(c_szFileName, file.size(), file.data());
|
||||
}
|
||||
|
||||
bool CPythonLauncher::RunLine(const char* c_szSrc)
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
add_library(SpeedTreeLib STATIC ${FILE_SOURCES})
|
||||
|
||||
target_link_libraries(SpeedTreeLib
|
||||
lzo2
|
||||
cryptopp-static
|
||||
mio
|
||||
)
|
||||
|
||||
GroupSourcesByFolder(SpeedTreeLib)
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include "EterBase/Filename.h"
|
||||
|
||||
#include "EterBase/MappedFile.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
#include "SpeedTreeForest.h"
|
||||
#include "SpeedTreeConfig.h"
|
||||
@@ -84,23 +82,20 @@ BOOL CSpeedTreeForest::GetMainTree(DWORD dwCRC, SpeedTreeWrapperPtr &ppMainTree,
|
||||
pTree = itor->second;
|
||||
else
|
||||
{
|
||||
CMappedFile file;
|
||||
LPCVOID c_pvData;
|
||||
TPackFile file;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData))
|
||||
if (!CPackManager::Instance().GetFile(c_pszFileName, file))
|
||||
return FALSE;
|
||||
|
||||
pTree = std::make_shared<CSpeedTreeWrapper>();
|
||||
|
||||
if (!pTree->LoadTree(c_pszFileName, (const BYTE *) c_pvData, file.Size()))
|
||||
if (!pTree->LoadTree(c_pszFileName, (const BYTE *)file.data(), file.size()))
|
||||
{
|
||||
pTree.reset();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_pMainTreeMap.insert(std::map<DWORD, SpeedTreeWrapperPtr>::value_type(dwCRC, pTree));
|
||||
|
||||
file.Destroy();
|
||||
}
|
||||
|
||||
ppMainTree = pTree;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "Packet.h"
|
||||
#include "PythonNetworkStream.h"
|
||||
#include "EterBase/tea.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
// CHINA_CRYPT_KEY
|
||||
extern DWORD g_adwEncryptKey[4];
|
||||
@@ -288,7 +288,6 @@ bool CAccountConnector::__AuthState_RecvPanamaPack()
|
||||
if (!Recv(sizeof(TPacketGCPanamaPack), &kPacket))
|
||||
return false;
|
||||
|
||||
CEterPackManager::instance().RegisterPack(kPacket.szPackName, "*", kPacket.abIV);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -304,7 +303,6 @@ bool CAccountConnector::__AuthState_RecvHybridCryptKeys(int iTotalSize)
|
||||
if (!Recv(kPacket.iKeyStreamLen, kPacket.m_pStream))
|
||||
return false;
|
||||
|
||||
CEterPackManager::Instance().RetrieveHybridCryptPackKeys( kPacket.m_pStream );
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -320,7 +318,6 @@ bool CAccountConnector::__AuthState_RecvHybridCryptSDB(int iTotalSize)
|
||||
if (!Recv(kPacket.iSDBStreamLen, kPacket.m_pStream))
|
||||
return false;
|
||||
|
||||
CEterPackManager::Instance().RetrieveHybridCryptPackSDB( kPacket.m_pStream );
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -363,7 +360,6 @@ bool CAccountConnector::__AuthState_RecvAuthSuccess()
|
||||
else
|
||||
{
|
||||
DWORD dwPanamaKey = kAuthSuccessPacket.dwLoginKey ^ g_adwEncryptKey[0] ^ g_adwEncryptKey[1] ^ g_adwEncryptKey[2] ^ g_adwEncryptKey[3];
|
||||
CEterPackManager::instance().DecryptPackIV(dwPanamaKey);
|
||||
|
||||
CPythonNetworkStream & rkNet = CPythonNetworkStream::Instance();
|
||||
rkNet.SetLoginKey(kAuthSuccessPacket.dwLoginKey);
|
||||
|
||||
@@ -17,17 +17,18 @@ target_link_libraries(UserInterface
|
||||
EterImageLib
|
||||
EterLib
|
||||
EterLocale
|
||||
EterPack
|
||||
EterPythonLib
|
||||
GameLib
|
||||
PRTerrainLib
|
||||
ScriptLib
|
||||
SpeedTreeLib
|
||||
SphereLib
|
||||
PackLib
|
||||
|
||||
cryptopp-static
|
||||
lzo2
|
||||
libzstd_static
|
||||
mio
|
||||
|
||||
DirectX
|
||||
Granny
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "PythonApplication.h"
|
||||
#include "resource.h"
|
||||
#include "EterBase/CRC32.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "EterLocale/Japanese.h"
|
||||
#include <windowsx.h>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "MarkImage.h"
|
||||
#include "EterBase/lzo.h"
|
||||
|
||||
#include <stb_image.h>
|
||||
#include <stb_image_write.h>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Resource.h"
|
||||
#include "PythonApplication.h"
|
||||
#include "EterLib/Camera.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
#include <stb_image.h>
|
||||
|
||||
@@ -339,15 +340,13 @@ PyObject* appGetImageInfo(PyObject* poSelf, PyObject* poArgs)
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "EterPack/EterPackManager.h"
|
||||
|
||||
PyObject* appIsExistFile(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
char* szFileName;
|
||||
if (!PyTuple_GetString(poArgs, 0, &szFileName))
|
||||
return Py_BuildException();
|
||||
|
||||
bool isExist=CEterPackManager::Instance().isExist(szFileName);
|
||||
bool isExist=CPackManager::Instance().IsExist(szFileName);
|
||||
|
||||
return Py_BuildValue("i", isExist);
|
||||
}
|
||||
@@ -1021,12 +1020,11 @@ class CTextLineLoader
|
||||
public:
|
||||
CTextLineLoader(const char * c_szFileName)
|
||||
{
|
||||
const VOID* pvData;
|
||||
CMappedFile kFile;
|
||||
if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData))
|
||||
TPackFile kFile;
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, kFile))
|
||||
return;
|
||||
|
||||
m_kTextFileLoader.Bind(kFile.Size(), pvData);
|
||||
m_kTextFileLoader.Bind(kFile.size(), kFile.data());
|
||||
}
|
||||
|
||||
DWORD GetLineCount()
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "EterLib/CullingManager.h"
|
||||
#include "EterLib/Camera.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
#include "GameLib/MapOutDoor.h"
|
||||
#include "GameLib/PropertyLoader.h"
|
||||
|
||||
@@ -241,19 +241,7 @@ void CPythonBackground::Initialize()
|
||||
|
||||
void CPythonBackground::__CreateProperty()
|
||||
{
|
||||
if (CEterPackManager::SEARCH_FILE_FIRST == CEterPackManager::Instance().GetSearchMode() &&
|
||||
_access("property", 0) == 0)
|
||||
{
|
||||
m_PropertyManager.Initialize(NULL);
|
||||
|
||||
CPropertyLoader PropertyLoader;
|
||||
PropertyLoader.SetPropertyManager(&m_PropertyManager);
|
||||
PropertyLoader.Create("*.*", "Property");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_PropertyManager.Initialize("pack/property");
|
||||
}
|
||||
m_PropertyManager.Initialize("pack/property.pck");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "PythonEventManager.h"
|
||||
#include "PythonNetworkStream.h"
|
||||
#include "PythonNonPlayer.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
#include "PythonMiniMap.h"
|
||||
#include "AbstractApplication.h"
|
||||
|
||||
@@ -104,16 +104,14 @@ void CPythonEventManager::__InitEventSet(TEventSet& rEventSet)
|
||||
|
||||
int CPythonEventManager::RegisterEventSet(const char * c_szFileName)
|
||||
{
|
||||
CMappedFile File;
|
||||
LPCVOID pMap;
|
||||
TPackFile File;
|
||||
|
||||
if (!CEterPackManager::Instance().Get(File, c_szFileName, &pMap))
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, File))
|
||||
return -1;
|
||||
|
||||
std::string strEventString;
|
||||
strEventString.resize(File.Size()+1);
|
||||
|
||||
File.Read(&strEventString[0], File.Size());
|
||||
strEventString.resize(File.size() + 1);
|
||||
memcpy(strEventString.data(), File.data(), File.size());
|
||||
|
||||
TEventSet * pEventSet = m_EventSetPool.Alloc();
|
||||
if (!pEventSet)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "EterLib/StateManager.h"
|
||||
#include "EterLib/GrpSubImage.h"
|
||||
#include "EterLib/Camera.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
#include "PythonMiniMap.h"
|
||||
#include "PythonBackground.h"
|
||||
@@ -878,7 +878,7 @@ bool CPythonMiniMap::LoadAtlas()
|
||||
|
||||
char atlasFileName[1024+1];
|
||||
snprintf(atlasFileName, sizeof(atlasFileName), "%s/atlas.sub", rkMap.GetName().c_str());
|
||||
if (!CEterPackManager::Instance().isExist(atlasFileName))
|
||||
if (!CPackManager::Instance().IsExist(atlasFileName))
|
||||
{
|
||||
snprintf(atlasFileName, sizeof(atlasFileName), "d:/ymir work/ui/atlas/%s/atlas.sub", rkMap.GetName().c_str());
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include "PythonMessenger.h"
|
||||
#include "PythonApplication.h"
|
||||
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "GameLib/ItemManager.h"
|
||||
|
||||
#include "AbstractApplication.h"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "PythonNetworkStream.h"
|
||||
#include "PythonApplication.h"
|
||||
#include "Packet.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
// HandShake ---------------------------------------------------------------------------
|
||||
void CPythonNetworkStream::HandShakePhase()
|
||||
@@ -173,7 +173,6 @@ bool CPythonNetworkStream::RecvHybridCryptKeyPacket()
|
||||
if (!Recv(kPacket.iKeyStreamLen, kPacket.m_pStream))
|
||||
return false;
|
||||
|
||||
CEterPackManager::Instance().RetrieveHybridCryptPackKeys( kPacket.m_pStream );
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -193,7 +192,6 @@ bool CPythonNetworkStream::RecvHybridCryptSDBPacket()
|
||||
if (!Recv(kPacket.iSDBStreamLen, kPacket.m_pStream))
|
||||
return false;
|
||||
|
||||
CEterPackManager::Instance().RetrieveHybridCryptPackSDB( kPacket.m_pStream );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
#include "Packet.h"
|
||||
#include "PythonApplication.h"
|
||||
#include "NetworkActorManager.h"
|
||||
|
||||
#include "AbstractPlayer.h"
|
||||
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
|
||||
void CPythonNetworkStream::EnableChatInsultFilter(bool isEnable)
|
||||
{
|
||||
@@ -33,13 +31,12 @@ bool CPythonNetworkStream::IsInsultIn(const char* c_szMsg)
|
||||
|
||||
bool CPythonNetworkStream::LoadInsultList(const char* c_szInsultListFileName)
|
||||
{
|
||||
CMappedFile file;
|
||||
const VOID* pvData;
|
||||
if (!CEterPackManager::Instance().Get(file, c_szInsultListFileName, &pvData))
|
||||
TPackFile file;
|
||||
if (!CPackManager::Instance().GetFile(c_szInsultListFileName, file))
|
||||
return false;
|
||||
|
||||
CMemoryTextFileLoader kMemTextFileLoader;
|
||||
kMemTextFileLoader.Bind(file.Size(), pvData);
|
||||
kMemTextFileLoader.Bind(file.size(), file.data());
|
||||
|
||||
m_kInsultChecker.Clear();
|
||||
for (DWORD dwLineIndex=0; dwLineIndex<kMemTextFileLoader.GetLineCount(); ++dwLineIndex)
|
||||
@@ -55,9 +52,8 @@ bool CPythonNetworkStream::LoadConvertTable(DWORD dwEmpireID, const char* c_szFi
|
||||
if (dwEmpireID<1 || dwEmpireID>=4)
|
||||
return false;
|
||||
|
||||
CMappedFile file;
|
||||
const VOID* pvData;
|
||||
if (!CEterPackManager::Instance().Get(file, c_szFileName, &pvData))
|
||||
TPackFile file;
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, file))
|
||||
return false;
|
||||
|
||||
DWORD dwEngCount=26;
|
||||
@@ -65,10 +61,10 @@ bool CPythonNetworkStream::LoadConvertTable(DWORD dwEmpireID, const char* c_szFi
|
||||
DWORD dwHanSize=dwHanCount*2;
|
||||
DWORD dwFileSize=dwEngCount*2+dwHanSize;
|
||||
|
||||
if (file.Size()<dwFileSize)
|
||||
if (file.size()<dwFileSize)
|
||||
return false;
|
||||
|
||||
char* pcData=(char*)pvData;
|
||||
char* pcData=(char*)file.data();
|
||||
|
||||
STextConvertTable& rkTextConvTable=m_aTextConvTable[dwEmpireID-1];
|
||||
memcpy(rkTextConvTable.acUpper, pcData, dwEngCount);pcData+=dwEngCount;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "EterBase/lzo.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
#include "pythonnonplayer.h"
|
||||
#include "InstanceBase.h"
|
||||
#include "PythonCharacterManager.h"
|
||||
@@ -14,17 +15,15 @@ bool CPythonNonPlayer::LoadNonPlayerData(const char * c_szFileName)
|
||||
6822045
|
||||
};
|
||||
|
||||
CMappedFile file;
|
||||
LPCVOID pvData;
|
||||
TPackFile file;
|
||||
|
||||
Tracef("CPythonNonPlayer::LoadNonPlayerData: %s, sizeof(TMobTable)=%u\n", c_szFileName, sizeof(TMobTable));
|
||||
|
||||
if (!CEterPackManager::Instance().Get(file, c_szFileName, &pvData))
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, file))
|
||||
return false;
|
||||
|
||||
DWORD dwFourCC, dwElements, dwDataSize;
|
||||
|
||||
file.Read(&dwFourCC, sizeof(DWORD));
|
||||
memcpy(&dwFourCC, file.data(), sizeof(DWORD));
|
||||
|
||||
if (dwFourCC != MAKEFOURCC('M', 'M', 'P', 'T'))
|
||||
{
|
||||
@@ -32,11 +31,11 @@ bool CPythonNonPlayer::LoadNonPlayerData(const char * c_szFileName)
|
||||
return false;
|
||||
}
|
||||
|
||||
file.Read(&dwElements, sizeof(DWORD));
|
||||
file.Read(&dwDataSize, sizeof(DWORD));
|
||||
memcpy(&dwElements, file.data() + sizeof(DWORD), sizeof(DWORD));
|
||||
memcpy(&dwDataSize, file.data() + sizeof(DWORD) * 2, sizeof(DWORD));
|
||||
|
||||
BYTE * pbData = new BYTE[dwDataSize];
|
||||
file.Read(pbData, dwDataSize);
|
||||
memcpy(pbData, file.data() + sizeof(DWORD) * 3, dwDataSize);
|
||||
/////
|
||||
|
||||
CLZObject zObj;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "StdAfx.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
#include "EterBase/tea.h"
|
||||
|
||||
// CHINA_CRYPT_KEY
|
||||
@@ -45,7 +45,7 @@ PyObject * packExist(PyObject * poSelf, PyObject * poArgs)
|
||||
if (!PyTuple_GetString(poArgs, 0, &strFileName))
|
||||
return Py_BuildException();
|
||||
|
||||
return Py_BuildValue("i", CEterPackManager::Instance().isExist(strFileName)?1:0);
|
||||
return Py_BuildValue("i", CPackManager::Instance().IsExist(strFileName) ? 1 : 0);
|
||||
}
|
||||
|
||||
PyObject * packGet(PyObject * poSelf, PyObject * poArgs)
|
||||
@@ -63,11 +63,9 @@ PyObject * packGet(PyObject * poSelf, PyObject * poArgs)
|
||||
(stricmp(pcExt, ".pyc") == 0) ||
|
||||
(stricmp(pcExt, ".txt") == 0))
|
||||
{
|
||||
CMappedFile file;
|
||||
const void * pData = NULL;
|
||||
|
||||
if (CEterPackManager::Instance().Get(file,strFileName,&pData))
|
||||
return Py_BuildValue("s#",pData, file.Size());
|
||||
TPackFile file;
|
||||
if (CPackManager::Instance().GetFile(strFileName, file))
|
||||
return Py_BuildValue("s#",file.data(), file.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "PythonSkill.h"
|
||||
|
||||
#include "EterBase/Poly/Poly.h"
|
||||
#include "EterPack/EterPackManager.h"
|
||||
#include "PackLib/PackManager.h"
|
||||
#include "InstanceBase.h"
|
||||
#include "PythonPlayer.h"
|
||||
|
||||
@@ -89,13 +89,12 @@ void string_replace_word(const char* base, int base_len, const char* src, int sr
|
||||
|
||||
bool CPythonSkill::RegisterSkillTable(const char * c_szFileName)
|
||||
{
|
||||
const VOID* pvData;
|
||||
CMappedFile kFile;
|
||||
if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData))
|
||||
TPackFile kFile;
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, kFile))
|
||||
return false;
|
||||
|
||||
CMemoryTextFileLoader textFileLoader;
|
||||
textFileLoader.Bind(kFile.Size(), pvData);
|
||||
textFileLoader.Bind(kFile.size(), kFile.data());
|
||||
|
||||
// OVERWRITE_SKILLPROTO_POLY
|
||||
std::string src_poly_rand;
|
||||
@@ -279,13 +278,12 @@ void CPythonSkill::__RegisterNormalIconImage(TSkillData & rData, const char * c_
|
||||
extern const DWORD c_iSkillIndex_Riding;
|
||||
bool CPythonSkill::RegisterSkillDesc(const char * c_szFileName)
|
||||
{
|
||||
const VOID* pvData;
|
||||
CMappedFile kFile;
|
||||
if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData))
|
||||
TPackFile kFile;
|
||||
if (!CPackManager::Instance().GetFile(c_szFileName, kFile))
|
||||
return false;
|
||||
|
||||
CMemoryTextFileLoader textFileLoader;
|
||||
textFileLoader.Bind(kFile.Size(), pvData);
|
||||
textFileLoader.Bind(kFile.size(), kFile.data());
|
||||
|
||||
CTokenVector TokenVector;
|
||||
for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i)
|
||||
|
||||
@@ -9,9 +9,12 @@
|
||||
#include <crtdbg.h>
|
||||
#endif
|
||||
|
||||
#include "eterPack/EterPackManager.h"
|
||||
#include "eterLib/Util.h"
|
||||
#include "eterBase/CPostIt.h"
|
||||
#include "EterBase/lzo.h"
|
||||
|
||||
#include "PackLib/PackManager.h"
|
||||
#include <filesystem>
|
||||
|
||||
extern "C" {
|
||||
extern int _fltused;
|
||||
@@ -136,73 +139,124 @@ bool PackInitialize(const char * c_pszFolder)
|
||||
if (_access(c_pszFolder, 0) != 0)
|
||||
return false;
|
||||
|
||||
std::string stFolder(c_pszFolder);
|
||||
stFolder += "/";
|
||||
std::vector<std::string> packFiles = {
|
||||
"patch1",
|
||||
"season3_eu",
|
||||
"patch2",
|
||||
"metin2_patch_snow",
|
||||
"metin2_patch_snow_dungeon",
|
||||
"metin2_patch_etc_costume1",
|
||||
"metin2_patch_pet1",
|
||||
"metin2_patch_pet2",
|
||||
"metin2_patch_ramadan_costume",
|
||||
"metin2_patch_flame",
|
||||
"metin2_patch_flame_dungeon",
|
||||
"metin2_patch_w21_etc",
|
||||
"metin2_patch_w21_mobs",
|
||||
"metin2_patch_w21_mobs_m",
|
||||
"metin2_patch_dss_box",
|
||||
"metin2_patch_costume_soccer",
|
||||
"metin2_patch_easter1",
|
||||
"metin2_patch_mineral",
|
||||
"metin2_patch_w20_sound",
|
||||
"metin2_patch_ds",
|
||||
"metin2_patch_5th_armor",
|
||||
"metin2_patch_w20_etc",
|
||||
"metin2_patch_dragon_rock",
|
||||
"metin2_patch_dragon_rock_mobs",
|
||||
"metin2_patch_etc",
|
||||
"metin2_patch_xmas",
|
||||
"metin2_patch_eu3",
|
||||
"metin2_patch_eu4",
|
||||
"metin2_patch_mundi",
|
||||
"metin2_patch_sd",
|
||||
"metin2_patch_halloween",
|
||||
"metin2_patch_party",
|
||||
"metin2_patch_dance",
|
||||
"pc",
|
||||
"pc2",
|
||||
"monster",
|
||||
"monster2",
|
||||
"effect",
|
||||
"zone",
|
||||
"terrain",
|
||||
"npc",
|
||||
"npc2",
|
||||
"tree",
|
||||
"guild",
|
||||
"item",
|
||||
"textureset",
|
||||
"property",
|
||||
"icon",
|
||||
"season1",
|
||||
"season2",
|
||||
"outdoora1",
|
||||
"outdoora2",
|
||||
"outdoora3",
|
||||
"outdoorb1",
|
||||
"outdoorb3",
|
||||
"outdoorc1",
|
||||
"outdoorc3",
|
||||
"outdoorsnow1",
|
||||
"outdoordesert1",
|
||||
"outdoorflame1",
|
||||
"outdoorfielddungeon1",
|
||||
"outdoort1",
|
||||
"outdoort2",
|
||||
"outdoort3",
|
||||
"outdoort4",
|
||||
"outdoorwedding",
|
||||
"outdoormilgyo1",
|
||||
"indoorspiderdungeon1",
|
||||
"indoordeviltower1",
|
||||
"indoormonkeydungeon1",
|
||||
"indoormonkeydungeon2",
|
||||
"indoormonkeydungeon3",
|
||||
"outdoortrent",
|
||||
"outdoortrent02",
|
||||
"outdoorguild1",
|
||||
"outdoorguild2",
|
||||
"outdoorguild3",
|
||||
"outdoorduel",
|
||||
"outdoorgmguildbuild",
|
||||
"sound",
|
||||
"sound_m",
|
||||
"sound2",
|
||||
"bgm",
|
||||
"locale_ca",
|
||||
"locale_ae",
|
||||
"locale_de",
|
||||
"locale_es",
|
||||
"locale_fr",
|
||||
"locale_gr",
|
||||
"locale_it",
|
||||
"locale_nl",
|
||||
"locale_pl",
|
||||
"locale_pt",
|
||||
"locale_tr",
|
||||
"locale_uk",
|
||||
"locale_bg",
|
||||
"locale_en",
|
||||
"locale_mx",
|
||||
"locale_ro",
|
||||
"locale_ru",
|
||||
"locale_dk",
|
||||
"locale_cz",
|
||||
"locale_hu",
|
||||
"locale_us",
|
||||
"locale_pa",
|
||||
"uiscript",
|
||||
"ETC",
|
||||
"uiloading",
|
||||
};
|
||||
|
||||
std::string stFileName(stFolder);
|
||||
stFileName += "Index";
|
||||
std::filesystem::path folderPath = c_pszFolder;
|
||||
|
||||
CMappedFile file;
|
||||
LPCVOID pvData;
|
||||
|
||||
if (!file.Create(stFileName.c_str(), &pvData, 0, 0))
|
||||
{
|
||||
LogBoxf("FATAL ERROR! File not exist: %s", stFileName.c_str());
|
||||
TraceError("FATAL ERROR! File not exist: %s", stFileName.c_str());
|
||||
return true;
|
||||
CPackManager::instance().AddPack((folderPath / "root.pck").generic_string());
|
||||
for (const std::string& packFileName : packFiles) {
|
||||
CPackManager::instance().AddPack((folderPath / (packFileName + ".pck")).generic_string());
|
||||
}
|
||||
|
||||
CMemoryTextFileLoader TextLoader;
|
||||
TextLoader.Bind(file.Size(), pvData);
|
||||
|
||||
bool bPackFirst = TRUE;
|
||||
|
||||
const std::string& strPackType = TextLoader.GetLineString(0);
|
||||
|
||||
if (strPackType.compare("FILE") && strPackType.compare("PACK"))
|
||||
{
|
||||
TraceError("Pack/Index has invalid syntax. First line must be 'PACK' or 'FILE'");
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef _DISTRIBUTE
|
||||
Tracef("알림: 팩 모드입니다.\n");
|
||||
|
||||
//if (0 == strPackType.compare("FILE"))
|
||||
//{
|
||||
// bPackFirst = FALSE;
|
||||
// Tracef("알림: 파일 모드입니다.\n");
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// Tracef("알림: 팩 모드입니다.\n");
|
||||
//}
|
||||
#else
|
||||
bPackFirst = FALSE;
|
||||
Tracef("알림: 파일 모드입니다.\n");
|
||||
#endif
|
||||
|
||||
CTextFileLoader::SetCacheMode();
|
||||
#if defined(USE_RELATIVE_PATH)
|
||||
CEterPackManager::Instance().SetRelativePathMode();
|
||||
#endif
|
||||
CEterPackManager::Instance().SetCacheMode();
|
||||
CEterPackManager::Instance().SetSearchMode(bPackFirst);
|
||||
|
||||
std::string strPackName, strTexCachePackName;
|
||||
for (DWORD i = 1; i < TextLoader.GetLineCount() - 1; i += 2)
|
||||
{
|
||||
const std::string & c_rstFolder = TextLoader.GetLineString(i);
|
||||
const std::string & c_rstName = TextLoader.GetLineString(i + 1);
|
||||
|
||||
strPackName = stFolder + c_rstName;
|
||||
strTexCachePackName = strPackName + "_texcache";
|
||||
|
||||
CEterPackManager::Instance().RegisterPack(strPackName.c_str(), c_rstFolder.c_str());
|
||||
CEterPackManager::Instance().RegisterPack(strTexCachePackName.c_str(), c_rstFolder.c_str());
|
||||
}
|
||||
|
||||
CEterPackManager::Instance().RegisterRootPack((stFolder + std::string("root")).c_str());
|
||||
NANOEND
|
||||
return true;
|
||||
}
|
||||
@@ -362,7 +416,7 @@ bool Main(HINSTANCE hInstance, LPSTR lpCmdLine)
|
||||
#endif
|
||||
|
||||
static CLZO lzo;
|
||||
static CEterPackManager EterPackManager;
|
||||
CPackManager packMgr;
|
||||
|
||||
if (!PackInitialize("pack"))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user