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

Help with Plugin Coding

erenion

New Member
Joined
Jan 15, 2010
Messages
321
Reaction score
6
I realise recently I haven't been very prevalent in the community - been busy. Anyways I've decided to help out a bit. If anyone has questions feel free to email me at [email protected]. Try not to send me long blocks of code as I may be replying with my phone. It may also be more effective to post a topic on the forums but the offer is out there.

Ps Tony feel free to move this if you don't like it here.
 
All i need help with is the structure of how to write the code (blocks etc..) and some vocab help such as Bools and stuff like that = )
 
Email questions :P or if you ask nicely I may be able to hop on a vent and answer all questions for 20 mins or so :P
 
All i need help with is the structure of how to write the code (blocks etc..) and some vocab help such as Bools and stuff like that = )
all you have to do, is take Mr.Autofight, and Remove all the code in the Pulse() { }
and you then you have yourself a template, just add your code in Pulse(), and your good to go.
 
Hello,

just trying to catch some keys and when a special key is pushed i wanna jump into a function.

to many stuff from hb Toggle.


Can't test it @ the moment .. can someone maybe give a short look ...

yeah maybe it's creepy


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 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
    {
        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;
        private static extern short GetAsyncKeyState(System.Int32 vKey);
        private static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey); // Keys enumeration 


        void ReadLog(string line, System.Drawing.Color c)
        {
            Logging.WriteDebug("ReadLog: " + line);
            if (line == this.Name + " Initializing")
            {
                Logging.OnWrite -= ReadLog;
                Logging.Write("Recompile detected");
                keyPollThread.Abort();
                // wait for thread to abort.
                while (keyPollThread.IsAlive)
                {
                    Logging.Write("Waiting for thread to abort");
                    Thread.Sleep(100);
                }
            }
        }



        public override void Pulse()
        {
        }

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


        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
            while (Styx.Plugins.PluginManager.Plugins.Count() == 0)
                Thread.Sleep(100);
            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)");
            }
        }


    }
}

Thank You
 
Last edited:
Hello,

just trying to catch some keys and when a special key is pushed i wanna jump into a function.

to many stuff from hb Toggle.


Can't test it @ the moment .. can someone maybe give a short look ...


Thank You
Hello Spudstar,
I went through your code and made a few adjustments like using plugin's initializer and dispose
as well as fixing and removing few unneed lines of code
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)");
            }
        }
 
 
    }
}
 
i get crazy

i wrote this with the help of high voltz ...


but it shows millions errors .. but in the end it works ... but i don't find the errors


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, 55);
        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.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)");
            }
        }


    }
}


could maybe give it a quick view?!

thank you
 
Back
Top