FileExist cleanup

Use fs::path constructor for all strings.
Renamed CPakFile::AsyncLoad to CPakFile::LoadAsync.
Renamed CPakFile::Load to CPakFile::LoadPak.
This commit is contained in:
Kawe Mazidjatari 2022-06-12 12:40:26 +02:00
parent 97ca335a21
commit 7c0c541405
9 changed files with 41 additions and 41 deletions

View File

@ -211,7 +211,7 @@ void MOD_ProcessPakQueue()
}
if (!v14 || v13 == 9)
{
g_pakLoadApi->Unload(*(_DWORD*)v10);
g_pakLoadApi->UnloadPak(*(_DWORD*)v10);
MOD_UnloadPakFile();
}
if (v13 && (unsigned int)(v13 - 13) > 1)
@ -292,17 +292,17 @@ void MOD_ProcessPakQueue()
s_bLevelResourceInitialized = true;
MOD_PreloadPakFile(g_svLevelName);
}
*(_DWORD*)v15 = g_pakLoadApi->AsyncLoad(v17, g_pMallocPool.GetPtr(), 4, 0);
*(_DWORD*)v15 = g_pakLoadApi->LoadAsync(v17, g_pMallocPool.GetPtr(), 4, 0);
if (strcmp(v17, "common_mp.rpak") == 0 || strcmp(v17, "common_sp.rpak") == 0 || strcmp(v17, "common_pve.rpak") == 0)
{
RPakHandle_t pakHandle = g_pakLoadApi->AsyncLoad("common_sdk.rpak", g_pMallocPool.GetPtr(), 4, 0);
RPakHandle_t pakHandle = g_pakLoadApi->LoadAsync("common_sdk.rpak", g_pMallocPool.GetPtr(), 4, 0);
if (pakHandle != -1)
g_vLoadedPakHandle.push_back(pakHandle);
}
if (strcmp(v17, "ui_mp.rpak") == 0)
{
RPakHandle_t pakHandle = g_pakLoadApi->AsyncLoad("ui_sdk.rpak", g_pMallocPool.GetPtr(), 4, 0);
RPakHandle_t pakHandle = g_pakLoadApi->LoadAsync("ui_sdk.rpak", g_pMallocPool.GetPtr(), 4, 0);
if (pakHandle != -1)
g_vLoadedPakHandle.push_back(pakHandle);
}
@ -349,7 +349,7 @@ void MOD_PreloadPakFile(const string& svLevelName)
ostream << "platform\\scripts\\levels\\settings\\" << svLevelName << ".json";
fs::path fsPath = fs::current_path() /= ostream.str();
if (FileExists(fsPath.string().c_str()))
if (FileExists(fsPath))
{
nlohmann::json jsIn;
try
@ -368,7 +368,7 @@ void MOD_PreloadPakFile(const string& svLevelName)
if (it.is_string())
{
string svToLoad = it.get<string>() + ".rpak";
RPakHandle_t nPakId = g_pakLoadApi->AsyncLoad(svToLoad.c_str(), g_pMallocPool.GetPtr(), 4, 0);
RPakHandle_t nPakId = g_pakLoadApi->LoadAsync(svToLoad.c_str(), g_pMallocPool.GetPtr(), 4, 0);
if (nPakId == -1)
Error(eDLL_T::ENGINE, "%s: unable to load pak '%s' results '%d'\n", __FUNCTION__, svToLoad.c_str(), nPakId);
@ -396,7 +396,7 @@ void MOD_UnloadPakFile(void)
{
if (it >= 0)
{
g_pakLoadApi->Unload(it);
g_pakLoadApi->UnloadPak(it);
}
}
g_vLoadedPakHandle.clear();

View File

@ -107,7 +107,7 @@ void* HSys_LoadAssetHelper(const CHAR* lpFileName, std::int64_t a2, LARGE_INTEGE
base_file.erase(0, 11); // Erase 'base_dir'.
mod_file = mod_dir + base_file; // Prepend 'mod_dir'.
if (FileExists(mod_file.c_str()))
if (FileExists(mod_file))
{
// Load decompressed pak files from 'mod_dir'.
return Sys_LoadAssetHelper(mod_file.c_str(), a2, a3);

View File

@ -120,7 +120,7 @@ FileHandle_t CBaseFileSystem::ReadFromVPK(CBaseFileSystem* pFileSystem, FileHand
// TODO: obtain 'mod' SearchPath's instead.
svFilePath.insert(0, "platform\\");
if (::FileExists(svFilePath.c_str()) /*|| ::FileExists(pszFilePath)*/)
if (::FileExists(svFilePath) /*|| ::FileExists(pszFilePath)*/)
{
*reinterpret_cast<int64_t*>(pResults) = -1;
return pResults;
@ -148,7 +148,7 @@ bool CBaseFileSystem::ReadFromCache(CBaseFileSystem* pFileSystem, char* pszFileP
// TODO: obtain 'mod' SearchPath's instead.
svFilePath.insert(0, "platform\\");
if (::FileExists(svFilePath.c_str()) /*|| ::FileExists(pszFilePath)*/)
if (::FileExists(svFilePath) /*|| ::FileExists(pszFilePath)*/)
{
return false;
}

View File

@ -18,7 +18,7 @@ void StreamDB_Init(const char* pszStreamDBFile)
ostream << "platform\\scripts\\levels\\settings\\" << pszStreamDBFile << ".json";
fs::path fsPath = fs::current_path() /= ostream.str();
if (FileExists(fsPath.string().c_str()))
if (FileExists(fsPath))
{
nlohmann::json jsIn;
try

View File

@ -3,7 +3,7 @@
/////////////////////////////////////////////////////////////////////////////
// Internals
BOOL IsBadReadPtrV2(void* ptr);
BOOL FileExists(const char* szPath);
BOOL FileExists(const fs::path& svFilePath);
MODULEINFO GetModuleInfo(const char* szModule);
DWORD64 FindPatternSIMD(const char* szModule, const unsigned char* szPattern, const char* szMask);

View File

@ -8,9 +8,9 @@
///////////////////////////////////////////////////////////////////////////////
// For checking if a specific file exists.
BOOL FileExists(const char* szPath)
BOOL FileExists(const fs::path& svFilePath)
{
return fs::exists(szPath);
return fs::exists(svFilePath);
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -20,7 +20,7 @@ vector<RPakHandle_t> g_vLoadedPakHandle;
// 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 CPakFile::LoadAsync(const char* szPakFileName, uintptr_t pMalloc, int nIdx, bool bUnk)
{
RPakHandle_t pakHandle = -1;
#ifdef DEDICATED
@ -44,10 +44,10 @@ RPakHandle_t CPakFile::AsyncLoad(const char* szPakFileName, uintptr_t pMalloc, i
string svPakFilePathMod = "paks\\Win32\\" + string(szPakFileName);
string svPakFilePathBase = "paks\\Win64\\" + string(szPakFileName);
if (FileExists(svPakFilePathMod.c_str()) || FileExists(svPakFilePathBase.c_str()))
if (FileExists(svPakFilePathMod) || FileExists(svPakFilePathBase))
{
DevMsg(eDLL_T::RTECH, "Loading pak file: '%s'\n", szPakFileName);
pakHandle = CPakFile_AsyncLoad(szPakFileName, pMalloc, nIdx, bUnk);
pakHandle = CPakFile_LoadAsync(szPakFileName, pMalloc, nIdx, bUnk);
if (pakHandle == -1)
{
@ -66,7 +66,7 @@ RPakHandle_t CPakFile::AsyncLoad(const char* szPakFileName, uintptr_t pMalloc, i
// Purpose: unloads loaded pak files
// Input : handle -
//-----------------------------------------------------------------------------
void CPakFile::Unload(RPakHandle_t handle)
void CPakFile::UnloadPak(RPakHandle_t handle)
{
RPakLoadedInfo_t* pakInfo = g_pRTech->GetPakLoadedInfo(handle);
@ -81,19 +81,19 @@ void CPakFile::Unload(RPakHandle_t handle)
}
}
CPakFile_Unload(handle);
CPakFile_UnloadPak(handle);
}
void RTech_Game_Attach()
{
DetourAttach((LPVOID*)&CPakFile_AsyncLoad, &CPakFile::AsyncLoad);
DetourAttach((LPVOID*)&CPakFile_Unload, &CPakFile::Unload);
DetourAttach((LPVOID*)&CPakFile_LoadAsync, &CPakFile::LoadAsync);
DetourAttach((LPVOID*)&CPakFile_UnloadPak, &CPakFile::UnloadPak);
}
void RTech_Game_Detach()
{
DetourDetach((LPVOID*)&CPakFile_AsyncLoad, &CPakFile::AsyncLoad);
DetourDetach((LPVOID*)&CPakFile_Unload, &CPakFile::Unload);
DetourDetach((LPVOID*)&CPakFile_LoadAsync, &CPakFile::LoadAsync);
DetourDetach((LPVOID*)&CPakFile_UnloadPak, &CPakFile::UnloadPak);
}
// Symbols taken from R2 dll's.

View File

@ -24,20 +24,20 @@ enum class ePakStatus : int
};
/* ==== RTECH_GAME ====================================================================================================================================================== */
inline CMemory p_CPakFile_LoadAsync;
inline auto CPakFile_LoadAsync = p_CPakFile_LoadAsync.RCast<RPakHandle_t(*)(const char* szPakFileName, uintptr_t pMalloc, int nIdx, bool bUnk)>();
inline CMemory p_CPakFile_LoadPak;
inline auto CPakFile_LoadPak = p_CPakFile_LoadPak.RCast<unsigned int (*)(void* thisptr, void* a2, uint64_t a3)>();
inline CMemory p_CPakFile_AsyncLoad;
inline auto CPakFile_AsyncLoad = p_CPakFile_AsyncLoad.RCast<RPakHandle_t(*)(const char* szPakFileName, uintptr_t pMalloc, int nIdx, bool bUnk)>();
inline CMemory p_CPakFile_UnloadPak;
inline auto CPakFile_Unload = p_CPakFile_UnloadPak.RCast<void (*)(RPakHandle_t handle)>();
inline auto CPakFile_UnloadPak = p_CPakFile_UnloadPak.RCast<void (*)(RPakHandle_t handle)>();
class CPakFile
{
public:
static RPakHandle_t AsyncLoad(const char* szPakFileName, uintptr_t pMalloc = g_pMallocPool.GetPtr(), int nIdx = NULL, bool bUnk = false);
static void Unload(RPakHandle_t handle);
static RPakHandle_t LoadAsync(const char* szPakFileName, uintptr_t pMalloc = g_pMallocPool.GetPtr(), int nIdx = NULL, bool bUnk = false);
static void UnloadPak(RPakHandle_t handle);
};
extern CPakFile* g_pakLoadApi;
@ -50,7 +50,7 @@ class VRTechGame : public IDetour
{
virtual void GetAdr(void) const
{
spdlog::debug("| FUN: CPakFile::AsyncLoad : {:#18x} |\n", p_CPakFile_AsyncLoad.GetPtr());
spdlog::debug("| FUN: CPakFile::LoadAsync : {:#18x} |\n", p_CPakFile_LoadAsync.GetPtr());
spdlog::debug("| FUN: CPakFile::LoadPak : {:#18x} |\n", p_CPakFile_LoadPak.GetPtr());
spdlog::debug("| FUN: CPakFile::UnloadPak : {:#18x} |\n", p_CPakFile_UnloadPak.GetPtr());
spdlog::debug("+----------------------------------------------------------------+\n");
@ -65,14 +65,14 @@ class VRTechGame : public IDetour
CPakFile_LoadPak = p_CPakFile_LoadPak.RCast<unsigned int (*)(void*, void*, uint64_t)>();
#endif
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2)
p_CPakFile_AsyncLoad = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x48\x83\xEC\x40\x48\x89\x6C\x24\x00\x41\x8B\xE8"), "xxxxxxxxxx?xxx");
CPakFile_AsyncLoad = p_CPakFile_AsyncLoad.RCast<RPakHandle_t(*)(const char*, uintptr_t, int, bool)>(); /*40 53 48 83 EC 40 48 89 6C 24 ? 41 8B E8*/
p_CPakFile_LoadAsync = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x48\x83\xEC\x40\x48\x89\x6C\x24\x00\x41\x8B\xE8"), "xxxxxxxxxx?xxx");
CPakFile_LoadAsync = p_CPakFile_LoadAsync.RCast<RPakHandle_t(*)(const char*, uintptr_t, int, bool)>(); /*40 53 48 83 EC 40 48 89 6C 24 ? 41 8B E8*/
#elif defined (GAMEDLL_S3)
p_CPakFile_AsyncLoad = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x48\x83\xEC\x40\x48\x89\x6C\x24\x00\x41\x0F\xB6\xE9"), "xxxxxxxxxx?xxxx");
CPakFile_AsyncLoad = p_CPakFile_AsyncLoad.RCast<RPakHandle_t(*)(const char*, uintptr_t, int, bool)>(); /*40 53 48 83 EC 40 48 89 6C 24 ? 41 0F B6 E9*/
p_CPakFile_LoadAsync = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x48\x83\xEC\x40\x48\x89\x6C\x24\x00\x41\x0F\xB6\xE9"), "xxxxxxxxxx?xxxx");
CPakFile_LoadAsync = p_CPakFile_LoadAsync.RCast<RPakHandle_t(*)(const char*, uintptr_t, int, bool)>(); /*40 53 48 83 EC 40 48 89 6C 24 ? 41 0F B6 E9*/
#endif
p_CPakFile_UnloadPak = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xEC\x30\x8B\xC1"), "xxxx?xxxx?xxxxxxx");
CPakFile_Unload = p_CPakFile_UnloadPak.RCast<void (*)(RPakHandle_t)>(); /*48 89 5C 24 ? 48 89 74 24 ? 57 48 83 EC 30 8B C1*/
CPakFile_UnloadPak = p_CPakFile_UnloadPak.RCast<void (*)(RPakHandle_t)>(); /*48 89 5C 24 ? 48 89 74 24 ? 57 48 83 EC 30 8B C1*/
}
virtual void GetVar(void) const { }
virtual void GetCon(void) const { }

View File

@ -383,7 +383,7 @@ void Pak_RequestUnload_f(const CCommand& args)
string pakName = pakInfo->m_pszFileName;
!pakName.empty() ? DevMsg(eDLL_T::RTECH, "Requested pak unload for '%s'\n", pakName.c_str()) : DevMsg(eDLL_T::RTECH, "Requested Pak Unload for '%d'\n", nPakId);
g_pakLoadApi->Unload(nPakId);
g_pakLoadApi->UnloadPak(nPakId);
}
else
{
@ -394,7 +394,7 @@ void Pak_RequestUnload_f(const CCommand& args)
}
DevMsg(eDLL_T::RTECH, "Requested pak unload for '%s'\n", args.Arg(1));
g_pakLoadApi->Unload(pakInfo->m_nPakId);
g_pakLoadApi->UnloadPak(pakInfo->m_nPakId);
}
}
catch (std::exception& e)
@ -411,7 +411,7 @@ Pak_RequestLoad_f
*/
void Pak_RequestLoad_f(const CCommand& args)
{
g_pakLoadApi->AsyncLoad(args.Arg(1));
g_pakLoadApi->LoadAsync(args.Arg(1));
}
@ -453,12 +453,12 @@ void Pak_Swap_f(const CCommand& args)
!pakName.empty() ? DevMsg(eDLL_T::RTECH, "Requested pak swap for '%s'\n", pakName.c_str()) : DevMsg(eDLL_T::RTECH, "Requested pak swap for '%d'\n", nPakId);
g_pakLoadApi->Unload(nPakId);
g_pakLoadApi->UnloadPak(nPakId);
while (pakInfo->m_nStatus != RPakStatus_t::PAK_STATUS_FREED) // Wait till this slot gets free'd.
std::this_thread::sleep_for(std::chrono::seconds(1));
g_pakLoadApi->AsyncLoad(pakName.c_str());
g_pakLoadApi->LoadAsync(pakName.c_str());
}
catch (std::exception& e)
{
@ -512,7 +512,7 @@ void RTech_Decompress_f(const CCommand& args)
DevMsg(eDLL_T::RTECH, "______________________________________________________________\n");
DevMsg(eDLL_T::RTECH, "-+ RTech decompress ------------------------------------------\n");
if (!FileExists(pakNameIn.c_str()))
if (!FileExists(pakNameIn))
{
Error(eDLL_T::RTECH, "Error: pak file '%s' does not exist!\n", pakNameIn.c_str());
return;