-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
306 lines (256 loc) · 7.59 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#include <iostream>
#include <thread>
#include <atomic>
#include <chrono>
#include <string>
#include <windows.h>
#include <psapi.h>
#include <vector>
#include <tlhelp32.h>
constexpr COLORREF kTargetColor = RGB(43, 137, 254);
constexpr DWORD kHotkeyId = 1;
std::atomic<bool> g_isActive(false);
std::atomic<bool> g_autoTapXActive(false);
std::atomic<bool> g_moveCursor(false);
std::atomic<bool> g_programRunning(true);
std::thread autoTapXThread;
int g_xCoord;
int g_yStart;
int g_yEnd;
void LogMessage(const std::string& message) {
std::cout << message << std::endl;
}
void UserInput() {
std::cout << "> ";
std::flush(std::cout);
}
void AccountForDifferentRes(int width, int height) {
g_xCoord = static_cast<int>(width * 0.96);
g_yStart = static_cast<int>(height * 0.37);
g_yEnd = static_cast<int>(height * 0.72);
}
bool IsRobloxFocused() {
HWND hwnd = GetForegroundWindow();
if (hwnd == nullptr) {
return false;
}
DWORD processId;
GetWindowThreadProcessId(hwnd, &processId);
WCHAR exeName[MAX_PATH];
if (GetProcessImageFileNameW(OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId), exeName, MAX_PATH) > 0) {
return wcsstr(exeName, L"RobloxPlayerBeta.exe") != nullptr;
}
return false;
}
void Click() {
INPUT input = {0};
input.type = INPUT_MOUSE;
input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;
SendInput(1, &input, sizeof(INPUT));
}
void ReleaseHdc(HDC hdc) {
if (hdc) {
ReleaseDC(nullptr, hdc);
}
}
void DeleteGdiObject(HGDIOBJ obj) {
if (obj) {
DeleteObject(obj);
}
}
using UniqueHdc = std::unique_ptr<std::remove_pointer<HDC>::type,
decltype(&ReleaseHdc)>;
using UniqueBitmap = std::unique_ptr<std::remove_pointer<HBITMAP>::type,
decltype(&DeleteGdiObject)>;
void AutoEdge() {
UniqueHdc hdcScreen(GetDC(nullptr), ReleaseHdc);
if (!hdcScreen) {
return;
}
UniqueHdc hdcMem(CreateCompatibleDC(hdcScreen.get()), [](HDC hdc) { DeleteDC(hdc); });
if (!hdcMem) {
return;
}
int height = g_yEnd - g_yStart;
UniqueBitmap hBitmap(CreateCompatibleBitmap(hdcScreen.get(), 1, height), DeleteGdiObject);
if (!hBitmap) {
return;
}
SelectObject(hdcMem.get(), hBitmap.get());
BITMAPINFO bmi = {};
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = 1;
bmi.bmiHeader.biHeight = -height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
const int stride = ((24 * 1 + 31) / 32) * 4;
std::vector<BYTE> buffer(stride * height);
const int cachedXCoord = g_xCoord;
const int cachedYStart = g_yStart;
const BYTE targetRed = GetRValue(kTargetColor);
const BYTE targetGreen = GetGValue(kTargetColor);
const BYTE targetBlue = GetBValue(kTargetColor);
while (g_programRunning.load()) {
if (g_isActive.load() && IsRobloxFocused()) {
BitBlt(hdcMem.get(), 0, 0, 1, height, hdcScreen.get(), cachedXCoord, cachedYStart, SRCCOPY);
if (GetDIBits(hdcMem.get(), hBitmap.get(), 0, height, buffer.data(), &bmi, DIB_RGB_COLORS)) {
for (int y = 0; y < height; ++y) {
int index = y * stride;
if (buffer[index + 2] == targetRed &&
buffer[index + 1] == targetGreen &&
buffer[index + 0] == targetBlue) {
if (g_moveCursor.load()) {
SetCursorPos(cachedXCoord, cachedYStart + y);
}
Click();
break;
}
}
}
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}
}
void AutoTapX() {
const WORD xScanCode = MapVirtualKey(VkKeyScan('x'), MAPVK_VK_TO_VSC);
while (g_autoTapXActive && g_programRunning) {
if (IsRobloxFocused()) {
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = xScanCode;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0;
ip.ki.dwFlags = KEYEVENTF_SCANCODE;
SendInput(1, &ip, sizeof(INPUT));
std::this_thread::sleep_for(std::chrono::milliseconds(5));
ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
}
std::this_thread::sleep_for(std::chrono::milliseconds(300));
}
}
void ToggleAutoTapX() {
if (!g_autoTapXActive) {
g_autoTapXActive = true;
autoTapXThread = std::thread(AutoTapX);
LogMessage("started auto tapping x");
} else {
g_autoTapXActive = false;
if (autoTapXThread.joinable()) {
autoTapXThread.join();
}
LogMessage("stopped auto tapping x");
}
}
void ToggleMoveCursor() {
g_moveCursor = !g_moveCursor;
LogMessage(g_moveCursor ? "move cursor mode enabled" : "move cursor mode disabled");
}
void ToggleAutoEdge() {
g_isActive = !g_isActive;
LogMessage(g_isActive ? "started auto-edging" : "stopped auto-edging");
}
void HandleCommands() {
std::string command;
UserInput();
while (g_programRunning) {
std::getline(std::cin, command);
if (command == "help") {
LogMessage("commands:");
LogMessage("help - shows this message");
LogMessage("exit - ropemaxx");
LogMessage("autotapx - toggle auto tapping x every .3s (enters \'edge\' mode for you)");
LogMessage("movecursor - toggle moving cursor to the pixel position");
LogMessage("autoedge - toggle auto-edging");
} else if (command == "exit") {
g_autoTapXActive = false;
g_isActive = false;
g_programRunning = false;
} else if (command == "autotapx") {
ToggleAutoTapX();
} else if (command == "autoedge") {
ToggleAutoEdge();
} else if (command == "movecursor") {
ToggleMoveCursor();
} else if (command == "author") {
LogMessage("@z1xus");
} else {
LogMessage("i dont knowm this command yet!\ntype 'help' for a list of commands");
}
std::cout << std::endl;
UserInput();
}
LogMessage("\nbye!");
}
bool isRobloxOn() {
HANDLE hProcessSnap;
PROCESSENTRY32 pe32;
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE) {
CloseHandle(hProcessSnap);
return false;
}
pe32.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hProcessSnap, &pe32)) {
CloseHandle(hProcessSnap); // clean the snapshot object
return false;
}
do {
if (strcmp(pe32.szExeFile, "RobloxPlayerBeta.exe") == 0) {
CloseHandle(hProcessSnap);
return true;
}
} while (Process32Next(hProcessSnap, &pe32));
CloseHandle(hProcessSnap);
return false;
}
int main() {
SetConsoleTitle(TEXT("auto-edger"));
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
if (!SetProcessDPIAware()) {
LogMessage("warning: failed to set process dpi awareness");
}
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
AccountForDifferentRes(screenWidth, screenHeight);
if (!isRobloxOn()) {
LogMessage("warning: roblox is not running\nturn on roblox, dummy");
while (!isRobloxOn()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
if (!RegisterHotKey(nullptr, kHotkeyId, 0, VK_F8)) {
LogMessage("failed to register hotkey for f8. use 'autoedge' command to toggle");
} else {
LogMessage("press f8 to outedge everyone");
}
LogMessage("type 'help' for a list of commands");
std::thread autoEdgeThread(AutoEdge);
std::thread commandThread(HandleCommands);
MSG msg = {};
while (g_programRunning) {
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
if (msg.message == WM_HOTKEY && msg.wParam == kHotkeyId) {
std::cout << std::endl;
ToggleAutoEdge();
std::cout << std::endl;
UserInput();
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
UnregisterHotKey(nullptr, kHotkeyId);
if (commandThread.joinable()) {
commandThread.join();
}
if (autoEdgeThread.joinable()) {
autoEdgeThread.join();
}
return 0;
}