private Task ExecuteAndResetTokenSourceAsync(Action action) { return(Execute.AndForgetAsync(() => { action.Invoke(); Trace.WriteLine("Nulling now!"); tokenSource = null; })); }
private void OnWorldInformationChanged(object o, WorldInformationChangedEvent @event) { if (!settingsService.SmartFeatureSettings.SmartActionsEnabled) { return; } var handle = handleService.GetHandle("Diablo III64"); if (handle.IsDefault() || @event.NewOpenWindow == default) { return; } var actionName = settingsService.GetSmartActionName(@event.NewOpenWindow); if (!settingsService.IsSmartActionEnabled(actionName)) { return; } if (actionName == SmartActionName.UpgradeGem) { if (tokenSource == null) { tokenSource = new CancellationTokenSource(); var macro = actionFinderService.FindSmartAction(actionName, handle.Handle, tokenSource, (int)@event.WindowExtraInformation[0]); ExecuteAndResetTokenSourceAsync(macro); logService.AddEntry(this, $"Beginning to execute action... [{actionName}][{@event.NewOpenWindow}]"); } } else if (actionName == SmartActionName.Gamble) { if (tokenSource == null) { tokenSource = new CancellationTokenSource(); var action = actionFinderService.FindSmartAction(actionName, handle.Handle); ExecuteAndResetTokenSourceAsync(() => { action.Invoke(); Thread.Sleep(200); }); logService.AddEntry(this, $"Beginning to execute action... [{actionName}][{@event.NewOpenWindow}]"); } } else if (actionName != default) { var action = actionFinderService.FindSmartAction(actionName, handle.Handle); Execute.AndForgetAsync(action); logService.AddEntry(this, $"Beginning to execute action... [{actionName}][{@event.NewOpenWindow}]"); } }
private void OnHotkeyPressed(object o, HotkeyPressedEvent e) { var handle = handleService.GetHandle("Diablo III64"); if (e.PressedHotkey.KeyCode == Keys.Escape && e.PressedHotkey.Modifiers == Keys.None && tokenSource == null) { InputHelper.SendKey(WindowHelper.GetForegroundWindow(), Keys.Escape); } if (handle.IsDefault()) { return; } var actionName = settingsService.GetActionName(e.PressedHotkey); if (actionName == ActionName.Pause || (e.PressedHotkey.KeyCode == Keys.Escape && e.PressedHotkey.Modifiers == Keys.None)) { if (tokenSource != null) { tokenSource.Cancel(); logService.AddEntry(this, $"Cancelling current action... [{actionName}][{e.PressedHotkey}]"); } } else if (actionName.IsCancelable()) { if (tokenSource == null) { tokenSource = new CancellationTokenSource(); var macro = actionFinderService.FindAction(actionName, handle.Handle, tokenSource); ExecuteAndResetTokenSourceAsync(macro); logService.AddEntry(this, $"Beginning to execute... [{actionName}][{e.PressedHotkey}]"); } else { tokenSource.Cancel(); logService.AddEntry(this, $"Cancelling current action... [{actionName}][{e.PressedHotkey}]"); } } else if (!actionName.IsSuspensionAction()) { var macro = actionFinderService.FindAction(actionName, handle.Handle); Execute.AndForgetAsync(macro); logService.AddEntry(this, $"Beginning to execute... [{actionName}][{e.PressedHotkey}]"); } }
private void OnSkilCanBeCasted(object o, SkillCanBeCastedEvent @event) { if (!settingsService.SmartFeatureSettings.SkillCastingEnabled) { return; } var handle = handleService.GetHandle("Diablo III64"); if (handle.IsDefault() || !settingsService.SkillIsEnabled(@event.SkillName) || settingsService.SkillIndexIsSuspended(@event.SkillIndex)) { return; } Action action; if (@event.SkillIndex <= 3) { var key = settingsService.Settings.SkillKeybindings[@event.SkillIndex]; action = () => InputHelper.SendKey(handle.Handle, key); } else if (@event.SkillIndex == 4) { action = () => InputHelper.SendClickAtCursorPos(handle.Handle, MouseButtons.Left); } else { action = () => InputHelper.SendClickAtCursorPos(handle.Handle, MouseButtons.Right); } var condition = conditionFinderService.FindCondition(@event.SkillName); if (condition.Invoke(modelService.Player, modelService.World, modelService.GetSkill(@event.SkillIndex))) { Execute.AndForgetAsync(action); logService.AddEntry(this, $"Clicking skill... [{@event.SkillName}][{@event.SkillIndex}]", LogLevel.Debug); } else { logService.AddEntry(this, $"Condition for skill not fulfilled... [{@event.SkillName}][{@event.SkillIndex}]", LogLevel.Debug); } }
public void SkillCastLoop(IntPtr handle, CancellationTokenSource tokenSource, SkillCastConfiguration configuration, IList <Keys> skillKeybindings) { foreach (var index in configuration.SkillIndices) { var delay = configuration.Delays[index]; var key = index <= 3 ? skillKeybindings[index] : default; Execute.AndForgetAsync(() => SendKeyWithDelay(handle, tokenSource, index, delay, key)); } while (!IsCancelled(tokenSource)) { Thread.Sleep(20); } return; }