Example #1
0
        private bool FeiliuLogin(Account account, Role role)
        {
            DmPlugin        Dm          = role.Window.Dm;
            YeShenSimulator ysSimulator = SoftContext.YeShenSimulatorList.FirstOrDefault(x => x.NoxHwnd == role.Hwnd);
            string          noxPath     = "";

            if (File.Exists(@"E:\nox\Nox\bin\nox_adb.exe"))
            {
                noxPath = @"E:\nox\Nox\bin\";
            }
            if (File.Exists(@"E:\Nox\bin\nox_adb.exe"))
            {
                noxPath = @"E:\Nox\bin\";
            }
            string result = CmdHelper.ExecuteCmd(noxPath + @"nox_adb -s " + ysSimulator.AdbDevicesId + @" shell dumpsys window w|findstr \/|findstr name=");

            result = result.Replace("mSurface=Surface(name=", "").Replace(")", "");
            //com.regin.gcld.fl/com.regin.gcld.fl.gcld
            if (result.IndexOf("gcld") > 0) //当前应用程序是攻城掠地
            {
                int index = result.IndexOf('/');
                CmdHelper.ExecuteCmd(noxPath + @"nox_adb -s " + ysSimulator.AdbDevicesId + " shell am force-stop " + result.Remove(index, result.Length - index));
                Dm.Delay(5000);
            }
            switch (account.Platform)
            {
            case Platform.飞流:
                CmdHelper.ExecuteCmd(noxPath + @"nox_adb -s " + ysSimulator.AdbDevicesId + " shell am start -n com.regin.gcld.fl/.gcld");
                Delegater.WaitTrue(() => Dm.IsExistPic(279, 37, 476, 100, @"\bmp\飞流帐号登录.bmp", 0.9), () => Dm.Delay(1000), 20);
                Dm.Delay(1000);
                if (Dm.IsExistPic(279, 37, 476, 100, @"\bmp\飞流帐号登录.bmp", 0.9))
                {
                    Dm.Delay(1000);
                    Dm.MoveToClick(562, 156);
                    Dm.Delay(500);
                    for (int i = 0; i < 20; i++)
                    {
                        if (Dm.GetColorNum(292, 121, 414, 176, "ffffff-101010", 0.9) > 5)
                        {
                            CmdHelper.ExecuteCmd(string.Format("{0}nox_adb -s {1} shell input keyevent 67", noxPath, ysSimulator.AdbDevicesId));
                            Dm.Delay(200);
                        }
                        else
                        {
                            break;
                        }
                    }

                    CmdHelper.ExecuteCmd(noxPath + @"nox_adb -s " + ysSimulator.AdbDevicesId + " shell input text \"" + account.UserName + "\"");
                    Dm.Delay(1000);
                    Dm.MoveToClick(577, 218);
                    Dm.Delay(500);
                    for (int i = 0; i < 20; i++)
                    {
                        if (Dm.GetColorNum(290, 192, 444, 245, "ffffff-101010", 0.9) > 5)
                        {
                            CmdHelper.ExecuteCmd(noxPath + @"nox_adb -s " + ysSimulator.AdbDevicesId + " shell input keyevent 67");
                            Dm.Delay(200);
                        }
                        else
                        {
                            break;
                        }
                    }
                    CmdHelper.ExecuteCmd(noxPath + "nox_adb -s " + ysSimulator.AdbDevicesId + " shell input text \"" + account.Password + "\"");
                    Dm.Delay(1000);
                    Dm.FindPicAndClick(413, 279, 543, 348, @"\bmp\登录.bmp");

                    return(Delegater.WaitTrue(() => {
                        if (Dm.IsExistPic(818, 281, 953, 447, @"\bmp\世界.bmp") || Dm.IsExistPic(818, 281, 953, 447, @"\bmp\副本.bmp"))
                        {
                            while (Dm.IsExistPic(406, 378, 557, 432, @"\bmp\以后再说.bmp", 0.8))
                            {
                                Dm.MoveToClick(544, 414);
                                Dm.Delay(1000);
                            }
                            Dm.Delay(1000);
                            return true;
                        }
                        return false;
                    }, () => Dm.Delay(1000), 25));
                }
                break;

            case Platform.楚游:
                CmdHelper.ExecuteCmd(noxPath + @"nox_adb -s " + ysSimulator.AdbDevicesId + " shell am start -n com.regin.gcld.sy/.gcld");
                Delegater.WaitTrue(() => Dm.GetColorNum(113, 288, 193, 317, "f6c246-202020", 0.9) > 1000, () => Dm.Delay(1000), 20);
                Dm.Delay(1000);
                if (Dm.GetColorNum(113, 288, 193, 317, "f6c246-202020", 0.9) > 1000)
                {
                    Dm.Delay(1000);
                    Dm.MoveToClick(233, 203);
                    Dm.Delay(500);
                    for (int i = 0; i < 20; i++)
                    {
                        if (Dm.GetColorNum(67, 187, 210, 216, "242424-202030", 0.9) > 5)
                        {
                            CmdHelper.ExecuteCmd(string.Format("{0}nox_adb -s {1} shell input keyevent 67", noxPath, ysSimulator.AdbDevicesId));
                            Dm.Delay(200);
                        }
                        else
                        {
                            break;
                        }
                    }
                    CmdHelper.ExecuteCmd(noxPath + @"nox_adb -s " + ysSimulator.AdbDevicesId + " shell input text \"" + account.UserName + "\"");
                    Dm.Delay(1000);
                    Dm.MoveToClick(235, 246);
                    Dm.Delay(500);
                    for (int i = 0; i < 20; i++)
                    {
                        if (Dm.GetColorNum(70, 230, 209, 263, "242424-202030", 0.9) > 5)
                        {
                            CmdHelper.ExecuteCmd(string.Format("{0}nox_adb -s {1} shell input keyevent 67", noxPath, ysSimulator.AdbDevicesId));
                            Dm.Delay(200);
                        }
                        else
                        {
                            break;
                        }
                    }
                    CmdHelper.ExecuteCmd(noxPath + "nox_adb -s " + ysSimulator.AdbDevicesId + " shell input text \"" + account.Password + "\"");
                    Dm.Delay(500);
                    Dm.MoveToClick(149, 302);

                    return(Delegater.WaitTrue(() => {
                        if (Dm.IsExistPic(818, 281, 953, 447, @"\bmp\世界.bmp") || Dm.IsExistPic(818, 281, 953, 447, @"\bmp\副本.bmp"))
                        {
                            //while (Dm.IsExistPic(406, 378, 557, 432, @"\bmp\以后再说.bmp", 0.8))
                            //{
                            //    Dm.MoveToClick(544, 414);
                            //    Dm.Delay(1000);
                            //}
                            //Dm.Delay(1000);
                            return true;
                        }
                        return false;
                    }, () => Dm.Delay(1000), 25));
                }
                break;
            }
            return(false);
        }
Example #2
0
        public static void UpdateSimulator()
        {
            if (DmSystem == null)
            {
                return;;
            }
            DmPlugin dm = DmSystem.Dm;

            string hwnds = dm.EnumWindow(0, "QWidgetClassWindow", "Qt5QWindowIcon", 3);

            if (hwnds == "")
            {
                Debug.WriteLine("获取句柄失败!");
                return;
            }
            else
            {
                Debug.WriteLine(hwnds);
            }

            Process p = new Process();

            p.StartInfo.FileName               = "cmd.exe"; //设置启动的应用程序
            p.StartInfo.UseShellExecute        = false;     //禁止使用操作系统外壳程序启动进程
            p.StartInfo.RedirectStandardInput  = true;      //应用程序的输入从流中读取
            p.StartInfo.RedirectStandardOutput = true;      //应用程序的输出写入流中
            p.StartInfo.RedirectStandardError  = true;      //将错误信息写入流
            p.StartInfo.CreateNoWindow         = true;      //是否在新窗口中启动进程
            p.Start();
            p.StandardInput.WriteLine(@"netstat -aon|findstr ""ESTABLISHED""");
            p.StandardInput.WriteLine("exit");
            Regex          reg  = new Regex("\\s+", RegexOptions.Compiled);
            string         line = "";
            List <NetStat> list = new List <NetStat>();

            while ((line = p.StandardOutput.ReadLine()) != null)
            {
                line = line.Trim();
                if (line.StartsWith("TCP", StringComparison.OrdinalIgnoreCase))
                {
                    line = reg.Replace(line, ",");
                    string[] arr = line.Split(',');
                    if (arr.Length == 5)
                    {
                        if (arr[1].StartsWith("127.0.0.1") && arr[2].StartsWith("127.0.0.1") || arr[2].StartsWith(ServerIp))
                        {
                            NetStat netstat = new NetStat()
                            {
                                Proto          = arr[0],
                                LocalAddress   = arr[1],
                                ForeignAddress = arr[2],
                                State          = arr[3],
                                Pid            = arr[4]
                            };
                            list.Add(netstat);
                        }
                    }
                }
            }
            //移除所有不存在的窗口
            YeShenSimulatorList.RemoveAll(x => !dm.GetWindowState(x.NoxHwnd, 0));
            foreach (var hwnd in hwnds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(Int32.Parse).ToList())
            {
                YeShenSimulator yss = new YeShenSimulator();
                var             s   = YeShenSimulatorList.FirstOrDefault(x => x.NoxHwnd == hwnd);
                if (s != null)
                {
                    if (s.NoxVMHandlePid == 0)
                    {
                        yss.NoxHwnd = s.NoxHwnd;
                        yss.NoxPid  = s.NoxPid;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    yss.NoxHwnd = hwnd;
                    yss.NoxPid  = dm.GetWindowProcessId(hwnd);
                }
                try
                {
                    //找到模拟器Nox所对应连接NoxVMHandle,可能有多个连接
                    List <NetStat> ln1 = list.FindAll(a => a.Pid == yss.NoxPid.ToString());
                    //本地远程相反的连接就是NoxVMHandle,获得NoxVMHandle进程Id,n2为NoxVMHandle进程与Nox一个链接
                    NetStat n2 = list.First(b => b.ForeignAddress == ln1.FirstOrDefault().LocalAddress&& b.LocalAddress == ln1.FirstOrDefault().ForeignAddress);
                    //找到该进程id的另一个连接就是adb连接
                    NetStat n3 = list.FirstOrDefault(c => c.Pid == n2.Pid && (ln1.FirstOrDefault(x => x.ForeignAddress == c.LocalAddress)) == null);
                    if (n3 != null)
                    {
                        yss.NoxVMHandlePid = int.Parse(n3.Pid);
                        yss.AdbDevicesId   = n3.LocalAddress; //对应的本地地址就是adb设备地址
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }

                YeShenSimulatorList.Add(yss);
            }
            p.Close();
            Debug.WriteLine("当前打开的模拟器:" + YeShenSimulatorList.Count);
        }