mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-12 11:55:15 -05:00
Clean up memcard handling a little
This commit is contained in:
@@ -58,8 +58,6 @@ public static bool IsMemoryCardSize(byte[] Data)
|
||||
return true;
|
||||
}
|
||||
|
||||
private static readonly byte[] RawEmpty_DEntry = { 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
|
||||
// Control blocks
|
||||
private const int Header_Block = 0;
|
||||
private const int Directory_Block = 1;
|
||||
@@ -220,13 +218,11 @@ public GCMemoryCardState GetMemoryCardState()
|
||||
? DirectoryBackup_Block
|
||||
: Directory_Block;
|
||||
|
||||
string Empty_DEntry = EncodingType.GetString(RawEmpty_DEntry, 0, 4);
|
||||
// Search for pokemon savegames in the directory
|
||||
for (int i = 0; i < NumEntries_Directory; i++)
|
||||
{
|
||||
int offset = (DirectoryBlock_Used * BLOCK_SIZE) + (i * DENTRY_SIZE);
|
||||
string GameCode = EncodingType.GetString(Data, offset, 4);
|
||||
if (GameCode == Empty_DEntry)
|
||||
if (BitConverter.ToUInt32(Data, offset) == uint.MaxValue) // empty entry
|
||||
continue;
|
||||
|
||||
int FirstBlock = BigEndian.ToUInt16(Data, offset + 0x36);
|
||||
@@ -236,7 +232,8 @@ public GCMemoryCardState GetMemoryCardState()
|
||||
if (FirstBlock + BlockCount > NumBlocks)
|
||||
continue;
|
||||
|
||||
var ver = SaveHandlerGCI.GetGameCode(GameCode);
|
||||
var gameCode = EncodingType.GetString(Data, offset, 4);
|
||||
var ver = SaveHandlerGCI.GetGameCode(gameCode);
|
||||
if (ver == GameVersion.COLO)
|
||||
{
|
||||
if (HasCOLO) // another entry already exists
|
||||
|
||||
@@ -574,14 +574,15 @@ private static GameVersion GetIsG8SAV(byte[] data)
|
||||
public static SaveFile? GetVariantSAV(SAV3GCMemoryCard memCard)
|
||||
{
|
||||
// Pre-check for header/footer signatures
|
||||
SaveFile sav;
|
||||
byte[] data = memCard.SelectedSaveData;
|
||||
var split = DolphinHandler.TrySplit(data);
|
||||
if (split == null)
|
||||
if (data.Length == 0)
|
||||
return null;
|
||||
|
||||
data = split.Data;
|
||||
var split = DolphinHandler.TrySplit(data);
|
||||
if (split != null)
|
||||
data = split.Data;
|
||||
|
||||
SaveFile sav;
|
||||
switch (memCard.SelectedGameVersion)
|
||||
{
|
||||
// Side Games
|
||||
@@ -593,7 +594,8 @@ private static GameVersion GetIsG8SAV(byte[] data)
|
||||
default: return null;
|
||||
}
|
||||
|
||||
sav.Metadata.SetExtraInfo(split.Header, split.Footer);
|
||||
if (split != null)
|
||||
sav.Metadata.SetExtraInfo(split.Header, split.Footer);
|
||||
return sav;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user