Use correct boxdata buffer when doing box manip

Closes #2386 ; guess I forgot to finish this.
This commit is contained in:
Kurt 2019-09-12 19:01:06 -07:00
parent 81e27eff7c
commit dc10c057a0
2 changed files with 11 additions and 7 deletions

View file

@ -17,6 +17,8 @@ namespace PKHeX.Core
private readonly int GeneralBlockPosition; // Small Block private readonly int GeneralBlockPosition; // Small Block
private readonly int StorageBlockPosition; // Big Block private readonly int StorageBlockPosition; // Big Block
protected override byte[] StorageData => Storage;
protected SAV4() protected SAV4()
{ {
Data = BAK = Array.Empty<byte>(); Data = BAK = Array.Empty<byte>();

View file

@ -591,7 +591,7 @@ namespace PKHeX.Core
public int NextOpenBoxSlot(int lastKnownOccupied = -1) public int NextOpenBoxSlot(int lastKnownOccupied = -1)
{ {
var storage = Data; var storage = StorageData;
int count = BoxSlotCount * BoxCount; int count = BoxSlotCount * BoxCount;
for (int i = lastKnownOccupied + 1; i < count; i++) for (int i = lastKnownOccupied + 1; i < count; i++)
{ {
@ -652,6 +652,8 @@ namespace PKHeX.Core
#endregion #endregion
#region Storage Manipulations #region Storage Manipulations
protected virtual byte[] StorageData => Data;
public bool MoveBox(int box, int insertBeforeBox) public bool MoveBox(int box, int insertBeforeBox)
{ {
if (box == insertBeforeBox) // no movement required if (box == insertBeforeBox) // no movement required
@ -659,7 +661,7 @@ namespace PKHeX.Core
if (box >= BoxCount || insertBeforeBox >= BoxCount) // invalid box positions if (box >= BoxCount || insertBeforeBox >= BoxCount) // invalid box positions
return false; return false;
MoveBox(box, insertBeforeBox, Data); MoveBox(box, insertBeforeBox, StorageData);
return true; return true;
} }
@ -707,7 +709,7 @@ namespace PKHeX.Core
if (!IsBoxAbleToMove(box1) || !IsBoxAbleToMove(box2)) if (!IsBoxAbleToMove(box1) || !IsBoxAbleToMove(box2))
return false; return false;
SwapBox(box1, box2, Data); SwapBox(box1, box2, StorageData);
return true; return true;
} }
@ -785,7 +787,7 @@ namespace PKHeX.Core
/// <param name="storedCount">Count of actual <see cref="PKM"/> stored.</param> /// <param name="storedCount">Count of actual <see cref="PKM"/> stored.</param>
/// <param name="slotPointers">Important slot pointers that need to be repointed if a slot moves.</param> /// <param name="slotPointers">Important slot pointers that need to be repointed if a slot moves.</param>
/// <returns>True if <see cref="BoxData"/> was updated, false if no update done.</returns> /// <returns>True if <see cref="BoxData"/> was updated, false if no update done.</returns>
public bool CompressStorage(out int storedCount, params IList<int>[] slotPointers) => this.CompressStorage(Data, out storedCount, slotPointers); public bool CompressStorage(out int storedCount, params IList<int>[] slotPointers) => this.CompressStorage(StorageData, out storedCount, slotPointers);
/// <summary> /// <summary>
/// Removes all <see cref="PKM"/> present within the range specified by <see cref="BoxStart"/> and <see cref="BoxEnd"/> if the provied <see cref="deleteCriteria"/> is satisfied. /// Removes all <see cref="PKM"/> present within the range specified by <see cref="BoxStart"/> and <see cref="BoxEnd"/> if the provied <see cref="deleteCriteria"/> is satisfied.
@ -796,7 +798,7 @@ namespace PKHeX.Core
/// <returns>Count of deleted <see cref="PKM"/> slots.</returns> /// <returns>Count of deleted <see cref="PKM"/> slots.</returns>
public int ClearBoxes(int BoxStart = 0, int BoxEnd = -1, Func<PKM, bool> deleteCriteria = null) public int ClearBoxes(int BoxStart = 0, int BoxEnd = -1, Func<PKM, bool> deleteCriteria = null)
{ {
var storage = Data; var storage = StorageData;
if (BoxEnd < 0) if (BoxEnd < 0)
BoxEnd = BoxCount - 1; BoxEnd = BoxCount - 1;
@ -819,7 +821,7 @@ namespace PKHeX.Core
continue; continue;
} }
SetData(blank, ofs); SetData(storage, blank, ofs);
++deleted; ++deleted;
} }
} }
@ -835,7 +837,7 @@ namespace PKHeX.Core
/// <returns>Count of modified <see cref="PKM"/> slots.</returns> /// <returns>Count of modified <see cref="PKM"/> slots.</returns>
public int ModifyBoxes(Action<PKM> action, int BoxStart = 0, int BoxEnd = -1) public int ModifyBoxes(Action<PKM> action, int BoxStart = 0, int BoxEnd = -1)
{ {
var storage = Data; var storage = StorageData;
if (action == null) if (action == null)
throw new ArgumentException(nameof(action)); throw new ArgumentException(nameof(action));