1
0
forked from metin2/client

Improved pack initialization algorithm, archive types are now configurable in the Index file.

This commit is contained in:
2025-04-12 07:00:29 +03:00
parent c21c99393d
commit 830e47b00b
6 changed files with 279 additions and 303 deletions

View File

@ -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,52 +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("<EFBFBD>˸<EFBFBD>: <20><> <20><><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>.\n");
//if (0 == strPackType.compare("FILE"))
//{
// bPackFirst = FALSE;
// Tracef("<22>˸<EFBFBD>: <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>.\n");
//}
//else
//{
// Tracef("<22>˸<EFBFBD>: <20><> <20><><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>.\n");
//}
#else
bPackFirst = FALSE;
Tracef("<EFBFBD>˸<EFBFBD>: <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Դϴ<D4B4>.\n");
#endif
// Set up archive manager
CTextFileLoader::SetCacheMode();
CEterPackManager::Instance().SetSearchMode(bPackFirst);
CSoundData::SetPackMode(); // Miles <20><><EFBFBD><EFBFBD> <20>ݹ<EFBFBD><DDB9><EFBFBD> <20><><EFBFBD><EFBFBD>
// 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().RegisterPack((stFolder + "root").c_str(), (stFolder + "root").c_str());
NANOEND
return true;
}