mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
This change was planned for a long time. This moves all REGISTER calls to a single translation unit, this is required as we currently added a very dirty workaround for not registering duplicates by checking if VFTable pointer was already present in the vector... Registering from single translation unit prevents duplicate instances that gets created if header is included by more cpp files. Reworking this reduced 100kb+ of compiled code. This commit also reworked the way functions/variables/constant gets logged with their addresses; the new code formats them on the fly, and allows for resize at any time. Formatting is no longer required by programmer. TODO: currently there are some compile errors for dedicated and client dll's. These will be resolved very soon as they need to be properly worked out still (server & client only stuff needs to be properly split). Use the 'main' (stable) branch for the time being if you need to compile these dll's.
101 lines
3.1 KiB
C++
101 lines
3.1 KiB
C++
//=============================================================================//
|
|
//
|
|
// Purpose: RTech game utilities
|
|
//
|
|
//=============================================================================//
|
|
#include "core/stdafx.h"
|
|
#include "engine/host_cmd.h"
|
|
#include "engine/host_state.h"
|
|
#include "engine/cmodel_bsp.h"
|
|
#include "rtech/rtech_game.h"
|
|
#include "rtech/rtech_utils.h"
|
|
|
|
vector<RPakHandle_t> g_vLoadedPakHandle;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: load user-requested pak files on-demand
|
|
// Input : *szPakFileName -
|
|
// *pMalloc -
|
|
// nIdx -
|
|
// bUnk -
|
|
// Output : pak file handle on success, INVALID_PAK_HANDLE on failure
|
|
//-----------------------------------------------------------------------------
|
|
RPakHandle_t CPakFile::LoadAsync(const char* szPakFileName, void* pMalloc, int nIdx, bool bUnk)
|
|
{
|
|
RPakHandle_t pakHandle = INVALID_PAK_HANDLE;
|
|
#ifdef DEDICATED
|
|
// Extraneous files (useless on the dedicated server).
|
|
if (strcmp(szPakFileName, "ui.rpak") == 0)
|
|
{
|
|
static const char* szReplacement = "empty.rpak";
|
|
// Returning INVALID_PAK_HANDLE triggers engine error, call is inline.
|
|
// Replacing the ui.rpak file here with a stub to avoid having to patch.
|
|
DevMsg(eDLL_T::RTECH, "Loading pak file: '%s' for '%s'\n", szReplacement, szPakFileName);
|
|
return pakHandle = CPakFile_LoadAsync(szReplacement, pMalloc, nIdx, bUnk);
|
|
}
|
|
else if (strstr(szPakFileName, "ui")
|
|
|| strstr(szPakFileName, "loadscreen")
|
|
|| strstr(szPakFileName, "subtitles"))
|
|
{
|
|
return pakHandle;
|
|
}
|
|
#endif // DEDICATED
|
|
|
|
string svPakFileModPath = "paks\\Win32\\" + string(szPakFileName);
|
|
string svPakFilePathBase = "paks\\Win64\\" + string(szPakFileName);
|
|
|
|
if (FileExists(svPakFileModPath) || FileExists(svPakFilePathBase))
|
|
{
|
|
DevMsg(eDLL_T::RTECH, "Loading pak file: '%s'\n", szPakFileName);
|
|
pakHandle = CPakFile_LoadAsync(szPakFileName, pMalloc, nIdx, bUnk);
|
|
|
|
if (pakHandle == INVALID_PAK_HANDLE)
|
|
{
|
|
Error(eDLL_T::RTECH, NO_ERROR, "%s: Failed read '%s' results '%u'\n", __FUNCTION__, szPakFileName, pakHandle);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Error(eDLL_T::RTECH, NO_ERROR, "%s: Failed. File '%s' doesn't exist\n", __FUNCTION__, szPakFileName);
|
|
}
|
|
|
|
return pakHandle;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: unloads loaded pak files
|
|
// Input : handle -
|
|
//-----------------------------------------------------------------------------
|
|
void CPakFile::UnloadPak(RPakHandle_t handle)
|
|
{
|
|
RPakLoadedInfo_t* pakInfo = g_pRTech->GetPakLoadedInfo(handle);
|
|
|
|
if (pakInfo)
|
|
{
|
|
if (pakInfo->m_pszFileName)
|
|
{
|
|
DevMsg(eDLL_T::RTECH, "Unloading pak file: '%s'\n", pakInfo->m_pszFileName);
|
|
|
|
if (strcmp(pakInfo->m_pszFileName, "mp_lobby.rpak") == 0)
|
|
s_bBasePaksInitialized = false;
|
|
}
|
|
}
|
|
|
|
CPakFile_UnloadPak(handle);
|
|
}
|
|
|
|
void V_RTechGame::Attach() const
|
|
{
|
|
DetourAttach(&CPakFile_LoadAsync, &CPakFile::LoadAsync);
|
|
DetourAttach(&CPakFile_UnloadPak, &CPakFile::UnloadPak);
|
|
}
|
|
|
|
void V_RTechGame::Detach() const
|
|
{
|
|
DetourDetach(&CPakFile_LoadAsync, &CPakFile::LoadAsync);
|
|
DetourDetach(&CPakFile_UnloadPak, &CPakFile::UnloadPak);
|
|
}
|
|
|
|
// Symbols taken from R2 dll's.
|
|
CPakFile* g_pakLoadApi = new CPakFile();
|