Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2012
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.39 KB | None | 0 0
  1. #include "ScanContents.h"
  2.  
  3.  
  4. bool TakeScreenshot(std::string WindowToFind, BITMAP &bm, HBITMAP &hbmap, BITMAPINFO &bmi, HDC &hdcShot, HBITMAP &hBitmapOld, HWND &hwnd);
  5. void SetupBitmapInfo(BITMAPINFO &bmi, int bWidth, int bHeight, int bitsPerPixel);
  6. bool CompareColour(RGBQUAD *pPixels, int height, int width, int x, int y);
  7. void ScanBMPHorizontal(ScanContents * scan);
  8. bool Aim_Bot(HWND appWnd, std::string GameWindow);
  9.  
  10. MouseCoord CurrentMouseXY(0, 0);
  11.  
  12.  
  13.  
  14. int main()
  15.  
  16. {  
  17.     std::string GameWindow = "Bloodline Champions - Version 2.7.1.0";
  18.     HWND appWnd = FindWindow(0, GameWindow.c_str()); //rgb - Windows Photo Viewer // Call of duty 4 // Counter-Strike Source
  19.     while(!appWnd)
  20.     {
  21.         system("CLS");
  22.         appWnd = FindWindow(0, GameWindow.c_str());
  23.         std::cout << "Unable to find " << GameWindow.c_str() << std::endl;
  24.         Sleep(500);
  25.     }
  26.  
  27.     POINT currentPos;
  28.     GetCursorPos(&currentPos);
  29.     CurrentMouseXY.X = currentPos.x;
  30.     CurrentMouseXY.Y = currentPos.y;
  31.  
  32.     Aim_Bot(appWnd, GameWindow);
  33.     system("pause");
  34.     return 0;
  35.  
  36. }
  37.  
  38. bool TakeScreenshot(std::string WindowToFind, BITMAP &bm, HBITMAP &hbmap, BITMAPINFO &bmi, HDC &hdcShot, HBITMAP &hBitmapOld, HWND &hwnd)
  39. {
  40.  
  41.  
  42.  
  43.     RECT rc;
  44.  GetWindowRect(hwnd, &rc);
  45.  
  46.  hdcShot = CreateCompatibleDC(0);
  47.  hbmap = CreateCompatibleBitmap(GetDC(0), rc.right - rc.left, rc.bottom - rc.top);
  48.  SelectObject(hdcShot, hbmap);
  49.  
  50.  BitBlt(hdcShot, 0, 0, rc.right - rc.left, rc.bottom - rc.top, GetDC(hwnd), 0, 0, SRCCOPY);
  51.     if (!GetObject(hbmap, sizeof(BITMAP), (LPSTR)&bm))
  52.         return false;
  53.     int bitsPerPixel = bm.bmBitsPixel;
  54.  
  55.     if (bitsPerPixel != 32 || bm.bmPlanes != 1)
  56.         return false;
  57.  
  58.     SetupBitmapInfo(bmi, bm.bmWidth, bm.bmHeight, bitsPerPixel);
  59.     return true;
  60. }
  61. bool Aim_Bot(HWND appWnd, std::string GameWindow)
  62. {
  63.     RECT rcWindow;
  64.     GetWindowRect(appWnd, &rcWindow);
  65.  
  66.     BITMAP bm;
  67.     HBITMAP hbmap;
  68.     HBITMAP hBitmapOld;
  69.     BITMAPINFO bmi;
  70.     HDC hdcShot;
  71.     HDC hdcScreen;
  72.  
  73.     RGBQUAD * pPixels;
  74.  
  75.     int TimeTakenScreenAndScan;
  76.     while(true)
  77.     {
  78.         //only allow pressing with a x ms difference
  79.         if(!GetAsyncKeyState('X')) //VK_RBUTTON
  80.         {
  81.             TimeTakenScreenAndScan = clock();
  82.             //get all contents of our screen and store them in bm
  83.             if(!TakeScreenshot(GameWindow, bm, hbmap, bmi, hdcShot, hBitmapOld, appWnd))
  84.                 break;
  85.  
  86.             ////NEED TO CALL THESE AGAIN FOR THE SCREENSHOT TO WORK PROPERLY, screenshotception
  87.             HBITMAP hbmapNew = CreateCompatibleBitmap(hdcShot, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top);
  88.  
  89.             HDC hdcShotNew = CreateCompatibleDC(hdcShot);
  90.  
  91.             HBITMAP OldBmp  = (HBITMAP) SelectObject(hdcShotNew, hbmapNew);
  92.  
  93.             //store our screenshot FROM TO, storing just the size of the window Keeping resource allocation down by a couple of 100,000 pixels
  94.             BitBlt(hdcShotNew, 0, 0, rcWindow.right - rcWindow.left/*Window WIDTH*/, rcWindow.bottom - rcWindow.top/*Window HEIGHT*/
  95.                 , hdcShot, 0, 0, SRCCOPY);
  96.  
  97.             pPixels = new RGBQUAD[bm.bmWidth * bm.bmHeight];
  98.             if (!pPixels) return false;
  99.  
  100.             SelectObject(hdcShotNew, OldBmp);
  101.  
  102.             if (!GetDIBits(hdcShotNew, hbmapNew, 0, bm.bmHeight, pPixels, &bmi, DIB_RGB_COLORS))
  103.             {
  104.                 ReleaseDC(appWnd, hdcShot);
  105.                 delete [] pPixels;
  106.                 return false;
  107.             }
  108.             ReleaseDC(appWnd, hdcShot);
  109.  
  110.             ScanContents scanContentsMain(bm, rcWindow, pPixels);
  111.  
  112.             ScanBMPHorizontal(&scanContentsMain);
  113.             //system("pause");
  114.  
  115.             if(pPixels)free(pPixels);
  116.             SelectObject(hdcShot, hBitmapOld);
  117.             DeleteObject(hbmap);
  118.             DeleteDC(hdcShot);
  119.             DeleteObject(hbmapNew);
  120.             DeleteObject(OldBmp);
  121.             DeleteDC(hdcShotNew);
  122.                     //  std::cout << "out of scan, took " << clock() - TimeTakenScreenAndScan << " milliseconds" << std::endl;
  123.         }
  124.     }
  125. }
  126.  
  127. void SetupBitmapInfo(BITMAPINFO &bmi, int bWidth, int bHeight, int bitsPerPixel)
  128. {
  129.     bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  130.     bmi.bmiHeader.biWidth = bWidth;
  131.     bmi.bmiHeader.biHeight = bHeight;
  132.     bmi.bmiHeader.biPlanes = 1;
  133.     bmi.bmiHeader.biBitCount = bitsPerPixel;
  134.     bmi.bmiHeader.biCompression = BI_RGB;
  135.     bmi.bmiHeader.biSizeImage = 0;
  136. }
  137.  
  138.  
  139.     void ScanBMPHorizontal(ScanContents * scan)
  140.     {
  141.         for(int y = (scan->RcWindow.bottom - scan->RcWindow.top)/4;
  142.             y < ((scan->RcWindow.bottom - scan->RcWindow.top) - (scan->RcWindow.bottom - scan->RcWindow.top)/3.5); y++)
  143.         {
  144.             for(int x = (scan->RcWindow.right - scan->RcWindow.left)/4;
  145.             x < ((scan->RcWindow.right - scan->RcWindow.left) - (scan->RcWindow.right - scan->RcWindow.left)/4); x++)
  146.             {
  147.             //  SetCursorPos(x+scan->RcWindow.left, (y+4)+scan->RcWindow.top);
  148.  
  149.                 if(CompareColour(scan->PPixels, scan->Bm.bmHeight, scan->Bm.bmWidth, x, y))
  150.                 {
  151.                     SetCursorPos(x+scan->RcWindow.left, (y+4)+scan->RcWindow.top);
  152.  
  153.                     POINT currentPos;
  154.                     GetCursorPos(&currentPos);
  155.  
  156.                     //ShootBot(x+scan->RCWindow.left, y+scan->RcWindow.top);
  157.  
  158.                     CurrentMouseXY.X = currentPos.x;
  159.                     CurrentMouseXY.Y = currentPos.y;
  160.                     return;
  161.                 }
  162.             }
  163.  
  164.         }
  165.  
  166.  
  167.     }
  168.  
  169.     bool CompareColour(RGBQUAD * pPixels, int height, int width, int x, int y)
  170.     {
  171.         int p = (height-y-1)*width+x;
  172.  
  173.         //std::cout << (int)pPixels[p].rgbRed << ", " << (int)pPixels[p].rgbGreen << ", " << (int)pPixels[p].rgbBlue  << std::endl;
  174.         if((int)pPixels[p].rgbRed < 30 && (int)pPixels[p].rgbGreen < 30 && (int)pPixels[p].rgbBlue > 215)
  175.         {
  176.             //std::cout << "Found color" << std::endl;
  177.             //system("pause");
  178.             return true;
  179.         }
  180.  
  181.         if(GetAsyncKeyState(VK_DELETE))
  182.         {
  183.             exit(0);
  184.         }
  185.         return false;
  186.        
  187.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement