Add team index recognition

lock by default until we find the location that locks team slots
This commit is contained in:
Kurt 2020-02-01 18:56:23 -08:00
parent cbf6c1e1b6
commit 43036e7e94
6 changed files with 85 additions and 2 deletions

View file

@ -16,5 +16,6 @@
TrainerCard8 TrainerCard { get; }
RaidSpawnList8 Raid { get; }
TitleScreen8 TitleScreen { get; }
TeamIndexes8 TeamIndexes { get; }
}
}

View file

@ -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

View file

@ -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

View file

@ -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;
}
}
}

View file

@ -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)
{
}
}
}

View file

@ -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);