Fix memcard sav cloning

Closes #2267 , Thanks @PMArkive && @Subject21J !
This commit is contained in:
Kurt 2019-03-07 18:05:55 -08:00
parent bd00680545
commit 0d5ee9489b
3 changed files with 60 additions and 25 deletions

View file

@ -109,6 +109,18 @@ namespace PKHeX.Core
}
protected override byte[] GetFinalData()
{
var newFile = GetInnerData();
// Return the gci if Memory Card is not being exported
if (!IsMemoryCardSave)
return newFile;
MC.SelectedSaveData = newFile;
return MC.Data;
}
private byte[] GetInnerData()
{
StrategyMemo.FinalData.CopyTo(Data, Memo);
SetChecksums();
@ -120,17 +132,17 @@ namespace PKHeX.Core
// Put save slot back in original save data
byte[] newFile = MC != null ? MC.SelectedSaveData : (byte[])BAK.Clone();
Array.Copy(newSAV, 0, newFile, SLOT_START + (SaveIndex * SLOT_SIZE), newSAV.Length);
// Return the gci if Memory Card is not being exported
if (!IsMemoryCardSave)
return newFile;
MC.SelectedSaveData = newFile;
return MC.Data;
return newFile;
}
// Configuration
public override SaveFile Clone() => new SAV3Colosseum(Write()) {Header = (byte[]) Header.Clone()};
public override SaveFile Clone()
{
var data = GetInnerData();
var sav = IsMemoryCardSave ? new SAV3Colosseum(data, MC) : new SAV3Colosseum(data);
sav.Header = (byte[])Header.Clone();
return sav;
}
public override int SIZE_STORED => PKX.SIZE_3CSTORED;
protected override int SIZE_PARTY => PKX.SIZE_3CSTORED; // unused

View file

@ -62,14 +62,7 @@ namespace PKHeX.Core
protected override byte[] GetFinalData()
{
// Copy Box data back
const int copySize = BLOCK_SIZE - 0x10;
foreach (var b in Blocks)
Array.Copy(Data, (int)(Box + (b.ID * copySize)), Data, b.Offset + 0xC, copySize);
SetChecksums();
byte[] newFile = GetData(0, Data.Length - SIZE_RESERVED);
var newFile = GetInnerData();
// Return the gci if Memory Card is not being exported
if (!IsMemoryCardSave)
@ -79,8 +72,26 @@ namespace PKHeX.Core
return MC.Data;
}
private byte[] GetInnerData()
{
// Copy Box data back
const int copySize = BLOCK_SIZE - 0x10;
foreach (var b in Blocks)
Array.Copy(Data, (int) (Box + (b.ID * copySize)), Data, b.Offset + 0xC, copySize);
SetChecksums();
return GetData(0, Data.Length - SIZE_RESERVED);
}
// Configuration
public override SaveFile Clone() => new SAV3RSBox(Write()) {Header = (byte[]) Header.Clone()};
public override SaveFile Clone()
{
var data = GetInnerData();
var sav = IsMemoryCardSave ? new SAV3RSBox(data, MC) : new SAV3RSBox(data);
sav.Header = (byte[])Header.Clone();
return sav;
}
public override int SIZE_STORED => PKX.SIZE_3STORED + 4;
protected override int SIZE_PARTY => PKX.SIZE_3PARTY; // unused

View file

@ -115,6 +115,18 @@ namespace PKHeX.Core
}
protected override byte[] GetFinalData()
{
var newFile = GetInnerData();
// Return the gci if Memory Card is not being exported
if (!IsMemoryCardSave)
return newFile;
MC.SelectedSaveData = newFile;
return MC.Data;
}
private byte[] GetInnerData()
{
// Set Memo Back
StrategyMemo.FinalData.CopyTo(Data, Memo);
@ -130,17 +142,17 @@ namespace PKHeX.Core
// Put save slot back in original save data
byte[] newFile = MC != null ? MC.SelectedSaveData : (byte[])BAK.Clone();
Array.Copy(newSAV, 0, newFile, SLOT_START + (SaveIndex * SLOT_SIZE), newSAV.Length);
// Return the gci if Memory Card is not being exported
if (!IsMemoryCardSave)
return newFile;
MC.SelectedSaveData = newFile;
return MC.Data;
return newFile;
}
// Configuration
public override SaveFile Clone() => new SAV3XD(Write()) {Header = (byte[]) Header.Clone()};
public override SaveFile Clone()
{
var data = GetInnerData();
var sav = IsMemoryCardSave ? new SAV3XD(data, MC) : new SAV3XD(data);
sav.Header = (byte[]) Header.Clone();
return sav;
}
public override int SIZE_STORED => PKX.SIZE_3XSTORED;
protected override int SIZE_PARTY => PKX.SIZE_3XSTORED; // unused