mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 04:23:12 +00:00
Simplify get/decrypt pkm access
This commit is contained in:
parent
5dcf2f4dc8
commit
bb8cf5d3d8
19 changed files with 40 additions and 50 deletions
|
@ -5,9 +5,6 @@
|
|||
/// <summary> Parent of the object that initiated the slot change. </summary>
|
||||
public object Parent { get; set; }
|
||||
|
||||
/// <summary> Original Data of the slot. </summary>
|
||||
public byte[] OriginalData { get; set; }
|
||||
|
||||
public int Slot { get; set; } = -1;
|
||||
public int Box { get; set; } = -1;
|
||||
public PKM PKM { get; set; }
|
||||
|
|
|
@ -12,11 +12,11 @@
|
|||
public SlotChange Source { get; set; }
|
||||
public SlotChange Destination { get; set; }
|
||||
|
||||
private readonly byte[] BlankData;
|
||||
private readonly PKM Blank;
|
||||
|
||||
public SlotChangeInfo(SaveFile sav)
|
||||
{
|
||||
BlankData = sav.BlankPKM.EncryptedPartyData;
|
||||
Blank = sav.BlankPKM;
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
|||
public void Reset()
|
||||
{
|
||||
LeftMouseIsDown = RightMouseIsDown = DragDropInProgress = false;
|
||||
Source = new SlotChange { OriginalData = BlankData };
|
||||
Source = new SlotChange { PKM = Blank };
|
||||
Destination = new SlotChange();
|
||||
Cursor = CurrentPath = null;
|
||||
}
|
||||
|
|
|
@ -453,14 +453,14 @@ namespace PKHeX.Core
|
|||
// Don't allow for custom box names
|
||||
}
|
||||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
protected override PKM GetPKM(byte[] data)
|
||||
{
|
||||
if (data.Length == SIZE_STORED)
|
||||
return new PokeList1(data, PokeListType.Single, Japanese)[0];
|
||||
return new PK1(data);
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data)
|
||||
protected override byte[] DecryptPKM(byte[] data)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -487,14 +487,14 @@ namespace PKHeX.Core
|
|||
SetData(data, Offsets.BoxNames + (box * len));
|
||||
}
|
||||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
protected override PKM GetPKM(byte[] data)
|
||||
{
|
||||
if (data.Length == SIZE_STORED)
|
||||
return new PokeList2(data, PokeListType.Single, Japanese)[0];
|
||||
return new PK2(data);
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data)
|
||||
protected override byte[] DecryptPKM(byte[] data)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -708,12 +708,12 @@ namespace PKHeX.Core
|
|||
SetString(value, 8).CopyTo(Data, offset + (box * 9));
|
||||
}
|
||||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
protected override PKM GetPKM(byte[] data)
|
||||
{
|
||||
return new PK3(data);
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data)
|
||||
protected override byte[] DecryptPKM(byte[] data)
|
||||
{
|
||||
return PKX.DecryptArray3(data);
|
||||
}
|
||||
|
|
|
@ -302,14 +302,14 @@ namespace PKHeX.Core
|
|||
SetString(value, 8).CopyTo(Data, Box + (0x24A4 * box));
|
||||
}
|
||||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
protected override PKM GetPKM(byte[] data)
|
||||
{
|
||||
if (data.Length != SIZE_STORED)
|
||||
Array.Resize(ref data, SIZE_STORED);
|
||||
return new CK3(data);
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data)
|
||||
protected override byte[] DecryptPKM(byte[] data)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -165,14 +165,14 @@ namespace PKHeX.Core
|
|||
SetData(data, offset);
|
||||
}
|
||||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
protected override PKM GetPKM(byte[] data)
|
||||
{
|
||||
if (data.Length != PKX.SIZE_3STORED)
|
||||
Array.Resize(ref data, PKX.SIZE_3STORED);
|
||||
return new PK3(data);
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data)
|
||||
protected override byte[] DecryptPKM(byte[] data)
|
||||
{
|
||||
if (data.Length != PKX.SIZE_3STORED)
|
||||
Array.Resize(ref data, PKX.SIZE_3STORED);
|
||||
|
|
|
@ -264,20 +264,20 @@ namespace PKHeX.Core
|
|||
SetString(value, 8).CopyTo(Data, GetBoxInfoOffset(box));
|
||||
}
|
||||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
protected override PKM GetPKM(byte[] data)
|
||||
{
|
||||
if (data.Length != SIZE_STORED)
|
||||
Array.Resize(ref data, SIZE_STORED);
|
||||
return new XK3(data);
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data) => data;
|
||||
protected override byte[] DecryptPKM(byte[] data) => data;
|
||||
public override PKM GetPartySlot(int offset) => GetStoredSlot(offset);
|
||||
|
||||
public override PKM GetStoredSlot(int offset)
|
||||
{
|
||||
// Get Shadow Data
|
||||
var pk = (XK3)GetPKM(DecryptPKM(GetData(offset, SIZE_STORED)));
|
||||
var pk = (XK3)base.GetStoredSlot(offset);
|
||||
if (pk.ShadowID > 0 && pk.ShadowID < ShadowInfo.Count)
|
||||
pk.Purification = ShadowInfo[pk.ShadowID - 1].Purification;
|
||||
return pk;
|
||||
|
|
|
@ -627,12 +627,12 @@ namespace PKHeX.Core
|
|||
SetData(SetString(value, 13), offset + (box * 0x28));
|
||||
}
|
||||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
protected override PKM GetPKM(byte[] data)
|
||||
{
|
||||
return new PK4(data);
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data)
|
||||
protected override byte[] DecryptPKM(byte[] data)
|
||||
{
|
||||
return PKX.DecryptArray45(data);
|
||||
}
|
||||
|
|
|
@ -205,14 +205,14 @@ namespace PKHeX.Core
|
|||
SetData(data, ofs);
|
||||
}
|
||||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
protected override PKM GetPKM(byte[] data)
|
||||
{
|
||||
if (data.Length != SIZE_STORED)
|
||||
Array.Resize(ref data, SIZE_STORED);
|
||||
return new BK4(data);
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data) => data;
|
||||
protected override byte[] DecryptPKM(byte[] data) => data;
|
||||
|
||||
protected override void SetDex(PKM pkm) { /* There's no PokéDex */ }
|
||||
|
||||
|
|
|
@ -262,12 +262,12 @@ namespace PKHeX.Core
|
|||
set { }
|
||||
}
|
||||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
protected override PKM GetPKM(byte[] data)
|
||||
{
|
||||
return new PK5(data);
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data)
|
||||
protected override byte[] DecryptPKM(byte[] data)
|
||||
{
|
||||
return PKX.DecryptArray45(data);
|
||||
}
|
||||
|
|
|
@ -778,7 +778,7 @@ namespace PKHeX.Core
|
|||
SetData(Encoding.Unicode.GetBytes(value.PadRight(LongStringLength / 2, '\0')), PCLayout + (LongStringLength * box));
|
||||
}
|
||||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
protected override PKM GetPKM(byte[] data)
|
||||
{
|
||||
return new PK6(data);
|
||||
}
|
||||
|
@ -939,7 +939,7 @@ namespace PKHeX.Core
|
|||
return false;
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data)
|
||||
protected override byte[] DecryptPKM(byte[] data)
|
||||
{
|
||||
return PKX.DecryptArray(data);
|
||||
}
|
||||
|
|
|
@ -967,7 +967,7 @@ namespace PKHeX.Core
|
|||
Edited = true;
|
||||
}
|
||||
|
||||
public override PKM GetPKM(byte[] data)
|
||||
protected override PKM GetPKM(byte[] data)
|
||||
{
|
||||
return new PK7(data);
|
||||
}
|
||||
|
@ -1233,7 +1233,7 @@ namespace PKHeX.Core
|
|||
return false;
|
||||
}
|
||||
|
||||
public override byte[] DecryptPKM(byte[] data)
|
||||
protected override byte[] DecryptPKM(byte[] data)
|
||||
{
|
||||
return PKX.DecryptArray(data);
|
||||
}
|
||||
|
|
|
@ -170,8 +170,8 @@ namespace PKHeX.Core
|
|||
public override bool GetCaught(int species) => Zukan.GetCaught(species);
|
||||
public override bool GetSeen(int species) => Zukan.GetSeen(species);
|
||||
|
||||
public override PKM GetPKM(byte[] data) => new PB7(data);
|
||||
public override byte[] DecryptPKM(byte[] data) => PKX.DecryptArray(data);
|
||||
protected override PKM GetPKM(byte[] data) => new PB7(data);
|
||||
protected override byte[] DecryptPKM(byte[] data) => PKX.DecryptArray(data);
|
||||
public override int GetBoxOffset(int box) => Box + (box * BoxSlotCount * SIZE_STORED);
|
||||
protected override IList<int>[] SlotPointers => new[] { Storage.PokeListInfo };
|
||||
|
||||
|
|
|
@ -38,9 +38,9 @@ namespace PKHeX.Core
|
|||
|
||||
// General PKM Properties
|
||||
public abstract Type PKMType { get; }
|
||||
public abstract PKM GetPKM(byte[] data);
|
||||
protected abstract PKM GetPKM(byte[] data);
|
||||
protected abstract byte[] DecryptPKM(byte[] data);
|
||||
public abstract PKM BlankPKM { get; }
|
||||
public abstract byte[] DecryptPKM(byte[] data);
|
||||
public abstract int SIZE_STORED { get; }
|
||||
protected abstract int SIZE_PARTY { get; }
|
||||
public abstract int MaxEV { get; }
|
||||
|
@ -596,11 +596,7 @@ namespace PKHeX.Core
|
|||
=> SetPartySlot(pkm, GetPartyOffset(index), trade, dex);
|
||||
|
||||
public virtual PKM GetPartySlot(int offset) => GetPKM(DecryptPKM(GetData(offset, SIZE_PARTY)));
|
||||
|
||||
public virtual PKM GetStoredSlot(int offset)
|
||||
{
|
||||
return GetPKM(DecryptPKM(GetData(offset, SIZE_STORED)));
|
||||
}
|
||||
public virtual PKM GetStoredSlot(int offset) => GetPKM(DecryptPKM(GetData(offset, SIZE_STORED)));
|
||||
|
||||
public void SetPartySlot(PKM pkm, int offset, PKMImportSetting trade = PKMImportSetting.UseDefault, PKMImportSetting dex = PKMImportSetting.UseDefault)
|
||||
{
|
||||
|
|
|
@ -36,8 +36,8 @@ namespace PKHeX.Core
|
|||
public override Type PKMType => blank.GetType();
|
||||
public override PKM BlankPKM => blank.Clone();
|
||||
|
||||
public override PKM GetPKM(byte[] data) => PKMConverter.GetPKMfromBytes(data, prefer: Generation);
|
||||
public override byte[] DecryptPKM(byte[] data) => GetPKM(data).Data;
|
||||
protected override PKM GetPKM(byte[] data) => PKMConverter.GetPKMfromBytes(data, prefer: Generation);
|
||||
protected override byte[] DecryptPKM(byte[] data) => GetPKM(data).Data;
|
||||
|
||||
public override int SIZE_STORED => blank.SIZE_STORED;
|
||||
protected override int SIZE_PARTY => blank.SIZE_PARTY;
|
||||
|
|
|
@ -20,8 +20,8 @@ namespace PKHeX.Core
|
|||
public override string Extension => ".bin";
|
||||
public override string Filter { get; } = "Ranch G4 Storage|*.bin*";
|
||||
|
||||
public override PKM GetPKM(byte[] data) => new PK4(data);
|
||||
public override byte[] DecryptPKM(byte[] data) => PKX.DecryptArray45(data);
|
||||
protected override PKM GetPKM(byte[] data) => new PK4(data);
|
||||
protected override byte[] DecryptPKM(byte[] data) => PKX.DecryptArray45(data);
|
||||
public override StorageSlotFlag GetSlotFlags(int index) => index >= SlotCount ? StorageSlotFlag.Locked : StorageSlotFlag.None;
|
||||
protected override bool IsSlotSwapProtected(int box, int slot) => IsSlotOverwriteProtected(box, slot);
|
||||
|
||||
|
|
|
@ -247,7 +247,7 @@ namespace PKHeX.WinForms.Controls
|
|||
|
||||
// Prepare Data
|
||||
DragInfo.Source = GetViewParent(pb).GetSlotData(pb);
|
||||
DragInfo.Source.OriginalData = SAV.GetData(DragInfo.Source.Offset, SAV.SIZE_STORED);
|
||||
DragInfo.Source.PKM = SAV.GetStoredSlot(DragInfo.Source.Offset);
|
||||
|
||||
// Make a new file name based off the PID
|
||||
string newfile = CreateDragDropPKM(pb, encrypt, out bool external);
|
||||
|
@ -272,11 +272,8 @@ namespace PKHeX.WinForms.Controls
|
|||
|
||||
private string CreateDragDropPKM(PictureBox pb, bool encrypt, out bool external)
|
||||
{
|
||||
byte[] dragdata = SAV.DecryptPKM(DragInfo.Source.OriginalData);
|
||||
Array.Resize(ref dragdata, SAV.SIZE_STORED);
|
||||
|
||||
// Make File
|
||||
PKM pk = SAV.GetPKM(dragdata);
|
||||
PKM pk = DragInfo.Source.PKM;
|
||||
string newfile = FileUtil.GetPKMTempFileName(pk, encrypt);
|
||||
try
|
||||
{
|
||||
|
|
|
@ -278,9 +278,9 @@ namespace PKHeX.WinForms
|
|||
|
||||
private void LoadBattleAgency()
|
||||
{
|
||||
p[0] = SAV.GetPKM(SAV.DecryptPKM(SAV.GetData(0x6C200, 0xE8)));
|
||||
p[1] = SAV.GetPKM(SAV.DecryptPKM(SAV.GetData(0x6C2E8, 0x104)));
|
||||
p[2] = SAV.GetPKM(SAV.DecryptPKM(SAV.GetData(0x6C420, 0x104)));
|
||||
p[0] = SAV.GetStoredSlot(0x6C200);
|
||||
p[1] = SAV.GetPartySlot(0x6C2E8);
|
||||
p[2] = SAV.GetPartySlot(0x6C420);
|
||||
LoadPictureBox();
|
||||
B_ImportParty.Visible = SAV.HasParty;
|
||||
CHK_Choosed.Checked = SAV.GetFlag(0x6C55E, 1);
|
||||
|
|
Loading…
Reference in a new issue