Better handling of ROM dumps without ExeFS

pkNX will now prompt the user to select a version before opening the wild editor, should no ExeFS data exist to determine which game is currently loaded.
This commit is contained in:
sora10pls
2021-04-20 12:47:39 -04:00
parent e772a99341
commit ae42c5ea45
5 changed files with 42 additions and 10 deletions

View File

@@ -63,8 +63,10 @@ public static IReadOnlyCollection<GameFileReference> 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,

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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)
{