2016-06-20 04:22:43 +00:00
|
|
|
|
using System;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
using System.Linq;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX
|
|
|
|
|
{
|
|
|
|
|
public enum InventoryType
|
|
|
|
|
{
|
|
|
|
|
Items,
|
|
|
|
|
KeyItems,
|
|
|
|
|
TMHMs,
|
|
|
|
|
Medicine,
|
|
|
|
|
Berries,
|
|
|
|
|
Balls,
|
|
|
|
|
BattleItems,
|
|
|
|
|
MailItems,
|
|
|
|
|
}
|
|
|
|
|
public class InventoryItem
|
|
|
|
|
{
|
|
|
|
|
public int Index, Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class InventoryPouch
|
|
|
|
|
{
|
|
|
|
|
public readonly InventoryType Type;
|
|
|
|
|
public readonly ushort[] LegalItems;
|
|
|
|
|
public readonly int MaxCount;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
public int Count => Items.Count(it => it.Count > 0);
|
|
|
|
|
public readonly int Offset;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
private readonly int PouchDataSize;
|
2016-07-01 04:53:24 +00:00
|
|
|
|
public uint SecurityKey { private get; set; } // = 0 // Gen3 Only
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public InventoryItem[] Items;
|
|
|
|
|
|
|
|
|
|
public InventoryPouch(InventoryType type, ushort[] legal, int maxcount, int offset, int size = -1)
|
|
|
|
|
{
|
|
|
|
|
Type = type;
|
|
|
|
|
LegalItems = legal;
|
|
|
|
|
MaxCount = maxcount;
|
|
|
|
|
Offset = offset;
|
|
|
|
|
PouchDataSize = size > -1 ? size : legal.Length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void getPouch(ref byte[] Data)
|
|
|
|
|
{
|
|
|
|
|
InventoryItem[] items = new InventoryItem[PouchDataSize];
|
|
|
|
|
for (int i = 0; i < items.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
items[i] = new InventoryItem
|
|
|
|
|
{
|
|
|
|
|
Index = BitConverter.ToUInt16(Data, Offset + i*4),
|
2016-07-01 04:53:24 +00:00
|
|
|
|
Count = BitConverter.ToUInt16(Data, Offset + i*4 + 2) ^ (ushort)SecurityKey
|
2016-06-20 04:22:43 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
Items = items;
|
|
|
|
|
}
|
|
|
|
|
public void setPouch(ref byte[] Data)
|
|
|
|
|
{
|
|
|
|
|
if (Items.Length != PouchDataSize)
|
|
|
|
|
throw new ArgumentException("Item array length does not match original pouch size.");
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Items.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
BitConverter.GetBytes((ushort)Items[i].Index).CopyTo(Data, Offset + i*4);
|
2016-07-02 04:21:15 +00:00
|
|
|
|
BitConverter.GetBytes((ushort)((ushort)Items[i].Count ^ (ushort)SecurityKey)).CopyTo(Data, Offset + i*4 + 2);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-28 10:18:22 +00:00
|
|
|
|
|
|
|
|
|
public void getPouchG1(ref byte[] Data)
|
|
|
|
|
{
|
|
|
|
|
InventoryItem[] items = new InventoryItem[PouchDataSize];
|
|
|
|
|
int numStored = Data[Offset];
|
|
|
|
|
for (int i = 0; i < numStored; i++)
|
|
|
|
|
{
|
|
|
|
|
items[i] = new InventoryItem
|
|
|
|
|
{
|
|
|
|
|
Index = Data[Offset + i * 2 + 1],
|
|
|
|
|
Count = Data[Offset + i * 2 + 2]
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
for (int i = numStored; i < items.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
items[i] = new InventoryItem
|
|
|
|
|
{
|
|
|
|
|
Index = 0,
|
|
|
|
|
Count = 0
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
Items = items;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setPouchG1(ref byte[] Data)
|
|
|
|
|
{
|
|
|
|
|
if (Items.Length != PouchDataSize)
|
|
|
|
|
throw new ArgumentException("Item array length does not match original pouch size.");
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Items.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
Data[Offset + i * 2 + 1] = (byte)Items[i].Index;
|
|
|
|
|
Data[Offset + i * 2 + 2] = (byte)Items[i].Count;
|
|
|
|
|
}
|
|
|
|
|
Data[Offset] = (byte) Count;
|
|
|
|
|
Data[Offset + 1 + 2*Count] = 0xFF;
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|