【按键精灵】分享某篮球游戏挂机源码
本帖最后由 阳光好青年 于 2019-9-13 21:18 编辑之前研究过两天某游戏的挂机脚本,现在感觉用不上了,佛系娱乐,就不写了。
主要当时考虑用状态机的方式去写,最后也没写太好,边看自带教程写的。机器人功能AI也只实现了进攻的移动,和防守时的一键防守。
写时的坑点:
1、启动线程要重新注册dm模块
2、找图时最好用不动点,后面才发现背景图一直在动,所以纳闷那么清晰的图怎么找不到。
3、按键写这种模拟机器人脚本感觉没个对位人的坐标不好搞,不知道游戏里时候有敌人坐标内存的信息,这方面应该更好,所以弃了。
//define value:
Global watchDog
Global Hwnd
Global windTitle
Global nowStep
Global TID
Global TIDmove
Global TIDdefence
//Initail value:
watchDog = 0
Hwnd = 0
nowStep = 0// 0:使用脚本 98:测试战斗功能
TID = 0
TIDmove = 0
TIDdefence = 0
//0:No Initail 1:In Main
PutAttachment "d:\ForScript","*.bmp"
//Initial Dm
set dm = createobject("dm.dmsoft")'创建大漠对象
dm_ret = dm.SetPath("C:\path")'设置目录
ver = dm.Ver()
If len(ver) = 0 Then
MessageBox "创建对象失败"
EndScript
End If
TracePrint ver
//注册收费版本,
dm_ret = dm.Reg("XXXXX","XXXXX")
If dm_ret <> 1 then
messagebox "注册失败,返回值是:"&dm_ret
endscript
End if
dm.DmGuard 1, "np" //大漠的绑定模式
Hwnd = Form1.WindTextIn.Text
dm_ret = dm.SetWindowState(Hwnd,1) '激活窗口
dm_ret = dm.BindWindowEx(Hwnd, "dx2", "windows3", "windows", "", 0) '窗口不能遮挡'
If dm_ret = 0 Then
TracePrint dm.GetLastError()
TracePrint Hwnd
MsgBox "dm bind Hwnd fail"
EndScript
End If
Event Form1.FindWindBtn.Click
TracePrint "In FindWindBtn"
If Form1.WindTextIn.Enabled = True Then
windTitle = Form1.WindTextIn.Text
Hwnd = Plugin.Window.Find(0, windTitle)
If Hwnd <> 0 Then
Form1.WindTextIn.Text = Hwnd
Form1.WindTextIn.Enabled = False
Form1.FindWindBtn.Caption = "Success"
//还原窗口
Call Plugin.Window.Restore(Hwnd)
//移动窗口到(0, 0)位置
Call Plugin.Window.Move(Hwnd, 0, 0)
End If
Else
End If
End Event
Event Form1.WindTextIn.Change
windTitle = Form1.WindTextIn.Text
End Event
线程ID = GetThreadID()
Event Form1.btnNext.Click
nowStep = Form1.stepInput.Text
End Event
// 主循环程序
TracePrint "Main Loop"
Do
If nowStep = 0 Then
Call CheckMain
End If
If nowStep = 1 Then
TracePrint "Now In Main"
Call GoInCheck3V3All
End If
If nowStep = 2 Then
Call PreFight
End If
If nowStep = 3 Then
Call ChooseStar
End If
If nowStep = 4 Then
Call IsFightOver
End If
If nowStep = 98 Then
Call Fighting()
End If
Delay 200
Loop
Sub CloseAD()
TracePrint "In CloseAD"
dm_ret = dm.FindPic(885, 73, 927, 111,"d:\ForScript\ad_close.bmp","000000",0.6,0,intX,intY)
If intX > 0 And intY > 0 Then
End If
If intX >0 And intY > 0Then
Call ClickPiont(909, 93)
Else
End If
Delay 200
End Sub
Sub CheckMain()
TracePrint "In CheckMain"
Call ClickPiont(11,169)
dm_ret = dm.FindPic(0, 0, 1000, 1000, "d:\ForScript\好友.bmp", "000000", 0.7, 0, intX, intY)
If intX > 0 And intY > 0 Then
nowStep = 1
Else
TracePrint "Not In Main : Go To CloseAD"
Call CloseAD
End If
Delay 500
End Sub
Sub GoInEmpire()
If nowStep = 1 Then
Call ClickPiont(134, 345)
dm_ret = dm.FindPic(572, 420, 606, 447, "d:\ForScript\empire.bmp","000000",0.6,0,intX,intY)
If intX > 0 And intY > 0 Then
nowStep = 2
Else
Call CheckMain
End If
End If
End Sub
Sub BackFromEmpire()
If nowStep = 2 Then
Call ClickPiont(473, 434)
Call CheckMain
End If
End Sub
Sub GoInCheckEmpire()
If nowStep = 2 Then
Call ClickPiont(1038, 910)
dm_ret = dm.FindPic(56, 93, 179, 103, "d:\ForScript\check_empire.bmp","000000",0.6,0,intX,intY)
If intX > 0 And intY > 0 Then
Else
Call CheckMain
End If
End If
End Sub
Sub GoStartEmpire()
If nowStep = 2 Then
Call ClickPiont(443, 534)
Delay 200
Call ClickPiont(827, 540)
Call PreFight()
End If
End Sub
Sub GoInCheck3V3All()
If nowStep = 1 Then
Call ClickPiont(150, 405)
Delay 1000
Call ClickPiont(150,405)
dm_ret = dm.FindPic(0, 0, 300, 100, "d:\ForScript\全场33.bmp","000000",0.7,0,intX,intY)
If intX > 0 And intY > 0 Then
nowStep = 2
End If
End If
End Sub
Sub PreFight()
If nowStep = 2 Then
TracePrint "Pre Fight"
Call ClickPiont(579, 550)
Delay 3000
dm_ret = dm.FindPic(0, 0, 1000, 1000, "d:\ForScript\开始匹配.bmp","000000",0.7,0,intX,intY)
If intX > 0 And intY > 0 Then
Call ClickPiont(816, 546)
Delay 1000
nowStep = 3
End If
dm_ret = dm.FindPic(0,0, 1000,1000, "d:\ForScript\Over2.bmp","000000",0.7,0,intX,intY)
If intX > 0 And intY > 0 Then
Call ClickPiont(727,533)
End If
End If
End Sub
Sub ChooseStar()
Delay 10000
Call ClickPiont(608, 223)
Delay 1000
Call ClickPiont(886,310)
Delay 2000
Call ClickPiont(723,308)
Delay 3000
Call ClickPiont(569, 309)
Delay 2000
Call ClickPiont(816,546)
TID = BeginThread(Fighting)
nowStep = 4
End Sub
Sub Fighting()
If nowStep <> 98 Then
set dm = createobject("dm.dmsoft")'创建大漠对象
End If
Do
dm_ret = dm.FindColor(434, 46, 446, 64, "B42423-1D0304", 0.9, 0, intX, intY)
If intX > 0 And intY > 0 Then
'TracePrint "In Attack"
dm_ret = dm.FindPic(600, 500, 800, 555, "d:\ForScript\passball.bmp","000000",0.6,0,intX,intY)
If intX > 0 And intY > 0 Then
Call PressA '传球键'
Delay 200
Else
If TIDmove = 0 Then
TIDmove = BeginThread(StarMoveW)
Delay 800
End If
End If
End If
dm_ret = dm.FindColor(511, 45, 516, 65, "B42423-1D0304", 0.9, 0, intX, intY)
If intX > 0 And intY > 0 Then
'TracePrint intX'
'TracePrint intY'
If TIDdefence = 0 Then
TIDdefence = BeginThread(StarDefence)
End If
End If
Loop
End Sub
Sub IsFightOver()
Call ClickPiont(579, 550)
Delay 2000
If nowStep = 4 Then
dm_ret = dm.FindPic(0,0, 1000,1000, "d:\ForScript\Over.bmp","000000",0.7,0,intX,intY)
If intX > 0 And intY > 0 Then
Call ClickPiont(323, 526)
Delay 300
StopThread TID
Delay 5000
Call ClickPiont(727,533)
nowStep = 2
End If
End If
End Sub
Sub ClickPiont(x, y)
dm.MoveTo x,y
dm.LeftClick
End Sub
Sub PressA()
Call ClickPiont(726, 499)
End Sub
Sub PressB()
Call ClickPiont(762, 373)
End Sub
Sub PressC()
Call ClickPiont(885, 346)
End Sub
Sub PressD()
Call ClickPiont(863, 484)
End Sub
Sub StarMoveW()
set dm = createobject("dm.dmsoft")'创建大漠对象
dm.KeyDownChar "W"
Delay 1800
dm.KeyUpChar "W"
Delay 50
TIDmove = 0
End Sub
Sub StarDefence()
set dm = createobject("dm.dmsoft")'创建大漠对象
dm.KeyDownChar "J"
Delay 1250
dm.KeyUpChar "J"
Delay 50
TIDdefence = 0
End Sub
Sub LeftClickHold(x, y, t)
dm.MoveTo x,y
dm.LeftDown
Delay t
dm.LeftUp
End Sub
以下是测试,模块是不是能找图的辅助工具源码:
https://attach.52pojie.cn//forum/201909/13/211416huplkzlp3e613pa4.png?l
Global FilePath
Global FileName
Global SimValue
Event Form1.Button1.Click
FilePath = Form1.InputBox1.Text
FileName = Form1.InputBox2.Text
SimValue = Form1.InputBox3.Text
set dm = createobject("dm.dmsoft")'创建大漠对象
dm_ret = dm.SetPath(FilePath)'设置目录
ver = dm.Ver()
If len(ver) = 0 Then
MessageBox "创建对象失败"
EndScript
End If
TracePrint ver
//注册收费版本
dm_ret = dm.Reg("XXXXX","XXXXX")
If dm_ret <> 1 then
messagebox "注册失败,返回值是:"&dm_ret
endscript
End If
dm_ret = dm.FindPic(0, 0, 2000, 2000, FileName,"000000",0.6,0,intX,intY)
If intX > 0 And intY > 0 Then
MsgBox "Find success!"
pic_size = dm.GetPicSize(FileName)
pic_size = split(pic_size,",")
w = int(pic_size(0))
h = int(pic_size(1))
Form1.InputBox4.Text = intX
Form1.InputBox5.Text = intY
Form1.InputBox6.Text = int(intX) + w / 2
Form1.InputBox7.Text = int(intY) + h / 2
Else
Form1.InputBox4.Text = "X"
Form1.InputBox5.Text = "Y"
Form1.InputBox6.Text = "0"
Form1.InputBox7.Text = "0"
End If
End Event
Event Form1.InputBox1.Change
FilePath = Form1.InputBox1.Text
End Event
Event Form1.InputBox2.Change
FileName = Form1.InputBox2.Text
End Event
Event Form1.InputBox3.Change
SimValue = Form1.InputBox3.Text
End Event
Do
GetCursorPos x, y
Form1.InputBox8.Text = x & "," & y
Loop
开创者 发表于 2019-9-13 21:32
弄不明白是啥,对了楼主有办法让夜神模拟器里的时间停止不动 ?
开创者 发表于 2019-9-13 21:32
弄不明白是啥,对了楼主有办法让夜神模拟器里的时间停止不动 ?
就是一个将打开夜神模拟器以及将adb连接自动配置好这两个功能集成在一个gui工具里面
就是一个将打开夜神模拟器以及将adb连接自动配置好这两个功能集成在一个gui工具里面 支持一下 感谢分享,真棒!!!
页:
[1]