C++ Color Detection Bot
마우스 클릭으로 색상추출 하는 코드
#include <iostream>
#include <windows.h>
#include <ctime>
#include <time.h>
#include <stdlib.h>
#include <cstdlib>
using namespace std;
int x, y;
int Cm = 253;
int ClickOnMap;
int redValue, greenValue, blueValue;
int connection;
int FirstMapClick;
int FleeFromEnemy;
int EnemyGone;
int ic;
static bool RandomSeed = true;
//HDC and hWnd
COLORREF c;
HDC hdcScreen;
COLORREF ReadPixel(int x, int y);
DWORD* bits = NULL;
COLORREF crPixel;
COLORREF SetRed = 2366701;
HWND hWnd;
//Colours
COLORREF Colour[25];
//minmax
COLORREF rmax,rmin,gmax,gmin,bmax,bmin;
int Random(int RandMin, int RandMax) //my random number generator
{
if(RandomSeed)
{
RandomSeed = false;
srand((unsigned) time(NULL));
}
int GeneratedNumber = RandMin + rand() % (RandMax - RandMin + 1);
return (GeneratedNumber);
}
int GetHandle()
{
HWND MainHandle = FindWindow(L"WindowsForms10.Window.8.app.0.33c0d9d", NULL);
if(!MainHandle)
return 10;
HWND Child1 = FindWindowEx(MainHandle, NULL, L"WindowsForms10.SysTabControl32.app.0.33c0d9d", NULL);
if(!Child1)
return 1;
HWND Child2 = FindWindowEx(Child1, NULL, L"WindowsForms10.Window.8.app.0.33c0d9d", L"DO Play");
if(!Child2)
return 2;
HWND Child3 = FindWindowEx(Child2, NULL, L"WindowsForms10.Window.8.app.0.33c0d9d", NULL);
if(!Child3)
return 3;
HWND Child4 = FindWindowEx(Child3, NULL, L"Shell Embedding", NULL);
if(!Child4)
return 4;
HWND Child5 = FindWindowEx(Child4, NULL, L"Shell DocObject View", NULL);
if(!Child5)
return 5;
HWND Child6 = FindWindowEx(Child5, NULL, L"Internet Explorer_Server", NULL);
if(!Child6)
return 6;
hWnd = FindWindowEx(Child6, NULL, L"MacromediaFlashPlayerActiveX", NULL);
if(!hWnd)
return 7;
return 0;
}
void ClickMouse(int a, int b)
{
SetActiveWindow(hWnd);
SetFocus(hWnd);
PostMessage(hWnd,WM_MOUSEMOVE, NULL, MAKELONG(a,b));
PostMessage(hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(a,b));
Sleep(50);
PostMessage(hWnd, WM_LBUTTONUP, 0x00000001, MAKELONG(a,b));
}
void AntiBan()
{
if(Random(0,10) == Random(0,10))
{
if(Random(1,3) == 1)
{
ClickMouse(476,595);//Laser Menu
Sleep(Random(1000,2000));
}
if(Random(1,3) == 2)
{
ClickMouse(524,600);//Rocket Menu
Sleep(Random(1000,2000));
}
if(Random(1,3) == 3)
{
ClickMouse(621,602);//Extras Menu
Sleep(Random(1000,2000));
}
Sleep(10);
}
}
BOOL SimilarColors(int Color1, int Color2, int Tolerance)
{
return ((abs((Color1 && 0xFF) - (Color2 && 0xFF)) <= Tolerance) &&
(abs(((Color1 && 0xFF00) >> 8) - ((Color2 && 0xFF00) >> 8)) <= Tolerance) &&
(abs(((Color1 && 0xFF0000) >> 16) - ((Color2 && 0xFF0000) >> 16)) <= Tolerance));
}
void CheckForEnemyPlayers()
{
hdcScreen = GetDC(hWnd);
crPixel = GetPixel(hdcScreen,811,645);
ReleaseDC(0,hdcScreen);
redValue = GetRValue(crPixel);
greenValue = GetGValue(crPixel);
blueValue = GetBValue(crPixel);
while(redValue != 225 && greenValue != 240 && blueValue != 255)
{
if(FleeFromEnemy == 0)
{
ClickMouse(Random(658,662),Random(551,555));
FleeFromEnemy = 1;
}
AntiBan();
hdcScreen = GetDC(hWnd);
crPixel = GetPixel(hdcScreen,811,645);
ReleaseDC(0,hdcScreen);
redValue = GetRValue(crPixel);
greenValue = GetGValue(crPixel);
blueValue = GetBValue(crPixel);
Sleep(Random(2000,4000));
EnemyGone = 1;
}
FleeFromEnemy = 0;
if(EnemyGone == 1)
{
EnemyGone = 0;
ClickMouse(Random(654,801),Random(548,642)); // random click on map
}
}
void SwapCol(DWORD* ptr)
{
*ptr = (*ptr & 0x000000FF) << 16 | (*ptr & 0x0000FF00) | (*ptr & 0x00FF0000) >> 16;
}
void ClickBonusBox()
{
SwapCol(&c);
c = (c & 0xFFFFFF);
int r = GetRValue(c);
int g = GetGValue(c);
int b = GetBValue(c);
COLORREF comp = RGB(r,g,b);
if(comp == Colour[0]) //RGB(r,g,b) or //c==23456
{
ClickMouse(x,y);
Sleep(4000);
ClickMouse(Random(654,801),Random(548,642)); // random click on map
x=816;
y=517;
}
}
COLORREF ReadPixel(int x, int y)
{
DWORD* p = bits + (y * 817 + x);
return *p;
}
void ScanPixels()
{
x = 0;
y = 73;
BITMAPINFO bi = { 0 };
bi.bmiHeader.biSize = sizeof(BITMAPINFO);
bi.bmiHeader.biWidth = 817;
bi.bmiHeader.biHeight = -517; //top down
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;
HDC hdc = GetDC(hWnd); //0 is the entire screen
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hDib = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hDib);
BitBlt(hdcMem, 0, 0, 817, 517, hdc, 0, 0, SRCCOPY);
//hdcMem is the destination, hdc is the source
//we have all the pixel data now, to access it, just make a pointer to it.
while(x!=817 && y!=517)
{
c = ReadPixel(x, y);
ClickBonusBox();
if(x == 817)
{
x = 0;
y++;
}
x++;
}
DeleteObject(hDib);
DeleteObject(hbmOld);
ReleaseDC(hWnd,hdc);
ReleaseDC(hWnd,hdcMem);
DeleteDC(hdc);
DeleteDC(hdcMem);
}
void InitializeColors()
{
ic = 0;
Colour[0] = RGB(183,181,177);
}
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
InitializeColors();
while(!hWnd)
{
GetHandle();
}
Sleep(1000);
ClickMouse(395,627); //Click "Start"
Sleep(1000);
while(!hWnd)
{
GetHandle();
}
while(connection != 1)
{
hdcScreen = GetDC(hWnd);
crPixel = GetPixel(hdcScreen,14,615);
ReleaseDC(0,hdcScreen);
redValue = GetRValue(crPixel);
greenValue = GetGValue(crPixel);
blueValue = GetBValue(crPixel);
if(redValue == 21 && greenValue == 63 && blueValue == 42)
{
connection = 1;
}
}
while(1)//MAIN
{
CheckForEnemyPlayers();
if(FirstMapClick == 0)
{
ClickMouse(Random(654,801),Random(548,642)); // random click on map
FirstMapClick = 1;
}
ScanPixels();
ClickOnMap++;
if(ClickOnMap == 30000)
{
ClickMouse(Random(654,801),Random(548,642)); // random click on map
ClickOnMap = 0;
}
}
return 0;
}
'개발언어 > c++' 카테고리의 다른 글
| 3D text, 예쁜 글 표현 (0) | 2016.07.18 |
|---|---|
| Use Direct3D 8 To Fly Through the Munsell Color Solid (0) | 2016.07.17 |
| Smooth color transition algorithm (0) | 2016.07.16 |
| 메모리 사용량 알기 (0) | 2016.07.16 |
| Clipboard 에 문자열 넣고,붙여넣기 (0) | 2016.07.16 |