Skip to content

Commit

Permalink
Fix gen3 save exporting
Browse files Browse the repository at this point in the history
Thanks BeyondTheHorizon!
  • Loading branch information
kwsch committed Jul 28, 2016
1 parent aa98fb1 commit e362a62
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion Saves/SAV3.cs
Expand Up @@ -57,7 +57,7 @@ public SAV3(byte[] data = null, GameVersion versionOverride = GameVersion.Any)

// Set up PC data buffer beyond end of save file.
Box = Data.Length;
Array.Resize(ref Data, Data.Length + 0x10000); // More than enough empty space.
Array.Resize(ref Data, Data.Length + SIZE_RESERVED); // More than enough empty space.

// Copy chunk to the allocated location
for (int i = 5; i < 14; i++)
Expand Down Expand Up @@ -109,6 +109,22 @@ public SAV3(byte[] data = null, GameVersion versionOverride = GameVersion.Any)
resetBoxes();
}

private const int SIZE_RESERVED = 0x10000; // unpacked box data
public override byte[] Write(bool DSV)
{
// Copy Box data back
for (int i = 5; i < 14; i++)
{
int blockIndex = Array.IndexOf(BlockOrder, i);
if (blockIndex == -1) // block empty
continue;
Array.Copy(Data, Box + (i - 5) * 0xF80, Data, blockIndex * 0x1000 + ABO, chunkLength[i]);
}

setChecksums();
return Data.Take(Data.Length - SIZE_RESERVED).ToArray();
}

private readonly int ActiveSAV;
private int ABO => ActiveSAV*0xE000;
private readonly int[] BlockOrder;
Expand Down
2 changes: 1 addition & 1 deletion Saves/SaveFile.cs
Expand Up @@ -32,7 +32,7 @@ public abstract class SaveFile
public ushort[] HeldItems { get; protected set; }

// General SAV Properties
public byte[] Write(bool DSV)
public virtual byte[] Write(bool DSV)
{
setChecksums();
if (Footer.Length > 0 && DSV)
Expand Down

0 comments on commit e362a62

Please sign in to comment.