Skip to content

Commit df1832f

Browse files
committed
Rework HostStateRequest logic
The addon string will always be cleared and setup cleanly, this should prevent all cases of addon pileup.
1 parent 24c4ea6 commit df1832f

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

src/multiaddonmanager.cpp

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ void MultiAddonManager::OnAddonDownloaded(DownloadItemResult_t *pResult)
441441
if (pResult->m_eResult == k_EResultOK)
442442
Message("Addon %lli downloaded successfully\n", pResult->m_nPublishedFileId);
443443
else
444-
Panic("%s: Addon %lli download failed with status %i\n", __func__, pResult->m_nPublishedFileId, pResult->m_eResult);
444+
Panic("Addon %lli download failed with status %i\n", pResult->m_nPublishedFileId, pResult->m_eResult);
445445

446446
// This download isn't triggered by us, don't do anything
447447
if (!m_DownloadQueue.Check(pResult->m_nPublishedFileId))
@@ -674,43 +674,28 @@ void* FASTCALL Hook_HostStateRequest(void *a1, void **pRequest)
674674
return g_pfnHostStateRequest(a1, pRequest);
675675

676676
// This offset hasn't changed in 6 years so it should be safe
677-
CUtlString *psNextMap = (CUtlString *)(pRequest + 5);
678677
CUtlString *psAddonString = (CUtlString *)(pRequest + 11);
679678

680-
std::string sExtraAddonString = VectorToString(g_MultiAddonManager.m_ExtraAddons);
681-
682-
static std::string sCurrentMap = psNextMap->Get();
683-
684-
// If reloading the same map after a match or from vote, the addon string is not cleared so we have to do this ourselves...
685-
// Also if this happens to be a different workshop item but with the same map name then the string will be cleared anyway
686-
if (psNextMap->IsEqual_CaseSensitive(sCurrentMap.c_str()))
687-
{
688-
std::string sCurrentWorkshopMap = g_MultiAddonManager.GetCurrentWorkshopMap();
679+
CUtlVector<std::string> vecAddons;
680+
StringToVector(psAddonString->Get(), vecAddons);
689681

690-
if (sCurrentWorkshopMap.empty())
691-
psAddonString->Clear();
692-
else
693-
psAddonString->Set(sCurrentWorkshopMap.c_str());
694-
}
695-
else
696-
{
697-
sCurrentMap = psNextMap->Get();
698-
}
682+
// Clear the string just in case it wasn't somehow, like when reloading the map
683+
psAddonString->Clear();
699684

700-
Message("%s: appending \"%s\" to addon string \"%s\"\n", __func__, sExtraAddonString.c_str(), psAddonString->Get());
685+
std::string sExtraAddonString = VectorToString(g_MultiAddonManager.m_ExtraAddons);
701686

702-
// Addons are simply comma-delimited, can have any number of them
703-
// The original addon string is the current workshop map
704-
// If it's empty, it means we're on a default map
705-
if (!psAddonString->IsEmpty())
687+
// If it's empty or the first addon in the string is ours, it means we're on a default map
688+
if (vecAddons.Count() == 0 || g_MultiAddonManager.m_ExtraAddons.HasElement(vecAddons[0]))
706689
{
707-
g_MultiAddonManager.SetCurrentWorkshopMap(psAddonString->Get());
708-
psAddonString->Format("%s,%s", psAddonString->Get(), sExtraAddonString.c_str());
690+
Message("%s: setting addon string to \"%s\"\n", __func__, sExtraAddonString.c_str());
691+
psAddonString->Set(sExtraAddonString.c_str());
692+
g_MultiAddonManager.ClearCurrentWorkshopMap();
709693
}
710694
else
711695
{
712-
g_MultiAddonManager.ClearCurrentWorkshopMap();
713-
psAddonString->Set(sExtraAddonString.c_str());
696+
Message("%s: appending \"%s\" to addon string \"%s\"\n", __func__, sExtraAddonString.c_str(), vecAddons[0].c_str());
697+
psAddonString->Format("%s,%s", vecAddons[0].c_str(), sExtraAddonString.c_str());
698+
g_MultiAddonManager.SetCurrentWorkshopMap(vecAddons[0].c_str());
714699
}
715700

716701
return g_pfnHostStateRequest(a1, pRequest);

0 commit comments

Comments
 (0)