// 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)");
}
}
}
}