Light changes for RTech::PakProcessGuidRelationsForAsset

* Use Warning() for deadlock detection debug log.
* Use const qualifiers where possible.
* Cache rtech_debug->GetBool().
* Renamed 'RPakAssetEntry' to 'RPakAssetEntry_t'.
* Renamed 'RPakDescriptor' to 'RPakDescriptor_t'.
This commit is contained in:
Kawe Mazidjatari 2022-11-01 00:44:09 +01:00
parent f8915f7c5d
commit 75b5148e65
2 changed files with 23 additions and 21 deletions

View File

@ -711,29 +711,29 @@ RPakLoadedInfo_t* RTech::GetPakLoadedInfo(const char* szPakName)
//-----------------------------------------------------------------------------
// Purpose: process guid relations for asset
//-----------------------------------------------------------------------------
void RTech::PakProcessGuidRelationsForAsset(PakFile_t* pPak, RPakAssetEntry* pAsset)
void RTech::PakProcessGuidRelationsForAsset(PakFile_t* pPak, RPakAssetEntry_t* pAsset)
{
RPakDescriptor* pGuidDescriptors = &pPak->m_pGuidDescriptors[pAsset->m_nUsesStartIdx];
RPakDescriptor_t* pGuidDescriptors = &pPak->m_pGuidDescriptors[pAsset->m_nUsesStartIdx];
volatile uint32_t* v5 = reinterpret_cast<volatile uint32_t*>(*(reinterpret_cast<uint64_t*>(g_pUnknownPakStruct) + 0x17 * (pPak->qword578 & 0x1FF) + 0x160212));
const bool bDebug = rtech_debug->GetBool();
if (rtech_debug->GetBool())
if (bDebug)
DevMsg(eDLL_T::RTECH, "Processing GUID relations for asset '0x%-16llX' in pak '%-32s'. Uses: %-4i\n", pAsset->m_Guid, pPak->m_pszFileName, pAsset->m_nUsesCount);
for (uint64_t i = 0; i < pAsset->m_nUsesCount; i++)
for (uint32_t i = 0; i < pAsset->m_nUsesCount; i++)
{
void** pCurrentGuid = reinterpret_cast<void**>(pPak->m_ppPagePointers[pGuidDescriptors[i].m_Index] + pGuidDescriptors[i].m_Offset);
// Get current guid.
uint64_t currentGuid = reinterpret_cast<uint64_t>(*pCurrentGuid);
const uint64_t currentGuid = reinterpret_cast<uint64_t>(*pCurrentGuid);
// Get asset index.
int assetIdx = currentGuid & 0x3FFFF;
uint64_t assetIdxEntryGuid = g_pUnknownPakStruct->m_Assets[assetIdx].m_Guid;
int64_t v9 = 2i64 * InterlockedExchangeAdd(v5, 1u);
*(uint64_t*)&v5[2 * v9 + 2] = currentGuid;
*(uint64_t*)&v5[2 * v9 + 4] = pAsset->m_Guid;
const int64_t v9 = 2i64 * InterlockedExchangeAdd(v5, 1u);
*reinterpret_cast<uint64_t*>(const_cast<uint32_t*>(&v5[2 * v9 + 2])) = currentGuid;
*reinterpret_cast<uint64_t*>(const_cast<uint32_t*>(&v5[2 * v9 + 4])) = pAsset->m_Guid;
std::function<bool(bool)> fnCheckAsset = [&](bool shouldCheckTwo)
{
@ -748,9 +748,9 @@ void RTech::PakProcessGuidRelationsForAsset(PakFile_t* pPak, RPakAssetEntry* pAs
assetIdx++;
// Check if we have a deadlock and report it if we have rtech_debug enabled.
if (rtech_debug->GetBool() && assetIdx > 0x40000)
if (bDebug && assetIdx > 0x40000)
{
DevMsg(eDLL_T::RTECH, "Possible deadlock detected in fnCheckAsset for asset '0x%-16llX' in pak '%-32s'. Uses: %-4i | assetIdxEntryGuid: '0x%-16llX' | currentGuid: '0x%-16llX'\n", pAsset->m_Guid, pPak->m_pszFileName, pAsset->m_nUsesCount, assetIdxEntryGuid, currentGuid);
Warning(eDLL_T::RTECH, "Possible deadlock detected while processing asset '0x%-16llX' in pak '%-32s'. Uses: %-4i | assetIdxEntryGuid: '0x%-16llX' | currentGuid: '0x%-16llX'\n", pAsset->m_Guid, pPak->m_pszFileName, pAsset->m_nUsesCount, assetIdxEntryGuid, currentGuid);
if (IsDebuggerPresent())
DebugBreak();
}
@ -768,8 +768,10 @@ void RTech::PakProcessGuidRelationsForAsset(PakFile_t* pPak, RPakAssetEntry* pAs
// Are we some special asset with the guid 2?
if (!fnCheckAsset(true))
{
RPakAssetEntry* assetEntries = pPak->m_pAssetEntries;
uint64_t a; for (a = 0; assetEntries->m_Guid != currentGuid; a++, assetEntries++)
RPakAssetEntry_t* assetEntries = pPak->m_pAssetEntries;
uint64_t a = 0;
for (; assetEntries->m_Guid != currentGuid; a++, assetEntries++)
{
if (a >= pPak->m_PakHdr.m_nAssetEntryCount)
{

View File

@ -109,7 +109,7 @@ struct RPakAssetBinding_t
// [ PIXIE ]: Should be the full size across Season 0-3.
};
struct RPakAssetEntry
struct RPakAssetEntry_t
{
uint64_t m_Guid;
uint64_t m_Padding;
@ -232,7 +232,7 @@ public:
uint64_t m_nUnkEnd; //0x00B0/0x00E8
}; //Size: 0x00B8/0x00E8
struct RPakDescriptor
struct RPakDescriptor_t
{
uint32_t m_Index;
uint32_t m_Offset;
@ -274,11 +274,11 @@ struct __declspec(align(2)) PakFile_t
void* m_pVirtualSegments;
void* m_pMemPages;
void* m_pVirtualPointers;
RPakAssetEntry* m_pAssetEntries;
RPakDescriptor* m_pGuidDescriptors;
RPakAssetEntry_t* m_pAssetEntries;
RPakDescriptor_t* m_pGuidDescriptors;
uint32_t* m_pFileRelations;
char gap5E0[40];
RPakAssetEntry** m_ppAssetEntries;
RPakAssetEntry_t** m_ppAssetEntries;
char gap610[520];
const char* m_pszFileName;
RPakHeader_t m_PakHdr;
@ -302,7 +302,7 @@ inline auto RTech_OpenFile = p_RTech_OpenFile.RCast<int32_t(*)(const char*, void
#ifdef GAMEDLL_S3
inline CMemory p_Pak_ProcessGuidRelationsForAsset;
inline auto RTech_Pak_ProcessGuidRelationsForAsset = p_RTech_OpenFile.RCast<void(__fastcall*)(PakFile_t*, RPakAssetEntry*)>();
inline auto RTech_Pak_ProcessGuidRelationsForAsset = p_RTech_OpenFile.RCast<void(__fastcall*)(PakFile_t*, RPakAssetEntry_t*)>();
#endif
inline CMemory p_StreamDB_Init;
@ -333,7 +333,7 @@ public:
static int32_t OpenFile(const CHAR* szFilePath, void* unused, LONGLONG* fileSizeOut);
#ifdef GAMEDLL_S3
static void PakProcessGuidRelationsForAsset(PakFile_t* pak, RPakAssetEntry* asset);
static void PakProcessGuidRelationsForAsset(PakFile_t* pak, RPakAssetEntry_t* asset);
#endif
@ -399,7 +399,7 @@ class VPakFile : public IDetour
#ifdef GAMEDLL_S3
p_Pak_ProcessGuidRelationsForAsset = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\xE8\x00\x00\x00\x00\x48\x8B\x86\x00\x00\x00\x00\x42\x8B\x0C\xB0"), "x????xxx????xxxx").FollowNearCallSelf();
RTech_Pak_ProcessGuidRelationsForAsset = p_Pak_ProcessGuidRelationsForAsset.RCast<void(__fastcall*)(PakFile_t*, RPakAssetEntry*)>(); /*E8 ? ? ? ? 48 8B 86 ? ? ? ? 42 8B 0C B0*/
RTech_Pak_ProcessGuidRelationsForAsset = p_Pak_ProcessGuidRelationsForAsset.RCast<void(__fastcall*)(PakFile_t*, RPakAssetEntry_t*)>(); /*E8 ? ? ? ? 48 8B 86 ? ? ? ? 42 8B 0C B0*/
#endif
}
virtual void GetVar(void) const