From 014c17b24531f50d74e5ec8575f14e8ff85bd3df Mon Sep 17 00:00:00 2001 From: Dixie J Date: Sat, 26 Feb 2022 22:29:37 +0800 Subject: [PATCH] PATCH v3.0.3 (Null handling fix) --- ValorantCC/ValorantCC.csproj | 2 +- ValorantCC/src/Binder.cs | 51 ++++++++++++++---------------- ValorantCC/src/Crosshair_Parser.cs | 20 ++++++++++-- ValorantCC/src/Processor.cs | 7 ++-- 4 files changed, 46 insertions(+), 34 deletions(-) diff --git a/ValorantCC/ValorantCC.csproj b/ValorantCC/ValorantCC.csproj index 20b3b11..cd90da5 100644 --- a/ValorantCC/ValorantCC.csproj +++ b/ValorantCC/ValorantCC.csproj @@ -14,7 +14,7 @@ false - 3.0.2 + 3.0.3 false diff --git a/ValorantCC/src/Binder.cs b/ValorantCC/src/Binder.cs index e54f087..ca10b15 100644 --- a/ValorantCC/src/Binder.cs +++ b/ValorantCC/src/Binder.cs @@ -52,38 +52,33 @@ public partial class CrosshairProfile public partial class ProfileSettings { - public CrosshairColor Color { get; set; } - public bool bHasOutline { get; set; } - public float OutlineThickness { get; set; } - public CrosshairColor OutlineColor { get; set; } - public float OutlineOpacity { get; set; } - public float CenterDotSize { get; set; } - public float CenterDotOpacity { get; set; } - public bool bDisplayCenterDot { get; set; } - public bool bFixMinErrorAcrossWeapons { get; set; } - public LineSettings InnerLines { get; set; } - public LineSettings OuterLines { get; set; } + public CrosshairColor Color { get; set; } = new CrosshairColor(); + public bool bHasOutline { get; set; } = false; + public float OutlineThickness { get; set; } = 1; + public CrosshairColor OutlineColor { get; set; } = new CrosshairColor(); + public float OutlineOpacity { get; set; } = 0; + public float CenterDotSize { get; set; } = 1; + public float CenterDotOpacity { get; set; } = 0; + public bool bDisplayCenterDot { get; set; } = false; + public bool bFixMinErrorAcrossWeapons { get; set; } = false; + public LineSettings InnerLines { get; set; } = new LineSettings(); + public LineSettings OuterLines { get; set; } = new LineSettings(); } public partial class SniperSettings { - public CrosshairColor CenterDotColor { get; set; } - public float CenterDotSize { get; set; } - public float CenterDotOpacity { get; set; } - public bool bDisplayCenterDot { get; set; } + public CrosshairColor CenterDotColor { get; set; } = new CrosshairColor(); + public float CenterDotSize { get; set; } = 0; + public float CenterDotOpacity { get; set; } = 0; + public bool bDisplayCenterDot { get; set; } = false; } - public partial class CrosshairColor : ICloneable + public partial class CrosshairColor { - public byte R { get; set; } - public byte G { get; set; } - public byte B { get; set; } - public byte A { get; set; } - - public object Clone() - { - throw new NotImplementedException(); - } + public byte R { get; set; } = 0; + public byte G { get; set; } = 0; + public byte B { get; set; } = 0; + public byte A { get; set; } = 0; } public partial class LineSettings @@ -91,9 +86,9 @@ public partial class LineSettings public float LineThickness { get; set; } = 2; public float LineLength { get; set; } = 4; public float LineOffset { get; set; } = 2; - public bool bShowMovementError { get; set; } - public bool bShowShootingError { get; set; } - public bool bShowMinError { get; set; } + public bool bShowMovementError { get; set; } = false; + public bool bShowShootingError { get; set; } = false; + public bool bShowMinError { get; set; } = false; public float Opacity { get; set; } = 1; public bool bShowLines { get; set; } = true; public float firingErrorScale { get; set; } diff --git a/ValorantCC/src/Crosshair_Parser.cs b/ValorantCC/src/Crosshair_Parser.cs index 459d466..b9c7bd6 100644 --- a/ValorantCC/src/Crosshair_Parser.cs +++ b/ValorantCC/src/Crosshair_Parser.cs @@ -14,9 +14,10 @@ public enum Position West = 2, East = 3, } - + static CrosshairColor defaultColor = new CrosshairColor(); public static void Generate(int column, Grid grid, ProfileSettings settings) { + settings = settings ?? new ProfileSettings(); Rectangle[] rectangles = new Rectangle[16]; int recindex = 0; for (int i = 0; i < rectangles.Length; i++) @@ -56,6 +57,8 @@ public static void Generate(int column, Grid grid, ProfileSettings settings) recindex++; rectangle_redraw(rectangles[i], rectangles[i + 1], pos, settings); + settings.Color = settings.Color ?? defaultColor; + settings.OutlineColor = settings.OutlineColor ?? defaultColor; rectangles[i].Fill = new SolidColorBrush(Color.FromArgb(settings.Color.A, settings.Color.R, settings.Color.G, settings.Color.B)); rectangles[i + 1].Stroke = new SolidColorBrush(Color.FromArgb(settings.OutlineColor.A, settings.OutlineColor.R, settings.OutlineColor.G, settings.OutlineColor.B)); Grid.SetColumn(rectangles[i], column); @@ -77,6 +80,8 @@ public static void Generate(int column, Grid grid, ProfileSettings settings) }; dot_redraw(dot, dotOT, settings); + settings.Color = settings.Color ?? defaultColor; + settings.OutlineColor = settings.OutlineColor ?? defaultColor; dot.Fill = new SolidColorBrush(Color.FromArgb(settings.Color.A, settings.Color.R, settings.Color.G, settings.Color.B)); dotOT.Stroke = new SolidColorBrush(Color.FromArgb(settings.OutlineColor.A, settings.OutlineColor.R, settings.OutlineColor.G, settings.OutlineColor.B)); Grid.SetColumn(dot, column); @@ -92,6 +97,8 @@ public static void Generate(int column, Grid grid, SniperSettings settings) { Ellipse ellipse = new(); dot_redraw(ellipse, settings); + settings = settings ?? new SniperSettings(); + settings.CenterDotColor = settings.CenterDotColor ?? defaultColor; ellipse.Fill = new SolidColorBrush(Color.FromArgb(settings.CenterDotColor.A, settings.CenterDotColor.R, settings.CenterDotColor.G, settings.CenterDotColor.B)); Grid.SetColumn(ellipse, column); Grid.SetRow(ellipse, 0); @@ -121,6 +128,7 @@ public static void dot_redraw(Rectangle Rect, Rectangle RectOT, ProfileSettings public static void dot_redraw(Ellipse ellipse, SniperSettings settings) { + settings = settings ?? new SniperSettings(); ellipse.Width = ellipse.Height = settings.CenterDotSize * 6; ellipse.Opacity = settings.CenterDotOpacity; @@ -137,10 +145,16 @@ public static void rectangle_redraw(Rectangle Rect, Rectangle RectOT, Position p Width = Rect.Width; Height = Rect.Height; + settings = settings ?? new ProfileSettings(); LineSettings line = settings.InnerLines; if (Rect.Name.Contains("OL")) line = settings.OuterLines; + line = line ?? new LineSettings() + { + bShowLines = false, + Opacity = 0 + }; if (line.bShowShootingError) Margin += 8; @@ -180,12 +194,12 @@ public static void rectangle_redraw(Rectangle Rect, Rectangle RectOT, Position p RectOT.Opacity = settings.OutlineOpacity; - if (line.bShowLines) + if (line.bShowLines || line.Opacity > 0) Rect.Visibility = Visibility.Visible; else Rect.Visibility = Visibility.Hidden; - if (settings.bHasOutline && line.LineThickness > 0 && line.bShowLines) + if (settings.bHasOutline && line.LineThickness > 0 && line.bShowLines && line.Opacity > 0) RectOT.Visibility = Visibility.Visible; else RectOT.Visibility = Visibility.Hidden; diff --git a/ValorantCC/src/Processor.cs b/ValorantCC/src/Processor.cs index b858b24..8ab6458 100644 --- a/ValorantCC/src/Processor.cs +++ b/ValorantCC/src/Processor.cs @@ -165,18 +165,20 @@ private async Task putUserSettings(Data newData) return false; } + private ProfileList FetchProfiles(string SettingValue, string? PrimOutlineColor, string? ADSColorValue, string? ADSOutlineColor, string? SniperCenterdotColor) { string DefaultUserSettings = JsonConvert.SerializeObject(UserSettings); Utilities.Utils.Log("Fetching/Creating Profile/s"); Utilities.Utils.Log($"Setting Value: {DefaultUserSettings}"); if (ProfileListed) return JsonConvert.DeserializeObject(SettingValue); - CrosshairColor PrimaryColor = Utilities.Utils.parseCrosshairColor(SettingValue); +#nullable enable CrosshairColor PrimaryOutlineColor = Utilities.Utils.parseCrosshairColor(PrimOutlineColor); CrosshairColor ADSColor = Utilities.Utils.parseCrosshairColor(ADSColorValue); CrosshairColor aDSOutlineColor = Utilities.Utils.parseCrosshairColor(ADSOutlineColor); - CrosshairColor sniperCenterdotColor = Utilities.Utils.parseCrosshairColor(SniperCenterdotColor); + CrosshairColor sniperCenterdotColor = Utilities.Utils.parseCrosshairColor(SniperCenterdotColor); +#nullable disable string profileName = UserSettings.stringSettings.FirstOrDefault(setting => setting.settingEnum == "EAresStringSettingName::CrosshairProfileName").value; return new ProfileList @@ -196,6 +198,7 @@ private ProfileList FetchProfiles(string SettingValue, string? PrimOutlineColor, }; } + private List FetchProfileNames(ProfileList ProfileList) { Utilities.Utils.Log("Fetching Profile names");