Jump to content

[How To] Index para o binário


Dynamic Things
 Share

Recommended Posts

Boas ppl, já tenho isto para mim a algum tempo mas como não vejo muitos a falarem disso por ai decidi publicar.
Passando agora ao tópico, neste tutorial tenho como objetivo de mostrar como podem passar a indexar os teus patchs

sem a necessidade de terem um ficheiro index no vosso cliente.

 

Muito bem uma vez explicado o que se pretende fazer vamos ver os prós e os contras que isto pode trazer:

 

Prós:

Obriga a qualquer pessoa que tente adicionar novo patch ao cliente a ter de o adicionar a source do binário para o fazer.

Permitira uma melhor reorganização da base do cliente.

 

Contras:

Quando queremos adicionar algum patch novo temos de o adicionar ao binário e voltar a compilar.

 

Como o fazer?

 

No ficheiro userinterface.cpp procurar pelo seguinte:

bool PackInitialize(const char * c_pszFolder)

E vão encontrar a seguinte função:

bool PackInitialize(const char * c_pszFolder)
{
	NANOBEGIN
		if (_access(c_pszFolder, 0) != 0)
			return true;

	std::string stFolder(c_pszFolder);
	stFolder += "/";

	std::string stFileName(stFolder);
	stFileName += "Index";

	CMappedFile file;
	LPCVOID pvData;

	if (!file.Create(stFileName.c_str(), &pvData, 0, 0))
	{
		LogBoxf("FATAL ERROR! File not exist: %s", stFileName.c_str());
		TraceError("FATAL ERROR! File not exist: %s", stFileName.c_str());
		return true;
	}

	CMemoryTextFileLoader TextLoader;
	TextLoader.Bind(file.Size(), pvData);

	bool bPackFirst = TRUE;

	const std::string& strPackType = TextLoader.GetLineString(0);

	if (strPackType.compare("FILE") && strPackType.compare("PACK"))
	{
		TraceError("Pack/Index has invalid syntax. First line must be 'PACK' or 'FILE'");
		return false;
	}

#ifdef _DISTRIBUTE
	Tracef("¾Ë¸²: ÆÑ ¸ðµåÀÔ´Ï´Ù.\n");

	//if (0 == strPackType.compare("FILE"))
	//{
	//	bPackFirst = FALSE;
	//	Tracef("¾Ë¸²: ÆÄÀÏ ¸ðµåÀÔ´Ï´Ù.\n");
	//}
	//else
	//{
	//	Tracef("¾Ë¸²: ÆÑ ¸ðµåÀÔ´Ï´Ù.\n");
	//}
#else
	bPackFirst = FALSE;
	Tracef("¾Ë¸²: ÆÄÀÏ ¸ðµåÀÔ´Ï´Ù.\n");
#endif

	CTextFileLoader::SetCacheMode();
#if defined(USE_RELATIVE_PATH)
	CEterPackManager::Instance().SetRelativePathMode();
#endif
	CEterPackManager::Instance().SetCacheMode();
	CEterPackManager::Instance().SetSearchMode(bPackFirst);

	CSoundData::SetPackMode(); // Miles ÆÄÀÏ ÄݹéÀ» ¼ÂÆÃ

	std::string strPackName, strTexCachePackName;
	for (DWORD i = 1; i < TextLoader.GetLineCount() - 1; i += 2)
	{
		const std::string & c_rstFolder = TextLoader.GetLineString(i);
		const std::string & c_rstName = TextLoader.GetLineString(i + 1);

		strPackName = stFolder + c_rstName;
		strTexCachePackName = strPackName + "_texcache";

		CEterPackManager::Instance().RegisterPack(strPackName.c_str(), c_rstFolder.c_str());
		CEterPackManager::Instance().RegisterPack(strTexCachePackName.c_str(), c_rstFolder.c_str());
	}

	CEterPackManager::Instance().RegisterRootPack((stFolder + std::string("root")).c_str());
	NANOEND
		return true;
}

E agora nessa função vamos começar por fazer o seguinte: Vamos comentar o seguinte

/*
	std::string stFileName(stFolder);
	stFileName += "Index";

	CMappedFile file;
	LPCVOID pvData;

	if (!file.Create(stFileName.c_str(), &pvData, 0, 0))
	{
		LogBoxf("FATAL ERROR! File not exist: %s", stFileName.c_str());
		TraceError("FATAL ERROR! File not exist: %s", stFileName.c_str());
		return true;
	}

	CMemoryTextFileLoader TextLoader;
	TextLoader.Bind(file.Size(), pvData);
*/

E agora dentro da nossa função vamos procurar pelo seguinte e comenta-lo

/*
	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;
	}
*/

e por ultimo para remover o index com sucesso procuramos e comentamos o seguinte

/*
	std::string strPackName, strTexCachePackName;
	for (DWORD i = 1; i < TextLoader.GetLineCount() - 1; i += 2)
	{
		const std::string & c_rstFolder = TextLoader.GetLineString(i);
		const std::string & c_rstName = TextLoader.GetLineString(i + 1);

		strPackName = stFolder + c_rstName;
		strTexCachePackName = strPackName + "_texcache";

		CEterPackManager::Instance().RegisterPack(strPackName.c_str(), c_rstFolder.c_str());
		CEterPackManager::Instance().RegisterPack(strTexCachePackName.c_str(), c_rstFolder.c_str());
	}
*/

Agora com a nossa função sem a verificação do ficheiro index deverá estar assim:

bool PackInitialize(const char * c_pszFolder)
{
	NANOBEGIN
		if (_access(c_pszFolder, 0) != 0)
			return true;

	std::string stFolder(c_pszFolder);
	stFolder += "/";

/*
	std::string stFileName(stFolder);
	stFileName += "Index";

	CMappedFile file;
	LPCVOID pvData;

	if (!file.Create(stFileName.c_str(), &pvData, 0, 0))
	{
		LogBoxf("FATAL ERROR! File not exist: %s", stFileName.c_str());
		TraceError("FATAL ERROR! File not exist: %s", stFileName.c_str());
		return true;
	}

	CMemoryTextFileLoader TextLoader;
	TextLoader.Bind(file.Size(), pvData);
*/

	bool bPackFirst = TRUE;

/*
	const std::string& strPackType = TextLoader.GetLineString(0);

	if (strPackType.compare("FILE") && strPackType.compare("PACK"))
	{
		TraceError("Pack/Index has invalid syntax. First line must be 'PACK' or 'FILE'");
		return false;
	}
*/

#ifdef _DISTRIBUTE
	Tracef("¾Ë¸²: ÆÑ ¸ðµåÀÔ´Ï´Ù.\n");
#else
	bPackFirst = FALSE;
	Tracef("¾Ë¸²: ÆÄÀÏ ¸ðµåÀÔ´Ï´Ù.\n");
#endif

	CTextFileLoader::SetCacheMode();
#if defined(USE_RELATIVE_PATH)
	CEterPackManager::Instance().SetRelativePathMode();
#endif
	CEterPackManager::Instance().SetCacheMode();
	CEterPackManager::Instance().SetSearchMode(bPackFirst);

	CSoundData::SetPackMode(); // Miles ÆÄÀÏ ÄݹéÀ» ¼ÂÆÃ

/*
	std::string strPackName, strTexCachePackName;
	for (DWORD i = 1; i < TextLoader.GetLineCount() - 1; i += 2)
	{
		const std::string & c_rstFolder = TextLoader.GetLineString(i);
		const std::string & c_rstName = TextLoader.GetLineString(i + 1);

		strPackName = stFolder + c_rstName;
		strTexCachePackName = strPackName + "_texcache";

		CEterPackManager::Instance().RegisterPack(strPackName.c_str(), c_rstFolder.c_str());
		CEterPackManager::Instance().RegisterPack(strTexCachePackName.c_str(), c_rstFolder.c_str());
	}
*/

	CEterPackManager::Instance().RegisterRootPack((stFolder + std::string("root")).c_str());
	NANOEND
		return true;
}

agora para adicionarem novos patchs ao binário fazem da seguinte forma: acima do seguinte

	CEterPackManager::Instance().RegisterRootPack((stFolder + std::string("root")).c_str());

adicionamos os nossos patchs, como por exemplo:

	CEterPackManager::Instance().RegisterPack("pack/item1", "*");
	CEterPackManager::Instance().RegisterPack("pack/pc1", "*");
	CEterPackManager::Instance().RegisterPack("pack/pc2", "*");
	CEterPackManager::Instance().RegisterRootPack((stFolder + std::string("root")).c_str());

Em caso de algum erro deixem nos comentários que posso ter me esquecido de alguma coisa.

 

Cumprimentos, Dynamic Things

Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...
Em 14/03/2019 em 07:36, Laos disse:

I have in index file something like this:

d:/ymir work/zone/
objects

How can I place it in this code?

When you index the directory zone you are already indexing all subdirectories that the folder contain, you can do it like the following example

CEterPackManager::Instance().RegisterPack("pack/zone", "*");

 

Edited by Dynamic Things
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...