From d1fc24956297c4a27f77d891e466e6b433dce6e0 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 19 Dec 2023 18:53:07 -0300 Subject: [PATCH] Added MORE missing null checks From #123 --- LemonUI/Menus/NativeMenu.cs | 17 ++++++++++--- LemonUI/Scaleform/BigMessage.cs | 21 +++++++++++++--- LemonUI/Scaleform/BruteForce.cs | 4 +++ LemonUI/Scaleform/Celebration.cs | 24 +++++++++++++++--- LemonUI/Scaleform/InstructionalButton.cs | 17 ++++++++----- LemonUI/Scaleform/LoadingScreen.cs | 24 +++++++++++++++--- LemonUI/Scaleform/PopUp.cs | 31 +++++++++++++++++++++--- LemonUI/TimerBars/TimerBar.cs | 5 ++-- 8 files changed, 119 insertions(+), 24 deletions(-) diff --git a/LemonUI/Menus/NativeMenu.cs b/LemonUI/Menus/NativeMenu.cs index c8ccae19..9b8a8a8a 100644 --- a/LemonUI/Menus/NativeMenu.cs +++ b/LemonUI/Menus/NativeMenu.cs @@ -230,6 +230,8 @@ public class NativeMenu : IContainer, IEnumerable /// private long heldSince = -1; private HeaderBehavior nameBehavior = HeaderBehavior.AlwaysShow; + private string description = string.Empty; + private string noItemsText = "There are no items available"; #endregion @@ -531,12 +533,16 @@ public string Name public string Subtitle { get => Name; - set => Name = value; + set => Name = value ?? throw new ArgumentNullException(nameof(value)); } /// /// The description used when this menu is used as a submenu. /// - public string Description { get; set; } = string.Empty; + public string Description + { + get => description; + set => description = value ?? throw new ArgumentNullException(nameof(value)); + } /// /// If the mouse should be used for navigating the menu. /// @@ -553,10 +559,15 @@ public string Subtitle /// The items that this menu contain. /// public List Items { get; } = new List(); + /// /// Text shown when there are no items in the menu. /// - public string NoItemsText { get; set; } = "There are no items available"; + public string NoItemsText + { + get => noItemsText; + set => noItemsText = value ?? throw new ArgumentNullException(nameof(value)); + } /// /// If the cursor should be reset when the menu is opened. /// diff --git a/LemonUI/Scaleform/BigMessage.cs b/LemonUI/Scaleform/BigMessage.cs index 6d7ba1eb..4258b32b 100644 --- a/LemonUI/Scaleform/BigMessage.cs +++ b/LemonUI/Scaleform/BigMessage.cs @@ -29,6 +29,9 @@ public class BigMessage : BaseScaleform private MessageType type; private uint weaponHash; private long hideAfter; + private string title; + private string message; + private string rank; #endregion @@ -37,11 +40,19 @@ public class BigMessage : BaseScaleform /// /// The title of the message. /// - public string Title { get; set; } + public string Title + { + get => title; + set => title = value ?? throw new ArgumentNullException(nameof(value)); + } /// /// The subtitle or description of the message. /// - public string Message { get; set; } + public string Message + { + get => message; + set => message = value ?? throw new ArgumentNullException(nameof(value)); + } /// /// The color of the text. /// Only used on the Customizable message type. @@ -54,7 +65,11 @@ public class BigMessage : BaseScaleform /// /// The Rank when the mode is set to Cops and Crooks. /// - public string Rank { get; set; } + public string Rank + { + get => rank; + set => rank = value ?? throw new ArgumentNullException(nameof(value)); + } #if !RAGEMP && !ALTV /// /// The hash of the Weapon as an enum. diff --git a/LemonUI/Scaleform/BruteForce.cs b/LemonUI/Scaleform/BruteForce.cs index e1cbfd24..df26ccb1 100644 --- a/LemonUI/Scaleform/BruteForce.cs +++ b/LemonUI/Scaleform/BruteForce.cs @@ -58,6 +58,10 @@ public string Word get => word; set { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } if (value.Length != 8) { throw new ArgumentOutOfRangeException(nameof(value), "The word needs to be exactly 8 characters long."); diff --git a/LemonUI/Scaleform/Celebration.cs b/LemonUI/Scaleform/Celebration.cs index a426c997..7df5bd3f 100644 --- a/LemonUI/Scaleform/Celebration.cs +++ b/LemonUI/Scaleform/Celebration.cs @@ -25,6 +25,9 @@ public class Celebration : CelebrationCore private long showUntil = 0; private bool cancel = false; + private string mode = string.Empty; + private string job = string.Empty; + private string challenge = string.Empty; #endregion @@ -38,27 +41,42 @@ public class Celebration : CelebrationCore /// The foreground of the scaleform. /// public CelebrationForeground Foreground { get; } = new CelebrationForeground(); + /// /// The mode name shown. /// /// /// This is used to show the current mode, like "HEIST", "RACE", "LAST TEAM STANDING", etc. /// - public string Mode { get; set; } = string.Empty; + public string Mode + { + get => mode; + set => mode = value ?? throw new ArgumentNullException(nameof(value)); + } + /// /// The job name shown. /// /// /// This is used to show the current job name like "The Prison Break" or "Premium Race - East Coast". /// - public string Job { get; set; } = string.Empty; + public string Job + { + get => job; + set => job = value ?? throw new ArgumentNullException(nameof(value)); + } + /// /// The challenge shown. /// /// /// This is used to show messages like "ROUND 10" or "POTENTIAL CUT $1000000". /// - public string Challenge { get; set; } = string.Empty; + public string Challenge + { + get => challenge; + set => challenge = value ?? throw new ArgumentNullException(nameof(value)); + } /// /// For how long the scalefom is show. /// diff --git a/LemonUI/Scaleform/InstructionalButton.cs b/LemonUI/Scaleform/InstructionalButton.cs index 3e021fd0..751b15ae 100644 --- a/LemonUI/Scaleform/InstructionalButton.cs +++ b/LemonUI/Scaleform/InstructionalButton.cs @@ -13,6 +13,7 @@ using GTA; using GTA.Native; #endif +using System; namespace LemonUI.Scaleform { @@ -25,6 +26,7 @@ public struct InstructionalButton private Control control; private string raw; + private string description; #endregion @@ -33,7 +35,11 @@ public struct InstructionalButton /// /// The description of this button. /// - public string Description { get; set; } + public string Description + { + get => description; + set => description = value ?? throw new ArgumentNullException(nameof(value)); + } /// /// The Control used by this button. /// @@ -64,7 +70,7 @@ public string Raw get => raw; set { - raw = value; + raw = value ?? throw new ArgumentNullException(nameof(value)); control = (Control)(-1); } } @@ -80,7 +86,7 @@ public string Raw /// The control to use. public InstructionalButton(string description, Control control) { - Description = description; + this.description = description ?? throw new ArgumentNullException(nameof(description)); this.control = control; #if FIVEM raw = API.GetControlInstructionalButton(2, (int)control, 1); @@ -94,7 +100,6 @@ public InstructionalButton(string description, Control control) raw = Function.Call(Hash.GET_CONTROL_INSTRUCTIONAL_BUTTONS_STRING, 2, (int)control, 1); #endif } - /// /// Creates an instructional button for a raw control. /// @@ -102,9 +107,9 @@ public InstructionalButton(string description, Control control) /// The raw value of the control. public InstructionalButton(string description, string raw) { - Description = description; + this.description = description ?? throw new ArgumentNullException(nameof(description)); control = (Control)(-1); - this.raw = raw; + this.raw = raw ?? throw new ArgumentNullException(nameof(raw)); } #endregion diff --git a/LemonUI/Scaleform/LoadingScreen.cs b/LemonUI/Scaleform/LoadingScreen.cs index a4e25bcc..1e8b8d9d 100644 --- a/LemonUI/Scaleform/LoadingScreen.cs +++ b/LemonUI/Scaleform/LoadingScreen.cs @@ -1,3 +1,5 @@ +using System; + namespace LemonUI.Scaleform { /// @@ -5,20 +7,36 @@ namespace LemonUI.Scaleform /// public class LoadingScreen : BaseScaleform { + private string title; + private string subtitle; + private string description; + #region Properties /// /// The title of the loading screen. /// - public string Title { get; set; } + public string Title + { + get => title; + set => title = value ?? throw new ArgumentNullException(nameof(value)); + } /// /// The subtitle of the loading screen. /// - public string Subtitle { get; set; } + public string Subtitle + { + get => subtitle; + set => subtitle = value ?? throw new ArgumentNullException(nameof(value)); + } /// /// The description of the loading screen. /// - public string Description { get; set; } + public string Description + { + get => description; + set => description = value ?? throw new ArgumentNullException(nameof(value)); + } /// /// The Texture Dictionary (TXD) where the texture is loaded. /// diff --git a/LemonUI/Scaleform/PopUp.cs b/LemonUI/Scaleform/PopUp.cs index d65b4e91..e860b93f 100644 --- a/LemonUI/Scaleform/PopUp.cs +++ b/LemonUI/Scaleform/PopUp.cs @@ -1,3 +1,5 @@ +using System; + namespace LemonUI.Scaleform { /// @@ -5,20 +7,37 @@ namespace LemonUI.Scaleform /// public class PopUp : BaseScaleform { + private string title; + private string subtitle; + private string prompt; + private string error; + #region Properties /// /// The title of the Pop-up. /// - public string Title { get; set; } + public string Title + { + get => title; + set => title = value ?? throw new ArgumentNullException(nameof(value)); + } /// /// The subtitle of the Pop-up. /// - public string Subtitle { get; set; } + public string Subtitle + { + get => subtitle; + set => subtitle = value ?? throw new ArgumentNullException(nameof(value)); + } /// /// The prompt of the Pop-up. /// - public string Prompt { get; set; } + public string Prompt + { + get => prompt; + set => prompt = value ?? throw new ArgumentNullException(nameof(value)); + } /// /// If the black background should be shown. /// @@ -26,7 +45,11 @@ public class PopUp : BaseScaleform /// /// The error message to show. /// - public string Error { get; set; } + public string Error + { + get => error; + set => error = value ?? throw new ArgumentNullException(nameof(value)); + } #endregion diff --git a/LemonUI/TimerBars/TimerBar.cs b/LemonUI/TimerBars/TimerBar.cs index 16a19d6d..abcc77f3 100644 --- a/LemonUI/TimerBars/TimerBar.cs +++ b/LemonUI/TimerBars/TimerBar.cs @@ -5,6 +5,7 @@ #elif SHVDN3 || SHVDNC using GTA.UI; #endif +using System; using LemonUI.Elements; using System.Drawing; @@ -69,7 +70,7 @@ public string Title get => rawTitle; set { - rawTitle = value; + rawTitle = value ?? throw new ArgumentNullException(nameof(value)); title.Text = value.ToUpperInvariant(); } } @@ -81,7 +82,7 @@ public string Info get => rawInfo; set { - rawInfo = value; + rawInfo = value ?? throw new ArgumentNullException(nameof(value)); info.Text = value.ToUpperInvariant(); } }