diff --git a/PKHeX.Core/Saves/SAV3XD.cs b/PKHeX.Core/Saves/SAV3XD.cs index 9e00dea66..b9317db4a 100644 --- a/PKHeX.Core/Saves/SAV3XD.cs +++ b/PKHeX.Core/Saves/SAV3XD.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; namespace PKHeX.Core { @@ -198,8 +197,8 @@ public override string ChecksumInfo int newHC = BigEndian.ToInt32(data, start + subOffsets[0] + 0x38); bool header = newHC == oldHC; - var oldCHK = Data.Skip(0x10).Take(0x10); - var newCHK = data.Skip(0x10).Take(0x10); + var oldCHK = Data.AsSpan(0x10, 0x10); + var newCHK = data.AsSpan(0x10, 0x10); bool body = newCHK.SequenceEqual(oldCHK); return $"Header Checksum {(header ? "V" : "Inv")}alid, Body Checksum {(body ? "V" : "Inv")}alid."; } @@ -221,13 +220,17 @@ private static byte[] SetChecksums(byte[] input, int subOffset0) BigEndian.GetBytes(newHC).CopyTo(data, start + subOffset0 + 0x38); // Body Checksum - new byte[16].CopyTo(data, 0x10); // Clear old Checksum Data + data.AsSpan(0x10, 0x10).Fill(0); // Clear old Checksum Data uint[] checksum = new uint[4]; int dt = 8; - for (int i = 0; i < 4; i++) + for (int i = 0; i < checksum.Length; i++) { - for (int j = 0; j < 0x9FF4; j += 2, dt += 2) - checksum[i] += BigEndian.ToUInt16(data, dt); + uint val = 0; + var end = dt + 0x9FF4; + for (int j = dt; j < end; j += 2) + val += BigEndian.ToUInt16(data, j); + dt = end; + checksum[i] = val; } ushort[] newchks = new ushort[8]; diff --git a/PKHeX.Core/Saves/Substructures/Gen7/PokeListHeader.cs b/PKHeX.Core/Saves/Substructures/Gen7/PokeListHeader.cs index f116bf555..7871717c2 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/PokeListHeader.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/PokeListHeader.cs @@ -29,13 +29,20 @@ public sealed class PokeListHeader : SaveBlock public PokeListHeader(SAV7b sav, int offset) : base(sav) { Offset = offset; - PokeListInfo = LoadPointerData(); + var info = PokeListInfo = LoadPointerData(); if (!sav.State.Exportable) { for (int i = 0; i < COUNT; i++) - PokeListInfo[i] = SLOT_EMPTY; + info[i] = SLOT_EMPTY; + } + else + { + for (int i = 0; i < 6; i++) + { + if (info[i] < MAX_SLOTS) + ++_partyCount; + } } - PartyCount = PokeListInfo.Take(6).Count(z => z < MAX_SLOTS); } private int _partyCount; diff --git a/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs index ac82d4a20..5c086d9d1 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs @@ -552,7 +552,7 @@ public void InitializeDataSources() { ChangingFields = true; CB_HPType.InitializeBinding(); - CB_HPType.DataSource = Util.GetCBList(GameInfo.Strings.types.Skip(1).Take(16).ToArray()); + CB_HPType.DataSource = Util.GetCBList(GameInfo.Strings.types.AsSpan(1, 16)); ChangingFields = false; } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_BoxLayout.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_BoxLayout.cs index ddc2f1092..8b39e09f4 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_BoxLayout.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_BoxLayout.cs @@ -43,13 +43,13 @@ private bool LoadWallpaperNames() switch (SAV.Generation) { case 3 when SAV is SAV3: - CB_BG.Items.AddRange(GameInfo.Strings.wallpapernames.Take(16).ToArray()); + CB_BG.Items.AddRange(GameInfo.Strings.wallpapernames.Slice(0, 16)); return true; case 4 or 5 or 6: CB_BG.Items.AddRange(GameInfo.Strings.wallpapernames); return true; case 7: - CB_BG.Items.AddRange(GameInfo.Strings.wallpapernames.Take(16).ToArray()); + CB_BG.Items.AddRange(GameInfo.Strings.wallpapernames.Slice(0, 16)); return true; case 8: CB_BG.Items.AddRange(Enumerable.Range(1, 19).Select(z => $"Wallpaper {z}").ToArray()); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_HallOfFame.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_HallOfFame.cs index 8d3de2eb6..08c93108a 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_HallOfFame.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_HallOfFame.cs @@ -419,7 +419,7 @@ private void ChangeNickname(object sender, MouseEventArgs e) return; int offset = LB_DataEntry.SelectedIndex * 0x1B4; - var nicktrash = data.Skip(offset + 0x18).Take(24).ToArray(); + var nicktrash = data.Slice(offset + 0x18, 24); SAV.SetString(TB_Nickname.Text, 12).CopyTo(nicktrash, 0); var d = new TrashEditor(tb, nicktrash, SAV); d.ShowDialog(); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_ZygardeCell.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_ZygardeCell.cs index db57263b1..f06abc56e 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_ZygardeCell.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_ZygardeCell.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Windows.Forms; using PKHeX.Core; @@ -20,7 +19,7 @@ public SAV_ZygardeCell(SaveFile sav) // Cell Data @ 0x1D8C // Use constants 0x18C/2 = 198 thru +95 ushort[] constants = SAV.GetEventConsts(); - ushort[] cells = constants.Skip(celloffset).Take(CellCount).ToArray(); + ushort[] cells = constants.Slice(celloffset, CellCount); int cellCount = constants[cellstotal]; int cellCollected = constants[cellscollected];