What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

[Plugin] Let me drive - Plugin that pauses the bot to allow you to move freely

Great code, now can you make it a toggle instead of while pressed?

Great idea yours!, yes now that you commented that I also think is better to use a kind of pause-toogle functionality instead of a "pause the bot until key is released", yes, this way we will gain full usability of keyboard.

So I did the necessary modifications and here below is the new code that you've demanded :).

I totally replaced the functionality to follow your suggestion, I also added the current key name to the plugin description, and a simple log message when the bot is paused or resumed, and now when the bot is paused the main thread is stopped during 500 ms to avoid any next pause/resume while the key is hold.

(sorry for my bad English, i hope all was good understood)

LetMeDrive v1.1:
Code:
#region " Namespace Imports "

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
using System.Windows.Forms;
using System.Windows;
using System.Windows.Input;
using Key = System.Windows.Input.Key;

using Zeta.Bot;
using Zeta.Bot.Logic;
using Zeta.Bot.Profile;
using Zeta.Common;
using Zeta.Common.Plugins;
using Zeta.TreeSharp;

using log4net;

#endregion

namespace LetMeDrive {

#region " P/Invoking "

    internal sealed class SafeNativeMethods {

        internal const int KEY_PRESSED = 0x8000;

        [SuppressUnmanagedCodeSecurity()]
        [DllImport("user32.dll", SetLastError = false)]
        internal static extern IntPtr GetForegroundWindow();

        [SuppressUnmanagedCodeSecurity()]
        [DllImport("user32.dll", SetLastError = false)]
        internal static extern int GetWindowThreadProcessId(IntPtr hwnd, out int pid);

        [SuppressUnmanagedCodeSecurity()]
        [DllImport("user32.dll", SetLastError = false, CharSet = CharSet.Unicode)]
        internal static extern short GetKeyState(int virtualKey);

        //[SuppressUnmanagedCodeSecurity()]
        //[DllImport("user32.dll", SetLastError = false, CharSet = CharSet.Unicode)]
        //internal static extern short GetAsyncKeyState(int virtualKey); 

    }

#endregion

    public sealed class Logic : IPlugin {

#region " User Fields "

        private readonly Key userKey = Key.LeftCtrl;

#endregion

#region " Private Fields "

        private readonly ILog logger = Logger.GetLoggerInstanceForType();
        private bool isBotPaused = false;

#endregion

#region " Properties "

        public string Name {
            get { return string.Format("LetMeDrive {0}", Version.ToString()); }
        }

        public Version Version {
            get { return new Version(1, 1); }
        }

        public string Author {
            get { return "Elektro"; }
        }

        public string Description {
            get { return string.Format("Lets you pause the bot on demand using '{0}' key.", this.userKey.ToString()); }
        }

        public Window DisplayWindow {
            get { return null; }
        }

#endregion

#region " Event Invocators "

        public void OnInitialize() {}

        public void OnEnabled() {
            this.logger.Info("[LetMeDrive] Plugin enabled.");
        }

        public void OnDisabled() {
            this.isBotPaused = false;
            this.logger.Info("[LetMeDrive] Plugin disabled.");
        }

        public void OnShutdown() {
            this.isBotPaused = false;
        }

        public void OnPulse() {
           if ((!BotMain.IsPaused && IsPauseRequested()) || BotMain.IsPaused && !IsPauseRequested()) {
                  BotMain.PauseWhile(IsPauseRequested);
               }
        }

#endregion

#region " Public Methods "

        public bool Equals(IPlugin other) {
            return (other.Name == Name) && (other.Version == Version);
        }

#endregion

#region " Private Methods "

        private bool IsPauseRequested() {

            int virtualKey = System.Windows.Input.KeyInterop.VirtualKeyFromKey(this.userKey);
            bool keyIsPressed = Convert.ToBoolean(SafeNativeMethods.GetKeyState(virtualKey) & SafeNativeMethods.KEY_PRESSED);

            if (keyIsPressed) {
                Process[] d3procs = Process.GetProcessesByName(processName: "Diablo III");
                if (d3procs.Any()) {
                    int[] d3pids = (from p in d3procs select p.Id).ToArray();
                    IntPtr activeWindow = SafeNativeMethods.GetForegroundWindow();
                    int activePid = 0;
                    SafeNativeMethods.GetWindowThreadProcessId(activeWindow, out activePid);
                    if (activePid != 0) {
                        Process activeProc = Process.GetProcessById(activePid);
                        if (d3pids.Contains(activeProc.Id)) {
                                this.isBotPaused = !this.isBotPaused;
                                this.logger.Info(string.Format("[LetMeDrive] Key '{0}' pressed, new bot status: {1}", 
                                                               this.userKey.ToString(), (this.isBotPaused ? "Paused" : "Resumed")));
                                Thread.Sleep(500);
                        }
                    }
                }
            }
            return this.isBotPaused;
        }

#endregion

    }

}
 
Last edited:
Great idea yours!, yes now that you commented that I also think is better to use a kind of pause-toogle functionality instead of a "pause the bot until key is released", yes, this way we will gain full usability of keyboard.

So I did the necessary modifications and here below is the new code that you've demanded :).

I totally replaced the functionality to follow your suggestion, I also added the current key name to the plugin description, and a simple log message when the bot is paused or resumed, and now when the bot is paused the main thread is stopped during 500 ms to avoid any next pause/resume while the key is hold.

(sorry for my bad English, i hope all was good understood)

No your english is fine but the new code isn't, it doesn't work or I should say it might work but it doesn't show up in the plugin tab so theres no way to activate it to try it. I looked through it but even with simple code I get lost. :P
 
the new code isn't, it doesn't work

True, it was my fault when copying and pasting the code on the forum on the fly, where I'd commited a mistake on OnEnabled and OnDisabled methods letting a unparametized string.Format(). Now it is fixed.

Regards!.
 
How do I make this work? Where do I put the code? Can you explain for those of us who don't understand this?
 
How do I make this work? Where do I put the code? Can you explain for those of us who don't understand this?

Yes of course. Firstlly you need to create a folder with any name inside the "...\Demonbuddy\Plugins" directory, for example: "...\Demonbuddy\Plugins\LetMeDrive", now in that folder you create a file with ".cs" extension (like "LetMeDrive.cs") and inside that file paste the code that I provided, then, when you run DemonBuddy the new plugin will appear and now you can activate it and use it.

Regards.
 
Yes of course. Firstlly you need to create a folder with any name inside the "...\Demonbuddy\Plugins" directory, for example: "...\Demonbuddy\Plugins\LetMeDrive", now in that folder you create a file with ".cs" extension (like "LetMeDrive.cs") and inside that file paste the code that I provided, then, when you run DemonBuddy the new plugin will appear and now you can activate it and use it.

Regards.

Thanks! It works!
 
Guys if you read this thread. THIS WAS INTEGRATED into trinity and works for me.
is called Lazyraider and its under Adv options or same tab you turn on More logs. Can be turned on and off. ( i should of went back 1 page )

Upgrades to it Should be thrown to Xzjv in trinity thread =)
I will try your upgrades
 
Last edited:
Guys if you read this thread. THIS WAS INTEGRATED into trinity and works for me.

Did you read the thread?. LazyRaider functionality is WRONG, as I explained all here:

The original LetMeDriveCTRL/LazyRaider plugin has some design issues.

1st: LetMeDriveCTRL can't handle the window on which the CTRL key was pressed, so when you press that key on any other window, the bot will be stopped.
......The same happens for LazyRaider when pressing left mouse button on a window, so just doing your common things on your PC it will stop the Bot everytime.
2st: LetMeDriveCTRL and LazyRaider can't handle multiple instances of Diablo III because the 1st reason.

LetMeDriveCTRL is very useful, but Lazy Raider is a feature that I really can't understand why exists,
because if the user needs to stop the bot to perform manual actions on the hero, that means the left mouse button should be free to use properlly on the D3 UI (to click on menus to select options, or to move, etc),
but since now Lazy Raider handles mouse buttons instead keyboard keys, the Bot resumes when left mouse button is released, then this plugin, in my oppinion, has really any sense.

In resume, we can say that LetMeDriveCTRL is very useful to pause the Bot to do any thing on the D3 client window using your mouse, and Lazy Raider is the opposite, it's useful to move your hero from a stuck and nothing nore (at least I can't find any other reason to use it) but... hey, you already can go out from a stuck using the mouse button without any plugin (yes, it doesn't stops the bot, it will interfere with the bot movement, but it just need one click) so as I said in my oppinion is very absurd the implementation of Lazy Raider feature, it should handle keys as did it before, no mouse buttons.

That is the reason why I shared a fixed version, and also I shared a totally replacement being a toogle behavior instead of "while key is pressed" (or "while mouse button is pressed" in case of LazyRaider, which has any sense to be,).

Thanks for read.
 
Did you read the thread?. LazyRaider functionality is WRONG, as I explained all here:



That is the reason why I shared a fixed version, and also I shared a totally replacement being a toogle behavior instead of "while key is pressed" (or "while mouse button is pressed" in case of LazyRaider, which has any sense to be,).

Thanks for read.


I dident then i did. Thats y i edited to include ( i should of went back 1 page )
And suggested you ask xzjv to integrate it into trinity. <3
There was a reason why the original was but i cant remember. =)

It works really nice. You may also want to consider making a new thread and releasing it as your own so people can find your changed better. with credit to Rrrix of course
 
Last edited:
I desperately need to change the button from Ctrl to something else, like a key combo cause I keep turning my bot off and on when i hold control to compare items and see their max values. Also my son tends to hit control on the keyboard while I am afk and turns my bot off.
 
Back
Top