private void ChangeCharacter(SelectCharacterResult result) { Process process = result.Process; Boolean isProcessSelected = result.IsSelected; // User never selected a process. if (result.Process == null || !isProcessSelected) { LogViewModel.Write("Process not found"); AppServices.InformUser("No valid process was selected."); return; } // Log that a process selected. LogViewModel.Write("Process found"); // Get memory reader set in config file. MemoryWrapper fface = MemoryWrapper.Create(process.Id); // Set the EliteApi Session. ViewModelBase.SetSession(fface); // Tell the user the program has loaded the player's data AppServices.InformUser("Bot Loaded: " + fface.Player.Name); // Set the main window's title to the player's name. AppServices.UpdateTitle("EasyFarm - " + fface.Player.Name); }
/// <summary> /// Stop the character from fight the target /// </summary> public static void Disengage(MemoryWrapper fface) { if (fface.Player.Status.Equals(Status.Fighting)) { fface.Windower.SendString(Constants.AttackOff); } }
/// <summary> /// Checks whether a spell or ability can be recasted. /// </summary> /// <param name="fface"></param> /// <param name="ability"></param> /// <returns></returns> public static bool IsRecastable(MemoryWrapper fface, Ability ability) { var recast = 0; // No recast time on weaponskills. if (ability.AbilityType == AbilityType.Weaponskill) { return(true); } // No recast for ranged attacks. if (AbilityType.Range.HasFlag(ability.AbilityType)) { return(true); } // If a spell get spell recast if (ResourceHelper.IsSpell(ability.AbilityType)) { recast = fface.Timer.GetSpellRecast(ability.Index); } // if ability get ability recast. if (ResourceHelper.IsAbility(ability.AbilityType)) { recast = fface.Timer.GetAbilityRecast(ability.Id); } return(recast <= 0); }
/// <summary> /// Makes the character stop resting /// </summary> public static void Stand(MemoryWrapper fface) { if (fface.Player.Status.Equals(Status.Healing)) { fface.Windower.SendString(Constants.RestingOff); Thread.Sleep(50); } }
public UnitService(MemoryWrapper fface) { _fface = fface; // Create the UnitArray Units = Enumerable.Range(0, UnitArrayMax) .Select(x => new Unit(_fface, x)).ToList(); }
public Caster(MemoryWrapper fface) { _fface = fface; if (_player == null) { _player = new MovingUnit(_fface, _fface.Player.ID); } }
public Unit(MemoryWrapper fface, int id) { // Set this unit's session data. _fface = fface; // Set the internal id. Id = id; // Set the NPC information. _npc = _fface.NPC; }
public MovingUnit(MemoryWrapper fface, int id) : base(fface, id) { _mutex = new object(); _timer = new Timer { AutoReset = true, Interval = 30 }; _timer.Elapsed += TimerTick; _timer.Start(); }
public static void SetSession(MemoryWrapper fface) { if (fface == null) { return; } // Save fface Instance FFACE = fface; // Create a new game engine to control our character. GameEngine = new GameEngine(FFACE); if (OnSessionSet != null) { OnSessionSet(fface); } }
internal void HandleHeartbeat(ArraySegment <byte> payload) { _stateLock.EnterReadLock(); try { if (State == ConnectionState.Connected) { HeapPointers pointers = HeartbeatChannel.HandleIncomingMessagePoll(payload); if (pointers != null) { MemoryWrapper wrapper = (MemoryWrapper)pointers.Pointers[0]; if (wrapper != null) { if (wrapper.AllocatedMemory != null) { LastMessageIn = NetTime.Now; // Dealloc the memory MemoryManager.DeAlloc(wrapper.AllocatedMemory); } if (wrapper.DirectMemory != null) { LastMessageIn = NetTime.Now; } // Dealloc the wrapper MemoryManager.DeAlloc(wrapper); } // Dealloc the pointers MemoryManager.DeAlloc(pointers); } } } finally { _stateLock.ExitReadLock(); } }
/// <summary> /// Filters out unusable targeted abilities. /// </summary> /// <param name="fface"></param> /// <param name="action"></param> /// <param name="unit"></param> /// <returns></returns> public static bool TargetedFilter(MemoryWrapper fface, BattleAbility action, Unit unit) { // Does not pass the base criteria for casting. if (!BuffingFilter(fface, action)) { return(false); } // Target HP Checks Enabled. if (action.TargetLowerHealth != 0 || action.TargetUpperHealth != 0) { // Target Upper Health Check if (unit.HppCurrent > action.TargetUpperHealth) { return(false); } // Target Lower Health Check if (unit.HppCurrent < action.TargetLowerHealth) { return(false); } } // Target Name Checks Enabled. if (!string.IsNullOrWhiteSpace(action.TargetName)) { // Target Name Check. if (!Regex.IsMatch(unit.Name, action.TargetName, RegexOptions.IgnoreCase)) { return(false); } } // Distance Check if (unit.Distance > action.Distance) { return(false); } return(true); }
/// <summary> /// Selects a process to user for this application. /// </summary> private void SelectProcess() { // Let user select ffxi process var selectionView = new ProcessSelectionView(); selectionView.ShowDialog(); // Grab the view model with the game sessions. var viewModel = selectionView.DataContext as ProcessSelectionViewModel; // If the view has a process selection view model binded to it. if (viewModel != null) { // Get the selected process. var process = viewModel.SelectedProcess; // User never selected a process. if (process == null || !viewModel.IsProcessSelected) { LogViewModel.Write("Process not found"); AppServices.InformUser("No valid process was selected."); return; } // Log that a process selected. LogViewModel.Write("Process found"); // Get memory reader set in config file. var fface = MemoryWrapper.Create(process.Id); // Set the fface Session. SetSession(fface); // Tell the user the program has loaded the player's data AppServices.InformUser("Bot Loaded: " + fface.Player.Name); // Set the main window's title to the player's name. MainWindowTitle = "EasyFarm - " + fface.Player.Name; } }
public async Task Handle(SelectProcessRequest message, CancellationToken cancellationToken) { // Let user select ffxi process var selectionView = new SelectProcessDialog(); var viewModel = new SelectProcessViewModel(selectionView); selectionView.DataContext = viewModel; // Show window and do not continue until user closes it. await window.ShowMetroDialogAsync(selectionView); await selectionView.WaitUntilUnloadedAsync(); // Get the selected process. var process = viewModel.SelectedProcess; // User never selected a process. if (process == null || !viewModel.IsProcessSelected) { LogViewModel.Write("Process not found"); AppServices.InformUser("No valid process was selected."); return; } // Log that a process selected. LogViewModel.Write("Process found"); // Get memory reader set in config file. var fface = MemoryWrapper.Create(process.Id); // Set the EliteApi Session. ViewModelBase.SetSession(fface); // Tell the user the program has loaded the player's data AppServices.InformUser("Bot Loaded: " + fface.Player.Name); // Set the main window's title to the player's name. AppServices.UpdateTitle("EasyFarm - " + fface.Player.Name); }
public DeadState(MemoryWrapper fface) : base(fface) { }
public BattleComponent(MemoryWrapper fface) : base(fface) { _executor = new Executor(fface); }
public StartEngineState(MemoryWrapper fface) : base(fface) { }
private static void EraseStreamImpl(long task, int loop, Stream destination, Options opts) { var buffer = new byte[opts.BufferSize]; if (opts.Randomize) { mRandom.NextBytes(buffer); } else { MemoryWrapper.Set(buffer, 0, buffer.Length); } var relativeProgressWidth = ContentWidth - 1; var lastPosition = 0L; var lastTime = DateTime.Now; Logger.Verbose("[{0}] Starting loop #{1}", task, loop); Write(ContentLeft + 1, ContentTop + 7, ' ', relativeProgressWidth); while (destination.Position < destination.Length) { if (opts.Randomize && !opts.RandomizeOnce) { mRandom.NextBytes(buffer); } var writeCount = (int)Math.Min( buffer.Length, destination.Length - destination.Position); destination.Write(buffer, 0, writeCount); mTotalPosition += writeCount; var now = DateTime.Now; var timeDelta = now.Subtract(lastTime); if (timeDelta.TotalSeconds >= 1.0 || destination.Position == destination.Length || opts.FastRefresh) { ResetColor(); // // Total progress // { var totalTimeDelta = now.Subtract(mTotalStartTime); var progress = ((double)mTotalPosition / mTotalLength); var averageSpeed = (mTotalPosition == 0 ? 0.0 : mTotalPosition / totalTimeDelta.TotalSeconds); var estimatedEnd = (averageSpeed == 0 ? TimeSpan.MaxValue : TimeSpan.FromSeconds((mTotalLength - mTotalPosition) / averageSpeed)); var widthProgress = (int)Math.Min(progress * relativeProgressWidth, relativeProgressWidth); Write(ContentLeft + 1, ContentTop + 3, '|', widthProgress); WriteFormat(ContentLeft, ContentTop + 4, "{0:0.00} % ", progress * 100); var progressString = string.Format( "{0} / {1}", FormatBytes(mTotalPosition, 3), FormatBytes(mTotalLength, 3)); var progressPadding = ""; if (progressString.Length < mLastTotalProgressString.Length) { progressPadding = new string(' ', mLastTotalProgressString.Length - progressString.Length); } mLastTotalProgressString = progressString; WriteFormatRight(ContentLeft + ContentWidth, ContentTop + 2, "{0}{1}", progressPadding, progressString); var speedString = string.Format( "ETA: {0:hh\\:mm\\:ss} @ {1}/s", estimatedEnd, FormatBytes(averageSpeed, 3)); var speedPadding = ""; if (speedString.Length < mLastTotalSpeedString.Length) { speedPadding = new string(' ', mLastTotalSpeedString.Length - speedString.Length); } mLastTotalSpeedString = speedString; WriteFormatRight(ContentLeft + ContentWidth, ContentTop + 4, "{0}{1}", speedPadding, speedString); } // // Current progress // { var posDelta = destination.Position - lastPosition; var progress = ((double)destination.Position / destination.Length); var averageSpeed = (posDelta == 0 ? 0.0 : posDelta / timeDelta.TotalSeconds); var estimatedEnd = (averageSpeed == 0 ? TimeSpan.MaxValue : TimeSpan.FromSeconds((destination.Length - destination.Position) / averageSpeed)); var widthProgress = (int)Math.Min(progress * relativeProgressWidth, relativeProgressWidth); Write(ContentLeft + 1, ContentTop + 7, '|', widthProgress); WriteFormat(ContentLeft, ContentTop + 8, "{0:0.00} % ", progress * 100); var progressString = string.Format( "{0} / {1}", FormatBytes(destination.Position, 3), FormatBytes(destination.Length, 3)); var progressPadding = ""; if (progressString.Length < mLastProgressString.Length) { progressPadding = new string(' ', mLastProgressString.Length - progressString.Length); } mLastProgressString = progressString; WriteFormatRight(ContentLeft + ContentWidth, ContentTop + 6, "{0}{1}", progressPadding, progressString); var speedString = string.Format( "ETA: {0:hh\\:mm\\:ss} @ {1}/s", estimatedEnd, FormatBytes(averageSpeed, 3)); var speedPadding = ""; if (speedString.Length < mLastSpeedString.Length) { speedPadding = new string(' ', mLastSpeedString.Length - speedString.Length); } mLastSpeedString = speedString; WriteFormatRight(ContentLeft + ContentWidth, ContentTop + 8, "{0}{1}", speedPadding, speedString); } lastPosition = destination.Position; lastTime = now; } } destination.Flush(); }
public SetTargetState(MemoryWrapper fface) : base(fface) { _units = new UnitService(fface); }
public TravelComponent(MemoryWrapper fface) : base(fface) { // Create unit object for parsing of npc array. _units = new UnitService(fface); }
public WeaponSkillComponent(MemoryWrapper fface) : base(fface) { Executor = new Executor(fface); }
public RestComponent(MemoryWrapper fface) : base(fface) { _units = new UnitService(fface); }
/// <summary> /// Filters out unusable buffing abilities. /// </summary> /// <param name="fface"></param> /// <param name="action"></param> /// <returns></returns> public static bool BuffingFilter(MemoryWrapper fface, BattleAbility action) { // Return if not enabled. if (!action.IsEnabled) { return(false); } // Name Check if (string.IsNullOrWhiteSpace(action.Name)) { return(false); } // MP Check if (action.Ability.MpCost > fface.Player.MPCurrent) { return(false); } // TP Check if (action.Ability.TpCost > fface.Player.TPCurrent) { return(false); } // Usage Limit Check. if (action.UsageLimit != 0) { if (action.Usages > action.UsageLimit) { return(false); } } // Recast Check if (!AbilityUtils.IsRecastable(fface, action.Ability)) { return(false); } // Limiting Status Effect Check for Spells. if (ResourceHelper.IsSpell(action.Ability.AbilityType)) { if (ProhibitEffects.ProhibitEffectsSpell.Intersect(fface.Player.StatusEffects).Any()) { return(false); } } // Limiting Status Effect Check for Abilities. if (ResourceHelper.IsAbility(action.Ability.AbilityType)) { if (ProhibitEffects.ProhibitEffectsAbility.Intersect(fface.Player.StatusEffects).Any()) { return(false); } } // Player HP Checks Enabled. if (action.PlayerLowerHealth != 0 || action.PlayerUpperHealth != 0) { // Player Upper HP Check if (fface.Player.HPPCurrent > action.PlayerUpperHealth) { return(false); } // Player Lower HP Check if (fface.Player.HPPCurrent < action.PlayerLowerHealth) { return(false); } } // Status Effect Checks Enabled if (!string.IsNullOrWhiteSpace(action.StatusEffect)) { var hasEffect = fface.Player.StatusEffects.Any(effect => Regex.IsMatch(effect.ToString(), action.StatusEffect.Replace(" ", "_"), RegexOptions.IgnoreCase)); // Contains Effect Check if (hasEffect && !action.TriggerOnEffectPresent) { return(false); } // Missing EFfect Check if (!hasEffect && action.TriggerOnEffectPresent) { return(false); } } // Check if action's recast period has passed. if (action.Recast != 0) { if (action.LastCast > DateTime.Now) { return(false); } } return(true); }
public StartComponent(MemoryWrapper fface) : base(fface) { Executor = new Executor(fface); }
public CombatBaseState(MemoryWrapper fface) : base(fface) { }
public ApproachComponent(MemoryWrapper fface) : base(fface) { }
/// <summary> /// Returns true if a mob is attackable by the player based on the various settings in the /// Config class. /// </summary> /// <param name="fface"></param> /// <param name="mob"></param> /// <returns></returns> public static bool MobFilter(MemoryWrapper fface, Unit mob) { // Function to use to filter surrounding mobs by. General Mob Filtering Criteria if (fface == null) { return(false); } if (mob == null) { return(false); } // Mob not active if (!mob.IsActive) { return(false); } // INFO: fixes trying to attack dead mob problem. Mob is dead if (mob.IsDead) { return(false); } // Mob not rendered on screen. if (!mob.IsRendered) { return(false); } // Type is not mob if (!mob.NpcType.Equals(NPCType.Mob)) { return(false); } // Mob is out of range if (!(mob.Distance < Config.Instance.DetectionDistance)) { return(false); } if (mob.IsPet) { return(false); } // If any unit is within the wander distance then the if (Config.Instance.Waypoints.Any()) { if (!(Config.Instance.Waypoints.Any(waypoint => Distance(mob, waypoint) <= Config.Instance.WanderDistance))) { return(false); } } // Mob too high out of reach. if (mob.YDifference > Config.Instance.HeightThreshold) { return(false); } // User Specific Filtering // Performs a case insensitve match on the mob's name. If any part of the mob's name is // in the ignored list, we will not attack it. if (MatchAny(mob.Name, Config.Instance.IgnoredMobs, RegexOptions.IgnoreCase)) { return(false); } // Kill aggro if aggro's checked regardless of target's list but follows the ignored list. if (mob.HasAggroed && Config.Instance.AggroFilter) { return(true); } // There is a target's list but the mob is not on it. if (!MatchAny(mob.Name, Config.Instance.TargetedMobs, RegexOptions.IgnoreCase) && Config.Instance.TargetedMobs.Any()) { return(false); } // Mob on our targets list or not on our ignore list. // Kill the creature if it has aggroed and aggro is checked. if (mob.HasAggroed && Config.Instance.AggroFilter) { return(true); } // Kill the creature if it is claimed by party and party is checked. if (mob.PartyClaim && Config.Instance.PartyFilter) { return(true); } // Kill the creature if it's not claimed and unclaimed is checked. if (!mob.IsClaimed && Config.Instance.UnclaimedFilter) { return(true); } // Kill the creature if it's claimed and we we don't have claim but // claim is checked. //FIX: Temporary fix until player.serverid is fixed. if (mob.IsClaimed && Config.Instance.ClaimedFilter) { return(true); } // Kill only mobs that we have claim on. return(mob.ClaimedId == fface.PartyMember[0].ServerID); }
public FiniteStateEngine(MemoryWrapper fface) { //Create the states AddComponent(new DeadState(fface) { Priority = 6 }); AddComponent(new ZoneState(fface) { Priority = 6 }); AddComponent(new SetTargetState(fface) { Priority = 6 }); AddComponent(new SetFightingState(fface) { Priority = 6 }); AddComponent(new FollowState(fface) { Priority = 5 }); AddComponent(new RestComponent(fface) { Priority = 2 }); AddComponent(new ApproachComponent(fface) { Priority = 0 }); AddComponent(new BattleComponent(fface) { Priority = 3 }); AddComponent(new WeaponSkillComponent(fface) { Priority = 2 }); AddComponent(new PullComponent(fface) { Priority = 4 }); AddComponent(new StartComponent(fface) { Priority = 5 }); AddComponent(new TravelComponent(fface) { Priority = 1 }); AddComponent(new HealingComponent(fface) { Priority = 2 }); AddComponent(new EndComponent(fface) { Priority = 3 }); AddComponent(new StartEngineState(fface) { Priority = Constants.MaxPriority }); _components.ForEach(x => x.Enabled = true); }
internal static void HandleIncomingMessage(ArraySegment <byte> payload, Connection connection, SocketConfig config, MemoryManager memoryManager) { // This is where all data packets arrive after passing the connection handling. byte channelId = payload.Array[payload.Offset]; if (channelId < 0 || channelId >= connection.Channels.Length) { // ChannelId out of range if (Logging.CurrentLogLevel <= LogLevel.Warning) { Logging.LogWarning("Got message on channel out of range. [ChannelId=" + channelId + "]"); } return; } IChannel channel = connection.Channels[channelId]; if (channel != null) { HeapPointers incomingPointers = channel.HandleIncomingMessagePoll(new ArraySegment <byte>(payload.Array, payload.Offset + 1, payload.Count - 1)); if (incomingPointers != null) { ushort sequence = (ushort)(payload.Array[payload.Offset] | (ushort)(payload.Array[payload.Offset + 1] << 8)); // TODO: This is already calculated inside HandleIncomingMessagePoll, we could just get it from there instead of doing this again... // There is new packets for (int i = 0; i < incomingPointers.VirtualCount; i++) { MemoryWrapper wrapper = (MemoryWrapper)incomingPointers.Pointers[i]; HeapMemory memory = null; if (wrapper.AllocatedMemory != null) { memory = wrapper.AllocatedMemory; } if (wrapper.DirectMemory != null) { // Alloc memory memory = memoryManager.AllocHeapMemory((uint)wrapper.DirectMemory.Value.Count); // Copy payload to borrowed memory Buffer.BlockCopy(wrapper.DirectMemory.Value.Array, wrapper.DirectMemory.Value.Offset, memory.Buffer, 0, wrapper.DirectMemory.Value.Count); } if (memory != null) { // Send to userspace connection.Socket.PublishEvent(new NetworkEvent() { Connection = connection, Socket = connection.Socket, Type = NetworkEventType.Data, AllowUserRecycle = true, Data = new ArraySegment <byte>(memory.Buffer, (int)memory.VirtualOffset, (int)memory.VirtualCount), InternalMemory = memory, SocketReceiveTime = NetTime.Now, ChannelId = channelId, Sequence = sequence, MemoryManager = memoryManager, EndPoint = connection.EndPoint }); } // Dealloc the wrapper memoryManager.DeAlloc(wrapper); } // Dealloc the pointers memoryManager.DeAlloc(incomingPointers); } } else { if (Logging.CurrentLogLevel <= LogLevel.Warning) { Logging.LogWarning("Receive message failed because the channel is not assigned"); } } }
public Executor(MemoryWrapper fface) { _fface = fface; _caster = new Caster(fface); }
public GameEngine(MemoryWrapper fface) { _fface = fface; _stateMachine = new FiniteStateEngine(fface); }