Skip to content

Commit 2002bb8

Browse files
committed
Move IsGfxVSyncEnabled to SDK::Options
1 parent 76eab58 commit 2002bb8

File tree

6 files changed

+52
-31
lines changed

6 files changed

+52
-31
lines changed

LatiteRewrite.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@
873873
</ClCompile>
874874
<ClCompile Include="src\sdk\common\client\game\ClientInstance.cpp" />
875875
<ClCompile Include="src\sdk\common\client\game\MinecraftGame.cpp" />
876+
<ClCompile Include="src\sdk\common\client\game\Options.cpp" />
876877
<ClCompile Include="src\sdk\common\client\gui\controls\UIControl.cpp" />
877878
<ClCompile Include="src\sdk\common\client\gui\screens\ContainerScreenController.cpp" />
878879
<ClCompile Include="src\sdk\common\client\input\RemappingLayout.cpp" />

LatiteRewrite.vcxproj.filters

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
<ClCompile Include="src\client\script\objects\OSScriptingObject.cpp" />
164164
<ClCompile Include="src\client\feature\module\impl\game\AutoGG.cpp" />
165165
<ClCompile Include="src\client\feature\module\impl\hud\FrameTimeDisplay.cpp" />
166+
<ClCompile Include="src\sdk\common\client\game\Options.cpp" />
166167
</ItemGroup>
167168
<ItemGroup>
168169
<ClInclude Include="assets\lang\en_US.json" />

src/client/hook/impl/DXHooks.cpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "DXHooks.h"
33
#include "client/Latite.h"
44
#include "client/render/Renderer.h"
5+
#include "sdk/common/client/game/Options.h"
56

67
namespace {
78
typedef HRESULT(WINAPI* CreateSwapChainForCoreWindow_t)(
@@ -18,35 +19,6 @@ namespace {
1819
std::shared_ptr<Hook> ExecuteCommandListsHook;
1920
}
2021

21-
// doing file read operations in DXHooks is a little silly but im too tired to find a better way
22-
bool DXHooks::IsGfxVSyncEnabled() {
23-
wchar_t userProfile[MAX_PATH];
24-
DWORD pathLen = GetEnvironmentVariableW(L"USERPROFILE", userProfile, MAX_PATH);
25-
if (pathLen == 0 || pathLen >= MAX_PATH) {
26-
return true;
27-
}
28-
29-
std::wstring optionsPath(userProfile);
30-
optionsPath +=
31-
L"\\AppData\\Local\\Packages\\Microsoft.MinecraftUWP_8wekyb3d8bbwe\\LocalState\\games\\com.mojang\\minecraftpe\\options.txt";
32-
33-
std::ifstream file(optionsPath.c_str());
34-
if (!file.is_open()) {
35-
return true;
36-
}
37-
38-
std::string line;
39-
while (std::getline(file, line)) {
40-
std::erase(line, '\r');
41-
if (line.find("gfx_vsync:") == 0) {
42-
return line != "gfx_vsync:0";
43-
}
44-
}
45-
46-
// default to enabled
47-
return true;
48-
}
49-
5022
void DXHooks::CheckTearingSupport() {
5123
ComPtr<IDXGIFactory5> factory5;
5224
if (SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory5)))) {
@@ -55,7 +27,7 @@ void DXHooks::CheckTearingSupport() {
5527
DXGI_FEATURE_PRESENT_ALLOW_TEARING,
5628
&allowTearing,
5729
sizeof(allowTearing)))) {
58-
if (allowTearing && !DXHooks::IsGfxVSyncEnabled()) {
30+
if (allowTearing && !SDK::Options::get().IsGfxVSyncEnabled()) {
5931
tearingSupported = true;
6032
}
6133
}

src/client/hook/impl/DXHooks.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class DXHooks : public HookGroup {
1010
static HRESULT __stdcall CommandQueue_ExecuteCommandLists(ID3D12CommandQueue* queue, UINT NumCommandLists, ID3D12CommandList* const* ppCommandLists);
1111

1212
static void CheckTearingSupport();
13-
static bool IsGfxVSyncEnabled();
1413
public:
1514
DXHooks();
1615
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "pch.h"
2+
#include "Options.h"
3+
4+
SDK::Options* SDK::Options::instance = nullptr;
5+
6+
SDK::Options& SDK::Options::get() {
7+
static Options instance;
8+
return instance;
9+
}
10+
11+
bool SDK::Options::IsGfxVSyncEnabled() {
12+
wchar_t userProfile[MAX_PATH];
13+
DWORD pathLen = GetEnvironmentVariableW(L"USERPROFILE", userProfile, MAX_PATH);
14+
if (pathLen == 0 || pathLen >= MAX_PATH) {
15+
return true;
16+
}
17+
18+
std::wstring optionsPath(userProfile);
19+
optionsPath +=
20+
L"\\AppData\\Local\\Packages\\Microsoft.MinecraftUWP_8wekyb3d8bbwe\\LocalState\\games\\com.mojang\\minecraftpe\\options.txt";
21+
22+
std::ifstream file(optionsPath.c_str());
23+
if (!file.is_open()) {
24+
return true;
25+
}
26+
27+
std::string line;
28+
while (std::getline(file, line)) {
29+
std::erase(line, '\r');
30+
if (line.find("gfx_vsync:") == 0) {
31+
return line != "gfx_vsync:0";
32+
}
33+
}
34+
35+
// default to enabled
36+
return true;
37+
}

src/sdk/common/client/game/Options.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
namespace SDK {
33
class Options {
44
public:
5+
static Options& get();
6+
7+
Options(const Options&) = delete;
8+
Options& operator=(const Options&) = delete;
59

610
void setPlayerViewPerspective(int) {
711
// TODO: lol
@@ -11,5 +15,12 @@ namespace SDK {
1115
// TODO: lol
1216
return 0;
1317
}
18+
19+
bool IsGfxVSyncEnabled();
20+
private:
21+
Options() = default;
22+
~Options() = default;
23+
24+
static Options* instance;
1425
};
1526
}

0 commit comments

Comments
 (0)