赞
踩
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Runtime.InteropServices;
namespace
llk_wg {
class
Main {
//游戏窗口标题
const
string
GAME_CAPTION =
"QQ游戏 - 连连看角色版"
;
//棋盘基址
static
IntPtr GAME_BASE = (IntPtr)0x0012A47C;
//声明一个棋盘数组
static
byte
[,] boxs =
new
byte
[11, 19];
//游戏窗口句柄
static
IntPtr hwnd;
//初始化棋盘数组
static
void
InitBox() {
//获取游戏句柄
hwnd = Win32.FindWindow(
null
, GAME_CAPTION);
//获取棋盘数组的内存基址
IntPtr lpBufferbase = Marshal.UnsafeAddrOfPinnedArrayElement(boxs, 0);
//获取pid
int
ProcessId;
Win32.GetWindowThreadProcessId(hwnd,
out
ProcessId);
//打开游戏线程
IntPtr hObject = Win32.OpenProcess(Win32.STANDARD_RIGHTS_REQUIRED | Win32.SYNCHRONIZE | 4095,
false
, ProcessId);
//读取棋盘数据
Win32.ReadProcessMemory(hObject, GAME_BASE, lpBufferbase, boxs.Length, IntPtr.Zero);
//关闭线程
Win32.CloseHandle(hObject);
}
//发送鼠标消息(顺便把图片的高度宽度也算进去)
static
void
SendMouseclick(
int
x,
int
y) {
//获取游戏句柄
hwnd = Win32.FindWindow(
null
, GAME_CAPTION);
//lparam的高位就是y坐标低位就是x坐标y左移16就到高位去了
int
lparam = (y << 16) + x;
Win32.PostMessage(hwnd, Win32.WM_LBUTTONDOWN, 0, lparam);
Win32.PostMessage(hwnd, Win32.WM_LBUTTONUP, 0, lparam);
}
//消除1对图片(模拟2次鼠标单击)
static
void
ClickTwo(
int
x1,
int
y1,
int
x2,
int
y2) {
SendMouseclick(22 + x1 * 31, 194 + y1 * 35);
SendMouseclick(22 + x2 * 31, 194 + y2 * 35);
}
//游戏开局
public
static
void
Start(
int
type) {
int
x = type == 1 ? 660 : 760;
SendMouseclick(x, 570);
}
//找相同的图片(本工具的核心)
static
bool
Select(
int
x1,
int
y1,
int
x2,
int
y2) {
if
(x1 == x2 && y1 + 1 == y2)
return
true
;
if
(y1 == y2 && x1 + 1 == x2)
return
true
;
List<
int
> list1 =
new
List<
int
>();
List<
int
> list2 =
new
List<
int
>();
List<
int
> list3 =
new
List<
int
>();
bool
flag;
list1.Add(x1);
for
(
int
i = x1 - 1; i >= 0; i--)
if
(boxs[i, y1] == 0) list1.Add(i);
else
break
;
for
(
int
i = x1 + 1; i < 11; i++)
if
(boxs[i, y1] == 0) list1.Add(i);
else
break
;
list2.Add(x2);
for
(
int
i = x2 - 1; i >= 0; i--)
if
(boxs[i, y2] == 0) list2.Add(i);
else
break
;
for
(
int
i = x2 + 1; i < 11; i++)
if
(boxs[i, y2] == 0) list2.Add(i);
else
break
;
list3 = list1.Intersect(list2).ToList();
for
(
int
i = 0; i < list3.Count(); i++) {
flag =
true
;
for
(
int
j = Math.Min(y1, y2) + 1; j < Math.Max(y1, y2); j++) {
if
(boxs[list3[i], j] != 0) { flag =
false
;
break
; } }
if
(flag)
return
true
;
}
list1.Clear(); list2.Clear(); list3.Clear();
list1.Add(y1);
for
(
int
i = y1 - 1; i >= 0; i--)
if
(boxs[x1, i] == 0) list1.Add(i);
else
break
;
for
(
int
i = y1 + 1; i < 19; i++)
if
(boxs[x1, i] == 0) list1.Add(i);
else
break
;
list2.Add(y2);
for
(
int
i = y2 - 1; i >= 0; i--)
if
(boxs[x2, i] == 0) list2.Add(i);
else
break
;
for
(
int
i = y2 + 1; i < 19; i++)
if
(boxs[x2, i] == 0) list2.Add(i);
else
break
;
list3 = list1.Intersect(list2).ToList();
for
(
int
i = 0; i < list3.Count(); i++) {
flag =
true
;
for
(
int
j = Math.Min(x1, x2) + 1; j < Math.Max(x1, x2); j++) {
if
(boxs[j, list3[i]] != 0) { flag =
false
;
break
; } }
if
(flag)
return
true
;
}
return
false
;
}
//消除一对
public
static
void
RemoveSingle() {
InitBox();
for
(
int
x1 = 0; x1 < 11; x1++) {
for
(
int
y1 = 0; y1 < 19; y1++) {
for
(
int
x2 = 0; x2 < 11; x2++) {
for
(
int
y2 = 0; y2 < 19; y2++) {
if
(boxs[x1, y1] != 0 && boxs[x1, y1] == boxs[x2, y2] && !(x1 == x2 && y1 == y2)) {
if
(Select(x1, y1, x2, y2)) {
ClickTwo(y1, x1, y2, x2);
return
;
}
}
}
}
}
}
}
//消除所有
public
static
void
RemoveAll() {
InitBox();
Target:
for
(
int
x1 = 0; x1 < 11; x1++) {
for
(
int
y1 = 0; y1 < 19; y1++) {
for
(
int
x2 = 0; x2 < 11; x2++) {
for
(
int
y2 = 0; y2 < 19; y2++) {
if
(boxs[x1, y1] != 0 && boxs[x1, y1] == boxs[x2, y2] && !(x1 == x2 && y1 == y2)) {
if
(Select(x1, y1, x2, y2)) {
ClickTwo(y1, x1, y2, x2);
boxs[x1, y1] = 0;
boxs[x2, y2] = 0;
goto
Target;
}
}
}
}
}
}
}
//获取其他玩家最小box数量值
public
static
byte
GetOtherUserMinNum() {
byte
value = 0;
byte
[] buffer =
new
byte
[20];
int
lpBase = 0x0012E04C;
// 0x00115CDC;//0012E04C
//获取游戏句柄
hwnd = Win32.FindWindow(
null
, GAME_CAPTION);
//获取棋盘数组的内存基址
IntPtr lpBufferbase = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
//获取pid
int
ProcessId;
Win32.GetWindowThreadProcessId(hwnd,
out
ProcessId);
//打开游戏线程
IntPtr hObject = Win32.OpenProcess(Win32.STANDARD_RIGHTS_REQUIRED | Win32.SYNCHRONIZE | 4095,
false
, ProcessId);
//读取棋盘数据
Win32.ReadProcessMemory(hObject, (IntPtr)lpBase, lpBufferbase, buffer.Length, IntPtr.Zero);
//关闭线程
Win32.CloseHandle(hObject);
try
{ value = buffer.Where(o => o != 0).Min(); }
catch
{ }
return
value;
}
//获取自己的图片数量
public
static
byte
GetShengyuNum() {
byte
[] buffer =
new
byte
[4];
//0012E048,00115CD8
int
lpBase = 0x0012E048;
// 0x00115CDC;//0012E04C
//获取游戏句柄
hwnd = Win32.FindWindow(
null
, GAME_CAPTION);
//获取棋盘数组的内存基址
IntPtr lpBufferbase = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
//获取pid
int
ProcessId;
Win32.GetWindowThreadProcessId(hwnd,
out
ProcessId);
//打开游戏线程
IntPtr hObject = Win32.OpenProcess(Win32.STANDARD_RIGHTS_REQUIRED | Win32.SYNCHRONIZE | 4095,
false
, ProcessId);
//读取棋盘数据
Win32.ReadProcessMemory(hObject, (IntPtr)lpBase, lpBufferbase, buffer.Length, IntPtr.Zero);
//关闭线程
Win32.CloseHandle(hObject);
return
Marshal.ReadByte(lpBufferbase);
}
}
}
Win32.cs
|
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。