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

[HELP] Plugin coding... >.<

volicio

New Member
Joined
Oct 29, 2010
Messages
48
Reaction score
1
I'll be the first to admit I generally dont have a clue what I'm doing. Sure I can look at the code of other peoples plugins and understand what they do and why, but I dont have the training or the knowledge to really write stuff of my own. That being said, I'm starting to think I've bitten off more then I can chew here trying to write my own plugin to toggle HB on and off on a keystorke.

What I'm Trying to do is something like this:

Code:
If (IsKeyDown(Pageup) && (honorbuddy.IsRunning)
{
	dLog("Stopping Bot");
	TreeRoot.Stop();
}
ElseIf (IsKeyDown(Pageup) && (honorbuddy.IsNotRunning)
{
	dLog("Starting Bot");
	TreeRoot.Start();
}

Its late and my VSC# doesn't want to load and I'm pulling this stuff off the top of my head, so most of that code is so wrong its kinda scary... but It gets the idea across... I'll try and update it a little later. The only problem is that the only two references I have for calling a keystroke are old and don't seem to work anymore.
 
I have, HB toggle is one of the two outdated references I talked about... Highvoltz hasn't supported it in over 6months and the code he used was for HB1 and doesn't seem to work at all with HB2
 
volicio, join irc and when apoc or one of the other Coders are on, maybe you can catch them (if they don't respond here)

its #honorbuddy on quakenet server
 
look in the plugin help thread .. i posted into it .. !! i tried the same .. and one of the solution worked ..!!



Code:
// Credits to Apoc and Main HighVoltz
 
using System;
using System.Collections.Generic;
using System.Threading;
using System.Diagnostics;
using System.Globalization;
using System.Windows.Forms;
using System.Text;
using System.Linq;
using Styx;
using Styx.Plugins.PluginClass;
using Styx.Logic.BehaviorTree;
using System.Runtime.InteropServices;
 
using Styx.Helpers;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Styx.Patchables;
using Tripper.XNAMath;
using Styx.Logic;
using Styx.Plugins;
 
 
namespace Spudstar
{
    class RunMacro : HBPlugin,IDisposable
    {
        static public string name = "LUAFun";
        public override string Name { get { return name + " " + Version.ToString(); } }
        public override string Author { get { return "spUdstAr"; } }
        private readonly Version _version = new Version(0, 1);
        public override Version Version { get { return _version; } }
        public override string ButtonText { get { return "RunLuaMacro"; } }
        static bool isPulsing = false;// check to prevent recursively calling Pulse() from Styx.WoWPulsator.Pulse()
        Styx.Plugins.PluginContainer MyPlugin;
 
 
        Thread keyPollThread;
        [DllImport("user32.dll")]
        static extern IntPtr GetForegroundWindow();
        private static IntPtr _wowHandle = ObjectManager.WoWProcess.MainWindowHandle;
        
        [DllImport("user32.dll")]
        static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);
 
        public override void Pulse()
        {
        }
 
 
        public override void Initialize()
        {
            keyPollThread = new Thread(new ThreadStart(ThreadLoop));
            keyPollThread.IsBackground = true;
            keyPollThread.Start();
        }
 
        public override void Dispose()
        {
            keyPollThread.Abort();
        }
        
        public static bool IsKeyDown(System.Windows.Forms.Keys vKey)
        {
            return (GetAsyncKeyState(vKey) != 0);
        }
 
 
        public void ThreadLoop()
        {
            bool toggleControl = false;
            // wait till plugin manager fully loads
 
            MyPlugin = Styx.Plugins.PluginManager.Plugins.FirstOrDefault(p => p.Plugin.PluginName == this.Name);
 
            while (true)
            {
                // if keybind is pressed and our wow window is the currently active window then toggle HB
                IntPtr fgWinHwnd = GetForegroundWindow();
 
                //if (HB_ToggleKeybind.PollKeys() && !toggleControl && (_wowHandle == fgWinHwnd) && myPlugin.Enabled)
                if (IsKeyDown(Keys.R) && (_wowHandle == fgWinHwnd) && MyPlugin.Enabled)
                {
                    toggleControl = true;
                    Toggle();
                }
                else
                {
                    toggleControl = false;
                }
                // Yield the rest of the time slice.
                Thread.Sleep(75);
            }
        }
 
 
 
 
        private static void Toggle()
        {
            if (TreeRoot.IsRunning)
            {
                Logging.Write("Honorbuddy: Off");
                TreeRoot.Stop();
                WoWMovement.MoveStop();
                Lua.DoString("UIErrorsFrame:AddMessage(\"HonorBuddy: OFF\", 1.0, 0.4, 0.0)");
 
            }
            else if (TreeRoot.Current != null)
            {
                Logging.Write("Honorbuddy: On");
                Lua.DoString("UIErrorsFrame:AddMessage(\"HonorBuddy: ON\", 0.0, 1.0, 0.0)");
                TreeRoot.Start();
            }
            else
            {
                Logging.Write("Need to start HonorBuddy 1st");
                Lua.DoString("UIErrorsFrame:AddMessage(\"Err: Start HonorBuddy\", 1.0, 0.0, 0.0)");
            }
        }
 
 
    }
}
 
Last edited:
thanks spud... looking at this, is your hotkey set to v? where it says IsKeyDown(System.Windows.Forms.Keys vKey)
 
vKey is short for VirtualKey

Keys Enumeration

Example

Code:
// Utilizing the Vkey for the Space bar
System.Windows.Forms.Keys((char)Keys.Space));
 
thanks I'm learning a lot... more so now since someone gave me all the answers in a working plug-in... I don't know the deal on posting such things I didn't make... so for now I'll keep it and just use it to teach myself how to write my own without just copy and pasting it all.
 
what did you tried to build up?! just a plugin to stop hb?! or a plugin which realize keystrokes?

maybe you can post your plugin in the hb toggle thread and give shout outz to the people which should be mentioned!


sincery spud
 
This Version is realy working .. with the newest HB .. i set the button to "F8"

Code:
// Credits to Apoc and Main HighVoltz

using System;
using System.Collections.Generic;
using System.Threading;
using System.Diagnostics;
using System.Globalization;
using System.Windows.Forms;
using System.Text;
using System.Linq;
using Styx;
using Styx.Plugins.PluginClass;
using Styx.Logic.BehaviorTree;
using System.Runtime.InteropServices;

using Styx.Helpers;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Styx.Patchables;
using Tripper.Tools;
using Styx.Logic;
using Styx.Plugins;


namespace Spudstar
{
    class RunMacro : HBPlugin, IDisposable
    {
        static public string name = "LUAFun";
        public override string Name { get { return name + " " + Version.ToString(); } }
        public override string Author { get { return "spUdstAr"; } }
        private readonly Version _version = new Version(0, 1);
        public override Version Version { get { return _version; } }
        public override string ButtonText { get { return "RunLuaMacro"; } }
        static bool isPulsing = false;// check to prevent recursively calling Pulse() from Styx.WoWPulsator.Pulse()
        Styx.Plugins.PluginContainer MyPlugin;


        Thread keyPollThread;
        [DllImport("user32.dll")]
        static extern IntPtr GetForegroundWindow();
        private static IntPtr _wowHandle = ObjectManager.WoWProcess.MainWindowHandle;

        [DllImport("user32.dll")]
        static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);

        public override void Pulse()
        {
        }


        public override void Initialize()
        {
            keyPollThread = new Thread(new ThreadStart(ThreadLoop));
            keyPollThread.IsBackground = true;
            keyPollThread.Start();
        }

        public override void Dispose()
        {
            keyPollThread.Abort();
        }

        public static bool IsKeyDown(System.Windows.Forms.Keys vKey)
        {
            return (GetAsyncKeyState(vKey) != 0);
        }


        public void ThreadLoop()
        {
            bool toggleControl = false;
            // wait till plugin manager fully loads

            MyPlugin = Styx.Plugins.PluginManager.Plugins.FirstOrDefault(p => p.Plugin.Name == this.Name);

            while (true)
            {
                // if keybind is pressed and our wow window is the currently active window then toggle HB
                IntPtr fgWinHwnd = GetForegroundWindow();

                //if (HB_ToggleKeybind.PollKeys() && !toggleControl && (_wowHandle == fgWinHwnd) && myPlugin.Enabled)
                if (IsKeyDown(Keys.F8) && (_wowHandle == fgWinHwnd) && MyPlugin.Enabled)
                {
                    toggleControl = true;
                    Toggle();
                }
                else
                {
                    toggleControl = false;
                }
                // Yield the rest of the time slice.
                Thread.Sleep(75);
            }
        }




        private static void Toggle()
        {
            if (TreeRoot.IsRunning)
            {
                Logging.Write("Honorbuddy: Off");
                TreeRoot.Stop();
                WoWMovement.MoveStop();
                Lua.DoString("UIErrorsFrame:AddMessage(\"HonorBuddy: OFF\", 1.0, 0.4, 0.0)");

            }
            else if (TreeRoot.Current != null)
            {
                Logging.Write("Honorbuddy: On");
                Lua.DoString("UIErrorsFrame:AddMessage(\"HonorBuddy: ON\", 0.0, 1.0, 0.0)");
                TreeRoot.Start();
            }
            else
            {
                Logging.Write("Need to start HonorBuddy 1st");
                Lua.DoString("UIErrorsFrame:AddMessage(\"Err: Start HonorBuddy\", 1.0, 0.0, 0.0)");
            }
        }


    }
}
 
Back
Top