diff --git a/src/public/rtech/ipakfile.h b/src/public/rtech/ipakfile.h index aedbbb72..61f6696e 100644 --- a/src/public/rtech/ipakfile.h +++ b/src/public/rtech/ipakfile.h @@ -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 diff --git a/src/rtech/pak/paktools.cpp b/src/rtech/pak/paktools.cpp index 5283597d..bdb617f6 100644 --- a/src/rtech/pak/paktools.cpp +++ b/src/rtech/pak/paktools.cpp @@ -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 //-----------------------------------------------------------------------------