Hi,
first off I know there are couple of Threads that concern facing but none do really touch this or even solve this issue so I hope I am not breaking the rules(Yes, I read them
).
Currently I am trying to set my facing on the current target with the help of CGObject_SetFacing. My Problem is that it has no effect when I call it. No Exceptions, no crashs, no changes in WoW. I am sick of it now and want to see if you guys maybe know whats wrong.
I am using Apoc's WhiteMagic and managed injection. Thanks to Robske007a for showing/helping me with everything.
Here is how I try to call the function.
Code:
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
public delegate void CGObject_C__SetFacing(IntPtr __This, float Angle);
private static Hooks.CGObject_C__SetFacing _SetFacing;
public float Rotation
{
get { return Bot.Memory.Read<float>(((uint)ObjPtr + 0x7A8)); }
set
{
try
{
if (_SetFacing == null)
{
_SetFacing = Bot.Memory.RegisterDelegate<Hooks.CGObject_C__SetFacing>(Statics.CGObject_SetFacing);
}
if (ObjPtr == IntPtr.Zero)
throw new NullReferenceException("SetFacing invoked on an invalid Object");
_SetFacing(this, value);
}
catch (Exception Ex)
{
Log.ShowException(Ex);
}
}
}
Here is the rest that sets the facing
Code:
public static void FaceTarget()
{
if (Bot.Me.TargetGuid != 0)
{
Bot.Target = (WoWUnit)ObjectManager.GetObjectByGuid(Bot.Me.TargetGuid);
// Calculate Facing
float DistanceY = Bot.Me.WowPoint.X - Bot.Target.WowPoint.X;
float DistanceX = Bot.Me.WowPoint.Y - Bot.Target.WowPoint.Y;
//Note that wow uses X Y different to the normal math !
double ATan = Math.Abs(Math.Atan(DistanceX / DistanceY));
double TotalShouldFace = 0;
if (DistanceX < 0)
{
if (DistanceY > 0)
{
TotalShouldFace = (2 * Math.PI) - ATan;
}
else
{
TotalShouldFace = ATan;
}
}
else
{
if (DistanceY > 0)
{
TotalShouldFace = Math.PI + ATan;
}
else
{
TotalShouldFace = Math.PI - ATan;
}
}
Bot.Me.Rotation = (float)TotalShouldFace;
}
}
Any Information is welcome