C# QQ连连看外挂(内存版)源代码

29 篇文章 2 订阅
发一个C#QQ连连看外挂(内存版)源代码
现在游戏的基址已经改变了大家只要重新查找一下基址就直接可以用了
里面用了最经典的寻路算法(比递归算法快100倍+)
Main.cs
C# code
?
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
C# code
?
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
using  System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Text;
using  System.Runtime.InteropServices;
 
namespace  llk_wg
{
     /// <summary>
     /// win32API函数声明
     /// </summary>
     class  Win32
     {
 
         [DllImport( "user32.dll" , EntryPoint =  "FindWindowA" )]
         public  static  extern  IntPtr FindWindow(  string  lpClassName,   string  lpWindowName);
 
         [DllImport( "user32.dll" , EntryPoint =  "PostMessageA" )]
         public  static  extern  bool  PostMessage(IntPtr hWnd,  int  Msg,  int  wParam,  int  lParam);
 
         [DllImport( "user32.dll" , EntryPoint =  "GetWindowThreadProcessId" )]
         public  static  extern  int  GetWindowThreadProcessId( IntPtr hWnd,  out  int  lpdwProcessId);
 
         [DllImport( "kernel32.dll" , EntryPoint =  "OpenProcess" )]
         public  static  extern  IntPtr OpenProcess( int  dwDesiredAccess,  bool  bInheritHandle,  int  dwProcessId);
 
         [DllImport( "kernel32.dll" , EntryPoint =  "CloseHandle" )]
         public  static  extern  bool  CloseHandle(IntPtr hObject);
 
         [DllImport( "kernel32.dll" , EntryPoint =  "ReadProcessMemory" )]
         public  static  extern  bool  ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer,  int  nSize, IntPtr lpNumberOfBytesRead);
 
         public  const  int  WM_LBUTTONDOWN = 513;
         public  const  int  WM_LBUTTONUP = 514;
         public  const  int  STANDARD_RIGHTS_REQUIRED = 983040;
         public  const  int  SYNCHRONIZE = 1048576;
 
     }
}


Program.cs
C# code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using  System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Windows.Forms;
 
namespace  llk_wg
{
     static  class  Program
     {
         /// <summary>
         /// 应用程序的主入口点。
         /// </summary>
         [STAThread]
         static  void  Main()
         {
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault( false );
             Application.Run( new  Form1());
         }
     }
}



Form1.cs
C# code
?
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
using  System;
using  System.Collections.Generic;
using  System.ComponentModel;
using  System.Data;
using  System.Drawing;
using  System.Linq;
using  System.Text;
using  System.Windows.Forms;
using  System.Runtime.InteropServices;
 
namespace  llk_wg
{
     public  partial  class  Form1 : Form
     {
         bool  flag =  false ;
 
         public  Form1()
         {
             InitializeComponent();
         }
 
         private  void  btnStart_Click( object  sender, EventArgs e)
         {
             Main.Start(1);
         }
 
         private  void  btnLianxi_Click( object  sender, EventArgs e)
         {
             Main.Start(2);
         }
 
         private  void  btnSingle_Click( object  sender, EventArgs e)
         {
             Main.RemoveSingle();
         }
 
         private  void  btnAll_Click( object  sender, EventArgs e)
         {
             Main.RemoveAll();
         }
 
         private  void  btnAuto_Click( object  sender, EventArgs e)
         {
             flag = !flag;
 
             if  (flag)
             {
                 this .btnAuto.Text =  "停止挂机" ;
                 this .timer1.Start();
             }
             else 
             {
                 this .btnAuto.Text =  "挂机" ;
                 this .timer1.Stop(); 
             }
         }
 
         private  void  timer1_Tick( object  sender, EventArgs e)
         {
             this .timer1.Interval = 100;
             int  otherMin = Main.GetOtherUserMinNum();
             int  selfMin = Main.GetShengyuNum();
             if  (otherMin - 2 <= selfMin) Main.RemoveSingle();
             if  (selfMin == 0) Main.Start(1);
         }
     }
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值