1
0
mirror of https://github.com/alliedmodders/metamod-source.git synced 2025-03-28 14:50:19 +01:00

Fix gamedir detection on Deadlock

This commit is contained in:
Nicholas Hastings 2025-02-17 15:17:50 -05:00
parent 4bc5a3a0b7
commit 376e0ed259

@ -30,6 +30,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <cstdint> #include <cstdint>
#include <cstdlib>
#include "loader.h" #include "loader.h"
#include "serverplugin.h" #include "serverplugin.h"
#include "gamedll.h" #include "gamedll.h"
@ -214,46 +215,26 @@ mm_GetGameName(char *buffer, size_t size)
{ {
if (!mm_GetCommandArgument("-game", buffer, size)) if (!mm_GetCommandArgument("-game", buffer, size))
{ {
char tier0_path[PLATFORM_MAX_PATH]; // Source 2 doesn't ever use -game, so we'll hardcode by app id for now. This same approach
#ifdef _WIN32 // won't work for the few Source 1 games that don't require -game, as S1 initializes Steam
if (mm_ResolvePath("tier0.dll", tier0_path, sizeof(tier0_path), false)) // too late (although the env var still still be already set if their is a running Steam client
#elif defined __linux__ // installed). We previously called GetGameInfoString exported from tier0 to look up the first Mod
if (mm_ResolvePath("libtier0.so", tier0_path, sizeof(tier0_path), false)) // dir defined. While that worked for CS2 and Dota 2, Deadlock does not define any Mod paths, solely
#elif defined __APPLE__ // relying on Game paths. The function only returns the first path defined, and in the case of S2, where
if (mm_ResolvePath("libtier0.dylib", tier0_path, sizeof(tier0_path), false)) // we can't even set MM:S path with GameBin instead of Game, the first Game path will always be MM:S's
#else // location, rather than the real Game dir
#error unsupported platform char *pszAppId = std::getenv("SteamAppId");
#endif switch (strtoul(pszAppId, nullptr, 10))
{ {
char err[1024]; case 570ul:
void* pTier0 = mm_LoadLibrary(tier0_path, err, sizeof(err)); strncpy(buffer, "dota", size);
if (pTier0) break;
{ case 730ul:
#ifdef _WIN32 strncpy(buffer, "csgo", size);
GetGameInfoStringFn func = (GetGameInfoStringFn)mm_GetLibAddress(pTier0, "?GetGameInfoString@@YAPEBDPEBD0PEAD_K@Z"); break;
#else case 1422450ul:
GetGameInfoStringFn func = (GetGameInfoStringFn)mm_GetLibAddress(pTier0, "_Z17GetGameInfoStringPKcS0_Pcm"); strncpy(buffer, "citadel", size);
#endif break;
if (func != nullptr)
{
static char szTmp[260];
strncpy(buffer, func("FileSystem/SearchPaths/Mod", "", szTmp, sizeof(szTmp)), size);
}
else
{
mm_LogFatal("Failed to resolve GetGameInfoString in fallback gamedir lookup.");
}
mm_UnloadLibrary(pTier0);
}
else
{
mm_LogFatal("Failed to load tier0 from \"%s\" in fallback gamedir lookup: %s", tier0_path, err);
}
}
else
{
mm_LogFatal("Failed to resolve tier0 path in fallback gamedir lookup.");
} }
} }