Code:
while(true){
Sleep(60);
dwObjMgr = GetObjManager(dwPid);
if(!dwObjMgr) { printf("Waiting to attach..."); continue; }
ReadProcessMemory( hProcess, (LPVOID)(dwObjMgr + 0xC0), (LPVOID)&PlayerGUID, 8, &dwReadBytes );
dwPlayerObj = GetObjectByGUID(hProcess,dwObjMgr,PlayerGUID);
ReadProcessMemory(hProcess,(LPVOID)(dwPlayerObj + 0x120), (LPVOID)&temp,4,&dwReadBytes);
ReadProcessMemory(hProcess,(LPVOID)(temp + 0x28), (LPVOID)&TargetGUID,8,&dwReadBytes);
dwTargetObj = GetObjectByGUID(hProcess,dwObjMgr,TargetGUID);
ReadProcessMemory( hProcess, (LPVOID)(dwObjMgr + 0xAC), (LPVOID)&dwCurObj, 4, &dwReadBytes );
dwNextObj = dwCurObj;
memset(&pPS,0,sizeof(Unit_Info));
memset(&tTarget,0,sizeof(Mob_Info));
ReadProcessMemory( hProcess, (LPVOID)(dwPlayerObj), (LPVOID)&pPS, sizeof(Unit_Info), &dwReadBytes );
ReadProcessMemory( hProcess, (LPVOID)(dwTargetObj), (LPVOID)&tTarget, sizeof(Mob_Info), &dwReadBytes );
//if we've found our target id, walk to it!
if (dwTargetObj)
{
float dist = (float)GetDistance(pPS.x,pPS.y,tTarget.x,tTarget.y);
float rotate = (float)atan2((tTarget.y - pPS.y),(tTarget.x - pPS.x));
if(rotate < 0)
rotate +=(float)(PI * 2);
//printf("Distance: %f\nFacing: %f\n",dis,rotate);
if(pPS.h < ( rotate + turnaccuracy) && pPS.h > ( rotate - turnaccuracy )) {
if (isTurning)
{
isTurning = false;
ArrowKeyUp(hWoW, turnkey);
}
//if we're close to the target
if (dist < walkaccuracy)
{
//if we're walking, stop walking
if (isWalking)
{
ArrowKeyUp(hWoW, UP);
isWalking = false;
}
}
//we're not close, so we're walking
isWalking = true;
//hold down the up button
ArrowKeyDown(hWoW, UP);
} else {
//if we're already turning, no need to turn again
//if (isTurning) //no need to have this enabled
// break; //while debugging
//we're turning
isTurning = true;
//variable definition
double r, l;
//if our current facing angle, in radians, is greater than
//the angle which we desire to face
if (pPS.h > rotate)
{
//we'd have to turn past North if we're turning left
l = ((2 * PI) - pPS.h) + rotate;
//we don't have to turn past North if we're turning right
r = pPS.h - rotate;
}
else
{
//we don't have to turn past North if we're turning left
l = rotate - pPS.h;
//we have to turn past North if we're turning right
r = pPS.h + ((2 * PI) - rotate);
}
//let's please turn in the direction where we have to spend
//the least amount of time turning
if (l < r)
turnkey = LEFT;
else
turnkey = RIGHT;
//hold down the arrow key in the direction we've determined
//we should be turning
ArrowKeyDown(hWoW, turnkey);
}
}
//printf("Player Obj: 0x%X\n",dwPlayerObj);
//printf("Target Obj: 0x%X\n",dwTargetObj);
//printf("Target GUID: 0x%X\n\n",TargetGUID);
//printf("Player Info:\nX: %f, Y: %f, Z: %f - Facing: %f\nHealth: %d of %d\nRage: %d of %d\n\n",pPS.x,pPS.y,pPS.z,pPS.h,pPS.HP,pPS.max_health,pPS.rage,pPS.max_rage);
//printf("TargetInfo:\nX: %f, Y: %f, Z: %f - Facing: %f\nHealth: %d of %d\n\n\n",tTarget.x,tTarget.y,tTarget.z,tTarget.h,tTarget.HP,tTarget.max_health);
//Sleep(1000);
//system("cls");
}