From 291a99e3ae8e5baa84bdde0312f9d7a7a6909623 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 22 Jan 2025 13:57:44 +0100 Subject: [PATCH] RTech: return the most recently loaded pak in Pak_GetPakInfo Make sure to always return the most recently loaded pak instead of the first hit with provided name. The pak system supports live asset hot swapping so we need to take this into account here. --- src/rtech/pak/paktools.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/rtech/pak/paktools.cpp b/src/rtech/pak/paktools.cpp index 5706e585..8c70f996 100644 --- a/src/rtech/pak/paktools.cpp +++ b/src/rtech/pak/paktools.cpp @@ -263,7 +263,14 @@ PakLoadedInfo_s* Pak_GetPakInfo(const PakHandle_t pakId) //----------------------------------------------------------------------------- const PakLoadedInfo_s* Pak_GetPakInfo(const char* const pakName) { - for (int16_t i = 0; i < PAK_MAX_LOADED_PAKS; ++i) + // a pak under the same name can be loaded more than once, the hotswap + // system just switches the asset pointers to the new 'live' pak if + // there are assets that overlap the ones in the previous pak. we want + // to find the most recently loaded pak under the provided name and + // return that to the caller. the higher the handle, the newer it is. + PakHandle_t highestHandle = PAK_INVALID_HANDLE; + + for (uint16_t i = 0; i < PAK_MAX_LOADED_PAKS; ++i) { const PakLoadedInfo_s* const info = &g_pakGlobals->loadedPaks[i]; if (!info) @@ -275,11 +282,17 @@ const PakLoadedInfo_s* Pak_GetPakInfo(const char* const pakName) if (strcmp(pakName, info->fileName) != 0) continue; - return info; + if (info->handle > highestHandle) + highestHandle = info->handle; } - DevWarning(eDLL_T::RTECH, "%s - Failed to retrieve pak info for name '%s'\n", __FUNCTION__, pakName); - return nullptr; + if (highestHandle == PAK_INVALID_HANDLE) + { + DevWarning(eDLL_T::RTECH, "%s - Failed to retrieve pak info for name '%s'\n", __FUNCTION__, pakName); + return nullptr; + } + + return Pak_GetPakInfo(highestHandle); } //-----------------------------------------------------------------------------