Minor relocation of logic

and the gradual shift to full-oop continues
This commit is contained in:
Kurt 2019-07-05 21:39:47 -07:00
parent c0eda5eb61
commit 9a61f0de0f
9 changed files with 85 additions and 54 deletions

View file

@ -58,8 +58,6 @@ namespace PKHeX.Core
// Accessible as SAV6
public int MaisonStats { get; protected set; } = int.MinValue;
public int Accessories { get; protected set; } = int.MinValue;
public int PokeDexLanguageFlags { get; protected set; } = int.MinValue;
public int Spinda { get; protected set; } = int.MinValue;
protected internal const int LongStringLength = 0x22; // bytes, not characters
protected internal const int ShortStringLength = 0x1A; // bytes, not characters
@ -207,26 +205,6 @@ namespace PKHeX.Core
protected set => Data[Party + (6 * SIZE_PARTY)] = (byte)value;
}
private int LockedFlagOffset => BattleBox + (6 * SIZE_STORED);
public override bool BattleBoxLocked
{
get => BattleBoxLockedWiFiTournament || BattleBoxLockedLiveTournament;
set => BattleBoxLockedWiFiTournament = BattleBoxLockedLiveTournament = value;
}
public bool BattleBoxLockedWiFiTournament
{
get => (Data[LockedFlagOffset] & 1) != 0;
set => Data[LockedFlagOffset] = (byte)((Data[LockedFlagOffset] & ~1) | (value ? 1 : 0));
}
public bool BattleBoxLockedLiveTournament
{
get => (Data[LockedFlagOffset] & 2) != 0;
set => Data[LockedFlagOffset] = (byte)((Data[LockedFlagOffset] & ~2) | (value ? 2 : 0));
}
public override string GetString(byte[] data, int offset, int length) => StringConverter.GetString6(data, offset, length);
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)

View file

@ -154,6 +154,7 @@ namespace PKHeX.Core
Situation = new Situation6(this, 0x01400);
Played = new PlayTime6(this, 0x01800);
BoxLayout = new BoxLayout6(this, 0x04400);
BattleBoxBlock = new BattleBox6(this, 0x04A00);
Status = new MyStatus6(this, 0x14000);
Zukan = new Zukan6AO(this, 0x15000, 0x400);
OPowerBlock = new OPower6(this, 0x17400);
@ -162,8 +163,6 @@ namespace PKHeX.Core
Sango = new SangoInfoBlock(this, 0x2B600);
EventFlag = EventConst + 0x2FC;
PokeDexLanguageFlags = PokeDex + 0x400;
Spinda = PokeDex + 0x680;
WondercardData = WondercardFlags + 0x100;
Daycare2 = Daycare + 0x1F0;
@ -171,8 +170,8 @@ namespace PKHeX.Core
Personal = PersonalTable.AO;
}
public int EonTicket { get; private set; } = int.MinValue;
public int Contest { get; private set; } = int.MinValue;
public int EonTicket { get; private set; }
public int Contest { get; private set; }
public Zukan6 Zukan { get; private set; }
public Puff6 PuffBlock { get; private set; }
@ -180,6 +179,7 @@ namespace PKHeX.Core
public BoxLayout6 BoxLayout { get; private set; }
public MysteryBlock6 MysteryBlock { get; private set; }
public SangoInfoBlock Sango { get; set; }
public BattleBox6 BattleBoxBlock { get; private set; }
public override GameVersion Version
{
@ -338,5 +338,11 @@ namespace PKHeX.Core
protected override int GetBoxWallpaperOffset(int box) => BoxLayout.GetBoxWallpaperOffset(box);
public override int BoxesUnlocked { get => BoxLayout.BoxesUnlocked; set => BoxLayout.BoxesUnlocked = value; }
public override byte[] BoxFlags { get => BoxLayout.BoxFlags; set => BoxLayout.BoxFlags = value; }
public override bool BattleBoxLocked
{
get => BattleBoxBlock.Locked;
set => BattleBoxBlock.Locked = value;
}
}
}

View file

@ -147,6 +147,7 @@ namespace PKHeX.Core
Situation = new Situation6(this, 0x01400);
Played = new PlayTime6(this, 0x01800);
BoxLayout = new BoxLayout6(this, 0x4400);
BattleBoxBlock = new BattleBox6(this, 0x04A00);
Status = new MyStatus6XY(this, 0x14000);
Zukan = new Zukan6XY(this, 0x15000, 0x3C8);
OPowerBlock = new OPower6(this, 0x16A00);
@ -154,8 +155,6 @@ namespace PKHeX.Core
Records = new Record6(this, 0x1E400, Core.Records.MaxType_XY);
EventFlag = EventConst + 0x2FC;
PokeDexLanguageFlags = PokeDex + 0x3C8;
Spinda = PokeDex + 0x648;
WondercardData = WondercardFlags + 0x100;
HeldItems = Legal.HeldItem_XY;
@ -167,6 +166,7 @@ namespace PKHeX.Core
public OPower6 OPowerBlock { get; private set; }
public BoxLayout6 BoxLayout { get; private set; }
public MysteryBlock6 MysteryBlock { get; private set; }
public BattleBox6 BattleBoxBlock { get; private set; }
protected override void SetDex(PKM pkm) => Zukan.SetDex(pkm);
@ -307,5 +307,11 @@ namespace PKHeX.Core
protected override int GetBoxWallpaperOffset(int box) => BoxLayout.GetBoxWallpaperOffset(box);
public override int BoxesUnlocked { get => BoxLayout.BoxesUnlocked; set => BoxLayout.BoxesUnlocked = value; }
public override byte[] BoxFlags { get => BoxLayout.BoxFlags; set => BoxLayout.BoxFlags = value; }
public override bool BattleBoxLocked
{
get => BattleBoxBlock.Locked;
set => BattleBoxBlock.Locked = value;
}
}
}

View file

@ -1,5 +1,4 @@
using System;
using System.Linq;
namespace PKHeX.Core
{
@ -31,7 +30,13 @@ namespace PKHeX.Core
set => Data[Offset + 5] = (byte)value;
}
public int MultiplayerSpriteID
public int MultiplayerSpriteID_1
{
get => Data[Offset + 6];
set => Data[Offset + 6] = (byte)value;
}
public int MultiplayerSpriteID_2
{
get => Data[Offset + 7];
set => Data[Offset + 7] = (byte)value;
@ -41,22 +46,16 @@ namespace PKHeX.Core
public string GameSyncID
{
get
{
var data = Data.Skip(Offset + 8).Take(GameSyncIDSize / 2).Reverse().ToArray();
return BitConverter.ToString(data).Replace("-", string.Empty);
}
get => Util.GetHexStringFromBytes(Data, Offset + 0x08, GameSyncIDSize / 2);
set
{
if (value == null)
return;
if (value.Length > GameSyncIDSize)
if (value.Length != GameSyncIDSize)
return;
Enumerable.Range(0, value.Length)
.Where(x => x % 2 == 0)
.Reverse()
.Select(x => Convert.ToByte(value.Substring(x, 2), 16))
.ToArray().CopyTo(Data, Offset + 8);
var data = Util.GetBytesFromHexString(value);
SAV.SetData(data, Offset + 0x08);
}
}
@ -72,6 +71,18 @@ namespace PKHeX.Core
set => Data[Offset + 0x27] = (byte)value;
}
public decimal Latitude // don't use the setters
{
get => (BitConverter.ToInt16(Data, Offset + 0x28) * 180m) / 0x8000;
set => SAV.SetData(BitConverter.GetBytes((short)(value * 0x8000) / 180), Offset + 0x28);
}
public decimal Longitude // don't use the setters
{
get => (BitConverter.ToInt16(Data, Offset + 0x2A) * 180m) / 0x8000;
set => SAV.SetData(BitConverter.GetBytes((short)(value * 0x8000) / 180), Offset + 0x2A);
}
public int ConsoleRegion
{
get => Data[Offset + 0x2C];

View file

@ -2,6 +2,10 @@
namespace PKHeX.Core
{
/// <summary>
/// XY specific features for <see cref="MyStatus6"/>
/// </summary>
/// <remarks>These properties are technically included in OR/AS but they are unused; assumed backwards compatibility for communications with XY</remarks>
public sealed class MyStatus6XY : MyStatus6
{
public MyStatus6XY(SaveFile sav, int offset) : base(sav, offset) { }

View file

@ -56,4 +56,30 @@ namespace PKHeX.Core
Array.Reverse(Data, Offset, PuffCount);
}
}
public class BattleBox6 : SaveBlock
{
public BattleBox6(SaveFile SAV, int offset) : base(SAV) => Offset = offset;
private int LockedFlagOffset => Offset + (6 * PKX.SIZE_6STORED);
public bool Locked
{
get => LockedWiFiTournament || LockedLiveTournament;
set => LockedWiFiTournament = LockedLiveTournament = value;
}
public bool LockedWiFiTournament
{
get => (Data[LockedFlagOffset] & 1) != 0;
set => Data[LockedFlagOffset] = (byte)((Data[Offset + LockedFlagOffset] & ~1) | (value ? 1 : 0));
}
public bool LockedLiveTournament
{
get => (Data[LockedFlagOffset] & 2) != 0;
set => Data[LockedFlagOffset] = (byte)((Data[Offset + LockedFlagOffset] & ~2) | (value ? 2 : 0));
}
}
}

View file

@ -10,6 +10,7 @@ namespace PKHeX.Core
protected override int BitSeenSize => 0x60;
protected override int DexLangFlagByteCount => 7;
protected override int DexLangIDCount => 7;
protected int SpindaOffset { get; set; }
protected Zukan6(SaveFile sav, int dex, int langflag) : base(sav, dex, langflag) { }
@ -117,6 +118,12 @@ namespace PKHeX.Core
return false;
}
public uint SpindaPID
{
get => BitConverter.ToUInt32(SAV.Data, PokeDex + SpindaOffset);
set => SAV.SetData(BitConverter.GetBytes(value), PokeDex + SpindaOffset);
}
public bool[] GetLanguageBitflags(int species)
{
var result = new bool[DexLangIDCount];
@ -166,6 +173,7 @@ namespace PKHeX.Core
public Zukan6AO(SaveFile sav, int dex, int langflag) : base(sav, dex, langflag)
{
DexFormIndexFetcher = (spec, form, _) => DexFormUtil.GetDexFormIndexORAS(spec, form);
SpindaOffset = 0x680;
}
protected override void SetCaughtFlag(int bit, int origin)
@ -194,6 +202,7 @@ namespace PKHeX.Core
public Zukan6XY(SaveFile sav, int dex, int langflag) : base(sav, dex, langflag)
{
DexFormIndexFetcher = (spec, form, _) => DexFormUtil.GetDexFormIndexXY(spec, form);
SpindaOffset = 0x648;
}
protected override void SetCaughtFlag(int bit, int origin)

View file

@ -34,7 +34,7 @@ namespace PKHeX.WinForms
editing = false;
LB_Species.SelectedIndex = 0;
TB_Spinda.Text = BitConverter.ToUInt32(SAV.Data, SAV.Spinda).ToString("X8");
TB_Spinda.Text = Zukan.SpindaPID.ToString("X8");
CB_Species.KeyDown += WinFormsUtil.RemoveDropCB;
}
@ -194,11 +194,7 @@ namespace PKHeX.WinForms
private void B_Save_Click(object sender, EventArgs e)
{
SetEntry();
// Store Spinda Spot
uint PID = Util.GetHexValue(TB_Spinda.Text);
BitConverter.GetBytes(PID).CopyTo(SAV.Data, SAV.Spinda);
Zukan.SpindaPID = Util.GetHexValue(TB_Spinda.Text);
Origin.SetData(SAV.Data, 0);
Close();
}

View file

@ -34,7 +34,7 @@ namespace PKHeX.WinForms
editing = false;
LB_Species.SelectedIndex = 0;
TB_Spinda.Text = BitConverter.ToUInt32(SAV.Data, SAV.Spinda).ToString("X8");
TB_Spinda.Text = Zukan.SpindaPID.ToString("X8");
CB_Species.KeyDown += WinFormsUtil.RemoveDropCB;
}
@ -203,12 +203,7 @@ namespace PKHeX.WinForms
private void B_Save_Click(object sender, EventArgs e)
{
SetEntry();
// Store Spinda Spot
uint PID = Util.GetHexValue(TB_Spinda.Text);
BitConverter.GetBytes(PID).CopyTo(SAV.Data, SAV.Spinda);
// Return back to the parent savefile
Zukan.SpindaPID = Util.GetHexValue(TB_Spinda.Text);
Origin.SetData(SAV.Data, 0);
Close();
}