From 955ba9fed6fcd7de291a09695e4eb4fd17d24677 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 27 Dec 2020 16:35:08 -0800 Subject: [PATCH] Enable nullable checks for all subprojects except structures/game --- pkNX.Containers/Container.cs | 8 ++--- .../ContainerHandler/ContainerHandler.cs | 8 ++--- .../FileProgressedEventArgs.cs | 2 +- pkNX.Containers/FakeContainer.cs | 2 +- pkNX.Containers/FileMitm.cs | 6 ++-- pkNX.Containers/FolderContainer.cs | 28 ++++++++-------- pkNX.Containers/GARC/FATBEntry.cs | 13 ++++---- pkNX.Containers/GARC/FATO.cs | 2 +- pkNX.Containers/GARC/GARC.cs | 16 +++++---- pkNX.Containers/IFileContainer.cs | 2 +- pkNX.Containers/LargeContainer.cs | 25 +++++++------- pkNX.Containers/LargeContainerEntry.cs | 2 +- pkNX.Containers/Mini/Mini.cs | 2 +- pkNX.Containers/Mini/MiniUtil.cs | 33 ++++++++++--------- pkNX.Containers/Misc/BinaryRWExtensions.cs | 2 +- pkNX.Containers/Misc/GFPack.cs | 14 ++++---- pkNX.Containers/NX/NSO.cs | 2 ++ pkNX.Containers/NX/NSOHeader.cs | 2 ++ pkNX.Containers/SARC/SARC.cs | 17 ++++++---- pkNX.Containers/SARC/SFATEntry.cs | 4 +-- pkNX.Containers/SingleFileContainer.cs | 11 ++++--- pkNX.Containers/pkNX.Containers.csproj | 1 + .../Randomizers/FormRandomizer.cs | 4 +-- .../Randomizers/LearnsetRandomizer.cs | 9 +++-- .../Randomizers/MoveRandomizer.cs | 2 +- .../Personal/PersonalRandomizer.cs | 11 ++++--- .../Randomizers/SpeciesRandomizer.cs | 7 ++-- .../Randomizers/TrainerRandomizer.cs | 20 ++++++----- pkNX.Randomization/Util.cs | 12 ++++--- pkNX.Randomization/pkNX.Randomization.csproj | 1 + pkNX.Sprites/ImageUtil.cs | 2 -- pkNX.Structures/Evolution/EvolutionSet.cs | 6 +++- pkNX.Structures/Learnset/Learnset.cs | 6 ++++ pkNX.Structures/Scripts/AmxHeader.cs | 1 - pkNX.WinForms/Controls/EncounterList.cs | 4 +-- pkNX.WinForms/Controls/EncounterList8.cs | 4 +-- pkNX.WinForms/Controls/EvolutionRow.cs | 12 ++++--- pkNX.WinForms/Controls/MegaEvoEntry.cs | 7 ++-- pkNX.WinForms/Controls/StatEditor.cs | 10 ++++-- pkNX.WinForms/Main.cs | 2 +- pkNX.WinForms/MainEditor/EditUtil.cs | 4 +-- pkNX.WinForms/MainEditor/EditorProvider.cs | 14 +++++--- pkNX.WinForms/Ripper/FileRipper.cs | 4 +-- pkNX.WinForms/Subforms/BTTE.cs | 21 ++++++------ pkNX.WinForms/Subforms/GGWE.cs | 4 +-- pkNX.WinForms/Subforms/GenericEditor.cs | 2 +- pkNX.WinForms/Subforms/PokeDataUI.cs | 33 +++++++++++-------- pkNX.WinForms/Subforms/SSWE.cs | 4 +-- pkNX.WinForms/Subforms/ShinyRate.cs | 4 +-- pkNX.WinForms/Subforms/TMList.cs | 2 +- pkNX.WinForms/Subforms/TextContainer.cs | 6 ++-- pkNX.WinForms/Subforms/TextEditor.cs | 15 ++++----- pkNX.WinForms/WinFormsUtil.cs | 2 +- pkNX.WinForms/pkNX.WinForms.csproj | 1 + 54 files changed, 251 insertions(+), 187 deletions(-) diff --git a/pkNX.Containers/Container.cs b/pkNX.Containers/Container.cs index c24ee910..559b00f3 100644 --- a/pkNX.Containers/Container.cs +++ b/pkNX.Containers/Container.cs @@ -28,7 +28,7 @@ public static IFileContainer GetContainer(string path, ContainerType t) /// Gets a for the stream. /// /// Path to the binary data - public static IFileContainer GetContainer(string path) + public static IFileContainer? GetContainer(string path) { var fs = new FileStream(path, FileMode.Open); var container = GetContainer(fs); @@ -45,7 +45,7 @@ public static IFileContainer GetContainer(string path) /// Gets a for the stream. /// /// Stream for the binary data - public static IFileContainer GetContainer(Stream stream) + public static IFileContainer? GetContainer(Stream stream) { var br = new BinaryReader(stream); var container = GetContainer(br); @@ -58,9 +58,9 @@ public static IFileContainer GetContainer(Stream stream) /// Gets a for the stream within the . /// /// Reader for the binary data - public static IFileContainer GetContainer(BinaryReader br) + public static IFileContainer? GetContainer(BinaryReader br) { - IFileContainer container; + IFileContainer? container; if ((container = GARC.GetGARC(br)) != null) return container; if ((container = MiniUtil.GetMini(br)) != null) diff --git a/pkNX.Containers/ContainerHandler/ContainerHandler.cs b/pkNX.Containers/ContainerHandler/ContainerHandler.cs index c2069ace..7a69ff3e 100644 --- a/pkNX.Containers/ContainerHandler/ContainerHandler.cs +++ b/pkNX.Containers/ContainerHandler/ContainerHandler.cs @@ -6,8 +6,8 @@ namespace pkNX.Containers { public sealed class ContainerHandler { - public event EventHandler FileCountDetermined; - public event EventHandler FileProgressed; + public event EventHandler? FileCountDetermined; + public event EventHandler? FileProgressed; private int count; @@ -18,11 +18,11 @@ public void Initialize(int total) FileCountDetermined?.Invoke(null, args); } - public void StepFile(int ctr, int total = -1, string fileName = null) + public void StepFile(int ctr, int total = -1, string? fileName = null) { if (total < 0) total = count; - var args = new FileProgressedEventArgs {Current = ctr, Total = total, CurrentFile = fileName}; + var args = new FileProgressedEventArgs {Current = ctr, Total = total, CurrentFile = fileName ?? string.Empty}; FileProgressed?.Invoke(null, args); } } diff --git a/pkNX.Containers/ContainerHandler/FileProgressedEventArgs.cs b/pkNX.Containers/ContainerHandler/FileProgressedEventArgs.cs index 7b49e7bd..2a7a2aba 100644 --- a/pkNX.Containers/ContainerHandler/FileProgressedEventArgs.cs +++ b/pkNX.Containers/ContainerHandler/FileProgressedEventArgs.cs @@ -6,6 +6,6 @@ public class FileProgressedEventArgs : EventArgs { public int Current { get; set; } public int Total { get; set; } - public string CurrentFile { get; set; } + public string? CurrentFile { get; set; } } } \ No newline at end of file diff --git a/pkNX.Containers/FakeContainer.cs b/pkNX.Containers/FakeContainer.cs index bbf3bb74..6d20bf20 100644 --- a/pkNX.Containers/FakeContainer.cs +++ b/pkNX.Containers/FakeContainer.cs @@ -17,7 +17,7 @@ public FakeContainer(byte[][] files) Backup[i] = (byte[])files[i].Clone(); } - public string FilePath { get; set; } = string.Empty; + public string? FilePath { get; set; } = string.Empty; public bool Modified { get; set; } public int Count => Files.Length; diff --git a/pkNX.Containers/FileMitm.cs b/pkNX.Containers/FileMitm.cs index 07703add..dd62a41e 100644 --- a/pkNX.Containers/FileMitm.cs +++ b/pkNX.Containers/FileMitm.cs @@ -12,8 +12,8 @@ public static class FileMitm public static void EnableIfSetup() => Enabled = PathOriginal != null; public static void Disable() => Enabled = false; - private static string PathOriginal; - private static string PathRedirect; + private static string? PathOriginal; + private static string? PathRedirect; public static byte[] ReadAllBytes(string path) { @@ -23,6 +23,8 @@ public static byte[] ReadAllBytes(string path) public static void WriteAllBytes(string path, byte[] data) { + if (string.IsNullOrWhiteSpace(path)) + throw new FileNotFoundException("Invalid filename."); path = GetRedirectedWritePath(path); File.WriteAllBytes(path, data); } diff --git a/pkNX.Containers/FolderContainer.cs b/pkNX.Containers/FolderContainer.cs index 4a45b596..1c969357 100644 --- a/pkNX.Containers/FolderContainer.cs +++ b/pkNX.Containers/FolderContainer.cs @@ -10,16 +10,18 @@ namespace pkNX.Containers public class FolderContainer : IFileContainer { private readonly List Paths = new(); - private readonly List Data = new(); + private readonly List Data = new(); private readonly List TrackModify = new(); + public string? FilePath { get; set; } + public FolderContainer() { } public FolderContainer(IEnumerable files) => AddFiles(files); public FolderContainer(string path) => FilePath = path; public FolderContainer(string path, Func filter) : this(path) => Initialize(filter); - public void Initialize(Func filter = null) + public void Initialize(Func? filter = null) { if (Paths.Count > 0) return; // already initialized @@ -30,7 +32,7 @@ public void Initialize(Func filter = null) AddFiles(files); } - public void AddFile(string file, byte[] data = null) + public void AddFile(string file, byte[]? data = null) { Paths.Add(file); Data.Add(data); @@ -43,7 +45,7 @@ public void AddFiles(IEnumerable files) AddFile(f); } - public byte[] GetFileData(string file) + public byte[]? GetFileData(string file) { var index = Paths.FindIndex(z => Path.GetFileName(z) == file); if (index < 0) @@ -55,8 +57,6 @@ public byte[] GetFileData(string file) public byte[] GetFileData(int index) { - if (index < 0 || (uint)index >= Data.Count) - return null; var data = Data[index] ??= FileMitm.ReadAllBytes(Paths[index]); return (byte[])data.Clone(); } @@ -66,18 +66,20 @@ public byte[] GetFileData(int index) get => GetFileData(index); set { - if (value != null) - { - var current = Data[index] ??= GetFileData(index); - TrackModify[index] = !value.SequenceEqual(current); - } + var current = Data[index] ??= GetFileData(index); + TrackModify[index] = !value.SequenceEqual(current); + Data[index] = value; } } - public string GetFileName(int index) => Paths[index]; + public void ResetIndex(int index) + { + Data[index] = null; + TrackModify[index] = false; + } - public string FilePath { get; set; } + public string GetFileName(int index) => Paths[index]; public bool Modified { diff --git a/pkNX.Containers/GARC/FATBEntry.cs b/pkNX.Containers/GARC/FATBEntry.cs index 906b4888..06068fb9 100644 --- a/pkNX.Containers/GARC/FATBEntry.cs +++ b/pkNX.Containers/GARC/FATBEntry.cs @@ -10,15 +10,14 @@ internal class FATBEntry public readonly bool IsFolder; public readonly FATBSubEntry[] SubEntries; - // ReSharper disable once UnusedMember.Local -- needed to init subentries private FATBEntry() { - SubEntries = new FATBSubEntry[32]; - for (int i = 0; i < SubEntries.Length; i++) - SubEntries[i] = new FATBSubEntry(); + var sub = SubEntries = new FATBSubEntry[32]; + for (int i = 0; i < sub.Length; i++) + sub[i] = new FATBSubEntry(); } - public FATBEntry(string file) + public FATBEntry(string file) : this() { IsFolder = false; Vector = 1; @@ -26,7 +25,7 @@ public FATBEntry(string file) SubEntries[0].File = file; } - public FATBEntry(IEnumerable files) + public FATBEntry(IEnumerable files) : this() { IsFolder = true; Vector = 0; @@ -45,7 +44,7 @@ public FATBEntry(IEnumerable files) } } - public FATBEntry(BinaryReader br, int DataOffset) + public FATBEntry(BinaryReader br, int DataOffset) : this() { Vector = br.ReadUInt32(); diff --git a/pkNX.Containers/GARC/FATO.cs b/pkNX.Containers/GARC/FATO.cs index 4900fdda..9b166b84 100644 --- a/pkNX.Containers/GARC/FATO.cs +++ b/pkNX.Containers/GARC/FATO.cs @@ -8,7 +8,7 @@ internal class FATO private readonly uint Magic = MAGIC; private readonly int HeaderSize = 0xC; - private readonly ushort EntryCount; + public readonly ushort EntryCount; private readonly short Padding = -1; private FATOEntry[] Entries { get; } diff --git a/pkNX.Containers/GARC/GARC.cs b/pkNX.Containers/GARC/GARC.cs index 0f601650..51337736 100644 --- a/pkNX.Containers/GARC/GARC.cs +++ b/pkNX.Containers/GARC/GARC.cs @@ -12,22 +12,26 @@ public class GARC : LargeContainer private FATO FATO; private FATB FATB; +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public GARC(BinaryReader br) => OpenRead(br); public GARC(string file) => OpenBinary(file); +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public GARC(IReadOnlyList files, GARCVersion version = GARCVersion.VER_6) { Header = new GARCHeader(version); FATO = new FATO(files.Count); FATB = new FATB(files); + Files = new byte[]?[files.Count]; } protected override void Initialize() { - Reader.BaseStream.Position = 0; + Reader!.BaseStream.Position = 0; Header = new GARCHeader(Reader); FATO = new FATO(Reader); FATB = new FATB(Reader, Header.DataOffset); + Files = new byte[]?[FATO.EntryCount]; } protected override int GetFileOffset(int file, int subFile = 0) @@ -42,12 +46,12 @@ public override byte[] GetEntry(int index, int subFile) if (f.File is byte[] data) return data; - data = f.GetFileData(Reader.BaseStream); + data = f.GetFileData(Reader!.BaseStream); f.File = data; // cache for future fetches return data; } - public override void SetEntry(int index, byte[] value, int subFile) + public override void SetEntry(int index, byte[]? value, int subFile) { Modified |= value != null && !GetEntry(index, subFile).SequenceEqual(value); var f = FATB[index].SubEntries[subFile]; @@ -94,7 +98,7 @@ private void WriteIntro(BinaryWriter bw, bool lastPass = false) private void WriteEntry(BinaryWriter bw, int i, int DataOffset) { FATO[i].Offset = (uint)bw.BaseStream.Position; - FATB[i].WriteEntries(bw, Reader?.BaseStream, Header.ContentPadToNearest, DataOffset, + FATB[i].WriteEntries(bw, Reader!.BaseStream, Header.ContentPadToNearest, DataOffset, ref Header.ContentLargestUnpadded, ref Header.ContentLargestPadded); } @@ -108,12 +112,12 @@ public override void Dump(string path, ContainerHandler handler) handler.Initialize(Count); for (int i = 0; i < Count; i++) { - FATB[i].Dump(path, i, format, Reader.BaseStream, Header.DataOffset); + FATB[i].Dump(path, i, format, Reader!.BaseStream, Header.DataOffset); handler.StepFile(i+1); } } - public static GARC GetGARC(BinaryReader br) + public static GARC? GetGARC(BinaryReader br) { if (br.BaseStream.Length < 20) return null; diff --git a/pkNX.Containers/IFileContainer.cs b/pkNX.Containers/IFileContainer.cs index 77da7bd6..65ed294c 100644 --- a/pkNX.Containers/IFileContainer.cs +++ b/pkNX.Containers/IFileContainer.cs @@ -12,7 +12,7 @@ public interface IFileContainer /// /// Path the was loaded from. /// - string FilePath { get; set; } + string? FilePath { get; set; } /// /// Indication if the contents of the have been modified. diff --git a/pkNX.Containers/LargeContainer.cs b/pkNX.Containers/LargeContainer.cs index 906e3099..45549c9a 100644 --- a/pkNX.Containers/LargeContainer.cs +++ b/pkNX.Containers/LargeContainer.cs @@ -14,16 +14,16 @@ public abstract class LargeContainer : IDisposable, IFileContainer { public virtual int Count => Files.Length; - public Task GetFiles() => new(() => { CacheAll(); return Files; }); + public Task GetFiles() => new(() => { CacheAll(); return Files!; }); public Task GetFile(int file, int subFile = 0) => new(() => GetEntry(file, subFile)); public Task SetFile(int file, byte[] value, int subFile = 0) => new(() => SetEntry(file, value, subFile)); - public string Extension => Path.GetExtension(FilePath); - public string FileName => Path.GetFileName(FilePath); - public string FilePath { get; set; } + public string? Extension => Path.GetExtension(FilePath); + public string? FileName => Path.GetFileName(FilePath); + public string? FilePath { get; set; } public bool Modified { get; set; } - protected byte[][] Files { get; set; } + protected byte[]?[] Files = Array.Empty(); /// /// Packs the to the specified writing stream. @@ -36,8 +36,8 @@ public abstract class LargeContainer : IDisposable, IFileContainer #region File Reading - protected BinaryReader Reader { get; private set; } - private Stream Stream; + protected BinaryReader? Reader { get; private set; } + private Stream? Stream; protected void OpenBinary(string path) { @@ -60,6 +60,8 @@ protected void OpenRead(BinaryReader br) public BinaryReader Seek(int file, long offset = 0, int subFile = 0) { + if (Reader == null) + throw new NullReferenceException("Reader is not initialized."); offset += GetFileOffset(file, subFile); Reader.BaseStream.Position = offset; return Reader; @@ -67,7 +69,7 @@ public BinaryReader Seek(int file, long offset = 0, int subFile = 0) public abstract byte[] GetEntry(int index, int subFile); - public virtual void SetEntry(int index, byte[] value, int subFile) + public virtual void SetEntry(int index, byte[]? value, int subFile) { Files[index] = value; Modified |= value != null && !this[index].SequenceEqual(value); @@ -92,7 +94,8 @@ public void CacheAll() Files[i] ??= GetCachedValue(i, 0); Reader = null; - Stream.Close(); + Stream?.Close(); + Stream = null; } public void CancelEdits() @@ -143,8 +146,8 @@ public void Dispose() protected virtual void Dispose(bool disposing) { - Stream.Dispose(); - Reader.Dispose(); + Stream?.Dispose(); + Reader?.Dispose(); } } } diff --git a/pkNX.Containers/LargeContainerEntry.cs b/pkNX.Containers/LargeContainerEntry.cs index 30ae6a97..aa9a7624 100644 --- a/pkNX.Containers/LargeContainerEntry.cs +++ b/pkNX.Containers/LargeContainerEntry.cs @@ -7,7 +7,7 @@ public class LargeContainerEntry public int Start { get; set; } public int End { get; set; } public virtual int Length { get; set; } - public object File { get; set; } + public object? File { get; set; } public int ParentDataPosition { get; set; } public byte[] GetFileData(Stream parent) diff --git a/pkNX.Containers/Mini/Mini.cs b/pkNX.Containers/Mini/Mini.cs index 1c2777d2..e8552a7e 100644 --- a/pkNX.Containers/Mini/Mini.cs +++ b/pkNX.Containers/Mini/Mini.cs @@ -29,7 +29,7 @@ public Mini(byte[][] data, string ident) } } - public string FilePath { get; set; } + public string? FilePath { get; set; } private readonly byte[][] Backup; public bool Modified { get; set; } diff --git a/pkNX.Containers/Mini/MiniUtil.cs b/pkNX.Containers/Mini/MiniUtil.cs index 69ab3499..c22cb3f1 100644 --- a/pkNX.Containers/Mini/MiniUtil.cs +++ b/pkNX.Containers/Mini/MiniUtil.cs @@ -30,10 +30,10 @@ public static byte[] PackMini(byte[][] fileData, string identifier) int dataOffset = 4 + 4 + (count * 4); // Start the data filling. - using MemoryStream dataout = new MemoryStream(); - using MemoryStream offsetMap = new MemoryStream(); - using BinaryWriter bd = new BinaryWriter(dataout); - using BinaryWriter bo = new BinaryWriter(offsetMap); + using MemoryStream dataout = new(); + using MemoryStream offsetMap = new(); + using BinaryWriter bd = new(dataout); + using BinaryWriter bo = new(offsetMap); // For each file... for (int i = 0; i < count; i++) { @@ -60,21 +60,21 @@ public static byte[] PackMini(byte[][] fileData, string identifier) return newPack.ToArray(); } - public static byte[][] UnpackMini(string file, string identifier = null) + public static byte[][] UnpackMini(string file, string identifier) { byte[] fileData = FileMitm.ReadAllBytes(file); return UnpackMini(fileData, identifier); } - public static byte[][] UnpackMini(byte[] fileData, string identifier = null) + public static byte[][] UnpackMini(byte[] fileData, string identifier) { - if (fileData == null || fileData.Length < 4) - return null; + if (fileData.Length < 4) + throw new ArgumentOutOfRangeException(nameof(fileData)); - if (identifier?.Length == 2) + if (identifier.Length == 2) { if (identifier[0] != fileData[0] || identifier[1] != fileData[1]) - return null; + throw new FormatException("Prefix does not match."); } int count = BitConverter.ToUInt16(fileData, 2); int ctr = 4; @@ -97,10 +97,13 @@ public static Mini GetMini(string path) path = FileMitm.GetRedirectedReadPath(path); using var fs = new FileStream(path, FileMode.Open, FileAccess.Read); using var br = new BinaryReader(fs); - return GetMini(br); + var result = GetMini(br); + if (result is null) + throw new FormatException($"The file at {path} is not a {nameof(Mini)} file."); + return result; } - public static Mini GetMini(BinaryReader br) + public static Mini? GetMini(BinaryReader br) { var ident = GetIsMini(br); if (string.IsNullOrEmpty(ident)) @@ -115,18 +118,18 @@ public static Mini GetMini(BinaryReader br) public static string GetIsMini(BinaryReader br) { if (br.BaseStream.Length < 12) - return null; + return string.Empty; br.BaseStream.Position = 0; var ident = br.ReadBytes(2); var count = br.ReadUInt16(); int finalLengthOfs = 4 + (count * 4); if (br.BaseStream.Length < finalLengthOfs + 4) - return null; + return string.Empty; br.BaseStream.Position = 4 + (count * 4); var len = br.ReadUInt32(); if (len != br.BaseStream.Length) - return null; + return string.Empty; return $"{(char)ident[0]}{(char)ident[1]}"; } diff --git a/pkNX.Containers/Misc/BinaryRWExtensions.cs b/pkNX.Containers/Misc/BinaryRWExtensions.cs index 0bd2290b..3f69d733 100644 --- a/pkNX.Containers/Misc/BinaryRWExtensions.cs +++ b/pkNX.Containers/Misc/BinaryRWExtensions.cs @@ -35,7 +35,7 @@ public static string ReadNXString(this BinaryReader br) public static string ReadStringBytesUntil(this BinaryReader br, byte end = 0) { - StringBuilder str = new StringBuilder(); + StringBuilder str = new(); byte b; while ((b = br.ReadByte()) != end) str.Append((char)b); diff --git a/pkNX.Containers/Misc/GFPack.cs b/pkNX.Containers/Misc/GFPack.cs index b1fc1688..d99bdff9 100644 --- a/pkNX.Containers/Misc/GFPack.cs +++ b/pkNX.Containers/Misc/GFPack.cs @@ -24,6 +24,7 @@ public class GFPack : IEnumerable, IFileContainer public byte[][] CompressedFiles { get; set; } public byte[][] DecompressedFiles { get; set; } +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public GFPack(string path) : this(FileMitm.ReadAllBytes(path)) => FilePath = path; public GFPack(string[] directories, string parent = @"\bin") => LoadFiles(directories, parent); @@ -39,6 +40,7 @@ public GFPack(byte[] data) } public GFPack(BinaryReader br) => ReadPack(br); +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. private void ReadPack(BinaryReader br) { @@ -212,8 +214,7 @@ private static byte[] Decompress(byte[] encryptedData, int decryptedLength, Comp return type switch { CompressionType.None => encryptedData, - CompressionType.Zlib => null // not implemented - , + CompressionType.Zlib => throw new NotSupportedException(nameof(CompressionType.Zlib)), // not implemented _ => LZ4.Decode(encryptedData, decryptedLength) }; } @@ -223,8 +224,7 @@ private static byte[] Compress(byte[] decryptedData, CompressionType type) return type switch { CompressionType.None => decryptedData, - CompressionType.Zlib => null // not implemented - , + CompressionType.Zlib => throw new NotSupportedException(nameof(CompressionType.Zlib)), // not implemented _ => LZ4.Encode(decryptedData) }; } @@ -260,7 +260,7 @@ private void WriteHeaderTableList(BinaryWriter bw) bw.Write(ft.ToBytesClass()); } - public string FilePath { get; set; } + public string? FilePath { get; set; } public bool Modified { get; set; } public Task GetFiles() => Task.FromResult(DecompressedFiles); public Task GetFile(int file, int subFile = 0) => Task.FromResult(this[file]); @@ -365,8 +365,8 @@ public class FileHashAbsolute public class FileHashFolder { - public FileHashFolderInfo Folder; - public FileHashIndex[] Files; + public FileHashFolderInfo Folder = new(); + public FileHashIndex[] Files = Array.Empty(); public int GetIndexFileName(ulong hash) => Array.FindIndex(Files, z => z.HashFnv1aPathFileName == hash); public int GetIndexFileName(string name) => Array.FindIndex(Files, z => z.IsMatch(name)); } diff --git a/pkNX.Containers/NX/NSO.cs b/pkNX.Containers/NX/NSO.cs index 894b4d08..0ecf9845 100644 --- a/pkNX.Containers/NX/NSO.cs +++ b/pkNX.Containers/NX/NSO.cs @@ -24,6 +24,7 @@ public class NSO public decimal CompressionRatioRO => (decimal)DecompressedRO.Length / CompressedRO.Length; public decimal CompressionRatioData => (decimal)DecompressedData.Length / CompressedData.Length; +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public NSO(BinaryReader br) => ReadHeader(br); public NSO(byte[] data) @@ -32,6 +33,7 @@ public NSO(byte[] data) using var br = new BinaryReader(ms); ReadHeader(br); } +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. private void ReadHeader(BinaryReader br) { diff --git a/pkNX.Containers/NX/NSOHeader.cs b/pkNX.Containers/NX/NSOHeader.cs index d9325e31..d8d5fa28 100644 --- a/pkNX.Containers/NX/NSOHeader.cs +++ b/pkNX.Containers/NX/NSOHeader.cs @@ -16,6 +16,7 @@ public class NSOHeader public uint Reserved; public NSOFlag Flags; +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public SegmentHeader HeaderText; public int ModuleOffset; public SegmentHeader HeaderRO; @@ -46,4 +47,5 @@ public class NSOHeader [MarshalAs(UnmanagedType.ByValArray, SizeConst = 0x20)] public byte[] HashData; } +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. } \ No newline at end of file diff --git a/pkNX.Containers/SARC/SARC.cs b/pkNX.Containers/SARC/SARC.cs index 6556f64a..19b2f3a0 100644 --- a/pkNX.Containers/SARC/SARC.cs +++ b/pkNX.Containers/SARC/SARC.cs @@ -34,8 +34,10 @@ public SARC(IReadOnlyList files, string baseFolder) Header = new SARCHeader(); SFAT = new SFAT(baseFolder, files); SFNT = new SFNT(); + Files = new byte[]?[SFAT.Entries.Count]; } +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. /// /// Initializes a from a file location. /// @@ -53,12 +55,15 @@ public SARC(IReadOnlyList files, string baseFolder) /// /// public SARC(BinaryReader br) => OpenRead(br); +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. /// /// Reads the contents of the header and file info tables. /// protected override void Initialize() { + if (Reader is null) + throw new NullReferenceException(nameof(Reader)); Header = new SARCHeader(Reader); if (!SigMatches) return; @@ -83,8 +88,8 @@ private void PackSARC(BinaryWriter bw, ContainerHandler handler, CancellationTok { var entr = SFAT.Entries[i]; if (entr.FileName == null) - entr.GetFileName(Reader.BaseStream, (int)currentStringOffset); - entr.WriteFileName(Reader.BaseStream, (int)SFNT.StringOffset); + entr.GetFileName(Reader!.BaseStream, (int)currentStringOffset); + entr.WriteFileName(Reader!.BaseStream, (int)SFNT.StringOffset); while (Reader.BaseStream.Position % 4 != 0) bw.Write((byte)0); } @@ -126,12 +131,12 @@ public override byte[] GetEntry(int index, int subFile) if (f.File is byte[] data) return data; - data = f.GetFileData(Reader.BaseStream); + data = f.GetFileData(Reader!.BaseStream); f.File = data; // cache for future fetches return data; } - public override void Dump(string path, ContainerHandler handler) + public override void Dump(string? path, ContainerHandler handler) { path ??= FilePath; if (path == null) @@ -149,12 +154,12 @@ public override void Dump(string path, ContainerHandler handler) handler.Initialize(count); for (int i = 0; i < count; i++) { - SFAT.Entries[i].Dump(Reader.BaseStream, path, Header.DataOffset); + SFAT.Entries[i].Dump(Reader!.BaseStream, path, Header.DataOffset); handler.StepFile(i + 1); } } - public static SARC GetSARC(BinaryReader br) + public static SARC? GetSARC(BinaryReader br) { if (br.BaseStream.Length < 20) return null; diff --git a/pkNX.Containers/SARC/SFATEntry.cs b/pkNX.Containers/SARC/SFATEntry.cs index b4e40fad..1f46f32d 100644 --- a/pkNX.Containers/SARC/SFATEntry.cs +++ b/pkNX.Containers/SARC/SFATEntry.cs @@ -11,7 +11,7 @@ public class SFATEntry : LargeContainerEntry public uint FileNameHash; public int FileNameOffset; - public string FileName { get; private set; } + public string? FileName { get; private set; } private static uint GetHash(string name, int length, uint multiplier) { @@ -66,7 +66,7 @@ public void WriteFileName(Stream parent, int StringOffset) { FileNameOffset = (int)(parent.Position - StringOffset) / 4; - var str = FileName.Replace(Path.DirectorySeparatorChar, '/'); + var str = FileName?.Replace(Path.DirectorySeparatorChar, '/') ?? string.Empty; foreach (var b in str) parent.WriteByte((byte)b); parent.WriteByte(0); // \0 diff --git a/pkNX.Containers/SingleFileContainer.cs b/pkNX.Containers/SingleFileContainer.cs index 184337d4..d137b560 100644 --- a/pkNX.Containers/SingleFileContainer.cs +++ b/pkNX.Containers/SingleFileContainer.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -7,12 +8,12 @@ namespace pkNX.Containers { public class SingleFileContainer : IFileContainer { - public string FilePath { get; set; } + public string? FilePath { get; set; } public bool Modified { get; set; } public int Count => 1; - public byte[] Data; - private byte[] Backup; + public byte[] Data = Array.Empty(); + private byte[] Backup = Array.Empty(); public SingleFileContainer(byte[] data) => LoadData(data); public SingleFileContainer(BinaryReader br) => LoadData(br.ReadBytes((int) br.BaseStream.Length)); public SingleFileContainer(string path) => LoadData(FileMitm.ReadAllBytes(FilePath = path)); @@ -39,6 +40,6 @@ public void CancelEdits() public Task GetFile(int file, int subFile = 0) => Task.FromResult(this[0]); public Task SetFile(int file, byte[] value, int subFile = 0) => Task.FromResult(Data = value); public Task SaveAs(string path, ContainerHandler handler, CancellationToken token) => new(() => Dump(path, handler), token); - public void Dump(string path, ContainerHandler handler) => FileMitm.WriteAllBytes(path ?? FilePath, Data); + public void Dump(string? path, ContainerHandler handler) => FileMitm.WriteAllBytes(path ?? FilePath!, Data); } } diff --git a/pkNX.Containers/pkNX.Containers.csproj b/pkNX.Containers/pkNX.Containers.csproj index 196cacb1..fefc8ef3 100644 --- a/pkNX.Containers/pkNX.Containers.csproj +++ b/pkNX.Containers/pkNX.Containers.csproj @@ -4,6 +4,7 @@ netstandard2.0;net46 Packing & Unpacking 9 + enable diff --git a/pkNX.Randomization/Randomizers/FormRandomizer.cs b/pkNX.Randomization/Randomizers/FormRandomizer.cs index 7342017e..581ccad2 100644 --- a/pkNX.Randomization/Randomizers/FormRandomizer.cs +++ b/pkNX.Randomization/Randomizers/FormRandomizer.cs @@ -14,7 +14,7 @@ public FormRandomizer(PersonalTable t) Personal = t; } - public int GetRandomForme(int species, bool mega, bool fused, bool alola, bool galar, PersonalInfo[] stats = null) + public int GetRandomForme(int species, bool mega, bool fused, bool alola, bool galar, PersonalInfo[]? stats = null) { stats ??= Personal.Table; if (stats[species].FormeCount <= 1) @@ -48,7 +48,7 @@ public int GetRandomForme(int species, bool mega, bool fused, bool alola, bool g case Darmanitan when galar: { int form = Util.Random.Next(stats[species].FormeCount); - return form &= 2; + return form & 2; } // some species have 1 invalid form among several other valid forms, handle them here diff --git a/pkNX.Randomization/Randomizers/LearnsetRandomizer.cs b/pkNX.Randomization/Randomizers/LearnsetRandomizer.cs index 2fd11259..e104d35e 100644 --- a/pkNX.Randomization/Randomizers/LearnsetRandomizer.cs +++ b/pkNX.Randomization/Randomizers/LearnsetRandomizer.cs @@ -14,9 +14,9 @@ public class LearnsetRandomizer : Randomizer private readonly GameInfo Game; private readonly PersonalTable Personal; private MoveRandomizer moverand; - public IReadOnlyList Moves { private get; set; } + public IReadOnlyList Moves { private get; set; } = Array.Empty(); - public LearnSettings Settings { get; private set; } + public LearnSettings Settings { get; private set; } = new(); public IList BannedMoves { set => moverand.Settings.BannedMoves = value; } public LearnsetRandomizer(GameInfo game, Learnset[] learnsets, PersonalTable t) @@ -24,6 +24,9 @@ public LearnsetRandomizer(GameInfo game, Learnset[] learnsets, PersonalTable t) Game = game; Learnsets = learnsets; Personal = t; + + // temp, overwrite later if using it + moverand = new MoveRandomizer(game, Moves, Personal); } private static readonly int[] MetronomeMove = { 118 }; @@ -59,7 +62,7 @@ public void ExecuteExpandOnly() } } - public void Initialize(Move[] moves, LearnSettings settings, MovesetRandSettings moverandset, int[] bannedMoves = null) + public void Initialize(Move[] moves, LearnSettings settings, MovesetRandSettings moverandset, int[]? bannedMoves = null) { Moves = moves; Settings = settings; diff --git a/pkNX.Randomization/Randomizers/MoveRandomizer.cs b/pkNX.Randomization/Randomizers/MoveRandomizer.cs index 0b6e672d..282c481c 100644 --- a/pkNX.Randomization/Randomizers/MoveRandomizer.cs +++ b/pkNX.Randomization/Randomizers/MoveRandomizer.cs @@ -12,7 +12,7 @@ public class MoveRandomizer : Randomizer private readonly GameInfo Config; private GenericRandomizer RandMove; - internal MovesetRandSettings Settings; + internal MovesetRandSettings Settings = new(); public MoveRandomizer(GameInfo config, IReadOnlyList moves, PersonalTable t) { diff --git a/pkNX.Randomization/Randomizers/Personal/PersonalRandomizer.cs b/pkNX.Randomization/Randomizers/Personal/PersonalRandomizer.cs index 9475e92d..b1629b3f 100644 --- a/pkNX.Randomization/Randomizers/Personal/PersonalRandomizer.cs +++ b/pkNX.Randomization/Randomizers/Personal/PersonalRandomizer.cs @@ -17,7 +17,7 @@ public class PersonalRandomizer : Randomizer private readonly PersonalTable Table; private readonly EvolutionSet[] Evolutions; - public PersonalRandSettings Settings { get; set; } + public PersonalRandSettings Settings { get; set; } = new(); public PersonalRandomizer(PersonalTable table, GameInfo game, EvolutionSet[] evolutions) { @@ -47,7 +47,7 @@ private void RandomizeAllSpecies() RandomizeSpecies(species); } - private bool[] processed; + private bool[] processed = Array.Empty(); private void RandomizeChains() { @@ -61,9 +61,12 @@ private void RandomizeChains() private bool AlreadyProcessed(int index) { - if (processed[index]) + var p = processed; + if (p.Length <= index) + return false; + if (p[index]) return true; - processed[index] = true; + p[index] = true; return false; } diff --git a/pkNX.Randomization/Randomizers/SpeciesRandomizer.cs b/pkNX.Randomization/Randomizers/SpeciesRandomizer.cs index 90149175..9fb8d1cf 100644 --- a/pkNX.Randomization/Randomizers/SpeciesRandomizer.cs +++ b/pkNX.Randomization/Randomizers/SpeciesRandomizer.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using pkNX.Structures; namespace pkNX.Randomization @@ -9,7 +10,7 @@ public class SpeciesRandomizer private readonly int MaxSpeciesID; private readonly GameInfo Game; - private SpeciesSettings s; + private SpeciesSettings s = new(); public SpeciesRandomizer(GameInfo game, PersonalTable t) { @@ -31,7 +32,7 @@ public void Initialize(SpeciesSettings settings, params int[] banlist) } #region Random Species Filtering Parameters - private GenericRandomizer RandSpec; + private GenericRandomizer RandSpec = new(Array.Empty()); private int loopctr; private const int l = 10; // tweakable scalars private const int h = 11; diff --git a/pkNX.Randomization/Randomizers/TrainerRandomizer.cs b/pkNX.Randomization/Randomizers/TrainerRandomizer.cs index ed0b57f5..1c08ddc9 100644 --- a/pkNX.Randomization/Randomizers/TrainerRandomizer.cs +++ b/pkNX.Randomization/Randomizers/TrainerRandomizer.cs @@ -17,17 +17,19 @@ public class TrainerRandomizer : Randomizer private readonly IList SpecialClasses; private readonly IList CrashClasses; - public GenericRandomizer Class { get; set; } - public LearnsetRandomizer Learn { get; set; } - public SpeciesRandomizer RandSpec { get; set; } - public FormRandomizer RandForm { get; set; } - public MoveRandomizer RandMove { get; set; } public int ClassCount { get; set; } - public Func GetBlank { get; set; } - public EvolutionSet[] Evos { get; set; } + public EvolutionSet[] Evos { get; } - private TrainerRandSettings Settings; - private SpeciesSettings SpecSettings; + // Set these before starting up + public GenericRandomizer Class { get; set; } = null!; + public LearnsetRandomizer Learn { get; set; } = null!; + public SpeciesRandomizer RandSpec { get; set; } = null!; + public FormRandomizer RandForm { get; set; } = null!; + public MoveRandomizer RandMove { get; set; } = null!; + public Func GetBlank { get; set; } = null!; + + private TrainerRandSettings Settings = null!; + private SpeciesSettings SpecSettings = null!; public TrainerRandomizer(GameInfo info, PersonalTable t, VsTrainer[] trainers, EvolutionSet[] evos) { diff --git a/pkNX.Randomization/Util.cs b/pkNX.Randomization/Util.cs index 3ff85270..3c53ec61 100644 --- a/pkNX.Randomization/Util.cs +++ b/pkNX.Randomization/Util.cs @@ -28,15 +28,19 @@ public static void Shuffle(IList array) } } - public static int ToInt32(string value) + public static int ToInt32(string? value) { - string val = value?.Replace(" ", "").Replace("_", "").Trim(); + if (value is null) + return 0; + string val = value.Replace(" ", "").Replace("_", "").Trim(); return string.IsNullOrWhiteSpace(val) ? 0 : int.Parse(val); } - public static uint ToUInt32(string value) + public static uint ToUInt32(string? value) { - string val = value?.Replace(" ", "").Replace("_", "").Trim(); + if (value is null) + return 0; + string val = value.Replace(" ", "").Replace("_", "").Trim(); return string.IsNullOrWhiteSpace(val) ? 0 : uint.Parse(val); } diff --git a/pkNX.Randomization/pkNX.Randomization.csproj b/pkNX.Randomization/pkNX.Randomization.csproj index be2421bc..2be3af3d 100644 --- a/pkNX.Randomization/pkNX.Randomization.csproj +++ b/pkNX.Randomization/pkNX.Randomization.csproj @@ -4,6 +4,7 @@ netstandard2.0;net46 Randomizer Utility 9 + enable diff --git a/pkNX.Sprites/ImageUtil.cs b/pkNX.Sprites/ImageUtil.cs index 1282852e..fc9633ab 100644 --- a/pkNX.Sprites/ImageUtil.cs +++ b/pkNX.Sprites/ImageUtil.cs @@ -19,8 +19,6 @@ public static Bitmap LayerImage(Image baseLayer, Image overLayer, int x, int y, public static Bitmap LayerImage(Image baseLayer, Image overLayer, int x, int y) { - if (baseLayer is null) - return (Bitmap)overLayer; Bitmap img = new(baseLayer); using Graphics gr = Graphics.FromImage(img); gr.DrawImage(overLayer, x, y, overLayer.Width, overLayer.Height); diff --git a/pkNX.Structures/Evolution/EvolutionSet.cs b/pkNX.Structures/Evolution/EvolutionSet.cs index 0290df3d..661393ea 100644 --- a/pkNX.Structures/Evolution/EvolutionSet.cs +++ b/pkNX.Structures/Evolution/EvolutionSet.cs @@ -1,4 +1,6 @@ -namespace pkNX.Structures +using System; + +namespace pkNX.Structures { /// /// Table of Evolution Branch Entries @@ -7,5 +9,7 @@ public abstract class EvolutionSet { public EvolutionMethod[] PossibleEvolutions; public abstract byte[] Write(); + + protected EvolutionSet() => PossibleEvolutions = Array.Empty(); } } diff --git a/pkNX.Structures/Learnset/Learnset.cs b/pkNX.Structures/Learnset/Learnset.cs index cddecd4a..1d83faa8 100644 --- a/pkNX.Structures/Learnset/Learnset.cs +++ b/pkNX.Structures/Learnset/Learnset.cs @@ -10,6 +10,12 @@ public abstract class Learnset public int[] Moves { get; protected set; } public int[] Levels { get; protected set; } + protected Learnset() + { + Moves = Array.Empty(); + Levels = Array.Empty(); + } + public abstract byte[] Write(); /// diff --git a/pkNX.Structures/Scripts/AmxHeader.cs b/pkNX.Structures/Scripts/AmxHeader.cs index f524e955..5a757a54 100644 --- a/pkNX.Structures/Scripts/AmxHeader.cs +++ b/pkNX.Structures/Scripts/AmxHeader.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Runtime.InteropServices; namespace pkNX.Structures diff --git a/pkNX.WinForms/Controls/EncounterList.cs b/pkNX.WinForms/Controls/EncounterList.cs index bbf09a7d..6c7e3f6a 100644 --- a/pkNX.WinForms/Controls/EncounterList.cs +++ b/pkNX.WinForms/Controls/EncounterList.cs @@ -89,8 +89,8 @@ private void UpdateRowImage(int row) dgv.Rows[row].Cells[0].Value = SpriteUtil.GetSprite(sp, form, 0, 0, false, false, false); } - private EncounterSlot7b[] Slots; - public static string[] species; + private EncounterSlot7b[]? Slots; + public static string[] species = Array.Empty(); public void LoadSlots(EncounterSlot7b[] slots) { diff --git a/pkNX.WinForms/Controls/EncounterList8.cs b/pkNX.WinForms/Controls/EncounterList8.cs index d2f2fcd7..f60bae42 100644 --- a/pkNX.WinForms/Controls/EncounterList8.cs +++ b/pkNX.WinForms/Controls/EncounterList8.cs @@ -79,8 +79,8 @@ private void UpdateRowImage(int row) dgv.Rows[row].Cells[0].Value = SpriteUtil.GetSprite(sp, form, 0, 0, false, false, false); } - private EncounterSlot8[] Slots; - public static string[] species; + private EncounterSlot8[]? Slots; + public static string[] species = Array.Empty(); public void LoadSlots(EncounterSlot8[] slots) { diff --git a/pkNX.WinForms/Controls/EvolutionRow.cs b/pkNX.WinForms/Controls/EvolutionRow.cs index b46bc48e..a3f6899e 100644 --- a/pkNX.WinForms/Controls/EvolutionRow.cs +++ b/pkNX.WinForms/Controls/EvolutionRow.cs @@ -42,7 +42,7 @@ public EvolutionRow() private void ChangeSpecies(int spec, int form) => PB_Preview.Image = SpriteUtil.GetSprite(spec, form, 0, 0, false, false, false); - private EvolutionMethod current; + private EvolutionMethod? current; private EvolutionTypeArgumentType oldMethod; public void LoadEvolution(EvolutionMethod s) @@ -58,6 +58,8 @@ public void LoadEvolution(EvolutionMethod s) public void SaveEvolution() { var evo = current; + if (evo == null) + return; evo.Species = CB_Species.SelectedIndex; evo.Form = (int)NUD_Form.Value; evo.Level = (int)NUD_Level.Value; @@ -65,10 +67,10 @@ public void SaveEvolution() evo.Argument = CB_Arg.SelectedIndex; } - public static string[] items; - public static string[] movelist; - public static string[] species; - public static string[] types; + public static string[] items = Array.Empty(); + public static string[] movelist = Array.Empty(); + public static string[] species = Array.Empty(); + public static string[] types = Array.Empty(); private static readonly string[] EvoMethods = Enum.GetNames(typeof(EvolutionType)); private static readonly string[] Levels = Enumerable.Range(0, 100 + 1).Select(z => z.ToString()).ToArray(); diff --git a/pkNX.WinForms/Controls/MegaEvoEntry.cs b/pkNX.WinForms/Controls/MegaEvoEntry.cs index cc40cfd6..4cbf59f4 100644 --- a/pkNX.WinForms/Controls/MegaEvoEntry.cs +++ b/pkNX.WinForms/Controls/MegaEvoEntry.cs @@ -7,7 +7,7 @@ namespace pkNX.WinForms { public partial class MegaEvoEntry : UserControl { - public static string[] items; + public static string[] items = Array.Empty(); private static readonly string[] EvoMethods = Enum.GetNames(typeof(MegaEvolutionMethod)); @@ -27,7 +27,7 @@ public MegaEvoEntry() } public int Species { private get; set; } - private MegaEvolutionSet current; + private MegaEvolutionSet? current; private void ChangeSpecies(int form) { @@ -47,6 +47,9 @@ public void LoadEvolution(MegaEvolutionSet s, int species) public void SaveEvolution() { + if (current == null) + return; + if (CB_Method.SelectedIndex <= 0) { current.ToForm = 0; diff --git a/pkNX.WinForms/Controls/StatEditor.cs b/pkNX.WinForms/Controls/StatEditor.cs index ffb4977b..0583434b 100644 --- a/pkNX.WinForms/Controls/StatEditor.cs +++ b/pkNX.WinForms/Controls/StatEditor.cs @@ -26,9 +26,9 @@ public void Initialize(string[] types) UpdatingFields = false; } - public PersonalTable Personal { private get; set; } + public PersonalTable? Personal { private get; set; } public bool UpdatingFields; - public StatPKM PKM { get; set; } + public StatPKM PKM { get; set; } = new TrainerPoke7b(); private readonly MaskedTextBox[] tb_iv; private readonly MaskedTextBox[] tb_ev; @@ -52,7 +52,11 @@ public void UpdateStats() } UpdatingFields = false; - var pi = Personal.GetFormeEntry(PKM.Species, PKM.Form); + var pt = Personal; + if (pt == null) + throw new NullReferenceException("Personal table hasn't been initialized."); + + var pi = pt.GetFormeEntry(PKM.Species, PKM.Form); var stats = PKM.GetStats(pi); Stat_HP.Text = stats[0].ToString(); diff --git a/pkNX.WinForms/Main.cs b/pkNX.WinForms/Main.cs index 95560a8e..e57e9285 100644 --- a/pkNX.WinForms/Main.cs +++ b/pkNX.WinForms/Main.cs @@ -17,7 +17,7 @@ private int Language set => CB_Lang.SelectedIndex = value; } - private EditorBase Editor; + private EditorBase? Editor; public Main() { diff --git a/pkNX.WinForms/MainEditor/EditUtil.cs b/pkNX.WinForms/MainEditor/EditUtil.cs index c683d21d..337b959f 100644 --- a/pkNX.WinForms/MainEditor/EditUtil.cs +++ b/pkNX.WinForms/MainEditor/EditUtil.cs @@ -20,7 +20,7 @@ public class SharedSettings public static class EditUtil { - public static SharedSettings Settings { get; set; } + public static SharedSettings Settings { get; set; } = new(); public static void LoadSettings(GameVersion game) { @@ -35,7 +35,7 @@ public static void LoadSettings(GameVersion game) var reader = new XmlSerializer(typeof(SharedSettings)); try { - Settings = (SharedSettings) reader.Deserialize(file) ?? new SharedSettings(); + Settings = (SharedSettings?) reader.Deserialize(file) ?? new SharedSettings(); } catch (Exception e) { diff --git a/pkNX.WinForms/MainEditor/EditorProvider.cs b/pkNX.WinForms/MainEditor/EditorProvider.cs index 9ed24d0e..2a5f78fc 100644 --- a/pkNX.WinForms/MainEditor/EditorProvider.cs +++ b/pkNX.WinForms/MainEditor/EditorProvider.cs @@ -14,7 +14,7 @@ public abstract class EditorBase public int Language { get => ROM.Language; set => ROM.Language = value; } protected EditorBase(GameManager rom) => ROM = rom; - public string Location { get; internal set; } + public string? Location { get; internal set; } public IEnumerable /// ComboBox to retrieve value for. - internal static int GetIndex(ComboBox cb) => (int)(cb?.SelectedValue ?? 0); + internal static int GetIndex(ComboBox cb) => (int)(cb.SelectedValue ?? 0); } } \ No newline at end of file diff --git a/pkNX.WinForms/pkNX.WinForms.csproj b/pkNX.WinForms/pkNX.WinForms.csproj index 58e37e9f..e490bcfd 100644 --- a/pkNX.WinForms/pkNX.WinForms.csproj +++ b/pkNX.WinForms/pkNX.WinForms.csproj @@ -12,6 +12,7 @@ pkNX.WinForms.Program pkNX 9 + enable