private void SaveSettings(object sender, RoutedEventArgs e) { var settingsVM = (SettingsVM)DataContext; RatConfig.NameScan.Enable = settingsVM.EnableNameScan; RatConfig.IconScan.Enable = settingsVM.EnableIconScan; RatConfig.IconScan.ScanRotatedIcons = settingsVM.ScanRotatedIcons; RatConfig.IconScan.UseCachedIcons = settingsVM.UseCachedIcons; RatConfig.IconScan.ModifierKeyCode = settingsVM.IconScanModifier; RatConfig.ToolTip.Duration = int.TryParse(settingsVM.ToolTipDuration, out var i) ? i : 0; RatConfig.MinimalUi.ShowName = settingsVM.ShowName; RatConfig.MinimalUi.ShowPrice = settingsVM.ShowPrice; RatConfig.MinimalUi.ShowAvgDayPrice = settingsVM.ShowAvgDayPrice; RatConfig.MinimalUi.ShowAvgWeekPrice = settingsVM.ShowAvgWeekPrice; RatConfig.MinimalUi.ShowPricePerSlot = settingsVM.ShowPricePerSlot; RatConfig.MinimalUi.ShowTraderPrice = settingsVM.ShowTraderPrice; RatConfig.MinimalUi.ShowUpdated = settingsVM.ShowUpdated; RatConfig.MinimalUi.Opacity = settingsVM.Opacity; RatConfig.ScreenResolution = (RatConfig.Resolution)settingsVM.ScreenResolution; RatConfig.MinimizeToTray = settingsVM.MinimizeToTray; RatConfig.AlwaysOnTop = settingsVM.AlwaysOnTop; RatConfig.LogDebug = settingsVM.LogDebug; Logger.LogInfo("Saving config..."); RatConfig.SaveConfig(); // Apply config PageSwitcher.Instance.Topmost = RatConfig.AlwaysOnTop; PageSwitcher.Instance.Navigate(new MainMenu()); }
private void SaveSettings(object sender, RoutedEventArgs e) { if (!scanLockTask.Wait(1000)) { Logger.LogWarning("Could not save settings. Scan lock not acquired!"); return; } var settingsVM = (SettingsVM)DataContext; // Pre saving stuff var updateMarketDB = settingsVM.NameScanLanguage != (int)RatConfig.NameScan.Language; // Save settings RatConfig.NameScan.Enable = settingsVM.EnableNameScan; RatConfig.NameScan.Language = (ApiManager.Language)settingsVM.NameScanLanguage; RatConfig.IconScan.Enable = settingsVM.EnableIconScan; RatConfig.IconScan.ScanRotatedIcons = settingsVM.ScanRotatedIcons; RatConfig.IconScan.UseCachedIcons = settingsVM.UseCachedIcons; RatConfig.IconScan.ModifierKeyCode = settingsVM.IconScanModifier; RatConfig.ToolTip.Duration = int.TryParse(settingsVM.ToolTipDuration, out var i) ? i : 0; RatConfig.MinimalUi.ShowName = settingsVM.ShowName; RatConfig.MinimalUi.ShowPrice = settingsVM.ShowPrice; RatConfig.MinimalUi.ShowAvgDayPrice = settingsVM.ShowAvgDayPrice; RatConfig.MinimalUi.ShowAvgWeekPrice = settingsVM.ShowAvgWeekPrice; RatConfig.MinimalUi.ShowPricePerSlot = settingsVM.ShowPricePerSlot; RatConfig.MinimalUi.ShowTraderPrice = settingsVM.ShowTraderPrice; RatConfig.MinimalUi.ShowUpdated = settingsVM.ShowUpdated; RatConfig.MinimalUi.Opacity = settingsVM.Opacity; RatConfig.ScreenResolution = (RatConfig.Resolution)settingsVM.ScreenResolution; RatConfig.MinimizeToTray = settingsVM.MinimizeToTray; RatConfig.AlwaysOnTop = settingsVM.AlwaysOnTop; RatConfig.LogDebug = settingsVM.LogDebug; Logger.LogInfo("Saving config..."); RatConfig.SaveConfig(); // Apply config PageSwitcher.Instance.Topmost = RatConfig.AlwaysOnTop; if (updateMarketDB) { RatScannerMain.Instance.MarketDB.Init(); } // Switch back to main menu PageSwitcher.Instance.Navigate(new MainMenu()); }
private void SaveSettings(object sender, RoutedEventArgs e) { Logger.LogInfo("Applying config..."); var settingsVM = (SettingsVM)DataContext; // Pre saving stuff var updateMarketDB = settingsVM.NameScanLanguage != (int)RatConfig.NameScan.Language; // Save settings RatConfig.NameScan.Enable = settingsVM.EnableNameScan; RatConfig.NameScan.Language = (ApiManager.Language)settingsVM.NameScanLanguage; RatConfig.IconScan.Enable = settingsVM.EnableIconScan; RatConfig.IconScan.ScanRotatedIcons = settingsVM.ScanRotatedIcons; RatConfig.IconScan.UseCachedIcons = settingsVM.UseCachedIcons; RatConfig.IconScan.Hotkey = settingsVM.IconScanHotkey; RatConfig.ToolTip.Duration = int.TryParse(settingsVM.ToolTipDuration, out var i) ? i : 0; RatConfig.MinimalUi.ShowName = settingsVM.ShowName; RatConfig.MinimalUi.ShowAvgDayPrice = settingsVM.ShowAvgDayPrice; RatConfig.MinimalUi.ShowPricePerSlot = settingsVM.ShowPricePerSlot; RatConfig.MinimalUi.ShowTraderPrice = settingsVM.ShowTraderPrice; RatConfig.MinimalUi.ShowTraderMaxPrice = settingsVM.ShowTraderMaxPrice; RatConfig.MinimalUi.ShowUpdated = settingsVM.ShowUpdated; RatConfig.MinimalUi.Opacity = settingsVM.Opacity; RatConfig.ScreenResolution = (RatConfig.Resolution)settingsVM.ScreenResolution; RatConfig.MinimizeToTray = settingsVM.MinimizeToTray; RatConfig.AlwaysOnTop = settingsVM.AlwaysOnTop; RatConfig.LogDebug = settingsVM.LogDebug; Logger.LogInfo("Saving config..."); RatConfig.SaveConfig(); // Apply config PageSwitcher.Instance.Topmost = RatConfig.AlwaysOnTop; if (updateMarketDB) { RatScannerMain.Instance.MarketDB.Init(); } RatScannerMain.Instance.HotkeyManager.RegisterHotkeys(); Logger.LogInfo("Config saved!"); // Switch back to main menu PageSwitcher.Instance.Navigate(new MainMenu()); }
internal ItemIconScan(Bitmap capture, Vector2 mouseVector2) { Logger.ClearDebugMats(); Capture = capture; MousePos = mouseVector2; var(iconPosition, iconSize) = LocateIcon(Capture); var padding = RatConfig.IconScan.ScanPadding; // Add padding var iconSlotSize = new Size(); iconSlotSize.Width = IconManager.PixelsToSlots(iconSize.X); iconSlotSize.Height = IconManager.PixelsToSlots(iconSize.Y); // Rectify icon position for padding iconPosition -= new Vector2(padding / 2, padding / 2); iconSize.X += padding; iconSize.Y += padding; if (iconPosition.X < 0) { iconPosition.X = 0; } if (iconPosition.Y < 0) { iconPosition.Y = 0; } if (iconSize.X + iconPosition.X > Capture.Width) { iconSize.X = Capture.Width - iconPosition.X; } if (iconSize.Y + iconPosition.Y > Capture.Height) { iconSize.Y = Capture.Height - iconPosition.Y; } if (iconSlotSize.Width == 0 || iconSlotSize.Height == 0) { return; } Logger.LogDebug("pX: " + iconPosition.X + " | pY: " + iconPosition.Y); Logger.LogDebug("pW: " + iconSize.X + " | pH: " + iconSize.Y); Logger.LogDebug("sW: " + iconSlotSize.Width + " | sH: " + iconSlotSize.Height); // Crop capture to icon var sourceBitmap = new Bitmap(Capture).Clone(new Rectangle(iconPosition, iconSize), Capture.PixelFormat); var croppedIcon = sourceBitmap.ToMat(); Logger.LogDebugMat(croppedIcon, "cropped_icon"); // Rescale captured icon if resolution is not FHD if (RatConfig.ScreenResolution != RatConfig.Resolution.R1920x1080) { var invSSF = RatConfig.GetInverseScreenScaleFactor(); var croppedSize = new Size(croppedIcon.Width * invSSF, croppedIcon.Height * invSSF); croppedIcon = croppedIcon.Resize(croppedSize, 0, 0, InterpolationFlags.Area); Logger.LogDebugMat(croppedIcon, "resized_cropped_icon"); } var iconWidthPixel = IconManager.SlotsToPixels(iconSlotSize.Width); var iconHeightPixel = IconManager.SlotsToPixels(iconSlotSize.Height); IconRect.Size = new Size(iconWidthPixel, iconHeightPixel); // Actually scan the source var matchResult = ScanStaticAndDynamic(iconSlotSize, croppedIcon); if (RatConfig.IconScan.ScanRotatedIcons) { // Rotate source var croppedIconRotated = new Mat(); Cv2.Rotate(croppedIcon, croppedIconRotated, RotateFlags.Rotate90Counterclockwise); var iconSlotSizeRotated = new Size(iconSlotSize.Height, iconSlotSize.Width); // Actually scan the source var matchResultRotated = ScanStaticAndDynamic(iconSlotSizeRotated, croppedIconRotated); if (matchResultRotated.conf > matchResult.conf) { matchResult = matchResultRotated; // Rotate match position when matched on rotated source var xPos = matchResult.pos.X; matchResult.pos.X = matchResult.pos.Y; matchResult.pos.Y = xPos; Rotated = true; } } Logger.LogDebug("Icon Key: " + matchResult.iconKey); Logger.LogDebug("Conf: " + matchResult.conf); IconRect.X = MousePos.X - (RatConfig.IconScan.ScanWidth / 2) + iconPosition.X + matchResult.pos.X; IconRect.Y = MousePos.Y - (RatConfig.IconScan.ScanHeight / 2) + iconPosition.Y + matchResult.pos.Y; Confidence = matchResult.conf; var itemInfos = IconManager.GetItemInfo(matchResult.iconKey); if (!(itemInfos?.Length > 0)) { return; } MatchedItems = Array.ConvertAll(itemInfos, itemInfo => itemInfo.GetItem()); if (MatchedItems?.Length > 0) { MatchedItems = MatchedItems.Where(item => item != null).ToArray(); } if (MatchedItems?.Length > 0) { ValidItem = true; } }