使用CE进行扫雷
原理
使用ce進行掃描,直到找到存儲信息的位置,然后讀取就行了
具體方法
使用未知的初始值進行第一次掃描,數據類型大多是Byte,之后點第一行第一列雷,根據數據選擇變化的值或者未變化的值進行下一次掃描,直到找到存儲位置
代碼
#include <iostream> #include <conio.h> #include <windows.h>using namespace std;class Pos { public:int _x;int _y;Pos() {_x = 0;_y = 0;}Pos(int x, int y) :_x(x), _y(y) {} };// 簡單封裝下Windows API void SetMousePos(Pos pos) {SetCursorPos(pos._x, pos._y); } void MouseLeftEvent() {mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); } void MouseRightEvent() {mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); } template<typename T> void GetArr(T **&arr,int h,int w) {arr = new T *[h];for (int i = 0; i < h; ++i) {arr[i] = new T[w];}} template<typename T> void DelArr(T **&arr,int h,int w) {for (int i = 0; i < h; ++i) {delete[]arr[i];}delete arr;arr = nullptr; }int main() {// 修改cmd顯示編碼,防止中文亂碼system("chcp 65001");// 打開掃雷進程HWND handle = FindWindow(NULL,"Minesweeper");if (handle == NULL) {cout << "打開失敗" << endl;return 0;}DWORD pid;GetWindowThreadProcessId(handle, &pid);HANDLE process_handle = OpenProcess(PROCESS_ALL_ACCESS, false, pid);// 獲取掃雷的雷盤信息BYTE h, w;ReadProcessMemory(process_handle, (void*)0x01005338, &h, sizeof(h), NULL);ReadProcessMemory(process_handle, (void*)0x01005334, &w, sizeof(h), NULL);BYTE* buf = (BYTE*)malloc(h * 32);ReadProcessMemory(process_handle, (void*)0x01005361, (void*)buf, h * 32, NULL);// 獲取窗口位置,并依此移動鼠標RECT rect;GetWindowRect(handle, &rect);cout << "窗口位置:" << rect.left << "," << rect.top;cout << "行數:" << (int)h << endl;cout << "列數:" << (int)w << endl;SetMousePos(Pos(rect.left, rect.top));MouseLeftEvent();// 將鼠標移動到掃雷的左上第一個點POINT begin_pos;begin_pos.x = rect.left + 20;begin_pos.y = rect.top + 105;SetMousePos(Pos(begin_pos.x, begin_pos.y));MouseLeftEvent();Pos** mouse_pos;bool** mines;GetArr<Pos>(mouse_pos, h, w);GetArr<bool>(mines, h, w);// 將每個點的鼠標坐標都計算出來,并保存到數組中for (int i = 0; i < h; ++i) {for (int j = 0; j < w; ++j) {mouse_pos[i][j] = Pos(begin_pos.x + 16 * j, begin_pos.y + 16 * i);}}int num = 0;int i, j;BYTE* line = buf;for (i = 0; i < h; i++) {for (j = 0; j < w; j++) {if (line[j] == 0x8F) {mines[i][j] = true;num++;}printf("%2X ", line[j]);}cout << endl;line = line + 32;}cout << num << endl;num = 0;for (int i = 0; i < h; ++i) {for (int j = 0; j < w; ++j) {if (mines[i][j] == true)num++;printf("%2d", mines[i][j]);}cout << endl;}cout << num << endl;num = 0;for (int i = 0; i < h; ++i) {for (int j = 0; j < w; ++j) {SetMousePos(mouse_pos[i][j]);// 如果當前鼠標下是雷,模擬鼠標右鍵if (mines[i][j] == true) {MouseRightEvent();num++;}// 否則模擬左鍵else {MouseLeftEvent();}// Sleep(1);}}cout << num << endl;DelArr(mines,h,w);DelArr(mouse_pos, h, w);return 0; }運行結果
已知問題
- 僅適用于 Minesweeper 2000 xp 版本
題外
- ce 7.4安裝后存在捆綁軟件可以在安裝時選擇拒絕
- ce 7.4安裝時無法選擇安裝路徑,可以通過github獲取源碼并手動編譯
總結
- 上一篇: DXP 快捷键
- 下一篇: 十大MES系统排行 制造执行系统 生产管