diff --git a/PKHeX.Core/Saves/Access/SaveBlockAccessor8SWSH.cs b/PKHeX.Core/Saves/Access/SaveBlockAccessor8SWSH.cs index 7a3093918..5768b2791 100644 --- a/PKHeX.Core/Saves/Access/SaveBlockAccessor8SWSH.cs +++ b/PKHeX.Core/Saves/Access/SaveBlockAccessor8SWSH.cs @@ -52,7 +52,7 @@ public SaveBlockAccessor8SWSH(SAV8SWSH sav) RaidArmor = new RaidSpawnList8(sav, GetBlockSafe(KRaidSpawnListR1), RaidSpawnList8.RaidCountLegal_R1); RaidCrown = new RaidSpawnList8(sav, GetBlockSafe(KRaidSpawnListR2), RaidSpawnList8.RaidCountLegal_R2); TitleScreen = new TitleScreen8(sav, GetBlock(KTitleScreenTeam)); - TeamIndexes = new TeamIndexes8(sav, GetBlock(KTeamIndexes)); + TeamIndexes = new TeamIndexes8(sav, GetBlock(KTeamIndexes), GetBlock(KTeamLocks)); FameTime = new HallOfFameTime8(sav, GetBlock(KEnteredHallOfFame)); } @@ -97,6 +97,7 @@ public SaveBlockAccessor8SWSH(SAV8SWSH sav) private const uint KTrainer3EndlessRecordData = 0x7BD78AF1; // Trainer 3's Data of Best Endless Dynamax Adventure Record private const uint KTrainer4EndlessRecordData = 0x7AD7895E; // Trainer 4's Data of Best Endless Dynamax Adventure Record private const uint KPokeJobStorage = 0xB25C772B; // Pokémon storage while they are doing Jobs + private const uint KTeamLocks = 0x605EBC30; // Rental Teams - Objects (Blocks) private const uint KRentalTeam1 = 0x149A1DD0; diff --git a/PKHeX.Core/Saves/Access/SaveBlockAccessor9SV.cs b/PKHeX.Core/Saves/Access/SaveBlockAccessor9SV.cs index 5c37869d0..96a145308 100644 --- a/PKHeX.Core/Saves/Access/SaveBlockAccessor9SV.cs +++ b/PKHeX.Core/Saves/Access/SaveBlockAccessor9SV.cs @@ -46,7 +46,7 @@ public SaveBlockAccessor9SV(SAV9SV sav) Zukan = new Zukan9(sav, GetBlock(KZukan), GetBlockSafe(KZukanT1)); Config = new ConfigSave9(sav, GetBlock(KConfig)); ConfigCamera = new ConfigCamera9(sav, GetBlockSafe(KConfigCamera)); - TeamIndexes = new TeamIndexes9(sav, GetBlock(KTeamIndexes)); + TeamIndexes = new TeamIndexes9(sav, GetBlock(KTeamIndexes), GetBlock(KTeamLocks)); LastSaved = new Epoch1900DateTimeValue(GetBlock(KLastSaved)); LastDateCycle = new Epoch1970Value(GetBlock(KLastDateCycle)); PlayerFashion = new PlayerFashion9(sav, GetBlock(KCurrentClothing)); @@ -138,6 +138,7 @@ public SaveBlockAccessor9SV(SAV9SV sav) private const uint KFieldItems = 0x2482AD60; // Stores grabbed status for each existing field item private const uint KDefeatedTrainers01 = 0xF018C4AC; // Stores history of up to 300 regular trainers defeated private const uint KDefeatedTrainers02 = 0x28E475DE; // 2.0.2+ Expansion with additional 100 slots + private const uint KTeamLocks = 0x605EBC30; // BCAT (Tera Raid Battles) private const uint KBCATRaidFixedRewardItemArray = 0x7D6C2B82; // fixed_reward_item_array diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/TeamIndexes8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/TeamIndexes8.cs index 712aeb1f5..40de912ef 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/TeamIndexes8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/TeamIndexes8.cs @@ -3,7 +3,7 @@ namespace PKHeX.Core; -public sealed class TeamIndexes8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Data), ITeamIndexSet +public sealed class TeamIndexes8(SAV8SWSH sav, SCBlock indexes, SCBlock locks) : ITeamIndexSet { private const int TeamCount = 6; private const int NONE_SELECTED = -1; @@ -11,7 +11,7 @@ public sealed class TeamIndexes8(SAV8SWSH sav, SCBlock block) : SaveBlock> 8; int slot = val & 0xFF; - int index = (SAV.BoxSlotCount * box) + slot; + int index = (sav.BoxSlotCount * box) + slot; TeamSlots[i] = index & 0xFFFF; } } @@ -47,7 +47,7 @@ public void UnlockAllTeams() public void SaveBattleTeams() { - var span = Data.AsSpan(Offset); + var span = indexes.Data.AsSpan(); for (int i = 0; i < TeamCount * 6; i++) { int index = TeamSlots[i]; @@ -57,12 +57,12 @@ public void SaveBattleTeams() continue; } - SAV.GetBoxSlotFromIndex(index, out var box, out var slot); + sav.GetBoxSlotFromIndex(index, out var box, out var slot); index = (box << 8) | slot; WriteInt16LittleEndian(span[(i * 2)..], (short)index); } } - public bool GetIsTeamLocked(int team) => true; - public void SetIsTeamLocked(int team, bool value) { } + public bool GetIsTeamLocked(int team) => FlagUtil.GetFlag(locks.Data, 0, team); + public void SetIsTeamLocked(int team, bool value) => FlagUtil.SetFlag(locks.Data, 0, team, value); } diff --git a/PKHeX.Core/Saves/Substructures/Gen9/TeamIndexes9.cs b/PKHeX.Core/Saves/Substructures/Gen9/TeamIndexes9.cs index b8bf743db..3bdd65e70 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/TeamIndexes9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/TeamIndexes9.cs @@ -3,7 +3,7 @@ namespace PKHeX.Core; -public sealed class TeamIndexes9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data), ITeamIndexSet +public sealed class TeamIndexes9(SAV9SV sav, SCBlock indexes, SCBlock locks) : ITeamIndexSet { private const int TeamCount = 6; private const int NONE_SELECTED = -1; @@ -11,7 +11,7 @@ public sealed class TeamIndexes9(SAV9SV sav, SCBlock block) : SaveBlock( public void LoadBattleTeams() { - if (!SAV.State.Exportable) + if (!sav.State.Exportable) { ClearBattleTeams(); return; @@ -19,7 +19,7 @@ public void LoadBattleTeams() for (int i = 0; i < TeamCount * 6; i++) { - short val = ReadInt16LittleEndian(Data.AsSpan(i * 2)); + short val = ReadInt16LittleEndian(indexes.Data.AsSpan(i * 2)); if (val < 0) { TeamSlots[i] = NONE_SELECTED; @@ -28,7 +28,7 @@ public void LoadBattleTeams() int box = val >> 8; int slot = val & 0xFF; - int index = (SAV.BoxSlotCount * box) + slot; + int index = (sav.BoxSlotCount * box) + slot; TeamSlots[i] = index & 0xFFFF; } } @@ -47,7 +47,7 @@ public void UnlockAllTeams() public void SaveBattleTeams() { - var span = Data.AsSpan(); + var span = indexes.Data.AsSpan(); for (int i = 0; i < TeamCount * 6; i++) { int index = TeamSlots[i]; @@ -57,12 +57,12 @@ public void SaveBattleTeams() continue; } - SAV.GetBoxSlotFromIndex(index, out var box, out var slot); + sav.GetBoxSlotFromIndex(index, out var box, out var slot); index = (box << 8) | slot; WriteInt16LittleEndian(span[(i * 2)..], (short)index); } } - public bool GetIsTeamLocked(int team) => true; - public void SetIsTeamLocked(int team, bool value) { } + public bool GetIsTeamLocked(int team) => FlagUtil.GetFlag(locks.Data, 0, team); + public void SetIsTeamLocked(int team, bool value) => FlagUtil.SetFlag(locks.Data, 0, team, value); }