public static List <Point> FindPathUnstuck(Point to) { try { bool result; List <Point> points = FindPath(to, out result); if (!result && points.Count <= 2) { Thread.Sleep(100); Logging.WriteNavigator("FindPathUnstuck : FindPath failed. From: " + ObjectManager.ObjectManager.Me.Position + " To: " + to); int trys = 0; while (!result && trys <= 2) { MovementsAction.MoveForward(true); Thread.Sleep(1000); MovementsAction.Ascend(true); Thread.Sleep(100); MovementsAction.Ascend(false); points = FindPath(to, out result); Thread.Sleep(200); MovementsAction.MoveForward(false); trys++; } } return(points); } catch (Exception exception) { Logging.WriteError("FindPathUnstuck(Point to): " + exception); } return(new List <Point>()); }
public static void CGPlayer_C__MoveTo(Vector3 point) { lock (thisLock) { MovementsAction.Ascend(false); MovementsAction.Descend(false); if (!Usefuls.InGame || Usefuls.IsLoading) { return; } Helpful.Timer timer = new Helpful.Timer(2000); while (ObjectManager.ObjectManager.Me.GetBaseAddress == 0) { if (timer.IsReady) { return; } Thread.Sleep(200); } Usefuls.UpdateLastHardwareAction(); if (!point.IsValid) { return; } // Allocate Memory: uint posCodecave = Memory.WowMemory.Memory.AllocateMemory(0x4 * 3); Memory.WowMemory.Memory.WriteFloat(posCodecave, point.X); Memory.WowMemory.Memory.WriteFloat(posCodecave + 0x4, point.Y); Memory.WowMemory.Memory.WriteFloat(posCodecave + 0x8, point.Z); string[] asm = new[] { "push " + posCodecave, "mov ecx, " + ObjectManager.ObjectManager.Me.GetBaseAddress, "call " + (Memory.WowProcess.WowModule + (uint)Addresses.FunctionWow.CGPlayer_C__MoveTo), "retn" }; Memory.WowMemory.InjectAndExecute(asm); Memory.WowMemory.Memory.FreeMemory(posCodecave); if (cache != point) { Logging.WriteNavigator("MoveTo(" + point + ")"); if (cache.IsValid && cache.DistanceTo(point) > 500) { Logging.WriteDebug("The two previouses CTM were very far appart from each others, logging CallStack."); Logging.WriteDebug(Hook.CurrentCallStack); } cache = point; } } }
public static void StopLongMove() { try { MovementsAction.Ascend(false); MovementsAction.Descend(false); _used = false; _usedLoop = false; } catch (Exception exception) { Logging.WriteError("LongMove > StopLongMove(): " + exception); _used = false; _usedLoop = false; } }
public static void LongMoveGo(Point point) { try { //MovementManager.StopMove(); int timer = Others.Times; if (_used) { _used = false; while (_usedLoop) { Thread.Sleep(5); } } _used = true; _usedLoop = true; //MovementManager.StopMove(); MountTask.Mount(false, true); Point pTemps = ObjectManager.ObjectManager.Me.Position; Timer timerSit = new Timer(2500); bool flyingPathFinder = false; while (Products.Products.IsStarted && (ObjectManager.ObjectManager.Me.IsMounted || MountTask.GetMountCapacity() == MountCapacity.Feet) && ObjectManager.ObjectManager.Me.Position.DistanceTo(point) > 3.5f && _used && _usedLoop) { bool forceGround = false; if (Usefuls.IsFlying) { Point pos = ObjectManager.ObjectManager.Me.Position; if (point.DistanceTo2D(pos) <= 60 || flyingPathFinder && point.DistanceTo2D(pos) <= 110) { Point p = new Point(ObjectManager.ObjectManager.Me.Position.LerpByDistance(point, 3f)); bool failed = false; Point targetPoint = new Point(); if (p.IsValid && TraceLine.TraceLineGo(ObjectManager.ObjectManager.Me.Position, p, CGWorldFrameHitFlags.HitTestAllButLiquid)) { if ((point.DistanceTo2D(pos) <= 60 || flyingPathFinder && point.DistanceTo2D(pos) <= 110)) { float degree = 0f; bool doContinue = false; try { LongMoveIsLanding = true; while (degree < 360) { var rnd = new Random(); float radius = rnd.Next(25, 50); float x = (float)(pos.X + radius * System.Math.Cos(Math.DegreeToRadian(degree))); float y = (float)(pos.Y + radius * System.Math.Sin(Math.DegreeToRadian(degree))); Point topPoint = new Point(x, y, pos.Z); Point bottomPoint = new Point(x, y, PathFinder.GetZPosition(x, y)); if (!TraceLine.TraceLineGo(topPoint, new Point(topPoint.LerpByDistance(point, 3f)), CGWorldFrameHitFlags.HitTestAllButLiquid)) { targetPoint = topPoint; MovementManager.MoveTo(targetPoint); Thread.Sleep(2500); flyingPathFinder = true; doContinue = true; break; // we want to go to topPoint and directly go to point. } else if (!TraceLine.TraceLineGo(topPoint, bottomPoint, CGWorldFrameHitFlags.HitTestAllButLiquid)) { bool success; PathFinder.FindPath(bottomPoint, point, Usefuls.ContinentNameMpq, out success); if (success) { targetPoint = topPoint; MovementManager.MoveTo(targetPoint); Thread.Sleep(2500); flyingPathFinder = true; break; // we want to go to topPoint then dismount down to bottomPoint, then findPath to target. } } float randomDegree = rnd.Next(20, 30); degree += randomDegree; if (degree >= 360f) { failed = true; } } } finally { LongMoveIsLanding = false; } if (doContinue) { Thread.Sleep(1000); continue; } } if (!failed) { if (ObjectManager.ObjectManager.Me.Position.DistanceTo(targetPoint) > 5f) { Thread.Sleep(2500); } if (ObjectManager.ObjectManager.Me.Position.DistanceTo(targetPoint) > 5f) { continue; } MountTask.DismountMount(); _used = false; _usedLoop = false; return; } } else { MovementManager.MoveTo(p); flyingPathFinder = false; } } } if (MountTask.GetMountCapacity() <= MountCapacity.Ground || forceGround) { if (RegenPath.IsReady && ObjectManager.ObjectManager.Me.Position.DistanceTo(point) > 3.5f) { RegenPath = new Timer(1000 * 60); List <Point> getFullPath = PathFinder.FindPath(point); MovementManager.Go(getFullPath); RegenPath.Reset(); } else { Thread.Sleep(1000); } } else { if (!MovementManager.IsUnStuck) { if (ObjectManager.ObjectManager.Me.IsDeadMe) { return; } const int checkInFront = 130; // was 100 const int checkCollision = 60; // was 40 if (ObjectManager.ObjectManager.Me.Position.DistanceTo2D(point) > 15) { Point meTemps = ObjectManager.ObjectManager.Me.Position; meTemps.Z = meTemps.Z - 2; Point temps = new Point(point.X, point.Y, ObjectManager.ObjectManager.Me.Position.Z - 2.5f); if (point.DistanceTo(ObjectManager.ObjectManager.Me.Position) > checkInFront) { temps = Math.GetPosition2DOfLineByDistance(ObjectManager.ObjectManager.Me.Position, point, checkInFront); temps.Z = ObjectManager.ObjectManager.Me.Position.Z - 2.5f; } if (TraceLine.TraceLineGo(meTemps, temps) || (ObjectManager.ObjectManager.Me.Position.Z + 10 < point.Z && point.DistanceTo2D(ObjectManager.ObjectManager.Me.Position) < 100)) { MovementsAction.Descend(false); MovementsAction.Ascend(true); timerSit = new Timer(1000); // If distance to colission < checkCollision stop moveto temps = new Point(point.X, point.Y, ObjectManager.ObjectManager.Me.Position.Z - 2.5f); if (point.DistanceTo(ObjectManager.ObjectManager.Me.Position) > checkInFront) { temps = Math.GetPosition2DOfLineByDistance(ObjectManager.ObjectManager.Me.Position, point, checkCollision); temps.Z = ObjectManager.ObjectManager.Me.Position.Z - 2.5f; } if (TraceLine.TraceLineGo(meTemps, temps)) { MovementManager.StopMoveTo(false); } // End Stop move to Thread.Sleep(800); if (pTemps.DistanceTo(ObjectManager.ObjectManager.Me.Position) < 1f) { MovementManager.UnStuckFly(); } else { pTemps = ObjectManager.ObjectManager.Me.Position; } } else { MovementsAction.Ascend(false); if (timerSit.IsReady) { // If distance to ground > 100 temps = new Point(ObjectManager.ObjectManager.Me.Position.X, ObjectManager.ObjectManager.Me.Position.Y, ObjectManager.ObjectManager.Me.Position.Z - altitude); Point tempsMe = new Point(ObjectManager.ObjectManager.Me.Position.X, ObjectManager.ObjectManager.Me.Position.Y, ObjectManager.ObjectManager.Me.Position.Z + 5f); Point temps2 = Math.GetPosition2DOfLineByDistance(tempsMe, point, 80); temps2.Z = ObjectManager.ObjectManager.Me.Position.Z - altitude; if (!TraceLine.TraceLineGo(tempsMe, temps)) { if (!TraceLine.TraceLineGo(tempsMe, temps2)) { MovementsAction.Descend(true); } else { timerSit = new Timer(1000); MovementsAction.Descend(false); } } else { timerSit = new Timer(1000); MovementsAction.Descend(false); } // End Stop move ground } MovementManager.MoveTo(point.X, point.Y, ObjectManager.ObjectManager.Me.Position.Z); if (Others.Times > (timer + 1500)) { MovementManager.MoveTo(point.X, point.Y, ObjectManager.ObjectManager.Me.Position.Z); timer = Others.Times; } } } else { MovementsAction.Descend(false); MovementsAction.Ascend(false); if (ObjectManager.ObjectManager.Me.Position.DistanceTo2D(point) <= 5f && ObjectManager.ObjectManager.Me.Position.DistanceZ(point) > 2f) { MovementsAction.Descend(false); MovementsAction.Ascend(false); MovementManager.StopMove(); MovementManager.StopMove(); MountTask.Land(); } else { MovementManager.MoveTo(point); } } } if (ObjectManager.ObjectManager.Me.IsMounted && !Usefuls.IsFlying) { MovementsAction.Descend(false); MovementsAction.Ascend(false); MountTask.Mount(false, true); MovementsAction.Ascend(true); Thread.Sleep(1300); MovementsAction.Ascend(false); } } Thread.Sleep(150); //50 } MovementsAction.Descend(false); MovementsAction.Ascend(false); _used = false; _usedLoop = false; RegenPath.ForceReady(); } catch (Exception exception) { MovementsAction.Descend(false); MovementsAction.Ascend(false); Logging.WriteError("LongMove > LongMoveGo(Point point): " + exception); _used = false; _usedLoop = false; RegenPath.ForceReady(); } }
public static UInt128 StartFight(UInt128 guid = default(UInt128)) { MovementManager.StopMove(); WoWUnit targetNpc = null; try { if (guid == 0) { targetNpc = new WoWUnit( ObjectManager.ObjectManager.GetNearestWoWUnit( ObjectManager.ObjectManager.GetHostileUnitAttackingPlayer()).GetBaseAddress); } else { targetNpc = new WoWUnit(ObjectManager.ObjectManager.GetObjectByGuid(guid).GetBaseAddress); } if (!targetNpc.Attackable) { nManagerSetting.AddBlackList(targetNpc.Guid, 20000); // blacklist 20 sec } if (ObjectManager.ObjectManager.Me.IsMounted && (CombatClass.InAggroRange(targetNpc) || CombatClass.InRange(targetNpc))) { MountTask.DismountMount(); } InFight = true; if (!ObjectManager.ObjectManager.Me.IsCast) { Interact.InteractWith(targetNpc.GetBaseAddress); } Thread.Sleep(100); if (ObjectManager.ObjectManager.Me.GetMove && !ObjectManager.ObjectManager.Me.IsCast) { MovementManager.StopMoveTo(); } Point positionStartTarget = targetNpc.Position; int timer = 0; figthStart: // If pos start is very different if (targetNpc.Position.DistanceTo(positionStartTarget) > 50) { return(0); } if (!targetNpc.Attackable) { nManagerSetting.AddBlackList(targetNpc.Guid, 20000); // blacklist 20 sec // Some become unattackable instead of being dead. // Some will evade. } if (Usefuls.IsInBattleground && !Battleground.IsFinishBattleground()) { List <WoWUnit> tLUnit = ObjectManager.ObjectManager.GetHostileUnitAttackingPlayer(); if (tLUnit.Count > 0) { if (ObjectManager.ObjectManager.GetNearestWoWUnit(tLUnit).GetDistance < targetNpc.GetDistance && ObjectManager.ObjectManager.GetNearestWoWUnit(tLUnit).SummonedBy == 0) { return(0); } } } if ((ObjectManager.ObjectManager.Me.InCombat && !CombatClass.InRange(targetNpc)) || TraceLine.TraceLineGo(targetNpc.Position)) // If obstacle or not in range { bool resultSucces; List <Point> points = PathFinder.FindPath(targetNpc.Position, out resultSucces); if (!resultSucces && !Usefuls.IsFlying && MountTask.GetMountCapacity() >= MountCapacity.Fly) { MountTask.Mount(true, true); } // TODO: Code a FindTarget that includes CombatClass.GetRange here or we will often do wierd thing with casters. MovementManager.Go(points); timer = Others.Times + (int)(Math.DistanceListPoint(points) / 3 * 1000) + 15000; while (!ObjectManager.ObjectManager.Me.IsDeadMe && !targetNpc.IsDead && targetNpc.Attackable && !targetNpc.IsLootable && targetNpc.Health > 0 && targetNpc.IsValid && MovementManager.InMovement && InFight && Usefuls.InGame && (TraceLine.TraceLineGo(targetNpc.Position) || !CombatClass.InAggroRange(targetNpc)) ) { // Mob already in fight if (targetNpc.Type != Enums.WoWObjectType.Player && !(targetNpc.IsTargetingMe || targetNpc.Target == 0 || ((WoWUnit)ObjectManager.ObjectManager.GetObjectByGuid(targetNpc.Target)). SummonedBy == ObjectManager.ObjectManager.Me.Guid || targetNpc.Target == ObjectManager.ObjectManager.Pet.Guid)) { return(targetNpc.Guid); } // Timer if (Others.Times > timer && TraceLine.TraceLineGo(targetNpc.Position)) { return(targetNpc.Guid); } // Target Pos Verif if (!targetNpc.Position.IsValid) { return(targetNpc.Guid); } // If pos start is very different if (targetNpc.Position.DistanceTo(positionStartTarget) > 50) { return(0); } // Return if player/pet is attacked by another unit if (ObjectManager.ObjectManager.GetNumberAttackPlayer() > 0 && !targetNpc.IsTargetingMe && !(targetNpc.Target == ObjectManager.ObjectManager.Pet.Guid && targetNpc.Target > 0)) { return(0); } Thread.Sleep(50); } } timer = Others.Times + (int)(ObjectManager.ObjectManager.Me.Position.DistanceTo(targetNpc.Position) / 3 * 1000) + 5000; if (MovementManager.InMovement) { MovementManager.StopMove(); } if (!ObjectManager.ObjectManager.Me.IsCast && ObjectManager.ObjectManager.Me.Target != targetNpc.Guid) { Interact.InteractWith(targetNpc.GetBaseAddress); } InFight = true; Thread.Sleep(200); if (CombatClass.InAggroRange(targetNpc)) { if (ObjectManager.ObjectManager.Me.GetMove && !ObjectManager.ObjectManager.Me.IsCast) { MovementManager.StopMoveTo(); } if (!ObjectManager.ObjectManager.Me.GetMove && ObjectManager.ObjectManager.Me.IsMounted) { MountTask.DismountMount(); } } // If target died after only 0.2sec of fight, let's find a new target. if (targetNpc.IsDead || !targetNpc.IsValid || targetNpc.Attackable) { WoWUnit newTargetNpc = new WoWUnit(ObjectManager.ObjectManager.GetNearestWoWUnit(ObjectManager.ObjectManager.GetHostileUnitAttackingPlayer()).GetBaseAddress); if (newTargetNpc.IsValid && !ObjectManager.ObjectManager.Me.IsCast && ObjectManager.ObjectManager.Me.Target != newTargetNpc.Guid) { targetNpc = newTargetNpc; Interact.InteractWith(targetNpc.GetBaseAddress); // Face the new target MovementManager.Face(targetNpc); } } while (!ObjectManager.ObjectManager.Me.IsDeadMe && !targetNpc.IsDead && targetNpc.Attackable && targetNpc.IsValid && InFight && targetNpc.IsValid && !ObjectManager.ObjectManager.Me.InTransport) { // Return if player attacked and this target not attack player if (targetNpc.Type != Enums.WoWObjectType.Player && !targetNpc.IsTargetingMe && !(targetNpc.Target == ObjectManager.ObjectManager.Pet.Guid && targetNpc.Target > 0) && ObjectManager.ObjectManager.GetNumberAttackPlayer() > 0) { return(0); } // Cancel fight if the mob was tapped by another player if (targetNpc.IsTapped) { return(0); } // Target Pos Verif if (!targetNpc.Position.IsValid) { InFight = false; return(targetNpc.Guid); } // Target mob if not target if (ObjectManager.ObjectManager.Me.Target != targetNpc.Guid && !targetNpc.IsDead && !ObjectManager.ObjectManager.Me.IsCast) { Interact.InteractWith(targetNpc.GetBaseAddress); } // Move to target if out of range if (!ObjectManager.ObjectManager.Me.IsCast && ((!ObjectManager.ObjectManager.Me.InCombat && !CombatClass.InAggroRange(targetNpc)) || ((ObjectManager.ObjectManager.Me.InCombat && !CombatClass.InRange(targetNpc))))) { int rJump = Others.Random(1, 20); MovementManager.MoveTo(targetNpc); if (rJump == 5) { MovementsAction.Jump(); } } // Create path if the mob is out of sight or out of range if ((!CombatClass.InRange(targetNpc) && !ObjectManager.ObjectManager.Me.IsCast) || TraceLine.TraceLineGo(targetNpc.Position)) { goto figthStart; } // Stop move if in range if (CombatClass.InRange(targetNpc) && ObjectManager.ObjectManager.Me.GetMove && !ObjectManager.ObjectManager.Me.IsCast) { MovementManager.StopMoveTo(); } if (ObjectManager.ObjectManager.Me.IsMounted) { MountTask.DismountMount(); Interact.InteractWith(targetNpc.GetBaseAddress); } // Face player to mob MovementManager.Face(targetNpc); // If obstacle between us and the target after this timer expires then stop the fight and blacklist if (Others.Times > timer && TraceLine.TraceLineGo(targetNpc.Position) && targetNpc.HealthPercent > 90) { InFight = false; return(targetNpc.Guid); } Thread.Sleep(75 + Usefuls.Latency); // If timer expires and still not in fight, then stop the fight and blacklist if (Others.Times > timer && !ObjectManager.ObjectManager.Me.InCombat && !targetNpc.IsDead) { InFight = false; return(targetNpc.Guid); } } MovementManager.StopMoveTo(); InFight = false; } catch (Exception exception) { Logging.WriteError("StartFight(UInt128 guid = 0, bool inBg = false): " + exception); InFight = false; } try { if (targetNpc != null) { return(targetNpc.Guid); } } catch { return(0); } return(0); }