Skip to content

Commit 945b74a

Browse files
committed
Check process name when getting game version
Apparently SHV's getGameVersion() does not work immediately
1 parent 07df663 commit 945b74a

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

ChaosMod/game.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#pragma once
22

3+
#include <Windows.h>
34
#include <scripthookv/inc/main.h>
45

6+
#include "Util/Logging.h"
7+
58
enum class GameVersion
69
{
710
GTA5_LEGACY,
@@ -10,8 +13,31 @@ enum class GameVersion
1013

1114
inline GameVersion GetGame()
1215
{
13-
static GameVersion result = getGameVersion() > 1000 ? GameVersion::GTA5_ENHANCED : GameVersion::GTA5_LEGACY;
14-
return result;
16+
static bool gotResultFromSHV = false;
17+
static GameVersion version;
18+
19+
static auto versionFromFilename = []() -> GameVersion
20+
{
21+
WCHAR moduleName[MAX_PATH];
22+
GetModuleFileName(NULL, moduleName, MAX_PATH);
23+
std::wstring ws(moduleName);
24+
return ws.ends_with(L"_Enhanced.exe") ? GameVersion::GTA5_ENHANCED : GameVersion::GTA5_LEGACY;
25+
}();
26+
27+
if (!gotResultFromSHV)
28+
{
29+
auto v = getGameVersion();
30+
if (v != -1)
31+
{
32+
gotResultFromSHV = true;
33+
version = v > 1000 ? GameVersion::GTA5_ENHANCED : GameVersion::GTA5_LEGACY;
34+
}
35+
else
36+
{
37+
version = versionFromFilename;
38+
}
39+
}
40+
return version;
1541
}
1642

1743
inline bool IsEnhanced()

0 commit comments

Comments
 (0)