Advertisement
hoosier18

Untitled

Feb 22nd, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.68 KB | None | 0 0
  1. #include "ScanContents.h"
  2.  
  3.  
  4. bool TakeScreenshot(std::string WindowToFind, BITMAP &bm, HBITMAP &hbmap, BITMAPINFO &bmi, HDC &hdcShot,
  5. HBITMAP &hbitmapOld, HWND &hwnd);
  6.  
  7.  
  8.  
  9.  
  10. void SetupBitmapInfo(BITMAPINFO &bmi, int bWidth, int bHeight, int bitsPerPixel);
  11. bool CompareColour(RGBQUAD * pPixels, int height, int width, int x, int y);
  12. void ScanBMP(ScanContents * scan);
  13. bool Aim_Bot(HWND appWnd, std::string GameWindow);
  14. MouseCoord CurrentMouseXY(0, 0);
  15.  
  16.  
  17. int main()
  18. {
  19. std::string GameWindow = "rgb - Windows Photo Viewer";  //Counter-Strike Source      
  20. HWND appWnd = FindWindow(0, GameWindow.c_str());
  21.  
  22.  
  23. while(!appWnd)
  24. {
  25. system("CLS");
  26. HWND appWnd = FindWindow(0, GameWindow.c_str());
  27. std::cout << "Unable to find " << GameWindow.c_str() <<std::endl;
  28. Sleep(500);
  29. }
  30.  
  31.  
  32. POINT currentPos;
  33. GetCursorPos(& currentPos);
  34. CurrentMouseXY.X = currentPos.x;
  35. CurrentMouseXY.Y = currentPos.y;
  36.  
  37.  
  38. Aim_Bot(appWnd, GameWindow);
  39. system("Pause");
  40. return 0;
  41. }
  42.  
  43.  
  44. bool TakeScreenshot(std::string WindowToFind, BITMAP &bm, HBITMAP &hbmap, BITMAPINFO &bmi, HDC &hdcShot,
  45. HBITMAP &hbitmapOld, HWND &hwnd)
  46.  
  47.  
  48. {
  49. RECT rc;
  50. GetWindowRect(hwnd, &rc);
  51.  
  52.  
  53. hdcShot = CreateCompatibleDC(0);
  54. hbmap = CreateCompatibleBitmap(GetDC(0), rc.right - rc.left, rc.bottom - rc.top);
  55. SelectObject(hdcShot, hbmap);
  56.  
  57.  
  58. BitBlt(hdcShot, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
  59. GetDC(0),rc.left,rc.top, SRCCOPY);
  60.  
  61.  
  62.  
  63. if(!GetObject(hbmap, sizeof(BITMAP), (LPSTR)&bm))
  64. return false;
  65.  
  66.  
  67. int bitsPerPixel = bm.bmBitsPixel;
  68.  
  69.  
  70. if(bitsPerPixel != 32 || bm.bmPlanes != 1)
  71. return false;
  72.  
  73.  
  74. SetupBitmapInfo(bmi, bm.bmWidth, bm.bmHeight, bitsPerPixel);
  75. return true;
  76. }
  77.  
  78.  
  79. bool Aim_Bot(HWND appWnd, std::string GameWindow)
  80. {
  81. RECT rcWindow;
  82. GetWindowRect(appWnd, &rcWindow);
  83. BITMAP bm;
  84. HBITMAP hbmap;
  85. HBITMAP hbmapOld;
  86. BITMAPINFO bmi;
  87. HDC hdcShot;
  88. HDC hdfcScreen;
  89.  
  90.  
  91. RGBQUAD * pPixels;
  92.  
  93.  
  94. int TimeTakenScreenAndScan;
  95. while(true)
  96. {
  97. if(!GetAsyncKeyState('X'))
  98. {
  99.   TimeTakenScreenAndScan = clock();
  100.  
  101.  
  102. if(TakeScreenshot(GameWindow, bm, hbmap, bmi, hdcShot, hbmapOld, appWnd))
  103. break;
  104.  
  105.  
  106. HBITMAP hbmapNew = CreateCompatibleBitmap(hdcShot, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top);
  107.  
  108.  
  109. HDC hdcShotNew = CreateCompatibleDC(hdcShot);
  110.  
  111.  
  112. HBITMAP OldBmp = (HBITMAP) SelectObject(hdcShotNew, hbmapNew);
  113.  
  114.  
  115. BitBlt(hdcShotNew, 0, 0, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top,
  116. hdcShot, 0,0, SRCCOPY);
  117.  
  118.  
  119.  
  120.  
  121. pPixels = new RGBQUAD[bm.bmWidth * bm.bmHeight];
  122. if(!pPixels)return false;
  123.  
  124.  
  125. SelectObject(hdcShotNew, OldBmp);
  126.  
  127.  
  128. if(!GetDIBits(hdcShotNew, hbmapNew, 0, bm.bmHeight, pPixels, &bmi, DIB_RGB_COLORS))
  129. {
  130. ReleaseDC(appWnd, hdcShot);
  131. delete[] pPixels;
  132. return false;
  133. }
  134. ReleaseDC(appWnd, hdcShot);
  135.  
  136.  
  137. ScanContents scanContentsMain(bm,rcWindow, pPixels);
  138.  
  139.  
  140. ScanBMP(&scanContentsMain);
  141.  
  142.  
  143.  
  144.  
  145. if(pPixels)
  146. free(pPixels);
  147. SelectObject(hdcShot, hbmapOld);
  148. DeleteObject(hbmap);
  149. DeleteDC(hdcShot);
  150. DeleteObject(hbmapNew);
  151. DeleteObject(OldBmp);
  152. DeleteDC(hdcShotNew);
  153. //std::cout << "out of scan, took " << clock() - TimeTakenScreenAndScan << " milliseconds" << std::endl;
  154. }
  155. }
  156. }
  157. void SetupBitmapInfo(BITMAPINFO &bmi, int bWidth, int bHeight, int bitsPerPixel)
  158. {
  159. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  160. bmi.bmiHeader.biWidth = bWidth;
  161. bmi.bmiHeader.biHeight = bHeight;
  162. bmi.bmiHeader.biPlanes = 1;
  163. bmi.bmiHeader.biBitCount = bitsPerPixel;
  164. bmi.bmiHeader.biCompression = BI_RGB;
  165. bmi.bmiHeader.biSizeImage = 0;
  166. }
  167. void ShootBot(int x, int y)
  168. {
  169. mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
  170. mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
  171. }
  172.  
  173.  
  174. void ScanBMP(ScanContents * scan)
  175. {
  176. for(int y = (scan ->RcWindow.bottom - scan->RcWindow.top)/4;
  177. y < ((scan->RcWindow.bottom - scan->RcWindow.top) - (scan->RcWindow.bottom - scan->RcWindow.top)/3.5);
  178. y++)
  179.  
  180.  
  181. {
  182. for(int x = (scan ->RcWindow.right - scan->RcWindow.left)/4;
  183. x < ((scan->RcWindow.right - scan->RcWindow.left) - (scan->RcWindow.right - scan->RcWindow.left)/4);
  184. x++)
  185. {
  186.     SetCursorPos(x+scan->RcWindow.left, (y+4)+scan->RcWindow.top);
  187.  
  188.  
  189.  
  190.  
  191. if(CompareColour(scan-> PPixels, scan->Bm.bmHeight, scan ->Bm.bmWidth, x, y))
  192. {
  193. //SetCursorPos(x+scan->RcWindow.left, (y+4)+scan->RcWindow.top);
  194.  
  195.  
  196. POINT currentPos;
  197. GetCursorPos(&currentPos);
  198.  
  199.  
  200.  //ShootBot(x+scan->RcWindow.left, y+scan->RcWindow.top);
  201.  
  202.  
  203. CurrentMouseXY.X = currentPos.x;
  204. CurrentMouseXY.Y = currentPos.y;
  205. return;
  206. }
  207. }
  208. }
  209. }
  210. bool CompareColour(RGBQUAD * pPixels, int height, int width, int x, int y)
  211. {
  212.  
  213.  
  214. int p = (height-y-1)*width+x;
  215.  
  216.  
  217. if((int)pPixels[p].rgbRed > 215 && (int)pPixels[p].rgbGreen < 30 && (int)pPixels[p].rgbBlue < 30)
  218. {
  219. return true;
  220.  
  221.  
  222.  
  223.  
  224. }
  225.  
  226.  
  227. if(GetAsyncKeyState(VK_DELETE))
  228. {
  229. exit(0);
  230. }
  231. return false;
  232.  
  233.  
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement