mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Note: this does not work reliably still. The only way we could make this work 100% reliable would be to fully rebuild '0x140341D40' in the SDK and load our pak files among with the pre-existing g_pakLoadApi->AsyncLoad() call in this function, as this will ensure everything will be ran synchronously. The current approach by taking some JT fifolock wrapper will only work reliably between one level change, unsure why the second and up fail.
90 lines
2.6 KiB
C++
90 lines
2.6 KiB
C++
//=============================================================================//
|
|
//
|
|
// Purpose: RTech game utilities
|
|
//
|
|
//=============================================================================//
|
|
#include "core/stdafx.h"
|
|
#include "engine/host_cmd.h"
|
|
#include "engine/sys_utils.h"
|
|
#include "engine/host_state.h"
|
|
#include "engine/cmodel_bsp.h"
|
|
#include "rtech/rtech_game.h"
|
|
|
|
vector<RPakHandle_t> g_LoadedPakHandle{ };
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: load user-requested pak files on-demand
|
|
// Input : *szPakFileName -
|
|
// *pMalloc -
|
|
// nIdx -
|
|
// bUnk -
|
|
// Output : pak file handle on success, -1 (INVALID_PAK_HANDLE) on failure
|
|
//-----------------------------------------------------------------------------
|
|
RPakHandle_t CPakFile::AsyncLoad(const char* szPakFileName, uintptr_t pMalloc, int nIdx, bool bUnk)
|
|
{
|
|
RPakHandle_t pakHandle = -1;
|
|
#ifdef DEDICATED
|
|
// Extraneous files (useless on the dedicated server).
|
|
if (strcmp(szPakFileName, "ui.rpak") == 0)
|
|
{
|
|
static const char* szReplacement = "common_empty.rpak";
|
|
// Returning -1 (invalid handle) triggers engine error, call is inline.
|
|
// Replacing the ui.rpak file here with a stub to avoid having to patch.
|
|
Warning(eDLL_T::RTECH, "Replacing '%s' with '%s'\n", szPakFileName, szReplacement);
|
|
return pakHandle = CPakFile_AsyncLoad(szReplacement, pMalloc, nIdx, bUnk);
|
|
}
|
|
else if (strstr(szPakFileName, "ui")
|
|
|| strstr(szPakFileName, "loadscreen")
|
|
|| strstr(szPakFileName, "subtitles"))
|
|
{
|
|
return pakHandle;
|
|
}
|
|
#endif // DEDICATED
|
|
|
|
if (strcmp(szPakFileName, "mp_lobby.rpak") == 0)
|
|
g_bBasePaksInitialized = true;
|
|
|
|
static bool bOnce = false;
|
|
if (g_bBasePaksInitialized && !g_bLevelResourceInitialized
|
|
&& !bOnce)
|
|
{
|
|
g_bLevelResourceInitialized = true;
|
|
bOnce = true;
|
|
|
|
if (g_pHostState->LevelHasChanged())
|
|
MOD_PreloadPak();
|
|
}
|
|
|
|
string svPakFilePathMod = "paks\\Win32\\" + string(szPakFileName);
|
|
string svPakFilePathBase = "paks\\Win64\\" + string(szPakFileName);
|
|
|
|
if (FileExists(svPakFilePathMod.c_str()) || FileExists(svPakFilePathBase.c_str()))
|
|
{
|
|
pakHandle = CPakFile_AsyncLoad(szPakFileName, pMalloc, nIdx, bUnk);
|
|
|
|
if (pakHandle == -1)
|
|
{
|
|
Error(eDLL_T::RTECH, "%s: Failed read '%s' results '%u'\n", __FUNCTION__, szPakFileName, pakHandle);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Error(eDLL_T::RTECH, "%s: Failed. File '%s' doesn't exist\n", __FUNCTION__, szPakFileName);
|
|
}
|
|
|
|
return pakHandle;
|
|
}
|
|
|
|
void RTech_Game_Attach()
|
|
{
|
|
DetourAttach((LPVOID*)&CPakFile_AsyncLoad, &CPakFile::AsyncLoad);
|
|
}
|
|
|
|
void RTech_Game_Detach()
|
|
{
|
|
DetourDetach((LPVOID*)&CPakFile_AsyncLoad, &CPakFile::AsyncLoad);
|
|
}
|
|
|
|
// Symbols taken from R2 dll's.
|
|
CPakFile* g_pakLoadApi = new CPakFile();
|