Shynd’s WoW Modification Journal

June 22, 2008

Movement

Filed under: World of Warcraft — Tags: , , , , , , , — Shynd @ 9:55 pm

Well, I don’t know about the rest of you, but this part is both EXTREMELY tedious to figure out and very, very interesting to me.  Very quick back story: whereas I am pretty good at mathematical concepts, I never passed any high school math higher than Geometry, due to turning in precisely 36% of my math homework three semesters in a row, so any math Algebra 2 and above I have to teach myself as if it were new (because it is).  That makes facing rotation, degrees, radians, tangents, etc., all new-sauce to me.  This article will attempt to make some of these subjects easier for those of you who aren’t math majors.

As I understand it, there are two ways of measuring rotation: degrees and radians.  As you should all know, there are 360 degrees in a circle (with 0 degrees and 360 degrees meeting at north, 90 degrees being west, 180 degrees being south, and 270 degrees being east… counter-clockwise, if you will).  What many of you may not know is that there is π*2 radians in a circle.  That’s pi multiplied-by two, or 3.1415.. + 3.1415.. (which turns out to be approximately 6.3).  A radian is exactly 180/π degrees, or about 57.2958 degrees.  57.2958 * 3.1415 * 2 == 360.  There’s the math you need to know.  To go from radians (which is how we will read Object.Facing from WoW’s memory) to degrees, you need to multiply by 180 and divide by pi.  I hope that’s clear.  If not, perhaps this will help:
WoWFacing

Also mentioned in the above picture is something many of you may not have encountered yet, atan or atan2.  The atan/atan2 function allows us to determine the arctangent between two coordinates, or the measurement, in radians, which we SHOULD be facing in order to face directly at a given point, knowing our own coordinates.  Thankfully, whatever programming language–in my case, C#–we’re using should be doing most of the work.  In C#, System.Math.Atan2 will give you the cake you’re so eagerly awaiting.  But, wait!, what if it returns a negative facing value?  WoW only deals with positive facing values!  Simple: add this negative facing value to Math.PI * 2, thus normalizing it.

Was that a lot to deal with?  Yeah, and I’m sorry.  There’s more, too: what if we want to determine which way we should turn in order to spend the least amount of time turning?  Well, we need to calculate how many radians (or degrees, if you wish) we’d need to turn to the left and how many radians we’d need to turn to the right, then compare the two.

Basically, you set up two if..then statements, and calculate the radians needed to turn depending on which situation you’re in for each direction.  If your current facing is greater than where you want to face, you’re going to have to turn past north if you turn left but you won’t have to turn past north if you turn right; conversely, if your current facing is lesser than the point you wish to be facing, you’re going to have to rotate past north if you turn to the right, but not if you turn to the left.

If you’re turning past north–which is sometimes shorter–you have to calculate the radians between your current facing and north… then between north and your goal… then add those two together to get your total needed rotation.  If you’re facing at 5.3 and you want to face 1.0, you’ll need to turn from 5.3 to north (6.3), or 1 radian, and then from north (also 0) to 1, or another 1 radian.  So, turning to the left from 5.3 to 1.0 is 2.0 radians, whereas turning to the right would be 5.3 – 1.0, or 4.3 radians.  It’s obvious which turn is shorter.

This is what mine looks like.

Anyway, you should all know, by now, that you can find a unit’s positional information–which includes facing direction–by reading from baseaddress+0xBF0.  +0xBF0 is XCoordinate, +0xBF4 is YCoordinate, +0xBF8 is ZCoordinate, and +0xBFC is FacingDirection.  Once you know your own facing direction, and the coordinates of yourself plus whatever object (or way point) you want to face, you should have no trouble, now, figuring out which way to turn and when to stop turning.  As always, I’ll post some source along with my article, which should make things just that much easier.  Here it is, in a .rar format. (Again, you’ll need my MemoryLib C# class library, and you’ll need to add that as a reference to your project.)

Until next time!

Click here to read the next post in this journal.

5 Comments »

  1. good stuff as usual

    Comment by blizzocode — June 23, 2008 @ 7:55 am

  2. Very nice, though I was wondering how you got the lparam value’s that you use in your PostMessage.cs. So if you could teach me how to find the lparam for different keys I will be happily on my way again XD. Ow, and good luck with helping people write a bot.

    Cheers
    -Katsumura

    Comment by katsumura — June 29, 2008 @ 5:07 pm

  3. Download Winspector (google it). It allows you to see what Windows messages are received by any window you want. I simply attached Winspector to a game, used the keyboard, and figured out which keycode went with which key. Simple.

    Comment by Shynd — July 3, 2008 @ 4:25 pm

  4. I’m trying to get this working myself, but it seems to not be functional anymore.

    I keep getting:
    Could not find WoW’s Object Manager.

    Any fix?

    Comment by fabolous1 — June 18, 2009 @ 12:58 am

  5. You are my hero. Awesome stuff, fixed a key problem for my bot.

    Comment by aevitas — October 18, 2009 @ 11:28 am


RSS feed for comments on this post.

Leave a comment

You must be logged in to post a comment.

Blog at WordPress.com.