这些日子,QQ游戏外挂是风光了一阵.俄罗斯方块,连连看,对对碰这些游戏的外挂层出不穷。其实这一类外挂的原理大体都是一样的。下面我就以QQ游戏对对碰外挂作为例子阐述一下QQ外挂的制作原理。
观察QQ游戏对对碰的游戏界面及游戏规则,发现玩家是在固定的一个游戏区内寻找复合要求的方块然后点击两次鼠标消去方块从而达到得分的目的。因此,我们可以通过模拟人的观察,和鼠标点击来实现外挂自动消除方块,完成全局。
取得可消方块(模拟人观察):要判断哪个方块可以消,我们可以通过获取方块某点的颜色来判断方块的类型,然后建立方块矩阵,然后在矩阵中选择出适合消去的方块。关于取颜色,我们用到几个API函数 GetPixel、GetDC、ReleaseDC。(详细的介绍请参考MSDN或各种API相关资料)
模拟鼠标击:在此我们使用 mouse_event 来模拟鼠标的移动,点击,弹起。个人认为用postmessage是更好的,在此使用mouse_event只是为了阐述简单。
下面是VB实现代码(带详细注释):
'模块中
'*************模块:modMain******************
'作者:Cyril
'Email:terry6394@126.com
'Web: http://www.sguca.com/other
'书写日期:2004.10.23
'编辑日期:2002.10.23
'转载请保留此信息
'版权所有(a)Cyril 405 工作室
'********************************************
Option Explicit
'API声明
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
'API类型定义
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
'方块类型定义
Public Enum BOX_TYPE
Ox = 0
Dog = 1
Panda = 2
Chicken = 3
Cat = 4
Frog = 5
Monkey = 6
End Enum
'自定义方块数据类型x,y位方块坐标,type为方块类型.
'在Easy对对碰1.5版中还加如了一些其他属性,例如是否带道具属性.
Public Type BOX
x As Integer
y As Integer
type As BOX_TYPE
End Type
'Api常量
'鼠标事件常量
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_MOVE = &H1
Private Const MOUSEEVENTF_ABSOLUTE = &H8000
Public Const HWND_TOPMOST = -1
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOMOVE = &H2
'自定义常量
'游戏区左上角坐标
Const GAME_LEFT As Integer = 176
Const GAME_TOP As Integer = 102
'每个方块的长宽
Const BOX_WIDTH As Integer = 48
Const BOX_HEIGHT As Integer = 48
'游戏窗口句柄
Public g_WindowHwnd As Long
'方块矩阵 (8*8)
Public boxs(7, 7) As BOX
**********过程名:DelayTime******************
'作者:Cyril
'书写日期:2004.10.23
'编辑日期:2002.10.23
'目的:获取当前场景 , 建立方块矩阵
'方法:killBox
'应用于:MainMod模块
'********************************************
Public Function getBoxs()
Dim i As Integer '矩阵行
Dim j As Integer '矩阵列
Dim color1 As Long '颜色 (22,22)处
Dim color2 As Long '颜色 (22,17)处
For i = 0 To 7
For j = 0 To 7
With boxs(i, j)
.x = GAME_LEFT + 22 + BOX_WIDTH * j
.y = GAME_TOP + 22 + BOX_HEIGHT * i
'取每个方块坐标(22,22)和(22,17)位置的颜色
color1 = getColor(.x, .y)
color2 = getColor(.x, .y - 5)
'用两点颜色确定一个方块类型.
If color1 = 16777215 And color2 = 16777215 Then .type = Panda
If color1 = 2097151 And color2 = 1353909 Then .type = Chicken
If color1 = 4473924 And color2 = 14209230 Then .type = Dog
If color1 = 13828048 And color2 = 3862322 Then .type = Frog
If color1 = 8623264 And color2 = 5805536 Then .type = Monkey
If color1 = 10921638 And color2 = 9408399 Then .type = Cat
If color1 = 15398649 And color2 = 1655140 Then .type = Ox
End With
Next j
Next i
End Function
为了方便理解,这里用了一种比较简单的算法 -- 穷举法.(这也是Easy对对碰最初版本的算法).
'其主要思想是列举16种消除方块的可能。一旦有匹配的情况出现,则马上执行鼠标点击动作.
'如果你要使你的外挂更强大,就必须采更优秀的算法.
'**********过程名:DelayTime******************
'作者:Cyril
'书写日期:2004.10.23
'编辑日期:2002.10.23
'目的:消去一个方块
'方法:killBox
'说明:无
'返回值:无
'应用于:MainMod模块
'********************************************
Public Function killBox()
Dim i As Integer
Dim j As Integer
getBoxs
' :
' 情况
For i = 0 To 4
| 相关文章: | 关闭或者删除腾讯QQ空间的办法 获赠QQ秀再次转送的小技巧 QQ等级想要几级就几级 随便改 QQ截图 截取右键菜单的最好法宝 QQ情侣个性签名 QQ空间导航代码最新版 让你的QQ空间用上漂亮的导航 玩对对碰游戏时的四大注意事项 QQ出现异常要求激活原因和处理办法 点亮QQ音信图标!教你又一招QQ图标点亮法 让QQ空间播放多首背景音乐技巧 |
|
|
![]() QQ空间会将启用全新版 |
![]() QQ空间模块使用方法及 |
![]() 心情文字:那年,她来 |
![]() 天天都是情人节 和dar |
| · | [组图]QQ空间会将启用全 |
| · | QQ同时在线用户数突破3 |
| · | [图文]QQ宠物结婚系统全 |
| · | [图文]QQ宠物包治百病小 |
| · | [推荐]QQ聊天时如何避开 |
| · | QQ空间模块使用方法及下 |