public static bool GamePosition() { object w, h; int width, height, x, y; dmsoft dm = GetDm(); dm.GetClientSize(hwnd, out w, out h); width = Convert.ToInt32(w); height = Convert.ToInt32(h); windowW = width; windowH = height; Outputs.Log("定位游戏窗口中,请勿更改poi浏览器大小"); gameX1 = 0; gameY1 = 0; if (!FindPic(0, 0, width, height, "position", 0.9, out x, out y)) { Outputs.Log("未找到游戏窗口"); return(false); } gameX1 = x - 1; gameY1 = y + 1; DebugBmp(0, 0, gameW - 1, gameH - 1, "t"); Outputs.Log("游戏窗口已更新:" + "x" + gameX1.ToString() + "y" + gameY1.ToString()); return(true); }
public MultiDm(string game, Action <string, string> gameMsg) { dm = new dmsoft(); dm.SetPath(mainPath); this.game = game; this.gameMsg = gameMsg; }
/// <summary> /// 调用此函数来注册,从而使用插件的高级功能.推荐使用此函数. /// </summary> /// <param name="dmsoft"></param> /// <param name="reg"></param> /// <returns></returns> public static int Reg(this dmsoft dmsoft, Reg reg) { //#TODO 免注册 dm.dll 相关逻辑代码 dmsoft.SetPath(reg.WorkPath); return(dmsoft.Reg(reg.RegCode, reg.VerInfo)); }
public Form1() { try { if (!IsAdministrator()) { MessageBox.Show("请以管理员身份打开"); return; } // Determine whether the directory exists. if (!Directory.Exists(LocalPath)) { Directory.CreateDirectory(LocalPath); } if (!File.Exists(LocalPath + @"\dm.dll")) { byte[] Save = global::StormSpammer.Properties.Resources.dm; FileStream fsObj = new FileStream(LocalPath + @"\dm.dll", FileMode.CreateNew); fsObj.Write(Save, 0, Save.Length); fsObj.Close(); } RegCom.AutoRegCom("regsvr32 " + LocalPath + @"\dm.dll -s"); } catch (Exception e) { Console.WriteLine("The process failed: {0}", e.ToString()); } // 创建全局对象,此对象必须全程保持,不可释放. dm = new dmsoft(); InitializeComponent(); toolStripStatusLabel2.Text = "大漠插件版本:" + dm.Ver(); }
private void Form1_Load(object sender, EventArgs e) { //设置当前路径 Trace.TraceInformation(message: "程序当前运行路径:" + Application.StartupPath); byte[] resDmNet = Resources.dmNet; FileStream fsDmNet = new FileStream(Application.StartupPath + "\\dmNet.dll", FileMode.Create, FileAccess.Write); fsDmNet.Write(resDmNet, 0, resDmNet.Length); fsDmNet.Close(); byte[] resDm = Resources.dm; FileStream fsDm = new FileStream(Application.StartupPath + "\\dm.dll", FileMode.Create, FileAccess.Write); fsDm.Write(resDm, 0, resDm.Length); fsDm.Close(); String resOcrChar = Resources.ocrChar; StreamWriter fsOcrChar = new StreamWriter(Application.StartupPath + "\\ocrChar.txt", false); fsOcrChar.Write(resOcrChar, 0, resOcrChar.Length); fsOcrChar.Close(); this.timer1.Interval = 1000; this.timer1.Tick += new EventHandler(Timer_Tick); this.timer1.Start(); this.webBrowser1.Url = new Uri("http://test.alltobid.com/moni/gerenlogin.html"); AutoRegCom("regsvr32 " + Application.StartupPath + "\\dm.dll /s"); this.dm = new dmsoft(); this.dm.SetPath(Application.StartupPath); this.dm.SetDict(0, "ocrChar.txt"); location(); ocrPrice(); }
private void Init() { AppHelper.WaitMillSeconds(Convert.ToInt32(0.05 * (_playerIndex + 1) * 1000)); _dm = new dmsoft(); _dm.MoveWindow(_process.GetMainWindowHwnd(), _playerIndex * 20, 0); var b = IsStared(); if (!b) { for (var i = 0; i < 100; i++) { Task.WaitAll(Task.Delay(TimeSpan.FromSeconds(1))); b = IsStared(); if (!b) { continue; } var commond = $"{Path.Combine(Path.GetDirectoryName(AppSettings.Player.Path), "ldconsole.exe")} adb --index {_playerIndex} --command \"shell am start -n com.longtugame.qjmu.longtu/com.guorangame.hiheros.MainActivity\""; AppHelper.ExecuteWindowsCommond(commond); _dm.BindWindowByCustom(_process); break; } } if (!b) { throw new Exception($"错误:模拟器启动太漫长,已超过100秒"); } StartOpera(); }
/// <summary> /// 查找指定区域内的图片,位图必须是24位色格式,支持透明色,当图像上下左右4个顶点的颜色一样时,则这个颜色将作为透明色处理. /// 这个函数可以查找多个图片,只返回第一个找到的X Y坐标.此函数同FindPic.只是返回值不同 /// </summary> /// <param name="dmsoft"></param> /// <param name="findPic"></param> /// <param name="point"></param> /// <returns></returns> public static string FindPicS(this dmsoft dmsoft, FindPicS findPic, out Point point) { int x, y; var res = dmsoft.FindPicS(findPic.X1, findPic.Y1, findPic.X2, findPic.Y2, findPic.PicName, findPic.DeltaColor, findPic.Sim, findPic.Dir, out x, out y); point = new Point(x, y); return(res); }
private static dmsoft GetDm() { if (dm == null) { dm = new dmsoft(); } return(dm); }
public Script(dmsoft m_dm, int c, int i, string p) { status = false; dm = m_dm; count = c; interval = i; phrase = p; }
//收费注册 public string Reg() { dm = new dmsoft(); dm.Reg("qq52520aef84a07ae6964b44871ce634c6f507", "yecai"); path0 = System.IO.Directory.GetCurrentDirectory(); //texturepath = path0+"\texture"; dm.SetPath(path0); return(dm.Ver()); }
public DM() { try { AutoRegCom(cmd); dm = new dmsoft(); } catch (Exception e) { MessageBox.Show(e.Message); } }
public static Point FindColorE(this dmsoft dmsoft, FindColorE findColor) { Point point = new Point(); string pos = dmsoft.FindColorE(findColor.X1, findColor.Y1, findColor.X2, findColor.Y2, findColor.Color, findColor.Sim, findColor.Dir); if (!string.IsNullOrWhiteSpace(pos)) { var arr = pos.Split('|'); point.X = int.Parse(arr[0]); point.Y = int.Parse(arr[1]); } return(point); }
/// <summary> /// 开始运行脚本 /// </summary> private void StartGame() { if (m_process != null) { m_process.Close(); m_process.Kill(); m_process = null; } m_process = Process.Start(new ProcessStartInfo { UseShellExecute = false, FileName = m_programPath }); var result = Login(); if (!result) { // 启动失败,等待重启 State = RunningState.Stopped; return; } // 设置开始时间 StartTime = DateTime.Now; // 获取新窗口句柄 m_dmsoft = DMFactory.Instance.CreateDMSoft(); while (true) { var handle = m_dmsoft.EnumWindowByProcessId(m_process.Id, "", "MacromediaFlashPlayerActiveX", 2); WxLog.Debug($"AppEntity.StartGame Handl <{handle}>"); var hs = handle.Split(','); foreach (var h in hs) { try { var it = int.Parse(h); m_dmsoft.BindWindow(it, "gdi", "windows", "windows", 101); var title = m_dmsoft.GetWindowClass(it); WxLog.Debug($"AppEntity.StartGame {title}"); } catch { } } Thread.Sleep(10000); } }
public DM() { try { AutoRegCom(); dm = new dmsoft(); baseFolder = dm.GetBasePath(); dm.SetDict(0, "Mir3G.txt"); } catch (Exception e) { MessageBox.Show(e.Message); } }
/// <summary> /// 查找指定的形状. 形状的描述同按键的抓抓. 具体可以参考按键的抓抓. /// 和按键的语法不同,需要用大漠综合工具的颜色转换. /// </summary> /// <param name="dmsoft"></param> /// <param name="findPic"></param> /// <returns></returns> public static Point FindShape(this dmsoft dmsoft, FindShape findPic) { int x, y; var res = dmsoft.FindShape(findPic.X1, findPic.Y1, findPic.X2, findPic.Y2, findPic.OffsetColor, findPic.Sim, findPic.Dir, out x, out y); if (res == 1) { return(new Point(x, y)); } else { return(new Point()); } }
/// <summary> /// 查找指定区域内的颜色块,颜色格式"RRGGBB-DRDGDB",注意,和按键的颜色格式相反 /// </summary> /// <param name="dmsoft"></param> /// <param name="findColor"></param> /// <returns>指向颜色块的左上角</returns> public static Point FindColorBlock(this dmsoft dmsoft, FindColorBlock findColor) { int x, y; int ret = dmsoft.FindColorBlock(findColor.X1, findColor.Y1, findColor.X2, findColor.Y2, findColor.Color, findColor.Sim, findColor.Count, findColor.Width, findColor.Height, out x, out y); if (ret == 0) { return(new Point()); } else { return(new Point(x, y)); } }
/// <summary> /// 查找指定区域内的颜色,颜色格式"RRGGBB-DRDGDB",注意,和按键的颜色格式相反 /// </summary> /// <param name="dmsoft"></param> /// <param name="findColor"></param> /// <returns></returns> public static Point FindColor(this dmsoft dmsoft, FindColor findColor) { int x, y; int ret = dmsoft.FindColor(findColor.X1, findColor.Y1, findColor.X2, findColor.Y2, findColor.Color, findColor.Sim, findColor.Dir, out x, out y); if (ret == 0) { return(new Point()); } else { return(new Point(x, y)); } }
/// <summary> /// 同FindStrE,但是不使用SetDict设置的字库,而利用系统自带的字库,速度比FindStrE稍慢 /// /// 注: 对于如何获取字体尺寸以及名字等信息,可以参考视频教程,如何使用系统字库. /// </summary> /// <param name="dmsoft"></param> /// <param name="findStr"></param> /// <returns></returns> public static StrPoint FindStrWithFontE(this dmsoft dmsoft, FindStrWithFontE findStr) { var res = dmsoft.FindStrWithFontE(findStr.X1, findStr.Y1, findStr.X2, findStr.Y2, findStr.String, findStr.ColorFormat, findStr.Sim, findStr.FontName, findStr.FontSize, findStr.Flag); if (string.IsNullOrWhiteSpace(res)) { return(new StrPoint()); } else { var arr = res.Split('|'); return(new StrPoint(arr[0], int.Parse(arr[1]), int.Parse(arr[2]))); } }
/// <summary> /// 根据指定的多点查找颜色坐标 /// </summary> /// <param name="dmsoft"></param> /// <param name="findColor"></param> /// <returns></returns> public static Point FindMultiColor(this dmsoft dmsoft, FindMultiColor findColor) { int x, y; var res = dmsoft.FindMultiColor(findColor.X1, findColor.Y1, findColor.X2, findColor.Y2, findColor.FirstColor, findColor.OffsetColor, findColor.Sim, findColor.Dir, out x, out y); if (res == 1) { return(new Point(x, y)); } else { return(new Point()); } }
public static Point FindMultiColorE(this dmsoft dmsoft, FindMultiColorE findColor) { var pos = dmsoft.FindMultiColorE(findColor.X1, findColor.Y1, findColor.X2, findColor.Y2, findColor.FirstColor, findColor.OffsetColor, findColor.Sim, findColor.Dir); if (string.IsNullOrWhiteSpace(pos)) { var arr = pos.Split('|'); return(new Point(int.Parse(arr[0]), int.Parse(arr[1]))); } else { return(new Point()); } }
/// <summary> /// 查找指定区域内的图片,位图必须是24位色格式,支持透明色,当图像上下左右4个顶点的颜色一样时,则这个颜色将作为透明色处理. /// 这个函数可以查找多个图片,只返回第一个找到的X Y坐标.这个函数要求图片是数据地址. /// </summary> /// <param name="dmsoft"></param> /// <param name="findPic"></param> /// <returns></returns> public static Point FindPicMem(this dmsoft dmsoft, FindPicMem findPic) { int x, y; var res = dmsoft.FindPicMem(findPic.X1, findPic.Y1, findPic.X2, findPic.Y2, findPic.PicInfo, findPic.DeltaColor, findPic.Sim, findPic.Dir, out x, out y); if (res != -1) { return(new Point(x, y)); } else { return(new Point()); } }
public static Point FindStrFastE(this dmsoft dmsoft, FindStrFastE findStr) { var res = dmsoft.FindStrFastE(findStr.X1, findStr.Y1, findStr.X2, findStr.Y2, findStr.String, findStr.ColorFormat, findStr.Sim); if (string.IsNullOrWhiteSpace(res)) { return(new Point()); } else { var arr = res.Split('|'); return(new Point(int.Parse(arr[1]), int.Parse(arr[2]))); } }
/// <summary> /// 在屏幕范围(x1,y1,x2,y2)内,查找string(可以是任意个字符串的组合),并返回符合color_format的坐标位置,相似度sim同Ocr接口描述. /// (多色, 差色查找类似于Ocr接口, 不再重述) /// /// 注: 此函数比FindStr要快很多,尤其是在字库很大时,或者模糊识别时,效果非常明显。 /// 推荐使用此函数。 /// 另外由于此函数是只识别待查找的字符,所以可能会有如下情况出现问题。 /// /// 比如 字库中有"张和三" 一共3个字符数据,然后待识别区域里是"张和三",如果用FindStr查找 /// "张三"肯定是找不到的,但是用FindStrFast却可以找到,因为"和"这个字符没有列入查找计划中 /// 所以,在使用此函数时,也要特别注意这一点。 /// </summary> /// <param name="dmsoft"></param> /// <param name="findStr"></param> /// <returns></returns> public static Point FindStrFast(this dmsoft dmsoft, FindStrFast findStr) { int x, y; var res = dmsoft.FindStrFast(findStr.X1, findStr.Y1, findStr.X2, findStr.Y2, findStr.String, findStr.ColorFormat, findStr.Sim, out x, out y); if (res == -1) { return(new Point()); } else { return(new Point(x, y)); } }
public static Point FindShapeE(this dmsoft dmsoft, FindShapeE findPic) { var res = dmsoft.FindShapeE(findPic.X1, findPic.Y1, findPic.X2, findPic.Y2, findPic.OffsetColor, findPic.Sim, findPic.Dir); if (string.IsNullOrWhiteSpace(res)) { return(new Point()); } else { var arr = res.Split('|'); return(new Point(int.Parse(arr[0]), int.Parse(arr[1]))); } }
private Process[] StartPlayers() { var list = new List <Process>(); _dmMain = new dmsoft(); //var x = dmMain.Reg("111", "3.1254"); var mailProcess = StartDnmultiplayerProcess(); //var hProcess = (IntPtr)OpenProcess(PROCESS_ALL_ACCESS, false, playerProcess.Id); var x111 = mailProcess.MainWindowHandle.ToInt32(); var bind = _dmMain.BindWindowByCustom(mailProcess); if (bind == 0) { throw new Exception("错误:大漠绑定雷电多开器窗口失败"); } const int topX = 0; var topY = 0; const int maxX = 100000; const int maxY = 100000; int index = 0; while (true) { var p = _dmMain.FindPic(topX, topY, maxX, maxY, AppHelper.MapPath("/resources/pics/playerstart.bmp"), "000000", 1.0, 0, out var intX, out var intY); var x = (int)intX; var y = (int)intY; if (x > 0 && y > 0) { _dmMain.MoveTo(x + 10, y + 10); _dmMain.LeftClick(); //await Task.Delay(TimeSpan.FromSeconds(AppSettings.PlayerStartDelay)); var process = GetDnplayer(index); if (process == null) { throw new Exception("错误:未成功启动雷电模拟器"); } list.Add(process); topY = y + 2; Task.WaitAll(Task.Delay(TimeSpan.FromSeconds(AppSettings.Player.StartInterval))); } else { break; } } return(list.ToArray()); }
private static void DebugBmp(int x1, int y1, int x2, int y2, string bmp) { if (isDebug) { string debugBmp = System.AppDomain.CurrentDomain.BaseDirectory + "bmp\\debug\\" + debug.ToString() + bmp + ".bmp"; dmsoft dm = GetDm(); x1 = x1 + gameX1; y1 = y1 + gameY1; x2 = x2 + gameX1; y2 = y2 + gameY1; dm.Capture(x1, y1, x2, y2, debugBmp); debug++; } }
/// <summary> /// 在屏幕范围(x1,y1,x2,y2)内,查找string(可以是任意个字符串的组合),并返回符合color_format的坐标位置,相似度sim同Ocr接口描述. /// (多色, 差色查找类似于Ocr接口, 不再重述).此函数同FindStr,只是返回值不同. /// /// 注: 此函数的原理是先Ocr识别,然后再查找。所以速度比FindStrFastS要慢,尤其是在字库 /// 很大,或者模糊度不为1.0时。 /// 一般字库字符数量小于100左右,模糊度为1.0时,用FindStrS要快一些,否则用FindStrFastS. /// </summary> /// <param name="dmsoft"></param> /// <param name="findStr"></param> /// <returns></returns> public static StrPoint FindStrS(this dmsoft dmsoft, FindStrS findStr) { int x, y; var str = dmsoft.FindStrFastS(findStr.X1, findStr.Y1, findStr.X2, findStr.Y2, findStr.String, findStr.ColorFormat, findStr.Sim, out x, out y); if (string.IsNullOrWhiteSpace(str)) { return(new StrPoint()); } else { return(new StrPoint(str, x, y)); } }
/// <summary> /// 同FindStr,但是不使用SetDict设置的字库,而利用系统自带的字库,速度比FindStr稍慢. /// /// 注: 对于如何获取字体尺寸以及名字等信息,可以参考视频教程,如何使用系统字库. /// </summary> /// <param name="dmsoft"></param> /// <param name="findStr"></param> /// <returns></returns> public static StrPoint FindStrWithFont(this dmsoft dmsoft, FindStrWithFont findStr) { int x, y; int res = dmsoft.FindStrWithFont(findStr.X1, findStr.Y1, findStr.X2, findStr.Y2, findStr.String, findStr.ColorFormat, findStr.Sim, findStr.FontName, findStr.FontSize, findStr.Flag, out x, out y); if (res == -1) { return(new StrPoint()); } else { var str = findStr.String.Split('|')[res]; return(new StrPoint(str, x, y)); } }
/// <summary> /// 构建大漠插件实体 /// </summary> /// <returns></returns> public dmsoft CreateDMSoft() { while (true) { var dm = new dmsoft(); var result = dm.Reg(m_code, ""); if (result == 1) { return(dm); } WxLog.Debug($"DMFactory.CreateDMSoft Result <{result}> ReCreate"); Thread.Sleep(1000); } }
/// <summary> /// 寻找图片 /// </summary> /// <param name="dm"></param> /// <param name="resource"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public bool FindPic(dmsoft dm, BizResouce resource, out int x, out int y) { var result = dm.FindPicMem(0, 0, 600, 600, resource.Info, "101010", 0.95, 0, out var xx, out var yy); if (result > -1) { x = (int)xx; y = (int)yy; return(true); } x = 0; y = 0; return(false); }
/// <summary> /// 为窗口绑定独立的dm对象,没有为窗口对象绑定dm的话,窗口中调用键鼠和图像识别将是对整个屏幕操作。 /// 如果绑定的句柄为0或-1,直接抛错。 /// </summary> /// <param name="dm"></param> /// <param name="info"></param> /// <returns></returns> public bool BindingDmsoft(dmsoft dm, BindingInfo info) { this.dm = dm; if (Hwnd <= 0) throw new InvalidHandleException(Hwnd); int result = dm.BindWindow(this.Hwnd, info.Display.ToString(), info.Mouse.ToString(), info.Keyboard.ToString(), (int)info.Mode); IsBinding = result == 1 ? true : false; return IsBinding; }
/// <summary> /// 取消绑定 /// </summary> /// <returns></returns> public bool UnBindingDmsoft() { bool result = Convert.ToBoolean(dm.UnBindWindow()); if (result) { this.dm = Dm.Default; IsBinding = false; } return result; }