Advertisement
captmicro

Untitled

Apr 13th, 2013
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.26 KB | None | 0 0
  1. #include "main.h"
  2. #include "../keys.h"
  3.  
  4. int main(char argv[][], int argc)
  5. {
  6.     HWND hM = NULL;
  7.     do {
  8.         hM = FindWindowA(NULL, "Minesweeper");
  9.     } while (hM == NULL);
  10.  
  11.     HANDLE outfile = NULL;
  12.     outfile = CreateFile("minemap.txt", GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
  13.     char newline = '\n';
  14.    
  15.     RECT rM, rM2;
  16.     GetClientRect(hM, &rM);
  17.     GetWindowRect(hM, &rM2);
  18.     POINT pM; pM.x = 0; pM.y = 0;
  19.     ClientToScreen(hM, &pM);
  20.     rM.left = pM.x; rM.top = pM.y;
  21.     MoveMouse(rM.left, rM.top);
  22.  
  23.     PressKey(hM, KEY_X);
  24.     PressKey(hM, KEY_Y);
  25.     PressKey(hM, KEY_Z);
  26.     PressKey(hM, KEY_Z);
  27.     PressKey(hM, KEY_Y);
  28.     PressKey(hM, VK_SHIFT);
  29.  
  30.     //Init shit
  31.     int startX = 20, startY = 63;
  32.     int incX = 16, incY = 16;
  33.     int rows = Xatoi(argv[1]);
  34.     int columns = Xatoi(argv[2]);
  35.     int rowIdx = 0, columnIdx = 0;
  36.     int currentIsMine = FALSE;
  37.     int sleepTime = Xatoi(argv[3]);
  38.     int doRealSolve = Xatoi(argv[4]);
  39.     //End Init
  40.  
  41.     Sleep(1000);
  42.  
  43.     SetFocus(hM);
  44.  
  45.     for (; columnIdx < columns; ++columnIdx)
  46.     {
  47.         for (; rowIdx < rows; ++rowIdx)
  48.         {
  49.             if (GetAsyncKeyState(VK_END)) { break; }
  50.             MoveMouseInWindow(hM, startX + (rowIdx*incX), startY + (columnIdx*incY));
  51.             ClickMouse(3, 10); //*** Pixel doesnt change without this ***
  52.             currentIsMine = IsMine();
  53.             WriteFile(outfile, &currentIsMine, sizeof(currentIsMine), NULL, NULL);
  54.             if (doRealSolve && !currentIsMine) { ClickMouse(1, 5); }
  55.             Sleep(sleepTime);
  56.         }
  57.         if (GetAsyncKeyState(VK_END)) { break; }
  58.         WriteFile(outfile, &newline, sizeof(newline), NULL, NULL);
  59.         rowIdx = 0;
  60.     }
  61.  
  62.     CloseHandle(outfile);
  63.     return 0;
  64. }
  65.  
  66. int IsMine()
  67. {
  68.     HDC dc = GetDC(0);
  69.     COLORREF pixel = GetPixel(dc, 0, 0);
  70.     BYTE r = GetRValue(pixel);
  71.     BYTE g = GetGValue(pixel);
  72.     BYTE b = GetBValue(pixel);
  73.     if (r==255 && g == 255 && b == 255)
  74.     {
  75.         return FALSE;
  76.     }
  77.     return TRUE;
  78. }
  79.  
  80. void ClickMouse(int btn, int sleep)
  81. {
  82.     switch(btn)
  83.     {
  84.         case 1:
  85.             mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
  86.             Sleep(sleep);
  87.             mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
  88.         case 2:
  89.             mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
  90.             Sleep(sleep);
  91.             mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
  92.         case 3:
  93.             mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0);
  94.             Sleep(sleep);
  95.             mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0);
  96.     }
  97. }
  98.  
  99. void MoveMouseInWindow(HWND window, int x, int y)
  100. {
  101.     POINT pM; pM.x = x; pM.y = y;
  102.     ClientToScreen(window, &pM);
  103.     SetCursorPos((int)pM.x, (int)pM.y);
  104. }
  105.  
  106. void MoveMouse(int x, int y)
  107. {
  108.     POINT moveTo;
  109.     moveTo.x = x;
  110.     moveTo.y = y;
  111.     SetCursorPos((int)moveTo.x, (int)moveTo.y);
  112. }
  113.  
  114. void PressKey(HWND window, BYTE key)
  115. {
  116.     PostMessage(window, WM_KEYDOWN, key, 1);
  117. }
  118.  
  119. int Xatoi(char const *str)
  120. {
  121.     int result = 0;
  122.     while( char c = *str++ )
  123.         result = result*10 + (c-'0');
  124.     return result;
  125. }
  126.  
  127. void Xitoa(int n, char s[])
  128. {
  129.     int i, sign;
  130.  
  131.     if ((sign = n) < 0)  /* record sign */
  132.     n = -n;          /* make n positive */
  133.     i = 0;
  134.     do {       /* generate digits in reverse order */
  135.         s[i++] = n % 10 + '0';   /* get next digit */
  136.     } while ((n /= 10) > 0);     /* delete it */
  137.     if (sign < 0)
  138.         s[i++] = '-';
  139.     s[i] = '\0';
  140.     Xreverse(s);
  141. }
  142. void Xreverse(char s[])
  143. {
  144.     int i, j;
  145.     char c;
  146.  
  147.     for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
  148.         c = s[i];
  149.         s[i] = s[j];
  150.         s[j] = c;
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement