Handle SwSh and SV Team Locks (#4186)

This commit is contained in:
Jonathan Herbert 2024-02-15 10:33:25 -04:00 committed by GitHub
parent 704a7036ea
commit 247340dff4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 18 deletions

View file

@ -52,7 +52,7 @@ public sealed class SaveBlockAccessor8SWSH : SCBlockAccessor, ISaveBlock8Main
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 sealed class SaveBlockAccessor8SWSH : SCBlockAccessor, ISaveBlock8Main
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;

View file

@ -46,7 +46,7 @@ public sealed class SaveBlockAccessor9SV : SCBlockAccessor, ISaveBlock9Main
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 sealed class SaveBlockAccessor9SV : SCBlockAccessor, ISaveBlock9Main
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

View file

@ -3,7 +3,7 @@ using static System.Buffers.Binary.BinaryPrimitives;
namespace PKHeX.Core;
public sealed class TeamIndexes8(SAV8SWSH sav, SCBlock block) : SaveBlock<SAV8SWSH>(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<SAV8SW
public void LoadBattleTeams()
{
if (!SAV.State.Exportable)
if (!sav.State.Exportable)
{
ClearBattleTeams();
return;
@ -19,7 +19,7 @@ public sealed class TeamIndexes8(SAV8SWSH sav, SCBlock block) : SaveBlock<SAV8SW
for (int i = 0; i < TeamCount * 6; i++)
{
short val = ReadInt16LittleEndian(Data.AsSpan(Offset + (i * 2)));
short val = ReadInt16LittleEndian(indexes.Data.AsSpan((i * 2)));
if (val < 0)
{
TeamSlots[i] = NONE_SELECTED;
@ -28,7 +28,7 @@ public sealed class TeamIndexes8(SAV8SWSH sav, SCBlock block) : SaveBlock<SAV8SW
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 sealed class TeamIndexes8(SAV8SWSH sav, SCBlock block) : SaveBlock<SAV8SW
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 sealed class TeamIndexes8(SAV8SWSH sav, SCBlock block) : SaveBlock<SAV8SW
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);
}

View file

@ -3,7 +3,7 @@ using static System.Buffers.Binary.BinaryPrimitives;
namespace PKHeX.Core;
public sealed class TeamIndexes9(SAV9SV sav, SCBlock block) : SaveBlock<SAV9SV>(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<SAV9SV>(
public void LoadBattleTeams()
{
if (!SAV.State.Exportable)
if (!sav.State.Exportable)
{
ClearBattleTeams();
return;
@ -19,7 +19,7 @@ public sealed class TeamIndexes9(SAV9SV sav, SCBlock block) : SaveBlock<SAV9SV>(
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 sealed class TeamIndexes9(SAV9SV sav, SCBlock block) : SaveBlock<SAV9SV>(
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 sealed class TeamIndexes9(SAV9SV sav, SCBlock block) : SaveBlock<SAV9SV>(
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 sealed class TeamIndexes9(SAV9SV sav, SCBlock block) : SaveBlock<SAV9SV>(
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);
}