-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathDynamicFPS.cpp
More file actions
61 lines (51 loc) · 1.89 KB
/
DynamicFPS.cpp
File metadata and controls
61 lines (51 loc) · 1.89 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
// Updated 1:52 UTC+8 by Leqixn
#include "DynamicFPS.hpp"
#include "SDK/SDK.hpp"
#include <Windows.h>
void DynamicFPS::onTick() {
if (!enabled.boolValue) return;
auto context = GameContext::getInstance();
if (!context || !context->getClientInstance()) return;
auto options = context->getClientInstance()->getOptions();
if (!options) return;
HWND foreground = GetForegroundWindow();
char className[256];
if (GetClassNameA(foreground, className, sizeof(className))) {
bool isGameFocused = (strcmp(className, "ApplicationFrameWindow") == 0 ||
strcmp(className, "Windows.UI.Core.CoreWindow") == 0);
bool shouldThrottle = !isGameFocused || isAFK();
if (shouldThrottle) {
if (!isThrottled) {
originalLimit = options->framerateLimit;
isThrottled = true;
}
options->framerateLimit = !isGameFocused ? (int)unfocusedFPS.floatValue : (int)afkFPS.floatValue;
}
else if (isThrottled) {
if (originalLimit.has_value()) {
options->framerateLimit = originalLimit.value();
}
isThrottled = false;
}
}
}
bool DynamicFPS::isAFK() const {
LASTINPUTINFO lii = { sizeof(LASTINPUTINFO) };
if (GetLastInputInfo(&lii)) {
uint64_t idleSeconds = (GetTickCount64() - lii.dwTime) / 1000;
return idleSeconds >= static_cast<uint64_t>(afkTimeout.floatValue);
}
return false;
}
void DynamicFPS::onDisable() {
if (isThrottled && originalLimit.has_value()) {
auto context = GameContext::getInstance();
if (context && context->getClientInstance()) {
auto options = context->getClientInstance()->getOptions();
if (options) {
options->framerateLimit = originalLimit.value();
}
}
}
isThrottled = false;
}