原理
使用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获取源码并手动编译