Skip to content

Commit e883513

Browse files
committed
Take into account multi-chunk vpks
This seems to apply to ANY new addon uploaded after the 13/02/2025 update
1 parent 839c564 commit e883513

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/multiaddonmanager.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,13 @@ void *MultiAddonManager::OnMetamodQuery(const char *iface, int *ret)
264264
return &g_AddonManagerInterface;
265265
}
266266

267-
void MultiAddonManager::BuildAddonPath(const char *pszAddon, char *buf, size_t len)
267+
void MultiAddonManager::BuildAddonPath(const char *pszAddon, char *buf, size_t len, bool bLegacy = false)
268268
{
269269
// The workshop on a dedicated server is stored relative to the working directory for whatever reason
270270
static CBufferStringGrowable<MAX_PATH> s_sWorkingDir;
271271
ExecuteOnce(g_pFullFileSystem->GetSearchPath("EXECUTABLE_PATH", GET_SEARCH_PATH_ALL, s_sWorkingDir, 1));
272272

273-
V_snprintf(buf, len, "%ssteamapps/workshop/content/730/%s/%s.vpk", s_sWorkingDir.Get(), pszAddon, pszAddon);
273+
V_snprintf(buf, len, "%ssteamapps/workshop/content/730/%s/%s%s.vpk", s_sWorkingDir.Get(), pszAddon, pszAddon, bLegacy ? "" : "_dir");
274274
}
275275

276276
bool g_bAddonMountDownload = false;
@@ -296,13 +296,24 @@ bool MultiAddonManager::MountAddon(const char *pszAddon, bool bAddToTail = false
296296
DownloadAddon(pszAddon, false, true);
297297
}
298298

299-
char path[MAX_PATH];
300-
BuildAddonPath(pszAddon, path, sizeof(path));
299+
char pszPath[MAX_PATH];
300+
BuildAddonPath(pszAddon, pszPath, sizeof(pszPath));
301301

302-
if (!g_pFullFileSystem->FileExists(path))
302+
if (!g_pFullFileSystem->FileExists(pszPath))
303303
{
304-
Panic("%s: Addon %s not found at %s\n", __func__, pszAddon, path);
305-
return false;
304+
// This might be a legacy addon (before mutli-chunk was introduced), try again without the _dir
305+
BuildAddonPath(pszAddon, pszPath, sizeof(pszPath), true);
306+
307+
if (!g_pFullFileSystem->FileExists(pszPath))
308+
{
309+
Panic("%s: Addon %s not found at %s\n", __func__, pszAddon, pszPath);
310+
return false;
311+
}
312+
}
313+
else
314+
{
315+
// We still need it without _dir anyway because the filesystem will append suffixes if needed
316+
BuildAddonPath(pszAddon, pszPath, sizeof(pszPath), true);
306317
}
307318

308319
if (m_MountedAddons.Find(pszAddon) != -1)
@@ -311,9 +322,9 @@ bool MultiAddonManager::MountAddon(const char *pszAddon, bool bAddToTail = false
311322
return false;
312323
}
313324

314-
Message("Adding search path: %s\n", path);
325+
Message("Adding search path: %s\n", pszPath);
315326

316-
g_pFullFileSystem->AddSearchPath(path, "GAME", bAddToTail ? PATH_ADD_TO_TAIL : PATH_ADD_TO_HEAD, SEARCH_PATH_PRIORITY_VPK);
327+
g_pFullFileSystem->AddSearchPath(pszPath, "GAME", bAddToTail ? PATH_ADD_TO_TAIL : PATH_ADD_TO_HEAD, SEARCH_PATH_PRIORITY_VPK);
317328
m_MountedAddons.AddToTail(pszAddon);
318329

319330
return true;

src/multiaddonmanager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class MultiAddonManager : public ISmmPlugin, public IMetamodListener
8282
INetworkMessageInternal *pEvent, const CNetMessage *pData, unsigned long nSize, NetChannelBufType_t bufType);
8383
int Hook_LoadEventsFromFile(const char *filename, bool bSearchAll);
8484

85-
void BuildAddonPath(const char *pszAddon, char *buf, size_t len);
85+
void BuildAddonPath(const char *pszAddon, char *buf, size_t len, bool bLegacy);
8686
bool MountAddon(const char *pszAddon, bool bAddToTail);
8787
bool UnmountAddon(const char *pszAddon);
8888
bool AddAddon(const char *pszAddon, bool bRefresh);

0 commit comments

Comments
 (0)