Created
May 20, 2016 18:36
-
-
Save anonymous/a34aea97cf1695a132bbdc0923f0a9c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <vector> | |
#include <iostream> | |
#include <ctime> | |
#include <process.h> | |
using namespace std; | |
bool started = false; | |
vector<INPUT> v; | |
void genClicks() { | |
int startX = 220; | |
int startY = 220; | |
int endX = 1400; | |
int endY = 1000; | |
int xStep = 20; | |
int yStep = 40; | |
int curX = startX; | |
int curY = startY; | |
while (curY <= endY) { | |
while (curX <= endX) { | |
const double XSCALEFACTOR = 65535 / (GetSystemMetrics(SM_CXSCREEN) - 1); | |
const double YSCALEFACTOR = 65535 / (GetSystemMetrics(SM_CYSCREEN) - 1); | |
POINT cursorPos; | |
GetCursorPos(&cursorPos); | |
double cx = cursorPos.x * XSCALEFACTOR; | |
double cy = cursorPos.y * YSCALEFACTOR; | |
double nx = curX * XSCALEFACTOR; | |
double ny = curY * YSCALEFACTOR; | |
INPUT Input = { 0 }; | |
Input.type = INPUT_MOUSE; | |
Input.mi.dx = (LONG)nx; | |
Input.mi.dy = (LONG)ny; | |
Input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP; | |
v.push_back(Input); | |
Input.mi.dx = (LONG)nx + 5; | |
v.push_back(Input); | |
Input.mi.dy = (LONG)ny + 5; | |
v.push_back(Input); | |
Input.mi.dx = (LONG)nx; | |
Input.mi.dy = (LONG)ny + 5; | |
v.push_back(Input); | |
Input.mi.dx = (LONG)nx + 5; | |
Input.mi.dy = (LONG)ny - 5; | |
v.push_back(Input); | |
Input.mi.dx = (LONG)nx; | |
Input.mi.dy = (LONG)ny - 5; | |
v.push_back(Input); | |
Input.mi.dx = (LONG)nx - 5; | |
Input.mi.dy = (LONG)ny - 5; | |
v.push_back(Input); | |
Input.mi.dx = (LONG)nx - 5; | |
Input.mi.dy = (LONG)ny; | |
v.push_back(Input); | |
Input.mi.dx = (LONG)nx - 5; | |
Input.mi.dy = (LONG)ny + 5; | |
v.push_back(Input); | |
curX += xStep; | |
} | |
curY += yStep; | |
curX = startX; | |
} | |
} | |
void postClick(HWND wnd, POINT &p, int c) { | |
::PostMessage(wnd, WM_MOUSEMOVE, 0, MAKELPARAM(p.x, p.y)); | |
for (int i = 0; i < c; i++) { | |
::PostMessage(wnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(p.x, p.y)); | |
::PostMessage(wnd, WM_LBUTTONUP, 0, MAKELPARAM(p.x, p.y)); | |
} | |
} | |
void postMsgSend() { | |
HWND wnd = FindWindow(NULL, L"Dota 2"); | |
if (wnd == NULL) { | |
cout << "Can't find Dota 2, will try again after 4 seconds!"; | |
return; | |
} | |
WINDOWPLACEMENT placement; | |
GetWindowPlacement(wnd, &placement); | |
int w = placement.rcNormalPosition.right - placement.rcNormalPosition.left; | |
int h = placement.rcNormalPosition.bottom - placement.rcNormalPosition.top; | |
int startX, startY, endX, endY, xStep, yStep; | |
if ((w == 1920 && h == 1080) || (w == 1680 && h == 1050)) { | |
startX = 220; | |
startY = 220; | |
endX = 1290; | |
endY = 880; | |
xStep = 25; | |
yStep = 25; | |
} else if (w == 1366 && h == 768) { | |
startX = 150; | |
startY = 175; | |
endX = 950; | |
endY = 650; | |
xStep = 15; | |
yStep = 15; | |
} else { | |
cout << "Unsupported Dota2 resolution " << w << "x" << h << "\n"; | |
system("PAUSE"); | |
exit(1); | |
} | |
int curX = startX; | |
int curY = startY; | |
while (curY <= endY) { | |
while (curX <= endX) { | |
POINT p; | |
p.x = curX; | |
p.y = curY; | |
postClick(wnd, p, 8); | |
curX += xStep; | |
Sleep(1); | |
} | |
curY += yStep; | |
curX = startX; | |
} | |
} | |
DWORD threadId = -1; | |
long lastCulling = clock(); | |
void cullingThread(void*) { | |
while (started) { | |
long now = clock(); | |
if (now - lastCulling > 5000) { | |
lastCulling = now; | |
//SendInput(v.size(), &v[0], sizeof(INPUT)); | |
postMsgSend(); | |
} | |
} | |
threadId = -1; | |
} | |
int main() { | |
//genClicks(); | |
cout << "Press F5 to start cutting trees (preferably after the mini game is open). This will only work on 1920x1080 resolution!\n"; | |
cout << "After it starts cutting you can alt tab and leave dota running and do whatever\n"; | |
cout << "Press F9 to stop culling\n"; | |
cout << "CTRL+C to quit this or just press the X\n"; | |
cout << "Also remember to use engine_no_focus_sleep \"0\" console command so that your background fps in dota stays the same while you are alttabbed\n"; | |
while (true) { | |
if (GetAsyncKeyState(VK_F5) & 0x8000) { | |
if (threadId == -1) { | |
started = true; | |
threadId = _beginthread(cullingThread, NULL, 0); | |
cout << "Culling enabled!\n"; | |
} | |
} else if (GetAsyncKeyState(VK_F9) & 0x8000) { | |
started = false; | |
while (threadId != -1) { | |
Sleep(50); | |
} | |
cout << "Culling disabled!\n"; | |
} | |
Sleep(10); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment