Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "main.h"
- #include "../keys.h"
- int main(char argv[][], int argc)
- {
- HWND hM = NULL;
- do {
- hM = FindWindowA(NULL, "Minesweeper");
- } while (hM == NULL);
- HANDLE outfile = NULL;
- outfile = CreateFile("minemap.txt", GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
- char newline = '\n';
- RECT rM, rM2;
- GetClientRect(hM, &rM);
- GetWindowRect(hM, &rM2);
- POINT pM; pM.x = 0; pM.y = 0;
- ClientToScreen(hM, &pM);
- rM.left = pM.x; rM.top = pM.y;
- MoveMouse(rM.left, rM.top);
- PressKey(hM, KEY_X);
- PressKey(hM, KEY_Y);
- PressKey(hM, KEY_Z);
- PressKey(hM, KEY_Z);
- PressKey(hM, KEY_Y);
- PressKey(hM, VK_SHIFT);
- //Init shit
- int startX = 20, startY = 63;
- int incX = 16, incY = 16;
- int rows = Xatoi(argv[1]);
- int columns = Xatoi(argv[2]);
- int rowIdx = 0, columnIdx = 0;
- int currentIsMine = FALSE;
- int sleepTime = Xatoi(argv[3]);
- int doRealSolve = Xatoi(argv[4]);
- //End Init
- Sleep(1000);
- SetFocus(hM);
- for (; columnIdx < columns; ++columnIdx)
- {
- for (; rowIdx < rows; ++rowIdx)
- {
- if (GetAsyncKeyState(VK_END)) { break; }
- MoveMouseInWindow(hM, startX + (rowIdx*incX), startY + (columnIdx*incY));
- ClickMouse(3, 10); //*** Pixel doesnt change without this ***
- currentIsMine = IsMine();
- WriteFile(outfile, ¤tIsMine, sizeof(currentIsMine), NULL, NULL);
- if (doRealSolve && !currentIsMine) { ClickMouse(1, 5); }
- Sleep(sleepTime);
- }
- if (GetAsyncKeyState(VK_END)) { break; }
- WriteFile(outfile, &newline, sizeof(newline), NULL, NULL);
- rowIdx = 0;
- }
- CloseHandle(outfile);
- return 0;
- }
- int IsMine()
- {
- HDC dc = GetDC(0);
- COLORREF pixel = GetPixel(dc, 0, 0);
- BYTE r = GetRValue(pixel);
- BYTE g = GetGValue(pixel);
- BYTE b = GetBValue(pixel);
- if (r==255 && g == 255 && b == 255)
- {
- return FALSE;
- }
- return TRUE;
- }
- void ClickMouse(int btn, int sleep)
- {
- switch(btn)
- {
- case 1:
- mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
- Sleep(sleep);
- mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
- case 2:
- mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
- Sleep(sleep);
- mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
- case 3:
- mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0);
- Sleep(sleep);
- mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0);
- }
- }
- void MoveMouseInWindow(HWND window, int x, int y)
- {
- POINT pM; pM.x = x; pM.y = y;
- ClientToScreen(window, &pM);
- SetCursorPos((int)pM.x, (int)pM.y);
- }
- void MoveMouse(int x, int y)
- {
- POINT moveTo;
- moveTo.x = x;
- moveTo.y = y;
- SetCursorPos((int)moveTo.x, (int)moveTo.y);
- }
- void PressKey(HWND window, BYTE key)
- {
- PostMessage(window, WM_KEYDOWN, key, 1);
- }
- int Xatoi(char const *str)
- {
- int result = 0;
- while( char c = *str++ )
- result = result*10 + (c-'0');
- return result;
- }
- void Xitoa(int n, char s[])
- {
- int i, sign;
- if ((sign = n) < 0) /* record sign */
- n = -n; /* make n positive */
- i = 0;
- do { /* generate digits in reverse order */
- s[i++] = n % 10 + '0'; /* get next digit */
- } while ((n /= 10) > 0); /* delete it */
- if (sign < 0)
- s[i++] = '-';
- s[i] = '\0';
- Xreverse(s);
- }
- void Xreverse(char s[])
- {
- int i, j;
- char c;
- for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
- c = s[i];
- s[i] = s[j];
- s[j] = c;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement