Compare commits

..

1 Commits

Author SHA1 Message Date
609862f222 Cleaned up project, added configuration utility
Reviewed-on: #12
2024-12-14 20:54:06 +02:00
65 changed files with 4314 additions and 762 deletions

1
bin/.gitignore vendored
View File

@ -18,7 +18,6 @@ syserr.txt
# Game files
pack/*.eix
pack/*.epk
pack/*.zip
# Guild images
mark/

View File

@ -1,15 +0,0 @@
@echo off
setlocal enabledelayedexpansion
FOR /d %%i IN ("*") DO (
echo Packing %%i
rem "C:\Program Files\7-Zip\7z.exe" a "%%i.zip" ".\%%i\*" -m0=BZip2
rem "C:\Program Files\7-Zip-Zstandard\7za.exe" a "%%i.zip" ".\%%i\*" -m0=Zstd
"C:\Program Files\7-Zip\7z.exe" a "%%i.zip" ".\%%i\*" -m0=Copy
rem "C:\Program Files\7-Zip\7z.exe" a "%%i.zip" ".\%%i\*"
if !errorlevel! neq 0 exit /b !errorlevel!
cls
)
pause

View File

@ -3,7 +3,7 @@
#include <d3d9.h>
#include <algorithm>
#include <vector>
#include <math.h>
#define APP_NAME _T("Metin2 Config")
#define FILENAME_CONFIG "metin2.cfg"
@ -164,24 +164,12 @@ BOOL CMainDialog::OnInitDialog(CWindow wndFocus, LPARAM lInitParam)
m_comboShadow.SetCurSel(m_stConfig.iShadowLevel);
// Language
// Load the languages into an array
std::vector<ATL::CString> languages;
ATL::CString language;
for (int i = 0; i < kLanguageMax; ++i) {
ATL::CString language;
language.LoadString(kLanguageConfig[i].stringId);
languages.push_back(language);
m_comboLanguage.InsertString(i, language);
}
// Sort the array
std::sort(languages.begin(), languages.end(), [](const ATL::CString& a, const ATL::CString& b) {
return a.CompareNoCase(b) < 0;
});
// Add the languages to the combo
for (auto& language : languages)
m_comboLanguage.AddString(language);
m_stConfig.language = std::clamp((int) m_stConfig.language, 0, kLanguageMax - 1);
m_comboLanguage.SetCurSel(m_stConfig.language);
@ -241,66 +229,10 @@ void CMainDialog::InitDefaultConfig()
auto lang = PRIMARYLANGID(LANGIDFROMLCID(GetUserDefaultLCID()));
switch (lang) {
case LANG_CZECH:
m_stConfig.language = kLanguageCzech;
break;
case LANG_DANISH:
m_stConfig.language = kLanguageDanish;
break;
case LANG_DUTCH:
m_stConfig.language = kLanguageDutch;
break;
case LANG_ENGLISH:
m_stConfig.language = kLanguageEnglish;
break;
case LANG_FRENCH:
m_stConfig.language = kLanguageFrench;
break;
case LANG_GERMAN:
m_stConfig.language = kLanguageGerman;
break;
case LANG_GREEK:
m_stConfig.language = kLanguageGreek;
break;
case LANG_HUNGARIAN:
m_stConfig.language = kLanguageHungarian;
break;
case LANG_ITALIAN:
m_stConfig.language = kLanguageItalian;
break;
case LANG_POLISH:
m_stConfig.language = kLanguagePolish;
break;
case LANG_PORTUGUESE:
m_stConfig.language = kLanguagePortuguese;
break;
case LANG_ROMANIAN:
m_stConfig.language = kLanguageRomanian;
break;
case LANG_RUSSIAN:
m_stConfig.language = kLanguageRussian;
break;
case LANG_SPANISH:
m_stConfig.language = kLanguageSpanish;
break;
case LANG_TURKISH:
m_stConfig.language = kLanguageTurkish;
break;
default:
m_stConfig.language = kLanguageEnglish;
break;

View File

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>

View File

@ -17,6 +17,3 @@ IDR_MAINFRAME ICON "metin2.ico"
#define METIN2_COMPONENT_TYPE VFT_APP
#include <version_info.rc>
// Visual Styles manifest
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "Metin2Config.exe.manifest"

View File

@ -31,18 +31,18 @@
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

Binary file not shown.

View File

@ -192,14 +192,15 @@ BOOL CEffectMesh::__LoadData_Ver002(int iSize, const BYTE * c_pbBuf)
if (0 == strExtension.compare("ifl"))
{
CEterPackManager::TPackDataPtr motionData;
CMemoryTextFileLoader textFileLoader;
LPCVOID pMotionData;
CMappedFile File;
if (CEterPackManager::Instance().Get(pMeshData->szDiffuseMapFileName, motionData))
if (CEterPackManager::Instance().Get(File, pMeshData->szDiffuseMapFileName, &pMotionData))
{
CMemoryTextFileLoader textFileLoader;
std::vector<std::string> stTokenVector;
textFileLoader.Bind(motionData->size(), motionData->data());
textFileLoader.Bind(File.Size(), pMotionData);
std::string strPathName;
GetOnlyPathName(pMeshData->szDiffuseMapFileName, strPathName);
@ -336,14 +337,15 @@ BOOL CEffectMesh::__LoadData_Ver001(int iSize, const BYTE * c_pbBuf)
if (0 == strExtension.compare("ifl"))
{
CEterPackManager::TPackDataPtr motionData;
CMemoryTextFileLoader textFileLoader;
LPCVOID pMotionData;
CMappedFile File;
if (CEterPackManager::Instance().Get(pMeshData->szDiffuseMapFileName, motionData))
if (CEterPackManager::Instance().Get(File, pMeshData->szDiffuseMapFileName, &pMotionData))
{
CMemoryTextFileLoader textFileLoader;
std::vector<std::string> stTokenVector;
textFileLoader.Bind(motionData->size(), motionData->data());
textFileLoader.Bind(File.Size(), pMotionData);
std::string strPathName;
GetOnlyPathName(pMeshData->szDiffuseMapFileName, strPathName);

View File

@ -234,6 +234,18 @@ bool CTGAImage::LoadFromMemory(int iSize, const BYTE * c_pbMem)
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;

View File

@ -17,6 +17,7 @@ class CTGAImage : public CImage
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);

View File

@ -47,6 +47,9 @@ void CFileLoaderThread::Destroy()
CloseHandle(m_hSemaphore);
m_hSemaphore = NULL;
}
stl_wipe(m_pRequestDeque);
stl_wipe(m_pCompleteDeque);
}
UINT CFileLoaderThread::Setup()
@ -108,11 +111,13 @@ UINT CFileLoaderThread::Execute(void * /*pvArg*/)
return 1;
}
void CFileLoaderThread::Request(const std::string& c_rstFileName) // called in main thread
void CFileLoaderThread::Request(std::string & c_rstFileName) // called in main thread
{
TData pData;
pData.fileName = c_rstFileName;
pData.data = nullptr;
TData * pData = new TData;
pData->dwSize = 0;
pData->pvBuf = NULL;
pData->stFileName = c_rstFileName;
m_RequestMutex.Lock();
m_pRequestDeque.push_back(pData);
@ -126,7 +131,7 @@ void CFileLoaderThread::Request(const std::string& c_rstFileName) // called in m
--m_iRestSemCount;
}
bool CFileLoaderThread::Fetch(TData& data) // called in main thread
bool CFileLoaderThread::Fetch(TData ** ppData) // called in main thread
{
m_CompleteMutex.Lock();
@ -136,7 +141,7 @@ bool CFileLoaderThread::Fetch(TData& data) // called in main thread
return false;
}
data = m_pCompleteDeque.front();
*ppData = m_pCompleteDeque.front();
m_pCompleteDeque.pop_front();
m_CompleteMutex.Unlock();
@ -153,16 +158,22 @@ void CFileLoaderThread::Process() // called in loader thread
return;
}
auto request = m_pRequestDeque.front();
TData * pData = m_pRequestDeque.front();
m_pRequestDeque.pop_front();
m_RequestMutex.Unlock();
if (!CEterPackManager::Instance().Get(request.fileName, request.data))
request.data = nullptr;
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);
}
m_CompleteMutex.Lock();
m_pCompleteDeque.push_back(request);
m_pCompleteDeque.push_back(pData);
m_CompleteMutex.Unlock();
Sleep(g_iLoadingDelayTime);

View File

@ -2,18 +2,20 @@
#define __INC_YMIR_ETERLIB_FILELOADERTHREAD_H__
#include <deque>
#include <memory>
#include <vector>
#include "Thread.h"
#include "Mutex.h"
#include "../eterBase/MappedFile.h"
class CFileLoaderThread
{
public:
typedef struct SData
{
std::string fileName;
std::shared_ptr<std::vector<char>> data;
std::string stFileName;
CMappedFile File;
LPVOID pvBuf;
DWORD dwSize;
} TData;
public:
@ -23,8 +25,8 @@ class CFileLoaderThread
int Create(void * arg);
public:
void Request(const std::string& c_rstFileName);
bool Fetch(TData& data);
void Request(std::string & c_rstFileName);
bool Fetch(TData ** ppData);
void Shutdown();
protected:
@ -47,10 +49,10 @@ class CFileLoaderThread
void Process();
private:
std::deque<TData> m_pRequestDeque;
std::deque<TData *> m_pRequestDeque;
Mutex m_RequestMutex;
std::deque<TData> m_pCompleteDeque;
std::deque<TData *> m_pCompleteDeque;
Mutex m_CompleteMutex;
HANDLE m_hSemaphore;

View File

@ -50,11 +50,13 @@ bool CGraphicImageTexture::CreateDeviceObjects()
}
else
{
CEterPackManager::TPackDataPtr data;
if (!CEterPackManager::Instance().Get(m_stFileName, data))
CMappedFile mappedFile;
LPCVOID c_pvMap;
if (!CEterPackManager::Instance().Get(mappedFile, m_stFileName.c_str(), &c_pvMap))
return false;
return CreateFromMemoryFile(data->size(), data->data(), m_d3dFmt, m_dwFilter);
return CreateFromMemoryFile(mappedFile.Size(), c_pvMap, m_d3dFmt, m_dwFilter);
}
m_bEmpty = false;

View File

@ -42,17 +42,18 @@ void CResource::Load()
const char * c_szFileName = GetFileName();
DWORD dwStart = ELTimer_GetMSec();
CEterPackManager::TPackDataPtr fileData;
DWORD dwStart = ELTimer_GetMSec();
CMappedFile file;
LPCVOID fileData;
//Tracenf("Load %s", c_szFileName);
if (CEterPackManager::Instance().Get(c_szFileName, fileData))
if (CEterPackManager::Instance().Get(file, c_szFileName, &fileData))
{
m_dwLoadCostMiliiSecond = ELTimer_GetMSec() - dwStart;
//Tracef("CResource::Load %s (%d bytes) in %d ms\n", c_szFileName, file.Size(), m_dwLoadCostMiliiSecond);
if (OnLoad(fileData->size(), fileData->data()))
if (OnLoad(file.Size(), fileData))
{
me_state = STATE_EXIST;
}
@ -80,11 +81,12 @@ void CResource::Reload()
Clear();
Tracef("CResource::Reload %s\n", GetFileName());
CEterPackManager::TPackDataPtr fileData;
CMappedFile file;
LPCVOID fileData;
if (CEterPackManager::Instance().Get(GetFileName(), fileData))
if (CEterPackManager::Instance().Get(file, GetFileName(), &fileData))
{
if (OnLoad(fileData->size(), fileData->data()))
if (OnLoad(file.Size(), fileData))
{
me_state = STATE_EXIST;
}

View File

@ -61,17 +61,17 @@ void CResourceManager::ProcessBackgroundLoading()
DWORD dwCurrentTime = ELTimer_GetMSec();
CFileLoaderThread::TData pData;
while (ms_loadingThread.Fetch(pData))
CFileLoaderThread::TData * pData;
while (ms_loadingThread.Fetch(&pData))
{
//printf("LOD %s\n", pData->stFileName.c_str());
CResource * pResource = GetResourcePointer(pData.fileName.c_str());
CResource * pResource = GetResourcePointer(pData->stFileName.c_str());
if (pResource)
{
if (pResource->IsEmpty())
{
pResource->OnLoad(pData.data->size(), pData.data->data());
pResource->OnLoad(pData->dwSize, pData->pvBuf);
pResource->AddReferenceOnly();
// 여기서 올라간 레퍼런스 카운트를 일정 시간이 지난 뒤에 풀어주기 위하여
@ -79,7 +79,10 @@ void CResourceManager::ProcessBackgroundLoading()
}
}
m_WaitingMap.erase(GetCRC32(pData.fileName.c_str(), pData.fileName.size()));
m_WaitingMap.erase(GetCRC32(pData->stFileName.c_str(), pData->stFileName.size()));
delete [] ((char *) pData->pvBuf);
delete pData;
}
// DO : 일정 시간이 지나고 난뒤 미리 로딩해 두었던 리소스의 레퍼런스 카운트를 감소 시킨다 - [levites]

View File

@ -2,7 +2,6 @@
#include "Resource.h"
#include "FileLoaderThread.h"
#include "../EterBase/Singleton.h"
#include <set>
#include <map>

View File

@ -179,13 +179,14 @@ bool CTextFileLoader::Load(const char * c_szFileName)
{
m_strFileName = "";
CEterPackManager::TPackDataPtr data;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
const VOID* pvData;
CMappedFile kFile;
if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData))
return false;
if (m_dwBufCapacity < data->size())
if (m_dwBufCapacity<kFile.Size())
{
m_dwBufCapacity = data->size();
m_dwBufCapacity=kFile.Size();
if (m_acBufData)
delete [] m_acBufData;
@ -193,8 +194,8 @@ bool CTextFileLoader::Load(const char * c_szFileName)
m_acBufData=new char[m_dwBufCapacity];
}
m_dwBufSize = data->size();
memcpy_s(m_acBufData, m_dwBufCapacity, data->data(), data->size());
m_dwBufSize=kFile.Size();
memcpy(m_acBufData, pvData, m_dwBufSize);
m_strFileName = c_szFileName;
m_dwcurLineIndex = 0;

View File

@ -20,14 +20,16 @@ void PrintfTabs(FILE * File, int iTabCount, const char * c_szString, ...)
bool LoadTextData(const char * c_szFileName, CTokenMap & rstTokenMap)
{
CEterPackManager::TPackDataPtr motionData;
CMemoryTextFileLoader textFileLoader;
LPCVOID pMotionData;
CMappedFile File;
if (!CEterPackManager::Instance().Get(c_szFileName, motionData))
if (!CEterPackManager::Instance().Get(File, c_szFileName, &pMotionData))
return false;
CMemoryTextFileLoader textFileLoader;
CTokenVector stTokenVector;
textFileLoader.Bind(motionData->size(), motionData->data());
textFileLoader.Bind(File.Size(), pMotionData);
for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i)
{
@ -48,16 +50,18 @@ bool LoadTextData(const char * c_szFileName, CTokenMap & rstTokenMap)
bool LoadMultipleTextData(const char * c_szFileName, CTokenVectorMap & rstTokenVectorMap)
{
CEterPackManager::TPackDataPtr modelData;
CMemoryTextFileLoader textFileLoader;
LPCVOID pModelData;
CMappedFile File;
if (!CEterPackManager::Instance().Get(c_szFileName, modelData))
if (!CEterPackManager::Instance().Get(File, c_szFileName, &pModelData))
return false;
DWORD i;
CMemoryTextFileLoader textFileLoader;
CTokenVector stTokenVector;
textFileLoader.Bind(modelData->size(), modelData->data());
textFileLoader.Bind(File.Size(), pModelData);
for (i = 0; i < textFileLoader.GetLineCount(); ++i)
{

1565
src/EterPack/EterPack.cpp Normal file

File diff suppressed because it is too large Load Diff

243
src/EterPack/EterPack.h Normal file
View File

@ -0,0 +1,243 @@
#ifndef __INC_ETERPACKLIB_ETERPACK_H__
#define __INC_ETERPACKLIB_ETERPACK_H__
#include <list>
#include <unordered_map>
#include "../EterBase/MappedFile.h"
#ifndef MAKEFOURCC
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
((DWORD)(BYTE) (ch0 ) | ((DWORD)(BYTE) (ch1) << 8) | \
((DWORD)(BYTE) (ch2) << 16) | ((DWORD)(BYTE) (ch3) << 24))
#endif
//#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();
bool Get(CMappedFile & mappedFile, const char * filename, LPCVOID * data);
bool Get2(CMappedFile & mappedFile, const char * filename, TEterPackIndex* index, LPCVOID * data);
bool Put(const char * filename, const char * sourceFilename, BYTE packType, const std::string& strRelateMapName);
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

View File

@ -170,6 +170,20 @@
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="EterPack.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
</ClCompile>
<ClCompile Include="EterPackCursor.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
</ClCompile>
<ClCompile Include="EterPackManager.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
@ -177,16 +191,25 @@
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
</ClCompile>
<ClCompile Include="Folder.cpp" />
<ClCompile Include="ZIP.cpp" />
<ClCompile Include="EterPackPolicy_CSHybridCrypt.cpp" />
<ClCompile Include="md5.c" />
<ClCompile Include="StdAfx.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</BrowseInformation>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Distribute|Win32'">MaxSpeed</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="EterPack.h" />
<ClInclude Include="EterPackCursor.h" />
<ClInclude Include="EterPackManager.h" />
<ClInclude Include="FileProvider.h" />
<ClInclude Include="Folder.h" />
<ClInclude Include="EterPackPolicy_CSHybridCrypt.h" />
<ClInclude Include="Inline.h" />
<ClInclude Include="md5.h" />
<ClInclude Include="StdAfx.h" />
<ClInclude Include="ZIP.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -9,39 +9,48 @@
<UniqueIdentifier>{c156ef19-8b61-496c-a499-8bf66e9ca80d}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl</Extensions>
</Filter>
<Filter Include="File Providers">
<UniqueIdentifier>{6348898e-222d-4516-8d4e-e37f9e17d872}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="EterPack.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="EterPackCursor.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="EterPackManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Folder.cpp">
<Filter>File Providers</Filter>
<ClCompile Include="EterPackPolicy_CSHybridCrypt.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ZIP.cpp">
<Filter>File Providers</Filter>
<ClCompile Include="md5.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="StdAfx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="EterPack.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EterPackCursor.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EterPackManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EterPackPolicy_CSHybridCrypt.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Inline.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="md5.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="StdAfx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Folder.h">
<Filter>File Providers</Filter>
</ClInclude>
<ClInclude Include="ZIP.h">
<Filter>File Providers</Filter>
</ClInclude>
<ClInclude Include="FileProvider.h">
<Filter>File Providers</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -0,0 +1,59 @@
#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 = max(0, 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();
}

View File

@ -0,0 +1,25 @@
#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

View File

@ -1,34 +1,73 @@
#include "StdAfx.h"
#include <fstream>
#include <io.h>
#include <assert.h>
#include "EterPackManager.h"
#include "EterPackPolicy_CSHybridCrypt.h"
#include "../eterBase/Debug.h"
#include "../eterBase/CRC32.h"
#include "Folder.h"
#include "ZIP.h"
#define PATH_ABSOLUTE_YMIRWORK1 "d:/ymir work/"
#define PATH_ABSOLUTE_YMIRWORK2 "d:\\ymir work\\"
// StringPath std::string ¹öÀü
std::string CEterPackManager::ConvertFileName(std::string fileName)
CEterPack* CEterPackManager::FindPack(const char* c_szPathName)
{
std::string convertedFileName = fileName;
stl_lowers(convertedFileName);
std::string strFileName;
for (DWORD i = 0; i < convertedFileName.length(); i++)
if (0 == ConvertFileName(c_szPathName, strFileName))
{
if (convertedFileName[i] == '\\')
convertedFileName[i] = '/';
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 convertedFileName;
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)
@ -48,6 +87,54 @@ bool CEterPackManager::CompareName(const char * c_szDirectoryName, DWORD /*dwLen
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)
@ -63,37 +150,27 @@ struct TimeChecker
DWORD baseTime;
};
bool CEterPackManager::Get(const std::string& fileName, TPackDataPtr& dataPtr)
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(fileName, dataPtr))
if (GetFromFile(rMappedFile, c_szFileName, pData))
{
return true;
}
return GetFromPack(fileName, dataPtr);
return GetFromPack(rMappedFile, c_szFileName, pData);
}
if (GetFromPack(fileName, dataPtr))
if (GetFromPack(rMappedFile, c_szFileName, pData))
{
return true;
}
return GetFromFile(fileName, dataPtr);
}
bool CEterPackManager::Get(const std::string& fileName, std::stringstream& dataStream)
{
CEterPackManager::TPackDataPtr data;
if (!Get(fileName, data))
return false;
// Copy the data from the pack into the file sstream
dataStream.str("");
std::copy(data->begin(), data->end(), std::ostream_iterator<char>(dataStream));
return true;
return GetFromFile(rMappedFile, c_szFileName, pData);
}
struct FinderLock
@ -111,60 +188,109 @@ struct FinderLock
CRITICAL_SECTION* p_cs;
};
bool CEterPackManager::GetFromPack(const std::string& fileName, TPackDataPtr& dataPtr)
bool CEterPackManager::GetFromPack(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData)
{
FinderLock lock(m_csFinder);
std::string strFileName = ConvertFileName(fileName);
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);
auto pkFileItem = m_FileMap.find(strFileName);
if (pkCache)
{
rMappedFile.Link(pkCache->m_dwBufSize, pkCache->m_abBufData);
return true;
}
if (pkFileItem == m_FileMap.end()) {
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());
TraceError("CANNOT_FIND_PACK_FILE [%s]", strFileName.c_str());
#endif
return false;
}
auto data = std::make_shared<std::vector<char>>();
if (!pkFileItem->second->getFile(strFileName, data))
return false;
// Set dataPtr to the retreived data pointer
dataPtr = data;
return true;
return false;
}
bool CEterPackManager::GetFromFile(const std::string& fileName, TPackDataPtr& dataPtr)
const time_t g_tCachingInterval = 10; // 10초
void CEterPackManager::ArrangeMemoryMappedPack()
{
// Try to open the file
std::ifstream file(fileName, std::ios::binary);
if (!file.is_open())
return false;
//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();
// }
// }
//}
}
// Read the file's contents
dataPtr = std::make_shared<std::vector<char>>(
std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>()
);
return true;
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 = ConvertFileName(c_szFileName);
std::string strFileName;
auto pkFileItem = m_FileMap.find(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 == m_FileMap.end())
return false;
if (pkFileItem)
if (pkFileItem->pkPack)
return pkFileItem->pkPack->IsExist(strFileName.c_str());
}
if (!pkFileItem->second)
return false;
return pkFileItem->second->fileExists(strFileName.c_str());
// NOTE : 매치 되는 팩이 없다면 false - [levites]
return false;
}
bool CEterPackManager::isExist(const char * c_szFileName)
@ -174,9 +300,16 @@ bool CEterPackManager::isExist(const char * c_szFileName)
if (isExistInPack(c_szFileName))
return true;
return _access(c_szFileName, 0) == 0;
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;
@ -184,40 +317,82 @@ bool CEterPackManager::isExist(const char * 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)
{
auto it = m_PackMap.find(c_szName);
if (it != m_PackMap.end())
return true;
try {
bool bReadOnly = true;
std::shared_ptr<FileProvider> pack;
// TODO: allow configurable containers
//pack = std::make_shared<Folder>(c_szName);
pack = std::make_shared<ZIP>(std::string(c_szName) + ".zip");
auto packFiles = pack->listFiles();
for (auto const& fileName : packFiles)
m_FileMap.insert({ fileName, pack });
m_PackMap.insert({ c_szName, pack });
return true;
}
catch (std::exception& e)
CEterPack * pEterPack = NULL;
{
#ifdef _DEBUG
Tracef("Unable to load file provider '%s': %s\n", c_szName, e.what());
#endif
TEterPackMap::iterator itor = m_PackMap.find(c_szName);
return false;
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)
@ -230,16 +405,209 @@ int CEterPackManager::GetSearchMode()
return m_iSearchMode;
}
CEterPackManager::CEterPackManager() : m_iSearchMode(SEARCH_FILE_FIRST)
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);
}
const CEterPackManager::TFileMap& CEterPackManager::GetFileMap() {
return this->m_FileMap;
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 )
{
std::string noPathName = CFileNameHelper::NoPath(std::string(cit->first));
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 )
{
std::string noPathName = CFileNameHelper::NoPath(std::string(cit->first));
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++;
std::string noPathName = CFileNameHelper::NoPath(std::string(cit->first));
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++;
std::string noPathName = CFileNameHelper::NoPath(std::string(cit->first));
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();
}

View File

@ -5,10 +5,16 @@
#include "../eterBase/Singleton.h"
#include "../eterBase/Stl.h"
#include "FileProvider.h"
#include "EterPack.h"
class CEterPackManager : public CSingleton<CEterPackManager>
{
public:
struct SCache
{
BYTE* m_abBufData;
DWORD m_dwBufSize;
};
public:
enum ESearchModes
{
@ -16,39 +22,69 @@ class CEterPackManager : public CSingleton<CEterPackManager>
SEARCH_PACK_FIRST
};
typedef std::list<std::shared_ptr<FileProvider>> TEterPackList;
typedef std::unordered_map<std::string, std::shared_ptr<FileProvider>, stringhash> TEterPackMap;
typedef std::unordered_map<std::string, std::shared_ptr<FileProvider>, stringhash> TFileMap;
typedef std::shared_ptr<std::vector<char>> TPackDataPtr;
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();
bool Get(const std::string& fileName, TPackDataPtr& dataPtr);
bool Get(const std::string& fileName, std::stringstream& dataStream);
bool Get(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData);
bool GetFromPack(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData);
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);
std::string ConvertFileName(std::string fileName);
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);
const TFileMap& GetFileMap();
bool DecryptPackIV(DWORD key);
const char * GetRootPackFileName();
//for hybridcrypt
void WriteHybridCryptPackInfo(const char* pFileName);
void RetrieveHybridCryptPackKeys( const BYTE* pStream );
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);
bool GetFromPack(const std::string& fileName, TPackDataPtr& dataPtr);
bool GetFromFile(const std::string& fileName, TPackDataPtr& dataPtr);
CEterPack* FindPack(const char* c_szPathName);
SCache* __FindCache(DWORD dwFileNameHash);
void __ClearCacheMap();
protected:
bool m_bTryRelativePath;
bool m_isCacheMode;
int m_iSearchMode;
TFileMap m_FileMap;
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;
};

View File

@ -1,14 +0,0 @@
#pragma once
#include <vector>
#include <string>
#include <sstream>
#include <memory>
class FileProvider
{
public:
virtual std::vector<std::string> listFiles() = 0;
virtual bool fileExists(const std::string& fileName) = 0;
virtual bool getFile(const std::string& fileName, std::shared_ptr<std::vector<char>>& fileData) = 0;
};

View File

@ -1,98 +0,0 @@
#include "Folder.h"
#include "EterPackManager.h"
#include <iostream>
#include <fstream>
#include <Windows.h>
#include "../eterBase/Stl.h"
void Folder::ListFiles(const std::string& directory, const std::string& relativePath = "") {
WIN32_FIND_DATA findData;
HANDLE hFind;
std::string searchPath = directory + "\\*";
// Start searching for files and directories
hFind = FindFirstFile(searchPath.c_str(), &findData);
if (hFind == INVALID_HANDLE_VALUE)
throw std::runtime_error("Failed to open directory: " + directory);
do {
const std::string fileOrDirName = findData.cFileName;
// Skip the "." and ".." directories
if (fileOrDirName == "." || fileOrDirName == "..") {
continue;
}
// Construct the full and relative paths
std::string fullPath = directory + "\\" + fileOrDirName;
std::string currentRelativePath = relativePath + fileOrDirName;
// Check if the current entry is a directory
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
// Recurse into the subdirectory
ListFiles(fullPath, currentRelativePath + "\\");
}
else {
if (currentRelativePath.rfind("ymir work\\", 0) == 0) {
currentRelativePath = "d:\\" + currentRelativePath;
}
currentRelativePath = CEterPackManager::Instance().ConvertFileName(currentRelativePath);
// Print the file's relative path
this->fileList.insert(currentRelativePath);
}
} while (FindNextFile(hFind, &findData) != 0);
FindClose(hFind);
}
Folder::Folder(const std::string& folderPath)
{
this->folderPath = folderPath;
ListFiles(folderPath);
}
std::vector<std::string> Folder::listFiles()
{
std::vector<std::string> result;
std::copy(fileList.begin(), fileList.end(), std::back_inserter(result));
return result;
}
bool Folder::fileExists(const std::string& fileName)
{
auto it = fileList.find(fileName);
if (it == fileList.end())
return false;
return true;
}
bool Folder::getFile(const std::string& fileName, std::shared_ptr<std::vector<char>>& fileData)
{
std::string realFileName = fileName;
std::string ymirPrefix = "d:/";
if (fileName.find(ymirPrefix) == 0)
realFileName = realFileName.substr(ymirPrefix.length());
realFileName = this->folderPath + "/" + realFileName;
// Try to open the file
std::ifstream file(realFileName, std::ios::binary);
if (!file.is_open())
return false;
// Read the file's contents
fileData = std::make_shared<std::vector<char>>(
std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>()
);
return true;
}

View File

@ -1,23 +0,0 @@
#pragma once
#include <string>
#include <set>
#include "FileProvider.h"
class Folder : public FileProvider
{
protected:
std::string folderPath;
std::set<std::string> fileList = {};
public:
Folder(const std::string& folderPath);
std::vector<std::string> listFiles();
bool fileExists(const std::string& fileName);
bool getFile(const std::string& fileName, std::shared_ptr<std::vector<char>>& fileData);
private:
void ListFiles(const std::string& directory, const std::string& relativePath);
};

2
src/EterPack/StdAfx.cpp Normal file
View File

@ -0,0 +1,2 @@
#include "stdafx.h"

View File

@ -1,97 +0,0 @@
#include "ZIP.h"
#include "EterPackManager.h"
#include <iostream>
#include <fstream>
#include <Windows.h>
#include "../eterBase/Stl.h"
ZIP::ZIP(const std::string& archivePath)
{
int err;
if ((zipFile = zip_open(archivePath.c_str(), 0, &err)) == NULL) {
zip_error_t error;
zip_error_init_with_code(&error, err);
std::string errorMessage = zip_error_strerror(&error);
zip_error_fini(&error);
throw std::runtime_error("Cannot open ZIP archive '" + archivePath + "': " + errorMessage);
}
// Read the list of files in the archive
zip_int64_t numEntries = zip_get_num_entries(zipFile, 0);
for (int index = 0; index < numEntries; index++)
{
zip_stat_t fileData;
zip_stat_index(zipFile, index, 0, &fileData);
std::string fileName(fileData.name);
if (fileData.size == 0) {
// This is a folder, skip it
continue;
}
if (fileName.rfind("ymir work/", 0) == 0) {
fileName = "d:/" + fileName;
}
fileName = CEterPackManager::Instance().ConvertFileName(fileName);
fileList.insert({ fileName, fileData.index });
}
}
ZIP::~ZIP()
{
zip_close(zipFile);
zipFile = nullptr;
}
std::vector<std::string> ZIP::listFiles()
{
std::vector<std::string> result;
for (auto const& file : fileList)
result.push_back(file.first);
return result;
}
bool ZIP::fileExists(const std::string& fileName)
{
auto it = fileList.find(fileName);
if (it == fileList.end())
return false;
return true;
}
bool ZIP::getFile(const std::string& fileName, std::shared_ptr<std::vector<char>>& fileData)
{
auto it = fileList.find(fileName);
if (it == fileList.end())
return false;
auto file = zip_fopen_index(zipFile, it->second, 0);
if (file == NULL)
return false;
zip_stat_t fileInfo;
zip_stat_index(zipFile, it->second, 0, &fileInfo);
// Initialize the buffer
fileData = std::make_shared<std::vector<char>>(fileInfo.size);
// Attempt to read the data into the buffer
auto retval = zip_fread(file, fileData->data(), fileData->size());
// Close the file
zip_fclose(file);
if (retval == -1)
return false;
return true;
}

View File

@ -1,20 +0,0 @@
#include <string>
#include <map>
#include <zip.h>
#include "FileProvider.h"
class ZIP : public FileProvider
{
protected:
zip_t* zipFile = nullptr;
std::map<std::string, zip_uint64_t> fileList;
public:
ZIP(const std::string& archivePath);
~ZIP();
std::vector<std::string> listFiles();
bool fileExists(const std::string& fileName);
bool getFile(const std::string& fileName, std::shared_ptr<std::vector<char>>& fileData);
};

1033
src/EterPack/md5.c Normal file

File diff suppressed because it is too large Load Diff

128
src/EterPack/md5.h Normal file
View File

@ -0,0 +1,128 @@
#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

View File

@ -106,8 +106,10 @@ bool CTerrain::LoadShadowMap(const char * c_pszFileName)
DWORD dwStart = ELTimer_GetMSec();
Tracef("LoadShadowMap %s ", c_pszFileName);
CEterPackManager::TPackDataPtr data;
if (!CEterPackManager::Instance().Get(c_pszFileName, data))
CMappedFile file;
LPCVOID c_pvData;
if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData))
{
TraceError(" CTerrain::LoadShadowMap - %s OPEN ERROR", c_pszFileName);
return false;
@ -115,13 +117,13 @@ bool CTerrain::LoadShadowMap(const char * c_pszFileName)
DWORD dwShadowMapSize = sizeof(WORD) * 256 * 256;
if (data->size() != dwShadowMapSize)
if (file.Size() != dwShadowMapSize)
{
TraceError(" CTerrain::LoadShadowMap - %s SIZE ERROR", c_pszFileName);
return false;
}
memcpy_s(m_awShadowMap, dwShadowMapSize, data->data(), data->size());
memcpy(m_awShadowMap, c_pvData, dwShadowMapSize);
Tracef("%d ms\n", ELTimer_GetMSec() - dwStart);
return true;

View File

@ -95,12 +95,14 @@ CItemData * CItemManager::MakeItemData(DWORD dwIndex)
bool CItemManager::LoadItemList(const char * c_szFileName)
{
CEterPackManager::TPackDataPtr data;
CMemoryTextFileLoader textFileLoader;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
CMappedFile File;
LPCVOID pData;
if (!CEterPackManager::Instance().Get(File, c_szFileName, &pData))
return false;
textFileLoader.Bind(data->size(), data->data());
CMemoryTextFileLoader textFileLoader;
textFileLoader.Bind(File.Size(), pData);
CTokenVector TokenVector;
for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i)
@ -194,15 +196,16 @@ const std::string& __SnapString(const std::string& c_rstSrc, std::string& rstTem
bool CItemManager::LoadItemDesc(const char* c_szFileName)
{
CEterPackManager::TPackDataPtr data;
CMemoryTextFileLoader kTextFileLoader;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
const VOID* pvData;
CMappedFile kFile;
if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData))
{
Tracenf("CItemManager::LoadItemDesc(c_szFileName=%s) - Load Error", c_szFileName);
return false;
}
kTextFileLoader.Bind(data->size(), data->data());
CMemoryTextFileLoader kTextFileLoader;
kTextFileLoader.Bind(kFile.Size(), pvData);
std::string stTemp;
@ -251,27 +254,22 @@ DWORD GetHashCode( const char* pString )
bool CItemManager::LoadItemTable(const char* c_szFileName)
{
std::stringstream data;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
CMappedFile file;
LPCVOID pvData;
if (!CEterPackManager::Instance().Get(file, c_szFileName, &pvData))
return false;
DWORD dwFourCC, dwElements, dwDataSize;
DWORD dwVersion=0;
DWORD dwStride=0;
data.read((char*)&dwFourCC, sizeof(DWORD));
if (!data)
return false;
file.Read(&dwFourCC, sizeof(DWORD));
if (dwFourCC == MAKEFOURCC('M', 'I', 'P', 'X'))
{
data.read((char*)&dwVersion, sizeof(DWORD));
if (!data)
return false;
data.read((char*)&dwStride, sizeof(DWORD));
if (!data)
return false;
file.Read(&dwVersion, sizeof(DWORD));
file.Read(&dwStride, sizeof(DWORD));
if (dwVersion != 1)
{
@ -291,25 +289,19 @@ bool CItemManager::LoadItemTable(const char* c_szFileName)
return false;
}
data.read((char*)&dwElements, sizeof(DWORD));
if (!data)
return false;
file.Read(&dwElements, sizeof(DWORD));
file.Read(&dwDataSize, sizeof(DWORD));
data.read((char*)&dwDataSize, sizeof(DWORD));
if (!data)
return false;
auto pbData = std::make_shared<std::vector<BYTE>>(dwDataSize);
data.read((char*)pbData->data(), pbData->size());
if (!data)
return false;
BYTE * pbData = new BYTE[dwDataSize];
file.Read(pbData, dwDataSize);
/////
CLZObject zObj;
if (!CLZO::Instance().Decompress(zObj, pbData->data(), s_adwItemProtoKey))
if (!CLZO::Instance().Decompress(zObj, pbData, s_adwItemProtoKey))
{
delete [] pbData;
return false;
}
@ -390,6 +382,7 @@ bool CItemManager::LoadItemTable(const char* c_szFileName)
// pItemData->SetItemTableData(table);
// }
delete [] pbData;
return true;
}

View File

@ -597,14 +597,14 @@ void CMapManager::GetBaseXY(DWORD * pdwBaseX, DWORD * pdwBaseY)
void CMapManager::__LoadMapInfoVector()
{
CEterPackManager::TPackDataPtr data;
CMemoryTextFileLoader textFileLoader;
if (!CEterPackManager::Instance().Get(m_stAtlasInfoFileName, data))
if (!CEterPackManager::Instance().Get("AtlasInfo.txt", data))
CMappedFile kFile;
LPCVOID pData;
if (!CEterPackManager::Instance().Get(kFile, m_stAtlasInfoFileName.c_str(), &pData))
if (!CEterPackManager::Instance().Get(kFile, "AtlasInfo.txt", &pData))
return;
textFileLoader.Bind(data->size(), data->data());
CMemoryTextFileLoader textFileLoader;
textFileLoader.Bind(kFile.Size(), pData);
char szMapName[256];
int x, y;

View File

@ -452,18 +452,19 @@ bool CMapOutdoor::LoadMonsterAreaInfo()
char c_szFileName[256];
sprintf(c_szFileName, "%s\\regen.txt", GetMapDataDirectory().c_str());
CEterPackManager::TPackDataPtr modelData;
CMemoryTextFileLoader textFileLoader;
LPCVOID pModelData;
CMappedFile File;
if (!CEterPackManager::Instance().Get(c_szFileName, modelData))
if (!CEterPackManager::Instance().Get(File, c_szFileName, &pModelData))
{
//TraceError(" CMapOutdoorAccessor::LoadMonsterAreaInfo Load File %s ERROR", c_szFileName);
return false;
}
CMemoryTextFileLoader textFileLoader;
CTokenVector stTokenVector;
textFileLoader.Bind(modelData->size(), modelData->data());
textFileLoader.Bind(File.Size(), pModelData);
for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i)
{

View File

@ -136,6 +136,54 @@ 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;

View File

@ -19,6 +19,8 @@ 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();

View File

@ -4,7 +4,7 @@
#include "PropertyManager.h"
#include "Property.h"
CPropertyManager::CPropertyManager()
CPropertyManager::CPropertyManager() : m_isFileMode(true)
{
}
@ -13,34 +13,90 @@ CPropertyManager::~CPropertyManager()
Clear();
}
void CPropertyManager::Initialize()
bool CPropertyManager::Initialize(const char * c_pszPackFileName)
{
auto fileMap = CEterPackManager::Instance().GetFileMap();
for (auto& itor : fileMap)
if (c_pszPackFileName)
{
if (itor.first.rfind("property/reserve", 0) == 0)
if (!m_pack.Create(m_fileDict, c_pszPackFileName, "", true))
{
LoadReservedCRC(itor.first.c_str());
continue;
LogBoxf("Cannot open property pack file (filename %s)", c_pszPackFileName);
return false;
}
if (itor.first.rfind("property/", 0) == 0) {
if (!Register(itor.first.c_str()))
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;
}
if (!Register(pIndex->filename))
continue;
++i;
}
}
else
{
m_isFileMode = true;
// NOTE : 여기서 Property를 등록시키면 WorldEditor에서 이상이 생김 ;
// 또한, Property Tree List에도 등록을 시켜야 되기 때문에 바깥쪽에서.. - [levites]
}
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)
{
CEterPackManager::TPackDataPtr data;
CMemoryTextFileLoader textFileLoader;
CMappedFile file;
LPCVOID c_pvData;
if (!CEterPackManager::Instance().Get(c_pszFileName, data))
if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData))
return false;
textFileLoader.Bind(data->size(), data->data());
CMemoryTextFileLoader textFileLoader;
textFileLoader.Bind(file.Size(), c_pvData);
for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i)
{
@ -80,13 +136,15 @@ DWORD CPropertyManager::GetUniqueCRC(const char * c_szSeed)
bool CPropertyManager::Register(const char * c_pszFileName, CProperty ** ppProperty)
{
CEterPackManager::TPackDataPtr data;
if (!CEterPackManager::Instance().Get(c_pszFileName, data))
CMappedFile file;
LPCVOID c_pvData;
if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData))
return false;
CProperty * pProperty = new CProperty(c_pszFileName);
if (!pProperty->ReadFromMemory(data->data(), data->size(), c_pszFileName))
if (!pProperty->ReadFromMemory(c_pvData, file.Size(), c_pszFileName))
{
delete pProperty;
return false;
@ -130,6 +188,67 @@ 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);

View File

@ -1,5 +1,7 @@
#pragma once
#include "../eterPack/EterPack.h"
class CPropertyManager : public CSingleton<CPropertyManager>
{
public:
@ -8,20 +10,34 @@ 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);
void Initialize();
bool Initialize(const char * c_pszPackFileName = NULL);
bool Register(const char * c_pszFileName, CProperty ** ppProperty = NULL);
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;
bool m_isFileMode;
TPropertyCRCMap m_PropertyByCRCMap;
TCRCSet m_ReservedCRCSet;
CEterPack m_pack;
CEterFileDict m_fileDict;
};

View File

@ -237,13 +237,14 @@ 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));
}
CEterPackManager::TPackDataPtr data;
CMemoryTextFileLoader kTextFileLoader;
if (!CEterPackManager::Instance().Get(motionListFileName, data))
const void* pvData;
CMappedFile kMappedFile;
if (!CEterPackManager::Instance().Get(kMappedFile, motionListFileName, &pvData))
return false;
kTextFileLoader.Bind(data->size(), data->data());
CMemoryTextFileLoader kTextFileLoader;
kTextFileLoader.Bind(kMappedFile.Size(), pvData);
rkRaceData.RegisterMotionMode(CRaceMotionData::MODE_GENERAL);

View File

@ -5,7 +5,7 @@
#include "../eterBase/Timer.h"
bool CSoundData::ms_isSoundFile[SOUND_FILE_MAX_NUM];
std::stringstream CSoundData::ms_SoundFile[SOUND_FILE_MAX_NUM];
CMappedFile CSoundData::ms_SoundFile[SOUND_FILE_MAX_NUM];
const char * CSoundData::GetFileName()
{
@ -139,7 +139,9 @@ U32 AILCALLBACK CSoundData::open_callback(char const * filename, U32 *file_handl
if (-1 == iIndex)
return 0;
if (!CEterPackManager::Instance().Get(filename, ms_SoundFile[iIndex]))
LPCVOID pMap;
if (!CEterPackManager::Instance().Get(ms_SoundFile[iIndex], filename, &pMap))
return 0;
ms_isSoundFile[iIndex] = true;
@ -153,7 +155,7 @@ void AILCALLBACK CSoundData::close_callback(U32 file_handle)
if (!isSlotIndex(file_handle))
return;
ms_SoundFile[file_handle].str("");
ms_SoundFile[file_handle].Destroy();
ms_isSoundFile[file_handle] = false;
}
@ -162,8 +164,7 @@ S32 AILCALLBACK CSoundData::seek_callback(U32 file_handle, S32 offset, U32 type)
if (!isSlotIndex(file_handle))
return 0;
ms_SoundFile[file_handle].seekg(offset, type);
return ms_SoundFile[file_handle].tellg();
return ms_SoundFile[file_handle].Seek(offset, type);
}
U32 AILCALLBACK CSoundData::read_callback(U32 file_handle, void * buffer, U32 bytes)
@ -171,8 +172,9 @@ U32 AILCALLBACK CSoundData::read_callback(U32 file_handle, void * buffer, U32 by
if (!isSlotIndex(file_handle))
return 0;
ms_SoundFile[file_handle].read((char*) buffer, bytes);
return ms_SoundFile[file_handle].gcount();
DWORD dwRealSize = min(ms_SoundFile[file_handle].Size(), bytes);
ms_SoundFile[file_handle].Read(buffer, dwRealSize);
return dwRealSize;
}
void CSoundData::SetPackMode()

View File

@ -1,7 +1,6 @@
#ifndef __MILESLIB_CSOUNDDATA_H__
#define __MILESLIB_CSOUNDDATA_H__
#include <sstream>
#include <miles/MSS.H>
#include "../eterBase/MappedFile.h"
@ -54,7 +53,7 @@ class CSoundData
static int GetEmptySlotIndex();
static bool ms_isSoundFile[SOUND_FILE_MAX_NUM];
static std::stringstream ms_SoundFile[SOUND_FILE_MAX_NUM];
static CMappedFile ms_SoundFile[SOUND_FILE_MAX_NUM];
};
#endif

View File

@ -76,23 +76,18 @@ bool CTerrainImpl::LoadHeightMap(const char*c_szFileName)
{
Tracef("LoadRawHeightMapFile %s ", c_szFileName);
std::stringstream data;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
CMappedFile kMappedFile;
LPCVOID lpcvFileData;
if (!CEterPackManager::Instance().Get(kMappedFile, c_szFileName, &lpcvFileData))
{
Tracen("Error");
TraceError("CTerrainImpl::LoadHeightMap - %s OPEN ERROR", c_szFileName);
return false;
}
data.read((char*) m_awRawHeightMap, sizeof(WORD)*HEIGHTMAP_RAW_XSIZE*HEIGHTMAP_RAW_YSIZE);
if (!data)
{
// Could not read data
TraceError("CTerrainImpl::LoadHeightMap - %s READ ERROR", c_szFileName);
return false;
}
// Data read successfully
memcpy(m_awRawHeightMap, lpcvFileData, sizeof(WORD)*HEIGHTMAP_RAW_XSIZE*HEIGHTMAP_RAW_YSIZE);
return true;
}
@ -101,13 +96,18 @@ bool CTerrainImpl::LoadAttrMap(const char *c_szFileName)
DWORD dwStart = ELTimer_GetMSec();
Tracef("LoadAttrMapFile %s ", c_szFileName);
std::stringstream data;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
CMappedFile kMappedFile;
LPCVOID lpcvFileData;
if (!CEterPackManager::Instance().Get(kMappedFile, c_szFileName, &lpcvFileData))
{
TraceError("CTerrainImpl::LoadAttrMap - %s OPEN ERROR", c_szFileName);
return false;
}
DWORD dwFileSize = kMappedFile.Size();
BYTE * abFileData = (BYTE *) lpcvFileData;
// LoadAttrMap
{
#pragma pack(push)
@ -119,15 +119,16 @@ bool CTerrainImpl::LoadAttrMap(const char *c_szFileName)
WORD m_wHeight;
};
#pragma pack(pop)
SAttrMapHeader kAttrMapHeader;
data.read((char*) &kAttrMapHeader, sizeof(kAttrMapHeader));
if (!data)
if (dwFileSize < sizeof(SAttrMapHeader))
{
TraceError(" CTerrainImpl::LoadAttrMap - %s FILE SIZE ERROR", c_szFileName);
return false;
}
SAttrMapHeader kAttrMapHeader;
memcpy(&kAttrMapHeader, abFileData, sizeof(kAttrMapHeader));
const WORD c_wAttrMapMagic = 2634;
if (c_wAttrMapMagic != kAttrMapHeader.m_wMagic)
{
@ -147,40 +148,40 @@ bool CTerrainImpl::LoadAttrMap(const char *c_szFileName)
return false;
}
data.read((char*)m_abyAttrMap, sizeof(m_abyAttrMap));
if (!data)
DWORD dwFileRestSize=dwFileSize-sizeof(kAttrMapHeader);
DWORD dwFileNeedSize=sizeof(m_abyAttrMap);
if (dwFileRestSize != dwFileNeedSize)
{
TraceError("CTerrainImpl::LoadAttrMap - %s FILE DATA SIZE ERROR", c_szFileName);
TraceError("CTerrainImpl::LoadAttrMap - %s FILE DATA SIZE(rest %d != need %d) ERROR", c_szFileName, dwFileRestSize, dwFileNeedSize);
return false;
}
BYTE* abSrcAttrData= abFileData+sizeof(kAttrMapHeader);
memcpy(m_abyAttrMap, abSrcAttrData, sizeof(m_abyAttrMap));
}
Tracef("%d\n", ELTimer_GetMSec() - dwStart);
return true;
}
bool CTerrainImpl::RAW_LoadTileMap(const char* c_szFileName)
bool CTerrainImpl::RAW_LoadTileMap(const char * c_szFileName)
{
Tracef("LoadSplatFile %s ", c_szFileName);
std::stringstream data;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
CMappedFile kMappedFile;
LPCVOID lpcvFileData;
if (!CEterPackManager::Instance().Get(kMappedFile, c_szFileName, &lpcvFileData))
{
Tracen("Error");
TraceError("CTerrainImpl::RAW_LoadTileMap - %s OPEN ERROR", c_szFileName);
return false;
}
data.read((char*)m_abyTileMap, sizeof(BYTE) * (TILEMAP_RAW_XSIZE) * (TILEMAP_RAW_YSIZE));
if (!data)
{
// Could not read data
TraceError("CTerrainImpl::RAW_LoadTileMap - %s READ ERROR", c_szFileName);
return false;
}
// Data read successfully
memcpy(m_abyTileMap, lpcvFileData, sizeof(BYTE)*(TILEMAP_RAW_XSIZE)*(TILEMAP_RAW_YSIZE));
return true;
}
bool CTerrainImpl::LoadWaterMap(const char * c_szFileName)
@ -205,16 +206,18 @@ bool CTerrainImpl::LoadWaterMap(const char * c_szFileName)
bool CTerrainImpl::LoadWaterMapFile(const char * c_szFileName)
{
std::stringstream data;
size_t fileSize = 0;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
CMappedFile kMappedFile;
LPCVOID lpcvFileData;
if (!CEterPackManager::Instance().Get(kMappedFile, c_szFileName, &lpcvFileData))
{
Tracen("Error");
TraceError("CTerrainImpl::LoadWaterMap - %s OPEN ERROR", c_szFileName);
return false;
}
}
fileSize = data.str().length();
DWORD dwFileSize = kMappedFile.Size();
BYTE* abFileData = (BYTE*)lpcvFileData;
{
#pragma pack(push)
@ -228,14 +231,15 @@ bool CTerrainImpl::LoadWaterMapFile(const char * c_szFileName)
};
#pragma pack(pop)
SWaterMapHeader kWaterMapHeader;
data.read((char*)&kWaterMapHeader, sizeof(kWaterMapHeader));
if (!data)
if (dwFileSize < sizeof(SWaterMapHeader))
{
TraceError("CTerrainImpl::LoadWaterMap - %s FILE SIZE ERROR", c_szFileName);
return false;
}
SWaterMapHeader kWaterMapHeader;
memcpy(&kWaterMapHeader, abFileData, sizeof(kWaterMapHeader));
const WORD c_wWaterMapMagic = 5426;
if (c_wWaterMapMagic != kWaterMapHeader.m_wMagic)
@ -258,23 +262,22 @@ bool CTerrainImpl::LoadWaterMapFile(const char * c_szFileName)
m_byNumWater = kWaterMapHeader.m_byLayerCount;
DWORD dwFileRestSize = fileSize - sizeof(kWaterMapHeader);
DWORD dwFileRestSize = dwFileSize - sizeof(kWaterMapHeader);
DWORD dwFileNeedSize = sizeof(m_abyWaterMap) + sizeof(long) * m_byNumWater;
DWORD dwFileNeedSize2 = sizeof(m_abyWaterMap) + sizeof(WORD) * m_byNumWater;
if (dwFileRestSize == dwFileNeedSize2)
{
WORD wWaterHeight[MAX_WATER_NUM + 1];
data.read((char*)m_abyWaterMap, sizeof(m_abyWaterMap));
if (!data)
return false;
BYTE * abSrcWaterData = abFileData + sizeof(kWaterMapHeader);
memcpy(m_abyWaterMap, abSrcWaterData, sizeof(m_abyWaterMap));
BYTE * abSrcWaterHeight = abSrcWaterData + sizeof(m_abyWaterMap);
m_byNumWater = MIN(MAX_WATER_NUM, m_byNumWater);
if (m_byNumWater)
{
data.read((char*)wWaterHeight, sizeof(WORD) * m_byNumWater);
if (!data)
return false;
memcpy(wWaterHeight, abSrcWaterHeight, sizeof(WORD) * m_byNumWater);
for (int i = 0; i < m_byNumWater; ++i)
m_lWaterHeight[i] = wWaterHeight[i];
@ -286,15 +289,13 @@ bool CTerrainImpl::LoadWaterMapFile(const char * c_szFileName)
return false;
}
data.read((char*)m_abyWaterMap, sizeof(m_abyWaterMap));
if (!data)
return false;
BYTE * abSrcWaterData = abFileData + sizeof(kWaterMapHeader);
memcpy(m_abyWaterMap, abSrcWaterData, sizeof(m_abyWaterMap));
if (m_byNumWater) {
data.read((char*)m_lWaterHeight, sizeof(long)* m_byNumWater);
if (!data)
return false;
}
BYTE * abSrcWaterHeight = abSrcWaterData + sizeof(m_abyWaterMap);
if (m_byNumWater)
memcpy(m_lWaterHeight, abSrcWaterHeight, sizeof(long) * m_byNumWater);
}
return true;

View File

@ -196,19 +196,21 @@ bool CPythonLauncher::RunCompiledFile(const char* c_szFileName)
}
bool CPythonLauncher::RunMemoryTextFile(const char* c_szFileName, std::shared_ptr<std::vector<char>> fileData)
bool CPythonLauncher::RunMemoryTextFile(const char* c_szFileName, UINT uFileSize, const VOID* c_pvFileData)
{
NANOBEGIN
const CHAR* c_pcFileData=(const CHAR*)c_pvFileData;
std::string stConvFileData;
stConvFileData.reserve(fileData->size());
stConvFileData.reserve(uFileSize);
stConvFileData+="exec(compile('''";
// ConvertPythonTextFormat
{
for (UINT i=0; i<fileData->size(); ++i)
for (UINT i=0; i<uFileSize; ++i)
{
if ((*fileData)[i] != 13)
stConvFileData+= (*fileData)[i];
if (c_pcFileData[i]!=13)
stConvFileData+=c_pcFileData[i];
}
}
@ -225,14 +227,29 @@ bool CPythonLauncher::RunMemoryTextFile(const char* c_szFileName, std::shared_pt
bool CPythonLauncher::RunFile(const char* c_szFileName)
{
CEterPackManager::TPackDataPtr data;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
return false;
char* acBufData=NULL;
DWORD dwBufSize=0;
{
CMappedFile file;
const VOID* pvData;
CEterPackManager::Instance().Get(file, c_szFileName, &pvData);
if (data->size() == 0)
return false;
dwBufSize=file.Size();
if (dwBufSize==0)
return false;
return RunMemoryTextFile(c_szFileName, data);
acBufData=new char[dwBufSize];
memcpy(acBufData, pvData, dwBufSize);
}
bool ret=false;
ret=RunMemoryTextFile(c_szFileName, dwBufSize, acBufData);
delete [] acBufData;
return ret;
}
bool CPythonLauncher::RunLine(const char* c_szSrc)

View File

@ -15,7 +15,7 @@ class CPythonLauncher : public CSingleton<CPythonLauncher>
void SetTraceFunc(int (*pFunc)(PyObject * obj, PyFrameObject * f, int what, PyObject *arg));
bool RunLine(const char* c_szLine);
bool RunFile(const char* c_szFileName);
bool RunMemoryTextFile(const char* c_szFileName, std::shared_ptr<std::vector<char>> fileData);
bool RunMemoryTextFile(const char* c_szFileName, UINT uFileSize, const VOID* c_pvFileData);
bool RunCompiledFile(const char* c_szFileName);
const char* GetError();

View File

@ -75,15 +75,16 @@ BOOL CSpeedTreeForest::GetMainTree(DWORD dwCRC, CSpeedTreeWrapper ** ppMainTree,
pTree = itor->second;
else
{
CEterPackManager::TPackDataPtr data;
CMappedFile file;
LPCVOID c_pvData;
// NOTE : 파일이 없을때는 return FALSE 아닌가요? - [levites]
if (!CEterPackManager::Instance().Get(c_pszFileName, data))
if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData))
return FALSE;
pTree = new CSpeedTreeWrapper;
if (!pTree->LoadTree(c_pszFileName, (const BYTE *) data->data(), data->size()))
if (!pTree->LoadTree(c_pszFileName, (const BYTE *) c_pvData, file.Size()))
{
delete pTree;
pTree = nullptr;
@ -91,6 +92,8 @@ BOOL CSpeedTreeForest::GetMainTree(DWORD dwCRC, CSpeedTreeWrapper ** ppMainTree,
}
m_pMainTreeMap.insert(std::map<DWORD, CSpeedTreeWrapper *>::value_type(dwCRC, pTree));
file.Destroy();
}
*ppMainTree = pTree;

View File

@ -141,6 +141,13 @@ bool CAccountConnector::__HandshakeState_Process()
if (!__AnalyzePacket(HEADER_GC_PING, sizeof(TPacketGCPing), &CAccountConnector::__AuthState_RecvPing))
return false;
// TODO : 차후 서버와 동일하게 가변길이 data serialize & deserialize 작업해야 한다.
if (!__AnalyzeVarSizePacket(HEADER_GC_HYBRIDCRYPT_KEYS, &CAccountConnector::__AuthState_RecvHybridCryptKeys))
return false;
if (!__AnalyzeVarSizePacket(HEADER_GC_HYBRIDCRYPT_SDB, &CAccountConnector::__AuthState_RecvHybridCryptSDB))
return false;
return true;
}
@ -178,6 +185,16 @@ bool CAccountConnector::__AuthState_Process()
if (!__AnalyzePacket(HEADER_GC_HANDSHAKE, sizeof(TPacketGCHandshake), &CAccountConnector::__AuthState_RecvHandshake))
return false;
if (!__AnalyzePacket(HEADER_GC_PANAMA_PACK, sizeof(TPacketGCPanamaPack), &CAccountConnector::__AuthState_RecvPanamaPack))
return false;
// TODO : 차후 서버와 동일하게 가변길이 data serialize & deserialize 작업해야 한다.
if (!__AnalyzeVarSizePacket(HEADER_GC_HYBRIDCRYPT_KEYS, &CAccountConnector::__AuthState_RecvHybridCryptKeys))
return false;
if (!__AnalyzeVarSizePacket(HEADER_GC_HYBRIDCRYPT_SDB, &CAccountConnector::__AuthState_RecvHybridCryptSDB))
return false;
return true;
}
@ -328,6 +345,50 @@ bool CAccountConnector::__AuthState_RecvHandshake()
return true;
}
bool CAccountConnector::__AuthState_RecvPanamaPack()
{
TPacketGCPanamaPack kPacket;
if (!Recv(sizeof(TPacketGCPanamaPack), &kPacket))
return false;
CEterPackManager::instance().RegisterPack(kPacket.szPackName, "*", kPacket.abIV);
return true;
}
bool CAccountConnector::__AuthState_RecvHybridCryptKeys(int iTotalSize)
{
int iFixedHeaderSize = TPacketGCHybridCryptKeys::GetFixedHeaderSize();
TPacketGCHybridCryptKeys kPacket(iTotalSize-iFixedHeaderSize);
if (!Recv(iFixedHeaderSize, &kPacket))
return false;
if (!Recv(kPacket.iKeyStreamLen, kPacket.m_pStream))
return false;
CEterPackManager::Instance().RetrieveHybridCryptPackKeys( kPacket.m_pStream );
return true;
}
bool CAccountConnector::__AuthState_RecvHybridCryptSDB(int iTotalSize)
{
int iFixedHeaderSize = TPacketGCHybridSDB::GetFixedHeaderSize();
TPacketGCHybridSDB kPacket(iTotalSize-iFixedHeaderSize);
if (!Recv(iFixedHeaderSize, &kPacket))
return false;
if (!Recv(kPacket.iSDBStreamLen, kPacket.m_pStream))
return false;
CEterPackManager::Instance().RetrieveHybridCryptPackSDB( kPacket.m_pStream );
return true;
}
bool CAccountConnector::__AuthState_RecvPing()
{
TPacketGCPing kPacketPing;
@ -363,6 +424,7 @@ 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);

View File

@ -59,6 +59,9 @@ class CAccountConnector : public CNetworkStream, public CSingleton<CAccountConne
bool __AuthState_RecvChinaMatrixCard();
bool __AuthState_RecvRunupMatrixQuiz();
bool __AuthState_RecvNEWCIBNPasspodRequest();
bool __AuthState_RecvPanamaPack();
bool __AuthState_RecvHybridCryptKeys(int VarSize);
bool __AuthState_RecvHybridCryptSDB(int VarSize);
bool __AnalyzePacket(UINT uHeader, UINT uPacketSize, bool (CAccountConnector::*pfnDispatchPacket)());
// TODO: 지금 현재는 임시다. header뒤에 size 4byte가 무조건 온다는 가정임.

View File

@ -1042,11 +1042,12 @@ class CTextLineLoader
public:
CTextLineLoader(const char * c_szFileName)
{
CEterPackManager::TPackDataPtr data;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
const VOID* pvData;
CMappedFile kFile;
if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData))
return;
m_kTextFileLoader.Bind(data->size(), data->data());
m_kTextFileLoader.Bind(kFile.Size(), pvData);
}
DWORD GetLineCount()

View File

@ -241,7 +241,19 @@ void CPythonBackground::Initialize()
void CPythonBackground::__CreateProperty()
{
m_PropertyManager.Initialize();
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");
}
}
//////////////////////////////////////////////////////////////////////

View File

@ -106,11 +106,16 @@ void CPythonEventManager::__InitEventSet(TEventSet& rEventSet)
int CPythonEventManager::RegisterEventSet(const char * c_szFileName)
{
std::stringstream data;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
CMappedFile File;
LPCVOID pMap;
if (!CEterPackManager::Instance().Get(File, c_szFileName, &pMap))
return -1;
std::string strEventString = data.str();
std::string strEventString;
strEventString.resize(File.Size()+1);
File.Read(&strEventString[0], File.Size());
TEventSet * pEventSet = m_EventSetPool.Alloc();
if (!pEventSet)

View File

@ -264,6 +264,9 @@ class CPythonNetworkStream : public CNetworkStream, public CSingleton<CPythonNet
bool RecvHandshakePacket();
bool RecvHandshakeOKPacket();
bool RecvHybridCryptKeyPacket();
bool RecvHybridCryptSDBPacket();
// ETC
DWORD GetMainActorVID();
DWORD GetMainActorRace();

View File

@ -590,6 +590,16 @@ void CPythonNetworkStream::GamePhase()
RecvHandshakeOKPacket();
return;
break;
case HEADER_GC_HYBRIDCRYPT_KEYS:
RecvHybridCryptKeyPacket();
return;
break;
case HEADER_GC_HYBRIDCRYPT_SDB:
RecvHybridCryptSDBPacket();
return;
break;
case HEADER_GC_HS_REQUEST:
ret = RecvHSCheckRequest();

View File

@ -61,6 +61,16 @@ void CPythonNetworkStream::HandShakePhase()
RecvPingPacket();
return;
break;
case HEADER_GC_HYBRIDCRYPT_KEYS:
RecvHybridCryptKeyPacket();
return;
break;
case HEADER_GC_HYBRIDCRYPT_SDB:
RecvHybridCryptSDBPacket();
return;
break;
}
RecvErrorPacket(header);
@ -135,6 +145,46 @@ bool CPythonNetworkStream::RecvHandshakeOKPacket()
return true;
}
bool CPythonNetworkStream::RecvHybridCryptKeyPacket()
{
int iFixedHeaderSize = TPacketGCHybridCryptKeys::GetFixedHeaderSize();
TDynamicSizePacketHeader header;
if( !Peek( sizeof(header), &header) )
return false;
TPacketGCHybridCryptKeys kPacket(header.size-iFixedHeaderSize);
if (!Recv(iFixedHeaderSize, &kPacket))
return false;
if (!Recv(kPacket.iKeyStreamLen, kPacket.m_pStream))
return false;
CEterPackManager::Instance().RetrieveHybridCryptPackKeys( kPacket.m_pStream );
return true;
}
bool CPythonNetworkStream::RecvHybridCryptSDBPacket()
{
int iFixedHeaderSize = TPacketGCHybridSDB::GetFixedHeaderSize();
TDynamicSizePacketHeader header;
if( !Peek( sizeof(header), &header) )
return false;
TPacketGCHybridSDB kPacket(header.size-iFixedHeaderSize);
if (!Recv(iFixedHeaderSize, &kPacket))
return false;
if (!Recv(kPacket.iSDBStreamLen, kPacket.m_pStream))
return false;
CEterPackManager::Instance().RetrieveHybridCryptPackSDB( kPacket.m_pStream );
return true;
}
bool CPythonNetworkStream::RecvHSCheckRequest()
{
TPacketHSCheck packet;

View File

@ -33,12 +33,13 @@ bool CPythonNetworkStream::IsInsultIn(const char* c_szMsg)
bool CPythonNetworkStream::LoadInsultList(const char* c_szInsultListFileName)
{
CEterPackManager::TPackDataPtr data;
CMemoryTextFileLoader kMemTextFileLoader;
if (!CEterPackManager::Instance().Get(c_szInsultListFileName, data))
CMappedFile file;
const VOID* pvData;
if (!CEterPackManager::Instance().Get(file, c_szInsultListFileName, &pvData))
return false;
kMemTextFileLoader.Bind(data->size(), data->data());
CMemoryTextFileLoader kMemTextFileLoader;
kMemTextFileLoader.Bind(file.Size(), pvData);
m_kInsultChecker.Clear();
for (DWORD dwLineIndex=0; dwLineIndex<kMemTextFileLoader.GetLineCount(); ++dwLineIndex)
@ -54,8 +55,9 @@ bool CPythonNetworkStream::LoadConvertTable(DWORD dwEmpireID, const char* c_szFi
if (dwEmpireID<1 || dwEmpireID>=4)
return false;
std::stringstream data;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
CMappedFile file;
const VOID* pvData;
if (!CEterPackManager::Instance().Get(file, c_szFileName, &pvData))
return false;
DWORD dwEngCount=26;
@ -63,17 +65,16 @@ bool CPythonNetworkStream::LoadConvertTable(DWORD dwEmpireID, const char* c_szFi
DWORD dwHanSize=dwHanCount*2;
DWORD dwFileSize=dwEngCount*2+dwHanSize;
if (data.str().length() < dwFileSize)
if (file.Size()<dwFileSize)
return false;
char* pcData=(char*)pvData;
STextConvertTable& rkTextConvTable=m_aTextConvTable[dwEmpireID-1];
data.read((char*)rkTextConvTable.acUpper, dwEngCount);
data.read((char*)rkTextConvTable.acLower, dwEngCount);
data.read((char*)rkTextConvTable.aacHan, dwHanSize);
memcpy(rkTextConvTable.acUpper, pcData, dwEngCount);pcData+=dwEngCount;
memcpy(rkTextConvTable.acLower, pcData, dwEngCount);pcData+=dwEngCount;
memcpy(rkTextConvTable.aacHan, pcData, dwHanSize);
if (!data)
return false;
return true;
}
@ -145,6 +146,17 @@ void CPythonNetworkStream::LoadingPhase()
return;
break;
case HEADER_GC_HYBRIDCRYPT_KEYS:
RecvHybridCryptKeyPacket();
return;
break;
case HEADER_GC_HYBRIDCRYPT_SDB:
RecvHybridCryptSDBPacket();
return;
break;
default:
GamePhase();
return;

View File

@ -68,6 +68,16 @@ void CPythonNetworkStream::LoginPhase()
return;
break;
case HEADER_GC_HYBRIDCRYPT_KEYS:
RecvHybridCryptKeyPacket();
return;
break;
case HEADER_GC_HYBRIDCRYPT_SDB:
RecvHybridCryptSDBPacket();
return;
break;
default:
if (RecvDefaultPacket(header))
return;

View File

@ -99,6 +99,16 @@ void CPythonNetworkStream::SelectPhase()
return;
break;
case HEADER_GC_HYBRIDCRYPT_KEYS:
RecvHybridCryptKeyPacket();
return;
break;
case HEADER_GC_HYBRIDCRYPT_SDB:
RecvHybridCryptSDBPacket();
return;
break;
case HEADER_GC_PLAYER_POINT_CHANGE:
TPacketGCPointChange PointChange;
Recv(sizeof(TPacketGCPointChange), &PointChange);

View File

@ -14,17 +14,17 @@ bool CPythonNonPlayer::LoadNonPlayerData(const char * c_szFileName)
6822045
};
CMappedFile file;
LPCVOID pvData;
Tracef("CPythonNonPlayer::LoadNonPlayerData: %s, sizeof(TMobTable)=%u\n", c_szFileName, sizeof(TMobTable));
std::stringstream data;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
if (!CEterPackManager::Instance().Get(file, c_szFileName, &pvData))
return false;
DWORD dwFourCC, dwElements, dwDataSize;
data.read((char*)&dwFourCC, sizeof(DWORD));
if (!data)
return false;
file.Read(&dwFourCC, sizeof(DWORD));
if (dwFourCC != MAKEFOURCC('M', 'M', 'P', 'T'))
{
@ -32,26 +32,20 @@ bool CPythonNonPlayer::LoadNonPlayerData(const char * c_szFileName)
return false;
}
data.read((char*)&dwElements, sizeof(DWORD));
if (!data)
return false;
data.read((char*)&dwDataSize, sizeof(DWORD));
if (!data)
return false;
auto pbData = std::make_shared<std::vector<BYTE>>(dwDataSize);
data.read((char*)pbData->data(), pbData->size());
if (!data)
return false;
file.Read(&dwElements, sizeof(DWORD));
file.Read(&dwDataSize, sizeof(DWORD));
BYTE * pbData = new BYTE[dwDataSize];
file.Read(pbData, dwDataSize);
/////
CLZObject zObj;
if (!CLZO::Instance().Decompress(zObj, pbData->data(), s_adwMobProtoKey))
if (!CLZO::Instance().Decompress(zObj, pbData, s_adwMobProtoKey))
{
delete [] pbData;
return false;
}
if ((zObj.GetSize() % sizeof(TMobTable)) != 0)
{
@ -70,6 +64,7 @@ bool CPythonNonPlayer::LoadNonPlayerData(const char * c_szFileName)
m_NonPlayerDataMap.insert(TNonPlayerDataMap::value_type(pNonPlayerData->dwVnum, pNonPlayerData));
}
delete [] pbData;
return true;
}

View File

@ -63,9 +63,11 @@ PyObject * packGet(PyObject * poSelf, PyObject * poArgs)
(stricmp(pcExt, ".pyc") == 0) ||
(stricmp(pcExt, ".txt") == 0))
{
CEterPackManager::TPackDataPtr data;
if (CEterPackManager::Instance().Get(strFileName, data))
return Py_BuildValue("s#", data->data(), data->size());
CMappedFile file;
const void * pData = NULL;
if (CEterPackManager::Instance().Get(file,strFileName,&pData))
return Py_BuildValue("s#",pData, file.Size());
}
}

View File

@ -89,13 +89,13 @@ void string_replace_word(const char* base, int base_len, const char* src, int sr
bool CPythonSkill::RegisterSkillTable(const char * c_szFileName)
{
CEterPackManager::TPackDataPtr data;
CMemoryTextFileLoader textFileLoader;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
const VOID* pvData;
CMappedFile kFile;
if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData))
return false;
textFileLoader.Bind(data->size(), data->data());
CMemoryTextFileLoader textFileLoader;
textFileLoader.Bind(kFile.Size(), pvData);
// OVERWRITE_SKILLPROTO_POLY
std::string src_poly_rand;
@ -279,13 +279,13 @@ void CPythonSkill::__RegisterNormalIconImage(TSkillData & rData, const char * c_
extern const DWORD c_iSkillIndex_Riding;
bool CPythonSkill::RegisterSkillDesc(const char * c_szFileName)
{
CEterPackManager::TPackDataPtr data;
CMemoryTextFileLoader textFileLoader;
if (!CEterPackManager::Instance().Get(c_szFileName, data))
const VOID* pvData;
CMappedFile kFile;
if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData))
return false;
textFileLoader.Bind(data->size(), data->data());
CMemoryTextFileLoader textFileLoader;
textFileLoader.Bind(kFile.Size(), pvData);
CTokenVector TokenVector;
for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i)

View File

@ -256,6 +256,10 @@ bool PackInitialize(const char * c_pszFolder)
#endif
CTextFileLoader::SetCacheMode();
#if defined(USE_RELATIVE_PATH)
CEterPackManager::Instance().SetRelativePathMode();
#endif
CEterPackManager::Instance().SetCacheMode();
CEterPackManager::Instance().SetSearchMode(bPackFirst);
CSoundData::SetPackMode(); // Miles 파일 콜백을 셋팅
@ -273,7 +277,7 @@ bool PackInitialize(const char * c_pszFolder)
CEterPackManager::Instance().RegisterPack(strTexCachePackName.c_str(), c_rstFolder.c_str());
}
CEterPackManager::Instance().RegisterPack((stFolder + "root").c_str(), (stFolder + "root").c_str());
CEterPackManager::Instance().RegisterRootPack((stFolder + std::string("root")).c_str());
NANOEND
return true;
}

View File

@ -15,13 +15,6 @@
"name": "directxsdk",
"version>=": "jun10"
},
{
"name": "libzip",
"features": [
"zstd"
],
"version>=": "1.10.1"
},
{
"name": "lzo",
"version>=": "2.10#7"