-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathgameproc.cpp
57 lines (50 loc) · 1.6 KB
/
gameproc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<windows.h>
#include<iostream>
using namespace std;
HWND gameh;
DWORD processid = 0;
HANDLE processh = 0;
byte chessdata[11][19]; //数据保存缓冲区,假设棋盘为11*19
const char *gamename = "连连看"; //某连连看游戏名称,可通过SPY++查找
struct point { //具体使用和算法见"连连看BFS算法"
int x, y, direct;
int step, hp;
};
void readchess() { //读数据并更新
gameh = ::FindWindow(NULL, gamename);
::GetWindowThreadProcessId(gameh, &processid);
processh = ::OpenProcess(PROCESS_ALL_ACCESS, false, processid);
LPCVOID pbase = (LPCVOID)棋盘基址;
LPVOID nbuffer = (LPVOID)&chessdata;
::ReadProcessMemory(processh, pbase, nbuffer, 11*19, &byread);
}
void click2p(POINT p1, POINT p2) { //点击两个点的操作功能
HWND hwnd=FindWindow(NULL, gamename);
int lparam;
lparam=((p1.y*35+192)<<16)+(p1.x*31+21);
SendMessage(hwnd, WM_LBUTTONDOWN, 0, lparam);
SendMessage(hwnd, WM_LBUTTONUP, 0, lparam);
lparam=((p2.y*35+192)<<16)+(p2.x*31+21);
SendMessage(hwnd, WM_LBUTTONDOWN, 0, lparam);
SendMessage(hwnd, WM_LBUTTONUP, 0, lparam);
}
void clearapair() { //找到可消去的两个点并点击
POINT p1, p2;
int x1, y1, x2, y2;
for (y1=0; y1<11; y1++)
for (x1=0; x1<19; x1++) {
if (!chessdata[y1][x1])
continue;
for (y2=0; y2<11; y2++)
for (x2=0; x2<19; x2++)
if (chessdata[y2][x2] && (chessdata[y1][x1]==chessdata[y2][x2]) && (x1!=x2 || y1!=y2) ) {
p1.x=x1; p1.y=y1;
p2.x=x2; p2.y=y2;
readchess();
if (llk_bfs(y1, x1, y2, x2) != -1) {
click2p(p1, p2);
return;
}
}
}
}