Fix clearing of clones (off by 1 last box)

Clamp end box in the clear/modify actions too, just in case.
This commit is contained in:
Kurt 2022-08-05 11:24:54 -07:00
parent 999caedf6e
commit 94668b4672
3 changed files with 5 additions and 5 deletions

View file

@ -1,9 +1,9 @@
namespace PKHeX.Core;
namespace PKHeX.Core;
/// <summary>
/// Criteria for manipulating box data.
/// </summary>
/// <param name="Start">Box to start at (inclusive)</param>
/// <param name="Stop">Box to stop at (exclusive)</param>
/// <param name="Stop">Box to stop after (inclusive)</param>
/// <param name="Reverse">Iterate in reverse</param>
public readonly record struct BoxManipParam(int Start, int Stop, bool Reverse = false);

View file

@ -741,7 +741,7 @@ public abstract class SaveFile : ITrainerInfo, IGameValueLimit, IBoxDetailWallpa
{
var storage = BoxBuffer.AsSpan();
if (BoxEnd < 0)
if ((uint)BoxEnd >= BoxCount)
BoxEnd = BoxCount - 1;
var blank = GetDataForBox(BlankPKM);
@ -778,7 +778,7 @@ public abstract class SaveFile : ITrainerInfo, IGameValueLimit, IBoxDetailWallpa
/// <returns>Count of modified <see cref="PKM"/> slots.</returns>
public int ModifyBoxes(Action<PKM> action, int BoxStart = 0, int BoxEnd = -1)
{
if (BoxEnd < 0)
if ((uint)BoxEnd >= BoxCount)
BoxEnd = BoxCount - 1;
var storage = BoxBuffer.AsSpan();

View file

@ -681,7 +681,7 @@ public partial class SAV_Database : Form
}
var boxClear = new BoxManipClearDuplicate<string>(BoxManipType.DeleteClones, pk => SearchUtil.GetCloneDetectMethod(method)(pk));
var param = new BoxManipParam(0, SAV.BoxCount);
var param = new BoxManipParam(0, SAV.BoxCount - 1);
int count = boxClear.Execute(SAV, param);
deleted += count;