diff --git a/PKHeX.Core/Saves/Access/ISaveBlock8Main.cs b/PKHeX.Core/Saves/Access/ISaveBlock8Main.cs index b1b779549..8797674ca 100644 --- a/PKHeX.Core/Saves/Access/ISaveBlock8Main.cs +++ b/PKHeX.Core/Saves/Access/ISaveBlock8Main.cs @@ -16,5 +16,6 @@ TrainerCard8 TrainerCard { get; } RaidSpawnList8 Raid { get; } TitleScreen8 TitleScreen { get; } + TeamIndexes8 TeamIndexes { get; } } } \ No newline at end of file diff --git a/PKHeX.Core/Saves/Access/SaveBlockAccessor8SWSH.cs b/PKHeX.Core/Saves/Access/SaveBlockAccessor8SWSH.cs index b30557aec..88518d6dc 100644 --- a/PKHeX.Core/Saves/Access/SaveBlockAccessor8SWSH.cs +++ b/PKHeX.Core/Saves/Access/SaveBlockAccessor8SWSH.cs @@ -20,6 +20,7 @@ namespace PKHeX.Core public FashionUnlock8 Fashion { get; } public RaidSpawnList8 Raid { get; } public TitleScreen8 TitleScreen { get; } + public TeamIndexes8 TeamIndexes { get; } public SaveBlockAccessor8SWSH(SAV8SWSH sav) { @@ -39,6 +40,7 @@ namespace PKHeX.Core Fashion = new FashionUnlock8(sav, GetBlock(KFashionUnlock)); Raid = new RaidSpawnList8(sav, GetBlock(KRaidSpawnList)); TitleScreen = new TitleScreen8(sav, GetBlock(KTitleScreenTeam)); + TeamIndexes = new TeamIndexes8(sav, GetBlock(KTeamIndexes)); } /* To dump key list of current format, use the following in the immediate window, and update Meta8 @@ -58,6 +60,7 @@ namespace PKHeX.Core private const uint KMisc = 0x1b882b09; // Money private const uint KParty = 0x2985fe5d; // Party Data private const uint KDaycare = 0x2d6fba6a; // Daycare slots (2 daycares) + private const uint KTeamIndexes = 0x33F39467; // Team Indexes for competition private const uint KRecord = 0x37da95a3; private const uint KZukan = 0x4716c404; // PokeDex private const uint KTrainerCard = 0x874da6fa; // Trainer Card diff --git a/PKHeX.Core/Saves/SAV8.cs b/PKHeX.Core/Saves/SAV8.cs index eba2dc4ab..6af38a2f1 100644 --- a/PKHeX.Core/Saves/SAV8.cs +++ b/PKHeX.Core/Saves/SAV8.cs @@ -54,6 +54,7 @@ namespace PKHeX.Core public abstract TrainerCard8 TrainerCard { get; } public abstract RaidSpawnList8 Raid { get; } public abstract TitleScreen8 TitleScreen { get; } + public abstract TeamIndexes8 TeamIndexes { get; } #endregion public override GameVersion Version diff --git a/PKHeX.Core/Saves/SAV8SWSH.cs b/PKHeX.Core/Saves/SAV8SWSH.cs index 3666664b8..b99607b5f 100644 --- a/PKHeX.Core/Saves/SAV8SWSH.cs +++ b/PKHeX.Core/Saves/SAV8SWSH.cs @@ -65,6 +65,7 @@ namespace PKHeX.Core public override TrainerCard8 TrainerCard => Blocks.TrainerCard; public override RaidSpawnList8 Raid => Blocks.Raid; public override TitleScreen8 TitleScreen => Blocks.TitleScreen; + public override TeamIndexes8 TeamIndexes => Blocks.TeamIndexes; public object GetValue(uint key) => Blocks.GetBlockValue(key); @@ -90,6 +91,7 @@ namespace PKHeX.Core Box = 0; Party = 0; PokeDex = 0; + TeamIndexes.LoadBattleTeams(); } public int GetRecord(int recordID) => Records.GetRecord(recordID); @@ -97,5 +99,18 @@ namespace PKHeX.Core public int GetRecordMax(int recordID) => Records.GetRecordMax(recordID); public int GetRecordOffset(int recordID) => Records.GetRecordOffset(recordID); public int RecordCount => Record8.RecordCount; + + public override StorageSlotFlag GetSlotFlags(int index) + { + int team = Array.IndexOf(TeamIndexes.TeamSlots, index); + if (team < 0) + return StorageSlotFlag.None; + + team /= 6; + var val = (StorageSlotFlag)((int)StorageSlotFlag.BattleTeam1 << team); + if (TeamIndexes.GetIsTeamLocked(team)) + val |= StorageSlotFlag.Locked; + return val; + } } } \ No newline at end of file diff --git a/PKHeX.Core/Saves/Substructures/Gen8/TeamIndexes8.cs b/PKHeX.Core/Saves/Substructures/Gen8/TeamIndexes8.cs new file mode 100644 index 000000000..a5f8b9de1 --- /dev/null +++ b/PKHeX.Core/Saves/Substructures/Gen8/TeamIndexes8.cs @@ -0,0 +1,63 @@ +using System; + +namespace PKHeX.Core +{ + public sealed class TeamIndexes8 : SaveBlock + { + private const int TeamCount = 6; + private const int NONE_SELECTED = -1; + public readonly int[] TeamSlots = new int[TeamCount * 6]; + + public TeamIndexes8(SAV8SWSH sav, SCBlock block) : base(sav, block.Data) { } + + public void LoadBattleTeams() + { + for (int i = 0; i < TeamCount * 6; i++) + { + short val = BitConverter.ToInt16(Data, Offset + (i * 2)); + if (val < 0) + { + TeamSlots[i] = NONE_SELECTED; + continue; + } + + int box = val >> 8; + int slot = val & 0xFF; + int index = (SAV.BoxSlotCount * box) + slot; + TeamSlots[i] = index & 0xFFFF; + } + } + + public void ClearBattleTeams() + { + for (int i = 0; i < TeamSlots.Length; i++) + TeamSlots[i] = NONE_SELECTED; + for (int i = 0; i < TeamCount; i++) + SetIsTeamLocked(i, false); + } + + public void SaveBattleTeams() + { + for (int i = 0; i < TeamCount * 6; i++) + { + int index = TeamSlots[i]; + if (index < 0) + { + BitConverter.GetBytes((short)index).CopyTo(Data, Offset + (i * 2)); + continue; + } + + SAV.GetBoxSlotFromIndex(index, out var box, out var slot); + int val = (box << 8) | slot; + BitConverter.GetBytes((short)val).CopyTo(Data, Offset + (i * 2)); + } + } + + public bool GetIsTeamLocked(int team) => true; + + public void SetIsTeamLocked(int team, bool value) + { + + } + } +} \ No newline at end of file diff --git a/PKHeX.Drawing/Sprites/SpriteUtil.cs b/PKHeX.Drawing/Sprites/SpriteUtil.cs index 1220c3bb4..734a41f9e 100644 --- a/PKHeX.Drawing/Sprites/SpriteUtil.cs +++ b/PKHeX.Drawing/Sprites/SpriteUtil.cs @@ -142,11 +142,11 @@ namespace PKHeX.Drawing if (inBox) // in box { var flags = sav.GetSlotFlags(box, slot); - if (flags.HasFlagFast(StorageSlotFlag.Locked)) - sprite = ImageUtil.LayerImage(sprite, Resources.locked, SlotLockShiftX, 0); int team = flags.IsBattleTeam(); if (team >= 0) sprite = ImageUtil.LayerImage(sprite, Resources.team, SlotTeamShiftX, 0); + if (flags.HasFlagFast(StorageSlotFlag.Locked)) + sprite = ImageUtil.LayerImage(sprite, Resources.locked, SlotLockShiftX, 0); int party = flags.IsParty(); if (party >= 0) sprite = ImageUtil.LayerImage(sprite, PartyMarks[party], PartyMarkShiftX, 0);