From 44df39709b27a78561f03d5d2c6dfc66aceb1087 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 2 Jun 2024 18:50:22 -0500 Subject: [PATCH] Reattach resources --- Directory.Build.props | 11 ++++++++ pk3DS.Core/CTR/ETC1.cs | 7 +++-- pk3DS.Core/CTR/GARC.cs | 24 ++++++++-------- pk3DS.Core/CTR/Images/BCLIM.cs | 20 ++++++------- pk3DS.Core/CTR/mini.cs | 22 +++++++-------- pk3DS.Core/Game/GameConfig.cs | 2 +- pk3DS.Core/Properties/Resources.Designer.cs | 22 +++++++-------- pk3DS.Core/TextFile.cs | 23 +++++++-------- pk3DS.Core/Util.cs | 10 ++----- pk3DS.Core/pk3DS.Core.csproj | 14 +++++++++- pk3DS.WinForms/Main.cs | 25 +++++++++++++---- pk3DS.WinForms/Misc/Patch.cs | 2 +- .../Properties/Resources.Designer.cs | 6 ++-- .../Properties/Settings.Designer.cs | 4 +-- .../Subforms/Gen6/EggMoveEditor6.cs | 4 +-- .../Subforms/Gen6/EvolutionEditor6.cs | 2 +- .../Subforms/Gen6/LevelUpEditor6.cs | 2 +- .../Subforms/Gen6/PersonalEditor6.cs | 12 ++++---- pk3DS.WinForms/Subforms/Gen6/RSTE.cs | 8 +++--- .../Subforms/Gen7/EggMoveEditor7.cs | 2 +- .../Subforms/Gen7/LevelUpEditor7.cs | 7 ++--- pk3DS.WinForms/Subforms/TextEditor.cs | 25 ++++++++++------- pk3DS.WinForms/Tools/Scripts.cs | 6 ++-- pk3DS.WinForms/WinFormsUtil.cs | 2 +- pk3DS.WinForms/app.config | 18 ------------ pk3DS.WinForms/pk3DS.WinForms.csproj | 28 ++++++++++++++++++- 26 files changed, 175 insertions(+), 133 deletions(-) create mode 100644 Directory.Build.props delete mode 100644 pk3DS.WinForms/app.config diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..1ed906c --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,11 @@ + + + latest + en + pk3DS + Project Pokémon + Kaphotics + Kaphotics + $([System.DateTime]::UtcNow.ToString("yyMMddHHmmss")) + + diff --git a/pk3DS.Core/CTR/ETC1.cs b/pk3DS.Core/CTR/ETC1.cs index 8841f39..97d3d7b 100644 --- a/pk3DS.Core/CTR/ETC1.cs +++ b/pk3DS.Core/CTR/ETC1.cs @@ -6,10 +6,11 @@ namespace pk3DS.Core.CTR; -internal static class ETC1 +internal static partial class ETC1 { - [DllImport("ETC1Lib.dll", EntryPoint = "ConvertETC1", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConvertETC1(IntPtr dataOut, ref uint dataOutSize, IntPtr dataIn, ushort width, ushort height, bool alpha); + [LibraryImport("ETC1Lib.dll", EntryPoint = "ConvertETC1")] + [UnmanagedCallConv(CallConvs = [typeof(System.Runtime.CompilerServices.CallConvCdecl)])] + public static partial void ConvertETC1(IntPtr dataOut, ref uint dataOutSize, IntPtr dataIn, ushort width, ushort height, [MarshalAs(UnmanagedType.Bool)] bool alpha); public static void CheckETC1Lib() { diff --git a/pk3DS.Core/CTR/GARC.cs b/pk3DS.Core/CTR/GARC.cs index f05ab87..5a6c98c 100644 --- a/pk3DS.Core/CTR/GARC.cs +++ b/pk3DS.Core/CTR/GARC.cs @@ -73,7 +73,7 @@ public static int PackGARC(string folderPath, string garcPath, int version, int #endregion // Set Up the GARC template. - GARCFile garc = new GARCFile + var garc = new GARCFile { ContentPadToNearest = 4, fato = @@ -131,7 +131,7 @@ public static int PackGARC(string folderPath, string garcPath, int version, int v = 1; // Assemble Entry - FileInfo fi = new FileInfo(packOrder[i]); + var fi = new FileInfo(packOrder[i]); int actualLength = (int)(fi.Length % 4 == 0 ? fi.Length : fi.Length + 4 - (fi.Length % 4)); garc.fatb.Entries[i].SubEntries[0].Start = od; garc.fatb.Entries[i].SubEntries[0].End = actualLength + garc.fatb.Entries[i].SubEntries[0].Start; @@ -167,7 +167,7 @@ public static int PackGARC(string folderPath, string garcPath, int version, int v |= 1 << fileNumber; // Assemble Entry - FileInfo fi = new FileInfo(s); + var fi = new FileInfo(s); int actualLength = (int)(fi.Length % 4 == 0 ? fi.Length : fi.Length + 4 - (fi.Length % 4)); garc.fatb.Entries[i].SubEntries[fileNumber].Start = od; garc.fatb.Entries[i].SubEntries[fileNumber].End = actualLength + garc.fatb.Entries[i].SubEntries[fileNumber].Start; @@ -192,7 +192,7 @@ public static int PackGARC(string folderPath, string garcPath, int version, int // Set up the Header Info using var newGARC = new FileStream(garcPath, FileMode.Create); - using BinaryWriter gw = new BinaryWriter(newGARC); + using var gw = new BinaryWriter(newGARC); #region Write GARC Headers // Write GARC @@ -327,7 +327,7 @@ public static int GarcUnpack(string garcPath, string outPath, bool skipDecompres FileCountDetermined?.Invoke(null, new FileCountDeterminedEventArgs { Total = fileCount }); - using BinaryReader br = new BinaryReader(File.OpenRead(garcPath)); + using var br = new BinaryReader(File.OpenRead(garcPath)); // Create Extraction folder if it does not exist. if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath); @@ -365,7 +365,7 @@ public static int GarcUnpack(string garcPath, string outPath, bool skipDecompres // Write File string fileOut = Path.Combine(parentFolder, (Entry.IsFolder ? i.ToString("00") : fileName) + "." + ext); - using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut))) + using (var bw = new BinaryWriter(File.OpenWrite(fileOut))) { // Write out the data for the file br.BaseStream.Position = SubEntry.Start + garc.DataOffset; @@ -412,8 +412,8 @@ private static GARCFile UnpackGARC(byte[] data) private static GARCFile UnpackGARC(Stream stream) { - using BinaryReader br = new BinaryReader(stream); - GARCFile garc = new GARCFile + using var br = new BinaryReader(stream); + var garc = new GARCFile { Magic = br.ReadChars(4), HeaderSize = br.ReadUInt32(), @@ -494,7 +494,7 @@ public static MemGARC PackGARC(byte[][] data, int version, int contentpadnearest if (contentpadnearest < 0) contentpadnearest = 4; // Set Up the GARC template. - GARCFile garc = new GARCFile + var garc = new GARCFile { ContentPadToNearest = (uint)contentpadnearest, fato = @@ -544,7 +544,7 @@ public static MemGARC PackGARC(byte[][] data, int version, int contentpadnearest // Set up the Header Info string tempFile = Path.GetTempFileName(); using (var newGARC = new FileStream(tempFile, FileMode.Create)) - using (BinaryWriter gw = new BinaryWriter(newGARC)) + using (var gw = new BinaryWriter(newGARC)) { #region Write GARC Headers @@ -746,7 +746,7 @@ public GARCEntry(byte[] data) try { - using (MemoryStream newMS = new MemoryStream()) + using (var newMS = new MemoryStream()) { LZSS.Decompress(new MemoryStream(data), data.Length, newMS); Data = newMS.ToArray(); @@ -764,7 +764,7 @@ public byte[] Save() byte[] data; try { - using MemoryStream newMS = new MemoryStream(); + using var newMS = new MemoryStream(); LZSS.Compress(new MemoryStream(Data), Data.Length, newMS, original: true); data = newMS.ToArray(); } diff --git a/pk3DS.Core/CTR/Images/BCLIM.cs b/pk3DS.Core/CTR/Images/BCLIM.cs index 4a422e0..4a5ad09 100644 --- a/pk3DS.Core/CTR/Images/BCLIM.cs +++ b/pk3DS.Core/CTR/Images/BCLIM.cs @@ -25,15 +25,15 @@ public BCLIM(string path) private void ReadBCLIM(Stream ms) { PixelData = new byte[ms.Length - FLIMHeader.SIZE]; - ms.Read(PixelData, 0, PixelData.Length); + _ = ms.Read(PixelData, 0, PixelData.Length); var footer = new byte[FLIMHeader.SIZE]; - ms.Read(footer, 0, footer.Length); + _ = ms.Read(footer, 0, footer.Length); Footer = footer.ToStructure(); } public override uint[] GetPixels() { - if (Format == (XLIMEncoding)7 && BitConverter.ToUInt16(PixelData, 0) == 2) // Gen6 Palette + if (Format == XLIMEncoding.RGB5A1 && BitConverter.ToUInt16(PixelData, 0) == 2) // Gen6 Palette return GetPixelsViaPalette(); return base.GetPixels(); } @@ -72,8 +72,8 @@ private uint[] GetPixelsViaPalette() // todo: move System.Drawing utilization out, make encoding generic for bflim public static byte[] IMGToBCLIM(Image img, char fc) { - Bitmap mBitmap = new Bitmap(img); - MemoryStream ms = new MemoryStream(); + var mBitmap = new Bitmap(img); + var ms = new MemoryStream(); int bclimformat = 7; // Init to default (for X) if (fc == 'X') @@ -96,7 +96,7 @@ public static byte[] IMGToBCLIM(Image img, char fc) long datalength = ms.Length; // Write the CLIM + imag data. - using (BinaryWriter bw = new BinaryWriter(ms)) + using (var bw = new BinaryWriter(ms)) { bw.Write((uint)0x4D494C43); // CLIM bw.Write((ushort)0xFEFF); // BOM @@ -156,8 +156,8 @@ public static Image MakeBMP(string path, bool autosave = false, bool crop = true // BCLIM Data Writing public static int Write16BitColorPalette(Bitmap img, MemoryStream ms) { - using Stream pixelcolors = new MemoryStream(); - using BinaryWriter bz = new BinaryWriter(pixelcolors); + using var pixelcolors = new MemoryStream(); + using var bz = new BinaryWriter(pixelcolors); // Set up our basis. bool under16colors = false; int colors = GetColorCount(img); @@ -284,8 +284,8 @@ public static byte[] GetPixelData(Bitmap img, int format, bool rectangle = true) } } - using MemoryStream mz = new MemoryStream(); - using BinaryWriter bz = new BinaryWriter(mz); + using var mz = new MemoryStream(); + using var bz = new BinaryWriter(mz); int p = XLIMUtil.GreatestCommonMultiple(w, 8) / 8; if (p == 0) p = 1; for (uint i = 0; i < w * h; i++) diff --git a/pk3DS.Core/CTR/mini.cs b/pk3DS.Core/CTR/mini.cs index 8ff891f..4fa4c1b 100644 --- a/pk3DS.Core/CTR/mini.cs +++ b/pk3DS.Core/CTR/mini.cs @@ -48,10 +48,10 @@ public static void PackMini(string path, string ident, string fileName, string o 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 (var dataout = new MemoryStream()) + using (var offsetMap = new MemoryStream()) + using (var bd = new BinaryWriter(dataout)) + using (var bo = new BinaryWriter(offsetMap)) { // For each file... for (int i = 0; i < count; i++) @@ -96,10 +96,10 @@ public static byte[] PackMini(byte[][] fileData, string ident) 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 var dataout = new MemoryStream(); + using var offsetMap = new MemoryStream(); + using var bd = new BinaryWriter(dataout); + using var bo = new BinaryWriter(offsetMap); // For each file... for (int i = 0; i < count; i++) { @@ -148,7 +148,7 @@ public static void UnpackMini(string path, string ident, string outFolder = null using (var s = new MemoryStream(File.ReadAllBytes(path))) using (var br = new BinaryReader(s)) { - string fx = new string(br.ReadChars(2)); + var fx = new string(br.ReadChars(2)); if (fx != ident) return; @@ -164,7 +164,7 @@ public static void UnpackMini(string path, string ident, string outFolder = null for (int i = 0; i < count; i++) { br.BaseStream.Seek(offsets[i], SeekOrigin.Begin); - using MemoryStream dataout = new MemoryStream(); + using var dataout = new MemoryStream(); byte[] data = []; s.CopyTo(dataout, (int)offsets[i]); int len = (int)offsets[i + 1] - (int)offsets[i]; @@ -217,7 +217,7 @@ public static string GetIsMini(string path) var fi = new FileInfo(path); try { - string fx = new string(new[] { (char)data[0], (char)data[1] }); + string fx = new(new[] { (char)data[0], (char)data[1] }); ushort count = BitConverter.ToUInt16(data, 2); uint[] offsets = new uint[count + 1]; diff --git a/pk3DS.Core/Game/GameConfig.cs b/pk3DS.Core/Game/GameConfig.cs index f7ae04e..dbd62c0 100644 --- a/pk3DS.Core/Game/GameConfig.cs +++ b/pk3DS.Core/Game/GameConfig.cs @@ -241,7 +241,7 @@ private GARC.LazyGARC GetlzGARC(string file) public TextVariableCode GetVariableCode(string name) { return Variables?.FirstOrDefault(v => v.Name == name); } public TextVariableCode GetVariableName(int value) { return Variables?.FirstOrDefault(v => v.Code == value); } - private TextReference GetGameText(TextName name) { return GameText?.FirstOrDefault(f => f.Name == name); } + private TextReference GetGameText(TextName name) { return GameText.FirstOrDefault(f => f.Name == name); } public TextData GetTextData(TextName file) => new(GetText(file)); public string[] GetText(TextName file) diff --git a/pk3DS.Core/Properties/Resources.Designer.cs b/pk3DS.Core/Properties/Resources.Designer.cs index ead022b..ba65eab 100644 --- a/pk3DS.Core/Properties/Resources.Designer.cs +++ b/pk3DS.Core/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace pk3DS.Core.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] public class Resources { @@ -160,16 +160,6 @@ public class Resources { } } - /// - /// Looks up a localized resource of type System.Byte[]. - /// - public static byte[] XY { - get { - object obj = ResourceManager.GetObject("XY", resourceCulture); - return ((byte[])(obj)); - } - } - /// /// Looks up a localized resource of type System.Byte[]. /// @@ -189,5 +179,15 @@ public class Resources { return ((byte[])(obj)); } } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + public static byte[] XY { + get { + object obj = ResourceManager.GetObject("XY", resourceCulture); + return ((byte[])(obj)); + } + } } } diff --git a/pk3DS.Core/TextFile.cs b/pk3DS.Core/TextFile.cs index 4255e7b..132695d 100644 --- a/pk3DS.Core/TextFile.cs +++ b/pk3DS.Core/TextFile.cs @@ -142,7 +142,7 @@ public byte[][] LineData public string[] Lines { - get => LineData.Select(z => GetLineString(Config, z)).ToArray(); + get => Array.ConvertAll(LineData, z => GetLineString(Config, z)); set => LineData = ConvertLinesToData(value); } @@ -186,8 +186,8 @@ private byte[] GetLineData(GameConfig config, string line) if (line == null) return new byte[2]; - MemoryStream ms = new MemoryStream(); - using BinaryWriter bw = new BinaryWriter(ms); + var ms = new MemoryStream(); + using var bw = new BinaryWriter(ms); int i = 0; while (i < line.Length) { @@ -200,7 +200,7 @@ private byte[] GetLineData(GameConfig config, string line) case '[': { // grab the string - int bracket = line.IndexOf("]", i, StringComparison.Ordinal); + int bracket = line.IndexOf(']', i); if (bracket < 0) throw new ArgumentException("Variable text is not capped properly: " + line); string varText = line[i..bracket]; @@ -255,20 +255,17 @@ private ushort TryUnmapChar(ushort val) private string GetLineString(GameConfig config, byte[] data) { - if (data == null) - return null; - var s = new StringBuilder(); int i = 0; while (i < data.Length) { ushort val = BitConverter.ToUInt16(data, i); - if (val == KEY_TERMINATOR) break; + if (val == KEY_TERMINATOR) + break; i += 2; switch (val) { - case KEY_TERMINATOR: return s.ToString(); case KEY_VARIABLE: s.Append(GetVariableString(config, data, ref i)); break; case '\n': s.Append(@"\n"); break; case '\\': s.Append(@"\\"); break; @@ -318,7 +315,7 @@ private static string GetVariableString(GameConfig config, byte[] data, ref int return s.ToString(); } - private static IEnumerable GetEscapeValues(char esc) + private static List GetEscapeValues(char esc) { var vals = new List(); switch (esc) @@ -332,7 +329,7 @@ private static IEnumerable GetEscapeValues(char esc) } } - private IEnumerable GetVariableValues(GameConfig config, string variable) + private static List GetVariableValues(GameConfig config, string variable) { string[] split = variable.Split(' '); if (split.Length < 2) @@ -359,7 +356,7 @@ private IEnumerable GetVariableValues(GameConfig config, string variable return vals; } - private IEnumerable GetVariableParameters(GameConfig config, string text) + private static List GetVariableParameters(GameConfig config, string text) { var vals = new List(); int bracket = text.IndexOf('('); @@ -405,7 +402,7 @@ private static string GetVariableString(GameConfig config, ushort variable) public static string[] GetStrings(GameConfig config, byte[] data, bool remapChars = false) { TextFile t; - try { t = new TextFile(config, data, remapChars); } catch { return null; } + try { t = new TextFile(config, data, remapChars); } catch { return []; } return t.Lines; } diff --git a/pk3DS.Core/Util.cs b/pk3DS.Core/Util.cs index 26fb6f4..db1da00 100644 --- a/pk3DS.Core/Util.cs +++ b/pk3DS.Core/Util.cs @@ -10,9 +10,7 @@ public static class Util public static FileInfo GetNewestFile(DirectoryInfo directory) { return directory.GetFiles() - .Union(directory.GetDirectories().Select(GetNewestFile)) - .OrderByDescending(f => f?.LastWriteTime ?? DateTime.MinValue) - .FirstOrDefault(); + .Union(directory.GetDirectories().Select(GetNewestFile)).MaxBy(f => f?.LastWriteTime ?? DateTime.MinValue); } public static string NormalizePath(string path) @@ -60,9 +58,7 @@ public static void Shuffle(T[] array) for (int i = 0; i < n; i++) { int r = i + (int)(Rand.NextDouble() * (n - i)); - T t = array[r]; - array[r] = array[i]; - array[i] = t; + (array[r], array[i]) = (array[i], array[r]); } } @@ -149,7 +145,7 @@ public static string GuessExtension(BinaryReader br, string defaultExt, bool byp public static string GuessExtension(string path, bool bypass) { - using BinaryReader br = new BinaryReader(File.OpenRead(path)); + using var br = new BinaryReader(File.OpenRead(path)); return GuessExtension(br, "bin", bypass); } diff --git a/pk3DS.Core/pk3DS.Core.csproj b/pk3DS.Core/pk3DS.Core.csproj index af0a4c4..a50fd89 100644 --- a/pk3DS.Core/pk3DS.Core.csproj +++ b/pk3DS.Core/pk3DS.Core.csproj @@ -2,7 +2,19 @@ true net8.0-windows - latest true + + + True + True + Resources.resx + + + + + PublicResXFileCodeGenerator + Resources.Designer.cs + + \ No newline at end of file diff --git a/pk3DS.WinForms/Main.cs b/pk3DS.WinForms/Main.cs index e00a08d..6567dc6 100644 --- a/pk3DS.WinForms/Main.cs +++ b/pk3DS.WinForms/Main.cs @@ -216,6 +216,9 @@ private void OpenExeFSCombined(string path, FileInfo fi) { if (fi.Length % 0x200 != 0) return; + var dir = Path.GetDirectoryName(path); + if (dir is null) + return; var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Detected ExeFS.bin.", "Unpack?"); if (prompt != DialogResult.Yes) @@ -224,7 +227,7 @@ private void OpenExeFSCombined(string path, FileInfo fi) new Thread(() => { Interlocked.Increment(ref threads); - ExeFS.UnpackExeFS(path, Path.GetDirectoryName(path)); + ExeFS.UnpackExeFS(path, dir); Interlocked.Decrement(ref threads); WinFormsUtil.Alert("Unpacked!"); }).Start(); @@ -317,8 +320,12 @@ private void OpenDirectory(string path) UpdateStatus("Data found! Loading persistent data for subforms...", false); try { - Config.Initialize(RomFSPath, ExeFSPath, Language); - Config.BackupFiles(); + if (Config is not null) + { + if (ExeFSPath is not null) + Config.Initialize(RomFSPath, ExeFSPath, Language); + Config.BackupFiles(); + } } catch (Exception ex) { @@ -493,7 +500,11 @@ private static GameConfig CheckGameType(string[] files) { if (files.Length > 1000) return null; - string[] fileArr = Directory.GetFiles(Path.Combine(Directory.GetParent(files[0]).FullName, "a"), "*", SearchOption.AllDirectories); + var parent = Directory.GetParent(files[0]); + if (parent is null) + return null; + + string[] fileArr = Directory.GetFiles(Path.Combine(parent.FullName, "a"), "*", SearchOption.AllDirectories); int fileCount = fileArr.Count(file => Path.GetFileName(file).Length == 1); return new GameConfig(fileCount); } @@ -588,12 +599,14 @@ private bool ThreadActive() private void TabMain_DragEnter(object sender, DragEventArgs e) { - if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; + if (e.Data?.GetDataPresent(DataFormats.FileDrop) is true) + e.Effect = DragDropEffects.Copy; } private void TabMain_DragDrop(object sender, DragEventArgs e) { - string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + if (e.Data?.GetData(DataFormats.FileDrop) is not string[] { Length: not 0 } files) + return; string path = files[0]; // open first D&D OpenQuick(path); } diff --git a/pk3DS.WinForms/Misc/Patch.cs b/pk3DS.WinForms/Misc/Patch.cs index 3ec9585..f9f27d5 100644 --- a/pk3DS.WinForms/Misc/Patch.cs +++ b/pk3DS.WinForms/Misc/Patch.cs @@ -116,7 +116,7 @@ private void B_PatchCIA_Click(object sender, EventArgs e) private string[] GetGARCs() { - StringCollection sc = new StringCollection(); + var sc = new StringCollection(); foreach (int indexChecked in CHKLB_GARCs.CheckedIndices) sc.Add(CHKLB_GARCs.Items[indexChecked].ToString()); diff --git a/pk3DS.WinForms/Properties/Resources.Designer.cs b/pk3DS.WinForms/Properties/Resources.Designer.cs index ac2fb8f..38af0a2 100644 --- a/pk3DS.WinForms/Properties/Resources.Designer.cs +++ b/pk3DS.WinForms/Properties/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace pk3DS.Properties { +namespace pk3DS.WinForms.Properties { using System; @@ -19,7 +19,7 @@ namespace pk3DS.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -39,7 +39,7 @@ internal class Resources { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("pk3DS.Properties.Resources", typeof(Resources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("pk3DS.WinForms.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; diff --git a/pk3DS.WinForms/Properties/Settings.Designer.cs b/pk3DS.WinForms/Properties/Settings.Designer.cs index 56d7348..983acb6 100644 --- a/pk3DS.WinForms/Properties/Settings.Designer.cs +++ b/pk3DS.WinForms/Properties/Settings.Designer.cs @@ -8,11 +8,11 @@ // //------------------------------------------------------------------------------ -namespace pk3DS.Properties { +namespace pk3DS.WinForms.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/pk3DS.WinForms/Subforms/Gen6/EggMoveEditor6.cs b/pk3DS.WinForms/Subforms/Gen6/EggMoveEditor6.cs index 9a7aab2..ebdbbee 100644 --- a/pk3DS.WinForms/Subforms/Gen6/EggMoveEditor6.cs +++ b/pk3DS.WinForms/Subforms/Gen6/EggMoveEditor6.cs @@ -6,10 +6,10 @@ using System.Media; using System.Text; using System.Windows.Forms; -using pk3DS.Properties; using pk3DS.Core.Structures; using pk3DS.Core; using pk3DS.Core.Randomizers; +using pk3DS.WinForms.Properties; namespace pk3DS.WinForms; @@ -176,7 +176,7 @@ public void CalcStats() byte[] movedata = files[i]; if (movedata.Length <= 2) continue; int movecount = BitConverter.ToUInt16(movedata, 0); - if (movecount == 65535 || movecount < 0) + if (movecount == 65535) continue; species++; movectr += movecount; // Average Moves diff --git a/pk3DS.WinForms/Subforms/Gen6/EvolutionEditor6.cs b/pk3DS.WinForms/Subforms/Gen6/EvolutionEditor6.cs index 33a30b3..8d2fb6e 100644 --- a/pk3DS.WinForms/Subforms/Gen6/EvolutionEditor6.cs +++ b/pk3DS.WinForms/Subforms/Gen6/EvolutionEditor6.cs @@ -5,10 +5,10 @@ using System.Media; using System.Text; using System.Windows.Forms; -using pk3DS.Properties; using pk3DS.Core; using pk3DS.Core.Randomizers; using pk3DS.Core.Structures; +using pk3DS.WinForms.Properties; namespace pk3DS.WinForms; diff --git a/pk3DS.WinForms/Subforms/Gen6/LevelUpEditor6.cs b/pk3DS.WinForms/Subforms/Gen6/LevelUpEditor6.cs index a35d1a8..8d057cf 100644 --- a/pk3DS.WinForms/Subforms/Gen6/LevelUpEditor6.cs +++ b/pk3DS.WinForms/Subforms/Gen6/LevelUpEditor6.cs @@ -6,10 +6,10 @@ using System.Media; using System.Text; using System.Windows.Forms; -using pk3DS.Properties; using pk3DS.Core.Structures; using pk3DS.Core; using pk3DS.Core.Randomizers; +using pk3DS.WinForms.Properties; namespace pk3DS.WinForms; diff --git a/pk3DS.WinForms/Subforms/Gen6/PersonalEditor6.cs b/pk3DS.WinForms/Subforms/Gen6/PersonalEditor6.cs index e81d96f..bdedecb 100644 --- a/pk3DS.WinForms/Subforms/Gen6/PersonalEditor6.cs +++ b/pk3DS.WinForms/Subforms/Gen6/PersonalEditor6.cs @@ -183,7 +183,7 @@ private void ByteLimiter(object sender, EventArgs e) { if (sender is not MaskedTextBox mtb) return; - int.TryParse(mtb.Text, out int val); + _ = int.TryParse(mtb.Text, out int val); if (Array.IndexOf(byte_boxes, mtb) > -1 && val > 255) mtb.Text = "255"; else if (Array.IndexOf(ev_boxes, mtb) > -1 && val > 3) @@ -271,8 +271,8 @@ private void ReadEntry() int f = formVal[entry]; if (entry <= Main.Config.MaxSpeciesID) s = entry; - Bitmap rawImg = WinFormsUtil.GetSprite(s, f, 0, 0, Main.Config); - Bitmap bigImg = new Bitmap(rawImg.Width * 2, rawImg.Height * 2); + var rawImg = WinFormsUtil.GetSprite(s, f, 0, 0, Main.Config); + var bigImg = new Bitmap(rawImg.Width * 2, rawImg.Height * 2); for (int x = 0; x < rawImg.Width; x++) { for (int y = 0; y < rawImg.Height; y++) @@ -321,8 +321,8 @@ private void SavePersonal() pkm.Color = (byte)(Convert.ToByte(CB_Color.SelectedIndex) | (Convert.ToByte(TB_RawColor.Text) & 0xF0)); pkm.BaseEXP = Convert.ToUInt16(TB_BaseExp.Text); - decimal.TryParse(TB_Height.Text, out var h); - decimal.TryParse(TB_Weight.Text, out var w); + _ = decimal.TryParse(TB_Height.Text, out var h); + _ = decimal.TryParse(TB_Weight.Text, out var w); pkm.Height = (int)(h * 100); pkm.Weight = (int)(w * 10); @@ -447,7 +447,7 @@ private void B_Dump_Click(object sender, EventArgs e) { if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Dump all Personal Entries to Text File?")) return; - SaveFileDialog sfd = new SaveFileDialog { FileName = "Personal Entries.txt", Filter = "Text File|*.txt" }; + var sfd = new SaveFileDialog { FileName = "Personal Entries.txt", Filter = "Text File|*.txt" }; SystemSounds.Asterisk.Play(); if (sfd.ShowDialog() != DialogResult.OK) return; diff --git a/pk3DS.WinForms/Subforms/Gen6/RSTE.cs b/pk3DS.WinForms/Subforms/Gen6/RSTE.cs index 58592a2..2bc763b 100644 --- a/pk3DS.WinForms/Subforms/Gen6/RSTE.cs +++ b/pk3DS.WinForms/Subforms/Gen6/RSTE.cs @@ -217,7 +217,7 @@ private void B_Dump_Click(object sender, EventArgs e) string tdata = GetTRSummary(); toret += tdata; } - SaveFileDialog sfd = new SaveFileDialog { FileName = "Battles.txt", Filter = "Text File|*.txt" }; + var sfd = new SaveFileDialog { FileName = "Battles.txt", Filter = "Text File|*.txt" }; SystemSounds.Asterisk.Play(); if (sfd.ShowDialog() == DialogResult.OK) @@ -465,7 +465,7 @@ private void Setup() public static int[] rFinalEvo; private string[] rImportant; private readonly List Tags = []; - private readonly Dictionary TagTypes = new(); + private readonly Dictionary TagTypes = []; public static int[] sL; // Random Species List public static decimal rGiftPercent, rLevelMultiplier, rMinPKM, rMaxPKM, rForceFullyEvolvedLevel, rForceHighPowerLevel; @@ -514,7 +514,7 @@ private void Randomize() GymE4Types.AddRange(Enumerable.Range(0, types.Length).ToArray()); } - foreach (int t1 in rEnsureMEvo.Where(t1 => rTags[t1].Length != 0 && !TagTypes.Keys.Contains(rTags[t1]))) + foreach (int t1 in rEnsureMEvo.Where(t1 => rTags[t1].Length != 0 && !TagTypes.ContainsKey(rTags[t1]))) { int t; if (rTags[t1].Contains("GYM") || rTags[t1].Contains("ELITE") || rTags[t1].Contains("CHAMPION")) @@ -531,7 +531,7 @@ private void Randomize() } foreach (string t1 in Tags) { - if (!TagTypes.Keys.Contains(t1) && t1.Length != 0) + if (!TagTypes.ContainsKey(t1) && t1.Length != 0) { int t; if (t1.Contains("GYM") || t1.Contains("ELITE") || t1.Contains("CHAMPION")) diff --git a/pk3DS.WinForms/Subforms/Gen7/EggMoveEditor7.cs b/pk3DS.WinForms/Subforms/Gen7/EggMoveEditor7.cs index 1738903..c89ca37 100644 --- a/pk3DS.WinForms/Subforms/Gen7/EggMoveEditor7.cs +++ b/pk3DS.WinForms/Subforms/Gen7/EggMoveEditor7.cs @@ -6,10 +6,10 @@ using System.Media; using System.Text; using System.Windows.Forms; -using pk3DS.Properties; using pk3DS.Core.Structures; using pk3DS.Core; using pk3DS.Core.Randomizers; +using pk3DS.WinForms.Properties; namespace pk3DS.WinForms; diff --git a/pk3DS.WinForms/Subforms/Gen7/LevelUpEditor7.cs b/pk3DS.WinForms/Subforms/Gen7/LevelUpEditor7.cs index ffac561..518d07c 100644 --- a/pk3DS.WinForms/Subforms/Gen7/LevelUpEditor7.cs +++ b/pk3DS.WinForms/Subforms/Gen7/LevelUpEditor7.cs @@ -6,12 +6,10 @@ using System.Media; using System.Text; using System.Windows.Forms; - -using pk3DS.Properties; - using pk3DS.Core.Structures; using pk3DS.Core; using pk3DS.Core.Randomizers; +using pk3DS.WinForms.Properties; namespace pk3DS.WinForms; @@ -162,7 +160,8 @@ private void B_RandAll_Click(object sender, EventArgs e) private void B_Metronome_Click(object sender, EventArgs e) { - if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Play using Metronome Mode?", "This will modify learnsets to only have Metronome.") != DialogResult.Yes) return; + if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Play using Metronome Mode?", "This will modify learnsets to only have Metronome.") != DialogResult.Yes) + return; // clear all data, then only assign Metronome at Lv1 for (int i = 0; i < CB_Species.Items.Count; i++) diff --git a/pk3DS.WinForms/Subforms/TextEditor.cs b/pk3DS.WinForms/Subforms/TextEditor.cs index 48951d0..7930d5d 100644 --- a/pk3DS.WinForms/Subforms/TextEditor.cs +++ b/pk3DS.WinForms/Subforms/TextEditor.cs @@ -28,10 +28,12 @@ public TextEditor(string[][] infiles, string mode) // IO private void B_Export_Click(object sender, EventArgs e) { - if (files.Length == 0) return; - SaveFileDialog Dump = new SaveFileDialog { Filter = "Text File|*.txt" }; - DialogResult sdr = Dump.ShowDialog(); - if (sdr != DialogResult.OK) return; + if (files.Length == 0) + return; + var Dump = new SaveFileDialog { Filter = "Text File|*.txt" }; + var sdr = Dump.ShowDialog(); + if (sdr != DialogResult.OK) + return; bool newline = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Remove newline formatting codes? (\\n,\\r,\\c)", "Removing newline formatting will make it more readable but will prevent any importing of that dump.") == DialogResult.Yes; string path = Dump.FileName; ExportTextFile(path, newline, files); @@ -39,13 +41,16 @@ private void B_Export_Click(object sender, EventArgs e) private void B_Import_Click(object sender, EventArgs e) { - if (files.Length == 0) return; - OpenFileDialog Dump = new OpenFileDialog { Filter = "Text File|*.txt" }; - DialogResult odr = Dump.ShowDialog(); - if (odr != DialogResult.OK) return; + if (files.Length == 0) + return; + var Dump = new OpenFileDialog { Filter = "Text File|*.txt" }; + var odr = Dump.ShowDialog(); + if (odr != DialogResult.OK) + return; string path = Dump.FileName; - if (!ImportTextFile(path)) return; + if (!ImportTextFile(path)) + return; // Reload the form with the new data. ChangeEntry(null, null); @@ -174,7 +179,7 @@ private void SetStringsDataGridView(string[] textArray) }; dgvLine.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; - DataGridViewTextBoxColumn dgvText = new DataGridViewTextBoxColumn + var dgvText = new DataGridViewTextBoxColumn { HeaderText = "Text", DisplayIndex = 1, diff --git a/pk3DS.WinForms/Tools/Scripts.cs b/pk3DS.WinForms/Tools/Scripts.cs index e5f0ad6..e544c0c 100644 --- a/pk3DS.WinForms/Tools/Scripts.cs +++ b/pk3DS.WinForms/Tools/Scripts.cs @@ -106,8 +106,8 @@ internal static uint[] QuickDecompress(byte[] data, int count) // Compression internal static byte[] CompressScript(byte[] data) { - if (data == null || data.Length % 4 != 0) // Bad Input - return null; + if (data.Length % 4 != 0) // Bad Input + throw new ArgumentException(nameof(data)); using var mn = new MemoryStream(); using var bw = new BinaryWriter(mn); int pos = 0; @@ -622,7 +622,7 @@ internal static string[] ParseScript(uint[] cmd, int sanity = -1) } if (sanity >= 0 && sanity != sanityMode) - throw new ArgumentException(); + throw new ArgumentException(null, nameof(sanity)); return [.. parse]; } diff --git a/pk3DS.WinForms/WinFormsUtil.cs b/pk3DS.WinForms/WinFormsUtil.cs index 6176dfd..2e8c92d 100644 --- a/pk3DS.WinForms/WinFormsUtil.cs +++ b/pk3DS.WinForms/WinFormsUtil.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Runtime.InteropServices; using System.Windows.Forms; -using pk3DS.Properties; +using pk3DS.WinForms.Properties; namespace pk3DS.WinForms; diff --git a/pk3DS.WinForms/app.config b/pk3DS.WinForms/app.config deleted file mode 100644 index 29a0bf5..0000000 --- a/pk3DS.WinForms/app.config +++ /dev/null @@ -1,18 +0,0 @@ - - - - -
- - - - - - 2 - - - - - - - diff --git a/pk3DS.WinForms/pk3DS.WinForms.csproj b/pk3DS.WinForms/pk3DS.WinForms.csproj index b223617..c8f11d8 100644 --- a/pk3DS.WinForms/pk3DS.WinForms.csproj +++ b/pk3DS.WinForms/pk3DS.WinForms.csproj @@ -4,7 +4,6 @@ WinExe net8.0-windows true - latest @@ -15,4 +14,31 @@ + + + True + True + Resources.resx + + + True + True + Settings.settings + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + \ No newline at end of file