Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ScanContents.h"
- bool TakeScreenshot(std::string WindowToFind, BITMAP &bm, HBITMAP &hbmap, BITMAPINFO &bmi, HDC &hdcShot, HBITMAP &hBitmapOld, HWND &hwnd);
- void SetupBitmapInfo(BITMAPINFO &bmi, int bWidth, int bHeight, int bitsPerPixel);
- bool CompareColour(RGBQUAD *pPixels, int height, int width, int x, int y);
- void ScanBMPHorizontal(ScanContents * scan);
- bool Aim_Bot(HWND appWnd, std::string GameWindow);
- MouseCoord CurrentMouseXY(0, 0);
- int main()
- {
- std::string GameWindow = "Bloodline Champions - Version 2.7.1.0";
- HWND appWnd = FindWindow(0, GameWindow.c_str()); //rgb - Windows Photo Viewer // Call of duty 4 // Counter-Strike Source
- while(!appWnd)
- {
- system("CLS");
- appWnd = FindWindow(0, GameWindow.c_str());
- std::cout << "Unable to find " << GameWindow.c_str() << std::endl;
- Sleep(500);
- }
- POINT currentPos;
- GetCursorPos(¤tPos);
- CurrentMouseXY.X = currentPos.x;
- CurrentMouseXY.Y = currentPos.y;
- Aim_Bot(appWnd, GameWindow);
- system("pause");
- return 0;
- }
- bool TakeScreenshot(std::string WindowToFind, BITMAP &bm, HBITMAP &hbmap, BITMAPINFO &bmi, HDC &hdcShot, HBITMAP &hBitmapOld, HWND &hwnd)
- {
- RECT rc;
- GetWindowRect(hwnd, &rc);
- hdcShot = CreateCompatibleDC(0);
- hbmap = CreateCompatibleBitmap(GetDC(0), rc.right - rc.left, rc.bottom - rc.top);
- SelectObject(hdcShot, hbmap);
- BitBlt(hdcShot, 0, 0, rc.right - rc.left, rc.bottom - rc.top, GetDC(hwnd), 0, 0, SRCCOPY);
- if (!GetObject(hbmap, sizeof(BITMAP), (LPSTR)&bm))
- return false;
- int bitsPerPixel = bm.bmBitsPixel;
- if (bitsPerPixel != 32 || bm.bmPlanes != 1)
- return false;
- SetupBitmapInfo(bmi, bm.bmWidth, bm.bmHeight, bitsPerPixel);
- return true;
- }
- bool Aim_Bot(HWND appWnd, std::string GameWindow)
- {
- RECT rcWindow;
- GetWindowRect(appWnd, &rcWindow);
- BITMAP bm;
- HBITMAP hbmap;
- HBITMAP hBitmapOld;
- BITMAPINFO bmi;
- HDC hdcShot;
- HDC hdcScreen;
- RGBQUAD * pPixels;
- int TimeTakenScreenAndScan;
- while(true)
- {
- //only allow pressing with a x ms difference
- if(!GetAsyncKeyState('X')) //VK_RBUTTON
- {
- TimeTakenScreenAndScan = clock();
- //get all contents of our screen and store them in bm
- if(!TakeScreenshot(GameWindow, bm, hbmap, bmi, hdcShot, hBitmapOld, appWnd))
- break;
- ////NEED TO CALL THESE AGAIN FOR THE SCREENSHOT TO WORK PROPERLY, screenshotception
- HBITMAP hbmapNew = CreateCompatibleBitmap(hdcShot, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top);
- HDC hdcShotNew = CreateCompatibleDC(hdcShot);
- HBITMAP OldBmp = (HBITMAP) SelectObject(hdcShotNew, hbmapNew);
- //store our screenshot FROM TO, storing just the size of the window Keeping resource allocation down by a couple of 100,000 pixels
- BitBlt(hdcShotNew, 0, 0, rcWindow.right - rcWindow.left/*Window WIDTH*/, rcWindow.bottom - rcWindow.top/*Window HEIGHT*/
- , hdcShot, 0, 0, SRCCOPY);
- pPixels = new RGBQUAD[bm.bmWidth * bm.bmHeight];
- if (!pPixels) return false;
- SelectObject(hdcShotNew, OldBmp);
- if (!GetDIBits(hdcShotNew, hbmapNew, 0, bm.bmHeight, pPixels, &bmi, DIB_RGB_COLORS))
- {
- ReleaseDC(appWnd, hdcShot);
- delete [] pPixels;
- return false;
- }
- ReleaseDC(appWnd, hdcShot);
- ScanContents scanContentsMain(bm, rcWindow, pPixels);
- ScanBMPHorizontal(&scanContentsMain);
- //system("pause");
- if(pPixels)free(pPixels);
- SelectObject(hdcShot, hBitmapOld);
- DeleteObject(hbmap);
- DeleteDC(hdcShot);
- DeleteObject(hbmapNew);
- DeleteObject(OldBmp);
- DeleteDC(hdcShotNew);
- // std::cout << "out of scan, took " << clock() - TimeTakenScreenAndScan << " milliseconds" << std::endl;
- }
- }
- }
- void SetupBitmapInfo(BITMAPINFO &bmi, int bWidth, int bHeight, int bitsPerPixel)
- {
- bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmi.bmiHeader.biWidth = bWidth;
- bmi.bmiHeader.biHeight = bHeight;
- bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biBitCount = bitsPerPixel;
- bmi.bmiHeader.biCompression = BI_RGB;
- bmi.bmiHeader.biSizeImage = 0;
- }
- void ScanBMPHorizontal(ScanContents * scan)
- {
- for(int y = (scan->RcWindow.bottom - scan->RcWindow.top)/4;
- y < ((scan->RcWindow.bottom - scan->RcWindow.top) - (scan->RcWindow.bottom - scan->RcWindow.top)/3.5); y++)
- {
- for(int x = (scan->RcWindow.right - scan->RcWindow.left)/4;
- x < ((scan->RcWindow.right - scan->RcWindow.left) - (scan->RcWindow.right - scan->RcWindow.left)/4); x++)
- {
- // SetCursorPos(x+scan->RcWindow.left, (y+4)+scan->RcWindow.top);
- if(CompareColour(scan->PPixels, scan->Bm.bmHeight, scan->Bm.bmWidth, x, y))
- {
- SetCursorPos(x+scan->RcWindow.left, (y+4)+scan->RcWindow.top);
- POINT currentPos;
- GetCursorPos(¤tPos);
- //ShootBot(x+scan->RCWindow.left, y+scan->RcWindow.top);
- CurrentMouseXY.X = currentPos.x;
- CurrentMouseXY.Y = currentPos.y;
- return;
- }
- }
- }
- }
- bool CompareColour(RGBQUAD * pPixels, int height, int width, int x, int y)
- {
- int p = (height-y-1)*width+x;
- //std::cout << (int)pPixels[p].rgbRed << ", " << (int)pPixels[p].rgbGreen << ", " << (int)pPixels[p].rgbBlue << std::endl;
- if((int)pPixels[p].rgbRed < 30 && (int)pPixels[p].rgbGreen < 30 && (int)pPixels[p].rgbBlue > 215)
- {
- //std::cout << "Found color" << std::endl;
- //system("pause");
- return true;
- }
- if(GetAsyncKeyState(VK_DELETE))
- {
- exit(0);
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement