Beispiel #1
0
        public void OnPressed()
        {
            Logger.Instance.WriteGlobal("Hotkey pressed: {0}+{1} : {2}", _hotkey.Modifier.ToString().Replace(", ", "+"), _hotkey.Key, Name);

            // Get active window
            var hwnd = WinAPI.GetForegroundWindow();

            var test = BotSettings.Instance.Bots.FirstOrDefault(x => x.Diablo.MainWindowHandle == hwnd);

            if (test != null)
            {
                var diablo = test.Diablo;
                if (diablo == null)
                {
                    return;
                }
                AutoPosition.ManualPositionWindow(hwnd, diablo.X, diablo.Y, diablo.W, diablo.H);
                return;
            }
            test = BotSettings.Instance.Bots.FirstOrDefault(x => x.Demonbuddy.MainWindowHandle == hwnd);
            if (test != null)
            {
                var demonbuddy = test.Demonbuddy;
                if (demonbuddy == null)
                {
                    return;
                }
                AutoPosition.ManualPositionWindow(hwnd, demonbuddy.X, demonbuddy.Y, demonbuddy.W, demonbuddy.H);
                return;
            }
            Logger.Instance.WriteGlobal("Reposition Current Failed");
        }
Beispiel #2
0
        public void OnPressed()
        {
            Logger.Instance.WriteGlobal("Hotkey pressed: {0}+{1} : {2}", _hotkey.Modifier.ToString().Replace(", ", "+"), _hotkey.Key, Name);

            // Get active window
            var hwnd = WinAPI.GetForegroundWindow();

            var test = BotSettings.Instance.Bots.FirstOrDefault(x => x.Diablo.MainWindowHandle == hwnd);

            if (test != null)
            {
                var diablo = test.Diablo;
                if (diablo == null)
                {
                    return;
                }

                // Get window rectangle
                WinAPI.RECT rct;
                if (WinAPI.GetWindowRect(new HandleRef(test, hwnd), out rct))
                {
                    // Get screen where window is located
                    var rect   = new Rectangle(rct.Left, rct.Top, rct.Width, rct.Heigth);
                    var screen = Screen.FromRectangle(rect);
                    // Calculate window position
                    var posX = (screen.Bounds.Width * 0.5) - 400 + screen.Bounds.X;
                    var posY = (screen.Bounds.Height * 0.5) - 300 + screen.Bounds.Y;
                    // Set window position and size
                    AutoPosition.ManualPositionWindow(hwnd, (int)posX, (int)posY, 800, 600);
                }

                return;
            }
            Logger.Instance.WriteGlobal("Resize Current Failed");
        }
Beispiel #3
0
        public void Start()
        {
            if (!Parent.IsStarted)
            {
                return;
            }

            if (!File.Exists(Location))
            {
                Logger.Instance.Write("File not found: {0}", Location);
                return;
            }

            _isStopped = false;
            // Ping check
            while (Settings.Default.ConnectionCheckPing && !ConnectionCheck.PingCheck() && !_isStopped)
            {
                Parent.Status = "Wait on internet connection";
                Logger.Instance.WriteGlobal("PingCheck: Waiting 10 seconds and trying again!");
                Thread.Sleep(10000);
            }

            // Check valid host
            while (Settings.Default.ConnectionCheckIpHost && !ConnectionCheck.CheckValidConnection() && !_isStopped)
            {
                Parent.Status = "Wait on host validation";
                Logger.Instance.WriteGlobal("ConnectionValidation: Waiting 10 seconds and trying again!");
                Thread.Sleep(10000);
            }

            // Check if we need to create a Diablo clone
            if (Parent.UseDiabloClone)
            {
                DiabloClone.Create(Parent);
            }

            Parent.Status = "Prepare Diablo"; // Update Status

            General.AgentKiller();            // Kill all Agent.exe processes

            // Prepare D3 for launch
            var agentDBPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\Battle.net\Agent\agent.db";

            if (File.Exists(agentDBPath))
            {
                Logger.Instance.Write("Deleting: {0}", agentDBPath);
                try
                {
                    File.Delete(agentDBPath);
                }
                catch (Exception ex)
                {
                    Logger.Instance.Write("Failed to delete! Exception: {0}", ex.Message);
                    DebugHelper.Exception(ex);
                }
            }

            // Copy D3Prefs
            if (!string.IsNullOrEmpty(Parent.D3PrefsLocation))
            {
                D3Prefs();
            }

            // Registry Changes
            RegistryClass.ChangeLocale(Parent.Diablo.Language); // change language
            RegistryClass.ChangeRegion(Parent.Diablo.Region);   // change region

            if (UseIsBoxer)
            {
                IsBoxerStarter();
            }
            else if (Settings.Default.UseD3Starter)
            {
                ApocD3Starter();
            }
            else
            {
                try
                {
                    var arguments = "-launch";
                    var pi        = new ProcessStartInfo(Location2, arguments)
                    {
                        WorkingDirectory = Path.GetDirectoryName(Location2)
                    };
                    pi = UserAccount.ImpersonateStartInfo(pi, Parent);
                    // Set working directory to executable location
                    Parent.Status = "Starting Diablo"; // Update Status
                    Proc          = Process.Start(pi);
                }
                catch (Exception ex)
                {
                    Parent.Stop();
                    DebugHelper.Exception(ex);
                    return;
                }
            }

            if (!UseIsBoxer) // Don't want to fight with isboxer
            {
                if (CpuCount != Environment.ProcessorCount)
                {
                    ProcessorAffinity = AllProcessors; // set it to all ones
                    CpuCount          = Environment.ProcessorCount;
                }
                Proc.ProcessorAffinity = (IntPtr)ProcessorAffinity;
            }


            if (_isStopped)
            {
                return;             // Halt here when bot is stopped while we where waiting for it to become active
            }
            // Wait for d3 to fully load
            var state    = (Settings.Default.UseD3Starter || UseIsBoxer ? 0 : 2);
            var handle   = IntPtr.Zero;
            var timedout = false;

            LimitStartTime(true); // reset startup time
            while ((!Proc.HasExited && state < 4))
            {
                if (timedout)
                {
                    return;
                }
                //Debug.WriteLine("Splash: " + FindWindow.FindWindowClass("D3 Splash Window Class", Proc.Id) + " Main:" + FindWindow.FindWindowClass("D3 Main Window Class", Proc.Id));
                switch (state)
                {
                case 0:
                    handle = FindWindow.FindWindowClass("D3 Splash Window Class", Proc.Id);
                    if (handle != IntPtr.Zero)
                    {
                        Logger.Instance.Write("Diablo:{0}: Found D3 Splash Window ({1})", Proc.Id, handle);
                        state++;
                        LimitStartTime(true);     // reset startup time
                    }
                    timedout = LimitStartTime();
                    break;

                case 1:
                    handle = FindWindow.FindWindowClass("D3 Splash Window Class", Proc.Id);
                    if (handle == IntPtr.Zero)
                    {
                        Logger.Instance.Write("Diablo:{0}: D3 Splash Window Closed ({1})", Proc.Id, handle);
                        state++;
                        LimitStartTime(true);     // reset startup time
                    }
                    timedout = LimitStartTime();
                    break;

                case 2:
                    handle = FindWindow.FindWindowClass("D3 Main Window Class", Proc.Id);
                    if (handle != IntPtr.Zero)
                    {
                        Logger.Instance.Write("Diablo:{0}: Found D3 Main Window ({1})", Proc.Id, handle);
                        state++;
                        LimitStartTime(true);     // reset startup time
                    }
                    timedout = LimitStartTime();
                    break;

                case 3:
                    if (CrashChecker.IsResponding(handle))
                    {
                        MainWindowHandle = handle;
                        state++;
                        LimitStartTime(true);     // reset startup time
                    }
                    timedout = LimitStartTime();
                    break;
                }
                Thread.Sleep(500);
            }
            if (timedout)
            {
                return;
            }

            if (Program.IsRunAsAdmin)
            {
                Proc.PriorityClass = General.GetPriorityClass(Priority);
            }
            else
            {
                Logger.Instance.Write(Parent, "Failed to change priority (No admin rights)");
            }
            // Continue after launching stuff
            Logger.Instance.Write("Diablo:{0}: Waiting for process to become ready", Proc.Id);

            var timeout = DateTime.Now;

            while (true)
            {
                if (General.DateSubtract(timeout) > 30)
                {
                    Logger.Instance.Write("Diablo:{0}: Failed to start!", Proc.Id);
                    Parent.Restart();
                    return;
                }
                Thread.Sleep(500);
                try
                {
                    Proc.Refresh();
                    if (Proc.WaitForInputIdle(100) || CrashChecker.IsResponding(MainWindowHandle))
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    DebugHelper.Exception(ex);
                }
            }

            if (!IsRunning)
            {
                return;
            }

            _lastRepsonse = DateTime.Now;

            Thread.Sleep(1500);
            if (NoFrame)
            {
                AutoPosition.RemoveWindowFrame(MainWindowHandle, true);          // Force remove window frame
            }
            if (ManualPosSize)
            {
                AutoPosition.ManualPositionWindow(MainWindowHandle, X, Y, W, H, Parent);
            }
            else if (Settings.Default.UseAutoPos)
            {
                AutoPosition.PositionWindows();
            }

            Logger.Instance.Write("Diablo:{0}: Process is ready", Proc.Id);

            // Demonbuddy start delay
            if (Settings.Default.DemonbuddyStartDelay > 0)
            {
                Logger.Instance.Write("Demonbuddy start delay, waiting {0} seconds", Settings.Default.DemonbuddyStartDelay);
                Thread.Sleep((int)Settings.Default.DemonbuddyStartDelay * 1000);
            }
        }
        public void Start(bool noprofile = false, string profilepath = null, bool crashtenderstart = false)
        {
            if (!Parent.IsStarted || !Parent.Diablo.IsRunning || (_crashTenderRestart && !crashtenderstart))
            {
                return;
            }
            if (!File.Exists(Location))
            {
                Logger.Instance.Write("File not found: {0}", Location);
                return;
            }

            while (Parent.IsStarted && Parent.Diablo.IsRunning)
            {
                // Get Last login time and kill old session
                if (GetLastLoginTime)
                {
                    BuddyAuth.Instance.KillSession(Parent);
                }

                _isStopped = false;

                // Reset AntiIdle;
                Parent.AntiIdle.Reset(true);

                var arguments = "-pid=" + Parent.Diablo.Proc.Id;
                arguments += " -key=" + Key;
                arguments += " -autostart";
                arguments += string.Format(" -routine=\"{0}\"", CombatRoutine);
                arguments += string.Format(" -bnetaccount=\"{0}\"", Parent.Diablo.Username);
                arguments += string.Format(" -bnetpassword=\"{0}\"", Parent.Diablo.Password);

                if (profilepath != null)
                {
                    // Check if current profile path is Kickstart
                    var file = Path.GetFileName(profilepath);
                    if (file == null || (file.Equals("YAR_Kickstart.xml") || file.Equals("YAR_TMP_Kickstart.xml")))
                    {
                        profilepath = Parent.ProfileSchedule.GetProfile;
                    }

                    var profile = new Profile()
                    {
                        Location = profilepath
                    };
                    var path = ProfileKickstart.GenerateKickstart(profile);
                    arguments += string.Format(" -profile=\"{0}\"", path);
                }
                else if (Parent.ProfileSchedule.Profiles.Count > 0 && !noprofile)
                {
                    var path = Parent.ProfileSchedule.GetProfile;
                    if (File.Exists(path))
                    {
                        arguments += string.Format(" -profile=\"{0}\"", path);
                    }
                }
                else if (!noprofile)
                {
                    Logger.Instance.Write(
                        "Warning: Launching Demonbuddy without a starting profile (Add a profile to the profilescheduler for this bot)");
                }

                if (NoFlash)
                {
                    arguments += " -noflash";
                }
                if (AutoUpdate)
                {
                    arguments += " -autoupdate";
                }
                if (NoUpdate)
                {
                    arguments += " -noupdate";
                }

                if (ForceEnableAllPlugins)
                {
                    arguments += " -YarEnableAll";
                }

                Debug.WriteLine("DB Arguments: {0}", arguments);

                var p = new ProcessStartInfo(Location, arguments)
                {
                    WorkingDirectory = Path.GetDirectoryName(Location)
                };
                p = UserAccount.ImpersonateStartInfo(p, Parent);

                // Check/Install latest Communicator plugin
                var plugin = string.Format("{0}\\Plugins\\YAR\\Plugin.cs", p.WorkingDirectory);
                if (!PluginVersionCheck.Check(plugin))
                {
                    PluginVersionCheck.Install(plugin);
                }


                DateTime timeout;
                try                                        // Try to start Demonbuddy
                {
                    Parent.Status = "Starting Demonbuddy"; // Update Status
                    Proc          = Process.Start(p);

                    if (Program.IsRunAsAdmin)
                    {
                        Proc.PriorityClass = General.GetPriorityClass(Priority);
                    }
                    else
                    {
                        Logger.Instance.Write(Parent, "Failed to change priority (No admin rights)");
                    }


                    // Set affinity
                    if (CpuCount != Environment.ProcessorCount)
                    {
                        ProcessorAffinity = AllProcessors; // set it to all ones
                        CpuCount          = Environment.ProcessorCount;
                    }
                    Proc.ProcessorAffinity = (IntPtr)ProcessorAffinity;


                    Logger.Instance.Write(Parent, "Demonbuddy:{0}: Waiting for process to become ready", Proc.Id);

                    timeout = DateTime.Now;
                    while (true)
                    {
                        if (General.DateSubtract(timeout) > 30)
                        {
                            Logger.Instance.Write(Parent, "Demonbuddy:{0}: Failed to start!", Proc.Id);
                            Parent.Restart();
                            return;
                        }
                        Thread.Sleep(500);
                        try
                        {
                            Proc.Refresh();
                            if (Proc.WaitForInputIdle(100) || CrashChecker.IsResponding(MainWindowHandle))
                            {
                                break;
                            }
                        }
                        catch
                        {
                        }
                    }

                    if (_isStopped)
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.Write(ex.ToString());
                    Parent.Stop();
                }

                timeout = DateTime.Now;
                while (!FindMainWindow())
                {
                    if (General.DateSubtract(timeout) > 30)
                    {
                        MainWindowHandle = Proc.MainWindowHandle;
                        break;
                    }
                    Thread.Sleep(500);
                }

                // Window postion & resizing
                if (ManualPosSize)
                {
                    AutoPosition.ManualPositionWindow(MainWindowHandle, X, Y, W, H, Parent);
                }
                Logger.Instance.Write(Parent, "Demonbuddy:{0}: Process is ready", Proc.Id);

                // Wait for demonbuddy to be Initialized (this means we are logged in)
                // If we don't wait here the Region changeing for diablo fails!
                Logger.Instance.Write(Parent, "Demonbuddy:{0}: Waiting for demonbuddy to log into Diablo", Proc.Id);
                while (!IsInitialized && !_isStopped)
                {
                    Thread.Sleep(1000);
                }
                // We made to many attempts break here
                if (Parent.AntiIdle.FailedInitCount > 3)
                {
                    break;
                }
                if (!Parent.AntiIdle.IsInitialized)
                {
                    continue;                                 // Retry
                }
                // We are ready to go
                Logger.Instance.Write(Parent, "Demonbuddy:{0}: Initialized! We are ready to go", Proc.Id);
                Parent.AntiIdle.FailedInitCount = 0; // only reset counter
                break;
            } // while (Parent.IsStarted && Parent.Diablo.IsRunning)
        }
Beispiel #5
0
        public void Start(bool noprofile = false)
        {
            if (!Parent.IsStarted || !Parent.Diablo.IsRunning)
            {
                return;
            }
            if (!File.Exists(Location))
            {
                Logger.Instance.Write("File not found: {0}", Location);
                return;
            }

            // Get Last login time and kill old session
            if (GetLastLoginTime)
            {
                BuddyAuth.Instance.KillSession(Parent);
            }

            _isStopped = false;

            // Reset AntiIdle;
            Parent.AntiIdle.Reset(true);

            var arguments = "-pid=" + Parent.Diablo.Proc.Id;

            arguments += " -key=" + Key;
            arguments += " -autostart";
            arguments += string.Format(" -routine=\"{0}\"", CombatRoutine);
            arguments += string.Format(" -bnetaccount=\"{0}\"", Parent.Diablo.Username);
            arguments += string.Format(" -bnetpassword=\"{0}\"", Parent.Diablo.Password);

            if (Parent.ProfileSchedule.Profiles.Count > 0 && !noprofile)
            {
                var profilepath = Parent.ProfileSchedule.GetProfile;
                if (File.Exists(profilepath))
                {
                    arguments += string.Format(" -profile=\"{0}\"", profilepath);
                }
            }
            else if (!noprofile)
            {
                Logger.Instance.Write("Warning: Launching Demonbuddy without a starting profile (Add a profile to the profilescheduler for this bot)");
            }

            if (NoFlash)
            {
                arguments += " -noflash";
            }
            if (AutoUpdate)
            {
                arguments += " -autoupdate";
            }
            if (NoUpdate)
            {
                arguments += " -noupdate";
            }

            if (ForceEnableAllPlugins)
            {
                arguments += " -YarEnableAll";
            }

            Debug.WriteLine("DB Arguments: {0}", arguments);

            var p = new ProcessStartInfo(Location, arguments)
            {
                WorkingDirectory = Path.GetDirectoryName(Location)
            };

            // Check/Install latest Communicator plugin
            var plugin = string.Format("{0}\\Plugins\\YAR\\Plugin.cs", p.WorkingDirectory);

            if (!PluginVersionCheck.Check(plugin))
            {
                PluginVersionCheck.Install(plugin);
            }


            try                                        // Try to start Demonbuddy
            {
                Parent.Status = "Starting Demonbuddy"; // Update Status
                Proc          = Process.Start(p);

                if (Program.IsRunAsAdmin)
                {
                    Proc.PriorityClass = General.GetPriorityClass(Priority);
                }
                else
                {
                    Logger.Instance.Write(Parent, "Failed to change priority (No admin rights)");
                }


                // Set affinity
                if (CpuCount != Environment.ProcessorCount)
                {
                    ProcessorAffinity = AllProcessors; // set it to all ones
                    CpuCount          = Environment.ProcessorCount;
                }
                Proc.ProcessorAffinity = (IntPtr)ProcessorAffinity;


                Logger.Instance.Write(Parent, "Demonbuddy:{0}: Waiting for process to become ready", Proc.Id);
                if (!Proc.WaitForInputIdle(30000))
                {
                    Logger.Instance.Write(Parent, "Demonbuddy:{0}: Failed to start!", Proc.Id);
                    Parent.Restart();
                    return;
                }

                if (_isStopped)
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.Write(ex.ToString());
                Parent.Stop();
            }

            var timeout = DateTime.Now;

            while (!FindMainWindow())
            {
                if (General.DateSubtract(timeout) > 30)
                {
                    MainWindowHandle = Proc.MainWindowHandle;
                    break;
                }
                Thread.Sleep(500);
            }

            // Window postion & resizing
            if (ManualPosSize)
            {
                AutoPosition.ManualPositionWindow(MainWindowHandle, X, Y, W, H, Parent);
            }

            Logger.Instance.Write(Parent, "Demonbuddy:{0}: Process is ready", Proc.Id);
        }