From 40c2c483fb7b4662356feafd3c646cf0a657d95b Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 18 Jan 2020 14:19:01 -0800 Subject: [PATCH] Common1-3 => Bool1-3 Blocks that use Bool1/2 toggle to the other state; evident when comparing between two different saves. The key doesn't change, only the Type is toggled. --- PKHeX.Core/Saves/MemeCrypto/SwishCrypto.cs | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/PKHeX.Core/Saves/MemeCrypto/SwishCrypto.cs b/PKHeX.Core/Saves/MemeCrypto/SwishCrypto.cs index d506c9738..778154b3f 100644 --- a/PKHeX.Core/Saves/MemeCrypto/SwishCrypto.cs +++ b/PKHeX.Core/Saves/MemeCrypto/SwishCrypto.cs @@ -279,9 +279,9 @@ private int GetEncryptedDataSize() const int size = 4 + 1; // key + type switch (Type) { - case SCTypeCode.Common1: - case SCTypeCode.Common2: - case SCTypeCode.Common3: + case SCTypeCode.Bool1: + case SCTypeCode.Bool2: + case SCTypeCode.Bool3: return size; case SCTypeCode.Object: return size + 4 + Data.Length; @@ -351,9 +351,9 @@ public static SCBlock ReadFromOffset(byte[] data, ref int offset) switch (block.Type) { - case SCTypeCode.Common1: - case SCTypeCode.Common2: - case SCTypeCode.Common3: + case SCTypeCode.Bool1: + case SCTypeCode.Bool2: + case SCTypeCode.Bool3: // Block types are empty, and have no extra data. offset++; break; @@ -369,7 +369,7 @@ public static SCBlock ReadFromOffset(byte[] data, ref int offset) block.SubType = (SCTypeCode)block.CryptBytes(data, offset, 5, 1)[0]; switch (block.SubType) { - case SCTypeCode.Common3: + case SCTypeCode.Bool3: // This is an array of booleans. block.Data = block.CryptBytes(data, offset, 6, num_entries); offset += 6 + num_entries; @@ -424,14 +424,13 @@ public static SCBlock ReadFromOffset(byte[] data, ref int offset) /// Block type for a . /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1027:Mark enums with FlagsAttribute", Justification = "NOT FLAGS")] - public enum SCTypeCode + public enum SCTypeCode : byte { None = 0, - // All aliases of each other - Common1 = 1, - Common2 = 2, - Common3 = 3, + Bool1 = 1, // False? + Bool2 = 2, // True? + Bool3 = 3, // Either? (Array boolean type) Object = 4, @@ -451,11 +450,13 @@ public enum SCTypeCode public static class SCTypeCodeExtensions { + public static bool IsBoolean(this SCTypeCode type) => (byte)type - 1 < 3; + public static int GetTypeSize(this SCTypeCode type) { return type switch { - SCTypeCode.Common3 => sizeof(bool), + SCTypeCode.Bool3 => sizeof(bool), SCTypeCode.Byte => sizeof(byte), SCTypeCode.UInt16 => sizeof(ushort),