Created
May 20, 2016 12:04
-
-
Save anonymous/fe85e7254db8b729ce7f8857cf467019 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 = 250; | |
int startY = 250; | |
int endX = 1320; | |
int endY = 930; | |
int xStep = 40; | |
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) { | |
::PostMessage(wnd, WM_MOUSEMOVE, 0, MAKELPARAM(p.x, p.y)); | |
::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; | |
} | |
int startX = 250; | |
int startY = 250; | |
int endX = 1320; | |
int endY = 930; | |
int xStep = 25; | |
int yStep = 40; | |
int curX = startX; | |
int curY = startY; | |
while (curY <= endY) { | |
while (curX <= endX) { | |
POINT p; | |
p.x = curX; | |
p.y = curY; | |
postClick(wnd, p); | |
postClick(wnd, p); | |
postClick(wnd, p); | |
postClick(wnd, p); | |
postClick(wnd, p); | |
postClick(wnd, p); | |
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 > 4000) { | |
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