-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
141 lines (114 loc) · 3.35 KB
/
main.cpp
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <Windows.h>
#include <TlHelp32.h>
#include <cstdio>
// Utilities
typedef LONG(NTAPI* NtSuspendProcess)(IN HANDLE ProcessHandle);
typedef LONG(NTAPI* NtResumeProcess)(IN HANDLE ProcessHandle);
NtSuspendProcess dSuspendProcess = nullptr;
NtResumeProcess dResumeProcess = nullptr;
// Process running?
BOOL is_running(DWORD process)
{
HANDLE proc = OpenProcess(SYNCHRONIZE, FALSE, process);
DWORD ret = WaitForSingleObject(proc, 0);
CloseHandle(proc);
return ret == WAIT_TIMEOUT;
}
// Get process
DWORD get(LPCTSTR name)
{
PROCESSENTRY32 pt;
HANDLE hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
pt.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hsnap, &pt))
{
do
{
if (!lstrcmpi(pt.szExeFile, name))
{
CloseHandle(hsnap);
return pt.th32ProcessID;
}
} while (Process32Next(hsnap, &pt));
}
CloseHandle(hsnap);
return 0;
}
// Handling process
void handle(int type, DWORD process)
{
HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, process);
if (h == nullptr)
return;
switch (type)
{
case 1:
dSuspendProcess(h);
break;
case 2:
dResumeProcess(h);
break;
}
CloseHandle(h);
}
// Init
void init()
{
// Load NtSuspendProcess from ntdll.dll
HMODULE ntmod = GetModuleHandleA("ntdll");
dSuspendProcess = (NtSuspendProcess)GetProcAddress(ntmod, "NtSuspendProcess");
dResumeProcess = (NtResumeProcess)GetProcAddress(ntmod, "NtResumeProcess");
// Congratulations
printf("RIGHT CONTROL - Freeze Lag, INSERT - Quit\n[Miscellaneous: PAGE UP - Freeze process | PAGE DOWN - Unfreeze process]\n\nMade with love by nloginov @ 2023");
}
// Definitions
#define GET_PROC get(L"DyingLightGame.exe")
#define CURRENT GetTickCount64()
// Main
void main()
{
// Allocate console
AllocConsole();
AttachConsole(GetCurrentProcessId());
FILE* out{};
freopen_s(&out, "CONOUT$", "w", stdout);
// Console title
SetConsoleTitleA("Frame Limiter");
// Initialize
init();
// We do this so that we can grab the process not just 1 time
while (true)
{
// Getting game process
DWORD game = GET_PROC;
// Variable for freeze lag
ULONGLONG last_use = CURRENT;
// Cool loop here...
while (is_running(game))
{
// INSERT for quit, obviously
if (GetAsyncKeyState(VK_INSERT))
TerminateProcess(GetCurrentProcess(), 0);
else if (GetAsyncKeyState(VK_NEXT)) // Page Down
handle(2, game);
else if (GetAsyncKeyState(VK_PRIOR)) // Page Up
handle(1, game);
else if (GetAsyncKeyState(VK_RCONTROL)) // Right control
{
if (last_use - CURRENT > 150)
{
// Suspend
handle(1, game);
// Wait
Sleep(150);
// Resume
handle(2, game);
// Update timer
last_use = CURRENT;
}
}
}
}
// Free everything
FreeConsole();
}