pkNX/pkNX.Game/GameManagerGG.cs
sora10pls d231a411a0 Properly differentiate between SW/SH
Previous implementation did not work correctly for LGPE. If someone wishes to merge the wild encounter buttons again, make sure it works for all games before submitting a pull request. Also fixes LGPE wild editor using small sprites.

Closes #110
2021-03-04 14:43:21 -05:00

65 lines
2.5 KiB
C#

using System;
using System.IO;
using System.Linq;
using pkNX.Containers;
using pkNX.Structures;
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 GameVersion ActualGame => TitleID == "010003F003A34000" ? GameVersion.GP : GameVersion.GE;
private string TitleID => BitConverter.ToString(File.ReadAllBytes(Main).Skip(0x290).Take(0x08).Reverse().ToArray()).Replace("-", "");
protected override void SetMitm()
{
var basePath = Path.GetDirectoryName(ROM.RomFS);
var redirect = Path.Combine(basePath, TitleID);
FileMitm.SetRedirect(basePath, redirect);
}
protected override void Initialize()
{
// initialize gametext
GetFilteredFolder(GameFile.GameText, z => Path.GetExtension(z) == ".dat");
// initialize common structures
var personal = GetFilteredFolder(GameFile.PersonalStats, z => Path.GetFileNameWithoutExtension(z) == "personal_total");
Data = new GameData
{
MoveData = new DataCache<Move>(this[GameFile.MoveStats]) // mini
{
Create = z => new Move7(z),
Write = z => z.Write(),
},
LevelUpData = new DataCache<Learnset>(this[GameFile.Learnsets]) // gfpak
{
Create = z => new Learnset6(z),
Write = z => z.Write(),
},
// folders;
PersonalData = new PersonalTable(personal[0], Game),
MegaEvolutionData = new DataCache<MegaEvolutionSet[]>(GetFilteredFolder(GameFile.MegaEvolutions))
{
Create = MegaEvolutionSet.ReadArray,
Write = MegaEvolutionSet.WriteArray,
},
EvolutionData = new DataCache<EvolutionSet>(GetFilteredFolder(GameFile.Evolutions))
{
Create = (data) => new EvolutionSet7(data),
Write = evo => evo.Write(),
},
};
}
protected override void Terminate()
{
// Store Personal Data back in the file. Let the container detect if it is modified.
var personal = this[GameFile.PersonalStats];
personal[0] = Data.PersonalData.Table.SelectMany(z => z.Write()).ToArray();
}
}
}