diff --git a/pkNX.Game/File/GameFileMapping.cs b/pkNX.Game/File/GameFileMapping.cs index de156edc..9a94e4fb 100644 --- a/pkNX.Game/File/GameFileMapping.cs +++ b/pkNX.Game/File/GameFileMapping.cs @@ -63,8 +63,10 @@ public static IReadOnlyCollection GetMapping(GameVersion game GameVersion.XY => XY, GameVersion.GP => GG, GameVersion.GE => GG, + GameVersion.GG => GG, GameVersion.SW => SWSH, GameVersion.SH => SWSH, + GameVersion.SWSH => SWSH, GameVersion.ORASDEMO => AO, GameVersion.ORAS => AO, GameVersion.SMDEMO => SMDEMO, diff --git a/pkNX.Game/GameLocation.cs b/pkNX.Game/GameLocation.cs index 2ea577e4..e4e23911 100644 --- a/pkNX.Game/GameLocation.cs +++ b/pkNX.Game/GameLocation.cs @@ -46,7 +46,7 @@ public static GameLocation GetGame(string dir) var romfs = Array.Find(dirs, z => Path.GetFileName(z).StartsWith("rom", StringComparison.CurrentCultureIgnoreCase)); var exefs = Array.Find(dirs, z => Path.GetFileName(z).StartsWith("exe", StringComparison.CurrentCultureIgnoreCase)); - if (romfs == null || exefs == null) + if (romfs == null && exefs == null) return null; var files = Directory.GetFiles(romfs, "*", SearchOption.AllDirectories); @@ -70,8 +70,7 @@ public static GameLocation GetGame(string dir) private static GameVersion GetGameFromCount(int fileCount, string romfs, string exefs) { - string Main = Path.Combine(exefs, "main.npdm"); - string TitleID = BitConverter.ToString(File.ReadAllBytes(Main).Skip(0x290).Take(0x08).Reverse().ToArray()).Replace("-", ""); + string GetTitleID() => BitConverter.ToString(File.ReadAllBytes(Path.Combine(exefs, "main.npdm")).Skip(0x290).Take(0x08).Reverse().ToArray()).Replace("-", ""); switch (fileCount) { @@ -86,6 +85,7 @@ private static GameVersion GetGameFromCount(int fileCount, string romfs, string return GameVersion.SN; return GameVersion.MN; } + case FILECOUNT_USUM: { var encdata = Path.Combine(romfs, "a", "0", "8", "2"); @@ -95,13 +95,26 @@ private static GameVersion GetGameFromCount(int fileCount, string romfs, string } case FILECOUNT_GG: - return TitleID == "010003F003A34000" ? GameVersion.GP : GameVersion.GE; + { + if (exefs == null) + { + bool eevee = Directory.Exists(Path.Combine(romfs, "bin", "movies", "EEVEE_GO")); + if (eevee) + return GameVersion.GE; + return GameVersion.GP; + } + return GetTitleID() == "010003F003A34000" ? GameVersion.GP : GameVersion.GE; + } case FILECOUNT_SWSH: case FILECOUNT_SWSH_1: case FILECOUNT_SWSH_2: case FILECOUNT_SWSH_3: - return TitleID == "0100ABF008968000" ? GameVersion.SW : GameVersion.SH; + { + if (exefs == null) + return GameVersion.SWSH; + return GetTitleID() == "0100ABF008968000" ? GameVersion.SW : GameVersion.SH; + } default: return GameVersion.Invalid; diff --git a/pkNX.Game/GameManagerGG.cs b/pkNX.Game/GameManagerGG.cs index f66079d2..1949c6a7 100644 --- a/pkNX.Game/GameManagerGG.cs +++ b/pkNX.Game/GameManagerGG.cs @@ -9,12 +9,17 @@ namespace pkNX.Game public class GameManagerGG : GameManager { public GameManagerGG(GameLocation rom, int language) : base(rom, language) { } - private string Main => Path.Combine(PathExeFS, "main.npdm"); - private string TitleID => BitConverter.ToString(File.ReadAllBytes(Main).Skip(0x290).Take(0x08).Reverse().ToArray()).Replace("-", ""); + private GameVersion ActualGame; + private string TitleID => ActualGame == GameVersion.GP ? Pikachu : Eevee; + private const string Pikachu = "010003F003A34000"; + private const string Eevee = "0100187003A36000"; protected override void SetMitm() { var basePath = Path.GetDirectoryName(ROM.RomFS); + // unlike SWSH, LGPE has a unique opening movie in romfs to differentiate between versions + bool eevee = Directory.Exists(Path.Combine(PathRomFS, "bin", "movies", "EEVEE_GO")); + ActualGame = eevee ? GameVersion.GE : GameVersion.GP; var redirect = Path.Combine(basePath, TitleID); FileMitm.SetRedirect(basePath, redirect); } diff --git a/pkNX.Game/GameManagerSWSH.cs b/pkNX.Game/GameManagerSWSH.cs index 71864908..cd565124 100644 --- a/pkNX.Game/GameManagerSWSH.cs +++ b/pkNX.Game/GameManagerSWSH.cs @@ -9,12 +9,12 @@ namespace pkNX.Game public class GameManagerSWSH : GameManager { public GameManagerSWSH(GameLocation rom, int language) : base(rom, language) { } - private string Main => Path.Combine(PathExeFS, "main.npdm"); - private string TitleID => BitConverter.ToString(File.ReadAllBytes(Main).Skip(0x290).Take(0x08).Reverse().ToArray()).Replace("-", ""); + private string GetTitleID() => BitConverter.ToString(File.ReadAllBytes(Path.Combine(PathExeFS, "main.npdm")).Skip(0x290).Take(0x08).Reverse().ToArray()).Replace("-", ""); protected override void SetMitm() { var basePath = Path.GetDirectoryName(ROM.RomFS); + var TitleID = PathExeFS != null ? GetTitleID() : "0100ABF008968000"; // no way to differentiate without exefs, so default to Sword var redirect = Path.Combine(basePath, TitleID); FileMitm.SetRedirect(basePath, redirect); } diff --git a/pkNX.WinForms/MainEditor/EditorSWSH.cs b/pkNX.WinForms/MainEditor/EditorSWSH.cs index c63b2279..af605df8 100644 --- a/pkNX.WinForms/MainEditor/EditorSWSH.cs +++ b/pkNX.WinForms/MainEditor/EditorSWSH.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Windows.Forms; using pkNX.Containers; using pkNX.Game; using pkNX.Randomization; @@ -186,7 +187,18 @@ public void NotWorking_EditTypeChart() FileMitm.WriteAllBytes(path, data); } - public void EditWild() => PopWildEdit(ROM.Game == GameVersion.SW ? "k" : "t"); + public void EditWild() + { + if (ROM.PathExeFS == null) + { + var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, "No ExeFS data found. Please choose which game's encounter tables you wish to edit.", "Yes for Sword, No for Shield."); + if (dr == DialogResult.Cancel) + return; + PopWildEdit(dr == DialogResult.Yes ? "k" : "t"); + } + else + PopWildEdit(ROM.Game == GameVersion.SW ? "k" : "t"); + } private void PopWildEdit(string file) {