mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00:00
Replace MC->MemoryCard
Simplify some interactions to be more clear
This commit is contained in:
parent
5a769312fd
commit
de8e855116
8 changed files with 45 additions and 46 deletions
|
@ -14,8 +14,7 @@ namespace PKHeX.Core
|
|||
public override string Extension => this.GCExtension();
|
||||
public override PersonalTable Personal => PersonalTable.RS;
|
||||
public override IReadOnlyList<ushort> HeldItems => Legal.HeldItems_COLO;
|
||||
public bool IsMemoryCardSave => MC != null;
|
||||
private readonly SAV3GCMemoryCard? MC;
|
||||
public SAV3GCMemoryCard? MemoryCard { get; }
|
||||
|
||||
// 3 Save files are stored
|
||||
// 0x0000-0x6000 contains memory card data
|
||||
|
@ -34,7 +33,7 @@ namespace PKHeX.Core
|
|||
private readonly StrategyMemo StrategyMemo;
|
||||
public const int MaxShadowID = 0x80; // 128
|
||||
private int Memo;
|
||||
public SAV3Colosseum(byte[] data, SAV3GCMemoryCard MC) : this(data, MC.Data) { this.MC = MC; }
|
||||
public SAV3Colosseum(byte[] data, SAV3GCMemoryCard memCard) : this(data, memCard.Data) => MemoryCard = memCard;
|
||||
public SAV3Colosseum(byte[] data) : this(data, (byte[])data.Clone()) { }
|
||||
|
||||
public SAV3Colosseum() : base(SaveUtil.SIZE_G3COLO)
|
||||
|
@ -102,11 +101,11 @@ namespace PKHeX.Core
|
|||
var newFile = GetInnerData();
|
||||
|
||||
// Return the gci if Memory Card is not being exported
|
||||
if (!IsMemoryCardSave)
|
||||
if (MemoryCard is null)
|
||||
return newFile;
|
||||
|
||||
MC!.SelectedSaveData = newFile;
|
||||
return MC.Data;
|
||||
MemoryCard.WriteSaveGameData(newFile);
|
||||
return MemoryCard.Data;
|
||||
}
|
||||
|
||||
private byte[] GetInnerData()
|
||||
|
@ -119,7 +118,7 @@ namespace PKHeX.Core
|
|||
byte[] newSAV = EncryptColosseum(Data, digest);
|
||||
|
||||
// Put save slot back in original save data
|
||||
byte[] newFile = MC != null ? MC.SelectedSaveData : (byte[]) State.BAK.Clone();
|
||||
byte[] newFile = MemoryCard != null ? MemoryCard.ReadSaveGameData() : (byte[]) State.BAK.Clone();
|
||||
Array.Copy(newSAV, 0, newFile, SLOT_START + (SaveIndex * SLOT_SIZE), newSAV.Length);
|
||||
return newFile;
|
||||
}
|
||||
|
@ -128,7 +127,7 @@ namespace PKHeX.Core
|
|||
protected override SaveFile CloneInternal()
|
||||
{
|
||||
var data = GetInnerData();
|
||||
var sav = IsMemoryCardSave ? new SAV3Colosseum(data, MC!) : new SAV3Colosseum(data);
|
||||
var sav = MemoryCard is not null ? new SAV3Colosseum(data, MemoryCard) : new SAV3Colosseum(data);
|
||||
return sav;
|
||||
}
|
||||
|
||||
|
|
|
@ -304,7 +304,6 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
public string GCISaveName => GCISaveGameName();
|
||||
public byte[] SelectedSaveData { get => ReadSaveGameData(); set => WriteSaveGameData(value); }
|
||||
public readonly byte[] Data;
|
||||
|
||||
private string GCISaveGameName()
|
||||
|
@ -317,7 +316,7 @@ namespace PKHeX.Core
|
|||
return $"{Makercode}-{GameCode}-{Util.TrimFromZero(FileName)}.gci";
|
||||
}
|
||||
|
||||
private byte[] ReadSaveGameData()
|
||||
public byte[] ReadSaveGameData()
|
||||
{
|
||||
if (EntrySelected < 0)
|
||||
return Array.Empty<byte>(); // No entry selected
|
||||
|
@ -332,7 +331,7 @@ namespace PKHeX.Core
|
|||
return SaveData;
|
||||
}
|
||||
|
||||
private void WriteSaveGameData(byte[] SaveData)
|
||||
public void WriteSaveGameData(byte[] SaveData)
|
||||
{
|
||||
if (EntrySelected < 0) // Can't write anywhere
|
||||
return;
|
||||
|
|
|
@ -13,11 +13,10 @@ namespace PKHeX.Core
|
|||
public override string Extension => this.GCExtension();
|
||||
public override PersonalTable Personal => PersonalTable.RS;
|
||||
public override IReadOnlyList<ushort> HeldItems => Legal.HeldItems_RS;
|
||||
public bool IsMemoryCardSave => MC != null;
|
||||
private readonly SAV3GCMemoryCard? MC;
|
||||
public SAV3GCMemoryCard? MemoryCard { get; }
|
||||
public readonly bool Japanese = false; // todo?
|
||||
|
||||
public SAV3RSBox(byte[] data, SAV3GCMemoryCard MC) : this(data, MC.Data) { this.MC = MC; }
|
||||
public SAV3RSBox(byte[] data, SAV3GCMemoryCard memCard) : this(data, memCard.Data) => MemoryCard = memCard;
|
||||
public SAV3RSBox(byte[] data) : this(data, (byte[])data.Clone()) { }
|
||||
|
||||
public SAV3RSBox() : base(SaveUtil.SIZE_G3BOX)
|
||||
|
@ -74,11 +73,11 @@ namespace PKHeX.Core
|
|||
var newFile = GetInnerData();
|
||||
|
||||
// Return the gci if Memory Card is not being exported
|
||||
if (!IsMemoryCardSave)
|
||||
if (MemoryCard is null)
|
||||
return newFile;
|
||||
|
||||
MC!.SelectedSaveData = newFile;
|
||||
return MC.Data;
|
||||
MemoryCard.WriteSaveGameData(newFile);
|
||||
return MemoryCard.Data;
|
||||
}
|
||||
|
||||
private byte[] GetInnerData()
|
||||
|
@ -97,7 +96,7 @@ namespace PKHeX.Core
|
|||
protected override SaveFile CloneInternal()
|
||||
{
|
||||
var data = GetInnerData();
|
||||
var sav = IsMemoryCardSave ? new SAV3RSBox(data, MC!) : new SAV3RSBox(data);
|
||||
var sav = MemoryCard is not null ? new SAV3RSBox(data, MemoryCard) : new SAV3RSBox(data);
|
||||
return sav;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,7 @@ namespace PKHeX.Core
|
|||
{
|
||||
protected internal override string ShortSummary => $"{OT} ({Version}) #{SaveCount:0000}";
|
||||
public override string Extension => this.GCExtension();
|
||||
public bool IsMemoryCardSave => MC != null;
|
||||
private readonly SAV3GCMemoryCard? MC;
|
||||
public SAV3GCMemoryCard? MemoryCard { get; }
|
||||
|
||||
private const int SLOT_SIZE = 0x28000;
|
||||
private const int SLOT_START = 0x6000;
|
||||
|
@ -27,7 +26,7 @@ namespace PKHeX.Core
|
|||
public int MaxShadowID => ShadowInfo.Count;
|
||||
private int OFS_PouchHeldItem, OFS_PouchKeyItem, OFS_PouchBalls, OFS_PouchTMHM, OFS_PouchBerry, OFS_PouchCologne, OFS_PouchDisc;
|
||||
private readonly int[] subOffsets = new int[16];
|
||||
public SAV3XD(byte[] data, SAV3GCMemoryCard MC) : this(data, MC.Data) { this.MC = MC; }
|
||||
public SAV3XD(byte[] data, SAV3GCMemoryCard memCard) : this(data, memCard.Data) => MemoryCard = memCard;
|
||||
public SAV3XD(byte[] data) : this(data, (byte[])data.Clone()) { }
|
||||
|
||||
public SAV3XD() : base(SaveUtil.SIZE_G3XD)
|
||||
|
@ -121,11 +120,11 @@ namespace PKHeX.Core
|
|||
var newFile = GetInnerData();
|
||||
|
||||
// Return the gci if Memory Card is not being exported
|
||||
if (!IsMemoryCardSave)
|
||||
if (MemoryCard is null)
|
||||
return newFile;
|
||||
|
||||
MC!.SelectedSaveData = newFile;
|
||||
return MC.Data;
|
||||
MemoryCard.WriteSaveGameData(newFile);
|
||||
return MemoryCard.Data;
|
||||
}
|
||||
|
||||
private byte[] GetInnerData()
|
||||
|
@ -142,7 +141,7 @@ namespace PKHeX.Core
|
|||
byte[] newSAV = GeniusCrypto.Encrypt(Data, 0x10, 0x27FD8, keys);
|
||||
|
||||
// Put save slot back in original save data
|
||||
byte[] newFile = MC != null ? MC.SelectedSaveData : (byte[]) State.BAK.Clone();
|
||||
byte[] newFile = MemoryCard != null ? MemoryCard.ReadSaveGameData() : (byte[]) State.BAK.Clone();
|
||||
Array.Copy(newSAV, 0, newFile, SLOT_START + (SaveIndex * SLOT_SIZE), newSAV.Length);
|
||||
return newFile;
|
||||
}
|
||||
|
@ -151,7 +150,7 @@ namespace PKHeX.Core
|
|||
protected override SaveFile CloneInternal()
|
||||
{
|
||||
var data = GetInnerData();
|
||||
var sav = IsMemoryCardSave ? new SAV3XD(data, MC!) : new SAV3XD(data);
|
||||
var sav = MemoryCard is not null ? new SAV3XD(data, MemoryCard) : new SAV3XD(data);
|
||||
return sav;
|
||||
}
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace PKHeX.Core
|
|||
var flags = ExportFlags.None;
|
||||
if (ext == ".dsv")
|
||||
flags |= ExportFlags.IncludeFooter;
|
||||
if (ext == ".gci" || SAV is IGCSaveFile {IsMemoryCardSave: false})
|
||||
if (ext == ".gci" || SAV is IGCSaveFile {MemoryCard: null})
|
||||
flags |= ExportFlags.IncludeHeader;
|
||||
return flags;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
/// </summary>
|
||||
public interface IGCSaveFile
|
||||
{
|
||||
bool IsMemoryCardSave { get; }
|
||||
/// <summary>
|
||||
/// GameCube Memory Card the save file was read from.
|
||||
/// </summary>
|
||||
SAV3GCMemoryCard? MemoryCard { get; }
|
||||
}
|
||||
|
||||
public static class GCSaveExtensions
|
||||
|
@ -17,12 +20,12 @@
|
|||
{
|
||||
const string regular = "GameCube Save File|*.gci|All Files|*.*";
|
||||
const string memcard = "Memory Card Raw File|*.raw|Memory Card Binary File|*.bin|";
|
||||
return gc.IsMemoryCardSave ? memcard + regular : regular;
|
||||
return gc.MemoryCard is not null ? memcard + regular : regular;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the export extension for a GameCube file.
|
||||
/// </summary>
|
||||
public static string GCExtension(this IGCSaveFile gc) => gc.IsMemoryCardSave ? ".raw" : ".gci";
|
||||
public static string GCExtension(this IGCSaveFile gc) => gc.MemoryCard is not null ? ".raw" : ".gci";
|
||||
}
|
||||
}
|
|
@ -607,7 +607,7 @@ namespace PKHeX.Core
|
|||
public static SaveFile? GetVariantSAV(SAV3GCMemoryCard memCard)
|
||||
{
|
||||
// Pre-check for header/footer signatures
|
||||
byte[] data = memCard.SelectedSaveData;
|
||||
byte[] data = memCard.ReadSaveGameData();
|
||||
if (data.Length == 0)
|
||||
return null;
|
||||
|
||||
|
|
|
@ -676,24 +676,24 @@ namespace PKHeX.WinForms
|
|||
return true;
|
||||
}
|
||||
|
||||
private static GameVersion SelectMemoryCardSaveGame(SAV3GCMemoryCard MC)
|
||||
private static GameVersion SelectMemoryCardSaveGame(SAV3GCMemoryCard memCard)
|
||||
{
|
||||
if (MC.SaveGameCount == 1)
|
||||
return MC.SelectedGameVersion;
|
||||
if (memCard.SaveGameCount == 1)
|
||||
return memCard.SelectedGameVersion;
|
||||
|
||||
var games = new List<ComboItem>();
|
||||
if (MC.HasCOLO) games.Add(new ComboItem(MsgGameColosseum, (int)GameVersion.COLO));
|
||||
if (MC.HasXD) games.Add(new ComboItem(MsgGameXD, (int)GameVersion.XD));
|
||||
if (MC.HasRSBOX) games.Add(new ComboItem(MsgGameRSBOX, (int)GameVersion.RSBOX));
|
||||
if (memCard.HasCOLO) games.Add(new ComboItem(MsgGameColosseum, (int)GameVersion.COLO));
|
||||
if (memCard.HasXD) games.Add(new ComboItem(MsgGameXD, (int)GameVersion.XD));
|
||||
if (memCard.HasRSBOX) games.Add(new ComboItem(MsgGameRSBOX, (int)GameVersion.RSBOX));
|
||||
|
||||
var dialog = new SAV_GameSelect(games, MsgFileLoadSaveMultiple, MsgFileLoadSaveSelectGame);
|
||||
dialog.ShowDialog();
|
||||
return dialog.Result;
|
||||
}
|
||||
|
||||
private static bool CheckGCMemoryCard(SAV3GCMemoryCard MC, string path)
|
||||
private static bool CheckGCMemoryCard(SAV3GCMemoryCard memCard, string path)
|
||||
{
|
||||
var state = MC.GetMemoryCardState();
|
||||
var state = memCard.GetMemoryCardState();
|
||||
switch (state)
|
||||
{
|
||||
case GCMemoryCardState.NoPkmSaveGame:
|
||||
|
@ -708,18 +708,18 @@ namespace PKHeX.WinForms
|
|||
|
||||
case GCMemoryCardState.MultipleSaveGame:
|
||||
{
|
||||
GameVersion Game = SelectMemoryCardSaveGame(MC);
|
||||
if (Game == GameVersion.Invalid) //Cancel
|
||||
GameVersion game = SelectMemoryCardSaveGame(memCard);
|
||||
if (game == GameVersion.Invalid) //Cancel
|
||||
return false;
|
||||
MC.SelectSaveGame(Game);
|
||||
memCard.SelectSaveGame(game);
|
||||
break;
|
||||
}
|
||||
case GCMemoryCardState.SaveGameCOLO: MC.SelectSaveGame(GameVersion.COLO); break;
|
||||
case GCMemoryCardState.SaveGameXD: MC.SelectSaveGame(GameVersion.XD); break;
|
||||
case GCMemoryCardState.SaveGameRSBOX: MC.SelectSaveGame(GameVersion.RSBOX); break;
|
||||
case GCMemoryCardState.SaveGameCOLO: memCard.SelectSaveGame(GameVersion.COLO); break;
|
||||
case GCMemoryCardState.SaveGameXD: memCard.SelectSaveGame(GameVersion.XD); break;
|
||||
case GCMemoryCardState.SaveGameRSBOX: memCard.SelectSaveGame(GameVersion.RSBOX); break;
|
||||
|
||||
default:
|
||||
WinFormsUtil.Error(!SaveUtil.IsSizeValid(MC.Data.Length) ? MsgFileGameCubeBad : MsgFileLoadSaveLoadFail, path);
|
||||
WinFormsUtil.Error(!SaveUtil.IsSizeValid(memCard.Data.Length) ? MsgFileGameCubeBad : MsgFileLoadSaveLoadFail, path);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue