From 2c233be43f2f550e447754e689ede640c4043ea3 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Thu, 21 Apr 2016 18:48:21 -0700 Subject: [PATCH] Refactoring No functional changes --- Legality/Core.cs | 4 ++-- Legality/Data.cs | 2 +- Misc/PKX.cs | 21 ++++++++++++--------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Legality/Core.cs b/Legality/Core.cs index f83ce25e9..6bab844ad 100644 --- a/Legality/Core.cs +++ b/Legality/Core.cs @@ -8,8 +8,8 @@ public static partial class Legal // PKHeX master Wonder Card Database internal static WC6[] WC6DB; // PKHeX master personal.dat - internal static readonly PersonalInfo[] PersonalAO = PersonalInfo.getPersonalArray(Properties.Resources.personal_ao, PersonalInfo.SizeAO); - private static readonly PersonalInfo[] PersonalXY = PersonalInfo.getPersonalArray(Properties.Resources.personal_xy, PersonalInfo.SizeXY); + internal static readonly PersonalInfo[] PersonalAO = PersonalInfo.getArray(Properties.Resources.personal_ao, PersonalInfo.SizeAO); + private static readonly PersonalInfo[] PersonalXY = PersonalInfo.getArray(Properties.Resources.personal_xy, PersonalInfo.SizeXY); private static readonly EggMoves[] EggMoveXY = EggMoves.getArray(Data.unpackMini(Properties.Resources.eggmove_xy, "xy")); private static readonly Learnset[] LevelUpXY = Learnset.getArray(Data.unpackMini(Properties.Resources.lvlmove_xy, "xy")); private static readonly EggMoves[] EggMoveAO = EggMoves.getArray(Data.unpackMini(Properties.Resources.eggmove_ao, "ao")); diff --git a/Legality/Data.cs b/Legality/Data.cs index af849bf03..d7d047386 100644 --- a/Legality/Data.cs +++ b/Legality/Data.cs @@ -344,7 +344,7 @@ public int RandomGender } public bool HasFormes => FormeCount > 1; - internal static PersonalInfo[] getPersonalArray(byte[] data, int size) + internal static PersonalInfo[] getArray(byte[] data, int size) { PersonalInfo[] d = new PersonalInfo[data.Length / size]; for (int i = 0; i < d.Length; i++) diff --git a/Misc/PKX.cs b/Misc/PKX.cs index d4f9bd107..394f125e0 100644 --- a/Misc/PKX.cs +++ b/Misc/PKX.cs @@ -556,20 +556,23 @@ internal static uint getRandomPID(int species, int cg, int origin, int nature, i // SAV Manipulation /// Calculates the CRC16-CCITT checksum over an input byte array. - /// Input byte array + /// Input byte array /// Checksum - internal static ushort ccitt16(byte[] chunk) + internal static ushort ccitt16(byte[] data) { - ushort crc = 0xFFFF; - foreach (byte t in chunk) + const ushort init = 0xFFFF; + const ushort poly = 0x1021; + + ushort crc = init; + foreach (byte b in data) { - crc ^= (ushort)(t << 8); + crc ^= (ushort)(b << 8); for (int j = 0; j < 8; j++) { - if ((crc & 0x8000) > 0) - crc = (ushort)(crc << 1 ^ 0x1021); - else - crc <<= 1; + bool flag = (crc & 0x8000) > 0; + crc <<= 1; + if (flag) + crc ^= poly; } } return crc;