public Bitmap Load <T>(T value) { var cachedBitmap = cacheService.Get <T, Bitmap>(value); if (cachedBitmap != null) { return(cachedBitmap); } var path = GetTypeBastedPath(value); try { var bitmap = new Bitmap(path); if (bitmap.PixelFormat != PixelFormat.Format24bppRgb) { bitmap = ImageHelper.To24bppRgbFormat(bitmap); } cacheService.Add(value, bitmap); logService.AddEntry(this, $"Loaded Image from [{path}] for {value} and added to Cache."); return(bitmap); } catch (Exception ex) { logService.AddEntry(this, $"Couldent load image for {value}", LogLevel.Warning, ex); } return(default);
public void AddHotkey(Hotkey hotkey) { var result = hotkeyListener.Add(hotkey); if (!result) { logService.AddEntry(this, $"Failed to add Hotkey {hotkey} to the listener", Enum.LogLevel.Error); } }
public void UpdateHandle(string processName) { var hwnd = WindowHelper.GetHWND(processName); var currentHandle = GetHandle(processName); var processId = WindowHelper.GetWindowThreadProcessId(hwnd); var clientRect = WindowHelper.GetClientRect(hwnd); if (currentHandle == default || currentHandle.Handle != hwnd || currentHandle.ProcessId != processId || currentHandle.ClientRectangle != clientRect) { var rect = WindowHelper.GetClientRect(hwnd); //var bitmap = new Bitmap(rect.Width - rect.X, rect.Height - rect.Y, PixelFormat.Format24bppRgb); //var graphics = Graphics.FromImage(bitmap); var handle = new WindowInformation { ClientRectangle = rect, Handle = hwnd, ProcessId = WindowHelper.GetWindowThreadProcessId(hwnd), ProcessName = processName, //WindowBitmap = bitmap, //Graphics = graphics, //GraphicsHdc = graphics.GetHdc() }; handles[processName] = handle; HandleStatusChanged?.Invoke(this, new HandleChangedEventArgs { ProcessName = processName, NewHandle = handle }); logService.AddEntry(this, $"Handle information changed [{processName}][{hwnd}][{clientRect}]"); } }
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 Extract(Bitmap picture) { if (picture == null) { return; } var classPart = imageService.CropPlayerClass(picture); var healthPart = imageService.CropHealthbar(picture); var primaryPart = imageService.CropPrimaryResource(picture, modelService.Player.Class); var secondaryPart = imageService.CropSecondaryResource(picture, modelService.Player.Class); var classChanged = ExtractPlayerClass(classPart); var healthChanged = ExtractHealth(healthPart); var primaryResourceChanged = ExtractPrimaryResource(primaryPart); var secondaryResourceChanged = ExtractSecondaryResource(secondaryPart); var @event = new PlayerInformationChangedEvent(); if (classChanged) { @event.ChangedProperties.Add(nameof(Player.Class)); } if (healthChanged) { @event.ChangedProperties.Add(nameof(Player.HealthPercentage)); } if (primaryResourceChanged) { @event.ChangedProperties.Add(nameof(Player.PrimaryResourcePercentage)); } if (secondaryResourceChanged) { @event.ChangedProperties.Add(nameof(Player.SecondaryRessourcePercentage)); } if (@event.ChangedProperties.Any()) { Publish(@event); } logService.AddEntry(this, $"Extracted Playerinformation: [Class:{modelService.Player.Class}, HP: {modelService.Player.HealthPercentage}, PrimaryResource: {modelService.Player.PrimaryResourcePercentage}].", LogLevel.Debug); }
public Item AddOrUpdateItem(ModelItem item, string userid) { Employee employee = context.Employees.FirstOrDefault(e => e.Id == userid); var dbItem = context.Items.Include(i => i.Container).FirstOrDefault(i => i.Id == item.Id); if (dbItem == null) { dbItem = new Item() { Name = item.Name, Description = item.Description, Count = item.Count, ContainerId = item.ContainerId }; context.Items.Add(dbItem); string containername = context.Containers.FirstOrDefault(c => c.Id == item.ContainerId).Name; logService.AddEntry(userid, $"Added {item.Count} item(s) {item.Name} to container {containername}"); } else { string newcontainername = context.Containers.FirstOrDefault(c => c.Id == item.ContainerId).Name; if (dbItem.ContainerId != item.ContainerId) { logService.AddEntry(userid, $"Moved {item.Name} from {dbItem.Container.Name} to {newcontainername}"); } if (dbItem.Name != item.Name) { logService.AddEntry(userid, $"Renamed {dbItem.Name} to {item.Name}"); } if (dbItem.Count != item.Count) { logService.AddEntry(userid, $"{dbItem.Name} count changed from {dbItem.Count} to {item.Count}"); } dbItem.Container.LastEmployee = employee; dbItem.Name = item.Name; dbItem.Description = item.Description; dbItem.Count = item.Count; dbItem.ContainerId = item.ContainerId; } Container newContainer = context.Containers.FirstOrDefault(c => c.Id == dbItem.ContainerId); if (newContainer != null) { newContainer.LastEmployee = employee; } context.SaveChanges(); return(dbItem); }
public ConditionFunction FindCondition(SkillName skillName) { var condition = typeof(Condition).GetMethod(skillName.ToString()); if (condition == null) { logService.AddEntry(this, $"{skillName} has no condition defined, defaulting to return cast inside grift / rift.", LogLevel.Debug); condition = typeof(Condition).GetMethod(nameof(Condition.DefaultAlways)); } return((ConditionFunction)Delegate.CreateDelegate(typeof(ConditionFunction), condition)); }
public Action FindAction(ActionName actionName, IntPtr handle, CancellationTokenSource tokenSource) { if (!actionName.IsCancelable()) { throw new Exception($"Tried to recive non cancelable Macro {actionName} as a cancellable Macro."); } switch (actionName) { case ActionName.CubeConverterDualSlot: var speed = settingsService.MacroSettings.ConvertingSpeed; return(() => actionService.CubeConverterDualSlot(handle, tokenSource, speed)); case ActionName.CubeConverterSingleSlot: speed = settingsService.MacroSettings.ConvertingSpeed; return(() => actionService.CubeConverterSingleSlot(handle, tokenSource, speed)); case ActionName.UpgradeGem: var key = settingsService.GetKeybinding(CommandKeybinding.TeleportToTown); var isEmpowered = settingsService.MacroSettings.Empowered; var pickYourself = settingsService.MacroSettings.PickGemYourself; return(() => actionService.UpgradeGem(handle, tokenSource, isEmpowered, pickYourself, key)); case ActionName.SkillCastLoop: var configuration = settingsService.SkillCastSettings.SelectedSkillCastConfiguration; var keybindings = settingsService.Settings.SkillKeybindings; if (configuration == default) { logService.AddEntry(this, "SelectedSkillCastConfiguration was null", LogLevel.Warning); return(() => { }); } return(() => actionService.SkillCastLoop(handle, tokenSource, configuration, keybindings)); default: throw new NotImplementedException($"Cancellable Macro not implemented for {actionName}"); } }
public void AddEntry(LogEntry entry) { _queue.Enqueue(entry); // Check if it is critical entry and should be passed to global log service if (_logService != null && CriticalEntryTypes != null && CriticalEntryTypes.Contains(entry.GetType())) { _logService.AddEntry(entry); } // count errors if (entry.IsError) { Interlocked.Increment(ref _errorCount); } }
protected internal void OnLoginEvent(OperationContext context, LoginEventType eventType, ILogin login = null, string message = null, string userName = null) { if (context == null && login != null) { context = EntityHelper.GetSession(login).Context; } if (_logService != null) { _logService.AddEntry(new EventLogEntry("Login", eventType.ToString(), EventSeverity.Info, message: message, objectId: login?.Id, context: context, objectName: userName)); } var args = new LoginEventArgs(eventType, login, context); LoginEvent?.Invoke(this, args); }
public void Flush() { if (_logService == null) { return; } var entries = DequeueAll(); if (entries.Count == 0) { return; } var compEntry = new BatchedLogEntry(_contextInfo, entries); _logService.AddEntry(compEntry); }
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}]"); } }
// TODO: Make more performant. This eats most of the cpu usage. public Bitmap CaptureWindow(IntPtr hwnd) { var watch = Stopwatch.StartNew(); if (hwnd == default) { logService.AddEntry(this, $"Got empty handle when trying to capture window.", LogLevel.Debug); return(null); } var rect = WindowHelper.GetClientRect(hwnd); var bitmap = new Bitmap(rect.Width - rect.X, rect.Height - rect.Y, PixelFormat.Format24bppRgb); using (var graphics = Graphics.FromImage(bitmap)) { var dc = graphics.GetHdc(); WindowHelper.PrintWindow(hwnd, dc, 0); graphics.ReleaseHdc(); } watch.Stop(); Trace.WriteLine($"Image:{watch.ElapsedMilliseconds}"); return(bitmap); }
public void AddEntry(LogEntry entry) { _logService.AddEntry(entry); }