RTech: add GUID helper functions to fix a defect

Several instances of Pak_GetValidAssetGUID() in the engine are calling the hashing algorithm twice; once to get the guid, once to return the guid. The rewrite eliminates the bug by returning the cached guid. This is still pending a hook to effectively replace the defective function(s).
This commit is contained in:
Kawe Mazidjatari 2024-06-05 17:58:08 +02:00
parent 328d88213c
commit 77521b61c6
2 changed files with 45 additions and 0 deletions

View File

@ -89,6 +89,9 @@
// the handle that should be returned when a pak failed to load or process
#define PAK_INVALID_HANDLE -1
// the guid that should be returned for assets that do not exist in the runtime
#define PAK_INVALID_GUID 0
#define PAK_MAX_DISPATCH_LOAD_JOBS 4
#define PAK_DEFAULT_JOB_GROUP_ID 0x3000

View File

@ -282,6 +282,48 @@ const PakLoadedInfo_s* Pak_GetPakInfo(const char* const pakName)
return nullptr;
}
//-----------------------------------------------------------------------------
// returns a pointer to the asset data by GUID, returns NULL if not found in
// the runtime
//-----------------------------------------------------------------------------
void* Pak_FindAssetByGUID(const PakGuid_t guid)
{
int assetIndex = guid & PAK_MAX_LOADED_ASSETS_MASK;
const PakAssetShort_s* asset = &g_pakGlobals->loadedAssets[assetIndex];
PakGuid_t assetGuid = asset->guid;
if (assetGuid == guid)
return asset->head;
while (assetGuid)
{
assetIndex = (assetIndex +1) & PAK_MAX_LOADED_ASSETS_MASK;
asset = &g_pakGlobals->loadedAssets[assetIndex];
assetGuid = asset->guid;
if (assetGuid == guid)
return asset->head;
}
return nullptr;
}
//-----------------------------------------------------------------------------
// returns the guid of the asset if it exists in the runtime, returns
// PAK_INVALID_GUID if not found in the runtime
//-----------------------------------------------------------------------------
PakGuid_t Pak_GetValidAssetGUID(const char* const name)
{
const PakGuid_t guid = Pak_StringToGuid(name);
if (guid && Pak_FindAssetByGUID(guid))
return guid;
return PAK_INVALID_GUID;
}
//-----------------------------------------------------------------------------
// returns a pointer to the patch data header
//-----------------------------------------------------------------------------