ryonadv

Untitled

Sep 29th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1. #include "ScanContents.h"
  2.  
  3. bool TakeScreenshot(std::string WindowToFind, BITMAP &bm, HBITMAP &hbmap, BITMAPINFO &bmi, HDC &hdcShot, HBITMAP &hbitmapOld, HWND &hwnd);
  4.  
  5. void SetupBitmapInfo(BITMAPINFO &bmi, int bWitdth, int bHeight, int bitsPerPixel);
  6. bool CompareColour(RGBQUAD * pPixels, int height, int width, int x, int y);
  7. void ScanBMP(ScanContents * scan);
  8. bool Aim_Bot(HWND appWnd, std::string GameWindow);
  9. MouseCoord CurrentMouseXY(0, 0);
  10.  
  11. int main()
  12. {
  13. std::string GameWindow = "Hero OnLine";
  14. HWND appWnd = FindWindow(0, GameWindow.c_str());
  15.  
  16. while(!appWnd)
  17. {
  18. std::cout << "Unable to find" << GameWindow.c_str() << std::endl;
  19. Sleep(500);
  20. }
  21.  
  22. POINT currentPos;
  23. GetCursorPos(& currentPos);
  24. CurrentMouseXY.X = currentPos.x;
  25. CurrentMouseXY.Y = currentPos.y;
  26.  
  27. Aim_Bot(appWnd, GameWindow);
  28. system("PAUSE");
  29. return 0;
  30. }
  31.  
  32. bool TakeScreenshot(std::string WindowToFind, BITMAP &bm, HBITMAP &hbmap, BITMAPINFO &bmi, HDC &hdcShot, HBITMAP &hbitmapOld, HWND &hwnd)
  33. {
  34. RECT rc;
  35. GetWindowRect(hwnd, &rc);
  36.  
  37. hdcShot = CreateCompatibleDC(0);
  38. hbmap = CreateCompatibleBitmap(GetDC(0), rc.right - rc.left, rc.bottom - rc.top);
  39. SelectObject(hdcShot, hbmap);
  40.  
  41. BitBlt(hdcShot, 0, 0, rc.right - rc.left, rc.bottom - rc.top, hdcShot, rc.left, rc.top, SRCCOPY);
  42.  
  43. if(!GetObject(hbmap, sizeof(BITMAP), (LPSTR)&bm))
  44. return false;
  45.  
  46. int bitsPerPixel = bm.bmBitsPixel;
  47.  
  48. if(bitsPerPixel != 32 || bm.bmPlanes != 1)
  49. return false;
  50.  
  51. SetupBitmapInfo(bmi, bm.bmWidth, bm.bmHeight, bitsPerPixel);
  52. return true;
  53.  
  54. }
  55.  
  56. bool Aim_Bot(HWND appWnd, std::string GameWindow)
  57. {
  58. RECT rcWindow;
  59. GetWindowRect(appWnd, &rcWindow);
  60.  
  61. BITMAP bm;
  62. HBITMAP hbmap;
  63. HBITMAP hBitmapOld;
  64. BITMAPINFO bmi;
  65. HDC hdcShot;
  66. HDC hdcScreen;
  67.  
  68. RGBQUAD *pPixels;
  69. //Do things with bits here
  70. int TimeTakenScreenAndScan;
  71.  
  72. while(true)
  73. {
  74. //only allow pressing with a x ms difference
  75. if(!GetAsyncKeyState('X')) //VK_RBUTTON
  76. {
  77. TimeTakenScreenAndScan = clock();
  78. //get all contents of our screen and store them in bm
  79. if(!TakeScreenshot(GameWindow, bm, hbmap, bmi, hdcShot, hBitmapOld, appWnd))
  80. break;
  81.  
  82. ////NEED TO CALL THESE AGAIN FOR THE SCREENSHOT TO WORK PROPERLY, screenshotception
  83. HBITMAP hbmapNew = CreateCompatibleBitmap(hdcShot, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top);
  84.  
  85. HDC hdcShotNew = CreateCompatibleDC(hdcShot);
  86.  
  87. HBITMAP OldBmp = (HBITMAP) SelectObject(hdcShotNew, hbmapNew);
  88.  
  89. //store our screenshot FROM TO, storing just the size of the window Keeping resource allocation down by a couple of 100,000 pixels
  90. BitBlt(hdcShotNew, 0, 0, rcWindow.right - rcWindow.left/*Window WIDTH*/, rcWindow.bottom - rcWindow.top/*Window HEIGHT*/
  91. , hdcShot, 0, 0, SRCCOPY);
  92.  
  93. //--TOOK ABOUT 50 milliSECONDS TO TAKE SCREENSHOT AND GET HERE--, with improvements approximately 40 ms
  94. //std::cout << "Took screenshot in " << clock() - TimeTakenScreenAndScan << " milliseconds" << std::endl;
  95. pPixels = new RGBQUAD[bm.bmWidth * bm.bmHeight];
  96. if (!pPixels) return false;
  97.  
  98. SelectObject(hdcShotNew, OldBmp);
  99.  
  100. //HDC hdc = GetDC(HWND_DESKTOP);
  101. if (!GetDIBits(hdcShotNew, hbmapNew, 0, bm.bmHeight, pPixels, &bmi, DIB_RGB_COLORS))
  102. {
  103. ReleaseDC(appWnd, hdcShot);
  104. delete [] pPixels;
  105. return false;
  106. }
  107. ReleaseDC(appWnd, hdcShot);
  108.  
  109. ScanContents scanContentsMain(bm, rcWindow, pPixels);
  110.  
  111.  
  112. //system("pause");
  113.  
  114. //CURRENTLY AT 66 MILLISECONDS PER SCAN(A PROBLEM)
  115. //IMPROVED TO BETWEEN 40-50 MS WITH FOCUSED SCREENSHOTS, E.G. storing the games screen only instead of the whole desktop
  116.  
  117.  
  118. //CHECK IF OUR THREADS are still running and i+f NOT then we allow player to scan aimbot again
  119.  
  120. //system("pause");
  121. //if we ended our scan we free up the memory for our next screenshot
  122.  
  123. //free our memory again or head on to crash town
  124. if(pPixels)free(pPixels);
  125. SelectObject(hdcShot, hBitmapOld);
  126. DeleteObject(hbmap);
  127. DeleteDC(hdcShot);
  128. DeleteObject(hbmapNew);
  129. DeleteObject(OldBmp);
  130. DeleteDC(hdcShotNew);
  131. // std::cout << "out of scan, took " << clock() - TimeTakenScreenAndScan << " milliseconds" << std::endl;
  132. }
  133. //std::cout << "NORMAL Scan " << " took " << clock() - TimeTakenScreenAndScan << " ms to complete" << std::endl;
  134. }
  135. }
  136.  
  137. void SetupBitmapInfo(BITMAPINFO &bmi, int bWidth, int bHeight, int bitsPerPixel)
  138. {
  139. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  140. bmi.bmiHeader.biWidth = bWidth;
  141. bmi.bmiHeader.biHeight = bHeight;
  142. bmi.bmiHeader.biPlanes = 1;
  143. bmi.bmiHeader.biBitCount = bitsPerPixel;
  144. bmi.bmiHeader.biCompression = BI_RGB;
  145. bmi.bmiHeader.biSizeImage = 0;
  146.  
  147. }
  148.  
  149. void ShootBot(int x, int y)
  150. {
  151. mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
  152. mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
  153. }
  154.  
  155. void ScanBMP(ScanContents * scan)
  156. {
  157. for(int y = (scan->RcWindow.bottom - scan->RcWindow.top)/4;
  158. y < ((scan->RcWindow.bottom - scan->RcWindow.top) - (scan->RcWindow.bottom - scan->RcWindow.top)/3.5);
  159. y++)
  160. {
  161. for(int x = (scan->RcWindow.right - scan->RcWindow.left)/4;
  162. x < ((scan->RcWindow.right - scan->RcWindow.left) - (scan->RcWindow.right - scan->RcWindow.left)/4);
  163. x++)
  164. {
  165. if(CompareColour(scan->PPixels, scan->Bm.bmHeight, scan->Bm.bmWidth, x, y))
  166. {
  167. SetCursorPos(x+scan->RcWindow.left, (y+4)+scan->RcWindow.top);
  168.  
  169. POINT currentPos;
  170. GetCursorPos(&currentPos);
  171.  
  172. //ShootBot(x+scan->RcWindow.left, y+scan->RcWindow.top);
  173.  
  174. CurrentMouseXY.X = currentPos.x;
  175. CurrentMouseXY.Y = currentPos.y;
  176. return;
  177. }
  178. }
  179. }
  180. }
  181. bool CompareColour(RGBQUAD * pPixels, int height, int width, int x, int y)
  182. {
  183. int p = (height-y-1)*width+x;
  184.  
  185. if((int)pPixels[p].rgbRed > 215 && (int)pPixels[p].rgbGreen < 30 && (int)pPixels[p].rgbBlue < 30)
  186. {
  187. return true;
  188. }
  189.  
  190. if(GetAsyncKeyState(VK_DELETE))
  191. {
  192. exit(0);
  193. }
  194. return false;
  195. }
Add Comment
Please, Sign In to add comment