forked from citizenfx/fivem
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXBRInit.cpp
More file actions
103 lines (83 loc) · 2.27 KB
/
Copy pathXBRInit.cpp
File metadata and controls
103 lines (83 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "StdInc.h"
#ifndef IS_FXSERVER
#include "CrossBuildRuntime.h"
#include <HostSharedData.h>
#include <CfxState.h>
#include <shellapi.h>
namespace xbr
{
int GetRequestedGameBuildInit()
{
constexpr const std::pair<std::wstring_view, int> buildNumbers[] = {
#define EXPAND(_, __, x) \
{ BOOST_PP_WSTRINGIZE(BOOST_PP_CAT(-b, x)), x },
BOOST_PP_SEQ_FOR_EACH(EXPAND, , GAME_BUILDS)
#undef EXPAND
};
constexpr const std::pair<const wchar_t*, int> deprecatedBuildMappings[] = {
{ L"-b3717", xbr::Build::Winter_2025 }
};
auto sharedData = CfxState::Get();
std::wstring_view cli = (sharedData->initCommandLine[0]) ? sharedData->initCommandLine : GetCommandLineW();
auto buildNumber = GetDefaultGameBuild();
int argc;
wchar_t** wargv = CommandLineToArgvW(cli.data(), &argc);
for (int i = 1; i < argc; i++)
{
if (buildNumber != GetDefaultGameBuild())
{
break;
}
std::wstring_view arg = wargv[i];
for (auto [build, number] : buildNumbers)
{
if (arg == build)
{
buildNumber = number;
break;
}
}
for (const auto& [deprecatedBuild, mappedBuild] : deprecatedBuildMappings)
{
if (arg == deprecatedBuild)
{
buildNumber = mappedBuild;
break;
}
}
}
LocalFree(wargv);
return buildNumber;
}
bool GetReplaceExecutableInit()
{
bool replaceExecutable = false;
std::wstring fpath = MakeRelativeCitPath(L"CitizenFX.ini");
if (GetFileAttributes(fpath.c_str()) != INVALID_FILE_ATTRIBUTES)
{
replaceExecutable = (GetPrivateProfileInt(L"Game", L"ReplaceExecutable", 0, fpath.c_str()) != 0);
}
return replaceExecutable;
}
int GetDefaultBuildInit()
{
std::wstring fpath = MakeRelativeCitPath(L"CitizenFX.ini");
if (GetFileAttributes(fpath.c_str()) != INVALID_FILE_ATTRIBUTES)
{
// New ini key: explicit default build persisted from sv_defaultGameBuild or legacy effectiveDefaultBuild
int defaultBuild = GetPrivateProfileInt(L"Game", L"DefaultBuild", 0, fpath.c_str());
if (defaultBuild > 0)
{
return defaultBuild;
}
// Backward compat: old ReplaceExecutable=1 means use the requested build's exe directly
bool replaceExecutable = (GetPrivateProfileInt(L"Game", L"ReplaceExecutable", 0, fpath.c_str()) != 0);
if (replaceExecutable)
{
return GetRequestedGameBuildInit();
}
}
return GetDefaultGameBuild();
}
}
#endif