Exemplo n.º 1
0
 private void MainScreen_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (ScriptRun.Run)
     {
         Button3_Click(sender, e);
     }
     EmulatorLoader.EjectSockets();
     Environment.Exit(0);
 }
Exemplo n.º 2
0
 private void Button3_Click(object sender, EventArgs e)
 {
     if (cap != null)
     {
         try
         {
             if (cap.IsAlive)
             {
                 cap.Abort();
             }
         }
         catch
         {
         }
     }
     PrivateVariable.Instance.nospam        = DateTime.Now;
     PrivateVariable.Instance.Battling      = false;
     PrivateVariable.Instance.InEventScreen = false;
     PrivateVariable.Instance.InMainScreen  = false;
     PrivateVariable.Instance.InMap         = false;
     EmulatorLoader.EjectSockets();
     Variables.ScriptLog("Script Stopped!", Color.White);
     if (Width > 1280)
     {
         Width         -= 1280;
         panel3.Visible = false;
     }
     if (Variables.Proc != null)
     {
         DllImport.SetParent(Variables.Proc.MainWindowHandle, IntPtr.Zero);
         DllImport.MoveWindow(Variables.Proc.MainWindowHandle, PrivateVariable.Instance.EmuDefaultLocation.X, PrivateVariable.Instance.EmuDefaultLocation.Y, 1318, 752, true);
     }
     foreach (Control control in Debug.Controls)
     {
         control.Enabled = true;
     }
     ScriptRun.StopScript();
     btn_Start.Enabled = true;
     Controls.Remove(tp);
 }
Exemplo n.º 3
0
 /// <summary>
 /// The emulator path that is installed at PC with outputing the emulator enum
 /// </summary>
 public static void LoadEmulator()
 {
     EmulatorLoader.LoadEmulatorInterface();
     if (emulator == null)
     {
         throw new FileNotFoundException("No supported emulators detected!");
     }
     else
     {
         if (!string.IsNullOrEmpty(VBoxManagerPath))
         {
             if (!File.Exists(VBoxManagerPath))
             {
                 throw new FileNotFoundException("Emulator exe file is not found in " + VBoxManagerPath + "!");
             }
         }
         else
         {
             throw new FileNotFoundException("Emulator don't have installed exe exist detected by BotFramework! Please make sure the VBoxManagerPath is not null or empty before proceed!");
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Fast Capturing screen and return the image, uses WinAPI capture if Variables.Background is false.
        /// </summary>
        public static ScreenshotData ImageCapture([CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null)
        {
            if (!ScriptRun.Run)
            {
                return(null);
            }
            if (Variables.WinApiCapt && !Instance.captureerror)
            {
                if (Variables.ProchWnd != null)
                {
                    return(ImageCapture(Variables.ProchWnd, Variables.WinApiCaptCropStart, Variables.WinApiCaptCropEnd, lineNumber, caller));
                }
                else
                {
                    return(ImageCapture(Variables.Proc.MainWindowHandle, Variables.WinApiCaptCropStart, Variables.WinApiCaptCropEnd, lineNumber, caller));
                }
            }
            Instance.captureerror = false;
            try
            {
                Stopwatch s = Stopwatch.StartNew();
                if (!Directory.Exists(Variables.SharedPath))
                {
                    Variables.ScriptLog("Warning, unable to find shared folder! Trying to use WinAPI!", Color.Red);
                    Variables.WinApiCapt = true;
                    return(ImageCapture(Variables.Proc.MainWindowHandle, Variables.WinApiCaptCropStart, Variables.WinApiCaptCropEnd, lineNumber, caller));
                }
                if (AdbInstance.Instance.pcimagepath == "" || AdbInstance.Instance.androidimagepath == "")
                {
                    var tempname = Encryption.SHA256(DateTime.Now.ToString());
                    AdbInstance.Instance.pcimagepath = (Variables.SharedPath + "\\" + tempname + ".rgba").Replace("\\\\", "\\");
                    if (Variables.AndroidSharedPath.Contains("|"))
                    {
                        foreach (var path in Variables.AndroidSharedPath.Split('|'))
                        {
                            if (EmulatorLoader.AndroidDirectoryExist(path))
                            {
                                string temppath = path;
                                if (temppath.Last() != '/')
                                {
                                    temppath += "/";
                                }
                                AdbInstance.Instance.androidimagepath = (temppath + tempname + ".rgba");
                                Variables.AdvanceLog("Multiple Android Path settes, selected " + AdbInstance.Instance.androidimagepath);
                                break;
                            }
                        }
                    }
                    else
                    {
                        AdbInstance.Instance.androidimagepath = (Variables.AndroidSharedPath + tempname + ".rgba");
                    }
                }
                byte[] raw = null;

                if (Variables.Controlled_Device == null)
                {
                    Variables.AdvanceLog("No device connected!", lineNumber, caller);
                    EmulatorLoader.ConnectAndroidEmulator();
                    return(null);
                }
                if ((Variables.Controlled_Device as DeviceData).State == SharpAdbClient.DeviceState.Offline || !ScriptRun.Run)
                {
                    return(null);
                }
                ConsoleOutputReceiver receiver = new ConsoleOutputReceiver();
                AdbInstance.Instance.client.ExecuteRemoteCommand("screencap " + AdbInstance.Instance.androidimagepath, (Variables.Controlled_Device as DeviceData), receiver);
                if (Variables.NeedPull)
                {
                    if (File.Exists(AdbInstance.Instance.pcimagepath))
                    {
                        File.Delete(AdbInstance.Instance.pcimagepath);
                    }
                    BotCore.Pull(AdbInstance.Instance.androidimagepath, AdbInstance.Instance.pcimagepath);
                }
                if (!File.Exists(AdbInstance.Instance.pcimagepath))
                {
                    Variables.AdvanceLog("Unable to read rgba file because of file not exist!", lineNumber, caller);
                    return(null);
                }
                raw = File.ReadAllBytes(AdbInstance.Instance.pcimagepath);
                int expectedsize = (Variables.EmulatorHeight * Variables.EmulatorWidth * 4) + 12;
                if (raw.Length != expectedsize || raw.Length > int.MaxValue || raw.Length < 1)
                {
                    //Image is not in same size, resize emulator
                    EmulatorLoader.ResizeEmulator();
                    return(null);
                }
                byte[] img = new byte[raw.Length - 12]; //remove header
                Array.Copy(raw, 12, img, 0, img.Length);
                Image <Rgba, byte> image = new Image <Rgba, byte>(Variables.EmulatorWidth, Variables.EmulatorHeight);
                image.Bytes = img;
                if (Variables.ImageDebug)
                {
                    image.Save("Profiles\\Logs\\" + Encryption.SHA256(DateTime.Now.ToString()) + ".bmp");
                }
                Variables.AdvanceLog("Screenshot saved to memory used " + s.ElapsedMilliseconds + " ms", lineNumber, caller);
                s.Stop();
                return(Compress(image.Bitmap));
            }
            catch (IOException)
            {
            }
            catch (ArgumentOutOfRangeException)
            {
            }
            return(null);
        }
Exemplo n.º 5
0
        private static void _RunScript(bool KeepRunning, ScriptInterface script)
        {
            if (script != null)
            {
                do
                {
                    try
                    {
                        script.Script();
                        errornum = 0;
                    }
                    catch (Exception ex)
                    {
                        if (ex is SocketException || ex is DeviceNotFoundException || ex is AdbException)
                        {
                            Variables.ScriptLog("Exception found! Restarting emulator as emulator had closed!", Color.Red);
Start:
                            try
                            {
                                AdbInstance.Instance.server.RestartServer();
                            }
                            catch
                            {
                                Variables.ScriptLog("Adb start failed! Retrying in 3 seconds!");
                                BotCore.Delay(3000);
                                goto Start;
                            }
                            try
                            {
                                EmulatorLoader.RestartEmulator();
                                BotCore.Delay(10000);
                                EmulatorLoader.ConnectAndroidEmulator();
                                script.ResetScript();
                            }
                            catch (Exception ex2)
                            {
                                if (ex2 is SocketException || ex2 is DeviceNotFoundException || ex2 is AdbException)
                                {
                                    goto Start;
                                }
                                else if (ex is ThreadAbortException) //Bot stopped
                                {
                                }
                                else
                                {
                                    ThrowException(ex2);
                                }
                            }
                            continue;
                        }
                        else if (ex is ThreadAbortException) //Bot stopped
                        {
                            script.ResetScript();
                        }
                        else
                        {
                            ThrowException(ex);
                            continue;
                        }
                    }
                }while (KeepRunning && Run);
            }
            else
            {
                throw new DllNotFoundException("No script dll found!");
            }
            Run = false;
        }