From ad749d801a8a8c8c945612fbb7eacd16f265785f Mon Sep 17 00:00:00 2001 From: Macocian Alexandru Victor Date: Sat, 25 Mar 2023 10:36:15 +0200 Subject: [PATCH] Minimap improvements (#189) Closes #187 Closes #188 Minimap performance improvements Add context menues for main player and living entities --- .editorconfig | 7 +- Daybreak/Controls/GuildwarsMinimap.xaml | 17 ++- Daybreak/Controls/GuildwarsMinimap.xaml.cs | 136 ++++++++++++------ .../Controls/LivingEntityContextMenu.xaml | 19 +++ .../Controls/LivingEntityContextMenu.xaml.cs | 13 ++ Daybreak/Controls/MainPlayerContextMenu.xaml | 25 ++++ .../Controls/MainPlayerContextMenu.xaml.cs | 14 ++ .../Controls/WorldPlayerContextMenu.xaml.cs | 17 ++- Daybreak/Daybreak.csproj | 2 +- Daybreak/Launch/MainWindow.xaml.cs | 2 +- Daybreak/Models/Interop/PathingTrapezoid.cs | 1 + Daybreak/Models/Interop/ProfessionsContext.cs | 2 +- .../ApplicationLauncher.cs | 14 +- .../Experience/ExperienceCalculator.cs | 2 +- .../Monitoring/ProcessorUsageMonitor.cs | 2 +- Daybreak/Services/Mutex/MutexHandler.cs | 2 +- Daybreak/Utils/EncryptionHelper.cs | 2 +- 17 files changed, 201 insertions(+), 76 deletions(-) create mode 100644 Daybreak/Controls/LivingEntityContextMenu.xaml create mode 100644 Daybreak/Controls/LivingEntityContextMenu.xaml.cs create mode 100644 Daybreak/Controls/MainPlayerContextMenu.xaml create mode 100644 Daybreak/Controls/MainPlayerContextMenu.xaml.cs diff --git a/.editorconfig b/.editorconfig index a2f8fb40..58f1f4f5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,8 +6,8 @@ csharp_indent_labels = one_less_than_current csharp_using_directive_placement = outside_namespace:error csharp_prefer_simple_using_statement = true:error csharp_prefer_braces = true:silent -csharp_style_namespace_declarations = block_scoped:silent -csharp_style_prefer_method_group_conversion = true:silent +csharp_style_namespace_declarations = file_scoped:error +csharp_style_prefer_method_group_conversion = true:suggestion csharp_style_expression_bodied_methods = false:silent csharp_style_expression_bodied_constructors = false:silent csharp_style_expression_bodied_operators = false:silent @@ -46,6 +46,9 @@ csharp_style_prefer_extended_property_pattern = true:suggestion csharp_style_var_for_built_in_types = false:silent csharp_style_var_when_type_is_apparent = false:silent csharp_style_var_elsewhere = false:silent +csharp_style_prefer_top_level_statements = true:suggestion +csharp_style_prefer_utf8_string_literals = true:suggestion +csharp_style_prefer_readonly_struct = true:suggestion [*.{cs,vb}] #### Naming styles #### diff --git a/Daybreak/Controls/GuildwarsMinimap.xaml b/Daybreak/Controls/GuildwarsMinimap.xaml index 4611efee..e1688bc7 100644 --- a/Daybreak/Controls/GuildwarsMinimap.xaml +++ b/Daybreak/Controls/GuildwarsMinimap.xaml @@ -22,10 +22,23 @@ + + + + + + + + + + + + + + - - + /// Interaction logic for GuildwarsMinimap.xaml /// public partial class GuildwarsMinimap : UserControl { + private const int MapDownscaleFactor = 10; + private const int EntitySize = 100; private const float PositionRadius = 150; + + private readonly List mainPlayerPositionHistory = new(); private readonly IGuildwarsEntityDebouncer guildwarsEntityDebouncer; private readonly Color positionHistoryColor = Color.FromArgb(155, Colors.Red.R, Colors.Red.G, Colors.Red.B); private bool resizeEntities; private bool dragging; - private double mapMinWidth; - private double mapMinHeight; + private double mapVirtualMinWidth; + private double mapVirtualMinHeight; private double mapWidth; private double mapHeight; private Point originPoint = new(0, 0); private Vector originOffset = new(0, 0); private Point initialClickPoint = new(0, 0); private DebounceResponse? cachedDebounceResponse; - private List mainPlayerPositionHistory = new(); - + [GenerateDependencyProperty] private PathingData pathingData = new(); [GenerateDependencyProperty] @@ -81,7 +85,6 @@ public partial class GuildwarsMinimap : UserControl else if (e.Property == ZoomProperty) { this.UpdateGameData(); - this.DrawMap(); } else if (e.Property == GameDataProperty && this.GameData.Valid) @@ -100,8 +103,8 @@ public partial class GuildwarsMinimap : UserControl var debounceResponse = this.guildwarsEntityDebouncer.DebounceEntities(this.GameData); if (!double.IsFinite(this.mapWidth) || !double.IsFinite(this.mapHeight) || - !double.IsFinite(this.mapMinWidth) || - !double.IsFinite(this.mapMinHeight)) + !double.IsFinite(this.mapVirtualMinWidth) || + !double.IsFinite(this.mapVirtualMinHeight)) { return; } @@ -113,12 +116,14 @@ public partial class GuildwarsMinimap : UserControl position.X - (screenVirtualWidth / 2) - (this.originOffset.X / this.Zoom), position.Y + (screenVirtualHeight / 2) + (this.originOffset.Y / this.Zoom)); - var adjustedPosition = new Point((int)((position.X - this.mapMinWidth / this.Zoom) * this.Zoom), (int)(this.mapHeight / this.Zoom - position.Y + this.mapMinHeight / this.Zoom) * this.Zoom); + var adjustedPosition = new Point((int)((position.X - this.mapVirtualMinWidth) * this.Zoom), (int)(this.mapHeight - position.Y + this.mapVirtualMinHeight) * this.Zoom); this.MapDrawingHost.Margin = new Thickness( - (-adjustedPosition.X + this.ActualWidth / 2) + this.originOffset.X, - (-adjustedPosition.Y + this.ActualHeight / 2) + this.originOffset.Y, + -adjustedPosition.X + (this.ActualWidth / 2) + this.originOffset.X, + -adjustedPosition.Y + (this.ActualHeight / 2) + this.originOffset.Y, 0, 0); + this.MapDrawingHost.Height = this.mapHeight * this.Zoom; + this.MapDrawingHost.Width = this.mapWidth * this.Zoom; this.ManageMainPlayerPositionHistory(); this.DrawEntities(debounceResponse); this.cachedDebounceResponse = debounceResponse; @@ -132,7 +137,7 @@ public partial class GuildwarsMinimap : UserControl } var currentPosition = this.cachedDebounceResponse.MainPlayer.Position ?? throw new InvalidOperationException("Unexpected main player null position"); - if (this.mainPlayerPositionHistory.Any(oldPosition => this.PositionsCollide(oldPosition, currentPosition))) + if (this.mainPlayerPositionHistory.Any(oldPosition => PositionsCollide(oldPosition, currentPosition))) { return; } @@ -186,10 +191,10 @@ public partial class GuildwarsMinimap : UserControl var width = maxWidth - minWidth; var height = maxHeight - minHeight; - this.mapMinHeight = minHeight * this.Zoom; - this.mapMinWidth = minWidth * this.Zoom; - this.mapWidth = width * this.Zoom; - this.mapHeight = height * this.Zoom; + this.mapVirtualMinHeight = minHeight; + this.mapVirtualMinWidth = minWidth; + this.mapWidth = width; + this.mapHeight = height; if (width <= 0 || height <= 0 || !double.IsFinite(width) || @@ -198,20 +203,20 @@ public partial class GuildwarsMinimap : UserControl return; } - var bitmap = BitmapFactory.New((int)(width * this.Zoom), (int)(height * this.Zoom)); + var bitmap = BitmapFactory.New((int)(width / MapDownscaleFactor), (int)(height / MapDownscaleFactor)); this.MapDrawingHost.Source = bitmap; - this.MapDrawingHost.Width = width * this.Zoom; - this.MapDrawingHost.Height = height * this.Zoom; + this.MapDrawingHost.Width = width / MapDownscaleFactor; + this.MapDrawingHost.Height = height / MapDownscaleFactor; using var bitmapContext = bitmap.GetBitmapContext(); bitmap.Clear(Colors.Transparent); foreach (var trapezoid in this.PathingData.Trapezoids!) { - var a = new Point((int)((trapezoid.XTL - minWidth) * this.Zoom), (int)((height - trapezoid.YT + minHeight) * this.Zoom)); - var b = new Point((int)((trapezoid.XTR - minWidth) * this.Zoom), (int)((height - trapezoid.YT + minHeight) * this.Zoom)); - var c = new Point((int)((trapezoid.XBR - minWidth) * this.Zoom), (int)((height - trapezoid.YB + minHeight) * this.Zoom)); - var d = new Point((int)((trapezoid.XBL - minWidth) * this.Zoom), (int)((height - trapezoid.YB + minHeight) * this.Zoom)); - var e = new Point((int)((trapezoid.XTL - minWidth) * this.Zoom), (int)((height - trapezoid.YT + minHeight) * this.Zoom)); + var a = new Point((int)((trapezoid.XTL - minWidth) / MapDownscaleFactor), (int)((height - trapezoid.YT + minHeight) / MapDownscaleFactor)); + var b = new Point((int)((trapezoid.XTR - minWidth) / MapDownscaleFactor), (int)((height - trapezoid.YT + minHeight) / MapDownscaleFactor)); + var c = new Point((int)((trapezoid.XBR - minWidth) / MapDownscaleFactor), (int)((height - trapezoid.YB + minHeight) / MapDownscaleFactor)); + var d = new Point((int)((trapezoid.XBL - minWidth) / MapDownscaleFactor), (int)((height - trapezoid.YB + minHeight) / MapDownscaleFactor)); + var e = new Point((int)((trapezoid.XTL - minWidth) / MapDownscaleFactor), (int)((height - trapezoid.YT + minHeight) / MapDownscaleFactor)); bitmap.FillPolygon(new int[] { (int)a.X, (int)a.Y, (int)b.X, (int)b.Y, (int)c.X, (int)c.Y, (int)d.X, (int)d.Y, (int)e.X, (int)e.Y, (int)a.X, (int)a.Y }, Colors.White); } @@ -233,17 +238,17 @@ public partial class GuildwarsMinimap : UserControl this.FillEllipse(debounceResponse.MainPlayer.Position, bitmap, Colors.Green); - foreach (var partyMember in debounceResponse.Party) + foreach (var partyMember in debounceResponse.Party.Where(p => IsValidEntity(p))) { this.FillEllipse(partyMember.Position, bitmap, Colors.Green); } - foreach (var player in debounceResponse.WorldPlayers) + foreach (var player in debounceResponse.WorldPlayers.Where(p => IsValidEntity(p))) { this.FillEllipse(player.Position, bitmap, Colors.CornflowerBlue); } - foreach (var livingEntity in debounceResponse.LivingEntities) + foreach (var livingEntity in debounceResponse.LivingEntities.Where(p => IsValidEntity(p))) { if (livingEntity.State is LivingEntityState.ToBeCleanedUp) { @@ -263,7 +268,7 @@ public partial class GuildwarsMinimap : UserControl } else if (livingEntity.Allegiance is LivingEntityAllegiance.Neutral) { - this.FillEllipse(livingEntity.Position, bitmap, Colors.Gray); + this.FillEllipse(livingEntity.Position, bitmap, Colors.LightSteelBlue); } else if (livingEntity.Allegiance is LivingEntityAllegiance.Enemy) { @@ -320,8 +325,8 @@ public partial class GuildwarsMinimap : UserControl bitmap.FillEllipseCentered( x, y, - (int)(100 * this.Zoom), - (int)(100 * this.Zoom), + (int)(EntitySize * this.Zoom), + (int)(EntitySize * this.Zoom), color); } @@ -341,12 +346,12 @@ public partial class GuildwarsMinimap : UserControl } bitmap.FillTriangle( - (int)((position.Value.X - this.originPoint.X - 100) * this.Zoom), - 0 - (int)((position.Value.Y - this.originPoint.Y + 100) * this.Zoom), + (int)((position.Value.X - this.originPoint.X - EntitySize) * this.Zoom), + 0 - (int)((position.Value.Y - this.originPoint.Y + EntitySize) * this.Zoom), (int)((position.Value.X - this.originPoint.X) * this.Zoom), - 0 - (int)((position.Value.Y - this.originPoint.Y - 100) * this.Zoom), - (int)((position.Value.X - this.originPoint.X + 100) * this.Zoom), - 0 - (int)((position.Value.Y - this.originPoint.Y + 100) * this.Zoom), + 0 - (int)((position.Value.Y - this.originPoint.Y - EntitySize) * this.Zoom), + (int)((position.Value.X - this.originPoint.X + EntitySize) * this.Zoom), + 0 - (int)((position.Value.Y - this.originPoint.Y + EntitySize) * this.Zoom), color); } @@ -355,15 +360,7 @@ public partial class GuildwarsMinimap : UserControl var x = (int)((entity.Position!.Value.X - this.originPoint.X) * this.Zoom); var y = 0 - (int)((entity.Position!.Value.Y - this.originPoint.Y) * this.Zoom); - return Math.Pow(mousePosition.X - x, 2) + Math.Pow(mousePosition.Y - y, 2) < Math.Pow(100 * this.Zoom, 2); - } - - private bool PositionsCollide(Position position1, Position position2) - { - var a = PositionRadius + PositionRadius; - var dx = position1.X - position2.X; - var dy = position1.Y - position2.Y; - return a * a > ((dx * dx) + (dy * dy)); + return Math.Pow(mousePosition.X - x, 2) + Math.Pow(mousePosition.Y - y, 2) < Math.Pow(EntitySize * this.Zoom, 2); } private void DragMinimap() @@ -414,6 +411,15 @@ public partial class GuildwarsMinimap : UserControl private void GuildwarsMinimap_MouseRightButtonDown(object sender, MouseButtonEventArgs e) { + if (this.CheckMouseOverEntity(Enumerable.Repeat(this.GameData.MainPlayer.As(), 1)) is MainPlayerInformation && + this.TryFindResource("MainPlayerContextMenu") is ContextMenu mainPlayerContextMenu) + { + this.ContextMenu = mainPlayerContextMenu; + this.ContextMenu.DataContext = this.GameData.MainPlayer; + this.ContextMenu.IsOpen = true; + return; + } + var maybeWorldPlayer = this.CheckMouseOverEntity(this.GameData.WorldPlayers!.OfType()); if (maybeWorldPlayer is WorldPlayerInformation worldPlayerInformation && this.TryFindResource("WorldPlayerContextMenu") is ContextMenu worldPlayerContextMenu) @@ -424,6 +430,16 @@ public partial class GuildwarsMinimap : UserControl return; } + var maybeLivingEntity = this.CheckMouseOverEntity(this.GameData.LivingEntities!.OfType()); + if (maybeLivingEntity is LivingEntity livingEntity && + this.TryFindResource("LivingEntityContextMenu") is ContextMenu livingEntityContextMenu) + { + this.ContextMenu = livingEntityContextMenu; + this.ContextMenu.DataContext = livingEntity; + this.ContextMenu.IsOpen = true; + return; + } + this.ContextMenu = default; } @@ -439,7 +455,20 @@ public partial class GuildwarsMinimap : UserControl } this.DragMinimap(); - this.CheckMouseOverEntity(this.GameData.WorldPlayers!.OfType()); + if (this.CheckMouseOverEntity(this.GameData.WorldPlayers!.OfType()) is not null) + { + return; + } + + if (this.CheckMouseOverEntity(Enumerable.Repeat(this.GameData.MainPlayer.As(), 1)) is not null) + { + return; + } + + if (this.CheckMouseOverEntity(this.GameData.LivingEntities!.OfType()) is not null) + { + return; + } } private void GuildwarsMinimap_MouseWheel(object sender, MouseWheelEventArgs e) @@ -456,4 +485,23 @@ public partial class GuildwarsMinimap : UserControl mouseButtonEventArgs.Handled = true; } } + + private static bool PositionsCollide(Position position1, Position position2) + { + var a = PositionRadius + PositionRadius; + var dx = position1.X - position2.X; + var dy = position1.Y - position2.Y; + return a * a > ((dx * dx) + (dy * dy)); + } + + private static bool IsValidEntity(IEntity entity) + { + if (entity.Position?.X == 0 && + entity.Position?.Y == 0) + { + return false; + } + + return true; + } } diff --git a/Daybreak/Controls/LivingEntityContextMenu.xaml b/Daybreak/Controls/LivingEntityContextMenu.xaml new file mode 100644 index 00000000..82daa8a0 --- /dev/null +++ b/Daybreak/Controls/LivingEntityContextMenu.xaml @@ -0,0 +1,19 @@ + + + + + + + + + diff --git a/Daybreak/Controls/LivingEntityContextMenu.xaml.cs b/Daybreak/Controls/LivingEntityContextMenu.xaml.cs new file mode 100644 index 00000000..46999bc9 --- /dev/null +++ b/Daybreak/Controls/LivingEntityContextMenu.xaml.cs @@ -0,0 +1,13 @@ +using System.Windows.Controls; + +namespace Daybreak.Controls; +/// +/// Interaction logic for LivingEntityContextMenu.xaml +/// +public partial class LivingEntityContextMenu : UserControl +{ + public LivingEntityContextMenu() + { + this.InitializeComponent(); + } +} diff --git a/Daybreak/Controls/MainPlayerContextMenu.xaml b/Daybreak/Controls/MainPlayerContextMenu.xaml new file mode 100644 index 00000000..ba1e71ff --- /dev/null +++ b/Daybreak/Controls/MainPlayerContextMenu.xaml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + diff --git a/Daybreak/Controls/MainPlayerContextMenu.xaml.cs b/Daybreak/Controls/MainPlayerContextMenu.xaml.cs new file mode 100644 index 00000000..73c5744a --- /dev/null +++ b/Daybreak/Controls/MainPlayerContextMenu.xaml.cs @@ -0,0 +1,14 @@ +using System.Windows.Controls; + +namespace Daybreak.Controls; + +/// +/// Interaction logic for MainPlayerContextMenu.xaml +/// +public partial class MainPlayerContextMenu : UserControl +{ + public MainPlayerContextMenu() + { + this.InitializeComponent(); + } +} diff --git a/Daybreak/Controls/WorldPlayerContextMenu.xaml.cs b/Daybreak/Controls/WorldPlayerContextMenu.xaml.cs index ca4d8b96..b191de77 100644 --- a/Daybreak/Controls/WorldPlayerContextMenu.xaml.cs +++ b/Daybreak/Controls/WorldPlayerContextMenu.xaml.cs @@ -1,15 +1,14 @@ using System.Windows.Controls; -namespace Daybreak.Controls +namespace Daybreak.Controls; + +/// +/// Interaction logic for WorldPlayerContextMenu.xaml +/// +public partial class WorldPlayerContextMenu : UserControl { - /// - /// Interaction logic for WorldPlayerContextMenu.xaml - /// - public partial class WorldPlayerContextMenu : UserControl + public WorldPlayerContextMenu() { - public WorldPlayerContextMenu() - { - this.InitializeComponent(); - } + this.InitializeComponent(); } } diff --git a/Daybreak/Daybreak.csproj b/Daybreak/Daybreak.csproj index 7ac4a4de..24b7c20a 100644 --- a/Daybreak/Daybreak.csproj +++ b/Daybreak/Daybreak.csproj @@ -13,7 +13,7 @@ preview Daybreak.ico true - 0.9.8.21 + 0.9.8.22 true cfb2a489-db80-448d-a969-80270f314c46 True diff --git a/Daybreak/Launch/MainWindow.xaml.cs b/Daybreak/Launch/MainWindow.xaml.cs index 3a821bf0..cf10c7c1 100644 --- a/Daybreak/Launch/MainWindow.xaml.cs +++ b/Daybreak/Launch/MainWindow.xaml.cs @@ -320,6 +320,6 @@ public partial class MainWindow : Window double R = color.ScR; double G = color.ScG; double B = color.ScB; - return 0.299 * R + 0.587 * G + 0.114 * B; + return (0.299 * R) + (0.587 * G) + (0.114 * B); } } diff --git a/Daybreak/Models/Interop/PathingTrapezoid.cs b/Daybreak/Models/Interop/PathingTrapezoid.cs index 6500c2b2..01ac03cc 100644 --- a/Daybreak/Models/Interop/PathingTrapezoid.cs +++ b/Daybreak/Models/Interop/PathingTrapezoid.cs @@ -10,6 +10,7 @@ public readonly struct PathingTrapezoid [MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x4)] public readonly int[] AdjacentPathingTrapezoids; + [System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "Used for proper padding")] private readonly uint H0014; public readonly float XTL; diff --git a/Daybreak/Models/Interop/ProfessionsContext.cs b/Daybreak/Models/Interop/ProfessionsContext.cs index da748d70..c042e417 100644 --- a/Daybreak/Models/Interop/ProfessionsContext.cs +++ b/Daybreak/Models/Interop/ProfessionsContext.cs @@ -18,6 +18,6 @@ public readonly struct ProfessionsContext public bool ProfessionUnlocked(int professionId) { - return (this.UnlockedProfessionsFlags & 1U << professionId) != 0; + return (this.UnlockedProfessionsFlags & (1U << professionId)) != 0; } } diff --git a/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs b/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs index e93567cc..f8c01cbb 100644 --- a/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs +++ b/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs @@ -147,12 +147,7 @@ public class ApplicationLauncher : IApplicationLauncher private async Task LaunchGuildwarsProcess(string email, Models.SecureString password, string character) { - var executable = this.liveOptions.Value.GuildwarsPaths.Where(path => path.Default).FirstOrDefault(); - if (executable is null) - { - throw new ExecutableNotFoundException($"No executable selected"); - } - + var executable = this.liveOptions.Value.GuildwarsPaths.Where(path => path.Default).FirstOrDefault() ?? throw new ExecutableNotFoundException($"No executable selected"); if (File.Exists(executable.Path) is false) { throw new ExecutableNotFoundException($"Guildwars executable doesn't exist at {executable}"); @@ -255,12 +250,7 @@ public class ApplicationLauncher : IApplicationLauncher private void SetRegistryGuildwarsPath() { - var path = this.liveOptions.Value.GuildwarsPaths.Where(path => path.Default).FirstOrDefault(); - if (path is null) - { - throw new ExecutableNotFoundException("No executable currently selected"); - } - + var path = this.liveOptions.Value.GuildwarsPaths.Where(path => path.Default).FirstOrDefault() ?? throw new ExecutableNotFoundException("No executable currently selected"); var gamePath = path.Path; try { diff --git a/Daybreak/Services/Experience/ExperienceCalculator.cs b/Daybreak/Services/Experience/ExperienceCalculator.cs index b92d372d..6e6b6f0f 100644 --- a/Daybreak/Services/Experience/ExperienceCalculator.cs +++ b/Daybreak/Services/Experience/ExperienceCalculator.cs @@ -57,7 +57,7 @@ public sealed class ExperienceCalculator : IExperienceCalculator else { var experienceOverThreshold = currentTotalExperience - ExperienceCalculationThreshold; - var currentExperience = (experienceOverThreshold % MaxExperienceRequirement); + var currentExperience = experienceOverThreshold % MaxExperienceRequirement; return currentExperience; } } diff --git a/Daybreak/Services/Monitoring/ProcessorUsageMonitor.cs b/Daybreak/Services/Monitoring/ProcessorUsageMonitor.cs index 5379ae05..a1f8dfcb 100644 --- a/Daybreak/Services/Monitoring/ProcessorUsageMonitor.cs +++ b/Daybreak/Services/Monitoring/ProcessorUsageMonitor.cs @@ -43,7 +43,7 @@ namespace Daybreak.Services.Monitoring var endCpuUsage = this.currentProcess.TotalProcessorTime; var elapsedTicks = stopwatch.ElapsedTicks; - var usage = ((double)(endCpuUsage - startCpuUsage).Ticks / (double)elapsedTicks) / this.processorCount * 100d; + var usage = (double)(endCpuUsage - startCpuUsage).Ticks / (double)elapsedTicks / this.processorCount * 100d; this.processorTimeHistogram.Record(usage); _ = Task.Run(this.PeriodicallyCheckCPU); diff --git a/Daybreak/Services/Mutex/MutexHandler.cs b/Daybreak/Services/Mutex/MutexHandler.cs index ff432936..95d1f6f5 100644 --- a/Daybreak/Services/Mutex/MutexHandler.cs +++ b/Daybreak/Services/Mutex/MutexHandler.cs @@ -20,7 +20,7 @@ public sealed class MutexHandler : IMutexHandler NativeMethods.SystemHandleInformation currentHandleInfo; for (int i = 0; i < Marshal.ReadInt32(systemHandle); i++) { - var currentOffset = IntPtr.Size + i * Marshal.SizeOf(typeof(NativeMethods.SystemHandleInformation)); + var currentOffset = IntPtr.Size + (i * Marshal.SizeOf(typeof(NativeMethods.SystemHandleInformation))); currentHandleInfo = (NativeMethods.SystemHandleInformation)Marshal.PtrToStructure(new IntPtr(basePointer + currentOffset), typeof(NativeMethods.SystemHandleInformation))!; if (currentHandleInfo.OwnerPID == (uint)targetProcess.Id) { diff --git a/Daybreak/Utils/EncryptionHelper.cs b/Daybreak/Utils/EncryptionHelper.cs index 6eb2b9c8..9ff532d1 100644 --- a/Daybreak/Utils/EncryptionHelper.cs +++ b/Daybreak/Utils/EncryptionHelper.cs @@ -51,7 +51,7 @@ internal static class EncryptionHelper { var saltBytes = new byte[Aes.BlockSize / 8]; var ivBytes = new byte[Aes.BlockSize / 8]; - var cipherBytes = new byte[bytes.Length - Aes.BlockSize / 4]; + var cipherBytes = new byte[bytes.Length - (Aes.BlockSize / 4)]; using var encryptedStream = new MemoryStream(bytes); encryptedStream.Read(saltBytes, 0, saltBytes.Length);