Fix gamedata library search order in some cases. (#1914)

This commit is contained in:
Nicholas Hastings 2023-01-29 15:24:34 -05:00 committed by GitHub
parent d57d7e7401
commit 30a2160839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 18 deletions

View File

@ -1083,15 +1083,7 @@ bool CGameConfig::GetMemSig(const char *key, void **addr)
return m_Sigs.retrieve(key, addr); return m_Sigs.retrieve(key, addr);
} }
GameConfigManager::GameConfigManager() void GameBinPathManager::Init()
{
}
GameConfigManager::~GameConfigManager()
{
}
void GameConfigManager::OnSourceModStartup(bool late)
{ {
char search_path[PLATFORM_MAX_PATH * 8]; char search_path[PLATFORM_MAX_PATH * 8];
bridge->filesystem->GetSearchPath("GAMEBIN", false, search_path, sizeof(search_path)); bridge->filesystem->GetSearchPath("GAMEBIN", false, search_path, sizeof(search_path));
@ -1104,19 +1096,41 @@ void GameConfigManager::OnSourceModStartup(bool late)
{ {
if (path.length() > 0 if (path.length() > 0
&& path.find(addons_folder) == std::string::npos && path.find(addons_folder) == std::string::npos
&& m_gameBinDirectories.find(path.c_str()) == m_gameBinDirectories.cend() && m_lookup.find(path) == m_lookup.cend()
) )
m_gameBinDirectories.insert(path); {
m_lookup.insert(path);
m_ordered.push_back(path);
}
} }
iss.clear();
bridge->filesystem->GetSearchPath("EXECUTABLE_PATH", false, search_path, sizeof(search_path)); bridge->filesystem->GetSearchPath("EXECUTABLE_PATH", false, search_path, sizeof(search_path));
std::istringstream iss2(search_path); iss.str(search_path);
for (std::string path; std::getline(iss2, path, ';');)
for (std::string path; std::getline(iss, path, ';');)
{ {
if (m_gameBinDirectories.find(path.c_str()) == m_gameBinDirectories.cend()) if (m_lookup.find(path) == m_lookup.cend())
m_gameBinDirectories.insert(path); {
m_lookup.insert(path);
m_ordered.push_back(path);
}
} }
}
GameConfigManager::GameConfigManager()
{
}
GameConfigManager::~GameConfigManager()
{
}
void GameConfigManager::OnSourceModStartup(bool late)
{
m_gameBinPathManager.Init();
LoadGameConfigFile("core.games", &g_pGameConf, NULL, 0); LoadGameConfigFile("core.games", &g_pGameConf, NULL, 0);
strncopy(g_Game, g_pSM->GetGameFolderName(), sizeof(g_Game)); strncopy(g_Game, g_pSM->GetGameFolderName(), sizeof(g_Game));
@ -1249,7 +1263,7 @@ void GameConfigManager::CacheGameBinaryInfo(const char* pszName)
bool binary_found = false; bool binary_found = false;
char binary_path[PLATFORM_MAX_PATH]; char binary_path[PLATFORM_MAX_PATH];
for (auto it = m_gameBinDirectories.begin(); it != m_gameBinDirectories.end(); ++it) for (auto it = m_gameBinPathManager.Paths().begin(); it != m_gameBinPathManager.Paths().end(); ++it)
{ {
ke::SafeSprintf(binary_path, sizeof(binary_path), "%s%s%s", it->c_str(), it->back() == PLATFORM_SEP_CHAR ? "" : PLATFORM_SEP, name); ke::SafeSprintf(binary_path, sizeof(binary_path), "%s%s%s", it->c_str(), it->back() == PLATFORM_SEP_CHAR ? "" : PLATFORM_SEP, name);
#if defined PLATFORM_WINDOWS #if defined PLATFORM_WINDOWS

View File

@ -38,7 +38,7 @@
#include <am-refcounting.h> #include <am-refcounting.h>
#include <sm_stringhashmap.h> #include <sm_stringhashmap.h>
#include <sm_namehashset.h> #include <sm_namehashset.h>
#include <set> #include <unordered_set>
using namespace SourceMod; using namespace SourceMod;
@ -136,6 +136,23 @@ struct GameBinaryInfo
bool m_crcOK = false; bool m_crcOK = false;
}; };
class GameBinPathManager
{
public:
GameBinPathManager() {}
~GameBinPathManager() {}
public:
void Init();
inline const std::vector<std::string>& Paths() const
{
return m_ordered;
}
private:
std::unordered_set<std::string> m_lookup;
std::vector<std::string> m_ordered;
};
class GameConfigManager : class GameConfigManager :
public IGameConfigManager, public IGameConfigManager,
public SMGlobalClass public SMGlobalClass
@ -165,9 +182,9 @@ private:
private: private:
NameHashSet<CGameConfig *> m_Lookup; NameHashSet<CGameConfig *> m_Lookup;
StringHashMap<GameBinaryInfo> m_gameBinInfos; StringHashMap<GameBinaryInfo> m_gameBinInfos;
std::set<std::string> m_gameBinDirectories;
public: public:
StringHashMap<ITextListener_SMC *> m_customHandlers; StringHashMap<ITextListener_SMC *> m_customHandlers;
GameBinPathManager m_gameBinPathManager;
}; };
extern GameConfigManager g_GameConfigs; extern GameConfigManager g_GameConfigs;