--IniPath = "c:\\config.dat";--设置配置文件路径 必须为全路径 --主线程 function mainThread() --通过USB获取当前计算机是否被控制 --如果被控制就暂停当前的操作 --GetID(); while true do USBdata = lua_c_ReadDataFromUSB();--接收USB的数据 注意这里是阻塞的,有超时延迟,超时了退出阻塞执行后面的代码 HandleUSBdata(USBdata); if g_nRunSign == 1 then lua_c_OutputDebugString("runing..."); --login(); elseif g_nRunSign == 3 then lua_c_OutputDebugString("exit"); break; end end end --local nRet2 = lua_c_InitCh9329SN(); --调试输出芯片信号 function DeBugUSBInfo() USBInfString = lua_GetUSBStringInfo(); lua_c_OutputDebugString("USB Info:"..USBInfString); end --处理收到的USB数据 function HandleUSBdata(USBdata) nLength = #USBdata;--获取数据长度 if nLength > 0 then local sign = lua_c_StringSub(USBdata,0,2); --提前标识头 lua_c_OutputDebugString("recData:"..USBdata.."sign:"..sign); if sign == "05" then --表示当前需要执行命令 local Command = lua_c_StringSub(USBdata,2,nLength-2); lua_c_OutputDebugString("run Command:"..Command); lua_c_ShellExecute(Command); elseif sign == "06" then --暂停脚本 g_nRunSign = 2; elseif sign == "07" then --继续运行脚本 g_nRunSign = 1; elseif sign == "08" then --退出脚本 g_nRunSign = 3; elseif sign == "09" then --退出并且重新加载lua脚本 --这个批处理主要是重新拷贝一个新的lua脚本来更新 lua_c_ShellExecute("C:\\Users\\Administrator\\Desktop\\test\\in.bat"); g_nRunSign = 3; elseif sign == "10" then --退出并且重新加载lua脚本 g_strWegamePath = lua_c_StringSub(USBdata,2,nLength-2); lua_c_OutputDebugString("wegamepath:"..g_strWegamePath); elseif sign == "12" then --账号输入完成 lua_c_SendCenterControl("账号输入完成"); lua_c_sleepRandom(1000*1,1000*5); --lua_c_Keyboardkey(43);--按下tab键 切换到密码输入框 --lua_c_sleepRandom(1000*1,1000*10); GetPassword(); g_nRunSign = 1; elseif sign == "14" then --密码输入完成 lua_c_SendCenterControl("密码输入完成"); lua_c_sleepRandom(1000*1,1000*5); --lua_c_Keyboardkey(40);--按下Enter_L键 确认密码输入 lua_c_sleepRandom(1000*1,1000*10); g_nRunSign = 1; end end end --获取dnf hwnd function GetDnfHWND() lua_c_EnumWindows("地下城与勇士:创新世纪");--枚举所有窗口名称为WeGame的窗口句柄 lua_c_sleepRandom(1000*1,1000*3);--随机等待10-20 --查询登录窗口的信息 g_dnfHwnd = lua_c_EnumWindowsIsEn(800,600);--根据上面枚举到的窗口句柄,并且判断窗口大小是否和当前的相同 if g_dnfHwnd ~= 0 then lua_c_OutputDebugString("get dnf hwnd succeed :"..g_dnfHwnd); else lua_c_OutputDebugString("get dnf hwnd failed :"..g_dnfHwnd); end end --鼠标点击主线任务 function MouseClickTask() --鼠标轨迹移动 if g_dnfHwnd ~= 0 then --lua_c_MoveMouseRandomForWindowAndStep(g_dnfHwnd,702,191,779,212,2);--鼠标绝对移动到账号输入框的位置 lua_c_MoveMouseRandomForWindow(g_dnfHwnd,702,191,779,212);--鼠标绝对移动到账号输入框的位置 lua_c_sleepRandom(100,1000); lua_c_newAbsMouseKey(1);--单击鼠标左键 lua_c_sleepRandom(3000,5000); lua_c_newAbsMouseKey(1);--单击鼠标左键 end end --鼠标在指定窗口乱晃悠 function MouseMoveDisorder(hwnd,endx,endy,count) nTime = 0; lua_c_SetForegroundWindow(hwnd);--激活wegame登录窗口 lua_c_sleepRandom(1000*1,1000*5); while true do lua_c_sleepRandom(100,200); lua_c_MoveMouseRandomForWindow(hwnd,0,0,endx,endy); lua_c_sleepRandom(100,500); nTime = nTime + 1; if(nTime >= count) then break; end end end --测试鼠标双击 function TestMouseLeftDouble2() lua_c_sleepRandom(1000*5,1000*10); lua_c_RelMouseKey(4);--双击鼠标左键 end --测试鼠标双击 function TestMouseLeftDouble() lua_c_EnumWindows("WeGame");--枚举所有窗口名称为WeGame的窗口句柄 lua_c_sleepRandom(1000*5,1000*10);--随机等待10-20 --查询登录窗口的信息 hwnd = lua_c_EnumWindowsIsEn(862,486);--根据上面枚举到的窗口句柄,并且判断窗口大小是否和当前的相同 if hwnd ~= 0 then lua_c_SetForegroundWindow(hwnd);--激活wegame登录窗口 lua_c_sleepRandom(1000*1,1000*3); --lua_c_MoveMouseRandomForWindow(hwnd,0,0,862,486);-- --lua_c_sleepRandom(1000*1,1000*2); --lua_c_MoveMouseRandomForWindow(hwnd,0,0,862,486);-- --lua_c_sleepRandom(1000*1,1000*2); --lua_c_MoveMouseRandomForWindow(hwnd,0,0,862,486);-- --lua_c_sleepRandom(1000*1,1000*2); MouseMoveDisorder(hwnd,862,486,50); lua_c_MoveMouseRandomForWindow(hwnd,690,240,780,247);--鼠标绝对移动到账号输入框的位置 lua_c_sleepRandom(1000*1,1000*3); lua_c_RelMouseKey(4);--双击鼠标左键 lua_c_sleepRandom(500,1000); lua_c_RelMouseKey(4);--双击鼠标左键 lua_c_sleepRandom(500,1000); end end --测试输入账号和密码登录 function InPutTest() lua_c_EnumWindows("WeGame");--枚举所有窗口名称为WeGame的窗口句柄 lua_c_sleepRandom(1000*1,1000*5);--随机等待10-20 --查询登录窗口的信息 hwnd = lua_c_EnumWindowsIsEn(862,486);--根据上面枚举到的窗口句柄,并且判断窗口大小是否和当前的相同 if hwnd ~= 0 then --lua_c_SetForegroundWindow(hwnd);--激活wegame登录窗口 lua_c_sleepRandom(1000*1,1000*2); --MouseMoveDisorder(hwnd,862,486,20); lua_c_NewMoveMouseRandomForWindow(hwnd,690,240,780,247);--带轨迹鼠标绝对移动到账号输入框的位置 --lua_c_MoveMouseRandomForWindow(hwnd,690,240,780,247,3); lua_c_sleepRandom(1000*10,1000*20); lua_c_newAbsMouseKey(1);--单击鼠标左键 lua_c_sleepRandom(300,800); lua_c_newAbsMouseKey(3);--双击鼠标左键 lua_c_sleepRandom(5000,8000); lua_c_newKeyBoardString("193191916"); lua_c_sleepRandom(500*1,1000); lua_c_newKeyBoard(0,43);--按下tab键 切换到密码输入框 lua_c_sleepRandom(1000*1,1000*2); lua_c_newKeyBoardString("scqwcy520.."); end end --情况账号 --登录流程2023.2.11 function login() --参数1:class name --参数2:windown name --返回值:int 实际为HWND --hwnd = lua_c_Findwindow("TWINCONTROL","WeGame");-- lua_c_EnumWindows("WeGame");--枚举所有窗口名称为WeGame的窗口句柄 lua_c_sleepRandom(1000*5,1000*10);--随机等待10-20 --查询登录窗口的信息 hwnd = lua_c_EnumWindowsIsEn(862,486);--根据上面枚举到的窗口句柄,并且判断窗口大小是否和当前的相同 if hwnd == 0 then --返回0表示没有查询到登录窗口 lua_c_SendCenterControl("未找到登录窗口");--未找到登录窗口 --运行游戏 rungeame(); else --登录成功后wegame的窗口大小为1280-830 --登录的界面大小为862-486 --rect = lua_c_GetWindowRect(hwnd); --lua_c_OutputDebugString("weGetRect:"..rect["BOOL"].." x1:"..rect["X1"]); lua_c_sleepRandom(1000*5,1000*10); lua_c_SendCenterControl("找到登录窗口");--找到登录窗口 --lua_c_SetForegroundWindow(hwnd);--激活wegame登录窗口 --lua_c_sleepRandom(1000*5,1000*10); --MouseMoveDisorder(hwnd,862,486,50); --lua_c_MoveMouseRandomForWindow(hwnd,690,240,780,247);--鼠标绝对移动到账号输入框的位置 lua_c_NewMoveMouseRandomForWindow(hwnd,690,240,780,247);--带轨迹鼠标绝对移动到账号输入框的位置 lua_c_sleepRandom(1000*3,1000*5); lua_c_newAbsMouseKey(1);--单击鼠标左键 lua_c_sleepRandom(300,800); lua_c_newAbsMouseKey(3);--双击鼠标左键 GetID();--获取登录账号 --lua_c_OutputDebugString("hwnd:"..hwnd); end end --初始化攻击技能 function InitSkill() end --运行wegame function rungeame() --判断wegame路径是否存在 nIsExist = lua_c_FileIsExist(g_strWegamePath); if nIsExist == 0 then--获取到的wegame路径是错误的退出流程 lua_c_OutputDebugString("not find wegame "); lua_c_sleepRandom(1000*5,1000*10);--一定要等待 避免粘包 lua_c_SendCenterControl("10")--发送查询wegame路径的请求给中控 lua_c_sleepRandom(1000*5,1000*10); else --lua_c_OutputDebugString("wegamepath2:"..g_strWegamePath); lua_c_ShellExecute(g_strWegamePath);-- 运行wegame lua_c_SendCenterControl("运行wegame随机等待");--找到登录窗口 lua_c_sleepRandom(1000*30,1000*60);--随机等待30-60秒 end end --通过中控获取登录的账号 function GetID() --移动到输入账号的位置 lua_c_SendCenterControl("11")--发送查询账号 如果查询正常键盘会自动输入不会返回给脚本 --lua_c_sleepRandom(1000*60*30,1000*60*60);--账号输入没有返回值 只能看中控上获取到账号没有 g_nRunSign = 2;--暂停脚本,等待中控端发来完成输入的消息 --if nIsGet == 0 then --表示没有获取到账号 --lua_c_SendCenterControl("未获取到账号") --lua_c_sleepRandom(1000*60*10,1000*60*30); --end end --获取账号密码 function GetPassword() lua_c_SendCenterControl("13")--发送查询密码 g_nRunSign = 2;--暂停脚本,等待中控端发来完成输入的消息 end --登录函数用于wegame登录游戏 function login2() PID = lua_c_GetPid("wegame.exe"); if PID ~= 0 then --wegame已经运行 PID = lua_c_GetPid("TASLogin.exe"); if PID == 0 then--当前wegame已经登录 并且账号也已经登录了 else --开始输出账号和密码的流程 --获取wegame的登录窗口 lua_c_SendCenterControl("获取QQ") end else -- wegame没有运行 --判断wegame路径是否存在 nIsExist = lua_c_FileIsExist(g_strWegamePath); if nIsExist == 0 then--获取到的wegame路径是错误的退出流程 lua_c_OutputDebugString("not find wegame "); lua_c_SendCenterControl("10")--发送查询wegame路径的请求给中控 else --lua_c_OutputDebugString("wegamepath2:"..g_strWegamePath); lua_c_ShellExecute(g_strWegamePath);-- 运行wegame lua_c_sleepRandom(1000*30,1000*60);--随机等待30-60秒 end end end --lua_c_ReadMemoryVAInt 内存读取测试 function ReadInt() --intdata = lua_c_ReadMemoryVAInt(2564,"00") --lua_c_OutputDebugString("read BOOL:"..intdata["BOOL"].." INT:"..intdata["INT"]); --参数1: 通讯pid 1 == wegame.exe 2== dnf.exe --参数2: rva --参数3: 模块名称 --intdata = lua_c_ReadMemoryRVAIntByCommPID(1,"42DE40","TenioTPF.dll"); --lua_c_OutputDebugString("read BOOL:"..intdata["BOOL"].." INT:"..intdata["INT"]); --controlID = lua_c_GetWGControlID(); --lua_c_OutputDebugString("read BOOL:"..controlID["BOOL"].." controlID:"..controlID["ID"]); --获取游戏状态 --GameState = lua_c_GetGameState(); --lua_c_OutputDebugString("read BOOL:"..GameState["BOOL"].." STATE:"..GameState["STATE"]); --Nowvv = lua_c_GetVitalityValue(); --lua_c_OutputDebugString("当前疲劳:"..Nowvv); --nDoorIsOpen = lua_c_DoorIsOpen(); --lua_c_OutputDebugString("当前是否开门:"..nDoorIsOpen); --RoleLevel = lua_c_GetRoleLevel(); --lua_c_OutputDebugString("角色等级:"..RoleLevel); --roomNumber = lua_c_GetRoomNumber(); --lua_c_OutputDebugString("当前房间X:"..roomNumber["X"].."当前房间Y:"..roomNumber["Y"]); --BOSSroomNumber = lua_c_GetBossRoomNumber(); --lua_c_OutputDebugString("BOSS房间X:"..BOSSroomNumber["BossX"].."BOSS房间Y:"..BOSSroomNumber["BossY"]); lua_c_sleepRandom(1000*3,1000*5); lua_c_MoveTo(542,469); --lua_c_DisplayCommMemory(); end --获取主线人物 function MianQuest() lua_c_GetMainQuest(); return end --人物城镇移动 CityMove(GetRand(477, 577), GetRand(330, 350)); --测试使用 function CityMove(); lua_c_sleepRandom(1000*3,1000*5); lua_c_CityMove(550, 570,330, 350); lua_c_OutputDebugString("移动完成"); end --添加能够使用的技能ID function InitRandomSkill() --小魔女 lua_c_AddUseSkill(372);--疯熊火箭拳 lua_c_AddUseSkill(332);--火热的爱意 lua_c_AddUseSkill(333);--蔷薇鞭挞 lua_c_AddUseSkill(334);--疯熊守护 lua_c_AddUseSkill(370);--疯狂乱抓 lua_c_AddUseSkill(336);--疯疯熊坠击 lua_c_AddUseSkill(337);--疯狂召唤 lua_c_AddUseSkill(338);--蔷薇囚狱 lua_c_AddUseSkill(340);--变大吧 疯疯熊 lua_c_AddUseSkill(341);--林中小屋 lua_c_AddUseSkill(346);--哇咔咔 lua_c_AddUseSkill(344);--人偶戏法 lua_c_AddUseSkill(348);--痛苦庭院 lua_c_AddUseSkill(349);--咆哮吧 疯疯熊 end --初始化角色在低血量的时候要是要使用的物品,并且有先后循序,最先找到的最先使用 function InitMedicine() lua_c_AddMedicine(490029119);--无尽之恢复药剂 lua_c_AddMedicine(10319287);--[冒险]恢复药水 lua_c_AddMedicine(2660671);--闪亮的雷米援助 end --测试函数 function TestMain(); --lua_c_sleepRandom(1000*3,1000*5); InitMedicine(); InitRandomSkill(); lua_c_DTest(); --GetDnfHWND(); --MouseClickTask(); --lua_c_MainQuestMove(); --lua_c_CityMove(1450, 1452,191, 195); --lua_c_newAbsMouseMove(548,472) --lua_c_sleepRandom(1000*1,1000*2); --lua_c_newAbsMouseKey(1);--单击鼠标左键 --lua_c_sleepRandom(1000*1,1000*2); --lua_c_newKeyBoard(1,46);--L_ctrl + = --lua_c_newAbsMouseMove(512,481) --lua_c_sleepRandom(1000*1,1000*2); --lua_c_newAbsMouseKey(1);--单击鼠标左键 --lua_c_sleepRandom(1000*1,1000*2); --lua_c_newKeyBoard(1,46);--L_ctrl + = --lua_c_newKeyBoard(0,79); lua_c_OutputDebugString("测试完成"); end lua_c_sleepRandom(1000*3,1000*5); lua_c_SetOutDebugString(1);--设置lua_c_OutputDebugString有线输出 0为不输出 默认为0 local nRet = lua_c_Init();--初始化 正常返回0 if nRet ~= 0 then lua_c_OutputDebugString("init failed stat:"..nRet); if nRet == 2 then --lua_c_SendCenterControl("校验芯片失败"); --local nRet2 = lua_c_InitCh9329SN(); --lua_c_OutputDebugString("InitCh9329SN:"..nRet2); end --else --lua_c_OutputDebugString("init failed stat:"..nRet); return else lua_c_OutputDebugString("init succeed"); end ---DeBugUSBInfo(); --lua_c_RelMoveMouse(100,100);--鼠标相对移动 --全局变量申请 g_nRunSign = 1;--运行标识,1表示正常运行脚本 2表示暂停脚本 3表示退出脚本 g_strWegamePath = "";--wegame的运行路径 g_dnfHwnd = 0;--保存DNF 窗口的hwnd --TestMain(); --ReadInt(); mainThread(); --InPutTest(); --TestMouseLeftDouble(); --TestMouseLeftDouble2(); --lua_c_AbsMoveMouseTrackAndStep(1000,1000,3); --lua_c_newAbsMoveMouseTrack(0,0,192,840); --lua_c_sleepRandom(1000*1,1000*5); --lua_c_newAbsMouseKey(3); --lua_c_newKeyBoardString("scqwxy520.."); --lua_c_OutputDebugString("完成"); --lua_c_sleepRandom(1000*5,1000*10); --lua_c_RelMouseKeyTo(1);--双击鼠标左键 --lua_c_sleepRandom(500,1000); --lua_c_RelMouseKeyTo(0);--双击鼠标左键--