Extract IMultiplayerSprite from SaveFile

only used by gen6 saves
This commit is contained in:
Kurt 2022-04-15 14:58:40 -07:00
parent a681783f1a
commit a61d8d1efc
9 changed files with 25 additions and 15 deletions

View file

@ -8,7 +8,7 @@ namespace PKHeX.Core
/// Generation 6 <see cref="SaveFile"/> object for <see cref="GameVersion.ORAS"/>. /// Generation 6 <see cref="SaveFile"/> object for <see cref="GameVersion.ORAS"/>.
/// </summary> /// </summary>
/// <inheritdoc cref="SAV6" /> /// <inheritdoc cref="SAV6" />
public sealed class SAV6AO : SAV6, ISaveBlock6AO public sealed class SAV6AO : SAV6, ISaveBlock6AO, IMultiplayerSprite
{ {
public SAV6AO(byte[] data) : base(data, SaveBlockAccessor6AO.BlockMetadataOffset) public SAV6AO(byte[] data) : base(data, SaveBlockAccessor6AO.BlockMetadataOffset)
{ {
@ -104,7 +104,7 @@ namespace PKHeX.Core
public override int Badges { get => Blocks.Misc.Badges; set => Blocks.Misc.Badges = value; } public override int Badges { get => Blocks.Misc.Badges; set => Blocks.Misc.Badges = value; }
public override int BP { get => Blocks.Misc.BP; set => Blocks.Misc.BP = value; } public override int BP { get => Blocks.Misc.BP; set => Blocks.Misc.BP = value; }
public override int MultiplayerSpriteID public int MultiplayerSpriteID
{ {
get => Blocks.Status.MultiplayerSpriteID_1; get => Blocks.Status.MultiplayerSpriteID_1;
set => Blocks.Status.MultiplayerSpriteID_1 = Blocks.Status.MultiplayerSpriteID_2 = value; set => Blocks.Status.MultiplayerSpriteID_1 = Blocks.Status.MultiplayerSpriteID_2 = value;

View file

@ -8,7 +8,7 @@ namespace PKHeX.Core
/// Generation 6 <see cref="SaveFile"/> object for <see cref="GameVersion.XY"/>. /// Generation 6 <see cref="SaveFile"/> object for <see cref="GameVersion.XY"/>.
/// </summary> /// </summary>
/// <inheritdoc cref="SAV6" /> /// <inheritdoc cref="SAV6" />
public sealed class SAV6XY : SAV6, ISaveBlock6XY public sealed class SAV6XY : SAV6, ISaveBlock6XY, IMultiplayerSprite
{ {
public SAV6XY(byte[] data) : base(data, SaveBlockAccessor6XY.BlockMetadataOffset) public SAV6XY(byte[] data) : base(data, SaveBlockAccessor6XY.BlockMetadataOffset)
{ {
@ -161,7 +161,7 @@ namespace PKHeX.Core
public override int Badges { get => Blocks.Misc.Badges; set => Blocks.Misc.Badges = value; } public override int Badges { get => Blocks.Misc.Badges; set => Blocks.Misc.Badges = value; }
public override int BP { get => Blocks.Misc.BP; set => Blocks.Misc.BP = value; } public override int BP { get => Blocks.Misc.BP; set => Blocks.Misc.BP = value; }
public override int MultiplayerSpriteID public int MultiplayerSpriteID
{ {
get => Blocks.Status.MultiplayerSpriteID_1; get => Blocks.Status.MultiplayerSpriteID_1;
set => Blocks.Status.MultiplayerSpriteID_1 = Blocks.Status.MultiplayerSpriteID_2 = value; set => Blocks.Status.MultiplayerSpriteID_1 = Blocks.Status.MultiplayerSpriteID_2 = value;

View file

@ -134,7 +134,7 @@ namespace PKHeX.Core
public byte ConsoleRegion { get => MyStatus.ConsoleRegion; set => MyStatus.ConsoleRegion = value; } public byte ConsoleRegion { get => MyStatus.ConsoleRegion; set => MyStatus.ConsoleRegion = value; }
public override int Language { get => MyStatus.Language; set => MyStatus.Language = value; } public override int Language { get => MyStatus.Language; set => MyStatus.Language = value; }
public override string OT { get => MyStatus.OT; set => MyStatus.OT = value; } public override string OT { get => MyStatus.OT; set => MyStatus.OT = value; }
public override int MultiplayerSpriteID { get => MyStatus.MultiplayerSpriteID; set => MyStatus.MultiplayerSpriteID = value; } public int MultiplayerSpriteID { get => MyStatus.MultiplayerSpriteID; set => MyStatus.MultiplayerSpriteID = value; }
public override uint Money { get => Misc.Money; set => Misc.Money = value; } public override uint Money { get => Misc.Money; set => Misc.Money = value; }
public override int PlayedHours { get => Played.PlayedHours; set => Played.PlayedHours = value; } public override int PlayedHours { get => Played.PlayedHours; set => Played.PlayedHours = value; }

View file

@ -151,7 +151,6 @@ namespace PKHeX.Core
public virtual uint Money { get; set; } public virtual uint Money { get; set; }
public abstract int BoxCount { get; } public abstract int BoxCount { get; }
public virtual int SlotCount => BoxCount * BoxSlotCount; public virtual int SlotCount => BoxCount * BoxSlotCount;
public virtual int MultiplayerSpriteID { get => 0; set { } }
public int TrainerID7 { get => (int)((uint)(TID | (SID << 16)) % 1000000); set => SetID7(TrainerSID7, value); } public int TrainerID7 { get => (int)((uint)(TID | (SID << 16)) % 1000000); set => SetID7(TrainerSID7, value); }
public int TrainerSID7 { get => (int)((uint)(TID | (SID << 16)) / 1000000); set => SetID7(value, TrainerID7); } public int TrainerSID7 { get => (int)((uint)(TID | (SID << 16)) / 1000000); set => SetID7(value, TrainerID7); }
public virtual int MaxMoney => 9999999; public virtual int MaxMoney => 9999999;
@ -836,7 +835,7 @@ namespace PKHeX.Core
if (IsRegionOverwriteProtected(0, SlotCount)) if (IsRegionOverwriteProtected(0, SlotCount))
return false; return false;
int expectLength = SlotCount * GetDataForBox(BlankPKM).Length; int expectLength = SlotCount * SIZE_BOXSLOT;
return SetConcatenatedBinary(data, expectLength); return SetConcatenatedBinary(data, expectLength);
} }
@ -848,7 +847,7 @@ namespace PKHeX.Core
if (IsRegionOverwriteProtected(start, end)) if (IsRegionOverwriteProtected(start, end))
return false; return false;
int expectLength = BoxSlotCount * GetDataForBox(BlankPKM).Length; int expectLength = BoxSlotCount * SIZE_BOXSLOT;
return SetConcatenatedBinary(data, expectLength, start); return SetConcatenatedBinary(data, expectLength, start);
} }
@ -858,7 +857,7 @@ namespace PKHeX.Core
return false; return false;
var BD = BoxData; var BD = BoxData;
var entryLength = GetDataForBox(BlankPKM).Length; var entryLength = SIZE_BOXSLOT;
var pkdata = ArrayUtil.EnumerateSplit(data, entryLength); var pkdata = ArrayUtil.EnumerateSplit(data, entryLength);
pkdata.Select(GetPKM).CopyTo(BD, IsSlotOverwriteProtected, start); pkdata.Select(GetPKM).CopyTo(BD, IsSlotOverwriteProtected, start);

View file

@ -104,7 +104,7 @@ namespace PKHeX.Core
set => Data[Offset + 0x54] = (byte)((Data[Offset + 0x54] & ~(7 << 2)) | (value << 2)); set => Data[Offset + 0x54] = (byte)((Data[Offset + 0x54] & ~(7 << 2)) | (value << 2));
} }
public int MultiplayerSpriteID public int MultiplayerSpriteID // holdover from Gen6
{ {
get => Data[Offset + 0x58]; get => Data[Offset + 0x58];
set => Data[Offset + 0x58] = (byte)value; set => Data[Offset + 0x58] = (byte)value;

View file

@ -0,0 +1,6 @@
namespace PKHeX.Core;
public interface IMultiplayerSprite
{
public int MultiplayerSpriteID { get; set; }
}

View file

@ -10,9 +10,10 @@ public static class PlayerSpriteUtil
private static Image? GetSprite(SaveFile sav) private static Image? GetSprite(SaveFile sav)
{ {
if (sav is SAV6XY or SAV6AO) if (sav is IMultiplayerSprite ms)
{ {
string file = $"tr_{sav.MultiplayerSpriteID:00}"; // Gen6 only
string file = $"tr_{ms.MultiplayerSpriteID:00}";
return Resources.ResourceManager.GetObject(file) as Image ?? Resources.tr_00; return Resources.ResourceManager.GetObject(file) as Image ?? Resources.tr_00;
} }
return null; return null;

View file

@ -165,7 +165,8 @@ namespace PKHeX.WinForms
MT_Seconds.Text = SAV.PlayedSeconds.ToString(); MT_Seconds.Text = SAV.PlayedSeconds.ToString();
// Load PSS Sprite // Load PSS Sprite
CB_MultiplayerSprite.SelectedValue = SAV.MultiplayerSpriteID; if (SAV is IMultiplayerSprite ms)
CB_MultiplayerSprite.SelectedValue = ms.MultiplayerSpriteID;
PB_Sprite.Image = SAV.Sprite(); PB_Sprite.Image = SAV.Sprite();
if (SAV is SAV6XY xy) if (SAV is SAV6XY xy)
@ -253,7 +254,8 @@ namespace PKHeX.WinForms
SAV.PlayedSeconds = ushort.Parse(MT_Seconds.Text)%60; SAV.PlayedSeconds = ushort.Parse(MT_Seconds.Text)%60;
// Sprite // Sprite
SAV.MultiplayerSpriteID = Convert.ToByte(CB_MultiplayerSprite.SelectedValue); if (SAV is IMultiplayerSprite ms)
ms.MultiplayerSpriteID = Convert.ToByte(CB_MultiplayerSprite.SelectedValue);
// Appearance // Appearance
if (SAV is SAV6XY xy) if (SAV is SAV6XY xy)
@ -348,7 +350,9 @@ namespace PKHeX.WinForms
{ {
if (editing) if (editing)
return; return;
SAV.MultiplayerSpriteID = WinFormsUtil.GetIndex(CB_MultiplayerSprite);
if (SAV is IMultiplayerSprite ms)
ms.MultiplayerSpriteID = WinFormsUtil.GetIndex(CB_MultiplayerSprite);
PB_Sprite.Image = SAV.Sprite(); PB_Sprite.Image = SAV.Sprite();
} }