2022-03-01 02:39:46 +01:00
|
|
|
//=============================================================================//
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
//
|
|
|
|
// $NoKeywords: $
|
|
|
|
//=============================================================================//
|
|
|
|
|
|
|
|
#include "core/stdafx.h"
|
|
|
|
#include "engine/host_cmd.h"
|
|
|
|
#include "engine/host_state.h"
|
|
|
|
#include "engine/sys_utils.h"
|
|
|
|
#include "engine/cmodel_bsp.h"
|
|
|
|
#include "rtech/rtech_game.h"
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-03-02 01:16:35 +01:00
|
|
|
// Purpose: loads required pakfile assets for specified BSP
|
2022-03-07 11:32:12 +01:00
|
|
|
// Input : svSetFile -
|
2022-03-01 02:39:46 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-04-09 06:05:47 +02:00
|
|
|
void MOD_PreloadPak(const string& svSetFile)
|
2022-03-01 02:39:46 +01:00
|
|
|
{
|
2022-04-09 06:05:47 +02:00
|
|
|
ostringstream ostream;
|
2022-03-02 01:16:35 +01:00
|
|
|
ostream << "platform\\scripts\\levels\\settings\\" << g_pHostState->m_levelName << ".json";
|
2022-03-01 02:39:46 +01:00
|
|
|
|
2022-04-09 06:05:47 +02:00
|
|
|
fs::path fsPath = std::filesystem::current_path() /= ostream.str();
|
2022-03-01 02:39:46 +01:00
|
|
|
if (FileExists(fsPath.string().c_str()))
|
|
|
|
{
|
|
|
|
nlohmann::json jsIn;
|
|
|
|
try
|
|
|
|
{
|
2022-04-09 06:05:47 +02:00
|
|
|
ifstream iPakLoadDefFile(fsPath, std::ios::binary); // Parse prerequisites file.
|
2022-03-01 02:39:46 +01:00
|
|
|
iPakLoadDefFile >> jsIn;
|
|
|
|
iPakLoadDefFile.close();
|
|
|
|
|
2022-03-02 01:16:35 +01:00
|
|
|
if (!jsIn.is_null())
|
2022-03-01 02:39:46 +01:00
|
|
|
{
|
2022-03-02 01:16:35 +01:00
|
|
|
if (!jsIn["rpak"].is_null())
|
2022-03-01 02:39:46 +01:00
|
|
|
{
|
2022-03-02 01:16:35 +01:00
|
|
|
for (auto it = jsIn["rpak"].begin(); it != jsIn["rpak"].end(); ++it)
|
2022-03-01 02:39:46 +01:00
|
|
|
{
|
2022-03-02 01:16:35 +01:00
|
|
|
if (it.value().is_string())
|
2022-03-01 02:39:46 +01:00
|
|
|
{
|
2022-04-09 06:05:47 +02:00
|
|
|
string svToLoad = it.value().get<string>() + ".rpak";
|
|
|
|
uint32_t nPakId = RTech_AsyncLoad((void*)svToLoad.c_str(), g_pMallocPool.GetPtr(), 4, 0);
|
2022-03-01 02:39:46 +01:00
|
|
|
|
2022-03-02 01:16:35 +01:00
|
|
|
if (nPakId == -1)
|
|
|
|
{
|
2022-03-07 11:32:12 +01:00
|
|
|
Error(eDLL_T::RTECH, "RTech_AsyncLoad: failed read '%s' results '%u'\n", fsPath.string().c_str(), nPakId);
|
2022-03-02 01:16:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-28 00:57:04 +02:00
|
|
|
g_nLoadedPakFileId.push_back(nPakId);
|
2022-03-01 02:39:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
2022-03-07 11:32:12 +01:00
|
|
|
Warning(eDLL_T::RTECH, "Exception while parsing RPak load list: '%s'\n", ex.what());
|
2022-03-01 02:39:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|