diff --git a/pkNX.Containers/SARC/SARC.cs b/pkNX.Containers/SARC/SARC.cs index fcdf8f9e..9b29c59a 100644 --- a/pkNX.Containers/SARC/SARC.cs +++ b/pkNX.Containers/SARC/SARC.cs @@ -103,7 +103,7 @@ private void PackSARC(BinaryWriter bw, ContainerHandler handler, CancellationTok bw.Flush(); } - private void StartPack() { } + private static void StartPack() { } // do nothing? private void WriteIntro(BinaryWriter bw, bool finalPass = false) { @@ -146,7 +146,7 @@ public override void Dump(string? path, ContainerHandler handler) if (path == null) throw new ArgumentNullException(nameof(path)); - var folder = FileName ?? "sarc"; + var folder = FileName ?? Identifier; string dir = Path.Combine(path, folder); Directory.CreateDirectory(dir); diff --git a/pkNX.Structures.FlatBuffers/Arceus/Integration/PersonalTable8LA.cs b/pkNX.Structures.FlatBuffers/Arceus/Integration/PersonalTable8LA.cs index 6e476929..b06e828e 100644 --- a/pkNX.Structures.FlatBuffers/Arceus/Integration/PersonalTable8LA.cs +++ b/pkNX.Structures.FlatBuffers/Arceus/Integration/PersonalTable8LA.cs @@ -1,3 +1,4 @@ +using System.Collections; using pkNX.Containers; using System.Collections.Generic; using System.Diagnostics; @@ -15,7 +16,7 @@ public sealed class PersonalTable8LA : IPersonalTable, IPersonalTable MaxSpecies; private readonly IFileContainer File; - public PersonalTableLAfb Root { get; private set; } + public PersonalTableLAfb Root { get; } public PersonalTable8LA(IFileContainer file) { @@ -38,7 +39,7 @@ public PersonalTable8LA(IFileContainer file) Table = baseForms.Concat(formTable).ToArray(); } - private PersonalInfo8LA GetObj(PersonalInfoLAfb e, List forms, ushort max, List formTable, int f = 0) + private static PersonalInfo8LA GetObj(PersonalInfoLAfb e, ICollection forms, ushort max, ICollection formTable, int f = 0) { return new PersonalInfo8LA(e) { @@ -116,45 +117,43 @@ public void FixMissingData() Debug.Assert(l.DexIndexNational == s.DexIndexNational); if (l.HP == 0) - { l.SetPersonalInfo(s); - } if (l.FormCount == 1) continue; + var expectFormIndex = MaxSpeciesID + 1 + laFormCount; if (l.FormStatsIndex != 0) - Debug.Assert(l.FormStatsIndex == (MaxSpeciesID + 1) + laFormCount); + Debug.Assert(l.FormStatsIndex == expectFormIndex); - l.FormStatsIndex = (MaxSpeciesID + 1) + laFormCount; + l.FormStatsIndex = expectFormIndex; laFormCount += l.FormCount - 1; for (byte f = 1; f < l.FormCount; f++) { var formL = Table[l.FormStatsIndex + (f - 1)]; + if (formL.HP != 0) + continue; - if (formL.HP == 0) + // Check if SWSH table has form data for this entry + if (f < s.FormCount) { - // Check if SWSH table has form data for this entry - if (f < s.FormCount) + if (s.FormCount <= l.FormCount || (FormInfo.HasBattleOnlyForm(i) && !FormInfo.IsBattleOnlyForm(i, f, 8))) { - if (s.FormCount <= l.FormCount || (FormInfo.HasBattleOnlyForm(i) && !FormInfo.IsBattleOnlyForm(i, f, 8))) - { - var formS = ResourcesUtil.SWSH.GetFormEntry(i, f); + var formS = ResourcesUtil.SWSH.GetFormEntry(i, f); - Debug.Assert(formL.DexIndexNational == formS.DexIndexNational); - formL.SetPersonalInfo(formS); - } - } - else - { - // No form data was found, just write the base form data - formL.SetPersonalInfo(l); + Debug.Assert(formL.DexIndexNational == formS.DexIndexNational); + formL.SetPersonalInfo(formS); } } + else + { + // No form data was found, just write the base form data + formL.SetPersonalInfo(l); + } } } - Debug.WriteLine("Auto fix for PLA data succeded"); + Debug.WriteLine("Auto fix for PLA data succeeded"); } } diff --git a/pkNX.Structures/Personal/Table/PersonalTable8SWSH.cs b/pkNX.Structures/Personal/Table/PersonalTable8SWSH.cs index 3a98a0c6..8f35a664 100644 --- a/pkNX.Structures/Personal/Table/PersonalTable8SWSH.cs +++ b/pkNX.Structures/Personal/Table/PersonalTable8SWSH.cs @@ -143,6 +143,6 @@ public void FixMissingData() } } - Debug.WriteLine("Auto fix for SWSH data succeded"); + Debug.WriteLine("Auto fix for SWSH data succeeded"); } } diff --git a/pkNX.WinForms/MainEditor/EditorGG.cs b/pkNX.WinForms/MainEditor/EditorGG.cs index 92c723fc..f6239a67 100644 --- a/pkNX.WinForms/MainEditor/EditorGG.cs +++ b/pkNX.WinForms/MainEditor/EditorGG.cs @@ -12,8 +12,9 @@ namespace pkNX.WinForms.Controls; internal class EditorGG : EditorBase { - private GameData Data => ((GameManagerGG)ROM).Data; - protected internal EditorGG(GameManagerGG rom) : base(rom) { } + protected override GameManagerGG ROM { get; } + private GameData Data => ROM.Data; + protected internal EditorGG(GameManagerGG rom) => ROM = rom; public void EditCommon() { @@ -232,7 +233,7 @@ private void PopWildEdit(GameFile type) var data = file[0]; var obj = FlatBufferConverter.DeserializeFrom(data); - using var form = new GGWE((GameManagerGG)ROM, obj); + using var form = new GGWE(ROM, obj); if (form.ShowDialog() != DialogResult.OK) return; diff --git a/pkNX.WinForms/MainEditor/EditorPLA.cs b/pkNX.WinForms/MainEditor/EditorPLA.cs index abd5acd6..6b4aba1d 100644 --- a/pkNX.WinForms/MainEditor/EditorPLA.cs +++ b/pkNX.WinForms/MainEditor/EditorPLA.cs @@ -15,8 +15,13 @@ namespace pkNX.WinForms.Controls; internal class EditorPLA : EditorBase { - private GameData8a Data => ((GameManagerPLA)ROM).Data; - protected internal EditorPLA(GameManagerPLA rom) : base(rom) => CheckOodleDllPresence(); + protected override GameManagerPLA ROM { get; } + private GameData8a Data => ROM.Data; + protected internal EditorPLA(GameManagerPLA rom) + { + ROM = rom; + CheckOodleDllPresence(); + } private static void CheckOodleDllPresence() { @@ -329,13 +334,13 @@ public void EditMiscSpeciesInfo() public void EditMap_Viewer() { var resident = (GFPack)ROM.GetFile(GameFile.Resident); - using var form = new MapViewer8a((GameManagerPLA)ROM, resident); + using var form = new MapViewer8a(ROM, resident); form.ShowDialog(); } public void EditAreas() { - using var form = new AreaEditor8a((GameManagerPLA)ROM); + using var form = new AreaEditor8a(ROM); form.ShowDialog(); } @@ -396,7 +401,6 @@ public void EditPokemon() editor.Save(); } - public void PopFlatConfig(GameFile file, string title) { var obj = ROM.GetFile(file); // flatbuffer @@ -456,7 +460,7 @@ public void EditSymbolBehave() public void EditMasterDump() { - using var md = new DumperPLA((GameManagerPLA)ROM); + using var md = new DumperPLA(ROM); md.ShowDialog(); } } diff --git a/pkNX.WinForms/MainEditor/EditorProvider.cs b/pkNX.WinForms/MainEditor/EditorProvider.cs index fa7fb9b1..ce12609d 100644 --- a/pkNX.WinForms/MainEditor/EditorProvider.cs +++ b/pkNX.WinForms/MainEditor/EditorProvider.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Reflection; -using System.Text; using System.Windows.Forms; using pkNX.Game; using pkNX.Structures; @@ -10,53 +9,14 @@ namespace pkNX.WinForms.Controls; public abstract class EditorBase { - protected readonly GameManager ROM; + protected abstract GameManager ROM { get; } public GameVersion Game => ROM.Game; 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; private set; } public void Initialize() => ROM.Initialize(); - private static string GetEditorName(string name) - { - var newName = name.Replace('_', ' ').ToCharArray(); - var builder = new StringBuilder(); - - // Force first char to upper - newName[0] = char.ToUpper(newName[0]); - - for (int i = 0; i < newName.Length; ++i) - { - char c = newName[i]; - builder.Append(c); - - // Check the next char - if (i + 1 >= newName.Length) - continue; - char nextC = newName[i + 1]; - - // If current is space, replace next with upper char - if (c == ' ') - { - newName[i + 1] = char.ToUpper(nextC); - } - // If current is lower and next is upper, add a space in between - else if (char.IsLower(c) && char.IsUpper(nextC)) - { - builder.Append(' '); - } - // If previous is upper, current is upper and next is lower, add a space in between - else if (i + 2 < newName.Length && char.IsUpper(c) && char.IsUpper(nextC) && char.IsLower(newName[i + 2])) - { - builder.Append(' '); - } - } - return builder.ToString(); - } - public IEnumerable