See description

Fixed 'MOD_PreloadPak()' being called recursively.
Fixed wrong datatype for pak handle.
Use new and better method of parsing JSON files.
Don't unload pak files if user issued 'ChangeLevel' to the same level.

NOTE: This is still not complete and currently under development.
This commit is contained in:
Kawe Mazidjatari 2022-05-03 17:36:42 +02:00
parent 10474d07d7
commit 713bafc416
3 changed files with 16 additions and 28 deletions

View File

@ -16,7 +16,7 @@
// Purpose: loads required pakfile assets for specified BSP
// Input : svSetFile -
//-----------------------------------------------------------------------------
void MOD_PreloadPak(const string& svSetFile)
void MOD_PreloadPak()
{
ostringstream ostream;
ostream << "platform\\scripts\\levels\\settings\\" << g_pHostState->m_levelName << ".json";
@ -27,29 +27,26 @@ void MOD_PreloadPak(const string& svSetFile)
nlohmann::json jsIn;
try
{
ifstream iPakLoadDefFile(fsPath, std::ios::binary); // Parse prerequisites file.
iPakLoadDefFile >> jsIn;
ifstream iPakLoadDefFile(fsPath.string().c_str(), std::ios::binary); // Load prerequisites file.
jsIn = nlohmann::json::parse(iPakLoadDefFile);
iPakLoadDefFile.close();
if (!jsIn.is_null())
{
if (!jsIn["rpak"].is_null())
{
for (auto it = jsIn["rpak"].begin(); it != jsIn["rpak"].end(); ++it)
for (auto& it : jsIn["rpak"])
{
if (it.value().is_string())
if (it.is_string())
{
string svToLoad = it.value().get<string>() + ".rpak";
uint32_t nPakId = g_pakLoadApi->AsyncLoad(svToLoad.c_str(), g_pMallocPool.GetPtr(), 4, 0);
string svToLoad = it.get<string>() + ".rpak";
RPakHandle_t nPakId = g_pakLoadApi->AsyncLoad(svToLoad.c_str(), g_pMallocPool.GetPtr(), 4, 0);
if (nPakId == -1)
{
Error(eDLL_T::RTECH, "RTech_AsyncLoad: failed read '%s' results '%u'\n", fsPath.string().c_str(), nPakId);
}
Error(eDLL_T::ENGINE, "%s: unable to load pak '%s' results '%d'\n", __FUNCTION__, svToLoad.c_str(), nPakId);
else
{
g_LoadedPakHandle.push_back(nPakId);
}
}
}
}

View File

@ -3,7 +3,7 @@
inline CMemory p_CollisionBSPData_LinkPhysics;
inline auto CollisionBSPData_LinkPhysics = p_CollisionBSPData_LinkPhysics.RCast<uint64_t(*)(void* thisptr)>();
void MOD_PreloadPak(const string& svSetFile);
void MOD_PreloadPak();
///////////////////////////////////////////////////////////////////////////////
class HModel_BSP : public IDetour
{

View File

@ -40,23 +40,14 @@ RPakHandle_t CPakFile::AsyncLoad(const char* szPakFileName, uintptr_t pMalloc, i
return pakHandle;
}
#endif // DEDICATED
static bool bBasePaksLoaded = false;
if (g_pHostState)
if (strcmp(szPakFileName, "mp_lobby.rpak") == 0 || !g_bLevelResourceInitialized && !g_pHostState->m_bActiveGame &&
bBasePaksLoaded)
{
string svLevelName = g_pHostState->m_levelName;
string svMapPakName = svLevelName + ".rpak";
static bool bBasePaksLoaded = false;
if (!g_bLevelResourceInitialized && !g_pHostState->m_bActiveGame &&
bBasePaksLoaded || !strcmp(szPakFileName, "mp_lobby.rpak"))
{
// Attempt to load level dependencies if they exist.
MOD_PreloadPak(svLevelName);
// By the time mp_lobby.rpak is loaded, all the base paks are loaded as well and we can load anything else.
bBasePaksLoaded = true;
g_bLevelResourceInitialized = true;
}
bBasePaksLoaded = true; // By the time mp_lobby.rpak is loaded, all the base paks are loaded as well and we can load anything else.
g_bLevelResourceInitialized = true;
MOD_PreloadPak();
}
string svPakFilePathMod = "paks\\Win32\\" + string(szPakFileName);