Advertisement
finalshare

WinMineTrainer.cpp

Mar 17th, 2017
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.69 KB | None | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <conio.h>
  5.  
  6. //Address
  7. #define addNumRow      0x010056A8
  8. #define addNumCol      0x010056AC
  9. #define addNumFlagLeft 0x01005194
  10. #define addNumBomb     0x01005330
  11. #define addTimer       0x0100579C
  12. //End Define Address
  13.  
  14. //Array Flag
  15. #define isSafe 0xF
  16. #define isBomb 0x8F
  17. #define isOpen 0x40
  18. #define is1bomb 0x41
  19. #define is2bomb 0x42
  20. #define is3bomb 0x43
  21. #define is4bomb 0x44
  22. #define is5bomb 0x45
  23. #define is6bomb 0x46
  24. #define is7bomb 0x47
  25. #define is8bomb 0x48
  26. #define isFlag 0x8E
  27. #define unKnown 0x8D
  28. #define isExploded 0xCC
  29. #define isRevealed 0x8A
  30. //End Define Array Flag
  31.  
  32. using namespace std;
  33. void setTextColor(int k)//Change Text Color
  34. {
  35.  
  36.     HANDLE  hConsole;
  37.     hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  38.     SetConsoleTextAttribute(hConsole, k);
  39.  
  40. }
  41. BYTE readBYTE(DWORD address) {
  42.     BYTE value = 0; //Result will go here
  43.     DWORD pid;
  44.     HWND hwnd;
  45.     hwnd = FindWindow(NULL, "Minesweeper");
  46.     if (!hwnd)
  47.     {
  48.         cout << "Window not found!\n";
  49.     }
  50.     else
  51.     {
  52.         GetWindowThreadProcessId(hwnd, &pid);
  53.         HANDLE phandle = OpenProcess(PROCESS_VM_READ, 0, pid); //Tao handle va Xin phep quyen Doc
  54.         if (!phandle) //Unsuccess
  55.         {
  56.             cout << "Could not get handle!\n";
  57.         }
  58.         else
  59.         {
  60.             ReadProcessMemory(phandle, (void*)address, &value, sizeof(value), 0);
  61.         }
  62.     }
  63.     return value;
  64. }
  65. DWORD readDWORD(DWORD address) {
  66.     DWORD value = 0; //Result will go here
  67.     DWORD pid;
  68.     HWND hwnd;
  69.     hwnd = FindWindow(NULL, "Minesweeper");
  70.     if (!hwnd)
  71.     {
  72.         cout << "Window not found!\n";
  73.     }
  74.     else
  75.     {
  76.         GetWindowThreadProcessId(hwnd, &pid);
  77.         HANDLE phandle = OpenProcess(PROCESS_VM_READ, 0, pid); //Tao handle va Xin phep quyen Doc
  78.         if (!phandle)  //Unsuccess
  79.         {
  80.             cout << "Could not get handle!\n";
  81.         }
  82.         else
  83.         {
  84.                 ReadProcessMemory(phandle, (void*)address, &value, sizeof(value), 0);
  85.         }
  86.     }
  87.     return value;
  88. }
  89. DWORD getAdressOfXY(DWORD row, DWORD col) {
  90.     return (row << 5) + col + 0x1005340;
  91. }
  92.  
  93. DWORD main()
  94. {
  95.     DWORD numRow;
  96.     DWORD numCol;
  97.     DWORD numFlagLeft;
  98.     DWORD numBomb;
  99.     DWORD timer;
  100.     BYTE res;
  101.    
  102.     while ( !_kbhit() )
  103.     {
  104.         numRow = readDWORD(addNumRow);
  105.         numCol = readDWORD(addNumCol);
  106.         numFlagLeft = readDWORD(addNumFlagLeft);
  107.         numBomb = readDWORD(addNumBomb);
  108.         timer = readDWORD(addTimer);
  109.         printf("Row: %d Col: %d Bomb: %d Flag Left: %d Time: %d\n", numRow, numCol, numBomb, numFlagLeft, timer );
  110.         for (DWORD r = 1; r <= numRow; r++) {
  111.             for (DWORD c = 1; c <= numCol; c++) {
  112.  
  113.                 res = readBYTE(getAdressOfXY(r, c));
  114.                 switch (res)
  115.                 {
  116.                     case isSafe:
  117.                         printf(". ");
  118.                         break;
  119.                     case isBomb:
  120.                         setTextColor(12);
  121.                         printf("* ");
  122.                         setTextColor(15);
  123.                         break;
  124.                     case isFlag:
  125.                         setTextColor(10);
  126.                         printf("F ");
  127.                         setTextColor(15);
  128.                         break;
  129.                     case is1bomb:
  130.                         printf("1 ");
  131.                         break;
  132.                     case is2bomb:
  133.                         printf("2 ");
  134.                         break;
  135.                     case is3bomb:
  136.                         printf("3 ");
  137.                         break;
  138.                     case is4bomb:
  139.                         printf("4 ");
  140.                         break;
  141.                     case is5bomb:
  142.                         printf("5 ");
  143.                         break;
  144.                     case is6bomb:
  145.                         printf("6 ");
  146.                         break;
  147.                     case is7bomb:
  148.                         printf("7 ");
  149.                         break;
  150.                     case is8bomb:
  151.                         printf("8 ");
  152.                         break;
  153.                     case isOpen:
  154.                         printf("  ");
  155.                         break;
  156.                     case isExploded:
  157.                         setTextColor(14);
  158.                         printf("* ");
  159.                         setTextColor(15);
  160.                         break;
  161.                     case isRevealed:
  162.                         setTextColor(12);
  163.                         printf("* ");
  164.                         setTextColor(15);
  165.                         break;                 
  166.                 default:
  167.                     printf("? ");
  168.                     break;
  169.                 }//End switch
  170.             } //end for j
  171.             cout << "\n";
  172.         } //end for i
  173.  
  174.         Sleep(1000);
  175.         system("cls");
  176.     }//end while
  177.     cin.get();
  178.     return 0;
  179. }//end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement