Advertisement
lynnxx

Main threaded

Jan 4th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "ScanContents.h"
  2.  
  3. //-----------------------------------THIS IS THE LATEST VERSION USE THIS--------------------------------
  4. //INSTRUCTIONS ON HOW TO USE:
  5. //1- Set up chams, load up game
  6. //2- turn this hack on
  7. //3- detect based on colour CURRENTLY BLUE
  8. //4-play game and trigger with specific key CURRENTLY RIGHT MOUSE
  9.  
  10.  
  11.  
  12.  
  13. bool TakeScreenshot(std::string WindowToFind, BITMAP &bm, HBITMAP &hbmap, BITMAPINFO &bmi, HDC &hdcShot, HBITMAP &hBitmapOld, HWND &hwnd);
  14. void SetupBitmapInfo(BITMAPINFO &bmi, int bWidth, int bHeight, int bitsPerPixel);
  15. bool CompareColour(RGBQUAD *pPixels, int height, int width, int x, int y);
  16. void ScanBMPHorizontal(ScanContents * scan);
  17. //add after BASIC CONCEPT
  18. bool Aim_BotThr(AimbotThr * aimThr1);
  19.  
  20. //heres our global mouse XY that remembers where the mouse last was
  21. //-----
  22. MouseCoord CurrentMouseXY(0, 0);
  23.  
  24. bool CompareColour(RGBQUAD *pPixels, int height, int width, int x, int y)
  25. {
  26.     int p = (height-y-1)*width+x; // upside down
  27.     //int r = (int)pPixels[p].rgbRed;
  28.     //int g = (int)pPixels[p].rgbGreen;
  29.     //int b = (int)pPixels[p].rgbBlue;
  30.     //std::cout << (int)pPixels[p].rgbRed << ", " << (int)pPixels[p].rgbGreen << ", " << (int)pPixels[p].rgbBlue  << std::endl;
  31.     //SetCursorPos(x, y);
  32.     //PINK
  33.     //CSS BLUE
  34.     if((int)pPixels[p].rgbRed < 30 && (int)pPixels[p].rgbGreen < 30 && (int)pPixels[p].rgbBlue > 215)
  35.     //css red
  36.     //if((int)pPixels[p].rgbRed > 215 && (int)pPixels[p].rgbGreen < 30 && (int)pPixels[p].rgbBlue < 30)
  37.     {
  38.         //std::cout << "FOUND PINK" << std::endl;
  39.         //system("PAUSE");
  40.         //std::cout << r << ", " << g << ", " << b  << std::endl;
  41.         //std::cout << "Found color" << std::endl;
  42.  
  43.         return true;
  44.     }
  45.     //else std::cout << "NOT FOUND PINK" << std::endl;
  46.     if(GetAsyncKeyState(VK_ESCAPE))
  47.     {
  48.         exit(0);
  49.     }
  50.     return false;
  51. }
  52.  
  53.  
  54. void ShootBot(int x, int y)
  55. {
  56.     mouse_event(MOUSEEVENTF_LEFTDOWN,x, y,0,0);
  57.     mouse_event(MOUSEEVENTF_LEFTUP,x, y,0,0);
  58. }
  59.  
  60.  
  61. //OUR MAIN SCANNER LOOP
  62. void ScanBMPHorizontal(ScanContents * scan)
  63. {
  64.     int startedInScanTime = clock();
  65.     //scan until it reaches the limits/bounds of the game window
  66.    
  67.     //THIS CAN BE DIVIDED BY ANY NUMBER, 5 WAS JUST THE CHOICE THAT FELT RIGHT FOR ME, E.G. DOESNT SCAN TOO MUCH OF THE SCREEN. Lower numbers cover
  68.     //more of the game
  69.     //Just like well do below with the X, here we start scanning at about 1/4 of the screen, this allows us to scan the screen much faster
  70.     //and makes our aimbot much more efficient
  71.     for(int y = (scan->RcWindow.bottom - scan->RcWindow.top)/4;
  72.         y < ((scan->RcWindow.bottom - scan->RcWindow.top)-(scan->RcWindow.bottom - scan->RcWindow.top)/3.5);
  73.         y++)
  74.     //for(scan->Y = scan->StartingY-((int)(scan->RcWindow.bottom - scan->RcWindow.top)/5)/*GET'S THE WINDOW'S HEIGHT/5*/; scan->Y < scan->StartingY + ((int)(scan->RcWindow.bottom - scan->RcWindow.top)/5); scan->Y+=3)
  75.     {
  76.         //SetCursorPos(scan->X, scan->Y);
  77.         //3 because we are checking RGB every time
  78.         //ONLY SCAN about 2-3/4 of the screen, this way scans are much faster and we have much more control over the aimbot
  79.         //WE START X at about 1/4 of the screen and stop at 3/4, this way it can work at any window resolution
  80.         for(int x = (int)((scan->RcWindow.right - scan->RcWindow.left)/4)/*+15*/;
  81.             x < (int)((scan->RcWindow.right - scan->RcWindow.left)-(scan->RcWindow.right - scan->RcWindow.left)/4);
  82.             x ++)
  83.         {
  84.             //SetCursorPos(scan->X+scan->RcWindow.left, scan->Y+scan->RcWindow.top);
  85.             //Sleep(1);
  86.             //CHECK IF OUR CHOSEN COLOUR = TRUE
  87.             if(CompareColour(scan->PPixels, scan->Bm.bmHeight, scan->Bm.bmWidth, x, y))
  88.             {
  89.                 int z = x;
  90.                 //the width - itself/2
  91.                 while(z < (int)((scan->RcWindow.right - scan->RcWindow.left)-(scan->RcWindow.right - scan->RcWindow.left)/4))
  92.                 {
  93.                     //comment this after
  94.                     //SetCursorPos(z, scan->Y);
  95.                     //search until our color is not the same and then DEFINE A CENTER POINT from the point found
  96.                     //within the for loop(POINT 1 = scan->X to POINT 2 = z (Center  = z - (z - scan->X)/2))
  97.                     //the pixel between point 2 and point 1
  98.                     if(!CompareColour(scan->PPixels, scan->Bm.bmHeight, scan->Bm.bmWidth, z, y))
  99.                     {
  100.                         break;
  101.                     }
  102.                     z++; //COULD ALSO BE 3, 2 is used because i am looking for the exact center point of the first and last pixel
  103.                 }
  104.                 //MouseCoord coord((z -( z - scan->X)/2)+scan->RcWindow.left means position CURSOR ON CENTER PIXEL(BETWEEN 1st and last), scan->Y+scan->RcWindow.top);
  105.                 //4 IS A PERSONAL CHOICE, THIS MEANS AIM 4 pixels below where the top found pixel is
  106.                 //that is usually the head, so i prefer to give a shot square in the face
  107.                 //as the normal shot may skim the top of the head and miss
  108.                 //this way there could be problems with the array, but not with our design
  109.                 SetCursorPos((z -( z - x)/2)+scan->RcWindow.left, (y+4)+scan->RcWindow.top);
  110.                 //Sleep(85);
  111.                
  112.                 //SmoothMouseMovement((z -( z - x)/2)+scan->RcWindow.left, y+scan->RcWindow.top);
  113.                 //system("pause");
  114.                 //SHOOT AT THE EXACT CENTER POINT of the color
  115.  
  116.                 //ADD AFTER BASIC CONCEPT
  117.                 //GET OUR CURRENT MOUSE POSITION AND COMPARE TO PREVIOUS
  118.                 POINT currentPos;
  119.                 GetCursorPos(&currentPos);
  120.                 //~ more or less in the same place as the last position therefor we shoot
  121.                 //this tells us that the mouse didnt have to move much and is VERY CLOSE to
  122.                 //our target, this stops us from shooting during aiming. Forcing us to conserve
  123.                 //ammo and increasing accuracy 60% of the time works every time
  124.                 //+ X is just a personal choice, this means if its within X pixels of the last scan then shoot
  125.                 //just checking if the mouse is within a nice range
  126.                 //2 IS A GOOD NUMBER FOR SNIPERS
  127.  
  128.                 //if(currentPos.x < CurrentMouseXY.X + 4 && currentPos.x > CurrentMouseXY.X-4 &&
  129.                 //  currentPos.y < CurrentMouseXY.Y + 4 && currentPos.y > CurrentMouseXY.Y-4)
  130.                 //{
  131.                     //ShootBot((z -( z - x)/2)+scan->RcWindow.left, y+scan->RcWindow.top);
  132.                 //}
  133.  
  134.                 CurrentMouseXY.X = currentPos.x;
  135.                 CurrentMouseXY.Y = currentPos.y;
  136.                 //std::cout << "Bang bang "  << std::endl;
  137.                 //*scan->ColorFoundK = true;
  138.                 return;
  139.             }
  140.         }
  141.     }
  142.     std::cout << "out of CLOCK, took " << clock() - startedInScanTime << " milliseconds" << std::endl;
  143. }
  144.  
  145.  
  146. bool Aim_BotThr(AimbotThr * aimThr1)
  147. {
  148.     RECT rcWindow;
  149.     GetWindowRect(aimThr1->AppWnd, &rcWindow);
  150.  
  151.     BITMAP bm;
  152.     HBITMAP hbmap;
  153.     HBITMAP hBitmapOld;
  154.     BITMAPINFO bmi;
  155.     HDC hdcShot;
  156.     HDC hdcScreen;
  157.  
  158.     RGBQUAD *pPixels;
  159.     //Do things with bits here
  160.     int TimeTakenScreenAndScan;
  161.     while(true)
  162.     {
  163.         //only allow pressing with a x ms difference
  164.         if(!GetAsyncKeyState('X')) //VK_RBUTTON
  165.         {
  166.             TimeTakenScreenAndScan = clock();
  167.             //get all contents of our screen and store them in bm
  168.             if(!TakeScreenshot(aimThr1->GameWindow, bm, hbmap, bmi, hdcShot, hBitmapOld, aimThr1->AppWnd))
  169.                 break;
  170.  
  171.             ////NEED TO CALL THESE AGAIN FOR THE SCREENSHOT TO WORK PROPERLY, screenshotception
  172.             HBITMAP hbmapNew = CreateCompatibleBitmap(hdcShot, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top);
  173.  
  174.             HDC hdcShotNew = CreateCompatibleDC(hdcShot);
  175.  
  176.             HBITMAP OldBmp  = (HBITMAP) SelectObject(hdcShotNew, hbmapNew);
  177.  
  178.             //store our screenshot FROM TO, storing just the size of the window Keeping resource allocation down by a couple of 100,000 pixels
  179.             BitBlt(hdcShotNew, 0, 0, rcWindow.right - rcWindow.left/*Window WIDTH*/, rcWindow.bottom - rcWindow.top/*Window HEIGHT*/
  180.                 , hdcShot, 0, 0, SRCCOPY);
  181.  
  182.             //--TOOK ABOUT 50 milliSECONDS TO TAKE SCREENSHOT AND GET HERE--, with improvements approximately 40 ms
  183.             //std::cout << "Took screenshot in " << clock() - TimeTakenScreenAndScan << " milliseconds" << std::endl;
  184.  
  185.             pPixels = new RGBQUAD[bm.bmWidth * bm.bmHeight];
  186.             if (!pPixels) return false;
  187.  
  188.             SelectObject(hdcShotNew, OldBmp);
  189.  
  190.             //HDC hdc = GetDC(HWND_DESKTOP);
  191.             if (!GetDIBits(hdcShotNew, hbmapNew, 0, bm.bmHeight, pPixels, &bmi, DIB_RGB_COLORS))
  192.             {
  193.                 ReleaseDC(aimThr1->AppWnd, hdcShot);
  194.                 delete [] pPixels;
  195.                 return false;
  196.             }
  197.             ReleaseDC(aimThr1->AppWnd, hdcShot);
  198.  
  199.             ScanContents scanContentsMain(bm, rcWindow, pPixels);
  200.  
  201.             ScanBMPHorizontal(&scanContentsMain);
  202.             //system("pause");
  203.  
  204.         //CURRENTLY AT 66 MILLISECONDS PER SCAN(A PROBLEM)
  205.         //IMPROVED TO BETWEEN 40-50 MS WITH FOCUSED SCREENSHOTS, E.G. storing the games screen only instead of the whole desktop
  206.  
  207.  
  208.         //CHECK IF OUR THREADS are still running and i+f NOT then we allow player to scan aimbot again
  209.        
  210.         //system("pause");
  211.         //if we ended our scan we free up the memory for our next screenshot
  212.  
  213.             //free our memory again or head on to crash town
  214.             if(pPixels)free(pPixels);
  215.             SelectObject(hdcShot, hBitmapOld);
  216.             DeleteObject(hbmap);
  217.             DeleteDC(hdcShot);
  218.             DeleteObject(hbmapNew);
  219.             DeleteObject(OldBmp);
  220.             DeleteDC(hdcShotNew);
  221.                     //  std::cout << "out of scan, took " << clock() - TimeTakenScreenAndScan << " milliseconds" << std::endl;
  222.         }
  223.         //IMPROVED TO 30-40MS
  224.         //std::cout << "Scan THREADED" << " took " << clock() - TimeTakenScreenAndScan << " ms to complete" << std::endl;
  225.     }
  226. }
  227.  
  228.  
  229. bool Aim_Bot(HWND appWnd, std::string GameWindow)
  230. {
  231.     RECT rcWindow;
  232.     GetWindowRect(appWnd, &rcWindow);
  233.  
  234.     BITMAP bm;
  235.     HBITMAP hbmap;
  236.     HBITMAP hBitmapOld;
  237.     BITMAPINFO bmi;
  238.     HDC hdcShot;
  239.     HDC hdcScreen;
  240.  
  241.     RGBQUAD *pPixels;
  242.    //Do things with bits here
  243.     int TimeTakenScreenAndScan;
  244.  
  245.     while(true)
  246.     {
  247.         //only allow pressing with a x ms difference
  248.         if(!GetAsyncKeyState('X')) //VK_RBUTTON
  249.         {
  250.             TimeTakenScreenAndScan = clock();
  251.             //get all contents of our screen and store them in bm
  252.             if(!TakeScreenshot(GameWindow, bm, hbmap, bmi, hdcShot, hBitmapOld, appWnd))
  253.                 break;
  254.  
  255.             ////NEED TO CALL THESE AGAIN FOR THE SCREENSHOT TO WORK PROPERLY, screenshotception
  256.             HBITMAP hbmapNew = CreateCompatibleBitmap(hdcShot, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top);
  257.  
  258.             HDC hdcShotNew = CreateCompatibleDC(hdcShot);
  259.  
  260.             HBITMAP OldBmp  = (HBITMAP) SelectObject(hdcShotNew, hbmapNew);
  261.  
  262.             //store our screenshot FROM TO, storing just the size of the window Keeping resource allocation down by a couple of 100,000 pixels
  263.             BitBlt(hdcShotNew, 0, 0, rcWindow.right - rcWindow.left/*Window WIDTH*/, rcWindow.bottom - rcWindow.top/*Window HEIGHT*/
  264.                 , hdcShot, 0, 0, SRCCOPY);
  265.  
  266.             //--TOOK ABOUT 50 milliSECONDS TO TAKE SCREENSHOT AND GET HERE--, with improvements approximately 40 ms
  267.             std::cout << "Took screenshot in " << clock() - TimeTakenScreenAndScan << " milliseconds" << std::endl;
  268.             pPixels = new RGBQUAD[bm.bmWidth * bm.bmHeight];
  269.             if (!pPixels) return false;
  270.  
  271.             SelectObject(hdcShotNew, OldBmp);
  272.  
  273.             //HDC hdc = GetDC(HWND_DESKTOP);
  274.             if (!GetDIBits(hdcShotNew, hbmapNew, 0, bm.bmHeight, pPixels, &bmi, DIB_RGB_COLORS))
  275.             {
  276.                 ReleaseDC(appWnd, hdcShot);
  277.                 delete [] pPixels;
  278.                 return false;
  279.             }
  280.             ReleaseDC(appWnd, hdcShot);
  281.  
  282.             ScanContents scanContentsMain(bm, rcWindow, pPixels);
  283.  
  284.             ScanBMPHorizontal(&scanContentsMain);
  285.             //system("pause");
  286.  
  287.         //CURRENTLY AT 66 MILLISECONDS PER SCAN(A PROBLEM)
  288.         //IMPROVED TO BETWEEN 40-50 MS WITH FOCUSED SCREENSHOTS, E.G. storing the games screen only instead of the whole desktop
  289.  
  290.  
  291.         //CHECK IF OUR THREADS are still running and i+f NOT then we allow player to scan aimbot again
  292.        
  293.         //system("pause");
  294.         //if we ended our scan we free up the memory for our next screenshot
  295.  
  296.             //free our memory again or head on to crash town
  297.             if(pPixels)free(pPixels);
  298.             SelectObject(hdcShot, hBitmapOld);
  299.             DeleteObject(hbmap);
  300.             DeleteDC(hdcShot);
  301.             DeleteObject(hbmapNew);
  302.             DeleteObject(OldBmp);
  303.             DeleteDC(hdcShotNew);
  304.             //  std::cout << "out of scan, took " << clock() - TimeTakenScreenAndScan << " milliseconds" << std::endl;
  305.         }
  306.         //IMPROVED TO 30-40MS
  307.         std::cout << "NORMAL Scan " << " took " << clock() - TimeTakenScreenAndScan << " ms to complete" << std::endl;
  308.     }
  309. }
  310.  
  311.  
  312.  
  313.  
  314. int main()
  315. {  
  316.     std::string GameWindow = "Counter-Strike Source";
  317.     HWND appWnd = FindWindow(0, GameWindow.c_str()); //rgb - Windows Photo Viewer // Call of duty 4 // Counter-Strike Source
  318.     while(!appWnd)
  319.     {
  320.         system("CLS");
  321.         appWnd = FindWindow(0, GameWindow.c_str());
  322.         std::cout << "Unable to find " << GameWindow.c_str() << std::endl;
  323.         Sleep(500);
  324.     }
  325.     //GET OUR CURRENT MOUSE POSITION
  326.     POINT currentPos;
  327.     GetCursorPos(&currentPos);
  328.  
  329.     CurrentMouseXY.X = currentPos.x;
  330.     CurrentMouseXY.Y = currentPos.y;
  331.  
  332.  
  333.     //Thread number 1
  334.     AimbotThr aimThr1(appWnd, GameWindow);
  335.     _beginthread((void(*)(void*))Aim_BotThr, 0, (void*)&aimThr1);
  336.    
  337.     //Thread number 2
  338.     AimbotThr aimThr2(appWnd, GameWindow);
  339.     _beginthread((void(*)(void*))Aim_BotThr, 0, (void*)&aimThr2);
  340.  
  341.     //Thread number 3
  342.     AimbotThr aimThr3(appWnd, GameWindow);
  343.     _beginthread((void(*)(void*))Aim_BotThr, 0, (void*)&aimThr3);
  344.  
  345.     Aim_Bot(appWnd, GameWindow);
  346.     system("pause");
  347.     return 0;
  348. }
  349.  
  350.  
  351. void SetupBitmapInfo(BITMAPINFO &bmi, int bWidth, int bHeight, int bitsPerPixel)
  352. {
  353.    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  354.    bmi.bmiHeader.biWidth = bWidth;
  355.    bmi.bmiHeader.biHeight = bHeight;
  356.    bmi.bmiHeader.biPlanes = 1;
  357.    bmi.bmiHeader.biBitCount = bitsPerPixel;
  358.    bmi.bmiHeader.biCompression = BI_RGB;
  359.    bmi.bmiHeader.biSizeImage = 0;
  360. }
  361.  
  362.  
  363. //bool TakeScreenshot(std::string WindowToFind, BITMAP &bm, HBITMAP &hbmap, BITMAPINFO &bmi, HDC &hdcShot, HBITMAP &hBitmapOld, HDC &hdcScreen)
  364. bool TakeScreenshot(std::string WindowToFind, BITMAP &bm, HBITMAP &hbmap, BITMAPINFO &bmi, HDC &hdcShot, HBITMAP &hBitmapOld, HWND &hwnd)
  365. {
  366.     RECT rc;
  367.     //get our window's rectangle
  368.     GetWindowRect(hwnd, &rc);
  369.    hdcShot = CreateCompatibleDC(0);
  370.    hbmap = CreateCompatibleBitmap(GetDC(0), rc.right - rc.left/*Window WIDTH*/, rc.bottom - rc.top/*Window HEIGHT*/);
  371.  
  372.     SelectObject(hdcShot, hbmap);
  373.  
  374.     //store our screenshot FROM TO, storing just the size of the window Keeping resource allocation down by a couple of 100,000 pixels
  375.     BitBlt(hdcShot, 0, 0, rc.right - rc.left/*Window WIDTH*/, rc.bottom - rc.top/*Window HEIGHT*/
  376.         , GetDC(0), rc.left, rc.top, SRCCOPY);
  377.     //HERE WE decided where we want our screenshot to begin, we chose the left and top of the rectangle(window)
  378.  
  379.    if (!GetObject(hbmap, sizeof(BITMAP), (LPSTR)&bm))
  380.         return false;
  381.    int bitsPerPixel = bm.bmBitsPixel;
  382.  
  383.    if (bitsPerPixel != 32 || bm.bmPlanes != 1)
  384.         return false;
  385.  
  386.     SetupBitmapInfo(bmi, bm.bmWidth, bm.bmHeight, bitsPerPixel);
  387.     return true;
  388.  
  389. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement