diff --git a/bin/.gitignore b/bin/.gitignore index d8377271..00c5fdbe 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -16,8 +16,7 @@ log.txt syserr.txt # Game files -pack/*.eix -pack/*.epk +pack/*.zip # Guild images mark/ diff --git a/bin/pack/Index b/bin/pack/Index index c96e66f1..90de63a7 100644 --- a/bin/pack/Index +++ b/bin/pack/Index @@ -1,249 +1,102 @@ -PACK -* -patch1 -* -season3_eu -* -patch2 -* -metin2_patch_snow -pack/ -metin2_patch_snow_dungeon -pack/ -metin2_patch_etc_costume1 -pack/ -metin2_patch_pet1 -pack/ -metin2_patch_pet2 -pack/ -metin2_patch_ramadan_costume -pack/ -metin2_patch_flame -pack/ -metin2_patch_flame_dungeon -pack/ -metin2_patch_w21_etc -pack/ -metin2_patch_w21_mobs -pack/ -metin2_patch_w21_mobs_m -pack/ -metin2_patch_dss_box -pack/ -metin2_patch_costume_soccer -pack/ -metin2_patch_easter1 -pack/ -metin2_patch_mineral -pack/ -metin2_patch_w20_sound -pack/ -metin2_patch_ds -pack/ -metin2_patch_5th_armor -pack/ -metin2_patch_w20_etc -pack/ -metin2_patch_dragon_rock -pack/ -metin2_patch_dragon_rock_mobs -pack/ -metin2_patch_etc -pack/ -metin2_patch_xmas -pack/ -metin2_patch_eu3 -pack/ -metin2_patch_eu4 -pack/ -metin2_patch_mundi -pack/ -metin2_patch_sd -pack/ -metin2_patch_halloween -pack/ -metin2_patch_party -pack/ -metin2_patch_dance -d:/ymir work/pc/ -pc -d:/ymir work/pc2/ -pc2 -d:/ymir work/monster/ -monster -d:/ymir work/monster2/ -monster2 -d:/ymir work/effect/ -effect -d:/ymir work/zone/ -zone -d:/ymir work/terrainmaps/ -terrain -d:/ymir work/npc/ -npc -d:/ymir work/npc2/ -npc2 -d:/ymir work/tree/ -tree -d:/ymir work/guild/ -guild -d:/ymir work/item/ -item -textureset/ -textureset -property/ -property -icon/ -icon -season1/ -season1 -season2/ -season2 -metin2_map_a1/ -outdoora1 -map_a2/ -outdoora2 -metin2_map_a3/ -outdoora3 -metin2_map_b1/ -outdoorb1 -metin2_map_b3/ -outdoorb3 -metin2_map_c1/ -outdoorc1 -metin2_map_c3/ -outdoorc3 -map_n_snowm_01/ -outdoorsnow1 -metin2_map_n_desert_01/ -outdoordesert1 -metin2_map_n_flame_01/ -outdoorflame1 -map_b_fielddungeon/ -outdoorfielddungeon1 -metin2_map_t1/ -outdoort1 -metin2_map_t2/ -outdoort2 -metin2_map_t3/ -outdoort3 -metin2_map_t4/ -outdoort4 -metin2_map_wedding_01/ -outdoorwedding -metin2_map_milgyo/ -outdoormilgyo1 -metin2_map_spiderdungeon/ -indoorspiderdungeon1 -metin2_map_deviltower1/ -indoordeviltower1 -metin2_map_monkeydungeon/ -indoormonkeydungeon1 -metin2_map_monkeydungeon_02/ -indoormonkeydungeon2 -metin2_map_monkeydungeon_03/ -indoormonkeydungeon3 -metin2_map_trent02/ -outdoortrent02 -metin2_map_guild_01/ -outdoorguild1 -metin2_map_guild_02/ -outdoorguild2 -metin2_map_guild_03/ -outdoorguild3 -metin2_map_trent/ -outdoortrent -metin2_map_trent02/ -outdoortrent02 -metin2_map_duel/ -outdoorduel -gm_guild_build/ -outdoorgmguildbuild -sound/ambience/ -sound -sound/common/ -sound -sound/effect/ -sound -sound/monster/ -sound -sound/npc/ -sound -sound/pc/ -sound -sound/ui/ -sound -sound/ambience/ -sound_m -sound/common/ -sound_m -sound/effect/ -sound_m -sound/monster/ -sound_m -sound/npc/ -sound_m -sound/pc/ -sound_m -sound/ui/ -sound_m -sound/monster2/ -sound2 -sound/pc2/ -sound2 -bgm/ -bgm -d:/ymir work/special/ -ETC -d:/ymir work/environment/ -ETC -locale/ca/ -locale_ca -locale/ae/ -locale_ae -locale/de/ -locale_de -locale/es/ -locale_es -locale/fr/ -locale_fr -locale/gr/ -locale_gr -locale/it/ -locale_it -locale/nl/ -locale_nl -locale/pl/ -locale_pl -locale/pt/ -locale_pt -locale/tr/ -locale_tr -locale/uk/ -locale_uk -locale/bg/ -locale_bg -locale/en/ -locale_en -locale/mx/ -locale_mx -locale/ro/ -locale_ro -locale/ru/ -locale_ru -locale/dk/ -locale_dk -locale/cz/ -locale_cz -locale/hu/ -locale_hu -locale/us/ -locale_us -locale/pa/ -locale_pa -uiscript/ -uiscript -d:/ymir work/ui/ -ETC -d:/ymir work/uiloading/ -uiloading +patch1 ZIP +season3_eu ZIP +patch2 ZIP +metin2_patch_snow ZIP +metin2_patch_snow_dungeon ZIP +metin2_patch_etc_costume1 ZIP +metin2_patch_pet1 ZIP +metin2_patch_pet2 ZIP +metin2_patch_ramadan_costume ZIP +metin2_patch_flame ZIP +metin2_patch_flame_dungeon ZIP +metin2_patch_w21_etc ZIP +metin2_patch_w21_mobs ZIP +metin2_patch_w21_mobs_m ZIP +metin2_patch_dss_box ZIP +metin2_patch_costume_soccer ZIP +metin2_patch_easter1 ZIP +metin2_patch_mineral ZIP +metin2_patch_w20_sound ZIP +metin2_patch_ds ZIP +metin2_patch_5th_armor ZIP +metin2_patch_w20_etc ZIP +metin2_patch_dragon_rock ZIP +metin2_patch_dragon_rock_mobs ZIP +metin2_patch_etc ZIP +metin2_patch_xmas ZIP +metin2_patch_eu3 ZIP +metin2_patch_eu4 ZIP +metin2_patch_mundi ZIP +metin2_patch_sd ZIP +metin2_patch_halloween ZIP +metin2_patch_party ZIP +metin2_patch_dance ZIP +pc ZIP +pc2 ZIP +monster ZIP +monster2 ZIP +effect ZIP +zone ZIP +terrain ZIP +npc ZIP +npc2 ZIP +tree ZIP +guild ZIP +item ZIP +textureset ZIP +property ZIP +icon ZIP +season1 ZIP +season2 ZIP +outdoora1 ZIP +outdoora2 ZIP +outdoora3 ZIP +outdoorb1 ZIP +outdoorb3 ZIP +outdoorc1 ZIP +outdoorc3 ZIP +outdoorsnow1 ZIP +outdoordesert1 ZIP +outdoorflame1 ZIP +outdoorfielddungeon1 ZIP +outdoort1 ZIP +outdoort2 ZIP +outdoort3 ZIP +outdoort4 ZIP +outdoorwedding ZIP +outdoormilgyo1 ZIP +indoorspiderdungeon1 ZIP +indoordeviltower1 ZIP +indoormonkeydungeon1 ZIP +indoormonkeydungeon2 ZIP +indoormonkeydungeon3 ZIP +outdoortrent02 ZIP +outdoorguild1 ZIP +outdoorguild2 ZIP +outdoorguild3 ZIP +outdoortrent ZIP +outdoorduel ZIP +outdoorgmguildbuild ZIP +sound ZIP +sound_m ZIP +sound2 ZIP +bgm ZIP +ETC ZIP +locale_de ZIP +locale_es ZIP +locale_fr ZIP +locale_gr ZIP +locale_it ZIP +locale_nl ZIP +locale_pl ZIP +locale_pt ZIP +locale_tr ZIP +locale_en ZIP +locale_ro ZIP +locale_ru ZIP +locale_dk ZIP +locale_cz ZIP +locale_hu ZIP +uiscript ZIP +uiloading ZIP +root ZIP diff --git a/bin/pack/Index.dev b/bin/pack/Index.dev new file mode 100644 index 00000000..03c7170f --- /dev/null +++ b/bin/pack/Index.dev @@ -0,0 +1,102 @@ +patch1 FOLDER +season3_eu FOLDER +patch2 FOLDER +metin2_patch_snow FOLDER +metin2_patch_snow_dungeon FOLDER +metin2_patch_etc_costume1 FOLDER +metin2_patch_pet1 FOLDER +metin2_patch_pet2 FOLDER +metin2_patch_ramadan_costume FOLDER +metin2_patch_flame FOLDER +metin2_patch_flame_dungeon FOLDER +metin2_patch_w21_etc FOLDER +metin2_patch_w21_mobs FOLDER +metin2_patch_w21_mobs_m FOLDER +metin2_patch_dss_box FOLDER +metin2_patch_costume_soccer FOLDER +metin2_patch_easter1 FOLDER +metin2_patch_mineral FOLDER +metin2_patch_w20_sound FOLDER +metin2_patch_ds FOLDER +metin2_patch_5th_armor FOLDER +metin2_patch_w20_etc FOLDER +metin2_patch_dragon_rock FOLDER +metin2_patch_dragon_rock_mobs FOLDER +metin2_patch_etc FOLDER +metin2_patch_xmas FOLDER +metin2_patch_eu3 FOLDER +metin2_patch_eu4 FOLDER +metin2_patch_mundi FOLDER +metin2_patch_sd FOLDER +metin2_patch_halloween FOLDER +metin2_patch_party FOLDER +metin2_patch_dance FOLDER +pc FOLDER +pc2 FOLDER +monster FOLDER +monster2 FOLDER +effect FOLDER +zone FOLDER +terrain FOLDER +npc FOLDER +npc2 FOLDER +tree FOLDER +guild FOLDER +item FOLDER +textureset FOLDER +property FOLDER +icon FOLDER +season1 FOLDER +season2 FOLDER +outdoora1 FOLDER +outdoora2 FOLDER +outdoora3 FOLDER +outdoorb1 FOLDER +outdoorb3 FOLDER +outdoorc1 FOLDER +outdoorc3 FOLDER +outdoorsnow1 FOLDER +outdoordesert1 FOLDER +outdoorflame1 FOLDER +outdoorfielddungeon1 FOLDER +outdoort1 FOLDER +outdoort2 FOLDER +outdoort3 FOLDER +outdoort4 FOLDER +outdoorwedding FOLDER +outdoormilgyo1 FOLDER +indoorspiderdungeon1 FOLDER +indoordeviltower1 FOLDER +indoormonkeydungeon1 FOLDER +indoormonkeydungeon2 FOLDER +indoormonkeydungeon3 FOLDER +outdoortrent02 FOLDER +outdoorguild1 FOLDER +outdoorguild2 FOLDER +outdoorguild3 FOLDER +outdoortrent FOLDER +outdoorduel FOLDER +outdoorgmguildbuild FOLDER +sound FOLDER +sound_m FOLDER +sound2 FOLDER +bgm FOLDER +ETC FOLDER +locale_de FOLDER +locale_es FOLDER +locale_fr FOLDER +locale_gr FOLDER +locale_it FOLDER +locale_nl FOLDER +locale_pl FOLDER +locale_pt FOLDER +locale_tr FOLDER +locale_en FOLDER +locale_ro FOLDER +locale_ru FOLDER +locale_dk FOLDER +locale_cz FOLDER +locale_hu FOLDER +uiscript FOLDER +uiloading FOLDER +root FOLDER diff --git a/build.bat b/build.bat index d1f1c43b..65e372d3 100644 --- a/build.bat +++ b/build.bat @@ -6,7 +6,7 @@ ECHO Only use on a clean project directory. ECHO ====================================================== rem SET M2_MSVC_DIR=C:\Program Files\Microsoft Visual Studio\2022\Community\ -rem SET M2_PML_PATH=C:\Users\User\Path\To\PackMakerLite\PackMakerLite.exe +rem SET M2_7ZIP_PATH=C:\Program Files\7-Zip\7z.exe rem Check the environment variables VERIFY OTHER 2>nul @@ -16,17 +16,21 @@ IF NOT DEFINED M2_MSVC_DIR ( ECHO M2_MSVC_DIR is NOT defined! Please define M2_MSVC_DIR with the path of your local MSVC install. EXIT /B -1 ) -IF NOT DEFINED M2_PML_PATH ( - ECHO M2_PML_PATH is NOT defined! Please define M2_PML_PATH with the path of your local PackMakerLite executable. +IF NOT DEFINED M2_7ZIP_PATH ( + ECHO M2_7ZIP_PATH is NOT defined! Please define M2_7ZIP_PATH with the path of your local 7-Zip "7z.exe" executable. EXIT /B -1 ) ENDLOCAL +rem Cause variables to be expanded at execution time (in order for !errorlevel! to work) +SETLOCAL EnableDelayedExpansion + rem Initialize the MSVC environment CALL "%M2_MSVC_DIR%\VC\Auxiliary\Build\vcvars32.bat" rem Build msbuild Metin2Client.sln /p:Configuration=Distribute /p:Platform="Win32" +if !errorlevel! neq 0 exit /b !errorlevel! rem Start assembling the client package RMDIR /S /Q dist @@ -48,12 +52,11 @@ MKDIR dist\screenshot\ xcopy bin\upload\ dist\upload\ /E /Y /Q rem Build and copy the archives -DEL /F /Q "bin\pack\*.eix" -DEL /F /Q "bin\pack\*.epk" +DEL /F /Q "bin\pack\*.zip" FOR /d %%i IN ("bin\pack\*") DO ( echo Packing %%i - %M2_PML_PATH% --nolog --parallel -p "%%i" + "%M2_7ZIP_PATH%" a "%%i.zip" ".\%%i\*" + if !errorlevel! neq 0 exit /b !errorlevel! ) -MOVE /Y bin\pack\*.eix dist\pack\ -MOVE /Y bin\pack\*.epk dist\pack\ +MOVE /Y bin\pack\*.zip dist\pack\ diff --git a/src/Config/MainDialog.cpp b/src/Config/MainDialog.cpp index 9e54319f..8b819e6b 100644 --- a/src/Config/MainDialog.cpp +++ b/src/Config/MainDialog.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #define APP_NAME _T("Metin2 Config") #define FILENAME_CONFIG "metin2.cfg" @@ -164,12 +164,24 @@ BOOL CMainDialog::OnInitDialog(CWindow wndFocus, LPARAM lInitParam) m_comboShadow.SetCurSel(m_stConfig.iShadowLevel); // Language - ATL::CString language; + + // Load the languages into an array + std::vector languages; for (int i = 0; i < kLanguageMax; ++i) { + ATL::CString language; language.LoadString(kLanguageConfig[i].stringId); - m_comboLanguage.InsertString(i, language); + languages.push_back(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); @@ -229,10 +241,66 @@ 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; diff --git a/src/Config/Metin2Config.exe.manifest b/src/Config/Metin2Config.exe.manifest new file mode 100644 index 00000000..22f5a2f8 --- /dev/null +++ b/src/Config/Metin2Config.exe.manifest @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/src/Config/Metin2Config.rc b/src/Config/Metin2Config.rc index 62c71471..109e2f3f 100644 --- a/src/Config/Metin2Config.rc +++ b/src/Config/Metin2Config.rc @@ -17,3 +17,6 @@ IDR_MAINFRAME ICON "metin2.ico" #define METIN2_COMPONENT_TYPE VFT_APP #include + +// Visual Styles manifest +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "Metin2Config.exe.manifest" diff --git a/src/Config/Metin2Config.vcxproj b/src/Config/Metin2Config.vcxproj index 9c58713e..a889feb4 100644 --- a/src/Config/Metin2Config.vcxproj +++ b/src/Config/Metin2Config.vcxproj @@ -31,18 +31,18 @@ Application v143 false - MultiByte + Unicode Application v143 false - MultiByte + Unicode Application false - MultiByte + Unicode v143 diff --git a/src/Config/ui.rc b/src/Config/ui.rc index a08cdd90..7ec6c0c8 100644 Binary files a/src/Config/ui.rc and b/src/Config/ui.rc differ diff --git a/src/Config/version_info.rc b/src/Config/version_info.rc index 14016f91..a576468b 100644 --- a/src/Config/version_info.rc +++ b/src/Config/version_info.rc @@ -15,8 +15,8 @@ #endif VS_VERSION_INFO VERSIONINFO -FILEVERSION 0, 3, 1, 0 -PRODUCTVERSION 0, 3, 1, 0 +FILEVERSION 0,4,0,0 +PRODUCTVERSION 0,4,0,0 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEFLAGS METIN2_DEBUG FILEOS VOS__WINDOWS32 @@ -29,12 +29,12 @@ BEGIN BEGIN VALUE "CompanyName", "The Old Metin2 Project" VALUE "FileDescription", METIN2_COMPONENT_DESCRIPTION - VALUE "FileVersion", "0.3.1.0" + VALUE "FileVersion", "0.4.0.0" VALUE "InternalName", METIN2_COMPONENT_INTERNALNAME - VALUE "LegalCopyright", "Copyright (C) 2024" + VALUE "LegalCopyright", "Copyright (C) 2022-2025" VALUE "OriginalFilename", METIN2_COMPONENT_FILENAME VALUE "ProductName", "Metin2Config" - VALUE "ProductVersion", "0.3.1.0" + VALUE "ProductVersion", "0.4.0.0" END END diff --git a/src/EffectLib/EffectMesh.cpp b/src/EffectLib/EffectMesh.cpp index 91cae49b..672849e2 100644 --- a/src/EffectLib/EffectMesh.cpp +++ b/src/EffectLib/EffectMesh.cpp @@ -192,15 +192,14 @@ BOOL CEffectMesh::__LoadData_Ver002(int iSize, const BYTE * c_pbBuf) if (0 == strExtension.compare("ifl")) { - LPCVOID pMotionData; - CMappedFile File; + CEterPackManager::TPackDataPtr motionData; + CMemoryTextFileLoader textFileLoader; - if (CEterPackManager::Instance().Get(File, pMeshData->szDiffuseMapFileName, &pMotionData)) + if (CEterPackManager::Instance().Get(pMeshData->szDiffuseMapFileName, motionData)) { - CMemoryTextFileLoader textFileLoader; std::vector stTokenVector; - textFileLoader.Bind(File.Size(), pMotionData); + textFileLoader.Bind(motionData->size(), motionData->data()); std::string strPathName; GetOnlyPathName(pMeshData->szDiffuseMapFileName, strPathName); @@ -337,15 +336,14 @@ BOOL CEffectMesh::__LoadData_Ver001(int iSize, const BYTE * c_pbBuf) if (0 == strExtension.compare("ifl")) { - LPCVOID pMotionData; - CMappedFile File; + CEterPackManager::TPackDataPtr motionData; + CMemoryTextFileLoader textFileLoader; - if (CEterPackManager::Instance().Get(File, pMeshData->szDiffuseMapFileName, &pMotionData)) + if (CEterPackManager::Instance().Get(pMeshData->szDiffuseMapFileName, motionData)) { - CMemoryTextFileLoader textFileLoader; std::vector stTokenVector; - textFileLoader.Bind(File.Size(), pMotionData); + textFileLoader.Bind(motionData->size(), motionData->data()); std::string strPathName; GetOnlyPathName(pMeshData->szDiffuseMapFileName, strPathName); diff --git a/src/EterImageLib/TGAImage.cpp b/src/EterImageLib/TGAImage.cpp index dfcbfc13..4bbbb58f 100644 --- a/src/EterImageLib/TGAImage.cpp +++ b/src/EterImageLib/TGAImage.cpp @@ -234,18 +234,6 @@ 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; diff --git a/src/EterImageLib/TGAImage.h b/src/EterImageLib/TGAImage.h index 9b1e58c2..beabdaf8 100644 --- a/src/EterImageLib/TGAImage.h +++ b/src/EterImageLib/TGAImage.h @@ -17,7 +17,6 @@ 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); diff --git a/src/EterLib/FileLoaderThread.cpp b/src/EterLib/FileLoaderThread.cpp index e7fcb649..25065e6b 100644 --- a/src/EterLib/FileLoaderThread.cpp +++ b/src/EterLib/FileLoaderThread.cpp @@ -47,9 +47,6 @@ void CFileLoaderThread::Destroy() CloseHandle(m_hSemaphore); m_hSemaphore = NULL; } - - stl_wipe(m_pRequestDeque); - stl_wipe(m_pCompleteDeque); } UINT CFileLoaderThread::Setup() @@ -111,13 +108,11 @@ UINT CFileLoaderThread::Execute(void * /*pvArg*/) return 1; } -void CFileLoaderThread::Request(std::string & c_rstFileName) // called in main thread +void CFileLoaderThread::Request(const std::string& c_rstFileName) // called in main thread { - TData * pData = new TData; - - pData->dwSize = 0; - pData->pvBuf = NULL; - pData->stFileName = c_rstFileName; + TData pData; + pData.fileName = c_rstFileName; + pData.data = nullptr; m_RequestMutex.Lock(); m_pRequestDeque.push_back(pData); @@ -131,7 +126,7 @@ void CFileLoaderThread::Request(std::string & c_rstFileName) // called in main t --m_iRestSemCount; } -bool CFileLoaderThread::Fetch(TData ** ppData) // called in main thread +bool CFileLoaderThread::Fetch(TData& data) // called in main thread { m_CompleteMutex.Lock(); @@ -141,7 +136,7 @@ bool CFileLoaderThread::Fetch(TData ** ppData) // called in main thread return false; } - *ppData = m_pCompleteDeque.front(); + data = m_pCompleteDeque.front(); m_pCompleteDeque.pop_front(); m_CompleteMutex.Unlock(); @@ -158,22 +153,16 @@ void CFileLoaderThread::Process() // called in loader thread return; } - TData * pData = m_pRequestDeque.front(); + auto request = m_pRequestDeque.front(); m_pRequestDeque.pop_front(); m_RequestMutex.Unlock(); - LPCVOID pvBuf; - - if (CEterPackManager::Instance().Get(pData->File, pData->stFileName.c_str(), &pvBuf)) - { - pData->dwSize = pData->File.Size(); - pData->pvBuf = new char [pData->dwSize]; - memcpy(pData->pvBuf, pvBuf, pData->dwSize); - } + if (!CEterPackManager::Instance().Get(request.fileName, request.data)) + request.data = nullptr; m_CompleteMutex.Lock(); - m_pCompleteDeque.push_back(pData); + m_pCompleteDeque.push_back(request); m_CompleteMutex.Unlock(); Sleep(g_iLoadingDelayTime); diff --git a/src/EterLib/FileLoaderThread.h b/src/EterLib/FileLoaderThread.h index e8f095b1..35932b60 100644 --- a/src/EterLib/FileLoaderThread.h +++ b/src/EterLib/FileLoaderThread.h @@ -2,20 +2,18 @@ #define __INC_YMIR_ETERLIB_FILELOADERTHREAD_H__ #include +#include +#include #include "Thread.h" #include "Mutex.h" -#include "../eterBase/MappedFile.h" class CFileLoaderThread { public: typedef struct SData { - std::string stFileName; - - CMappedFile File; - LPVOID pvBuf; - DWORD dwSize; + std::string fileName; + std::shared_ptr> data; } TData; public: @@ -25,8 +23,8 @@ class CFileLoaderThread int Create(void * arg); public: - void Request(std::string & c_rstFileName); - bool Fetch(TData ** ppData); + void Request(const std::string& c_rstFileName); + bool Fetch(TData& data); void Shutdown(); protected: @@ -49,10 +47,10 @@ class CFileLoaderThread void Process(); private: - std::deque m_pRequestDeque; + std::deque m_pRequestDeque; Mutex m_RequestMutex; - std::deque m_pCompleteDeque; + std::deque m_pCompleteDeque; Mutex m_CompleteMutex; HANDLE m_hSemaphore; diff --git a/src/EterLib/GrpImageTexture.cpp b/src/EterLib/GrpImageTexture.cpp index 1b7391bb..618379c6 100644 --- a/src/EterLib/GrpImageTexture.cpp +++ b/src/EterLib/GrpImageTexture.cpp @@ -50,13 +50,11 @@ bool CGraphicImageTexture::CreateDeviceObjects() } else { - CMappedFile mappedFile; - LPCVOID c_pvMap; - - if (!CEterPackManager::Instance().Get(mappedFile, m_stFileName.c_str(), &c_pvMap)) + CEterPackManager::TPackDataPtr data; + if (!CEterPackManager::Instance().Get(m_stFileName, data)) return false; - return CreateFromMemoryFile(mappedFile.Size(), c_pvMap, m_d3dFmt, m_dwFilter); + return CreateFromMemoryFile(data->size(), data->data(), m_d3dFmt, m_dwFilter); } m_bEmpty = false; diff --git a/src/EterLib/Resource.cpp b/src/EterLib/Resource.cpp index a37003c2..34d67612 100644 --- a/src/EterLib/Resource.cpp +++ b/src/EterLib/Resource.cpp @@ -42,18 +42,17 @@ void CResource::Load() const char * c_szFileName = GetFileName(); - DWORD dwStart = ELTimer_GetMSec(); - CMappedFile file; - LPCVOID fileData; + DWORD dwStart = ELTimer_GetMSec(); + CEterPackManager::TPackDataPtr fileData; //Tracenf("Load %s", c_szFileName); - if (CEterPackManager::Instance().Get(file, c_szFileName, &fileData)) + if (CEterPackManager::Instance().Get(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(file.Size(), fileData)) + if (OnLoad(fileData->size(), fileData->data())) { me_state = STATE_EXIST; } @@ -81,12 +80,11 @@ void CResource::Reload() Clear(); Tracef("CResource::Reload %s\n", GetFileName()); - CMappedFile file; - LPCVOID fileData; + CEterPackManager::TPackDataPtr fileData; - if (CEterPackManager::Instance().Get(file, GetFileName(), &fileData)) + if (CEterPackManager::Instance().Get(GetFileName(), fileData)) { - if (OnLoad(file.Size(), fileData)) + if (OnLoad(fileData->size(), fileData->data())) { me_state = STATE_EXIST; } diff --git a/src/EterLib/ResourceManager.cpp b/src/EterLib/ResourceManager.cpp index c917caa6..7857680a 100644 --- a/src/EterLib/ResourceManager.cpp +++ b/src/EterLib/ResourceManager.cpp @@ -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->stFileName.c_str()); + CResource * pResource = GetResourcePointer(pData.fileName.c_str()); if (pResource) { if (pResource->IsEmpty()) { - pResource->OnLoad(pData->dwSize, pData->pvBuf); + pResource->OnLoad(pData.data->size(), pData.data->data()); pResource->AddReferenceOnly(); // 여기서 올라간 레퍼런스 카운트를 일정 시간이 지난 뒤에 풀어주기 위하여 @@ -79,10 +79,7 @@ void CResourceManager::ProcessBackgroundLoading() } } - m_WaitingMap.erase(GetCRC32(pData->stFileName.c_str(), pData->stFileName.size())); - - delete [] ((char *) pData->pvBuf); - delete pData; + m_WaitingMap.erase(GetCRC32(pData.fileName.c_str(), pData.fileName.size())); } // DO : 일정 시간이 지나고 난뒤 미리 로딩해 두었던 리소스의 레퍼런스 카운트를 감소 시킨다 - [levites] diff --git a/src/EterLib/ResourceManager.h b/src/EterLib/ResourceManager.h index 22308a5e..7e382f1f 100644 --- a/src/EterLib/ResourceManager.h +++ b/src/EterLib/ResourceManager.h @@ -2,6 +2,7 @@ #include "Resource.h" #include "FileLoaderThread.h" +#include "../EterBase/Singleton.h" #include #include diff --git a/src/EterLib/TextFileLoader.cpp b/src/EterLib/TextFileLoader.cpp index d6639011..20f16157 100644 --- a/src/EterLib/TextFileLoader.cpp +++ b/src/EterLib/TextFileLoader.cpp @@ -179,14 +179,13 @@ bool CTextFileLoader::Load(const char * c_szFileName) { m_strFileName = ""; - const VOID* pvData; - CMappedFile kFile; - if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData)) + CEterPackManager::TPackDataPtr data; + if (!CEterPackManager::Instance().Get(c_szFileName, data)) return false; - if (m_dwBufCapacitysize()) { - m_dwBufCapacity=kFile.Size(); + m_dwBufCapacity = data->size(); if (m_acBufData) delete [] m_acBufData; @@ -194,8 +193,8 @@ bool CTextFileLoader::Load(const char * c_szFileName) m_acBufData=new char[m_dwBufCapacity]; } - m_dwBufSize=kFile.Size(); - memcpy(m_acBufData, pvData, m_dwBufSize); + m_dwBufSize = data->size(); + memcpy_s(m_acBufData, m_dwBufCapacity, data->data(), data->size()); m_strFileName = c_szFileName; m_dwcurLineIndex = 0; diff --git a/src/EterLib/Util.cpp b/src/EterLib/Util.cpp index 764947d1..25dc4a1f 100644 --- a/src/EterLib/Util.cpp +++ b/src/EterLib/Util.cpp @@ -20,16 +20,14 @@ void PrintfTabs(FILE * File, int iTabCount, const char * c_szString, ...) bool LoadTextData(const char * c_szFileName, CTokenMap & rstTokenMap) { - LPCVOID pMotionData; - CMappedFile File; + CEterPackManager::TPackDataPtr motionData; + CMemoryTextFileLoader textFileLoader; - if (!CEterPackManager::Instance().Get(File, c_szFileName, &pMotionData)) + if (!CEterPackManager::Instance().Get(c_szFileName, motionData)) return false; - CMemoryTextFileLoader textFileLoader; CTokenVector stTokenVector; - - textFileLoader.Bind(File.Size(), pMotionData); + textFileLoader.Bind(motionData->size(), motionData->data()); for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i) { @@ -50,18 +48,16 @@ bool LoadTextData(const char * c_szFileName, CTokenMap & rstTokenMap) bool LoadMultipleTextData(const char * c_szFileName, CTokenVectorMap & rstTokenVectorMap) { - LPCVOID pModelData; - CMappedFile File; + CEterPackManager::TPackDataPtr modelData; + CMemoryTextFileLoader textFileLoader; - if (!CEterPackManager::Instance().Get(File, c_szFileName, &pModelData)) + if (!CEterPackManager::Instance().Get(c_szFileName, modelData)) return false; DWORD i; - - CMemoryTextFileLoader textFileLoader; CTokenVector stTokenVector; - textFileLoader.Bind(File.Size(), pModelData); + textFileLoader.Bind(modelData->size(), modelData->data()); for (i = 0; i < textFileLoader.GetLineCount(); ++i) { diff --git a/src/EterPack/EterPack.cpp b/src/EterPack/EterPack.cpp deleted file mode 100644 index 62d55618..00000000 --- a/src/EterPack/EterPack.cpp +++ /dev/null @@ -1,1565 +0,0 @@ -#include "StdAfx.h" - -#include -#include -#include -#include - -#include "EterPack.h" -#include "Inline.h" -#include "EterPackPolicy_CSHybridCrypt.h" - -#pragma warning(push, 3) -#include -#include -#include -#include -#include -#include -#include -#include - -#pragma warning(pop) - -#include "../EterBase/utils.h" -#include "../EterBase/Debug.h" -#include "../EterBase/CRC32.h" - -#include -#include - -void CMakePackLog::SetFileName(const char* c_szFileName) -{ - m_stFileName=c_szFileName; - m_stFileName +=".log"; - m_stErrorFileName = c_szFileName; - m_stErrorFileName += ".err"; -} - -CMakePackLog& CMakePackLog::GetSingleton() -{ - static CMakePackLog s_kMakePackLog; - return s_kMakePackLog; -} - -CMakePackLog::CMakePackLog() -{ - m_fp=NULL; - m_fp_err = NULL; -} - -CMakePackLog::~CMakePackLog() -{ - if (NULL!=m_fp) - { - fclose(m_fp); - m_fp=NULL; - } - if (NULL != m_fp_err) - { - fclose(m_fp_err); - m_fp_err = NULL; - } -} - -bool CMakePackLog::__IsLogMode() -{ - if (m_stFileName.empty()) - return false; - - return true; -} - -void CMakePackLog::Writef(const char* c_szFormat, ...) -{ - if (!__IsLogMode()) - return; - - va_list args; - va_start(args, c_szFormat); - - char szBuf[1024]; - int nBufLen = _vsnprintf(szBuf, sizeof(szBuf), c_szFormat, args); - szBuf[nBufLen++] = '\0'; - __Write(szBuf, nBufLen); -} - -void CMakePackLog::Writenf(const char* c_szFormat, ...) -{ - if (!__IsLogMode()) - return; - - va_list args; - va_start(args, c_szFormat); - - char szBuf[1024+1]; - int nBufLen = _vsnprintf(szBuf, sizeof(szBuf)-1, c_szFormat, args); - if (nBufLen > 0) - { - szBuf[nBufLen++] = '\n'; - szBuf[nBufLen++] = '\0'; - } - __Write(szBuf, nBufLen); -} - -void CMakePackLog::Write(const char* c_szBuf) -{ - if (!__IsLogMode()) - return; - - __Write(c_szBuf, strlen(c_szBuf)+1); -} - -void CMakePackLog::__Write(const char* c_szBuf, int nBufLen) -{ - if (!__IsLogMode()) - return; - - if (NULL==m_fp) - m_fp=fopen(m_stFileName.c_str(), "w"); - - fwrite(c_szBuf, nBufLen, 1, m_fp); - - printf("%s", c_szBuf); -} - - - -void CMakePackLog::WriteErrorf(const char* c_szFormat, ...) -{ - if (!__IsLogMode()) - return; - - va_list args; - va_start(args, c_szFormat); - - char szBuf[1024]; - int nBufLen = _vsnprintf(szBuf, sizeof(szBuf), c_szFormat, args); - szBuf[nBufLen++] = '\0'; - __WriteError(szBuf, nBufLen); -} - -void CMakePackLog::WriteErrornf(const char* c_szFormat, ...) -{ - if (!__IsLogMode()) - return; - - va_list args; - va_start(args, c_szFormat); - - char szBuf[1024+1]; - int nBufLen = _vsnprintf(szBuf, sizeof(szBuf)-1, c_szFormat, args); - if (nBufLen > 0) - { - szBuf[nBufLen++] = '\n'; - szBuf[nBufLen++] = '\0'; - } - __WriteError(szBuf, nBufLen); -} - -void CMakePackLog::WriteError(const char* c_szBuf) -{ - if (!__IsLogMode()) - return; - - __WriteError(c_szBuf, strlen(c_szBuf)+1); -} - -void CMakePackLog::__WriteError(const char* c_szBuf, int nBufLen) -{ - if (!__IsLogMode()) - return; - - if (NULL==m_fp_err) - m_fp_err=fopen(m_stErrorFileName.c_str(), "w"); - - fwrite(c_szBuf, nBufLen, 1, m_fp_err); - - printf("Error: %s", c_szBuf); -} - -void CMakePackLog::FlushError() -{ - std::wifstream iFile(m_stErrorFileName.c_str()); - std::istream_iterator iit(iFile); - std::istream_iterator eos; - - std::vector vText; - - std::copy (iit, eos, std::back_inserter(vText)); - - std::ostream_iterator > oit(std::wcout); - - std::sort (vText.begin(), vText.end()); - std::copy (vText.begin(), vText.end(), oit); -} -#ifdef __MAKE_PACK__ -FILE * CEterPack::ms_PackLogFile = NULL; -#endif -/////////////////////////////////////////////////////////////////////////////// -CEterPack::CEterPack() : m_indexCount(0), m_indexData(NULL), m_FragmentSize(0), m_bEncrypted(false), m_bReadOnly(false), m_bDecrypedIV(false) -{ - m_pCSHybridCryptPolicy = new EterPackPolicy_CSHybridCrypt; - -} - -CEterPack::~CEterPack() -{ - Destroy(); - - delete m_pCSHybridCryptPolicy; - m_pCSHybridCryptPolicy = NULL; -} - -void CEterPack::Destroy() -{ - m_bReadOnly = false; - m_bEncrypted = false; - m_indexCount = 0; - m_DataPositionMap.clear(); - - for (int i = 0; i < FREE_INDEX_MAX_SIZE + 1; ++i) - m_FreeIndexList[i].clear(); - - SAFE_DELETE_ARRAY(m_indexData); - - m_FragmentSize = 0; - - memset(m_dbName, 0, sizeof(m_dbName)); - memset(m_indexFileName, 0, sizeof(m_indexFileName)); -} - -const std::string& CEterPack::GetPathName() -{ - return m_stPathName; -} - -bool CEterPack::Create(CEterFileDict& rkFileDict, const char * dbname, const char* pathName, bool bReadOnly, const BYTE* iv) -{ - if (iv) - { - m_stIV_Panama.assign((const char*) iv, 32); - m_bDecrypedIV = false; - } - - m_stPathName = pathName; - - strncpy(m_dbName, dbname, DBNAME_MAX_LEN); - - strncpy(m_indexFileName, dbname, MAX_PATH); - strcat(m_indexFileName, ".eix"); - - m_stDataFileName = dbname; - m_stDataFileName += ".epk"; - - m_bReadOnly = bReadOnly; - - // bReadOnly 모드가 아니고 데이터 베이스가 열린다면 생성 실패 - if (!CreateIndexFile()) - return false; - - if (!CreateDataFile()) - return false; - - bool bOverwrite = (iv != NULL); - __BuildIndex(rkFileDict, bOverwrite); - - if (m_bReadOnly) - { - //m_bIsDataLoaded = true; - //if (!m_file.Create(m_stDataFileName.c_str(), (const void**)&m_file_data, 0, 0)) - // return false; - } - else - { - DecryptIndexFile(); - } - - return true; -} - -bool CEterPack::DecryptIV(DWORD dwPanamaKey) -{ - if (m_stIV_Panama.length() != 32) - return false; - - if (m_bDecrypedIV) // 이미 암호화가 풀렸으면 다시 처리 안함 - return true; - - DWORD* ivs = (DWORD*)&m_stIV_Panama[0]; - for (int i = 0; i != m_stIV_Panama.length() / sizeof(DWORD); ++i) - { - ivs[i] ^= dwPanamaKey + i * 16777619; - } - - m_bDecrypedIV = true; - return true; -} - -bool CEterPack::DecryptIndexFile() -{ - if (!m_bEncrypted) - return true; - - CFileBase file; - - if (!file.Create(m_indexFileName, CFileBase::FILEMODE_WRITE)) - return false; - - file.Write(&eterpack::c_IndexCC, sizeof(DWORD)); - file.Write(&eterpack::c_Version, sizeof(DWORD)); - file.Write(&m_indexCount, sizeof(long)); - file.Write(m_indexData, sizeof(TEterPackIndex) * m_indexCount); - - file.Close(); - - m_bEncrypted = false; - return true; -} - -static DWORD s_adwEterPackKey[] = -{ - 45129401, - 92367215, - 681285731, - 1710201, -}; - -static DWORD s_adwEterPackSecurityKey[] = -{ - 78952482, - 527348324, - 1632942, - 486274726, -}; - -bool CEterPack::EncryptIndexFile() -{ - CMappedFile file; - LPCVOID pvData; - - if (NULL == file.Create(m_indexFileName, &pvData, 0, 0)) - { - TraceError("EncryptIndex: Cannot open pack index file! %s", m_dbName); - return false; - } - - BYTE * pbData = new BYTE[file.Size()]; - memcpy(pbData, pvData, file.Size()); - - CLZObject zObj; - - if (!CLZO::Instance().CompressEncryptedMemory(zObj, pbData, file.Size(), s_adwEterPackKey)) - { - TraceError("EncryptIndex: Cannot encrypt! %s", m_dbName); - SAFE_DELETE_ARRAY(pbData); - return false; - } - - file.Destroy(); - - while (!DeleteFile(m_indexFileName)); - - FILE * fp; - - fp = fopen(m_indexFileName, "wb"); - - if (!fp) - { - TraceError("EncryptIndex: Cannot open file for writing! %s", m_dbName); - SAFE_DELETE_ARRAY(pbData); - return false; - } - - if (1 != fwrite(zObj.GetBuffer(), zObj.GetSize(), 1, fp)) - { - TraceError("Encryptindex: Cannot write to file! %s", m_indexFileName); - SAFE_DELETE_ARRAY(pbData); - fclose(fp); - return false; - } - - fclose(fp); - - m_bEncrypted = true; - delete [] pbData; - return true; -} - -bool CEterPack::__BuildIndex(CEterFileDict& rkFileDict, bool bOverwrite) -{ - //DWORD dwBeginTime = ELTimer_GetMSec(); - CMappedFile file; - LPCVOID pvData; - CLZObject zObj; - - if (NULL == file.Create(m_indexFileName, &pvData, 0, 0)) - { - TraceError("Cannot open pack index file! %s", m_dbName); - return false; - } - - if (file.Size() < eterpack::c_HeaderSize) - { - TraceError("Pack index file header error! %s", m_dbName); - return false; - } - - DWORD fourcc = *(DWORD *) pvData; - - BYTE * pbData; - UINT uiFileSize; - - if (fourcc == eterpack::c_IndexCC) - { - pbData = (BYTE *) pvData; - uiFileSize = file.Size(); - } - else if (fourcc == CLZObject::ms_dwFourCC) - { - m_bEncrypted = true; - - if (!CLZO::Instance().Decompress(zObj, (const BYTE *) pvData, s_adwEterPackKey)) - return false; - - if (zObj.GetSize() < eterpack::c_HeaderSize) - return false; - - pbData = zObj.GetBuffer(); - uiFileSize = zObj.GetSize(); - } - else - { - TraceError("Pack index file fourcc error! %s", m_dbName); - return false; - } - - pbData += sizeof(DWORD); - - DWORD ver = *(DWORD *) pbData; - pbData += sizeof(DWORD); - - if (ver != eterpack::c_Version) - { - TraceError("Pack index file version error! %s", m_dbName); - return false; - } - - m_indexCount = *(long *) pbData; - pbData += sizeof(long); - - if (uiFileSize < eterpack::c_HeaderSize + sizeof(TEterPackIndex) * m_indexCount) - { - TraceError("Pack index file size error! %s, indexCount %d", m_dbName, m_indexCount); - return false; - } - - //Tracef("Loading Pack file %s elements: %d ... ", m_dbName, m_indexCount); - - m_indexData = new TEterPackIndex[m_indexCount]; - memcpy(m_indexData, pbData, sizeof(TEterPackIndex) * m_indexCount); - - TEterPackIndex * index = m_indexData; - - for (int i = 0; i < m_indexCount; ++i, ++index) - { - if (!index->filename_crc) - { - PushFreeIndex(index); - } - else - { - if (index->real_data_size > index->data_size) - m_FragmentSize += index->real_data_size - index->data_size; - - m_DataPositionMap.insert(TDataPositionMap::value_type(index->filename_crc, index)); - - if (bOverwrite) // 서버 연동 패킹 파일은 나중에 들어오지만 최상위로 등록해야한다 - rkFileDict.UpdateItem(this, index); - else - rkFileDict.InsertItem(this, index); - } - } - - //Tracef("Done. (spent %dms)\n", ELTimer_GetMSec() - dwBeginTime); - return true; -} -// -//void CEterPack::UpdateLastAccessTime() -//{ -// m_tLastAccessTime = time(NULL); -//} -// -//void CEterPack::ClearDataMemoryMap() -//{ -// // m_file이 data file이다... -// m_file.Destroy(); -// m_tLastAccessTime = 0; -// m_bIsDataLoaded = false; -//} - -bool CEterPack::Get(CMappedFile& out_file, const char * filename, LPCVOID * data) -{ - TEterPackIndex * index = FindIndex(filename); - - if (!index) - { - return false; - } - - //UpdateLastAccessTime(); - //if (!m_bIsDataLoaded) - //{ - // if (!m_file.Create(m_stDataFileName.c_str(), (const void**)&m_file_data, 0, 0)) - // return false; - // - // m_bIsDataLoaded = true; - //} - - // 기존에는 CEterPack에서 epk를 memory map에 올려놓고, 요청이 오면 그 부분을 링크해서 넘겨 줬었는데, - // 이제는 요청이 오면, 필요한 부분만 memory map에 올리고, 요청이 끝나면 해제하게 함. - out_file.Create(m_stDataFileName.c_str(), data, index->data_position, index->data_size); - - bool bIsSecurityCheckRequired = ( index->compressed_type == COMPRESSED_TYPE_SECURITY || - index->compressed_type == COMPRESSED_TYPE_PANAMA ); - - if( bIsSecurityCheckRequired ) - { -#ifdef CHECKSUM_CHECK_MD5 - MD5_CTX context; - GenerateMD5Hash( (BYTE*)(*data), index->data_size, context ); - - if( memcmp( index->MD5Digest, context.digest, 16 ) != 0 ) - { - return false; - } -#else - DWORD dwCrc32 = GetCRC32((const char*)(*data), index->data_size); - - if( index->data_crc != dwCrc32 ) - { - return false; - } -#endif - } - - - if (COMPRESSED_TYPE_COMPRESS == index->compressed_type) - { - CLZObject * zObj = new CLZObject; - - if (!CLZO::Instance().Decompress(*zObj, static_cast(*data))) - { - TraceError("Failed to decompress : %s", filename); - delete zObj; - return false; - } - - out_file.BindLZObject(zObj); - *data = zObj->GetBuffer(); - } - else if (COMPRESSED_TYPE_SECURITY == index->compressed_type) - { - CLZObject * zObj = new CLZObject; - - if (!CLZO::Instance().Decompress(*zObj, static_cast(*data), s_adwEterPackSecurityKey)) - { - TraceError("Failed to encrypt : %s", filename); - delete zObj; - return false; - } - - out_file.BindLZObject(zObj); - *data = zObj->GetBuffer(); - } - else if (COMPRESSED_TYPE_PANAMA == index->compressed_type) - { - CLZObject * zObj = new CLZObject; - __Decrypt_Panama(filename, static_cast(*data), index->data_size, *zObj); - out_file.BindLZObjectWithBufferedSize(zObj); - *data = zObj->GetBuffer(); - } - else if (COMPRESSED_TYPE_HYBRIDCRYPT == index->compressed_type || COMPRESSED_TYPE_HYBRIDCRYPT_WITHSDB == index->compressed_type) - { - CLZObject * zObj = new CLZObject; - - if( !m_pCSHybridCryptPolicy->DecryptMemory( std::string(filename), static_cast(*data), index->data_size, *zObj) ) - { - return false; - } - - out_file.BindLZObjectWithBufferedSize(zObj); - if( COMPRESSED_TYPE_HYBRIDCRYPT_WITHSDB == index->compressed_type) - { - BYTE* pSDBData; - int iSDBSize; - - if( !m_pCSHybridCryptPolicy->GetSupplementaryDataBlock( std::string(filename), pSDBData, iSDBSize) ) - { - return false; - } - - *data = out_file.AppendDataBlock( pSDBData, iSDBSize ); - } - else - { - *data = zObj->GetBuffer(); - } - } - return true; -} - -bool CEterPack::Get2(CMappedFile& out_file, const char * filename, TEterPackIndex * index, LPCVOID * data) -{ - if (!index) - { - return false; - } - - //UpdateLastAccessTime(); - //if (!m_bIsDataLoaded) - //{ - // if (!m_file.Create(m_stDataFileName.c_str(), (const void**)&m_file_data, 0, 0)) - // return false; - // - // m_bIsDataLoaded = true; - //} - out_file.Create(m_stDataFileName.c_str(), data, index->data_position, index->data_size); - - bool bIsSecurityCheckRequired = ( index->compressed_type == COMPRESSED_TYPE_SECURITY || - index->compressed_type == COMPRESSED_TYPE_PANAMA ); - - if( bIsSecurityCheckRequired ) - { -#ifdef CHECKSUM_CHECK_MD5 - MD5_CTX context; - GenerateMD5Hash( (BYTE*)(*data), index->data_size, context ); - - if( memcmp( index->MD5Digest, context.digest, 16 ) != 0 ) - { - return false; - } -#else - DWORD dwCrc32 = GetCRC32((const char*)(*data), index->data_size); - - if( index->data_crc != dwCrc32 ) - { - return false; - } -#endif - } - - - if (COMPRESSED_TYPE_COMPRESS == index->compressed_type) - { - CLZObject * zObj = new CLZObject; - - if (!CLZO::Instance().Decompress(*zObj, static_cast(*data))) - { - TraceError("Failed to decompress : %s", filename); - delete zObj; - return false; - } - - out_file.BindLZObject(zObj); - *data = zObj->GetBuffer(); - } - else if (COMPRESSED_TYPE_SECURITY == index->compressed_type) - { - CLZObject * zObj = new CLZObject; - - if (!CLZO::Instance().Decompress(*zObj, static_cast(*data), s_adwEterPackSecurityKey)) - { - TraceError("Failed to encrypt : %s", filename); - delete zObj; - return false; - } - - out_file.BindLZObject(zObj); - *data = zObj->GetBuffer(); - } - else if (COMPRESSED_TYPE_PANAMA == index->compressed_type) - { - CLZObject * zObj = new CLZObject; - __Decrypt_Panama(filename, static_cast(*data), index->data_size, *zObj); - out_file.BindLZObjectWithBufferedSize(zObj); - *data = zObj->GetBuffer(); - } - else if (COMPRESSED_TYPE_HYBRIDCRYPT == index->compressed_type || COMPRESSED_TYPE_HYBRIDCRYPT_WITHSDB == index->compressed_type) - { - CLZObject * zObj = new CLZObject; - - if( !m_pCSHybridCryptPolicy->DecryptMemory( std::string(filename), static_cast(*data), index->data_size, *zObj) ) - { - return false; - } - - out_file.BindLZObjectWithBufferedSize(zObj); - - if( COMPRESSED_TYPE_HYBRIDCRYPT_WITHSDB == index->compressed_type) - { - BYTE* pSDBData; - int iSDBSize; - - if( !m_pCSHybridCryptPolicy->GetSupplementaryDataBlock( std::string(filename), pSDBData, iSDBSize) ) - { - return false; - } - - *data = out_file.AppendDataBlock( pSDBData, iSDBSize ); - } - else - { - *data = zObj->GetBuffer(); - } - } - - return true; -} - - -bool CEterPack::Delete(TEterPackIndex * pIndex) -{ - CFileBase fileIndex; - - if (!fileIndex.Create(m_indexFileName, CFileBase::FILEMODE_WRITE)) - return false; - - PushFreeIndex(pIndex); - WriteIndex(fileIndex, pIndex); - return true; -} - -bool CEterPack::Delete(const char * filename) -{ - TEterPackIndex * pIndex = FindIndex(filename); - - if (!pIndex) - return false; - - return Delete(pIndex); -} - -bool CEterPack::Extract() -{ - CMappedFile dataMapFile; - LPCVOID data; - - if (!dataMapFile.Create(m_stDataFileName.c_str(), &data, 0, 0)) - return false; - - CLZObject zObj; - - for (TDataPositionMap::iterator i = m_DataPositionMap.begin(); - i != m_DataPositionMap.end(); - ++i) - { - TEterPackIndex* index = i->second; - CFileBase writeFile; - - inlinePathCreate(index->filename); - printf("%s\n", index->filename); - - writeFile.Create(index->filename, CFileBase::FILEMODE_WRITE); - - if (COMPRESSED_TYPE_COMPRESS == index->compressed_type) - { - if (!CLZO::Instance().Decompress(zObj, (const BYTE *) data + index->data_position)) - { - printf("cannot decompress"); - return false; - } - - writeFile.Write(zObj.GetBuffer(), zObj.GetSize()); - zObj.Clear(); - } - else if (COMPRESSED_TYPE_SECURITY == index->compressed_type) - { - if (!CLZO::Instance().Decompress(zObj, (const BYTE *) data + index->data_position, s_adwEterPackSecurityKey)) - { - printf("cannot decompress"); - return false; - } - - writeFile.Write(zObj.GetBuffer(), zObj.GetSize()); - zObj.Clear(); - } - else if (COMPRESSED_TYPE_PANAMA == index->compressed_type) - { - __Decrypt_Panama(index->filename, (const BYTE *) data + index->data_position, index->data_size, zObj); - writeFile.Write(zObj.GetBuffer(), zObj.GetBufferSize()); - zObj.Clear(); - } - else if (COMPRESSED_TYPE_HYBRIDCRYPT == index->compressed_type || COMPRESSED_TYPE_HYBRIDCRYPT_WITHSDB == index->compressed_type) - { - if( !m_pCSHybridCryptPolicy->DecryptMemory( std::string(index->filename), (const BYTE *) data + index->data_position, index->data_size, zObj) ) - return false; - - if( COMPRESSED_TYPE_HYBRIDCRYPT_WITHSDB == index->compressed_type) - { - dataMapFile.BindLZObjectWithBufferedSize(&zObj); - - BYTE* pSDBData; - int iSDBSize; - - if( !m_pCSHybridCryptPolicy->GetSupplementaryDataBlock( std::string(index->filename), pSDBData, iSDBSize) ) - return false; - - dataMapFile.AppendDataBlock( pSDBData, iSDBSize ); - writeFile.Write(dataMapFile.AppendDataBlock( pSDBData, iSDBSize ),dataMapFile.Size()); - } - else - { - writeFile.Write(zObj.GetBuffer(), zObj.GetBufferSize()); - } - zObj.Clear(); - } - else if (COMPRESSED_TYPE_NONE == index->compressed_type) - writeFile.Write((const char *) data + index->data_position, index->data_size); - - writeFile.Destroy(); - } - return true; -} - -bool CEterPack::GetNames(std::vector* retNames) -{ - CMappedFile dataMapFile; - LPCVOID data; - - if (!dataMapFile.Create(m_stDataFileName.c_str(), &data, 0, 0)) - return false; - - CLZObject zObj; - - for (TDataPositionMap::iterator i = m_DataPositionMap.begin(); - i != m_DataPositionMap.end(); - ++i) - { - TEterPackIndex* index = i->second; - - inlinePathCreate(index->filename); - - retNames->push_back(index->filename); - } - return true; -} - -bool CEterPack::Put(const char * filename, const char * sourceFilename, BYTE packType, const std::string& strRelateMapName ) -{ - CMappedFile mapFile; - LPCVOID data; - - if (sourceFilename) - { - if (!mapFile.Create(sourceFilename, &data, 0, 0)) - { - return false; - } - } - else if (!mapFile.Create(filename, &data, 0, 0)) - { - return false; - } - - BYTE* pMappedData = (BYTE*)data; - int iMappedDataSize = mapFile.Size(); - - if( packType == COMPRESSED_TYPE_HYBRIDCRYPT || packType == COMPRESSED_TYPE_HYBRIDCRYPT_WITHSDB ) - { - m_pCSHybridCryptPolicy->GenerateCryptKey( std::string(filename) ); - - if( packType == COMPRESSED_TYPE_HYBRIDCRYPT_WITHSDB ) - { - if( !m_pCSHybridCryptPolicy->GenerateSupplementaryDataBlock( std::string(filename), strRelateMapName, (const BYTE*)data, mapFile.Size(), pMappedData, iMappedDataSize )) - { - return false; - } - } - } - - return Put(filename, pMappedData, iMappedDataSize, packType); -} - -#ifdef CHECKSUM_CHECK_MD5 -void CEterPack::GenerateMD5Hash( BYTE* pData, int nLength, IN OUT MD5_CTX& mdContext ) -{ - MD5Init (&mdContext); - - const int nBlockSize = 1024; - - int nLoopCnt = nLength / nBlockSize; - int nRemainder = nLength % nBlockSize; - int i; - - for(i = 0; i < nLoopCnt; ++i ) - { - MD5Update (&mdContext, reinterpret_cast(pData + i*nBlockSize), nBlockSize); - } - - if( nRemainder > 0 ) - MD5Update (&mdContext, reinterpret_cast(pData + i*nBlockSize), nRemainder); - - MD5Final (&mdContext); -} -#endif -bool CEterPack::Put(const char * filename, LPCVOID data, long len, BYTE packType) -{ - if (m_bEncrypted) - { - TraceError("EterPack::Put : Cannot put to encrypted pack (filename: %s, DB: %s)", filename, m_dbName); - return false; - } - - CFileBase fileIndex; - - if (!fileIndex.Create(m_indexFileName, CFileBase::FILEMODE_WRITE)) - { - return false; - } - - CFileBase fileData; - - if (!fileData.Create(m_stDataFileName.c_str(), CFileBase::FILEMODE_WRITE)) - { - return false; - } - - TEterPackIndex * pIndex; - pIndex = FindIndex(filename); - - CLZObject zObj; - std::string encryptStr; - - if (packType == COMPRESSED_TYPE_SECURITY || - packType == COMPRESSED_TYPE_COMPRESS) - { - if (packType == COMPRESSED_TYPE_SECURITY) - { - if (!CLZO::Instance().CompressEncryptedMemory(zObj, data, len, s_adwEterPackSecurityKey)) - { - return false; - } - } - else - { - if (!CLZO::Instance().CompressMemory(zObj, data, len)) - { - return false; - } - } - - data = zObj.GetBuffer(); - len = zObj.GetSize(); - } - else if (packType == COMPRESSED_TYPE_PANAMA) - { - if (!__Encrypt_Panama(filename, (const BYTE *) data, len, zObj)) - { - return false; - } - - data = zObj.GetBuffer(); - len = zObj.GetBufferSize(); - } - else if (packType == COMPRESSED_TYPE_HYBRIDCRYPT || packType == COMPRESSED_TYPE_HYBRIDCRYPT_WITHSDB ) - { - if( !m_pCSHybridCryptPolicy->EncryptMemory( std::string(filename), (const BYTE *)data, len, zObj ) ) - { - return false; - } - - data = zObj.GetBuffer(); - len = zObj.GetBufferSize(); - } - - -#ifdef CHECKSUM_CHECK_MD5 - MD5_CTX context; - GenerateMD5Hash( (BYTE*)(data), len, context ); -#else - DWORD data_crc; - data_crc = GetCRC32((const char *) data, len); -#endif - - // 기존 데이터가 있으면.. - if (pIndex) - { - // 기존 data 크기가 넣을 데이터 크기를 수용할 수 있다면 - if (pIndex->real_data_size >= len) - { - ++m_map_indexRefCount[pIndex->id]; - - // 길이가 틀리거나, checksum이 틀릴 때만 저장 한다. - if ( (pIndex->data_size != len) || -#ifdef CHECKSUM_CHECK_MD5 - (memcmp( pIndex->MD5Digest, context.digest, 16 ) != 0) ) -#else - (pIndex->data_crc != data_crc) ) -#endif - { -#ifdef __MAKE_PACK__ - if (ms_PackLogFile) - fprintf(ms_PackLogFile, "Overwrite[%d/%d] %s\n", bCompress, bSecurity, pIndex->filename); - printf("Overwrite[%d/%d] %s\n", bCompress, bSecurity, pIndex->filename); -#endif - pIndex->data_size = len; -#ifdef CHECKSUM_CHECK_MD5 - memcpy( pIndex->MD5Digest, context.digest, 16 ); - -#else - pIndex->data_crc = data_crc; -#endif - - pIndex->compressed_type = packType; - - CMakePackLog::GetSingleton().Writef("Overwrite[type:%u] %s\n", pIndex->compressed_type, pIndex->filename); - - WriteIndex(fileIndex, pIndex); - WriteData(fileData, pIndex, data); - } - - return true; - } - - // 기존 데이터 크기가 새로 들어갈 것 보다 적다면, 새로 인덱스를 할당해 - // 넣어야 한다. 원래 있던 인덱스는 비워 둔다. - PushFreeIndex(pIndex); - WriteIndex(fileIndex, pIndex); - } - - // 새 데이터 - pIndex = NewIndex(fileIndex, filename, len); - pIndex->data_size = len; - -#ifdef CHECKSUM_CHECK_MD5 - memcpy( pIndex->MD5Digest, context.digest, 16 ); -#else - pIndex->data_crc = data_crc; -#endif - - - pIndex->data_position = GetNewDataPosition(fileData); - pIndex->compressed_type = packType; - - WriteIndex(fileIndex, pIndex); - WriteNewData(fileData, pIndex, data); - - ++m_map_indexRefCount[pIndex->id]; - -#ifdef __MAKE_PACK__ - if (ms_PackLogFile) - fprintf(ms_PackLogFile, "Write[%d/%d] %s\n", bCompress, bSecurity, pIndex->filename); - printf("Write[%d/%d] %s, position %ld realsize %ld size %ld\n", - bCompress, bSecurity, pIndex->filename, pIndex->data_position, pIndex->real_data_size, pIndex->data_size); -#endif - CMakePackLog::GetSingleton().Writef("Write[type:%u] %s\n", pIndex->compressed_type, pIndex->filename); - - return true; -} - -long CEterPack::GetFragmentSize() -{ - return m_FragmentSize; -} - -// Private methods -bool CEterPack::CreateIndexFile() -{ - FILE * fp; - - if (NULL != (fp = fopen(m_indexFileName, "rb"))) - { - fclose(fp); - return true; - } - else if (m_bReadOnly) - return false; - - // - // 파일이 없으므로 새로 만든다. - // - fp = fopen(m_indexFileName, "wb"); - - if (!fp) - return false; - - fwrite(&eterpack::c_IndexCC, sizeof(DWORD), 1, fp); - fwrite(&eterpack::c_Version, sizeof(DWORD), 1, fp); - fwrite(&m_indexCount, sizeof(long), 1, fp); - - fclose(fp); - return true; -} - - -void CEterPack::WriteIndex(CFileBase & file, TEterPackIndex * index) -{ - file.Seek(sizeof(DWORD) + sizeof(DWORD)); - file.Write(&m_indexCount, sizeof(long)); - file.Seek(eterpack::c_HeaderSize + (index->id * sizeof(TEterPackIndex))); - - if (!file.Write(index, sizeof(TEterPackIndex))) - { - assert(!"WriteIndex: fwrite failed"); - return; - } -} - -/* - * Free Block 이란 데이터에서 지워진 부분을 말한다. - * Free Block 들은 각각 FREE_INDEX_BLOCK_SIZE (32768) 단위로 나누어져 - * 리스트로 관리된다. - * - * 예를 들어 128k 의 데이터는 - * 128 * 1024 / FREE_INDEX_BLOCK_SIZE = 4 이므로 - * 최종 적으로는 m_FreeIndexList[4] 에 들어간다. - * - * FREE_INDEX_BLOCK_SIZE 의 최대 값은 FREE_INDEX_MAX_SIZE(512) 이다. - * 따라서 16MB 이상의 데이터는 무조건 배열의 512 위치에 들어간다. - */ -int CEterPack::GetFreeBlockIndex(long size) -{ - return min(FREE_INDEX_MAX_SIZE, size / FREE_INDEX_BLOCK_SIZE); -} - -void CEterPack::PushFreeIndex(TEterPackIndex* index) -{ - if (index->filename_crc != 0) - { - TDataPositionMap::iterator i = m_DataPositionMap.find(index->filename_crc); - - if (i != m_DataPositionMap.end()) - m_DataPositionMap.erase(i); - - index->filename_crc = 0; - memset(index->filename, 0, sizeof(index->filename)); - } - - int blockidx = GetFreeBlockIndex(index->real_data_size); - m_FreeIndexList[blockidx].push_back(index); - m_FragmentSize += index->real_data_size; - //printf("FreeIndex: size %d: blockidx: %d\n", index->real_data_size, blockidx); -} - -long CEterPack::GetNewIndexPosition(CFileBase & file) -{ - long pos = (file.Size() - eterpack::c_HeaderSize) / sizeof(TEterPackIndex); - ++m_indexCount; - return (pos); -} - -TEterPackIndex* CEterPack::NewIndex(CFileBase& file, const char* filename, long size) -{ - TEterPackIndex* index = NULL; - int block_size = size + (DATA_BLOCK_SIZE - (size % DATA_BLOCK_SIZE)); -// if ((index = FindIndex(filename))) // 이미 인덱스가 존재하는지 확인 -// return index; - - int blockidx = GetFreeBlockIndex(block_size); - - for (TFreeIndexList::iterator i = m_FreeIndexList[blockidx].begin(); - i != m_FreeIndexList[blockidx].end(); - ++i) - { - if ((*i)->real_data_size >= size) - { - index = *i; - m_FreeIndexList[blockidx].erase(i); - - assert(index->filename_crc == 0); - break; - } - } - - if (!index) - { - index = new TEterPackIndex; - index->real_data_size = block_size; - index->id = GetNewIndexPosition(file); - } - - strncpy(index->filename, filename, FILENAME_MAX_LEN); - index->filename[FILENAME_MAX_LEN] = '\0'; - inlineConvertPackFilename(index->filename); - - index->filename_crc = GetCRC32(index->filename, strlen(index->filename)); - - m_DataPositionMap.insert(TDataPositionMap::value_type(index->filename_crc, index)); - return index; -} - -TEterPackIndex* CEterPack::FindIndex(const char * filename) -{ - static char tmpFilename[MAX_PATH + 1]; - strncpy(tmpFilename, filename, MAX_PATH); - inlineConvertPackFilename(tmpFilename); - - DWORD filename_crc = GetCRC32(tmpFilename, strlen(tmpFilename)); - TDataPositionMap::iterator i = m_DataPositionMap.find(filename_crc); - - if (i == m_DataPositionMap.end()) - return NULL; - - return (i->second); -} - -bool CEterPack::IsExist(const char * filename) -{ - return FindIndex(filename) ? true : false; -} - -bool CEterPack::CreateDataFile() -{ - FILE * fp; - - if (NULL != (fp = fopen(m_stDataFileName.c_str(), "rb"))) - { - fclose(fp); - return true; - } - else if (m_bReadOnly) - return false; - - fp = fopen(m_stDataFileName.c_str(), "wb"); - - if (!fp) - return false; - - fclose(fp); - return true; -} - -long CEterPack::GetNewDataPosition(CFileBase& file) -{ - return file.Size(); -} - -bool CEterPack::ReadData(CFileBase & file, TEterPackIndex* index, LPVOID data, long maxsize) -{ - if (index->data_size > maxsize) - return false; - - file.Seek(index->data_position); - file.Read(data, index->data_size); - return true; -} - -bool CEterPack::WriteData(CFileBase & file, TEterPackIndex* index, LPCVOID data) -{ - file.Seek(index->data_position); - - if (!file.Write(data, index->data_size)) - { - assert(!"WriteData: fwrite data failed"); - return false; - } - - return true; -} - -bool CEterPack::WriteNewData(CFileBase& file, TEterPackIndex* index, LPCVOID data) -{ - file.Seek(index->data_position); - - if (!file.Write(data, index->data_size)) - { - assert(!"WriteData: fwrite data failed"); - return false; - } - - int empty_size = index->real_data_size - index->data_size; - - if (empty_size < 0) - { - printf("SYSERR: WriteNewData(): CRITICAL ERROR: empty_size lower than 0!\n"); - exit(1); - } - - if (empty_size == 0) - return true; - - char * empty_buf = (char *) calloc(empty_size, sizeof(char)); - - if (!file.Write(empty_buf, empty_size)) - { - assert(!"WriteData: fwrite empty data failed"); - return false; - } - - free(empty_buf); - return true; -} - -TDataPositionMap & CEterPack::GetIndexMap() -{ - return m_DataPositionMap; -} - -DWORD CEterPack::DeleteUnreferencedData() -{ - TDataPositionMap::iterator i = m_DataPositionMap.begin(); - DWORD dwCount = 0; - - while (i != m_DataPositionMap.end()) - { - TEterPackIndex * pIndex = (i++)->second; - - if (0 == m_map_indexRefCount[pIndex->id]) - { - printf("Unref File %s\n", pIndex->filename); - Delete(pIndex); - ++dwCount; - } - } - - return dwCount; -} - -const char * CEterPack::GetDBName() -{ - return m_dbName; -} - -void CEterPack::__CreateFileNameKey_Panama(const char * filename, BYTE * key, unsigned int keySize) -{ - // 키 암호화 - if (keySize != 32) - return; - - std::string SrcStringForKey(filename); - unsigned int idx = GetCRC32(SrcStringForKey.c_str(), SrcStringForKey.length()) & 3; - - CryptoPP::HashTransformation* hm1 = NULL; - CryptoPP::HashTransformation* hm2 = NULL; - - static CryptoPP::Tiger tiger; - static CryptoPP::SHA1 sha1; - static CryptoPP::RIPEMD128 ripemd128; - static CryptoPP::Whirlpool whirlpool; - - switch (idx & 3) - { - case 0: - hm1 = &whirlpool; - break; - - case 1: - hm1 = &tiger; - break; - - case 2: - hm1 = &sha1; - break; - - case 3: - hm1 = &ripemd128; - break; - } - - CryptoPP::StringSource(SrcStringForKey, true, - new CryptoPP::HashFilter(*hm1, - //new CryptoPP::HexEncoder( - new CryptoPP::ArraySink(key, 16) - //) // HexEncoder - ) // HashFilter - ); // StringSource - - // 만들어진 키의 첫번째 4바이트로 다음 16바이트 키 생성 알고리즘 선택 - unsigned int idx2 = *(unsigned int*) key; - - switch (idx2 & 3) - { - case 0: - hm2 = &sha1; - break; - - case 1: - hm2 = &ripemd128; - break; - - case 2: - hm2 = &whirlpool; - break; - - case 3: - hm2 = &tiger; - break; - } - - CryptoPP::StringSource(SrcStringForKey, true, - new CryptoPP::HashFilter(*hm2, - //new CryptoPP::HexEncoder( - new CryptoPP::ArraySink(key + 16, 16) - //) // HexEncoder - ) // HashFilter - ); // StringSource - // 키 생성 완료 -} - -bool CEterPack::__Encrypt_Panama(const char* filename, const BYTE* data, SIZE_T dataSize, CLZObject& zObj) -{ - if (32 != m_stIV_Panama.length()) - { - // 해커가 이 메세지를 보면 힌트를 얻을까봐 디버그에서만 출력 -#ifdef _DEBUG - TraceError("IV not set (filename: %s)", filename); -#endif - return false; - } - - CryptoPP::PanamaCipher::Encryption Encryptor; - - if (dataSize < Encryptor.MandatoryBlockSize()) - { -#ifdef _DEBUG - TraceError("Type 3 pack file must be bigger than %u bytes (filename: %s)", Encryptor.MandatoryBlockSize(), filename); -#endif - return false; - } - - BYTE key[32]; - - __CreateFileNameKey_Panama(filename, key, sizeof(key)); - Encryptor.SetKeyWithIV(key, sizeof(key), (const BYTE*) m_stIV_Panama.c_str(), 32); - - // MandatoryBlockSize에 나누어 떨어지게 만들고 최대 2048 바이트만 - DWORD cryptSize = dataSize - (dataSize % Encryptor.MandatoryBlockSize()); - cryptSize = cryptSize > 2048 ? 2048 : cryptSize; - - std::string tmp; - - tmp.reserve(cryptSize); - - CryptoPP::ArraySource(data, cryptSize, true, - new CryptoPP::StreamTransformationFilter(Encryptor, - new CryptoPP::StringSink(tmp) - ) - ); - - if (tmp.length() != cryptSize) - { -#ifdef _DEBUG - TraceError("Type 3 pack crypt buffer size error (out %u should be %u)", tmp.length(), cryptSize); -#endif - return false; - } - - zObj.AllocBuffer(dataSize); - memcpy(zObj.GetBuffer(), tmp.c_str(), cryptSize); - - if (dataSize - cryptSize > 0) - memcpy(zObj.GetBuffer() + cryptSize, data + cryptSize, dataSize - cryptSize); - - return true; -} - -bool CEterPack::__Decrypt_Panama(const char* filename, const BYTE* data, SIZE_T dataSize, CLZObject& zObj) -{ - if (32 != m_stIV_Panama.length()) - { - // 해커가 이 메세지를 보면 힌트를 얻을까봐 디버그에서만 출력 -#ifdef _DEBUG - TraceError("IV not set (filename: %s)", filename); -#endif - return false; - } - - CryptoPP::PanamaCipher::Decryption Decryptor; - - BYTE key[32]; - - __CreateFileNameKey_Panama(filename, key, sizeof(key)); - Decryptor.SetKeyWithIV(key, sizeof(key), (const BYTE*) m_stIV_Panama.c_str(), 32); - - // MandatoryBlockSize에 나누어 떨어지게 만들고 최대 2048 바이트만 - DWORD cryptSize = dataSize - (dataSize % Decryptor.MandatoryBlockSize()); - cryptSize = cryptSize > 2048 ? 2048 : cryptSize; - - std::string tmp; - - tmp.reserve(cryptSize); - - CryptoPP::ArraySource(data, cryptSize, true, - new CryptoPP::StreamTransformationFilter(Decryptor, - new CryptoPP::StringSink(tmp) - ) - ); - - if (tmp.length() != cryptSize) - { -#ifdef _DEBUG - TraceError("Type 3 pack crypt buffer size error (out %u should be %u)", tmp.length(), cryptSize); -#endif - return false; - } - - zObj.AllocBuffer(dataSize); - memcpy(zObj.GetBuffer(), tmp.c_str(), cryptSize); - - if (dataSize - cryptSize > 0) - memcpy(zObj.GetBuffer() + cryptSize, data + cryptSize, dataSize - cryptSize); - - return true; -} - -EterPackPolicy_CSHybridCrypt* CEterPack::GetPackPolicy_HybridCrypt() const -{ - return m_pCSHybridCryptPolicy; -} - - -///////////////////////// - -void CEterFileDict::InsertItem(CEterPack* pkPack, TEterPackIndex* pkInfo) -{ - Item item; - - item.pkPack = pkPack; - item.pkInfo = pkInfo; - - m_dict.insert(TDict::value_type(pkInfo->filename_crc, item)); -} - -void CEterFileDict::UpdateItem(CEterPack* pkPack, TEterPackIndex* pkInfo) -{ - Item item; - - item.pkPack = pkPack; - item.pkInfo = pkInfo; - - TDict::iterator f = m_dict.find(pkInfo->filename_crc); - if (f == m_dict.end()) - m_dict.insert(TDict::value_type(pkInfo->filename_crc, item)); - else - { - if (strcmp(f->second.pkInfo->filename, item.pkInfo->filename) == 0) - { - f->second = item; - } - else - { - TraceError("NAME_COLLISION: OLD: %s NEW: %s", f->second.pkInfo->filename, item.pkInfo->filename); - } - - } -} - -CEterFileDict::Item* CEterFileDict::GetItem(DWORD dwFileNameHash, const char * c_pszFileName) -{ - std::pair iter_pair = m_dict.equal_range(dwFileNameHash); - - TDict::iterator iter = iter_pair.first; - - while (iter != iter_pair.second) - { - Item& item = iter->second; - - if (0 == strcmp(c_pszFileName, item.pkInfo->filename)) - return &item; - - ++iter; - } - - return NULL; -} diff --git a/src/EterPack/EterPack.h b/src/EterPack/EterPack.h deleted file mode 100644 index 72597784..00000000 --- a/src/EterPack/EterPack.h +++ /dev/null @@ -1,243 +0,0 @@ -#ifndef __INC_ETERPACKLIB_ETERPACK_H__ -#define __INC_ETERPACKLIB_ETERPACK_H__ - -#include -#include - -#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 TDataPositionMap; -typedef std::list 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 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* 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 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 diff --git a/src/EterPack/EterPack.vcxproj b/src/EterPack/EterPack.vcxproj index 82245bfb..a5767495 100644 --- a/src/EterPack/EterPack.vcxproj +++ b/src/EterPack/EterPack.vcxproj @@ -170,20 +170,6 @@ - - Disabled - EnableFastChecks - true - MaxSpeed - MaxSpeed - - - Disabled - EnableFastChecks - true - MaxSpeed - MaxSpeed - Disabled EnableFastChecks @@ -191,25 +177,16 @@ MaxSpeed MaxSpeed - - - - Disabled - EnableFastChecks - Create - true - MaxSpeed - MaxSpeed - + + - - - + + - + diff --git a/src/EterPack/EterPack.vcxproj.filters b/src/EterPack/EterPack.vcxproj.filters index 78338a16..b79c7850 100644 --- a/src/EterPack/EterPack.vcxproj.filters +++ b/src/EterPack/EterPack.vcxproj.filters @@ -9,48 +9,39 @@ {c156ef19-8b61-496c-a499-8bf66e9ca80d} h;hpp;hxx;hm;inl + + {6348898e-222d-4516-8d4e-e37f9e17d872} + - - Source Files - - - Source Files - Source Files - - Source Files + + File Providers - - Source Files - - - Source Files + + File Providers - - Header Files - - - Header Files - Header Files - - Header Files - Header Files - - Header Files - Header Files + + File Providers + + + File Providers + + + File Providers + \ No newline at end of file diff --git a/src/EterPack/EterPackCursor.cpp b/src/EterPack/EterPackCursor.cpp deleted file mode 100644 index 288a90cc..00000000 --- a/src/EterPack/EterPackCursor.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "StdAfx.h" -#include "EterPackCursor.h" -#include "Inline.h" - -CEterPackCursor::CEterPackCursor(CEterPack* pack) : m_pPack(pack), m_pData(NULL), m_ReadPoint(0) -{ -} - -CEterPackCursor::~CEterPackCursor() -{ - Close(); -} - -bool CEterPackCursor::Open(const char* filename) -{ - assert(m_pPack != NULL); - - char tmpFilename[MAX_PATH + 1]; - strncpy(tmpFilename, filename, MAX_PATH); - inlineConvertPackFilename(tmpFilename); - - if (!m_pPack->Get(m_file, tmpFilename, &m_pData)) - return false; - - return true; -} - -void CEterPackCursor::Close() -{ - m_file.Destroy(); - m_pData = NULL; - m_ReadPoint = 0; -} - -void CEterPackCursor::Seek(long offset) -{ - m_ReadPoint = 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(); -} diff --git a/src/EterPack/EterPackCursor.h b/src/EterPack/EterPackCursor.h deleted file mode 100644 index 5ba802a5..00000000 --- a/src/EterPack/EterPackCursor.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __INC_ETERPACKCURSOR_H__ -#define __INC_ETERPACKCURSOR_H__ - -#include "EterPack.h" - -class CEterPackCursor -{ - public: - CEterPackCursor(CEterPack * pack); - ~CEterPackCursor(); - - bool Open(const char* filename); - void Close(); - void Seek(long offset); - bool Read(LPVOID data, long size); - long Size(); - - private: - CEterPack * m_pPack; - CMappedFile m_file; - LPCVOID m_pData; - long m_ReadPoint; -}; - -#endif diff --git a/src/EterPack/EterPackManager.cpp b/src/EterPack/EterPackManager.cpp index 5c9b7355..b1af5b23 100644 --- a/src/EterPack/EterPackManager.cpp +++ b/src/EterPack/EterPackManager.cpp @@ -1,73 +1,34 @@ #include "StdAfx.h" +#include + #include #include #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\\" -CEterPack* CEterPackManager::FindPack(const char* c_szPathName) -{ - std::string strFileName; - - if (0 == ConvertFileName(c_szPathName, strFileName)) - { - return &m_RootPack; - } - else - { - for (TEterPackMap::iterator itor = m_DirPackMap.begin(); itor != m_DirPackMap.end(); ++itor) - { - const std::string & c_rstrName = itor->first; - CEterPack * pEterPack = itor->second; - - if (CompareName(c_rstrName.c_str(), c_rstrName.length(), strFileName.c_str())) - { - return pEterPack; - } - } - } - - return NULL; -} - -void CEterPackManager::SetCacheMode() -{ - m_isCacheMode=true; -} - -void CEterPackManager::SetRelativePathMode() -{ - m_bTryRelativePath = true; -} - - // StringPath std::string 버전 -int CEterPackManager::ConvertFileName(const char * c_szFileName, std::string & rstrFileName) +std::string CEterPackManager::ConvertFileName(std::string fileName) { - rstrFileName = c_szFileName; - stl_lowers(rstrFileName); + std::string convertedFileName = fileName; + stl_lowers(convertedFileName); - int iCount = 0; - - for (DWORD i = 0; i < rstrFileName.length(); ++i) + for (DWORD i = 0; i < convertedFileName.length(); i++) { - if (rstrFileName[i] == '/') - ++iCount; - else if (rstrFileName[i] == '\\') - { - rstrFileName[i] = '/'; - ++iCount; - } + if (convertedFileName[i] == '\\') + convertedFileName[i] = '/'; } - return iCount; + return convertedFileName; } bool CEterPackManager::CompareName(const char * c_szDirectoryName, DWORD /*dwLength*/, const char * c_szFileName) @@ -87,54 +48,6 @@ 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::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::value_type(dwFileNameHash, kNewCache)); -} - -CEterPackManager::SCache* CEterPackManager::__FindCache(DWORD dwFileNameHash) -{ - std::unordered_map::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::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) @@ -150,27 +63,37 @@ struct TimeChecker DWORD baseTime; }; -bool CEterPackManager::Get(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData) +bool CEterPackManager::Get(const std::string& fileName, TPackDataPtr& dataPtr) { //TimeChecker timeChecker(c_szFileName); //Logf(1, "Load %s\n", c_szFileName); if (m_iSearchMode == SEARCH_FILE_FIRST) { - if (GetFromFile(rMappedFile, c_szFileName, pData)) - { + if (GetFromFile(fileName, dataPtr)) return true; - } - return GetFromPack(rMappedFile, c_szFileName, pData); + return GetFromPack(fileName, dataPtr); } - if (GetFromPack(rMappedFile, c_szFileName, pData)) - { + if (GetFromPack(fileName, dataPtr)) return true; - } - return GetFromFile(rMappedFile, c_szFileName, pData); + 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(dataStream)); + + return true; } struct FinderLock @@ -188,109 +111,60 @@ struct FinderLock CRITICAL_SECTION* p_cs; }; -bool CEterPackManager::GetFromPack(CMappedFile & rMappedFile, const char * c_szFileName, LPCVOID * pData) +bool CEterPackManager::GetFromPack(const std::string& fileName, TPackDataPtr& dataPtr) { FinderLock lock(m_csFinder); - static std::string strFileName; - - if (0 == ConvertFileName(c_szFileName, strFileName)) - { - return m_RootPack.Get(rMappedFile, strFileName.c_str(), pData); - } - else - { - DWORD dwFileNameHash = GetCRC32(strFileName.c_str(), strFileName.length()); - SCache* pkCache = __FindCache(dwFileNameHash); + std::string strFileName = ConvertFileName(fileName); - if (pkCache) - { - rMappedFile.Link(pkCache->m_dwBufSize, pkCache->m_abBufData); - return true; - } + auto pkFileItem = m_FileMap.find(strFileName); - 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; - } - } + if (pkFileItem == m_FileMap.end()) { #ifdef _DEBUG - TraceError("CANNOT_FIND_PACK_FILE [%s]", strFileName.c_str()); + TraceError("CANNOT_FIND_PACK_FILE [%s]", strFileName.c_str()); #endif - return false; + return false; + } + + auto data = std::make_shared>(); + if (!pkFileItem->second->getFile(strFileName, data)) + return false; + + // Set dataPtr to the retreived data pointer + dataPtr = data; + + return true; } -const time_t g_tCachingInterval = 10; // 10초 -void CEterPackManager::ArrangeMemoryMappedPack() +bool CEterPackManager::GetFromFile(const std::string& fileName, TPackDataPtr& dataPtr) { - //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(); - // } - // } - //} -} + // Try to open the file + std::ifstream file(fileName, std::ios::binary); + if (!file.is_open()) + return false; -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; + // Read the file's contents + dataPtr = std::make_shared>( + std::istreambuf_iterator(file), + std::istreambuf_iterator() + ); + return true; } bool CEterPackManager::isExistInPack(const char * c_szFileName) { - std::string strFileName; + std::string strFileName = ConvertFileName(c_szFileName); - 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()); + auto pkFileItem = m_FileMap.find(strFileName); - if (pkFileItem) - if (pkFileItem->pkPack) - return pkFileItem->pkPack->IsExist(strFileName.c_str()); - } + if (pkFileItem == m_FileMap.end()) + return false; - // NOTE : 매치 되는 팩이 없다면 false - [levites] - return false; + if (!pkFileItem->second) + return false; + + return pkFileItem->second->fileExists(strFileName.c_str()); } bool CEterPackManager::isExist(const char * c_szFileName) @@ -300,99 +174,66 @@ bool CEterPackManager::isExist(const char * c_szFileName) if (isExistInPack(c_szFileName)) return true; - return _access(c_szFileName, 0) == 0 ? true : false; + return _access(c_szFileName, 0) == 0; } - //if(m_bTryRelativePath) { - // if (strnicmp(c_szFileName, PATH_ABSOLUTE_YMIRWORK1, strlen(PATH_ABSOLUTE_YMIRWORK1)) == 0 || strnicmp(c_szFileName, PATH_ABSOLUTE_YMIRWORK2, strlen(PATH_ABSOLUTE_YMIRWORK2)) == 0) { - // if(access(c_szFileName+strlen(PATH_ABSOLUTE_YMIRWORK1), 0) == 0) - // return true; - // } - //} - if (_access(c_szFileName, 0) == 0) return true; return isExistInPack(c_szFileName); } - -void CEterPackManager::RegisterRootPack(const char * c_szName) +bool CEterPackManager::PackExists(const std::string& name, const std::string& container) { - if (!m_RootPack.Create(m_FileDict, c_szName, "")) - { - TraceError("%s: Pack file does not exist", c_szName); + if (container == "FOLDER") { + return _access(name.c_str(), 0) == 0; } -} - -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++; + else if (container == "ZIP") { + std::string zipName = name + ".zip"; + return _access(zipName.c_str(), 0) == 0; } - return true; + + throw std::runtime_error("Unexpected container type: " + container + "!"); } -bool CEterPackManager::RegisterPackWhenPackMaking(const char * c_szName, const char * c_szDirectory, CEterPack* pPack) +bool CEterPackManager::RegisterPack(const std::string& name, const std::string& container) { - m_PackMap.insert(TEterPackMap::value_type(c_szName, pPack)); - m_PackList.push_front(pPack); + auto it = m_PackMap.find(name); - m_DirPackMap.insert(TEterPackMap::value_type(c_szDirectory, pPack)); - return true; -} + if (it != m_PackMap.end()) + return true; + try { + bool bReadOnly = true; -bool CEterPackManager::RegisterPack(const char * c_szName, const char * c_szDirectory, const BYTE* c_pbIV) -{ - CEterPack * pEterPack = NULL; - { - TEterPackMap::iterator itor = m_PackMap.find(c_szName); + std::shared_ptr pack; - 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; - } - } + // Determine requested container type + if (container == "FOLDER") + pack = std::make_shared(name); + else if (container == "ZIP") + pack = std::make_shared(name + ".zip"); else - { - pEterPack = itor->second; - } + throw std::runtime_error("Unexpected container type: " + container + "!"); + + // Load container data + auto packFiles = pack->listFiles(); + + for (auto const& fileName : packFiles) + m_FileMap.insert({ fileName, pack }); + + m_PackMap.insert({ name, pack }); + + return true; } - - if (c_szDirectory && c_szDirectory[0] != '*') + catch (std::exception& e) { - 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)); - } - } +#ifdef _DEBUG + Tracef("Unable to load file provider '%s': %s\n", name.c_str(), e.what()); +#endif - return true; + return false; + } } void CEterPackManager::SetSearchMode(bool bPackFirst) @@ -405,209 +246,16 @@ int CEterPackManager::GetSearchMode() return m_iSearchMode; } -CEterPackManager::CEterPackManager() : m_bTryRelativePath(false), m_iSearchMode(SEARCH_FILE_FIRST), m_isCacheMode(false) +CEterPackManager::CEterPackManager() : m_iSearchMode(SEARCH_FILE_FIRST) { InitializeCriticalSection(&m_csFinder); } CEterPackManager::~CEterPackManager() { - __ClearCacheMap(); - - TEterPackMap::iterator i = m_PackMap.begin(); - TEterPackMap::iterator e = m_PackMap.end(); - while (i != e) - { - delete i->second; - i++; - } DeleteCriticalSection(&m_csFinder); } -void CEterPackManager::RetrieveHybridCryptPackKeys(const BYTE *pStream) -{ - ////dump file format - //total packagecnt (4byte) - // for packagecntpackage - // db name hash ( stl.h stringhash ) - // extension cnt( 4byte) - // for extension cnt - // ext hash ( stl.h stringhash ) - // key-16byte - // iv-16byte - int iMemOffset = 0; - - int iPackageCnt; - DWORD dwPackageNameHash; - - memcpy( &iPackageCnt, pStream + iMemOffset, sizeof(int) ); - iMemOffset += sizeof(iPackageCnt); - - for( int i = 0; i < iPackageCnt; ++i ) - { - int iRecvedCryptKeySize = 0; - memcpy( &iRecvedCryptKeySize, pStream + iMemOffset, sizeof(iRecvedCryptKeySize) ); - iRecvedCryptKeySize -= sizeof(dwPackageNameHash); // 서버에서 받은 key stream에는 filename hash가 포함되어 있으므로, hash 사이즈 만큼 배줌. - iMemOffset += sizeof(iRecvedCryptKeySize); - - memcpy( &dwPackageNameHash, pStream + iMemOffset, sizeof(dwPackageNameHash) ); - iMemOffset += sizeof(dwPackageNameHash); - - TEterPackMap::const_iterator cit; - for( cit = m_PackMap.begin(); cit != m_PackMap.end(); ++cit ) - { - 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 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(); +const CEterPackManager::TFileMap& CEterPackManager::GetFileMap() { + return this->m_FileMap; } diff --git a/src/EterPack/EterPackManager.h b/src/EterPack/EterPackManager.h index e73eb6e9..286b2daa 100644 --- a/src/EterPack/EterPackManager.h +++ b/src/EterPack/EterPackManager.h @@ -5,16 +5,10 @@ #include "../eterBase/Singleton.h" #include "../eterBase/Stl.h" -#include "EterPack.h" +#include "FileProvider.h" class CEterPackManager : public CSingleton { - public: - struct SCache - { - BYTE* m_abBufData; - DWORD m_dwBufSize; - }; public: enum ESearchModes { @@ -22,69 +16,40 @@ class CEterPackManager : public CSingleton SEARCH_PACK_FIRST }; - typedef std::list TEterPackList; - typedef std::unordered_map TEterPackMap; + typedef std::list> TEterPackList; + typedef std::unordered_map> TEterPackMap; + typedef std::unordered_map> TFileMap; + typedef std::shared_ptr> TPackDataPtr; public: CEterPackManager(); virtual ~CEterPackManager(); - - void SetCacheMode(); - void SetRelativePathMode(); - - void LoadStaticCache(const char* c_szFileName); void SetSearchMode(bool bPackFirst); int GetSearchMode(); - 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 Get(const std::string& fileName, TPackDataPtr& dataPtr); + bool Get(const std::string& fileName, std::stringstream& dataStream); + bool isExist(const char * c_szFileName); bool isExistInPack(const char * c_szFileName); - bool RegisterPack(const char * c_szName, const char * c_szDirectory, const BYTE* c_pbIV = NULL); - void RegisterRootPack(const char * c_szName); - bool RegisterPackWhenPackMaking(const char * c_szName, const char * c_szDirectory, CEterPack* pPack); + bool PackExists(const std::string& name, const std::string& container); + bool RegisterPack(const std::string& name, const std::string& container); + std::string ConvertFileName(std::string fileName); - - 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(); + const TFileMap& GetFileMap(); protected: - int ConvertFileName(const char * c_szFileName, std::string & rstrFileName); // StringPath std::string 버전 bool CompareName(const char * c_szDirectoryName, DWORD iLength, const char * c_szFileName); - - CEterPack* FindPack(const char* c_szPathName); - - SCache* __FindCache(DWORD dwFileNameHash); - void __ClearCacheMap(); + bool GetFromPack(const std::string& fileName, TPackDataPtr& dataPtr); + bool GetFromFile(const std::string& fileName, TPackDataPtr& dataPtr); protected: - bool m_bTryRelativePath; - bool m_isCacheMode; int m_iSearchMode; - CEterFileDict m_FileDict; - CEterPack m_RootPack; - TEterPackList m_PackList; + TFileMap m_FileMap; TEterPackMap m_PackMap; - TEterPackMap m_DirPackMap; - - std::unordered_map m_kMap_dwNameKey_kCache; CRITICAL_SECTION m_csFinder; }; diff --git a/src/EterPack/FileProvider.h b/src/EterPack/FileProvider.h new file mode 100644 index 00000000..bfb159b8 --- /dev/null +++ b/src/EterPack/FileProvider.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include +#include +#include + +class FileProvider +{ +public: + virtual std::vector listFiles() = 0; + virtual bool fileExists(const std::string& fileName) = 0; + virtual bool getFile(const std::string& fileName, std::shared_ptr>& fileData) = 0; +}; diff --git a/src/EterPack/Folder.cpp b/src/EterPack/Folder.cpp new file mode 100644 index 00000000..906f8a14 --- /dev/null +++ b/src/EterPack/Folder.cpp @@ -0,0 +1,98 @@ +#include "Folder.h" +#include "EterPackManager.h" + +#include +#include +#include +#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 Folder::listFiles() +{ + std::vector 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>& 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::istreambuf_iterator(file), + std::istreambuf_iterator() + ); + return true; +} \ No newline at end of file diff --git a/src/EterPack/Folder.h b/src/EterPack/Folder.h new file mode 100644 index 00000000..60655dd2 --- /dev/null +++ b/src/EterPack/Folder.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +#include "FileProvider.h" + +class Folder : public FileProvider +{ +protected: + std::string folderPath; + std::set fileList = {}; + +public: + Folder(const std::string& folderPath); + std::vector listFiles(); + bool fileExists(const std::string& fileName); + bool getFile(const std::string& fileName, std::shared_ptr>& fileData); + +private: + void ListFiles(const std::string& directory, const std::string& relativePath); +}; + diff --git a/src/EterPack/StdAfx.cpp b/src/EterPack/StdAfx.cpp deleted file mode 100644 index 804d0881..00000000 --- a/src/EterPack/StdAfx.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "stdafx.h" - diff --git a/src/EterPack/ZIP.cpp b/src/EterPack/ZIP.cpp new file mode 100644 index 00000000..df060897 --- /dev/null +++ b/src/EterPack/ZIP.cpp @@ -0,0 +1,97 @@ +#include "ZIP.h" +#include "EterPackManager.h" + +#include +#include +#include +#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 ZIP::listFiles() +{ + std::vector 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>& 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>(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; +} \ No newline at end of file diff --git a/src/EterPack/ZIP.h b/src/EterPack/ZIP.h new file mode 100644 index 00000000..ffd58cdf --- /dev/null +++ b/src/EterPack/ZIP.h @@ -0,0 +1,20 @@ +#include +#include +#include + +#include "FileProvider.h" + +class ZIP : public FileProvider +{ +protected: + zip_t* zipFile = nullptr; + std::map fileList; + +public: + ZIP(const std::string& archivePath); + ~ZIP(); + + std::vector listFiles(); + bool fileExists(const std::string& fileName); + bool getFile(const std::string& fileName, std::shared_ptr>& fileData); +}; diff --git a/src/EterPack/md5.c b/src/EterPack/md5.c deleted file mode 100644 index 2fe2f4e9..00000000 --- a/src/EterPack/md5.c +++ /dev/null @@ -1,1033 +0,0 @@ -/* - - *********************************************************************** - - ** 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. ** - - *********************************************************************** - - */ - - -#include "md5.h" - - - -/* - - *********************************************************************** - - ** Message-digest routines: ** - - ** To form the message digest for a message M ** - - ** (1) Initialize a context buffer mdContext using MD5Init ** - - ** (2) Call MD5Update on mdContext and M ** - - ** (3) Call MD5Final on mdContext ** - - ** The message digest is now in mdContext->digest[0...15] ** - - *********************************************************************** - - */ - - - -static unsigned char PADDING[64] = { - - 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - -}; - - - -#ifndef CPU386 /* Alternate defs exist for 386 assembler version */ - -/* F, G, H and I are basic MD5 functions */ - -#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) - -#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) - -#define H(x, y, z) ((x) ^ (y) ^ (z)) - -#define I(x, y, z) ((y) ^ ((x) | (~z))) - - - -/* ROTATE_LEFT rotates x left n bits */ - -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - - - -/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */ - -/* Rotation is separate from addition to prevent recomputation */ - -#define FF(a, b, c, d, x, s, ac) \ - (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - -#define GG(a, b, c, d, x, s, ac) \ - (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - -#define HH(a, b, c, d, x, s, ac) \ - (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - -#define II(a, b, c, d, x, s, ac) \ - (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - -#endif /* CPU386 */ - - - -/* The routine MD5Init initializes the message-digest context - - mdContext. All fields are set to zero. - - */ - -void MD5Init (MD5_CTX *mdContext) -{ - - mdContext->i[0] = mdContext->i[1] = (UINT4)0; - - - - /* Load magic initialization constants. - - */ - - mdContext->buf[0] = (UINT4)0x67452301; - - mdContext->buf[1] = (UINT4)0xefcdab89; - - mdContext->buf[2] = (UINT4)0x98badcfe; - - mdContext->buf[3] = (UINT4)0x10325476; - -} - - - -/* The routine MD5Update updates the message-digest context to - - account for the presence of each of the characters inBuf[0..inLen-1] - - in the message whose digest is being computed. - - */ - -void MD5Update (MD5_CTX *mdContext, unsigned char *inBuf, unsigned int inLen) -{ - - UINT4 in[16]; - - int mdi; - - unsigned int i, ii; - - - - /* compute number of bytes mod 64 */ - - mdi = (int)((mdContext->i[0] >> 3) & 0x3F); - - - - /* update number of bits */ - - if ((mdContext->i[0] + ((UINT4)inLen << 3)) < mdContext->i[0]) - - mdContext->i[1]++; - - mdContext->i[0] += ((UINT4)inLen << 3); - - mdContext->i[1] += ((UINT4)inLen >> 29); - - - -#ifdef LITTLE_ENDIAN - - /* Speedup for little-endian machines suggested in MD5 report --P Karn */ - - if(mdi == 0 && ((int)inBuf & 3) == 0){ - - while(inLen >= 64){ - - MD5Transform(mdContext->buf,(UINT4 *)inBuf); - - inLen -= 64; - - inBuf += 64; - - } - - } - -#endif /* LITTLE_ENDIAN */ - - while (inLen--) { - - /* add new character to buffer, increment mdi */ - - mdContext->in[mdi++] = *inBuf++; - - - - /* transform if necessary */ - - if (mdi == 0x40) { - - for (i = 0, ii = 0; i < 16; i++, ii += 4) - - in[i] = (((UINT4)mdContext->in[ii+3]) << 24) | - - (((UINT4)mdContext->in[ii+2]) << 16) | - - (((UINT4)mdContext->in[ii+1]) << 8) | - - ((UINT4)mdContext->in[ii]); - - MD5Transform (mdContext->buf, in); - - mdi = 0; - - } - - } - -} - - - -/* The routine MD5Final terminates the message-digest computation and - - ends with the desired message digest in mdContext->digest[0...15]. - - */ - -void MD5Final (MD5_CTX *mdContext) -{ - - UINT4 in[16]; - - int mdi; - - unsigned int i, ii; - - unsigned int padLen; - - - - /* save number of bits */ - - in[14] = mdContext->i[0]; - - in[15] = mdContext->i[1]; - - - - /* compute number of bytes mod 64 */ - - mdi = (int)((mdContext->i[0] >> 3) & 0x3F); - - - - /* pad out to 56 mod 64 */ - - padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi); - - MD5Update (mdContext, PADDING, padLen); - - - - /* append length in bits and transform */ - - for (i = 0, ii = 0; i < 14; i++, ii += 4) - - in[i] = (((UINT4)mdContext->in[ii+3]) << 24) | - - (((UINT4)mdContext->in[ii+2]) << 16) | - - (((UINT4)mdContext->in[ii+1]) << 8) | - - ((UINT4)mdContext->in[ii]); - - MD5Transform (mdContext->buf, in); - - - - /* store buffer in digest */ - - for (i = 0, ii = 0; i < 4; i++, ii += 4) { - - mdContext->digest[ii] = (unsigned char)(mdContext->buf[i] & 0xFF); - - mdContext->digest[ii+1] = - - (unsigned char)((mdContext->buf[i] >> 8) & 0xFF); - - mdContext->digest[ii+2] = - - (unsigned char)((mdContext->buf[i] >> 16) & 0xFF); - - mdContext->digest[ii+3] = - - (unsigned char)((mdContext->buf[i] >> 24) & 0xFF); - - } - -} - - - -#ifndef CPU386 /* Fast assembler version exists for 386/486 */ - - - -/* Basic MD5 step. Transforms buf based on in. - - */ - -void MD5Transform (buf, in) - -UINT4 *buf; - -UINT4 *in; - -{ - - UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3]; - - - - /* Round 1 */ - -#define S11 7 - -#define S12 12 - -#define S13 17 - -#define S14 22 - - FF ( a, b, c, d, in[ 0], S11, 3614090360); /* 1 */ - - FF ( d, a, b, c, in[ 1], S12, 3905402710); /* 2 */ - - FF ( c, d, a, b, in[ 2], S13, 606105819); /* 3 */ - - FF ( b, c, d, a, in[ 3], S14, 3250441966); /* 4 */ - - FF ( a, b, c, d, in[ 4], S11, 4118548399); /* 5 */ - - FF ( d, a, b, c, in[ 5], S12, 1200080426); /* 6 */ - - FF ( c, d, a, b, in[ 6], S13, 2821735955); /* 7 */ - - FF ( b, c, d, a, in[ 7], S14, 4249261313); /* 8 */ - - FF ( a, b, c, d, in[ 8], S11, 1770035416); /* 9 */ - - FF ( d, a, b, c, in[ 9], S12, 2336552879); /* 10 */ - - FF ( c, d, a, b, in[10], S13, 4294925233); /* 11 */ - - FF ( b, c, d, a, in[11], S14, 2304563134); /* 12 */ - - FF ( a, b, c, d, in[12], S11, 1804603682); /* 13 */ - - FF ( d, a, b, c, in[13], S12, 4254626195); /* 14 */ - - FF ( c, d, a, b, in[14], S13, 2792965006); /* 15 */ - - FF ( b, c, d, a, in[15], S14, 1236535329); /* 16 */ - - - - /* Round 2 */ - -#define S21 5 - -#define S22 9 - -#define S23 14 - -#define S24 20 - - GG ( a, b, c, d, in[ 1], S21, 4129170786); /* 17 */ - - GG ( d, a, b, c, in[ 6], S22, 3225465664); /* 18 */ - - GG ( c, d, a, b, in[11], S23, 643717713); /* 19 */ - - GG ( b, c, d, a, in[ 0], S24, 3921069994); /* 20 */ - - GG ( a, b, c, d, in[ 5], S21, 3593408605); /* 21 */ - - GG ( d, a, b, c, in[10], S22, 38016083); /* 22 */ - - GG ( c, d, a, b, in[15], S23, 3634488961); /* 23 */ - - GG ( b, c, d, a, in[ 4], S24, 3889429448); /* 24 */ - - GG ( a, b, c, d, in[ 9], S21, 568446438); /* 25 */ - - GG ( d, a, b, c, in[14], S22, 3275163606); /* 26 */ - - GG ( c, d, a, b, in[ 3], S23, 4107603335); /* 27 */ - - GG ( b, c, d, a, in[ 8], S24, 1163531501); /* 28 */ - - GG ( a, b, c, d, in[13], S21, 2850285829); /* 29 */ - - GG ( d, a, b, c, in[ 2], S22, 4243563512); /* 30 */ - - GG ( c, d, a, b, in[ 7], S23, 1735328473); /* 31 */ - - GG ( b, c, d, a, in[12], S24, 2368359562); /* 32 */ - - - - /* Round 3 */ - -#define S31 4 - -#define S32 11 - -#define S33 16 - -#define S34 23 - - HH ( a, b, c, d, in[ 5], S31, 4294588738); /* 33 */ - - HH ( d, a, b, c, in[ 8], S32, 2272392833); /* 34 */ - - HH ( c, d, a, b, in[11], S33, 1839030562); /* 35 */ - - HH ( b, c, d, a, in[14], S34, 4259657740); /* 36 */ - - HH ( a, b, c, d, in[ 1], S31, 2763975236); /* 37 */ - - HH ( d, a, b, c, in[ 4], S32, 1272893353); /* 38 */ - - HH ( c, d, a, b, in[ 7], S33, 4139469664); /* 39 */ - - HH ( b, c, d, a, in[10], S34, 3200236656); /* 40 */ - - HH ( a, b, c, d, in[13], S31, 681279174); /* 41 */ - - HH ( d, a, b, c, in[ 0], S32, 3936430074); /* 42 */ - - HH ( c, d, a, b, in[ 3], S33, 3572445317); /* 43 */ - - HH ( b, c, d, a, in[ 6], S34, 76029189); /* 44 */ - - HH ( a, b, c, d, in[ 9], S31, 3654602809); /* 45 */ - - HH ( d, a, b, c, in[12], S32, 3873151461); /* 46 */ - - HH ( c, d, a, b, in[15], S33, 530742520); /* 47 */ - - HH ( b, c, d, a, in[ 2], S34, 3299628645); /* 48 */ - - - - /* Round 4 */ - -#define S41 6 - -#define S42 10 - -#define S43 15 - -#define S44 21 - - II ( a, b, c, d, in[ 0], S41, 4096336452); /* 49 */ - - II ( d, a, b, c, in[ 7], S42, 1126891415); /* 50 */ - - II ( c, d, a, b, in[14], S43, 2878612391); /* 51 */ - - II ( b, c, d, a, in[ 5], S44, 4237533241); /* 52 */ - - II ( a, b, c, d, in[12], S41, 1700485571); /* 53 */ - - II ( d, a, b, c, in[ 3], S42, 2399980690); /* 54 */ - - II ( c, d, a, b, in[10], S43, 4293915773); /* 55 */ - - II ( b, c, d, a, in[ 1], S44, 2240044497); /* 56 */ - - II ( a, b, c, d, in[ 8], S41, 1873313359); /* 57 */ - - II ( d, a, b, c, in[15], S42, 4264355552); /* 58 */ - - II ( c, d, a, b, in[ 6], S43, 2734768916); /* 59 */ - - II ( b, c, d, a, in[13], S44, 1309151649); /* 60 */ - - II ( a, b, c, d, in[ 4], S41, 4149444226); /* 61 */ - - II ( d, a, b, c, in[11], S42, 3174756917); /* 62 */ - - II ( c, d, a, b, in[ 2], S43, 718787259); /* 63 */ - - II ( b, c, d, a, in[ 9], S44, 3951481745); /* 64 */ - - - - buf[0] += a; - - buf[1] += b; - - buf[2] += c; - - buf[3] += d; - -} - -#else /* CPU386 */ - -/* Fast 386 Borland C inline assembler version of the MD5Transform() function - - * from the RSA Data Security, Inc, MD5 Message Digest Algorithm. - - * - - * This version uses native 32 bit registers, so it needs a 386 or 486 CPU. - - * - - * Because this function does *lots* of 32-bit operations, this version is - - * MUCH faster than the reference C version compiled with a garden- - - * variety 16-bit MS-DOS C compiler. - - * - - * Written and placed into the public domain on - - * 22 February 1992 by Phil Karn, KA9Q - - */ - -/* I really shouldn't have to do this explicitly... */ - -#ifdef __COMPACT__ - - asm .MODEL COMPACT - -#elif __HUGE__ - - asm .MODEL HUGE - -#elif __LARGE__ - - asm .MODEL LARGE - -#elif __MEDIUM__ - - asm .MODEL MEDIUM - -#elif __SMALL__ - - asm .MODEL SMALL - -#elif __TINY__ - - asm .MODEL TINY - -#endif - - - -/* Code sequence common to all four rounds. - - * evaluates a = b + (a + edi + x + t) <<< s - - * Assumes a,b are registers, s,t are immediate constants - - * The 'lea' instruction is just a fast way to compute "a = a+t+edi" - - */ - -#define COM(a,b,x,s,t)\ - - asm lea a,t[a+edi];\ - - asm add a,x;\ - - asm rol a,s;\ - - asm add a,b; - - - -/* Round 1 functions */ - -/* edi = F(x,y,z) = (x & y) | (~x & z) */ - -#define F(x,y,z)\ - - asm mov edi,x;\ - - asm and edi,y;\ - - asm mov esi,x;\ - - asm not esi;\ - - asm and esi,z;\ - - asm or edi,esi - - - -/* a = b + ((a + F(x,y,z) + x + t) <<< s); */ - -#define FF(a,b,c,d,x,s,t)\ - - F(b,c,d);\ - - COM(a,b,x,s,t) - - - -/* Round 2 functions */ - -/* edi = G(x,y,z) = F(z,x,y) = (x & z) | (y & ~z) */ - -#define G(x,y,z) F(z,x,y) - - - -/* a = b + ((a + G(b,c,d) + x + t) <<< s) */ - -#define GG(a,b,c,d,x,s,t)\ - - G(b,c,d);\ - - COM(a,b,x,s,t) - - - -/* Round 3 functions */ - -/* edi = H(x,y,z) = x ^ y ^ z */ - -#define H(x,y,z)\ - - asm mov edi,x;\ - - asm xor edi,y;\ - - asm xor edi,z - - - -/* a = b + ((a + H(b,c,d) + x + t) <<< s) */ - -#define HH(a,b,c,d,x,s,t)\ - - H(b,c,d);\ - - COM(a,b,x,s,t) - - - -/* Round 4 functions */ - -/* edi = I(x,y,z) = y ^ (x | ~z) */ - -#define I(x,y,z)\ - - asm mov edi,z;\ - - asm not edi;\ - - asm or edi,x;\ - - asm xor edi,y - - - -/* a = b + ((a + I(b,c,d) + x + t) <<< s) */ - -#define II(a,b,c,d,x,s,t)\ - - I(b,c,d);\ - - COM(a,b,x,s,t) - - - -#define A eax - -#define B ebx - -#define C ecx - -#define D edx - - - -void - -MD5Transform(buf,input) - -UINT4 *buf; - -UINT4 *input; - -{ - - asm .386; /* Allow use of 32-bit general registers */ - - - - /* Save caller's registers */ - - asm push si; - - asm push di; - - asm push es; - - asm if @DataSize NE 0 - - asm push ds; - - asm endif - - - - /* Get buf argument */ - - asm if @DataSize NE 0 - - asm lds si,buf; - - asm else - - asm mov si,buf; - - asm endif - - asm mov A,dword ptr si[0*4]; /* A = buf[0] */ - - asm mov B,dword ptr si[1*4]; /* B = buf[1] */ - - asm mov C,dword ptr si[2*4]; /* C = buf[2] */ - - asm mov D,dword ptr si[3*4]; /* D = buf[3] */ - - - - /* Warning: This makes our other args inaccessible until bp - - * is restored! - - */ - - asm push bp; - - asm les bp,input - - - -/* Round 1. The *4 factors in the subscripts to bp account for the - - * byte offsets of each long element in the input array. - - */ - -#define S11 7 - -#define S12 12 - -#define S13 17 - -#define S14 22 - - FF(A,B,C,D,es:bp[ 0*4],S11,3614090360); /* 1 */ - - FF(D,A,B,C,es:bp[ 1*4],S12,3905402710); /* 2 */ - - FF(C,D,A,B,es:bp[ 2*4],S13, 606105819); /* 3 */ - - FF(B,C,D,A,es:bp[ 3*4],S14,3250441966); /* 4 */ - - FF(A,B,C,D,es:bp[ 4*4],S11,4118548399); /* 5 */ - - FF(D,A,B,C,es:bp[ 5*4],S12,1200080426); /* 6 */ - - FF(C,D,A,B,es:bp[ 6*4],S13,2821735955); /* 7 */ - - FF(B,C,D,A,es:bp[ 7*4],S14,4249261313); /* 8 */ - - FF(A,B,C,D,es:bp[ 8*4],S11,1770035416); /* 9 */ - - FF(D,A,B,C,es:bp[ 9*4],S12,2336552879); /* 10 */ - - FF(C,D,A,B,es:bp[10*4],S13,4294925233); /* 11 */ - - FF(B,C,D,A,es:bp[11*4],S14,2304563134); /* 12 */ - - FF(A,B,C,D,es:bp[12*4],S11,1804603682); /* 13 */ - - FF(D,A,B,C,es:bp[13*4],S12,4254626195); /* 14 */ - - FF(C,D,A,B,es:bp[14*4],S13,2792965006); /* 15 */ - - FF(B,C,D,A,es:bp[15*4],S14,1236535329); /* 16 */ - - - -/* Round 2 */ - -#define S21 5 - -#define S22 9 - -#define S23 14 - -#define S24 20 - - GG(A,B,C,D,es:bp[ 1*4],S21,4129170786); /* 17 */ - - GG(D,A,B,C,es:bp[ 6*4],S22,3225465664); /* 18 */ - - GG(C,D,A,B,es:bp[11*4],S23, 643717713); /* 19 */ - - GG(B,C,D,A,es:bp[ 0*4],S24,3921069994); /* 20 */ - - GG(A,B,C,D,es:bp[ 5*4],S21,3593408605); /* 21 */ - - GG(D,A,B,C,es:bp[10*4],S22, 38016083); /* 22 */ - - GG(C,D,A,B,es:bp[15*4],S23,3634488961); /* 23 */ - - GG(B,C,D,A,es:bp[ 4*4],S24,3889429448); /* 24 */ - - GG(A,B,C,D,es:bp[ 9*4],S21, 568446438); /* 25 */ - - GG(D,A,B,C,es:bp[14*4],S22,3275163606); /* 26 */ - - GG(C,D,A,B,es:bp[ 3*4],S23,4107603335); /* 27 */ - - GG(B,C,D,A,es:bp[ 8*4],S24,1163531501); /* 28 */ - - GG(A,B,C,D,es:bp[13*4],S21,2850285829); /* 29 */ - - GG(D,A,B,C,es:bp[ 2*4],S22,4243563512); /* 30 */ - - GG(C,D,A,B,es:bp[ 7*4],S23,1735328473); /* 31 */ - - GG(B,C,D,A,es:bp[12*4],S24,2368359562); /* 32 */ - - - -/* Round 3 */ - -#define S31 4 - -#define S32 11 - -#define S33 16 - -#define S34 23 - - HH(A,B,C,D,es:bp[ 5*4],S31,4294588738); /* 33 */ - - HH(D,A,B,C,es:bp[ 8*4],S32,2272392833); /* 34 */ - - HH(C,D,A,B,es:bp[11*4],S33,1839030562); /* 35 */ - - HH(B,C,D,A,es:bp[14*4],S34,4259657740); /* 36 */ - - HH(A,B,C,D,es:bp[ 1*4],S31,2763975236); /* 37 */ - - HH(D,A,B,C,es:bp[ 4*4],S32,1272893353); /* 38 */ - - HH(C,D,A,B,es:bp[ 7*4],S33,4139469664); /* 39 */ - - HH(B,C,D,A,es:bp[10*4],S34,3200236656); /* 40 */ - - HH(A,B,C,D,es:bp[13*4],S31, 681279174); /* 41 */ - - HH(D,A,B,C,es:bp[ 0*4],S32,3936430074); /* 42 */ - - HH(C,D,A,B,es:bp[ 3*4],S33,3572445317); /* 43 */ - - HH(B,C,D,A,es:bp[ 6*4],S34, 76029189); /* 44 */ - - HH(A,B,C,D,es:bp[ 9*4],S31,3654602809); /* 45 */ - - HH(D,A,B,C,es:bp[12*4],S32,3873151461); /* 46 */ - - HH(C,D,A,B,es:bp[15*4],S33, 530742520); /* 47 */ - - HH(B,C,D,A,es:bp[ 2*4],S34,3299628645); /* 48 */ - - - -/* Round 4 */ - -#define S41 6 - -#define S42 10 - -#define S43 15 - -#define S44 21 - - II(A,B,C,D,es:bp[ 0*4],S41,4096336452); /* 49 */ - - II(D,A,B,C,es:bp[ 7*4],S42,1126891415); /* 50 */ - - II(C,D,A,B,es:bp[14*4],S43,2878612391); /* 51 */ - - II(B,C,D,A,es:bp[ 5*4],S44,4237533241); /* 52 */ - - II(A,B,C,D,es:bp[12*4],S41,1700485571); /* 53 */ - - II(D,A,B,C,es:bp[ 3*4],S42,2399980690); /* 54 */ - - II(C,D,A,B,es:bp[10*4],S43,4293915773); /* 55 */ - - II(B,C,D,A,es:bp[ 1*4],S44,2240044497); /* 56 */ - - II(A,B,C,D,es:bp[ 8*4],S41,1873313359); /* 57 */ - - II(D,A,B,C,es:bp[15*4],S42,4264355552); /* 58 */ - - II(C,D,A,B,es:bp[ 6*4],S43,2734768916); /* 59 */ - - II(B,C,D,A,es:bp[13*4],S44,1309151649); /* 60 */ - - II(A,B,C,D,es:bp[ 4*4],S41,4149444226); /* 61 */ - - II(D,A,B,C,es:bp[11*4],S42,3174756917); /* 62 */ - - II(C,D,A,B,es:bp[ 2*4],S43, 718787259); /* 63 */ - - II(B,C,D,A,es:bp[ 9*4],S44,3951481745); /* 64 */ - - - - asm pop bp; /* We can address our args again */ - - asm if @DataSize NE 0 - - asm lds si,buf - - asm else - - asm mov si,buf; - - asm endif - - asm add dword ptr si[0*4],A; /* buf[0] += A */ - - asm add dword ptr si[1*4],B; /* buf[1] += B */ - - asm add dword ptr si[2*4],C; /* buf[2] += C */ - - asm add dword ptr si[3*4],D; /* buf[3] += D */ - - - - /* Restore caller's registers */ - - asm if @DataSize NE 0 - - asm pop ds - - asm endif - - - - asm pop es; - - asm pop di; - - asm pop si; - -} - -#endif /* CPU386 */ - - - -/* - - *********************************************************************** - - ** End of md5.c ** - - ******************************** (cut) ******************************** - - */ \ No newline at end of file diff --git a/src/EterPack/md5.h b/src/EterPack/md5.h deleted file mode 100644 index 9ed936f9..00000000 --- a/src/EterPack/md5.h +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef __INC_ETERPACKLIB_MD5_H__ -#define __INC_ETERPACKLIB_MD5_H__ - -/* - - *********************************************************************** - - ** md5.h -- header file for implementation of MD5 ** - - ** RSA Data Security, Inc. MD5 Message-Digest Algorithm ** - - ** Created: 2/17/90 RLR ** - - ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version ** - - ** Revised (for MD5): RLR 4/27/91 ** - - ** -- G modified to have y&~z instead of y&z ** - - ** -- FF, GG, HH modified to add in last register done ** - - ** -- Access pattern: round 2 works mod 5, round 3 works mod 3 ** - - ** -- distinct additive constant for each step ** - - ** -- round 4 added, working mod 7 ** - - *********************************************************************** - - */ - -/* - - *********************************************************************** - - ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. ** - - ** ** - - ** License to copy and use this software is granted provided that ** - - ** it is identified as the "RSA Data Security, Inc. MD5 Message- ** - - ** Digest Algorithm" in all material mentioning or referencing this ** - - ** software or this function. ** - - ** ** - - ** License is also granted to make and use derivative works ** - - ** provided that such works are identified as "derived from the RSA ** - - ** Data Security, Inc. MD5 Message-Digest Algorithm" in all ** - - ** material mentioning or referencing the derived work. ** - - ** ** - - ** RSA Data Security, Inc. makes no representations concerning ** - - ** either the merchantability of this software or the suitability ** - - ** of this software for any particular purpose. It is provided "as ** - - ** is" without express or implied warranty of any kind. ** - - ** ** - - ** These notices must be retained in any copies of any part of this ** - - ** documentation and/or software. ** - - *********************************************************************** - - */ - - - -/* typedef a 32-bit type */ - -typedef unsigned long int UINT4; - - - -/* Data structure for MD5 (Message-Digest) computation */ - -typedef struct { - - UINT4 i[2]; /* number of _bits_ handled mod 2^64 */ - - UINT4 buf[4]; /* scratch buffer */ - - unsigned char in[64]; /* input buffer */ - - unsigned char digest[16]; /* actual digest after MD5Final call */ - -} MD5_CTX; - - -#if defined (__cplusplus) -extern "C" { -#endif - -void MD5Init (MD5_CTX *); - -void MD5Update (MD5_CTX *,unsigned char *,unsigned int); - -void MD5Final (MD5_CTX *); - -void MD5Transform(UINT4 *,UINT4 *); - -#if defined (__cplusplus) -}; -#endif - -/* - - *********************************************************************** - - ** End of md5.h ** - - ******************************** (cut) ******************************** - - */ - - -#endif \ No newline at end of file diff --git a/src/GameLib/AreaTerrain.cpp b/src/GameLib/AreaTerrain.cpp index ec71a228..05e686bd 100644 --- a/src/GameLib/AreaTerrain.cpp +++ b/src/GameLib/AreaTerrain.cpp @@ -106,10 +106,8 @@ bool CTerrain::LoadShadowMap(const char * c_pszFileName) DWORD dwStart = ELTimer_GetMSec(); Tracef("LoadShadowMap %s ", c_pszFileName); - CMappedFile file; - LPCVOID c_pvData; - - if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData)) + CEterPackManager::TPackDataPtr data; + if (!CEterPackManager::Instance().Get(c_pszFileName, data)) { TraceError(" CTerrain::LoadShadowMap - %s OPEN ERROR", c_pszFileName); return false; @@ -117,13 +115,13 @@ bool CTerrain::LoadShadowMap(const char * c_pszFileName) DWORD dwShadowMapSize = sizeof(WORD) * 256 * 256; - if (file.Size() != dwShadowMapSize) + if (data->size() != dwShadowMapSize) { TraceError(" CTerrain::LoadShadowMap - %s SIZE ERROR", c_pszFileName); return false; } - memcpy(m_awShadowMap, c_pvData, dwShadowMapSize); + memcpy_s(m_awShadowMap, dwShadowMapSize, data->data(), data->size()); Tracef("%d ms\n", ELTimer_GetMSec() - dwStart); return true; diff --git a/src/GameLib/ItemManager.cpp b/src/GameLib/ItemManager.cpp index 8e96b0e5..c50067d5 100644 --- a/src/GameLib/ItemManager.cpp +++ b/src/GameLib/ItemManager.cpp @@ -95,14 +95,12 @@ CItemData * CItemManager::MakeItemData(DWORD dwIndex) bool CItemManager::LoadItemList(const char * c_szFileName) { - CMappedFile File; - LPCVOID pData; - - if (!CEterPackManager::Instance().Get(File, c_szFileName, &pData)) + CEterPackManager::TPackDataPtr data; + CMemoryTextFileLoader textFileLoader; + if (!CEterPackManager::Instance().Get(c_szFileName, data)) return false; - CMemoryTextFileLoader textFileLoader; - textFileLoader.Bind(File.Size(), pData); + textFileLoader.Bind(data->size(), data->data()); CTokenVector TokenVector; for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i) @@ -196,16 +194,15 @@ const std::string& __SnapString(const std::string& c_rstSrc, std::string& rstTem bool CItemManager::LoadItemDesc(const char* c_szFileName) { - const VOID* pvData; - CMappedFile kFile; - if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData)) + CEterPackManager::TPackDataPtr data; + CMemoryTextFileLoader kTextFileLoader; + if (!CEterPackManager::Instance().Get(c_szFileName, data)) { Tracenf("CItemManager::LoadItemDesc(c_szFileName=%s) - Load Error", c_szFileName); return false; } - CMemoryTextFileLoader kTextFileLoader; - kTextFileLoader.Bind(kFile.Size(), pvData); + kTextFileLoader.Bind(data->size(), data->data()); std::string stTemp; @@ -254,22 +251,27 @@ DWORD GetHashCode( const char* pString ) bool CItemManager::LoadItemTable(const char* c_szFileName) { - CMappedFile file; - LPCVOID pvData; - - if (!CEterPackManager::Instance().Get(file, c_szFileName, &pvData)) + std::stringstream data; + if (!CEterPackManager::Instance().Get(c_szFileName, data)) return false; DWORD dwFourCC, dwElements, dwDataSize; DWORD dwVersion=0; DWORD dwStride=0; - file.Read(&dwFourCC, sizeof(DWORD)); + data.read((char*)&dwFourCC, sizeof(DWORD)); + if (!data) + return false; if (dwFourCC == MAKEFOURCC('M', 'I', 'P', 'X')) { - file.Read(&dwVersion, sizeof(DWORD)); - file.Read(&dwStride, sizeof(DWORD)); + data.read((char*)&dwVersion, sizeof(DWORD)); + if (!data) + return false; + + data.read((char*)&dwStride, sizeof(DWORD)); + if (!data) + return false; if (dwVersion != 1) { @@ -289,19 +291,25 @@ bool CItemManager::LoadItemTable(const char* c_szFileName) return false; } - file.Read(&dwElements, sizeof(DWORD)); - file.Read(&dwDataSize, sizeof(DWORD)); + data.read((char*)&dwElements, sizeof(DWORD)); + if (!data) + return false; - BYTE * pbData = new BYTE[dwDataSize]; - file.Read(pbData, dwDataSize); + data.read((char*)&dwDataSize, sizeof(DWORD)); + if (!data) + return false; + + auto pbData = std::make_shared>(dwDataSize); + data.read((char*)pbData->data(), pbData->size()); + if (!data) + return false; ///// CLZObject zObj; - if (!CLZO::Instance().Decompress(zObj, pbData, s_adwItemProtoKey)) + if (!CLZO::Instance().Decompress(zObj, pbData->data(), s_adwItemProtoKey)) { - delete [] pbData; return false; } @@ -382,7 +390,6 @@ bool CItemManager::LoadItemTable(const char* c_szFileName) // pItemData->SetItemTableData(table); // } - delete [] pbData; return true; } diff --git a/src/GameLib/MapManager.cpp b/src/GameLib/MapManager.cpp index cae13853..41cd29ff 100644 --- a/src/GameLib/MapManager.cpp +++ b/src/GameLib/MapManager.cpp @@ -597,14 +597,14 @@ void CMapManager::GetBaseXY(DWORD * pdwBaseX, DWORD * pdwBaseY) void CMapManager::__LoadMapInfoVector() { - CMappedFile kFile; - LPCVOID pData; - if (!CEterPackManager::Instance().Get(kFile, m_stAtlasInfoFileName.c_str(), &pData)) - if (!CEterPackManager::Instance().Get(kFile, "AtlasInfo.txt", &pData)) + CEterPackManager::TPackDataPtr data; + CMemoryTextFileLoader textFileLoader; + + if (!CEterPackManager::Instance().Get(m_stAtlasInfoFileName, data)) + if (!CEterPackManager::Instance().Get("AtlasInfo.txt", data)) return; - CMemoryTextFileLoader textFileLoader; - textFileLoader.Bind(kFile.Size(), pData); + textFileLoader.Bind(data->size(), data->data()); char szMapName[256]; int x, y; diff --git a/src/GameLib/MapOutdoorLoad.cpp b/src/GameLib/MapOutdoorLoad.cpp index 800cf425..cfccfe1a 100644 --- a/src/GameLib/MapOutdoorLoad.cpp +++ b/src/GameLib/MapOutdoorLoad.cpp @@ -452,19 +452,18 @@ bool CMapOutdoor::LoadMonsterAreaInfo() char c_szFileName[256]; sprintf(c_szFileName, "%s\\regen.txt", GetMapDataDirectory().c_str()); - LPCVOID pModelData; - CMappedFile File; + CEterPackManager::TPackDataPtr modelData; + CMemoryTextFileLoader textFileLoader; - if (!CEterPackManager::Instance().Get(File, c_szFileName, &pModelData)) + if (!CEterPackManager::Instance().Get(c_szFileName, modelData)) { //TraceError(" CMapOutdoorAccessor::LoadMonsterAreaInfo Load File %s ERROR", c_szFileName); return false; } - - CMemoryTextFileLoader textFileLoader; + CTokenVector stTokenVector; - textFileLoader.Bind(File.Size(), pModelData); + textFileLoader.Bind(modelData->size(), modelData->data()); for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i) { diff --git a/src/GameLib/Property.cpp b/src/GameLib/Property.cpp index ef408820..4e92b9d6 100644 --- a/src/GameLib/Property.cpp +++ b/src/GameLib/Property.cpp @@ -136,54 +136,6 @@ void GetTimeString(char * str, time_t ct) tm.tm_sec); } -bool CProperty::Save(const char * c_pszFileName) -{ - CTempFile file; - - DWORD fourcc = MAKEFOURCC('Y', 'P', 'R', 'T'); - file.Write(&fourcc, sizeof(DWORD)); - file.Write("\r\n", 2); - - if (0 == m_stCRC.length()) - { - char szCRC[MAX_PATH + 16 + 1]; - - GetTimeString(szCRC, time(0)); - strcpy(szCRC + strlen(szCRC), c_pszFileName); - - m_dwCRC = CPropertyManager::Instance().GetUniqueCRC(szCRC); - _snprintf(szCRC, sizeof(szCRC), "%u", m_dwCRC); - - m_stCRC.assign(szCRC); - } - - file.Write(m_stCRC.c_str(), m_stCRC.length()); - file.Write("\r\n", 2); - - CTokenVectorMap::iterator itor = m_stTokenMap.begin(); - char buf[4096 + 1]; - - while (itor != m_stTokenMap.end()) - { - CTokenVector & tokenVector = itor->second; - - int len = _snprintf(buf, sizeof(buf), "%s\t", itor->first.c_str()); - file.Write(buf, len); - - for (DWORD i = 0; i < tokenVector.size(); ++i) - { - len = _snprintf(buf, sizeof(buf), "\t\"%s\"", tokenVector[i].c_str()); - file.Write(buf, len); - } - - file.Write("\r\n", 2); - ++itor; - } - - file.Close(); - return CPropertyManager::Instance().Put(c_pszFileName, file.GetFileName()); -} - bool CProperty::ReadFromMemory(const void * c_pvData, int iLen, const char * c_pszFileName) { const char * pcData = (const char *) c_pvData; diff --git a/src/GameLib/Property.h b/src/GameLib/Property.h index bf20d38f..5268f663 100644 --- a/src/GameLib/Property.h +++ b/src/GameLib/Property.h @@ -19,8 +19,6 @@ class CProperty void PutVector(const char * c_pszKey, const CTokenVector & c_rTokenVector); void PutString(const char * c_pszKey, const char * c_pszString); - bool Save(const char * c_pszFileName); - DWORD GetSize(); DWORD GetCRC(); diff --git a/src/GameLib/PropertyManager.cpp b/src/GameLib/PropertyManager.cpp index 27cd6a3a..e239613f 100644 --- a/src/GameLib/PropertyManager.cpp +++ b/src/GameLib/PropertyManager.cpp @@ -4,7 +4,7 @@ #include "PropertyManager.h" #include "Property.h" -CPropertyManager::CPropertyManager() : m_isFileMode(true) +CPropertyManager::CPropertyManager() { } @@ -13,90 +13,34 @@ CPropertyManager::~CPropertyManager() Clear(); } -bool CPropertyManager::Initialize(const char * c_pszPackFileName) +void CPropertyManager::Initialize() { - if (c_pszPackFileName) + auto fileMap = CEterPackManager::Instance().GetFileMap(); + + for (auto& itor : fileMap) { - if (!m_pack.Create(m_fileDict, c_pszPackFileName, "", true)) + if (itor.first.rfind("property/reserve", 0) == 0) { - LogBoxf("Cannot open property pack file (filename %s)", c_pszPackFileName); - return false; - } - - m_isFileMode = false; - - TDataPositionMap & indexMap = m_pack.GetIndexMap(); - - TDataPositionMap::iterator itor = indexMap.begin(); - - typedef std::map 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) + LoadReservedCRC(itor.first.c_str()); continue; + } - char szSourceFileName[256 + 1]; - _snprintf(szSourceFileName, sizeof(szSourceFileName), "property\\%s", fdata.cFileName); - - m_pack.Put(fdata.cFileName, szSourceFileName,COMPRESSED_TYPE_NONE,""); + if (itor.first.rfind("property/", 0) == 0) { + if (!Register(itor.first.c_str())) + continue; + } } - while (FindNextFile(hFind, &fdata)); - - FindClose(hFind); - return true; } bool CPropertyManager::LoadReservedCRC(const char * c_pszFileName) { - CMappedFile file; - LPCVOID c_pvData; + CEterPackManager::TPackDataPtr data; + CMemoryTextFileLoader textFileLoader; - if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData)) + if (!CEterPackManager::Instance().Get(c_pszFileName, data)) return false; - CMemoryTextFileLoader textFileLoader; - textFileLoader.Bind(file.Size(), c_pvData); + textFileLoader.Bind(data->size(), data->data()); for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i) { @@ -136,15 +80,13 @@ DWORD CPropertyManager::GetUniqueCRC(const char * c_szSeed) bool CPropertyManager::Register(const char * c_pszFileName, CProperty ** ppProperty) { - CMappedFile file; - LPCVOID c_pvData; - - if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData)) + CEterPackManager::TPackDataPtr data; + if (!CEterPackManager::Instance().Get(c_pszFileName, data)) return false; CProperty * pProperty = new CProperty(c_pszFileName); - if (!pProperty->ReadFromMemory(c_pvData, file.Size(), c_pszFileName)) + if (!pProperty->ReadFromMemory(data->data(), data->size(), c_pszFileName)) { delete pProperty; return false; @@ -188,67 +130,6 @@ bool CPropertyManager::Get(DWORD dwCRC, CProperty ** ppProperty) return true; } -bool CPropertyManager::Put(const char * c_pszFileName, const char * c_pszSourceFileName) -{ - if (!CopyFile(c_pszSourceFileName, c_pszFileName, FALSE)) - return false; - - if (!m_isFileMode) // 팩 파일에도 넣음 - { - if (!m_pack.Put(c_pszFileName, NULL, COMPRESSED_TYPE_NONE,"")) - { - assert(!"CPropertyManager::Put cannot write to pack file"); - return false; - } - } - - Register(c_pszFileName); - return true; -} - -bool CPropertyManager::Erase(DWORD dwCRC) -{ - TPropertyCRCMap::iterator itor = m_PropertyByCRCMap.find(dwCRC); - - if (m_PropertyByCRCMap.end() == itor) - return false; - - CProperty * pProperty = itor->second; - m_PropertyByCRCMap.erase(itor); - - DeleteFile(pProperty->GetFileName()); - ReserveCRC(pProperty->GetCRC()); - - if (!m_isFileMode) // 파일 모드가 아니면 팩에서도 지움 - m_pack.Delete(pProperty->GetFileName()); - - FILE * fp = fopen("property/reserve", "a+"); - - if (!fp) - LogBox("Unable to Open Scheduled CRC Files."); - 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); diff --git a/src/GameLib/PropertyManager.h b/src/GameLib/PropertyManager.h index 0ad11c15..b7234bcd 100644 --- a/src/GameLib/PropertyManager.h +++ b/src/GameLib/PropertyManager.h @@ -1,7 +1,5 @@ #pragma once -#include "../eterPack/EterPack.h" - class CPropertyManager : public CSingleton { public: @@ -10,34 +8,20 @@ class CPropertyManager : public CSingleton void Clear(); - void SetPack(CEterPack * pPack); - bool BuildPack(); - bool LoadReservedCRC(const char * c_pszFileName); void ReserveCRC(DWORD dwCRC); DWORD GetUniqueCRC(const char * c_szSeed); - bool Initialize(const char * c_pszPackFileName = NULL); + void Initialize(); 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 TPropertyCRCMap; typedef std::set TCRCSet; - bool m_isFileMode; TPropertyCRCMap m_PropertyByCRCMap; TCRCSet m_ReservedCRCSet; - CEterPack m_pack; - CEterFileDict m_fileDict; }; diff --git a/src/GameLib/RaceManager.cpp b/src/GameLib/RaceManager.cpp index 58601698..19614fbb 100644 --- a/src/GameLib/RaceManager.cpp +++ b/src/GameLib/RaceManager.cpp @@ -237,14 +237,13 @@ bool CRaceManager::__LoadRaceMotionList(CRaceData& rkRaceData, const char* pathN s_kMap_stType_dwIndex.insert(std::map::value_type("SKILL5", CRaceMotionData::NAME_SKILL+125)); } - const void* pvData; - CMappedFile kMappedFile; - if (!CEterPackManager::Instance().Get(kMappedFile, motionListFileName, &pvData)) - return false; - - + CEterPackManager::TPackDataPtr data; CMemoryTextFileLoader kTextFileLoader; - kTextFileLoader.Bind(kMappedFile.Size(), pvData); + + if (!CEterPackManager::Instance().Get(motionListFileName, data)) + return false; + + kTextFileLoader.Bind(data->size(), data->data()); rkRaceData.RegisterMotionMode(CRaceMotionData::MODE_GENERAL); diff --git a/src/MilesLib/SoundData.cpp b/src/MilesLib/SoundData.cpp index e1a52e12..2105a28f 100644 --- a/src/MilesLib/SoundData.cpp +++ b/src/MilesLib/SoundData.cpp @@ -5,7 +5,7 @@ #include "../eterBase/Timer.h" bool CSoundData::ms_isSoundFile[SOUND_FILE_MAX_NUM]; -CMappedFile CSoundData::ms_SoundFile[SOUND_FILE_MAX_NUM]; +std::stringstream CSoundData::ms_SoundFile[SOUND_FILE_MAX_NUM]; const char * CSoundData::GetFileName() { @@ -139,9 +139,7 @@ U32 AILCALLBACK CSoundData::open_callback(char const * filename, U32 *file_handl if (-1 == iIndex) return 0; - LPCVOID pMap; - - if (!CEterPackManager::Instance().Get(ms_SoundFile[iIndex], filename, &pMap)) + if (!CEterPackManager::Instance().Get(filename, ms_SoundFile[iIndex])) return 0; ms_isSoundFile[iIndex] = true; @@ -155,7 +153,7 @@ void AILCALLBACK CSoundData::close_callback(U32 file_handle) if (!isSlotIndex(file_handle)) return; - ms_SoundFile[file_handle].Destroy(); + ms_SoundFile[file_handle].str(""); ms_isSoundFile[file_handle] = false; } @@ -164,7 +162,8 @@ S32 AILCALLBACK CSoundData::seek_callback(U32 file_handle, S32 offset, U32 type) if (!isSlotIndex(file_handle)) return 0; - return ms_SoundFile[file_handle].Seek(offset, type); + ms_SoundFile[file_handle].seekg(offset, type); + return ms_SoundFile[file_handle].tellg(); } U32 AILCALLBACK CSoundData::read_callback(U32 file_handle, void * buffer, U32 bytes) @@ -172,9 +171,8 @@ U32 AILCALLBACK CSoundData::read_callback(U32 file_handle, void * buffer, U32 by if (!isSlotIndex(file_handle)) return 0; - DWORD dwRealSize = min(ms_SoundFile[file_handle].Size(), bytes); - ms_SoundFile[file_handle].Read(buffer, dwRealSize); - return dwRealSize; + ms_SoundFile[file_handle].read((char*) buffer, bytes); + return ms_SoundFile[file_handle].gcount(); } void CSoundData::SetPackMode() diff --git a/src/MilesLib/SoundData.h b/src/MilesLib/SoundData.h index 13ddb1c5..9c22c13c 100644 --- a/src/MilesLib/SoundData.h +++ b/src/MilesLib/SoundData.h @@ -1,6 +1,7 @@ #ifndef __MILESLIB_CSOUNDDATA_H__ #define __MILESLIB_CSOUNDDATA_H__ +#include #include #include "../eterBase/MappedFile.h" @@ -53,7 +54,7 @@ class CSoundData static int GetEmptySlotIndex(); static bool ms_isSoundFile[SOUND_FILE_MAX_NUM]; - static CMappedFile ms_SoundFile[SOUND_FILE_MAX_NUM]; + static std::stringstream ms_SoundFile[SOUND_FILE_MAX_NUM]; }; #endif \ No newline at end of file diff --git a/src/PRTerrainLib/Terrain.cpp b/src/PRTerrainLib/Terrain.cpp index c4812b88..213dcac5 100644 --- a/src/PRTerrainLib/Terrain.cpp +++ b/src/PRTerrainLib/Terrain.cpp @@ -76,18 +76,23 @@ bool CTerrainImpl::LoadHeightMap(const char*c_szFileName) { Tracef("LoadRawHeightMapFile %s ", c_szFileName); - CMappedFile kMappedFile; - LPCVOID lpcvFileData; - - if (!CEterPackManager::Instance().Get(kMappedFile, c_szFileName, &lpcvFileData)) + std::stringstream data; + if (!CEterPackManager::Instance().Get(c_szFileName, data)) { Tracen("Error"); TraceError("CTerrainImpl::LoadHeightMap - %s OPEN ERROR", c_szFileName); return false; } - memcpy(m_awRawHeightMap, lpcvFileData, sizeof(WORD)*HEIGHTMAP_RAW_XSIZE*HEIGHTMAP_RAW_YSIZE); - + 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 return true; } @@ -96,18 +101,13 @@ bool CTerrainImpl::LoadAttrMap(const char *c_szFileName) DWORD dwStart = ELTimer_GetMSec(); Tracef("LoadAttrMapFile %s ", c_szFileName); - CMappedFile kMappedFile; - LPCVOID lpcvFileData; - - if (!CEterPackManager::Instance().Get(kMappedFile, c_szFileName, &lpcvFileData)) + std::stringstream data; + if (!CEterPackManager::Instance().Get(c_szFileName, data)) { TraceError("CTerrainImpl::LoadAttrMap - %s OPEN ERROR", c_szFileName); return false; } - DWORD dwFileSize = kMappedFile.Size(); - BYTE * abFileData = (BYTE *) lpcvFileData; - // LoadAttrMap { #pragma pack(push) @@ -119,16 +119,15 @@ bool CTerrainImpl::LoadAttrMap(const char *c_szFileName) WORD m_wHeight; }; #pragma pack(pop) - - if (dwFileSize < sizeof(SAttrMapHeader)) + + SAttrMapHeader kAttrMapHeader; + data.read((char*) &kAttrMapHeader, sizeof(kAttrMapHeader)); + if (!data) { 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) { @@ -148,40 +147,40 @@ bool CTerrainImpl::LoadAttrMap(const char *c_szFileName) return false; } - DWORD dwFileRestSize=dwFileSize-sizeof(kAttrMapHeader); - DWORD dwFileNeedSize=sizeof(m_abyAttrMap); - if (dwFileRestSize != dwFileNeedSize) + data.read((char*)m_abyAttrMap, sizeof(m_abyAttrMap)); + if (!data) { - TraceError("CTerrainImpl::LoadAttrMap - %s FILE DATA SIZE(rest %d != need %d) ERROR", c_szFileName, dwFileRestSize, dwFileNeedSize); + TraceError("CTerrainImpl::LoadAttrMap - %s FILE DATA SIZE ERROR", c_szFileName); 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); - - CMappedFile kMappedFile; - LPCVOID lpcvFileData; - - if (!CEterPackManager::Instance().Get(kMappedFile, c_szFileName, &lpcvFileData)) + + std::stringstream data; + if (!CEterPackManager::Instance().Get(c_szFileName, data)) { Tracen("Error"); TraceError("CTerrainImpl::RAW_LoadTileMap - %s OPEN ERROR", c_szFileName); return false; } - - memcpy(m_abyTileMap, lpcvFileData, sizeof(BYTE)*(TILEMAP_RAW_XSIZE)*(TILEMAP_RAW_YSIZE)); - - return true; + 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 + return true; } bool CTerrainImpl::LoadWaterMap(const char * c_szFileName) @@ -206,18 +205,16 @@ bool CTerrainImpl::LoadWaterMap(const char * c_szFileName) bool CTerrainImpl::LoadWaterMapFile(const char * c_szFileName) { - CMappedFile kMappedFile; - LPCVOID lpcvFileData; - - if (!CEterPackManager::Instance().Get(kMappedFile, c_szFileName, &lpcvFileData)) + std::stringstream data; + size_t fileSize = 0; + if (!CEterPackManager::Instance().Get(c_szFileName, data)) { Tracen("Error"); TraceError("CTerrainImpl::LoadWaterMap - %s OPEN ERROR", c_szFileName); return false; - } + } - DWORD dwFileSize = kMappedFile.Size(); - BYTE* abFileData = (BYTE*)lpcvFileData; + fileSize = data.str().length(); { #pragma pack(push) @@ -231,15 +228,14 @@ bool CTerrainImpl::LoadWaterMapFile(const char * c_szFileName) }; #pragma pack(pop) - if (dwFileSize < sizeof(SWaterMapHeader)) + SWaterMapHeader kWaterMapHeader; + data.read((char*)&kWaterMapHeader, sizeof(kWaterMapHeader)); + if (!data) { 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) @@ -262,22 +258,23 @@ bool CTerrainImpl::LoadWaterMapFile(const char * c_szFileName) m_byNumWater = kWaterMapHeader.m_byLayerCount; - DWORD dwFileRestSize = dwFileSize - sizeof(kWaterMapHeader); + DWORD dwFileRestSize = fileSize - 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]; - BYTE * abSrcWaterData = abFileData + sizeof(kWaterMapHeader); - memcpy(m_abyWaterMap, abSrcWaterData, sizeof(m_abyWaterMap)); - - BYTE * abSrcWaterHeight = abSrcWaterData + sizeof(m_abyWaterMap); + data.read((char*)m_abyWaterMap, sizeof(m_abyWaterMap)); + if (!data) + return false; m_byNumWater = MIN(MAX_WATER_NUM, m_byNumWater); if (m_byNumWater) { - memcpy(wWaterHeight, abSrcWaterHeight, sizeof(WORD) * m_byNumWater); + data.read((char*)wWaterHeight, sizeof(WORD) * m_byNumWater); + if (!data) + return false; for (int i = 0; i < m_byNumWater; ++i) m_lWaterHeight[i] = wWaterHeight[i]; @@ -289,13 +286,15 @@ bool CTerrainImpl::LoadWaterMapFile(const char * c_szFileName) return false; } - BYTE * abSrcWaterData = abFileData + sizeof(kWaterMapHeader); - memcpy(m_abyWaterMap, abSrcWaterData, sizeof(m_abyWaterMap)); + data.read((char*)m_abyWaterMap, sizeof(m_abyWaterMap)); + if (!data) + return false; - BYTE * abSrcWaterHeight = abSrcWaterData + sizeof(m_abyWaterMap); - - if (m_byNumWater) - memcpy(m_lWaterHeight, abSrcWaterHeight, sizeof(long) * m_byNumWater); + if (m_byNumWater) { + data.read((char*)m_lWaterHeight, sizeof(long)* m_byNumWater); + if (!data) + return false; + } } return true; diff --git a/src/ScriptLib/PythonLauncher.cpp b/src/ScriptLib/PythonLauncher.cpp index 9012474c..4ee247f1 100644 --- a/src/ScriptLib/PythonLauncher.cpp +++ b/src/ScriptLib/PythonLauncher.cpp @@ -196,21 +196,19 @@ bool CPythonLauncher::RunCompiledFile(const char* c_szFileName) } -bool CPythonLauncher::RunMemoryTextFile(const char* c_szFileName, UINT uFileSize, const VOID* c_pvFileData) +bool CPythonLauncher::RunMemoryTextFile(const char* c_szFileName, std::shared_ptr> fileData) { NANOBEGIN - const CHAR* c_pcFileData=(const CHAR*)c_pvFileData; - std::string stConvFileData; - stConvFileData.reserve(uFileSize); + stConvFileData.reserve(fileData->size()); stConvFileData+="exec(compile('''"; // ConvertPythonTextFormat { - for (UINT i=0; isize(); ++i) { - if (c_pcFileData[i]!=13) - stConvFileData+=c_pcFileData[i]; + if ((*fileData)[i] != 13) + stConvFileData+= (*fileData)[i]; } } @@ -227,29 +225,14 @@ bool CPythonLauncher::RunMemoryTextFile(const char* c_szFileName, UINT uFileSize bool CPythonLauncher::RunFile(const char* c_szFileName) { - char* acBufData=NULL; - DWORD dwBufSize=0; - - { - CMappedFile file; - const VOID* pvData; - CEterPackManager::Instance().Get(file, c_szFileName, &pvData); + CEterPackManager::TPackDataPtr data; + if (!CEterPackManager::Instance().Get(c_szFileName, data)) + return false; - dwBufSize=file.Size(); - if (dwBufSize==0) - return false; + if (data->size() == 0) + return false; - acBufData=new char[dwBufSize]; - memcpy(acBufData, pvData, dwBufSize); - } - - bool ret=false; - - ret=RunMemoryTextFile(c_szFileName, dwBufSize, acBufData); - - delete [] acBufData; - - return ret; + return RunMemoryTextFile(c_szFileName, data); } bool CPythonLauncher::RunLine(const char* c_szSrc) diff --git a/src/ScriptLib/PythonLauncher.h b/src/ScriptLib/PythonLauncher.h index 1495813b..37c5e6cd 100644 --- a/src/ScriptLib/PythonLauncher.h +++ b/src/ScriptLib/PythonLauncher.h @@ -15,7 +15,7 @@ class CPythonLauncher : public CSingleton 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, UINT uFileSize, const VOID* c_pvFileData); + bool RunMemoryTextFile(const char* c_szFileName, std::shared_ptr> fileData); bool RunCompiledFile(const char* c_szFileName); const char* GetError(); diff --git a/src/SpeedTreeLib/SpeedTreeForest.cpp b/src/SpeedTreeLib/SpeedTreeForest.cpp index ef84787e..1c2425d9 100644 --- a/src/SpeedTreeLib/SpeedTreeForest.cpp +++ b/src/SpeedTreeLib/SpeedTreeForest.cpp @@ -75,16 +75,15 @@ BOOL CSpeedTreeForest::GetMainTree(DWORD dwCRC, CSpeedTreeWrapper ** ppMainTree, pTree = itor->second; else { - CMappedFile file; - LPCVOID c_pvData; + CEterPackManager::TPackDataPtr data; // NOTE : 파일이 없을때는 return FALSE 아닌가요? - [levites] - if (!CEterPackManager::Instance().Get(file, c_pszFileName, &c_pvData)) + if (!CEterPackManager::Instance().Get(c_pszFileName, data)) return FALSE; pTree = new CSpeedTreeWrapper; - if (!pTree->LoadTree(c_pszFileName, (const BYTE *) c_pvData, file.Size())) + if (!pTree->LoadTree(c_pszFileName, (const BYTE *) data->data(), data->size())) { delete pTree; pTree = nullptr; @@ -92,8 +91,6 @@ BOOL CSpeedTreeForest::GetMainTree(DWORD dwCRC, CSpeedTreeWrapper ** ppMainTree, } m_pMainTreeMap.insert(std::map::value_type(dwCRC, pTree)); - - file.Destroy(); } *ppMainTree = pTree; diff --git a/src/UserInterface/AccountConnector.cpp b/src/UserInterface/AccountConnector.cpp index 4e06c0fd..272db8b3 100644 --- a/src/UserInterface/AccountConnector.cpp +++ b/src/UserInterface/AccountConnector.cpp @@ -141,13 +141,6 @@ 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; } @@ -185,16 +178,6 @@ 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; } @@ -345,50 +328,6 @@ 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; @@ -423,9 +362,6 @@ bool CAccountConnector::__AuthState_RecvAuthSuccess() } else { - DWORD dwPanamaKey = kAuthSuccessPacket.dwLoginKey ^ g_adwEncryptKey[0] ^ g_adwEncryptKey[1] ^ g_adwEncryptKey[2] ^ g_adwEncryptKey[3]; - CEterPackManager::instance().DecryptPackIV(dwPanamaKey); - CPythonNetworkStream & rkNet = CPythonNetworkStream::Instance(); rkNet.SetLoginKey(kAuthSuccessPacket.dwLoginKey); rkNet.Connect(m_strAddr.c_str(), m_iPort); @@ -451,9 +387,6 @@ bool CAccountConnector::__AuthState_RecvAuthSuccess_OpenID() } else { - DWORD dwPanamaKey = kAuthSuccessOpenIDPacket.dwLoginKey ^ g_adwEncryptKey[0] ^ g_adwEncryptKey[1] ^ g_adwEncryptKey[2] ^ g_adwEncryptKey[3]; - CEterPackManager::instance().DecryptPackIV(dwPanamaKey); - CPythonNetworkStream & rkNet = CPythonNetworkStream::Instance(); rkNet.SetLoginInfo(kAuthSuccessOpenIDPacket.login, "0000"); //OpenID 인증 과정에서 비밀번호는 사용되지 않는다. rkNet.SetLoginKey(kAuthSuccessOpenIDPacket.dwLoginKey); diff --git a/src/UserInterface/AccountConnector.h b/src/UserInterface/AccountConnector.h index 67134284..82a9e1a3 100644 --- a/src/UserInterface/AccountConnector.h +++ b/src/UserInterface/AccountConnector.h @@ -59,9 +59,6 @@ class CAccountConnector : public CNetworkStream, public CSingletonsize(), data->data()); } DWORD GetLineCount() diff --git a/src/UserInterface/PythonBackground.cpp b/src/UserInterface/PythonBackground.cpp index 300c4f5f..efd597f4 100644 --- a/src/UserInterface/PythonBackground.cpp +++ b/src/UserInterface/PythonBackground.cpp @@ -241,19 +241,7 @@ void CPythonBackground::Initialize() void CPythonBackground::__CreateProperty() { - if (CEterPackManager::SEARCH_FILE_FIRST == CEterPackManager::Instance().GetSearchMode() && - _access("property", 0) == 0) - { - m_PropertyManager.Initialize(NULL); - - CPropertyLoader PropertyLoader; - PropertyLoader.SetPropertyManager(&m_PropertyManager); - PropertyLoader.Create("*.*", "Property"); - } - else - { - m_PropertyManager.Initialize("pack/property"); - } + m_PropertyManager.Initialize(); } ////////////////////////////////////////////////////////////////////// diff --git a/src/UserInterface/PythonEventManager.cpp b/src/UserInterface/PythonEventManager.cpp index 7b4007fb..6fc440c1 100644 --- a/src/UserInterface/PythonEventManager.cpp +++ b/src/UserInterface/PythonEventManager.cpp @@ -106,16 +106,11 @@ void CPythonEventManager::__InitEventSet(TEventSet& rEventSet) int CPythonEventManager::RegisterEventSet(const char * c_szFileName) { - CMappedFile File; - LPCVOID pMap; - - if (!CEterPackManager::Instance().Get(File, c_szFileName, &pMap)) + std::stringstream data; + if (!CEterPackManager::Instance().Get(c_szFileName, data)) return -1; - std::string strEventString; - strEventString.resize(File.Size()+1); - - File.Read(&strEventString[0], File.Size()); + std::string strEventString = data.str(); TEventSet * pEventSet = m_EventSetPool.Alloc(); if (!pEventSet) diff --git a/src/UserInterface/PythonNetworkStream.cpp b/src/UserInterface/PythonNetworkStream.cpp index abc97ee0..b18ce062 100644 --- a/src/UserInterface/PythonNetworkStream.cpp +++ b/src/UserInterface/PythonNetworkStream.cpp @@ -176,8 +176,6 @@ class CMainPacketHeaderMap : public CNetworkPacketHeaderMap Set(HEADER_GC_HS_REQUEST, CNetworkPacketHeaderMap::TPacketType(sizeof(TPacketHSCheck), STATIC_SIZE_PACKET)); Set(HEADER_GC_XTRAP_CS1_REQUEST, CNetworkPacketHeaderMap::TPacketType(sizeof(TPacketXTrapCSVerify), STATIC_SIZE_PACKET)); - Set(HEADER_GC_HYBRIDCRYPT_KEYS, CNetworkPacketHeaderMap::TPacketType(sizeof(TPacketGCHybridCryptKeys), DYNAMIC_SIZE_PACKET)); - Set(HEADER_GC_HYBRIDCRYPT_SDB, CNetworkPacketHeaderMap::TPacketType(sizeof(TPacketGCHybridSDB), DYNAMIC_SIZE_PACKET)); Set(HEADER_GC_SPECIFIC_EFFECT, CNetworkPacketHeaderMap::TPacketType(sizeof(TPacketGCSpecificEffect), STATIC_SIZE_PACKET)); Set(HEADER_GC_DRAGON_SOUL_REFINE, CNetworkPacketHeaderMap::TPacketType(sizeof(TPacketGCDragonSoulRefine), STATIC_SIZE_PACKET)); diff --git a/src/UserInterface/PythonNetworkStream.h b/src/UserInterface/PythonNetworkStream.h index b855d771..a55965fe 100644 --- a/src/UserInterface/PythonNetworkStream.h +++ b/src/UserInterface/PythonNetworkStream.h @@ -264,9 +264,6 @@ class CPythonNetworkStream : public CNetworkStream, public CSingletonsize(), data->data()); m_kInsultChecker.Clear(); for (DWORD dwLineIndex=0; dwLineIndex=4) return false; - CMappedFile file; - const VOID* pvData; - if (!CEterPackManager::Instance().Get(file, c_szFileName, &pvData)) + std::stringstream data; + if (!CEterPackManager::Instance().Get(c_szFileName, data)) return false; DWORD dwEngCount=26; @@ -65,16 +63,17 @@ bool CPythonNetworkStream::LoadConvertTable(DWORD dwEmpireID, const char* c_szFi DWORD dwHanSize=dwHanCount*2; DWORD dwFileSize=dwEngCount*2+dwHanSize; - if (file.Size()>(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, s_adwMobProtoKey)) - { - delete [] pbData; + if (!CLZO::Instance().Decompress(zObj, pbData->data(), s_adwMobProtoKey)) return false; - } if ((zObj.GetSize() % sizeof(TMobTable)) != 0) { @@ -64,7 +70,6 @@ bool CPythonNonPlayer::LoadNonPlayerData(const char * c_szFileName) m_NonPlayerDataMap.insert(TNonPlayerDataMap::value_type(pNonPlayerData->dwVnum, pNonPlayerData)); } - delete [] pbData; return true; } diff --git a/src/UserInterface/PythonPackModule.cpp b/src/UserInterface/PythonPackModule.cpp index ad58d3da..21fe504c 100644 --- a/src/UserInterface/PythonPackModule.cpp +++ b/src/UserInterface/PythonPackModule.cpp @@ -63,11 +63,9 @@ PyObject * packGet(PyObject * poSelf, PyObject * poArgs) (stricmp(pcExt, ".pyc") == 0) || (stricmp(pcExt, ".txt") == 0)) { - CMappedFile file; - const void * pData = NULL; - - if (CEterPackManager::Instance().Get(file,strFileName,&pData)) - return Py_BuildValue("s#",pData, file.Size()); + CEterPackManager::TPackDataPtr data; + if (CEterPackManager::Instance().Get(strFileName, data)) + return Py_BuildValue("s#", data->data(), data->size()); } } diff --git a/src/UserInterface/PythonSkill.cpp b/src/UserInterface/PythonSkill.cpp index 94568773..f9b9e3a1 100644 --- a/src/UserInterface/PythonSkill.cpp +++ b/src/UserInterface/PythonSkill.cpp @@ -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) { - const VOID* pvData; - CMappedFile kFile; - if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData)) + CEterPackManager::TPackDataPtr data; + CMemoryTextFileLoader textFileLoader; + + if (!CEterPackManager::Instance().Get(c_szFileName, data)) return false; - CMemoryTextFileLoader textFileLoader; - textFileLoader.Bind(kFile.Size(), pvData); + textFileLoader.Bind(data->size(), data->data()); // 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) { - const VOID* pvData; - CMappedFile kFile; - if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData)) + CEterPackManager::TPackDataPtr data; + CMemoryTextFileLoader textFileLoader; + + if (!CEterPackManager::Instance().Get(c_szFileName, data)) return false; - CMemoryTextFileLoader textFileLoader; - textFileLoader.Bind(kFile.Size(), pvData); + textFileLoader.Bind(data->size(), data->data()); CTokenVector TokenVector; for (DWORD i = 0; i < textFileLoader.GetLineCount(); ++i) diff --git a/src/UserInterface/UserInterface.cpp b/src/UserInterface/UserInterface.cpp index 9eede980..7e46028e 100644 --- a/src/UserInterface/UserInterface.cpp +++ b/src/UserInterface/UserInterface.cpp @@ -203,18 +203,31 @@ const char* ApplicationStringTable_GetStringz(DWORD dwID) int Setup(LPSTR lpCmdLine); // Internal function forward -bool PackInitialize(const char * c_pszFolder) +bool PackInitialize(const std::string& packFolder) { NANOBEGIN - if (_access(c_pszFolder, 0) != 0) + if (_access(packFolder.c_str(), 0) != 0) return true; - std::string stFolder(c_pszFolder); - stFolder += "/"; + // Initialize variables + bool bPackFirst = true; + std::string stFolder = packFolder + "/"; + std::string stFileName; - std::string stFileName(stFolder); - stFileName += "Index"; +#ifdef _DISTRIBUTE + Tracef("Info: Pack search mode set to archive-first.\n"); + // Set Index file name to production value + stFileName = stFolder + "Index"; +#else + bPackFirst = false; + Tracef("Info: Pack search mode set to file-first.\n"); + + // Set Index file name to development value + stFileName = stFolder + "Index.dev"; +#endif + + // Set up file reader CMappedFile file; LPCVOID pvData; @@ -228,56 +241,43 @@ bool PackInitialize(const char * c_pszFolder) CMemoryTextFileLoader TextLoader; TextLoader.Bind(file.Size(), pvData); - bool bPackFirst = TRUE; - - const std::string& strPackType = TextLoader.GetLineString(0); - - if (strPackType.compare("FILE") && strPackType.compare("PACK")) - { - TraceError("Pack/Index has invalid syntax. First line must be 'PACK' or 'FILE'"); - return false; - } - -#ifdef _DISTRIBUTE - Tracef("You are in pack mode.\n"); - - //if (0 == strPackType.compare("FILE")) - //{ - // bPackFirst = FALSE; - // Tracef("You are in file mode.\n"); - //} - //else - //{ - // Tracef("You are in pack mode.\n"); - //} -#else - bPackFirst = FALSE; - Tracef("You are in file mode.\n"); -#endif - + // Set up archive manager CTextFileLoader::SetCacheMode(); -#if defined(USE_RELATIVE_PATH) - CEterPackManager::Instance().SetRelativePathMode(); -#endif - CEterPackManager::Instance().SetCacheMode(); CEterPackManager::Instance().SetSearchMode(bPackFirst); CSoundData::SetPackMode(); // Miles 파일 콜백을 셋팅 + // Read lines and parse tokens std::string strPackName, strTexCachePackName; - for (DWORD i = 1; i < TextLoader.GetLineCount() - 1; i += 2) + CTokenVector tokens = CTokenVector(); + + for (DWORD i = 0; i < TextLoader.GetLineCount() - 1; i++) { - const std::string & c_rstFolder = TextLoader.GetLineString(i); - const std::string & c_rstName = TextLoader.GetLineString(i + 1); + // Split line into tokens + TextLoader.SplitLineByTab(i, &tokens); + // Check if the read number of tokens is valid + if (tokens.size() != 2) + { + TraceError("Invalid number of tokens on line %d: expected %d, got %d!", i, 2, tokens.size()); + return false; + } + + // Assign tokens into variables + const std::string& c_rstName = tokens[0]; + const std::string& c_rstContainer = tokens[1]; + + // Load pack strPackName = stFolder + c_rstName; - strTexCachePackName = strPackName + "_texcache"; + CEterPackManager::Instance().RegisterPack(strPackName, c_rstContainer); - CEterPackManager::Instance().RegisterPack(strPackName.c_str(), c_rstFolder.c_str()); - CEterPackManager::Instance().RegisterPack(strTexCachePackName.c_str(), c_rstFolder.c_str()); + // Try to load texture cache pack if it exists + strTexCachePackName = strPackName + "_texcache"; + if (CEterPackManager::Instance().PackExists(strTexCachePackName, c_rstContainer)) { + CEterPackManager::Instance().RegisterPack(strTexCachePackName, c_rstContainer); + } } - CEterPackManager::Instance().RegisterRootPack((stFolder + std::string("root")).c_str()); NANOEND return true; } diff --git a/src/UserInterface/UserInterface.rc b/src/UserInterface/UserInterface.rc index 0c13c245..35e6eb3a 100644 --- a/src/UserInterface/UserInterface.rc +++ b/src/UserInterface/UserInterface.rc @@ -126,8 +126,8 @@ IDI_METIN2 ICON "metin2.ico" // VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,3,1,0 - PRODUCTVERSION 0,3,1,0 + FILEVERSION 0,4,0,0 + PRODUCTVERSION 0,4,0,0 FILEFLAGSMASK 0x17L #ifdef _DEBUG FILEFLAGS 0x1L @@ -144,12 +144,12 @@ BEGIN BEGIN VALUE "CompanyName", "The Old Metin2 Project" VALUE "FileDescription", "The Metin2 Client" - VALUE "FileVersion", "0.3.1.0" + VALUE "FileVersion", "0.4.0.0" VALUE "InternalName", "Metin2Client" - VALUE "LegalCopyright", "Copyright (C) 2024" + VALUE "LegalCopyright", "Copyright (C) 2022-2025" VALUE "OriginalFilename", "Metin2.exe" VALUE "ProductName", "Metin2Client" - VALUE "ProductVersion", "0.3.1.0" + VALUE "ProductVersion", "0.4.0.0" END END BLOCK "VarFileInfo" diff --git a/src/vcpkg.json b/src/vcpkg.json index 1a21caa7..c5e34c63 100644 --- a/src/vcpkg.json +++ b/src/vcpkg.json @@ -15,6 +15,13 @@ "name": "directxsdk", "version>=": "jun10" }, + { + "name": "libzip", + "features": [ + "zstd" + ], + "version>=": "1.10.1" + }, { "name": "lzo", "version>=": "2.10#7"