Skip to content

Commit 69cd364

Browse files
committed
Merge branch 'master' of https://github.com/LatiteClient/Latite
2 parents 4bf75aa + 1a0f880 commit 69cd364

File tree

10 files changed

+100
-54
lines changed

10 files changed

+100
-54
lines changed

LatiteRewrite.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@
618618
<ClInclude Include="src\client\script\PluginManager.h" />
619619
<ClInclude Include="src\client\ui\TextBox.h" />
620620
<ClInclude Include="src\sdk\common\client\game\FontRepository.h" />
621+
<ClInclude Include="src\sdk\common\client\game\Option.h" />
621622
<ClInclude Include="src\sdk\common\client\game\Options.h" />
622623
<ClInclude Include="src\sdk\common\client\gui\controls\UIControl.h" />
623624
<ClInclude Include="src\sdk\common\client\gui\controls\VisualTree.h" />

LatiteRewrite.vcxproj.filters

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@
484484
<ClInclude Include="assets\lang\zh_TW.json" />
485485
<ClInclude Include="src\client\script\objects\OSScriptingObject.h" />
486486
<ClInclude Include="src\client\feature\module\impl\hud\FrameTimeDisplay.h" />
487+
<ClInclude Include="src\sdk\common\client\game\Option.h" />
487488
</ItemGroup>
488489
<ItemGroup>
489490
<ResourceCompile Include="LatiteRewrite.rc" />

src/client/feature/module/impl/game/AutoGG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ AutoGG::AutoGG() : Module("AutoGG", LocalizeString::get("client.module.autoGG.na
88
addSetting("useCustomMessage", LocalizeString::get("client.module.autoGG.useCustomMessage.name"),
99
LocalizeString::get("client.module.autoGG.useCustomMessage.desc"), useCustomMessage);
1010
addSetting("customMessage", LocalizeString::get("client.module.autoGG.customMessage.name"),
11-
LocalizeString::get("client.module.autoGG.customMessage.desc"), customMessage);
11+
LocalizeString::get("client.module.autoGG.customMessage.desc"), customMessage, "useCustomMessage"_istrue);
1212
listen<ChatMessageEvent>(static_cast<EventListenerFunc>(&AutoGG::onText));
1313
}
1414

src/client/feature/module/impl/hud/FrameTimeDisplay.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,23 @@ FrameTimeDisplay::FrameTimeDisplay() : TextModule("FrameTimeDisplay",
99
addSliderSetting("interval", LocalizeString::get("client.textmodule.frameTimeDisplay.interval.name"),
1010
LocalizeString::get("client.textmodule.frameTimeDisplay.interval.desc"), interval, FloatValue(0.f),
1111
FloatValue(1000.f), FloatValue(100.f));
12+
1213
this->prefix = TextValue(L"Frame time: ");
1314
this->suffix = TextValue(L"ms");
1415
}
1516

1617
std::wstringstream FrameTimeDisplay::text(bool isDefault, bool inEditor) {
17-
// normal caching in the TextModule constructor didnt work so im doing this
18-
static std::wstring cachedText;
19-
static std::chrono::steady_clock::time_point lastUpdate;
20-
static float displayedValue = -1.0f;
21-
22-
const float currentValue = Latite::get().getTimings().getFrameTime();
2318
const std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
2419
const long long elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - lastUpdate).count();
2520

21+
std::wstringstream ss;
22+
2623
if (elapsed >= std::get<FloatValue>(interval)) {
27-
std::wstringstream ss;
28-
ss << std::fixed << std::setprecision(1) << currentValue;
29-
cachedText = ss.str();
30-
displayedValue = currentValue;
24+
displayedValue = Latite::get().getTimings().getFrameTime();
3125
lastUpdate = now;
3226
}
3327

34-
std::wstringstream output;
35-
if (!cachedText.empty()) {
36-
output.str(cachedText);
37-
output.clear();
38-
}
39-
return output;
28+
ss << std::fixed << std::setprecision(1) << displayedValue;
29+
30+
return ss;
4031
}

src/client/feature/module/impl/hud/FrameTimeDisplay.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ class FrameTimeDisplay : public TextModule {
88
std::wstringstream text(bool isDefault, bool inEditor) override;
99
private:
1010
ValueType interval = FloatValue(100.f);
11+
12+
std::chrono::steady_clock::time_point lastUpdate;
13+
float displayedValue = -1.0f;
1114
};

src/client/hook/impl/DXHooks.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,40 @@ namespace {
1313
IDXGIOutput*,
1414
IDXGISwapChain1**);
1515

16-
SDK::Options* options = new SDK::Options();
1716
bool tearingSupported = false;
1817
bool isForceDisableVSync = false;
1918
std::shared_ptr<Hook> PresentHook;
2019
std::shared_ptr<Hook> ResizeBuffersHook;
2120
std::shared_ptr<Hook> ExecuteCommandListsHook;
21+
22+
// TODO: temporary, remove this
23+
bool isGfxVsyncDisabled() {
24+
wchar_t userProfile[MAX_PATH];
25+
DWORD pathLen = GetEnvironmentVariableW(L"USERPROFILE", userProfile, MAX_PATH);
26+
if (pathLen == 0 || pathLen >= MAX_PATH) {
27+
return true;
28+
}
29+
30+
std::wstring optionsPath(userProfile);
31+
optionsPath +=
32+
L"\\AppData\\Local\\Packages\\Microsoft.MinecraftUWP_8wekyb3d8bbwe\\LocalState\\games\\com.mojang\\minecraftpe\\options.txt";
33+
34+
std::ifstream file(optionsPath.c_str());
35+
if (!file.is_open()) {
36+
return true;
37+
}
38+
39+
std::string line;
40+
while (std::getline(file, line)) {
41+
std::erase(line, '\r');
42+
if (line.find("gfx_vsync:") == 0) {
43+
return line != "gfx_vsync:0";
44+
}
45+
}
46+
47+
// default to enabled
48+
return true;
49+
}
2250
}
2351

2452
void DXHooks::CheckForceDisableVSync() {
@@ -37,7 +65,7 @@ void DXHooks::CheckTearingSupport() {
3765
DXGI_FEATURE_PRESENT_ALLOW_TEARING,
3866
&allowTearing,
3967
sizeof(allowTearing)))) {
40-
if (allowTearing && !options->IsGfxVSyncEnabled()) {
68+
if (allowTearing && !isGfxVsyncDisabled()) {
4169
tearingSupported = true;
4270
}
4371
}

src/sdk/common/client/game/ClientInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ SDK::GuiData* SDK::ClientInstance::getGuiData() {
8282
}
8383

8484
SDK::Options* SDK::ClientInstance::getOptions() {
85-
return memory::callVirtual<Options*>(this, 0xC7);
85+
return memory::callVirtual<Options*>(this, 0xC3);
8686
}
8787

8888
void SDK::ClientInstance::grabCursor() {

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
namespace SDK {
3+
enum class OptionID {
4+
Vsync = 54,
5+
};
6+
7+
class Option {
8+
public:
9+
10+
class Impl {
11+
private:
12+
char pad[0x124];
13+
public:
14+
OptionID id;
15+
};
16+
17+
18+
std::unique_ptr<Impl> impl;
19+
20+
virtual ~Option() = 0;
21+
};
22+
23+
class BoolOption : public Option {
24+
public:
25+
bool value;
26+
bool defaultValue;
27+
std::function<bool(bool)> coerceValueCallback;
28+
};
29+
}
Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,2 @@
11
#include "pch.h"
22
#include "Options.h"
3-
4-
bool SDK::Options::IsGfxVSyncEnabled() {
5-
wchar_t userProfile[MAX_PATH];
6-
DWORD pathLen = GetEnvironmentVariableW(L"USERPROFILE", userProfile, MAX_PATH);
7-
if (pathLen == 0 || pathLen >= MAX_PATH) {
8-
return true;
9-
}
10-
11-
std::wstring optionsPath(userProfile);
12-
optionsPath +=
13-
L"\\AppData\\Local\\Packages\\Microsoft.MinecraftUWP_8wekyb3d8bbwe\\LocalState\\games\\com.mojang\\minecraftpe\\options.txt";
14-
15-
std::ifstream file(optionsPath.c_str());
16-
if (!file.is_open()) {
17-
return true;
18-
}
19-
20-
std::string line;
21-
while (std::getline(file, line)) {
22-
std::erase(line, '\r');
23-
if (line.find("gfx_vsync:") == 0) {
24-
return line != "gfx_vsync:0";
25-
}
26-
}
27-
28-
// default to enabled
29-
return true;
30-
}

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
#pragma once
2+
#include "Option.h"
3+
24
namespace SDK {
3-
class Options {
5+
6+
7+
class Options : std::enable_shared_from_this<Options> {
48
public:
5-
void setPlayerViewPerspective(int) {
6-
// TODO: lol
9+
void setPlayerViewPerspective(int perspective) {
10+
memory::callVirtual<void>(this, 136, perspective);
711
}
812

913
int getPlayerViewPerspective() {
10-
// TODO: lol
11-
return 0;
14+
return memory::callVirtual<int>(this, 137);
1215
}
1316

14-
bool IsGfxVSyncEnabled();
17+
bool getVsync() {
18+
auto it = std::find_if(options.begin(), options.end(), [](std::unique_ptr<Option>& option) {
19+
if (option && option->impl->id == OptionID::Vsync) {
20+
return true;
21+
}
22+
});
23+
24+
if (it == options.end()) {
25+
return false;
26+
}
27+
28+
return static_cast<BoolOption*>(it->get())->value;
29+
}
30+
31+
private:
32+
void* unknown;
33+
std::array<std::unique_ptr<class Option>, 788> options;
34+
35+
virtual ~Options() = 0;
1536
};
1637
}

0 commit comments

Comments
 (0)