From 6ff2aab80136a189eae20f6583299f353bd5b49f Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 13 Feb 2022 13:35:29 -0800 Subject: [PATCH] Add personal/learnset raw editor --- .../Arceus/Static/EventEncount8a.cs | 2 +- pkNX.WinForms/Dumping/DumperPLA.Designer.cs | 21 ++---- pkNX.WinForms/Dumping/DumperPLA.cs | 6 -- pkNX.WinForms/Dumping/GameDumperPLA.cs | 71 ++++--------------- pkNX.WinForms/MainEditor/EditorPLA.cs | 12 ++++ 5 files changed, 29 insertions(+), 83 deletions(-) diff --git a/pkNX.Structures.FlatBuffers/Arceus/Static/EventEncount8a.cs b/pkNX.Structures.FlatBuffers/Arceus/Static/EventEncount8a.cs index cdf11487..0517b304 100644 --- a/pkNX.Structures.FlatBuffers/Arceus/Static/EventEncount8a.cs +++ b/pkNX.Structures.FlatBuffers/Arceus/Static/EventEncount8a.cs @@ -17,5 +17,5 @@ public class EventEncount8a [FlatBufferItem(0)] public string EncounterName { get; set; } = string.Empty; [FlatBufferItem(1)] public string Field_01 { get; set; } = string.Empty; [FlatBufferItem(2)] public int Field_02 { get; set; } // All Entries have empty - [FlatBufferItem(3)] public EventEncountPoke8a[]? Table { get; set; } = Array.Empty(); + [FlatBufferItem(3)] public EventEncountPoke8a[] Table { get; set; } = Array.Empty(); } diff --git a/pkNX.WinForms/Dumping/DumperPLA.Designer.cs b/pkNX.WinForms/Dumping/DumperPLA.Designer.cs index a48ef26b..d1e9be9a 100644 --- a/pkNX.WinForms/Dumping/DumperPLA.Designer.cs +++ b/pkNX.WinForms/Dumping/DumperPLA.Designer.cs @@ -50,7 +50,6 @@ private void InitializeComponent() this.flowLayoutPanel3 = new System.Windows.Forms.FlowLayoutPanel(); this.B_DumpHash = new System.Windows.Forms.Button(); this.B_FlavorText = new System.Windows.Forms.Button(); - this.B_EggMove = new System.Windows.Forms.Button(); this.B_Dex = new System.Windows.Forms.Button(); this.B_Outbreak = new System.Windows.Forms.Button(); this.B_MoveShop = new System.Windows.Forms.Button(); @@ -277,7 +276,6 @@ private void InitializeComponent() // this.flowLayoutPanel3.Controls.Add(this.B_DumpHash); this.flowLayoutPanel3.Controls.Add(this.B_FlavorText); - this.flowLayoutPanel3.Controls.Add(this.B_EggMove); this.flowLayoutPanel3.Controls.Add(this.B_Dex); this.flowLayoutPanel3.Controls.Add(this.B_Outbreak); this.flowLayoutPanel3.Controls.Add(this.B_MoveShop); @@ -308,19 +306,9 @@ private void InitializeComponent() this.B_FlavorText.UseVisualStyleBackColor = true; this.B_FlavorText.Click += new System.EventHandler(this.B_FlavorText_Click); // - // B_EggMove - // - this.B_EggMove.Location = new System.Drawing.Point(261, 3); - this.B_EggMove.Name = "B_EggMove"; - this.B_EggMove.Size = new System.Drawing.Size(123, 55); - this.B_EggMove.TabIndex = 17; - this.B_EggMove.Text = "Egg Move Entries"; - this.B_EggMove.UseVisualStyleBackColor = true; - this.B_EggMove.Click += new System.EventHandler(this.B_EggMove_Click); - // // B_Dex // - this.B_Dex.Location = new System.Drawing.Point(3, 64); + this.B_Dex.Location = new System.Drawing.Point(261, 3); this.B_Dex.Name = "B_Dex"; this.B_Dex.Size = new System.Drawing.Size(123, 55); this.B_Dex.TabIndex = 18; @@ -330,7 +318,7 @@ private void InitializeComponent() // // B_Outbreak // - this.B_Outbreak.Location = new System.Drawing.Point(132, 64); + this.B_Outbreak.Location = new System.Drawing.Point(3, 64); this.B_Outbreak.Name = "B_Outbreak"; this.B_Outbreak.Size = new System.Drawing.Size(123, 55); this.B_Outbreak.TabIndex = 19; @@ -340,7 +328,7 @@ private void InitializeComponent() // // B_MoveShop // - this.B_MoveShop.Location = new System.Drawing.Point(261, 64); + this.B_MoveShop.Location = new System.Drawing.Point(132, 64); this.B_MoveShop.Name = "B_MoveShop"; this.B_MoveShop.Size = new System.Drawing.Size(123, 55); this.B_MoveShop.TabIndex = 20; @@ -350,7 +338,7 @@ private void InitializeComponent() // // B_ScriptCommandNames // - this.B_ScriptCommandNames.Location = new System.Drawing.Point(3, 125); + this.B_ScriptCommandNames.Location = new System.Drawing.Point(261, 64); this.B_ScriptCommandNames.Name = "B_ScriptCommandNames"; this.B_ScriptCommandNames.Size = new System.Drawing.Size(123, 55); this.B_ScriptCommandNames.TabIndex = 21; @@ -430,7 +418,6 @@ private void InitializeComponent() private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel3; private System.Windows.Forms.Button B_DumpHash; private System.Windows.Forms.Button B_FlavorText; - private System.Windows.Forms.Button B_EggMove; private System.Windows.Forms.Button B_OpenFolder; private System.Windows.Forms.TabPage Tab_Future; private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel4; diff --git a/pkNX.WinForms/Dumping/DumperPLA.cs b/pkNX.WinForms/Dumping/DumperPLA.cs index d9f45da7..a6100c42 100644 --- a/pkNX.WinForms/Dumping/DumperPLA.cs +++ b/pkNX.WinForms/Dumping/DumperPLA.cs @@ -134,12 +134,6 @@ private void B_FlavorText_Click(object sender, EventArgs e) Dumper.DumpFlavorText(); System.Media.SystemSounds.Asterisk.Play(); } - - private void B_EggMove_Click(object sender, EventArgs e) - { - Dumper.DumpEggEntries(); - System.Media.SystemSounds.Asterisk.Play(); - } #endregion } diff --git a/pkNX.WinForms/Dumping/GameDumperPLA.cs b/pkNX.WinForms/Dumping/GameDumperPLA.cs index 5241ce10..9f14633a 100644 --- a/pkNX.WinForms/Dumping/GameDumperPLA.cs +++ b/pkNX.WinForms/Dumping/GameDumperPLA.cs @@ -161,15 +161,15 @@ public void DumpAHTB() var pak = new GFPack(f); foreach (var bytes in pak.DecompressedFiles) { - if (AHTB.IsAHTB(bytes)) - { - var tbl = new AHTB(bytes); - var summaries = tbl.Summary; - foreach (var t in tbl.ShortSummary) - result.Add(t); - list.Add(Path.GetFileName(f)); - list.AddRange(summaries); - } + if (!AHTB.IsAHTB(bytes)) + continue; + + var tbl = new AHTB(bytes); + var summaries = tbl.Summary; + foreach (var t in tbl.ShortSummary) + result.Add(t); + list.Add(Path.GetFileName(f)); + list.AddRange(summaries); } for (var i = 0; i < pak.HashAbsolute.Length; i++) @@ -199,32 +199,6 @@ public void DumpAHTB() File.WriteAllLines(outname3, gf); } - public static Dictionary ReadAHTB(byte[] bytes) - { - if (!AHTB.IsAHTB(bytes)) - throw new ArgumentException(); - - var tbl = new AHTB(bytes); - return tbl.ToDictionary(); - } - - private TrainerEditor GetTrainerEditor() - { - var editor = new TrainerEditor - { - ReadClass = data => new TrainerClass8(data), - ReadPoke = data => new TrainerPoke8(data), - ReadTrainer = data => new TrainerData8(data), - ReadTeam = TrainerPoke8.ReadTeam, - WriteTeam = TrainerPoke8.WriteTeam, - TrainerData = ROM.GetFilteredFolder(GameFile.TrainerData), - TrainerPoke = ROM.GetFilteredFolder(GameFile.TrainerPoke), - TrainerClass = ROM.GetFilteredFolder(GameFile.TrainerClass), - }; - editor.Initialize(); - return editor; - } - public void DumpDrops() { var names = ROM.GetStrings(TextName.ItemNames); @@ -386,7 +360,7 @@ public void DumpStatic() File.WriteAllLines(fn, lines); var f2 = GetPath("StaticEncountersPKHeX.txt"); - File.WriteAllLines(f2, statics.Table.SelectMany(z => z.Table?.Select(x => x.Dump(speciesNames, z.EncounterName))).OrderBy(z => z)); + File.WriteAllLines(f2, statics.Table.SelectMany(z => z.Table.Select(x => x.Dump(speciesNames, z.EncounterName))).OrderBy(z => z)); } public void DumpWilds() @@ -791,8 +765,8 @@ int GetDexIndex(int species) for (var species = 0; species <= 980; species++) { - var entries = dexResearch.Table.Where(e => e.Species == species); - if (!entries.Any()) + var entries = Array.FindAll(dexResearch.Table, z => z.Species == species); + if (entries.Length == 0) continue; var dexInd = GetDexIndex(species); @@ -944,27 +918,6 @@ IEnumerable Zip(TextName name, TextName flavor) File.WriteAllLines(p3, l3); } - public void DumpEggEntries() - { - } - - public static byte[] GetDistributionContents(string path, out int index) - { - var archive = File.ReadAllBytes(path); - - // Validate Header - if (archive.Length < 0x20 || archive.Length != 4 + BitConverter.ToInt32(archive, 0x10) || BitConverter.ToInt32(archive, 0x8) != 0x20) - throw new ArgumentException(); - - index = archive[0]; - - // TODO: Eventually validate CRC16 over Data[:-4], CRC stored at Data[-4:] - - var data = new byte[archive.Length - 0x24]; - Array.Copy(archive, 0x20, data, 0, data.Length); - return data; - } - private static readonly string[] LanguageCodes = { "ja", "en", "fr", "it", "de", "es", "ko", "zh", "zh2" }; private static readonly string[] LanguageNames = diff --git a/pkNX.WinForms/MainEditor/EditorPLA.cs b/pkNX.WinForms/MainEditor/EditorPLA.cs index 3413f885..5042b577 100644 --- a/pkNX.WinForms/MainEditor/EditorPLA.cs +++ b/pkNX.WinForms/MainEditor/EditorPLA.cs @@ -201,6 +201,18 @@ void Randomize(IEnumerable arr) } } + public void EditPersonal_Raw() + { + var names = ROM.GetStrings(TextName.SpeciesNames); + PopFlat(GameFile.PersonalStats, "Personal Info Editor (Raw)", z => $"{names[z.Species]}{(z.Form == 0 ? "" : $"-{z.Form}")}"); + } + + public void EditLearnset_Raw() + { + var names = ROM.GetStrings(TextName.SpeciesNames); + PopFlat(GameFile.Learnsets, "Learnset Editor (Raw)", z => $"{names[z.Species]}{(z.Form == 0 ? "" : $"-{z.Form}")}"); + } + public void EditMiscSpeciesInfo() { var names = ROM.GetStrings(TextName.SpeciesNames);