diff --git a/PKHeX.Core/Saves/Access/SaveBlockAccessor8SWSH.cs b/PKHeX.Core/Saves/Access/SaveBlockAccessor8SWSH.cs index 4a02b1ff1..729f142e4 100644 --- a/PKHeX.Core/Saves/Access/SaveBlockAccessor8SWSH.cs +++ b/PKHeX.Core/Saves/Access/SaveBlockAccessor8SWSH.cs @@ -110,6 +110,7 @@ public SaveBlockAccessor8SWSH(SAV8SWSH sav) private const uint KBonusRewards = 0xEFCAE04E; // bonus_rewards // Values + public const uint KCurrentBox = 0x017C3CBB; // U32 Box Index public const uint KGameLanguage = 0x0BFDEBA1; // U32 Game Language public const uint KRepel = 0x9ec079da; // U16 Repel Steps remaining public const uint KRotoRally = 0x38548020; // U32 Roto Rally Score (99,999 cap) diff --git a/PKHeX.Core/Saves/MemeCrypto/SCTypeCode.cs b/PKHeX.Core/Saves/MemeCrypto/SCTypeCode.cs index 4589b0775..a9f8dd781 100644 --- a/PKHeX.Core/Saves/MemeCrypto/SCTypeCode.cs +++ b/PKHeX.Core/Saves/MemeCrypto/SCTypeCode.cs @@ -80,23 +80,22 @@ public static Type GetType(this SCTypeCode type) public static object GetValue(this SCTypeCode type, byte[] data) { - return type switch + // don't use a switch expression here, we want to box our underlying type rather than the last type (double) + switch (type) { - SCTypeCode.Byte => data[0], - SCTypeCode.UInt16 => BitConverter.ToUInt16(data, 0), - SCTypeCode.UInt32 => BitConverter.ToUInt32(data, 0), - SCTypeCode.UInt64 => BitConverter.ToUInt64(data, 0), - - SCTypeCode.SByte => (sbyte)data[0], - SCTypeCode.Int16 => BitConverter.ToInt16(data, 0), - SCTypeCode.Int32 => BitConverter.ToInt32(data, 0), - SCTypeCode.Int64 => BitConverter.ToInt64(data, 0), - - SCTypeCode.Single => BitConverter.ToSingle(data, 0), - SCTypeCode.Double => BitConverter.ToDouble(data, 0), - - _ => throw new ArgumentException(type.ToString(), nameof(type)) - }; + case SCTypeCode.Byte: return data[0]; + case SCTypeCode.UInt16: return BitConverter.ToUInt16(data, 0); + case SCTypeCode.UInt32: return BitConverter.ToUInt32(data, 0); + case SCTypeCode.UInt64: return BitConverter.ToUInt64(data, 0); + case SCTypeCode.SByte: return (sbyte) data[0]; + case SCTypeCode.Int16: return BitConverter.ToInt16(data, 0); + case SCTypeCode.Int32: return BitConverter.ToInt32(data, 0); + case SCTypeCode.Int64: return BitConverter.ToInt64(data, 0); + case SCTypeCode.Single: return BitConverter.ToSingle(data, 0); + case SCTypeCode.Double: return BitConverter.ToDouble(data, 0); + default: + throw new ArgumentException(type.ToString(), nameof(type)); + } } public static void SetValue(this SCTypeCode type, byte[] data, object value) diff --git a/PKHeX.Core/Saves/SAV8SWSH.cs b/PKHeX.Core/Saves/SAV8SWSH.cs index b99607b5f..d19280e05 100644 --- a/PKHeX.Core/Saves/SAV8SWSH.cs +++ b/PKHeX.Core/Saves/SAV8SWSH.cs @@ -67,7 +67,12 @@ public override void CopyChangesFrom(SaveFile sav) public override TitleScreen8 TitleScreen => Blocks.TitleScreen; public override TeamIndexes8 TeamIndexes => Blocks.TeamIndexes; - public object GetValue(uint key) => Blocks.GetBlockValue(key); + public object GetValue(uint key) + { + if (!Exportable) + return (byte)0; + return Blocks.GetBlockValue(key); + } public void SetValue(uint key, object value) { @@ -112,5 +117,7 @@ public override StorageSlotFlag GetSlotFlags(int index) val |= StorageSlotFlag.Locked; return val; } + + public override int CurrentBox { get => BoxLayout.CurrentBox; set => BoxLayout.CurrentBox = value; } } } \ No newline at end of file diff --git a/PKHeX.Core/Saves/Substructures/Gen8/BoxLayout8.cs b/PKHeX.Core/Saves/Substructures/Gen8/BoxLayout8.cs index dc143ebb0..87f8f92aa 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/BoxLayout8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/BoxLayout8.cs @@ -27,5 +27,11 @@ public void SetBoxName(int box, string value) get => GetBoxName(i); set => SetBoxName(i, value); } + + public int CurrentBox + { + get => (byte)((SAV8SWSH)SAV).GetValue(SaveBlockAccessor8SWSH.KCurrentBox); + set => ((SAV8SWSH)SAV).SetValue(SaveBlockAccessor8SWSH.KCurrentBox, (byte)value); + } } } \ No newline at end of file