Light cleanup of pak load api var names

* Rename some pakload api vars.
* Removed 2 duplicate pointers from (g_ClientState_Shifted and g_pakLoadJobID).
* Removed unnecessary signonstate check in 'Mod_ProcessPakQueue' for dedicated.
This commit is contained in:
Kawe Mazidjatari 2023-01-31 16:09:30 +01:00
parent 8b6e22473e
commit c17913bfe9
6 changed files with 55 additions and 46 deletions

View File

@ -16,6 +16,9 @@
#include "vpc/keyvalues.h"
#include "datacache/mdlcache.h"
#include "filesystem/filesystem.h"
#ifndef DEDICATED
#include "client/clientstate.h"
#endif // !DEDICATED
vector<string> g_vAllMaps;
string s_svLevelName;
@ -158,7 +161,13 @@ void Mod_ProcessPakQueue()
__int64 v25{}; // rcx
v0 = 0;
if (*(float*)&*dword_14B383420 == 1.0 && *qword_167ED7BB8 && *((int*)&*qword_14180A098/* + 36*/) < 2)
#ifndef DEDICATED
bool bUnconnected = !(*g_pClientState_Shifted)->IsConnected();
#else // !DEDICATED
bool bUnconnected = false; // Always false for dedicated.
#endif
if (*(float*)&*dword_14B383420 == 1.0 && *qword_167ED7BB8 && bUnconnected)
{
*byte_16709DDDF = 0;
v0 = 1;
@ -292,7 +301,7 @@ void Mod_ProcessPakQueue()
{
if (!*(_BYTE*)(*g_pMTVFTaskItem + 4))
{
if (*qword_167ED7BC0 || WORD2(*qword_167ED7C68) != HIWORD(*qword_167ED7C68))
if (*qword_167ED7BC0 || WORD2(*g_pPakLoadJobID) != HIWORD(*g_pPakLoadJobID))
{
if (!JT_AcquireFifoLock(&*g_pPakFifoLock)
&& !(unsigned __int8)sub_14045BAC0((__int64(__fastcall*)(__int64, _DWORD*, __int64, _QWORD*))g_pPakFifoLockWrapper, &*g_pPakFifoLock, -1i64, 0i64))

View File

@ -15,14 +15,12 @@ inline auto v_Mod_ProcessPakQueue = p_Mod_ProcessPakQueue.RCast<void(*)(void)>()
inline float* dword_14B383420;
inline int32_t * dword_1634F445C;
inline void** qword_167ED7BB8;
inline void** qword_14180A098;
inline bool* byte_16709DDDF;
inline char** off_141874660;
inline void** unk_141874555;
inline void** unk_1418749B0;
inline void** unk_141874550;
inline int64_t* qword_167ED7BC0;
inline int64_t* qword_167ED7C68;
inline auto sub_14045BAC0 = p_Mod_ProcessPakQueue.RCast<__int64(*)(__int64(__fastcall* a1)(__int64, _DWORD*, __int64, _QWORD*), JobFifoLock_s* pFifoLock, __int64 a3, __int64 a4)>();
inline auto sub_14045A1D0 = p_Mod_ProcessPakQueue.RCast<__int64(*)(unsigned __int8(__fastcall* a1)(_QWORD), JobFifoLock_s* pFifoLock, __int64 a3, __int64 a4, volatile signed __int64* a5, char a6)>();
@ -51,14 +49,12 @@ class VModel_BSP : public IDetour
LogVarAdr("dword_14B383420", reinterpret_cast<uintptr_t>(dword_14B383420));
LogVarAdr("dword_1634F445C", reinterpret_cast<uintptr_t>(dword_1634F445C));
LogVarAdr("qword_167ED7BB8", reinterpret_cast<uintptr_t>(qword_167ED7BB8));
LogVarAdr("qword_14180A098", reinterpret_cast<uintptr_t>(qword_14180A098));
LogVarAdr("byte_16709DDDF", reinterpret_cast<uintptr_t>(byte_16709DDDF));
LogVarAdr("off_141874660", reinterpret_cast<uintptr_t>(off_141874660));
LogVarAdr("unk_141874555", reinterpret_cast<uintptr_t>(unk_141874555));
LogVarAdr("unk_1418749B0", reinterpret_cast<uintptr_t>(unk_1418749B0));
LogVarAdr("unk_141874550", reinterpret_cast<uintptr_t>(unk_141874550));
LogVarAdr("qword_167ED7BC0", reinterpret_cast<uintptr_t>(qword_167ED7BC0));
LogVarAdr("qword_167ED7C68", reinterpret_cast<uintptr_t>(qword_167ED7C68));
}
virtual void GetFun(void) const
{
@ -85,16 +81,12 @@ class VModel_BSP : public IDetour
dword_14B383420 = p_Mod_ProcessPakQueue.FindPattern("F3 0F 10").ResolveRelativeAddressSelf(0x4, 0x8).RCast<float*>();
dword_1634F445C = p_Mod_ProcessPakQueue.FindPattern("8B 05").ResolveRelativeAddressSelf(0x2, 0x6).RCast<int32_t*>();
qword_167ED7BB8 = p_Mod_ProcessPakQueue.Offset(0x10).FindPatternSelf("48 83").ResolveRelativeAddressSelf(0x3, 0x8).RCast<void**>();
qword_14180A098 = p_Mod_ProcessPakQueue.Offset(0x20).FindPatternSelf("83 3D").ResolveRelativeAddressSelf(0x2, 0x7).RCast<void**>();
byte_16709DDDF = p_Mod_ProcessPakQueue.Offset(0x20).FindPatternSelf("88 1D").ResolveRelativeAddressSelf(0x2, 0x6).RCast<bool*>();
off_141874660 = p_Mod_ProcessPakQueue.Offset(0x40).FindPatternSelf("4C 8D 15").ResolveRelativeAddressSelf(0x3, 0x7).RCast<char**>();
unk_141874555 = p_Mod_ProcessPakQueue.Offset(0x40).FindPatternSelf("4C 8D 1D").ResolveRelativeAddressSelf(0x3, 0x7).RCast<void**>();
unk_1418749B0 = p_Mod_ProcessPakQueue.Offset(0xA0).FindPatternSelf("48 8D 1D").ResolveRelativeAddressSelf(0x3, 0x7).RCast<void**>();
unk_141874550 = p_Mod_ProcessPakQueue.Offset(0x150).FindPatternSelf("48 8D 2D").ResolveRelativeAddressSelf(0x3, 0x7).RCast<void**>();
qword_167ED7BC0 = p_Mod_ProcessPakQueue.Offset(0x200).FindPatternSelf("48 83 3D").ResolveRelativeAddressSelf(0x3, 0x8).RCast<int64_t*>();
qword_167ED7C68 = p_Mod_ProcessPakQueue.Offset(0x200).FindPatternSelf("0F B7 05").ResolveRelativeAddressSelf(0x3, 0x7).RCast<int64_t*>();
(*((char**)(&qword_167ED7C68))) -= 6;
}
virtual void GetCon(void) const { }
virtual void Attach(void) const;

View File

@ -650,15 +650,15 @@ int32_t RTech::OpenFile(const CHAR* szFilePath, void* unused, LONGLONG* fileSize
*fileSizeOut = fileSize.QuadPart;
}
AcquireSRWLockExclusive(reinterpret_cast<PSRWLOCK>(&*g_pPakFileSlotLock));
AcquireSRWLockExclusive(reinterpret_cast<PSRWLOCK>(&*s_pFileArrayMutex));
const int32_t fileIdx = RTech_FindFreeSlotInFiles(s_pFileArray);
ReleaseSRWLockExclusive(reinterpret_cast<PSRWLOCK>(&*g_pPakFileSlotLock));
ReleaseSRWLockExclusive(reinterpret_cast<PSRWLOCK>(&*s_pFileArrayMutex));
const int32_t fileHandleIdx = (fileIdx & 0x3FF); // Something with ArraySize.
m_FileHandles->self[fileHandleIdx].m_nFileNumber = fileIdx;
m_FileHandles->self[fileHandleIdx].m_hFileHandle = hFile;
m_FileHandles->self[fileHandleIdx].m_nCurOfs = 1;
s_pFileHandles->self[fileHandleIdx].m_nFileNumber = fileIdx;
s_pFileHandles->self[fileHandleIdx].m_hFileHandle = hFile;
s_pFileHandles->self[fileHandleIdx].m_nCurOfs = 1;
return fileIdx;
}
@ -668,7 +668,7 @@ int32_t RTech::OpenFile(const CHAR* szFilePath, void* unused, LONGLONG* fileSize
//-----------------------------------------------------------------------------
RPakLoadedInfo_t* RTech::GetPakLoadedInfo(RPakHandle_t nHandle)
{
for (int16_t i = 0; i < *s_pLoadedPakCount; ++i)
for (int16_t i = 0; i < *g_pLoadedPakCount; ++i)
{
RPakLoadedInfo_t* info = &g_pLoadedPakInfo[i];
if (!info)
@ -689,7 +689,7 @@ RPakLoadedInfo_t* RTech::GetPakLoadedInfo(RPakHandle_t nHandle)
//-----------------------------------------------------------------------------
RPakLoadedInfo_t* RTech::GetPakLoadedInfo(const char* szPakName)
{
for (int16_t i = 0; i < *s_pLoadedPakCount; ++i)
for (int16_t i = 0; i < *g_pLoadedPakCount; ++i)
{
RPakLoadedInfo_t* info = &g_pLoadedPakInfo[i];
if (!info)
@ -715,7 +715,7 @@ RPakLoadedInfo_t* RTech::GetPakLoadedInfo(const char* szPakName)
void RTech::PakProcessGuidRelationsForAsset(PakFile_t* pPak, RPakAssetEntry_t* pAsset)
{
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));
volatile uint32_t* v5 = reinterpret_cast<volatile uint32_t*>(*(reinterpret_cast<uint64_t*>(g_pPakGlobals) + 0x17 * (pPak->qword578 & 0x1FF) + 0x160212));
const bool bDebug = rtech_debug->GetBool();
if (bDebug)
@ -730,7 +730,7 @@ void RTech::PakProcessGuidRelationsForAsset(PakFile_t* pPak, RPakAssetEntry_t* p
// Get asset index.
int assetIdx = currentGuid & 0x3FFFF;
uint64_t assetIdxEntryGuid = g_pUnknownPakStruct->m_Assets[assetIdx].m_Guid;
uint64_t assetIdxEntryGuid = g_pPakGlobals->m_Assets[assetIdx].m_Guid;
const int64_t v9 = 2i64 * InterlockedExchangeAdd(v5, 1u);
*reinterpret_cast<uint64_t*>(const_cast<uint32_t*>(&v5[2 * v9 + 2])) = currentGuid;
@ -757,7 +757,7 @@ void RTech::PakProcessGuidRelationsForAsset(PakFile_t* pPak, RPakAssetEntry_t* p
}
assetIdx &= 0x3FFFF;
assetIdxEntryGuid = g_pUnknownPakStruct->m_Assets[assetIdx].m_Guid;
assetIdxEntryGuid = g_pPakGlobals->m_Assets[assetIdx].m_Guid;
if (assetIdxEntryGuid == currentGuid)
return true;
@ -786,7 +786,7 @@ void RTech::PakProcessGuidRelationsForAsset(PakFile_t* pPak, RPakAssetEntry_t* p
}
// Finally write the pointer to the guid entry.
*pCurrentGuid = g_pUnknownPakStruct->m_Assets[assetIdx].m_pHead;
*pCurrentGuid = g_pPakGlobals->m_Assets[assetIdx].m_pHead;
}
}

View File

@ -138,7 +138,7 @@ struct RPakAssetEntryShort
void* m_pCpu;
};
struct RPakUnknownStruct_t
struct RPakGlobals_t
{
RPakAssetBinding_t m_nAssetBindings[64]; // [ PIXIE ]: Max possible registered assets on Season 3, 0-2 I did not check yet.
RPakAssetEntryShort m_Assets[0x40000];
@ -332,13 +332,14 @@ inline CMemory p_StreamDB_Init;
inline auto v_StreamDB_Init = p_StreamDB_Init.RCast<void (*)(const char* pszLevelName)>();
inline RPakLoadedInfo_t* g_pLoadedPakInfo;
inline int16_t* s_pLoadedPakCount;
inline int16_t* s_pParsedPakCount;
inline RPakUnknownStruct_t* g_pUnknownPakStruct;
inline int16_t* g_pRequestedPakCount;
inline int16_t* g_pLoadedPakCount;
inline JobID_t* g_pPakLoadJobID;
inline RPakGlobals_t* g_pPakGlobals;
inline int32_t* s_pFileArray;
inline PSRWLOCK* g_pPakFileSlotLock;
inline pFileHandleTracker_t* m_FileHandles;
inline PSRWLOCK* s_pFileArrayMutex;
inline pFileHandleTracker_t* s_pFileHandles;
inline JobFifoLock_s* g_pPakFifoLock;
inline void* g_pPakFifoLockWrapper; // Pointer to functor that takes the global pak fifolock as argument.
@ -383,16 +384,20 @@ class V_RTechUtils : public IDetour
LogFunAdr("GetStreamOverlay", p_GetStreamOverlay.GetPtr());
#endif // !DEDICATED
LogFunAdr("StreamDB_Init", p_StreamDB_Init.GetPtr());
LogVarAdr("g_pLoadedPakInfo", reinterpret_cast<uintptr_t>(g_pLoadedPakInfo));
LogVarAdr("s_pLoadedPakCount", reinterpret_cast<uintptr_t>(s_pLoadedPakCount));
LogVarAdr("s_pParsedPakCount", reinterpret_cast<uintptr_t>(s_pParsedPakCount));
LogVarAdr("s_pFileArray", reinterpret_cast<uintptr_t>(s_pFileArray));
LogVarAdr("g_pPakFileSlotLock", reinterpret_cast<uintptr_t>(g_pPakFileSlotLock));
LogVarAdr("m_FileHandles", reinterpret_cast<uintptr_t>(m_FileHandles));
LogVarAdr("g_pUnknownPakStruct", reinterpret_cast<uintptr_t>(g_pUnknownPakStruct));
LogVarAdr("g_pPakFifoLock", reinterpret_cast<uintptr_t>(g_pPakFifoLock));
LogVarAdr("g_pPakFifoLockWrapper", reinterpret_cast<uintptr_t>(g_pPakFifoLockWrapper));
LogVarAdr("g_bPakFifoLockAcquired", reinterpret_cast<uintptr_t>(g_bPakFifoLockAcquired));
LogVarAdr("s_FileArray", reinterpret_cast<uintptr_t>(s_pFileArray));
LogVarAdr("s_FileArrayMutex", reinterpret_cast<uintptr_t>(s_pFileArrayMutex));
LogVarAdr("s_FileHandles", reinterpret_cast<uintptr_t>(s_pFileHandles));
LogVarAdr("g_loadedPakInfo", reinterpret_cast<uintptr_t>(g_pLoadedPakInfo));
LogVarAdr("g_loadedPakCount", reinterpret_cast<uintptr_t>(g_pLoadedPakCount));
LogVarAdr("g_requestedPakCount", reinterpret_cast<uintptr_t>(g_pRequestedPakCount));
LogVarAdr("g_pakGlobals", reinterpret_cast<uintptr_t>(g_pPakGlobals));
LogVarAdr("g_pakLoadJobID", reinterpret_cast<uintptr_t>(g_pPakLoadJobID));
LogVarAdr("g_pakFifoLock", reinterpret_cast<uintptr_t>(g_pPakFifoLock));
LogVarAdr("g_pakFifoLockWrapper", reinterpret_cast<uintptr_t>(g_pPakFifoLockWrapper));
LogVarAdr("g_pakFifoLockAcquired", reinterpret_cast<uintptr_t>(g_bPakFifoLockAcquired));
}
virtual void GetFun(void) const
{
@ -426,15 +431,16 @@ class V_RTechUtils : public IDetour
}
virtual void GetVar(void) const
{
g_pLoadedPakInfo = p_CPakFile_UnloadPak.FindPattern("48 8D 05", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast<RPakLoadedInfo_t*>();
s_pLoadedPakCount = p_CPakFile_UnloadPak.FindPattern("66 89", CMemory::Direction::DOWN, 450).ResolveRelativeAddressSelf(0x3, 0x7).RCast<int16_t*>();
s_pParsedPakCount = &*s_pLoadedPakCount - 1; // '-1' shifts it back with sizeof(int16_t).
g_pPakFileSlotLock = p_StreamDB_Init.Offset(0x70).FindPatternSelf("48 8D 0D", CMemory::Direction::DOWN, 512, 1).ResolveRelativeAddress(0x3, 0x7).RCast<PSRWLOCK*>();
s_pFileArray = p_StreamDB_Init.Offset(0x70).FindPatternSelf("48 8D 0D", CMemory::Direction::DOWN, 512, 2).ResolveRelativeAddress(0x3, 0x7).RCast<int32_t*>();
m_FileHandles = p_StreamDB_Init.Offset(0x70).FindPatternSelf("4C 8D", CMemory::Direction::DOWN, 512, 1).ResolveRelativeAddress(0x3, 0x7).RCast<pFileHandleTracker_t*>();
s_pFileHandles = p_StreamDB_Init.Offset(0x70).FindPatternSelf("4C 8D", CMemory::Direction::DOWN, 512, 1).ResolveRelativeAddress(0x3, 0x7).RCast<pFileHandleTracker_t*>();
s_pFileArrayMutex = p_StreamDB_Init.Offset(0x70).FindPatternSelf("48 8D 0D", CMemory::Direction::DOWN, 512, 1).ResolveRelativeAddress(0x3, 0x7).RCast<PSRWLOCK*>();
g_pUnknownPakStruct = g_GameDll.FindPatternSIMD("48 8D 1D ?? ?? ?? ?? 45 8D 5A 0E").ResolveRelativeAddressSelf(0x3, 0x7).RCast<RPakUnknownStruct_t*>(); /*48 8D 1D ? ? ? ? 45 8D 5A 0E*/
g_pLoadedPakInfo = p_CPakFile_UnloadPak.FindPattern("48 8D 05", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast<RPakLoadedInfo_t*>();
g_pRequestedPakCount = p_CPakFile_UnloadPak.FindPattern("66 89", CMemory::Direction::DOWN, 450).ResolveRelativeAddressSelf(0x3, 0x7).RCast<int16_t*>();
g_pLoadedPakCount = &*g_pRequestedPakCount - 1; // '-1' shifts it back with sizeof(int16_t).
g_pPakGlobals = g_GameDll.FindPatternSIMD("48 8D 1D ?? ?? ?? ?? 45 8D 5A 0E").ResolveRelativeAddressSelf(0x3, 0x7).RCast<RPakGlobals_t*>(); /*48 8D 1D ? ? ? ? 45 8D 5A 0E*/
g_pPakLoadJobID = reinterpret_cast<JobID_t*>(&*g_pLoadedPakCount - 2);
g_pPakFifoLock = p_JT_HelpWithAnything.Offset(0x155).FindPatternSelf("48 8D 0D").ResolveRelativeAddressSelf(0x3, 0x7).RCast<JobFifoLock_s*>();
g_pPakFifoLockWrapper = p_JT_HelpWithAnything.Offset(0x1BC).FindPatternSelf("48 8D 0D").ResolveRelativeAddressSelf(0x3, 0x7).RCast<void*>();

View File

@ -5,6 +5,8 @@ struct JobFifoLock_s
{
};
typedef uint32_t JobID_t;
inline CMemory p_JT_ParallelCall;
inline auto JT_ParallelCall = p_JT_ParallelCall.RCast<void (*)(void)>();

View File

@ -258,7 +258,7 @@ void Pak_ListPaks_f(const CCommand& args)
uint32_t nTotalLoaded = 0;
for (int16_t i = 0; i < *s_pLoadedPakCount; ++i)
for (int16_t i = 0; i < *g_pLoadedPakCount; ++i)
{
const RPakLoadedInfo_t& info = g_pLoadedPakInfo[i];
@ -294,7 +294,7 @@ void Pak_ListTypes_f(const CCommand& args)
for (int8_t i = 0; i < 64; ++i)
{
RPakAssetBinding_t* type = &g_pUnknownPakStruct->m_nAssetBindings[i];
RPakAssetBinding_t* type = &g_pPakGlobals->m_nAssetBindings[i];
if (!type->m_szDescription)
continue;